Cleaned up the AT config updater, should work for any setup of the MCP workspace now.

This commit is contained in:
LexManos 2012-11-17 19:08:47 -08:00
parent 783926194e
commit 8d26642a84
2 changed files with 94 additions and 73 deletions

View file

@ -757,7 +757,7 @@ def gen_merged_srg(mcp_dir, fml_dir):
#Print joined retroguard files
if fml_dir is None:
return common
return common
with open(os.path.join(fml_dir, 'conf', 'joined.srg'), 'wb') as f:
for type in ['PK:', 'CL:', 'FD:', 'MD:']:

View file

@ -1,80 +1,101 @@
import os, os.path, sys
import urllib, zipfile
import shutil, glob, fnmatch
import subprocess, logging, re, shlex
import csv
import csv, re
print(os.getcwd())
sys.path.append('install')
from fml import gen_merged_srg
ctorsigre = re.compile('<init>\((.*)\)')
ctorparamre = re.compile('(([ZBCSIJFD]|L([\w\/]+);))')
common = gen_merged_srg('..',None)
rev_common = {t:{v.split(' ')[0]:k for k, v in m.items()} for t,m in common.items()}
if len(sys.argv) < 2:
print('Give me a file to process please')
sys.exit(1)
print(sys.argv, len(sys.argv))
if sys.argv[1]=='mcp_merge.cfg':
print('Fixing mcp_merge.cfg')
with open('mcp_merge.cfg-new','w') as nf:
with open(sys.argv[1]) as f:
for line in f:
parts = line.split('#')
target = parts[1].strip()
newpart = parts[0][0]+rev_common['CL:'][target]+" #"+target+'\n'
nf.write(newpart)
sys.exit(0)
elif len(sys.argv)==2:
with open(sys.argv[1]+'-new','w') as nf:
with open(sys.argv[1]) as f:
for line in f:
parts = line.split('#')
if len(parts[1])<4:
nf.write(line)
continue
typ = parts[1][0:3]
if not rev_common.has_key(typ):
nf.write(line)
continue
name = parts[1][3:].strip()
action = parts[0].split(' ')
if name.endswith('/*'):
targ = rev_common['CL:']['net/minecraft/src/'+name[:-2]]
if typ == 'MD:':
wildcard = '.*()'
else:
wildcard = '.*'
newline = action[0]+' '+targ+wildcard+' #'+'#'.join(parts[1:])
nf.write(newline)
elif name.find('/<init>')>=0:
targ = rev_common['CL:']['net/minecraft/src/'+name[:name.find('/<init>')]]
args = '<init>('
armatch = ctorsigre.search(name).group(1)
for bit in ctorparamre.findall(armatch):
if len(bit[2])>0 and rev_common['CL:'].has_key(bit[2]):
cl = 'L'+rev_common['CL:'][bit[2]]+';'
else:
cl = bit[1]
args+=cl
args+=')V'
print(line.strip())
newline = action[0]+' '+targ+'.'+args+' #'+'#'.join(parts[1:])
print(newline.strip())
nf.write(newline)
else:
targ = rev_common[typ]['net/minecraft/src/'+name]
newline = action[0]+' '+targ.replace('/','.',1).replace(' ','',1)+' #'+'#'.join(parts[1:])
nf.write(newline)
else:
typ = sys.argv[1]
name = sys.argv[2]
name = name.replace('.','/')
if typ.startswith('-'):
print(rev_common[typ[1:]][name])
else:
print(common[typ][name])
def get_merged_info():
mcp_dir = os.path.join(os.getcwd(), '..')
joined = os.path.join(mcp_dir, 'conf', 'joined.srg')
values = {'PK:': {}, 'CL:': {}, 'FD:': {}, 'MD:': {}}
if not os.path.isfile(joined):
sys.path.append('install')
from fml import gen_merged_srg
values = gen_merged_srg(mcp_dir, None)
else:
with open(joined, 'r') as fh:
for line in fh:
pts = line.rstrip('\r\n').split(' ')
if pts[0] == 'MD:':
values[pts[0]][pts[1] + ' ' + pts[2]] = pts[3] + ' ' + pts[4]
else:
values[pts[0]][pts[1]] = pts[2]
return {t:{v.split(' ')[0]:k for k, v in m.items()} for t,m in values.items()}
def process_file(file, srg):
name = os.path.basename(file)
print 'Processing: ' + name
if name == 'mcp_merge.cfg':
with open(file + '-new','w') as nf:
with open(file) as f:
for line in f:
parts = line.split('#')
target = parts[1].strip()
newpart = '%s%s #%s\n' % (parts[0][0], srg['CL:'][target], target)
nf.write(newpart)
else:
with open(file + '-new', 'w') as nf:
with open(file) as f:
for line in f:
parts = line.split('#')
if len(parts[1]) < 4:
nf.write(line)
continue
typ = parts[1][0:3]
if not srg.has_key(typ):
nf.write(line)
continue
name = parts[1][3:].strip()
name = (name if name.startswith('net/minecraft/') else 'net/minecraft/src/' + name)
action = parts[0].split(' ')
if name.endswith('/*'):
targ = srg['CL:'][name[:-2]]
wildcard = ('.*()' if typ == 'MD:' else '.*')
newline = '%s %s%s #%s' % (action[0], targ, wildcard, '#'.join(parts[1:]))
nf.write(newline)
elif name.find('/<init>') >= 0:
targ = srg['CL:'][name[:name.find('/<init>')]]
args = '<init>('
armatch = ctorsigre.search(name).group(1)
for bit in ctorparamre.findall(armatch):
if len(bit[2]) > 0 and srg['CL:'].has_key(bit[2]):
cl = 'L' + srg['CL:'][bit[2]] + ';'
else:
cl = bit[1]
args += cl
args += ')V'
newline = ('%s %s.%s #%s' % (action[0], targ, args, '#'.join(parts[1:])))
nf.write(newline)
else:
targ = srg[typ][name]
args = targ.replace('/', '.', 1).replace(' ', '', 1)
newline = ('%s %s #%s' % (action[0], args, '#'.join(parts[1:])))
nf.write(newline)
def main():
srg = get_merged_info()
for arg in sys.argv:
path = os.path.join(os.getcwd(), arg)
if arg.endswith('_at.cfg') or arg == 'mcp_merge.cfg':
process_file(path, srg)
elif os.path.isdir(path):
for file in os.listdir(path):
if file.endswith('_at.cfg'):
process_file(os.path.join(path, file), srg)
if __name__ == '__main__':
main()