Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions convert_all.py
Original file line number Diff line number Diff line change
@@ -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))
20 changes: 14 additions & 6 deletions lolpytools/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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("[")
Expand Down
4 changes: 2 additions & 2 deletions lolpytools/inibin2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
182 changes: 174 additions & 8 deletions lolpytools/inibin_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
[
Expand All @@ -88,6 +102,7 @@ def map_vars(*args):
[
"EventLookupTable",
"NumOfSoundBanks",
*[ f'SoundBank{i}' for i in range(1, 23) ],
],
],
# LEVELS/MapX/clouds.inibin
Expand Down Expand Up @@ -377,6 +392,8 @@ def map_vars(*args):
"EdgeEnhancement",
"EdgeTintPoint",
"Upscale",
"BaseMapBrightness",
"UVAnimate",
],
],
[
Expand Down Expand Up @@ -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", ],
[
Expand All @@ -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/
[
Expand Down
6 changes: 3 additions & 3 deletions lolpytools/plua.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -127,7 +127,7 @@ def F8(v):
R(a)[0] = "<CLOUSURE>"
pc = pc + 1
else:
raise "Unknown opcode: {}".format(op)
raise ValueError("Unknown opcode: {}".format(op))
return {
"Values": G
}
Expand Down
2 changes: 1 addition & 1 deletion lolpytools/releasemanifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) ]
Expand Down
2 changes: 1 addition & 1 deletion lolpytools/troybin_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down