Repository navigation
Expand file tree
/
Copy pathhook.cpp
More file actions
189 lines (135 loc) · 6.51 KB
/
Copy pathhook.cpp
File metadata and controls
189 lines (135 loc) · 6.51 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "hook.h"
#include "F4VRBody.h"
#include "f4se/GameReferences.h"
#include "f4se/GameCamera.h"
#include "xbyak/xbyak.h"
//RelocAddr<uintptr_t> hookBeforeRenderer(0xd844bc); // this hook didn't work as only a few nodes get moved
RelocAddr<uintptr_t> hookBeforeRenderer(0x1C21156); // This hook is in member function 0x33 for BSFlattenedBoneTree right before it updates it's own data buffer of all the skeleton world transforms. I think that buffer is what actually gets rendered
//RelocAddr<uintptr_t> hookMainLoopFunc(0xd8187e); // now using in fo4vr better scopes
RelocAddr<uintptr_t> hookAnimationVFunc(0xf2f0a8); // This is PostUpdateAnimationGraphManager virtual function that updates the player skeleton below the hmd.
RelocAddr<uintptr_t> hookPlayerUpdate(0xf1004c);
RelocAddr<uintptr_t> hookBoneTreeUpdate(0xd84ee4);
RelocAddr<uintptr_t> hookEndUpdate(0xd84f2c);
RelocAddr<uintptr_t> hookMainDrawCandidate(0xd844bc);
RelocAddr<uintptr_t> hookMainDrawandUi(0xd87ace);
typedef void(*_hookedFunc)(uint64_t param1, uint64_t param2, uint64_t param3);
RelocAddr<_hookedFunc> hookedFunc(0x1C18620);
typedef void(*_hookedPosPlayerFunc)(double param1, double param2, double param3);
RelocAddr<_hookedPosPlayerFunc> hookedPosPlayerFunc(0x2841530);
typedef void(*_hookedMainDrawCandidateFunc)(uint64_t param1, uint64_t param2, uint64_t param3, uint64_t param4);
RelocAddr<_hookedMainDrawCandidateFunc> hookedMainDrawCandidateFunc(0xd831f0);
//typedef void(*_hookedMainLoop)();
//RelocAddr<_hookedMainLoop> hookedMainLoop(0xd83ac0);
typedef void(*_hookedf10ed0)(uint64_t pc);
RelocAddr<_hookedf10ed0> hookedf10ed0(0xf10ed0);
typedef void(*_hookedda09a0)(uint64_t parm);
RelocAddr<_hookedda09a0> hookedda09a0(0xda09a0);
typedef void(*_hooked1c22fb0)(uint64_t a, uint64_t b);
RelocAddr<_hooked1c22fb0> hooked1c22fb0(0x1c22fb0);
typedef void(*_main_update_player)(uint64_t rcx, uint64_t rdx);
RelocAddr<_main_update_player> main_update_player(0x1c22fb0);
RelocAddr<uintptr_t> hookMainUpdatePlayer(0x0f0ff6a);
typedef void(*_hookMultiBoundCullingFunc)();
RelocAddr<_hookMultiBoundCullingFunc> hookMultiBoundCullingFunc(0x0d84930);
RelocAddr<uintptr_t> hookMultiBoundCulling(0x0d8445d);
// renderer stuff
void RendererEnable(std::uint64_t a_ptr, bool a_bool) {
using func_t = decltype(&RendererEnable);
RelocAddr<func_t> func(0x0b00150);
return func(a_ptr, a_bool);
}
std::uint64_t RendererGetByName(const BSFixedString& a_name) {
using func_t = decltype(&RendererGetByName);
RelocAddr<func_t> func(0x0b00270);
return func(a_name);
}
RelocAddr<uint64_t> wandMesh(0x2d686d8);
void hookIt(uint64_t rcx) {
uint64_t parm = rcx;
F4VRBody::update();
//hookedf10ed0((uint64_t)(*g_player)); // this function does the final body updates and does some stuff with the world bound to reporting up the parent tree.
// so all of this below is an attempt to bypass the functionality in game around my hook at resets the root parent node's world pos which screws up armor
// we still need to call the fucntion i hooked below to get some things ready for the renderer however starting with the named "Root" node instead of it's parent preseves locations
if ((*g_player)->unkF0 && (*g_player)->unkF0->rootNode) {
if ((*g_player)->unkF0->rootNode->m_children.m_emptyRunStart > 0) {
if ((*g_player)->unkF0->rootNode->m_children.m_data[0]) {
uint64_t arr[5] = { 0, 0, 0, 0, 0 };
uint64_t body = (uint64_t) & (*(*g_player)->unkF0->rootNode->m_children.m_data[0]);
arr[1] = body + 0x180;
arr[2] = 0x800;
arr[3] = 2;
arr[4] = 0x3c0c1400;
hooked1c22fb0(body, (uint64_t)&arr);
}
}
}
hookedda09a0(parm);
return;
}
void hook2(uint64_t rcx, uint64_t rdx, uint64_t r8, uint64_t r9) {
F4VRBody::update();
hookedMainDrawCandidateFunc(rcx, rdx, r8, r9);
BSFixedString name("ScopeMenu");
std::uint64_t renderer = RendererGetByName(name);
if (renderer) {
// RendererEnable(renderer, false);
}
return;
}
void hook3(double param1, double param2, double param3) {
hookedPosPlayerFunc(param1, param2, param3);
F4VRBody::update();
return;
}
void hook4() {
F4VRBody::update();
hookMultiBoundCullingFunc();
return;
}
void hookSmoothMovement() {
if ((*g_player)->unkF0 && (*g_player)->unkF0->rootNode) {
F4VRBody::smoothMovement();
}
hookMultiBoundCullingFunc();
}
void hook_main_update_player(uint64_t rcx, uint64_t rdx) {
if ((*g_player) && (*g_player)->unkF0 && (*g_player)->unkF0->rootNode) {
NiNode* body = (*g_player)->unkF0->rootNode->GetAsNiNode();
body->m_localTransform.pos.x = (*g_playerCamera)->cameraNode->m_worldTransform.pos.x;
body->m_localTransform.pos.y = (*g_playerCamera)->cameraNode->m_worldTransform.pos.y;
body->m_worldTransform.pos.x = (*g_playerCamera)->cameraNode->m_worldTransform.pos.x;
body->m_worldTransform.pos.y = (*g_playerCamera)->cameraNode->m_worldTransform.pos.y;
static BSFixedString pwn("PlayerWorldNode");
NiNode* pwn_node = (*g_player)->unkF0->rootNode->m_parent->GetObjectByName(&pwn)->GetAsNiNode();
body->m_localTransform.pos.z += pwn_node->m_localTransform.pos.z;
body->m_worldTransform.pos.z += pwn_node->m_localTransform.pos.z;
}
main_update_player(rcx, rdx);
}
void updateCounter() {
g_mainLoopCounter++;
//hookedMainLoop();
}
void hookMain() {
//_MESSAGE("Hooking before main renderer");
// g_branchTrampoline.Write5Call(hookBeforeRenderer.GetUIntPtr(), (uintptr_t)hookIt);
//_MESSAGE("Successfully hooked before main renderer");
// replace mesh pointer string
const char* mesh = "Data\\Meshes\\FRIK\\_primaryWand.nif";
for (int i = 0; i < strlen(mesh); ++i) {
SafeWrite8(wandMesh.GetUIntPtr() + i, mesh[i]);
}
int bytesToNOP = 0x1FF;
for (int i = 0; i < bytesToNOP; ++i) {
SafeWrite8(hookAnimationVFunc.GetUIntPtr() + i, 0x90); // this block resets the body pose to hang off the camera. Blocking this off so body height is correct.
}
// g_branchTrampoline.Write5Call(hookAnimationVFunc.GetUIntPtr(), (uintptr_t)&F4VRBody::update);
// g_branchTrampoline.Write5Call(hookEndUpdate.GetUIntPtr(), (uintptr_t)&hookIt);
g_branchTrampoline.Write5Call(hookMainDrawCandidate.GetUIntPtr(), (uintptr_t)&hook2);
// g_branchTrampoline.Write5Call(hookMultiBoundCulling.GetUIntPtr(), (uintptr_t)&hook4);
g_branchTrampoline.Write5Call(hookMainUpdatePlayer.GetUIntPtr(), (uintptr_t)&hook_main_update_player);
g_branchTrampoline.Write5Call(hookMultiBoundCulling.GetUIntPtr(), (uintptr_t)&hookSmoothMovement);
// _MESSAGE("hooking main loop function");
// g_branchTrampoline.Write5Call(hookMainLoopFunc.GetUIntPtr(), (uintptr_t)updateCounter);
// _MESSAGE("successfully hooked main loop");
}