-
Notifications
You must be signed in to change notification settings - Fork 3
/
Autowall.cpp
332 lines (263 loc) · 8.82 KB
/
Autowall.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*credits by ibanned*/
#include "AutoWall.h"
//#include "R.h"
#define HITGROUP_GENERIC 0
#define HITGROUP_HEAD 1
#define HITGROUP_CHEST 2
#define HITGROUP_STOMACH 3
#define HITGROUP_LEFTARM 4
#define HITGROUP_RIGHTARM 5
#define HITGROUP_LEFTLEG 6
#define HITGROUP_RIGHTLEG 7
#define HITGROUP_GEAR 10
inline bool CGameTrace::DidHitWorld() const
{
return m_pEnt->GetIndex() == 0;
}
inline bool CGameTrace::DidHitNonWorldEntity() const
{
return m_pEnt != NULL && !DidHitWorld();
}
bool HandleBulletPenetration(CSWeaponInfo *wpn_data, FireBulletData &data);
bool isArmored(IClientEntity *player, int armorVal, int hitgroup)
{
bool res = false;
if (armorVal > 0)
{
switch (hitgroup)
{
case HITGROUP_GENERIC:
case HITGROUP_CHEST:
case HITGROUP_STOMACH:
case HITGROUP_LEFTARM:
case HITGROUP_RIGHTARM:
res = true;
break;
case HITGROUP_HEAD:
res = player->HasHelmet();
break;
}
}
return res;
}
float GetHitgroupDamageMult(int iHitGroup)
{
switch (iHitGroup)
{
case HITGROUP_GENERIC:
return 1.f;
case HITGROUP_HEAD:
return 4.f;
case HITGROUP_CHEST:
return 1.f;
case HITGROUP_STOMACH:
return 1.25f;
case HITGROUP_LEFTARM:
return 1.f;
case HITGROUP_RIGHTARM:
return 1.f;
case HITGROUP_LEFTLEG:
return 0.75f;
case HITGROUP_RIGHTLEG:
return 0.75f;
case HITGROUP_GEAR:
return 1.f;
default:
break;
}
return 1.f;
}
void ScaleDamage(int hitgroup, IClientEntity *enemy, float weapon_armor_ratio, float ¤t_damage)
{
current_damage *= GetHitgroupDamageMult(hitgroup);
if (enemy->ArmorValue() > 0)
{
if (hitgroup == HITGROUP_HEAD)
{
if (enemy->HasHelmet())
{
current_damage *= (weapon_armor_ratio * 0.5f);
}
}
else
{
current_damage *= (weapon_armor_ratio* 0.5);
}
}
}
/*
void ScaleDamage(int hitgroup, IClientEntity *player, float weapon_armor_ratio, float ¤t_damage)
{
bool heavArmor = player->m_bHasHeavyArmor();
int armor = player->ArmorValue();
player->ArmorValue();
switch (hitgroup)
{
case HITGROUP_HEAD:
if (heavArmor)
current_damage *= (current_damage * 4.f) * 0.5f;
else
current_damage *= 4.f;
break;
case HITGROUP_CHEST:
case HITGROUP_LEFTARM:
case HITGROUP_RIGHTARM:
current_damage *= 1.f;
break;
case HITGROUP_STOMACH:
current_damage *= 1.25f;
break;
case HITGROUP_LEFTLEG:
case HITGROUP_RIGHTLEG:
current_damage *= 0.75f;
break;
}
if (isArmored(player, armor, hitgroup))
{
float v47 = 1.f, armor_bonus_ratio = 0.5f, armor_ratio = weapon_armor_ratio;
if (heavArmor)
{
armor_bonus_ratio = 0.33f;
armor_ratio = (weapon_armor_ratio * 0.5f) * 0.5f;
v47 = 0.33f;
}
float new_damage = current_damage * armor_ratio;
if (heavArmor)
new_damage *= 0.85f;
if (((current_damage - (current_damage * armor_ratio)) * (v47 * armor_bonus_ratio)) > armor)
new_damage = current_damage - (armor / armor_bonus_ratio);
current_damage = new_damage;
}
}*/
bool SimulateFireBullet(IClientEntity* entity, IClientEntity *local, C_BaseCombatWeapon *weapon, FireBulletData &data)
{
data.penetrate_count = 4;
data.trace_length = 0.0f;
auto *wpn_data = weapon->GetCSWpnData();
data.current_damage = (float)wpn_data->m_iDamage;
while ((data.penetrate_count > 0) && (data.current_damage >= 1.0f))
{
data.trace_length_remaining = wpn_data->m_flRange - data.trace_length;
Vector end = data.src + data.direction * data.trace_length_remaining;
//UTIL_TraceLine(data.src, end + data.direction *40.f, 0x4600400B, local, 0, &data.enter_trace);
UTIL_TraceLine(data.src, end, MASK_SHOT | CONTENTS_GRATE, local, 0, &data.enter_trace);
//UTIL_ClipTraceToPlayers( data.src, end + data.direction * 40.f, 0x4600400B, &data.filter, &data.enter_trace);// honestly no reason to have to traces...
if (data.enter_trace.fraction == 1.0f)
break;
ClientClass* pClass = (ClientClass*)data.enter_trace.m_pEnt->GetClientClass();
if ((data.enter_trace.hitgroup <= 7) && (data.enter_trace.hitgroup > 0) && pClass->m_ClassID != (int)CSGOClassID::CHostage && (local->GetTeamNum() != data.enter_trace.m_pEnt->GetTeamNum() || g_menu::window.RageBotTab.naosei.GetState()))
{
data.trace_length += (float)(data.enter_trace.fraction * data.trace_length_remaining);
data.current_damage *= (float)(pow(wpn_data->m_flRangeModifier, data.trace_length * 0.002));
ScaleDamage(data.enter_trace.hitgroup, data.enter_trace.m_pEnt, wpn_data->m_flArmorRatio, data.current_damage);
return true;
}
if (!HandleBulletPenetration(wpn_data, data))
break;
}
return false;
}
/*OLD*/
/*
bool SimulateFireBullet(IClientEntity *local, CBaseCombatWeapon *weapon, FireBulletData &data)
{
data.penetrate_count = 4; // Max Amount Of Penitration
data.trace_length = 0.0f; // wow what a meme
auto *wpn_data = weapon->GetCSWpnData(); // Get Weapon Info
data.current_damage = (float)wpn_data->iDamage;// Set Damage Memes
while ((data.penetrate_count > 0) && (data.current_damage >= 1.0f))
{
data.trace_length_remaining = wpn_data->flRange - data.trace_length;
Vector End_Point = data.src + data.direction * data.trace_length_remaining;
UTIL_TraceLine(data.src, End_Point, MASK_SHOT | CONTENTS_GRATE, local, 0, &data.enter_trace);
UTIL_ClipTraceToPlayers(data.src, End_Point + data.direction * 40.f, MASK_SHOT | CONTENTS_GRATE, &data.filter, &data.enter_trace);
if (data.enter_trace.fraction == 1.0f)
break;
if ((data.enter_trace.hitgroup <= 7) && (data.enter_trace.hitgroup > 0) && (local->GetTeamNum() != data.enter_trace.m_pEnt->GetTeamNum()))
{
data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
data.current_damage *= pow(wpn_data->flRangeModifier, data.trace_length * 0.002);
ScaleDamage(data.enter_trace.hitgroup, data.enter_trace.m_pEnt, wpn_data->flArmorRatio, data.current_damage);
return true;
}
if (!HandleBulletPenetration(wpn_data, data)) break;
}
return false;
}*/
bool HandleBulletPenetration(CSWeaponInfo *wpn_data, FireBulletData &data)
{
surfacedata_t *enter_surface_data = Interfaces::PhysProps->GetSurfaceData(data.enter_trace.surface.surfaceProps);
int enter_material = enter_surface_data->game.material;
float enter_surf_penetration_mod = enter_surface_data->game.flPenetrationModifier;
data.trace_length += data.enter_trace.fraction * data.trace_length_remaining;
data.current_damage *= (float)(pow(wpn_data->m_flRangeModifier, (data.trace_length * 0.002)));
if ((data.trace_length > 3000.f) || (enter_surf_penetration_mod < 0.1f))
data.penetrate_count = 0;
if (data.penetrate_count <= 0)
return false;
Vector dummy;
trace_t trace_exit;
if (!TraceToExit(dummy, data.enter_trace, data.enter_trace.endpos, data.direction, &trace_exit))
return false;
surfacedata_t *exit_surface_data = Interfaces::PhysProps->GetSurfaceData(trace_exit.surface.surfaceProps);
int exit_material = exit_surface_data->game.material;
float exit_surf_penetration_mod = exit_surface_data->game.flPenetrationModifier;
float final_damage_modifier = 0.16f;
float combined_penetration_modifier = 0.0f;
if (((data.enter_trace.contents & CONTENTS_GRATE) != 0) || (enter_material == 89) || (enter_material == 71))
{
combined_penetration_modifier = 3.0f;
final_damage_modifier = 0.05f;
}
else
{
combined_penetration_modifier = (enter_surf_penetration_mod + exit_surf_penetration_mod) * 0.5f;
}
if (enter_material == exit_material)
{
if (exit_material == 87 || exit_material == 85)
combined_penetration_modifier = 3.0f;
else if (exit_material == 76)
combined_penetration_modifier = 2.0f;
}
float v34 = fmaxf(0.f, 1.0f / combined_penetration_modifier);
float v35 = (data.current_damage * final_damage_modifier) + v34 * 3.0f * fmaxf(0.0f, (3.0f / wpn_data->m_flPenetration) * 1.25f);
float thickness = VectorLength(trace_exit.endpos - data.enter_trace.endpos);
thickness *= thickness;
thickness *= v34;
thickness /= 24.0f;
float lost_damage = fmaxf(0.0f, v35 + thickness);
if (lost_damage > data.current_damage)
return false;
if (lost_damage >= 0.0f)
data.current_damage -= lost_damage;
if (data.current_damage < 1.0f)
return false;
data.src = trace_exit.endpos;
data.penetrate_count--;
return true;
}
/*
* CanHit() - example of how to use the code
* @in point: target hitbox vector
* @out damage_given: amount of damage the shot would do
*/
bool CanHit(IClientEntity* entity, const Vector &point, float *damage_given)
{
//Utils::ToLog("CANHIT");
auto *local = Interfaces::EntList->GetClientEntity(Interfaces::Engine->GetLocalPlayer());
auto data = FireBulletData(local->GetOrigin() + local->GetViewOffset());
data.filter = CTraceFilter();
data.filter.pSkip = local;
Vector angles;
CalcAngle(data.src, point, angles);
AngleVectors(angles, &data.direction);
VectorNormalize(data.direction);
if (SimulateFireBullet(entity, local, (C_BaseCombatWeapon*)Interfaces::EntList->GetClientEntityFromHandle((HANDLE)local->GetActiveWeaponHandle()), data))
{
*damage_given = data.current_damage;
//Utils::ToLog("CANHIT END");
return true;
}
return false;
}