Skip to content

Commit

Permalink
smt45 align hp mp
Browse files Browse the repository at this point in the history
  • Loading branch information
aqiu384 committed Jul 27, 2024
1 parent 84b7b64 commit c5b25c2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
20 changes: 17 additions & 3 deletions src/smt4/demon-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import struct
import json
import os
from math import floor

LINE_LEN = 0x94
START_OFFSET = 0x30
END_OFFSET = START_OFFSET + 1200 * LINE_LEN
OLD_RESISTS = ['phy', 'gun', 'fir', 'ice', 'ele', 'for', 'lig', 'dar']
OLD_AILMENTS = ['Bind', 'Panic', 'Poison', 'Sick', 'Sleep']
ALIGNS1 = ['???', 'Neutral', 'Light', 'Dark']
ALIGNS2 = ['???', 'Neutral', '???', '???', 'Law', 'Chaos']

RESIST_LVLS = {
0: '-',
Expand Down Expand Up @@ -44,6 +47,8 @@

with open('../../../megaten-fusion-tool/src/app/smt4/data/demon-data.json') as jsonfile:
OLD_DEMONS = json.load(jsonfile)
with open('../../../megaten-fusion-tool/src/app/smt4/data/alignments.json') as jsonfile:
RACE_ALIGNS = json.load(jsonfile)
with open('data/demon-ids.tsv') as tsvfile:
DEMON_IDS = ['BLANK\t0'] + [x.strip() for x in tsvfile]
with open('data/skill-ids.tsv') as tsvfile:
Expand Down Expand Up @@ -98,17 +103,26 @@ def check_demon_data(fname, start_offset, end_offset, line_len):

race_id = struct.unpack('<1B', line[0x02:0x03])[0]
dlvl = struct.unpack('<1B', line[0x03:0x04])[0]
stats = struct.unpack('<5H', line[0x1A:0x24])
align1, align2 = struct.unpack('<2B', line[0x04:0x06])
stats = struct.unpack('<2H2B5H', line[0x14:0x24])
innate = struct.unpack('<8H', line[0x3C:0x4C])
learned = struct.unpack('<16H', line[0x4C:0x6C])
full_resists = struct.unpack('<8H', line[0x6C:0x7C])
full_ailments = struct.unpack('<8H', line[0x7C:0x8C])

race = RACE_IDS[race_id]
align = f"{ALIGNS1[align1]}-{ALIGNS2[align2]}"
hp = stats[0] + dlvl * stats[2]
mp = floor(0.45 * (stats[1] + dlvl * stats[3]))
new_stats = [hp, mp] + list(stats[4:])

printif_notequal(dname, 'align', RACE_ALIGNS.get(dname, RACE_ALIGNS[race]), align)
printif_notequal(dname, 'd_id', d_id, new_d_id)
printif_notequal(dname, 'race', demon['race'], RACE_IDS[race_id])
printif_notequal(dname, 'race', demon['race'], race)
printif_notequal(dname, 'lvl', demon['lvl'], dlvl)
printif_notequal(dname, 'stats', demon['stats'][2:], list(stats))
printif_notequal(dname, 'stats', demon['stats'], new_stats)

demon['stats'] = list(stats)
resists = ''.join(RESIST_LVLS[x >> 10] for x in full_resists)
ailments = ''.join(RESIST_LVLS[full_ailments[x] >> 10] for x in AILMENT_ORDER)
res_mods = [x & 0x3FF for x in full_resists]
Expand Down
21 changes: 18 additions & 3 deletions src/smt4f/demon-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
import struct
import json
import os
from math import floor

LINE_LEN = 0xB4
START_OFFSET = 0x30
END_OFFSET = START_OFFSET + 1200 * LINE_LEN
OLD_AILMENTS = ['Bind', 'Charm', 'Daze', 'Mute', 'Panic', 'Poison', 'Sick', 'Sleep']
ALIGNS1 = ['???', 'Neutral', 'Light', 'Dark']
ALIGNS2 = ['???', 'Neutral', '???', '???', 'Law', 'Chaos']
MP_TYPES = [0, 0, 0, 0, 1, 0, 0, 3, 0, 0, 0, 4, 5]

RESIST_LVLS = {
0: '-',
Expand Down Expand Up @@ -48,6 +52,8 @@

with open('../../../megaten-fusion-tool/src/app/smt4f/data/demon-data.json') as jsonfile:
OLD_DEMONS = json.load(jsonfile)
with open('../../../megaten-fusion-tool/src/app/smt4/data/alignments.json') as jsonfile:
RACE_ALIGNS = json.load(jsonfile)
with open('data/demon-ids.tsv') as tsvfile:
DEMON_IDS = ['BLANK\t0'] + [x.strip() for x in tsvfile]
with open('data/skill-ids.tsv') as tsvfile:
Expand Down Expand Up @@ -102,18 +108,27 @@ def check_demon_data(fname, start_offset, end_offset, line_len):

race_id = struct.unpack('<1L', line[0x02:0x06])[0]
dlvl = struct.unpack('<1H', line[0x06:0x08])[0]
stats = struct.unpack('<5H', line[0x1E:0x28])
align1, align2 = struct.unpack('<2B', line[0x08:0x0A])
stats = struct.unpack('<2H2B5H', line[0x18:0x28])
innate = struct.unpack('<8H', line[0x40:0x50])
learned = struct.unpack('<16H', line[0x50:0x70])
full_resists = struct.unpack('<8H', line[0x70:0x80])
full_ailments = struct.unpack('<13H', line[0x80:0x9A])
full_affinities = struct.unpack('<16b', line[0xA2:0xB2])

race = RACE_IDS[race_id]
align = f"{ALIGNS1[align1]}-{ALIGNS2[align2]}"
hp = stats[0] + (dlvl - 1) * stats[2]
mp = stats[1] + (dlvl - 1) * MP_TYPES[stats[3]]
new_stats = [hp, mp] + list(stats[4:])

printif_notequal(dname, 'align', RACE_ALIGNS.get(dname, RACE_ALIGNS[race]), align)
printif_notequal(dname, 'd_id', d_id, new_d_id)
printif_notequal(dname, 'race', demon['race'], RACE_IDS[race_id])
printif_notequal(dname, 'race', demon['race'], race)
printif_notequal(dname, 'lvl', demon['lvl'], dlvl)
printif_notequal(dname, 'stats', demon['stats'][2:], list(stats))
printif_notequal(dname, 'stats', demon['stats'], new_stats)

demon['stats'] = list(stats)
resists = ''.join(RESIST_LVLS[x >> 10] for x in full_resists)
ailments = ''.join(RESIST_LVLS[full_ailments[x] >> 10] for x in AILMENT_ORDER)
affinities = list(full_affinities[:8]) + [full_affinities[x] for x in (8, 12, 10, 14)]
Expand Down
10 changes: 9 additions & 1 deletion src/smt5/demons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json

INNATES = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]
ALIGNS1 = ['???', 'Neutral', 'Light', 'Dark']
ALIGNS2 = ['???', 'Neutral', '???', '???', 'Law', 'Chaos']

RESIST_LVLS = {
0: 'n',
Expand Down Expand Up @@ -87,6 +89,8 @@ def load_id_file(fname):

with open('Content/Blueprints/Gamedata/BinTable/Devil/NKMBaseTable.bin', 'rb') as binfile:
NEW_DEMONS = binfile.read()
with open('../../../megaten-fusion-tool/src/app/smt5/data/alignments.json') as jsonfile:
RACE_ALIGNS = json.load(jsonfile)

def save_ordered_demons(demons, fname):
for entry in demons.values():
Expand Down Expand Up @@ -114,7 +118,8 @@ def printif_notequal(dname, field, lhs, rhs):
dname = DEMON_IDS[d_id]

d_id2, order_comp, race = struct.unpack('<LLB', line[0x00:0x09])
unk_race = struct.unpack('<7BL', line[0x09:0x14])
unk_race = struct.unpack('<6B', line[0x09:0x0F])
align1, align2 = struct.unpack('<BL', line[0x0F:0x14])
lvl, in_comp = struct.unpack('<LB', line[0x14:0x19])
magic_comp = struct.unpack('<7B4L', line[0x19:0x30])
race = RACE_IDS[race]
Expand Down Expand Up @@ -146,6 +151,9 @@ def printif_notequal(dname, field, lhs, rhs):
if learned[i + 1] > 0:
skills[SKILL_IDS[learned[i + 1]]] = learned[i]

align = f"{ALIGNS1[align1]}-{ALIGNS2[align2]}"

printif_notequal(dname, 'align', RACE_ALIGNS.get(dname, RACE_ALIGNS[race]), align)
printif_notequal(dname, 'd_id2', d_id, d_id2)
# printif_notequal(dname, 'magic_comp', MAGIC_COMP, magic_comp)

Expand Down
10 changes: 9 additions & 1 deletion src/smt5v/demons.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import json

INNATES = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]
ALIGNS1 = ['???', 'Neutral', 'Light', 'Dark']
ALIGNS2 = ['???', 'Neutral', '???', '???', 'Law', 'Chaos']

RESIST_LVLS = {
0: 'n',
Expand Down Expand Up @@ -92,6 +94,8 @@ def load_id_file(fname):

with open('Content/Blueprints/Gamedata/BinTable/Devil/NKMBaseTable.bin', 'rb') as binfile:
NEW_DEMONS = binfile.read()
with open('../../../megaten-fusion-tool/src/app/smt5/data/alignments.json') as jsonfile:
RACE_ALIGNS = json.load(jsonfile)

def save_ordered_demons(demons, fname):
for entry in demons.values():
Expand Down Expand Up @@ -119,7 +123,8 @@ def printif_notequal(dname, field, lhs, rhs):
dname = DEMON_IDS[d_id]

d_id2, order_comp, race = struct.unpack('<LLB', line[0x00:0x09])
unk_race = struct.unpack('<7BL', line[0x09:0x14])
unk_race = struct.unpack('<6B', line[0x09:0x0F])
align1, align2 = struct.unpack('<BL', line[0x0F:0x14])
lvl, in_comp = struct.unpack('<LB', line[0x14:0x19])
magic_comp = struct.unpack('<7B4L', line[0x19:0x30])
race = RACE_IDS[race]
Expand Down Expand Up @@ -154,6 +159,9 @@ def printif_notequal(dname, field, lhs, rhs):
if learned[i + 1] > 0:
skills[SKILL_IDS[learned[i + 1]]] = learned[i]

align = f"{ALIGNS1[align1]}-{ALIGNS2[align2]}"

printif_notequal(dname, 'align', RACE_ALIGNS.get(dname, RACE_ALIGNS[race]), align)
printif_notequal(dname, 'd_id2', d_id, d_id2)
# printif_notequal(dname, 'magic_comp', MAGIC_COMP, magic_comp)

Expand Down

0 comments on commit c5b25c2

Please sign in to comment.