-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerInfluence.cpp
54 lines (40 loc) · 1.84 KB
/
PlayerInfluence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "PlayerInfluence.h"
#include "Runtime.h"
namespace PlayerInfluence {
ProxyTypes::PushMethods base_PushMethods;
ProxyTypes::PushMethods orig_PushMethods;
Types::GetInstance GetInstance;
Types::SetTokensToGive SetTokensToGive;
int lSetTokensToGive(hks::lua_State* L) {
Influence* influence = GetInstance(L, 1, true);
int tokens = hks::checkinteger(L, 2);
SetTokensToGive(influence, tokens);
return 0;
}
int lSetPoints(hks::lua_State* L) {
Influence* influence = GetInstance(L, 1, true);
double points = hks::checknumber(L, 2);
*(unsigned int*)((uintptr_t)influence + 0xb8) = static_cast<unsigned int>(std::round(points * 256.0));
return 0;
}
int lAdjustPoints(hks::lua_State* L) {
void* influence = GetInstance(L, 1, true);
double amountPoints = hks::checknumber(L, 2);
*(unsigned int*)((uintptr_t)influence + 0xb8) += static_cast<unsigned int>(std::round(amountPoints * 256.0));
return 0;
}
void __cdecl PushMethods(hks::lua_State* L, int stackOffset) {
std::cout << "Hooked Influence::PushMethods!\n";
PushLuaMethod(L, lSetTokensToGive, "lSetTokensToGive", stackOffset, "SetTokensToGive");
PushLuaMethod(L, lSetPoints, "lSetPoints", stackOffset, "SetPoints");
PushLuaMethod(L, lAdjustPoints, "lAdjustPoints", stackOffset, "AdjustPoints");
base_PushMethods(L, stackOffset);
}
void Create() {
using namespace Runtime;
GetInstance = GetGameCoreGlobalAt<Types::GetInstance>(GET_INSTANCE_OFFSET);
SetTokensToGive = GetGameCoreGlobalAt<Types::SetTokensToGive>(SET_TOKENS_TO_GIVE_OFFSET);
orig_PushMethods = GetGameCoreGlobalAt<ProxyTypes::PushMethods>(PUSH_METHODS_OFFSET);
CreateHook(orig_PushMethods, &PushMethods, &base_PushMethods);
}
}