CreateRandomDrop and droptables

This commit is contained in:
Henny022p 2022-02-03 05:44:50 +01:00
parent 67d369c53b
commit bbc3a88415
18 changed files with 2563 additions and 1434 deletions

1254
asm/code_08001A7C.s Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -209,7 +209,7 @@ sub_08081790: @ 0x08081790
adds r1, r1, r0
ldrb r1, [r1]
adds r0, r2, #0
bl sub_0805457C
bl CreateRandomItemDrop
b _080817C6
.align 2, 0
_080817B0: .4byte gUnk_0811EC64
@ -231,7 +231,7 @@ _080817C8: .4byte gUnk_0811EC24
sub_080817CC: @ 0x080817CC
push {lr}
movs r1, #9
bl sub_0805457C
bl CreateRandomItemDrop
pop {pc}
.align 2, 0
@ -239,7 +239,7 @@ sub_080817CC: @ 0x080817CC
sub_080817D8: @ 0x080817D8
push {lr}
movs r1, #0xd
bl sub_0805457C
bl CreateRandomItemDrop
pop {pc}
.align 2, 0
@ -247,7 +247,7 @@ sub_080817D8: @ 0x080817D8
sub_080817E4: @ 0x080817E4
push {lr}
movs r1, #0xe
bl sub_0805457C
bl CreateRandomItemDrop
pop {pc}
.align 2, 0
@ -255,7 +255,7 @@ sub_080817E4: @ 0x080817E4
sub_080817F0: @ 0x080817F0
push {lr}
movs r1, #1
bl sub_0805457C
bl CreateRandomItemDrop
pop {pc}
.align 2, 0

View File

@ -214,7 +214,7 @@ sub_08087640: @ 0x08087640
_08087676:
adds r0, r4, #0
adds r1, r2, #0
bl sub_0805457C
bl CreateRandomItemDrop
strh r5, [r4, #0x2e]
strh r6, [r4, #0x32]
pop {r4, r5, r6, pc}

View File

@ -43,7 +43,7 @@ sub_08093D88: @ 0x08093D88
_08093DAC:
adds r0, r4, #0
movs r1, #4
bl sub_0805457C
bl CreateRandomItemDrop
cmp r0, #0
bne _08093DBC
movs r0, #2

View File

@ -110,7 +110,7 @@ _08084582:
beq _08084594
ldrb r1, [r4, #1]
adds r0, r5, #0
bl sub_0805457C
bl CreateRandomItemDrop
_08084594:
ldrb r1, [r5, #0xb]
movs r0, #0x20

View File

@ -55,119 +55,16 @@
"start": 4484,
"size": 64
},
{
"path": "code_080011C4/gUnk_0800137C.bin",
"start": 4988,
"size": 192
},
{
"path": "code_080011C4/gUnk_0800143C.bin",
"start": 5180,
"size": 384
},
{
"path": "code_080011C4/gUnk_080015BC.bin",
"start": 5564,
"size": 96
},
{
"path": "code_080011C4/gUnk_0800161C.bin",
"start": 5660,
"size": 230
},
{
"path": "code_080011C4/gUnk_0800161C_1_EU.bin",
"variants": [
"EU"
],
"starts": {
"EU": 5962
},
"size": 20
},
{
"path": "code_080011C4/gUnk_0800161C_2_USA-JP-DEMO_USA-DEMO_JP.bin",
"variants": [
"USA",
"JP",
"DEMO_USA",
"DEMO_JP"
],
"start": 5890,
"size": 20
},
{
"path": "code_080011C4/gUnk_0800161C_3.bin",
"start": 5910,
"size": 398
},
{
"path": "code_080011C4/gUnk_0800161C_4_EU.bin",
"variants": [
"EU"
],
"starts": {
"EU": 6380
},
"size": 126
},
{
"path": "code_080011C4/gUnk_0800161C_5_USA-JP-DEMO_USA-DEMO_JP.bin",
"variants": [
"USA",
"JP",
"DEMO_USA",
"DEMO_JP"
],
"start": 6308,
"size": 94
},
{
"offsets": {
"EU": 104
}
},
{
"path": "code_080011C4/gUnk_0800161C_6.bin",
"start": 6402,
"size": 26
},
{
"path": "code_080011C4/gUnk_0800191C_EU.bin",
"variants": [
"EU"
],
"starts": {
"EU": 6532
},
"size": 143
},
{
"path": "code_080011C4/gUnk_0800191C_1_USA-JP-DEMO_USA-DEMO_JP.bin",
"variants": [
"USA",
"JP",
"DEMO_USA",
"DEMO_JP"
],
"start": 6428,
"size": 79
},
{
"offsets": {
"EU": 168
}
},
{
"path": "code_080011C4/gUnk_0800191C_2.bin",
"start": 6507,
"size": 177
},
{
"path": "code_080011C4/gUnk_08001A1C.bin",
"start": 6684,
"size": 96
},
{
"path": "code_080011C4/gUnk_08001C5C.bin",
"start": 7260,

34
include/droptables.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef TMC_DROPTABLES_H
#define TMC_DROPTABLES_H
typedef union {
struct {
s16 none;
s16 rupee1;
s16 rupee5;
s16 rupee20;
s16 hearts;
s16 fairy;
s16 bombs;
s16 arrows;
s16 mysteriousShells;
s16 kinstoneGreen;
s16 kinstoneBlue;
s16 kinstoneRed;
s16 none2;
s16 none3;
s16 none4;
s16 none5;
} s;
s16 a[16];
} Droptable;
static_assert(sizeof(Droptable) == 0x20);
extern const Droptable gUnk_0800137C[];
extern const Droptable gUnk_0800143C[];
extern const Droptable gUnk_080015BC[];
extern const Droptable gUnk_0800161C[];
extern const Droptable gUnk_0800191C[];
extern const Droptable gUnk_08001A1C[];
#endif // TMC_DROPTABLES_H

View File

@ -168,7 +168,7 @@ extern void sub_080044AE(Entity*, u32, u32);
extern void sub_0801AF18(u8*, u32, u32);
extern void sub_0807B9B8(s32, s32, s32);
extern void sub_08000148(u32, u32, u32);
extern void sub_0805457C(Entity*, s32);
extern void CreateRandomItemDrop(Entity*, s32);
extern Entity* sub_080A2A3C(Entity*, u32, u32, u32);
extern void sub_0806FCF4(Entity*, s32, s32, s32);
extern u32 sub_080041DC(Entity*, u32, u32);

View File

@ -143,6 +143,12 @@ typedef enum {
ITEM_SKILL_FAST_SPIN,
ITEM_SKILL_FAST_SPLIT,
ITEM_SKILL_LONG_SPIN,
// these are not actually item ids but special values used by item drops for example
ITEM_KINSTONE_GREEN = 0xfc,
ITEM_KINSTONE_BLUE,
ITEM_KINSTONE_RED,
ITEM_ENEMY_BEETLE
} Item;
#endif

View File

@ -255,7 +255,8 @@ typedef struct {
/*0x0c*/ u8 itemButtons[2];
/*0x0e*/ u8 bottles[4];
/*0x12*/ u8 effect;
/*0x13*/ u8 filler3[5];
/*0x13*/ u8 hasAllFigurines;
/*0x14*/ u8 filler3[4];
/*0x18*/ u16 rupees;
/*0x1a*/ u16 field_0x1a;
/*0x1c*/ u16 charmTimer;

View File

@ -283,6 +283,8 @@ SECTIONS {
asm/code_08000F10.o(.text);
data/data_08000F54.o(.rodata);
asm/enemy.o(.text);
src/droptables.o(.rodata);
asm/code_08001A7C.o(.text);
data/gfx/sprite_ptrs.o(.rodata);
asm/code_08003FC4.o(.text);
asm/code_080043E8.o(.text);

View File

@ -8,6 +8,7 @@
#include "item.h"
#include "object.h"
#include "enemy.h"
#include "droptables.h"
typedef struct {
u8 unk;
@ -18,9 +19,8 @@ extern struct_080FD5B4 gUnk_080FD5B4[];
extern u8 gUnk_0200AF13;
extern u8 gUnk_0200AF14;
extern u32 gUnk_080015BC;
extern u8 gUnk_080FE1C6[];
extern u32 gUnk_02034398;
extern Droptable gUnk_02034398;
extern void (*const gUnk_080FE2A0[])(void);
void ForceEquipItem(u32, u8);
@ -79,7 +79,6 @@ void PutItemOnSlot(u32 itemID) {
ASM_FUNC("asm/non_matching/ForceEquipItem.inc", void ForceEquipItem(u32 itemID, u8 itemSlot))
u32 SetBottleContents(u32 itemID, u32 bottleIndex) {
if (bottleIndex > 3) {
bottleIndex = 0;
if (gSave.stats.bottles[0] != 0x20) {
@ -159,7 +158,7 @@ NONMATCH("asm/non_matching/sub_08054524.inc", void sub_08054524(void)) {
bVar1 = 0;
}
MemCopy(&gUnk_080015BC + gUnk_080FE1C6[bVar1] * 0x8, &gUnk_02034398, 0x20);
MemCopy(&gUnk_080015BC[0] + gUnk_080FE1C6[bVar1] * 0x8, &gUnk_02034398, 0x20);
}
END_NONMATCH
@ -171,68 +170,162 @@ void sub_08054570(void) {
gRoomVars.field_0x2 = 0;
}
ASM_FUNC("asm/non_matching/sub_0805457C.inc", u32 sub_0805457C(u32 arg0, u32 arg1));
// BUG?
extern const Droptable gUnk_080014e4[];
extern void sub_08000F14(s16*, const s16*, const s16*, const s16*);
extern u32 sub_08000F2C(s16*, const s16*, const s16*, const s16*);
u32 CreateItemDrop(Entity* arg0, u32 itemID, u32 itemParameter);
u32 CreateRandomItemDrop(Entity* arg0, u32 arg1) {
extern const u8 gUnk_080FE1B4[]/* = {
ITEM_NONE, ITEM_RUPEE1, ITEM_RUPEE5, ITEM_RUPEE20, ITEM_HEART, ITEM_FAIRY,
ITEM_BOMBS5, ITEM_ARROWS5, ITEM_SHELLS, ITEM_KINSTONE_GREEN, ITEM_KINSTONE_BLUE, ITEM_KINSTONE_RED,
ITEM_ENEMY_BEETLE, ITEM_NONE, ITEM_NONE, ITEM_NONE, ITEM_NONE, ITEM_NONE,
}*/;
int r0, r1, r2, r4, r5;
u32 r3;
const Droptable *ptr2, *ptr3, *ptr4;
Droptable s0;
r3 = arg1;
if (gRoomVars.field_0x2 != 1) {
ptr2 = &gUnk_08001A1C[0];
ptr4 = 0;
switch (r3) {
case 1 ... 12:
ptr4 = &gUnk_0800137C[r3];
break;
#ifndef EU
case 24:
case 25:
r0 = gRoomVars.unk2;
ptr4 = &gUnk_0800191C[0];
if (r0) {
ptr4++;
}
break;
#endif
case 16 ... 23:
#ifdef EU
case 24:
#endif
ptr2 = &gUnk_0800161C[r3];
case 15:
ptr4 = &gUnk_02034398;
break;
case 0:
default:
break;
}
if (ptr4 != 0) {
if ((r1 = gSave.stats.unkB) == 0) {
ptr3 = &gUnk_08001A1C[0];
} else {
#ifdef EU
ptr3 = &gUnk_0800143C[r1+3];
#else
ptr3 = &gUnk_0800143C[r1];
#endif
}
sub_08000F14(s0.a, ptr4->a, ptr2->a, ptr3->a);
if (gSave.stats.health <= 8) {
s0.s.hearts += 5;
}
if (gSave.stats.bombCount == 0) {
s0.s.bombs += 3;
}
if (gSave.stats.arrowCount == 0) {
s0.s.arrows += 3;
}
if (gSave.stats.rupees <= 10) {
s0.s.rupee5 += 1;
}
ptr2 = &gUnk_08001A1C[0];
r0 = gSave.stats.hasAllFigurines;
ptr3 = ptr2;
if (r0 != 0) {
ptr2++;
}
if (gSave.fillerD0[0x46] != 0) {
ptr3 += 2;
}
r4 = sub_08000F2C(s0.a, s0.a, ptr2->a, ptr3->a);
r2 = Random();
r5 = (r2 >> 0x18);
r5 &= 0xF;
r2 = r2 % r4;
{
u32 r3;
for (r3 = 0, r1 = 0; r3 < 0x10; r3++, r5 = (r5 + 1) & 0xF) {
if ((r1 += s0.a[r5]) > r2) {
break;
}
}
}
r1 = gUnk_080FE1B4[r5];
if (r1 != 0) {
r2 = 0;
return CreateItemDrop(arg0, r1, r2);
}
}
}
return 0;
}
u32 CreateItemDrop(Entity* arg0, u32 itemID, u32 itemParameter) {
u32 prereqID;
u32 adjustedParam = itemParameter;
u32 uVar1;
Entity* itemEntity;
switch (itemID) {
case 0xff:
if (!GetInventoryValue(0x1)) {
return 0;
case ITEM_ENEMY_BEETLE:
if (!GetInventoryValue(ITEM_SMITH_SWORD)) {
return ITEM_NONE;
}
break;
case 0x5d:
if (!GetInventoryValue(0x65)) {
return 0;
case ITEM_BOMBS5:
if (!GetInventoryValue(ITEM_BOMBBAG)) {
return ITEM_NONE;
}
break;
case 0x5e:
if (!GetInventoryValue(0x9)) {
return 0;
case ITEM_ARROWS5:
if (!GetInventoryValue(ITEM_BOW)) {
return ITEM_NONE;
}
break;
case 0x3f: {
if (!GetInventoryValue(0x40)) {
return 0;
case ITEM_SHELLS: {
if (!GetInventoryValue(ITEM_EARTH_ELEMENT)) {
return ITEM_NONE;
}
if (itemParameter == 0) {
adjustedParam = 1;
}
break;
}
case 0x5c:
case 0xfc ... 0xfe: {
u32 tmp, tmp2;
case ITEM_KINSTONE:
case ITEM_KINSTONE_GREEN ... ITEM_KINSTONE_RED: {
u32 rand;
u8* ptr;
if (GetInventoryValue(0x67) == 0) {
if (GetInventoryValue(ITEM_KINSTONE_BAG) == 0) {
return 0;
}
if (3 < gRoomVars.filler1[0]) {
return 0;
}
if (itemID != 0x5c) {
adjustedParam = itemID - 0xfc;
if (itemID != ITEM_KINSTONE) {
adjustedParam = itemID - ITEM_KINSTONE_GREEN;
rand = (Random() & 0x3f);
ptr = gUnk_080FE1DD;
adjustedParam = gUnk_080FE1DD[(rand + adjustedParam * 0x40)];
if (adjustedParam == 0) {
itemID = 0;
itemID = ITEM_NONE;
} else {
itemID = 0x5c;
itemID = ITEM_KINSTONE;
}
}
break;
}
}
if (itemID != 0) {
if (itemID != 0xff) {
if (itemID != ITEM_NONE) {
if (itemID != ITEM_ENEMY_BEETLE) {
itemEntity = CreateObject(GROUND_ITEM, itemID, adjustedParam);
if (itemEntity != NULL) {
if (arg0 == &gPlayerEntity) {

1128
src/droptables.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -123,7 +123,7 @@ void sub_0806B540(Entity* this) {
case 2:
if ((gMessage.doTextBox & 0x7f) == 0) {
context->unk_18 = 3;
if (gSave.stats.filler3[0] != 0) {
if (gSave.stats.hasAllFigurines != 0) {
sub_080A7C18(0x58, 0, 0);
} else {
sub_080A7C18(0x3f, 100, 0);

View File

@ -101,7 +101,7 @@ void sub_08092B0C(Entity* this) {
CreateFx(this, FX_POT_SHATTER, 0);
sub_0805457C(this, 3);
CreateRandomItemDrop(this, 3);
} else {
sub_080044EC(this, this->field_0x78.HWORD);

View File

@ -31,7 +31,7 @@ void sub_080A7C18(u32 type, u32 type2, u32 delay) {
Entity* GiveItemWithCutscene(u32 type, u32 type2, u32 delay) {
Entity* e;
if (type == 63 && gSave.stats.filler3[0]) {
if (type == 63 && gSave.stats.hasAllFigurines) {
type = 87;
type2 = 0;
}

View File

@ -5279,7 +5279,7 @@ void sub_StateChange_HouseInteriors3_StockwellShop(void) {
LoadRoomEntityList(&gUnk_080F5848);
}
}
if (gSave.stats.filler3[0] == 0) {
if (gSave.stats.hasAllFigurines == 0) {
LoadRoomEntityList(&gUnk_080F5788);
}
}