Skip to content

Commit 3de6972

Browse files
committed
1.05
1 parent 5ef39a3 commit 3de6972

File tree

5 files changed

+79
-18
lines changed

5 files changed

+79
-18
lines changed

src/Image.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Image::Image()
3737
spdlog::info("\tResolved to version: 1.04");
3838
version = MakeVersion(1,4);
3939
break;
40+
case 0x20F87F01:
41+
spdlog::info("\tResolved to version: 1.05");
42+
version = MakeVersion(1, 5);
43+
break;
4044
default:
4145
spdlog::error("\tUnknown version, please update the mod");
4246
break;

src/overlay/Overlay.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void Overlay::DrawImgui(IDXGISwapChain3* apSwapChain)
4646

4747
ImGui::Begin("Cyber Engine Tweaks");
4848

49-
if (Options::Get().GameImage.version == Image::MakeVersion(1, 4))
49+
if (Options::Get().GameImage.version == Image::MakeVersion(1, 4) ||
50+
Options::Get().GameImage.version == Image::MakeVersion(1, 5))
5051
{
5152
ImGui::PushItemWidth(600.f);
5253

src/reverse/RTTI.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct CRTTIBaseType
3434
};
3535

3636
struct CClassFunction;
37+
struct CBaseFunction;
3738

3839
struct CClass : CRTTIBaseType
3940
{
@@ -50,7 +51,7 @@ struct IRTTISystem
5051
virtual void sub_3() = 0;
5152
virtual void sub_4() = 0;
5253
virtual void sub_5() = 0;
53-
virtual void sub_6() = 0;
54+
virtual CBaseFunction* GetGlobalFunction(uint64_t aNameHash) = 0;
5455
virtual void sub_7() = 0;
5556
virtual void sub_8() = 0;
5657
virtual void sub_9() = 0;

src/reverse/Scripting.cpp

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,40 @@
55
#include <spdlog/spdlog.h>
66

77
#include "Engine.h"
8+
#include "Options.h"
89
#include "Pattern.h"
910
#include "RTTI.h"
1011
#include "Utils.h"
1112

1213
using TExec = bool(void* apThis, ScriptArgs* apArgs, Result* apResult, uintptr_t apScriptable);
1314
auto* RealExec = (TExec*)(0x25FB960 + reinterpret_cast<uintptr_t>(GetModuleHandleA(nullptr)));
1415

16+
struct Unk523
17+
{
18+
int64_t unk0;
19+
uint64_t unk8;
20+
};
21+
22+
struct CScriptableStackFrame
23+
{
24+
int64_t vtbl;
25+
int64_t unk8;
26+
int64_t unk10;
27+
int64_t scriptable18;
28+
int64_t scriptable20;
29+
int64_t unk28;
30+
int64_t args;
31+
int32_t argCount;
32+
int64_t unk40;
33+
};
34+
1535
bool Scripting::Execute(const std::string& aCommand, std::string& aReturnMessage)
1636
{
1737
const auto argsStart = aCommand.find_first_of('(');
1838
const auto argsEnd = aCommand.find_first_of(')');
1939

2040
const auto funcName = aCommand.substr(0, argsStart);
41+
trim(funcName);
2142

2243
std::string s = aCommand.substr(argsStart + 1, argsEnd - argsStart - 1);
2344
const std::string delimiter = ",";
@@ -37,33 +58,71 @@ bool Scripting::Execute(const std::string& aCommand, std::string& aReturnMessage
3758
trim(s);
3859
redArgs.emplace_back(s.c_str());
3960

61+
uintptr_t arg0Rtti = 0;
62+
uintptr_t argiRtti = 0;
63+
uintptr_t ctorOffset = 0;
64+
uintptr_t execOffset = 0;
65+
66+
if (Options::Get().GameImage.version == Image::MakeVersion(1, 4))
67+
{
68+
arg0Rtti = 0x1442FD030 - 0x140000000;
69+
argiRtti = 0x143C62438 - 0x140000000;
70+
ctorOffset = 0x140270370 - 0x140000000;
71+
execOffset = 0x1402254A0 - 0x140000000;
72+
}
73+
else if (Options::Get().GameImage.version == Image::MakeVersion(1, 5))
74+
{
75+
arg0Rtti = 0x1442BC710 - 0x140000000;
76+
argiRtti = 0x143C22238 - 0x140000000;
77+
ctorOffset = 0x14026F8A0 - 0x140000000;
78+
execOffset = 0x1402249F0 - 0x140000000;
79+
}
80+
4081
auto* const type = CRTTISystem::Get()->GetType<CClass>(REDString::Hash("cpPlayerSystem"));
4182
auto* const engine = CGameEngine::Get();
4283
auto* unk10 = engine->framework->unk10;
4384

85+
auto func = CRTTISystem::Get()->GetGlobalFunction(REDString::Hash(funcName.c_str()));
86+
4487
const auto scriptable = unk10->GetTypeInstance(type);
4588

46-
ScriptArgs args{};
47-
args.args = redArgs.data();
48-
args.argCount = redArgs.size() & 0xFFFFFFFF;
89+
uint64_t a1 = *(uintptr_t*)(scriptable + 0x40);
4990

50-
Result result;
91+
Unk523 args[4];
92+
args[0].unk0 = *(uintptr_t*)(arg0Rtti + (uintptr_t)GetModuleHandle(nullptr));
93+
args[0].unk8 = (uint64_t)&a1;
5194

52-
if (!RealExec(nullptr, &args, &result, scriptable))
95+
for(auto i = 1u; i < redArgs.size(); ++i)
5396
{
54-
aReturnMessage = result.output->ToString();
55-
return false;
97+
args[i].unk0 = (uintptr_t)(argiRtti + (uintptr_t)GetModuleHandle(nullptr));
98+
args[i].unk8 = (uint64_t)&redArgs[i];
5699
}
57100

58-
return true;
101+
CScriptableStackFrame stack;
102+
auto script40 = *(uintptr_t*)(scriptable + 0x40);
103+
auto script40100 = *(uintptr_t*)(script40 + 0x100);
104+
105+
using ctor_t = CScriptableStackFrame * (*)(CScriptableStackFrame* aThis, __int64 aScriptable, Unk523* aArgs,
106+
int aArgsCount, __int64 a5, __int64* a6);
107+
ctor_t ctor = (ctor_t)(ctorOffset + (uintptr_t)GetModuleHandle(nullptr));
108+
109+
Result result;
110+
111+
ctor(&stack, scriptable, args, 3, 0, 0);
112+
113+
using exec_t = bool (*)(CBaseFunction* aThis, CScriptableStackFrame* stack);
114+
exec_t exec = (exec_t)(execOffset + (uintptr_t)GetModuleHandle(nullptr));
115+
116+
return exec(func, &stack);
59117
}
60118

61119
Result::Result()
62120
{
63-
static auto* ptr = FindSignature({ 0x4C,0x8D,0x25,0x03,0x63,0xAF,0x02,0x4C
64-
,0x89,0xBC,0x24,0x90,0x01,0x00,0x00,0x66
65-
,0x0F,0x42,0xC1,0x0F,0x29,0xBC,0x24,0x70
66-
,0x01,0x00 }) + 3;
121+
static auto* ptr = FindSignature({
122+
0x48, 0x89, 0xB4, 0x24, 0xD8, 0x01, 0x00, 0x00, 0xB9,
123+
0x05, 0x00, 0x00, 0x00, 0x4C, 0x89, 0xA4, 0x24, 0xA0,
124+
0x01, 0x00, 0x00, 0x66, 0x3B, 0xC1, 0x4C, 0x89, 0xAC,
125+
0x24, 0x98, 0x01, 0x00, 0x00, 0x4C, 0x8D, 0x25 }) + 0x24;
67126

68127
output = reinterpret_cast<REDString*>(ptr + *reinterpret_cast<int32_t*>(ptr) + 4);
69128
}

src/string_initalizer_patch.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#include <windows.h>
2-
31
#include "Image.h"
4-
#include <utility>
5-
#include <cstring>
62
#include <spdlog/spdlog.h>
73
#include <cstdint>
84

0 commit comments

Comments
 (0)