From 2e588fd4d73a123ec41c92f2d7d3e70225c31c9d Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 29 Mar 2019 22:22:26 -0400 Subject: [PATCH] through sub_80181DC --- asm/union_room.s | 136 --------------------------------------- include/event_obj_lock.h | 1 + include/rom_8011DC0.h | 8 +-- src/union_room.c | 103 +++++++++++++++++++++++++---- 4 files changed, 95 insertions(+), 153 deletions(-) diff --git a/asm/union_room.s b/asm/union_room.s index 9bbbf52e5..a83ae2d30 100755 --- a/asm/union_room.s +++ b/asm/union_room.s @@ -5,142 +5,6 @@ .text - thumb_func_start sub_8018120 -sub_8018120: @ 8018120 - push {r4-r7,lr} - mov r7, r8 - push {r7} - lsls r1, 24 - movs r2, 0 - mov r8, r2 - cmp r1, 0 - bne _0801813E - ldrh r7, [r0, 0xA] - ldr r6, [r0, 0x4] - b _08018142 -_08018136: - lsls r0, r5, 16 - lsrs r0, 16 - mov r8, r0 - b _08018176 -_0801813E: - ldrh r7, [r0, 0xE] - ldr r6, [r0, 0x14] -_08018142: - movs r5, 0 - b _0801816E -_08018146: - movs r0, 0x64 - adds r1, r5, 0 - muls r1, r0 - ldr r0, =gPlayerParty - adds r4, r1, r0 - adds r0, r4, 0 - movs r1, 0 - bl GetMonData - cmp r0, r6 - bne _0801816C - adds r0, r4, 0 - movs r1, 0x41 - bl GetMonData - lsls r0, 16 - lsrs r0, 16 - cmp r0, r7 - beq _08018136 -_0801816C: - adds r5, 0x1 -_0801816E: - ldr r0, =gPlayerPartyCount - ldrb r0, [r0] - cmp r5, r0 - blt _08018146 -_08018176: - mov r0, r8 - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r1} - bx r1 - .pool - thumb_func_end sub_8018120 - - thumb_func_start sub_801818C -sub_801818C: @ 801818C - push {r4,lr} - adds r4, r0, 0 - bl sub_80173B0 - bl ScriptContext2_Disable - bl sub_8098524 - ldr r1, =gUnknown_02022C2C - movs r0, 0 - strb r0, [r1] - cmp r4, 0 - beq _080181BC - ldr r2, =gUnknown_02022C40 - ldrh r0, [r2, 0x2] - ldrh r1, [r2, 0xA] - ldrh r2, [r2, 0xC] - bl sub_8010FCC - movs r0, 0x40 - movs r1, 0 - movs r2, 0 - bl sub_8011090 -_080181BC: - pop {r4} - pop {r0} - bx r0 - .pool - thumb_func_end sub_801818C - - thumb_func_start sub_80181CC -sub_80181CC: @ 80181CC - push {lr} - bl ScriptContext2_Enable - bl ScriptFreezeEventObjects - pop {r0} - bx r0 - thumb_func_end sub_80181CC - - thumb_func_start sub_80181DC -sub_80181DC: @ 80181DC - push {r4,lr} - movs r3, 0x80 - movs r2, 0 - ldr r4, [r0, 0xC] -_080181E4: - lsls r0, r2, 3 - subs r0, r2 - lsls r0, 2 - adds r1, r4, r0 - ldrb r0, [r1, 0x18] - lsls r0, 31 - cmp r0, 0 - beq _0801820C - ldrb r0, [r1, 0xB] - lsls r0, 31 - lsrs r0, 31 - lsls r0, 3 - orrs r3, r0 - ldrb r1, [r1, 0x2] - movs r0, 0x7 - ands r0, r1 - orrs r3, r0 - lsls r0, r3, 24 - lsrs r3, r0, 24 - b _08018216 -_0801820C: - adds r0, r2, 0x1 - lsls r0, 24 - lsrs r2, r0, 24 - cmp r2, 0x3 - bls _080181E4 -_08018216: - adds r0, r3, 0 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_80181DC - thumb_func_start sub_8018220 sub_8018220: @ 8018220 push {r4-r7,lr} diff --git a/include/event_obj_lock.h b/include/event_obj_lock.h index 2f09ad36a..037c0080d 100644 --- a/include/event_obj_lock.h +++ b/include/event_obj_lock.h @@ -8,5 +8,6 @@ void LockSelectedEventObject(void); void sub_8098630(void); bool8 sub_8098734(void); void ScriptUnfreezeEventObjects(void); +void sub_8098524(void); #endif // GUARD_EVENT_OBJ_LOCK_H diff --git a/include/rom_8011DC0.h b/include/rom_8011DC0.h index 4341185a3..f994f846e 100644 --- a/include/rom_8011DC0.h +++ b/include/rom_8011DC0.h @@ -135,12 +135,12 @@ union UnkUnion_Main struct TradeUnkStruct { u16 field_0; - u16 field_2; - u32 field_4; + u16 type; + u32 playerPersonality; u8 field_8; u8 field_9; - u16 field_A; - u16 field_C; + u16 playerSpecies; + u16 playerLevel; u16 species; u16 level; u16 field_12; diff --git a/src/union_room.c b/src/union_room.c index d3a9c95a0..59b38e6cd 100644 --- a/src/union_room.c +++ b/src/union_room.c @@ -41,6 +41,7 @@ #include "mevent.h" #include "dynamic_placeholder_text_util.h" #include "rom_8011DC0.h" +#include "event_obj_lock.h" EWRAM_DATA u8 gUnknown_02022C20[12] = {}; EWRAM_DATA u8 gUnknown_02022C2C = 0; @@ -3341,7 +3342,7 @@ void sub_80156E0(u8 taskId) break; case 2: sub_8010F84(0x40, 0, 0); - sub_8010FCC(gUnknown_02022C40.field_2, gUnknown_02022C40.field_A, gUnknown_02022C40.field_C); + sub_8010FCC(gUnknown_02022C40.type, gUnknown_02022C40.playerSpecies, gUnknown_02022C40.playerLevel); sub_800B488(); OpenLink(); sub_8011C84(); @@ -3936,14 +3937,14 @@ void sub_80156E0(u8 taskId) sub_801568C(gUnknown_082EF4FC); break; default: - gUnknown_02022C40.field_2 = var5; + gUnknown_02022C40.type = var5; data->state = 55; break; } } break; case 55: - sub_8010FCC(gUnknown_02022C40.field_2, gUnknown_02022C40.field_A, gUnknown_02022C40.field_C); + sub_8010FCC(gUnknown_02022C40.type, gUnknown_02022C40.playerSpecies, gUnknown_02022C40.playerLevel); sub_801568C(gUnknown_082EF520); break; case 44: @@ -5112,8 +5113,8 @@ s32 sub_8017EA0(u8 *dst, u32 gender, u16 *arg2, struct UnkStruct_URoom *arg3) result = 1; break; case 0x44: - ConvertIntToDecimalStringN(arg3->field_58 + 0x00, gUnknown_02022C40.field_C, STR_CONV_MODE_LEFT_ALIGN, 3); - StringCopy(arg3->field_58 + 0x10, gSpeciesNames[gUnknown_02022C40.field_A]); + ConvertIntToDecimalStringN(arg3->field_58 + 0x00, gUnknown_02022C40.playerLevel, STR_CONV_MODE_LEFT_ALIGN, 3); + StringCopy(arg3->field_58 + 0x10, gSpeciesNames[gUnknown_02022C40.playerSpecies]); for (i = 0; i < 4; i++) { if (gUnknown_03007890->unk_14[i].unk_04 == 2) @@ -5203,10 +5204,10 @@ bool32 sub_8018024(void) void sub_801807C(struct TradeUnkStruct *arg0) { arg0->field_0 = 0; - arg0->field_2 = 0; - arg0->field_4 = 0; - arg0->field_A = 0; - arg0->field_C = 0; + arg0->type = 0; + arg0->playerPersonality = 0; + arg0->playerSpecies = 0; + arg0->playerLevel = 0; arg0->species = 0; arg0->level = 0; arg0->personality = 0; @@ -5219,10 +5220,10 @@ void sub_8018090(void) bool32 sub_80180A0(u32 monId, struct TradeUnkStruct *arg1) { - arg1->field_A = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES2); - arg1->field_C = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); - arg1->field_4 = GetMonData(&gPlayerParty[monId], MON_DATA_PERSONALITY); - if (arg1->field_A == SPECIES_EGG) + arg1->playerSpecies = GetMonData(&gPlayerParty[monId], MON_DATA_SPECIES2); + arg1->playerLevel = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); + arg1->playerPersonality = GetMonData(&gPlayerParty[monId], MON_DATA_PERSONALITY); + if (arg1->playerSpecies == SPECIES_EGG) { return TRUE; } @@ -5238,3 +5239,79 @@ void sub_80180E8(u32 monId, struct TradeUnkStruct *arg1) arg1->level = GetMonData(&gPlayerParty[monId], MON_DATA_LEVEL); arg1->personality = GetMonData(&gPlayerParty[monId], MON_DATA_PERSONALITY); } + +u32 sub_8018120(struct TradeUnkStruct *arg0, u8 multiplayerId) +{ + u16 response = 0; + u16 species; + u32 personality; + u32 cur_personality; + u16 cur_species; + s32 i; + + if (multiplayerId == 0) + { + species = arg0->playerSpecies; + personality = arg0->playerPersonality; + } + else + { + species = arg0->species; + personality = arg0->personality; + } + + for (i = 0; i < gPlayerPartyCount; i++) + { + cur_personality = GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY); + if (cur_personality != personality) + { + continue; + } + cur_species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2); + if (cur_species != species) + { + continue; + } + response = i; + break; + } + + return response; +} + +void sub_801818C(bool32 arg0) +{ + sub_80173B0(); + ScriptContext2_Disable(); + sub_8098524(); + gUnknown_02022C2C = 0; + if (arg0) + { + sub_8010FCC(gUnknown_02022C40.type, gUnknown_02022C40.playerSpecies, gUnknown_02022C40.playerLevel); + sub_8011090(0x40, 0, 0); + } +} + +void sub_80181CC(void) +{ + ScriptContext2_Enable(); + ScriptFreezeEventObjects(); +} + +u8 sub_80181DC(struct UnkStruct_URoom *arg0) +{ + u8 retVal = 0x80; + u8 i; + + for (i = 0; i < 4; i++) + { + if (arg0->field_C->arr[i].unk18) + { + retVal |= arg0->field_C->arr[i].unk0.field_0.playerGender << 3; + retVal |= arg0->field_C->arr[i].unk0.field_0.unk_00.playerTrainerId[0] & 7; + break; + } + } + + return retVal; +}