aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/data/extract_ip_training.py (3602B)


      1 import hashlib
      2 import json
      3 import pathlib
      4 import struct
      5 
      6 import ao_database
      7 
      8 
      9 def main():
     10     client = pathlib.Path('anarchy-vanilla-14.9.1')
     11     assert (client / 'version.id').read_text().strip() == '14.9.1'
     12     database = ao_database.Database(client)
     13     records = []
     14 
     15     # kkr.dll FUN_100e9670 reads resource 1000206 in this stat order.
     16     order = [152, 137, 154, 153, 155, 156, 138, 142, 144, 100, 143, 93, 95,
     17              139, 166, 117, 140, 92, 97, 168, 123, 124, 118, 119, 149, 120,
     18              151, 167, 111, 148, 133, 134, 150, 114, 112, 116, 115, 113,
     19              121, 107, 106, 102, 104, 147, 105, 145, 146, 103, 101, 91,
     20              128, 132, 130, 127, 129, 122, 131, 90, 126, 125, 96, 94,
     21              165, 164, 135, 136, 163, 161, 159, 160, 162, 157, 158, 141,
     22              110, 109, 108]
     23     assert len(order) == len(set(order)) == 77
     24 
     25     def read(kind, identity, count):
     26         raw = database.read(kind, identity)
     27         words = struct.unpack('<' + 'i' * count, raw)
     28         records.append(dict(kind=kind, identity=identity, payload_hex=raw.hex(),
     29                             payload_sha256=hashlib.sha256(raw).hexdigest()))
     30         return words
     31 
     32     # All supported professions share these six title thresholds.
     33     starts = None
     34     for profession in range(1, 13):
     35         levels = list(read(1000200, profession, 24)[::4])
     36         assert starts is None or starts == levels
     37         starts = levels
     38     lines = ['# Generated from original 14.9.1 resources by extract_ip_training.py.',
     39              f'title_levels: {json.dumps(starts)}', 'breeds:']
     40 
     41     # FUN_100ef270: normal ability order; FUN_100dd9a0: STR, INT, AGI, SEN, STA, PSY.
     42     for breed in range(1, 5):
     43         bounds = read(1000027, breed, 13)
     44         assert bounds[0] == breed
     45         costs = read(1000210, breed, 6)
     46         costs = [costs[index] for index in [0, 2, 4, 1, 3, 5]]
     47         lines.extend([f'  {breed}:', f'    base: {json.dumps(bounds[1:7])}',
     48                       f'    maximum: {json.dumps(bounds[7:])}', f'    cost: {json.dumps(costs)}'])
     49 
     50     # Retain only the 69 trainable skills, excluding the eight armor classes.
     51     lines.append('professions:')
     52     for profession in range(1, 13):
     53         costs = dict(zip(order, read(1000206, profession, 77)))
     54         lines.append(f'  {profession}:')
     55         for stat in range(100, 169):
     56             assert 10 <= costs[stat] <= 50
     57             lines.append(f'    {stat}: {costs[stat]}')
     58 
     59     # FUN_100ee0e0 reads six title caps, followed by growth per level.
     60     lines.append('limits:')
     61     for category in range(1, 6):
     62         limits = read(1000209, category, 7)
     63         lines.extend([f'  {category}:', f'    titles: {json.dumps(limits[:6])}',
     64                       f'    per_level: {limits[6]}'])
     65     lines.append('weights:')
     66     for stat in range(100, 169):
     67         weights = read(1000204, stat, 6)
     68         assert all(0 <= weight <= 100 for weight in weights)
     69         assert sum(weights) == (110 if stat == 156 else 100)
     70         lines.append(f'  {stat}: {json.dumps(weights)}')
     71     database.close()
     72 
     73     # Keep source bytes and their hashes with the local research evidence.
     74     output = pathlib.Path('server/gamedata/ip_training.yaml')
     75     output.write_text('\n'.join(lines) + '\n')
     76     report = pathlib.Path('local/ip-training-research/resources.json')
     77     report.parent.mkdir(parents=True, exist_ok=True)
     78     report.write_text(json.dumps(dict(index_sha256=hashlib.sha256(database.index).hexdigest(),
     79                                       records=records), indent=2) + '\n')
     80     print(output)
     81     print(report)
     82 
     83 
     84 if __name__ == '__main__':
     85     main()