still not working as intended

This commit is contained in:
nullifiedcat 2017-11-24 21:46:19 +03:00
parent dca7c701b9
commit 506df2cccb
13 changed files with 93 additions and 73 deletions

View File

@ -13,14 +13,14 @@ class IClientEntity;
// BUGBUG TODO this struct is outdated // BUGBUG TODO this struct is outdated
struct crithack_saved_state { struct crithack_saved_state {
float bucket; // 2612 float unknown2868;
bool unknown2831; float unknown2864;
int seed; // 2868 int unknown2620;
float time; // 2872 float unknown2880;
int unknown2616; char unknown2839;
int unknown2620; float bucket2616;
float unknown2856; int seed2876;
float unknown2860;
void Save(IClientEntity* entity); void Save(IClientEntity* entity);
void Load(IClientEntity* entity); void Load(IClientEntity* entity);
}; };
@ -33,6 +33,7 @@ namespace criticals
{ {
void create_move(); void create_move();
void draw();
bool random_crits_enabled(); bool random_crits_enabled();
} }

View File

@ -3,7 +3,7 @@ class CTFPlayerShared
public: public:
inline static float GetCritMult(CTFPlayerShared *self) inline static float GetCritMult(CTFPlayerShared *self)
{ {
return ((fminf(fmaxf(*(unsigned(self) + 672) * 0.0039215689f, 0.0f), 1.0f) * 3.0f) + 1.0f); return ((fminf(fmaxf(*(float *)(unsigned(self) + 672) * 0.0039215689f, 0.0f), 1.0f) * 3.0f) + 1.0f);
} }
inline static bool IsCritBoosted(CTFPlayerShared *self) inline static bool IsCritBoosted(CTFPlayerShared *self)
{ {

View File

@ -15,7 +15,7 @@ public:
typedef bool(*fn_t)(IClientEntity *); typedef bool(*fn_t)(IClientEntity *);
return vfunc<fn_t>(self, offsets::PlatformOffset(184, offsets::undefined, 184), 0)(self); return vfunc<fn_t>(self, offsets::PlatformOffset(184, offsets::undefined, 184), 0)(self);
} }
inline int& m_nPredictionRandomSeed() inline static int& m_nPredictionRandomSeed()
{ {
static int placeholder = 0; static int placeholder = 0;
return placeholder; return placeholder;

View File

@ -3,6 +3,6 @@ class C_BasePlayer: public C_BaseEntity
public: public:
inline static CTFPlayerShared& shared_(IClientEntity *self) inline static CTFPlayerShared& shared_(IClientEntity *self)
{ {
return *((CTFPlayerShared *)(unsigned(self) + 6092)) return *((CTFPlayerShared *)(unsigned(self) + 6092));
} }
}; };

View File

