From 5efe8f3a0d0db0228fd0980c90013a4602c731b3 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Tue, 8 May 2018 19:00:23 -0400 Subject: [PATCH] through sub_80DAB8C --- asm/contest.s | 520 +------------------------------------------------ data/contest.s | 2 +- src/contest.c | 159 ++++++++++++++- 3 files changed, 159 insertions(+), 522 deletions(-) diff --git a/asm/contest.s b/asm/contest.s index 574ddf86e..2b19b9b66 100644 --- a/asm/contest.s +++ b/asm/contest.s @@ -5,522 +5,6 @@ .text - thumb_func_start sub_80DA884 -sub_80DA884: @ 80DA884 - push {lr} - ldr r0, =gIsLinkContest - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _080DA898 - ldr r1, =gContestPlayerMonIndex - movs r0, 0x3 - strb r0, [r1] -_080DA898: - pop {r0} - bx r0 - .pool - thumb_func_end sub_80DA884 - - thumb_func_start sub_80DA8A4 -sub_80DA8A4: @ 80DA8A4 - push {lr} - ldr r0, =gContestPlayerMonIndex - ldr r1, =gUnknown_02039F2B - ldrb r0, [r0] - ldrb r1, [r1] - cmp r0, r1 - beq _080DA8C0 - movs r0, 0 - b _080DA8C2 - .pool -_080DA8C0: - movs r0, 0x1 -_080DA8C2: - pop {r1} - bx r1 - thumb_func_end sub_80DA8A4 - - thumb_func_start sub_80DA8C8 -sub_80DA8C8: @ 80DA8C8 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x14 - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - ldr r6, =gSaveBlock2Ptr - ldr r1, [r6] - mov r0, sp - bl StringCopy - ldr r0, =gIsLinkContest - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080DA8F2 - mov r0, sp - bl sub_80DF9D4 -_080DA8F2: - ldr r5, =gContestPlayerMonIndex - ldrb r0, [r5] - lsls r0, 6 - ldr r4, =gContestMons + 13 - adds r0, r4 - mov r1, sp - movs r2, 0x8 - bl memcpy - ldr r0, [r6] - ldrb r0, [r0, 0x8] - cmp r0, 0 - bne _080DA928 - ldrb r0, [r5] - lsls r0, 6 - adds r0, r4, r0 - movs r1, 0xD8 - b _080DA930 - .pool -_080DA928: - ldrb r0, [r5] - lsls r0, 6 - adds r0, r4, r0 - movs r1, 0xD9 -_080DA930: - strb r1, [r0, 0x8] - ldr r7, =gContestMons - ldr r6, =gContestPlayerMonIndex - ldrb r0, [r6] - lsls r0, 6 - adds r1, r7, 0 - adds r1, 0x18 - adds r0, r1 - movs r1, 0 - str r1, [r0] - ldrb r0, [r6] - lsls r0, 6 - adds r0, r7 - adds r0, 0x2C - strb r1, [r0] - movs r0, 0x64 - mov r1, r8 - muls r1, r0 - ldr r0, =gPlayerParty - adds r5, r1, r0 - adds r0, r5, 0 - movs r1, 0xB - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - strh r0, [r1] - adds r0, r5, 0 - movs r1, 0x2 - mov r2, sp - bl GetMonData - mov r0, sp - bl StringGetEnd10 - ldr r0, =gIsLinkContest - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - beq _080DA994 - adds r0, r5, 0 - movs r1, 0x3 - bl GetMonData - adds r1, r0, 0 - mov r0, sp - bl sub_80DF9E0 -_080DA994: - ldrb r0, [r6] - lsls r0, 6 - adds r4, r7, 0x2 - adds r0, r4 - mov r1, sp - movs r2, 0xB - bl memcpy - ldrb r0, [r6] - lsls r0, 6 - adds r0, r4 - mov r1, sp - bl StringCopy - adds r0, r5, 0 - movs r1, 0x16 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - adds r1, 0x26 - strb r0, [r1] - adds r0, r5, 0 - movs r1, 0x17 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - adds r1, 0x27 - strb r0, [r1] - adds r0, r5, 0 - movs r1, 0x18 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - adds r1, 0x28 - strb r0, [r1] - adds r0, r5, 0 - movs r1, 0x21 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - adds r1, 0x29 - strb r0, [r1] - adds r0, r5, 0 - movs r1, 0x2F - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - adds r1, 0x2A - strb r0, [r1] - adds r0, r5, 0 - movs r1, 0x30 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - adds r1, 0x2B - strb r0, [r1] - adds r0, r5, 0 - movs r1, 0xD - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - strh r0, [r1, 0x1E] - adds r0, r5, 0 - movs r1, 0xE - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - strh r0, [r1, 0x20] - adds r0, r5, 0 - movs r1, 0xF - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - strh r0, [r1, 0x22] - adds r0, r5, 0 - movs r1, 0x10 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r1, r7 - strh r0, [r1, 0x24] - adds r0, r5, 0 - movs r1, 0 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r2, r7, 0 - adds r2, 0x38 - adds r1, r2 - str r0, [r1] - adds r0, r5, 0 - movs r1, 0x1 - bl GetMonData - ldrb r1, [r6] - lsls r1, 6 - adds r2, r7, 0 - adds r2, 0x3C - adds r1, r2 - str r0, [r1] - adds r0, r5, 0 - movs r1, 0xC - bl GetMonData - lsls r0, 16 - lsrs r2, r0, 16 - ldrb r0, [r6] - lsls r0, 6 - adds r1, r0, r7 - adds r0, r1, 0 - adds r0, 0x26 - ldrb r3, [r0] - adds r0, 0x1 - ldrb r5, [r0] - adds r0, 0x1 - ldrb r6, [r0] - adds r0, 0x1 - ldrb r7, [r0] - adds r0, 0x1 - ldrb r4, [r0] - cmp r2, 0xFE - bne _080DAAC4 - adds r3, 0x14 - b _080DAB12 - .pool -_080DAAC4: - cmp r2, 0xFF - bne _080DAAD4 - lsls r0, r5, 16 - movs r1, 0xA0 - lsls r1, 13 - adds r0, r1 - lsrs r5, r0, 16 - b _080DAB12 -_080DAAD4: - movs r0, 0x80 - lsls r0, 1 - cmp r2, r0 - bne _080DAAE8 - lsls r0, r6, 16 - movs r1, 0xA0 - lsls r1, 13 - adds r0, r1 - lsrs r6, r0, 16 - b _080DAB12 -_080DAAE8: - ldr r0, =0x00000101 - cmp r2, r0 - bne _080DAB00 - lsls r0, r7, 16 - movs r1, 0xA0 - lsls r1, 13 - adds r0, r1 - lsrs r7, r0, 16 - b _080DAB12 - .pool -_080DAB00: - movs r0, 0x81 - lsls r0, 1 - cmp r2, r0 - bne _080DAB12 - lsls r0, r4, 16 - movs r1, 0xA0 - lsls r1, 13 - adds r0, r1 - lsrs r4, r0, 16 -_080DAB12: - cmp r3, 0xFF - ble _080DAB18 - movs r3, 0xFF -_080DAB18: - lsls r0, r5, 16 - asrs r0, 16 - cmp r0, 0xFF - ble _080DAB22 - movs r5, 0xFF -_080DAB22: - lsls r0, r6, 16 - asrs r0, 16 - cmp r0, 0xFF - ble _080DAB2C - movs r6, 0xFF -_080DAB2C: - lsls r0, r7, 16 - asrs r0, 16 - cmp r0, 0xFF - ble _080DAB36 - movs r7, 0xFF -_080DAB36: - lsls r0, r4, 16 - asrs r0, 16 - cmp r0, 0xFF - ble _080DAB40 - movs r4, 0xFF -_080DAB40: - ldr r2, =gContestMons - ldr r1, =gContestPlayerMonIndex - ldrb r0, [r1] - lsls r0, 6 - adds r0, r2 - adds r0, 0x26 - strb r3, [r0] - ldrb r0, [r1] - lsls r0, 6 - adds r0, r2 - adds r0, 0x27 - strb r5, [r0] - ldrb r0, [r1] - lsls r0, 6 - adds r0, r2 - adds r0, 0x28 - strb r6, [r0] - ldrb r0, [r1] - lsls r0, 6 - adds r0, r2 - adds r0, 0x29 - strb r7, [r0] - ldrb r0, [r1] - lsls r0, 6 - adds r0, r2 - adds r0, 0x2A - strb r4, [r0] - add sp, 0x14 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80DA8C8 - - thumb_func_start sub_80DAB8C -sub_80DAB8C: @ 80DAB8C - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0x64 - lsls r0, 24 - lsrs r4, r0, 24 - lsls r1, 24 - lsrs r1, 24 - mov r8, r1 - movs r6, 0 - movs r7, 0 - bl sub_80DA884 - ldr r0, =0x00000864 - bl FlagGet - lsls r0, 24 - cmp r0, 0 - beq _080DABC0 - ldr r0, =gIsLinkContest - ldrb r1, [r0] - movs r0, 0x1 - ands r0, r1 - cmp r0, 0 - bne _080DABC0 - movs r7, 0x1 -_080DABC0: - movs r5, 0 - ldr r2, =gUnknown_085880A4 - ldr r3, =gUnknown_085898A4 -_080DABC6: - ldrb r0, [r2, 0x1C] - lsls r0, 30 - lsrs r0, 30 - cmp r8, r0 - bne _080DAC3A - cmp r7, 0x1 - bne _080DABEC - ldrb r0, [r3] - cmp r0, 0x1 - beq _080DAC3A - b _080DABF2 - .pool -_080DABEC: - ldrb r0, [r3] - cmp r0, 0x2 - beq _080DAC3A -_080DABF2: - cmp r4, 0 - bne _080DABFE - ldrb r0, [r2, 0x1C] - lsls r0, 29 - cmp r0, 0 - blt _080DAC2E -_080DABFE: - cmp r4, 0x1 - bne _080DAC0A - ldrb r0, [r2, 0x1C] - lsls r0, 28 - cmp r0, 0 - blt _080DAC2E -_080DAC0A: - cmp r4, 0x2 - bne _080DAC16 - ldrb r0, [r2, 0x1C] - lsls r0, 27 - cmp r0, 0 - blt _080DAC2E -_080DAC16: - cmp r4, 0x3 - bne _080DAC22 - ldrb r0, [r2, 0x1C] - lsls r0, 26 - cmp r0, 0 - blt _080DAC2E -_080DAC22: - cmp r4, 0x4 - bne _080DAC3A - ldrb r0, [r2, 0x1C] - lsls r0, 25 - cmp r0, 0 - bge _080DAC3A -_080DAC2E: - adds r0, r6, 0 - adds r1, r0, 0x1 - lsls r1, 24 - lsrs r6, r1, 24 - add r0, sp - strb r5, [r0] -_080DAC3A: - adds r2, 0x40 - adds r3, 0x1 - adds r5, 0x1 - cmp r5, 0x5F - bls _080DABC6 - mov r0, sp - adds r1, r0, r6 - movs r0, 0xFF - strb r0, [r1] - movs r5, 0 - ldr r7, =gUnknown_085880A4 -_080DAC50: - bl Random - lsls r0, 16 - lsrs r0, 16 - adds r1, r6, 0 - bl __modsi3 - lsls r0, 16 - lsrs r0, 16 - ldr r1, =gContestMons - lsls r2, r5, 6 - adds r2, r1 - mov r1, sp - adds r4, r1, r0 - ldrb r1, [r4] - lsls r1, 6 - adds r1, r7 - adds r0, r2, 0 - movs r2, 0x40 - bl memcpy - ldrb r0, [r4] - adds r2, r5, 0x1 - subs r1, r6, 0x1 - cmp r0, 0xFF - beq _080DAC92 - adds r3, r4, 0 -_080DAC86: - ldrb r0, [r3, 0x1] - strb r0, [r3] - adds r3, 0x1 - ldrb r0, [r3] - cmp r0, 0xFF - bne _080DAC86 -_080DAC92: - lsls r0, r1, 24 - lsrs r6, r0, 24 - adds r5, r2, 0 - cmp r5, 0x2 - ble _080DAC50 - ldr r0, =gUnknown_02039F24 - ldrb r0, [r0] - bl sub_80DA8C8 - add sp, 0x64 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end sub_80DAB8C - thumb_func_start sub_80DACBC sub_80DACBC: @ 80DACBC push {r4-r7,lr} @@ -542,7 +26,7 @@ sub_80DACBC: @ 80DACBC b _080DADF6 _080DACDE: movs r5, 0 - ldr r3, =gUnknown_085880A4 + ldr r3, =gContestOpponents ldr r6, =gUnknown_085898A4 _080DACE4: ldrb r0, [r3, 0x1C] @@ -640,7 +124,7 @@ _080DAD82: adds r0, r5 lsls r0, 6 add r0, r8 - ldr r2, =gUnknown_085880A4 + ldr r2, =gContestOpponents mov r3, sp adds r4, r3, r1 ldrb r1, [r4] diff --git a/data/contest.s b/data/contest.s index 357a95d1d..eaf3f8c95 100644 --- a/data/contest.s +++ b/data/contest.s @@ -352,7 +352,7 @@ gUnknown_08587FA4:: @ 8587FA4 .align 2 -gUnknown_085880A4:: @ 85880A4 +gContestOpponents:: @ 85880A4 .include "data/contest_opponents.inc" gUnknown_085898A4:: @ 85898A4 diff --git a/src/contest.c b/src/contest.c index ac3f120a3..bd9fc0403 100644 --- a/src/contest.c +++ b/src/contest.c @@ -7,6 +7,7 @@ #include "constants/moves.h" #include "constants/songs.h" #include "constants/species.h" +#include "constants/flags.h" #include "battle.h" #include "battle_anim.h" #include "blend_palette.h" @@ -34,6 +35,7 @@ #include "dma3.h" #include "battle_message.h" #include "event_scripts.h" +#include "event_data.h" #include "strings.h" #include "contest_effect.h" #include "contest_link_80FC4F4.h" @@ -91,8 +93,8 @@ void sub_80DA7A0(u8); void sub_80DA7EC(u8); void sub_80DA830(u8); void sub_80DA874(void); -void sub_80DE424(u8); bool8 sub_80DA8A4(void); +void sub_80DE424(u8); u8 sub_80DB0C4(void); u8 sub_80DB120(void); void sub_80DB2BC(void); @@ -130,7 +132,6 @@ void prints_contest_move_description(u16); void sub_80DBD18(void); void sub_80DF250(void); void sub_80DF4F8(void); - void sub_80DD080(u8); void sub_80DF080(u8); void sub_80DF750(void); @@ -160,6 +161,8 @@ void sub_80DB944(void); void sub_80DBA18(void); void sub_80DC3AC(void); bool8 sub_80DC3C4(void); +void sub_80DF9D4(u8 *); +void sub_80DF9E0(u8 *, s32); EWRAM_DATA struct ContestPokemon gContestMons[4] = {0}; EWRAM_DATA s16 gUnknown_02039F00[4] = {0}; @@ -223,7 +226,8 @@ extern const u8 gText_0827E817[]; extern const u8 gText_0827E58A[]; extern const u8 gText_0827D56F[]; extern const u8 gText_0827D597[]; - +extern const struct ContestPokemon gContestOpponents[96]; +extern const u8 gUnknown_085898A4[96]; void TaskDummy1(u8 taskId) { @@ -1962,3 +1966,152 @@ void sub_80DA874(void) ScriptContext2_Disable(); EnableBothScriptContexts(); } + +void sub_80DA884(void) +{ + if (!(gIsLinkContest & 1)) + gContestPlayerMonIndex = 3; +} + +bool8 sub_80DA8A4(void) +{ + if (gContestPlayerMonIndex == gUnknown_02039F2B) + return TRUE; + return FALSE; +} + + +void sub_80DA8C8(u8 partyIndex) +{ + u8 name[20]; + u16 heldItem; + s16 cool; + s16 beauty; + s16 cute; + s16 smart; + s16 tough; + + StringCopy(name, gSaveBlock2Ptr->playerName); + if (gIsLinkContest & 1) + { + sub_80DF9D4(name); + } + memcpy(gContestMons[gContestPlayerMonIndex].trainerName, name, 8); + if (gSaveBlock2Ptr->playerGender == MALE) + gContestMons[gContestPlayerMonIndex].trainerGfxId = MAP_OBJ_GFX_LINK_BRENDAN; + else + gContestMons[gContestPlayerMonIndex].trainerGfxId = MAP_OBJ_GFX_LINK_MAY; + gContestMons[gContestPlayerMonIndex].flags = 0; + gContestMons[gContestPlayerMonIndex].unk2C[0] = 0; + gContestMons[gContestPlayerMonIndex].species = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES); + GetMonData(&gPlayerParty[partyIndex], MON_DATA_NICKNAME, name); + StringGetEnd10(name); + if (gIsLinkContest & 1) + { + sub_80DF9E0(name, GetMonData(&gPlayerParty[partyIndex], MON_DATA_LANGUAGE)); + } + memcpy(gContestMons[gContestPlayerMonIndex].nickname, name, 11); + StringCopy(gContestMons[gContestPlayerMonIndex].nickname, name); + gContestMons[gContestPlayerMonIndex].cool = GetMonData(&gPlayerParty[partyIndex], MON_DATA_COOL); + gContestMons[gContestPlayerMonIndex].beauty = GetMonData(&gPlayerParty[partyIndex], MON_DATA_BEAUTY); + gContestMons[gContestPlayerMonIndex].cute = GetMonData(&gPlayerParty[partyIndex], MON_DATA_CUTE); + gContestMons[gContestPlayerMonIndex].smart = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SMART); + gContestMons[gContestPlayerMonIndex].tough = GetMonData(&gPlayerParty[partyIndex], MON_DATA_TOUGH); + gContestMons[gContestPlayerMonIndex].sheen = GetMonData(&gPlayerParty[partyIndex], MON_DATA_SHEEN); + gContestMons[gContestPlayerMonIndex].moves[0] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE1); + gContestMons[gContestPlayerMonIndex].moves[1] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE2); + gContestMons[gContestPlayerMonIndex].moves[2] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE3); + gContestMons[gContestPlayerMonIndex].moves[3] = GetMonData(&gPlayerParty[partyIndex], MON_DATA_MOVE4); + gContestMons[gContestPlayerMonIndex].personality = GetMonData(&gPlayerParty[partyIndex], MON_DATA_PERSONALITY); + gContestMons[gContestPlayerMonIndex].otId = GetMonData(&gPlayerParty[partyIndex], MON_DATA_OT_ID); + + heldItem = GetMonData(&gPlayerParty[partyIndex], MON_DATA_HELD_ITEM); + cool = gContestMons[gContestPlayerMonIndex].cool; + beauty = gContestMons[gContestPlayerMonIndex].beauty; + cute = gContestMons[gContestPlayerMonIndex].cute; + smart = gContestMons[gContestPlayerMonIndex].smart; + tough = gContestMons[gContestPlayerMonIndex].tough; + if (heldItem == ITEM_RED_SCARF) + cool += 20; + else if (heldItem == ITEM_BLUE_SCARF) + beauty += 20; + else if (heldItem == ITEM_PINK_SCARF) + cute += 20; + else if (heldItem == ITEM_GREEN_SCARF) + smart += 20; + else if (heldItem == ITEM_YELLOW_SCARF) + tough += 20; + if (cool > 255) + cool = 255; + if (beauty > 255) + beauty = 255; + if (cute > 255) + cute = 255; + if (smart > 255) + smart = 255; + if (tough > 255) + tough = 255; + gContestMons[gContestPlayerMonIndex].cool = cool; + gContestMons[gContestPlayerMonIndex].beauty = beauty; + gContestMons[gContestPlayerMonIndex].cute = cute; + gContestMons[gContestPlayerMonIndex].smart = smart; + gContestMons[gContestPlayerMonIndex].tough = tough; +} + +void sub_80DAB8C(u8 contestType, u8 rank) +{ + s32 i; + u8 opponentsCount = 0; + u8 opponents[100]; + bool8 r7 = FALSE; + const u8 * r3; + + sub_80DA884(); + + if (FlagGet(FLAG_SYS_GAME_CLEAR) && !(gIsLinkContest & 1)) + r7 = TRUE; + + // Find all suitable opponents + r3 = gUnknown_085898A4; + for (i = 0; i < ARRAY_COUNT(gContestOpponents); i++) + { + if (rank == gContestOpponents[i].whichRank) + { + if (r7 == TRUE) + { + if (r3[i] == 1) + continue; + } + else + { + if (r3[i] == 2) + continue; + } + if (contestType == 0 && gContestOpponents[i].aiPool_Cool) + opponents[opponentsCount++] = i; + else if (contestType == 1 && gContestOpponents[i].aiPool_Beauty) + opponents[opponentsCount++] = i; + else if (contestType == 2 && gContestOpponents[i].aiPool_Cute) + opponents[opponentsCount++] = i; + else if (contestType == 3 && gContestOpponents[i].aiPool_Smart) + opponents[opponentsCount++] = i; + else if (contestType == 4 && gContestOpponents[i].aiPool_Tough) + opponents[opponentsCount++] = i; + } + } + opponents[opponentsCount] = 0xFF; + + // Choose three random opponents from the list + for (i = 0; i < 3; i++) + { + u16 rnd = Random() % opponentsCount; + s32 j; + + gContestMons[i] = gContestOpponents[opponents[rnd]]; + for (j = rnd; opponents[j] != 0xFF; j++) + opponents[j] = opponents[j + 1]; + opponentsCount--; + } + + sub_80DA8C8(gUnknown_02039F24); +}