1:1 source port of the engine and game code; Windows build and system layer; docs. No game files or SDK headers.
This commit is contained in:
parent
c3b032a45a
commit
0ecb47e9cb
3871 changed files with 91080 additions and 1640063 deletions
43
tools/port/fn.py
Normal file
43
tools/port/fn.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
"""Show the decompile of a function from the game binary and from the SDK debug build side by side.
|
||||
|
||||
usage: python3 tools/port/fn.py PATTERN [--game-only|--sdk-only]
|
||||
PATTERN matches the demangled name (e.g. 'TTextGraphic::RenderText') or part of the mangled one.
|
||||
Game: parity-out/full/decomp/_global.c (addresses are the shipped binary). SDK: parity-out/sdk/decomp/*.c (typed, DWARF names).
|
||||
"""
|
||||
import glob, os, re, subprocess, sys
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
def blocks(path):
|
||||
text = open(path, errors='replace').read()
|
||||
parts = re.split(r'\n(?=// )', text)
|
||||
for p in parts:
|
||||
head = p.split('\n', 1)[0]
|
||||
yield head, p
|
||||
|
||||
def demangle(names):
|
||||
out = subprocess.run(['c++filt'], input='\n'.join(names), capture_output=True, text=True).stdout.split('\n')
|
||||
return out
|
||||
|
||||
def main():
|
||||
pat = sys.argv[1]
|
||||
mode = sys.argv[2] if len(sys.argv) > 2 else ''
|
||||
if mode != '--sdk-only':
|
||||
hits = []
|
||||
for head, body in blocks(os.path.join(ROOT, 'parity-out/full/decomp/_global.c')):
|
||||
m = re.search(r'\((_*Z\S*|[^)]*)\)\s*$', head)
|
||||
mangled = m.group(1) if m else ''
|
||||
hits.append((head, body, mangled))
|
||||
names = demangle([h[2][1:] if h[2].startswith('__Z') else h[2] for h in hits])
|
||||
for (head, body, mangled), dem in zip(hits, names):
|
||||
if pat in dem or pat in mangled:
|
||||
print('=' * 20, 'GAME', dem, '=' * 20)
|
||||
print(body)
|
||||
if mode != '--game-only':
|
||||
for path in sorted(glob.glob(os.path.join(ROOT, 'parity-out/sdk/decomp/*.c'))):
|
||||
for head, body in blocks(path):
|
||||
if pat in head:
|
||||
print('=' * 20, 'SDK', os.path.basename(path), '=' * 20)
|
||||
print(body)
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue