aorecomp

Anarchy Online classic in the browser

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


client/tests/mission_expiry_notification.c (3704B)


      1 #include "recomp_types.h"
      2 #include <assert.h>
      3 
      4 void sub_3606C060(void);
      5 enum { manager = 0x50000000, actor = 0x50000200, identity = 0x50000400,
      6        quest = 0x50000500, bus = 0x50000600 };
      7 static unsigned found, event, processed, removed, chats, completed, coordinates;
      8 
      9 static void find_quest(void)
     10 {
     11     assert(g_ecx == manager && MEM32(g_esp + 4) == identity);
     12     g_eax = found ? quest : 0;
     13     g_esp += 8;
     14 }
     15 
     16 static void process_event(void)
     17 {
     18     assert(g_ecx == quest && MEM32(g_esp + 4) == event);
     19     ++processed;
     20     g_esp += 8;
     21 }
     22 
     23 static void remove_quest(void)
     24 {
     25     assert(g_ecx == manager && MEM32(g_esp + 4) == quest);
     26     assert(MEM32(g_esp + 8) == (event == 1));
     27     ++removed;
     28     g_esp += 12;
     29 }
     30 
     31 static void format_text(void)
     32 {
     33     assert(MEM32(g_esp + 8) == (event == 1 ? 0x361c3778 : 0x361c3760));
     34     g_esp += 4;
     35 }
     36 
     37 static void get_bus(void) { g_eax = bus; g_esp += 4; }
     38 
     39 static void chat(void)
     40 {
     41     assert(g_ecx == bus && MEM32(g_esp + 8) == 0);
     42     ++chats;
     43     g_esp += 12;
     44 }
     45 
     46 static void completion_event(void)
     47 {
     48     assert(g_ecx == bus && MEM32(g_esp + 4) == 0x2c);
     49     assert(MEM32(g_esp + 8) == identity && MEM32(g_esp + 12) == 0);
     50     ++completed;
     51     g_esp += 16;
     52 }
     53 
     54 static void remove_coordinates(void)
     55 {
     56     const uint32_t modules[] = {0xe, 0x1c, 0x1f};
     57     assert(coordinates < 3);
     58     assert(g_ecx == bus && MEM32(g_esp + 4) == modules[coordinates]);
     59     assert(MEM32(g_esp + 8) == 0xaf && MEM32(g_esp + 12) == identity);
     60     assert(MEM32(identity) == 56003 && MEM32(identity + 4) == 17);
     61     ++coordinates;
     62     g_esp += 16;
     63 }
     64 
     65 recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; }
     66 recomp_func_t recomp_lookup_import(uint32_t address) { abort(); }
     67 recomp_func_t recomp_lookup(uint32_t address)
     68 {
     69     switch (address) {
     70     case 0x3606c1d0: return find_quest;
     71     case 0x3610def0: return process_event;
     72     case 0x3606be30: return remove_quest;
     73     case 1: return format_text;
     74     case 0x3601c590: case 2: return get_bus;
     75     case 0x3601c8c0: return chat;
     76     case 0x3601d080: return completion_event;
     77     case 3: return remove_coordinates;
     78     default: fprintf(stderr, "Unexpected expiry dependency: %08x\n", address); abort();
     79     }
     80 }
     81 
     82 int main(void)
     83 {
     84     assert(guest_map("expiry imports", 0x36160000, 0x10000));
     85     assert(guest_map("expiry objects and stack", 0x50000000, 0x10000));
     86     const struct { unsigned event, found, local; } cases[] = {
     87         {1, 1, 1}, {1, 1, 0}, {1, 0, 1}, {2, 1, 1}, {2, 1, 0}, {3, 1, 1},
     88     };
     89     for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) {
     90         event = cases[i].event;
     91         found = cases[i].found;
     92         processed = removed = chats = completed = coordinates = 0;
     93         MEM32(0x3616f25c) = 1;
     94         MEM32(0x3616f304) = 2;
     95         MEM32(0x3616f30c) = 3;
     96         MEM32(manager) = actor;
     97         MEM8(actor + 0x128) = cases[i].local;
     98         MEM32(identity) = 56003;
     99         MEM32(identity + 4) = 17;
    100         g_ecx = manager;
    101         g_esp = 0x5000ff00;
    102         MEM32(g_esp + 4) = identity;
    103         MEM32(g_esp + 8) = event;
    104         g_ebp = 123; g_ebx = 234; g_esi = 345; g_edi = 456;
    105         g_fp_top = 8;
    106 
    107         sub_3606C060();
    108 
    109         assert(processed == found);
    110         assert(removed == (found && event <= 2));
    111         assert(chats == (found && cases[i].local && event <= 2));
    112         assert(completed == (found && cases[i].local && event == 2));
    113         assert(coordinates == 3 * (found && cases[i].local && event == 1));
    114         assert(g_esp == 0x5000ff0c && g_ebp == 123);
    115         assert(g_ebx == 234 && g_esi == 345 && g_edi == 456 && g_fp_top == 8);
    116     }
    117     puts("mission expiry: local identity removal, original completion, unknown quests and guest ABI passed");
    118 }