From f6f06ed8fe76eb1ff19348815788af221cd11728 Mon Sep 17 00:00:00 2001 From: 7abf7473 Date: Sun, 16 Oct 2022 04:53:40 +0300 Subject: [PATCH] update 1 --- convert_all.py | 45 +++++++++ lolpytools/convert.py | 20 ++-- lolpytools/inibin2.py | 4 +- lolpytools/inibin_fix.py | 182 ++++++++++++++++++++++++++++++++-- lolpytools/plua.py | 6 +- lolpytools/releasemanifest.py | 2 +- lolpytools/troybin_fix.py | 2 +- 7 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 convert_all.py diff --git a/convert_all.py b/convert_all.py new file mode 100644 index 0000000..9f28fcf --- /dev/null +++ b/convert_all.py @@ -0,0 +1,45 @@ +import os +import argparse +from tqdm.contrib.concurrent import process_map +from lolpytools.convert import inibin2ini, luaobj2lua, troybin2troy +import re +import traceback + +parser = argparse.ArgumentParser(description='Convert all supported files from binary to text format') +parser.add_argument('folder', type=str, help='deploy folder') +parser.add_argument('output', type=str, help='output folder', default='-', nargs='?') +args = parser.parse_args() + +input_folder = args.folder +output_folder = args.output +if output_folder == '-': + output_folder = input_folder + + +print('Searching for files...') + +filepaths = [] +for root, dirnames, filenames in os.walk(input_folder): + for filename in filenames: + if filename.endswith('.inibin') or filename.endswith('.troybin'): #or filename.endswith('.luaobj'): + filepath = os.path.join(root, filename) + filepaths.append(filepath) + +def process_file(infilepath: str): + outfilepath = infilepath.replace(input_folder, output_folder, 1) + outfilepath = re.sub(r'(bin|obj)$', '', outfilepath) + #print(infilepath, '->', outfilepath) + with open(infilepath, 'rb') as infile, open(outfilepath, 'w') as outfile: + try: + if infilepath.endswith('.inibin'): + inibin2ini(infile, outfile) + elif infilepath.endswith('.troybin'): + troybin2troy(infile, outfile) + #elif infilepath.endswith('.luaobj'): + # luaobj2lua(infile, outfile) + except Exception as e: + print(infilepath, e, sep='\n') + traceback.print_exc() + +process_map(process_file, filepaths, max_workers=1000, chunksize=10) +#list(map(process_file, filepaths)) \ No newline at end of file diff --git a/lolpytools/convert.py b/lolpytools/convert.py index c61649a..13057c3 100755 --- a/lolpytools/convert.py +++ b/lolpytools/convert.py @@ -5,23 +5,29 @@ from . import plua import json +def rrepr(value): + # Otherwise, the League does not read colors + if isinstance(value, float) and value % 1 == 0: + return str(int(value)) + return repr(value) + def writeini(ibin, outfile): def write_value(name, value): if isinstance(value, str): - outfile.write('{}={}\n'.format(name, json.dumps(value))) + outfile.write('{}={}\n'.format(name, value)) elif isinstance(value, bool): - outfile.write('{}={}\n'.format(name, '1' if value else '0')) + outfile.write('{}={}\n'.format(name, 'true' if value else 'false')) elif isinstance(value, list) or isinstance(value, tuple): - outfile.write('{}={}\n'.format(name, ' '.join([repr(x) for x in value]))) + outfile.write('{}={}\n'.format(name, ' '.join([rrepr(x) for x in value]))) elif isinstance(value, int): outfile.write('{}={}\n'.format(name, value)) elif isinstance(value, float): - outfile.write('{}={}\n'.format(name, repr(value))) + outfile.write('{}={}\n'.format(name, rrepr(value))) else: raise Exception("Unknown type: {}".format(type(value))) for section, names in sorted(ibin["Values"].items()): outfile.write('[{}]\n'.format(section)) - for name,value in sorted(names.items()): + for name, value in sorted(names.items()): write_value(name, value) outfile.write('\n') if len(ibin["UNKNOWN_HASHES"]) > 0: @@ -71,7 +77,9 @@ def write_value(value, indent = 0): else: outfile.write("{\n") isarray = verify_array(value) - for tkey, tvalue in sorted(value.items()): + #TODO: Find out why the error occurs + #for tkey, tvalue in sorted(value.items()): + for tkey, tvalue in value.items(): outfile.write(" " * ((indent + 1) * 4)) if not isarray: outfile.write("[") diff --git a/lolpytools/inibin2.py b/lolpytools/inibin2.py index 00921f3..504a2f7 100755 --- a/lolpytools/inibin2.py +++ b/lolpytools/inibin2.py @@ -118,7 +118,7 @@ def read_strings(buffer, stringsLength, dumy=None): if x < len(read_conf): target.update(read_conf[x][0](buffer, *(read_conf[x][1]))) else: - raise "Unknown inibin flag {} in {}!".format(x, buffer.name) + raise ValueError("Unknown inibin flag {} in {}!".format(x, buffer.name)) return target # reads version 1 .inibin @@ -162,7 +162,7 @@ def read(buffer, result = None): elif version == 1: read_1(buffer, target) else: - raise "Unknow version!" + raise ValueError("Unknow version!") assert(buffer.tell() == os.fstat(buffer.fileno()).st_size) return result diff --git a/lolpytools/inibin_fix.py b/lolpytools/inibin_fix.py index 0c405e2..826f7b8 100755 --- a/lolpytools/inibin_fix.py +++ b/lolpytools/inibin_fix.py @@ -4,7 +4,7 @@ def ihash(value, ret = 0): for c in value: - ret = (ord(c.lower()) +((65599 * ret) & 0xffffffff)) & 0xffffffff + ret = (ord(c.lower()) + ((65599 * ret) & 0xffffffff)) & 0xffffffff return ret def a_ihash(sections, names): @@ -65,9 +65,23 @@ def map_vars(*args): *[ "Map%d_%s" % (x,a) for a in args for x in range(0, 15) ], ] -#FIXME: Blacklisted stuff: "UnitBarData", "MapObjects", "GeneralCharacterData" +#FIXME: Blacklisted stuff: "MapObjects" -all_inibin_fixlist = [ +todo_rename1 = [ + 'UnitSingle', + 'UnitDouble', + 'Dragon', + 'Ward', + 'Baron', + 'Turret', + 'NexusPaladin', + 'NexusMage', + 'InhibPaladin', + 'InhibMage', + 'Counter' +] + +all_inibin_fixlist: list[list[list[str]]] = [ # TODO: LEVELS/MapX/AtmosphereMutators.inibin (Atmosphere*mutators) # LEVELS/MapX/Audio.inibin [ @@ -88,6 +102,7 @@ def map_vars(*args): [ "EventLookupTable", "NumOfSoundBanks", + *[ f'SoundBank{i}' for i in range(1, 23) ], ], ], # LEVELS/MapX/clouds.inibin @@ -377,6 +392,8 @@ def map_vars(*args): "EdgeEnhancement", "EdgeTintPoint", "Upscale", + "BaseMapBrightness", + "UVAnimate", ], ], [ @@ -741,11 +758,7 @@ def map_vars(*args): ], ], # DATA/Menu_SC4/GeneralCharacterData.inibin -# TODO: Do we need this? - [ - [ "AttackData", ], - [ "AttackAutoInterruptPercent", ], - ], +# DATA/Menu_SC4/UnitBarData.inibin [ [ "GeneralDataHero", ], [ @@ -759,7 +772,160 @@ def map_vars(*args): "FullHealthAlpha", "MaxHealthTicks", "ZeroHealthAlpha", + + 'MPBarColor', + 'OtherBarColor', + 'ShieldBarColor', + 'EnergyFadeColor', + 'ShieldFadeColor', + 'ChampionParallaxOffset', + 'MPFadeColor', + 'OtherFadeColor', + 'EnergyBarColor', + ], + ], + [ + [ + *[ f'{x}_Backdrop' for x in todo_rename1 ], + *[ + f'Champion{x}BackdropTemplate{y}' + for x in ['Self', 'Friendly', 'Enemy'] + for y in ['Default', 'Spectator', 'Colorblind'] + ], + 'ChampionLoCBarBackdropTemplate', + 'ChampionChatBubbleTemplate', + + ], + [ + 'BackgroundTexture', + * [ f'{x}{y}PixelRegion' for x in ['Highlight', 'Background'] for y in ['Mid', 'Left', 'Right'] ], + ], + ], + [ + [ + *[ f'{x}_{y}Bar' for x in todo_rename1 for y in ['Health', 'Timer', 'Par'] ], + *[ f'Champion{x}BarTemplate' for x in ['Health', 'PAR', 'LoC'] ], + ], + [ + 'BarTexture', + 'BarPixelRegion', + 'MegaTickPixelRegion', + 'TickPixelWidth', + 'TickPixelRegion', + ] + ], + [ + [ + f'{x}_UnitParams{y}{z}' + for x in todo_rename1 + for y in ['Friendly', 'Enemy', 'Neutral'] + for z in ['Default', 'Spectator', 'Colorblind'] ], + [ + 'MagicShieldColor', + 'HealthBarColor', + 'PhysShieldColor', + 'FadeSpeed', + 'HealthFadeColor', + 'AllShieldColor', + + 'HighlightColor', + 'MidHorizontalScaling', + 'AggroIndicatorOffset', + 'HPBarStartOffset', + 'BackgroundColor', + 'TimerBarColor', + 'TimerBarStartOffset', + 'PowerBarColor', + 'PowerBarStartOffset', + 'HealthTextOffset', + ] + ], + [ + [ + f'HealthBarChampion{x}{y}' + for x in ['Self', 'Friendly', 'Enemy'] + for y in ['Default', 'Spectator', 'Colorblind'] + ], + [ + 'MagicShieldColor', + 'HealthBarColor', + 'PhysShieldColor', + 'FadeSpeed', + 'HealthFadeColor', + 'AllShieldColor', + + 'LevelTextOffset', + 'PercentageOffset', + 'HealthFillColor', + 'ChatBubbleOffset', + 'HealthOffset', + 'LoCOffset', + 'TitleTextOffset', + 'PAROffset', + ] + ], + [ + [ + * [ f'{x}_HealthText' for x in todo_rename1 ], + * [ f'Champion{x}TextTemplate' for x in [ 'Level', 'Title' ] ] + ], + [ + 'FontName', + 'DropShadowDepth', + ], + ], + [ + [ 'HealthBarSettings' ], + [ + * [ + x.format(y) + for x in [ + 'DefaultHealthPer{}Tick', + 'MaxHealth{}Ticks', + '{}TickThickness', + '{}TickAlpha', + '{}TickHeight' + ] + for y in [ '', 'Micro', 'Mega' ] + ], + 'GoTransparent', + 'UseCompression', + ] + ], + [ + [ f'Champion{x}LoCBarIconData' for x in ['Self', 'Friendly', 'Enemy'] ], + [ + 'RootTexture', + 'CharmTexture', + 'AirborneTexture', + 'SuppressionTexture', + 'BlindTexture', + 'SilenceTexture', + 'TauntTexture', + 'DisarmTexture', + 'SlowTexture', + 'StunTexture', + 'FearTexture', + + 'IconWidth', + 'IconHeight', + 'IconOffsetX', + 'IconOffsetY', + 'AdditionalIconOffsetX', + 'AdditionalIconOffsetY', + ], + ], + [ + [ 'UnitAggroEffect' ], + [ + 'TextureSheet', + *[ + f'KeyFrame{x}_{y}' + for x in range(1, 12 + 1) + for y in ['Time', 'PixelRegion'] + ], + ] ], # DATA/LoadingScreen/ [ diff --git a/lolpytools/plua.py b/lolpytools/plua.py index 38cb018..fde259b 100755 --- a/lolpytools/plua.py +++ b/lolpytools/plua.py @@ -33,7 +33,7 @@ def read_list(what): magic = readx(12) if not magic == b'\x1B\x4C\x75\x61\x51\x00\x01\x04\x04\x04\x08\x00': - raise "Magic doesn't match" + raise ValueError("Magic doesn't match") source = read_str() flags = readx(12) ops = read_list(read_op) @@ -53,7 +53,7 @@ def F8(v): return x if e == 0 else (x | 8) * (2 ** (e -1)) while True: if pc >= len(ops): - raise "Pc out of range!" + raise ValueError("Pc out of range!") code = ops[pc] pc = pc + 1 op = code & 0b111111 @@ -127,7 +127,7 @@ def F8(v): R(a)[0] = "" pc = pc + 1 else: - raise "Unknown opcode: {}".format(op) + raise ValueError("Unknown opcode: {}".format(op)) return { "Values": G } diff --git a/lolpytools/releasemanifest.py b/lolpytools/releasemanifest.py index 68f1e02..47faeb0 100755 --- a/lolpytools/releasemanifest.py +++ b/lolpytools/releasemanifest.py @@ -54,7 +54,7 @@ def read(buffer): def unpack(what): return what.unpack_from(buffer.read(what.size)) if not magic == b"RLSM": - raise "Wrong releasemanifest magic!" + raise ValueError("Wrong releasemanifest magic!") majorV, minorV, prNameIndex, releaseV, = unpack(s_header) folderC, = unpack(s_count) folders = [ rel_folder(buffer) for x in range(0, folderC) ] diff --git a/lolpytools/troybin_fix.py b/lolpytools/troybin_fix.py index 4640dbf..d6cd5a2 100755 --- a/lolpytools/troybin_fix.py +++ b/lolpytools/troybin_fix.py @@ -8,7 +8,7 @@ def ihash(value, ret = 0): for c in value: - ret = (ord(c.lower()) +((65599 * ret) & 0xffffffff)) & 0xffffffff + ret = (ord(c.lower()) + ((65599 * ret) & 0xffffffff)) & 0xffffffff return ret def a_ihash(sections, names):