From bd35573dad5dfe044fba449afc1572b6ea5d5c73 Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Sat, 10 Oct 2020 21:06:02 +0100 Subject: [PATCH] evt_halt and evt_if_str_equal --- .gitignore | 3 ++- evtmgr.c | 25 ++++++++++++++++++++++--- evtmgr.h | 3 ++- evtmgr_cmd.c | 24 ++++++++++++++++++++++++ evtmgr_cmd.h | 13 ++++++------- loclessdiff.py | 2 +- string.h | 1 + 7 files changed, 58 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 5196523..eb71674 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode help.txt ldhelp.txt -*.s \ No newline at end of file +*.s +*.o \ No newline at end of file diff --git a/evtmgr.c b/evtmgr.c index d164420..ac2eddb 100644 --- a/evtmgr.c +++ b/evtmgr.c @@ -7,6 +7,7 @@ #include #include "evtmgr.h" +#include "evtmgr_cmd.h" #include "memory.h" #include "somewhere.h" #include "mariost.h" @@ -156,8 +157,7 @@ EvtEntry * evtEntry(int * script, uint8_t priority, uint8_t flags) { entry->unknown_0x160 = 0.0f; entry->unknown_0x164 = -1; entry->unknown_0x168 = 0; - entry->unknown_0x4 = 0; - entry->unknown_0x0 = 0; + entry->lifetime = 0; for (int j = 0; j < 16; j++) { entry->lw[i] = 0; } @@ -197,6 +197,7 @@ EvtEntry * evtEntry(int * script, uint8_t priority, uint8_t flags) { // unfinished void evtmgrMain() { EvtWork * wp = evtGetWork(); + runMainF = 1; int64_t timeDif = gp->time - wp->time; if (timeDif < 0) { timeDif = 0; @@ -209,8 +210,26 @@ void evtmgrMain() { wp->time = gp->time; make_pri_table(); for (int i = 0; i < priTblNum; i++) { - + EvtEntry * entry = &wp->entries[priTbl[i]]; + if (entry->flags & 1 && entry->id == priIdTbl[i] && entry->flags & 0x92) { + if (entry->flags & 4) { + entry->lifetime += ms; + } + entry->unknown_0x160 += 1.0f; + int shouldBreak = 0; + while (entry->unknown_0x160 >= 1.0f) { + entry->unknown_0x160 -= 1.0f; + int ret = evtmgrCmd(entry); + if (ret == 1) { + shouldBreak = 1; + break; + } + if (ret == -1) break; + } + if (shouldBreak) break; + } } + runMainF = 0; } void evtDelete(EvtEntry * entry) { diff --git a/evtmgr.h b/evtmgr.h index ce42c53..b83382f 100644 --- a/evtmgr.h +++ b/evtmgr.h @@ -29,7 +29,8 @@ typedef struct _EvtEntry { struct _EvtEntry * childEntry; struct _EvtEntry * brotherEntry; int unknown_0x74; - char unknown_0x78[0x94 - 0x78]; + int64_t unknown_0x78; + char unknown_0x80[0x94 - 0x80]; user_func * userFunc; // Function set & called by the user_func opcode int lw[16]; uint32_t lf[3]; diff --git a/evtmgr_cmd.c b/evtmgr_cmd.c index 713b495..1904fe6 100644 --- a/evtmgr_cmd.c +++ b/evtmgr_cmd.c @@ -1,5 +1,6 @@ #include #include +#include #include "evtmgr_cmd.h" #include "evtmgr.h" @@ -129,6 +130,29 @@ EVT_CMD_FN(wait_frm) { } } +// EVT_CMD_FN(wait_msec) + +EVT_CMD_FN(halt) { + return evtGetValue(entry, *entry->pCurData) ? 0 : EVT_CONTINUE; +} + +EVT_CMD_FN(if_str_equal) { + int * p = entry->pCurData; + char * s1 = (char *) evtGetValue(entry, p[0]); + char * s2 = (char *) evtGetValue(entry, p[1]); + if (s1 == NULL) { + s1 = ""; + } + if (s2 == NULL) { + s2 = ""; + } + if (strcmp(s1, s2)) { + entry->pCurInstruction = evtSearchElse(entry); + return EVT_CONTINUE; + } + return EVT_CONTINUE; +} + // a lot EVT_CMD_FN(debug_put_msg) { diff --git a/evtmgr_cmd.h b/evtmgr_cmd.h index 4cb5e97..77e12c3 100644 --- a/evtmgr_cmd.h +++ b/evtmgr_cmd.h @@ -44,9 +44,9 @@ EVT_CMD_FN(while); EVT_CMD_FN(do_break); EVT_CMD_FN(do_continue); EVT_CMD_FN(wait_frm); - +EVT_CMD_FN(wait_msec); +EVT_CMD_FN(halt); /* - 0002f0d4 0000d0 800346b4 4 evt_wait_msec evtmgr_cmd.o UNUSED 00003c ........ evt_halt evtmgr_cmd.o 0002efe4 0000f0 800345c4 4 evt_if_str_equal evtmgr_cmd.o 0002eef4 0000f0 800344d4 4 evt_if_str_not_equal evtmgr_cmd.o @@ -157,10 +157,7 @@ EVT_CMD_FN(debug_name); EVT_CMD_FN(debug_rem); EVT_CMD_FN(debug_bp); -/* - 0002af10 0013b0 800304f0 4 evtmgrCmd evtmgr_cmd.o -*/ - +int evtmgrCmd(EvtEntry * entry); int evtGetValue(EvtEntry * entry, int data); /* @@ -173,7 +170,9 @@ float evtGetFloat(EvtEntry * entry, int data); /* 00029d14 000384 8002f2f4 4 evtSetFloat evtmgr_cmd.o UNUSED 00005c ........ evtSearchLabel evtmgr_cmd.o - UNUSED 00006c ........ evtSearchElse evtmgr_cmd.o +*/ +int * evtSearchElse(EvtEntry * entry); +/* UNUSED 000064 ........ evtSearchEndIf evtmgr_cmd.o UNUSED 00005c ........ evtSearchEndSwitch evtmgr_cmd.o UNUSED 000080 ........ evtSearchCase evtmgr_cmd.o diff --git a/loclessdiff.py b/loclessdiff.py index 9d6cca4..d44f79f 100644 --- a/loclessdiff.py +++ b/loclessdiff.py @@ -30,7 +30,7 @@ for line1 in f1.readlines(): line2 = noComment(noAddress(noNewline(f2.readline()))) if line1 != line2: print(Fore.CYAN + f"[{n:04}]: {line1}") - print(Fore.YELLOW + f"[{n:04}]: {line2}") + print(Fore.YELLOW + f"{{{n:04}}}: {line2}") n += 1 f1.close() f2.close() \ No newline at end of file diff --git a/string.h b/string.h index 634d838..78df01c 100644 --- a/string.h +++ b/string.h @@ -4,5 +4,6 @@ #include void * memset(void * ptr, int value, size_t num); // 80004104 +int strcmp(char * s1, char * s2); // 8025ea78 #endif \ No newline at end of file