Merge pull request #246 from abaresk/gymmick-init

Decompile gymmick_init.c
This commit is contained in:
Adrienn Tindall 2023-08-30 11:55:25 -05:00 committed by GitHub
commit b4b116e5b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 155 additions and 271 deletions

View File

@ -1,249 +0,0 @@
.include "asm/macros.inc"
.include "unk_02068DE0.inc"
.include "global.inc"
.rodata
sTrashCanData:
.word 2
.byte 1, 5, 0xFF, 0xFF
.word 3
.byte 0, 2, 6, 0xFF
.word 3
.byte 1, 3, 7, 0xFF
.word 3
.byte 2, 4, 8, 0xFF
.word 2
.byte 3, 9, 0xFF, 0xFF
.word 3
.byte 0, 6, 10, 0xFF
.word 4
.byte 1, 5, 7, 11
.word 4
.byte 2, 6, 8, 12
.word 4
.byte 3, 7, 9, 13
.word 3
.byte 4, 8, 14, 0xFF
.word 2
.byte 5, 11, 0xFF, 0xFF
.word 3
.byte 6, 10, 12, 0xFF
.word 3
.byte 7, 11, 13, 0xFF
.word 3
.byte 8, 12, 14, 0xFF
.word 2
.byte 9, 13, 0xFF, 0xFF
.text
thumb_func_start InitEcruteakGym
InitEcruteakGym: ; 0x02068DE0
push {r4, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
add r4, r0, #0
mov r1, #1
bl Save_Gymmick_Init
add r0, r4, #0
mov r1, #1
bl Save_Gymmick_AssertMagic_GetData
mov r2, #0
add r1, r2, #0
_02068DFE:
strb r1, [r0, r2]
add r2, r2, #1
cmp r2, #4
blt _02068DFE
pop {r4, pc}
thumb_func_end InitEcruteakGym
thumb_func_start InitCianwoodGym
InitCianwoodGym: ; 0x02068E08
push {r4, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
add r4, r0, #0
mov r1, #2
bl Save_Gymmick_Init
add r0, r4, #0
mov r1, #2
bl Save_Gymmick_AssertMagic_GetData
pop {r4, pc}
thumb_func_end InitCianwoodGym
thumb_func_start InitVermilionGym
InitVermilionGym: ; 0x02068E24
push {r3, r4, r5, lr}
add r5, r0, #0
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
add r4, r0, #0
mov r1, #3
bl Save_Gymmick_Init
add r0, r4, #0
mov r1, #3
bl Save_Gymmick_AssertMagic_GetData
add r4, r0, #0
ldr r0, [r5, #0xc]
bl Save_PlayerData_GetProfileAddr
mov r1, #0xa
bl PlayerProfile_TestBadgeFlag
cmp r0, #0
beq _02068E60
mov r0, #0
strb r0, [r4]
strb r0, [r4, #1]
mov r0, #1
strb r0, [r4, #2]
strb r0, [r4, #3]
pop {r3, r4, r5, pc}
_02068E60:
add r0, r5, #0
bl PlaceVermilionGymSwitches
mov r0, #0
strb r0, [r4, #2]
strb r0, [r4, #3]
pop {r3, r4, r5, pc}
.balign 4, 0
thumb_func_end InitVermilionGym
thumb_func_start PlaceVermilionGymSwitches
PlaceVermilionGymSwitches: ; 0x02068E70
push {r3, r4, r5, r6, r7, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
mov r1, #3
bl Save_Gymmick_AssertMagic_GetData
add r5, r0, #0
bl LCRandom
mov r1, #0xf
bl _s32_div_f
strb r1, [r5]
ldrb r0, [r5]
ldr r7, _02068EAC ; =sTrashCanData
lsl r4, r0, #3
add r6, r7, r4
bl LCRandom
ldr r1, [r7, r4]
bl _s32_div_f
lsl r0, r1, #0x18
lsr r0, r0, #0x18
add r0, r6, r0
ldrb r0, [r0, #4]
strb r0, [r5, #1]
pop {r3, r4, r5, r6, r7, pc}
.balign 4, 0
_02068EAC: .word sTrashCanData
thumb_func_end PlaceVermilionGymSwitches
thumb_func_start InitVioletGym
InitVioletGym: ; 0x02068EB0
push {r4, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
add r4, r0, #0
mov r1, #4
bl Save_Gymmick_Init
add r0, r4, #0
mov r1, #4
bl Save_Gymmick_AssertMagic_GetData
mov r1, #0
str r1, [r0]
pop {r4, pc}
thumb_func_end InitVioletGym
thumb_func_start InitAzaleaGym
InitAzaleaGym: ; 0x02068ED0
push {r4, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
add r4, r0, #0
mov r1, #5
bl Save_Gymmick_Init
add r0, r4, #0
mov r1, #5
bl Save_Gymmick_AssertMagic_GetData
mov r2, #0
strb r2, [r0]
mov r1, #1
strb r1, [r0, #1]
mov r1, #2
strb r1, [r0, #2]
mov r1, #7
strb r1, [r0, #3]
str r2, [r0, #4]
pop {r4, pc}
.balign 4, 0
thumb_func_end InitAzaleaGym
thumb_func_start InitBlackthornGym
InitBlackthornGym: ; 0x02068F00
push {r4, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
add r4, r0, #0
mov r1, #6
bl Save_Gymmick_Init
add r0, r4, #0
mov r1, #6
bl Save_Gymmick_AssertMagic_GetData
mov r1, #0xd
strh r1, [r0]
mov r1, #0x4b
strh r1, [r0, #6]
mov r2, #0
strb r2, [r0, #0xc]
mov r1, #9
strh r1, [r0, #2]
mov r1, #0x3a
strh r1, [r0, #8]
mov r1, #1
strb r1, [r0, #0xd]
mov r1, #0xe
strh r1, [r0, #4]
mov r1, #0x20
strh r1, [r0, #0xa]
strb r2, [r0, #0xe]
pop {r4, pc}
.balign 4, 0
thumb_func_end InitBlackthornGym
thumb_func_start InitFuchsiaGym
InitFuchsiaGym: ; 0x02068F40
push {r3, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
mov r1, #7
bl Save_Gymmick_Init
pop {r3, pc}
.balign 4, 0
thumb_func_end InitFuchsiaGym
thumb_func_start InitViridianGym
InitViridianGym: ; 0x02068F54
push {r3, lr}
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
mov r1, #8
bl Save_Gymmick_Init
pop {r3, pc}
.balign 4, 0
thumb_func_end InitViridianGym
thumb_func_start FieldSystem_IsSaveGymmickTypeEqualTo
FieldSystem_IsSaveGymmickTypeEqualTo: ; 0x02068F68
push {r4, lr}
add r4, r1, #0
bl FieldSystem_GetSaveData
bl Save_GetGymmickPtr
bl Save_Gymmick_GetType
cmp r4, r0
bne _02068F80
mov r0, #1
pop {r4, pc}
_02068F80:
mov r0, #0
pop {r4, pc}
thumb_func_end FieldSystem_IsSaveGymmickTypeEqualTo

View File

@ -12,7 +12,7 @@
#define GYMMICK_VIRIDIAN 8
#define GYMMICK_SINJOH 9
union GymmickUnion {
typedef union GymmickUnion {
u8 raw[0x20];
struct {
u8 candles[4];
@ -41,16 +41,16 @@ union GymmickUnion {
struct {
u32 choice;
} sinjoh;
};
} GymmickUnion;
struct Gymmick {
typedef struct Gymmick {
int kind;
union GymmickUnion data;
};
GymmickUnion data;
} Gymmick;
void Save_Gymmick_Clear(struct Gymmick *gymmick);
union GymmickUnion *Save_Gymmick_Init(struct Gymmick *gymmick, int kind);
union GymmickUnion *Save_Gymmick_AssertMagic_GetData(struct Gymmick *gymmick, int kind);
int Save_Gymmick_GetType(struct Gymmick *gymmick);
void Save_Gymmick_Clear(Gymmick *gymmick);
GymmickUnion *Save_Gymmick_Init(Gymmick *gymmick, int kind);
GymmickUnion *Save_Gymmick_AssertMagic_GetData(Gymmick *gymmick, int kind);
int Save_Gymmick_GetType(Gymmick *gymmick);
#endif //POKEHEARTGOLD_GYMMICK_H

View File

@ -1,5 +1,5 @@
#ifndef POKEHEARTGOLD_UNK_02068DE0_H
#define POKEHEARTGOLD_UNK_02068DE0_H
#ifndef POKEHEARTGOLD_GYMMICK_INIT_H
#define POKEHEARTGOLD_GYMMICK_INIT_H
#include "script.h"
@ -12,5 +12,6 @@ void InitAzaleaGym(FieldSystem *fieldSystem);
void InitBlackthornGym(FieldSystem *fieldSystem);
void InitFuchsiaGym(FieldSystem *fieldSystem);
void InitViridianGym(FieldSystem *fieldSystem);
BOOL FieldSystem_IsSaveGymmickTypeEqualTo(FieldSystem *fieldSystem, int kind);
#endif //POKEHEARTGOLD_UNK_02068DE0_H
#endif //POKEHEARTGOLD_GYMMICK_INIT_H

View File

@ -41,7 +41,7 @@ typedef struct SAVE_MISC_DATA {
APRICORN_TREE apricorn_trees[MAX_APRICORN_TREE];
BerryPot berry_pots[MAX_BERRY_POT];
struct GF_RTC_DateTime berry_datetime;
struct Gymmick gymmick;
Gymmick gymmick;
u16 rivalName[PLAYER_NAME_LENGTH + 1];
u8 unk_0280[8]; // 3 chunks of size (4, 2, 2)
u8 filler_0288[0x10];
@ -69,7 +69,7 @@ const SAVE_MISC_DATA *Save_Misc_Const_Get(const SaveData *saveData);
APRICORN_TREE *Save_FieldApricornTrees_Get(SaveData *saveData);
BerryPot *Save_BerryPots_Get(SaveData *saveData);
struct GF_RTC_DateTime *Save_BerryPotRTC_Get(SaveData *saveData);
struct Gymmick *Save_GetGymmickPtr(SaveData *saveData);
Gymmick *Save_GetGymmickPtr(SaveData *saveData);
const u16 *Save_Misc_RivalName_Const_Get(const SAVE_MISC_DATA *saveMiscData);
void Save_Misc_RivalName_Set(SAVE_MISC_DATA *saveMiscData, const String *name);
void SaveMisc_SetExtraChunksExist(SAVE_MISC_DATA *saveMiscData);

View File

@ -233,7 +233,7 @@ Static main
Object asm/unk_02067A60.o
Object src/field_move.o
Object asm/unk_020689C8.o
Object asm/unk_02068DE0.o
Object src/gymmick_init.o
Object src/unk_02068F84.o
Object asm/unk_02068FC8.o
Object asm/unk_02069528.o

132
src/gymmick_init.c Normal file
View File

@ -0,0 +1,132 @@
#include "global.h"
#include "field_system.h"
#include "gymmick.h"
#include "gymmick_init.h"
#include "math_util.h"
#include "player_data.h"
#include "save.h"
#include "save_misc_data.h"
#include "constants/badge.h"
#define NUM_TRASH_CANS 15
typedef struct TrashCan {
int numNeighbors;
u8 neighbors[4];
} TrashCan;
static const TrashCan sTrashCans[NUM_TRASH_CANS] = {
[0] = {.numNeighbors = 2, .neighbors = { 1, 5, 0xFF, 0xFF }},
[1] = {.numNeighbors = 3, .neighbors = { 0, 2, 6, 0xFF }},
[2] = {.numNeighbors = 3, .neighbors = { 1, 3, 7, 0xFF }},
[3] = {.numNeighbors = 3, .neighbors = { 2, 4, 8, 0xFF }},
[4] = {.numNeighbors = 2, .neighbors = { 3, 9, 0xFF, 0xFF }},
[5] = {.numNeighbors = 3, .neighbors = { 0, 6, 10, 0xFF }},
[6] = {.numNeighbors = 4, .neighbors = { 1, 5, 7, 11 }},
[7] = {.numNeighbors = 4, .neighbors = { 2, 6, 8, 12 }},
[8] = {.numNeighbors = 4, .neighbors = { 3, 7, 9, 13 }},
[9] = {.numNeighbors = 3, .neighbors = { 4, 8, 14, 0xFF }},
[10] = {.numNeighbors = 2, .neighbors = { 5, 11, 0xFF, 0xFF }},
[11] = {.numNeighbors = 3, .neighbors = { 6, 10, 12, 0xFF }},
[12] = {.numNeighbors = 3, .neighbors = { 7, 11, 13, 0xFF }},
[13] = {.numNeighbors = 3, .neighbors = { 8, 12, 14, 0xFF }},
[14] = {.numNeighbors = 2, .neighbors = { 9 , 13, 0xFF, 0xFF }},
};
void InitEcruteakGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_ECRUTEAK);
GymmickUnion *data = Save_Gymmick_AssertMagic_GetData(gymmick, GYMMICK_ECRUTEAK);
for (int i = 0; i < 4; i++) {
data->ecruteak.candles[i] = 0;
}
}
void InitCianwoodGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_CIANWOOD);
GymmickUnion *unused = Save_Gymmick_AssertMagic_GetData(gymmick, GYMMICK_CIANWOOD);
}
void InitVermilionGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_VERMILION);
GymmickUnion *data = Save_Gymmick_AssertMagic_GetData(gymmick, GYMMICK_VERMILION);
if (PlayerProfile_TestBadgeFlag(Save_PlayerData_GetProfileAddr(fieldSystem->saveData), BADGE_THUNDER)) {
data->vermilion.switches[0] = 0;
data->vermilion.switches[1] = 0;
data->vermilion.gates[0] = 1;
data->vermilion.gates[1] = 1;
return;
}
PlaceVermilionGymSwitches(fieldSystem);
data->vermilion.gates[0] = 0;
data->vermilion.gates[1] = 0;
}
void PlaceVermilionGymSwitches(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
GymmickUnion *data = Save_Gymmick_AssertMagic_GetData(gymmick, GYMMICK_VERMILION);
data->vermilion.switches[0] = LCRandom() % NUM_TRASH_CANS;
const TrashCan *trashCan = &sTrashCans[data->vermilion.switches[0]];
u8 index = LCRandom() % trashCan->numNeighbors;
data->vermilion.switches[1] = trashCan->neighbors[index];
}
void InitVioletGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_VIOLET);
GymmickUnion *data = Save_Gymmick_AssertMagic_GetData(gymmick, GYMMICK_VIOLET);
data->violet.liftState = 0;
}
void InitAzaleaGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_AZALEA);
GymmickUnion *data = Save_Gymmick_AssertMagic_GetData(gymmick, GYMMICK_AZALEA);
data->azalea.spiders[0] = 0;
data->azalea.spiders[1] = 1;
data->azalea.spiders[2] = 2;
data->azalea.spiders[3] = 7;
data->azalea.switches = 0;
}
void InitBlackthornGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_BLACKTHORN);
GymmickUnion *data = Save_Gymmick_AssertMagic_GetData(gymmick, GYMMICK_BLACKTHORN);
data->blackthorn.x[0] = 13;
data->blackthorn.z[0] = 75;
data->blackthorn.rot[0] = 0;
data->blackthorn.x[1] = 9;
data->blackthorn.z[1] = 58;
data->blackthorn.rot[1] = 1;
data->blackthorn.x[2] = 14;
data->blackthorn.z[2] = 32;
data->blackthorn.rot[2] = 0;
}
void InitFuchsiaGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_FUCHSIA);
}
void InitViridianGym(FieldSystem *fieldSystem) {
Gymmick *gymmick = Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem));
Save_Gymmick_Init(gymmick, GYMMICK_VIRIDIAN);
}
BOOL FieldSystem_IsSaveGymmickTypeEqualTo(FieldSystem *fieldSystem, int kind) {
return Save_Gymmick_GetType(Save_GetGymmickPtr(FieldSystem_GetSaveData(fieldSystem))) == kind;
}

View File

@ -1,21 +1,21 @@
#include "global.h"
#include "gymmick.h"
void Save_Gymmick_Clear(struct Gymmick *gymmick) {
MI_CpuClear8(gymmick, sizeof(struct Gymmick));
void Save_Gymmick_Clear(Gymmick *gymmick) {
MI_CpuClear8(gymmick, sizeof(Gymmick));
}
union GymmickUnion *Save_Gymmick_Init(struct Gymmick *gymmick, int kind) {
GymmickUnion *Save_Gymmick_Init(Gymmick *gymmick, int kind) {
Save_Gymmick_Clear(gymmick);
gymmick->kind = kind;
return &gymmick->data;
}
union GymmickUnion *Save_Gymmick_AssertMagic_GetData(struct Gymmick *gymmick, int kind) {
GymmickUnion *Save_Gymmick_AssertMagic_GetData(Gymmick *gymmick, int kind) {
GF_ASSERT(gymmick->kind == kind);
return &gymmick->data;
}
int Save_Gymmick_GetType(struct Gymmick *gymmick) {
int Save_Gymmick_GetType(Gymmick *gymmick) {
return gymmick->kind;
}

View File

@ -70,7 +70,7 @@ struct GF_RTC_DateTime *Save_BerryPotRTC_Get(SaveData *saveData) {
return &misc->berry_datetime;
}
struct Gymmick *Save_GetGymmickPtr(SaveData *saveData) {
Gymmick *Save_GetGymmickPtr(SaveData *saveData) {
SAVE_MISC_DATA *misc;
misc = SaveArray_Get(saveData, SAVE_MISC);
return &misc->gymmick;

View File

@ -65,7 +65,7 @@
#include "unk_02058034.h"
#include "unk_02056D7C.h"
#include "unk_02034B0C.h"
#include "unk_02068DE0.h"
#include "gymmick_init.h"
#include "unk_02097D3C.h"
#include "math_util.h"
#include "game_stats.h"