Skip to content

Instantly share code, notes, and snippets.

@matcool
Last active January 9, 2024 19:39
Show Gist options
  • Save matcool/3261e808bfc2785436b4ff2a3807b2e7 to your computer and use it in GitHub Desktop.
Save matcool/3261e808bfc2785436b4ff2a3807b2e7 to your computer and use it in GitHub Desktop.
gdstring.lib gen script
import subprocess
out = subprocess.check_output('dumpbin /exports libcocos2d.dll').decode()
# get just the symbol names
out = out[out.find('RVA'):].splitlines()[2:]
lines = []
for line in out:
if not line.strip(): break
lines.append(line.split()[-1])
symbols = []
for line in lines:
if not line.startswith('?'): continue
if line.startswith('??'): continue
if '@cocos2d@' not in line and '@DS_Dictionary@' not in line: continue
# if '@fmt@' in line: continue
# if 'base64EncodeEnc' not in line: continue
# skip ccstring::create, since we define it in geode
if 'create@CCString' in line: continue
if 'char_traits' in line:
symbols.append(line)
std_string_mangle = "V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@"
gd_string_mangle = "Vstring@gd@@"
vector_allocator_mangle = "$allocator@D@2@@std@@@2@@std"
vector_allocator_repl = "$allocator@D@2@@std@@@std@@@std"
make_symbol = lambda x: x.replace(vector_allocator_mangle, vector_allocator_repl).replace(std_string_mangle, gd_string_mangle)
with open('gdstring.asm', 'w') as file:
file.write('section .text\n')
for symbol in symbols:
file.write(f'extern {symbol}\n')
new_symbol = make_symbol(symbol)
file.write(f'extern {new_symbol}\n')
for symbol in symbols:
new_symbol = make_symbol(symbol)
file.write(f'{new_symbol}: \n\tjmp {symbol}\n\n')
import os
print_run = lambda x: (print(x), os.system(x))
print_run('nasm -f win32 gdstring.asm -o gdstring.obj')
print_run('link /lib gdstring.obj')
@matcool
Copy link
Author

matcool commented Dec 21, 2023

needs dumpbin, link and nasm. run in the same dir as libcocos2d.dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment