aorecomp

Anarchy Online classic in the browser

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


client/tests/effect_attachment.c (5930B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_36131C00(void), sub_361331E0(void), sub_36133580(void), sub_36133FC0(void);
      5 void sub_25112790(void), sub_3B004580(void);
      6 enum { pair = 0x50000000, endpoint = 0x50001000, owner = 0x50002000,
      7        visual = 0x50003000, mesh = 0x50004000, world = 0x50005000,
      8        output = 0x50006000 };
      9 static unsigned bone_calls, attractor_calls, skeleton_calls;
     10 static int bone_exists;
     11 
     12 static void find_owner(void) { g_eax = owner; g_esp += 4; }
     13 static void cast_owner(void) { g_eax = owner; g_esp += 4; }
     14 static void get_visual(void) { assert(g_ecx == owner); g_eax = visual; g_esp += 4; }
     15 static void get_world(void) { assert(g_ecx == mesh + 0x3c); g_eax = world; g_esp += 4; }
     16 static void update_orientation(void) { g_esp += 4; }
     17 static void update_skeleton(void) { ++skeleton_calls; g_esp += 4; }
     18 static void get_bone(void)
     19 {
     20     ++bone_calls;
     21     if (bone_exists) *(float *)ADDR(MEM32(g_esp + 8) + 0x34) = 3;
     22     g_eax = bone_exists;
     23     g_esp += 12;
     24 }
     25 static void get_attractor(void)
     26 {
     27     assert(g_ecx == mesh);
     28     ++attractor_calls;
     29     *(float *)ADDR(MEM32(g_esp + 8) + 0x34) = 2;
     30     g_eax = 1;
     31     g_esp += 12;
     32 }
     33 
     34 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     35 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
     36 recomp_func_t recomp_lookup(uint32_t address)
     37 {
     38     switch (address) {
     39     case 0x361331e0: return sub_361331E0;
     40     case 0x36133580: return sub_36133580;
     41     case 0x36133fc0: return sub_36133FC0;
     42     case 0x36133bd0: return update_orientation;
     43     case 0x3615fd86: return cast_owner;
     44     case 0x3615f7fc: return get_bone;
     45     case 0x3615f73c: return sub_25112790;
     46     case 0x2510f990: return update_skeleton;
     47     case 0x250f6a70: return get_attractor;
     48     case 0x70000000: return find_owner;
     49     case 0x70000004: return get_visual;
     50     case 0x70000008: return get_world;
     51     case 0x3b004580: return sub_3B004580;
     52     default: fprintf(stderr, "Unexpected attachment dependency: %08x\n", address); abort();
     53     }
     54 }
     55 
     56 static void arrange(void)
     57 {
     58     memset((void *)ADDR(0x50000000), 0, 0x10000);
     59     bone_calls = attractor_calls = skeleton_calls = 0;
     60     bone_exists = 0;
     61     MEM8(pair + 0x20) = 1;
     62     MEM32(pair + 0x28) = endpoint;
     63     MEM8(endpoint) = 1;
     64     MEM8(endpoint + 9) = 1;
     65     MEM32(endpoint + 4) = 4;
     66     MEM32(endpoint + 0x94) = 1006;
     67     MEM32(owner + 0x11c) = 0x100;
     68     MEM32(owner + 0xc8) = visual;
     69     MEM32(visual + 0x28) = mesh;
     70     const float transform[] = {0,0,-1,0, 0,1,0,0, 1,0,0,0, 64,14,75,1};
     71     memcpy((void *)ADDR(world), transform, sizeof(transform));
     72     MEM32(0x3616ff70) = 0x70000000;
     73     MEM32(0x3616ffe8) = 0x70000004;
     74     MEM32(0x3616f3a0) = 0x70000008;
     75     MEM32(0x36170198) = 0x3b004580;
     76     g_fs_base = 0x5000e000;
     77     MEM32(g_fs_base) = 0x12345678;
     78 }
     79 
     80 static void read_target(float y)
     81 {
     82     g_ecx = pair;
     83     g_esp = 0x5000ff00;
     84     MEM32(g_esp + 4) = output;
     85     g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444;
     86     g_fp_top = 8;
     87     sub_36131C00();
     88     const float expected[] = {64,y,75};
     89     assert(!memcmp((void *)ADDR(output), expected, sizeof(expected)));
     90     assert(g_eax == output && g_esp == 0x5000ff08);
     91     assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444);
     92     assert(g_fp_top == 8 && MEM32(g_fs_base) == 0x12345678);
     93     assert(MEM32(endpoint + 4) == 4);
     94 }
     95 
     96 static void inactive_mesh_uses_root_then_recovers(void)
     97 {
     98     /* The real attractor getter would return its distant placeholder. */
     99     arrange();
    100     MEM32(mesh + 0x284) = 7;
    101 
    102     /* Keep the endpoint valid at the actor root while inactive. */
    103     read_target(14);
    104     assert(bone_calls == 0 && attractor_calls == 0 && skeleton_calls == 0);
    105 
    106     /* Activation restores the authored attachment on the same pair. */
    107     MEM8(mesh + 0x288) = 1;
    108     read_target(16);
    109     assert(bone_calls == 1 && attractor_calls == 1 && skeleton_calls == 1);
    110 }
    111 
    112 static void throttled_skeleton_uses_root_then_recovers(void)
    113 {
    114     /* An active mesh cannot update its skeleton yet. */
    115     arrange();
    116     MEM8(mesh + 0x288) = 1;
    117     MEM32(mesh + 0x280) = 2;
    118 
    119     read_target(14);
    120     assert(bone_calls == 0 && attractor_calls == 0 && skeleton_calls == 0);
    121     MEM32(mesh + 0x280) = 0;
    122     read_target(16);
    123     assert(bone_calls == 1 && attractor_calls == 1 && skeleton_calls == 1);
    124 }
    125 
    126 static void unindexed_mesh_keeps_attachment(void)
    127 {
    128     arrange();
    129     MEM32(mesh + 0x284) = UINT32_MAX;
    130 
    131     read_target(16);
    132 
    133     assert(bone_calls == 1 && attractor_calls == 1 && skeleton_calls == 1);
    134 }
    135 
    136 static void ready_mesh_keeps_named_bone(void)
    137 {
    138     arrange();
    139     MEM8(mesh + 0x288) = 1;
    140     bone_exists = 1;
    141 
    142     read_target(17);
    143 
    144     assert(bone_calls == 1 && attractor_calls == 0 && skeleton_calls == 0);
    145 }
    146 
    147 static void unavailable_mesh_keeps_root_and_rejects_invalid_attachment(void)
    148 {
    149     /* An inactive mesh with a throttled skeleton. */
    150     arrange();
    151     MEM32(mesh + 0x280) = 2;
    152     MEM32(endpoint + 0x94) = 0;
    153 
    154     /* A root request does not require a skeleton. */
    155     read_target(14);
    156     MEM32(endpoint + 0x94) = 9999;
    157     g_ecx = endpoint;
    158     g_esp = 0x5000ff00;
    159     sub_361331E0();
    160 
    161     /* Unavailable bones do not make an unsupported attachment valid. */
    162     assert((g_eax & 255) == 0 && MEM32(endpoint + 4) == 0);
    163     assert(bone_calls == 0 && attractor_calls == 0 && skeleton_calls == 0);
    164     assert(g_esp == 0x5000ff04);
    165 }
    166 
    167 int main(void)
    168 {
    169     assert(guest_map("effect attachment fixture", 0x50000000, 0x10000));
    170     assert(guest_map("effect attachment imports", 0x36160000, 0x20000));
    171     assert(guest_map("effect attachment names", 0x362e0000, 0x10000));
    172     inactive_mesh_uses_root_then_recovers();
    173     throttled_skeleton_uses_root_then_recovers();
    174     unindexed_mesh_keeps_attachment();
    175     ready_mesh_keeps_named_bone();
    176     unavailable_mesh_keeps_root_and_rejects_invalid_attachment();
    177     puts("effect attachment: inactive/throttled roots, activation recovery and unindexed bones passed");
    178 }