Skip to content

Instantly share code, notes, and snippets.

@Jadd
Last active April 13, 2021 19:42
Show Gist options
  • Save Jadd/dbea076c53771c8751ea6c80c8117a43 to your computer and use it in GitHub Desktop.
Save Jadd/dbea076c53771c8751ea6c80c8117a43 to your computer and use it in GitHub Desktop.
import urllib2
opcode_names = []
total_messages = 0
valid_messages = 0
def get_trinity_opcodes():
global opcode_names
url = urllib2.urlopen("https://raw.githubusercontent.com/TrinityCore/TrinityCore/master/src/server/game/Server/Protocol/Opcodes.h")
code = url.read()
code = code.replace(" ", "")
code = code.split("\n")
url.close()
for line in code:
if not line.startswith("CMSG_"):
continue
name = line[:-8]
opcode = int(line[-5:-1], 16)
opcode_names.append([opcode, name])
def get_opcode_name(id):
for opcode in opcode_names:
if opcode[0] == id:
return opcode[1]
return None
def rename_opcode_functions():
global total_messages
global valid_messages
func = 0
messages = []
while True:
func = FindBinary(func + 1, SEARCH_DOWN, "55 8B EC 56 8B F1 8B 4D 08 68 ? ? ? ? E8 ? ? ? ? 8B 06 8B CE FF 75 08 FF 50 04 5E 5D C2 04 00")
if func == BADADDR:
break
total_messages = total_messages + 1
opcode = Dword(func + 0x0A)
vtable = DfirstB(func) - 0x08
constructor = DfirstB(vtable)
if constructor == BADADDR:
print("Warning: Could not find constructor for opcode 0x%04X" % opcode)
continue
constructor = FirstFuncFchunk(constructor)
name = get_opcode_name(opcode)
if name == None:
MakeNameEx(constructor, "CMSG_UNKNOWN_OPCODE_%04X" % opcode, SN_NOWARN)
print("Warning: Could not find name for opcode 0x%04X" % opcode)
continue
#print("{:<60}= 0x{:04X},".format(name, opcode))
MakeNameEx(constructor, name, SN_NOWARN)
valid_messages = valid_messages + 1
get_trinity_opcodes()
rename_opcode_functions()
print("Messages renamed: %u" % valid_messages)
print("Messages skipped: %u" % (total_messages - valid_messages))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment