diff --git a/asm/battle_records.s b/asm/battle_records.s index 5b6b0814a..69e207b61 100644 --- a/asm/battle_records.s +++ b/asm/battle_records.s @@ -5,746 +5,6 @@ .text - thumb_func_start InitLinkBattleRecord -InitLinkBattleRecord: @ 813BF94 - push {r4,lr} - sub sp, 0x4 - adds r4, r0, 0 - mov r1, sp - movs r0, 0 - strh r0, [r1] - ldr r2, =0x01000008 - mov r0, sp - adds r1, r4, 0 - bl CpuSet - movs r0, 0xFF - strb r0, [r4] - movs r0, 0 - strh r0, [r4, 0x8] - strh r0, [r4, 0xA] - strh r0, [r4, 0xC] - strh r0, [r4, 0xE] - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end InitLinkBattleRecord - - thumb_func_start InitLinkBattleRecords_ -InitLinkBattleRecords_: @ 813BFC4 - push {r4,r5,lr} - adds r4, r0, 0 - movs r5, 0x4 -_0813BFCA: - adds r0, r4, 0 - bl InitLinkBattleRecord - adds r4, 0x10 - subs r5, 0x1 - cmp r5, 0 - bge _0813BFCA - movs r0, 0x17 - movs r1, 0 - bl SetGameStat - movs r0, 0x18 - movs r1, 0 - bl SetGameStat - movs r0, 0x19 - movs r1, 0 - bl SetGameStat - pop {r4,r5} - pop {r0} - bx r0 - thumb_func_end InitLinkBattleRecords_ - - thumb_func_start GetLinkBattleRecordTotalBattles -GetLinkBattleRecordTotalBattles: @ 813BFF8 - adds r1, r0, 0 - ldrh r0, [r1, 0xA] - ldrh r2, [r1, 0xC] - adds r0, r2 - ldrh r1, [r1, 0xE] - adds r0, r1 - bx lr - thumb_func_end GetLinkBattleRecordTotalBattles - - thumb_func_start FindLinkBattleRecord -FindLinkBattleRecord: @ 813C008 - push {r4-r7,lr} - adds r7, r1, 0 - lsls r2, 16 - lsrs r6, r2, 16 - movs r5, 0 - adds r4, r0, 0 -_0813C014: - adds r0, r4, 0 - adds r1, r7, 0 - movs r2, 0x7 - bl StringCompareN - cmp r0, 0 - bne _0813C02C - ldrh r0, [r4, 0x8] - cmp r0, r6 - bne _0813C02C - adds r0, r5, 0 - b _0813C036 -_0813C02C: - adds r4, 0x10 - adds r5, 0x1 - cmp r5, 0x4 - ble _0813C014 - movs r0, 0x5 -_0813C036: - pop {r4-r7} - pop {r1} - bx r1 - thumb_func_end FindLinkBattleRecord - - thumb_func_start SortLinkBattleRecords -SortLinkBattleRecords: @ 813C03C - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0x18 - mov r10, r0 - movs r1, 0x4 -_0813C04C: - subs r3, r1, 0x1 - adds r6, r3, 0 - cmp r3, 0 - blt _0813C0BA - lsls r0, r1, 4 - add r0, r10 - str r0, [sp, 0x14] - lsls r0, r3, 4 - mov r2, r10 - adds r5, r0, r2 - movs r4, 0x50 - add r4, r10 - mov r9, r4 - add r1, r9 - mov r8, r1 -_0813C06A: - ldr r0, [sp, 0x14] - str r3, [sp, 0x10] - bl GetLinkBattleRecordTotalBattles - adds r4, r0, 0 - adds r0, r5, 0 - bl GetLinkBattleRecordTotalBattles - ldr r3, [sp, 0x10] - cmp r4, r0 - ble _0813C0B2 - mov r1, sp - ldr r0, [sp, 0x14] - ldm r0!, {r2,r4,r7} - stm r1!, {r2,r4,r7} - ldr r0, [r0] - str r0, [r1] - ldr r1, [sp, 0x14] - adds r0, r5, 0 - ldm r0!, {r2,r4,r7} - stm r1!, {r2,r4,r7} - ldr r0, [r0] - str r0, [r1] - adds r1, r5, 0 - mov r0, sp - ldm r0!, {r2,r4,r7} - stm r1!, {r2,r4,r7} - ldr r0, [r0] - str r0, [r1] - mov r7, r8 - ldrb r2, [r7] - mov r0, r9 - adds r1, r0, r6 - ldrb r0, [r1] - strb r0, [r7] - strb r2, [r1] -_0813C0B2: - subs r5, 0x10 - subs r6, 0x1 - cmp r6, 0 - bge _0813C06A -_0813C0BA: - adds r1, r3, 0 - cmp r1, 0 - bgt _0813C04C - add sp, 0x18 - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end SortLinkBattleRecords - - thumb_func_start UpdateLinkBattleRecord -UpdateLinkBattleRecord: @ 813C0D0 - push {lr} - adds r2, r0, 0 - cmp r1, 0x2 - beq _0813C100 - cmp r1, 0x2 - bgt _0813C0E2 - cmp r1, 0x1 - beq _0813C0E8 - b _0813C12A -_0813C0E2: - cmp r1, 0x3 - beq _0813C118 - b _0813C12A -_0813C0E8: - ldrh r0, [r2, 0xA] - adds r0, 0x1 - strh r0, [r2, 0xA] - lsls r0, 16 - lsrs r0, 16 - ldr r1, =0x0000270f - cmp r0, r1 - bls _0813C12A - strh r1, [r2, 0xA] - b _0813C12A - .pool -_0813C100: - ldrh r0, [r2, 0xC] - adds r0, 0x1 - strh r0, [r2, 0xC] - lsls r0, 16 - lsrs r0, 16 - ldr r1, =0x0000270f - cmp r0, r1 - bls _0813C12A - strh r1, [r2, 0xC] - b _0813C12A - .pool -_0813C118: - ldrh r0, [r2, 0xE] - adds r0, 0x1 - strh r0, [r2, 0xE] - lsls r0, 16 - lsrs r0, 16 - ldr r1, =0x0000270f - cmp r0, r1 - bls _0813C12A - strh r1, [r2, 0xE] -_0813C12A: - pop {r0} - bx r0 - .pool - thumb_func_end UpdateLinkBattleRecord - - thumb_func_start UpdateLinkBattleGameStats -UpdateLinkBattleGameStats: @ 813C134 - push {r4,lr} - cmp r0, 0x2 - beq _0813C14E - cmp r0, 0x2 - bgt _0813C144 - cmp r0, 0x1 - beq _0813C14A - b _0813C166 -_0813C144: - cmp r0, 0x3 - beq _0813C152 - b _0813C166 -_0813C14A: - movs r4, 0x17 - b _0813C154 -_0813C14E: - movs r4, 0x18 - b _0813C154 -_0813C152: - movs r4, 0x19 -_0813C154: - adds r0, r4, 0 - bl GetGameStat - ldr r1, =0x0000270e - cmp r0, r1 - bhi _0813C166 - adds r0, r4, 0 - bl IncrementGameStat -_0813C166: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end UpdateLinkBattleGameStats - - thumb_func_start UpdateLinkBattleRecords_ -UpdateLinkBattleRecords_: @ 813C170 - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - adds r6, r0, 0 - mov r8, r1 - mov r10, r3 - ldr r0, [sp, 0x20] - lsls r2, 16 - lsrs r7, r2, 16 - lsls r0, 24 - lsrs r0, 24 - mov r9, r0 - mov r0, r10 - bl UpdateLinkBattleGameStats - adds r0, r6, 0 - bl SortLinkBattleRecords - adds r0, r6, 0 - mov r1, r8 - adds r2, r7, 0 - bl FindLinkBattleRecord - adds r5, r0, 0 - cmp r5, 0x5 - bne _0813C1D4 - movs r5, 0x4 - adds r4, r6, 0 - adds r4, 0x40 - adds r0, r4, 0 - bl InitLinkBattleRecord - adds r0, r4, 0 - mov r1, r8 - movs r2, 0x7 - bl StringCopyN - strh r7, [r4, 0x8] - adds r2, r6, 0 - adds r2, 0x54 - ldr r1, =gLinkPlayers - mov r3, r9 - lsls r0, r3, 3 - subs r0, r3 - lsls r0, 2 - adds r0, r1 - ldrh r0, [r0, 0x1A] - strb r0, [r2] -_0813C1D4: - lsls r0, r5, 4 - adds r0, r6, r0 - mov r1, r10 - bl UpdateLinkBattleRecord - adds r0, r6, 0 - bl SortLinkBattleRecords - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end UpdateLinkBattleRecords_ - - thumb_func_start InitLinkBattleRecords -InitLinkBattleRecords: @ 813C1F8 - push {lr} - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00003150 - adds r0, r1 - bl InitLinkBattleRecords_ - pop {r0} - bx r0 - .pool - thumb_func_end InitLinkBattleRecords - - thumb_func_start IncTrainerCardWins -IncTrainerCardWins: @ 813C214 - push {lr} - movs r1, 0x64 - muls r1, r0 - ldr r0, =gUnknown_02039B6C - adds r1, r0 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - lsls r0, 16 - lsrs r0, 16 - ldr r2, =0x0000270f - cmp r0, r2 - bls _0813C230 - strh r2, [r1] -_0813C230: - pop {r0} - bx r0 - .pool - thumb_func_end IncTrainerCardWins - - thumb_func_start IncTrainerCardLosses -IncTrainerCardLosses: @ 813C23C - push {lr} - movs r1, 0x64 - muls r1, r0 - ldr r0, =gUnknown_02039B6E - adds r1, r0 - ldrh r0, [r1] - adds r0, 0x1 - strh r0, [r1] - lsls r0, 16 - lsrs r0, 16 - ldr r2, =0x0000270f - cmp r0, r2 - bls _0813C258 - strh r2, [r1] -_0813C258: - pop {r0} - bx r0 - .pool - thumb_func_end IncTrainerCardLosses - - thumb_func_start UpdateTrainerCardWinsLosses -UpdateTrainerCardWinsLosses: @ 813C264 - push {r4,lr} - adds r4, r0, 0 - ldr r0, =gBattleOutcome - ldrb r0, [r0] - cmp r0, 0x1 - beq _0813C27C - cmp r0, 0x2 - beq _0813C28A - b _0813C298 - .pool -_0813C27C: - eors r0, r4 - bl IncTrainerCardWins - adds r0, r4, 0 - bl IncTrainerCardLosses - b _0813C298 -_0813C28A: - movs r0, 0x1 - eors r0, r4 - bl IncTrainerCardLosses - adds r0, r4, 0 - bl IncTrainerCardWins -_0813C298: - pop {r4} - pop {r0} - bx r0 - thumb_func_end UpdateTrainerCardWinsLosses - - thumb_func_start UpdateLinkBattleRecords -UpdateLinkBattleRecords: @ 813C2A0 - push {r4,lr} - sub sp, 0x4 - adds r4, r0, 0 - bl InUnionRoom - cmp r0, 0x1 - beq _0813C2DA - adds r0, r4, 0 - bl UpdateTrainerCardWinsLosses - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00003150 - adds r0, r1 - movs r1, 0x64 - adds r3, r4, 0 - muls r3, r1 - ldr r2, =gUnknown_02039B88 - adds r1, r3, r2 - subs r2, 0x30 - adds r3, r2 - ldrh r2, [r3, 0xE] - ldr r3, =gBattleOutcome - ldrb r3, [r3] - lsls r4, 24 - lsrs r4, 24 - str r4, [sp] - bl UpdateLinkBattleRecords_ -_0813C2DA: - add sp, 0x4 - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end UpdateLinkBattleRecords - - thumb_func_start PrintLinkBattleWinsLossesDraws -PrintLinkBattleWinsLossesDraws: @ 813C2F4 - push {r4,lr} - sub sp, 0xC - ldr r4, =gStringVar1 - movs r0, 0x17 - bl GetGameStat - adds r1, r0, 0 - adds r0, r4, 0 - movs r2, 0 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - ldr r4, =gStringVar2 - movs r0, 0x18 - bl GetGameStat - adds r1, r0, 0 - adds r0, r4, 0 - movs r2, 0 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - ldr r4, =gStringVar3 - movs r0, 0x19 - bl GetGameStat - adds r1, r0, 0 - adds r0, r4, 0 - movs r2, 0 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - ldr r4, =gStringVar4 - ldr r1, =gText_TotalRecordWLD - adds r0, r4, 0 - bl StringExpandPlaceholders - movs r0, 0x1 - adds r1, r4, 0 - movs r2, 0xD0 - bl GetStringCenterAlignXOffset - adds r3, r0, 0 - ldr r0, =gResultsWindowId - ldrb r0, [r0] - lsls r3, 24 - lsrs r3, 24 - movs r1, 0x11 - str r1, [sp] - movs r1, 0 - str r1, [sp, 0x4] - str r1, [sp, 0x8] - movs r1, 0x1 - adds r2, r4, 0 - bl PrintTextOnWindow - add sp, 0xC - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end PrintLinkBattleWinsLossesDraws - - thumb_func_start PrintLinkBattleRecord -PrintLinkBattleRecord: @ 813C384 - push {r4-r7,lr} - mov r7, r8 - push {r7} - sub sp, 0xC - adds r6, r0, 0 - adds r5, r2, 0 - lsls r1, 24 - lsrs r4, r1, 24 - ldrh r0, [r6, 0xA] - cmp r0, 0 - bne _0813C40C - ldr r7, [r6, 0xC] - cmp r7, 0 - bne _0813C40C - ldr r0, =gResultsWindowId - mov r8, r0 - ldrb r0, [r0] - ldr r2, =gUnknown_085B3D84 - lsls r4, 3 - adds r4, 0x1 - lsls r4, 24 - lsrs r4, 24 - str r4, [sp] - str r7, [sp, 0x4] - str r7, [sp, 0x8] - movs r1, 0x1 - movs r3, 0x8 - bl PrintTextOnWindow - mov r1, r8 - ldrb r0, [r1] - ldr r5, =gUnknown_085B3D8C - str r4, [sp] - str r7, [sp, 0x4] - str r7, [sp, 0x8] - movs r1, 0x1 - adds r2, r5, 0 - movs r3, 0x50 - bl PrintTextOnWindow - mov r1, r8 - ldrb r0, [r1] - str r4, [sp] - str r7, [sp, 0x4] - str r7, [sp, 0x8] - movs r1, 0x1 - adds r2, r5, 0 - movs r3, 0x80 - bl PrintTextOnWindow - mov r1, r8 - ldrb r0, [r1] - str r4, [sp] - str r7, [sp, 0x4] - str r7, [sp, 0x8] - movs r1, 0x1 - adds r2, r5, 0 - movs r3, 0xB0 - bl PrintTextOnWindow - b _0813C4A8 - .pool -_0813C40C: - ldr r0, =gStringVar1 - movs r1, 0x8 - bl StringFillWithTerminator - ldr r0, =gStringVar1 - adds r1, r6, 0 - movs r2, 0x7 - bl StringCopyN - lsls r1, r5, 24 - lsrs r1, 24 - ldr r0, =gStringVar1 - bl ConvertInternationalString - ldr r0, =gResultsWindowId - mov r8, r0 - ldrb r0, [r0] - lsls r4, 3 - adds r4, 0x1 - lsls r4, 24 - lsrs r4, 24 - str r4, [sp] - movs r5, 0 - str r5, [sp, 0x4] - str r5, [sp, 0x8] - movs r1, 0x1 - ldr r2, =gStringVar1 - movs r3, 0x8 - bl PrintTextOnWindow - ldrh r1, [r6, 0xA] - ldr r0, =gStringVar1 - movs r2, 0x1 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - mov r1, r8 - ldrb r0, [r1] - str r4, [sp] - str r5, [sp, 0x4] - str r5, [sp, 0x8] - movs r1, 0x1 - ldr r2, =gStringVar1 - movs r3, 0x50 - bl PrintTextOnWindow - ldrh r1, [r6, 0xC] - ldr r0, =gStringVar1 - movs r2, 0x1 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - mov r1, r8 - ldrb r0, [r1] - str r4, [sp] - str r5, [sp, 0x4] - str r5, [sp, 0x8] - movs r1, 0x1 - ldr r2, =gStringVar1 - movs r3, 0x80 - bl PrintTextOnWindow - ldrh r1, [r6, 0xE] - ldr r0, =gStringVar1 - movs r2, 0x1 - movs r3, 0x4 - bl ConvertIntToDecimalStringN - mov r1, r8 - ldrb r0, [r1] - str r4, [sp] - str r5, [sp, 0x4] - str r5, [sp, 0x8] - movs r1, 0x1 - ldr r2, =gStringVar1 - movs r3, 0xB0 - bl PrintTextOnWindow -_0813C4A8: - add sp, 0xC - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end PrintLinkBattleRecord - - thumb_func_start ShowLinkBattleRecords -ShowLinkBattleRecords: @ 813C4BC - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - sub sp, 0xC - ldr r6, =gResultsWindowId - ldr r0, =gUnknown_085B3D7C - bl AddWindow - strb r0, [r6] - ldrb r0, [r6] - movs r1, 0 - bl NewMenuHelpers_DrawStdWindowFrame - ldrb r0, [r6] - movs r1, 0x11 - bl FillWindowPixelBuffer - ldr r5, =gStringVar4 - ldr r1, =gText_PlayersBattleResults - adds r0, r5, 0 - bl StringExpandPlaceholders - movs r0, 0x1 - adds r1, r5, 0 - movs r2, 0xD0 - bl GetStringCenterAlignXOffset - adds r3, r0, 0 - ldrb r0, [r6] - lsls r3, 24 - lsrs r3, 24 - movs r1, 0x1 - str r1, [sp] - movs r4, 0 - str r4, [sp, 0x4] - str r4, [sp, 0x8] - adds r2, r5, 0 - bl PrintTextOnWindow - ldr r0, =gSaveBlock1Ptr - mov r8, r0 - ldr r0, [r0] - ldr r1, =0x00003150 - mov r9, r1 - add r0, r9 - bl PrintLinkBattleWinsLossesDraws - ldr r1, =gText_WinLoseDraw - adds r0, r5, 0 - bl StringExpandPlaceholders - ldrb r0, [r6] - movs r1, 0x29 - str r1, [sp] - str r4, [sp, 0x4] - str r4, [sp, 0x8] - movs r1, 0x1 - adds r2, r5, 0 - movs r3, 0 - bl PrintTextOnWindow - mov r7, r8 - movs r6, 0xE0 - lsls r6, 19 - mov r5, r9 -_0813C540: - ldr r2, [r7] - adds r0, r2, r5 - lsrs r1, r6, 24 - ldr r3, =0x000031a0 - adds r2, r3 - adds r2, r4 - ldrb r2, [r2] - bl PrintLinkBattleRecord - movs r0, 0x80 - lsls r0, 18 - adds r6, r0 - adds r5, 0x10 - adds r4, 0x1 - cmp r4, 0x4 - ble _0813C540 - ldr r4, =gResultsWindowId - ldrb r0, [r4] - bl PutWindowTilemap - ldrb r0, [r4] - movs r1, 0x3 - bl CopyWindowToVram - add sp, 0xC - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .pool - thumb_func_end ShowLinkBattleRecords - thumb_func_start sub_813C5A0 sub_813C5A0: @ 813C5A0 push {r4,lr} diff --git a/asm/cable_club.s b/asm/cable_club.s index 3b8277f49..0ace58f4e 100644 --- a/asm/cable_club.s +++ b/asm/cable_club.s @@ -960,7 +960,7 @@ task_map_chg_seq_0807EC34: @ 80B2B94 push {r4,r5,lr} adds r5, r0, 0 adds r4, r1, 0 - ldr r1, =gUnknown_02039B58 + ldr r1, =gTrainerCards ldrh r0, [r5] cmp r0, 0x1 bne _080B2C10 @@ -1044,7 +1044,7 @@ sub_80B2C30: @ 80B2C30 _080B2C5C: movs r0, 0x64 muls r0, r4 - ldr r1, =gUnknown_02039B58 + ldr r1, =gTrainerCards adds r0, r1 lsls r1, r4, 8 ldr r2, =gBlockRecvBuffer @@ -2171,7 +2171,7 @@ sub_80B360C: @ 80B360C ldrb r0, [r0] movs r5, 0x1 eors r0, r5 - bl UpdateLinkBattleRecords + bl UpdatePlayerLinkBattleRecords ldr r0, =gWirelessCommType ldrb r0, [r0] cmp r0, 0 diff --git a/asm/rom_8011DC0.s b/asm/rom_8011DC0.s index 3a7f41d0b..0cdcc45d0 100644 --- a/asm/rom_8011DC0.s +++ b/asm/rom_8011DC0.s @@ -3181,7 +3181,7 @@ _08014138: adds r3, r1, r0 movs r0, 0x64 muls r0, r4 - ldr r1, =gUnknown_02039B58 + ldr r1, =gTrainerCards adds r0, r1 ldrb r2, [r5] adds r1, r3, 0 @@ -10615,7 +10615,7 @@ sub_8018220: @ 8018220 lsrs r0, 24 movs r1, 0x64 muls r1, r0 - ldr r0, =gUnknown_02039B58 + ldr r0, =gTrainerCards adds r1, r0 mov r8, r1 bl UnkTextUtil_Reset diff --git a/asm/trainer_card.s b/asm/trainer_card.s index a56dbd157..6d1be17cb 100644 --- a/asm/trainer_card.s +++ b/asm/trainer_card.s @@ -3894,7 +3894,7 @@ _080C48F6: sub_80C4904: @ 80C4904 lsls r0, 24 lsrs r0, 24 - ldr r2, =gUnknown_02039B58 + ldr r2, =gTrainerCards movs r1, 0x64 muls r0, r1 adds r0, r2 @@ -4578,7 +4578,7 @@ sub_80C4E74: @ 80C4E74 ldr r0, [r5] ldr r1, =0x00000534 adds r0, r1 - ldr r2, =gUnknown_02039B58 + ldr r2, =gTrainerCards movs r1, 0x64 muls r1, r4 adds r1, r2 diff --git a/include/battle_records.h b/include/battle_records.h index ac6c3cbdb..5db24f3c8 100644 --- a/include/battle_records.h +++ b/include/battle_records.h @@ -1,8 +1,8 @@ #ifndef GUARD_BATTLE_RECORDS_H #define GUARD_BATTLE_RECORDS_H -void InitLinkBattleRecords(void); -void UpdateLinkBattleRecords(int id); +void ClearPlayerLinkBattleRecords(void); +void UpdatePlayerLinkBattleRecords(s32 battlerId); void ShowLinkBattleRecords(void); void ShowBattleTowerRecords(void); diff --git a/include/global.h b/include/global.h index f88203c90..a223f9762 100644 --- a/include/global.h +++ b/include/global.h @@ -480,6 +480,8 @@ struct RecordMixing_UnknownStruct u16 unk74[0x2]; }; +#define LINK_B_RECORDS_COUNT 5 + struct LinkBattleRecord { u8 name[8]; @@ -489,6 +491,12 @@ struct LinkBattleRecord u16 draws; }; +struct LinkBattleRecords +{ + struct LinkBattleRecord entries[LINK_B_RECORDS_COUNT]; + u8 languages[LINK_B_RECORDS_COUNT]; +}; + struct RecordMixingGiftData { u8 unk0; @@ -703,9 +711,7 @@ struct SaveBlock1 /*0x2e64*/ struct EasyChatPair easyChatPairs[5]; //Dewford trend [0] and some other stuff /*0x2e90*/ struct ContestWinner contestWinners[13]; // 0 - 5 used in contest hall, 6 - 7 unused?, 8 - 12 museum /*0x3030*/ struct DayCare daycare; - /*0x3150*/ struct LinkBattleRecord linkBattleRecords[5]; - /*0x31A0*/ u8 unk_31A0; - /*0x31A1*/ u8 filler_31A1[7]; + /*0x3150*/ struct LinkBattleRecords linkBattleRecords; /*0x31A8*/ u8 giftRibbons[52]; /*0x31DC*/ struct Roamer roamer; /*0x31F8*/ struct EnigmaBerry enigmaBerry; diff --git a/include/strings.h b/include/strings.h index 7c81dbcfb..6ebbd7d73 100644 --- a/include/strings.h +++ b/include/strings.h @@ -429,5 +429,8 @@ extern const u8 gText_TooImportantToToss[]; extern const u8 gText_ConfirmTossItems[]; extern const u8 gText_MoveVar1Where[]; +extern const u8 gText_TotalRecordWLD[]; +extern const u8 gText_PlayersBattleResults[]; +extern const u8 gText_WinLoseDraw[]; #endif //GUARD_STRINGS_H diff --git a/include/trainer_card.h b/include/trainer_card.h new file mode 100644 index 000000000..5cb93dba0 --- /dev/null +++ b/include/trainer_card.h @@ -0,0 +1,35 @@ +#ifndef GUARD_TRAINER_CARD_H +#define GUARD_TRAINER_CARD_H + +struct TrainerCard +{ + /*0x00*/ u8 gender; + /*0x01*/ u8 stars; + /*0x02*/ bool8 hasPokedex; + /*0x03*/ bool8 var_3; + /*0x04*/ bool8 var_4; + /*0x05*/ u8 var_5; + /*0x06*/ u16 firstHallOfFameA; + /*0x08*/ u16 firstHallOfFameB; + /*0x0A*/ u16 firstHallOfFameC; + /*0x0C*/ u16 pokedexSeen; + /*0x0E*/ u16 trainerId; + /*0x10*/ u16 playTimeHours; + /*0x12*/ u16 playTimeMinutes; + /*0x14*/ u16 linkBattleWins; + /*0x16*/ u16 linkBattleLosses; + /*0x18*/ u16 battleTowerWins; + /*0x1A*/ u16 battleTowerLosses; + /*0x1C*/ u16 contestsWithFriends; + /*0x1E*/ u16 pokeblocksWithFriends; + /*0x20*/ u16 pokemonTrades; + /*0x22*/ u16 var_22; + /*0x24*/ u32 money; + /*0x28*/ u16 var_28[4]; + /*0x30*/ u8 playerName[8]; + /*0x38*/ u8 emeraldAddedUnknownFields[0x64-0x38]; +}; + +extern struct TrainerCard gTrainerCards[4]; + +#endif // GUARD_TRAINER_CARD_H diff --git a/ld_script.txt b/ld_script.txt index 3318bb521..3af52896b 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -184,8 +184,8 @@ SECTIONS { src/birch_pc.o(.text); src/hof_pc.o(.text); asm/field_specials.o(.text); - asm/battle_records.o(.text); src/battle_records.o(.text); + asm/battle_records.o(.text); asm/pokedex_area_screen.o(.text); src/evolution_scene.o(.text); asm/roulette.o(.text); diff --git a/src/battle_records.c b/src/battle_records.c index b21b07341..0a0e0bd42 100644 --- a/src/battle_records.c +++ b/src/battle_records.c @@ -5,8 +5,17 @@ #include "link.h" #include "battle.h" #include "overworld.h" +#include "text.h" +#include "strings.h" +#include "string_util.h" +#include "trainer_card.h" +#include "menu.h" +#include "menu_helpers.h" +#include "international_string_util.h" #include "constants/game_stat.h" +extern u8 gResultsWindowId; + // const rom data const u32 gUnknown_085B3484[] = INCBIN_U32("graphics/unknown/unknown_5B3484.4bpp"); const u16 gUnknown_085B3544[] = INCBIN_U16("graphics/unknown/unknown_5B3484.gbapal"); @@ -46,3 +55,251 @@ const u8 gUnknown_085B3D84[] = _("-------"); const u8 gUnknown_085B3D8C[] = _("----"); // code +static void ClearLinkBattleRecord(struct LinkBattleRecord *record) +{ + CpuFill16(0, record, sizeof(struct LinkBattleRecord)); + record->name[0] = EOS; + record->trainerId = 0; + record->wins = 0; + record->losses = 0; + record->draws = 0; +} + +static void ClearLinkBattleRecords(struct LinkBattleRecord *records) +{ + s32 i; + for (i = 0; i < LINK_B_RECORDS_COUNT; i++) + { + ClearLinkBattleRecord(records + i); + } + SetGameStat(GAME_STAT_LINK_BATTLE_WINS, 0); + SetGameStat(GAME_STAT_LINK_BATTLE_LOSSES, 0); + SetGameStat(GAME_STAT_LINK_BATTLE_DRAWS, 0); +} + +static s32 GetLinkBattleRecordTotalBattles(struct LinkBattleRecord *record) +{ + return record->wins + record->losses + record->draws; +} + +static s32 FindLinkBattleRecord(struct LinkBattleRecord *records, const u8 *name, u16 trainerId) +{ + s32 i; + + for (i = 0; i < LINK_B_RECORDS_COUNT; i++) + { + if (!StringCompareN(records[i].name, name, OT_NAME_LENGTH) && records[i].trainerId == trainerId) + return i; + } + + return LINK_B_RECORDS_COUNT; +} + +static void SortLinkBattleRecords(struct LinkBattleRecords *records) +{ + s32 i, j; + + for (i = LINK_B_RECORDS_COUNT - 1; i > 0; i--) + { + for (j = i - 1; j >= 0; j--) + { + s32 totalBattlesI = GetLinkBattleRecordTotalBattles(&records->entries[i]); + s32 totalBattlesJ = GetLinkBattleRecordTotalBattles(&records->entries[j]); + + if (totalBattlesI > totalBattlesJ) + { + struct LinkBattleRecord temp1; + u8 temp2; + + temp1 = records->entries[i]; + records->entries[i] = records->entries[j]; + records->entries[j] = temp1; + + temp2 = records->languages[i]; + records->languages[i] = records->languages[j]; + records->languages[j] = temp2; + } + } + } +} + +static void UpdateLinkBattleRecord(struct LinkBattleRecord *record, s32 battleOutcome) +{ + switch (battleOutcome) + { + case B_OUTCOME_WON: + record->wins++; + if (record->wins > 9999) + record->wins = 9999; + break; + case B_OUTCOME_LOST: + record->losses++; + if (record->losses > 9999) + record->losses = 9999; + break; + case B_OUTCOME_DREW: + record->draws++; + if (record->draws > 9999) + record->draws = 9999; + break; + } +} + +static void UpdateLinkBattleGameStats(s32 battleOutcome) +{ + u8 stat; + + switch (battleOutcome) + { + case B_OUTCOME_WON: + stat = GAME_STAT_LINK_BATTLE_WINS; + break; + case B_OUTCOME_LOST: + stat = GAME_STAT_LINK_BATTLE_LOSSES; + break; + case B_OUTCOME_DREW: + stat = GAME_STAT_LINK_BATTLE_DRAWS; + break; + default: + return; + } + + if (GetGameStat(stat) < 9999) + IncrementGameStat(stat); +} + +static void UpdateLinkBattleRecords(struct LinkBattleRecords *records, const u8 *name, u16 trainerId, s32 battleOutcome, u8 battlerId) +{ + s32 index; + + UpdateLinkBattleGameStats(battleOutcome); + SortLinkBattleRecords(records); + index = FindLinkBattleRecord(records->entries, name, trainerId); + if (index == LINK_B_RECORDS_COUNT) + { + index = LINK_B_RECORDS_COUNT - 1; + ClearLinkBattleRecord(&records->entries[index]); + StringCopyN(records->entries[index].name, name, OT_NAME_LENGTH); + records->entries[index].trainerId = trainerId; + records->languages[index] = gLinkPlayers[battlerId].language; + } + UpdateLinkBattleRecord(&records->entries[index], battleOutcome); + SortLinkBattleRecords(records); +} + +void ClearPlayerLinkBattleRecords(void) +{ + ClearLinkBattleRecords(gSaveBlock1Ptr->linkBattleRecords.entries); +} + +static void IncTrainerCardWins(int battlerId) +{ + u16 *wins = &gTrainerCards[battlerId].linkBattleWins; + (*wins)++; + if (*wins > 9999) + *wins = 9999; +} + +static void IncTrainerCardLosses(int battlerId) +{ + u16 *losses = &gTrainerCards[battlerId].linkBattleLosses; + (*losses)++; + if (*losses > 9999) + *losses = 9999; +} + +static void UpdateTrainerCardWinsLosses(int battlerId) +{ + switch (gBattleOutcome) + { + case B_OUTCOME_WON: + IncTrainerCardWins(BATTLE_OPPOSITE(battlerId)); + IncTrainerCardLosses(battlerId); + break; + case B_OUTCOME_LOST: + IncTrainerCardLosses(BATTLE_OPPOSITE(battlerId)); + IncTrainerCardWins(battlerId); + break; + } +} + +void UpdatePlayerLinkBattleRecords(int battlerId) +{ + if (InUnionRoom() != TRUE) + { + UpdateTrainerCardWinsLosses(battlerId); + UpdateLinkBattleRecords( + &gSaveBlock1Ptr->linkBattleRecords, + gTrainerCards[battlerId].playerName, + gTrainerCards[battlerId].trainerId, + gBattleOutcome, + battlerId); + } +} + +static void PrintLinkBattleWinsLossesDraws(struct LinkBattleRecord *records) +{ + s32 x; + + ConvertIntToDecimalStringN(gStringVar1, GetGameStat(GAME_STAT_LINK_BATTLE_WINS), STR_CONV_MODE_LEFT_ALIGN, 4); + ConvertIntToDecimalStringN(gStringVar2, GetGameStat(GAME_STAT_LINK_BATTLE_LOSSES), STR_CONV_MODE_LEFT_ALIGN, 4); + ConvertIntToDecimalStringN(gStringVar3, GetGameStat(GAME_STAT_LINK_BATTLE_DRAWS), STR_CONV_MODE_LEFT_ALIGN, 4); + StringExpandPlaceholders(gStringVar4, gText_TotalRecordWLD); + + x = GetStringCenterAlignXOffset(1, gStringVar4, 0xD0); + PrintTextOnWindow(gResultsWindowId, 1, gStringVar4, x, 0x11, 0, NULL); +} + +static void PrintLinkBattleRecord(struct LinkBattleRecord *record, u8 y, s32 language) +{ + if (record->wins == 0 && record->losses == 0 && record->draws == 0) + { + // empty slot + PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D84, 8, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D8C, 80, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D8C, 128, (y * 8) + 1, 0, NULL); + PrintTextOnWindow(gResultsWindowId, 1, gUnknown_085B3D8C, 176, (y * 8) + 1, 0, NULL); + } + else + { + StringFillWithTerminator(gStringVar1, 8); + StringCopyN(gStringVar1, record->name, 7); + ConvertInternationalString(gStringVar1, language); + + PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 8, (y * 8) + 1, 0, NULL); + + ConvertIntToDecimalStringN(gStringVar1, record->wins, STR_CONV_MODE_RIGHT_ALIGN, 4); + PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 80, (y * 8) + 1, 0, NULL); + + ConvertIntToDecimalStringN(gStringVar1, record->losses, STR_CONV_MODE_RIGHT_ALIGN, 4); + PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 128, (y * 8) + 1, 0, NULL); + + ConvertIntToDecimalStringN(gStringVar1, record->draws, STR_CONV_MODE_RIGHT_ALIGN, 4); + PrintTextOnWindow(gResultsWindowId, 1, gStringVar1, 176, (y * 8) + 1, 0, NULL); + } +} + +void ShowLinkBattleRecords(void) +{ + s32 i, x; + + gResultsWindowId = AddWindow(&gUnknown_085B3D7C); + NewMenuHelpers_DrawStdWindowFrame(gResultsWindowId, FALSE); + FillWindowPixelBuffer(gResultsWindowId, 0x11); + StringExpandPlaceholders(gStringVar4, gText_PlayersBattleResults); + + x = GetStringCenterAlignXOffset(1, gStringVar4, 208); + PrintTextOnWindow(gResultsWindowId, 1, gStringVar4, x, 1, 0, NULL); + PrintLinkBattleWinsLossesDraws(gSaveBlock1Ptr->linkBattleRecords.entries); + + StringExpandPlaceholders(gStringVar4, gText_WinLoseDraw); + PrintTextOnWindow(gResultsWindowId, 1, gStringVar4, 0, 41, 0, NULL); + + for (i = 0; i < LINK_B_RECORDS_COUNT; i++) + { + PrintLinkBattleRecord(&gSaveBlock1Ptr->linkBattleRecords.entries[i], 7 + (i * 2), gSaveBlock1Ptr->linkBattleRecords.languages[i]); + } + + PutWindowTilemap(gResultsWindowId); + CopyWindowToVram(gResultsWindowId, 3); +} diff --git a/src/new_game.c b/src/new_game.c index 89771e92b..92ca916d6 100644 --- a/src/new_game.c +++ b/src/new_game.c @@ -41,7 +41,7 @@ extern void ResetSecretBases(void); extern void ResetLinkContestBoolean(void); extern void ResetGameStats(void); extern void sub_8052DA8(void); -extern void InitLinkBattleRecords(void); +extern void ClearPlayerLinkBattleRecords(void); extern void ResetPokemonStorageSystem(void); extern void ClearBag(void); extern void NewGameInitPCItems(void); @@ -178,7 +178,7 @@ void NewGameInitData(void) ResetLinkContestBoolean(); ResetGameStats(); ClearAllContestWinnerPics(); - InitLinkBattleRecords(); + ClearPlayerLinkBattleRecords(); InitSeedotSizeRecord(); InitLotadSizeRecord(); gPlayerPartyCount = 0; diff --git a/sym_ewram.txt b/sym_ewram.txt index 9bf04d201..b66116714 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -318,7 +318,7 @@ gUnknown_02039B52: @ 2039B52 gUnknown_02039B54: @ 2039B54 .space 0x4 -gUnknown_02039B58: @ 2039B58 +gTrainerCards: @ 2039B58 .space 0x14 gUnknown_02039B6C: @ 2039B6C