5
5
#include < spdlog/spdlog.h>
6
6
7
7
#include " Engine.h"
8
+ #include " Options.h"
8
9
#include " Pattern.h"
9
10
#include " RTTI.h"
10
11
#include " Utils.h"
11
12
12
13
using TExec = bool (void * apThis, ScriptArgs* apArgs, Result* apResult, uintptr_t apScriptable);
13
14
auto * RealExec = (TExec*)(0x25FB960 + reinterpret_cast <uintptr_t >(GetModuleHandleA(nullptr )));
14
15
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
+
15
35
bool Scripting::Execute (const std::string& aCommand, std::string& aReturnMessage)
16
36
{
17
37
const auto argsStart = aCommand.find_first_of (' (' );
18
38
const auto argsEnd = aCommand.find_first_of (' )' );
19
39
20
40
const auto funcName = aCommand.substr (0 , argsStart);
41
+ trim (funcName);
21
42
22
43
std::string s = aCommand.substr (argsStart + 1 , argsEnd - argsStart - 1 );
23
44
const std::string delimiter = " ," ;
@@ -37,33 +58,71 @@ bool Scripting::Execute(const std::string& aCommand, std::string& aReturnMessage
37
58
trim (s);
38
59
redArgs.emplace_back (s.c_str ());
39
60
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
+
40
81
auto * const type = CRTTISystem::Get ()->GetType <CClass>(REDString::Hash (" cpPlayerSystem" ));
41
82
auto * const engine = CGameEngine::Get ();
42
83
auto * unk10 = engine->framework ->unk10 ;
43
84
85
+ auto func = CRTTISystem::Get ()->GetGlobalFunction (REDString::Hash (funcName.c_str ()));
86
+
44
87
const auto scriptable = unk10->GetTypeInstance (type);
45
88
46
- ScriptArgs args{};
47
- args.args = redArgs.data ();
48
- args.argCount = redArgs.size () & 0xFFFFFFFF ;
89
+ uint64_t a1 = *(uintptr_t *)(scriptable + 0x40 );
49
90
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;
51
94
52
- if (! RealExec ( nullptr , &args, &result, scriptable) )
95
+ for ( auto i = 1u ; i < redArgs. size (); ++i )
53
96
{
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] ;
56
99
}
57
100
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);
59
117
}
60
118
61
119
Result::Result ()
62
120
{
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 ;
67
126
68
127
output = reinterpret_cast <REDString*>(ptr + *reinterpret_cast <int32_t *>(ptr) + 4 );
69
128
}
0 commit comments