ActorRupee 90% (#124)

* Remove `force_data` macro

* Use size_t in `operator new`

* Bump objdiff to v3.0.0-beta.10

* Decompile functions using gRandom

* ActorRupee 90%

* Fix old gRandom.Next calls

* Revert objdiff

* Clean up
This commit is contained in:
Aetias
2025-07-21 19:09:56 +02:00
committed by GitHub
parent 32cc123547
commit aee9c362bb
21 changed files with 103 additions and 68 deletions
@@ -8,3 +8,7 @@
src/09_Adventure/Game/GameModeAdventure.cpp:
.text start:0x02112c20 end:0x021132cc
.data start:0x0211e680 end:0x0211e6ec
src/09_Adventure/func_ov009_0211c808.cpp:
.text start:0x0211c808 end:0x0211c844
.rodata start:0x0211e0fc end:0x0211e14c
@@ -5,3 +5,5 @@
.data start:0x02179e60 end:0x0217af60 kind:data align:32
.bss start:0x0217af60 end:0x0217b160 kind:bss align:32
src/24/func_ov024_02170f98.cpp:
.text start:0x02170f98 end:0x02170ff0
@@ -5,3 +5,5 @@
.data start:0x02194500 end:0x02194a00 kind:data align:32
.bss start:0x02194a00 end:0x02194aa0 kind:bss align:32
src/47/func_ov047_0219196c.cpp:
.text start:0x0219196c end:0x021919cc
+1 -1
View File
@@ -55,7 +55,7 @@ func_020029ec kind:function(arm,size=0x10) addr:0x020029ec
func_020029fc kind:function(arm,size=0x1b0) addr:0x020029fc
_ll_udiv kind:function(arm,size=0xc) addr:0x02002bac
func_02002bb8 kind:function(arm,size=0x3c) addr:0x02002bb8
func_02002bf4 kind:function(arm,size=0x20) addr:0x02002bf4
_ull_mul kind:function(arm,size=0x20) addr:0x02002bf4
_s32_div_f kind:function(arm,size=0x20c) addr:0x02002c14
_u32_div_f kind:function(arm,size=0x1e4) addr:0x02002e20
.L_02002e28 kind:label(arm) addr:0x02002e28
@@ -8,3 +8,7 @@
src/09_Adventure/Game/GameModeAdventure.cpp:
.text start:0x02112ba0 end:0x0211324c
.data start:0x0211e600 end:0x0211e66c
src/09_Adventure/func_ov009_0211c808.cpp:
.text start:0x0211c788 end:0x0211c7c4
.rodata start:0x0211e07c end:0x0211e0cc
@@ -5,3 +5,6 @@
.data start:0x02179dc0 end:0x0217aec0 kind:data align:32
.bss start:0x0217aec0 end:0x0217b0c0 kind:bss align:32
src/24/func_ov024_02170f98.cpp:
.text start:0x02170ef8 end:0x02170f50
@@ -5,3 +5,5 @@
.data start:0x02194460 end:0x02194960 kind:data align:32
.bss start:0x02194960 end:0x02194a00 kind:bss align:32
src/47/func_ov047_0219196c.cpp:
.text start:0x021918cc end:0x0219192c
+1 -1
View File
@@ -55,7 +55,7 @@ func_020029ec kind:function(arm,size=0x10) addr:0x020029ec
func_020029fc kind:function(arm,size=0x1b0) addr:0x020029fc
_ll_udiv kind:function(arm,size=0xc) addr:0x02002bac
func_02002bb8 kind:function(arm,size=0x3c) addr:0x02002bb8
func_02002bf4 kind:function(arm,size=0x20) addr:0x02002bf4
_ull_mul kind:function(arm,size=0x20) addr:0x02002bf4
_s32_div_f kind:function(arm,size=0x20c) addr:0x02002c14
_u32_div_f kind:function(arm,size=0x1e4) addr:0x02002e20
.L_02002e28 kind:label(arm) addr:0x02002e28
+6 -7
View File
@@ -95,14 +95,13 @@ enum ActorTypeId_ {
class ActorType_UnkClass {
public:
u32 unk_00;
u32 unk_04;
u32 unk_08;
u32 unk_0C;
u32 unk_10;
/* 0 */ u32 mUnk_0;
/* 4 */ s32 mUnk_4;
/* 8 */
ActorType_UnkClass(u32 unk_00, u32 unk_04) :
unk_00(unk_00),
unk_04(unk_04) {}
mUnk_0(unk_00),
mUnk_4(unk_04) {}
};
class Actor;
+3 -3
View File
@@ -12,10 +12,10 @@ struct Random {
/**
* Generate a random number from 0 (inclusive) to `max` (exclusive)
*/
inline u32 Next(u32 max) {
inline u32 Next(u32 min, u32 max) {
mRandomValue = mAddend + mFactor * mRandomValue;
u64 result = (mRandomValue >> 32) * max;
return result >> 32;
u64 result = (mRandomValue >> 32) * (max - min);
return (result >> 32) + min;
}
};
+4 -2
View File
@@ -3,6 +3,8 @@
#include "global.h"
#include "types.h"
#include <stddef.h>
struct UnkStruct_0202e894 {
/* 00 */ u32 mId;
/* 04 */ u32 *mUnk_04;
@@ -19,8 +21,8 @@ extern u32 *data_027e0ce0[];
class SysObject {
public:
static void *operator new(unsigned long length, u32 *id, u32 idLength);
static void *operator new[](unsigned long length, u32 *id, u32 idLength);
static void *operator new(size_t length, u32 *id, u32 idLength);
static void *operator new[](size_t length, u32 *id, u32 idLength);
static void operator delete(void *ptr);
static void operator delete[](void *ptr);
};
-4
View File
@@ -26,8 +26,4 @@
#pragma define_section sbss ".data" \
".sbss"
// Force variables to be in .data by using #pragma section force_data begin|end
#pragma define_section force_data ".data" \
".data"
#endif
+1
View File
@@ -16,6 +16,7 @@ typedef char s8;
typedef s8 unk8;
typedef s16 unk16;
typedef s32 unk32;
typedef s64 unk64;
#ifndef __cplusplus
typedef s32 bool;
+1 -1
View File
@@ -3,7 +3,7 @@
#define NULL 0
typedef unsigned int size_t;
typedef unsigned long size_t;
#define offsetof(type, member) ((size_t) &((type *) NULL)->member)
+17
View File
@@ -0,0 +1,17 @@
#include "global.h"
#include "types.h"
#include "System/Random.hpp"
extern "C" u32 func_ov009_0211c558(const u8 *param0, s32 param1);
const u8 data_ov009_0211e0fc[80] = {
0x59, 0x5B, 0x60, 0x60, 0x6A, 0x6A, 0x74, 0x58, 0x6A, 0x6A, 0x74, 0x60, 0x60, 0x59, 0x5B, 0x58, 0x60, 0x6A, 0x6A, 0x59,
0x5B, 0x74, 0x60, 0x58, 0x6A, 0x65, 0x60, 0x65, 0x60, 0x65, 0x63, 0x58, 0x65, 0x6A, 0x60, 0x65, 0x65, 0x63, 0x60, 0x58,
0x65, 0x65, 0x6A, 0x60, 0x63, 0x60, 0x65, 0x58, 0x59, 0x6A, 0x6A, 0x65, 0x6A, 0x60, 0x60, 0x58, 0x60, 0x60, 0x6A, 0x6A,
0x65, 0x59, 0x6A, 0x58, 0x6A, 0x59, 0x60, 0x60, 0x6A, 0x6A, 0x65, 0x58, 0x5B, 0x5B, 0x65, 0x6A, 0x6A, 0x65, 0x65, 0x5B,
};
THUMB void func_ov009_0211c808(unk32 *param1) {
*param1 = func_ov009_0211c558(data_ov009_0211e0fc, gRandom.Next(0, 100));
}
+28 -42
View File
@@ -12,7 +12,7 @@ void func_ov000_020d7ad4(u32 *param1, u32 param2);
}
u16 GetRupeeValue(RupeeId id);
char *gShipParts[8] = {"anc", "bow", "hul", "can", "dco", "pdl", "fnl", "brg"};
static char *gShipParts[8] = {"anc", "bow", "hul", "can", "dco", "pdl", "fnl", "brg"};
extern u32 *data_ov014_021589d8;
extern u32 data_ov000_020e9370[];
@@ -21,77 +21,63 @@ extern u32 **data_027e0fe0[];
ActorType ActorRupee::gType = ActorType(ActorTypeId_Rupee, (ActorCreateFunc) ActorRupee::Create, NULL);
#pragma section force_data begin
ActorType_UnkClass data_ov014_021589f4 = ActorType_UnkClass(FLOAT_TO_Q21(0.4662), FLOAT_TO_Q19(0.4661));
#pragma section force_data end
ActorRupee *ActorRupee::Create() {
ActorRupee *newRupee = new(*data_027e0fe0[0], 4) ActorRupee();
return newRupee;
}
static const ActorType_UnkClass data_ov014_021589f4 = ActorType_UnkClass(FLOAT_TO_Q21(0.4662), FLOAT_TO_Q19(0.4661));
ActorRupee::ActorRupee() {
mRupeeId = 8;
mUnk_15c = 0;
}
// https://decomp.me/scratch/1qjCc
bool ActorRupee::Init() {
u32 dVar5;
u32 iVar7;
mRupeeId = mUnk_020.mUnk_00[0];
dVar5 = func_ov14_0213b70c(mRupeeId) ? *data_ov014_021589d8 : FLOAT_TO_Q20(0.666);
iVar7 = (s32) dVar5 >> 1;
RupeeId rupeeId = (RupeeId) mUnk_020.mUnk_00[0];
mRupeeId = rupeeId;
s32 iVar1 = (func_ov14_0213b70c(rupeeId) ? data_ov014_021589f4.mUnk_4 : 0xaa8) >> 1;
mHitbox.pos.x = 0;
mHitbox.pos.y = iVar7;
mHitbox.pos.y = iVar1;
mHitbox.pos.z = 0;
mHitbox.size = iVar7;
mUnk_08c.pos = mHitbox.pos;
mHitbox.size = iVar1;
mUnk_08c.pos.x = mHitbox.pos.x;
mUnk_08c.pos.y = mHitbox.pos.y;
mUnk_08c.pos.z = mHitbox.pos.z;
mUnk_08c.size = mHitbox.size;
mUnk_0a4.mUnk_04.x = 0;
mUnk_0a4.mUnk_04.y = iVar7;
mUnk_0a4.mUnk_04.y = iVar1;
mUnk_0a4.mUnk_04.z = 0;
mUnk_0a4.mUnk_10 = iVar7 + FLOAT_TO_Q20(1.0);
mUnk_09c.mUnk_0 &= 0xFFFFFF4F;
mUnk_09c.mUnk_3 = 1;
mMaxFall = mUnk_08c.size - 1;
mUnk_0a4.mUnk_10 = iVar1 + 0x1000;
mUnk_09c.mUnk_0 = mUnk_09c.mUnk_0 & ~0xb0;
mUnk_09c.mUnk_3 = 1;
mMaxFall = mUnk_08c.size + -1;
if (mUnk_03c >= 0) {
func_ov14_0213b204(1);
this->func_ov14_0213b204(1);
} else {
switch (mUnk_144) {
case 0:
mVel.x = 0;
mVel.y = 0;
mVel.z = 0;
func_ov14_0213b204(0);
this->func_ov14_0213b204(0);
break;
case 1:
q20 x = gRandom.Next(FLOAT_TO_Q20(0.1335));
q20 y = gRandom.Next(FLOAT_TO_Q20(0.2));
q20 z = gRandom.Next(FLOAT_TO_Q20(0.1335));
mVel.x = x - FLOAT_TO_Q20(0.0666);
mVel.y = y + FLOAT_TO_Q20(0.3333);
mVel.z = z - FLOAT_TO_Q20(0.0666);
func_ov14_0213b204(0);
mVel.x = gRandom.Next(FLOAT_TO_Q20(-0.0666), FLOAT_TO_Q20(0.0666));
mVel.y = gRandom.Next(FLOAT_TO_Q20(0.3333), FLOAT_TO_Q20(0.5333));
mVel.z = gRandom.Next(FLOAT_TO_Q20(-0.0666), FLOAT_TO_Q20(0.0666));
this->func_ov14_0213b204(0);
break;
case 2:
mVel.x = 0;
mVel.y = FLOAT_TO_Q20(0.5);
mVel.z = 0;
func_ov14_0213b204(0);
this->func_ov14_0213b204(0);
break;
case 3:
func_ov14_0213b204(5);
break;
this->func_ov14_0213b204(5);
}
}
return true;
}
@@ -240,12 +226,12 @@ void ActorRupee::Update(bool param1) {
}
}
break;
case 3:
case 3: {
PlayerLinkBase *pLink = gPlayerLink;
if (pLink->PlayItemCutscene(GetRupeeCutsceneItemId())) {
Kill();
}
break;
} break;
case 1:
if (param1) {
mActiveFrames = 0;
@@ -329,8 +315,8 @@ void ActorRupee::func_ov14_0213b6a4(RupeeId id, Actor_UnkStruct_012 *param2) {
if (func_ov14_0213b70c(id)) {
param2->mUnk_08 = 2;
param2->mUnk_0c = 2;
param2->mUnk_14 = data_ov014_021589f4.unk_00;
param2->mUnk_18 = data_ov014_021589f4.unk_04;
param2->mUnk_14 = data_ov014_021589f4.mUnk_0;
param2->mUnk_18 = data_ov014_021589f4.mUnk_4;
} else {
param2->mUnk_08 = 2;
param2->mUnk_0c = 2;
+2 -2
View File
@@ -285,7 +285,7 @@ ARM bool ActorRefillTime::Init() {
case 0:
case 1:
case 3:
s32 temp_ip = gRandom.Next(10);
s32 temp_ip = gRandom.Next(0, 10);
if (temp_ip >= 9) {
mUnk_158 = 30;
} else if (temp_ip >= 6) {
@@ -339,7 +339,7 @@ ARM bool ActorLSTM::Init() {
case 0:
case 1:
case 3:
s32 temp_ip = gRandom.Next(10);
s32 temp_ip = gRandom.Next(0, 10);
if (temp_ip >= 9) {
mUnk_158 = -30;
} else if (temp_ip >= 6) {
+9
View File
@@ -0,0 +1,9 @@
#include "global.h"
#include "types.h"
#include "System/Random.hpp"
ARM void func_ov024_02170f98(s32 param1) {
*(unk32 *) (param1 + 0x330) = 0x3c + gRandom.Next(0, 1);
*(unk32 *) (*(s32 *) (param1 + 0x22c) + 0x10) = 0;
}
+8
View File
@@ -0,0 +1,8 @@
#include "global.h"
#include "types.h"
#include "System/Random.hpp"
ARM void func_ov047_0219196c(s32 param1) {
*(s16 *) (param1 + 0x334) = gRandom.Next(0, 61) + 0x3c;
}
+1 -1
View File
@@ -302,7 +302,7 @@ ARM void Game::Run() {
if ((this->mUnk_0f4 & 7U) == 0) {
data_027e0dbc.func_ov000_0207b9dc();
} else {
gRandom.Next(0);
gRandom.Next(0, 0);
}
}
nextGameMode = 0;
+4 -4
View File
@@ -101,7 +101,7 @@ ARM unk32 UnkStruct_02037750::vfunc_28(s32 param1) {
uVar10 = 0x0;
} else {
lVar2 = gRandom.mRandomValue * gRandom.mFactor;
uVar10 = gRandom.Next(lVar2);
uVar10 = gRandom.Next(0, lVar2);
// uVar10 = *(int *)((int)&gRandom.mAddend + 0x4) +
// *(int *)((int)&gRandom.mFactor + 0x4) *
// *(uint *)&gRandom.mRandomValue + *(uint *)&gRandom.mFactor *
@@ -133,7 +133,7 @@ ARM unk32 UnkStruct_02037750::vfunc_28(s32 param1) {
case 0xb:
lVar2 = gRandom.mRandomValue * gRandom.mFactor;
uVar7 = lVar2;
uVar10 = gRandom.Next(uVar7);
uVar10 = gRandom.Next(0, uVar7);
return (int) (uVar10 * 0x64 >> 0x20) < (param1 + 0x4);
case 0xc:
@@ -143,7 +143,7 @@ ARM unk32 UnkStruct_02037750::vfunc_28(s32 param1) {
} else {
lVar2 = gRandom.mRandomValue * gRandom.mFactor;
uVar11 = lVar2;
uVar10 = gRandom.Next(uVar11);
uVar10 = gRandom.Next(0, uVar11);
if (uVar7 != 0x0) {
uVar10 = (uVar7 * uVar10 >> 0x20);
@@ -168,7 +168,7 @@ ARM unk32 UnkStruct_02037750::vfunc_28(s32 param1) {
} else {
lVar2 = gRandom.mRandomValue * gRandom.mFactor;
uVar11 = lVar2;
uVar10 = gRandom.Next(uVar11);
uVar10 = gRandom.Next(0, uVar11);
if (uVar7 != 0x0) {
uVar10 = (uVar7 * uVar10 >> 0x20);