Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/RSBE01_02/splits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ sora/mt/mt_prng.cpp:
.sbss start:0x805A00B8 end:0x805A00C0
.sdata2 start:0x805A1748 end:0x805A176C

sora/mt/mt_prng_log.cpp:
.text start:0x8004392C end:0x80043B18
.ctors start:0x80406514 end:0x80406518
.bss start:0x804977A8 end:0x804977C0

sora/st/module.cpp:
.text start:0x80043B18 end:0x80043B6C
.data start:0x8042AEB0 end:0x8042B598
Expand Down
6 changes: 3 additions & 3 deletions config/RSBE01_02/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2971,9 +2971,9 @@ fn_800436E8 = .text:0x800436E8; // type:function size:0xF4
fn_800437DC = .text:0x800437DC; // type:function size:0xBC
fn_80043898 = .text:0x80043898; // type:function size:0x94
__ct__9mtPrngLogFUlPv = .text:0x8004392C; // type:function size:0xF4
fn_80043A20 = .text:0x80043A20; // type:function size:0x74
addLog__16mtPrngLogManagerFP9mtPrngLog = .text:0x80043A94; // type:function size:0x58
fn_80043AEC = .text:0x80043AEC; // type:function size:0x2C
__dt__16mtPrngLogManagerFv = .text:0x80043A20; // type:function size:0x74
addLog__16mtPrngLogManagerFPC9mtPrngLog = .text:0x80043A94; // type:function size:0x58
__sinit_\mt_prng_log_cpp = .text:0x80043AEC; // type:function size:0x2C scope:local
moUnResolvedMessage__FPCc = .text:0x80043B18; // type:function size:0x4
moGetStageModuleName__FQ26Stages11srStageKind = .text:0x80043B1C; // type:function size:0x50
fn_80043B6C = .text:0x80043B6C; // type:function size:0x9C
Expand Down
1 change: 1 addition & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ def MatchingFor(*versions):
Object(Matching, "sora/gf/gf_resource_loader.cpp"),
Object(NonMatching, "sora/mt/mt_vector_old.cpp"),
Object(Matching, "sora/mt/mt_prng.cpp", extra_cflags=["-RTTI off"]),
Object(Matching, "sora/mt/mt_prng_log.cpp"),
Object(Matching, "sora/st/module.cpp"),
Object(Matching, "sora/ut/ut_list.cpp"),
Object(Matching, "sora/ip/ip_human.cpp"),
Expand Down
2 changes: 1 addition & 1 deletion include/lib/BrawlHeaders
5 changes: 2 additions & 3 deletions src/sora/mt/mt_prng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
#include <types.h>

void mtRand::init(s32 p1) {
this->seed = p1;
m_seed = p1;
}

s32 mtRand::generate() {
return this->seed = (this->seed * MultVal + AddVal) & mtRand::getMax();
return m_seed = (m_seed * MultVal + AddVal) & mtRand::getMax();
}

s32 mtRand::randi() {
return generate();
}

static mtRand g_mtRand(0);
extern mtPrngLogManager g_mtPrngLogManager;

// [0, 1] random float
float mtRand::randf() {
Expand Down
60 changes: 60 additions & 0 deletions src/sora/mt/mt_prng_log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <gm/gm_global.h>
#include <gf/gf_heap_manager.h>
#include <mt/mt_prng.h>
#include <types.h>

mtPrngLogManager g_mtPrngLogManager;

// A node in a PPC stack trace, referencing the caller's SP and LR
// UBFIX: ABI-specific
struct PPCFrameInfo {
PPCFrameInfo* m_next;
void* m_retaddr;

bool isValid() const {
return reinterpret_cast<u32>(this) != -1;
}

bool isInRange() const {
return reinterpret_cast<u32>(this) & 0x80000000;
}
};

mtPrngLog::mtPrngLog(u32 val, void* sp) {
m_randVal = val;
PPCFrameInfo* bt = static_cast<PPCFrameInfo*>(sp)->m_next;
u32 i = 0;

// Store a stack trace of up to 2 return addresses in m_backtrace
if (bt && bt->isValid() && bt->isInRange()) {
m_backtrace[i++] = bt->m_retaddr;
bt = bt->m_next;
if (bt && bt->isValid() && bt->isInRange()) {
m_backtrace[i++] = bt->m_retaddr;
}
}

for ( ; i < BacktraceLength; i++) {
m_backtrace[i] = nullptr;
}
m_gameFrame = g_GameGlobal->getGameFrame();
}

mtPrngLogManager::~mtPrngLogManager() {
if (m_logs && m_logs) {
gfHeapManager::free(m_logs);
m_logs = nullptr;
m_len = 0;
m_maxLen = 0;
}
}

bool mtPrngLogManager::addLog(const mtPrngLog* log) {
bool res = false;
if (m_len < m_maxLen) {
m_logs[m_len] = *log;
res = true;
m_len++;
}
return res;
}
Loading