Skip to content

Instantly share code, notes, and snippets.

@barncastle
Created July 19, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barncastle/7ba656b732efdf9f13866870406c83ed to your computer and use it in GitHub Desktop.
Save barncastle/7ba656b732efdf9f13866870406c83ed to your computer and use it in GitHub Desktop.
Quick and dirty encode/decode script for SpellChainEffects' m_Combo field
import argparse
import struct
import array
'''
Quick and dirty encode/decode script for SpellChainEffects' m_Combo field (https://wowdev.wiki/DB/SpellChainEffects)
To decode: set -m to 1 and use the m_Combo value from the DB as the value for -d e.g.
combo_converter.py -m 1 -d "y3y3c3c3c3c3"
To encode: set -m to 2 and use a comma seperated list of ids for -d e.g.
combo_converter.py -m 2 -d "1017,1017,995,995,995,995"
Both the above can accept multiple sets of data for the -d parameter.
It will spit the results out on seperate lines e.g.
combo_converter.py -m 1 -d "y3y3" "c3c3c3c3"
combo_converter.py -m 2 -d "1017,1017" "995,995,995,995"
'''
parser = argparse.ArgumentParser()
parser.add_argument('-m', dest="mode", type=int, required=True, choices=[1, 2],
help="1 = decode, 2 = encode")
parser.add_argument('-d', dest="data", type=str, required=True, nargs='+',
help="decode: DB combo value, encode: comma separated ids")
args = parser.parse_args()
def decode(value):
return (
(value & 0xFEFEFEFE) |
(value & 0x08000000) >> 4 |
(value & 0x04000000) >> 11 |
(value & 0x40000000) >> 14 |
(value & 0x02000000) >> 18 |
(value & 0x20000000) >> 21 |
(value & 0x10000000) >> 28
) & 0xFFFFFF
def encode(value):
return (
(value | 0x01010101) |
(value << 4) & 0x08000000 |
(value << 11) & 0x04000000 |
(value << 14) & 0x40000000 |
(value << 18) & 0x02000000 |
(value << 21) & 0x20000000 |
(value << 28) & 0x10000000
) & ~0x80
if (args.mode == 1):
for data in args.data:
# convert arg to uint array
buffer = array.array("I")
buffer.fromstring(data.encode("utf-8", "ignore"))
# decode each value
decoded_ids = []
for b in buffer:
decoded_ids.append(decode(b))
# print decoded ids
print("Decoded Ids: " + ",".join(map(str, decoded_ids)))
elif (args.mode == 2):
for data in args.data:
# split args, cast to int, enforce uint and encode
encoded_ids = [encode(int(i) & 0xFFFFFFFF) for i in data.split(',')]
# convert to a byte array
buffer = struct.pack("{}I".format(len(encoded_ids)), *encoded_ids)
# utf8 encode
print("Encoded Ids: " + buffer.decode("utf-8"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment