From ca2bc94c2be5d7b915e5ab913ef026aa12b8fc0f Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 3 Nov 2017 20:59:29 -0400 Subject: [PATCH 01/26] through sub_80E6BF8 --- asm/record_mixing.s | 59 ----------------------------------------- include/cable_club.h | 12 +++++++++ include/global.h | 6 ++--- include/record_mixing.h | 19 +++++++++++++ ld_script.txt | 1 + src/record_mixing.c | 36 +++++++++++++++++++++++-- sym_ewram.txt | 12 +-------- 7 files changed, 70 insertions(+), 75 deletions(-) create mode 100644 include/cable_club.h create mode 100644 include/record_mixing.h diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 7e9ea30d1..8951649ec 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,65 +5,6 @@ .text - thumb_func_start sub_80E6BE8 -sub_80E6BE8: @ 80E6BE8 - push {lr} - ldr r0, =sub_80E715C - bl sub_80B37D4 - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E6BE8 - - thumb_func_start sub_80E6BF8 -sub_80E6BF8: @ 80E6BF8 - push {r4,lr} - ldr r2, =gUnknown_03001134 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r3, =0x00001a9c - adds r0, r1, r3 - str r0, [r2] - ldr r2, =gUnknown_03001138 - ldr r4, =0x000027cc - adds r0, r1, r4 - str r0, [r2] - ldr r2, =gUnknown_0300113C - ldr r3, =0x00002b50 - adds r0, r1, r3 - str r0, [r2] - ldr r2, =gUnknown_03001140 - ldr r4, =0x00002e28 - adds r0, r1, r4 - str r0, [r2] - ldr r2, =gUnknown_03001144 - ldr r3, =0x00002e68 - adds r0, r1, r3 - str r0, [r2] - ldr r2, =gUnknown_03001148 - ldr r0, =gUnknown_02039F9C - str r0, [r2] - ldr r2, =gUnknown_0300114C - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldr r4, =0x0000064c - adds r3, r0, r4 - str r3, [r2] - ldr r2, =gUnknown_03001150 - ldr r4, =0x00003b58 - adds r1, r4 - str r1, [r2] - ldr r1, =gUnknown_03001154 - adds r0, 0xDC - str r0, [r1] - ldr r0, =gUnknown_03001158 - str r3, [r0] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E6BF8 - thumb_func_start sub_80E6CA0 sub_80E6CA0: @ 80E6CA0 push {r4,r5,lr} diff --git a/include/cable_club.h b/include/cable_club.h new file mode 100644 index 000000000..adb0c4f90 --- /dev/null +++ b/include/cable_club.h @@ -0,0 +1,12 @@ +#ifndef GUARD_CABLE_CLUB_H +#define GUARD_CABLE_CLUB_H + +// Exported type declarations + +// Exported RAM declarations + +// Exported ROM declarations + +void sub_80B37D4(TaskFunc taskFunc); + +#endif //GUARD_CABLE_CLUB_H diff --git a/include/global.h b/include/global.h index 3421517d7..ad4f23c2b 100644 --- a/include/global.h +++ b/include/global.h @@ -192,7 +192,8 @@ struct SaveBlock2 /*0xAC*/ u32 encryptionKey; // TODO: fix and verify labels - /*0xB0*/ u8 field_B0[316]; + /*0xB0*/ u8 field_B0[0x2c]; + /*0xDC*/ u8 field_0DC[0x110]; /*0x1EC*/ struct BerryCrush berryCrush; /*0x1FC*/ struct PokemonJumpResults pokeJump; /*0x20C*/ struct BerryPickingResults berryPick; @@ -579,13 +580,12 @@ struct SaveBlock1 /*0x2BB0*/ u16 unk2BB0[6]; /*0x2BBC*/ u16 unk2BBC[6]; /*0x2BC8*/ u16 unk2BC8[6]; - /*0x2BD4*/ u16 unk2BD4[3]; + /*0x2BD4*/ u16 unk2BD4[6]; /*0x2BE0*/ struct MailStruct mail[16]; /*0x2E20*/ u8 additionalPhrases[5]; // bitfield for 33 additional phrases in easy chat system /*0x2E25*/ u8 unk2E25[3]; // possibly padding? /*0x2E28*/ OldMan oldMan; /*0x2e64*/ struct EasyChatPair easyChatPairs[5]; //Dewford trend [0] and some other stuff - /*0x2e8c*/ u8 filler_2E8C[0x4]; /*0x2e90*/ struct ContestWinner contestWinners[13]; // 0 - 5 used in contest hall, 6 - 7 unused?, 8 - 12 museum /*0x3030*/ struct DaycareData daycare; /*0x3150*/ struct LinkBattleRecord linkBattleRecords[5]; diff --git a/include/record_mixing.h b/include/record_mixing.h new file mode 100644 index 000000000..5ccbdc0dd --- /dev/null +++ b/include/record_mixing.h @@ -0,0 +1,19 @@ +#ifndef GUARD_RECORD_MIXING_H +#define GUARD_RECORD_MIXING_H + +// Exported type declarations + +struct DayCareMailRecordMixing { + struct MailStruct mail; + u8 OT_name[OT_NAME_LENGTH + 1]; + u8 monName[11]; + u8 language_maybe : 4; + u8 unknown : 4; + u32 stepsTaken; +}; + +// Exported RAM declarations + +// Exported ROM declarations + +#endif //GUARD_RECORD_MIXING_H diff --git a/ld_script.txt b/ld_script.txt index c8d31c846..7390a0702 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -146,6 +146,7 @@ SECTIONS { asm/naming_screen.o(.text); src/money.o(.text); asm/contest_effect.o(.text); + src/record_mixing.o(.text); asm/record_mixing.o(.text); src/secret_base.o(.text); src/tv.o(.text); diff --git a/src/record_mixing.c b/src/record_mixing.c index 151835e5e..ade4d6e8c 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -1,6 +1,9 @@ // Includes #include "global.h" +#include "task.h" +#include "cable_club.h" +#include "record_mixing.h" // Static type declarations @@ -9,10 +12,10 @@ IWRAM_DATA bool8 gUnknown_03001130; IWRAM_DATA struct SecretBaseRecord *gUnknown_03001134; IWRAM_DATA TVShow *gUnknown_03001138; -IWRAM_DATA struct UnknownSaveStruct2ABC *gUnknown_0300113C; +IWRAM_DATA PokeNews *gUnknown_0300113C; IWRAM_DATA OldMan *gUnknown_03001140; IWRAM_DATA struct EasyChatPair *gUnknown_03001144; -IWRAM_DATA struct DaycareData *gUnknown_03001148; +IWRAM_DATA struct DayCareMailRecordMixing *gUnknown_03001148; IWRAM_DATA void *gUnknown_0300114C; // gSaveBlock2Ptr->field_64C IWRAM_DATA LilycoveLady *gUnknown_03001150; IWRAM_DATA void *gUnknown_03001154; // gSaveBlock2Ptr->field_0DC; @@ -21,8 +24,37 @@ IWRAM_DATA u32 gUnknown_0300115C; IWRAM_DATA u8 gUnknown_03001160[8]; IWRAM_DATA u32 gUnknown_03001168[3]; +EWRAM_DATA struct DayCareMailRecordMixing gUnknown_02039F9C[2] = {}; +EWRAM_DATA struct { + /*0x0000*/ u8 filler_0000[0x5110]; +} *gUnknown_0203A014 = NULL; +EWRAM_DATA struct { + /*0x0000*/ u8 filler_0000[0x1444]; +} *gUnknown_0203A018 = NULL; + // Static ROM declarations +void sub_80E715C(u8 taskId); + // .rodata // .text + +void sub_80E6BE8(void) +{ + sub_80B37D4(sub_80E715C); +} + +void sub_80E6BF8(void) +{ + gUnknown_03001134 = gSaveBlock1Ptr->secretBases; + gUnknown_03001138 = gSaveBlock1Ptr->tvShows; + gUnknown_0300113C = gSaveBlock1Ptr->pokeNews; + gUnknown_03001140 = &gSaveBlock1Ptr->oldMan; + gUnknown_03001144 = gSaveBlock1Ptr->easyChatPairs; + gUnknown_03001148 = gUnknown_02039F9C; + gUnknown_0300114C = gSaveBlock2Ptr->field_64C; + gUnknown_03001150 = &gSaveBlock1Ptr->lilycoveLady; + gUnknown_03001154 = gSaveBlock2Ptr->field_0DC; + gUnknown_03001158 = gSaveBlock2Ptr->field_64C; +} diff --git a/sym_ewram.txt b/sym_ewram.txt index 52d24a9ab..27db667e8 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -1033,17 +1033,7 @@ gUnknown_02039F94: @ 2039F94 .space 0x4 .include "src/money.o" - - .align 2 -gUnknown_02039F9C: @ 2039F9C - .space 0x78 - -gUnknown_0203A014: @ 203A014 - .space 0x4 - -gUnknown_0203A018: @ 203A018 - .space 0x4 - + .include "src/record_mixing.o" .include "src/secret_base.o" .include "src/tv.o" From f8486b31c531dd9622e748e1382ab9e4b8a5fc5c Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 3 Nov 2017 21:56:18 -0400 Subject: [PATCH 02/26] sub_80E6CA0 --- Makefile | 2 ++ asm/record_mixing.s | 61 ---------------------------------- include/battle_tower.h | 1 + include/gba/gba.h | 1 + include/gba/libc.h | 10 ++++++ include/global.h | 7 ---- include/mystery_event_script.h | 1 + src/record_mixing.c | 37 +++++++++++++++++++-- 8 files changed, 49 insertions(+), 71 deletions(-) create mode 100644 include/gba/libc.h diff --git a/Makefile b/Makefile index 4a1f94352..9dfc1dbee 100644 --- a/Makefile +++ b/Makefile @@ -101,6 +101,8 @@ $(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork $(C_BUILDDIR)/m4a_2.o: CC1 := tools/agbcc/bin/old_agbcc $(C_BUILDDIR)/m4a_4.o: CC1 := tools/agbcc/bin/old_agbcc +$(C_BUILDDIR)/record_mixing.o: CFLAGS += -ffreestanding + ifeq ($(NODEP),) $(C_BUILDDIR)/%.o: c_dep = $(shell $(SCANINC) -I include $(C_SUBDIR)/$*.c) else diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 8951649ec..94f3756d5 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,67 +5,6 @@ .text - thumb_func_start sub_80E6CA0 -sub_80E6CA0: @ 80E6CA0 - push {r4,r5,lr} - adds r5, r0, 0 - ldr r0, =gUnknown_03001134 - ldr r1, [r0] - movs r4, 0xC8 - lsls r4, 4 - adds r0, r5, 0 - adds r2, r4, 0 - bl memcpy - adds r4, r5, r4 - ldr r0, =gUnknown_03001138 - ldr r1, [r0] - movs r2, 0xE1 - lsls r2, 2 - adds r0, r4, 0 - bl memcpy - adds r0, r4, 0 - bl sub_80F14F8 - ldr r1, =0x00001004 - adds r0, r5, r1 - ldr r1, =gUnknown_0300113C - ldr r1, [r1] - movs r2, 0x40 - bl memcpy - ldr r2, =0x00001044 - adds r0, r5, r2 - ldr r1, =gUnknown_03001140 - ldr r1, [r1] - movs r2, 0x40 - bl memcpy - ldr r1, =0x00001084 - adds r0, r5, r1 - ldr r1, =gUnknown_03001144 - ldr r1, [r1] - movs r2, 0x28 - bl memcpy - ldr r2, =0x000010ac - adds r0, r5, r2 - bl sub_80E89F8 - ldr r0, =gUnknown_0300114C - ldr r0, [r0] - ldr r2, =0x00001124 - adds r1, r5, r2 - bl sub_81659DC - bl GetMultiplayerId - lsls r0, 24 - cmp r0, 0 - bne _080E6D1C - bl sub_81539D4 - ldr r2, =0x000011c8 - adds r1, r5, r2 - strh r0, [r1] -_080E6D1C: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E6CA0 - thumb_func_start sub_80E6D54 sub_80E6D54: @ 80E6D54 push {r4,r5,lr} diff --git a/include/battle_tower.h b/include/battle_tower.h index 25b439c1b..a3bd3b6e8 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -2,5 +2,6 @@ #define GUARD_BATTLE_TOWER_H u16 sub_8164FCC(u8, u8); +void sub_81659DC(void *a0, void *a1); #endif //GUARD_BATTLE_TOWER_H diff --git a/include/gba/gba.h b/include/gba/gba.h index 42ae3cdde..19b65dbca 100644 --- a/include/gba/gba.h +++ b/include/gba/gba.h @@ -7,5 +7,6 @@ #include "gba/multiboot.h" #include "gba/syscall.h" #include "gba/macro.h" +#include "gba/libc.h" #endif // GUARD_GBA_GBA_H diff --git a/include/gba/libc.h b/include/gba/libc.h new file mode 100644 index 000000000..9ed82ac28 --- /dev/null +++ b/include/gba/libc.h @@ -0,0 +1,10 @@ +#ifndef GUARD_LIBC_H +#define GUARD_LIBC_H + +void *memset(void *dst, int val, size_t size); +void *memcpy(void *dst, const void *src, size_t size); +int strcmp(const char *s1, const char *s2); +char *strcpy(char *dst0, const char *src0); +#define abs(x) ((x) >= 0 ? (x) : -(x)) + +#endif //GUARD_LIBC_H diff --git a/include/global.h b/include/global.h index ad4f23c2b..f3c58a3d8 100644 --- a/include/global.h +++ b/include/global.h @@ -11,13 +11,6 @@ #define asm_comment(x) asm volatile("@ -- " x " -- ") #define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided") -#if defined (__APPLE__) || defined (__CYGWIN__) -void *memset(void *, int, size_t); -void *memcpy(void *, const void *, size_t); -int strcmp(const char *s1, const char *s2); -char* strcpy(char *dst0, const char *src0); -#endif // __APPLE__ - #define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0])) // useful math macros diff --git a/include/mystery_event_script.h b/include/mystery_event_script.h index ab23a8d00..1fad6c485 100644 --- a/include/mystery_event_script.h +++ b/include/mystery_event_script.h @@ -4,5 +4,6 @@ u32 RunMysteryEventScript(u8 *); void SetMysteryEventScriptStatus(u32 val); u16 GetRecordMixingGift(void); +u16 sub_81539D4(void); #endif // GUARD_MYSTERY_EVENT_SCRIPT_H diff --git a/src/record_mixing.c b/src/record_mixing.c index ade4d6e8c..06cf1ab2e 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -3,10 +3,26 @@ #include "global.h" #include "task.h" #include "cable_club.h" +#include "link.h" +#include "tv.h" +#include "battle_tower.h" +#include "mystery_event_script.h" #include "record_mixing.h" // Static type declarations +struct RecordMixingData { + struct SecretBaseRecord secretBases[20]; + TVShow tvShows[25]; + PokeNews pokeNews[16]; + OldMan oldMan; + struct EasyChatPair easyChatPair[5]; + u8 unk_10ac[0x78]; + u8 unk_1124[0xa4]; + u16 unk_11c8; + u8 unk_11ca[0x27a]; +}; + // Static RAM declarations IWRAM_DATA bool8 gUnknown_03001130; @@ -28,13 +44,12 @@ EWRAM_DATA struct DayCareMailRecordMixing gUnknown_02039F9C[2] = {}; EWRAM_DATA struct { /*0x0000*/ u8 filler_0000[0x5110]; } *gUnknown_0203A014 = NULL; -EWRAM_DATA struct { - /*0x0000*/ u8 filler_0000[0x1444]; -} *gUnknown_0203A018 = NULL; +EWRAM_DATA struct RecordMixingData *gUnknown_0203A018 = NULL; // Static ROM declarations void sub_80E715C(u8 taskId); +void sub_80E89F8(void *dest); // .rodata @@ -58,3 +73,19 @@ void sub_80E6BF8(void) gUnknown_03001154 = gSaveBlock2Ptr->field_0DC; gUnknown_03001158 = gSaveBlock2Ptr->field_64C; } + +void sub_80E6CA0(struct RecordMixingData *dest) +{ + memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); + memcpy(dest->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); + sub_80F14F8(dest->tvShows); + memcpy(dest->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); + memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); + memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); + sub_80E89F8(dest->unk_10ac); + sub_81659DC(gUnknown_0300114C, dest->unk_1124); + if (GetMultiplayerId() == 0) + { + dest->unk_11c8 = sub_81539D4(); + } +} From 20ebcf71699a3463e130b68b1c2c2a3f984c8db8 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 3 Nov 2017 22:07:36 -0400 Subject: [PATCH 03/26] sub_80E6D54 --- asm/record_mixing.s | 72 -------------------------------------- include/mauville_old_man.h | 1 + include/secret_base.h | 1 + include/tv.h | 1 + src/record_mixing.c | 24 +++++++++++++ 5 files changed, 27 insertions(+), 72 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 94f3756d5..e7827f8a4 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,78 +5,6 @@ .text - thumb_func_start sub_80E6D54 -sub_80E6D54: @ 80E6D54 - push {r4,r5,lr} - adds r5, r0, 0 - ldr r0, =gUnknown_03001134 - ldr r1, [r0] - movs r4, 0xC8 - lsls r4, 4 - adds r0, r5, 0 - adds r2, r4, 0 - bl memcpy - adds r0, r5, 0 - bl sub_80EB18C - adds r4, r5, r4 - ldr r0, =gUnknown_03001138 - ldr r1, [r0] - movs r2, 0xE1 - lsls r2, 2 - adds r0, r4, 0 - bl memcpy - adds r0, r4, 0 - bl sub_80F1208 - ldr r1, =0x00001004 - adds r0, r5, r1 - ldr r1, =gUnknown_0300113C - ldr r1, [r1] - movs r2, 0x40 - bl memcpy - ldr r2, =0x00001044 - adds r4, r5, r2 - ldr r0, =gUnknown_03001140 - ldr r1, [r0] - adds r0, r4, 0 - movs r2, 0x40 - bl memcpy - adds r0, r4, 0 - bl sub_8120B70 - ldr r1, =0x00001084 - adds r0, r5, r1 - ldr r1, =gUnknown_03001144 - ldr r1, [r1] - movs r2, 0x28 - bl memcpy - ldr r2, =0x000010ac - adds r4, r5, r2 - adds r0, r4, 0 - bl sub_80E89F8 - adds r0, r4, 0 - bl sub_80E8A54 - ldr r0, =gUnknown_0300114C - ldr r0, [r0] - ldr r1, =0x00001124 - adds r4, r5, r1 - adds r1, r4, 0 - bl sub_81659DC - adds r0, r4, 0 - bl TaskDummy4 - bl GetMultiplayerId - lsls r0, 24 - cmp r0, 0 - bne _080E6DEE - bl sub_81539D4 - ldr r2, =0x000011c8 - adds r1, r5, r2 - strh r0, [r1] -_080E6DEE: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E6D54 - thumb_func_start sub_80E6E24 sub_80E6E24: @ 80E6E24 push {r4,r5,lr} diff --git a/include/mauville_old_man.h b/include/mauville_old_man.h index aefc76083..25c5d8cd2 100644 --- a/include/mauville_old_man.h +++ b/include/mauville_old_man.h @@ -4,5 +4,6 @@ void SetMauvilleOldMan(void); u8 sub_81201C8(void); +void sub_8120B70(OldMan *dest); #endif // GUARD_MAUVILLE_OLD_MAN_H diff --git a/include/secret_base.h b/include/secret_base.h index 14defff26..d3ef57653 100644 --- a/include/secret_base.h +++ b/include/secret_base.h @@ -8,5 +8,6 @@ // Exported ROM declarations void sub_80E9578(void); void sub_80E980C(void); +void sub_80EB18C(struct SecretBaseRecord *dest); #endif //GUARD_SECRET_BASE_H diff --git a/include/tv.h b/include/tv.h index 43f36d69f..ea5bb726f 100644 --- a/include/tv.h +++ b/include/tv.h @@ -13,5 +13,6 @@ void sub_80EE184(void); void sub_80EEA70(void); void sub_80F14F8(TVShow *shows); size_t sub_80EF370(int value); +void sub_80F1208(TVShow *dest); #endif //GUARD_TV_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 06cf1ab2e..5b1f1c0c8 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -7,6 +7,8 @@ #include "tv.h" #include "battle_tower.h" #include "mystery_event_script.h" +#include "secret_base.h" +#include "mauville_old_man.h" #include "record_mixing.h" // Static type declarations @@ -50,6 +52,8 @@ EWRAM_DATA struct RecordMixingData *gUnknown_0203A018 = NULL; void sub_80E715C(u8 taskId); void sub_80E89F8(void *dest); +void sub_80E8A54(void *src); +void TaskDummy4(void *src); // .rodata @@ -89,3 +93,23 @@ void sub_80E6CA0(struct RecordMixingData *dest) dest->unk_11c8 = sub_81539D4(); } } + +void sub_80E6D54(struct RecordMixingData *dest) +{ + memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); + sub_80EB18C(dest->secretBases); + memcpy(dest->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); + sub_80F1208(dest->tvShows); + memcpy(dest->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); + memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); + sub_8120B70(&dest->oldMan); + memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); + sub_80E89F8(dest->unk_10ac); + sub_80E8A54(dest->unk_10ac); + sub_81659DC(gUnknown_0300114C, dest->unk_1124); + TaskDummy4(dest->unk_1124); + if (GetMultiplayerId() == 0) + { + dest->unk_11c8 = sub_81539D4(); + } +} From 1c3e7f169f26d471280a0f7aa1043dbd68e981c7 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 3 Nov 2017 22:26:12 -0400 Subject: [PATCH 04/26] sub_80E6E24 --- asm/record_mixing.s | 108 ---------------------------------------- include/global.h | 5 +- include/link.h | 2 + include/record_mixing.h | 2 + include/secret_base.h | 1 + include/tv.h | 1 + src/record_mixing.c | 47 ++++++++++++++++- 7 files changed, 54 insertions(+), 112 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index e7827f8a4..27aa86a2e 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,114 +5,6 @@ .text - thumb_func_start sub_80E6E24 -sub_80E6E24: @ 80E6E24 - push {r4,r5,lr} - bl sub_80E9914 - bl sub_80F0BB8 - bl sub_80E6BF8 - bl sub_800A064 - cmp r0, 0 - beq _080E6E60 - bl sub_800A03C - cmp r0, 0 - bne _080E6E50 - ldr r0, =gUnknown_0203A018 - ldr r0, [r0] - bl sub_80E6CA0 - b _080E6F12 - .pool -_080E6E50: - ldr r0, =gUnknown_0203A018 - ldr r0, [r0] - bl sub_80E6D54 - b _080E6F12 - .pool -_080E6E60: - ldr r5, =gUnknown_0203A018 - ldr r0, [r5] - ldr r1, =gUnknown_03001134 - ldr r1, [r1] - movs r4, 0xC8 - lsls r4, 4 - adds r2, r4, 0 - bl memcpy - ldr r0, [r5] - adds r0, r4 - ldr r1, =gUnknown_03001138 - ldr r1, [r1] - movs r2, 0xE1 - lsls r2, 2 - bl memcpy - ldr r0, [r5] - ldr r1, =0x00001004 - adds r0, r1 - ldr r1, =gUnknown_0300113C - ldr r1, [r1] - movs r2, 0x40 - bl memcpy - ldr r0, [r5] - ldr r2, =0x00001044 - adds r0, r2 - ldr r1, =gUnknown_03001140 - ldr r1, [r1] - movs r2, 0x40 - bl memcpy - ldr r0, [r5] - ldr r1, =0x00001214 - adds r0, r1 - ldr r1, =gUnknown_03001150 - ldr r1, [r1] - movs r2, 0x40 - bl memcpy - ldr r0, [r5] - ldr r2, =0x00001084 - adds r0, r2 - ldr r1, =gUnknown_03001144 - ldr r1, [r1] - movs r2, 0x28 - bl memcpy - ldr r0, [r5] - ldr r1, =0x000010ac - adds r0, r1 - bl sub_80E89F8 - ldr r0, [r5] - ldr r4, =0x00001124 - adds r0, r4 - ldr r1, =gUnknown_0300114C - ldr r1, [r1] - movs r2, 0xEC - bl memcpy - ldr r0, [r5] - adds r0, r4 - bl sub_80E8AC0 - bl GetMultiplayerId - lsls r0, 24 - cmp r0, 0 - bne _080E6EFA - bl sub_81539D4 - ldr r1, [r5] - ldr r2, =0x00001210 - adds r1, r2 - strh r0, [r1] -_080E6EFA: - ldr r0, [r5] - ldr r1, =0x00001254 - adds r0, r1 - ldr r1, =gUnknown_03001154 - ldr r1, [r1] - bl sub_80E8110 - ldr r0, [r5] - ldr r2, =0x000012dc - adds r0, r2 - bl sub_80E8260 -_080E6F12: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E6E24 - thumb_func_start sub_80E6F60 sub_80E6F60: @ 80E6F60 push {r4-r6,lr} diff --git a/include/global.h b/include/global.h index f3c58a3d8..8343f99f8 100644 --- a/include/global.h +++ b/include/global.h @@ -490,12 +490,13 @@ struct LilycoveLadyContest /*0x00e*/ u8 language; }; -typedef union // TODO +typedef union { struct LilycoveLadyQuiz quiz; struct LilycoveLadyFavour favour; struct LilycoveLadyContest contest; u8 id; + u8 pad[0x40]; } LilycoveLady; struct WaldaPhrase @@ -592,7 +593,7 @@ struct SaveBlock1 /*0x3B14*/ struct RecordMixingGift recordMixingGift; /*0x3B24*/ u8 seen2[52]; /*0x3B58*/ LilycoveLady lilycoveLady; - /*0x3B88*/ u8 filler_3B88[0x1E8]; + /*0x3B98*/ u8 filler_3B88[0x1D8]; /*0x3D70*/ struct WaldaPhrase waldaPhrase; // sizeof: 0x3D88 }; diff --git a/include/link.h b/include/link.h index 7a6563144..1bcdb047c 100644 --- a/include/link.h +++ b/include/link.h @@ -192,5 +192,7 @@ void sub_8011BD0(void); u8 sub_800ABAC(void); u8 sub_800ABBC(void); void sub_800AC34(void); +bool32 sub_800A064(void); +bool32 sub_800A03C(void); #endif // GUARD_LINK_H diff --git a/include/record_mixing.h b/include/record_mixing.h index 5ccbdc0dd..86e4b982e 100644 --- a/include/record_mixing.h +++ b/include/record_mixing.h @@ -16,4 +16,6 @@ struct DayCareMailRecordMixing { // Exported ROM declarations +void sub_80E8260(void *); + #endif //GUARD_RECORD_MIXING_H diff --git a/include/secret_base.h b/include/secret_base.h index d3ef57653..43ea66ebc 100644 --- a/include/secret_base.h +++ b/include/secret_base.h @@ -9,5 +9,6 @@ void sub_80E9578(void); void sub_80E980C(void); void sub_80EB18C(struct SecretBaseRecord *dest); +void sub_80E9914(void); #endif //GUARD_SECRET_BASE_H diff --git a/include/tv.h b/include/tv.h index ea5bb726f..9dc0f7719 100644 --- a/include/tv.h +++ b/include/tv.h @@ -14,5 +14,6 @@ void sub_80EEA70(void); void sub_80F14F8(TVShow *shows); size_t sub_80EF370(int value); void sub_80F1208(TVShow *dest); +void sub_80F0BB8(void); #endif //GUARD_TV_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 5b1f1c0c8..c8259e117 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -22,8 +22,13 @@ struct RecordMixingData { u8 unk_10ac[0x78]; u8 unk_1124[0xa4]; u16 unk_11c8; - u8 unk_11ca[0x27a]; -}; + u8 filler_11ca[0x46]; + u16 unk_1210; + u8 filler_1212[0x2]; + LilycoveLady lilycoveLady; + u8 unk_1254[0x88]; + u8 unk_12dc[0x168]; +}; // 1444 // Static RAM declarations @@ -54,6 +59,8 @@ void sub_80E715C(u8 taskId); void sub_80E89F8(void *dest); void sub_80E8A54(void *src); void TaskDummy4(void *src); +void sub_80E8AC0(void *); +void sub_80E8110(void *, void *); // .rodata @@ -113,3 +120,39 @@ void sub_80E6D54(struct RecordMixingData *dest) dest->unk_11c8 = sub_81539D4(); } } + +void sub_80E6E24(void) +{ + sub_80E9914(); + sub_80F0BB8(); + sub_80E6BF8(); + if (sub_800A064()) + { + if (sub_800A03C() == FALSE) + { + sub_80E6CA0(gUnknown_0203A018); + } + else + { + sub_80E6D54(gUnknown_0203A018); + } + } + else + { + memcpy(gUnknown_0203A018->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); + memcpy(gUnknown_0203A018->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); + memcpy(gUnknown_0203A018->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); + memcpy(&gUnknown_0203A018->oldMan, gUnknown_03001140, sizeof(OldMan)); + memcpy(&gUnknown_0203A018->lilycoveLady, gUnknown_03001150, sizeof(LilycoveLady)); + memcpy(gUnknown_0203A018->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); + sub_80E89F8(gUnknown_0203A018->unk_10ac); + memcpy(gUnknown_0203A018->unk_1124, gUnknown_0300114C, 0xec); + sub_80E8AC0(gUnknown_0203A018->unk_1124); + if (GetMultiplayerId() == 0) + { + gUnknown_0203A018->unk_1210 = sub_81539D4(); + } + sub_80E8110(gUnknown_0203A018->unk_1254, gUnknown_03001154); + sub_80E8260(gUnknown_0203A018->unk_12dc); + } +} From f5c1e190d1e8a50e9a5d27f2489d12167c193b61 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 09:39:41 -0400 Subject: [PATCH 05/26] sub_80E6F60 --- asm/record_mixing.s | 149 -------------------------------------------- src/record_mixing.c | 80 ++++++++++++++++++------ 2 files changed, 61 insertions(+), 168 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 27aa86a2e..bc1b27bd4 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,155 +5,6 @@ .text - thumb_func_start sub_80E6F60 -sub_80E6F60: @ 80E6F60 - push {r4-r6,lr} - mov r6, r8 - push {r6} - adds r4, r0, 0 - bl sub_800A064 - cmp r0, 0 - beq _080E7014 - ldr r5, =gUnknown_0203A014 - ldr r0, [r5] - movs r1, 0xC8 - lsls r1, 4 - mov r8, r1 - add r0, r8 - bl sub_80E7B2C - ldr r0, [r5] - ldr r6, =0x00001230 - lsls r4, 24 - lsrs r4, 24 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80EAF80 - ldr r3, [r5] - ldr r1, =0x000010ac - adds r0, r3, r1 - add r3, r8 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E7B60 - ldr r0, [r5] - ldr r1, =0x00001124 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E7948 - ldr r0, [r5] - add r0, r8 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80F01E8 - ldr r0, [r5] - ldr r1, =0x00001004 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80F0C7C - ldr r0, [r5] - ldr r1, =0x00001044 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E78C4 - ldr r0, [r5] - ldr r1, =0x00001084 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_812287C - ldr r0, [r5] - ldr r1, =0x000011c8 - adds r0, r1 - adds r1, r4, 0 - bl sub_80E7F68 - b _080E70BE - .pool -_080E7014: - ldr r5, =gUnknown_0203A014 - ldr r0, [r5] - movs r1, 0xC8 - lsls r1, 4 - mov r8, r1 - add r0, r8 - bl sub_80E7B2C - ldr r0, [r5] - ldr r6, =0x00001444 - lsls r4, 24 - lsrs r4, 24 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80EAF80 - ldr r0, [r5] - add r0, r8 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80F01E8 - ldr r0, [r5] - ldr r1, =0x00001004 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80F0C7C - ldr r0, [r5] - ldr r1, =0x00001044 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E78C4 - ldr r0, [r5] - ldr r1, =0x00001084 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_812287C - ldr r3, [r5] - ldr r1, =0x000010ac - adds r0, r3, r1 - add r3, r8 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E7B60 - ldr r0, [r5] - ldr r1, =0x00001124 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E7948 - ldr r0, [r5] - ldr r1, =0x00001210 - adds r0, r1 - adds r1, r4, 0 - bl sub_80E7F68 - ldr r0, [r5] - ldr r1, =0x00001214 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E7A14 - ldr r0, [r5] - ldr r1, =0x00001254 - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E8468 - ldr r0, [r5] - ldr r1, =0x000012dc - adds r0, r1 - adds r1, r6, 0 - adds r2, r4, 0 - bl sub_80E89AC -_080E70BE: - pop {r3} - mov r8, r3 - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E6F60 - thumb_func_start sub_80E70F4 sub_80E70F4: @ 80E70F4 push {r4,lr} diff --git a/src/record_mixing.c b/src/record_mixing.c index c8259e117..4853afb29 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -14,20 +14,19 @@ // Static type declarations struct RecordMixingData { - struct SecretBaseRecord secretBases[20]; - TVShow tvShows[25]; - PokeNews pokeNews[16]; - OldMan oldMan; - struct EasyChatPair easyChatPair[5]; - u8 unk_10ac[0x78]; - u8 unk_1124[0xa4]; - u16 unk_11c8; - u8 filler_11ca[0x46]; - u16 unk_1210; - u8 filler_1212[0x2]; - LilycoveLady lilycoveLady; - u8 unk_1254[0x88]; - u8 unk_12dc[0x168]; + /* 0x0000 */ struct SecretBaseRecord secretBases[20]; + /* 0x0c80 */ TVShow tvShows[25]; + /* 0x1004 */ PokeNews pokeNews[16]; + /* 0x1044 */ OldMan oldMan; + /* 0x1084 */ struct EasyChatPair easyChatPair[5]; + /* 0x10ac */ u8 unk_10ac[0x78]; + /* 0x1124 */ u8 unk_1124[0xa4]; + /* 0x11c8 */ u16 unk_11c8; + /* 0x11ca */ u8 filler_11ca[0x46]; + /* 0x1210 */ u16 unk_1210; + /* 0x1214 */ LilycoveLady lilycoveLady; + /* 0x1254 */ u8 unk_1254[0x88]; + /* 0x12dc */ u8 unk_12dc[0x168]; }; // 1444 // Static RAM declarations @@ -48,19 +47,29 @@ IWRAM_DATA u8 gUnknown_03001160[8]; IWRAM_DATA u32 gUnknown_03001168[3]; EWRAM_DATA struct DayCareMailRecordMixing gUnknown_02039F9C[2] = {}; -EWRAM_DATA struct { - /*0x0000*/ u8 filler_0000[0x5110]; -} *gUnknown_0203A014 = NULL; +EWRAM_DATA struct RecordMixingData *gUnknown_0203A014 = NULL; EWRAM_DATA struct RecordMixingData *gUnknown_0203A018 = NULL; // Static ROM declarations void sub_80E715C(u8 taskId); +void sub_80E78C4(OldMan *, size_t, u8); +void sub_80E7948(void *, size_t, u8); +void sub_80E7A14(LilycoveLady *, size_t, u8); +void sub_80E7B2C(TVShow *); +void sub_80E7B60(void *, size_t, u8, TVShow *); +void sub_80E7F68(void *, u8); +void sub_80E8110(void *, void *); +void sub_80E8468(void *, size_t, u8); +void sub_80E89AC(void *, size_t, u8); void sub_80E89F8(void *dest); void sub_80E8A54(void *src); -void TaskDummy4(void *src); void sub_80E8AC0(void *); -void sub_80E8110(void *, void *); +void sub_80EAF80(struct SecretBaseRecord *, size_t, u8); +void sub_80F01E8(void *, size_t, u8); +void sub_80F0C7C(PokeNews *, size_t, u8); +void sub_812287C(struct EasyChatPair *, size_t, u8); +void TaskDummy4(void *src); // .rodata @@ -156,3 +165,36 @@ void sub_80E6E24(void) sub_80E8260(gUnknown_0203A018->unk_12dc); } } + +void sub_80E6F60(u32 a0) +{ + if (sub_800A064()) + { + // Ruby/Sapphire + sub_80E7B2C(gUnknown_0203A014[0].tvShows); + sub_80EAF80(gUnknown_0203A014[0].secretBases, 0x1230, a0); + sub_80E7B60(gUnknown_0203A014[0].unk_10ac, 0x1230, a0, gUnknown_0203A014[0].tvShows); + sub_80E7948(gUnknown_0203A014[0].unk_1124, 0x1230, a0); + sub_80F01E8(gUnknown_0203A014[0].tvShows, 0x1230, a0); + sub_80F0C7C(gUnknown_0203A014[0].pokeNews, 0x1230, a0); + sub_80E78C4(&gUnknown_0203A014[0].oldMan, 0x1230, a0); + sub_812287C(gUnknown_0203A014[0].easyChatPair, 0x1230, a0); + sub_80E7F68(&gUnknown_0203A014[0].unk_11c8, a0); + } + else + { + // Emerald + sub_80E7B2C(gUnknown_0203A014[0].tvShows); + sub_80EAF80(gUnknown_0203A014[0].secretBases, 0x1444, a0); + sub_80F01E8(gUnknown_0203A014[0].tvShows, 0x1444, a0); + sub_80F0C7C(gUnknown_0203A014[0].pokeNews, 0x1444, a0); + sub_80E78C4(&gUnknown_0203A014[0].oldMan, 0x1444, a0); + sub_812287C(gUnknown_0203A014[0].easyChatPair, 0x1444, a0); + sub_80E7B60(gUnknown_0203A014[0].unk_10ac, 0x1444, a0, gUnknown_0203A014[0].tvShows); + sub_80E7948(gUnknown_0203A014[0].unk_1124, 0x1444, a0); + sub_80E7F68(&gUnknown_0203A014[0].unk_1210, a0); + sub_80E7A14(&gUnknown_0203A014[0].lilycoveLady, 0x1444, a0); + sub_80E8468(gUnknown_0203A014[0].unk_1254, 0x1444, a0); + sub_80E89AC(gUnknown_0203A014[0].unk_12dc, 0x1444, a0); + } +} From c05444679059e0692275781d065d36e79610cc4c Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 10:15:58 -0400 Subject: [PATCH 06/26] through sub_80E715C --- asm/cable_club.s | 2 +- asm/link.s | 26 +++-- asm/record_mixing.s | 241 +-------------------------------------- include/cable_club.h | 1 + include/field_screen.h | 1 + include/fldeff_80F9BCC.h | 2 + include/link.h | 3 +- include/overworld.h | 1 + include/strings.h | 1 + src/record_mixing.c | 114 ++++++++++++++++-- 10 files changed, 134 insertions(+), 258 deletions(-) diff --git a/asm/cable_club.s b/asm/cable_club.s index 15ba76e9c..80c177d20 100644 --- a/asm/cable_club.s +++ b/asm/cable_club.s @@ -795,7 +795,7 @@ sub_80B2A08: @ 80B2A08 ldrh r0, [r0] cmp r0, 0x4 bne _080B2A38 - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 bne _080B2A4A bl sub_800AC34 diff --git a/asm/link.s b/asm/link.s index 291f71a57..840b153e7 100644 --- a/asm/link.s +++ b/asm/link.s @@ -1394,8 +1394,10 @@ _08009FF4: bx r1 thumb_func_end GetLinkPlayerCount - thumb_func_start sub_8009FF8 -sub_8009FF8: @ 8009FF8 + thumb_func_start LinkPartnerVersionCheck +LinkPartnerVersionCheck: @ 8009FF8 +@ s32 LinkPartnerVersionCheck(u32 version1, u32 version2) +@ returns 1 if any link partners are playing either version1 or version2, -1 if no link partners are playing either version1 or version2 push {r4-r7,lr} adds r6, r0, 0 adds r5, r1, 0 @@ -1431,7 +1433,7 @@ _0800A034: pop {r4-r7} pop {r1} bx r1 - thumb_func_end sub_8009FF8 + thumb_func_end LinkPartnerVersionCheck thumb_func_start sub_800A03C sub_800A03C: @ 800A03C @@ -1439,8 +1441,8 @@ sub_800A03C: @ 800A03C bx lr thumb_func_end sub_800A03C - thumb_func_start sub_800A040 -sub_800A040: @ 800A040 + thumb_func_start Link_HaveFourPlayersWithAtLeastOneRubyOrSapphire +Link_HaveFourPlayersWithAtLeastOneRubyOrSapphire: @ 800A040 push {lr} bl GetLinkPlayerCount lsls r0, 24 @@ -1449,7 +1451,7 @@ sub_800A040: @ 800A040 bne _0800A05A movs r0, 0x2 movs r1, 0x1 - bl sub_8009FF8 + bl LinkPartnerVersionCheck cmp r0, 0 bge _0800A05E _0800A05A: @@ -1460,14 +1462,14 @@ _0800A05E: _0800A060: pop {r1} bx r1 - thumb_func_end sub_800A040 + thumb_func_end Link_HaveFourPlayersWithAtLeastOneRubyOrSapphire - thumb_func_start sub_800A064 -sub_800A064: @ 800A064 + thumb_func_start Link_AnyPartnersPlayingRubyOrSapphrie +Link_AnyPartnersPlayingRubyOrSapphrie: @ 800A064 push {lr} movs r0, 0x2 movs r1, 0x1 - bl sub_8009FF8 + bl LinkPartnerVersionCheck cmp r0, 0 bge _0800A076 movs r0, 0 @@ -1477,14 +1479,14 @@ _0800A076: _0800A078: pop {r1} bx r1 - thumb_func_end sub_800A064 + thumb_func_end Link_AnyPartnersPlayingRubyOrSapphrie thumb_func_start sub_800A07C sub_800A07C: @ 800A07C push {lr} movs r0, 0x4 movs r1, 0x5 - bl sub_8009FF8 + bl LinkPartnerVersionCheck adds r2, r0, 0 cmp r2, 0 blt _0800A0A4 diff --git a/asm/record_mixing.s b/asm/record_mixing.s index bc1b27bd4..ebfc0eff4 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,237 +5,6 @@ .text - thumb_func_start sub_80E70F4 -sub_80E70F4: @ 80E70F4 - push {r4,lr} - sub sp, 0xC - adds r4, r0, 0 - movs r0, 0 - movs r1, 0 - bl sub_81973C4 - movs r0, 0x1 - str r0, [sp] - movs r0, 0 - str r0, [sp, 0x4] - str r0, [sp, 0x8] - movs r1, 0x1 - adds r2, r4, 0 - movs r3, 0 - bl PrintTextOnWindow - movs r0, 0 - movs r1, 0x3 - bl CopyWindowToVram - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - thumb_func_end sub_80E70F4 - - thumb_func_start sub_80E7128 -sub_80E7128: @ 80E7128 - push {r4,lr} - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r4, r1, r2 - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x32 - bne _080E7150 - movs r0, 0xE2 - bl PlaySE - movs r0, 0 - strh r0, [r4, 0x8] -_080E7150: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7128 - - thumb_func_start sub_80E715C -sub_80E715C: @ 80E715C - push {r4,r5,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - ldr r1, =gTasks + 0x8 - adds r5, r0, r1 - movs r1, 0 - ldrsh r0, [r5, r1] - cmp r0, 0x5 - bls _080E7176 - b _080E730A -_080E7176: - lsls r0, 2 - ldr r1, =_080E7188 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_080E7188: - .4byte _080E71A0 - .4byte _080E7218 - .4byte _080E724C - .4byte _080E726C - .4byte _080E72AC - .4byte _080E72C0 -_080E71A0: - ldr r4, =gUnknown_0203A018 - ldr r0, =0x00001444 - bl Alloc - str r0, [r4] - ldr r4, =gUnknown_0203A014 - ldr r0, =0x00005110 - bl Alloc - str r0, [r4] - ldr r0, =gSpecialVar_0x8005 - ldrb r0, [r0] - bl sub_8009628 - movs r0, 0x80 - lsls r0, 7 - movs r1, 0x1 - bl VarSet - ldr r1, =gUnknown_03001130 - movs r0, 0 - strb r0, [r1] - bl sub_80E6E24 - bl sub_80FB00C - movs r0, 0x1 - strh r0, [r5] - ldr r0, =sub_80E7324 - movs r1, 0x50 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x14] - ldr r0, =sub_80E7128 - movs r1, 0x51 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x1E] - b _080E730A - .pool -_080E7218: - ldr r2, =gTasks - movs r0, 0x14 - ldrsh r1, [r5, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r0, [r0, 0x4] - cmp r0, 0 - bne _080E730A - movs r0, 0x2 - strh r0, [r5] - ldr r0, =0x00000894 - bl FlagSet - bl sub_80FB074 - ldrb r0, [r5, 0x1E] - bl DestroyTask - b _080E730A - .pool -_080E724C: - ldr r0, =sub_80E7FF8 - movs r1, 0xA - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x14] - movs r0, 0x3 - strh r0, [r5] - movs r0, 0xE0 - bl PlaySE - b _080E730A - .pool -_080E726C: - ldr r2, =gTasks - movs r0, 0x14 - ldrsh r1, [r5, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r4, [r0, 0x4] - cmp r4, 0 - bne _080E730A - movs r0, 0x4 - strh r0, [r5] - ldr r0, =gLinkVSyncDisabled - ldrb r0, [r0] - cmp r0, 0 - bne _080E7296 - bl sub_80B3050 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x14] -_080E7296: - ldr r0, =gText_RecordMixingComplete - bl sub_80E70F4 - strh r4, [r5, 0x10] - b _080E730A - .pool -_080E72AC: - ldrh r0, [r5, 0x10] - adds r0, 0x1 - strh r0, [r5, 0x10] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x3C - ble _080E730A - movs r0, 0x5 - strh r0, [r5] - b _080E730A -_080E72C0: - ldr r2, =gTasks - movs r0, 0x14 - ldrsh r1, [r5, r0] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r0, [r0, 0x4] - cmp r0, 0 - bne _080E730A - ldr r0, =gUnknown_0203A014 - ldr r0, [r0] - bl Free - ldr r0, =gUnknown_0203A018 - ldr r0, [r0] - bl Free - bl sub_808729C - ldr r0, =gLinkVSyncDisabled - ldrb r0, [r0] - cmp r0, 0 - beq _080E72F8 - ldr r0, =sub_80AF2B4 - movs r1, 0xA - bl CreateTask -_080E72F8: - movs r0, 0 - movs r1, 0x1 - bl sub_8197434 - adds r0, r4, 0 - bl DestroyTask - bl EnableBothScriptContexts -_080E730A: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E715C - thumb_func_start sub_80E7324 sub_80E7324: @ 80E7324 push {r4-r6,lr} @@ -431,7 +200,7 @@ _080E7490: strh r0, [r5, 0x12] ldr r0, =sub_80E756C str r0, [r5] - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 beq _080E7504 ldr r0, =gUnknown_0203A018 @@ -963,7 +732,7 @@ sub_80E78C4: @ 80E78C4 adds r0, r2 ldrb r4, [r0] ldrh r5, [r0, 0x1A] - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 beq _080E7910 adds r0, r6, 0 @@ -1013,7 +782,7 @@ sub_80E7948: @ 80E7948 lsrs r6, r2, 24 mov r0, sp bl sub_80E7830 - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 beq _080E79AC lsls r0, r6, 2 @@ -1330,7 +1099,7 @@ _080E7BB0: mov r8, r0 cmp r0, 0x3 bls _080E7BB0 - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie str r0, [sp, 0x3C] movs r2, 0 mov r8, r2 @@ -1887,7 +1656,7 @@ _080E8024: .4byte _080E80EE .4byte _080E80FA _080E804C: - bl sub_800A064 + bl Link_AnyPartnersPlayingRubyOrSapphrie cmp r0, 0 bne _080E80F2 movs r0, 0x6 diff --git a/include/cable_club.h b/include/cable_club.h index adb0c4f90..44831235c 100644 --- a/include/cable_club.h +++ b/include/cable_club.h @@ -8,5 +8,6 @@ // Exported ROM declarations void sub_80B37D4(TaskFunc taskFunc); +u8 sub_80B3050(void); #endif //GUARD_CABLE_CLUB_H diff --git a/include/field_screen.h b/include/field_screen.h index 089e79cc4..6e33a8b7b 100644 --- a/include/field_screen.h +++ b/include/field_screen.h @@ -9,5 +9,6 @@ void pal_fill_black(void); bool8 sub_80ABDFC(void); void sub_80AF168(void); +void sub_80AF2B4(u8 taskId); #endif //GUARD_FIELD_SCREEN_H diff --git a/include/fldeff_80F9BCC.h b/include/fldeff_80F9BCC.h index ecce04943..aae4751c1 100644 --- a/include/fldeff_80F9BCC.h +++ b/include/fldeff_80F9BCC.h @@ -9,5 +9,7 @@ void sub_80FA5E4(s16 id, s16 x, s16 y); void sub_80FA794(s16 x, s16 y); +void sub_80FB00C(void); +void sub_80FB074(void); #endif //GUARD_FLDEFF_80F9BCC_H diff --git a/include/link.h b/include/link.h index 1bcdb047c..6e60a1a84 100644 --- a/include/link.h +++ b/include/link.h @@ -192,7 +192,8 @@ void sub_8011BD0(void); u8 sub_800ABAC(void); u8 sub_800ABBC(void); void sub_800AC34(void); -bool32 sub_800A064(void); +bool32 Link_AnyPartnersPlayingRubyOrSapphrie(void); bool32 sub_800A03C(void); +void sub_8009628(u8); #endif // GUARD_LINK_H diff --git a/include/overworld.h b/include/overworld.h index 19bcaaf01..63c54eee3 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -64,5 +64,6 @@ void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpNum); void c2_load_new_map(void); void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); void mapldr_default(void); +void sub_808729C(void); #endif //GUARD_ROM4_H diff --git a/include/strings.h b/include/strings.h index fcdb1eca4..735fc1f1c 100644 --- a/include/strings.h +++ b/include/strings.h @@ -75,5 +75,6 @@ extern const u8 gText_NoRegistry[]; extern const u8 gText_OkayToDeleteFromRegistry[]; extern const u8 gText_RegisteredDataDeleted[]; extern const u8 gUnknown_085EA79D[]; +extern const u8 gText_RecordMixingComplete[]; #endif //GUARD_STRINGS_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 4853afb29..902dcde1d 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -1,19 +1,30 @@ // Includes #include "global.h" +#include "malloc.h" #include "task.h" #include "cable_club.h" #include "link.h" #include "tv.h" #include "battle_tower.h" +#include "new_menu_helpers.h" +#include "window.h" #include "mystery_event_script.h" #include "secret_base.h" #include "mauville_old_man.h" +#include "sound.h" +#include "songs.h" +#include "overworld.h" +#include "field_screen.h" +#include "fldeff_80F9BCC.h" +#include "script.h" +#include "event_data.h" +#include "strings.h" #include "record_mixing.h" // Static type declarations -struct RecordMixingData { +struct PlayerRecords { /* 0x0000 */ struct SecretBaseRecord secretBases[20]; /* 0x0c80 */ TVShow tvShows[25]; /* 0x1004 */ PokeNews pokeNews[16]; @@ -47,18 +58,20 @@ IWRAM_DATA u8 gUnknown_03001160[8]; IWRAM_DATA u32 gUnknown_03001168[3]; EWRAM_DATA struct DayCareMailRecordMixing gUnknown_02039F9C[2] = {}; -EWRAM_DATA struct RecordMixingData *gUnknown_0203A014 = NULL; -EWRAM_DATA struct RecordMixingData *gUnknown_0203A018 = NULL; +EWRAM_DATA struct PlayerRecords *gUnknown_0203A014 = NULL; +EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; // Static ROM declarations -void sub_80E715C(u8 taskId); +static void sub_80E715C(u8 taskId); +void sub_80E7324(u8 taskId); void sub_80E78C4(OldMan *, size_t, u8); void sub_80E7948(void *, size_t, u8); void sub_80E7A14(LilycoveLady *, size_t, u8); void sub_80E7B2C(TVShow *); void sub_80E7B60(void *, size_t, u8, TVShow *); void sub_80E7F68(void *, u8); +void sub_80E7FF8(u8 taskId); void sub_80E8110(void *, void *); void sub_80E8468(void *, size_t, u8); void sub_80E89AC(void *, size_t, u8); @@ -94,7 +107,7 @@ void sub_80E6BF8(void) gUnknown_03001158 = gSaveBlock2Ptr->field_64C; } -void sub_80E6CA0(struct RecordMixingData *dest) +void sub_80E6CA0(struct PlayerRecords *dest) { memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); memcpy(dest->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); @@ -110,7 +123,7 @@ void sub_80E6CA0(struct RecordMixingData *dest) } } -void sub_80E6D54(struct RecordMixingData *dest) +void sub_80E6D54(struct PlayerRecords *dest) { memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); sub_80EB18C(dest->secretBases); @@ -135,7 +148,7 @@ void sub_80E6E24(void) sub_80E9914(); sub_80F0BB8(); sub_80E6BF8(); - if (sub_800A064()) + if (Link_AnyPartnersPlayingRubyOrSapphrie()) { if (sub_800A03C() == FALSE) { @@ -168,7 +181,7 @@ void sub_80E6E24(void) void sub_80E6F60(u32 a0) { - if (sub_800A064()) + if (Link_AnyPartnersPlayingRubyOrSapphrie()) { // Ruby/Sapphire sub_80E7B2C(gUnknown_0203A014[0].tvShows); @@ -198,3 +211,88 @@ void sub_80E6F60(u32 a0) sub_80E89AC(gUnknown_0203A014[0].unk_12dc, 0x1444, a0); } } + +void sub_80E70F4(const u8 *src) +{ + sub_81973C4(0, 0); + PrintTextOnWindow(0, 1, src, 0, 1, 0, NULL); + CopyWindowToVram(0, 3); +} + +void sub_80E7128(u8 taskId) +{ + if (++ gTasks[taskId].data[0] == 50) + { + PlaySE(SE_W213); + gTasks[taskId].data[0] = 0; + } +} + +static void sub_80E715C(u8 taskId) +{ + s16 *data; + + data = gTasks[taskId].data; + switch (data[0]) + { + case 0: + gUnknown_0203A018 = malloc(sizeof(struct PlayerRecords)); + gUnknown_0203A014 = malloc(sizeof(struct PlayerRecords) * 4); + sub_8009628(gSpecialVar_0x8005); + VarSet(VAR_0x4000, 1); + gUnknown_03001130 = FALSE; + sub_80E6E24(); + sub_80FB00C(); + data[0] = 1; + data[10] = CreateTask(sub_80E7324, 80); + data[15] = CreateTask(sub_80E7128, 81); + break; + case 1: + if (!gTasks[data[10]].isActive) + { + data[0] = 2; + FlagSet(SYS_MIX_RECORD); + sub_80FB074(); + DestroyTask(data[15]); + } + break; + case 2: + data[10] = CreateTask(sub_80E7FF8, 10); + data[0] = 3; + PlaySE(SE_W226); + break; + case 3: + if (!gTasks[data[10]].isActive) + { + data[0] = 4; + if (!gLinkVSyncDisabled) + { + data[10] = sub_80B3050(); + } + sub_80E70F4(gText_RecordMixingComplete); + data[8] = 0; + } + break; + case 4: + if (++ data[8] > 60) + { + data[0] = 5; + } + break; + case 5: + if (!gTasks[data[10]].isActive) + { + free(gUnknown_0203A014); + free(gUnknown_0203A018); + sub_808729C(); + if (gLinkVSyncDisabled) + { + CreateTask(sub_80AF2B4, 10); + } + sub_8197434(0, 1); + DestroyTask(taskId); + EnableBothScriptContexts(); + } + break; + } +} From 411cb29f4ab513da00d15ff16fc98fed8b31dfdb Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 10:55:39 -0400 Subject: [PATCH 07/26] sub_80E7324 --- asm/record_mixing.s | 270 -------------------------------------------- include/link.h | 2 + include/strings.h | 1 + src/record_mixing.c | 107 +++++++++++++++++- 4 files changed, 109 insertions(+), 271 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index ebfc0eff4..634e7fc4f 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,276 +5,6 @@ .text - thumb_func_start sub_80E7324 -sub_80E7324: @ 80E7324 - push {r4-r6,lr} - lsls r0, 24 - lsrs r4, r0, 24 - lsls r0, r4, 2 - adds r0, r4 - lsls r0, 3 - ldr r6, =gTasks - adds r5, r0, r6 - movs r0, 0x8 - ldrsh r1, [r5, r0] - cmp r1, 0x64 - beq _080E73A0 - cmp r1, 0x64 - bgt _080E7362 - cmp r1, 0x1 - bne _080E7346 - b _080E7464 -_080E7346: - cmp r1, 0x1 - bgt _080E7354 - cmp r1, 0 - beq _080E7384 - b _080E7566 - .pool -_080E7354: - cmp r1, 0x2 - bne _080E735A - b _080E7490 -_080E735A: - cmp r1, 0x5 - bne _080E7360 - b _080E7550 -_080E7360: - b _080E7566 -_080E7362: - cmp r1, 0xC9 - beq _080E73F8 - cmp r1, 0xC9 - bgt _080E7370 - cmp r1, 0x65 - beq _080E73B8 - b _080E7566 -_080E7370: - ldr r0, =0x0000012d - cmp r1, r0 - beq _080E7432 - adds r0, 0x63 - cmp r1, r0 - beq _080E744A - b _080E7566 - .pool -_080E7384: - ldr r0, =gText_MixingRecords - bl sub_80E70F4 - movs r0, 0xE1 - lsls r0, 3 - strh r0, [r5, 0x18] - movs r0, 0xC8 - lsls r0, 1 - strh r0, [r5, 0x8] - bl sub_8009FAC - b _080E7566 - .pool -_080E73A0: - ldrh r0, [r5, 0x20] - adds r0, 0x1 - strh r0, [r5, 0x20] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x14 - bgt _080E73B0 - b _080E7566 -_080E73B0: - movs r0, 0 - strh r0, [r5, 0x20] - movs r0, 0x65 - b _080E7564 -_080E73B8: - bl sub_800ABAC - lsls r0, 24 - lsrs r4, r0, 24 - bl sub_800ABBC - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x1 - bne _080E73EA - bl sub_800AA48 - lsls r0, 24 - lsrs r0, 24 - cmp r4, r0 - beq _080E73DA - b _080E7566 -_080E73DA: - movs r0, 0x15 - bl PlaySE - movs r1, 0 - movs r0, 0xC9 - strh r0, [r5, 0x8] - strh r1, [r5, 0x20] - b _080E7566 -_080E73EA: - movs r0, 0x16 - bl PlaySE - ldr r0, =0x0000012d - b _080E7564 - .pool -_080E73F8: - bl sub_800AA48 - adds r4, r0, 0 - bl sub_800ABAC - lsls r4, 24 - lsls r0, 24 - cmp r4, r0 - beq _080E740C - b _080E7566 -_080E740C: - ldrh r4, [r5, 0x20] - adds r4, 0x1 - strh r4, [r5, 0x20] - lsls r4, 16 - asrs r4, 16 - bl sub_800ABAC - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 4 - subs r1, r0 - lsls r1, 1 - cmp r4, r1 - bgt _080E742A - b _080E7566 -_080E742A: - bl sub_800A620 - movs r0, 0x1 - b _080E7564 -_080E7432: - bl sub_800AA48 - adds r4, r0, 0 - bl sub_800ABAC - lsls r4, 24 - lsls r0, 24 - cmp r4, r0 - beq _080E7446 - b _080E7566 -_080E7446: - movs r0, 0x1 - b _080E7564 -_080E744A: - ldrh r0, [r5, 0x20] - adds r0, 0x1 - strh r0, [r5, 0x20] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x14 - bgt _080E745A - b _080E7566 -_080E745A: - movs r0, 0x1 - strh r0, [r5, 0x8] - movs r0, 0 - strh r0, [r5, 0x20] - b _080E7566 -_080E7464: - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0 - bne _080E746E - b _080E7566 -_080E746E: - ldr r4, =gStringVar1 - bl sub_80E7810 - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - movs r2, 0x2 - movs r3, 0x2 - bl ConvertIntToDecimalStringN - movs r0, 0x5 - b _080E7564 - .pool -_080E7490: - bl sub_800ABAC - lsls r0, 24 - lsrs r0, 24 - movs r1, 0 - strh r0, [r5, 0x14] - strh r1, [r5, 0x8] - bl sub_80E7810 - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x12] - ldr r0, =sub_80E756C - str r0, [r5] - bl Link_AnyPartnersPlayingRubyOrSapphrie - cmp r0, 0 - beq _080E7504 - ldr r0, =gUnknown_0203A018 - ldr r0, [r0] - adds r1, r5, 0 - adds r1, 0xC - bl sub_80E7808 - ldr r0, =sub_80E7630 - movs r1, 0x50 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x1C] - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r0, r1, r6 - strh r4, [r0, 0x8] - ldr r0, =gUnknown_0203A014 - ldr r0, [r0] - adds r1, r6, r1 - adds r1, 0x12 - bl sub_80E7808 - ldr r1, =gUnknown_0300115C - ldr r0, =0x00001230 - str r0, [r1] - b _080E7566 - .pool -_080E7504: - ldr r0, =gUnknown_0203A018 - ldr r0, [r0] - adds r1, r5, 0 - adds r1, 0xC - bl sub_80E7808 - ldr r0, =sub_80E7630 - movs r1, 0x50 - bl CreateTask - lsls r0, 24 - lsrs r0, 24 - strh r0, [r5, 0x1C] - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r0, r1, r6 - strh r4, [r0, 0x8] - ldr r0, =gUnknown_0203A014 - ldr r0, [r0] - adds r1, r6, r1 - adds r1, 0x12 - bl sub_80E7808 - ldr r1, =gUnknown_0300115C - ldr r0, =0x00001444 - str r0, [r1] - b _080E7566 - .pool -_080E7550: - ldrh r0, [r5, 0x1C] - adds r0, 0x1 - strh r0, [r5, 0x1C] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0x3C - ble _080E7566 - movs r0, 0 - strh r0, [r5, 0x1C] - movs r0, 0x2 -_080E7564: - strh r0, [r5, 0x8] -_080E7566: - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_80E7324 - thumb_func_start sub_80E756C sub_80E756C: @ 80E756C push {r4,r5,lr} diff --git a/include/link.h b/include/link.h index 6e60a1a84..8cd2ee72e 100644 --- a/include/link.h +++ b/include/link.h @@ -195,5 +195,7 @@ void sub_800AC34(void); bool32 Link_AnyPartnersPlayingRubyOrSapphrie(void); bool32 sub_800A03C(void); void sub_8009628(u8); +u8 sub_800AA48(void); +void sub_8009FAC(void); #endif // GUARD_LINK_H diff --git a/include/strings.h b/include/strings.h index 735fc1f1c..7ba979cdc 100644 --- a/include/strings.h +++ b/include/strings.h @@ -75,6 +75,7 @@ extern const u8 gText_NoRegistry[]; extern const u8 gText_OkayToDeleteFromRegistry[]; extern const u8 gText_RegisteredDataDeleted[]; extern const u8 gUnknown_085EA79D[]; +extern const u8 gText_MixingRecords[]; extern const u8 gText_RecordMixingComplete[]; #endif //GUARD_STRINGS_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 902dcde1d..c57dc9dae 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -20,6 +20,7 @@ #include "script.h" #include "event_data.h" #include "strings.h" +#include "string_util.h" #include "record_mixing.h" // Static type declarations @@ -64,7 +65,11 @@ EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; // Static ROM declarations static void sub_80E715C(u8 taskId); -void sub_80E7324(u8 taskId); +static void sub_80E7324(u8 taskId); +void sub_80E756C(u8 taskId); +void sub_80E7630(u8 taskId); +u8 sub_80E7810(void); +void sub_80E7808(struct PlayerRecords *records, s16 *a1); void sub_80E78C4(OldMan *, size_t, u8); void sub_80E7948(void *, size_t, u8); void sub_80E7A14(LilycoveLady *, size_t, u8); @@ -296,3 +301,103 @@ static void sub_80E715C(u8 taskId) break; } } + +static void sub_80E7324(u8 taskId) +{ + u8 r4; + u8 taskId2; + struct Task *task; + + task = &gTasks[taskId]; + switch (task->data[0]) + { + case 0: + sub_80E70F4(gText_MixingRecords); + task->data[8] = 0x708; + task->data[0] = 400; + sub_8009FAC(); + break; + case 100: + if (++ task->data[12] > 20) + { + task->data[12] = 0; + task->data[0] = 101; + } + break; + case 101: + r4 = sub_800ABAC(); + if (sub_800ABBC() == TRUE) + { + if (r4 == sub_800AA48()) + { + PlaySE(SE_PIN); + task->data[0] = 201; + task->data[12] = 0; + } + } + else + { + PlaySE(SE_BOO); + task->data[0] = 301; + } + break; + case 201: + if (sub_800AA48() == sub_800ABAC() && ++ task->data[12] > (sub_800ABAC() * 30)) + { + sub_800A620(); + task->data[0] = 1; + } + break; + case 301: + if (sub_800AA48() == sub_800ABAC()) + { + task->data[0] = 1; + } + break; + case 400: + if (++ task->data[12] > 20) + { + task->data[0] = 1; + task->data[12] = 0; + } + break; + case 1: + if (gReceivedRemoteLinkPlayers != 0) + { + ConvertIntToDecimalStringN(gStringVar1, sub_80E7810(), STR_CONV_MODE_LEADING_ZEROS, 2); + task->data[0] = 5; + } + break; + case 2: + task->data[6] = sub_800ABAC(); + task->data[0] = 0; + task->data[5] = sub_80E7810(); + task->func = sub_80E756C; + if (Link_AnyPartnersPlayingRubyOrSapphrie()) + { + sub_80E7808(gUnknown_0203A018, &task->data[2]); + taskId2 = CreateTask(sub_80E7630, 80); + task->data[10] = taskId2; + gTasks[taskId2].data[0] = taskId; + sub_80E7808(gUnknown_0203A014, &gTasks[taskId2].data[5]); + gUnknown_0300115C = 0x1230; + } + else + { + sub_80E7808(gUnknown_0203A018, &task->data[2]); + taskId2 = CreateTask(sub_80E7630, 80); + task->data[10] = taskId2; + gTasks[taskId2].data[0] = taskId; + sub_80E7808(gUnknown_0203A014, &gTasks[taskId2].data[5]); + gUnknown_0300115C = 0x1444; + } + break; + case 5: + if (++ task->data[10] > 60) + { + task->data[10] = 0; + task->data[0] = 2; + } + break; + } +} From 6c746425ed48ba6d4d6519959b13914192da95b7 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 11:16:07 -0400 Subject: [PATCH 08/26] sub_80E756C --- asm/record_mixing.s | 93 --------------------------------------------- include/link.h | 3 ++ src/record_mixing.c | 46 +++++++++++++++++++++- 3 files changed, 48 insertions(+), 94 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 634e7fc4f..77a4d5a51 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,99 +5,6 @@ .text - thumb_func_start sub_80E756C -sub_80E756C: @ 80E756C - push {r4,r5,lr} - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - ldr r0, =gTasks - adds r5, r1, r0 - movs r2, 0x8 - ldrsh r1, [r5, r2] - adds r2, r0, 0 - cmp r1, 0x4 - bhi _080E7624 - lsls r0, r1, 2 - ldr r1, =_080E7598 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_080E7598: - .4byte _080E75AC - .4byte _080E75D0 - .4byte _080E7624 - .4byte _080E75E2 - .4byte _080E760E -_080E75AC: - adds r0, r5, 0 - adds r0, 0xC - bl sub_80E77FC - adds r1, r0, 0 - movs r0, 0x10 - ldrsh r2, [r5, r0] - movs r0, 0xC8 - muls r0, r2 - adds r1, r0 - ldr r0, =gUnknown_020228C4 - movs r2, 0xC8 - bl memcpy - b _080E75FC - .pool -_080E75D0: - bl GetMultiplayerId - lsls r0, 24 - cmp r0, 0 - bne _080E75FC - movs r0, 0x1 - bl sub_800A4D8 - b _080E75FC -_080E75E2: - ldrh r0, [r5, 0x10] - adds r0, 0x1 - strh r0, [r5, 0x10] - movs r1, 0x10 - ldrsh r4, [r5, r1] - ldr r0, =gUnknown_0300115C - ldr r0, [r0] - movs r1, 0xC8 - bl __udivsi3 - adds r0, 0x1 - cmp r4, r0 - bne _080E7608 -_080E75FC: - ldrh r0, [r5, 0x8] - adds r0, 0x1 - strh r0, [r5, 0x8] - b _080E7624 - .pool -_080E7608: - movs r0, 0 - strh r0, [r5, 0x8] - b _080E7624 -_080E760E: - movs r1, 0x1C - ldrsh r0, [r5, r1] - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r1, r2 - ldrb r0, [r1, 0x4] - cmp r0, 0 - bne _080E7624 - ldr r0, =sub_80E77D4 - str r0, [r5] -_080E7624: - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E756C - thumb_func_start sub_80E7630 sub_80E7630: @ 80E7630 push {r4-r7,lr} diff --git a/include/link.h b/include/link.h index 8cd2ee72e..79ec62961 100644 --- a/include/link.h +++ b/include/link.h @@ -6,6 +6,8 @@ #define QUEUE_CAPACITY 50 #define BLOCK_BUFFER_SIZE 0x100 +#define gBlockSendBuffer gUnknown_020228C4 // FIXME + #define LINK_STAT_LOCAL_ID 0x00000003 #define LINK_STAT_PLAYER_COUNT 0x0000001C #define LINK_STAT_PLAYER_COUNT_SHIFT 2 @@ -197,5 +199,6 @@ bool32 sub_800A03C(void); void sub_8009628(u8); u8 sub_800AA48(void); void sub_8009FAC(void); +void sub_800A4D8(u8); #endif // GUARD_LINK_H diff --git a/src/record_mixing.c b/src/record_mixing.c index c57dc9dae..9dd3be0fe 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -66,8 +66,10 @@ EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; static void sub_80E715C(u8 taskId); static void sub_80E7324(u8 taskId); -void sub_80E756C(u8 taskId); +static void sub_80E756C(u8 taskId); void sub_80E7630(u8 taskId); +void sub_80E77D4(u8 taskId); +void *sub_80E77FC(s16 *asShort); u8 sub_80E7810(void); void sub_80E7808(struct PlayerRecords *records, s16 *a1); void sub_80E78C4(OldMan *, size_t, u8); @@ -401,3 +403,45 @@ static void sub_80E7324(u8 taskId) break; } } + +static void sub_80E756C(u8 taskId) +{ + struct Task *task; + void *dest; + + task = &gTasks[taskId]; + switch (task->data[0]) + { + case 0: + dest = sub_80E77FC(&task->data[2]) + task->data[4] * 200; + memcpy(gBlockSendBuffer, dest, 200); + task->data[0] ++; + break; + case 1: + if (GetMultiplayerId() == 0) + { + sub_800A4D8(1); + } + task->data[0] ++; + break; + case 2: + break; + case 3: + task->data[4] ++; + if (task->data[4] == gUnknown_0300115C / 200 + 1) + { + task->data[0] ++; + } + else + { + task->data[0] = 0; + } + break; + case 4: + if (!gTasks[task->data[10]].isActive) + { + task->func = sub_80E77D4; + } + break; + } +} From d921e555d20151c420eb0dab03913125a7bbf1fb Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 11:39:23 -0400 Subject: [PATCH 09/26] sub_80E7630 --- asm/record_mixing.s | 151 -------------------------------------------- include/link.h | 1 + src/record_mixing.c | 47 +++++++++++++- 3 files changed, 47 insertions(+), 152 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 77a4d5a51..e3e818a7e 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,157 +5,6 @@ .text - thumb_func_start sub_80E7630 -sub_80E7630: @ 80E7630 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - lsls r0, 2 - ldr r1, [sp] - adds r0, r1 - lsls r0, 3 - ldr r1, =gTasks - adds r0, r1 - mov r10, r0 - bl GetBlockReceivedStatus - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x4] - movs r2, 0 - str r2, [sp, 0x8] - bl sub_800A9D8 - lsls r0, 24 - lsrs r0, 24 - ldr r3, [sp, 0x4] - cmp r3, r0 - bne _080E773E - movs r4, 0 - mov r8, r4 - b _080E771C - .pool -_080E7678: - ldr r1, [sp, 0x4] - mov r0, r8 - asrs r1, r0 - movs r0, 0x1 - ands r1, r0 - movs r2, 0x1 - add r2, r8 - mov r9, r2 - cmp r1, 0 - beq _080E7714 - mov r0, r10 - adds r0, 0x12 - bl sub_80E77FC - mov r3, r9 - lsls r4, r3, 1 - mov r5, r10 - adds r5, 0x8 - adds r4, r5, r4 - movs r2, 0 - ldrsh r1, [r4, r2] - movs r7, 0xC8 - muls r1, r7 - adds r0, r1 - ldr r3, =gUnknown_0300115C - ldr r1, [r3] - mov r2, r8 - muls r2, r1 - adds r1, r2, 0 - adds r6, r0, r1 - mov r0, r8 - bl sub_80E7820 - adds r1, r0, 0 - movs r3, 0 - ldrsh r2, [r4, r3] - adds r0, r2, 0x1 - muls r0, r7 - ldr r4, =gUnknown_0300115C - ldr r3, [r4] - cmp r0, r3 - bls _080E76DC - muls r2, r7 - subs r2, r3, r2 - adds r0, r6, 0 - bl memcpy - b _080E76E4 - .pool -_080E76DC: - adds r0, r6, 0 - movs r2, 0xC8 - bl memcpy -_080E76E4: - mov r0, r8 - bl ResetBlockReceivedFlag - mov r0, r9 - lsls r1, r0, 1 - adds r1, r5, r1 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - movs r2, 0 - ldrsh r4, [r1, r2] - ldr r3, =gUnknown_0300115C - ldr r0, [r3] - movs r1, 0xC8 - bl __udivsi3 - adds r0, 0x1 - cmp r4, r0 - bne _080E7714 - ldr r0, [sp, 0x8] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x8] -_080E7714: - mov r4, r9 - lsls r0, r4, 24 - lsrs r0, 24 - mov r8, r0 -_080E771C: - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - cmp r8, r0 - bcc _080E7678 - ldr r2, =gTasks - mov r0, r10 - movs r3, 0x8 - ldrsh r1, [r0, r3] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrh r1, [r0, 0x8] - adds r1, 0x1 - strh r1, [r0, 0x8] -_080E773E: - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - ldr r4, [sp, 0x8] - cmp r4, r0 - bne _080E7752 - ldr r0, [sp] - bl DestroyTask -_080E7752: - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7630 - thumb_func_start sub_80E776C sub_80E776C: @ 80E776C push {r4,lr} diff --git a/include/link.h b/include/link.h index 79ec62961..04a7d3864 100644 --- a/include/link.h +++ b/include/link.h @@ -200,5 +200,6 @@ void sub_8009628(u8); u8 sub_800AA48(void); void sub_8009FAC(void); void sub_800A4D8(u8); +u8 sub_800A9D8(void); #endif // GUARD_LINK_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 9dd3be0fe..d00634212 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -67,10 +67,11 @@ EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; static void sub_80E715C(u8 taskId); static void sub_80E7324(u8 taskId); static void sub_80E756C(u8 taskId); -void sub_80E7630(u8 taskId); +static void sub_80E7630(u8 taskId); void sub_80E77D4(u8 taskId); void *sub_80E77FC(s16 *asShort); u8 sub_80E7810(void); +void *sub_80E7820(u8); void sub_80E7808(struct PlayerRecords *records, s16 *a1); void sub_80E78C4(OldMan *, size_t, u8); void sub_80E7948(void *, size_t, u8); @@ -445,3 +446,47 @@ static void sub_80E756C(u8 taskId) break; } } + +static void sub_80E7630(u8 taskId) +{ + struct Task *task; + u8 status; + u8 counter; + u8 i; + void *dest; + void *src; + + task = &gTasks[taskId]; + status = GetBlockReceivedStatus(); + counter = 0; + if (status == sub_800A9D8()) + { + for (i = 0; i < GetLinkPlayerCount(); i ++) + { + if ((status >> i) & 0x01) + { + dest = sub_80E77FC(&task->data[5]) + task->data[i + 1] * 200 + gUnknown_0300115C * i; + src = sub_80E7820(i); + if ((task->data[i + 1] + 1) * 200 > gUnknown_0300115C) + { + memcpy(dest, src, gUnknown_0300115C - task->data[i + 1] * 200); + } + else + { + memcpy(dest, src, 200); + } + ResetBlockReceivedFlag(i); + task->data[i + 1] ++; + if (task->data[i + 1] == gUnknown_0300115C / 200 + 1) + { + counter ++; + } + } + } + gTasks[task->data[0]].data[0] ++; + } + if (counter == GetLinkPlayerCount()) + { + DestroyTask(taskId); + } +} From cd4aa5efe5e3ca9ad96ceee0462ff69c99d3fc92 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 11:49:28 -0400 Subject: [PATCH 10/26] through sub_80E7820 --- asm/record_mixing.s | 109 -------------------------------------------- src/record_mixing.c | 71 +++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 119 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index e3e818a7e..50bc0037d 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,115 +5,6 @@ .text - thumb_func_start sub_80E776C -sub_80E776C: @ 80E776C - push {r4,lr} - lsls r0, 24 - lsrs r3, r0, 24 - lsls r0, r3, 2 - adds r0, r3 - lsls r0, 3 - ldr r2, =gTasks - adds r0, r2 - movs r4, 0x1C - ldrsh r1, [r0, r4] - lsls r0, r1, 2 - adds r0, r1 - lsls r0, 3 - adds r0, r2 - ldrb r0, [r0, 0x4] - cmp r0, 0 - bne _080E7794 - adds r0, r3, 0 - bl DestroyTask -_080E7794: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E776C - - thumb_func_start sub_80E77A0 -sub_80E77A0: @ 80E77A0 - push {lr} - lsls r0, 24 - lsrs r0, 24 - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - ldr r0, =gTasks - adds r1, r0 - ldr r0, =sub_80E776C - str r0, [r1] - ldr r0, =gUnknown_03001130 - ldrb r0, [r0] - cmp r0, 0x1 - bne _080E77C4 - movs r2, 0x12 - ldrsh r0, [r1, r2] - bl sub_80E6F60 -_080E77C4: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E77A0 - - thumb_func_start sub_80E77D4 -sub_80E77D4: @ 80E77D4 - lsls r0, 24 - lsrs r0, 24 - ldr r2, =gTasks - lsls r1, r0, 2 - adds r1, r0 - lsls r1, 3 - adds r1, r2 - ldr r0, =sub_80E77A0 - str r0, [r1] - ldr r1, =gUnknown_03001130 - movs r0, 0x1 - strb r0, [r1] - bx lr - .pool - thumb_func_end sub_80E77D4 - - thumb_func_start sub_80E77FC -sub_80E77FC: @ 80E77FC - adds r1, r0, 0 - ldrh r0, [r1] - ldrh r1, [r1, 0x2] - lsls r1, 16 - orrs r0, r1 - bx lr - thumb_func_end sub_80E77FC - - thumb_func_start sub_80E7808 -sub_80E7808: @ 80E7808 - strh r0, [r1] - lsrs r0, 16 - strh r0, [r1, 0x2] - bx lr - thumb_func_end sub_80E7808 - - thumb_func_start sub_80E7810 -sub_80E7810: @ 80E7810 - push {lr} - bl GetMultiplayerId - lsls r0, 24 - lsrs r0, 24 - pop {r1} - bx r1 - thumb_func_end sub_80E7810 - - thumb_func_start sub_80E7820 -sub_80E7820: @ 80E7820 - lsls r0, 24 - lsrs r0, 16 - ldr r1, =gBlockRecvBuffer - adds r0, r1 - bx lr - .pool - thumb_func_end sub_80E7820 - thumb_func_start sub_80E7830 sub_80E7830: @ 80E7830 push {r4,lr} diff --git a/src/record_mixing.c b/src/record_mixing.c index d00634212..01b19cbb3 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -68,11 +68,11 @@ static void sub_80E715C(u8 taskId); static void sub_80E7324(u8 taskId); static void sub_80E756C(u8 taskId); static void sub_80E7630(u8 taskId); -void sub_80E77D4(u8 taskId); -void *sub_80E77FC(s16 *asShort); -u8 sub_80E7810(void); -void *sub_80E7820(u8); -void sub_80E7808(struct PlayerRecords *records, s16 *a1); +static void sub_80E77D4(u8 taskId); +static void *sub_80E77FC(const u16 *asShort); +static void sub_80E7808(void *records, u16 *a1); +static u8 sub_80E7810(void); +static void *sub_80E7820(u8); void sub_80E78C4(OldMan *, size_t, u8); void sub_80E7948(void *, size_t, u8); void sub_80E7A14(LilycoveLady *, size_t, u8); @@ -378,20 +378,20 @@ static void sub_80E7324(u8 taskId) task->func = sub_80E756C; if (Link_AnyPartnersPlayingRubyOrSapphrie()) { - sub_80E7808(gUnknown_0203A018, &task->data[2]); + sub_80E7808(gUnknown_0203A018, (u16 *)&task->data[2]); taskId2 = CreateTask(sub_80E7630, 80); task->data[10] = taskId2; gTasks[taskId2].data[0] = taskId; - sub_80E7808(gUnknown_0203A014, &gTasks[taskId2].data[5]); + sub_80E7808(gUnknown_0203A014, (u16 *)&gTasks[taskId2].data[5]); gUnknown_0300115C = 0x1230; } else { - sub_80E7808(gUnknown_0203A018, &task->data[2]); + sub_80E7808(gUnknown_0203A018, (u16 *)&task->data[2]); taskId2 = CreateTask(sub_80E7630, 80); task->data[10] = taskId2; gTasks[taskId2].data[0] = taskId; - sub_80E7808(gUnknown_0203A014, &gTasks[taskId2].data[5]); + sub_80E7808(gUnknown_0203A014, (u16 *)&gTasks[taskId2].data[5]); gUnknown_0300115C = 0x1444; } break; @@ -465,7 +465,7 @@ static void sub_80E7630(u8 taskId) { if ((status >> i) & 0x01) { - dest = sub_80E77FC(&task->data[5]) + task->data[i + 1] * 200 + gUnknown_0300115C * i; + dest = sub_80E77FC((u16 *)&task->data[5]) + task->data[i + 1] * 200 + gUnknown_0300115C * i; src = sub_80E7820(i); if ((task->data[i + 1] + 1) * 200 > gUnknown_0300115C) { @@ -490,3 +490,54 @@ static void sub_80E7630(u8 taskId) DestroyTask(taskId); } } + +static void sub_80E776C(u8 taskId) +{ + struct Task *task; + + task = &gTasks[taskId]; + if (!gTasks[task->data[10]].isActive) + { + DestroyTask(taskId); + } +} + +static void sub_80E77A0(u8 taskId) +{ + struct Task *task; + + task = &gTasks[taskId]; + task->func = sub_80E776C; + if (gUnknown_03001130 == TRUE) + { + sub_80E6F60(task->data[5]); + } +} + +static void sub_80E77D4(u8 taskId) +{ + gTasks[taskId].func = sub_80E77A0; + gUnknown_03001130 = TRUE; +} + + +static void *sub_80E77FC(const u16 *asShort) +{ + return (void *)(asShort[0] | (asShort[1] << 16)); +} + +static void sub_80E7808(void *data, u16 *asShort) +{ + asShort[0] = (u32)data; + asShort[1] = ((u32)data >> 16); +} + +static u8 sub_80E7810(void) +{ + return GetMultiplayerId(); +} + +static void *sub_80E7820(u8 id) +{ + return gBlockRecvBuffer[id]; +} From fb9e5cb3a411a1186a029e089ee63a3f9928457b Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 12:03:50 -0400 Subject: [PATCH 11/26] sub_80E7830 --- asm/record_mixing.s | 77 --------------------------------------------- src/record_mixing.c | 34 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 77 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 50bc0037d..2c86404ec 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,83 +5,6 @@ .text - thumb_func_start sub_80E7830 -sub_80E7830: @ 80E7830 - push {r4,lr} - adds r4, r0, 0 - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3 - beq _080E7868 - cmp r0, 0x3 - bhi _080E784A - cmp r0, 0x2 - beq _080E7850 - b _080E78B8 -_080E784A: - cmp r0, 0x4 - beq _080E7894 - b _080E78B8 -_080E7850: - movs r3, 0 - ldr r2, =gUnknown_0858CF8C - adds r1, r4, 0 -_080E7856: - adds r0, r3, r2 - ldrb r0, [r0] - stm r1!, {r0} - adds r3, 0x1 - cmp r3, 0x1 - bls _080E7856 - b _080E78B8 - .pool -_080E7868: - movs r0, 0 - bl GetLinkPlayerTrainerId - adds r2, r0, 0 - movs r0, 0x1 - ands r2, r0 - movs r3, 0 - ldr r1, =gUnknown_0858CF8E - lsls r0, r2, 1 - adds r0, r2 - adds r1, r0, r1 - adds r2, r4, 0 -_080E7880: - ldrb r0, [r1] - stm r2!, {r0} - adds r1, 0x1 - adds r3, 0x1 - cmp r3, 0x2 - bls _080E7880 - b _080E78B8 - .pool -_080E7894: - movs r0, 0 - bl GetLinkPlayerTrainerId - movs r1, 0x9 - bl __umodsi3 - adds r2, r0, 0 - movs r3, 0 - ldr r1, =gUnknown_0858CF94 - lsls r0, r2, 2 - adds r1, r0, r1 - adds r2, r4, 0 -_080E78AC: - ldrb r0, [r1] - stm r2!, {r0} - adds r1, 0x1 - adds r3, 0x1 - cmp r3, 0x3 - bls _080E78AC -_080E78B8: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7830 - thumb_func_start sub_80E78C4 sub_80E78C4: @ 80E78C4 push {r4-r7,lr} diff --git a/src/record_mixing.c b/src/record_mixing.c index 01b19cbb3..14afd57ce 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -94,6 +94,10 @@ void TaskDummy4(void *src); // .rodata +extern const u8 gUnknown_0858CF8C[]; +extern const u8 gUnknown_0858CF8E[][3]; +extern const u8 gUnknown_0858CF94[][4]; + // .text void sub_80E6BE8(void) @@ -541,3 +545,33 @@ static void *sub_80E7820(u8 id) { return gBlockRecvBuffer[id]; } + +void sub_80E7830(u32 *data) +{ + u32 i; + u32 linkTrainerId; + + switch ((u32)GetLinkPlayerCount()) + { + case 2: + for (i = 0; i < 2; i ++) + { + data[i] = gUnknown_0858CF8C[i]; + } + break; + case 3: + linkTrainerId = GetLinkPlayerTrainerId(0) % 2; + for (i = 0; i < 3; i ++) + { + data[i] = gUnknown_0858CF8E[linkTrainerId][i]; + } + break; + case 4: + linkTrainerId = GetLinkPlayerTrainerId(0) % 9; + for (i = 0; i < 4; i ++) + { + data[i] = gUnknown_0858CF94[linkTrainerId][i]; + } + break; + } +} From 158e9ff7623a8eba3e00c962e1050c6937bf535a Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 12:20:40 -0400 Subject: [PATCH 12/26] sub_80E78C4 --- asm/cable_club.s | 2 +- asm/link.s | 6 ++-- asm/record_mixing.s | 70 ++------------------------------------ include/link.h | 2 +- include/mauville_old_man.h | 3 ++ src/record_mixing.c | 29 ++++++++++++++-- 6 files changed, 37 insertions(+), 75 deletions(-) diff --git a/asm/cable_club.s b/asm/cable_club.s index 80c177d20..c9f15ef47 100644 --- a/asm/cable_club.s +++ b/asm/cable_club.s @@ -795,7 +795,7 @@ sub_80B2A08: @ 80B2A08 ldrh r0, [r0] cmp r0, 0x4 bne _080B2A38 - bl Link_AnyPartnersPlayingRubyOrSapphrie + bl Link_AnyPartnersPlayingRubyOrSapphire cmp r0, 0 bne _080B2A4A bl sub_800AC34 diff --git a/asm/link.s b/asm/link.s index 840b153e7..6fc5a6dff 100644 --- a/asm/link.s +++ b/asm/link.s @@ -1464,8 +1464,8 @@ _0800A060: bx r1 thumb_func_end Link_HaveFourPlayersWithAtLeastOneRubyOrSapphire - thumb_func_start Link_AnyPartnersPlayingRubyOrSapphrie -Link_AnyPartnersPlayingRubyOrSapphrie: @ 800A064 + thumb_func_start Link_AnyPartnersPlayingRubyOrSapphire +Link_AnyPartnersPlayingRubyOrSapphire: @ 800A064 push {lr} movs r0, 0x2 movs r1, 0x1 @@ -1479,7 +1479,7 @@ _0800A076: _0800A078: pop {r1} bx r1 - thumb_func_end Link_AnyPartnersPlayingRubyOrSapphrie + thumb_func_end Link_AnyPartnersPlayingRubyOrSapphire thumb_func_start sub_800A07C sub_800A07C: @ 800A07C diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 2c86404ec..424913e6c 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,70 +5,6 @@ .text - thumb_func_start sub_80E78C4 -sub_80E78C4: @ 80E78C4 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x10 - mov r9, r0 - mov r8, r1 - lsls r2, 24 - lsrs r7, r2, 24 - mov r0, sp - bl sub_80E7830 - lsls r0, r7, 2 - add r0, sp - ldr r1, [r0] - mov r0, r8 - muls r0, r1 - mov r2, r9 - adds r6, r2, r0 - ldr r2, =gLinkPlayers - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrb r4, [r0] - ldrh r5, [r0, 0x1A] - bl Link_AnyPartnersPlayingRubyOrSapphrie - cmp r0, 0 - beq _080E7910 - adds r0, r6, 0 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_8120D34 - b _080E791A - .pool -_080E7910: - adds r0, r6, 0 - adds r1, r4, 0 - adds r2, r5, 0 - bl sub_8120CD0 -_080E791A: - ldr r0, =gUnknown_03001140 - ldr r0, [r0] - lsls r1, r7, 2 - add r1, sp - ldr r1, [r1] - mov r2, r8 - muls r2, r1 - adds r1, r2, 0 - add r1, r9 - movs r2, 0x40 - bl memcpy - bl sub_8120670 - add sp, 0x10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E78C4 - thumb_func_start sub_80E7948 sub_80E7948: @ 80E7948 push {r4-r7,lr} @@ -82,7 +18,7 @@ sub_80E7948: @ 80E7948 lsrs r6, r2, 24 mov r0, sp bl sub_80E7830 - bl Link_AnyPartnersPlayingRubyOrSapphrie + bl Link_AnyPartnersPlayingRubyOrSapphire cmp r0, 0 beq _080E79AC lsls r0, r6, 2 @@ -399,7 +335,7 @@ _080E7BB0: mov r8, r0 cmp r0, 0x3 bls _080E7BB0 - bl Link_AnyPartnersPlayingRubyOrSapphrie + bl Link_AnyPartnersPlayingRubyOrSapphire str r0, [sp, 0x3C] movs r2, 0 mov r8, r2 @@ -956,7 +892,7 @@ _080E8024: .4byte _080E80EE .4byte _080E80FA _080E804C: - bl Link_AnyPartnersPlayingRubyOrSapphrie + bl Link_AnyPartnersPlayingRubyOrSapphire cmp r0, 0 bne _080E80F2 movs r0, 0x6 diff --git a/include/link.h b/include/link.h index 04a7d3864..77e9a9d24 100644 --- a/include/link.h +++ b/include/link.h @@ -194,7 +194,7 @@ void sub_8011BD0(void); u8 sub_800ABAC(void); u8 sub_800ABBC(void); void sub_800AC34(void); -bool32 Link_AnyPartnersPlayingRubyOrSapphrie(void); +bool32 Link_AnyPartnersPlayingRubyOrSapphire(void); bool32 sub_800A03C(void); void sub_8009628(u8); u8 sub_800AA48(void); diff --git a/include/mauville_old_man.h b/include/mauville_old_man.h index 25c5d8cd2..0c0ed624a 100644 --- a/include/mauville_old_man.h +++ b/include/mauville_old_man.h @@ -5,5 +5,8 @@ void SetMauvilleOldMan(void); u8 sub_81201C8(void); void sub_8120B70(OldMan *dest); +void sub_8120D34(OldMan *dest, u8 version, u16 language); +void sub_8120CD0(OldMan *dest, u8 version, u16 language); +void sub_8120670(void); #endif // GUARD_MAUVILLE_OLD_MAN_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 14afd57ce..6670663f4 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -160,7 +160,7 @@ void sub_80E6E24(void) sub_80E9914(); sub_80F0BB8(); sub_80E6BF8(); - if (Link_AnyPartnersPlayingRubyOrSapphrie()) + if (Link_AnyPartnersPlayingRubyOrSapphire()) { if (sub_800A03C() == FALSE) { @@ -193,7 +193,7 @@ void sub_80E6E24(void) void sub_80E6F60(u32 a0) { - if (Link_AnyPartnersPlayingRubyOrSapphrie()) + if (Link_AnyPartnersPlayingRubyOrSapphire()) { // Ruby/Sapphire sub_80E7B2C(gUnknown_0203A014[0].tvShows); @@ -380,7 +380,7 @@ static void sub_80E7324(u8 taskId) task->data[0] = 0; task->data[5] = sub_80E7810(); task->func = sub_80E756C; - if (Link_AnyPartnersPlayingRubyOrSapphrie()) + if (Link_AnyPartnersPlayingRubyOrSapphire()) { sub_80E7808(gUnknown_0203A018, (u16 *)&task->data[2]); taskId2 = CreateTask(sub_80E7630, 80); @@ -575,3 +575,26 @@ void sub_80E7830(u32 *data) break; } } + +void sub_80E78C4(OldMan *oldMan, size_t recordSize, u8 which) +{ + u8 version; + u16 language; + OldMan *dest; + u32 data[4]; + + sub_80E7830(data); + dest = (OldMan *)((void *)oldMan + recordSize * data[which]); + version = gLinkPlayers[data[which]].version; + language = gLinkPlayers[data[which]].language; + if (Link_AnyPartnersPlayingRubyOrSapphire()) + { + sub_8120D34(dest, version, language); + } + else + { + sub_8120CD0(dest, version, language); + } + memcpy(gUnknown_03001140, (OldMan *)((void *)oldMan + recordSize * data[which]), sizeof(OldMan)); + sub_8120670(); +} From f2e723660bba8432f398784f9a1ea0d609e24e8d Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 18:48:13 -0400 Subject: [PATCH 13/26] sub_80E7948 --- asm/record_mixing.s | 99 ------------------------------------------ include/battle_tower.h | 39 ++++++++++++++++- src/record_mixing.c | 88 +++++++++++++++++++++++++------------ 3 files changed, 99 insertions(+), 127 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 424913e6c..cd4704245 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,105 +5,6 @@ .text - thumb_func_start sub_80E7948 -sub_80E7948: @ 80E7948 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0x10 - mov r8, r0 - adds r7, r1, 0 - lsls r2, 24 - lsrs r6, r2, 24 - mov r0, sp - bl sub_80E7830 - bl Link_AnyPartnersPlayingRubyOrSapphire - cmp r0, 0 - beq _080E79AC - lsls r0, r6, 2 - mov r1, sp - adds r5, r1, r0 - ldr r0, [r5] - muls r0, r7 - add r0, r8 - adds r4, r7, 0 - muls r4, r6 - mov r1, r8 - adds r6, r1, r4 - adds r1, r6, 0 - bl sub_816587C - mov r9, r4 - cmp r0, 0x1 - bne _080E79FE - adds r7, r6, 0 - ldr r2, =gLinkPlayers - ldr r1, [r5] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 2 - adds r0, r2 - ldrh r1, [r0, 0x1A] - adds r0, r7, 0 - adds r0, 0xE4 - strb r1, [r0] - adds r0, r7, 0 - bl sub_8164F70 - b _080E79FE - .pool -_080E79AC: - adds r5, r7, 0 - muls r5, r6 - mov r0, r8 - adds r4, r0, r5 - lsls r0, r6, 2 - add r0, sp - ldr r0, [r0] - adds r1, r7, 0 - muls r1, r0 - add r1, r8 - adds r0, r4, 0 - movs r2, 0xEC - bl memcpy - adds r7, r4, 0 - movs r6, 0 - mov r9, r5 -_080E79CE: - movs r0, 0x2C - muls r0, r6 - adds r0, 0x34 - adds r1, r7, r0 - ldrh r0, [r1] - cmp r0, 0 - beq _080E79F2 - adds r4, r1, 0 - adds r4, 0x20 - adds r0, r4, 0 - bl IsStringJapanese - cmp r0, 0 - beq _080E79F2 - adds r0, r4, 0 - movs r1, 0x1 - bl ConvertInternationalString -_080E79F2: - adds r6, 0x1 - cmp r6, 0x3 - ble _080E79CE - adds r0, r7, 0 - bl sub_8164F70 -_080E79FE: - mov r0, r8 - add r0, r9 - bl sub_81628A0 - add sp, 0x10 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80E7948 - thumb_func_start sub_80E7A14 sub_80E7A14: @ 80E7A14 push {r4-r7,lr} diff --git a/include/battle_tower.h b/include/battle_tower.h index a3bd3b6e8..7bacf5249 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -1,7 +1,44 @@ #ifndef GUARD_BATTLE_TOWER_H #define GUARD_BATTLE_TOWER_H +struct RSBattleTowerRecord { + /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 + /*0x01*/ u8 trainerClass; + /*0x02*/ u16 winStreak; + /*0x04*/ u8 name[8]; + /*0x0C*/ u8 trainerId[4]; + /*0x10*/ struct { + u16 easyChat[6]; + } greeting; + /*0x1C*/ struct UnknownPokemonStruct party[3]; + /*0xA0*/ u32 checksum; + /*0xA4*/ u16 unk_11c8; +}; + +struct EmeraldBattleTowerRecord { + /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 + /*0x01*/ u8 trainerClass; + /*0x02*/ u16 winStreak; + /*0x04*/ u8 name[8]; + /*0x0C*/ u8 trainerId[4]; + /*0x10*/ struct { + u16 easyChat[6]; + } greeting; + /*0x1C*/ u8 filler_1c[0x18]; + /*0x34*/ struct UnknownPokemonStruct party[4]; + /*0xe4*/ u8 language; + u8 filler_e5[7]; +}; + +union BattleTowerRecord { + struct RSBattleTowerRecord ruby_sapphire; + struct EmeraldBattleTowerRecord emerald; +}; + u16 sub_8164FCC(u8, u8); -void sub_81659DC(void *a0, void *a1); +void sub_81659DC(union BattleTowerRecord *a0, union BattleTowerRecord *a1); +bool32 sub_816587C(union BattleTowerRecord *, union BattleTowerRecord *); +bool32 sub_8164F70(union BattleTowerRecord *); +void sub_81628A0(union BattleTowerRecord *); #endif //GUARD_BATTLE_TOWER_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 6670663f4..6f09e30e2 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -3,6 +3,8 @@ #include "global.h" #include "malloc.h" #include "task.h" +#include "species.h" +#include "pokemon.h" #include "cable_club.h" #include "link.h" #include "tv.h" @@ -32,9 +34,7 @@ struct PlayerRecords { /* 0x1044 */ OldMan oldMan; /* 0x1084 */ struct EasyChatPair easyChatPair[5]; /* 0x10ac */ u8 unk_10ac[0x78]; - /* 0x1124 */ u8 unk_1124[0xa4]; - /* 0x11c8 */ u16 unk_11c8; - /* 0x11ca */ u8 filler_11ca[0x46]; + /* 0x1124 */ union BattleTowerRecord battleTowerRecord; /* 0x1210 */ u16 unk_1210; /* 0x1214 */ LilycoveLady lilycoveLady; /* 0x1254 */ u8 unk_1254[0x88]; @@ -73,8 +73,8 @@ static void *sub_80E77FC(const u16 *asShort); static void sub_80E7808(void *records, u16 *a1); static u8 sub_80E7810(void); static void *sub_80E7820(u8); -void sub_80E78C4(OldMan *, size_t, u8); -void sub_80E7948(void *, size_t, u8); +static void sub_80E78C4(OldMan *, size_t, u8); +static void sub_80E7948(union BattleTowerRecord *, size_t, u8); void sub_80E7A14(LilycoveLady *, size_t, u8); void sub_80E7B2C(TVShow *); void sub_80E7B60(void *, size_t, u8, TVShow *); @@ -85,12 +85,12 @@ void sub_80E8468(void *, size_t, u8); void sub_80E89AC(void *, size_t, u8); void sub_80E89F8(void *dest); void sub_80E8A54(void *src); -void sub_80E8AC0(void *); +void sub_80E8AC0(union BattleTowerRecord *); void sub_80EAF80(struct SecretBaseRecord *, size_t, u8); void sub_80F01E8(void *, size_t, u8); void sub_80F0C7C(PokeNews *, size_t, u8); void sub_812287C(struct EasyChatPair *, size_t, u8); -void TaskDummy4(void *src); +void TaskDummy4(union BattleTowerRecord *src); // .rodata @@ -128,10 +128,10 @@ void sub_80E6CA0(struct PlayerRecords *dest) memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); sub_80E89F8(dest->unk_10ac); - sub_81659DC(gUnknown_0300114C, dest->unk_1124); + sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); if (GetMultiplayerId() == 0) { - dest->unk_11c8 = sub_81539D4(); + dest->battleTowerRecord.ruby_sapphire.unk_11c8 = sub_81539D4(); } } @@ -147,11 +147,11 @@ void sub_80E6D54(struct PlayerRecords *dest) memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); sub_80E89F8(dest->unk_10ac); sub_80E8A54(dest->unk_10ac); - sub_81659DC(gUnknown_0300114C, dest->unk_1124); - TaskDummy4(dest->unk_1124); + sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); + TaskDummy4(&dest->battleTowerRecord); if (GetMultiplayerId() == 0) { - dest->unk_11c8 = sub_81539D4(); + dest->battleTowerRecord.ruby_sapphire.unk_11c8 = sub_81539D4(); } } @@ -180,8 +180,8 @@ void sub_80E6E24(void) memcpy(&gUnknown_0203A018->lilycoveLady, gUnknown_03001150, sizeof(LilycoveLady)); memcpy(gUnknown_0203A018->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); sub_80E89F8(gUnknown_0203A018->unk_10ac); - memcpy(gUnknown_0203A018->unk_1124, gUnknown_0300114C, 0xec); - sub_80E8AC0(gUnknown_0203A018->unk_1124); + memcpy(&gUnknown_0203A018->battleTowerRecord, gUnknown_0300114C, 0xec); + sub_80E8AC0(&gUnknown_0203A018->battleTowerRecord); if (GetMultiplayerId() == 0) { gUnknown_0203A018->unk_1210 = sub_81539D4(); @@ -199,12 +199,12 @@ void sub_80E6F60(u32 a0) sub_80E7B2C(gUnknown_0203A014[0].tvShows); sub_80EAF80(gUnknown_0203A014[0].secretBases, 0x1230, a0); sub_80E7B60(gUnknown_0203A014[0].unk_10ac, 0x1230, a0, gUnknown_0203A014[0].tvShows); - sub_80E7948(gUnknown_0203A014[0].unk_1124, 0x1230, a0); + sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, 0x1230, a0); sub_80F01E8(gUnknown_0203A014[0].tvShows, 0x1230, a0); sub_80F0C7C(gUnknown_0203A014[0].pokeNews, 0x1230, a0); sub_80E78C4(&gUnknown_0203A014[0].oldMan, 0x1230, a0); sub_812287C(gUnknown_0203A014[0].easyChatPair, 0x1230, a0); - sub_80E7F68(&gUnknown_0203A014[0].unk_11c8, a0); + sub_80E7F68(&gUnknown_0203A014[0].battleTowerRecord.ruby_sapphire.unk_11c8, a0); } else { @@ -216,7 +216,7 @@ void sub_80E6F60(u32 a0) sub_80E78C4(&gUnknown_0203A014[0].oldMan, 0x1444, a0); sub_812287C(gUnknown_0203A014[0].easyChatPair, 0x1444, a0); sub_80E7B60(gUnknown_0203A014[0].unk_10ac, 0x1444, a0, gUnknown_0203A014[0].tvShows); - sub_80E7948(gUnknown_0203A014[0].unk_1124, 0x1444, a0); + sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, 0x1444, a0); sub_80E7F68(&gUnknown_0203A014[0].unk_1210, a0); sub_80E7A14(&gUnknown_0203A014[0].lilycoveLady, 0x1444, a0); sub_80E8468(gUnknown_0203A014[0].unk_1254, 0x1444, a0); @@ -530,10 +530,10 @@ static void *sub_80E77FC(const u16 *asShort) return (void *)(asShort[0] | (asShort[1] << 16)); } -static void sub_80E7808(void *data, u16 *asShort) +static void sub_80E7808(void *records, u16 *asShort) { - asShort[0] = (u32)data; - asShort[1] = ((u32)data >> 16); + asShort[0] = (u32)records; + asShort[1] = ((u32)records >> 16); } static u8 sub_80E7810(void) @@ -576,17 +576,17 @@ void sub_80E7830(u32 *data) } } -void sub_80E78C4(OldMan *oldMan, size_t recordSize, u8 which) +static void sub_80E78C4(OldMan *oldMan, size_t recordSize, u8 which) { u8 version; u16 language; OldMan *dest; - u32 data[4]; + u32 mixIndices[4]; - sub_80E7830(data); - dest = (OldMan *)((void *)oldMan + recordSize * data[which]); - version = gLinkPlayers[data[which]].version; - language = gLinkPlayers[data[which]].language; + sub_80E7830(mixIndices); + dest = (OldMan *)((void *)oldMan + recordSize * mixIndices[which]); + version = gLinkPlayers[mixIndices[which]].version; + language = gLinkPlayers[mixIndices[which]].language; if (Link_AnyPartnersPlayingRubyOrSapphire()) { sub_8120D34(dest, version, language); @@ -595,6 +595,40 @@ void sub_80E78C4(OldMan *oldMan, size_t recordSize, u8 which) { sub_8120CD0(dest, version, language); } - memcpy(gUnknown_03001140, (OldMan *)((void *)oldMan + recordSize * data[which]), sizeof(OldMan)); + memcpy(gUnknown_03001140, (OldMan *)((void *)oldMan + recordSize * mixIndices[which]), sizeof(OldMan)); sub_8120670(); } + +static void sub_80E7948(union BattleTowerRecord *battleTowerRecord, size_t recordSize, u8 which) +{ + union BattleTowerRecord *r6; + struct UnknownPokemonStruct *btPokemon; + u32 mixIndices[4]; + s32 i; + + sub_80E7830(mixIndices); + if (Link_AnyPartnersPlayingRubyOrSapphire()) + { + if (sub_816587C((union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * mixIndices[which]), (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which)) == TRUE) + { + r6 = (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which); + r6->emerald.language = gLinkPlayers[mixIndices[which]].language; + sub_8164F70(r6); + } + } + else + { + memcpy((union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which), (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * mixIndices[which]), sizeof(union BattleTowerRecord)); + r6 = (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which); + for (i = 0; i < 4; i ++) + { + btPokemon = &r6->emerald.party[i]; + if (btPokemon->species != SPECIES_NONE && IsStringJapanese(btPokemon->nickname)) + { + ConvertInternationalString(btPokemon->nickname, LANGUAGE_JAPANESE); + } + } + sub_8164F70(r6); + } + sub_81628A0((union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which)); +} From 8d05aeccec2efb8943823124aaca79277d5ed305 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 4 Nov 2017 19:03:41 -0400 Subject: [PATCH 14/26] sub_80E7A14 --- asm/record_mixing.s | 62 ----------------------------------------- include/lilycove_lady.h | 2 +- src/lilycove_lady.c | 10 +++---- src/record_mixing.c | 56 ++++++++++++++++++++++++++++--------- 4 files changed, 49 insertions(+), 81 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index cd4704245..7d439292e 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,68 +5,6 @@ .text - thumb_func_start sub_80E7A14 -sub_80E7A14: @ 80E7A14 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x10 - mov r8, r0 - adds r7, r1, 0 - lsls r2, 24 - lsrs r5, r2, 24 - mov r0, sp - bl sub_80E7830 - adds r0, r7, 0 - muls r0, r5 - add r0, r8 - ldr r6, =gUnknown_03001150 - ldr r1, [r6] - movs r2, 0x40 - bl memcpy - bl GetLilycoveLadyId - lsls r0, 24 - cmp r0, 0 - bne _080E7A60 - movs r0, 0x40 - bl Alloc - adds r4, r0, 0 - cmp r4, 0 - beq _080E7A8A - ldr r1, [r6] - movs r2, 0x40 - bl memcpy - b _080E7A62 - .pool -_080E7A60: - movs r4, 0 -_080E7A62: - ldr r0, =gUnknown_03001150 - ldr r0, [r0] - lsls r1, r5, 2 - add r1, sp - ldr r1, [r1] - muls r1, r7 - add r1, r8 - movs r2, 0x40 - bl memcpy - bl sub_818DA78 - cmp r4, 0 - beq _080E7A8A - adds r0, r4, 0 - bl sub_818E570 - adds r0, r4, 0 - bl Free -_080E7A8A: - add sp, 0x10 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7A14 - thumb_func_start sub_80E7A9C sub_80E7A9C: @ 80E7A9C ldrh r0, [r0, 0x20] diff --git a/include/lilycove_lady.h b/include/lilycove_lady.h index c7776131b..66922273e 100644 --- a/include/lilycove_lady.h +++ b/include/lilycove_lady.h @@ -6,7 +6,7 @@ void SetLilycoveLady(void); void sub_818DA78(void); void sub_818DEF4(void); void sub_818E564(void); -void sub_818E570(const struct LilycoveLadyQuiz *quiz); +void sub_818E570(const LilycoveLady *lilycoveLady); bool8 sub_818E704(struct Pokeblock *pokeblock); void sub_818E7E0(u8 *dest1, u8 *dest2); void sub_818E81C(u8 *dest); diff --git a/src/lilycove_lady.c b/src/lilycove_lady.c index 3b7ae49f2..64e28ecc9 100644 --- a/src/lilycove_lady.c +++ b/src/lilycove_lady.c @@ -879,26 +879,26 @@ void sub_818E564(void) EnableBothScriptContexts(); } -void sub_818E570(const struct LilycoveLadyQuiz *quiz) +void sub_818E570(const LilycoveLady *lilycoveLady) { u8 i; gUnknown_0203CD68 = &gSaveBlock1Ptr->lilycoveLady.quiz; - if (quiz->unk_02c < 16 && gUnknown_0203CD68->id == LILYCOVE_LADY_QUIZ) + if (lilycoveLady->quiz.unk_02c < 16 && gUnknown_0203CD68->id == LILYCOVE_LADY_QUIZ) { for (i = 0; i < 4; i ++) { - if (quiz->unk_02c != gUnknown_0203CD68->unk_02b) + if (lilycoveLady->quiz.unk_02c != gUnknown_0203CD68->unk_02b) { break; } gUnknown_0203CD68->unk_02b = Random() % 16; } - if (quiz->unk_02c == gUnknown_0203CD68->unk_02b) + if (lilycoveLady->quiz.unk_02c == gUnknown_0203CD68->unk_02b) { gUnknown_0203CD68->unk_02b = (gUnknown_0203CD68->unk_02b + 1) % 16; } - gUnknown_0203CD68->unk_02c = quiz->unk_02c; + gUnknown_0203CD68->unk_02c = lilycoveLady->quiz.unk_02c; } } diff --git a/src/record_mixing.c b/src/record_mixing.c index 6f09e30e2..9157597dd 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -21,6 +21,7 @@ #include "fldeff_80F9BCC.h" #include "script.h" #include "event_data.h" +#include "lilycove_lady.h" #include "strings.h" #include "string_util.h" #include "record_mixing.h" @@ -75,7 +76,7 @@ static u8 sub_80E7810(void); static void *sub_80E7820(u8); static void sub_80E78C4(OldMan *, size_t, u8); static void sub_80E7948(union BattleTowerRecord *, size_t, u8); -void sub_80E7A14(LilycoveLady *, size_t, u8); +static void sub_80E7A14(LilycoveLady *, size_t, u8); void sub_80E7B2C(TVShow *); void sub_80E7B60(void *, size_t, u8, TVShow *); void sub_80E7F68(void *, u8); @@ -584,7 +585,7 @@ static void sub_80E78C4(OldMan *oldMan, size_t recordSize, u8 which) u32 mixIndices[4]; sub_80E7830(mixIndices); - dest = (OldMan *)((void *)oldMan + recordSize * mixIndices[which]); + dest = (void *)oldMan + recordSize * mixIndices[which]; version = gLinkPlayers[mixIndices[which]].version; language = gLinkPlayers[mixIndices[which]].language; if (Link_AnyPartnersPlayingRubyOrSapphire()) @@ -595,13 +596,13 @@ static void sub_80E78C4(OldMan *oldMan, size_t recordSize, u8 which) { sub_8120CD0(dest, version, language); } - memcpy(gUnknown_03001140, (OldMan *)((void *)oldMan + recordSize * mixIndices[which]), sizeof(OldMan)); + memcpy(gUnknown_03001140, (void *)oldMan + recordSize * mixIndices[which], sizeof(OldMan)); sub_8120670(); } static void sub_80E7948(union BattleTowerRecord *battleTowerRecord, size_t recordSize, u8 which) { - union BattleTowerRecord *r6; + union BattleTowerRecord *dest; struct UnknownPokemonStruct *btPokemon; u32 mixIndices[4]; s32 i; @@ -609,26 +610,55 @@ static void sub_80E7948(union BattleTowerRecord *battleTowerRecord, size_t recor sub_80E7830(mixIndices); if (Link_AnyPartnersPlayingRubyOrSapphire()) { - if (sub_816587C((union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * mixIndices[which]), (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which)) == TRUE) + if (sub_816587C((void *)battleTowerRecord + recordSize * mixIndices[which], (void *)battleTowerRecord + recordSize * which) == TRUE) { - r6 = (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which); - r6->emerald.language = gLinkPlayers[mixIndices[which]].language; - sub_8164F70(r6); + dest = (void *)battleTowerRecord + recordSize * which; + dest->emerald.language = gLinkPlayers[mixIndices[which]].language; + sub_8164F70(dest); } } else { - memcpy((union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which), (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * mixIndices[which]), sizeof(union BattleTowerRecord)); - r6 = (union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which); + memcpy((void *)battleTowerRecord + recordSize * which, (void *)battleTowerRecord + recordSize * mixIndices[which], sizeof(union BattleTowerRecord)); + dest = (void *)battleTowerRecord + recordSize * which; for (i = 0; i < 4; i ++) { - btPokemon = &r6->emerald.party[i]; + btPokemon = &dest->emerald.party[i]; if (btPokemon->species != SPECIES_NONE && IsStringJapanese(btPokemon->nickname)) { ConvertInternationalString(btPokemon->nickname, LANGUAGE_JAPANESE); } } - sub_8164F70(r6); + sub_8164F70(dest); + } + sub_81628A0((void *)battleTowerRecord + recordSize * which); +} + +static void sub_80E7A14(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) +{ + LilycoveLady *dest; + u32 mixIndices[4]; + + sub_80E7830(mixIndices); + memcpy((void *)lilycoveLady + recordSize * which, gUnknown_03001150, sizeof(LilycoveLady)); + if (GetLilycoveLadyId() == 0) + { + dest = malloc(sizeof(LilycoveLady)); + if (dest == NULL) + { + return; + } + memcpy(dest, gUnknown_03001150, sizeof(LilycoveLady)); + } + else + { + dest = NULL; + } + memcpy(gUnknown_03001150, (void *)lilycoveLady + recordSize * mixIndices[which], sizeof(LilycoveLady)); + sub_818DA78(); + if (dest != NULL) + { + sub_818E570(dest); + free(dest); } - sub_81628A0((union BattleTowerRecord *)((void *)battleTowerRecord + recordSize * which)); } From 0a17fc98f6cc08151aab395064185815e41ab898 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 6 Nov 2017 23:03:11 -0500 Subject: [PATCH 15/26] nonmatching sub_80E7B60 --- asm/record_mixing.s | 633 -------------------------------- include/record_mixing.h | 11 +- src/record_mixing.c | 779 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 772 insertions(+), 651 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 7d439292e..059faa8e5 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,639 +5,6 @@ .text - thumb_func_start sub_80E7A9C -sub_80E7A9C: @ 80E7A9C - ldrh r0, [r0, 0x20] - lsls r0, 24 - lsrs r0, 24 - bx lr - thumb_func_end sub_80E7A9C - - thumb_func_start sub_80E7AA4 -sub_80E7AA4: @ 80E7AA4 - push {r4-r6,lr} - mov r6, r10 - mov r5, r9 - mov r4, r8 - push {r4-r6} - sub sp, 0x38 - mov r8, r0 - mov r10, r1 - mov r9, r2 - adds r4, r3, 0 - ldr r5, [sp, 0x54] - lsls r4, 24 - lsls r5, 24 - lsrs r5, 24 - lsrs r4, 23 - add r4, r9 - ldrb r0, [r4] - mov r6, r10 - muls r6, r0 - add r6, r8 - ldrb r0, [r4, 0x1] - lsls r1, r0, 3 - subs r1, r0 - lsls r1, 3 - adds r1, r6, r1 - mov r0, sp - movs r2, 0x38 - bl memcpy - lsls r5, 1 - add r5, r9 - ldrb r0, [r5] - mov r1, r10 - muls r1, r0 - adds r0, r1, 0 - add r8, r0 - ldrb r1, [r4, 0x1] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 3 - adds r6, r0 - ldrb r0, [r5, 0x1] - lsls r1, r0, 3 - subs r1, r0 - lsls r1, 3 - add r1, r8 - adds r0, r6, 0 - movs r2, 0x38 - bl memcpy - ldrb r1, [r5, 0x1] - lsls r0, r1, 3 - subs r0, r1 - lsls r0, 3 - add r8, r0 - mov r0, r8 - mov r1, sp - movs r2, 0x38 - bl memcpy - add sp, 0x38 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_80E7AA4 - - thumb_func_start sub_80E7B2C -sub_80E7B2C: @ 80E7B2C - push {r4,lr} - adds r3, r0, 0 - movs r2, 0 - movs r1, 0 - ldr r4, =gUnknown_03001160 -_080E7B36: - adds r0, r3, r1 - ldrb r0, [r0] - adds r0, r2, r0 - lsls r0, 24 - lsrs r2, r0, 24 - adds r1, 0x1 - cmp r1, 0xFF - ble _080E7B36 - strb r2, [r4] - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7B2C - - thumb_func_start sub_80E7B54 -sub_80E7B54: @ 80E7B54 - ldr r0, =gUnknown_03001160 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end sub_80E7B54 - - thumb_func_start sub_80E7B60 -sub_80E7B60: @ 80E7B60 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x58 - str r0, [sp, 0x2C] - str r1, [sp, 0x30] - lsls r2, 24 - lsrs r2, 24 - mov r9, r2 - bl Random2 - lsls r0, 16 - lsrs r0, 16 - str r0, [sp, 0x38] - ldr r0, =gLinkPlayers - ldrh r0, [r0, 0x4] - bl SeedRng2 - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r4, r0, 24 - movs r0, 0 - mov r8, r0 - mov r1, sp - adds r1, 0x1C - str r1, [sp, 0x4C] - mov r2, sp - adds r2, 0x1D - str r2, [sp, 0x50] - mov r3, sp - adds r3, 0xC - str r3, [sp, 0x48] - movs r7, 0xFF - add r3, sp, 0x8 - movs r2, 0 - adds r6, r1, 0 - ldr r5, [sp, 0x50] -_080E7BB0: - mov r1, sp - add r1, r8 - adds r1, 0x4 - ldrb r0, [r1] - orrs r0, r7 - strb r0, [r1] - mov r1, r8 - adds r0, r3, r1 - strb r2, [r0] - lsls r1, 1 - adds r0, r6, r1 - strb r2, [r0] - adds r1, r5, r1 - strb r2, [r1] - mov r0, r8 - adds r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - cmp r0, 0x3 - bls _080E7BB0 - bl Link_AnyPartnersPlayingRubyOrSapphire - str r0, [sp, 0x3C] - movs r2, 0 - mov r8, r2 - lsls r4, 16 - str r4, [sp, 0x54] - ldr r0, [sp, 0x30] - mov r3, r9 - muls r3, r0 - str r3, [sp, 0x44] - b _080E7D04 - .pool -_080E7BF8: - ldr r1, [sp, 0x30] - mov r0, r8 - muls r0, r1 - ldr r2, [sp, 0x2C] - adds r7, r2, r0 - ldr r1, =gLinkPlayers - mov r3, r8 - lsls r0, r3, 3 - subs r0, r3 - lsls r0, 2 - adds r0, r1 - ldrh r1, [r0, 0x1A] - mov r9, r1 - ldrb r0, [r0] - str r0, [sp, 0x40] - movs r6, 0 - ldr r0, [r7, 0x70] - cmp r6, r0 - bcs _080E7CFA - movs r2, 0x10 - negs r2, r2 - mov r10, r2 -_080E7C24: - lsls r0, r6, 3 - subs r0, r6 - lsls r0, 3 - adds r5, r7, r0 - ldrh r0, [r5, 0x20] - cmp r0, 0 - beq _080E7CEE - ldr r3, [sp, 0x3C] - cmp r3, 0 - beq _080E7C9A - adds r4, r5, 0 - adds r4, 0x24 - adds r0, r4, 0 - bl StringLength - lsls r0, 16 - lsrs r0, 16 - cmp r0, 0x5 - bhi _080E7C54 - movs r4, 0x1 - b _080E7C5C - .pool -_080E7C54: - adds r0, r4, 0 - bl StripExtCtrlCodes - mov r4, r9 -_080E7C5C: - ldrh r1, [r5, 0x2C] - ldr r0, =0x000015fc - cmp r1, r0 - bne _080E7C74 - adds r0, r5, 0 - adds r0, 0x2C - bl StripExtCtrlCodes - movs r1, 0x1 - b _080E7C76 - .pool -_080E7C74: - mov r1, r9 -_080E7C76: - ldr r0, [sp, 0x40] - subs r0, 0x1 - cmp r0, 0x1 - bhi _080E7CEE - adds r2, r5, 0 - adds r2, 0x37 - movs r0, 0xF - ands r4, r0 - ldrb r0, [r2] - mov r3, r10 - ands r0, r3 - orrs r0, r4 - lsls r1, 4 - movs r3, 0xF - ands r0, r3 - orrs r0, r1 - strb r0, [r2] - b _080E7CEE -_080E7C9A: - mov r0, r9 - cmp r0, 0x1 - bne _080E7CEE - adds r0, r5, 0 - adds r0, 0x24 - bl IsStringJapanese - cmp r0, 0 - beq _080E7CBA - adds r0, r5, 0 - adds r0, 0x37 - ldrb r1, [r0] - mov r2, r10 - ands r1, r2 - movs r2, 0x1 - b _080E7CC6 -_080E7CBA: - adds r0, r5, 0 - adds r0, 0x37 - ldrb r1, [r0] - mov r3, r10 - ands r1, r3 - movs r2, 0x2 -_080E7CC6: - orrs r1, r2 - strb r1, [r0] - adds r4, r0, 0 - adds r0, r5, 0 - adds r0, 0x2C - bl IsStringJapanese - cmp r0, 0 - beq _080E7CE2 - ldrb r0, [r4] - movs r1, 0xF - ands r1, r0 - movs r0, 0x10 - b _080E7CEA -_080E7CE2: - ldrb r0, [r4] - movs r1, 0xF - ands r1, r0 - movs r0, 0x20 -_080E7CEA: - orrs r1, r0 - strb r1, [r4] -_080E7CEE: - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 - ldr r0, [r7, 0x70] - cmp r6, r0 - bcc _080E7C24 -_080E7CFA: - mov r0, r8 - adds r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 -_080E7D04: - bl GetLinkPlayerCount - lsls r0, 24 - lsrs r0, 24 - cmp r8, r0 - bcs _080E7D12 - b _080E7BF8 -_080E7D12: - movs r0, 0 - str r0, [sp, 0x34] - mov r8, r0 - ldr r1, [sp, 0x54] - lsrs r0, r1, 16 - ldr r2, [sp, 0x34] - cmp r2, r0 - bcs _080E7D70 - adds r5, r0, 0 -_080E7D24: - ldr r3, [sp, 0x30] - mov r0, r8 - muls r0, r3 - ldr r1, [sp, 0x2C] - adds r7, r1, r0 - ldr r0, [r7, 0x70] - cmp r0, 0 - beq _080E7D62 - movs r6, 0 - cmp r6, r0 - bcs _080E7D62 - adds r3, r7, 0 - adds r3, 0x74 - ldr r2, [sp, 0x4C] - mov r0, r8 - lsls r1, r0, 1 - movs r4, 0x1 -_080E7D46: - lsls r0, r6, 1 - adds r0, r3, r0 - ldrh r0, [r0] - cmp r0, 0 - bne _080E7D56 - adds r0, r6, r1 - adds r0, r2, r0 - strb r4, [r0] -_080E7D56: - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 - ldr r0, [r7, 0x70] - cmp r6, r0 - bcc _080E7D46 -_080E7D62: - mov r0, r8 - adds r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - cmp r8, r5 - bcc _080E7D24 -_080E7D70: - movs r6, 0 - mov r8, r6 - ldr r1, [sp, 0x54] - cmp r1, 0 - beq _080E7E64 - add r2, sp, 0x24 - mov r10, r2 - movs r3, 0x25 - add r3, sp - mov r9, r3 -_080E7D84: - ldr r1, [sp, 0x30] - mov r0, r8 - muls r0, r1 - ldr r2, [sp, 0x2C] - adds r7, r2, r0 - mov r3, r8 - lsls r1, r3, 1 - ldr r2, [sp, 0x4C] - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0x1 - beq _080E7DA6 - ldr r3, [sp, 0x50] - adds r0, r3, r1 - ldrb r0, [r0] - cmp r0, 0x1 - bne _080E7DB0 -_080E7DA6: - ldr r0, [sp, 0x34] - adds r0, 0x1 - lsls r0, 24 - lsrs r0, 24 - str r0, [sp, 0x34] -_080E7DB0: - ldr r2, [sp, 0x4C] - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0x1 - bne _080E7DD4 - ldr r3, [sp, 0x50] - adds r0, r3, r1 - ldrb r2, [r0] - cmp r2, 0 - bne _080E7DD4 -_080E7DC4: - lsls r1, r6, 1 - mov r3, r10 - adds r0, r3, r1 - mov r3, r8 - strb r3, [r0] - add r1, r9 - strb r2, [r1] - b _080E7E4E -_080E7DD4: - ldr r2, [sp, 0x4C] - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0 - bne _080E7DE8 - ldr r3, [sp, 0x50] - adds r0, r3, r1 - ldrb r2, [r0] - cmp r2, 0x1 - beq _080E7DC4 -_080E7DE8: - ldr r2, [sp, 0x4C] - adds r0, r2, r1 - ldrb r0, [r0] - cmp r0, 0x1 - bne _080E7E54 - ldr r3, [sp, 0x50] - adds r0, r3, r1 - ldrb r0, [r0] - cmp r0, 0x1 - bne _080E7E54 - lsls r5, r6, 1 - mov r1, r10 - adds r0, r1, r5 - mov r2, r8 - strb r2, [r0] - adds r0, r7, 0 - bl sub_80E7A9C - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - adds r0, r7, 0 - adds r0, 0x38 - bl sub_80E7A9C - lsls r0, 24 - lsrs r1, r0, 24 - cmp r4, 0 - bne _080E7E30 - cmp r1, 0 - beq _080E7E34 - mov r3, r9 - adds r1, r3, r5 - movs r0, 0x1 - strb r0, [r1] - b _080E7E4E -_080E7E30: - cmp r1, 0 - beq _080E7E48 -_080E7E34: - bl Random2 - mov r1, r9 - adds r2, r1, r5 - lsls r0, 16 - lsrs r0, 16 - movs r1, 0x1 - ands r0, r1 - strb r0, [r2] - b _080E7E4E -_080E7E48: - mov r2, r9 - adds r0, r2, r5 - strb r1, [r0] -_080E7E4E: - adds r0, r6, 0x1 - lsls r0, 16 - lsrs r6, r0, 16 -_080E7E54: - mov r0, r8 - adds r0, 0x1 - lsls r0, 16 - lsrs r3, r0, 16 - mov r8, r3 - ldr r1, [sp, 0x54] - cmp r0, r1 - bcc _080E7D84 -_080E7E64: - movs r2, 0 - mov r8, r2 - ldr r3, [sp, 0x44] - lsls r0, r3, 4 - subs r0, r3 - lsls r0, 3 - ldr r1, [sp, 0x2C] - adds r7, r1, r0 - ldr r1, [sp, 0x48] -_080E7E76: - mov r2, r8 - lsls r0, r2, 2 - adds r0, r1, r0 - str r7, [r0] - mov r0, r8 - adds r0, 0x1 - lsls r0, 16 - lsrs r0, 16 - mov r8, r0 - cmp r0, 0x3 - bls _080E7E76 - bl sub_80E7B54 - lsls r0, 24 - lsrs r0, 24 - movs r1, 0x3 - bl __umodsi3 - lsls r0, 24 - lsrs r1, r0, 24 - ldr r3, [sp, 0x34] - cmp r3, 0x3 - beq _080E7EC8 - cmp r3, 0x3 - bgt _080E7EAE - cmp r3, 0x2 - beq _080E7EB6 - b _080E7F1C -_080E7EAE: - ldr r0, [sp, 0x34] - cmp r0, 0x4 - beq _080E7EE8 - b _080E7F1C -_080E7EB6: - add r2, sp, 0x24 - movs r0, 0x1 - str r0, [sp] - ldr r0, [sp, 0x2C] - ldr r1, [sp, 0x30] - movs r3, 0 - bl sub_80E7AA4 - b _080E7F1C -_080E7EC8: - ldr r0, =gUnknown_0858CFB8 - lsls r1, 1 - adds r2, r1, r0 - ldrb r3, [r2] - adds r0, 0x1 - adds r1, r0 - ldrb r0, [r1] - add r2, sp, 0x24 - str r0, [sp] - ldr r0, [sp, 0x2C] - ldr r1, [sp, 0x30] - bl sub_80E7AA4 - b _080E7F1C - .pool -_080E7EE8: - add r6, sp, 0x24 - ldr r4, =gUnknown_0858CFBE - lsls r5, r1, 2 - adds r0, r5, r4 - ldrb r3, [r0] - adds r0, r4, 0x1 - adds r0, r5, r0 - ldrb r0, [r0] - str r0, [sp] - ldr r0, [sp, 0x2C] - ldr r1, [sp, 0x30] - adds r2, r6, 0 - bl sub_80E7AA4 - adds r0, r4, 0x2 - adds r0, r5, r0 - ldrb r3, [r0] - adds r4, 0x3 - adds r5, r4 - ldrb r0, [r5] - str r0, [sp] - ldr r0, [sp, 0x2C] - ldr r1, [sp, 0x30] - adds r2, r6, 0 - bl sub_80E7AA4 -_080E7F1C: - ldr r1, [sp, 0x2C] - ldr r2, [sp, 0x44] - adds r7, r1, r2 - ldr r4, =gSaveBlock1Ptr - ldr r0, [r4] - movs r3, 0xC2 - lsls r3, 6 - adds r0, r3 - adds r1, r7, 0 - movs r2, 0x38 - bl memcpy - ldr r0, [r4] - ldr r1, =0x0000310c - adds r0, r1 - adds r1, r7, 0 - adds r1, 0x38 - movs r2, 0x38 - bl memcpy - ldr r0, [sp, 0x38] - bl SeedRng - add sp, 0x58 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7B60 - thumb_func_start sub_80E7F68 sub_80E7F68: @ 80E7F68 push {r4,lr} diff --git a/include/record_mixing.h b/include/record_mixing.h index 86e4b982e..e327d1510 100644 --- a/include/record_mixing.h +++ b/include/record_mixing.h @@ -7,11 +7,16 @@ struct DayCareMailRecordMixing { struct MailStruct mail; u8 OT_name[OT_NAME_LENGTH + 1]; u8 monName[11]; - u8 language_maybe : 4; - u8 unknown : 4; - u32 stepsTaken; + u8 language_maybe:4; + u8 unknown:4; }; +struct UnkStruct_80E7B60 { + struct DayCareMailRecordMixing unk_00[2]; + u32 unk_70; + u16 unk_74[2]; +}; // size = 0x78 + // Exported RAM declarations // Exported ROM declarations diff --git a/src/record_mixing.c b/src/record_mixing.c index 9157597dd..66972b650 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -2,6 +2,10 @@ // Includes #include "global.h" #include "malloc.h" +#include "rng.h" +#include "items.h" +#include "text.h" + #include "task.h" #include "species.h" #include "pokemon.h" @@ -34,7 +38,7 @@ struct PlayerRecords { /* 0x1004 */ PokeNews pokeNews[16]; /* 0x1044 */ OldMan oldMan; /* 0x1084 */ struct EasyChatPair easyChatPair[5]; - /* 0x10ac */ u8 unk_10ac[0x78]; + /* 0x10ac */ struct UnkStruct_80E7B60 unk_10ac; /* 0x1124 */ union BattleTowerRecord battleTowerRecord; /* 0x1210 */ u16 unk_1210; /* 0x1214 */ LilycoveLady lilycoveLady; @@ -50,16 +54,17 @@ IWRAM_DATA TVShow *gUnknown_03001138; IWRAM_DATA PokeNews *gUnknown_0300113C; IWRAM_DATA OldMan *gUnknown_03001140; IWRAM_DATA struct EasyChatPair *gUnknown_03001144; -IWRAM_DATA struct DayCareMailRecordMixing *gUnknown_03001148; +IWRAM_DATA struct UnkStruct_80E7B60 *gUnknown_03001148; IWRAM_DATA void *gUnknown_0300114C; // gSaveBlock2Ptr->field_64C IWRAM_DATA LilycoveLady *gUnknown_03001150; IWRAM_DATA void *gUnknown_03001154; // gSaveBlock2Ptr->field_0DC; IWRAM_DATA void *gUnknown_03001158; // gSaveBlock2Ptr->field_64C IWRAM_DATA u32 gUnknown_0300115C; -IWRAM_DATA u8 gUnknown_03001160[8]; +IWRAM_DATA u8 gUnknown_03001160; +IWRAM_DATA u32 filler_03001164; IWRAM_DATA u32 gUnknown_03001168[3]; -EWRAM_DATA struct DayCareMailRecordMixing gUnknown_02039F9C[2] = {}; +EWRAM_DATA struct UnkStruct_80E7B60 gUnknown_02039F9C = {}; EWRAM_DATA struct PlayerRecords *gUnknown_0203A014 = NULL; EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; @@ -77,8 +82,8 @@ static void *sub_80E7820(u8); static void sub_80E78C4(OldMan *, size_t, u8); static void sub_80E7948(union BattleTowerRecord *, size_t, u8); static void sub_80E7A14(LilycoveLady *, size_t, u8); -void sub_80E7B2C(TVShow *); -void sub_80E7B60(void *, size_t, u8, TVShow *); +static void sub_80E7B2C(const u8 *); +static void sub_80E7B60(struct UnkStruct_80E7B60 *, size_t, u8, TVShow *); void sub_80E7F68(void *, u8); void sub_80E7FF8(u8 taskId); void sub_80E8110(void *, void *); @@ -99,6 +104,9 @@ extern const u8 gUnknown_0858CF8C[]; extern const u8 gUnknown_0858CF8E[][3]; extern const u8 gUnknown_0858CF94[][4]; +extern const u8 gUnknown_0858CFB8[3][2]; +extern const u8 gUnknown_0858CFBE[3][4]; + // .text void sub_80E6BE8(void) @@ -113,7 +121,7 @@ void sub_80E6BF8(void) gUnknown_0300113C = gSaveBlock1Ptr->pokeNews; gUnknown_03001140 = &gSaveBlock1Ptr->oldMan; gUnknown_03001144 = gSaveBlock1Ptr->easyChatPairs; - gUnknown_03001148 = gUnknown_02039F9C; + gUnknown_03001148 = &gUnknown_02039F9C; gUnknown_0300114C = gSaveBlock2Ptr->field_64C; gUnknown_03001150 = &gSaveBlock1Ptr->lilycoveLady; gUnknown_03001154 = gSaveBlock2Ptr->field_0DC; @@ -128,7 +136,7 @@ void sub_80E6CA0(struct PlayerRecords *dest) memcpy(dest->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); - sub_80E89F8(dest->unk_10ac); + sub_80E89F8(&dest->unk_10ac); sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); if (GetMultiplayerId() == 0) { @@ -146,8 +154,8 @@ void sub_80E6D54(struct PlayerRecords *dest) memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); sub_8120B70(&dest->oldMan); memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); - sub_80E89F8(dest->unk_10ac); - sub_80E8A54(dest->unk_10ac); + sub_80E89F8(&dest->unk_10ac); + sub_80E8A54(&dest->unk_10ac); sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); TaskDummy4(&dest->battleTowerRecord); if (GetMultiplayerId() == 0) @@ -180,7 +188,7 @@ void sub_80E6E24(void) memcpy(&gUnknown_0203A018->oldMan, gUnknown_03001140, sizeof(OldMan)); memcpy(&gUnknown_0203A018->lilycoveLady, gUnknown_03001150, sizeof(LilycoveLady)); memcpy(gUnknown_0203A018->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); - sub_80E89F8(gUnknown_0203A018->unk_10ac); + sub_80E89F8(&gUnknown_0203A018->unk_10ac); memcpy(&gUnknown_0203A018->battleTowerRecord, gUnknown_0300114C, 0xec); sub_80E8AC0(&gUnknown_0203A018->battleTowerRecord); if (GetMultiplayerId() == 0) @@ -197,9 +205,9 @@ void sub_80E6F60(u32 a0) if (Link_AnyPartnersPlayingRubyOrSapphire()) { // Ruby/Sapphire - sub_80E7B2C(gUnknown_0203A014[0].tvShows); + sub_80E7B2C((void *)gUnknown_0203A014[0].tvShows); sub_80EAF80(gUnknown_0203A014[0].secretBases, 0x1230, a0); - sub_80E7B60(gUnknown_0203A014[0].unk_10ac, 0x1230, a0, gUnknown_0203A014[0].tvShows); + sub_80E7B60(&gUnknown_0203A014[0].unk_10ac, 0x1230, a0, gUnknown_0203A014[0].tvShows); sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, 0x1230, a0); sub_80F01E8(gUnknown_0203A014[0].tvShows, 0x1230, a0); sub_80F0C7C(gUnknown_0203A014[0].pokeNews, 0x1230, a0); @@ -210,13 +218,13 @@ void sub_80E6F60(u32 a0) else { // Emerald - sub_80E7B2C(gUnknown_0203A014[0].tvShows); + sub_80E7B2C((void *)gUnknown_0203A014[0].tvShows); sub_80EAF80(gUnknown_0203A014[0].secretBases, 0x1444, a0); sub_80F01E8(gUnknown_0203A014[0].tvShows, 0x1444, a0); sub_80F0C7C(gUnknown_0203A014[0].pokeNews, 0x1444, a0); sub_80E78C4(&gUnknown_0203A014[0].oldMan, 0x1444, a0); sub_812287C(gUnknown_0203A014[0].easyChatPair, 0x1444, a0); - sub_80E7B60(gUnknown_0203A014[0].unk_10ac, 0x1444, a0, gUnknown_0203A014[0].tvShows); + sub_80E7B60(&gUnknown_0203A014[0].unk_10ac, 0x1444, a0, gUnknown_0203A014[0].tvShows); sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, 0x1444, a0); sub_80E7F68(&gUnknown_0203A014[0].unk_1210, a0); sub_80E7A14(&gUnknown_0203A014[0].lilycoveLady, 0x1444, a0); @@ -662,3 +670,744 @@ static void sub_80E7A14(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) free(dest); } } + +static u8 sub_80E7A9C(struct DayCareMailRecordMixing *rmMail) +{ + return rmMail->mail.itemId; +} + +static void sub_80E7AA4(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) +{ + struct DayCareMailRecordMixing buffer; + struct UnkStruct_80E7B60 *_src1; + struct UnkStruct_80E7B60 *_src2; + + _src1 = (void *)src + recordSize * idxs[which0][0]; + memcpy(&buffer, &_src1->unk_00[idxs[which0][1]], sizeof(struct DayCareMailRecordMixing)); + _src2 = (void *)src + recordSize * idxs[which1][0]; + memcpy(&_src1->unk_00[idxs[which0][1]], &_src2->unk_00[idxs[which1][1]], sizeof(struct DayCareMailRecordMixing)); + memcpy(&_src2->unk_00[idxs[which1][1]], &buffer, sizeof(struct DayCareMailRecordMixing)); +} + +static void sub_80E7B2C(const u8 *src) +{ + u8 sum; + int i; + + sum = 0; + for (i = 0; i < 256; i ++) + { + sum += src[i]; + } + gUnknown_03001160 = sum; +} + +static u8 sub_80E7B54(void) +{ + return gUnknown_03001160; +} + +#ifdef NONMATCHING +static void sub_80E7B60(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 which, TVShow *shows) +{ + // r9 = which + u16 i; + u16 j; + u8 linkPlayerCount; + u16 language; + u16 otNameLanguage; + u16 nicknameLanguage; + u32 version; + u8 dcMail1; + u8 dcMail2; + u8 r1_80e7b54; + struct DayCareMailRecordMixing *recordMixingMail; + struct UnkStruct_80E7B60 *_src; + u8 sp04[4]; + u8 sp08[4]; + struct UnkStruct_80E7B60 *sp0c[4]; // -> sp+48 + u8 sp1c[4][2]; // [][0] -> sp+4c, [][1] -> sp+50 + u8 sp24[4][2]; + // sp+2c = src + // sp+30 = recordSize + u8 sp34; + u16 oldSeed; + bool32 anyRS; // sp+3c + + oldSeed = Random2(); + SeedRng2(gLinkPlayers[0].trainerId); + linkPlayerCount = GetLinkPlayerCount(); + for (i = 0; i < 4; i ++) + { + sp04[i] = 0xFF; + sp08[i] = 0; + sp1c[i][0] = 0; + sp1c[i][1] = 0; + } + anyRS = Link_AnyPartnersPlayingRubyOrSapphire(); + for (i = 0; i < GetLinkPlayerCount(); i ++) // r8 = i + { + // sp+54 = linkPlayerCount << 16 + // sp+44 = which * recordSize + _src = (void *)src + i * recordSize; // r7 + language = gLinkPlayers[i].language; // r9 + version = (u8)gLinkPlayers[i].version; // sp+40 + for (j = 0; j < _src->unk_70; j ++) + { + // r10 = ~0x10 + recordMixingMail = &_src->unk_00[j]; + if (recordMixingMail->mail.itemId != ITEM_NONE) + { + if (anyRS) + { + if (StringLength(recordMixingMail->OT_name) <= 5) + { + otNameLanguage = LANGUAGE_JAPANESE; + } + else + { + StripExtCtrlCodes(recordMixingMail->OT_name); + otNameLanguage = language; + } + if (recordMixingMail->monName[0] == EXT_CTRL_CODE_BEGIN && recordMixingMail->monName[1] == EXT_CTRL_CODE_JPN) + { + StripExtCtrlCodes(recordMixingMail->monName); + nicknameLanguage = LANGUAGE_JAPANESE; + } + else + { + nicknameLanguage = language; + } + if (version == VERSION_RUBY || version == VERSION_SAPPHIRE) + { + recordMixingMail->language_maybe = otNameLanguage; + recordMixingMail->unknown = nicknameLanguage; + } + } + else if (language == LANGUAGE_JAPANESE) + { + if (IsStringJapanese(recordMixingMail->OT_name)) + { + recordMixingMail->language_maybe = LANGUAGE_JAPANESE; + } + else + { + recordMixingMail->language_maybe = GAME_LANGUAGE; + } + if (IsStringJapanese(recordMixingMail->monName)) + { + recordMixingMail->unknown = LANGUAGE_JAPANESE; + } + else + { + recordMixingMail->unknown = GAME_LANGUAGE; + } + } + } + } + } + sp34 = 0; + for (i = 0; i < linkPlayerCount; i ++) + { + _src = (void *)src + i * recordSize; // r7 + if (_src->unk_70 != 0) + { + for (j = 0; j < _src->unk_70; j ++) + { + if (_src->unk_74[j] == 0) + { + sp1c[i][j] = 1; + } + } + } + } + i = 0; + for (j = 0; j < linkPlayerCount; j ++) + { + _src = (void *)src + j * recordSize; + if (sp1c[j][0] == TRUE || sp1c[j][1] == TRUE) + { + sp34 ++; + } + if (sp1c[j][0] == TRUE && sp1c[j][1] == FALSE) + { + sp24[i][0] = j; + sp24[i][1] = 0; + i ++; + } + else if (sp1c[j][0] == FALSE && sp1c[j][1] == TRUE) + { + sp24[i][0] = j; + sp24[i][1] = 0; + i ++; + } + else if (sp1c[j][0] == TRUE && sp1c[j][1] == TRUE) + { + sp24[i][0] = j; + dcMail1 = sub_80E7A9C(&_src->unk_00[0]); + dcMail2 = sub_80E7A9C(&_src->unk_00[1]); + if (!dcMail1 && dcMail2) + { + sp24[i][1] = 1; + } + else if ((dcMail1 && dcMail2) || (!dcMail1 && !dcMail2)) + { + sp24[i][1] = Random2() % 2; + } + else + { + sp24[i][1] = 0; + } + i ++; + } + } + for (i = 0; i < 4; i ++) + { + _src = &src[which * recordSize]; + sp0c[i] = _src; + } + r1_80e7b54 = sub_80E7B54() % 3; + switch (sp34) + { + case 2: + sub_80E7AA4(src, recordSize, sp24, 0, 1); + break; + case 3: + sub_80E7AA4(src, recordSize, sp24, gUnknown_0858CFB8[r1_80e7b54][0], gUnknown_0858CFB8[r1_80e7b54][1]); + break; + case 4: + sub_80E7AA4(src, recordSize, sp24, gUnknown_0858CFBE[r1_80e7b54][0], gUnknown_0858CFBE[r1_80e7b54][1]); + sub_80E7AA4(src, recordSize, sp24, gUnknown_0858CFBE[r1_80e7b54][2], gUnknown_0858CFBE[r1_80e7b54][3]); + break; + } + _src = (void *)src + which * recordSize; + memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->unk_00[0], sizeof(struct DayCareMailRecordMixing)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->unk_00[1], sizeof(struct DayCareMailRecordMixing)); + SeedRng(oldSeed); +} +#else +__attribute__((naked)) static void sub_80E7B60(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 which, TVShow *shows) +{ + asm_unified("\tpush {r4-r7,lr}\n" + "\tmov r7, r10\n" + "\tmov r6, r9\n" + "\tmov r5, r8\n" + "\tpush {r5-r7}\n" + "\tsub sp, 0x58\n" + "\tstr r0, [sp, 0x2C]\n" + "\tstr r1, [sp, 0x30]\n" + "\tlsls r2, 24\n" + "\tlsrs r2, 24\n" + "\tmov r9, r2\n" + "\tbl Random2\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tstr r0, [sp, 0x38]\n" + "\tldr r0, =gLinkPlayers\n" + "\tldrh r0, [r0, 0x4]\n" + "\tbl SeedRng2\n" + "\tbl GetLinkPlayerCount\n" + "\tlsls r0, 24\n" + "\tlsrs r4, r0, 24\n" + "\tmovs r0, 0\n" + "\tmov r8, r0\n" + "\tmov r1, sp\n" + "\tadds r1, 0x1C\n" + "\tstr r1, [sp, 0x4C]\n" + "\tmov r2, sp\n" + "\tadds r2, 0x1D\n" + "\tstr r2, [sp, 0x50]\n" + "\tmov r3, sp\n" + "\tadds r3, 0xC\n" + "\tstr r3, [sp, 0x48]\n" + "\tmovs r7, 0xFF\n" + "\tadd r3, sp, 0x8\n" + "\tmovs r2, 0\n" + "\tadds r6, r1, 0\n" + "\tldr r5, [sp, 0x50]\n" + "_080E7BB0:\n" + "\tmov r1, sp\n" + "\tadd r1, r8\n" + "\tadds r1, 0x4\n" + "\tldrb r0, [r1]\n" + "\torrs r0, r7\n" + "\tstrb r0, [r1]\n" + "\tmov r1, r8\n" + "\tadds r0, r3, r1\n" + "\tstrb r2, [r0]\n" + "\tlsls r1, 1\n" + "\tadds r0, r6, r1\n" + "\tstrb r2, [r0]\n" + "\tadds r1, r5, r1\n" + "\tstrb r2, [r1]\n" + "\tmov r0, r8\n" + "\tadds r0, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tmov r8, r0\n" + "\tcmp r0, 0x3\n" + "\tbls _080E7BB0\n" + "\tbl Link_AnyPartnersPlayingRubyOrSapphire\n" + "\tstr r0, [sp, 0x3C]\n" + "\tmovs r2, 0\n" + "\tmov r8, r2\n" + "\tlsls r4, 16\n" + "\tstr r4, [sp, 0x54]\n" + "\tldr r0, [sp, 0x30]\n" + "\tmov r3, r9\n" + "\tmuls r3, r0\n" + "\tstr r3, [sp, 0x44]\n" + "\tb _080E7D04\n" + "\t.pool\n" + "_080E7BF8:\n" + "\tldr r1, [sp, 0x30]\n" + "\tmov r0, r8\n" + "\tmuls r0, r1\n" + "\tldr r2, [sp, 0x2C]\n" + "\tadds r7, r2, r0\n" + "\tldr r1, =gLinkPlayers\n" + "\tmov r3, r8\n" + "\tlsls r0, r3, 3\n" + "\tsubs r0, r3\n" + "\tlsls r0, 2\n" + "\tadds r0, r1\n" + "\tldrh r1, [r0, 0x1A]\n" + "\tmov r9, r1\n" + "\tldrb r0, [r0]\n" + "\tstr r0, [sp, 0x40]\n" + "\tmovs r6, 0\n" + "\tldr r0, [r7, 0x70]\n" + "\tcmp r6, r0\n" + "\tbcs _080E7CFA\n" + "\tmovs r2, 0x10\n" + "\tnegs r2, r2\n" + "\tmov r10, r2\n" + "_080E7C24:\n" + "\tlsls r0, r6, 3\n" + "\tsubs r0, r6\n" + "\tlsls r0, 3\n" + "\tadds r5, r7, r0\n" + "\tldrh r0, [r5, 0x20]\n" + "\tcmp r0, 0\n" + "\tbeq _080E7CEE\n" + "\tldr r3, [sp, 0x3C]\n" + "\tcmp r3, 0\n" + "\tbeq _080E7C9A\n" + "\tadds r4, r5, 0\n" + "\tadds r4, 0x24\n" + "\tadds r0, r4, 0\n" + "\tbl StringLength\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tcmp r0, 0x5\n" + "\tbhi _080E7C54\n" + "\tmovs r4, 0x1\n" + "\tb _080E7C5C\n" + "\t.pool\n" + "_080E7C54:\n" + "\tadds r0, r4, 0\n" + "\tbl StripExtCtrlCodes\n" + "\tmov r4, r9\n" + "_080E7C5C:\n" + "\tldrh r1, [r5, 0x2C]\n" + "\tldr r0, =0x000015fc\n" + "\tcmp r1, r0\n" + "\tbne _080E7C74\n" + "\tadds r0, r5, 0\n" + "\tadds r0, 0x2C\n" + "\tbl StripExtCtrlCodes\n" + "\tmovs r1, 0x1\n" + "\tb _080E7C76\n" + "\t.pool\n" + "_080E7C74:\n" + "\tmov r1, r9\n" + "_080E7C76:\n" + "\tldr r0, [sp, 0x40]\n" + "\tsubs r0, 0x1\n" + "\tcmp r0, 0x1\n" + "\tbhi _080E7CEE\n" + "\tadds r2, r5, 0\n" + "\tadds r2, 0x37\n" + "\tmovs r0, 0xF\n" + "\tands r4, r0\n" + "\tldrb r0, [r2]\n" + "\tmov r3, r10\n" + "\tands r0, r3\n" + "\torrs r0, r4\n" + "\tlsls r1, 4\n" + "\tmovs r3, 0xF\n" + "\tands r0, r3\n" + "\torrs r0, r1\n" + "\tstrb r0, [r2]\n" + "\tb _080E7CEE\n" + "_080E7C9A:\n" + "\tmov r0, r9\n" + "\tcmp r0, 0x1\n" + "\tbne _080E7CEE\n" + "\tadds r0, r5, 0\n" + "\tadds r0, 0x24\n" + "\tbl IsStringJapanese\n" + "\tcmp r0, 0\n" + "\tbeq _080E7CBA\n" + "\tadds r0, r5, 0\n" + "\tadds r0, 0x37\n" + "\tldrb r1, [r0]\n" + "\tmov r2, r10\n" + "\tands r1, r2\n" + "\tmovs r2, 0x1\n" + "\tb _080E7CC6\n" + "_080E7CBA:\n" + "\tadds r0, r5, 0\n" + "\tadds r0, 0x37\n" + "\tldrb r1, [r0]\n" + "\tmov r3, r10\n" + "\tands r1, r3\n" + "\tmovs r2, 0x2\n" + "_080E7CC6:\n" + "\torrs r1, r2\n" + "\tstrb r1, [r0]\n" + "\tadds r4, r0, 0\n" + "\tadds r0, r5, 0\n" + "\tadds r0, 0x2C\n" + "\tbl IsStringJapanese\n" + "\tcmp r0, 0\n" + "\tbeq _080E7CE2\n" + "\tldrb r0, [r4]\n" + "\tmovs r1, 0xF\n" + "\tands r1, r0\n" + "\tmovs r0, 0x10\n" + "\tb _080E7CEA\n" + "_080E7CE2:\n" + "\tldrb r0, [r4]\n" + "\tmovs r1, 0xF\n" + "\tands r1, r0\n" + "\tmovs r0, 0x20\n" + "_080E7CEA:\n" + "\torrs r1, r0\n" + "\tstrb r1, [r4]\n" + "_080E7CEE:\n" + "\tadds r0, r6, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r6, r0, 16\n" + "\tldr r0, [r7, 0x70]\n" + "\tcmp r6, r0\n" + "\tbcc _080E7C24\n" + "_080E7CFA:\n" + "\tmov r0, r8\n" + "\tadds r0, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tmov r8, r0\n" + "_080E7D04:\n" + "\tbl GetLinkPlayerCount\n" + "\tlsls r0, 24\n" + "\tlsrs r0, 24\n" + "\tcmp r8, r0\n" + "\tbcs _080E7D12\n" + "\tb _080E7BF8\n" + "_080E7D12:\n" + "\tmovs r0, 0\n" + "\tstr r0, [sp, 0x34]\n" + "\tmov r8, r0\n" + "\tldr r1, [sp, 0x54]\n" + "\tlsrs r0, r1, 16\n" + "\tldr r2, [sp, 0x34]\n" + "\tcmp r2, r0\n" + "\tbcs _080E7D70\n" + "\tadds r5, r0, 0\n" + "_080E7D24:\n" + "\tldr r3, [sp, 0x30]\n" + "\tmov r0, r8\n" + "\tmuls r0, r3\n" + "\tldr r1, [sp, 0x2C]\n" + "\tadds r7, r1, r0\n" + "\tldr r0, [r7, 0x70]\n" + "\tcmp r0, 0\n" + "\tbeq _080E7D62\n" + "\tmovs r6, 0\n" + "\tcmp r6, r0\n" + "\tbcs _080E7D62\n" + "\tadds r3, r7, 0\n" + "\tadds r3, 0x74\n" + "\tldr r2, [sp, 0x4C]\n" + "\tmov r0, r8\n" + "\tlsls r1, r0, 1\n" + "\tmovs r4, 0x1\n" + "_080E7D46:\n" + "\tlsls r0, r6, 1\n" + "\tadds r0, r3, r0\n" + "\tldrh r0, [r0]\n" + "\tcmp r0, 0\n" + "\tbne _080E7D56\n" + "\tadds r0, r6, r1\n" + "\tadds r0, r2, r0\n" + "\tstrb r4, [r0]\n" + "_080E7D56:\n" + "\tadds r0, r6, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r6, r0, 16\n" + "\tldr r0, [r7, 0x70]\n" + "\tcmp r6, r0\n" + "\tbcc _080E7D46\n" + "_080E7D62:\n" + "\tmov r0, r8\n" + "\tadds r0, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tmov r8, r0\n" + "\tcmp r8, r5\n" + "\tbcc _080E7D24\n" + "_080E7D70:\n" + "\tmovs r6, 0\n" + "\tmov r8, r6\n" + "\tldr r1, [sp, 0x54]\n" + "\tcmp r1, 0\n" + "\tbeq _080E7E64\n" + "\tadd r2, sp, 0x24\n" + "\tmov r10, r2\n" + "\tmovs r3, 0x25\n" + "\tadd r3, sp\n" + "\tmov r9, r3\n" + "_080E7D84:\n" + "\tldr r1, [sp, 0x30]\n" + "\tmov r0, r8\n" + "\tmuls r0, r1\n" + "\tldr r2, [sp, 0x2C]\n" + "\tadds r7, r2, r0\n" + "\tmov r3, r8\n" + "\tlsls r1, r3, 1\n" + "\tldr r2, [sp, 0x4C]\n" + "\tadds r0, r2, r1\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0x1\n" + "\tbeq _080E7DA6\n" + "\tldr r3, [sp, 0x50]\n" + "\tadds r0, r3, r1\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0x1\n" + "\tbne _080E7DB0\n" + "_080E7DA6:\n" + "\tldr r0, [sp, 0x34]\n" + "\tadds r0, 0x1\n" + "\tlsls r0, 24\n" + "\tlsrs r0, 24\n" + "\tstr r0, [sp, 0x34]\n" + "_080E7DB0:\n" + "\tldr r2, [sp, 0x4C]\n" + "\tadds r0, r2, r1\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0x1\n" + "\tbne _080E7DD4\n" + "\tldr r3, [sp, 0x50]\n" + "\tadds r0, r3, r1\n" + "\tldrb r2, [r0]\n" + "\tcmp r2, 0\n" + "\tbne _080E7DD4\n" + "_080E7DC4:\n" + "\tlsls r1, r6, 1\n" + "\tmov r3, r10\n" + "\tadds r0, r3, r1\n" + "\tmov r3, r8\n" + "\tstrb r3, [r0]\n" + "\tadd r1, r9\n" + "\tstrb r2, [r1]\n" + "\tb _080E7E4E\n" + "_080E7DD4:\n" + "\tldr r2, [sp, 0x4C]\n" + "\tadds r0, r2, r1\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0\n" + "\tbne _080E7DE8\n" + "\tldr r3, [sp, 0x50]\n" + "\tadds r0, r3, r1\n" + "\tldrb r2, [r0]\n" + "\tcmp r2, 0x1\n" + "\tbeq _080E7DC4\n" + "_080E7DE8:\n" + "\tldr r2, [sp, 0x4C]\n" + "\tadds r0, r2, r1\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0x1\n" + "\tbne _080E7E54\n" + "\tldr r3, [sp, 0x50]\n" + "\tadds r0, r3, r1\n" + "\tldrb r0, [r0]\n" + "\tcmp r0, 0x1\n" + "\tbne _080E7E54\n" + "\tlsls r5, r6, 1\n" + "\tmov r1, r10\n" + "\tadds r0, r1, r5\n" + "\tmov r2, r8\n" + "\tstrb r2, [r0]\n" + "\tadds r0, r7, 0\n" + "\tbl sub_80E7A9C\n" + "\tadds r4, r0, 0\n" + "\tlsls r4, 24\n" + "\tlsrs r4, 24\n" + "\tadds r0, r7, 0\n" + "\tadds r0, 0x38\n" + "\tbl sub_80E7A9C\n" + "\tlsls r0, 24\n" + "\tlsrs r1, r0, 24\n" + "\tcmp r4, 0\n" + "\tbne _080E7E30\n" + "\tcmp r1, 0\n" + "\tbeq _080E7E34\n" + "\tmov r3, r9\n" + "\tadds r1, r3, r5\n" + "\tmovs r0, 0x1\n" + "\tstrb r0, [r1]\n" + "\tb _080E7E4E\n" + "_080E7E30:\n" + "\tcmp r1, 0\n" + "\tbeq _080E7E48\n" + "_080E7E34:\n" + "\tbl Random2\n" + "\tmov r1, r9\n" + "\tadds r2, r1, r5\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tmovs r1, 0x1\n" + "\tands r0, r1\n" + "\tstrb r0, [r2]\n" + "\tb _080E7E4E\n" + "_080E7E48:\n" + "\tmov r2, r9\n" + "\tadds r0, r2, r5\n" + "\tstrb r1, [r0]\n" + "_080E7E4E:\n" + "\tadds r0, r6, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r6, r0, 16\n" + "_080E7E54:\n" + "\tmov r0, r8\n" + "\tadds r0, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r3, r0, 16\n" + "\tmov r8, r3\n" + "\tldr r1, [sp, 0x54]\n" + "\tcmp r0, r1\n" + "\tbcc _080E7D84\n" + "_080E7E64:\n" + "\tmovs r2, 0\n" + "\tmov r8, r2\n" + "\tldr r3, [sp, 0x44]\n" + "\tlsls r0, r3, 4\n" + "\tsubs r0, r3\n" + "\tlsls r0, 3\n" + "\tldr r1, [sp, 0x2C]\n" + "\tadds r7, r1, r0\n" + "\tldr r1, [sp, 0x48]\n" + "_080E7E76:\n" + "\tmov r2, r8\n" + "\tlsls r0, r2, 2\n" + "\tadds r0, r1, r0\n" + "\tstr r7, [r0]\n" + "\tmov r0, r8\n" + "\tadds r0, 0x1\n" + "\tlsls r0, 16\n" + "\tlsrs r0, 16\n" + "\tmov r8, r0\n" + "\tcmp r0, 0x3\n" + "\tbls _080E7E76\n" + "\tbl sub_80E7B54\n" + "\tlsls r0, 24\n" + "\tlsrs r0, 24\n" + "\tmovs r1, 0x3\n" + "\tbl __umodsi3\n" + "\tlsls r0, 24\n" + "\tlsrs r1, r0, 24\n" + "\tldr r3, [sp, 0x34]\n" + "\tcmp r3, 0x3\n" + "\tbeq _080E7EC8\n" + "\tcmp r3, 0x3\n" + "\tbgt _080E7EAE\n" + "\tcmp r3, 0x2\n" + "\tbeq _080E7EB6\n" + "\tb _080E7F1C\n" + "_080E7EAE:\n" + "\tldr r0, [sp, 0x34]\n" + "\tcmp r0, 0x4\n" + "\tbeq _080E7EE8\n" + "\tb _080E7F1C\n" + "_080E7EB6:\n" + "\tadd r2, sp, 0x24\n" + "\tmovs r0, 0x1\n" + "\tstr r0, [sp]\n" + "\tldr r0, [sp, 0x2C]\n" + "\tldr r1, [sp, 0x30]\n" + "\tmovs r3, 0\n" + "\tbl sub_80E7AA4\n" + "\tb _080E7F1C\n" + "_080E7EC8:\n" + "\tldr r0, =gUnknown_0858CFB8\n" + "\tlsls r1, 1\n" + "\tadds r2, r1, r0\n" + "\tldrb r3, [r2]\n" + "\tadds r0, 0x1\n" + "\tadds r1, r0\n" + "\tldrb r0, [r1]\n" + "\tadd r2, sp, 0x24\n" + "\tstr r0, [sp]\n" + "\tldr r0, [sp, 0x2C]\n" + "\tldr r1, [sp, 0x30]\n" + "\tbl sub_80E7AA4\n" + "\tb _080E7F1C\n" + "\t.pool\n" + "_080E7EE8:\n" + "\tadd r6, sp, 0x24\n" + "\tldr r4, =gUnknown_0858CFBE\n" + "\tlsls r5, r1, 2\n" + "\tadds r0, r5, r4\n" + "\tldrb r3, [r0]\n" + "\tadds r0, r4, 0x1\n" + "\tadds r0, r5, r0\n" + "\tldrb r0, [r0]\n" + "\tstr r0, [sp]\n" + "\tldr r0, [sp, 0x2C]\n" + "\tldr r1, [sp, 0x30]\n" + "\tadds r2, r6, 0\n" + "\tbl sub_80E7AA4\n" + "\tadds r0, r4, 0x2\n" + "\tadds r0, r5, r0\n" + "\tldrb r3, [r0]\n" + "\tadds r4, 0x3\n" + "\tadds r5, r4\n" + "\tldrb r0, [r5]\n" + "\tstr r0, [sp]\n" + "\tldr r0, [sp, 0x2C]\n" + "\tldr r1, [sp, 0x30]\n" + "\tadds r2, r6, 0\n" + "\tbl sub_80E7AA4\n" + "_080E7F1C:\n" + "\tldr r1, [sp, 0x2C]\n" + "\tldr r2, [sp, 0x44]\n" + "\tadds r7, r1, r2\n" + "\tldr r4, =gSaveBlock1Ptr\n" + "\tldr r0, [r4]\n" + "\tmovs r3, 0xC2\n" + "\tlsls r3, 6\n" + "\tadds r0, r3\n" + "\tadds r1, r7, 0\n" + "\tmovs r2, 0x38\n" + "\tbl memcpy\n" + "\tldr r0, [r4]\n" + "\tldr r1, =0x0000310c\n" + "\tadds r0, r1\n" + "\tadds r1, r7, 0\n" + "\tadds r1, 0x38\n" + "\tmovs r2, 0x38\n" + "\tbl memcpy\n" + "\tldr r0, [sp, 0x38]\n" + "\tbl SeedRng\n" + "\tadd sp, 0x58\n" + "\tpop {r3-r5}\n" + "\tmov r8, r3\n" + "\tmov r9, r4\n" + "\tmov r10, r5\n" + "\tpop {r4-r7}\n" + "\tpop {r0}\n" + "\tbx r0\n" + "\t.pool"); +} +#endif // NONMATCHING From 8d6007256f2d59765c89c41af4f3487e283e9381 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 6 Nov 2017 23:20:11 -0500 Subject: [PATCH 16/26] sub_80E7F68 --- asm/record_mixing.s | 58 ----------------------------- include/items.h | 9 +++++ src/item.c | 9 ----- src/record_mixing.c | 89 ++++++++++++++++++++++++++++++--------------- 4 files changed, 69 insertions(+), 96 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 059faa8e5..9ae60d9a7 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,64 +5,6 @@ .text - thumb_func_start sub_80E7F68 -sub_80E7F68: @ 80E7F68 - push {r4,lr} - adds r4, r0, 0 - lsls r1, 24 - cmp r1, 0 - beq _080E7FEC - ldrh r0, [r4] - cmp r0, 0 - beq _080E7FEC - bl GetPocketByItemId - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x5 - bne _080E7FEC - ldrh r0, [r4] - movs r1, 0x1 - bl CheckBagHasItem - lsls r0, 24 - cmp r0, 0 - bne _080E7FE4 - ldrh r0, [r4] - movs r1, 0x1 - bl CheckPCHasItem - lsls r0, 24 - cmp r0, 0 - bne _080E7FE4 - ldrh r0, [r4] - movs r1, 0x1 - bl AddBagItem - lsls r0, 24 - cmp r0, 0 - beq _080E7FE4 - ldr r0, =0x00004001 - ldrh r1, [r4] - bl VarSet - ldr r0, =gStringVar1 - ldr r1, =gLinkPlayers + 8 - bl StringCopy - ldrh r1, [r4] - ldr r0, =0x00000113 - cmp r1, r0 - bne _080E7FEC - ldr r0, =0x000008b3 - bl FlagSet - b _080E7FEC - .pool -_080E7FE4: - ldr r0, =0x00004001 - movs r1, 0 - bl VarSet -_080E7FEC: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E7F68 - thumb_func_start sub_80E7FF8 sub_80E7FF8: @ 80E7FF8 push {r4,r5,lr} diff --git a/include/items.h b/include/items.h index 69515f18e..b8cc23d82 100644 --- a/include/items.h +++ b/include/items.h @@ -386,4 +386,13 @@ enum ITEM_OLD_SEA_MAP, // 0x178 }; +enum +{ + ITEMS_POCKET, + BALLS_POCKET, + TMHM_POCKET, + BERRIES_POCKET, + KEYITEMS_POCKET +}; + #endif // GUARD_ITEMS_H diff --git a/src/item.c b/src/item.c index 0114676b6..845c0109c 100644 --- a/src/item.c +++ b/src/item.c @@ -16,15 +16,6 @@ extern const u8 gUnknown_085897E4[][28]; // not sure what this one is bool8 CheckPyramidBagHasItem(u16 itemId, u16 count); bool8 CheckPyramidBagHasSpace(u16 itemId, u16 count); -enum -{ - ITEMS_POCKET, - BALLS_POCKET, - TMHM_POCKET, - BERRIES_POCKET, - KEYITEMS_POCKET -}; - u16 GetBagItemQuantity(u16* quantity) { return gSaveBlock2Ptr->encryptionKey ^ *quantity; diff --git a/src/record_mixing.c b/src/record_mixing.c index 66972b650..e8a61a223 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -5,7 +5,7 @@ #include "rng.h" #include "items.h" #include "text.h" - +#include "item.h" #include "task.h" #include "species.h" #include "pokemon.h" @@ -32,13 +32,24 @@ // Static type declarations +struct PlayerRecordsRS { + struct SecretBaseRecord secretBases[20]; + TVShow tvShows[25]; + PokeNews pokeNews[16]; + OldMan oldMan; + struct EasyChatPair easyChatPairs[5]; + struct UnkStruct_80E7B60 dayCareMail; + struct RSBattleTowerRecord battleTowerRecord; + u16 filler11C8[0x32]; +}; + struct PlayerRecords { /* 0x0000 */ struct SecretBaseRecord secretBases[20]; /* 0x0c80 */ TVShow tvShows[25]; /* 0x1004 */ PokeNews pokeNews[16]; /* 0x1044 */ OldMan oldMan; /* 0x1084 */ struct EasyChatPair easyChatPair[5]; - /* 0x10ac */ struct UnkStruct_80E7B60 unk_10ac; + /* 0x10ac */ struct UnkStruct_80E7B60 dayCareMail; /* 0x1124 */ union BattleTowerRecord battleTowerRecord; /* 0x1210 */ u16 unk_1210; /* 0x1214 */ LilycoveLady lilycoveLady; @@ -84,7 +95,7 @@ static void sub_80E7948(union BattleTowerRecord *, size_t, u8); static void sub_80E7A14(LilycoveLady *, size_t, u8); static void sub_80E7B2C(const u8 *); static void sub_80E7B60(struct UnkStruct_80E7B60 *, size_t, u8, TVShow *); -void sub_80E7F68(void *, u8); +void sub_80E7F68(u16 *item, u8 which); void sub_80E7FF8(u8 taskId); void sub_80E8110(void *, void *); void sub_80E8468(void *, size_t, u8); @@ -136,7 +147,7 @@ void sub_80E6CA0(struct PlayerRecords *dest) memcpy(dest->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); - sub_80E89F8(&dest->unk_10ac); + sub_80E89F8(&dest->dayCareMail); sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); if (GetMultiplayerId() == 0) { @@ -154,8 +165,8 @@ void sub_80E6D54(struct PlayerRecords *dest) memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); sub_8120B70(&dest->oldMan); memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); - sub_80E89F8(&dest->unk_10ac); - sub_80E8A54(&dest->unk_10ac); + sub_80E89F8(&dest->dayCareMail); + sub_80E8A54(&dest->dayCareMail); sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); TaskDummy4(&dest->battleTowerRecord); if (GetMultiplayerId() == 0) @@ -188,7 +199,7 @@ void sub_80E6E24(void) memcpy(&gUnknown_0203A018->oldMan, gUnknown_03001140, sizeof(OldMan)); memcpy(&gUnknown_0203A018->lilycoveLady, gUnknown_03001150, sizeof(LilycoveLady)); memcpy(gUnknown_0203A018->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); - sub_80E89F8(&gUnknown_0203A018->unk_10ac); + sub_80E89F8(&gUnknown_0203A018->dayCareMail); memcpy(&gUnknown_0203A018->battleTowerRecord, gUnknown_0300114C, 0xec); sub_80E8AC0(&gUnknown_0203A018->battleTowerRecord); if (GetMultiplayerId() == 0) @@ -200,36 +211,36 @@ void sub_80E6E24(void) } } -void sub_80E6F60(u32 a0) +void sub_80E6F60(u32 which) { if (Link_AnyPartnersPlayingRubyOrSapphire()) { // Ruby/Sapphire sub_80E7B2C((void *)gUnknown_0203A014[0].tvShows); - sub_80EAF80(gUnknown_0203A014[0].secretBases, 0x1230, a0); - sub_80E7B60(&gUnknown_0203A014[0].unk_10ac, 0x1230, a0, gUnknown_0203A014[0].tvShows); - sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, 0x1230, a0); - sub_80F01E8(gUnknown_0203A014[0].tvShows, 0x1230, a0); - sub_80F0C7C(gUnknown_0203A014[0].pokeNews, 0x1230, a0); - sub_80E78C4(&gUnknown_0203A014[0].oldMan, 0x1230, a0); - sub_812287C(gUnknown_0203A014[0].easyChatPair, 0x1230, a0); - sub_80E7F68(&gUnknown_0203A014[0].battleTowerRecord.ruby_sapphire.unk_11c8, a0); + sub_80EAF80(gUnknown_0203A014[0].secretBases, sizeof(struct PlayerRecordsRS), which); + sub_80E7B60(&gUnknown_0203A014[0].dayCareMail, sizeof(struct PlayerRecordsRS), which, gUnknown_0203A014[0].tvShows); + sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, sizeof(struct PlayerRecordsRS), which); + sub_80F01E8(gUnknown_0203A014[0].tvShows, sizeof(struct PlayerRecordsRS), which); + sub_80F0C7C(gUnknown_0203A014[0].pokeNews, sizeof(struct PlayerRecordsRS), which); + sub_80E78C4(&gUnknown_0203A014[0].oldMan, sizeof(struct PlayerRecordsRS), which); + sub_812287C(gUnknown_0203A014[0].easyChatPair, sizeof(struct PlayerRecordsRS), which); + sub_80E7F68(&gUnknown_0203A014[0].battleTowerRecord.ruby_sapphire.unk_11c8, which); } else { // Emerald sub_80E7B2C((void *)gUnknown_0203A014[0].tvShows); - sub_80EAF80(gUnknown_0203A014[0].secretBases, 0x1444, a0); - sub_80F01E8(gUnknown_0203A014[0].tvShows, 0x1444, a0); - sub_80F0C7C(gUnknown_0203A014[0].pokeNews, 0x1444, a0); - sub_80E78C4(&gUnknown_0203A014[0].oldMan, 0x1444, a0); - sub_812287C(gUnknown_0203A014[0].easyChatPair, 0x1444, a0); - sub_80E7B60(&gUnknown_0203A014[0].unk_10ac, 0x1444, a0, gUnknown_0203A014[0].tvShows); - sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, 0x1444, a0); - sub_80E7F68(&gUnknown_0203A014[0].unk_1210, a0); - sub_80E7A14(&gUnknown_0203A014[0].lilycoveLady, 0x1444, a0); - sub_80E8468(gUnknown_0203A014[0].unk_1254, 0x1444, a0); - sub_80E89AC(gUnknown_0203A014[0].unk_12dc, 0x1444, a0); + sub_80EAF80(gUnknown_0203A014[0].secretBases, sizeof(struct PlayerRecords), which); + sub_80F01E8(gUnknown_0203A014[0].tvShows, sizeof(struct PlayerRecords), which); + sub_80F0C7C(gUnknown_0203A014[0].pokeNews, sizeof(struct PlayerRecords), which); + sub_80E78C4(&gUnknown_0203A014[0].oldMan, sizeof(struct PlayerRecords), which); + sub_812287C(gUnknown_0203A014[0].easyChatPair, sizeof(struct PlayerRecords), which); + sub_80E7B60(&gUnknown_0203A014[0].dayCareMail, sizeof(struct PlayerRecords), which, gUnknown_0203A014[0].tvShows); + sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, sizeof(struct PlayerRecords), which); + sub_80E7F68(&gUnknown_0203A014[0].unk_1210, which); + sub_80E7A14(&gUnknown_0203A014[0].lilycoveLady, sizeof(struct PlayerRecords), which); + sub_80E8468(gUnknown_0203A014[0].unk_1254, sizeof(struct PlayerRecords), which); + sub_80E89AC(gUnknown_0203A014[0].unk_12dc, sizeof(struct PlayerRecords), which); } } @@ -396,7 +407,7 @@ static void sub_80E7324(u8 taskId) task->data[10] = taskId2; gTasks[taskId2].data[0] = taskId; sub_80E7808(gUnknown_0203A014, (u16 *)&gTasks[taskId2].data[5]); - gUnknown_0300115C = 0x1230; + gUnknown_0300115C = sizeof(struct PlayerRecordsRS); } else { @@ -405,7 +416,7 @@ static void sub_80E7324(u8 taskId) task->data[10] = taskId2; gTasks[taskId2].data[0] = taskId; sub_80E7808(gUnknown_0203A014, (u16 *)&gTasks[taskId2].data[5]); - gUnknown_0300115C = 0x1444; + gUnknown_0300115C = sizeof(struct PlayerRecords); } break; case 5: @@ -1411,3 +1422,23 @@ __attribute__((naked)) static void sub_80E7B60(struct UnkStruct_80E7B60 *src, si "\t.pool"); } #endif // NONMATCHING + +static void sub_80E7F68(u16 *item, u8 which) +{ + if (which != 0 && *item != ITEM_NONE && GetPocketByItemId(*item) == KEYITEMS_POCKET + 1) + { + if (!CheckBagHasItem(*item, 1) && !CheckPCHasItem(*item, 1) && AddBagItem(*item, 1)) + { + VarSet(VAR_0x4001, *item); + StringCopy(gStringVar1, gLinkPlayers[0].name); + if (*item == ITEM_EON_TICKET) + { + FlagSet(SYS_HAS_EON_TICKET); + } + } + else + { + VarSet(VAR_0x4001, ITEM_NONE); + } + } +} From bc063b45d05716d1eab283f6d474bcdc601cafde Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 6 Nov 2017 23:33:39 -0500 Subject: [PATCH 17/26] sub_80E7FF8 --- asm/record_mixing.s | 126 -------------------------------------------- include/link.h | 1 + include/load_save.h | 3 +- include/save.h | 3 ++ src/record_mixing.c | 86 +++++++++++++++++++++++++++++- 5 files changed, 90 insertions(+), 129 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 9ae60d9a7..474eff46f 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,132 +5,6 @@ .text - thumb_func_start sub_80E7FF8 -sub_80E7FF8: @ 80E7FF8 - push {r4,r5,lr} - lsls r0, 24 - lsrs r5, r0, 24 - lsls r0, r5, 2 - adds r0, r5 - lsls r0, 3 - ldr r1, =gTasks - adds r4, r0, r1 - movs r1, 0x8 - ldrsh r0, [r4, r1] - cmp r0, 0x9 - bls _080E8012 - b _080E810A -_080E8012: - lsls r0, 2 - ldr r1, =_080E8024 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .pool - .align 2, 0 -_080E8024: - .4byte _080E80F2 - .4byte _080E804C - .4byte _080E805A - .4byte _080E8064 - .4byte _080E807C - .4byte _080E8090 - .4byte _080E80A4 - .4byte _080E80C0 - .4byte _080E80EE - .4byte _080E80FA -_080E804C: - bl Link_AnyPartnersPlayingRubyOrSapphire - cmp r0, 0 - bne _080E80F2 - movs r0, 0x6 - strh r0, [r4, 0x8] - b _080E810A -_080E805A: - bl sub_8076D5C - bl sub_8153430 - b _080E80F2 -_080E8064: - bl sub_8153474 - lsls r0, 24 - cmp r0, 0 - beq _080E810A - bl sav2_gender2_inplace_and_xFE - movs r1, 0 - movs r0, 0x4 - strh r0, [r4, 0x8] - strh r1, [r4, 0xA] - b _080E810A -_080E807C: - ldrh r0, [r4, 0xA] - adds r0, 0x1 - strh r0, [r4, 0xA] - lsls r0, 16 - asrs r0, 16 - cmp r0, 0xA - ble _080E810A - bl sub_800AC34 - b _080E80F2 -_080E8090: - ldr r0, =gReceivedRemoteLinkPlayers - ldrb r0, [r0] - cmp r0, 0 - bne _080E810A - adds r0, r5, 0 - bl DestroyTask - b _080E810A - .pool -_080E80A4: - movs r0, 0 - bl sub_801048C - lsls r0, 24 - cmp r0, 0 - bne _080E810A - ldr r0, =sub_8153688 - movs r1, 0x5 - bl CreateTask - b _080E80F2 - .pool -_080E80C0: - ldr r0, =sub_8153688 - bl FuncIsActiveTask - lsls r0, 24 - cmp r0, 0 - bne _080E810A - ldr r0, =gLinkVSyncDisabled - ldrb r0, [r0] - cmp r0, 0 - beq _080E80E8 - movs r0, 0x1 - bl sub_801048C - movs r0, 0x8 - strh r0, [r4, 0x8] - b _080E810A - .pool -_080E80E8: - movs r0, 0x4 - strh r0, [r4, 0x8] - b _080E810A -_080E80EE: - bl sub_800ADF8 -_080E80F2: - ldrh r0, [r4, 0x8] - adds r0, 0x1 - strh r0, [r4, 0x8] - b _080E810A -_080E80FA: - bl sub_800A520 - lsls r0, 24 - cmp r0, 0 - beq _080E810A - adds r0, r5, 0 - bl DestroyTask -_080E810A: - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_80E7FF8 - thumb_func_start sub_80E8110 sub_80E8110: @ 80E8110 push {r4-r7,lr} diff --git a/include/link.h b/include/link.h index 77e9a9d24..a33c7da89 100644 --- a/include/link.h +++ b/include/link.h @@ -201,5 +201,6 @@ u8 sub_800AA48(void); void sub_8009FAC(void); void sub_800A4D8(u8); u8 sub_800A9D8(void); +bool8 sub_801048C(u8); #endif // GUARD_LINK_H diff --git a/include/load_save.h b/include/load_save.h index 1f406bbad..ba85d4ad8 100644 --- a/include/load_save.h +++ b/include/load_save.h @@ -19,6 +19,7 @@ void LoadSerializedGame(void); void LoadPlayerBag(void); void SavePlayerBag(void); void SetSaveBlocksPointers(u16); -void MoveSaveBlocks_ResetHeap(void); +void sub_8076D5C(void); +void sav2_gender2_inplace_and_xFE(void); #endif // GUARD_LOAD_SAVE_H diff --git a/include/save.h b/include/save.h index 6c1238cd2..a3473371e 100644 --- a/include/save.h +++ b/include/save.h @@ -92,5 +92,8 @@ u8 HandleSavingData(u8 saveType); //u8 unref_sub_8126080(u8 sector, u8 *data); u16 sub_815355C(void); u8 sub_81534D0(u8); +u8 sub_8153430(void); +bool8 sub_8153474(void); +void sub_8153688(u8 taskId); #endif // GUARD_SAVE_H diff --git a/src/record_mixing.c b/src/record_mixing.c index e8a61a223..afaa091eb 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -8,6 +8,8 @@ #include "item.h" #include "task.h" #include "species.h" +#include "save.h" +#include "load_save.h" #include "pokemon.h" #include "cable_club.h" #include "link.h" @@ -95,8 +97,8 @@ static void sub_80E7948(union BattleTowerRecord *, size_t, u8); static void sub_80E7A14(LilycoveLady *, size_t, u8); static void sub_80E7B2C(const u8 *); static void sub_80E7B60(struct UnkStruct_80E7B60 *, size_t, u8, TVShow *); -void sub_80E7F68(u16 *item, u8 which); -void sub_80E7FF8(u8 taskId); +static void sub_80E7F68(u16 *item, u8 which); +static void sub_80E7FF8(u8 taskId); void sub_80E8110(void *, void *); void sub_80E8468(void *, size_t, u8); void sub_80E89AC(void *, size_t, u8); @@ -1442,3 +1444,83 @@ static void sub_80E7F68(u16 *item, u8 which) } } } + +static void sub_80E7FF8(u8 taskId) +{ + struct Task *task; + + task = &gTasks[taskId]; + switch (task->data[0]) + { + case 0: + task->data[0] ++; + break; + case 1: + if (Link_AnyPartnersPlayingRubyOrSapphire()) + { + task->data[0] ++; + } + else + { + task->data[0] = 6; + } + break; + case 2: + sub_8076D5C(); + sub_8153430(); + task->data[0] ++; + break; + case 3: + if (sub_8153474()) + { + sav2_gender2_inplace_and_xFE(); + task->data[0] = 4; + task->data[1] = 0; + } + break; + case 4: + if (++ task->data[1] > 10) + { + sub_800AC34(); + task->data[0] ++; + } + break; + case 5: + if (gReceivedRemoteLinkPlayers == 0) + { + DestroyTask(taskId); + } + break; + case 6: + if (!sub_801048C(0)) + { + CreateTask(sub_8153688, 5); + task->data[0] ++; + } + break; + case 7: + if (!FuncIsActiveTask(sub_8153688)) + { + if (gLinkVSyncDisabled) + { + sub_801048C(1); + task->data[0] = 8; + } + else + { + task->data[0] = 4; + } + } + break; + case 8: + sub_800ADF8(); + task->data[0] ++; + break; + case 9: + if (sub_800A520()) + { + DestroyTask(taskId); + } + break; + } +} From db898d0e4854c70a356d037919ea48aed1f62816 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 12 Feb 2018 08:16:28 -0500 Subject: [PATCH 18/26] Minor edit to make it possible to build when trying to match the nonmatching fn --- src/record_mixing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/record_mixing.c b/src/record_mixing.c index ff4d64f08..79db07bf0 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -894,8 +894,8 @@ static void sub_80E7B60(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 whi break; } _src = (void *)src + which * recordSize; - memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->unk_00[0], sizeof(struct DayCareMailRecordMixing)); - memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->unk_00[1], sizeof(struct DayCareMailRecordMixing)); + memcpy(&gSaveBlock1Ptr->daycare.mons[0].misc.mail, &_src->unk_00[0], sizeof(struct DayCareMailRecordMixing)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].misc.mail, &_src->unk_00[1], sizeof(struct DayCareMailRecordMixing)); SeedRng(oldSeed); } #else From 11d8f489c44cab2b05050ed136218957b2ef8a12 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 19 May 2018 14:30:41 +0200 Subject: [PATCH 19/26] failed attempt --- src/record_mixing.c | 62 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/record_mixing.c b/src/record_mixing.c index 1a39dfde9..43b87f840 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -31,9 +31,15 @@ #include "strings.h" #include "string_util.h" #include "record_mixing.h" +#include "new_game.h" // Static type declarations +struct UnkRecordMixingStruct +{ + u8 field_0[0x44]; +}; + struct PlayerRecordsRS { struct SecretBaseRecord secretBases[20]; TVShow tvShows[25]; @@ -99,7 +105,7 @@ static void sub_80E7B2C(const u8 *); static void sub_80E7B60(struct UnkStruct_80E7B60 *, size_t, u8, TVShow *); static void sub_80E7F68(u16 *item, u8 which); static void sub_80E7FF8(u8 taskId); -void sub_80E8110(void *, void *); +static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); void sub_80E8468(void *, size_t, u8); void sub_80E89AC(void *, size_t, u8); void sub_80E89F8(void *dest); @@ -206,7 +212,7 @@ void sub_80E6E24(void) { gUnknown_0203A018->unk_1210 = GetRecordMixingGift(); } - sub_80E8110(gUnknown_0203A018->unk_1254, gUnknown_03001154); + sub_80E8110((void*) gUnknown_0203A018->unk_1254, gUnknown_03001154); sub_80E8260(gUnknown_0203A018->unk_12dc); } } @@ -1521,3 +1527,55 @@ static void sub_80E7FF8(u8 taskId) break; } } + +/* +static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1) +{ + s32 i, id; + s32 var_28, var_24, var_2C, r8; + + arg0[0].field_0[0x38] = 0xFF; + arg0[1].field_0[0x38] = 0xFF; + memcpy(&arg0[0], &arg1[0], sizeof(struct UnkRecordMixingStruct)); + + var_28 = 0; + var_24 = 0; + var_2C = 0; + r8 = 0; + for (i = 0; i < 2; i++) + { + id = ((i + (gSaveBlock2Ptr->field_B0[2] << 0x1B >> 0x1E)) % 3) + 1; + if (arg1[id].field_0[0x38] != 0xFF) + { + if (ReadUnalignedWord(&arg1[id].field_0[0x34]) != ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId)) + { + r8++; + var_2C = id; + } + if (ReadUnalignedWord(&arg1[id].field_0[0x34]) == ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId)) + { + var_24++; + var_28 = id; + } + } + } + + if (r8 == 0 && var_24 != 0) + { + r8 = var_24; + var_2C = var_28; + } + + switch (r8) + { + case 1: + memcpy(&arg0[0], &arg1[var_2C], sizeof(struct UnkRecordMixingStruct)); + break; + case 2: + if (Random2() > 0x3333) + memcpy(&arg0[1], &arg1[(gSaveBlock2Ptr->field_B0[2] << 0x1B >> 0x1E) + 1], sizeof(struct UnkRecordMixingStruct)); + else + memcpy(&arg0[1], &arg1[((gSaveBlock2Ptr->field_B0[2] << 0x1B >> 0x1E) + 1) % 3 + 1], sizeof(struct UnkRecordMixingStruct)); + break; + } +}*/ From 1a8d5132d66c731c59ac1eee7eb33ea37a8cc1c4 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 20 May 2018 10:51:09 +0200 Subject: [PATCH 20/26] fix record mixing for real --- include/global.h | 1 - include/link.h | 1 - include/link_rfu.h | 1 + src/record_mixing.c | 3 ++- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/global.h b/include/global.h index a117a6391..bd2dbe7a6 100644 --- a/include/global.h +++ b/include/global.h @@ -749,7 +749,6 @@ struct SaveBlock1 /*0x3B14*/ struct RecordMixingGift recordMixingGift; /*0x3B24*/ u8 seen2[52]; /*0x3B58*/ LilycoveLady lilycoveLady; - /*0x3B88*/ u8 filler_3B88[0x10]; /*0x3B98*/ struct UnkSaveSubstruct_3b98 unk_3B98[20]; /*0x3C88*/ u8 filler_3C88[0xE8]; /*0x3D70*/ struct WaldaPhrase waldaPhrase; diff --git a/include/link.h b/include/link.h index 9dd85460e..5b3cd26ca 100644 --- a/include/link.h +++ b/include/link.h @@ -300,7 +300,6 @@ u8 sub_800AA48(void); void sub_8009FAC(void); bool8 sub_800A4D8(u8 a0); u8 sub_800A9D8(void); -bool8 sub_801048C(u8); u8 sub_800A0C8(s32, s32); #endif // GUARD_LINK_H diff --git a/include/link_rfu.h b/include/link_rfu.h index a6084b138..ca39c2fb2 100644 --- a/include/link_rfu.h +++ b/include/link_rfu.h @@ -231,5 +231,6 @@ struct UnkLinkRfuStruct_02022B14 *sub_800F7DC(void); void sub_8011068(u8 a0); void sub_8011170(u32 a0); void sub_8011A64(u8 a0, u16 a1); +u8 sub_801048C(bool32 a0); #endif //GUARD_LINK_RFU_H diff --git a/src/record_mixing.c b/src/record_mixing.c index 43b87f840..b825e7244 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -13,6 +13,7 @@ #include "pokemon.h" #include "cable_club.h" #include "link.h" +#include "link_rfu.h" #include "tv.h" #include "battle_tower.h" #include "window.h" @@ -105,7 +106,7 @@ static void sub_80E7B2C(const u8 *); static void sub_80E7B60(struct UnkStruct_80E7B60 *, size_t, u8, TVShow *); static void sub_80E7F68(u16 *item, u8 which); static void sub_80E7FF8(u8 taskId); -static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); +/*static*/ void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); void sub_80E8468(void *, size_t, u8); void sub_80E89AC(void *, size_t, u8); void sub_80E89F8(void *dest); From c8e1c80375e82358bd1dfdeb2254f5506fcb425b Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 20 May 2018 12:21:39 +0200 Subject: [PATCH 21/26] record mixing fix for real hopefully --- src/record_mixing.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/record_mixing.c b/src/record_mixing.c index b825e7244..e03702759 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -278,7 +278,7 @@ static void sub_80E715C(u8 taskId) gUnknown_0203A018 = malloc(sizeof(struct PlayerRecords)); gUnknown_0203A014 = malloc(sizeof(struct PlayerRecords) * 4); sub_8009628(gSpecialVar_0x8005); - VarSet(VAR_0x4000, 1); + VarSet(VAR_TEMP_0, 1); gUnknown_03001130 = FALSE; sub_80E6E24(); sub_80FB00C(); @@ -1435,7 +1435,7 @@ static void sub_80E7F68(u16 *item, u8 which) { if (!CheckBagHasItem(*item, 1) && !CheckPCHasItem(*item, 1) && AddBagItem(*item, 1)) { - VarSet(VAR_0x4001, *item); + VarSet(VAR_TEMP_1, *item); StringCopy(gStringVar1, gLinkPlayers[0].name); if (*item == ITEM_EON_TICKET) { @@ -1444,7 +1444,7 @@ static void sub_80E7F68(u16 *item, u8 which) } else { - VarSet(VAR_0x4001, ITEM_NONE); + VarSet(VAR_TEMP_1, ITEM_NONE); } } } From 03b593d3c3c763f29ba6e7c27e06fcae8a62054a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Tue, 22 May 2018 21:54:57 +0200 Subject: [PATCH 22/26] try my luck with record mixing --- asm/record_mixing.s | 411 ---------------------------------------- include/global.h | 62 +++++- include/record_mixing.h | 35 ++-- src/record_mixing.c | 149 ++++++++++----- 4 files changed, 182 insertions(+), 475 deletions(-) diff --git a/asm/record_mixing.s b/asm/record_mixing.s index 9ff2624d8..ceb25dd21 100644 --- a/asm/record_mixing.s +++ b/asm/record_mixing.s @@ -5,417 +5,6 @@ .text - thumb_func_start sub_80E8110 -sub_80E8110: @ 80E8110 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x10 - str r0, [sp] - mov r10, r1 - adds r1, r0, 0 - adds r1, 0x38 - movs r0, 0xFF - strb r0, [r1] - ldr r1, [sp] - adds r1, 0x7C - movs r0, 0x1 - negs r0, r0 - strb r0, [r1] - ldr r0, [sp] - mov r1, r10 - movs r2, 0x44 - bl memcpy - movs r0, 0 - str r0, [sp, 0x8] - movs r1, 0 - str r1, [sp, 0xC] - movs r2, 0 - str r2, [sp, 0x4] - mov r8, r2 - movs r7, 0 - ldr r0, =gSaveBlock2Ptr - mov r9, r0 -_080E8150: - mov r1, r9 - ldr r0, [r1] - adds r0, 0xB2 - ldrb r0, [r0] - lsls r0, 27 - lsrs r0, 30 - adds r0, r7, r0 - movs r1, 0x3 - bl __modsi3 - adds r6, r0, 0x1 - lsls r0, r6, 4 - adds r0, r6 - lsls r0, 2 - mov r2, r10 - adds r1, r0, r2 - adds r0, r1, 0 - adds r0, 0x38 - ldrb r0, [r0] - cmp r0, 0xFF - beq _080E81B8 - adds r5, r1, 0 - adds r5, 0x34 - adds r0, r5, 0 - bl ReadUnalignedWord - adds r4, r0, 0 - mov r1, r9 - ldr r0, [r1] - adds r0, 0xA - bl ReadUnalignedWord - cmp r4, r0 - beq _080E819A - movs r2, 0x1 - add r8, r2 - str r6, [sp, 0x4] -_080E819A: - adds r0, r5, 0 - bl ReadUnalignedWord - adds r4, r0, 0 - mov r1, r9 - ldr r0, [r1] - adds r0, 0xA - bl ReadUnalignedWord - cmp r4, r0 - bne _080E81B8 - ldr r2, [sp, 0xC] - adds r2, 0x1 - str r2, [sp, 0xC] - str r6, [sp, 0x8] -_080E81B8: - adds r7, 0x1 - cmp r7, 0x1 - ble _080E8150 - mov r0, r8 - cmp r0, 0 - bne _080E81D0 - ldr r1, [sp, 0xC] - cmp r1, 0 - beq _080E81D0 - mov r8, r1 - ldr r2, [sp, 0x8] - str r2, [sp, 0x4] -_080E81D0: - mov r0, r8 - cmp r0, 0x1 - beq _080E81E0 - cmp r0, 0x2 - beq _080E81EC - b _080E824C - .pool -_080E81E0: - ldr r2, [sp, 0x4] - lsls r1, r2, 4 - adds r1, r2 - lsls r1, 2 - add r1, r10 - b _080E820E -_080E81EC: - bl Random2 - lsls r0, 16 - ldr r1, =0x33330000 - cmp r0, r1 - bls _080E8224 - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - adds r0, 0xB2 - ldrb r0, [r0] - lsls r0, 27 - lsrs r0, 30 - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - add r1, r10 - adds r1, 0x44 -_080E820E: - ldr r0, [sp] - adds r0, 0x44 - movs r2, 0x44 - bl memcpy - b _080E824C - .pool -_080E8224: - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - adds r0, 0xB2 - ldrb r0, [r0] - lsls r0, 27 - lsrs r0, 30 - adds r0, 0x1 - movs r1, 0x3 - bl __modsi3 - lsls r1, r0, 4 - adds r1, r0 - lsls r1, 2 - add r1, r10 - adds r1, 0x44 - ldr r0, [sp] - adds r0, 0x44 - movs r2, 0x44 - bl memcpy -_080E824C: - add sp, 0x10 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E8110 - - thumb_func_start sub_80E8260 -sub_80E8260: @ 80E8260 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - mov r8, r0 - movs r6, 0 - ldr r0, =gSaveBlock2Ptr - mov r10, r0 -_080E8274: - movs r7, 0 - lsls r0, r6, 5 - adds r6, 0x1 - mov r9, r6 - mov r1, r8 - adds r4, r0, r1 - adds r0, 0x6 - adds r6, r1, r0 - adds r5, r4, 0 -_080E8286: - mov r2, r10 - ldr r1, [r2] - adds r1, 0xA - adds r0, r5, 0 - bl CopyUnalignedWord - movs r0, 0x2 - strb r0, [r4, 0xE] - mov r0, r10 - ldr r1, [r0] - adds r0, r6, 0 - bl StringCopy - adds r4, 0x10 - adds r6, 0x10 - adds r5, 0x10 - adds r7, 0x1 - cmp r7, 0x1 - ble _080E8286 - mov r6, r9 - cmp r6, 0x8 - ble _080E8274 - ldr r1, =gSaveBlock2Ptr - mov r10, r1 - ldr r2, =0x00000ee1 - str r2, [sp, 0x4] - movs r4, 0x99 - lsls r4, 1 - add r4, r8 - movs r0, 0x95 - lsls r0, 1 - add r0, r8 - mov r9, r0 - ldr r1, =0x00000ef1 - str r1, [sp, 0x8] - movs r6, 0x92 - lsls r6, 1 - add r6, r8 - movs r5, 0x90 - lsls r5, 1 - add r5, r8 - movs r7, 0x1 -_080E82DA: - movs r0, 0x2 - strb r0, [r4, 0x8] - mov r2, r10 - ldr r1, [r2] - adds r1, 0xA - adds r0, r5, 0 - bl CopyUnalignedWord - mov r0, r10 - ldr r1, [r0] - ldr r2, [sp, 0x8] - adds r1, r2 - adds r0, r6, 0 - bl CopyUnalignedWord - mov r0, r10 - ldr r1, [r0] - mov r0, r9 - bl StringCopy - mov r2, r10 - ldr r1, [r2] - ldr r0, [sp, 0x4] - adds r1, r0 - adds r0, r4, 0 - bl StringCopy - ldr r1, [sp, 0x4] - adds r1, 0x8 - str r1, [sp, 0x4] - adds r4, 0x1C - movs r2, 0x1C - add r9, r2 - ldr r0, [sp, 0x8] - adds r0, 0x4 - str r0, [sp, 0x8] - adds r6, 0x1C - adds r5, 0x1C - subs r7, 0x1 - cmp r7, 0 - bge _080E82DA - movs r6, 0 - ldr r0, =gSaveBlock2Ptr - ldr r3, [r0] - mov r4, r8 - movs r1, 0xC4 - adds r1, r4 - mov r9, r1 - movs r2, 0x84 - adds r2, r4 - mov r8, r2 - movs r0, 0x44 - adds r0, r4 - mov r12, r0 - adds r7, r4, 0x4 - movs r1, 0xCF - lsls r1, 4 - adds r1, r3, r1 - str r1, [sp] - mov r10, r4 - ldr r2, =0x00000cf4 - adds r5, r3, r2 -_080E8356: - lsls r2, r6, 1 - ldr r1, [sp] - ldrh r0, [r1] - strh r0, [r7] - ldrh r0, [r5] - strh r0, [r7, 0x20] - ldrh r0, [r5, 0x4] - mov r1, r12 - strh r0, [r1] - ldr r1, =0x00000d14 - adds r0, r3, r1 - adds r0, r2 - ldrh r0, [r0] - mov r1, r12 - strh r0, [r1, 0x20] - movs r1, 0xDD - lsls r1, 4 - adds r0, r3, r1 - adds r0, r2 - ldrh r0, [r0] - mov r1, r8 - strh r0, [r1] - ldr r1, =0x00000dde - adds r0, r3, r1 - adds r0, r2 - ldrh r0, [r0] - mov r1, r8 - strh r0, [r1, 0x20] - ldr r1, =0x00000dea - adds r0, r3, r1 - adds r0, r2 - ldrh r0, [r0] - mov r1, r9 - strh r0, [r1] - ldr r1, =0x00000e08 - adds r0, r3, r1 - adds r0, r2 - ldrh r0, [r0] - mov r1, r9 - strh r0, [r1, 0x20] - ldr r1, =0x00000e1e - adds r0, r3, r1 - adds r0, r2 - ldrh r1, [r0] - movs r0, 0x82 - lsls r0, 1 - add r0, r10 - strh r1, [r0] - ldr r1, =0x00000cfc - adds r0, r3, r1 - adds r0, r2 - ldrh r1, [r0] - movs r2, 0x94 - lsls r2, 1 - adds r0, r4, r2 - strh r1, [r0] - adds r4, 0x1C - movs r0, 0x10 - add r9, r0 - add r8, r0 - add r12, r0 - adds r7, 0x10 - ldr r1, [sp] - adds r1, 0x2 - str r1, [sp] - add r10, r0 - adds r5, 0x2 - adds r6, 0x1 - cmp r6, 0x1 - ble _080E8356 - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E8260 - - thumb_func_start sub_80E841C -sub_80E841C: @ 80E841C - push {r4-r7,lr} - mov r7, r8 - push {r7} - adds r7, r0, 0 - movs r0, 0 - mov r8, r0 - adds r6, r1, 0 - adds r6, 0x34 - adds r5, r1, 0 -_080E842E: - adds r0, r7, 0 - adds r0, 0x34 - bl ReadUnalignedWord - adds r4, r0, 0 - adds r0, r6, 0 - bl ReadUnalignedWord - cmp r4, r0 - bne _080E844E - ldrb r0, [r7, 0x2] - ldrb r1, [r5, 0x2] - cmp r0, r1 - bne _080E844E - movs r0, 0x1 - b _080E845E -_080E844E: - adds r6, 0x44 - adds r5, 0x44 - movs r0, 0x1 - add r8, r0 - mov r1, r8 - cmp r1, 0x3 - ble _080E842E - movs r0, 0 -_080E845E: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end sub_80E841C thumb_func_start sub_80E8468 sub_80E8468: @ 80E8468 diff --git a/include/global.h b/include/global.h index bd2dbe7a6..fe82ea9a7 100644 --- a/include/global.h +++ b/include/global.h @@ -281,7 +281,11 @@ struct SaveBlock2 /*0xAC*/ u32 encryptionKey; // TODO: fix and verify labels - /*0xB0*/ u8 field_B0[0x2c]; + /*0xB0*/ u8 field_B0; + /*0xB1*/ u8 field_B1; + /*0xB2*/ u8 field_B2_0:3; + /*0xB2*/ u8 field_B2_1:2; + /*0xB3*/ u8 field_B3[0x29]; /*0xDC*/ u8 field_0DC[0x110]; /*0x1EC*/ struct BerryCrush berryCrush; /*0x1FC*/ struct PokemonJumpResults pokeJump; @@ -308,22 +312,64 @@ struct SaveBlock2 /*0xCA9*/ u8 field_CA9_f : 1; // 0x80 /*0xCAA*/ u16 field_CAA[4]; /*0xCB2*/ u16 battlePyramidWildHeaderId; - /*0xCB4*/ u16 field_CB4[41]; + /*0xCB4*/ u16 field_CB4[30]; + /*0xCF0*/ u16 field_CF0[2]; + /*0xCF4*/ u16 field_CF4[2]; + /*0xCF8*/ u16 field_CF8[2]; + /*0xCFC*/ u16 field_CFC[5]; /*0xD06*/ u8 field_D06; /*0xD07*/ u8 field_D07; - /*0xD08*/ u8 filler_D08[0x112]; + /*0xD08*/ u8 filler_D08; + /*0xD09*/ u8 filler_D09; + /*0xD0A*/ u8 filler_D0A; + /*0xD0B*/ u8 filler_D0B; + /*0xD0C*/ u8 filler_D0C; + /*0xD0D*/ u8 filler_D0D; + /*0xD0E*/ u8 filler_D0E; + /*0xD0F*/ u8 filler_D0F; + /*0xD10*/ u8 filler_D10; + /*0xD11*/ u8 filler_D11; + /*0xD12*/ u8 filler_D12; + /*0xD13*/ u8 filler_D13; + /*0xD14*/ u16 field_D14[2]; + /*0xD18*/ u8 field_D18[0xB8]; + /*0xDD0*/ u16 field_DD0[2]; + /*0xDD4*/ u16 field_DD4[2]; + /*0xDD8*/ u16 field_DD8; + /*0xDDA*/ u16 field_DDA; + /*0xDDC*/ u16 field_DDC; + /*0xDDE*/ u16 field_DDE[2]; + /*0xDE2*/ u16 field_DE2; + /*0xDE4*/ u16 field_DE4; + /*0xDE6*/ u16 field_DE6; + /*0xDE8*/ u16 field_DE8; + /*0xDEA*/ u16 field_DEA[2]; + /*0xDEE*/ u16 field_DEE; + /*0xDF0*/ u16 field_DF0; + /*0xDF2*/ u16 field_DF2; + /*0xDF4*/ u16 field_DF4; + /*0xDF6*/ u16 field_DF6; + /*0xDF8*/ u16 field_DF8; + /*0xDFA*/ u16 field_DFA; + /*0xDFC*/ u16 field_DFC; + /*0xDFE*/ u16 field_DFE; + /*0xE00*/ u16 field_E00; + /*0xE02*/ u16 field_E02; + /*0xE04*/ u16 field_E04; + /*0xE06*/ u16 field_E06; + /*0xE08*/ u16 field_E08[9]; /*0xE1A*/ u16 battlePyramidFloor; // possibly? - /*0xE1C*/ u8 field_E1C[16]; + /*0xE1C*/ u16 field_E1C; + /*0xE1E*/ u16 field_E1E[7]; /*0xE2C*/ struct PyramidBag pyramidBag; /*0x???*/ u8 field_unkown[6]; /*0xE6E*/ u16 battleTentWinStreak; /*0xE70*/ u8 field_E70[72]; /*0xEB8*/ u16 frontierBattlePoints; /*0xEBA*/ u8 field_EBA[39]; - /*0xEE1*/ u8 field_EE1; - /*0xEE2*/ u8 field_EE2[7]; - /*0xEE9*/ u8 field_EE9; - /*0xEEA*/ u8 field_EEA[66]; + /*0xEE1*/ u8 field_EE1[2][PLAYER_NAME_LENGTH]; + /*0xEF1*/ u8 field_EF1[2][4]; + /*0xEF9*/ u8 field_EF9[51]; // sizeof=0xF2C }; diff --git a/include/record_mixing.h b/include/record_mixing.h index e327d1510..875eca815 100644 --- a/include/record_mixing.h +++ b/include/record_mixing.h @@ -2,25 +2,34 @@ #define GUARD_RECORD_MIXING_H // Exported type declarations - -struct DayCareMailRecordMixing { - struct MailStruct mail; - u8 OT_name[OT_NAME_LENGTH + 1]; - u8 monName[11]; - u8 language_maybe:4; - u8 unknown:4; +struct UnkRecordMixingStruct2a +{ + u8 playerId[4]; + u16 field_4; + u8 playerName[PLAYER_NAME_LENGTH]; + u8 language; }; -struct UnkStruct_80E7B60 { - struct DayCareMailRecordMixing unk_00[2]; - u32 unk_70; - u16 unk_74[2]; -}; // size = 0x78 +struct UnkRecordMixingStruct2b +{ + u8 playerId1[4]; + u8 playerId2[4]; + u16 field_8; + u8 playerName1[PLAYER_NAME_LENGTH]; + u8 playerName2[PLAYER_NAME_LENGTH]; + u8 language; +}; + +struct UnkRecordMixingStruct2 +{ + struct UnkRecordMixingStruct2a field_0[9][2]; + struct UnkRecordMixingStruct2b field_120[2]; +}; // Exported RAM declarations // Exported ROM declarations -void sub_80E8260(void *); +void sub_80E8260(struct UnkRecordMixingStruct2 *arg0); #endif //GUARD_RECORD_MIXING_H diff --git a/src/record_mixing.c b/src/record_mixing.c index e03702759..553174325 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -38,31 +38,35 @@ struct UnkRecordMixingStruct { - u8 field_0[0x44]; + u8 field_0[0x34]; + u8 playerId[4]; + u8 field_38[10]; }; -struct PlayerRecordsRS { +struct PlayerRecordsRS +{ struct SecretBaseRecord secretBases[20]; TVShow tvShows[25]; PokeNews pokeNews[16]; OldMan oldMan; struct EasyChatPair easyChatPairs[5]; - struct UnkStruct_80E7B60 dayCareMail; + struct RecordMixingDayCareMail dayCareMail; struct RSBattleTowerRecord battleTowerRecord; u16 filler11C8[0x32]; }; -struct PlayerRecords { +struct PlayerRecords +{ /* 0x0000 */ struct SecretBaseRecord secretBases[20]; /* 0x0c80 */ TVShow tvShows[25]; /* 0x1004 */ PokeNews pokeNews[16]; /* 0x1044 */ OldMan oldMan; /* 0x1084 */ struct EasyChatPair easyChatPair[5]; - /* 0x10ac */ struct UnkStruct_80E7B60 dayCareMail; + /* 0x10ac */ struct RecordMixingDayCareMail dayCareMail; /* 0x1124 */ union BattleTowerRecord battleTowerRecord; /* 0x1210 */ u16 unk_1210; /* 0x1214 */ LilycoveLady lilycoveLady; - /* 0x1254 */ u8 unk_1254[0x88]; + /* 0x1254 */ struct UnkRecordMixingStruct unk_1254[2]; /* 0x12dc */ u8 unk_12dc[0x168]; }; // 1444 @@ -74,7 +78,7 @@ IWRAM_DATA TVShow *gUnknown_03001138; IWRAM_DATA PokeNews *gUnknown_0300113C; IWRAM_DATA OldMan *gUnknown_03001140; IWRAM_DATA struct EasyChatPair *gUnknown_03001144; -IWRAM_DATA struct UnkStruct_80E7B60 *gUnknown_03001148; +IWRAM_DATA struct RecordMixingDayCareMail *gUnknown_03001148; IWRAM_DATA void *gUnknown_0300114C; // gSaveBlock2Ptr->field_64C IWRAM_DATA LilycoveLady *gUnknown_03001150; IWRAM_DATA void *gUnknown_03001154; // gSaveBlock2Ptr->field_0DC; @@ -84,7 +88,7 @@ IWRAM_DATA u8 gUnknown_03001160; IWRAM_DATA u32 filler_03001164; IWRAM_DATA u32 gUnknown_03001168[3]; -EWRAM_DATA struct UnkStruct_80E7B60 gUnknown_02039F9C = {}; +EWRAM_DATA struct RecordMixingDayCareMail gUnknown_02039F9C = {}; EWRAM_DATA struct PlayerRecords *gUnknown_0203A014 = NULL; EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; @@ -103,10 +107,10 @@ static void sub_80E78C4(OldMan *, size_t, u8); static void sub_80E7948(union BattleTowerRecord *, size_t, u8); static void sub_80E7A14(LilycoveLady *, size_t, u8); static void sub_80E7B2C(const u8 *); -static void sub_80E7B60(struct UnkStruct_80E7B60 *, size_t, u8, TVShow *); +static void sub_80E7B60(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); static void sub_80E7F68(u16 *item, u8 which); static void sub_80E7FF8(u8 taskId); -/*static*/ void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); +static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); void sub_80E8468(void *, size_t, u8); void sub_80E89AC(void *, size_t, u8); void sub_80E89F8(void *dest); @@ -213,8 +217,8 @@ void sub_80E6E24(void) { gUnknown_0203A018->unk_1210 = GetRecordMixingGift(); } - sub_80E8110((void*) gUnknown_0203A018->unk_1254, gUnknown_03001154); - sub_80E8260(gUnknown_0203A018->unk_12dc); + sub_80E8110(gUnknown_0203A018->unk_1254, gUnknown_03001154); + sub_80E8260((void*)gUnknown_0203A018->unk_12dc); } } @@ -688,22 +692,22 @@ static void sub_80E7A14(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) } } -static u8 sub_80E7A9C(struct DayCareMailRecordMixing *rmMail) +static u8 sub_80E7A9C(struct DaycareMiscMon *rmMail) { return rmMail->mail.itemId; } -static void sub_80E7AA4(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) +static void sub_80E7AA4(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) { - struct DayCareMailRecordMixing buffer; - struct UnkStruct_80E7B60 *_src1; - struct UnkStruct_80E7B60 *_src2; + struct DaycareMiscMon buffer; + struct RecordMixingDayCareMail *mail1; + struct RecordMixingDayCareMail *mail2; - _src1 = (void *)src + recordSize * idxs[which0][0]; - memcpy(&buffer, &_src1->unk_00[idxs[which0][1]], sizeof(struct DayCareMailRecordMixing)); - _src2 = (void *)src + recordSize * idxs[which1][0]; - memcpy(&_src1->unk_00[idxs[which0][1]], &_src2->unk_00[idxs[which1][1]], sizeof(struct DayCareMailRecordMixing)); - memcpy(&_src2->unk_00[idxs[which1][1]], &buffer, sizeof(struct DayCareMailRecordMixing)); + mail1 = (void *)src + recordSize * idxs[which0][0]; + memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DaycareMiscMon)); + mail2 = (void *)src + recordSize * idxs[which1][0]; + memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DaycareMiscMon)); + memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DaycareMiscMon)); } static void sub_80E7B2C(const u8 *src) @@ -725,7 +729,7 @@ static u8 sub_80E7B54(void) } #ifdef NONMATCHING -static void sub_80E7B60(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 which, TVShow *shows) +static void sub_80E7B60(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) { // r9 = which u16 i; @@ -738,11 +742,11 @@ static void sub_80E7B60(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 whi u8 dcMail1; u8 dcMail2; u8 r1_80e7b54; - struct DayCareMailRecordMixing *recordMixingMail; - struct UnkStruct_80E7B60 *_src; + struct DaycareMiscMon *recordMixingMail; + struct RecordMixingDayCareMail *_src; u8 sp04[4]; u8 sp08[4]; - struct UnkStruct_80E7B60 *sp0c[4]; // -> sp+48 + struct RecordMixingDayCareMail *sp0c[4]; // -> sp+48 u8 sp1c[4][2]; // [][0] -> sp+4c, [][1] -> sp+50 u8 sp24[4][2]; // sp+2c = src @@ -898,12 +902,12 @@ static void sub_80E7B60(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 whi break; } _src = (void *)src + which * recordSize; - memcpy(&gSaveBlock1Ptr->daycare.mons[0].misc.mail, &_src->unk_00[0], sizeof(struct DayCareMailRecordMixing)); - memcpy(&gSaveBlock1Ptr->daycare.mons[1].misc.mail, &_src->unk_00[1], sizeof(struct DayCareMailRecordMixing)); + memcpy(&gSaveBlock1Ptr->daycare.mons[0].misc.mail, &_src->unk_00[0], sizeof(struct DaycareMiscMon)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].misc.mail, &_src->unk_00[1], sizeof(struct DaycareMiscMon)); SeedRng(oldSeed); } #else -__attribute__((naked)) static void sub_80E7B60(struct UnkStruct_80E7B60 *src, size_t recordSize, u8 which, TVShow *shows) +__attribute__((naked)) static void sub_80E7B60(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) { asm_unified("\tpush {r4-r7,lr}\n" "\tmov r7, r10\n" @@ -1529,15 +1533,15 @@ static void sub_80E7FF8(u8 taskId) } } -/* -static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1) +static void sub_80E8110(struct UnkRecordMixingStruct *dst, struct UnkRecordMixingStruct *src) { s32 i, id; - s32 var_28, var_24, var_2C, r8; + s32 var_2C, var_28, var_24, r8; - arg0[0].field_0[0x38] = 0xFF; - arg0[1].field_0[0x38] = 0xFF; - memcpy(&arg0[0], &arg1[0], sizeof(struct UnkRecordMixingStruct)); + dst[0].field_38[0] = 0xFF; + dst[1].field_38[0] = 0xFF; + + dst[0] = src[0]; var_28 = 0; var_24 = 0; @@ -1545,15 +1549,15 @@ static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixi r8 = 0; for (i = 0; i < 2; i++) { - id = ((i + (gSaveBlock2Ptr->field_B0[2] << 0x1B >> 0x1E)) % 3) + 1; - if (arg1[id].field_0[0x38] != 0xFF) + id = ((i + gSaveBlock2Ptr->field_B2_1) % 3) + 1; + if (src[id].field_38[0] != 0xFF) { - if (ReadUnalignedWord(&arg1[id].field_0[0x34]) != ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId)) + if (ReadUnalignedWord(src[id].playerId) != ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId)) { r8++; var_2C = id; } - if (ReadUnalignedWord(&arg1[id].field_0[0x34]) == ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId)) + if (ReadUnalignedWord(src[id].playerId) == ReadUnalignedWord(gSaveBlock2Ptr->playerTrainerId)) { var_24++; var_28 = id; @@ -1570,13 +1574,72 @@ static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixi switch (r8) { case 1: - memcpy(&arg0[0], &arg1[var_2C], sizeof(struct UnkRecordMixingStruct)); + dst[1] = src[var_2C]; break; case 2: if (Random2() > 0x3333) - memcpy(&arg0[1], &arg1[(gSaveBlock2Ptr->field_B0[2] << 0x1B >> 0x1E) + 1], sizeof(struct UnkRecordMixingStruct)); + { + dst[1] = src[gSaveBlock2Ptr->field_B2_1 + 1]; + } else - memcpy(&arg0[1], &arg1[((gSaveBlock2Ptr->field_B0[2] << 0x1B >> 0x1E) + 1) % 3 + 1], sizeof(struct UnkRecordMixingStruct)); + { + dst[1] = src[((gSaveBlock2Ptr->field_B2_1 + 1) % 3 + 1)]; + } break; } -}*/ +} + +void sub_80E8260(struct UnkRecordMixingStruct2 *dst) +{ + s32 i, j; + + for (i = 0; i < 9; i++) + { + for (j = 0; j < 2; j++) + { + CopyUnalignedWord(dst->field_0[i][j].playerId, gSaveBlock2Ptr->playerTrainerId); + dst->field_0[i][j].language = LANGUAGE_ENGLISH; + StringCopy(dst->field_0[i][j].playerName, gSaveBlock2Ptr->playerName); + } + } + + for (j = 0; j < 2; j++) + { + dst->field_120[j].language = LANGUAGE_ENGLISH; + CopyUnalignedWord(dst->field_120[j].playerId1, gSaveBlock2Ptr->playerTrainerId); + CopyUnalignedWord(dst->field_120[j].playerId2, gSaveBlock2Ptr->field_EF1[j]); + StringCopy(dst->field_120[j].playerName1, gSaveBlock2Ptr->playerName); + StringCopy(dst->field_120[j].playerName2, gSaveBlock2Ptr->field_EE1[j]); + } + + for (i = 0; i < 2; i++) + { + dst->field_0[0][i].field_4 = gSaveBlock2Ptr->field_CF0[i]; + dst->field_0[1][i].field_4 = gSaveBlock2Ptr->field_CF4[i]; + dst->field_0[2][i].field_4 = gSaveBlock2Ptr->field_CF8[i]; + dst->field_0[3][i].field_4 = gSaveBlock2Ptr->field_D14[i]; + dst->field_0[4][i].field_4 = gSaveBlock2Ptr->field_DD0[i]; + dst->field_0[5][i].field_4 = gSaveBlock2Ptr->field_DDE[i]; + dst->field_0[6][i].field_4 = gSaveBlock2Ptr->field_DEA[i]; + dst->field_0[7][i].field_4 = gSaveBlock2Ptr->field_E08[i]; + dst->field_0[8][i].field_4 = gSaveBlock2Ptr->field_E1E[i]; + + dst->field_120[i].field_8 = gSaveBlock2Ptr->field_CFC[i]; + } +} + +bool32 sub_80E841C(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1) +{ + s32 i; + + for (i = 0; i < 4; i++) + { + if (ReadUnalignedWord(arg0->playerId) == ReadUnalignedWord(arg1[i].playerId) + && arg0->field_0[2] == arg1[i].field_0[2]) + { + return TRUE; + } + } + + return FALSE; +} From b051cbaaab8bacd0cdc65ce609a92bc9dd868a1f Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Fri, 25 May 2018 21:00:41 +0200 Subject: [PATCH 23/26] more record mixing decomp --- asm/record_mixing.s | 878 ---------------------------------------- data/record_mixing.s | 37 -- include/global.h | 21 +- include/record_mixing.h | 2 + ld_script.txt | 3 +- src/record_mixing.c | 732 +++++++++++++++++++++++++++++++-- 6 files changed, 711 insertions(+), 962 deletions(-) delete mode 100644 asm/record_mixing.s delete mode 100644 data/record_mixing.s diff --git a/asm/record_mixing.s b/asm/record_mixing.s deleted file mode 100644 index ceb25dd21..000000000 --- a/asm/record_mixing.s +++ /dev/null @@ -1,878 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - - thumb_func_start sub_80E8468 -sub_80E8468: @ 80E8468 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x14 - adds r6, r0, 0 - adds r5, r1, 0 - adds r4, r2, 0 - mov r0, sp - bl sub_80E7830 - lsls r4, 2 - mov r1, sp - adds r0, r1, r4 - ldr r0, [r0] - muls r0, r5 - adds r3, r6, r0 - movs r7, 0 - movs r2, 0 - mov r8, r2 - movs r5, 0 - adds r6, r3, 0 - adds r6, 0x38 - adds r4, r3, 0 -_080E8496: - ldrb r0, [r6] - cmp r0, 0xFF - beq _080E84B4 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - adds r1, 0xDC - adds r0, r4, 0 - str r3, [sp, 0x10] - bl sub_80E841C - ldr r3, [sp, 0x10] - cmp r0, 0 - bne _080E84B4 - adds r7, 0x1 - mov r8, r5 -_080E84B4: - adds r6, 0x44 - adds r4, 0x44 - adds r5, 0x1 - cmp r5, 0x1 - ble _080E8496 - cmp r7, 0x1 - beq _080E84CC - cmp r7, 0x2 - beq _080E8508 - b _080E8566 - .pool -_080E84CC: - ldr r4, =gSaveBlock2Ptr - ldr r0, [r4] - adds r1, r0, 0 - adds r1, 0xB2 - ldrb r1, [r1] - lsls r1, 27 - lsrs r1, 30 - adds r2, r1, 0x1 - lsls r1, r2, 4 - adds r1, r2 - lsls r1, 2 - adds r0, r1 - adds r0, 0xDC - mov r2, r8 - lsls r1, r2, 4 - add r1, r8 - lsls r1, 2 - adds r1, r3 - movs r2, 0x44 - bl memcpy - ldr r4, [r4] - adds r4, 0xB2 - ldrb r5, [r4] - lsls r0, r5, 27 - lsrs r0, 30 - adds r0, 0x1 - b _080E8550 - .pool -_080E8508: - movs r5, 0 - adds r6, r3, 0 -_080E850C: - movs r0, 0x1 - eors r0, r5 - ldr r7, =gSaveBlock2Ptr - ldr r4, [r7] - adds r1, r4, 0 - adds r1, 0xB2 - ldrb r1, [r1] - lsls r1, 27 - lsrs r1, 30 - adds r0, r1 - movs r1, 0x3 - bl __modsi3 - adds r2, r0, 0x1 - lsls r0, r2, 4 - adds r0, r2 - lsls r0, 2 - adds r4, r0 - adds r4, 0xDC - adds r0, r4, 0 - adds r1, r6, 0 - movs r2, 0x44 - bl memcpy - adds r6, 0x44 - adds r5, 0x1 - cmp r5, 0x1 - ble _080E850C - ldr r4, [r7] - adds r4, 0xB2 - ldrb r5, [r4] - lsls r0, r5, 27 - lsrs r0, 30 - adds r0, 0x2 -_080E8550: - movs r1, 0x3 - bl __modsi3 - movs r1, 0x3 - ands r0, r1 - lsls r0, 3 - movs r1, 0x19 - negs r1, r1 - ands r1, r5 - orrs r1, r0 - strb r1, [r4] -_080E8566: - add sp, 0x14 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E8468 - - thumb_func_start sub_80E8578 -sub_80E8578: @ 80E8578 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x54 - str r0, [sp] - ldr r0, [sp, 0x74] - movs r4, 0 - mov r8, r4 - movs r5, 0 - str r5, [sp, 0x4] - ldr r4, =gUnknown_03001168 - b _080E85A0 - .pool -_080E8598: - adds r1, r2 - ldr r6, [sp, 0x4] - adds r6, 0x1 - str r6, [sp, 0x4] -_080E85A0: - ldr r5, [sp, 0x4] - cmp r5, r0 - bge _080E85B6 - cmp r5, r3 - beq _080E85B0 - stm r4!, {r1} - movs r6, 0x1 - add r8, r6 -_080E85B0: - mov r5, r8 - cmp r5, 0x3 - bne _080E8598 -_080E85B6: - movs r6, 0 - str r6, [sp, 0x4] - subs r0, 0x1 - str r0, [sp, 0x24] -_080E85BE: - movs r0, 0 - str r0, [sp, 0x8] - ldr r1, [sp, 0x4] - adds r1, 0x1 - str r1, [sp, 0x28] - ldr r2, [sp, 0x4] - lsls r2, 1 - str r2, [sp, 0x34] - ldr r3, [sp, 0x4] - adds r3, r2, r3 - str r3, [sp, 0x10] - movs r4, 0 - str r4, [sp, 0x44] - movs r5, 0 - str r5, [sp, 0x48] -_080E85DC: - movs r6, 0 - mov r8, r6 - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - ldr r2, [sp, 0x10] - lsls r0, r2, 5 - ldr r3, [sp, 0x48] - adds r0, r3, r0 - adds r3, r0, r1 - lsls r0, r2, 6 - ldr r4, [sp, 0x44] - adds r0, r4, r0 - ldr r5, [sp] - adds r2, r0, r5 -_080E85F8: - adds r0, r2, 0 - movs r6, 0x87 - lsls r6, 2 - adds r1, r3, r6 - ldm r1!, {r4-r6} - stm r0!, {r4-r6} - ldr r1, [r1] - str r1, [r0] - adds r3, 0x10 - adds r2, 0x10 - movs r0, 0x1 - add r8, r0 - mov r1, r8 - cmp r1, 0x2 - ble _080E85F8 - movs r2, 0 - mov r8, r2 - ldr r3, [sp, 0x24] - cmp r8, r3 - bge _080E86DC - ldr r4, [sp, 0x4] - lsls r4, 5 - mov r9, r4 - ldr r5, [sp, 0x8] - lsls r7, r5, 4 - ldr r6, [sp, 0x34] - ldr r1, [sp, 0x4] - adds r0, r6, r1 - lsls r0, 6 - str r0, [sp, 0x14] - ldr r2, [sp] - adds r0, r2, r0 - ldr r3, [sp, 0x44] - str r3, [sp, 0x18] - adds r0, r3 - str r0, [sp, 0x1C] - ldr r4, [sp, 0x14] - adds r0, r3, r4 - adds r0, r2 - adds r0, 0x30 - mov r10, r0 -_080E864A: - movs r5, 0 - str r5, [sp, 0xC] - movs r3, 0 - mov r6, r8 - lsls r6, 2 - str r6, [sp, 0x38] - ldr r1, [sp, 0x18] - ldr r2, [sp, 0x14] - adds r0, r1, r2 - ldr r4, [sp] - adds r5, r0, r4 - ldr r0, =gUnknown_03001168 - adds r0, r6, r0 - str r0, [sp, 0x50] -_080E8666: - lsls r0, r3, 4 - ldr r6, [sp, 0x1C] - adds r0, r6, r0 - str r3, [sp, 0x4C] - bl ReadUnalignedWord - adds r4, r0, 0 - ldr r1, [sp, 0x50] - ldr r0, [r1] - add r0, r9 - adds r0, r7 - bl ReadUnalignedWord - ldr r3, [sp, 0x4C] - cmp r4, r0 - bne _080E86A8 - ldr r2, [sp, 0xC] - adds r2, 0x1 - str r2, [sp, 0xC] - ldr r4, [sp, 0x50] - ldr r0, [r4] - mov r6, r9 - adds r1, r7, r6 - adds r1, r0, r1 - ldrh r0, [r5, 0x4] - ldrh r2, [r1, 0x4] - cmp r0, r2 - bcs _080E86A8 - adds r0, r5, 0 - ldm r1!, {r2,r4,r6} - stm r0!, {r2,r4,r6} - ldr r1, [r1] - str r1, [r0] -_080E86A8: - adds r5, 0x10 - adds r3, 0x1 - cmp r3, 0x2 - ble _080E8666 - ldr r3, [sp, 0xC] - cmp r3, 0 - bne _080E86CE - ldr r0, =gUnknown_03001168 - ldr r4, [sp, 0x38] - adds r0, r4, r0 - ldr r0, [r0] - mov r5, r9 - adds r2, r7, r5 - mov r1, r10 - adds r0, r2 - ldm r0!, {r2,r3,r6} - stm r1!, {r2,r3,r6} - ldr r0, [r0] - str r0, [r1] -_080E86CE: - movs r4, 0x10 - add r10, r4 - movs r5, 0x1 - add r8, r5 - ldr r6, [sp, 0x24] - cmp r8, r6 - blt _080E864A -_080E86DC: - ldr r0, [sp, 0x44] - adds r0, 0x60 - str r0, [sp, 0x44] - ldr r1, [sp, 0x48] - adds r1, 0x30 - str r1, [sp, 0x48] - ldr r2, [sp, 0x8] - adds r2, 0x1 - str r2, [sp, 0x8] - cmp r2, 0x1 - bgt _080E86F4 - b _080E85DC -_080E86F4: - ldr r3, [sp, 0x28] - str r3, [sp, 0x4] - cmp r3, 0x8 - bgt _080E86FE - b _080E85BE -_080E86FE: - movs r4, 0 - str r4, [sp, 0x8] -_080E8702: - ldr r5, [sp, 0x8] - adds r5, 0x1 - str r5, [sp, 0x2C] - ldr r0, =gSaveBlock2Ptr - ldr r1, [r0] - movs r0, 0x54 - ldr r6, [sp, 0x8] - muls r0, r6 - adds r3, r0, r1 - movs r0, 0xA8 - muls r0, r6 - ldr r1, [sp] - adds r2, r0, r1 - movs r4, 0x2 - mov r8, r4 -_080E8720: - movs r5, 0xD8 - lsls r5, 3 - adds r0, r2, r5 - ldr r6, =0x0000057c - adds r1, r3, r6 - ldm r1!, {r4-r6} - stm r0!, {r4-r6} - ldm r1!, {r4-r6} - stm r0!, {r4-r6} - ldr r1, [r1] - str r1, [r0] - adds r3, 0x1C - adds r2, 0x1C - movs r0, 0x1 - negs r0, r0 - add r8, r0 - mov r1, r8 - cmp r1, 0 - bge _080E8720 - movs r2, 0 - mov r8, r2 - ldr r3, [sp, 0x24] - cmp r8, r3 - blt _080E8752 - b _080E885A -_080E8752: - ldr r4, [sp, 0x8] - lsls r1, r4, 3 - movs r0, 0xA8 - adds r5, r4, 0 - muls r5, r0 - str r5, [sp, 0x20] - str r5, [sp, 0x3C] - subs r1, r4 - lsls r1, 2 - mov r10, r1 -_080E8766: - movs r6, 0 - str r6, [sp, 0xC] - mov r0, r8 - lsls r0, 2 - str r0, [sp, 0x38] - mov r1, r8 - adds r1, 0x1 - str r1, [sp, 0x30] - ldr r0, =gUnknown_03001168 - ldr r2, [sp, 0x38] - adds r2, r0 - mov r9, r2 - ldr r3, [sp] - movs r4, 0xD8 - lsls r4, 3 - adds r0, r3, r4 - ldr r5, [sp, 0x3C] - adds r7, r5, r0 - str r6, [sp, 0x40] - movs r3, 0x2 -_080E878E: - ldr r1, [sp, 0x20] - movs r2, 0xD8 - lsls r2, 3 - adds r0, r1, r2 - ldr r4, [sp] - adds r0, r4, r0 - ldr r6, [sp, 0x40] - adds r5, r0, r6 - adds r0, r5, 0 - str r3, [sp, 0x4C] - bl ReadUnalignedWord - adds r4, r0, 0 - movs r6, 0x90 - lsls r6, 1 - add r6, r10 - mov r1, r9 - ldr r0, [r1] - adds r0, r6 - bl ReadUnalignedWord - ldr r3, [sp, 0x4C] - cmp r4, r0 - bne _080E8808 - adds r0, r5, 0x4 - bl ReadUnalignedWord - adds r4, r0, 0 - mov r2, r9 - ldr r0, [r2] - adds r0, r6 - adds r0, 0x4 - bl ReadUnalignedWord - ldr r3, [sp, 0x4C] - cmp r4, r0 - bne _080E8808 - ldr r4, [sp, 0xC] - adds r4, 0x1 - str r4, [sp, 0xC] - mov r5, r9 - ldr r0, [r5] - mov r6, r10 - adds r2, r0, r6 - movs r0, 0x94 - lsls r0, 1 - adds r1, r2, r0 - ldrh r0, [r7, 0x8] - ldrh r1, [r1] - cmp r0, r1 - bcs _080E8808 - adds r0, r7, 0 - movs r4, 0x90 - lsls r4, 1 - adds r1, r2, r4 - ldm r1!, {r2,r5,r6} - stm r0!, {r2,r5,r6} - ldm r1!, {r4-r6} - stm r0!, {r4-r6} - ldr r1, [r1] - str r1, [r0] -_080E8808: - adds r7, 0x1C - ldr r0, [sp, 0x40] - adds r0, 0x1C - str r0, [sp, 0x40] - subs r3, 0x1 - cmp r3, 0 - bge _080E878E - ldr r1, [sp, 0xC] - cmp r1, 0 - bne _080E8850 - mov r0, r8 - adds r0, 0x3 - lsls r1, r0, 3 - subs r1, r0 - lsls r1, 2 - ldr r2, [sp, 0x20] - adds r1, r2 - ldr r3, [sp] - adds r1, r3, r1 - ldr r0, =gUnknown_03001168 - ldr r4, [sp, 0x38] - adds r0, r4, r0 - ldr r0, [r0] - add r0, r10 - movs r5, 0xD8 - lsls r5, 3 - adds r1, r5 - movs r6, 0x90 - lsls r6, 1 - adds r0, r6 - ldm r0!, {r2-r4} - stm r1!, {r2-r4} - ldm r0!, {r2,r5,r6} - stm r1!, {r2,r5,r6} - ldr r0, [r0] - str r0, [r1] -_080E8850: - ldr r3, [sp, 0x30] - mov r8, r3 - ldr r4, [sp, 0x24] - cmp r8, r4 - blt _080E8766 -_080E885A: - ldr r5, [sp, 0x2C] - str r5, [sp, 0x8] - cmp r5, 0x1 - bgt _080E8864 - b _080E8702 -_080E8864: - add sp, 0x54 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E8578 - - thumb_func_start sub_80E8880 -sub_80E8880: @ 80E8880 - push {r4-r7,lr} - mov r12, r0 - adds r7, r1, 0 - movs r5, 0 -_080E8888: - movs r2, 0 - movs r4, 0x1 - negs r4, r4 - movs r1, 0 - adds r6, r5, 0x1 - adds r3, r7, 0 -_080E8894: - ldrh r0, [r3, 0x4] - cmp r0, r2 - ble _080E889E - adds r4, r1, 0 - adds r2, r0, 0 -_080E889E: - adds r3, 0x10 - adds r1, 0x1 - cmp r1, 0x5 - ble _080E8894 - cmp r4, 0 - blt _080E88C0 - lsls r1, r5, 4 - lsls r2, r4, 4 - adds r2, r7 - add r1, r12 - adds r0, r2, 0 - ldm r0!, {r3-r5} - stm r1!, {r3-r5} - ldr r0, [r0] - str r0, [r1] - movs r0, 0 - strh r0, [r2, 0x4] -_080E88C0: - adds r5, r6, 0 - cmp r5, 0x2 - ble _080E8888 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80E8880 - - thumb_func_start sub_80E88CC -sub_80E88CC: @ 80E88CC - push {r4-r7,lr} - mov r12, r0 - adds r6, r1, 0 - movs r5, 0 -_080E88D4: - movs r3, 0 - movs r4, 0x1 - negs r4, r4 - movs r2, 0 - adds r7, r5, 0x1 - adds r1, r6, 0 -_080E88E0: - ldrh r0, [r1, 0x8] - cmp r0, r3 - ble _080E88EA - adds r4, r2, 0 - adds r3, r0, 0 -_080E88EA: - adds r1, 0x1C - adds r2, 0x1 - cmp r2, 0x5 - ble _080E88E0 - cmp r4, 0 - blt _080E8918 - lsls r1, r5, 3 - subs r1, r5 - lsls r1, 2 - lsls r2, r4, 3 - subs r2, r4 - lsls r2, 2 - adds r2, r6 - add r1, r12 - adds r0, r2, 0 - ldm r0!, {r3-r5} - stm r1!, {r3-r5} - ldm r0!, {r3-r5} - stm r1!, {r3-r5} - ldr r0, [r0] - str r0, [r1] - movs r0, 0 - strh r0, [r2, 0x8] -_080E8918: - adds r5, r7, 0 - cmp r5, 0x2 - ble _080E88D4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80E88CC - - thumb_func_start sub_80E8924 -sub_80E8924: @ 80E8924 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - mov r9, r0 - movs r0, 0 - ldr r1, =gSaveBlock2Ptr - mov r10, r1 -_080E8936: - lsls r1, r0, 1 - adds r2, r0, 0x1 - mov r8, r2 - adds r1, r0 - lsls r0, r1, 5 - movs r2, 0x87 - lsls r2, 2 - adds r7, r0, r2 - lsls r1, 6 - mov r0, r9 - adds r4, r0, r1 - movs r6, 0 - movs r5, 0x1 -_080E8950: - mov r1, r10 - ldr r0, [r1] - adds r0, r7 - adds r0, r6 - adds r1, r4, 0 - bl sub_80E8880 - adds r4, 0x60 - adds r6, 0x30 - subs r5, 0x1 - cmp r5, 0 - bge _080E8950 - mov r0, r8 - cmp r0, 0x8 - ble _080E8936 - movs r5, 0 - ldr r4, =gSaveBlock2Ptr -_080E8972: - movs r0, 0x54 - adds r1, r5, 0 - muls r1, r0 - ldr r2, =0x0000057c - adds r1, r2 - ldr r0, [r4] - adds r0, r1 - movs r1, 0xA8 - muls r1, r5 - movs r2, 0xD8 - lsls r2, 3 - adds r1, r2 - add r1, r9 - bl sub_80E88CC - adds r5, 0x1 - cmp r5, 0x1 - ble _080E8972 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E8924 - - thumb_func_start sub_80E89AC -sub_80E89AC: @ 80E89AC - push {r4-r6,lr} - mov r6, r9 - mov r5, r8 - push {r5,r6} - sub sp, 0x4 - adds r6, r0, 0 - mov r8, r1 - mov r9, r2 - bl GetLinkPlayerCount - adds r4, r0, 0 - lsls r4, 24 - lsrs r4, 24 - movs r0, 0x81 - lsls r0, 4 - bl AllocZeroed - adds r5, r0, 0 - str r4, [sp] - adds r1, r6, 0 - mov r2, r8 - mov r3, r9 - bl sub_80E8578 - adds r0, r5, 0 - bl sub_80E8924 - adds r0, r5, 0 - bl Free - add sp, 0x4 - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_80E89AC - - thumb_func_start sub_80E89F8 -sub_80E89F8: @ 80E89F8 - push {r4-r6,lr} - adds r6, r0, 0 - ldr r5, =gUnknown_02039F9C - ldr r4, =gSaveBlock1Ptr - ldr r1, [r4] - movs r0, 0xC2 - lsls r0, 6 - adds r1, r0 - adds r0, r5, 0 - movs r2, 0x38 - bl memcpy - ldr r1, [r4] - ldr r0, =0x0000310c - adds r1, r0 - adds r0, r5, 0 - adds r0, 0x38 - movs r2, 0x38 - bl memcpy - ldr r0, [r4] - ldr r1, =0x00003030 - adds r0, r1 - adds r1, r5, 0 - bl InitDaycareMailRecordMixing - ldr r0, =gUnknown_03001148 - ldr r1, [r0] - adds r0, r6, 0 - movs r2, 0x78 - bl memcpy - pop {r4-r6} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80E89F8 - - thumb_func_start sub_80E8A54 -sub_80E8A54: @ 80E8A54 - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - adds r5, r0, 0 - movs r0, 0 - mov r9, r0 - ldr r0, [r5, 0x70] - cmp r9, r0 - bcs _080E8AAE - adds r4, r5, 0 - adds r4, 0x2C - movs r0, 0x24 - adds r0, r5 - mov r8, r0 - adds r7, r5, 0 - adds r7, 0x37 - adds r6, r5, 0 -_080E8A78: - ldrh r0, [r6, 0x20] - cmp r0, 0 - beq _080E8A9A - ldrb r1, [r4, 0xB] - movs r0, 0xF - ands r0, r1 - cmp r0, 0x1 - beq _080E8A90 - mov r0, r8 - movs r1, 0xFC - bl PadNameString -_080E8A90: - ldrb r1, [r7] - lsrs r1, 4 - adds r0, r4, 0 - bl ConvertInternationalString -_080E8A9A: - adds r4, 0x38 - movs r0, 0x38 - add r8, r0 - adds r7, 0x38 - adds r6, 0x38 - movs r0, 0x1 - add r9, r0 - ldr r0, [r5, 0x70] - cmp r9, r0 - bcc _080E8A78 -_080E8AAE: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end sub_80E8A54 - - thumb_func_start TaskDummy4 -TaskDummy4: @ 80E8ABC - bx lr - thumb_func_end TaskDummy4 - - thumb_func_start sub_80E8AC0 -sub_80E8AC0: @ 80E8AC0 - push {r4,r5,lr} - adds r5, r0, 0 - movs r4, 0 -_080E8AC6: - movs r0, 0x2C - muls r0, r4 - adds r0, 0x34 - adds r1, r5, r0 - ldrh r0, [r1] - cmp r0, 0 - beq _080E8ADC - adds r0, r1, 0 - adds r0, 0x20 - bl StripExtCtrlCodes -_080E8ADC: - adds r4, 0x1 - cmp r4, 0x3 - ble _080E8AC6 - adds r0, r5, 0 - bl sub_8164F70 - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end sub_80E8AC0 - - .align 2, 0 @ Don't pad with nop. diff --git a/data/record_mixing.s b/data/record_mixing.s deleted file mode 100644 index 20a37145c..000000000 --- a/data/record_mixing.s +++ /dev/null @@ -1,37 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .section .rodata - .align 2, 0 - -gUnknown_0858CF8C:: @ 858CF8C - .byte 1, 0 - -gUnknown_0858CF8E:: @ 858CF8E - .byte 1, 2, 0 - .byte 2, 0, 1 - -gUnknown_0858CF94:: @ 858CF94 - .byte 1, 0, 3 - .byte 2, 3, 0 - .byte 1, 2, 2 - .byte 0, 3, 1 - .byte 1, 3, 0 - .byte 2, 2, 3 - .byte 0, 1, 3 - .byte 2, 0, 1 - .byte 1, 2, 3 - .byte 0, 2, 3 - .byte 1, 0, 3 - .byte 2, 1, 0 - -gUnknown_0858CFB8:: @ 858CFB8 - .byte 0, 1 - .byte 1, 2 - .byte 2, 0 - -gUnknown_0858CFBE:: @ 858CFBE - .byte 0, 1, 2, 3 - .byte 0, 2, 1, 3 - .byte 0, 3, 2, 1 - .byte 0, 0 diff --git a/include/global.h b/include/global.h index fe82ea9a7..b869da813 100644 --- a/include/global.h +++ b/include/global.h @@ -256,6 +256,13 @@ struct UnknownSaveBlock2Struct u8 field_EB; }; // sizeof = 0xEC +struct UnkRecordMixingStruct +{ + u8 field_0[0x34]; + u8 playerId[4]; + u8 field_38[10]; +}; + struct SaveBlock2 { /*0x00*/ u8 playerName[PLAYER_NAME_LENGTH]; @@ -286,7 +293,7 @@ struct SaveBlock2 /*0xB2*/ u8 field_B2_0:3; /*0xB2*/ u8 field_B2_1:2; /*0xB3*/ u8 field_B3[0x29]; - /*0xDC*/ u8 field_0DC[0x110]; + /*0xDC*/ struct UnkRecordMixingStruct field_DC[4]; /*0x1EC*/ struct BerryCrush berryCrush; /*0x1FC*/ struct PokemonJumpResults pokeJump; /*0x20C*/ struct BerryPickingResults berryPick; @@ -605,9 +612,9 @@ struct ContestWinner u8 contestRank; }; -struct DaycareMiscMon +struct DayCareMail { - struct MailStruct mail; + struct MailStruct message; u8 OT_name[OT_NAME_LENGTH + 1]; u8 monName[POKEMON_NAME_LENGTH + 1]; u8 gameLanguage:4; @@ -617,7 +624,7 @@ struct DaycareMiscMon struct DaycareMon { struct BoxPokemon mon; - struct DaycareMiscMon misc; + struct DayCareMail mail; u32 steps; }; @@ -628,12 +635,6 @@ struct DayCare u8 stepCounter; }; -struct DayCareMail -{ - /*0x00*/ struct MailStruct message; - /*0x24*/ u8 names[19]; -}; - struct RecordMixingDayCareMail { struct DayCareMail mail[DAYCARE_MON_COUNT]; diff --git a/include/record_mixing.h b/include/record_mixing.h index 875eca815..900951516 100644 --- a/include/record_mixing.h +++ b/include/record_mixing.h @@ -26,6 +26,8 @@ struct UnkRecordMixingStruct2 struct UnkRecordMixingStruct2b field_120[2]; }; + + // Exported RAM declarations // Exported ROM declarations diff --git a/ld_script.txt b/ld_script.txt index a040df5d1..b2bc77160 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -145,7 +145,6 @@ SECTIONS { src/money.o(.text); asm/contest_effect.o(.text); src/record_mixing.o(.text); - asm/record_mixing.o(.text); src/secret_base.o(.text); src/tv.o(.text); asm/contest_link_80F57C4.o(.text); @@ -440,7 +439,7 @@ SECTIONS { src/naming_screen.o(.rodata); src/money.o(.rodata); data/contest_effect.o(.rodata); - data/record_mixing.o(.rodata); + src/record_mixing.o(.rodata); src/secret_base.o(.rodata); src/tv.o(.rodata); data/contest_link_80F57C4.o(.rodata); diff --git a/src/record_mixing.c b/src/record_mixing.c index 553174325..9a47d4112 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -1,5 +1,3 @@ - -// Includes #include "global.h" #include "malloc.h" #include "random.h" @@ -33,16 +31,11 @@ #include "string_util.h" #include "record_mixing.h" #include "new_game.h" +#include "daycare.h" +#include "international_string_util.h" // Static type declarations -struct UnkRecordMixingStruct -{ - u8 field_0[0x34]; - u8 playerId[4]; - u8 field_38[10]; -}; - struct PlayerRecordsRS { struct SecretBaseRecord secretBases[20]; @@ -67,7 +60,8 @@ struct PlayerRecords /* 0x1210 */ u16 unk_1210; /* 0x1214 */ LilycoveLady lilycoveLady; /* 0x1254 */ struct UnkRecordMixingStruct unk_1254[2]; - /* 0x12dc */ u8 unk_12dc[0x168]; + /* 0x12dc */ struct UnkRecordMixingStruct2 unk_12dc; + /* 0x1434 */ u8 field_1434[0x10]; }; // 1444 // Static RAM declarations @@ -111,23 +105,51 @@ static void sub_80E7B60(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); static void sub_80E7F68(u16 *item, u8 which); static void sub_80E7FF8(u8 taskId); static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); -void sub_80E8468(void *, size_t, u8); -void sub_80E89AC(void *, size_t, u8); -void sub_80E89F8(void *dest); -void sub_80E8A54(void *src); -void sub_80E8AC0(union BattleTowerRecord *); +static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg2); +static void sub_80E89AC(struct UnkRecordMixingStruct2 *arg0, size_t arg1, u32 arg2); +static void sub_80E89F8(struct RecordMixingDayCareMail *dst); +static void sub_80E8A54(struct RecordMixingDayCareMail *src); +static void sub_80E8AC0(union BattleTowerRecord *); void sub_80EAF80(struct SecretBaseRecord *, size_t, u8); void sub_812287C(struct EasyChatPair *, size_t, u8); -void TaskDummy4(union BattleTowerRecord *src); +static void nullsub_1405(union BattleTowerRecord *src); // .rodata -extern const u8 gUnknown_0858CF8C[]; -extern const u8 gUnknown_0858CF8E[][3]; -extern const u8 gUnknown_0858CF94[][4]; +static const u8 gUnknown_0858CF8C[] = {1, 0}; -extern const u8 gUnknown_0858CFB8[3][2]; -extern const u8 gUnknown_0858CFBE[3][4]; +static const u8 gUnknown_0858CF8E[][3] = +{ + {1, 2, 0}, + {2, 0, 1}, +}; + +static const u8 gUnknown_0858CF94[][4] = +{ + {1, 0, 3, 2}, + {3, 0, 1, 2}, + {2, 0, 3, 1}, + {1, 3, 0, 2}, + {2, 3, 0, 1}, + {3, 2, 0, 1}, + {1, 2, 3, 0}, + {2, 3, 1, 0}, + {3, 2, 1, 0}, +}; + +static const u8 gUnknown_0858CFB8[3][2] = +{ + {0, 1}, + {1, 2}, + {2, 0}, +}; + +static const u8 gUnknown_0858CFBE[3][4] = +{ + {0, 1, 2, 3}, + {0, 2, 1, 3}, + {0, 3, 2, 1}, +}; // .text @@ -146,7 +168,7 @@ void sub_80E6BF8(void) gUnknown_03001148 = &gUnknown_02039F9C; gUnknown_0300114C = gSaveBlock2Ptr->field_64C; gUnknown_03001150 = &gSaveBlock1Ptr->lilycoveLady; - gUnknown_03001154 = gSaveBlock2Ptr->field_0DC; + gUnknown_03001154 = gSaveBlock2Ptr->field_DC; gUnknown_03001158 = gSaveBlock2Ptr->field_64C; } @@ -179,7 +201,7 @@ void sub_80E6D54(struct PlayerRecords *dest) sub_80E89F8(&dest->dayCareMail); sub_80E8A54(&dest->dayCareMail); sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); - TaskDummy4(&dest->battleTowerRecord); + nullsub_1405(&dest->battleTowerRecord); if (GetMultiplayerId() == 0) { dest->battleTowerRecord.ruby_sapphire.unk_11c8 = GetRecordMixingGift(); @@ -218,7 +240,7 @@ void sub_80E6E24(void) gUnknown_0203A018->unk_1210 = GetRecordMixingGift(); } sub_80E8110(gUnknown_0203A018->unk_1254, gUnknown_03001154); - sub_80E8260((void*)gUnknown_0203A018->unk_12dc); + sub_80E8260(&gUnknown_0203A018->unk_12dc); } } @@ -250,8 +272,8 @@ void sub_80E6F60(u32 which) sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, sizeof(struct PlayerRecords), which); sub_80E7F68(&gUnknown_0203A014[0].unk_1210, which); sub_80E7A14(&gUnknown_0203A014[0].lilycoveLady, sizeof(struct PlayerRecords), which); - sub_80E8468(gUnknown_0203A014[0].unk_1254, sizeof(struct PlayerRecords), which); - sub_80E89AC(gUnknown_0203A014[0].unk_12dc, sizeof(struct PlayerRecords), which); + sub_80E8468(gUnknown_0203A014[0].unk_1254, sizeof(struct PlayerRecords), (u8) which); + sub_80E89AC(&gUnknown_0203A014[0].unk_12dc, sizeof(struct PlayerRecords), (u8) which); } } @@ -692,22 +714,22 @@ static void sub_80E7A14(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) } } -static u8 sub_80E7A9C(struct DaycareMiscMon *rmMail) +static u8 sub_80E7A9C(struct DayCareMail *rmMail) { - return rmMail->mail.itemId; + return rmMail->message.itemId; } static void sub_80E7AA4(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1) { - struct DaycareMiscMon buffer; + struct DayCareMail buffer; struct RecordMixingDayCareMail *mail1; struct RecordMixingDayCareMail *mail2; mail1 = (void *)src + recordSize * idxs[which0][0]; - memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DaycareMiscMon)); + memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DayCareMail)); mail2 = (void *)src + recordSize * idxs[which1][0]; - memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DaycareMiscMon)); - memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DaycareMiscMon)); + memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DayCareMail)); + memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DayCareMail)); } static void sub_80E7B2C(const u8 *src) @@ -742,7 +764,7 @@ static void sub_80E7B60(struct RecordMixingDayCareMail *src, size_t recordSize, u8 dcMail1; u8 dcMail2; u8 r1_80e7b54; - struct DaycareMiscMon *recordMixingMail; + struct DayCareMail *recordMixingMail; struct RecordMixingDayCareMail *_src; u8 sp04[4]; u8 sp08[4]; @@ -902,8 +924,8 @@ static void sub_80E7B60(struct RecordMixingDayCareMail *src, size_t recordSize, break; } _src = (void *)src + which * recordSize; - memcpy(&gSaveBlock1Ptr->daycare.mons[0].misc.mail, &_src->unk_00[0], sizeof(struct DaycareMiscMon)); - memcpy(&gSaveBlock1Ptr->daycare.mons[1].misc.mail, &_src->unk_00[1], sizeof(struct DaycareMiscMon)); + memcpy(&gSaveBlock1Ptr->daycare.mons[0].misc.mail, &_src->unk_00[0], sizeof(struct DayCareMail)); + memcpy(&gSaveBlock1Ptr->daycare.mons[1].misc.mail, &_src->unk_00[1], sizeof(struct DayCareMail)); SeedRng(oldSeed); } #else @@ -1643,3 +1665,643 @@ bool32 sub_80E841C(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStr return FALSE; } + +static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg2) +{ + s32 i, r7, r8; + struct UnkRecordMixingStruct *structPtr; + u32 data[4]; + u32 structId; + + sub_80E7830(data); + structPtr = (void*)(arg0) + (arg1 * data[arg2]); + r7 = 0; + r8 = 0; + for (i = 0; i < 2; i++) + { + if (structPtr[i].field_38[0] != 0xFF && !sub_80E841C(&structPtr[i], gSaveBlock2Ptr->field_DC)) + { + r7++; + r8 = i; + } + } + + switch (r7) + { + case 1: + structId = gSaveBlock2Ptr->field_B2_1 + 1; + gSaveBlock2Ptr->field_DC[structId] = structPtr[r8]; + gSaveBlock2Ptr->field_B2_1 = (gSaveBlock2Ptr->field_B2_1 + 1) % 3; + break; + case 2: + for (i = 0; i < 2; i++) + { + structId = ((i ^ 1) + gSaveBlock2Ptr->field_B2_1) % 3 + 1; + gSaveBlock2Ptr->field_DC[structId] = structPtr[i]; + } + gSaveBlock2Ptr->field_B2_1 = (gSaveBlock2Ptr->field_B2_1 + 2) % 3; + break; + } +} + +struct UnknownRecMixingStruct +{ + u32 field_0; + u16 field_4; + u8 field_6[9]; +}; + +struct UnknownRecMixingStruct2 +{ + u32 field_0; + u16 field_4; + u16 field_6; + u16 field_8; + u8 field_A[16]; +}; + +struct UnknownRecMixingStruct3 +{ + u8 field_0[0x810]; +}; + +NAKED +void sub_80E8578(struct UnknownRecMixingStruct3 *arg0, struct UnkRecordMixingStruct2 *arg1, size_t arg2, u32 arg3, u32 arg4) +{ + asm_unified(" push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + sub sp, 0x54\n\ + str r0, [sp]\n\ + ldr r0, [sp, 0x74]\n\ + movs r4, 0\n\ + mov r8, r4\n\ + movs r5, 0\n\ + str r5, [sp, 0x4]\n\ + ldr r4, =gUnknown_03001168\n\ + b _080E85A0\n\ + .pool\n\ +_080E8598:\n\ + adds r1, r2\n\ + ldr r6, [sp, 0x4]\n\ + adds r6, 0x1\n\ + str r6, [sp, 0x4]\n\ +_080E85A0:\n\ + ldr r5, [sp, 0x4]\n\ + cmp r5, r0\n\ + bge _080E85B6\n\ + cmp r5, r3\n\ + beq _080E85B0\n\ + stm r4!, {r1}\n\ + movs r6, 0x1\n\ + add r8, r6\n\ +_080E85B0:\n\ + mov r5, r8\n\ + cmp r5, 0x3\n\ + bne _080E8598\n\ +_080E85B6:\n\ + movs r6, 0\n\ + str r6, [sp, 0x4]\n\ + subs r0, 0x1\n\ + str r0, [sp, 0x24]\n\ +_080E85BE:\n\ + movs r0, 0\n\ + str r0, [sp, 0x8]\n\ + ldr r1, [sp, 0x4]\n\ + adds r1, 0x1\n\ + str r1, [sp, 0x28]\n\ + ldr r2, [sp, 0x4]\n\ + lsls r2, 1\n\ + str r2, [sp, 0x34]\n\ + ldr r3, [sp, 0x4]\n\ + adds r3, r2, r3\n\ + str r3, [sp, 0x10]\n\ + movs r4, 0\n\ + str r4, [sp, 0x44]\n\ + movs r5, 0\n\ + str r5, [sp, 0x48]\n\ +_080E85DC:\n\ + movs r6, 0\n\ + mov r8, r6\n\ + ldr r0, =gSaveBlock2Ptr\n\ + ldr r1, [r0]\n\ + ldr r2, [sp, 0x10]\n\ + lsls r0, r2, 5\n\ + ldr r3, [sp, 0x48]\n\ + adds r0, r3, r0\n\ + adds r3, r0, r1\n\ + lsls r0, r2, 6\n\ + ldr r4, [sp, 0x44]\n\ + adds r0, r4, r0\n\ + ldr r5, [sp]\n\ + adds r2, r0, r5\n\ +_080E85F8:\n\ + adds r0, r2, 0\n\ + movs r6, 0x87\n\ + lsls r6, 2\n\ + adds r1, r3, r6\n\ + ldm r1!, {r4-r6}\n\ + stm r0!, {r4-r6}\n\ + ldr r1, [r1]\n\ + str r1, [r0]\n\ + adds r3, 0x10\n\ + adds r2, 0x10\n\ + movs r0, 0x1\n\ + add r8, r0\n\ + mov r1, r8\n\ + cmp r1, 0x2\n\ + ble _080E85F8\n\ + movs r2, 0\n\ + mov r8, r2\n\ + ldr r3, [sp, 0x24]\n\ + cmp r8, r3\n\ + bge _080E86DC\n\ + ldr r4, [sp, 0x4]\n\ + lsls r4, 5\n\ + mov r9, r4\n\ + ldr r5, [sp, 0x8]\n\ + lsls r7, r5, 4\n\ + ldr r6, [sp, 0x34]\n\ + ldr r1, [sp, 0x4]\n\ + adds r0, r6, r1\n\ + lsls r0, 6\n\ + str r0, [sp, 0x14]\n\ + ldr r2, [sp]\n\ + adds r0, r2, r0\n\ + ldr r3, [sp, 0x44]\n\ + str r3, [sp, 0x18]\n\ + adds r0, r3\n\ + str r0, [sp, 0x1C]\n\ + ldr r4, [sp, 0x14]\n\ + adds r0, r3, r4\n\ + adds r0, r2\n\ + adds r0, 0x30\n\ + mov r10, r0\n\ +_080E864A:\n\ + movs r5, 0\n\ + str r5, [sp, 0xC]\n\ + movs r3, 0\n\ + mov r6, r8\n\ + lsls r6, 2\n\ + str r6, [sp, 0x38]\n\ + ldr r1, [sp, 0x18]\n\ + ldr r2, [sp, 0x14]\n\ + adds r0, r1, r2\n\ + ldr r4, [sp]\n\ + adds r5, r0, r4\n\ + ldr r0, =gUnknown_03001168\n\ + adds r0, r6, r0\n\ + str r0, [sp, 0x50]\n\ +_080E8666:\n\ + lsls r0, r3, 4\n\ + ldr r6, [sp, 0x1C]\n\ + adds r0, r6, r0\n\ + str r3, [sp, 0x4C]\n\ + bl ReadUnalignedWord\n\ + adds r4, r0, 0\n\ + ldr r1, [sp, 0x50]\n\ + ldr r0, [r1]\n\ + add r0, r9\n\ + adds r0, r7\n\ + bl ReadUnalignedWord\n\ + ldr r3, [sp, 0x4C]\n\ + cmp r4, r0\n\ + bne _080E86A8\n\ + ldr r2, [sp, 0xC]\n\ + adds r2, 0x1\n\ + str r2, [sp, 0xC]\n\ + ldr r4, [sp, 0x50]\n\ + ldr r0, [r4]\n\ + mov r6, r9\n\ + adds r1, r7, r6\n\ + adds r1, r0, r1\n\ + ldrh r0, [r5, 0x4]\n\ + ldrh r2, [r1, 0x4]\n\ + cmp r0, r2\n\ + bcs _080E86A8\n\ + adds r0, r5, 0\n\ + ldm r1!, {r2,r4,r6}\n\ + stm r0!, {r2,r4,r6}\n\ + ldr r1, [r1]\n\ + str r1, [r0]\n\ +_080E86A8:\n\ + adds r5, 0x10\n\ + adds r3, 0x1\n\ + cmp r3, 0x2\n\ + ble _080E8666\n\ + ldr r3, [sp, 0xC]\n\ + cmp r3, 0\n\ + bne _080E86CE\n\ + ldr r0, =gUnknown_03001168\n\ + ldr r4, [sp, 0x38]\n\ + adds r0, r4, r0\n\ + ldr r0, [r0]\n\ + mov r5, r9\n\ + adds r2, r7, r5\n\ + mov r1, r10\n\ + adds r0, r2\n\ + ldm r0!, {r2,r3,r6}\n\ + stm r1!, {r2,r3,r6}\n\ + ldr r0, [r0]\n\ + str r0, [r1]\n\ +_080E86CE:\n\ + movs r4, 0x10\n\ + add r10, r4\n\ + movs r5, 0x1\n\ + add r8, r5\n\ + ldr r6, [sp, 0x24]\n\ + cmp r8, r6\n\ + blt _080E864A\n\ +_080E86DC:\n\ + ldr r0, [sp, 0x44]\n\ + adds r0, 0x60\n\ + str r0, [sp, 0x44]\n\ + ldr r1, [sp, 0x48]\n\ + adds r1, 0x30\n\ + str r1, [sp, 0x48]\n\ + ldr r2, [sp, 0x8]\n\ + adds r2, 0x1\n\ + str r2, [sp, 0x8]\n\ + cmp r2, 0x1\n\ + bgt _080E86F4\n\ + b _080E85DC\n\ +_080E86F4:\n\ + ldr r3, [sp, 0x28]\n\ + str r3, [sp, 0x4]\n\ + cmp r3, 0x8\n\ + bgt _080E86FE\n\ + b _080E85BE\n\ +_080E86FE:\n\ + movs r4, 0\n\ + str r4, [sp, 0x8]\n\ +_080E8702:\n\ + ldr r5, [sp, 0x8]\n\ + adds r5, 0x1\n\ + str r5, [sp, 0x2C]\n\ + ldr r0, =gSaveBlock2Ptr\n\ + ldr r1, [r0]\n\ + movs r0, 0x54\n\ + ldr r6, [sp, 0x8]\n\ + muls r0, r6\n\ + adds r3, r0, r1\n\ + movs r0, 0xA8\n\ + muls r0, r6\n\ + ldr r1, [sp]\n\ + adds r2, r0, r1\n\ + movs r4, 0x2\n\ + mov r8, r4\n\ +_080E8720:\n\ + movs r5, 0xD8\n\ + lsls r5, 3\n\ + adds r0, r2, r5\n\ + ldr r6, =0x0000057c\n\ + adds r1, r3, r6\n\ + ldm r1!, {r4-r6}\n\ + stm r0!, {r4-r6}\n\ + ldm r1!, {r4-r6}\n\ + stm r0!, {r4-r6}\n\ + ldr r1, [r1]\n\ + str r1, [r0]\n\ + adds r3, 0x1C\n\ + adds r2, 0x1C\n\ + movs r0, 0x1\n\ + negs r0, r0\n\ + add r8, r0\n\ + mov r1, r8\n\ + cmp r1, 0\n\ + bge _080E8720\n\ + movs r2, 0\n\ + mov r8, r2\n\ + ldr r3, [sp, 0x24]\n\ + cmp r8, r3\n\ + blt _080E8752\n\ + b _080E885A\n\ +_080E8752:\n\ + ldr r4, [sp, 0x8]\n\ + lsls r1, r4, 3\n\ + movs r0, 0xA8\n\ + adds r5, r4, 0\n\ + muls r5, r0\n\ + str r5, [sp, 0x20]\n\ + str r5, [sp, 0x3C]\n\ + subs r1, r4\n\ + lsls r1, 2\n\ + mov r10, r1\n\ +_080E8766:\n\ + movs r6, 0\n\ + str r6, [sp, 0xC]\n\ + mov r0, r8\n\ + lsls r0, 2\n\ + str r0, [sp, 0x38]\n\ + mov r1, r8\n\ + adds r1, 0x1\n\ + str r1, [sp, 0x30]\n\ + ldr r0, =gUnknown_03001168\n\ + ldr r2, [sp, 0x38]\n\ + adds r2, r0\n\ + mov r9, r2\n\ + ldr r3, [sp]\n\ + movs r4, 0xD8\n\ + lsls r4, 3\n\ + adds r0, r3, r4\n\ + ldr r5, [sp, 0x3C]\n\ + adds r7, r5, r0\n\ + str r6, [sp, 0x40]\n\ + movs r3, 0x2\n\ +_080E878E:\n\ + ldr r1, [sp, 0x20]\n\ + movs r2, 0xD8\n\ + lsls r2, 3\n\ + adds r0, r1, r2\n\ + ldr r4, [sp]\n\ + adds r0, r4, r0\n\ + ldr r6, [sp, 0x40]\n\ + adds r5, r0, r6\n\ + adds r0, r5, 0\n\ + str r3, [sp, 0x4C]\n\ + bl ReadUnalignedWord\n\ + adds r4, r0, 0\n\ + movs r6, 0x90\n\ + lsls r6, 1\n\ + add r6, r10\n\ + mov r1, r9\n\ + ldr r0, [r1]\n\ + adds r0, r6\n\ + bl ReadUnalignedWord\n\ + ldr r3, [sp, 0x4C]\n\ + cmp r4, r0\n\ + bne _080E8808\n\ + adds r0, r5, 0x4\n\ + bl ReadUnalignedWord\n\ + adds r4, r0, 0\n\ + mov r2, r9\n\ + ldr r0, [r2]\n\ + adds r0, r6\n\ + adds r0, 0x4\n\ + bl ReadUnalignedWord\n\ + ldr r3, [sp, 0x4C]\n\ + cmp r4, r0\n\ + bne _080E8808\n\ + ldr r4, [sp, 0xC]\n\ + adds r4, 0x1\n\ + str r4, [sp, 0xC]\n\ + mov r5, r9\n\ + ldr r0, [r5]\n\ + mov r6, r10\n\ + adds r2, r0, r6\n\ + movs r0, 0x94\n\ + lsls r0, 1\n\ + adds r1, r2, r0\n\ + ldrh r0, [r7, 0x8]\n\ + ldrh r1, [r1]\n\ + cmp r0, r1\n\ + bcs _080E8808\n\ + adds r0, r7, 0\n\ + movs r4, 0x90\n\ + lsls r4, 1\n\ + adds r1, r2, r4\n\ + ldm r1!, {r2,r5,r6}\n\ + stm r0!, {r2,r5,r6}\n\ + ldm r1!, {r4-r6}\n\ + stm r0!, {r4-r6}\n\ + ldr r1, [r1]\n\ + str r1, [r0]\n\ +_080E8808:\n\ + adds r7, 0x1C\n\ + ldr r0, [sp, 0x40]\n\ + adds r0, 0x1C\n\ + str r0, [sp, 0x40]\n\ + subs r3, 0x1\n\ + cmp r3, 0\n\ + bge _080E878E\n\ + ldr r1, [sp, 0xC]\n\ + cmp r1, 0\n\ + bne _080E8850\n\ + mov r0, r8\n\ + adds r0, 0x3\n\ + lsls r1, r0, 3\n\ + subs r1, r0\n\ + lsls r1, 2\n\ + ldr r2, [sp, 0x20]\n\ + adds r1, r2\n\ + ldr r3, [sp]\n\ + adds r1, r3, r1\n\ + ldr r0, =gUnknown_03001168\n\ + ldr r4, [sp, 0x38]\n\ + adds r0, r4, r0\n\ + ldr r0, [r0]\n\ + add r0, r10\n\ + movs r5, 0xD8\n\ + lsls r5, 3\n\ + adds r1, r5\n\ + movs r6, 0x90\n\ + lsls r6, 1\n\ + adds r0, r6\n\ + ldm r0!, {r2-r4}\n\ + stm r1!, {r2-r4}\n\ + ldm r0!, {r2,r5,r6}\n\ + stm r1!, {r2,r5,r6}\n\ + ldr r0, [r0]\n\ + str r0, [r1]\n\ +_080E8850:\n\ + ldr r3, [sp, 0x30]\n\ + mov r8, r3\n\ + ldr r4, [sp, 0x24]\n\ + cmp r8, r4\n\ + blt _080E8766\n\ +_080E885A:\n\ + ldr r5, [sp, 0x2C]\n\ + str r5, [sp, 0x8]\n\ + cmp r5, 0x1\n\ + bgt _080E8864\n\ + b _080E8702\n\ +_080E8864:\n\ + add sp, 0x54\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool\n\ + "); +} + +void sub_80E8880(struct UnknownRecMixingStruct *arg0, struct UnknownRecMixingStruct *arg1) +{ + s32 i, j; + + for (i = 0; i < 3; i++) + { + s32 r2 = 0; + s32 r4 = -1; + for (j = 0; j < 6; j++) + { + if (arg1[j].field_4 > r2) + { + r4 = j; + r2 = arg1[j].field_4; + } + } + + if (r4 >= 0) + { + arg0[i] = arg1[r4]; + arg1[r4].field_4 = 0; + } + } +} + +void sub_80E88CC(struct UnknownRecMixingStruct2 *arg0, struct UnknownRecMixingStruct2 *arg1) +{ + s32 i, j; + + for (i = 0; i < 3; i++) + { + s32 r2 = 0; + s32 r4 = -1; + for (j = 0; j < 6; j++) + { + if (arg1[j].field_8 > r2) + { + r4 = j; + r2 = arg1[j].field_8; + } + } + + if (r4 >= 0) + { + arg0[i] = arg1[r4]; + arg1[r4].field_8 = 0; + } + } +} + +NAKED +void sub_80E8924(struct UnknownRecMixingStruct3 *arg0) +{ + asm_unified("push {r4-r7,lr}\n\ + mov r7, r10\n\ + mov r6, r9\n\ + mov r5, r8\n\ + push {r5-r7}\n\ + mov r9, r0\n\ + movs r0, 0\n\ + ldr r1, =gSaveBlock2Ptr\n\ + mov r10, r1\n\ +_080E8936:\n\ + lsls r1, r0, 1\n\ + adds r2, r0, 0x1\n\ + mov r8, r2\n\ + adds r1, r0\n\ + lsls r0, r1, 5\n\ + movs r2, 0x87\n\ + lsls r2, 2\n\ + adds r7, r0, r2\n\ + lsls r1, 6\n\ + mov r0, r9\n\ + adds r4, r0, r1\n\ + movs r6, 0\n\ + movs r5, 0x1\n\ +_080E8950:\n\ + mov r1, r10\n\ + ldr r0, [r1]\n\ + adds r0, r7\n\ + adds r0, r6\n\ + adds r1, r4, 0\n\ + bl sub_80E8880\n\ + adds r4, 0x60\n\ + adds r6, 0x30\n\ + subs r5, 0x1\n\ + cmp r5, 0\n\ + bge _080E8950\n\ + mov r0, r8\n\ + cmp r0, 0x8\n\ + ble _080E8936\n\ + movs r5, 0\n\ + ldr r4, =gSaveBlock2Ptr\n\ +_080E8972:\n\ + movs r0, 0x54\n\ + adds r1, r5, 0\n\ + muls r1, r0\n\ + ldr r2, =0x0000057c\n\ + adds r1, r2\n\ + ldr r0, [r4]\n\ + adds r0, r1\n\ + movs r1, 0xA8\n\ + muls r1, r5\n\ + movs r2, 0xD8\n\ + lsls r2, 3\n\ + adds r1, r2\n\ + add r1, r9\n\ + bl sub_80E88CC\n\ + adds r5, 0x1\n\ + cmp r5, 0x1\n\ + ble _080E8972\n\ + pop {r3-r5}\n\ + mov r8, r3\n\ + mov r9, r4\n\ + mov r10, r5\n\ + pop {r4-r7}\n\ + pop {r0}\n\ + bx r0\n\ + .pool"); +} + +static void sub_80E89AC(struct UnkRecordMixingStruct2 *arg0, size_t arg1, u32 arg2) +{ + u8 linkPlayerCount = GetLinkPlayerCount(); + struct UnknownRecMixingStruct3 *largeStructPtr = AllocZeroed(sizeof(struct UnknownRecMixingStruct3)); + + sub_80E8578(largeStructPtr, arg0, arg1, arg2, linkPlayerCount); + sub_80E8924(largeStructPtr); + + Free(largeStructPtr); +} + +static void sub_80E89F8(struct RecordMixingDayCareMail *dst) +{ + gUnknown_02039F9C.mail[0] = gSaveBlock1Ptr->daycare.mons[0].mail; + gUnknown_02039F9C.mail[1] = gSaveBlock1Ptr->daycare.mons[1].mail; + InitDaycareMailRecordMixing(&gSaveBlock1Ptr->daycare, &gUnknown_02039F9C); + *dst = *gUnknown_03001148; +} + +static void sub_80E8A54(struct RecordMixingDayCareMail *src) +{ + s32 i; + + for (i = 0; i < src->numDaycareMons; i++) + { + struct DayCareMail *mail = &src->mail[i]; + if (mail->message.itemId != 0) + { + if (mail->gameLanguage != LANGUAGE_JAPANESE) + PadNameString(mail->OT_name, 0xFC); + + ConvertInternationalString(mail->monName, mail->monLanguage); + } + } +} + +static void nullsub_1405(union BattleTowerRecord *src) +{ + +} + +static void sub_80E8AC0(union BattleTowerRecord *arg0) +{ + s32 i; + + for (i = 0; i < 4; i++) + { + struct UnknownPokemonStruct *towerMon = &arg0->emerald.party[i]; + if (towerMon->species != 0) + StripExtCtrlCodes(towerMon->nickname); + } + + sub_8164F70(arg0); +} From 9e7965fab085a06f700756f448fbc072ee7e0095 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 26 May 2018 00:25:36 +0200 Subject: [PATCH 24/26] document record mixing --- asm/battle_tower.s | 10 +- asm/fldeff_80F9BCC.s | 12 +- constants/item_data_constants.inc | 5 - include/battle_tower.h | 25 +- include/fldeff_80F9BCC.h | 4 +- include/global.h | 51 +- include/mauville_old_man.h | 4 +- include/mystery_event_script.h | 1 - include/pokemon.h | 27 - include/record_mixing.h | 4 +- include/tv.h | 4 +- src/daycare.c | 34 +- src/dewford_trend.c | 2 +- src/mauville_old_man.c | 29 +- src/record_mixing.c | 995 +++++++++++++++--------------- src/secret_base.c | 2 +- src/tv.c | 4 +- 17 files changed, 593 insertions(+), 620 deletions(-) delete mode 100644 constants/item_data_constants.inc diff --git a/asm/battle_tower.s b/asm/battle_tower.s index 6cee2dc0a..788061f2b 100644 --- a/asm/battle_tower.s +++ b/asm/battle_tower.s @@ -3746,7 +3746,7 @@ _08163FF4: ldr r0, [r6] ldr r1, =0x0000064c adds r0, r1 - bl sub_8164F70 + bl CalcEmeraldBattleTowerChecksum bl sub_8163E90 pop {r3,r4} mov r8, r3 @@ -5484,8 +5484,8 @@ _08164F52: .pool thumb_func_end sub_8164ED8 - thumb_func_start sub_8164F70 -sub_8164F70: @ 8164F70 + thumb_func_start CalcEmeraldBattleTowerChecksum +CalcEmeraldBattleTowerChecksum: @ 8164F70 push {r4,lr} adds r2, r0, 0 adds r2, 0xE8 @@ -5504,7 +5504,7 @@ _08164F7E: pop {r4} pop {r0} bx r0 - thumb_func_end sub_8164F70 + thumb_func_end CalcEmeraldBattleTowerChecksum thumb_func_start sub_8164F94 sub_8164F94: @ 8164F94 @@ -6750,7 +6750,7 @@ _08165988: ldr r1, [sp, 0x10] bl CpuSet adds r0, r5, 0 - bl sub_8164F70 + bl CalcEmeraldBattleTowerChecksum movs r0, 0x1 _081659BE: add sp, 0x14 diff --git a/asm/fldeff_80F9BCC.s b/asm/fldeff_80F9BCC.s index e31375f9f..8f1e198b8 100644 --- a/asm/fldeff_80F9BCC.s +++ b/asm/fldeff_80F9BCC.s @@ -2431,8 +2431,8 @@ sub_80FAFF8: @ 80FAFF8 .pool thumb_func_end sub_80FAFF8 - thumb_func_start sub_80FB00C -sub_80FB00C: @ 80FB00C + thumb_func_start CreateRecordMixingSprite +CreateRecordMixingSprite: @ 80FB00C push {r4,r5,lr} ldr r0, =gUnknown_0858E864 bl LoadSpritePalette @@ -2478,10 +2478,10 @@ _080FB06E: pop {r4,r5} pop {r1} bx r1 - thumb_func_end sub_80FB00C + thumb_func_end CreateRecordMixingSprite - thumb_func_start sub_80FB074 -sub_80FB074: @ 80FB074 + thumb_func_start DestroyRecordMixingSprite +DestroyRecordMixingSprite: @ 80FB074 push {r4-r7,lr} ldr r4, =gSprites adds r7, r4, 0 @@ -2509,6 +2509,6 @@ _080FB098: pop {r0} bx r0 .pool - thumb_func_end sub_80FB074 + thumb_func_end DestroyRecordMixingSprite .align 2, 0 @ Don't pad with nop. diff --git a/constants/item_data_constants.inc b/constants/item_data_constants.inc deleted file mode 100644 index f0badc467..000000000 --- a/constants/item_data_constants.inc +++ /dev/null @@ -1,5 +0,0 @@ - .set POCKET_ITEMS, 0x01 - .set POCKET_POKE_BALLS, 0x02 - .set POCKET_TM_HM, 0x03 - .set POCKET_BERRIES, 0x04 - .set BAG_KEYITEMS, 0x05 diff --git a/include/battle_tower.h b/include/battle_tower.h index 7bacf5249..9d4553132 100644 --- a/include/battle_tower.h +++ b/include/battle_tower.h @@ -1,7 +1,8 @@ #ifndef GUARD_BATTLE_TOWER_H #define GUARD_BATTLE_TOWER_H -struct RSBattleTowerRecord { +struct RSBattleTowerRecord +{ /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 /*0x01*/ u8 trainerClass; /*0x02*/ u16 winStreak; @@ -15,30 +16,16 @@ struct RSBattleTowerRecord { /*0xA4*/ u16 unk_11c8; }; -struct EmeraldBattleTowerRecord { - /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 - /*0x01*/ u8 trainerClass; - /*0x02*/ u16 winStreak; - /*0x04*/ u8 name[8]; - /*0x0C*/ u8 trainerId[4]; - /*0x10*/ struct { - u16 easyChat[6]; - } greeting; - /*0x1C*/ u8 filler_1c[0x18]; - /*0x34*/ struct UnknownPokemonStruct party[4]; - /*0xe4*/ u8 language; - u8 filler_e5[7]; -}; - -union BattleTowerRecord { +union BattleTowerRecord +{ struct RSBattleTowerRecord ruby_sapphire; struct EmeraldBattleTowerRecord emerald; }; u16 sub_8164FCC(u8, u8); -void sub_81659DC(union BattleTowerRecord *a0, union BattleTowerRecord *a1); +void sub_81659DC(struct RSBattleTowerRecord *a0, struct RSBattleTowerRecord *a1); bool32 sub_816587C(union BattleTowerRecord *, union BattleTowerRecord *); -bool32 sub_8164F70(union BattleTowerRecord *); +void CalcEmeraldBattleTowerChecksum(struct EmeraldBattleTowerRecord *); void sub_81628A0(union BattleTowerRecord *); #endif //GUARD_BATTLE_TOWER_H diff --git a/include/fldeff_80F9BCC.h b/include/fldeff_80F9BCC.h index 4169e328d..ba775cd6d 100644 --- a/include/fldeff_80F9BCC.h +++ b/include/fldeff_80F9BCC.h @@ -9,8 +9,8 @@ void sub_80FA5E4(s16 id, s16 x, s16 y); void sub_80FA794(s16 x, s16 y); -void sub_80FB00C(void); -void sub_80FB074(void); +void CreateRecordMixingSprite(void); +void DestroyRecordMixingSprite(void); void overworld_poison_effect(void); bool8 sub_80FADE4(u16, u8); diff --git a/include/global.h b/include/global.h index b869da813..f9e0aa66e 100644 --- a/include/global.h +++ b/include/global.h @@ -103,6 +103,8 @@ enum LanguageId #define VARS_COUNT 256 #define MAIL_COUNT 16 #define SECRET_BASES_COUNT 20 +#define TV_SHOWS_COUNT 25 +#define POKE_NEWS_COUNT 16 #define PC_ITEMS_COUNT 50 #define BAG_ITEMS_COUNT 30 #define BAG_KEYITEMS_COUNT 30 @@ -263,6 +265,49 @@ struct UnkRecordMixingStruct u8 field_38[10]; }; +struct UnknownPokemonStruct +{ + u16 species; + u16 heldItem; + u16 moves[4]; + u8 level; + u8 ppBonuses; + u8 hpEV; + u8 attackEV; + u8 defenseEV; + u8 speedEV; + u8 spAttackEV; + u8 spDefenseEV; + u32 otId; + u32 hpIV:5; + u32 attackIV:5; + u32 defenseIV:5; + u32 speedIV:5; + u32 spAttackIV:5; + u32 spDefenseIV:5; + u32 gap:1; + u32 altAbility:1; + u32 personality; + u8 nickname[POKEMON_NAME_LENGTH + 1]; + u8 friendship; +}; + +struct EmeraldBattleTowerRecord +{ + /*0x00*/ u8 battleTowerLevelType; // 0 = level 50, 1 = level 100 + /*0x01*/ u8 trainerClass; + /*0x02*/ u16 winStreak; + /*0x04*/ u8 name[8]; + /*0x0C*/ u8 trainerId[4]; + /*0x10*/ struct { + u16 easyChat[6]; + } greeting; + /*0x1C*/ u8 filler_1c[0x18]; + /*0x34*/ struct UnknownPokemonStruct party[4]; + /*0xE4*/ u8 language; + /*0xE8*/ u32 checksum; +}; + struct SaveBlock2 { /*0x00*/ u8 playerName[PLAYER_NAME_LENGTH]; @@ -302,7 +347,7 @@ struct SaveBlock2 // All below could be a one giant struct - /*0x64C*/ u8 field_64C[236]; + /*0x64C*/ struct EmeraldBattleTowerRecord battleTower; /*0x738*/ struct UnknownSaveBlock2Struct field_738[5]; // No idea here, it's probably wrong, no clue. /*0xBD4*/ u16 field_BD4; /*0xBD6*/ u16 field_BD6; @@ -763,8 +808,8 @@ struct SaveBlock1 /*0x????*/ u8 decorDoll[40]; /*0x????*/ u8 decorCushion[10]; /*0x27CA*/ u8 padding_27CA[2]; - /*0x27CC*/ TVShow tvShows[25]; - /*0x2B50*/ PokeNews pokeNews[16]; + /*0x27CC*/ TVShow tvShows[TV_SHOWS_COUNT]; + /*0x2B50*/ PokeNews pokeNews[POKE_NEWS_COUNT]; /*0x2B90*/ u16 outbreakPokemonSpecies; /*0x2B92*/ u8 outbreakLocationMapNum; /*0x2B93*/ u8 outbreakLocationMapGroup; diff --git a/include/mauville_old_man.h b/include/mauville_old_man.h index b1f10314a..e318ac8bb 100644 --- a/include/mauville_old_man.h +++ b/include/mauville_old_man.h @@ -19,8 +19,8 @@ void ScrSpecial_SetMauvilleOldManMapObjGfx(void); u8 sub_81201C8(void); void sub_8120B70(OldMan *dest); void sub_8120670(void); -void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6); -void sub_8120CD0(union OldMan * oldMan, u32 unused, u32 a2); +void SanitizeReceivedRubyOldMan(union OldMan * oldMan, u32 r1, u32 r6); +void SanitizeReceivedEmeraldOldMan(union OldMan * oldMan, u32 unused, u32 a2); void ResetMauvilleOldManFlag(void); #endif // GUARD_MAUVILLE_OLD_MAN_H diff --git a/include/mystery_event_script.h b/include/mystery_event_script.h index 0857c7188..991cab53a 100644 --- a/include/mystery_event_script.h +++ b/include/mystery_event_script.h @@ -6,6 +6,5 @@ bool32 sub_8153884(u32 *a0); u32 RunMysteryEventScript(u8 *script); void SetMysteryEventScriptStatus(u32 val); u16 GetRecordMixingGift(void); -u16 GetRecordMixingGift(void); #endif // GUARD_MYSTERY_EVENT_SCRIPT_H diff --git a/include/pokemon.h b/include/pokemon.h index b6b0d6d36..37028821a 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -240,33 +240,6 @@ struct PokemonStorage /*0x83C2*/ u8 boxWallpapers[14]; }; -struct UnknownPokemonStruct -{ - u16 species; - u16 heldItem; - u16 moves[4]; - u8 level; - u8 ppBonuses; - u8 hpEV; - u8 attackEV; - u8 defenseEV; - u8 speedEV; - u8 spAttackEV; - u8 spDefenseEV; - u32 otId; - u32 hpIV:5; - u32 attackIV:5; - u32 defenseIV:5; - u32 speedIV:5; - u32 spAttackIV:5; - u32 spDefenseIV:5; - u32 gap:1; - u32 altAbility:1; - u32 personality; - u8 nickname[POKEMON_NAME_LENGTH + 1]; - u8 friendship; -}; - struct UnknownPokemonSubStruct2 { u16 species; diff --git a/include/record_mixing.h b/include/record_mixing.h index 900951516..3cd4d649e 100644 --- a/include/record_mixing.h +++ b/include/record_mixing.h @@ -26,12 +26,10 @@ struct UnkRecordMixingStruct2 struct UnkRecordMixingStruct2b field_120[2]; }; - - // Exported RAM declarations // Exported ROM declarations - +void sub_80E6BE8(void); void sub_80E8260(struct UnkRecordMixingStruct2 *arg0); #endif //GUARD_RECORD_MIXING_H diff --git a/include/tv.h b/include/tv.h index 1b3423275..17be8c43c 100644 --- a/include/tv.h +++ b/include/tv.h @@ -16,7 +16,7 @@ void sub_80EED10(void); void sub_80EED34(void); void sub_80EED60(u16 delta); void sub_80F01B8(void); -void sub_80F01E8(void *src, u32 size, u8 masterIdx); +void ReceiveTvShowsData(void *src, u32 size, u8 masterIdx); void sub_80EE4DC(struct Pokemon *pokemon, u8 ribbonMonDataIdx); u32 GetPlayerIDAsU32(void); bool8 GetPriceReduction(u8 newsKind); @@ -30,7 +30,7 @@ void sub_80EEA70(void); void sub_80EDB44(void); void sub_80EDC60(const u16 *words); void sub_80EDA80(void); -void sub_80F0C7C(void *src, u32 size, u8 masterIdx); +void ReceivePokeNewsData(void *src, u32 size, u8 masterIdx); void sub_80F0BB8(void); void sub_80ED950(bool8 flag); void sub_80EEC80(void); diff --git a/src/daycare.c b/src/daycare.c index 17928324f..5a6aa2b40 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -47,7 +47,7 @@ extern void sub_81B9328(void); extern void CB2_ReturnToField(void); // this file's functions -static void ClearDaycareMonMisc(struct DaycareMiscMon *misc); +static void ClearDaycareMonMail(struct DayCareMail *mail); static void SetInitialEggData(struct Pokemon *mon, u16 species, struct DayCare *daycare); static u8 GetDaycareCompatibilityScore(struct DayCare *daycare); static void DaycarePrintMonInfo(u8 windowId, s32 daycareSlotId, u8 y); @@ -179,13 +179,13 @@ static void StorePokemonInDaycare(struct Pokemon *mon, struct DaycareMon *daycar { u8 mailId; - StringCopy(daycareMon->misc.OT_name, gSaveBlock2Ptr->playerName); - GetMonNick(mon, daycareMon->misc.monName); - StripExtCtrlCodes(daycareMon->misc.monName); - daycareMon->misc.gameLanguage = LANGUAGE_ENGLISH; - daycareMon->misc.monLanguage = GetMonData(mon, MON_DATA_LANGUAGE); + StringCopy(daycareMon->mail.OT_name, gSaveBlock2Ptr->playerName); + GetMonNick(mon, daycareMon->mail.monName); + StripExtCtrlCodes(daycareMon->mail.monName); + daycareMon->mail.gameLanguage = LANGUAGE_ENGLISH; + daycareMon->mail.monLanguage = GetMonData(mon, MON_DATA_LANGUAGE); mailId = GetMonData(mon, MON_DATA_MAIL); - daycareMon->misc.mail = gSaveBlock1Ptr->mail[mailId]; + daycareMon->mail.message = gSaveBlock1Ptr->mail[mailId]; TakeMailFromMon(mon); } @@ -219,10 +219,10 @@ static void ShiftDaycareSlots(struct DayCare *daycare) daycare->mons[0].mon = daycare->mons[1].mon; ZeroBoxMonData(&daycare->mons[1].mon); - daycare->mons[0].misc = daycare->mons[1].misc; + daycare->mons[0].mail = daycare->mons[1].mail; daycare->mons[0].steps = daycare->mons[1].steps; daycare->mons[1].steps = 0; - ClearDaycareMonMisc(&daycare->mons[1].misc); + ClearDaycareMonMail(&daycare->mons[1].mail); } } @@ -277,10 +277,10 @@ static u16 TakeSelectedPokemonFromDaycare(struct DaycareMon *daycareMon) } gPlayerParty[PARTY_SIZE - 1] = pokemon; - if (daycareMon->misc.mail.itemId) + if (daycareMon->mail.message.itemId) { - GiveMailToMon2(&gPlayerParty[PARTY_SIZE - 1], &daycareMon->misc.mail); - ClearDaycareMonMisc(&daycareMon->misc); + GiveMailToMon2(&gPlayerParty[PARTY_SIZE - 1], &daycareMon->mail.message); + ClearDaycareMonMail(&daycareMon->mail); } ZeroBoxMonData(&daycareMon->mon); @@ -364,23 +364,23 @@ u8 GetNumLevelsGainedFromDaycare(void) return 0; } -static void ClearDaycareMonMisc(struct DaycareMiscMon *misc) +static void ClearDaycareMonMail(struct DayCareMail *mail) { s32 i; for (i = 0; i < OT_NAME_LENGTH + 1; i++) - misc->OT_name[i] = 0; + mail->OT_name[i] = 0; for (i = 0; i < POKEMON_NAME_LENGTH + 1; i++) - misc->monName[i] = 0; + mail->monName[i] = 0; - ClearMailStruct(&misc->mail); + ClearMailStruct(&mail->message); } static void ClearDaycareMon(struct DaycareMon *daycareMon) { ZeroBoxMonData(&daycareMon->mon); daycareMon->steps = 0; - ClearDaycareMonMisc(&daycareMon->misc); + ClearDaycareMonMail(&daycareMon->mail); } static void ClearAllDaycareData(struct DayCare *daycare) diff --git a/src/dewford_trend.c b/src/dewford_trend.c index 3ceec6563..44b42c123 100644 --- a/src/dewford_trend.c +++ b/src/dewford_trend.c @@ -158,7 +158,7 @@ static void sub_8122804(struct EasyChatPair *s, u16 b, u8 c) } } -void sub_812287C(void *a, u32 b, u8 unused) +void ReceiveEasyChatPairsData(void *a, u32 b, u8 unused) { u16 i, j, r3, players; struct EasyChatPair *buffer1, *buffer2, *src, *dst, *foo_of_buffer2; diff --git a/src/mauville_old_man.c b/src/mauville_old_man.c index 70a934615..2ce8a271d 100644 --- a/src/mauville_old_man.c +++ b/src/mauville_old_man.c @@ -793,11 +793,11 @@ void sub_8120C0C(union OldMan * oldMan, u32 r8, u32 r7, u32 r3) } } -void sub_8120CD0(union OldMan * oldMan, u32 unused, u32 a2) +void SanitizeReceivedEmeraldOldMan(union OldMan * oldMan, u32 version, u32 language) { u8 sp00[8]; s32 i; - if (oldMan->common.id == MAUVILLE_MAN_STORYTELLER && a2 == LANGUAGE_JAPANESE) + if (oldMan->common.id == MAUVILLE_MAN_STORYTELLER && language == LANGUAGE_JAPANESE) { struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; @@ -816,9 +816,10 @@ void sub_8120CD0(union OldMan * oldMan, u32 unused, u32 a2) } } -void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6) +void SanitizeReceivedRubyOldMan(union OldMan * oldMan, u32 version, u32 language) { - u32 r2 = (r1 == LANGUAGE_JAPANESE || r1 == LANGUAGE_ENGLISH) ? 1 : 0; + bool32 isRuby = (version == VERSION_SAPPHIRE || version == VERSION_RUBY); + switch (oldMan->common.id) { case MAUVILLE_MAN_TRADER: @@ -826,7 +827,7 @@ void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6) struct MauvilleOldManTrader * trader = &oldMan->trader; s32 i; - if (r2) + if (isRuby) { for (i = 0; i < 4; i++) { @@ -837,7 +838,7 @@ void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6) trader->language[i] = LANGUAGE_JAPANESE; } else - trader->language[i] = r6; + trader->language[i] = language; } } else @@ -858,12 +859,12 @@ void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6) struct MauvilleManStoryteller * storyteller = &oldMan->storyteller; s32 i; - if (r2) + if (isRuby) { for (i = 0; i < 4; i++) { if (storyteller->gameStatIDs[i] != 0) - storyteller->language[i] = r6; + storyteller->language[i] = language; } } } @@ -872,9 +873,9 @@ void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6) { struct MauvilleManBard * bard = &oldMan->bard; - if (r2) + if (isRuby) { - bard->language = r6; + bard->language = language; } } break; @@ -882,9 +883,9 @@ void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6) { struct MauvilleManHipster * hipster = &oldMan->hipster; - if (r2) + if (isRuby) { - hipster->language = r6; + hipster->language = language; } } break; @@ -892,9 +893,9 @@ void sub_8120D34(union OldMan * oldMan, u32 r1, u32 r6) { struct MauvilleManGiddy * giddy = &oldMan->giddy; - if (r2) + if (isRuby) { - giddy->language = r6; + giddy->language = language; } } break; diff --git a/src/record_mixing.c b/src/record_mixing.c index 9a47d4112..19a8b0889 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -34,13 +34,37 @@ #include "daycare.h" #include "international_string_util.h" +extern void ReceiveSecretBasesData(struct SecretBaseRecord *, size_t, u8); +extern void ReceiveEasyChatPairsData(struct EasyChatPair *, size_t, u8); + // Static type declarations +struct UnknownRecMixingStruct +{ + u32 field_0; + u16 field_4; + u8 field_6[9]; +}; + +struct UnknownRecMixingStruct2 +{ + u32 field_0; + u16 field_4; + u16 field_6; + u16 field_8; + u8 field_A[16]; +}; + +struct UnknownRecMixingStruct3 +{ + u8 field_0[0x810]; +}; + struct PlayerRecordsRS { - struct SecretBaseRecord secretBases[20]; - TVShow tvShows[25]; - PokeNews pokeNews[16]; + struct SecretBaseRecord secretBases[SECRET_BASES_COUNT]; + TVShow tvShows[TV_SHOWS_COUNT]; + PokeNews pokeNews[POKE_NEWS_COUNT]; OldMan oldMan; struct EasyChatPair easyChatPairs[5]; struct RecordMixingDayCareMail dayCareMail; @@ -48,71 +72,75 @@ struct PlayerRecordsRS u16 filler11C8[0x32]; }; -struct PlayerRecords +struct PlayerRecordsEmerald { - /* 0x0000 */ struct SecretBaseRecord secretBases[20]; - /* 0x0c80 */ TVShow tvShows[25]; - /* 0x1004 */ PokeNews pokeNews[16]; + /* 0x0000 */ struct SecretBaseRecord secretBases[SECRET_BASES_COUNT]; + /* 0x0c80 */ TVShow tvShows[TV_SHOWS_COUNT]; + /* 0x1004 */ PokeNews pokeNews[POKE_NEWS_COUNT]; /* 0x1044 */ OldMan oldMan; - /* 0x1084 */ struct EasyChatPair easyChatPair[5]; + /* 0x1084 */ struct EasyChatPair easyChatPairs[5]; /* 0x10ac */ struct RecordMixingDayCareMail dayCareMail; - /* 0x1124 */ union BattleTowerRecord battleTowerRecord; + /* 0x1124 */ struct EmeraldBattleTowerRecord battleTowerRecord; /* 0x1210 */ u16 unk_1210; /* 0x1214 */ LilycoveLady lilycoveLady; /* 0x1254 */ struct UnkRecordMixingStruct unk_1254[2]; /* 0x12dc */ struct UnkRecordMixingStruct2 unk_12dc; /* 0x1434 */ u8 field_1434[0x10]; -}; // 1444 +}; // 0x1444 + +union PlayerRecords +{ + struct PlayerRecordsRS ruby; + struct PlayerRecordsEmerald emerald; +}; // Static RAM declarations -IWRAM_DATA bool8 gUnknown_03001130; -IWRAM_DATA struct SecretBaseRecord *gUnknown_03001134; -IWRAM_DATA TVShow *gUnknown_03001138; -IWRAM_DATA PokeNews *gUnknown_0300113C; -IWRAM_DATA OldMan *gUnknown_03001140; -IWRAM_DATA struct EasyChatPair *gUnknown_03001144; -IWRAM_DATA struct RecordMixingDayCareMail *gUnknown_03001148; -IWRAM_DATA void *gUnknown_0300114C; // gSaveBlock2Ptr->field_64C -IWRAM_DATA LilycoveLady *gUnknown_03001150; -IWRAM_DATA void *gUnknown_03001154; // gSaveBlock2Ptr->field_0DC; -IWRAM_DATA void *gUnknown_03001158; // gSaveBlock2Ptr->field_64C -IWRAM_DATA u32 gUnknown_0300115C; -IWRAM_DATA u8 gUnknown_03001160; -IWRAM_DATA u32 filler_03001164; -IWRAM_DATA u32 gUnknown_03001168[3]; +static IWRAM_DATA bool8 gUnknown_03001130; +static IWRAM_DATA struct SecretBaseRecord *sSecretBasesSave; +static IWRAM_DATA TVShow *sTvShowsSave; +static IWRAM_DATA PokeNews *sPokeNewsSave; +static IWRAM_DATA OldMan *sOldManSave; +static IWRAM_DATA struct EasyChatPair *sEasyChatPairsSave; +static IWRAM_DATA struct RecordMixingDayCareMail *gUnknown_03001148; +static IWRAM_DATA void *sBattleTowerSave; +static IWRAM_DATA LilycoveLady *sLilycoveLadySave; +static IWRAM_DATA void *gUnknown_03001154; // gSaveBlock2Ptr->field_0DC; +static IWRAM_DATA void *sBattleTowerSave_Duplicate; +static IWRAM_DATA u32 sRecordStructSize; +static IWRAM_DATA u8 gUnknown_03001160; +static IWRAM_DATA u32 filler_03001164; +static IWRAM_DATA u32 gUnknown_03001168[3]; -EWRAM_DATA struct RecordMixingDayCareMail gUnknown_02039F9C = {}; -EWRAM_DATA struct PlayerRecords *gUnknown_0203A014 = NULL; -EWRAM_DATA struct PlayerRecords *gUnknown_0203A018 = NULL; +static EWRAM_DATA struct RecordMixingDayCareMail gUnknown_02039F9C = {0}; +static EWRAM_DATA union PlayerRecords *sReceivedRecords = NULL; +static EWRAM_DATA union PlayerRecords *sSentRecord = NULL; // Static ROM declarations -static void sub_80E715C(u8 taskId); +static void Task_RecordMixing_Main(u8 taskId); static void sub_80E7324(u8 taskId); -static void sub_80E756C(u8 taskId); -static void sub_80E7630(u8 taskId); -static void sub_80E77D4(u8 taskId); -static void *sub_80E77FC(const u16 *asShort); -static void sub_80E7808(void *records, u16 *a1); -static u8 sub_80E7810(void); -static void *sub_80E7820(u8); -static void sub_80E78C4(OldMan *, size_t, u8); -static void sub_80E7948(union BattleTowerRecord *, size_t, u8); -static void sub_80E7A14(LilycoveLady *, size_t, u8); +static void Task_SendPacket(u8 taskId); +static void Task_CopyReceiveBuffer(u8 taskId); +static void Task_SendPacket_SwitchToReceive(u8 taskId); +static void *LoadPtrFromTaskData(const u16 *asShort); +static void StorePtrInTaskData(void *records, u16 *a1); +static u8 GetMultiplayerId_(void); +static void *GetPlayerRecvBuffer(u8); +static void ReceiveOldManData(OldMan *, size_t, u8); +static void ReceiveBattleTowerData(void *battleTowerRecord, size_t, u8); +static void ReceiveLilycoveLadyData(LilycoveLady *, size_t, u8); static void sub_80E7B2C(const u8 *); -static void sub_80E7B60(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); +static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *, size_t, u8, TVShow *); static void sub_80E7F68(u16 *item, u8 which); static void sub_80E7FF8(u8 taskId); static void sub_80E8110(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1); static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg2); static void sub_80E89AC(struct UnkRecordMixingStruct2 *arg0, size_t arg1, u32 arg2); static void sub_80E89F8(struct RecordMixingDayCareMail *dst); -static void sub_80E8A54(struct RecordMixingDayCareMail *src); -static void sub_80E8AC0(union BattleTowerRecord *); -void sub_80EAF80(struct SecretBaseRecord *, size_t, u8); -void sub_812287C(struct EasyChatPair *, size_t, u8); -static void nullsub_1405(union BattleTowerRecord *src); +static void SanitizeDayCareMailForRuby(struct RecordMixingDayCareMail *src); +static void SanitizeEmeraldBattleTowerRecord(struct EmeraldBattleTowerRecord *arg0); +static void SanitizeRubyBattleTowerRecord(struct RSBattleTowerRecord *src); // .rodata @@ -153,242 +181,244 @@ static const u8 gUnknown_0858CFBE[3][4] = // .text +#define BUFFER_CHUNK_SIZE 200 + void sub_80E6BE8(void) { - sub_80B37D4(sub_80E715C); + sub_80B37D4(Task_RecordMixing_Main); } -void sub_80E6BF8(void) +// these variables were const in R/S, but had to become changeable because of saveblocks changing RAM position +static void SetSrcLookupPointers(void) { - gUnknown_03001134 = gSaveBlock1Ptr->secretBases; - gUnknown_03001138 = gSaveBlock1Ptr->tvShows; - gUnknown_0300113C = gSaveBlock1Ptr->pokeNews; - gUnknown_03001140 = &gSaveBlock1Ptr->oldMan; - gUnknown_03001144 = gSaveBlock1Ptr->easyChatPairs; + sSecretBasesSave = gSaveBlock1Ptr->secretBases; + sTvShowsSave = gSaveBlock1Ptr->tvShows; + sPokeNewsSave = gSaveBlock1Ptr->pokeNews; + sOldManSave = &gSaveBlock1Ptr->oldMan; + sEasyChatPairsSave = gSaveBlock1Ptr->easyChatPairs; gUnknown_03001148 = &gUnknown_02039F9C; - gUnknown_0300114C = gSaveBlock2Ptr->field_64C; - gUnknown_03001150 = &gSaveBlock1Ptr->lilycoveLady; + sBattleTowerSave = &gSaveBlock2Ptr->battleTower; + sLilycoveLadySave = &gSaveBlock1Ptr->lilycoveLady; gUnknown_03001154 = gSaveBlock2Ptr->field_DC; - gUnknown_03001158 = gSaveBlock2Ptr->field_64C; + sBattleTowerSave_Duplicate = &gSaveBlock2Ptr->battleTower; } -void sub_80E6CA0(struct PlayerRecords *dest) +static void PrepareUnknownExchangePacket(struct PlayerRecordsRS *dest) { - memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); - memcpy(dest->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); + memcpy(dest->secretBases, sSecretBasesSave, sizeof(dest->secretBases)); + memcpy(dest->tvShows, sTvShowsSave, sizeof(dest->tvShows)); sub_80F14F8(dest->tvShows); - memcpy(dest->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); - memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); - memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); + memcpy(dest->pokeNews, sPokeNewsSave, sizeof(dest->pokeNews)); + memcpy(&dest->oldMan, sOldManSave, sizeof(dest->oldMan)); + memcpy(dest->easyChatPairs, sEasyChatPairsSave, sizeof(dest->easyChatPairs)); sub_80E89F8(&dest->dayCareMail); - sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); + sub_81659DC(sBattleTowerSave, &dest->battleTowerRecord); + if (GetMultiplayerId() == 0) - { - dest->battleTowerRecord.ruby_sapphire.unk_11c8 = GetRecordMixingGift(); - } + dest->battleTowerRecord.unk_11c8 = GetRecordMixingGift(); } -void sub_80E6D54(struct PlayerRecords *dest) +static void PrepareExchangePacketForRubySapphire(struct PlayerRecordsRS *dest) { - memcpy(dest->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); + memcpy(dest->secretBases, sSecretBasesSave, sizeof(dest->secretBases)); sub_80EB18C(dest->secretBases); - memcpy(dest->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); + memcpy(dest->tvShows, sTvShowsSave, sizeof(dest->tvShows)); sub_80F1208(dest->tvShows); - memcpy(dest->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); - memcpy(&dest->oldMan, gUnknown_03001140, sizeof(OldMan)); + memcpy(dest->pokeNews, sPokeNewsSave, sizeof(dest->pokeNews)); + memcpy(&dest->oldMan, sOldManSave, sizeof(dest->oldMan)); sub_8120B70(&dest->oldMan); - memcpy(dest->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); + memcpy(dest->easyChatPairs, sEasyChatPairsSave, sizeof(dest->easyChatPairs)); sub_80E89F8(&dest->dayCareMail); - sub_80E8A54(&dest->dayCareMail); - sub_81659DC(gUnknown_0300114C, &dest->battleTowerRecord); - nullsub_1405(&dest->battleTowerRecord); + SanitizeDayCareMailForRuby(&dest->dayCareMail); + sub_81659DC(sBattleTowerSave, &dest->battleTowerRecord); + SanitizeRubyBattleTowerRecord(&dest->battleTowerRecord); + if (GetMultiplayerId() == 0) - { - dest->battleTowerRecord.ruby_sapphire.unk_11c8 = GetRecordMixingGift(); - } + dest->battleTowerRecord.unk_11c8 = GetRecordMixingGift(); } -void sub_80E6E24(void) +static void PrepareExchangePacket(void) { sub_80E9914(); sub_80F0BB8(); - sub_80E6BF8(); + SetSrcLookupPointers(); + if (Link_AnyPartnersPlayingRubyOrSapphire()) { - if (sub_800A03C() == FALSE) - { - sub_80E6CA0(gUnknown_0203A018); - } + if (sub_800A03C() == 0) + PrepareUnknownExchangePacket(&sSentRecord->ruby); else - { - sub_80E6D54(gUnknown_0203A018); - } + PrepareExchangePacketForRubySapphire(&sSentRecord->ruby); } else { - memcpy(gUnknown_0203A018->secretBases, gUnknown_03001134, sizeof(struct SecretBaseRecord) * 20); - memcpy(gUnknown_0203A018->tvShows, gUnknown_03001138, sizeof(TVShow) * 25); - memcpy(gUnknown_0203A018->pokeNews, gUnknown_0300113C, sizeof(PokeNews) * 16); - memcpy(&gUnknown_0203A018->oldMan, gUnknown_03001140, sizeof(OldMan)); - memcpy(&gUnknown_0203A018->lilycoveLady, gUnknown_03001150, sizeof(LilycoveLady)); - memcpy(gUnknown_0203A018->easyChatPair, gUnknown_03001144, sizeof(struct EasyChatPair) * 5); - sub_80E89F8(&gUnknown_0203A018->dayCareMail); - memcpy(&gUnknown_0203A018->battleTowerRecord, gUnknown_0300114C, 0xec); - sub_80E8AC0(&gUnknown_0203A018->battleTowerRecord); + memcpy(sSentRecord->emerald.secretBases, sSecretBasesSave, sizeof(sSentRecord->emerald.secretBases)); + memcpy(sSentRecord->emerald.tvShows, sTvShowsSave, sizeof(sSentRecord->emerald.tvShows)); + memcpy(sSentRecord->emerald.pokeNews, sPokeNewsSave, sizeof(sSentRecord->emerald.pokeNews)); + memcpy(&sSentRecord->emerald.oldMan, sOldManSave, sizeof(sSentRecord->emerald.oldMan)); + memcpy(&sSentRecord->emerald.lilycoveLady, sLilycoveLadySave, sizeof(sSentRecord->emerald.lilycoveLady)); + memcpy(sSentRecord->emerald.easyChatPairs, sEasyChatPairsSave, sizeof(sSentRecord->emerald.easyChatPairs)); + sub_80E89F8(&sSentRecord->emerald.dayCareMail); + memcpy(&sSentRecord->emerald.battleTowerRecord, sBattleTowerSave, sizeof(sSentRecord->emerald.battleTowerRecord)); + SanitizeEmeraldBattleTowerRecord(&sSentRecord->emerald.battleTowerRecord); + if (GetMultiplayerId() == 0) - { - gUnknown_0203A018->unk_1210 = GetRecordMixingGift(); - } - sub_80E8110(gUnknown_0203A018->unk_1254, gUnknown_03001154); - sub_80E8260(&gUnknown_0203A018->unk_12dc); + sSentRecord->emerald.unk_1210 = GetRecordMixingGift(); + + sub_80E8110(sSentRecord->emerald.unk_1254, gUnknown_03001154); + sub_80E8260(&sSentRecord->emerald.unk_12dc); } } -void sub_80E6F60(u32 which) +static void ReceiveExchangePacket(u32 which) { if (Link_AnyPartnersPlayingRubyOrSapphire()) { // Ruby/Sapphire - sub_80E7B2C((void *)gUnknown_0203A014[0].tvShows); - sub_80EAF80(gUnknown_0203A014[0].secretBases, sizeof(struct PlayerRecordsRS), which); - sub_80E7B60(&gUnknown_0203A014[0].dayCareMail, sizeof(struct PlayerRecordsRS), which, gUnknown_0203A014[0].tvShows); - sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, sizeof(struct PlayerRecordsRS), which); - sub_80F01E8(gUnknown_0203A014[0].tvShows, sizeof(struct PlayerRecordsRS), which); - sub_80F0C7C(gUnknown_0203A014[0].pokeNews, sizeof(struct PlayerRecordsRS), which); - sub_80E78C4(&gUnknown_0203A014[0].oldMan, sizeof(struct PlayerRecordsRS), which); - sub_812287C(gUnknown_0203A014[0].easyChatPair, sizeof(struct PlayerRecordsRS), which); - sub_80E7F68(&gUnknown_0203A014[0].battleTowerRecord.ruby_sapphire.unk_11c8, which); + sub_80E7B2C((void *)sReceivedRecords->ruby.tvShows); + ReceiveSecretBasesData(sReceivedRecords->ruby.secretBases, sizeof(struct PlayerRecordsRS), which); + ReceiveDaycareMailData(&sReceivedRecords->ruby.dayCareMail, sizeof(struct PlayerRecordsRS), which, sReceivedRecords->ruby.tvShows); + ReceiveBattleTowerData(&sReceivedRecords->ruby.battleTowerRecord, sizeof(struct PlayerRecordsRS), which); + ReceiveTvShowsData(sReceivedRecords->ruby.tvShows, sizeof(struct PlayerRecordsRS), which); + ReceivePokeNewsData(sReceivedRecords->ruby.pokeNews, sizeof(struct PlayerRecordsRS), which); + ReceiveOldManData(&sReceivedRecords->ruby.oldMan, sizeof(struct PlayerRecordsRS), which); + ReceiveEasyChatPairsData(sReceivedRecords->ruby.easyChatPairs, sizeof(struct PlayerRecordsRS), which); + sub_80E7F68(&sReceivedRecords->ruby.battleTowerRecord.unk_11c8, which); } else { // Emerald - sub_80E7B2C((void *)gUnknown_0203A014[0].tvShows); - sub_80EAF80(gUnknown_0203A014[0].secretBases, sizeof(struct PlayerRecords), which); - sub_80F01E8(gUnknown_0203A014[0].tvShows, sizeof(struct PlayerRecords), which); - sub_80F0C7C(gUnknown_0203A014[0].pokeNews, sizeof(struct PlayerRecords), which); - sub_80E78C4(&gUnknown_0203A014[0].oldMan, sizeof(struct PlayerRecords), which); - sub_812287C(gUnknown_0203A014[0].easyChatPair, sizeof(struct PlayerRecords), which); - sub_80E7B60(&gUnknown_0203A014[0].dayCareMail, sizeof(struct PlayerRecords), which, gUnknown_0203A014[0].tvShows); - sub_80E7948(&gUnknown_0203A014[0].battleTowerRecord, sizeof(struct PlayerRecords), which); - sub_80E7F68(&gUnknown_0203A014[0].unk_1210, which); - sub_80E7A14(&gUnknown_0203A014[0].lilycoveLady, sizeof(struct PlayerRecords), which); - sub_80E8468(gUnknown_0203A014[0].unk_1254, sizeof(struct PlayerRecords), (u8) which); - sub_80E89AC(&gUnknown_0203A014[0].unk_12dc, sizeof(struct PlayerRecords), (u8) which); + sub_80E7B2C((void *)sReceivedRecords->emerald.tvShows); + ReceiveSecretBasesData(sReceivedRecords->emerald.secretBases, sizeof(struct PlayerRecordsEmerald), which); + ReceiveTvShowsData(sReceivedRecords->emerald.tvShows, sizeof(struct PlayerRecordsEmerald), which); + ReceivePokeNewsData(sReceivedRecords->emerald.pokeNews, sizeof(struct PlayerRecordsEmerald), which); + ReceiveOldManData(&sReceivedRecords->emerald.oldMan, sizeof(struct PlayerRecordsEmerald), which); + ReceiveEasyChatPairsData(sReceivedRecords->emerald.easyChatPairs, sizeof(struct PlayerRecordsEmerald), which); + ReceiveDaycareMailData(&sReceivedRecords->emerald.dayCareMail, sizeof(struct PlayerRecordsEmerald), which, sReceivedRecords->emerald.tvShows); + ReceiveBattleTowerData(&sReceivedRecords->emerald.battleTowerRecord, sizeof(struct PlayerRecordsEmerald), which); + sub_80E7F68(&sReceivedRecords->emerald.unk_1210, which); + ReceiveLilycoveLadyData(&sReceivedRecords->emerald.lilycoveLady, sizeof(struct PlayerRecordsEmerald), which); + sub_80E8468(sReceivedRecords->emerald.unk_1254, sizeof(struct PlayerRecordsEmerald), (u8) which); + sub_80E89AC(&sReceivedRecords->emerald.unk_12dc, sizeof(struct PlayerRecordsEmerald), (u8) which); } } -void sub_80E70F4(const u8 *src) +static void PrintTextOnRecordMixing(const u8 *src) { NewMenuHelpers_DrawDialogueFrame(0, 0); PrintTextOnWindow(0, 1, src, 0, 1, 0, NULL); CopyWindowToVram(0, 3); } -void sub_80E7128(u8 taskId) +#define tCounter data[0] + +static void Task_RecordMixing_SoundEffect(u8 taskId) { - if (++ gTasks[taskId].data[0] == 50) + if (++gTasks[taskId].tCounter == 50) { PlaySE(SE_W213); - gTasks[taskId].data[0] = 0; + gTasks[taskId].tCounter = 0; } } -static void sub_80E715C(u8 taskId) +#undef tCounter + +#define tState data[0] +#define tSndEffTaskId data[15] + +static void Task_RecordMixing_Main(u8 taskId) { - s16 *data; + s16 *data = gTasks[taskId].data; - data = gTasks[taskId].data; - switch (data[0]) + switch (tState) { - case 0: - gUnknown_0203A018 = malloc(sizeof(struct PlayerRecords)); - gUnknown_0203A014 = malloc(sizeof(struct PlayerRecords) * 4); - sub_8009628(gSpecialVar_0x8005); - VarSet(VAR_TEMP_0, 1); - gUnknown_03001130 = FALSE; - sub_80E6E24(); - sub_80FB00C(); - data[0] = 1; - data[10] = CreateTask(sub_80E7324, 80); - data[15] = CreateTask(sub_80E7128, 81); - break; - case 1: - if (!gTasks[data[10]].isActive) + case 0: // init + sSentRecord = malloc(sizeof(union PlayerRecords)); + sReceivedRecords = malloc(sizeof(union PlayerRecords) * 4); + sub_8009628(gSpecialVar_0x8005); + VarSet(VAR_TEMP_0, 1); + gUnknown_03001130 = FALSE; + PrepareExchangePacket(); + CreateRecordMixingSprite(); + tState = 1; + data[10] = CreateTask(sub_80E7324, 80); + tSndEffTaskId = CreateTask(Task_RecordMixing_SoundEffect, 81); + break; + case 1: // wait for sub_80E7324 + if (!gTasks[data[10]].isActive) + { + tState = 2; + FlagSet(FLAG_SYS_MIX_RECORD); + DestroyRecordMixingSprite(); + DestroyTask(tSndEffTaskId); + } + break; + case 2: + data[10] = CreateTask(sub_80E7FF8, 10); + tState = 3; + PlaySE(SE_W226); + break; + case 3: // wait for sub_80E7FF8 + if (!gTasks[data[10]].isActive) + { + tState = 4; + if (gWirelessCommType == 0) + data[10] = sub_80B3050(); + + PrintTextOnRecordMixing(gText_RecordMixingComplete); + data[8] = 0; + } + break; + case 4: // wait 60 frames + if (++data[8] > 60) + tState = 5; + break; + case 5: + if (!gTasks[data[10]].isActive) + { + free(sReceivedRecords); + free(sSentRecord); + sub_808729C(); + if (gWirelessCommType != 0) { - data[0] = 2; - FlagSet(FLAG_SYS_MIX_RECORD); - sub_80FB074(); - DestroyTask(data[15]); + CreateTask(sub_80AF2B4, 10); } - break; - case 2: - data[10] = CreateTask(sub_80E7FF8, 10); - data[0] = 3; - PlaySE(SE_W226); - break; - case 3: - if (!gTasks[data[10]].isActive) - { - data[0] = 4; - if (gWirelessCommType == 0) - { - data[10] = sub_80B3050(); - } - sub_80E70F4(gText_RecordMixingComplete); - data[8] = 0; - } - break; - case 4: - if (++ data[8] > 60) - { - data[0] = 5; - } - break; - case 5: - if (!gTasks[data[10]].isActive) - { - free(gUnknown_0203A014); - free(gUnknown_0203A018); - sub_808729C(); - if (gWirelessCommType != 0) - { - CreateTask(sub_80AF2B4, 10); - } - sub_8197434(0, 1); - DestroyTask(taskId); - EnableBothScriptContexts(); - } - break; + sub_8197434(0, 1); + DestroyTask(taskId); + EnableBothScriptContexts(); + } + break; } } +#undef tState +#undef tSndEffTaskId + static void sub_80E7324(u8 taskId) { - u8 r4; - u8 taskId2; - struct Task *task; + struct Task *task = &gTasks[taskId]; - task = &gTasks[taskId]; switch (task->data[0]) { - case 0: - sub_80E70F4(gText_MixingRecords); - task->data[8] = 0x708; - task->data[0] = 400; - ClearLinkCallback_2(); - break; - case 100: - if (++ task->data[12] > 20) - { - task->data[12] = 0; - task->data[0] = 101; - } - break; - case 101: - r4 = GetLinkPlayerCount_2(); + case 0: + PrintTextOnRecordMixing(gText_MixingRecords); + task->data[8] = 0x708; + task->data[0] = 400; + ClearLinkCallback_2(); + break; + case 100: // wait 20 frames + if (++task->data[12] > 20) + { + task->data[12] = 0; + task->data[0] = 101; + } + break; + case 101: + { + u8 players = GetLinkPlayerCount_2(); if (IsLinkMaster() == TRUE) { - if (r4 == sub_800AA48()) + if (players == sub_800AA48()) { PlaySE(SE_PIN); task->data[0] = 201; @@ -400,272 +430,248 @@ static void sub_80E7324(u8 taskId) PlaySE(SE_BOO); task->data[0] = 301; } - break; - case 201: - if (sub_800AA48() == GetLinkPlayerCount_2() && ++ task->data[12] > (GetLinkPlayerCount_2() * 30)) - { - sub_800A620(); - task->data[0] = 1; - } - break; - case 301: - if (sub_800AA48() == GetLinkPlayerCount_2()) - { - task->data[0] = 1; - } - break; - case 400: - if (++ task->data[12] > 20) - { - task->data[0] = 1; - task->data[12] = 0; - } - break; - case 1: - if (gReceivedRemoteLinkPlayers != 0) - { - ConvertIntToDecimalStringN(gStringVar1, sub_80E7810(), STR_CONV_MODE_LEADING_ZEROS, 2); - task->data[0] = 5; - } - break; - case 2: + } + break; + case 201: + if (sub_800AA48() == GetLinkPlayerCount_2() && ++task->data[12] > (GetLinkPlayerCount_2() * 30)) + { + sub_800A620(); + task->data[0] = 1; + } + break; + case 301: + if (sub_800AA48() == GetLinkPlayerCount_2()) + task->data[0] = 1; + break; + case 400: // wait 20 frames + if (++task->data[12] > 20) + { + task->data[0] = 1; + task->data[12] = 0; + } + break; + case 1: // wait for handshake + if (gReceivedRemoteLinkPlayers != 0) + { + ConvertIntToDecimalStringN(gStringVar1, GetMultiplayerId_(), STR_CONV_MODE_LEADING_ZEROS, 2); + task->data[0] = 5; + } + break; + case 2: + { + u8 subTaskId; + task->data[6] = GetLinkPlayerCount_2(); task->data[0] = 0; - task->data[5] = sub_80E7810(); - task->func = sub_80E756C; + task->data[5] = GetMultiplayerId_(); + task->func = Task_SendPacket; if (Link_AnyPartnersPlayingRubyOrSapphire()) { - sub_80E7808(gUnknown_0203A018, (u16 *)&task->data[2]); - taskId2 = CreateTask(sub_80E7630, 80); - task->data[10] = taskId2; - gTasks[taskId2].data[0] = taskId; - sub_80E7808(gUnknown_0203A014, (u16 *)&gTasks[taskId2].data[5]); - gUnknown_0300115C = sizeof(struct PlayerRecordsRS); + StorePtrInTaskData(sSentRecord, (u16 *)&task->data[2]); + subTaskId = CreateTask(Task_CopyReceiveBuffer, 80); + task->data[10] = subTaskId; + gTasks[subTaskId].data[0] = taskId; + StorePtrInTaskData(sReceivedRecords, (u16 *)&gTasks[subTaskId].data[5]); + sRecordStructSize = sizeof(struct PlayerRecordsRS); } else { - sub_80E7808(gUnknown_0203A018, (u16 *)&task->data[2]); - taskId2 = CreateTask(sub_80E7630, 80); - task->data[10] = taskId2; - gTasks[taskId2].data[0] = taskId; - sub_80E7808(gUnknown_0203A014, (u16 *)&gTasks[taskId2].data[5]); - gUnknown_0300115C = sizeof(struct PlayerRecords); - } - break; - case 5: - if (++ task->data[10] > 60) - { - task->data[10] = 0; - task->data[0] = 2; - } - break; - } -} - -static void sub_80E756C(u8 taskId) -{ - struct Task *task; - void *dest; - - task = &gTasks[taskId]; - switch (task->data[0]) - { - case 0: - dest = sub_80E77FC(&task->data[2]) + task->data[4] * 200; - memcpy(gBlockSendBuffer, dest, 200); - task->data[0] ++; - break; - case 1: - if (GetMultiplayerId() == 0) - { - sub_800A4D8(1); - } - task->data[0] ++; - break; - case 2: - break; - case 3: - task->data[4] ++; - if (task->data[4] == gUnknown_0300115C / 200 + 1) - { - task->data[0] ++; - } - else - { - task->data[0] = 0; - } - break; - case 4: - if (!gTasks[task->data[10]].isActive) - { - task->func = sub_80E77D4; - } - break; - } -} - -static void sub_80E7630(u8 taskId) -{ - struct Task *task; - u8 status; - u8 counter; - u8 i; - void *dest; - void *src; - - task = &gTasks[taskId]; - status = GetBlockReceivedStatus(); - counter = 0; - if (status == sub_800A9D8()) - { - for (i = 0; i < GetLinkPlayerCount(); i ++) - { - if ((status >> i) & 0x01) - { - dest = sub_80E77FC((u16 *)&task->data[5]) + task->data[i + 1] * 200 + gUnknown_0300115C * i; - src = sub_80E7820(i); - if ((task->data[i + 1] + 1) * 200 > gUnknown_0300115C) - { - memcpy(dest, src, gUnknown_0300115C - task->data[i + 1] * 200); - } - else - { - memcpy(dest, src, 200); - } - ResetBlockReceivedFlag(i); - task->data[i + 1] ++; - if (task->data[i + 1] == gUnknown_0300115C / 200 + 1) - { - counter ++; - } + StorePtrInTaskData(sSentRecord, (u16 *)&task->data[2]); + subTaskId = CreateTask(Task_CopyReceiveBuffer, 80); + task->data[10] = subTaskId; + gTasks[subTaskId].data[0] = taskId; + StorePtrInTaskData(sReceivedRecords, (u16 *)&gTasks[subTaskId].data[5]); + sRecordStructSize = sizeof(struct PlayerRecordsEmerald); } } - gTasks[task->data[0]].data[0] ++; + break; + case 5: // wait 60 frames + if (++task->data[10] > 60) + { + task->data[10] = 0; + task->data[0] = 2; + } + break; } - if (counter == GetLinkPlayerCount()) +} + +static void Task_SendPacket(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + // does this send the data 24 times? + + switch (task->data[0]) { - DestroyTask(taskId); + case 0: // Copy record data to send buffer + { + void *recordData = LoadPtrFromTaskData(&task->data[2]) + task->data[4] * BUFFER_CHUNK_SIZE; + + memcpy(gBlockSendBuffer, recordData, BUFFER_CHUNK_SIZE); + task->data[0]++; + } + break; + case 1: + if (GetMultiplayerId() == 0) + sub_800A4D8(1); + task->data[0]++; + break; + case 2: + break; + case 3: + task->data[4]++; + if (task->data[4] == sRecordStructSize / 200 + 1) + task->data[0]++; + else + task->data[0] = 0; + break; + case 4: + if (!gTasks[task->data[10]].isActive) + task->func = Task_SendPacket_SwitchToReceive; + break; } } +static void Task_CopyReceiveBuffer(u8 taskId) +{ + struct Task *task = &gTasks[taskId]; + u8 status = GetBlockReceivedStatus(); + u8 handledPlayers = 0; + + if (status == sub_800A9D8()) + { + u8 i; + + for (i = 0; i < GetLinkPlayerCount(); i++) + { + void *dest; + void *src; + + if ((status >> i) & 1) + { + dest = LoadPtrFromTaskData((u16 *)&task->data[5]) + task->data[i + 1] * BUFFER_CHUNK_SIZE + sRecordStructSize * i; + src = GetPlayerRecvBuffer(i); + if ((task->data[i + 1] + 1) * BUFFER_CHUNK_SIZE > sRecordStructSize) + memcpy(dest, src, sRecordStructSize - task->data[i + 1] * BUFFER_CHUNK_SIZE); + else + memcpy(dest, src, BUFFER_CHUNK_SIZE); + ResetBlockReceivedFlag(i); + task->data[i + 1]++; + if (task->data[i + 1] == sRecordStructSize / BUFFER_CHUNK_SIZE + 1) + handledPlayers++; + } + } + gTasks[task->data[0]].data[0]++; + } + + if (handledPlayers == GetLinkPlayerCount()) + DestroyTask(taskId); +} + static void sub_80E776C(u8 taskId) { - struct Task *task; + struct Task *task = &gTasks[taskId]; - task = &gTasks[taskId]; if (!gTasks[task->data[10]].isActive) - { DestroyTask(taskId); - } } -static void sub_80E77A0(u8 taskId) +static void Task_ReceivePacket(u8 taskId) { - struct Task *task; + struct Task *task = &gTasks[taskId]; - task = &gTasks[taskId]; task->func = sub_80E776C; if (gUnknown_03001130 == TRUE) - { - sub_80E6F60(task->data[5]); - } + ReceiveExchangePacket(task->data[5]); } -static void sub_80E77D4(u8 taskId) +static void Task_SendPacket_SwitchToReceive(u8 taskId) { - gTasks[taskId].func = sub_80E77A0; + gTasks[taskId].func = Task_ReceivePacket; gUnknown_03001130 = TRUE; } -static void *sub_80E77FC(const u16 *asShort) +static void *LoadPtrFromTaskData(const u16 *asShort) { return (void *)(asShort[0] | (asShort[1] << 16)); } -static void sub_80E7808(void *records, u16 *asShort) +static void StorePtrInTaskData(void *records, u16 *asShort) { asShort[0] = (u32)records; asShort[1] = ((u32)records >> 16); } -static u8 sub_80E7810(void) +static u8 GetMultiplayerId_(void) { return GetMultiplayerId(); } -static void *sub_80E7820(u8 id) +static void *GetPlayerRecvBuffer(u8 id) { return gBlockRecvBuffer[id]; } -void sub_80E7830(u32 *data) +static void ShufflePlayerIndices(u32 *data) { u32 i; u32 linkTrainerId; + u32 players = GetLinkPlayerCount(); - switch ((u32)GetLinkPlayerCount()) + switch (players) { - case 2: - for (i = 0; i < 2; i ++) - { - data[i] = gUnknown_0858CF8C[i]; - } - break; - case 3: - linkTrainerId = GetLinkPlayerTrainerId(0) % 2; - for (i = 0; i < 3; i ++) - { - data[i] = gUnknown_0858CF8E[linkTrainerId][i]; - } - break; - case 4: - linkTrainerId = GetLinkPlayerTrainerId(0) % 9; - for (i = 0; i < 4; i ++) - { - data[i] = gUnknown_0858CF94[linkTrainerId][i]; - } - break; + case 2: + for (i = 0; i < 2; i++) + data[i] = gUnknown_0858CF8C[i]; + break; + case 3: + linkTrainerId = GetLinkPlayerTrainerId(0) % 2; + for (i = 0; i < 3; i++) + data[i] = gUnknown_0858CF8E[linkTrainerId][i]; + break; + case 4: + linkTrainerId = GetLinkPlayerTrainerId(0) % 9; + for (i = 0; i < 4; i++) + data[i] = gUnknown_0858CF94[linkTrainerId][i]; + break; } } -static void sub_80E78C4(OldMan *oldMan, size_t recordSize, u8 which) +static void ReceiveOldManData(OldMan *oldMan, size_t recordSize, u8 which) { u8 version; u16 language; OldMan *dest; u32 mixIndices[4]; - sub_80E7830(mixIndices); + ShufflePlayerIndices(mixIndices); dest = (void *)oldMan + recordSize * mixIndices[which]; version = gLinkPlayers[mixIndices[which]].version; language = gLinkPlayers[mixIndices[which]].language; + if (Link_AnyPartnersPlayingRubyOrSapphire()) - { - sub_8120D34(dest, version, language); - } + SanitizeReceivedRubyOldMan(dest, version, language); else - { - sub_8120CD0(dest, version, language); - } - memcpy(gUnknown_03001140, (void *)oldMan + recordSize * mixIndices[which], sizeof(OldMan)); + SanitizeReceivedEmeraldOldMan(dest, version, language); + + memcpy(sOldManSave, (void *)oldMan + recordSize * mixIndices[which], sizeof(OldMan)); ResetMauvilleOldManFlag(); } -static void sub_80E7948(union BattleTowerRecord *battleTowerRecord, size_t recordSize, u8 which) +static void ReceiveBattleTowerData(void *battleTowerRecord, size_t recordSize, u8 which) { - union BattleTowerRecord *dest; + struct EmeraldBattleTowerRecord *dest; struct UnknownPokemonStruct *btPokemon; u32 mixIndices[4]; s32 i; - sub_80E7830(mixIndices); + ShufflePlayerIndices(mixIndices); if (Link_AnyPartnersPlayingRubyOrSapphire()) { if (sub_816587C((void *)battleTowerRecord + recordSize * mixIndices[which], (void *)battleTowerRecord + recordSize * which) == TRUE) { dest = (void *)battleTowerRecord + recordSize * which; - dest->emerald.language = gLinkPlayers[mixIndices[which]].language; - sub_8164F70(dest); + dest->language = gLinkPlayers[mixIndices[which]].language; + CalcEmeraldBattleTowerChecksum(dest); } } else @@ -674,38 +680,37 @@ static void sub_80E7948(union BattleTowerRecord *battleTowerRecord, size_t recor dest = (void *)battleTowerRecord + recordSize * which; for (i = 0; i < 4; i ++) { - btPokemon = &dest->emerald.party[i]; + btPokemon = &dest->party[i]; if (btPokemon->species != SPECIES_NONE && IsStringJapanese(btPokemon->nickname)) - { ConvertInternationalString(btPokemon->nickname, LANGUAGE_JAPANESE); - } } - sub_8164F70(dest); + CalcEmeraldBattleTowerChecksum(dest); } sub_81628A0((void *)battleTowerRecord + recordSize * which); } -static void sub_80E7A14(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) +static void ReceiveLilycoveLadyData(LilycoveLady *lilycoveLady, size_t recordSize, u8 which) { LilycoveLady *dest; u32 mixIndices[4]; - sub_80E7830(mixIndices); - memcpy((void *)lilycoveLady + recordSize * which, gUnknown_03001150, sizeof(LilycoveLady)); + ShufflePlayerIndices(mixIndices); + memcpy((void *)lilycoveLady + recordSize * which, sLilycoveLadySave, sizeof(LilycoveLady)); + if (GetLilycoveLadyId() == 0) { dest = malloc(sizeof(LilycoveLady)); if (dest == NULL) - { return; - } - memcpy(dest, gUnknown_03001150, sizeof(LilycoveLady)); + + memcpy(dest, sLilycoveLadySave, sizeof(LilycoveLady)); } else { dest = NULL; } - memcpy(gUnknown_03001150, (void *)lilycoveLady + recordSize * mixIndices[which], sizeof(LilycoveLady)); + + memcpy(sLilycoveLadySave, (void *)lilycoveLady + recordSize * mixIndices[which], sizeof(LilycoveLady)); sub_818DA78(); if (dest != NULL) { @@ -735,13 +740,12 @@ static void sub_80E7AA4(struct RecordMixingDayCareMail *src, size_t recordSize, static void sub_80E7B2C(const u8 *src) { u8 sum; - int i; + s32 i; sum = 0; for (i = 0; i < 256; i ++) - { sum += src[i]; - } + gUnknown_03001160 = sum; } @@ -751,7 +755,7 @@ static u8 sub_80E7B54(void) } #ifdef NONMATCHING -static void sub_80E7B60(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) +static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) { // r9 = which u16 i; @@ -929,7 +933,8 @@ static void sub_80E7B60(struct RecordMixingDayCareMail *src, size_t recordSize, SeedRng(oldSeed); } #else -__attribute__((naked)) static void sub_80E7B60(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) +NAKED +static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t recordSize, u8 which, TVShow *shows) { asm_unified("\tpush {r4-r7,lr}\n" "\tmov r7, r10\n" @@ -1464,9 +1469,7 @@ static void sub_80E7F68(u16 *item, u8 which) VarSet(VAR_TEMP_1, *item); StringCopy(gStringVar1, gLinkPlayers[0].name); if (*item == ITEM_EON_TICKET) - { FlagSet(FLAG_SYS_HAS_EON_TICKET); - } } else { @@ -1477,84 +1480,77 @@ static void sub_80E7F68(u16 *item, u8 which) static void sub_80E7FF8(u8 taskId) { - struct Task *task; + struct Task *task = &gTasks[taskId]; - task = &gTasks[taskId]; switch (task->data[0]) { - case 0: + case 0: + task->data[0]++; + break; + case 1: + if (Link_AnyPartnersPlayingRubyOrSapphire()) + task->data[0]++; + else + task->data[0] = 6; + break; + case 2: + sub_8076D5C(); + sub_8153430(); + task->data[0] ++; + break; + case 3: + if (sub_8153474()) + { + sav2_gender2_inplace_and_xFE(); + task->data[0] = 4; + task->data[1] = 0; + } + break; + case 4: + if (++task->data[1] > 10) + { + sub_800AC34(); task->data[0] ++; - break; - case 1: - if (Link_AnyPartnersPlayingRubyOrSapphire()) + } + break; + case 5: + if (gReceivedRemoteLinkPlayers == 0) + DestroyTask(taskId); + break; + case 6: + if (!sub_801048C(0)) + { + CreateTask(sub_8153688, 5); + task->data[0] ++; + } + break; + case 7: + if (!FuncIsActiveTask(sub_8153688)) + { + if (gWirelessCommType) { - task->data[0] ++; + sub_801048C(1); + task->data[0] = 8; } else { - task->data[0] = 6; - } - break; - case 2: - sub_8076D5C(); - sub_8153430(); - task->data[0] ++; - break; - case 3: - if (sub_8153474()) - { - sav2_gender2_inplace_and_xFE(); task->data[0] = 4; - task->data[1] = 0; } - break; - case 4: - if (++ task->data[1] > 10) - { - sub_800AC34(); - task->data[0] ++; - } - break; - case 5: - if (gReceivedRemoteLinkPlayers == 0) - { - DestroyTask(taskId); - } - break; - case 6: - if (!sub_801048C(0)) - { - CreateTask(sub_8153688, 5); - task->data[0] ++; - } - break; - case 7: - if (!FuncIsActiveTask(sub_8153688)) - { - if (gWirelessCommType) - { - sub_801048C(1); - task->data[0] = 8; - } - else - { - task->data[0] = 4; - } - } - break; - case 8: - sub_800ADF8(); - task->data[0] ++; - break; - case 9: - if (sub_800A520()) - { - DestroyTask(taskId); - } - break; + } + break; + case 8: + sub_800ADF8(); + task->data[0] ++; + break; + case 9: + if (sub_800A520()) + DestroyTask(taskId); + break; } } +// New Emerald functions + static void sub_80E8110(struct UnkRecordMixingStruct *dst, struct UnkRecordMixingStruct *src) { s32 i, id; @@ -1650,7 +1646,7 @@ void sub_80E8260(struct UnkRecordMixingStruct2 *dst) } } -bool32 sub_80E841C(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1) +static bool32 sub_80E841C(struct UnkRecordMixingStruct *arg0, struct UnkRecordMixingStruct *arg1) { s32 i; @@ -1670,11 +1666,11 @@ static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg { s32 i, r7, r8; struct UnkRecordMixingStruct *structPtr; - u32 data[4]; + u32 mixIndices[4]; u32 structId; - sub_80E7830(data); - structPtr = (void*)(arg0) + (arg1 * data[arg2]); + ShufflePlayerIndices(mixIndices); + structPtr = (void*)(arg0) + (arg1 * mixIndices[arg2]); r7 = 0; r8 = 0; for (i = 0; i < 2; i++) @@ -1704,29 +1700,8 @@ static void sub_80E8468(struct UnkRecordMixingStruct *arg0, size_t arg1, u32 arg } } -struct UnknownRecMixingStruct -{ - u32 field_0; - u16 field_4; - u8 field_6[9]; -}; - -struct UnknownRecMixingStruct2 -{ - u32 field_0; - u16 field_4; - u16 field_6; - u16 field_8; - u8 field_A[16]; -}; - -struct UnknownRecMixingStruct3 -{ - u8 field_0[0x810]; -}; - NAKED -void sub_80E8578(struct UnknownRecMixingStruct3 *arg0, struct UnkRecordMixingStruct2 *arg1, size_t arg2, u32 arg3, u32 arg4) +static void sub_80E8578(struct UnknownRecMixingStruct3 *arg0, struct UnkRecordMixingStruct2 *arg1, size_t arg2, u32 arg3, u32 arg4) { asm_unified(" push {r4-r7,lr}\n\ mov r7, r10\n\ @@ -2130,7 +2105,7 @@ _080E8864:\n\ "); } -void sub_80E8880(struct UnknownRecMixingStruct *arg0, struct UnknownRecMixingStruct *arg1) +static void sub_80E8880(struct UnknownRecMixingStruct *arg0, struct UnknownRecMixingStruct *arg1) { s32 i, j; @@ -2155,7 +2130,7 @@ void sub_80E8880(struct UnknownRecMixingStruct *arg0, struct UnknownRecMixingStr } } -void sub_80E88CC(struct UnknownRecMixingStruct2 *arg0, struct UnknownRecMixingStruct2 *arg1) +static void sub_80E88CC(struct UnknownRecMixingStruct2 *arg0, struct UnknownRecMixingStruct2 *arg1) { s32 i, j; @@ -2181,7 +2156,7 @@ void sub_80E88CC(struct UnknownRecMixingStruct2 *arg0, struct UnknownRecMixingSt } NAKED -void sub_80E8924(struct UnknownRecMixingStruct3 *arg0) +static void sub_80E8924(struct UnknownRecMixingStruct3 *arg0) { asm_unified("push {r4-r7,lr}\n\ mov r7, r10\n\ @@ -2270,7 +2245,7 @@ static void sub_80E89F8(struct RecordMixingDayCareMail *dst) *dst = *gUnknown_03001148; } -static void sub_80E8A54(struct RecordMixingDayCareMail *src) +static void SanitizeDayCareMailForRuby(struct RecordMixingDayCareMail *src) { s32 i; @@ -2287,21 +2262,21 @@ static void sub_80E8A54(struct RecordMixingDayCareMail *src) } } -static void nullsub_1405(union BattleTowerRecord *src) +static void SanitizeRubyBattleTowerRecord(struct RSBattleTowerRecord *src) { } -static void sub_80E8AC0(union BattleTowerRecord *arg0) +static void SanitizeEmeraldBattleTowerRecord(struct EmeraldBattleTowerRecord *dst) { s32 i; for (i = 0; i < 4; i++) { - struct UnknownPokemonStruct *towerMon = &arg0->emerald.party[i]; + struct UnknownPokemonStruct *towerMon = &dst->party[i]; if (towerMon->species != 0) StripExtCtrlCodes(towerMon->nickname); } - sub_8164F70(arg0); + CalcEmeraldBattleTowerChecksum(dst); } diff --git a/src/secret_base.c b/src/secret_base.c index d86b99345..44e980c43 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -1673,7 +1673,7 @@ void sub_80EAEF4(struct SecretBaseRecordMixer *mixers) sub_80EABA4(&mixers[2], 0); } -void sub_80EAF80(void *records, size_t recordSize, u8 linkIdx) +void ReceiveSecretBasesData(void *records, size_t recordSize, u8 linkIdx) { struct SecretBaseRecordMixer mixers[3]; u16 i; diff --git a/src/tv.c b/src/tv.c index 77b7d4a75..e69f6f411 100644 --- a/src/tv.c +++ b/src/tv.c @@ -3606,7 +3606,7 @@ void sub_80F01B8(void) FlagSet(0x396); } -void sub_80F01E8(void *src, u32 size, u8 masterIdx) +void ReceiveTvShowsData(void *src, u32 size, u8 masterIdx) { u8 i; u16 version; @@ -4434,7 +4434,7 @@ static void sub_80F0C04(void) } } -void sub_80F0C7C(void *src, u32 size, u8 masterIdx) +void ReceivePokeNewsData(void *src, u32 size, u8 masterIdx) { u8 i; PokeNews (*rmBuffer2)[4][16]; From dd1c7c741a0f6931915ed620bce71127a593ef5a Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sat, 26 May 2018 00:37:03 +0200 Subject: [PATCH 25/26] make record mixing compile --- src/egg_hatch.c | 10 +++++----- src/new_game.c | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/egg_hatch.c b/src/egg_hatch.c index 8914d6ff3..1ed38c67e 100644 --- a/src/egg_hatch.c +++ b/src/egg_hatch.c @@ -390,13 +390,13 @@ static bool8 sub_807158C(struct DayCare *daycare, u8 daycareId) struct DaycareMon *daycareMon = &daycare->mons[daycareId]; GetBoxMonNick(&daycareMon->mon, nick); - if (daycareMon->misc.mail.itemId != 0 - && (StringCompareWithoutExtCtrlCodes(nick, daycareMon->misc.monName) != 0 - || StringCompareWithoutExtCtrlCodes(gSaveBlock2Ptr->playerName, daycareMon->misc.OT_name) != 0)) + if (daycareMon->mail.message.itemId != 0 + && (StringCompareWithoutExtCtrlCodes(nick, daycareMon->mail.monName) != 0 + || StringCompareWithoutExtCtrlCodes(gSaveBlock2Ptr->playerName, daycareMon->mail.OT_name) != 0)) { StringCopy(gStringVar1, nick); - TVShowConvertInternationalString(gStringVar2, daycareMon->misc.OT_name, daycareMon->misc.gameLanguage); - TVShowConvertInternationalString(gStringVar3, daycareMon->misc.monName, daycareMon->misc.monLanguage); + TVShowConvertInternationalString(gStringVar2, daycareMon->mail.OT_name, daycareMon->mail.gameLanguage); + TVShowConvertInternationalString(gStringVar3, daycareMon->mail.monName, daycareMon->mail.monLanguage); return TRUE; } return FALSE; diff --git a/src/new_game.c b/src/new_game.c index 37336016e..c387bce65 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -119,11 +119,10 @@ void ClearAllContestWinnerPics(void) void sub_8084400(void) { // probably clearing one struct for battle frontier - CpuFill32(0, gSaveBlock2Ptr->field_64C, 2272); + CpuFill32(0, &gSaveBlock2Ptr->battleTower, 2272); - // those look like strings - gSaveBlock2Ptr->field_EE1 = 0xFF; - gSaveBlock2Ptr->field_EE9 = 0xFF; + gSaveBlock2Ptr->field_EE1[0][0] = EOS; + gSaveBlock2Ptr->field_EE1[1][0] = EOS; } void WarpToTruck(void) From 42731e4b88115bada3aed8ebc3b2c3dabecbb020 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Wed, 30 May 2018 20:28:31 +0200 Subject: [PATCH 26/26] LANG_ENG to GAME_LANGUAGE --- src/record_mixing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/record_mixing.c b/src/record_mixing.c index 19a8b0889..35e518d8a 100644 --- a/src/record_mixing.c +++ b/src/record_mixing.c @@ -1616,14 +1616,14 @@ void sub_80E8260(struct UnkRecordMixingStruct2 *dst) for (j = 0; j < 2; j++) { CopyUnalignedWord(dst->field_0[i][j].playerId, gSaveBlock2Ptr->playerTrainerId); - dst->field_0[i][j].language = LANGUAGE_ENGLISH; + dst->field_0[i][j].language = GAME_LANGUAGE; StringCopy(dst->field_0[i][j].playerName, gSaveBlock2Ptr->playerName); } } for (j = 0; j < 2; j++) { - dst->field_120[j].language = LANGUAGE_ENGLISH; + dst->field_120[j].language = GAME_LANGUAGE; CopyUnalignedWord(dst->field_120[j].playerId1, gSaveBlock2Ptr->playerTrainerId); CopyUnalignedWord(dst->field_120[j].playerId2, gSaveBlock2Ptr->field_EF1[j]); StringCopy(dst->field_120[j].playerName1, gSaveBlock2Ptr->playerName);