@ -7,7 +7,7 @@
#pragma once #pragma once
class C_TFWeaponBase : public C_BaseCombatWeapon class C_TFWeaponBase : public re::C_BaseCombatWeapon
{ {
public: public:
inline static IClientEntity *GetOwnerViaInterface(IClientEntity *self) inline static IClientEntity *GetOwnerViaInterface(IClientEntity *self)
@ -48,7 +48,7 @@ public:
inline static void AddToCritBucket(IClientEntity *self, float value) inline static void AddToCritBucket(IClientEntity *self, float value)
{ {
constexpr float max_bucket_capacity = 1000.0f; constexpr float max_bucket_capacity = 1000.0f;
bucket = fminf(bucket_() + value, max_bucket_capacity); crit_bucket_(self) = fminf(crit_bucket_(self) + value, max_bucket_capacity);
} }
inline static bool IsAllowedToWithdrawFromCritBucket(IClientEntity *self, float value) inline static bool IsAllowedToWithdrawFromCritBucket(IClientEntity *self, float value)
{ {
@ -71,7 +71,7 @@ public:
if (!C_BaseEntity::IsPlayer(owner)) if (!C_BaseEntity::IsPlayer(owner))
return false; return false;
CTFPlayerShared *shared = C_BasePlayer::shared_(owner); CTFPlayerShared *shared = &C_BasePlayer::shared_(owner);
float critmult = CTFPlayerShared::GetCritMult(shared); float critmult = CTFPlayerShared::GetCritMult(shared);
if (!CanFireCriticalShot(self, 0, nullptr)) if (!CanFireCriticalShot(self, 0, nullptr))
return false; return false;
@ -120,7 +120,7 @@ public:
IClientEntity *owner = GetOwnerViaInterface(self); IClientEntity *owner = GetOwnerViaInterface(self);
if (owner) if (owner)
{ {
if (IsPlayer(owner)) if (C_BaseEntity::IsPlayer(owner))
{ {
// Always run calculations // Always run calculations
// Never write anything into entity, at least from here. // Never write anything into entity, at least from here.

View File

@ -73,6 +73,7 @@ void unfuck_bucket(IClientEntity *weapon)
struct cached_calculation_s struct cached_calculation_s
{ {
int command_number; int command_number;
int init_command;
int weapon_entity; int weapon_entity;
}; };
@ -80,18 +81,28 @@ cached_calculation_s cached_calculation {};
bool force_crit(IClientEntity *weapon) bool force_crit(IClientEntity *weapon)
{ {
if (cached_calculation.init_command > g_pUserCmd->command_number ||
g_pUserCmd->command_number - cached_calculation.init_command > 4096 ||
cached_calculation.command_number < g_pUserCmd->command_number)
cached_calculation.weapon_entity = 0;
if (cached_calculation.weapon_entity == weapon->entindex()) if (cached_calculation.weapon_entity == weapon->entindex())
return bool(cached_calculation.command_number); return bool(cached_calculation.command_number);
int number = find_next_random_crit_for_weapon(weapon); int number = find_next_random_crit_for_weapon(weapon);
logging::Info("Found critical: %d -> %d", g_pUserCmd->command_number, number);
if (number && number != g_pUserCmd->command_number)
command_number_mod[g_pUserCmd->command_number] = number;
cached_calculation.command_number = number; cached_calculation.command_number = number;
cached_calculation.weapon_entity = LOCAL_W->m_IDX; cached_calculation.weapon_entity = LOCAL_W->m_IDX;
return false; return !!number;
} }
void create_move() void create_move()
{ {
if (!crit_key)
return;
if (!random_crits_enabled()) if (!random_crits_enabled())
return; return;
if (CE_BAD(LOCAL_W)) if (CE_BAD(LOCAL_W))
@ -102,7 +113,7 @@ void create_move()
if (!re::C_TFWeaponBase::AreRandomCritsEnabled(weapon)) if (!re::C_TFWeaponBase::AreRandomCritsEnabled(weapon))
return; return;
unfuck_bucket(weapon); unfuck_bucket(weapon);
if (crit_key.KeyDown()) if ((g_pUserCmd->buttons & IN_ATTACK) && crit_key.KeyDown() && g_pUserCmd->command_number)
{ {
force_crit(weapon); force_crit(weapon);
} }
@ -113,26 +124,58 @@ bool random_crits_enabled() {
return tf_weapon_criticals->GetBool(); return tf_weapon_criticals->GetBool();
} }
void draw()
{
if (CE_BAD(LOCAL_W))
return;
IClientEntity *weapon = RAW_ENT(LOCAL_W);
if (!weapon)
return;
if (!re::C_TFWeaponBase::IsBaseCombatWeapon(weapon))
return;
if (!re::C_TFWeaponBase::AreRandomCritsEnabled(weapon))
return;
if (crit_info && CE_GOOD(LOCAL_W))
{
if (crit_key.KeyDown())
{
AddCenterString("FORCED CRITS!", colors::red);
}
IF_GAME (IsTF2())
{
if (!random_crits_enabled())
AddCenterString("Random crits are disabled", colors::yellow);
else
{
if (!re::C_TFWeaponBase::CanFireCriticalShot(RAW_ENT(LOCAL_W), false, nullptr))
AddCenterString("Weapon can't randomly crit", colors::yellow);
else
AddCenterString("Weapon can randomly crit");
}
AddCenterString(format("Bucket: ", re::C_TFWeaponBase::crit_bucket_(RAW_ENT(LOCAL_W))));
}
//AddCenterString(format("Time: ", *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2872u)));
}
}
} }
void crithack_saved_state::Load(IClientEntity* entity) { void crithack_saved_state::Load(IClientEntity* entity) {
*(float*)((uintptr_t)entity + 2612) = bucket; *(float *)(uintptr_t(entity) + 2868) = unknown2868;
*(float*)((uintptr_t)entity + 2831) = unknown2831; *(float *)(uintptr_t(entity) + 2864) = unknown2864;
*(int*)((uintptr_t)entity + 2868) = seed; *(float *)(uintptr_t(entity) + 2880) = unknown2880;
*(float*)((uintptr_t)entity + 2872) = time; *(float *)(uintptr_t(entity) + 2616) = bucket2616;
*(int*)((uintptr_t)entity + 2616) = unknown2616; *(int *)(uintptr_t(entity) + 2620) = unknown2620;
*(int*)((uintptr_t)entity + 2620) = unknown2620; *(int *)(uintptr_t(entity) + 2876) = seed2876;
*(float*)((uintptr_t)entity + 2856) = unknown2856; *(char *)(uintptr_t(entity) + 2839) = unknown2839;
*(float*)((uintptr_t)entity + 2860) = unknown2860;
} }
void crithack_saved_state::Save(IClientEntity* entity) { void crithack_saved_state::Save(IClientEntity* entity) {
bucket = *(float*)((uintptr_t)entity + 2612); unknown2868 = *(float *)(uintptr_t(entity) + 2868);
unknown2831 = *(float*)((uintptr_t)entity + 2831); unknown2864 = *(float *)(uintptr_t(entity) + 2864);
seed = *(int*)((uintptr_t)entity + 2868); unknown2880 = *(float *)(uintptr_t(entity) + 2880);
time = *(float*)((uintptr_t)entity + 2872); bucket2616 = *(float *)(uintptr_t(entity) + 2616);
unknown2616 = *(int*)((uintptr_t)entity + 2616); unknown2620 = *(int *)(uintptr_t(entity) + 2620);
unknown2620 = *(int*)((uintptr_t)entity + 2620); seed2876 = *(int *)(uintptr_t(entity) + 2876);
unknown2856 = *(float*)((uintptr_t)entity + 2856); unknown2839 = *(char *)(uintptr_t(entity) + 2839);
unknown2860 = *(float*)((uintptr_t)entity + 2860);
} }

View File

@ -225,10 +225,6 @@ bool ShouldAim() {
return false; return false;
} }
} }
// Check if crithack allows attacking
if (!AllowAttacking())
return false;
} }
return true; return true;
} }

