-
Notifications
You must be signed in to change notification settings - Fork 34
Misc script
kmalone86 edited this page Oct 18, 2019
·
3 revisions
#!/usr/bin/python3
import sys
import collections
from collections import OrderedDict
import binascii
inFileName = "skill_player.db"
numGet = 1
argKey = []
cmdIndex = 1
while cmdIndex < len(sys.argv):
argKey.append(hex(int(sys.argv[cmdIndex], 16)))
cmdIndex = cmdIndex + 1
print('key='+str(argKey))
def runDecode(fileName, key):
i = 0
decode = []
with open(fileName, 'rb') as file:
while True:
ch = file.read(1).hex()
if not ch:
break
ch = hex(int(ch,16) ^ int(key[i],16))
ch = int(ch, 0)
if ch >= 128:
decode = []
#print("Invalid character")
break
decode.append(chr(ch))
i = i + 1
if i >= len(key):
i = 0
if decode != []:
print('--------------------')
print('Key='+str(key))
print('--------------------')
print(str(decode))
str1 = ""
print(str1.join(decode))
print('--------------------')
print('Key='+str(key))
print('--------------------')
return 1
return 0
def nextKey(key, length):
if len(key) == 0:
key.append('00')
elif key[length-1] == 'ff':
key[length-1] = '00'
if length == 1:
key.append('00')
else:
key = nextKey(key, length-1)
else:
key[length-1] = format(int(key[length-1], 16)+1, 'x')
if len(key[length-1]) == 1:
key[length-1] = '0'+key[length-1]
return key
if not argKey:
argKey = nextKey(argKey, len(argKey))
count = 0
found = 0
while found == 0:
count = count +1
if count >= 1000000:
print('Currently at '+str(argKey))
count = 0
ret = runDecode(inFileName, argKey)
if ret == 1:
break
if numGet != 0:
if numGet == 1:
break
numGet = numGet - 1
argKey = nextKey(argKey, len(argKey))
if len(argKey) > 64:
print("Too Long")
break
#while len(argKey) == 2:
# argKey = nextKey(argKey, len(argKey))
# print( str(argKey) )
#key = []
#key = nextKey(
#print( str(nextKey(['ff', 'ff'], 2)) )
#!/usr/bin/python3
import sys
import json
import collections
from collections import OrderedDict
import os.path
import ast
import itertools
fileName = sys.argv[1]
def writeJson(outputFile, jsonData):
with open(outputFile, 'w') as outfile:
json.dump(jsonData, outfile, indent=4, separators=(',', ': '), ensure_ascii=False)
outfile.write("\n")
def main(fileName):
with open(fileName, 'r') as infile:
inJson = json.load(infile, object_pairs_hook=OrderedDict)
baseDe = inJson['skillDescription']['base']
maxDe = inJson['skillDescription']['max']
bsplit = baseDe.split(' ')
msplit = maxDe.split(' ')
if len(bsplit) != len(msplit):
print(filename+' num words don\'t match. Manual fix needed.')
return
newStr = ''
i = 0
varId = 1
values = {}
for word in bsplit:
if word != msplit[i]:
one = word.rstrip('.')
two = msplit[i].rstrip('.')
addPeriod = False
if one != word:
addPeriod = True
refer = 'ps_refer'
if varId != 1:
refer+=str(varId)
newStr+=' {per_s('+refer+')}'
if one.endswith('%'):
newStr+='%'
one = one.rstrip('%')
two = two.rstrip('%')
if addPeriod:
newStr+='.'
try:
values[refer] = { 'base': float(one), 'max': float(two) }
except:
values[refer] = { 'base': one, 'max': two }
varId+=1
#newStr+=' '+one+' ('+two+')'
#if one != word:
# newStr+='.'
else:
newStr+=' '+word
i+=1
newStr = newStr.lstrip(' ')
#print(newStr)
inJson['skillDescription'] = [newStr]
newJson = OrderedDict()
for item in inJson:
if item == 'stats':
newJson['skillVal'] = values
newJson[item] = inJson[item]
#print(inJson)
writeJson(fileName, newJson)
def getAllJsonFiles(dir):
allFiles = os.listdir(dir)
jsonFiles = []
for fileName in allFiles:
if fileName.endswith('.json'):
if 'TEMPLATE'.lower() in fileName.lower():
continue
jsonFiles = jsonFiles + [fileName]
return jsonFiles
if fileName == 'all':
fileList = getAllJsonFiles('.')
else:
if os.path.isfile(fileName) == False:
print(fileName+' is not a file.')
quit()
fileList = [fileName]
# Walk through all files and act
for fileName in fileList:
main(fileName)