From 21c3e7e8e5555af964f7419aa9213446eaa421d6 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 2 May 2018 11:31:58 -0400 Subject: [PATCH] through SetMauvilleOldMan --- .../inspectionProfiles/profiles_settings.xml | 7 + asm/mauville_old_man.s | 138 ------------------ data/mauville_old_man.s | 3 - include/global.h | 60 +++++--- include/mauville_old_man.h | 9 ++ ld_script.txt | 2 + src/mauville_old_man.c | 84 +++++++++++ 7 files changed, 144 insertions(+), 159 deletions(-) create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 src/mauville_old_man.c diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..dd4c951ef --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/asm/mauville_old_man.s b/asm/mauville_old_man.s index af4764d76..b4302e5b1 100644 --- a/asm/mauville_old_man.s +++ b/asm/mauville_old_man.s @@ -5,144 +5,6 @@ .text - thumb_func_start sub_81200A0 -sub_81200A0: @ 81200A0 - push {r4,lr} - ldr r0, =gSaveBlock1Ptr - ldr r2, [r0] - ldr r1, =0x00002e28 - adds r0, r2, r1 - movs r1, 0 - strb r1, [r0] - ldr r3, =0x00002e51 - adds r0, r2, r3 - strb r1, [r0] - ldr r0, =gGameLanguage - ldrb r1, [r0] - adds r3, 0x1 - adds r0, r2, r3 - strb r1, [r0] - movs r3, 0 - ldr r0, =0x00002e2a - adds r2, r0 - ldr r4, =gUnknown_0859EFE4 -_081200C6: - lsls r0, r3, 1 - adds r1, r2, r0 - adds r0, r4 - ldrh r0, [r0] - strh r0, [r1] - adds r0, r3, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - cmp r3, 0x5 - bls _081200C6 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_81200A0 - - thumb_func_start sub_81200F8 -sub_81200F8: @ 81200F8 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =0x00002e28 - adds r1, r0 - movs r2, 0 - movs r0, 0x1 - strb r0, [r1] - strb r2, [r1, 0x1] - ldr r0, =gGameLanguage - ldrb r0, [r0] - strb r0, [r1, 0x2] - bx lr - .pool - thumb_func_end sub_81200F8 - - thumb_func_start sub_812011C -sub_812011C: @ 812011C - push {lr} - bl sub_8120E08 - pop {r0} - bx r0 - thumb_func_end sub_812011C - - thumb_func_start sub_8120128 -sub_8120128: @ 8120128 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =0x00002e28 - adds r2, r1, r0 - movs r3, 0 - movs r0, 0x4 - strb r0, [r2] - strb r3, [r2, 0x1] - ldr r0, =gGameLanguage - ldrb r0, [r0] - ldr r2, =0x00002e48 - adds r1, r2 - strb r0, [r1] - bx lr - .pool - thumb_func_end sub_8120128 - - thumb_func_start sub_8120154 -sub_8120154: @ 8120154 - push {lr} - bl sub_81339F8 - pop {r0} - bx r0 - thumb_func_end sub_8120154 - - thumb_func_start SetMauvilleOldMan -SetMauvilleOldMan: @ 8120160 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r1, [r0, 0xB] - lsls r1, 8 - ldrb r0, [r0, 0xA] - orrs r0, r1 - movs r1, 0xA - bl __umodsi3 - lsls r0, 16 - lsrs r0, 17 - cmp r0, 0x4 - bhi _081201C0 - lsls r0, 2 - ldr r1, =_08120190 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_08120190: - .4byte _081201A4 - .4byte _081201AA - .4byte _081201B0 - .4byte _081201B6 - .4byte _081201BC -_081201A4: - bl sub_81200A0 - b _081201C0 -_081201AA: - bl sub_81200F8 - b _081201C0 -_081201B0: - bl sub_8120154 - b _081201C0 -_081201B6: - bl sub_812011C - b _081201C0 -_081201BC: - bl sub_8120128 -_081201C0: - bl sub_8120B5C - pop {r0} - bx r0 - thumb_func_end SetMauvilleOldMan - thumb_func_start sub_81201C8 sub_81201C8: @ 81201C8 ldr r0, =gSaveBlock1Ptr diff --git a/data/mauville_old_man.s b/data/mauville_old_man.s index c1b4dd1be..0eee9698a 100644 --- a/data/mauville_old_man.s +++ b/data/mauville_old_man.s @@ -4,9 +4,6 @@ .section .rodata .align 2, 0 -gUnknown_0859EFE4:: @ 859EFE4 - .2byte 0x2811, 0x1029, 0x1018, 0xE0D, 0x1A1A, 0x1A1D - gUnknown_0859EFF0:: @ 859EFF0 .4byte gText_SoPretty .4byte gText_SoDarling diff --git a/include/global.h b/include/global.h index f88203c90..d3506d345 100644 --- a/include/global.h +++ b/include/global.h @@ -428,28 +428,50 @@ struct MailStruct /*0x20*/ u16 itemId; }; -struct UnkMauvilleOldManStruct +struct MauvilleManCommon { - u8 unk_2D94; - u8 unk_2D95; - /*0x2D96*/ u16 mauvilleOldMan_ecArray[6]; - /*0x2DA2*/ u16 mauvilleOldMan_ecArray2[6]; - /*0x2DAE*/ u8 playerName[8]; - /*0x2DB6*/ u8 filler_2DB6[0x3]; - /*0x2DB9*/ u8 playerTrainerId[4]; - u8 unk_2DBD; + u8 id; +}; + +struct MauvilleManBard +{ + /*0x00*/ u8 id; + /*0x02*/ u16 songLyrics[6]; + /*0x0E*/ u16 temporaryLyrics[6]; + /*0x1A*/ u8 playerName[8]; + /*0x22*/ u8 filler_2DB6[0x3]; + /*0x25*/ u8 playerTrainerId[4]; + /*0x29*/ bool8 hasChangedSong; + /*0x2A*/ u8 language; }; /*size = 0x2C*/ -struct UnkMauvilleOldManStruct2 +struct MauvilleManStoryteller { - u8 filler0; - u8 unk1; - u8 unk2; - u16 mauvilleOldMan_ecArray[10]; - u8 mauvilleOldMan_ecArray2[12]; - u8 fillerF[0x2]; + u8 id; + bool8 alreadyRecorded; + u8 filler2[2]; + u8 gameStatIDs[4]; + u8 trainerNames[4][7]; + u8 statValues[4][4]; +}; + +struct MauvilleManGiddy +{ + /*0x00*/ u8 id; + /*0x01*/ u8 taleCounter; + /*0x02*/ u8 questionNum; + /*0x04*/ u16 randomWords[10]; + /*0x18*/ u8 questionList[8]; + /*0x20*/ u8 language; }; /*size = 0x2C*/ +struct MauvilleManHipster +{ + u8 id; + bool8 alreadySpoken; + u8 language; +}; + struct MauvilleOldManTrader { u8 unk0; @@ -460,8 +482,10 @@ struct MauvilleOldManTrader typedef union OldMan { - struct UnkMauvilleOldManStruct oldMan1; - struct UnkMauvilleOldManStruct2 oldMan2; + struct MauvilleManCommon common; + struct MauvilleManBard bard; + struct MauvilleManGiddy giddy; + struct MauvilleManHipster hipster; struct MauvilleOldManTrader trader; u8 filler[0x40]; } OldMan; diff --git a/include/mauville_old_man.h b/include/mauville_old_man.h index aefc76083..0fc9fd6eb 100644 --- a/include/mauville_old_man.h +++ b/include/mauville_old_man.h @@ -2,6 +2,15 @@ #ifndef GUARD_MAUVILLE_OLD_MAN_H #define GUARD_MAUVILLE_OLD_MAN_H +enum MauvilleOldManType +{ + MAUVILLE_MAN_BARD, + MAUVILLE_MAN_HIPSTER, + MAUVILLE_MAN_TRADER, + MAUVILLE_MAN_STORYTELLER, + MAUVILLE_MAN_GIDDY +}; + void SetMauvilleOldMan(void); u8 sub_81201C8(void); diff --git a/ld_script.txt b/ld_script.txt index 2832bcada..c975586a6 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -162,6 +162,7 @@ SECTIONS { src/bike.o(.text); asm/easy_chat.o(.text); src/mon_markings.o(.text); + src/mauville_old_man.o(.text); asm/mauville_old_man.o(.text); src/mail.o(.text); asm/menu_helpers.o(.text); @@ -456,6 +457,7 @@ SECTIONS { src/bike.o(.rodata); data/easy_chat.o(.rodata); src/mon_markings.o(.rodata); + src/mauville_old_man.o(.rodata); data/mauville_old_man.o(.rodata); src/mail.o(.rodata); data/menu_helpers.o(.rodata); diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c new file mode 100644 index 000000000..592b5c4ce --- /dev/null +++ b/src/mauville_old_man.c @@ -0,0 +1,84 @@ +#include "global.h" +#include "main.h" +#include "constants/easy_chat.h" +#include "mauville_old_man.h" + +void sub_8120E08(void); // StorytellerSetup +void sub_81339F8(void); // TraderSetup +void sub_8120B5C(void); + +static const u16 sDefaultBardSongLyrics[6] = { + EC_WORD_SHAKE, + EC_WORD_IT, + EC_WORD_DO, + EC_WORD_THE, + EC_WORD_DIET, + EC_WORD_DANCE +}; + +static void SetupBard(void) +{ + u16 i; + struct MauvilleManBard *bard = &gSaveBlock1Ptr->oldMan.bard; + + bard->id = MAUVILLE_MAN_BARD; + bard->hasChangedSong = FALSE; + bard->language = gGameLanguage; + for (i = 0; i < 6; i++) + bard->songLyrics[i] = sDefaultBardSongLyrics[i]; +} + +static void SetupHipster(void) +{ + struct MauvilleManHipster *hipster = &gSaveBlock1Ptr->oldMan.hipster; + + hipster->id = MAUVILLE_MAN_HIPSTER; + hipster->alreadySpoken = FALSE; + hipster->language = gGameLanguage; +} + +static void SetupStoryteller(void) +{ + sub_8120E08(); +} + +static void SetupGiddy(void) +{ + struct MauvilleManGiddy *giddy = &gSaveBlock1Ptr->oldMan.giddy; + + giddy->id = MAUVILLE_MAN_GIDDY; + giddy->taleCounter = 0; + giddy->language = gGameLanguage; +} + +static void SetupTrader(void) +{ + sub_81339F8(); +} + +void SetMauvilleOldMan(void) +{ + u16 trainerId = (gSaveBlock2Ptr->playerTrainerId[1] << 8) | gSaveBlock2Ptr->playerTrainerId[0]; + + + // Determine man based on the last digit of the player's trainer ID. + switch ((trainerId % 10) / 2) + { + case MAUVILLE_MAN_BARD: + SetupBard(); + break; + case MAUVILLE_MAN_HIPSTER: + SetupHipster(); + break; + case MAUVILLE_MAN_TRADER: + SetupTrader(); + break; + case MAUVILLE_MAN_STORYTELLER: + SetupStoryteller(); + break; + case MAUVILLE_MAN_GIDDY: + SetupGiddy(); + break; + } + sub_8120B5C(); +}