Match sub_8083904 thanks to Seth

This commit is contained in:
DizzyEggg
2025-04-04 12:18:03 +02:00
parent be39215686
commit 4ce333bbb4
6 changed files with 142 additions and 366 deletions

View File

@@ -1,334 +0,0 @@
#include "asm/constants/gba_constants.inc"
#include "asm/macros.inc"
.syntax unified
.text
thumb_func_start sub_808384C
sub_808384C:
push {r4-r7,lr}
mov r7, r9
mov r6, r8
push {r6,r7}
sub sp, 0x4
adds r3, r0, 0
mov r9, r1
movs r0, 0
mov r8, r0
ldr r0, _080838BC
movs r2, 0
ldrsh r1, [r0, r2]
cmp r1, 0x63
beq _080838D8
movs r6, 0
_0808386A:
adds r2, r6, r0
movs r4, 0
ldrsh r1, [r2, r4]
mov r5, r9
movs r7, 0
ldrsh r0, [r5, r7]
adds r5, r1, r0
movs r0, 0x2
ldrsh r1, [r2, r0]
mov r2, r9
movs r4, 0x2
ldrsh r0, [r2, r4]
adds r4, r1, r0
adds r0, r5, 0
adds r1, r4, 0
str r3, [sp]
bl GetTile
adds r1, r0, 0
ldrh r2, [r1]
movs r7, 0x80
lsls r7, 4
adds r0, r7, 0
ands r0, r2
ldr r3, [sp]
cmp r0, 0
bne _080838C0
movs r0, 0x3
ands r0, r2
cmp r0, 0x1
bne _080838C0
ldr r0, [r1, 0x14]
cmp r0, 0
bne _080838C0
ldr r0, [r1, 0x10]
cmp r0, 0
bne _080838C0
strh r5, [r3]
strh r4, [r3, 0x2]
movs r0, 0x1
b _080838DA
.align 2, 0
_080838BC: .4byte gUnknown_80F4468
_080838C0:
adds r6, 0x4
movs r0, 0x1
add r8, r0
mov r2, r8
cmp r2, 0x18
bgt _080838D8
ldr r0, _080838E8
adds r1, r6, r0
movs r4, 0
ldrsh r1, [r1, r4]
cmp r1, 0x63
bne _0808386A
_080838D8:
movs r0, 0
_080838DA:
add sp, 0x4
pop {r3,r4}
mov r8, r3
mov r9, r4
pop {r4-r7}
pop {r1}
bx r1
.align 2, 0
_080838E8: .4byte gUnknown_80F4468
thumb_func_end sub_808384C
thumb_func_start sub_80838EC
sub_80838EC:
push {lr}
adds r2, r0, 0
ldrb r0, [r2]
adds r1, r0, 0
cmp r1, 0x7F
beq _08083900
cmp r1, 0
beq _08083900
subs r0, 0x1
strb r0, [r2]
_08083900:
pop {r0}
bx r0
thumb_func_end sub_80838EC
thumb_func_start sub_8083904
sub_8083904:
push {r4-r7,lr}
mov r7, r10
mov r6, r9
mov r5, r8
push {r5-r7}
sub sp, 0x20
str r0, [sp]
mov r10, r1
ldr r4, [r1, 0x70]
str r4, [sp, 0x4]
adds r5, r4, 0
adds r5, 0x46
ldrb r6, [r5]
mov r0, r10
movs r1, 0x1
bl CheckVariousStatuses2
lsls r0, 24
cmp r0, 0
beq _08083954
ldr r0, _08083950
lsls r2, r6, 2
adds r2, r0
movs r0, 0
ldrsh r1, [r2, r0]
lsls r0, r1, 1
adds r0, r1
mov r1, r10
ldrh r1, [r1, 0x4]
adds r0, r1
ldr r3, [sp]
strh r0, [r3]
movs r4, 0x2
ldrsh r1, [r2, r4]
lsls r0, r1, 1
adds r0, r1
b _08083A6E
.align 2, 0
_08083950: .4byte gAdjacentTileOffsets
_08083954:
ldr r1, [r4, 0x58]
movs r0, 0x1
negs r0, r0
cmp r1, r0
beq _08083960
b _08083A8C
_08083960:
ldrb r0, [r5]
ldr r1, _080839A0
lsls r0, 3
adds r0, r1
ldr r7, [r0]
movs r3, 0x4
ldrsh r2, [r0, r3]
str r2, [sp, 0x8]
movs r2, 0x6
ldrsh r1, [r0, r2]
str r1, [sp, 0xC]
mov r3, r10
movs r0, 0x4
ldrsh r3, [r3, r0]
str r3, [sp, 0x10]
mov r1, r10
movs r2, 0x6
ldrsh r1, [r1, r2]
str r1, [sp, 0x14]
ldr r0, _080839A4
ldr r1, [r0]
ldr r3, _080839A8
adds r0, r1, r3
ldrb r0, [r0]
cmp r0, 0
beq _080839B0
ldr r4, _080839AC
adds r4, r1, r4
str r4, [sp, 0x18]
movs r0, 0x14
b _080839D0
.align 2, 0
_080839A0: .4byte gUnknown_80F4CC4
_080839A4: .4byte gDungeon
_080839A8: .4byte 0x000037fc
_080839AC: .4byte 0x000135cc
_080839B0:
ldrb r0, [r4, 0x6]
cmp r0, 0
bne _080839C8
ldr r2, _080839C4
adds r2, r1, r2
str r2, [sp, 0x18]
movs r3, 0x10
str r3, [sp, 0x1C]
b _080839D2
.align 2, 0
_080839C4: .4byte 0x0001358c
_080839C8:
ldr r4, _08083A78
adds r4, r1, r4
str r4, [sp, 0x18]
movs r0, 0x4
_080839D0:
str r0, [sp, 0x1C]
_080839D2:
movs r1, 0
ldrsh r0, [r7, r1]
cmp r0, 0x63
beq _08083A46
_080839DA:
movs r2, 0
ldrsh r0, [r7, r2]
ldr r3, [sp, 0x8]
muls r0, r3
ldr r4, [sp, 0x10]
adds r4, r0
mov r9, r4
movs r1, 0x2
ldrsh r0, [r7, r1]
ldr r2, [sp, 0xC]
muls r0, r2
ldr r3, [sp, 0x14]
adds r3, r0
mov r8, r3
movs r6, 0
ldr r4, [sp, 0x1C]
cmp r6, r4
bge _08083A3C
ldr r5, [sp, 0x18]
_08083A00:
ldr r4, [r5]
adds r0, r4, 0
bl EntityIsValid
lsls r0, 24
cmp r0, 0
beq _08083A32
movs r1, 0x4
ldrsh r0, [r4, r1]
cmp r0, r9
bne _08083A32
movs r2, 0x6
ldrsh r0, [r4, r2]
cmp r0, r8
bne _08083A32
mov r0, r10
adds r1, r4, 0
movs r2, 0
movs r3, 0
bl GetTreatmentBetweenMonsters
lsls r0, 24
lsrs r0, 24
cmp r0, 0x1
beq _08083A80
_08083A32:
adds r5, 0x4
adds r6, 0x1
ldr r3, [sp, 0x1C]
cmp r6, r3
blt _08083A00
_08083A3C:
adds r7, 0x4
movs r4, 0
ldrsh r0, [r7, r4]
cmp r0, 0x63
bne _080839DA
_08083A46:
ldr r2, _08083A7C
ldr r1, [sp, 0x4]
adds r1, 0x46
ldrb r0, [r1]
lsls r0, 2
adds r0, r2
movs r3, 0
ldrsh r0, [r0, r3]
lsls r0, 1
mov r4, r10
ldrh r4, [r4, 0x4]
adds r0, r4
ldr r3, [sp]
strh r0, [r3]
ldrb r0, [r1]
lsls r0, 2
adds r0, r2
movs r4, 0x2
ldrsh r0, [r0, r4]
lsls r0, 1
_08083A6E:
mov r1, r10
ldrh r1, [r1, 0x6]
adds r0, r1
strh r0, [r3, 0x2]
b _08083A9E
.align 2, 0
_08083A78: .4byte 0x0001357c
_08083A7C: .4byte gAdjacentTileOffsets
_08083A80:
mov r3, r9
ldr r2, [sp]
strh r3, [r2]
mov r4, r8
strh r4, [r2, 0x2]
b _08083A9E
_08083A8C:
ldr r0, [sp, 0x4]
adds r0, 0x58
ldrh r0, [r0]
ldr r1, [sp]
strh r0, [r1]
ldr r0, [sp, 0x4]
adds r0, 0x5A
ldrh r0, [r0]
strh r0, [r1, 0x2]
_08083A9E:
add sp, 0x20
pop {r3-r5}
mov r8, r3
mov r9, r4
mov r10, r5
pop {r4-r7}
pop {r0}
bx r0
thumb_func_end sub_8083904
.align 2, 0

View File

@@ -0,0 +1,15 @@
#ifndef GUARD_DUNGEON_POS_DATA_H
#define GUARD_DUNGEON_POS_DATA_H
#include "structs/str_position.h"
#include "constants/direction.h"
struct Struct80F4CC4 {
const DungeonPos *posArray;
s16 xOffset;
s16 yOffset;
};
extern const struct Struct80F4CC4 gUnknown_80F4CC4[NUM_DIRECTIONS];
#endif

View File

@@ -276,7 +276,6 @@ SECTIONS {
src/trap.o(.text);
src/dungeon_serializer.o(.text);
src/dungeon_range.o(.text);
asm/code_8083654.o(.text);
src/dungeon_8083AB0.o(.text);
src/dungeon_music.o(.text);
src/dungeon_random.o(.text);

View File

@@ -41,18 +41,17 @@ static const u8 sUnknown_80F42F0[256] = {
};
static const u8 gUnknown_80F43F0[PASSWORD_BUFFER_SIZE] = {
0x0d, 0x07, 0x19, 0x0f, 0x04, 0x1d, 0x2a, 0x31, 0x08, 0x13,
0x2d, 0x18, 0x0e, 0x1a, 0x1b, 0x29, 0x01, 0x20, 0x21,
0x22, 0x11, 0x33, 0x26, 0x00, 0x35, 0x0a, 0x2b, 0x1f,
0x12, 0x23, 0x2c, 0x17, 0x27, 0x10, 0x1c, 0x30, 0x0b,
0x02, 0x24, 0x09, 0x32, 0x05, 0x28, 0x34, 0x2e, 0x03,
0x1e, 0x0c, 0x25, 0x14, 0x2f, 0x16, 0x06, 0x15
0x0d, 0x07, 0x19, 0x0f, 0x04, 0x1d, 0x2a, 0x31, 0x08, 0x13,
0x2d, 0x18, 0x0e, 0x1a, 0x1b, 0x29, 0x01, 0x20, 0x21,
0x22, 0x11, 0x33, 0x26, 0x00, 0x35, 0x0a, 0x2b, 0x1f,
0x12, 0x23, 0x2c, 0x17, 0x27, 0x10, 0x1c, 0x30, 0x0b,
0x02, 0x24, 0x09, 0x32, 0x05, 0x28, 0x34, 0x2e, 0x03,
0x1e, 0x0c, 0x25, 0x14, 0x2f, 0x16, 0x06, 0x15
};
static const u8 gUnknown_80F4426[34] = {
0x0c, 0x06, 0x13, 0x08, 0x04, 0x0d, 0x0f, 0x09, 0x10, 0x02,
0x14, 0x12, 0x00, 0x15, 0x0b, 0x05, 0x17, 0x03, 0x11,
0x0a, 0x01, 0x0e, 0x16, 0x07, 0x00, 0x00,0x70, 0x6b,
0x73, 0x64, 0x69, 0x72, 0x30, 0x00
static const u8 gUnknown_80F4426[] = {
0x0c, 0x06, 0x13, 0x08, 0x04, 0x0d, 0x0f, 0x09, 0x10, 0x02,
0x14, 0x12, 0x00, 0x15, 0x0b, 0x05, 0x17, 0x03, 0x11,
0x0a, 0x01, 0x0e, 0x16, 0x07, 0x00, 0x00
};

View File

@@ -1,5 +1,6 @@
#include "global.h"
#include "structs/str_position.h"
#include "globaldata.h"
#include "dungeon_pos_data.h"
const DungeonPos gAdjacentTileOffsets[] = {
{0, 1},
@@ -562,21 +563,15 @@ static const DungeonPos gUnknown_80F4B30[101] = {
{99, 99},
};
struct Struct80F4CC4 {
const DungeonPos *posArray;
s16 unk4;
s16 unk6;
};
const struct Struct80F4CC4 gUnknown_80F4CC4[] = {
{gUnknown_80F4810, 1, 1},
{gUnknown_80F4B30, 1, 1},
{gUnknown_80F499C, 1, 1},
{gUnknown_80F4B30, 1, -1},
{gUnknown_80F4810, -1, -1},
{gUnknown_80F4B30, -1, -1},
{gUnknown_80F499C, -1, -1},
{gUnknown_80F4B30, -1, 1},
const struct Struct80F4CC4 gUnknown_80F4CC4[NUM_DIRECTIONS] = {
[DIRECTION_SOUTH] = {gUnknown_80F4810, 1, 1},
[DIRECTION_SOUTHEAST] = {gUnknown_80F4B30, 1, 1},
[DIRECTION_EAST] = {gUnknown_80F499C, 1, 1},
[DIRECTION_NORTHEAST] = {gUnknown_80F4B30, 1, -1},
[DIRECTION_NORTH] = {gUnknown_80F4810, -1, -1},
[DIRECTION_NORTHWEST] = {gUnknown_80F4B30, -1, -1},
[DIRECTION_WEST] = {gUnknown_80F499C, -1, -1},
[DIRECTION_SOUTHWEST] = {gUnknown_80F4B30, -1, 1},
};
const s32 gFaceDirectionIncrements[] = {0, 1, -1, 2, -2, 3, -3, 4, 0, -1, 1, -2, 2, -3, 3, 4};

View File

@@ -3,6 +3,8 @@
#include "dungeon_range.h"
#include "dungeon_leader.h"
#include "dungeon_random.h"
#include "dungeon_logic.h"
#include "dungeon_pos_data.h"
#include "dungeon_util.h"
#include "sprite.h"
#include "structs/str_dungeon.h"
@@ -10,6 +12,8 @@
#include "structs/map.h"
#include "structs/str_202ED28.h"
extern const DungeonPos gUnknown_80F4468[];
EWRAM_INIT Entity *gLeaderPointer = NULL;
bool8 IsPositionActuallyInSight(DungeonPos *pos1, DungeonPos *pos2)
@@ -262,7 +266,7 @@ EntityInfo* GetLeaderInfo(void)
return GetEntInfo(GetLeader());
}
bool8 sub_8083660(DungeonPos *posArg)
bool8 sub_8083660(DungeonPos *posDst)
{
struct PositionU8 positions[DUNGEON_MAX_SIZE_X_MUL_Y];
s32 yLoop, xLoop;
@@ -338,8 +342,8 @@ bool8 sub_8083660(DungeonPos *posArg)
if (count != 0) {
s32 posId = DungeonRandInt(count);
posArg->x = positions[posId].x;
posArg->y = positions[posId].y;
posDst->x = positions[posId].x;
posDst->y = positions[posId].y;
return TRUE;
}
}
@@ -347,4 +351,102 @@ bool8 sub_8083660(DungeonPos *posArg)
return FALSE;
}
// all of code_8083654.s belongs to this file
bool8 sub_808384C(DungeonPos *posDst, const DungeonPos *posSrc)
{
s32 i;
s32 x, y;
const Tile *tile;
for (i = 0; i < 25; i++) {
if (gUnknown_80F4468[i].x == 99)
break;
x = gUnknown_80F4468[i].x + posSrc->x;
y = gUnknown_80F4468[i].y + posSrc->y;
tile = GetTile(x, y);
if (!(tile->terrainType & TERRAIN_TYPE_UNK_x800)
&& GetTerrainType(tile) == TERRAIN_TYPE_NORMAL
&& tile->object == NULL
&& tile->monster == NULL)
{
posDst->x = x;
posDst->y = y;
return TRUE;
}
}
return FALSE;
}
void sub_80838EC(u8 *a0)
{
if (*a0 == 0x7F)
return;
if (*a0 != 0) {
*a0 -= 1;
}
}
void sub_8083904(struct DungeonPos *posDst, struct Entity *entityArg)
{
struct EntityInfo *info;
s32 xOffset, yOffset;
s32 pokeX, pokeY;
s32 i;
const struct DungeonPos *posArray;
Entity **possibleTargets;
s32 maxTargets;
s32 direction;
info = GetEntInfo(entityArg);
direction = info->action.direction;
if (CheckVariousStatuses2(entityArg, TRUE)) {
posDst->x = (gAdjacentTileOffsets[direction].x * 3) + entityArg->pos.x;
posDst->y = (gAdjacentTileOffsets[direction].y * 3) + entityArg->pos.y;
}
else if (info->action.itemTargetPosition.x == -1 && info->action.itemTargetPosition.y == -1) {
s32 strId = info->action.direction;
posArray = gUnknown_80F4CC4[strId].posArray;
xOffset = gUnknown_80F4CC4[strId].xOffset;
yOffset = gUnknown_80F4CC4[strId].yOffset;
pokeX = entityArg->pos.x;
pokeY = entityArg->pos.y;
if (gDungeon->decoyIsActive) {
possibleTargets = gDungeon->activePokemon;
maxTargets = DUNGEON_MAX_POKEMON;
}
else if (!info->isNotTeamMember) {
possibleTargets = gDungeon->wildPokemon;
maxTargets = DUNGEON_MAX_WILD_POKEMON;
}
else {
possibleTargets = gDungeon->teamPokemon;
maxTargets = MAX_TEAM_MEMBERS;
}
while (posArray->x != 99) {
s32 x = pokeX + (xOffset * posArray->x);
s32 y = pokeY + (yOffset * posArray->y);
for (i = 0; i < maxTargets; i++) {
Entity *entity = possibleTargets[i];
if (EntityIsValid(entity)
&& entity->pos.x == x
&& entity->pos.y == y
&& GetTreatmentBetweenMonsters(entityArg,entity,FALSE,FALSE) == 1)
{
posDst->x = x;
posDst->y = y;
return;
}
}
posArray++;
}
posDst->x = (gAdjacentTileOffsets[info->action.direction].x * 2) + entityArg->pos.x;
posDst->y = (gAdjacentTileOffsets[info->action.direction].y * 2) + entityArg->pos.y;
}
else {
posDst->x = info->action.itemTargetPosition.x;
posDst->y = info->action.itemTargetPosition.y;
}
}