From b5134e6454fa74dfa2e5219d12488ac9ad9ca064 Mon Sep 17 00:00:00 2001 From: sourcehold Date: Wed, 13 May 2026 12:50:25 +0200 Subject: [PATCH 1/2] reimplement: OpenSHC::Random::RNG 100% --- src/OpenSHC/Random/RNG.func.hpp | 8 ++-- src/OpenSHC/Random/RNG/Constructor_RNG.cpp | 17 +++++++++ src/OpenSHC/Random/RNG/nextRandomNumber1.cpp | 19 ++++++++++ src/OpenSHC/Random/RNG/nextRandomNumber2.cpp | 19 ++++++++++ src/OpenSHC/Random/RNG/populateRNG1040.cpp | 39 ++++++++++++++++++++ src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp | 20 ++++++++++ status/addresses-SHC-3BB0A8C1.txt | 10 ++--- 7 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 src/OpenSHC/Random/RNG/Constructor_RNG.cpp create mode 100644 src/OpenSHC/Random/RNG/nextRandomNumber1.cpp create mode 100644 src/OpenSHC/Random/RNG/nextRandomNumber2.cpp create mode 100644 src/OpenSHC/Random/RNG/populateRNG1040.cpp create mode 100644 src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp diff --git a/src/OpenSHC/Random/RNG.func.hpp b/src/OpenSHC/Random/RNG.func.hpp index 6ca23d5..aad2d6b 100644 --- a/src/OpenSHC/Random/RNG.func.hpp +++ b/src/OpenSHC/Random/RNG.func.hpp @@ -7,16 +7,16 @@ namespace OpenSHC { namespace Random { namespace RNG_Func { - MACRO_FUNCTION_RESOLVER(void (RNG::*)(), false, Address::SHC_3BB0A8C1_0x0046A740, &RNG::setTimeBasedSeed) + MACRO_FUNCTION_RESOLVER(void (RNG::*)(), true, Address::SHC_3BB0A8C1_0x0046A740, &RNG::setTimeBasedSeed) setTimeBasedSeed; - MACRO_FUNCTION_RESOLVER(void (RNG::*)(), false, Address::SHC_3BB0A8C1_0x0046A760, &RNG::populateRNG1040) + MACRO_FUNCTION_RESOLVER(void (RNG::*)(), true, Address::SHC_3BB0A8C1_0x0046A760, &RNG::populateRNG1040) populateRNG1040; - MACRO_FUNCTION_RESOLVER(void (RNG::*)(), false, Address::SHC_3BB0A8C1_0x0046A7D0, &RNG::nextRandomNumber2) + MACRO_FUNCTION_RESOLVER(void (RNG::*)(), true, Address::SHC_3BB0A8C1_0x0046A7D0, &RNG::nextRandomNumber2) nextRandomNumber2; - MACRO_FUNCTION_RESOLVER(void (RNG::*)(), false, Address::SHC_3BB0A8C1_0x0046A800, &RNG::nextRandomNumber1) + MACRO_FUNCTION_RESOLVER(void (RNG::*)(), true, Address::SHC_3BB0A8C1_0x0046A800, &RNG::nextRandomNumber1) nextRandomNumber1; } // namespace RNG_Func diff --git a/src/OpenSHC/Random/RNG/Constructor_RNG.cpp b/src/OpenSHC/Random/RNG/Constructor_RNG.cpp new file mode 100644 index 0000000..d21cce3 --- /dev/null +++ b/src/OpenSHC/Random/RNG/Constructor_RNG.cpp @@ -0,0 +1,17 @@ +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Random/RNG.hpp" + +namespace OpenSHC { +namespace Random { + + // FUNCTION: STRONGHOLDCRUSADER 0x00471810 + RNG* RNG::Constructor_RNG() + + { + MACRO_CALL_MEMBER(RNG_Func::setTimeBasedSeed, this)(); + MACRO_CALL_MEMBER(RNG_Func::populateRNG1040, this)(); + return this; + } + +} +} diff --git a/src/OpenSHC/Random/RNG/nextRandomNumber1.cpp b/src/OpenSHC/Random/RNG/nextRandomNumber1.cpp new file mode 100644 index 0000000..accd6be --- /dev/null +++ b/src/OpenSHC/Random/RNG/nextRandomNumber1.cpp @@ -0,0 +1,19 @@ + +#include "OpenSHC/Random/RNG.hpp" + +namespace OpenSHC { +namespace Random { + + // FUNCTION: STRONGHOLDCRUSADER 0x0046a800 + void RNG::nextRandomNumber1() + { + this->currentNumber1 = this->randomNumbers[this->index1]; + this->index1 = this->index1 + 1; + if (20000 <= this->index1) { + this->index1 = 0; + } + return; + } +} + +} diff --git a/src/OpenSHC/Random/RNG/nextRandomNumber2.cpp b/src/OpenSHC/Random/RNG/nextRandomNumber2.cpp new file mode 100644 index 0000000..37df090 --- /dev/null +++ b/src/OpenSHC/Random/RNG/nextRandomNumber2.cpp @@ -0,0 +1,19 @@ + +#include "OpenSHC/Random/RNG.hpp" + +namespace OpenSHC { +namespace Random { + + // FUNCTION: STRONGHOLDCRUSADER 0x0046a7d0 + void RNG::nextRandomNumber2() + { + this->currentNumber2 = this->randomNumbers[this->index2]; + this->index2 = this->index2 + 1; + if (20000 <= this->index2) { + this->index2 = 0; + } + return; + } +} + +} diff --git a/src/OpenSHC/Random/RNG/populateRNG1040.cpp b/src/OpenSHC/Random/RNG/populateRNG1040.cpp new file mode 100644 index 0000000..efc746e --- /dev/null +++ b/src/OpenSHC/Random/RNG/populateRNG1040.cpp @@ -0,0 +1,39 @@ +#include "OpenSHC/Global.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Random/RNG.hpp" + +namespace OpenSHC { +namespace Random { + + // FUNCTION: STRONGHOLDCRUSADER 0x0046a760 + void RNG::populateRNG1040() + + { + int iVar1; + int iVar2; + short* _pRandomNumber; + + MACRO_CALL(OpenSHC::Global_Func::SetRNGSeed)(this->seed); + this->index2 = 0; + this->index1 = 0; + _pRandomNumber = &this->randomNumbers[0]; + iVar2 = 20000; + do { + iVar1 = MACRO_CALL(OpenSHC::OS_Func::_rand)(); + *_pRandomNumber = (short)iVar1; + _pRandomNumber = _pRandomNumber + 1; + iVar2 = iVar2 + -1; + } while (iVar2 != 0); + + this->currentNumber2 = this->randomNumbers[this->index2]; + this->index2 = this->index2 + 1; + + this->currentNumber1 = this->randomNumbers[this->index1]; + this->index1 = this->index1 + 1; + + return; + } + +} +} diff --git a/src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp b/src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp new file mode 100644 index 0000000..4fb06aa --- /dev/null +++ b/src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp @@ -0,0 +1,20 @@ +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Random/RNG.hpp" +#include + +namespace OpenSHC { +namespace Random { + + // FUNCTION: STRONGHOLDCRUSADER 0x0046a740 + void RNG::setTimeBasedSeed() + + { + + __time64_t _Var1 = MACRO_CALL(OpenSHC::OS_Func::__time64)((__time64_t*)0x0); + this->seed = (int)_Var1; + return; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f1a6853..4ce20ac 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -10168,10 +10168,10 @@ SHC_3BB0A8C1_0x0046A4C4 | 0.0% | Pending SHC_3BB0A8C1_0x0046A4C8 | 0.0% | Pending SHC_3BB0A8C1_0x0046A4D0 | 0.0% | Pending SHC_3BB0A8C1_0x0046A720 | 0.0% | Pending -SHC_3BB0A8C1_0x0046A740 | 0.0% | Pending -SHC_3BB0A8C1_0x0046A760 | 0.0% | Pending -SHC_3BB0A8C1_0x0046A7D0 | 0.0% | Pending -SHC_3BB0A8C1_0x0046A800 | 0.0% | Pending +SHC_3BB0A8C1_0x0046A740 | 100.0% | Reimplemented +SHC_3BB0A8C1_0x0046A760 | 100.0% | Reimplemented +SHC_3BB0A8C1_0x0046A7D0 | 100.0% | Reimplemented +SHC_3BB0A8C1_0x0046A800 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0046A830 | 0.0% | Pending SHC_3BB0A8C1_0x0046A850 | 0.0% | Pending SHC_3BB0A8C1_0x0046A890 | 0.0% | Pending @@ -10475,7 +10475,7 @@ SHC_3BB0A8C1_0x004717F8 | 0.0% | Pending SHC_3BB0A8C1_0x004717FC | 0.0% | Pending SHC_3BB0A8C1_0x00471800 | 0.0% | Pending SHC_3BB0A8C1_0x00471804 | 0.0% | Pending -SHC_3BB0A8C1_0x00471810 | 0.0% | Pending +SHC_3BB0A8C1_0x00471810 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00471830 | 0.0% | Pending SHC_3BB0A8C1_0x00471860 | 0.0% | Pending SHC_3BB0A8C1_0x00471890 | 0.0% | Pending From 7ff275328af6d31ce5dfeb5a3d7a63a03c6b17a2 Mon Sep 17 00:00:00 2001 From: sourcehold Date: Wed, 13 May 2026 12:56:00 +0200 Subject: [PATCH 2/2] improve code style --- src/OpenSHC/Random/RNG/populateRNG1040.cpp | 21 +++++++++------------ src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/OpenSHC/Random/RNG/populateRNG1040.cpp b/src/OpenSHC/Random/RNG/populateRNG1040.cpp index efc746e..89aadef 100644 --- a/src/OpenSHC/Random/RNG/populateRNG1040.cpp +++ b/src/OpenSHC/Random/RNG/populateRNG1040.cpp @@ -10,27 +10,24 @@ namespace Random { void RNG::populateRNG1040() { - int iVar1; - int iVar2; - short* _pRandomNumber; MACRO_CALL(OpenSHC::Global_Func::SetRNGSeed)(this->seed); this->index2 = 0; this->index1 = 0; - _pRandomNumber = &this->randomNumbers[0]; - iVar2 = 20000; + short* _pRandomNumber = &this->randomNumbers[0]; + int n = 20000; do { - iVar1 = MACRO_CALL(OpenSHC::OS_Func::_rand)(); - *_pRandomNumber = (short)iVar1; - _pRandomNumber = _pRandomNumber + 1; - iVar2 = iVar2 + -1; - } while (iVar2 != 0); + int random = MACRO_CALL(OpenSHC::OS_Func::_rand)(); + *_pRandomNumber = (short)random; + _pRandomNumber += 1; + n -= 1; + } while (n != 0); this->currentNumber2 = this->randomNumbers[this->index2]; - this->index2 = this->index2 + 1; + this->index2 += 1; this->currentNumber1 = this->randomNumbers[this->index1]; - this->index1 = this->index1 + 1; + this->index1 += 1; return; } diff --git a/src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp b/src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp index 4fb06aa..3d62394 100644 --- a/src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp +++ b/src/OpenSHC/Random/RNG/setTimeBasedSeed.cpp @@ -11,8 +11,8 @@ namespace Random { { - __time64_t _Var1 = MACRO_CALL(OpenSHC::OS_Func::__time64)((__time64_t*)0x0); - this->seed = (int)_Var1; + __time64_t time = MACRO_CALL(OpenSHC::OS_Func::__time64)((__time64_t*)0x0); + this->seed = (int)time; return; }