Skip to content

Commit 52fa955

Browse files
authored
PeridotTraceState0x438 (isledecomp#252)
1 parent 41b4d51 commit 52fa955

8 files changed

Lines changed: 159 additions & 21 deletions

File tree

LEGORacers/include/legoracers.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class LegoRacers : public CactusInterface0x4 {
3939
c_flagBit1 = 1 << 1,
4040
c_flagBit2 = 1 << 2,
4141
c_flagBit3 = 1 << 3,
42+
c_flagBit4 = 1 << 4,
4243
c_flagBit5 = 1 << 5,
4344
c_flagBit6 = 1 << 6,
4445
c_flagBit7 = 1 << 7,
@@ -61,7 +62,10 @@ class LegoRacers : public CactusInterface0x4 {
6162
LegoChar m_unk0x2d[8]; // 0x2d
6263
undefined m_unk0x35[0x38 - 0x35]; // 0x35
6364
RaceSlot m_raceSlots[4]; // 0x38
64-
undefined m_unk0x98[0xd8 - 0x98]; // 0x98
65+
undefined4 m_unk0x98[4]; // 0x98
66+
LegoU32 m_unk0xa8[4]; // 0xa8
67+
undefined4 m_unk0xb8[4]; // 0xb8
68+
LegoU32 m_unk0xc8[4]; // 0xc8
6569
undefined4 m_unk0xd8; // 0xd8
6670
LegoChar m_gameDataDirectory[18]; // 0xdc
6771
LegoChar m_commonDataDirectory[18]; // 0xee

LEGORacers/include/peridottrace0x4e0.h

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "types.h"
77

88
class GolFile;
9+
class GolString;
910
class InputManager;
1011
class PeridotTrace0x4e0;
1112

@@ -111,6 +112,7 @@ class PeridotTraceState0x438 {
111112
void FUN_0042f200(LegoU8 p_unk0x04);
112113
LegoBool32 FUN_0042f250(LegoU32 p_unk0x04);
113114
LegoBool32 FUN_0042f280() const;
115+
LegoBool32 FUN_0042f310(LegoU32 p_unk0x04, LegoBool32 p_unk0x08, LegoU32 p_unk0x0c, GolString* p_string);
114116

115117
void SetUnk0x00(undefined4 p_arg1) { m_unk0x00 = p_arg1; }
116118
undefined4 GetUnk0x00() const { return m_unk0x00; }
@@ -148,22 +150,26 @@ class PeridotTraceState0x438 {
148150
SerializedGuidWord m_words[sizeof(GUID) / sizeof(LegoU32)]; // 0x00
149151
};
150152

151-
undefined4 m_unk0x00; // 0x00
152-
undefined4 m_unk0x04; // 0x04
153-
InputManager* m_inputManager; // 0x08
154-
LegoU8 m_unk0x0c; // 0x0c
155-
SerializedGuid m_displayDriverGuid; // 0x0d
156-
undefined m_unk0x1d; // 0x1d
157-
undefined m_unk0x1e; // 0x1e
158-
LegoU8 m_unk0x1f; // 0x1f
159-
LegoU8 m_unk0x20; // 0x20
160-
LegoU8 m_unk0x21; // 0x21
161-
LegoU8 m_languageIndex; // 0x22
162-
undefined m_unk0x23; // 0x23
163-
LegoU8 m_unk0x24; // 0x24
164-
LegoU8 m_unk0x25; // 0x25
165-
LegoU16 m_unk0x26; // 0x26
166-
undefined m_unk0x28[0x438 - 0x28]; // 0x28
153+
undefined4 m_unk0x00; // 0x00
154+
undefined4 m_unk0x04; // 0x04
155+
InputManager* m_inputManager; // 0x08
156+
LegoU8 m_unk0x0c; // 0x0c
157+
SerializedGuid m_displayDriverGuid; // 0x0d
158+
undefined m_unk0x1d; // 0x1d
159+
undefined m_unk0x1e; // 0x1e
160+
LegoU8 m_unk0x1f; // 0x1f
161+
LegoU8 m_unk0x20; // 0x20
162+
LegoU8 m_unk0x21; // 0x21
163+
LegoU8 m_languageIndex; // 0x22
164+
undefined m_unk0x23; // 0x23
165+
LegoU8 m_unk0x24; // 0x24
166+
LegoU8 m_unk0x25; // 0x25
167+
LegoU16 m_unk0x26; // 0x26
168+
LegoU32 m_unk0x28[13]; // 0x28
169+
LegoU32 m_unk0x5c[13]; // 0x5c
170+
undefined2 m_unk0x90[13][14]; // 0x90
171+
undefined2 m_unk0x1fc[13][14]; // 0x1fc
172+
undefined m_unk0x368[0x438 - 0x368]; // 0x368
167173
};
168174

169175
// SIZE 0x250
@@ -172,6 +178,8 @@ class PeridotTraceBuffer0x250 {
172178
PeridotTraceBuffer0x250();
173179
~PeridotTraceBuffer0x250();
174180

181+
static void CopyStringToBuffer(GolString* p_string, undefined2* p_dest, LegoU32 p_count);
182+
175183
void Reset() { m_unk0x244 = 0; }
176184

177185
void FUN_0042b2f0(undefined4, undefined4, undefined4, undefined4);

LEGORacers/include/scarletnova0x5c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class ScarletNova0x5c {
1818
undefined4* m_unk0x20; // 0x20
1919
AmberHaze0x1c* m_unk0x24; // 0x24
2020
MagentaRibbon0x20* m_unk0x28; // 0x28
21-
undefined4* m_unk0x2c[6]; // 0x2c
21+
LegoChar m_unk0x2c[14]; // 0x2c
22+
undefined m_unk0x3a[0x44 - 0x3a]; // 0x3a
2223
undefined4* m_unk0x44; // 0x44
2324
AmberHaze0x1c* m_unk0x48; // 0x48
2425
MagentaRibbon0x20* m_unk0x4c; // 0x4c

LEGORacers/src/menumanager.cpp

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,57 @@ LegoBool32 MenuManager::FUN_0042e450()
645645
// STUB: LEGORACERS 0x0042e490
646646
LegoS32 MenuManager::FUN_0042e490()
647647
{
648-
// TODO
649-
STUB(0x42e490);
650-
return FALSE;
648+
LegoU8 flags = m_unk0x04.m_context->m_unk0x1e;
649+
650+
if (!(flags & LegoRacers::Context::c_flagBit4)) {
651+
return FALSE;
652+
}
653+
654+
m_unk0x04.m_context->m_unk0x1e = flags & ~LegoRacers::Context::c_flagBit4;
655+
LegoRacers::Context* context = m_unk0x04.m_context;
656+
657+
GolString string;
658+
LegoChar name[15];
659+
undefined2 wideName[15];
660+
LegoS32 result = FALSE;
661+
LegoU32 raceIndex = 0;
662+
663+
for (LegoS32 i = 0; i < 4; i++) {
664+
LegoBool32 hasRaceIndex = FALSE;
665+
666+
if (context->m_unk0x98[i]) {
667+
raceIndex = m_unk0x04.m_raceNames.GetEntryIndexByName(context->m_raceSlots[i].m_unk0x08);
668+
hasRaceIndex = TRUE;
669+
670+
const LegoChar* sourceName = context->m_unk0x108[context->m_unk0xa8[i]].m_unk0x2c;
671+
::strncpy(name, sourceName, sizeof(name) - 1);
672+
name[sizeof(name) - 1] = '\0';
673+
GolString::CopyStringToBuf16(sourceName, wideName);
674+
string.CopyFromBufSelection(wideName, sizeof(name) - 1);
675+
676+
if (m_unk0x04.m_unk0x258.GetUnk0x18c4().FUN_0042f310(raceIndex, 0, context->m_unk0x98[i], &string)) {
677+
result = TRUE;
678+
}
679+
}
680+
681+
if (context->m_unk0xb8[i]) {
682+
if (!hasRaceIndex) {
683+
raceIndex = m_unk0x04.m_raceNames.GetEntryIndexByName(context->m_raceSlots[i].m_unk0x08);
684+
}
685+
686+
const LegoChar* sourceName = context->m_unk0x108[context->m_unk0xc8[i]].m_unk0x2c;
687+
::strncpy(name, sourceName, sizeof(name) - 1);
688+
name[sizeof(name) - 1] = '\0';
689+
GolString::CopyStringToBuf16(sourceName, wideName);
690+
string.CopyFromBufSelection(wideName, sizeof(name) - 1);
691+
692+
if (m_unk0x04.m_unk0x258.GetUnk0x18c4().FUN_0042f310(raceIndex, 1, context->m_unk0xb8[i], &string)) {
693+
result = TRUE;
694+
}
695+
}
696+
}
697+
698+
return result;
651699
}
652700

653701
// FUNCTION: LEGORACERS 0x0042e680

LEGORacers/src/peridottrace0x4e0.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "peridottrace0x4e0.h"
22

3+
#include "golstring.h"
4+
35
DECOMP_SIZE_ASSERT(PeridotTraceBase0x24, 0x24)
46
DECOMP_SIZE_ASSERT(PeridotTraceBase0x24::Record, 0x241)
57
DECOMP_SIZE_ASSERT(PeridotTraceBuffer0x250, 0x250)
@@ -25,6 +27,30 @@ void PeridotTraceBuffer0x250::FUN_0042b2f0(undefined4, undefined4, undefined4, u
2527
STUB(0x0042b2f0);
2628
}
2729

30+
// FUNCTION: LEGORACERS 0x0042b560
31+
void PeridotTraceBuffer0x250::CopyStringToBuffer(GolString* p_string, undefined2* p_dest, LegoU32 p_count)
32+
{
33+
LegoU32 length = p_string->SelectionLength();
34+
if (length > p_count) {
35+
length = p_count;
36+
}
37+
38+
LegoU8* dest = reinterpret_cast<LegoU8*>(p_dest);
39+
LegoU32 i = 0;
40+
for (; i < length; i++) {
41+
undefined2 c = *p_string->FromCursor(i);
42+
43+
dest[0] = static_cast<LegoU8>(c);
44+
dest[1] = static_cast<LegoU8>(c >> 8);
45+
dest += 2;
46+
}
47+
48+
for (; i < p_count; i++) {
49+
*dest++ = 0;
50+
*dest++ = 0;
51+
}
52+
}
53+
2854
// FUNCTION: LEGORACERS 0x0042b6e0
2955
PeridotTraceBase0x24::PeridotTraceBase0x24()
3056
{

LEGORacers/src/peridottracestate0x438.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,43 @@ LegoBool32 PeridotTraceState0x438::FUN_0042f280() const
132132
{
133133
return m_unk0x26 == 0x0fff;
134134
}
135+
136+
// FUNCTION: LEGORACERS 0x0042f310
137+
LegoBool32 PeridotTraceState0x438::FUN_0042f310(
138+
LegoU32 p_unk0x04,
139+
LegoBool32 p_unk0x08,
140+
LegoU32 p_unk0x0c,
141+
GolString* p_string
142+
)
143+
{
144+
if (p_unk0x04 >= 13) {
145+
p_unk0x04 -= 13;
146+
if (p_unk0x04 >= 13) {
147+
return FALSE;
148+
}
149+
}
150+
151+
LegoU32 current;
152+
if (!p_unk0x08) {
153+
current = m_unk0x28[p_unk0x04];
154+
}
155+
else {
156+
current = m_unk0x5c[p_unk0x04];
157+
}
158+
159+
if (current && p_unk0x0c >= current) {
160+
return FALSE;
161+
}
162+
163+
if (!p_unk0x08) {
164+
m_unk0x28[p_unk0x04] = p_unk0x0c;
165+
PeridotTraceBuffer0x250::CopyStringToBuffer(p_string, m_unk0x90[p_unk0x04], 14);
166+
}
167+
else {
168+
m_unk0x5c[p_unk0x04] = p_unk0x0c;
169+
PeridotTraceBuffer0x250::CopyStringToBuffer(p_string, m_unk0x1fc[p_unk0x04], 14);
170+
}
171+
172+
m_unk0x00 = 1;
173+
return TRUE;
174+
}

common/include/golstring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class GolString {
1111
~GolString();
1212

1313
static LegoS32 GolStrlen(undefined2* p_string);
14+
static void CopyStringToBuf16(const LegoChar* p_src, undefined2* p_dst);
1415
undefined2* FromCursor(undefined4 p_param);
1516
undefined4 CopyFromBufSelection(undefined2* p_buf, undefined2 p_count);
1617
undefined4 CopyFromGolString(GolString* p_string);

common/src/golstring.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ LegoS32 GolString::GolStrlen(undefined2* p_string)
1717
return len;
1818
}
1919

20+
// FUNCTION: LEGORACERS 0x00449de0
21+
void GolString::CopyStringToBuf16(const LegoChar* p_src, undefined2* p_dst)
22+
{
23+
while (*p_src) {
24+
*p_dst++ = static_cast<LegoU8>(*p_src++);
25+
}
26+
27+
*p_dst = 0;
28+
}
29+
2030
// FUNCTION: GOLDP 0x1002f950
2131
// FUNCTION: LEGORACERS 0x00449e10
2232
GolString::GolString()

0 commit comments

Comments
 (0)