aorecomp

Anarchy Online classic in the browser

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


client/tests/fling_result.c (5588B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_360B2CB0(void);
      5 static unsigned lookups, names, feedbacks, reads, writes, deaths, ammo_updates;
      6 static uint32_t missing_actor, feedback_category, death_reason;
      7 static uint32_t special_skill, weapon_slot;
      8 static int32_t ammunition;
      9 
     10 static void actor_lookup(void)
     11 {
     12     uint32_t identity = MEM32(g_esp + 4);
     13     assert(MEM32(identity) == 50000);
     14     uint32_t instance = MEM32(identity + 4);
     15     assert(instance == 1 || instance == 2);
     16     lookups++;
     17     g_eax = instance == missing_actor ? 0 : 0x50000000 + instance * 0x1000;
     18     g_esp += 4;
     19 }
     20 
     21 static void special_name(void)
     22 {
     23     assert(MEM32(g_esp + 4) == special_skill);
     24     names++;
     25     g_eax = 0x50000800;
     26     g_esp += 4;
     27 }
     28 
     29 static void feedback_interface(void)
     30 {
     31     g_eax = 0x50000900;
     32     g_esp += 4;
     33 }
     34 
     35 static void feedback(void)
     36 {
     37     assert(g_ecx == 0x50000900);
     38     assert(MEM32(g_esp + 4) == feedback_category);
     39     assert(MEM32(g_esp + 8) == 0x50002000);
     40     assert(MEM32(g_esp + 12) == 13);
     41     assert(MEM32(g_esp + 16) == 0x50001000);
     42     assert(MEM32(g_esp + 20) == 0x50000800);
     43     assert(MEM32(g_esp + 24) == 0 && MEM32(g_esp + 28) == 0);
     44     feedbacks++;
     45     g_esp += 32;
     46 }
     47 
     48 static void health_getter(void)
     49 {
     50     assert(g_ecx == 0x500020e4);
     51     assert(MEM32(g_esp + 4) == 27 && MEM32(g_esp + 8) == 2);
     52     reads++;
     53     g_eax = MEM32(0x50002300);
     54     g_esp += 12;
     55 }
     56 
     57 static void health_setter(void)
     58 {
     59     assert(g_ecx == 0x500020e4);
     60     assert(MEM32(g_esp + 4) == 27 && MEM32(g_esp + 8) == 87);
     61     writes++;
     62     MEM32(0x50002300) = MEM32(g_esp + 8);
     63     g_esp += 12;
     64 }
     65 
     66 static void target_death(void)
     67 {
     68     assert(g_ecx == 0x50002000 && MEM32(g_esp + 4) == death_reason);
     69     assert(MEM32(0x50002300) == 87 && writes == 1);
     70     deaths++;
     71     g_esp += 8;
     72 }
     73 
     74 static void weapon_ammunition(void)
     75 {
     76     assert(g_ecx == 0x50003000 && MEM32(g_esp + 4) == weapon_slot);
     77     assert((int32_t)MEM32(g_esp + 8) == ammunition);
     78     assert(MEM32(0x50002300) == 87 && writes == 1);
     79     assert(deaths == (death_reason != 0));
     80     ammo_updates++;
     81     g_esp += 12;
     82 }
     83 
     84 recomp_func_t recomp_lookup(uint32_t address)
     85 {
     86     switch (address) {
     87     case 0x3606da90: return actor_lookup;
     88     case 0x3603d360: return special_name;
     89     case 0x3601c590: return feedback_interface;
     90     case 0x3601d0b0: return feedback;
     91     case 0x50000400: return health_getter;
     92     case 0x50000404: return health_setter;
     93     case 0x36072340: return target_death;
     94     case 0x3607c0f0: return weapon_ammunition;
     95     default: fprintf(stderr, "unexpected special-result call: %08x\n", address); abort();
     96     }
     97 }
     98 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     99 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
    100 
    101 int main(void)
    102 {
    103     assert(guest_map("special attack result fixture", 0x50000000, 0x10000));
    104     const struct {
    105         unsigned attacker_local, target_local, missing;
    106         uint32_t feedback, death;
    107         int32_t ammo;
    108         uint32_t skill, slot;
    109     } cases[] = {
    110         {1, 0, 0, 50, 0, 3, 150, 6},
    111         {0, 1, 0, 48, 0, 3, 150, 6},
    112         {0, 0, 0, 49, 0, 3, 150, 6},
    113         {1, 0, 0, 50, 7, 3, 150, 6},
    114         {1, 0, 0, 50, 0, 0, 150, 6},
    115         {1, 0, 0, 50, 0, -1, 150, 6},
    116         {1, 0, 1, 50, 0, 3, 150, 6},
    117         {1, 0, 2, 50, 0, 3, 150, 6},
    118         {1, 0, 0, 50, 0, -1, 142, 0},
    119         {0, 1, 0, 48, 0, -1, 142, 0},
    120         {0, 0, 0, 49, 0, -1, 142, 0},
    121         {1, 0, 0, 50, 4, -1, 142, 6},
    122         {1, 0, 0, 50, 0, -1, 142, 8},
    123         {1, 0, 1, 50, 0, -1, 142, 0},
    124         {1, 0, 2, 50, 0, -1, 142, 0},
    125         {1, 0, 0, 50, 0, -1, 147, 6},
    126         {0, 1, 0, 48, 0, -1, 147, 6},
    127         {0, 0, 0, 49, 0, -1, 147, 6},
    128         {1, 0, 0, 50, 4, -1, 147, 6},
    129         {1, 0, 1, 50, 0, -1, 147, 6},
    130         {1, 0, 2, 50, 0, -1, 147, 6}
    131     };
    132     for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
    133         lookups = names = feedbacks = reads = writes = deaths = ammo_updates = 0;
    134         missing_actor = cases[i].missing;
    135         feedback_category = cases[i].feedback;
    136         death_reason = cases[i].death;
    137         ammunition = cases[i].ammo;
    138         special_skill = cases[i].skill;
    139         weapon_slot = cases[i].slot;
    140         MEM32(0x50000004) = MEM32(0x50000020) = 50000;
    141         MEM32(0x50000008) = 1;
    142         MEM32(0x50000024) = 2;
    143         MEM32(0x50000028) = weapon_slot;
    144         MEM32(0x5000002c) = 13;
    145         MEM32(0x50000030) = ammunition;
    146         MEM32(0x50000034) = special_skill;
    147         MEM32(0x50000038) = death_reason;
    148         MEM8(0x50001128) = cases[i].attacker_local;
    149         MEM8(0x50002128) = cases[i].target_local;
    150         MEM32(0x50001300) = MEM32(0x50002300) = 100;
    151         MEM32(0x5000116c) = 0x50003000;
    152         MEM32(0x500010e4) = MEM32(0x500020e4) = 0x50000100;
    153         MEM32(0x50000104) = 0x50000400;
    154         MEM32(0x50000108) = 0x50000404;
    155         g_esp = 0x5000ff00;
    156         g_ecx = 0x50000000;
    157 
    158         sub_360B2CB0();
    159 
    160         assert(g_eax == 0 && g_esp == 0x5000ff04);
    161         assert(lookups == 2 && MEM32(0x50001300) == 100);
    162         if (missing_actor) {
    163             assert(MEM32(0x50002300) == 100);
    164             assert(names == 0 && feedbacks == 0 && reads == 0 && writes == 0);
    165             assert(deaths == 0 && ammo_updates == 0);
    166         } else {
    167             assert(MEM32(0x50002300) == 87);
    168             assert(names == 1 && feedbacks == 1 && reads == 1 && writes == 1);
    169             assert(deaths == (death_reason != 0) && ammo_updates == 1);
    170         }
    171     }
    172     puts("native weapon special result: target damage, named feedback, slot/ammunition and death routing passed");
    173 }