-
Notifications
You must be signed in to change notification settings - Fork 5
/
Hooks.cpp
223 lines (202 loc) · 6.2 KB
/
Hooks.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* __ __
*|__| _ _._ _ _ |__)|_
*| |(_)| |/_(_)| )| |__
*
* File: Hooks.cpp
* Created by Razzile & AlphaMATTER
*/
#include <substrate.h>
#include "Settings.h"
#define Hook(x,y,z) MSHookFunction(MSFindSymbol(NULL, x), (void*)y, (void**)&z)
#define Sym(x) MSFindSymbol(NULL, x)
__attribute__((constructor)) void InitHooks();
#pragma mark Utilities
/* definition of player abilities */
struct Abilities {
bool invulnerable;
bool flying;
bool mayfly;
bool instabuild;
};
void *playerRef = NULL;
bool IsEntityPlayer(void *entityRef)
{
return (entityRef == playerRef);
}
#pragma mark Originals
/* definition of original functions */
namespace Originals
{
namespace Player
{
float (*GetWalkingSpeedModifier)(void *self);
void (*Hurt)(void *self, void *entity, int damage);
void (*normalTick)(void *self);
}
namespace Mob
{
void (*JumpFromGround)(void *self, float height);
void (*ActuallyHurt)(void *self, int damage);
}
namespace Entity
{
bool (*IsInWater)(void *self);
bool (*IsInWaterOrRain)(void *self);
bool (*IsUnderLiquid)(void *self, void *material);
}
float (*HatchetItem_GetDestroySpeed)(void *ItemInstance, void *tile);
float (*PickaxeItem_GetDestroySpeed)(void *ItemInstance, void *tile);
float (*Item_GetDestroySpeed)(void *ItemInstance, void *tile);
float (*DiggerItem_GetDestroySpeed)(void *ItemInstance, void *tile);
float (*ShearsItem_GetDestroySpeed)(void *ItemInstance, void *tile);
float (*WeaponItem_GetDestroySpeed)(void *ItemInstance, void *tile);
namespace GameMode
{
void (*DestroyBlock)(void *self, void *player, int xco, int yco, int zco, char c);
}
}
#pragma mark Hooks
/* our mod implementations */
namespace Hooks {
namespace Player
{
float GetWalkingSpeedModifier(void *self)
{
return horizonSettings["kSpeed"];
}
void Hurt(void *self, void *entity, int damage)
{
bool invulnerable = horizonSettings["kInvulnerable"];
if(invulnerable)
{
return;
}
return Originals::Player::Hurt(self, entity, damage);
}
void normalTick(void *self)
{
playerRef = self;
bool fly = horizonSettings["kFly"];
if (fly)
{
/* The players Abilites struct is located 0xC6C bytes from the main player stack */
Abilities *dataPtr = (Abilities*)self;
Abilities *abilities = &dataPtr[0xC6C/sizeof(Abilities)];
abilities->mayfly = true;
}
return Originals::Player::normalTick(self);
}
}
namespace Mob
{
void JumpFromGround(void *self)
{
/* jump height is located 0x4C bytes up from Mob stack */
/* see this picture to see what I mean */
/* http://i.imgur.com/QeR9vPU.png */
float *dataPtr = (float*)self;
dataPtr[0x4C/sizeof(float)] = horizonSettings["kJump"];
}
void ActuallyHurt(void *self, int damage)
{
bool onehit = horizonSettings["kOnehit"];
if (onehit)
{
damage = 99;
}
return Originals::Mob::ActuallyHurt(self, damage);
}
}
namespace Entity
{
bool IsInWater(void *self)
{
bool enabled = horizonSettings["kWater"];
return (enabled) ? true : Originals::Entity::IsInWater(self);
}
bool IsInWaterOrRain(void *self)
{
bool enabled = horizonSettings["kWater"];
return (enabled) ? true : Originals::Entity::IsInWaterOrRain(self);
}
bool IsUnderLiquid(void *self, void *material)
{
bool scuba = horizonSettings["kScuba"];
if(scuba)
{
if(IsEntityPlayer(self))
{
return false;
}
}
return Originals::Entity::IsUnderLiquid(self, material);
}
}
namespace Items
{
float HatchetItem_GetDestroySpeed(void *ItemInstance, void *tile)
{
return horizonSettings["kDestroy"];
}
float PickaxeItem_GetDestroySpeed(void *ItemInstance, void *tile)
{
return horizonSettings["kDestroy"];
}
float Item_GetDestroySpeed(void *ItemInstance, void *tile)
{
return horizonSettings["kDestroy"];
}
float DiggerItem_GetDestroySpeed(void *ItemInstance, void *tile)
{
return horizonSettings["kDestroy"];
}
float ShearsItem_GetDestroySpeed(void *ItemInstance, void *tile)
{
return horizonSettings["kDestroy"];
}
float WeaponItem_GetDestroySpeed(void *ItemInstance, void *tile)
{
return horizonSettings["kDestroy"];
}
}
namespace GameMode
{
void DestroyBlock(void *self, void *player, int xco, int yco, int zco, char c)
{
bool nuker = horizonSettings["kNuker"];
int size = horizonSettings["kNukerSize"];
if(nuker)
{
for (int x = 0-size/2; x < size/2; x++)
{
for (int y = 0-size/2; y < size/2; y++)
{
for (int z = 0-size/2; z < size/2; z++)
{
Originals::GameMode::DestroyBlock(self, player, xco+x, yco+y, zco+z, c);
Originals::GameMode::DestroyBlock(self, player, xco+x, yco-y, zco+z, c);
}
}
}
}
return Originals::GameMode::DestroyBlock(self, player, xco, yco, zco, c);
}
}
} /* END HOOKS */
void InitHooks()
{
using namespace Hooks;
Hook("__ZN6Player23getWalkingSpeedModifierEv", Player::GetWalkingSpeedModifier, Originals::Player::GetWalkingSpeedModifier);
Hook("__ZN6Player4hurtEP6Entityi", Player::Hurt, Originals::Player::Hurt);
Hook("__ZN11LocalPlayer10normalTickEv", Player::normalTick, Originals::Player::normalTick);
Hook("__ZN3Mob14jumpFromGroundEv", Mob::JumpFromGround, Originals::Mob::JumpFromGround);
Hook("__ZN3Mob12actuallyHurtEi", Mob::ActuallyHurt, Originals::Mob::ActuallyHurt);
Hook("__ZN6Entity13isUnderLiquidEPK8Material", Entity::IsUnderLiquid, Originals::Entity::IsUnderLiquid);
Hook("__ZN11HatchetItem15getDestroySpeedEP12ItemInstanceP4Tile", Items::HatchetItem_GetDestroySpeed, Originals::HatchetItem_GetDestroySpeed);
Hook("__ZN11PickaxeItem15getDestroySpeedEP12ItemInstanceP4Tile", Items::HatchetItem_GetDestroySpeed, Originals::HatchetItem_GetDestroySpeed);
Hook("__ZN4Item15getDestroySpeedEP12ItemInstanceP4Tile", Items::Item_GetDestroySpeed, Originals::Item_GetDestroySpeed);
Hook("__ZN10DiggerItem15getDestroySpeedEP12ItemInstanceP4Tile", Items::DiggerItem_GetDestroySpeed, Originals::DiggerItem_GetDestroySpeed);
Hook("__ZN10ShearsItem15getDestroySpeedEP12ItemInstanceP4Tile", Items::ShearsItem_GetDestroySpeed, Originals::ShearsItem_GetDestroySpeed);
Hook("__ZN10WeaponItem15getDestroySpeedEP12ItemInstanceP4Tile", Items::WeaponItem_GetDestroySpeed, Originals::WeaponItem_GetDestroySpeed);
Hook("__ZN8GameMode12destroyBlockEP6Playeriiia", GameMode::DestroyBlock, Originals::GameMode::DestroyBlock);
}