#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import ctypes
import struct
import math
# prs_decompress is a naive python port of Fuzziqer Software's PRS Utility
# see http://www.fuzziqersoftware.com/projects.html for details
def prs_decompress(src):
dest = bytearray(prs_decompress_size(src))
r3 = 0
r5 = 0
bitpos = 9
sourceptr = 0
destptr = 0
currentbyte = src[0]
flag = 0
offset = 0
sourceptr += 1
while True:
bitpos -= 1
if bitpos == 0:
currentbyte = src[sourceptr]
bitpos = 8
sourceptr += 1
flag = currentbyte & 1
currentbyte = currentbyte >> 1
if flag != 0:
dest[destptr] = src[sourceptr]
sourceptr += 1
destptr += 1
continue
bitpos -= 1
if bitpos == 0:
currentbyte = src[sourceptr]
bitpos = 8
sourceptr += 1
flag = currentbyte & 1
currentbyte = currentbyte >> 1
if flag != 0:
r3 = src[sourceptr] & 0xFF
offset = ((src[sourceptr+1] & 0xFF) << 8) | r3
sourceptr += 2
if offset == 0:
return dest
r3 = r3 & 0x00000007
r5 = ctypes.c_int32((offset >> 3) | 0xFFFFE000).value
if r3 == 0:
flag = 0
r3 = src[sourceptr] & 0xFF
sourceptr += 1
r3 += 1
else:
r3 += 2
r5 += destptr
else:
r3 = 0
for x in range(2):
bitpos -= 1
if bitpos == 0:
currentbyte = src[sourceptr]
bitpos = 8
sourceptr += 1
flag = currentbyte & 1
currentbyte = currentbyte >> 1
offset = r3 << 1
r3 = offset | flag
offset = ctypes.c_int32(src[sourceptr] | 0xFFFFFF00).value
r3 += 2
sourceptr += 1
r5 = offset + destptr
if r3 == 0:
continue
t = r3
for x in range(t):
dest[destptr] = dest[r5]
r5 += 1
r3 += 1
destptr += 1
def prs_decompress_size(src):
r3 = 0
bitpos = 9
sourceptr = 0
destptr = 0
currentbyte = src[0]
flag = 0
offset = 0
sourceptr += 1
while True:
bitpos -= 1
if bitpos == 0:
currentbyte = src[sourceptr]
bitpos = 8
sourceptr += 1
flag = currentbyte & 1
currentbyte = currentbyte >> 1
if flag != 0:
sourceptr += 1
destptr += 1
continue
bitpos -= 1
if bitpos == 0:
currentbyte = src[sourceptr]
bitpos = 8
sourceptr += 1
flag = currentbyte & 1
currentbyte = currentbyte >> 1
if flag != 0:
r3 = src[sourceptr]
offset = (src[sourceptr+1] << 8) | r3
sourceptr += 2
if offset == 0:
return destptr
r3 = r3 & 0x00000007
if r3 == 0:
r3 = src[sourceptr]
sourceptr += 1
r3 += 1
else:
r3 += 2
else:
r3 = 0
for x in range(2):
bitpos -= 1
if bitpos == 0:
currentbyte = src[sourceptr]
bitpos = 8
sourceptr += 1
flag = currentbyte & 1
currentbyte = currentbyte >> 1
offset = r3 << 1
r3 = offset | flag
offset = ctypes.c_int32(src[sourceptr] | 0xFFFFFF00).value
r3 += 2
sourceptr += 1
if r3 == 0:
continue
t = r3
for x in range(t):
r3 += 1
destptr += 1
def gen_level_data(data):
char_data = {}
class_name = ('HUmar', 'HUnewearl', 'HUcast',
'RAmar', 'RAcast', 'RAcaseal',
'FOmarl', 'FOnewm', 'FOnewearl',
'HUcaseal', 'FOmar', 'RAmarl')
for i in range(12):
rawdata = []
minstat = () # ATP, DFP, MST, ATA, EVP, LCK
maxstat = ()
mat = ()
k = class_name[i]
if k == 'HUmar':
minstat = (10, 0, 0, 650, 0, 0)
maxstat = (1397, 579, 732, 2000, 756, 100)
mat = (250, 125, 125)
elif k == 'HUnewearl':
minstat = (10, 0, 0, 610, 0, 0)
maxstat = (1237, 589, 1177, 1990, 811, 100)
mat = (150, 125, 125)
elif k == 'HUcast':
minstat = (10, 0, 0, 610, 0, 0)
maxstat = (1639, 601, 0, 1910, 660, 100)
mat = (150, 125, 0)
elif k == 'HUcaseal':
minstat = (10, 0, 0, 680, 0, 0)
maxstat = (1301, 525, 0, 2180, 877, 100)
mat = (150, 125, 0)
elif k == 'RAmar':
minstat = (5, 0, 0, 760, 0, 0)
maxstat = (1260, 515, 665, 2490, 715, 100)
mat = (250, 125, 125)
elif k == 'RAmarl':
minstat = (5, 0, 0, 680, 0, 0)
maxstat = (1145, 577, 1031, 2410, 900, 100)
mat = (250, 125, 125)
elif k == 'RAcast':
minstat = (5, 0, 0, 710, 0, 0)
maxstat = (1350, 606, 0, 2240, 699, 100)
mat = (150, 125, 0)
elif k == 'RAcaseal':
minstat = (5, 0, 0, 730, 0, 0)
maxstat = (1175, 688, 0, 2310, 787, 100)
mat = (150, 125, 0)
elif k == 'FOmar':
minstat = (3, 0, 0, 620, 0, 0)
maxstat = (1002, 470, 1340, 1630, 651, 100)
mat = (250, 125, 125)
elif k == 'FOmarl':
minstat = (3, 0, 0, 620, 0, 0)
maxstat = (872, 498, 1284, 1700, 588, 100)
mat = (250, 125, 125)
elif k == 'FOnewm':
minstat = (3, 0, 0, 600, 0, 0)
maxstat = (814, 463, 1500, 1800, 679, 100)
mat = (150, 125, 125)
elif k == 'FOnewearl':
minstat = (3, 0, 0, 600, 0, 0)
maxstat = (585, 390, 1750, 1860, 883, 100)
mat = (150, 125, 125)
(atp, mst, evp, hp, dfp, ata, lck) = struct.unpack_from('HHHHHHH', data, i*14)
rawdata.append([atp, dfp, mst, ata, evp, lck, hp]) # level 1
for j in range(199):
(d_atp, d_mst, d_evp, d_hp, d_dfp, d_ata) = struct.unpack_from('BBBBBB', data, 0xE4 + i*200*12 + j*12)
atp += d_atp
mst += d_mst
evp += d_evp
hp += d_hp + 1
dfp += d_dfp
ata += d_ata
rawdata.append((atp, dfp, mst, ata, evp, lck, hp))
char_data[k] = {
'min': minstat,
'max': maxstat,
'mat': mat,
'raw': rawdata,
'data': [None, ] * 200,
}
for k in char_data:
for i in range(len(char_data[k]['raw'])):
(atp, dfp, mst, ata, evp, lck, hp) = char_data[k]['raw'][i]
if k == 'HUmar':
atp += 10
ata += 650
hp *= 2
elif k == 'HUnewearl':
atp += 10
ata += 610
hp *= 2
elif k == 'HUcast':
atp += 10
ata += 610
hp *= 2
elif k == 'HUcaseal':
atp += 10
ata += 680
hp *= 2
elif k == 'RAmar':
atp += 5
ata += 760
hp *= 1.85
elif k == 'RAmarl':
atp += 5
ata += 680
hp *= 1.85
elif k == 'RAcast':
atp += 5
ata += 710
hp *= 1.85
elif k == 'RAcaseal':
atp += 5
ata += 730
hp *= 1.85
elif k == 'FOmar':
atp += 3
ata += 620
hp *= 1.45
elif k == 'FOmarl':
atp += 3
ata += 620
hp *= 1.45
elif k == 'FOnewm':
atp += 3
ata += 600
hp *= 1.45
elif k == 'FOnewearl':
atp += 3
ata += 600
hp *= 1.45
hp = math.floor(hp)
char_data[k]['data'][i] = (atp, dfp, mst, ata, evp, lck, hp)
return char_data
if __name__ == '__main__':
with open('PlyLevelTbl.prs', 'rb') as f:
data = f.read()
data = prs_decompress(data)
lv_data = gen_level_data(data)
buf = []
buf.append('function CharData() {')
for k in ('HUmar', 'HUnewearl', 'HUcast', 'HUcaseal',
'RAmar', 'RAmarl', 'RAcast', 'RAcaseal',
'FOmar', 'FOmarl', 'FOnewm', 'FOnewearl'):
buf.append(' this.%s = {' % k)
buf.append(' // stat, hp, tp')
buf.append(' mat : [%s],' % ', '.join(map(str, lv_data[k]['mat'])))
buf.append(' data : [')
buf.append(' // min [ATP, DFP, MST, ATA, EVP, LCK]')
buf.append(' [%s],' % ', '.join(map(str, lv_data[k]['min'])))
buf.append(' // 1~200 [ATP, DFP, MST, ATA, EVP, LCK, HP]')
for l in range(len(lv_data[k]['data'])):
buf.append(' [%s], // %d' % (', '.join(map(str, lv_data[k]['data'][l])), l + 1))
buf.append(' // max [ATP, DFP, MST, ATA, EVP, LCK]')
buf.append(' [%s],' % ', '.join(map(str, lv_data[k]['max'])))
buf.append(' ],')
buf.append(' };')
buf.append('};')
with open('chardata.js', 'w') as out:
out.write('\n'.join(buf))