Merge pull request #62 from gamemasterplc/main

Decompile flag code
This commit is contained in:
gamemasterplc 2023-12-28 07:14:10 -06:00 committed by GitHub
commit ce13446a8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 77 additions and 23 deletions

View file

@ -276,8 +276,8 @@ config.libs = [
Object(NonMatching, "game/THPDraw.c"),
Object(NonMatching, "game/thpmain.c"),
Object(NonMatching, "game/objsub.c"),
Object(NonMatching, "game/flag.c"),
Object(NonMatching, "game/saveload.c"),
Object(Matching, "game/flag.c"),
Object(Matching, "game/saveload.c"),
Object(NonMatching, "game/sreset.c"),
Object(NonMatching, "game/board/main.c"),
Object(NonMatching, "game/board/board.c"),

View file

@ -14,8 +14,8 @@ typedef struct player_config {
typedef struct system_state {
/* 0x00 */ struct {
u16 story : 1;
u16 team : 1;
u8 story : 1;
u8 team : 1;
u8 : 7;
};
/* 0x02 */ struct {
@ -46,8 +46,9 @@ typedef struct system_state {
/* 0x32 */ char unk_32[0x2];
/* 0x34 */ u16 mg_next;
/* 0x36 */ s16 mg_next_extra;
/* 0x38 */ u8 flag[3][16];
/* 0x68 */ u8 unk_68[0x74];
/* 0x38 */ s16 unk_38;
/* 0x3A */ u8 flag[3][16];
/* 0x6A */ u8 unk_6A[0x72];
} SystemState; //8018fcf8, sizeof 0xDC
typedef struct player_state {

View file

@ -43,8 +43,6 @@ void MGSeqKillAll(void);
void MGSeqPracticeStart(void);
void fn_8004D6F4(s16 arg);
s32 _CheckFlag(u32 flag);
void BoardWinCreate(s16, s32, s32);
void BoardWinKill(void);
void BoardWinWait(void);

11
include/game/flag.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef _GAME_FLAG_H
#define _GAME_FLAG_H
#define FLAG_ID_MAKE(group, index) (((group) << 16)|(index))
s32 _CheckFlag(u32 flag);
void _SetFlag(u32 flag);
void _ClearFlag(u32 flag);
void _InitFlag(void);
#endif

41
src/game/flag.c Normal file
View file

@ -0,0 +1,41 @@
#include "common.h"
static u8 _Sys_Flag[16];
static u8 *GetFlagPtr(u32 flag)
{
u8 *ret;
u32 group = flag >> 16;
if((flag & 0xFFFF0000) == 0x30000) {
ret = _Sys_Flag;
} else {
ret = &GWSystem.flag[group][0];
}
return ret;
}
u32 _CheckFlag(u32 flag)
{
u8 *flag_ptr = GetFlagPtr(flag);
u16 index = flag;
return flag_ptr[index/8] & (1 << (index % 8));
}
void _SetFlag(u32 flag)
{
u8 *flag_ptr = GetFlagPtr(flag);
u16 index = flag;
flag_ptr[index/8] |= (1 << (index % 8));
}
void _ClearFlag(u32 flag)
{
u8 *flag_ptr = GetFlagPtr(flag);
u16 index = flag;
flag_ptr[index/8] &= ~(1 << (index % 8));
}
void _InitFlag(void)
{
memset(_Sys_Flag, 0, sizeof(_Sys_Flag));
}

View file

@ -1,6 +1,7 @@
#include "common.h"
#include "string.h"
#include "game/gamework.h"
#include "game/flag.h"
GameStat GWGameStatDefault;
GameStat GWGameStat;
@ -144,7 +145,7 @@ s16 GWGetMessSpeed(void)
void GWSetMGRecord(int index, s32 value)
{
if(!_CheckFlag(0x1000C)) {
if(!_CheckFlag(FLAG_ID_MAKE(1, 12))) {
GWGameStat.mg_record[index] = value;
}
}
@ -297,7 +298,7 @@ s16 GWGetCoins(int player)
void GWSetCoins(int player, s16 value)
{
if(!_CheckFlag(0x1000C)) {
if(!_CheckFlag(FLAG_ID_MAKE(1, 12))) {
if(value < 0) {
value = 0;
}

View file

@ -2,6 +2,7 @@
#include "game/printfunc.h"
#include "game/object.h"
#include "game/pad.h"
#include "game/flag.h"
#define OM_OVL_HIS_MAX 16
#define OM_MAX_GROUPS 10
@ -80,7 +81,7 @@ static void omWatchOverlayProc(void)
omovlevtno = omnextovlevtno;
omovlstat = omnextovlstat;
omnextovl = OVL_INVALID;
if(_CheckFlag(0x1000C)) {
if(_CheckFlag(FLAG_ID_MAKE(1, 12))) {
MGSeqPracticeStart();
}
omSysPauseEnable(TRUE);

View file

@ -2,6 +2,7 @@
#include "game/data.h"
#include "game/pad.h"
#include "game/window.h"
#include "game/flag.h"
#include "string.h"
@ -18,8 +19,7 @@ s32 HuCardFormat(s16);
s32 HuCardWrite(void*, void*, u32, s32);
s32 HuCardRead(void*, void*, s32, s32);
s32 HuCardClose(void*);
void _ClearFlag(s32);
void _SetFlag(s32);
extern u8 UnMountCnt;
@ -138,7 +138,7 @@ s32 SLFileCreate(char *arg0, u32 arg1, void *arg2) {
HuWinExAnimIn(temp_r30);
HuWinMesSet(temp_r30, 0x10000B);
HuWinMesWait(temp_r30);
_SetFlag(0x30000);
_SetFlag(FLAG_ID_MAKE(3, 0));
temp_r31 = HuCardCreate(curSlotNo, arg0, arg1, curFileInfo);
_ClearFlag(0x30000);
if (temp_r31 < 0) {
@ -153,9 +153,9 @@ s32 SLFileCreate(char *arg0, u32 arg1, void *arg2) {
SLMessOut(1);
return -0x80;
}
_SetFlag(0x30000);
_SetFlag(FLAG_ID_MAKE(3, 0));
temp_r31 = HuCardWrite(curFileInfo, arg2, arg1, 0);
_ClearFlag(0x30000);
_ClearFlag(FLAG_ID_MAKE(3, 0));
if (temp_r31 < 0) {
HuWinExAnimOut(temp_r30);
HuWinExCleanup(temp_r30);
@ -168,9 +168,9 @@ s32 SLFileCreate(char *arg0, u32 arg1, void *arg2) {
SLMessOut(1);
return -0x80;
}
_SetFlag(0x30000);
_SetFlag(FLAG_ID_MAKE(3, 0));
temp_r31 = SLStatSet(1);
_ClearFlag(0x30000);
_ClearFlag(FLAG_ID_MAKE(3, 0));
HuWinExAnimOut(temp_r30);
HuWinExCleanup(temp_r30);
if (temp_r31 < 0) {
@ -194,12 +194,12 @@ s32 SLFileWrite(s32 arg0, void *arg1) {
HuWinMesSet(temp_r31, 0x10000B);
HuWinMesWait(temp_r31);
HuPrcSleep(0x3C);
_SetFlag(0x30000);
_SetFlag(FLAG_ID_MAKE(3, 0));
var_r30 = HuCardWrite(curFileInfo, arg1, arg0, 0);
if (var_r30 == 0) {
var_r30 = SLStatSet(1);
}
_ClearFlag(0x30000);
_ClearFlag(FLAG_ID_MAKE(3, 0));
HuWinExAnimOut(temp_r31);
HuWinExCleanup(temp_r31);
return var_r30;
@ -661,9 +661,9 @@ s32 SLFormat(s16 arg0) {
SLMessOut(0xC);
return 0;
}
_SetFlag(0x30000);
_SetFlag(FLAG_ID_MAKE(3, 0));
temp_r24 = HuCardFormat(curSlotNo);
_ClearFlag(0x30000);
_ClearFlag(FLAG_ID_MAKE(3, 0));
if (temp_r24 < 0) {
HuWinExAnimOut(temp_r3);
HuWinExCleanup(temp_r3);

View file

@ -1,6 +1,7 @@
#include "dolphin.h"
#include "game/wipe.h"
#include "game/memory.h"
#include "game/flag.h"
extern s8 lbl_801D429C;
@ -110,7 +111,7 @@ void WipeExecAlways(void)
void WipeCreate(s16 mode, s16 type, s16 duration)
{
WipeState *wipe;
if(_CheckFlag(0x1000B) && lbl_801D429C) {
if(_CheckFlag(FLAG_ID_MAKE(1, 11)) && lbl_801D429C) {
return;
}
wipe = &wipeData;