View File

@ -86,7 +86,9 @@ void CreateMove() {
if (!g_pUserCmd) return; if (!g_pUserCmd) return;
if (!g_pUserCmd->command_number) return; if (!g_pUserCmd->command_number) return;
if (!master_switch) return; if (!master_switch) return;
int amount = int(value); int amount = 0;
if (key.KeyDown())
amount = int(value);
if (!amount) return; if (!amount) return;

View File

@ -270,30 +270,6 @@ void CreateMove() {
#if ENABLE_VISUALS == 1 #if ENABLE_VISUALS == 1
void DrawText() { void DrawText() {
// Crithack info
// CRITHACK IS DISABLED (temporarily)
/*
if (crit_info && CE_GOOD(LOCAL_W)) {
if (CritKeyDown() || experimental_crit_hack.KeyDown()) {
AddCenterString("FORCED CRITS!", colors::red);
}
IF_GAME (IsTF2()) {
if (!vfunc<bool(*)(IClientEntity*)>(RAW_ENT(LOCAL_W), 465, 0)(RAW_ENT(LOCAL_W)))
AddCenterString("Random crits are disabled", colors::yellow);
else {
if (!WeaponCanCrit())
AddCenterString("Weapon can't randomly crit", colors::yellow);
else
AddCenterString("Weapon can randomly crit");
}
AddCenterString(format("Bucket: ", *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2612u)));
if (crit_hack_next && found_crit_number > last_number && found_crit_weapon == RAW_ENT(LOCAL_W)) {
AddCenterString(format("Next crit in: ", roundf(((found_crit_number - last_number) / 66.0f) * 10.0f) / 10.0f, 's'));
}
//AddCenterString(format("Time: ", *(float*)((uintptr_t)RAW_ENT(LOCAL_W) + 2872u)));
}
}*/
/*if (!no_homo) { /*if (!no_homo) {
int width, height; int width, height;
g_IEngine->GetScreenSize(width, height); g_IEngine->GetScreenSize(width, height);

View File

@ -141,11 +141,6 @@ bool ShouldShoot() {
} }
} }
} }
IF_GAME (IsTF()) {
// Check if crithack allows attacking
if (!AllowAttacking())
return false;
}
return true; return true;
} }

View File

@ -263,7 +263,6 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
} }
#endif #endif
if (CE_GOOD(g_pLocalPlayer->entity)) { if (CE_GOOD(g_pLocalPlayer->entity)) {
ResetCritHack();
IF_GAME (IsTF2()) { IF_GAME (IsTF2()) {
SAFE_CALL(UpdateHoovyList()); SAFE_CALL(UpdateHoovyList());
} }
@ -352,6 +351,10 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
PROF_SECTION(CM_misc); PROF_SECTION(CM_misc);
SAFE_CALL(hacks::shared::misc::CreateMove()); SAFE_CALL(hacks::shared::misc::CreateMove());
} }
{
PROF_SECTION(CM_crits);
criticals::create_move();
}
{ {
PROF_SECTION(CM_spam); PROF_SECTION(CM_spam);
SAFE_CALL(hacks::shared::spam::CreateMove()); SAFE_CALL(hacks::shared::spam::CreateMove());

View File

@ -113,6 +113,10 @@ void DrawCheatVisuals() {
PROF_SECTION(DRAW_esp); PROF_SECTION(DRAW_esp);
hacks::shared::esp::Draw(); hacks::shared::esp::Draw();
} }
IF_GAME(IsTF2())
{
criticals::draw();
}
#ifndef FEATURE_FIDGET_SPINNER_DISABLED #ifndef FEATURE_FIDGET_SPINNER_DISABLED
DrawSpinner(); DrawSpinner();
#endif #endif