Created
December 13, 2018 03:06
-
-
Save Talv/9606d1142d891dd102400542baf23430 to your computer and use it in GitHub Desktop.
StarCraft II Editor 10k doodads limit patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import bitstring | |
dlimit = bitstring.Bits(intle=10000, length=16) | |
nlimit = bitstring.Bits(intle=30000, length=16) | |
def pause(): | |
print("Press Enter to continue ...") | |
input() | |
def stop(msg): | |
print("[ERR] %s" % msg) | |
pause() | |
sys.exit(1) | |
def main(): | |
if len(sys.argv) <= 1: | |
stop("Expected path to 'SC2Editor_x64.exe' as first argument") | |
edFilename = sys.argv[1] | |
os.stat(edFilename) | |
s = bitstring.BitStream(filename=edFilename) | |
print("Locating initial offset..") | |
result = s.find('Point['.encode('ascii'), bytealigned=True) | |
if not result: | |
stop("Not found") | |
print("Found 0x%02X." % result[0]) | |
offset = result[0] | |
offset -= offset % 8 | |
print("Locating offset to patch..") | |
result = s.findall(dlimit, start=offset - 4096, end=offset, bytealigned=True) | |
dofs = list(result) | |
if not len(dofs): | |
stop("No results. Already patched?") | |
for i, x in enumerate(dofs): | |
print("[%d] Patching %d bytes at 0x%02X" % (i + 1, nlimit.len / 8, x)) | |
s.overwrite(nlimit, pos=x) | |
print("Backing up current version of the editor..") | |
os.rename(edFilename, edFilename + '.bak') | |
print("Writing file..") | |
with open(sys.argv[1], 'wb') as f: | |
s.tofile(f) | |
print("Completed successfully") | |
pause() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment