Repository navigation
Expand file tree
/
Copy pathhook.cpp
More file actions
97 lines (68 loc) · 2.34 KB
/
Copy pathhook.cpp
File metadata and controls
97 lines (68 loc) · 2.34 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
#include "hook.h"
#include "utils.h"
#include "config.h"
#include "BetterScopes.h"
#include <math.h>
RelocAddr<uintptr_t> hookMainLoopFunc(0xd83ebc);
RelocAddr<uintptr_t> hookLateCulling(0xd84ee4);
RelocAddr<uintptr_t> hookEyeFOVAdjust(0x2804c26);
typedef void(*_hookedMainLoop)(uint64_t rcx);
RelocAddr<_hookedMainLoop> hookedMainLoop(0x1ba7a80);
typedef void(*_hookedLateCulling)(uint64_t rcx);
RelocAddr<_hookedLateCulling> hookedLateCulling(0xf10ed0);
typedef void(*_hookedEyeFOVAdjustFunc)(uintptr_t camera, uintptr_t adjust, UINT eye);
RelocAddr<_hookedEyeFOVAdjustFunc> hookedEyeFOVAdjustFunc(0x1c2bf60);
bool dir = true;
namespace Hook {
void hookIt(uint64_t rcx) {
BetterScopes::update();
hookedMainLoop(rcx);
return;
}
void hookCulling(uint64_t rcx) {
BetterScopes::keepScopeVisible();
hookedLateCulling(rcx);
return;
}
struct eyeFOV {
float left;
float right;
float bottom;
float top;
};
void hookEyeFOV(uintptr_t camera, uintptr_t adjust, UINT eye) {
eyeFOV* fov = (eyeFOV*)adjust;
float fovScale = BetterScopes::getScopeZoomScaleConfig();
float fovMult = BetterScopes::getZoomMultiplier() * fovScale;
float fovSpeed = BetterScopes::getScopeZoomSpeedConfig();
static float fovAdjust = 0.0f;
if (fovAdjust < fovMult) {
fovAdjust += fovSpeed;
}
else if (fovAdjust > 0.0f) {
fovAdjust -= fovSpeed;
}
if (fovAdjust < 0.0f) {
// never zoom out
fovAdjust = 0.0f;
}
float leftDeg = BetterScopes::rads_to_degrees(atan(fov->left));
float rightDeg = BetterScopes::rads_to_degrees(atan(fov->right));
float botDeg = BetterScopes::rads_to_degrees(atan(fov->bottom));
float topDeg = BetterScopes::rads_to_degrees(atan(fov->top));
leftDeg += fovAdjust;
rightDeg -= fovAdjust;
topDeg += fovAdjust;
botDeg -= fovAdjust;
fov->left = tanf(BetterScopes::degrees_to_rads(leftDeg));
fov->right = tanf(BetterScopes::degrees_to_rads(rightDeg));
fov->top = tanf(BetterScopes::degrees_to_rads(topDeg));
fov->bottom = tanf(BetterScopes::degrees_to_rads(botDeg));
hookedEyeFOVAdjustFunc(camera, adjust, eye);
}
void hookMain() {
g_branchTrampoline.Write5Call(hookMainLoopFunc.GetUIntPtr(), (uintptr_t)&hookIt);
g_branchTrampoline.Write5Call(hookLateCulling.GetUIntPtr(), (uintptr_t)&hookCulling);
g_branchTrampoline.Write5Call(hookEyeFOVAdjust.GetUIntPtr(), (uintptr_t)&hookEyeFOV);
}
}