Reconstruction layout: generated-src/ (generated) and src/ (curated), CMake, the first takeover: RNG
The decompiled C++ tree moves to generated-src/ (classes.h, C++20); src/ is for code written by hand. A curated function defines the generated declaration and starts its comment with its address, and source_tree.py stops emitting that body. src/rng.cpp takes over RNG (SetSeed, the constructor, Next, RandomInt, RandomFloat, Shuffle) with the shift table read from the exe as a constexpr array; src/log.h names KAGE_LogMessage's levels (1 INFO, 2 NET, 4 WARN, 8 ERROR, 16 ASSERT, from its prefix jump table). CMakeLists.txt builds src/*.cpp against generated-src/classes.h (clean with -Wall -Wextra). structs.hpp and headers.py are retired: scripts/merge_fields.py writes the merged field list, classes.h checks the layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2ff2d5d87f
commit
3ce74c6e2d
331 files changed
+485
-7835
No files matched your search
@@ -0,0 +1,107 @@
|
||||
#include "classes.h"
|
||||
|
||||
// 0049cbf0
|
||||
uint WeightedOutcomePicker::PickOutcome(RNG rng)
|
||||
{
|
||||
int iVar1;
|
||||
int iVar2;
|
||||
int iVar3;
|
||||
int iVar4;
|
||||
code *pcVar5;
|
||||
uint uVar6;
|
||||
uint outcomeCount;
|
||||
int *weightPtr;
|
||||
uint uVar7;
|
||||
int iVar8;
|
||||
int iVar9;
|
||||
int partialSum6;
|
||||
int partialSum7;
|
||||
int partialSum0;
|
||||
int partialSum1;
|
||||
int partialSum2;
|
||||
int partialSum3;
|
||||
WeightedOutcomePicker outcomes;
|
||||
|
||||
uVar7 = 0;
|
||||
outcomes = *this;
|
||||
uVar6 = 0;
|
||||
outcomeCount = GHIDRA_INT(this[1]) - GHIDRA_INT(outcomes) >> 3;
|
||||
if ((outcomeCount != 0) && (7 < outcomeCount)) {
|
||||
partialSum0 = 0;
|
||||
partialSum1 = 0;
|
||||
partialSum2 = 0;
|
||||
partialSum3 = 0;
|
||||
iVar8 = 0;
|
||||
iVar9 = 0;
|
||||
partialSum6 = 0;
|
||||
partialSum7 = 0;
|
||||
do {
|
||||
iVar1 = uVar6 * 8;
|
||||
iVar2 = uVar6 * 8;
|
||||
iVar3 = uVar6 * 8;
|
||||
partialSum0 = partialSum0 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 4 + uVar6 * 8));
|
||||
partialSum1 = partialSum1 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0xc + uVar6 * 8));
|
||||
partialSum2 = partialSum2 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0x14 + uVar6 * 8));
|
||||
partialSum3 = partialSum3 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0x1c + uVar6 * 8));
|
||||
iVar4 = uVar6 * 8;
|
||||
uVar6 = uVar6 + 8;
|
||||
iVar8 = iVar8 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0x24 + iVar4));
|
||||
iVar9 = iVar9 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0x2c + iVar3));
|
||||
partialSum6 = partialSum6 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0x34 + iVar1));
|
||||
partialSum7 = partialSum7 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0x3c + iVar2));
|
||||
} while (uVar6 < outcomeCount - (outcomeCount & 7));
|
||||
uVar7 = iVar8 + partialSum0 + partialSum6 + partialSum2 +
|
||||
iVar9 + partialSum1 + partialSum7 + partialSum3;
|
||||
}
|
||||
iVar8 = 0;
|
||||
iVar9 = 0;
|
||||
if (outcomeCount <= uVar6) goto LAB_0049ccec;
|
||||
if (outcomeCount - uVar6 < 2) {
|
||||
LAB_0049cce3:
|
||||
uVar7 = uVar7 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 4 + uVar6 * 8));
|
||||
}
|
||||
else {
|
||||
do {
|
||||
iVar8 = iVar8 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 4 + uVar6 * 8));
|
||||
iVar9 = iVar9 + *GHIDRA_CAST<int *>((GHIDRA_CAST<char *>(outcomes) + 0xc + uVar6 * 8));
|
||||
uVar6 = uVar6 + 2;
|
||||
} while (uVar6 < outcomeCount - 1);
|
||||
if (uVar6 < outcomeCount) goto LAB_0049cce3;
|
||||
}
|
||||
uVar7 = uVar7 + iVar9 + iVar8;
|
||||
LAB_0049ccec:
|
||||
if (rng._seed == 0) {
|
||||
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("RNG Seed is zero!\n"));
|
||||
pcVar5 = (code *)swi(3);
|
||||
uVar6 = (*pcVar5)();
|
||||
return uVar6;
|
||||
}
|
||||
uVar6 = GHIDRA_UINT(rng._seed) >> ((byte)rng._shift1 & 0x1f) ^ rng._seed;
|
||||
uVar6 = uVar6 << ((byte)rng._shift2 & 0x1f) ^ uVar6;
|
||||
if (uVar7 == 0) {
|
||||
uVar7 = 0;
|
||||
}
|
||||
else {
|
||||
uVar7 = (uVar6 >> ((byte)rng._shift3 & 0x1f) ^ uVar6) % uVar7;
|
||||
}
|
||||
iVar8 = 0;
|
||||
uVar6 = 0;
|
||||
outcomes = *this;
|
||||
outcomeCount = GHIDRA_INT(this[1]) - GHIDRA_INT(outcomes) >> 3;
|
||||
if (outcomeCount != 0) {
|
||||
weightPtr = GHIDRA_CAST<int *>((GHIDRA_INT(outcomes) + 4));
|
||||
do {
|
||||
iVar8 = iVar8 + *weightPtr;
|
||||
if (GHIDRA_INT(uVar7) < iVar8) {
|
||||
return *GHIDRA_CAST<uint *>((GHIDRA_CAST<char *>(outcomes) + uVar6 * 8));
|
||||
}
|
||||
uVar6 = uVar6 + 1;
|
||||
weightPtr = weightPtr + 2;
|
||||
} while (uVar6 < outcomeCount);
|
||||
if (0 < iVar8) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
KAGE_LogMessage(0x10,GHIDRA_CAST<byte *>("No weights were added. At least one outcome needs weight."));
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user