Improve crithack visuals on rapidfire weapons

Also improve the bucket fixer
This commit is contained in:
BenCat07 2021-08-20 18:06:55 +02:00
parent d40af68eb9
commit b791df315f
3 changed files with 52 additions and 20 deletions

View File

@ -30,7 +30,7 @@ public:
unsigned unknown1{};
unsigned unknown2{};
bool unknown3{};
float unknown4{};
float m_flCritTime{};
int crit_attempts{};
int crit_count{};
float observed_crit_chance{};
@ -47,7 +47,7 @@ public:
unknown1 = *(unsigned int *) ((uintptr_t) weapon + 0xb30);
unknown2 = *(unsigned int *) ((uintptr_t) weapon + 0xb34);
unknown3 = *(bool *) ((uintptr_t) weapon + 0xb17);
unknown4 = *(float *) ((uintptr_t) weapon + 0xb40);
m_flCritTime = *(float *) ((uintptr_t) weapon + 0xb40);
crit_attempts = *(int *) ((uintptr_t) weapon + 0xa3c);
crit_count = *(int *) ((uintptr_t) weapon + 0xa40);
observed_crit_chance = *(float *) ((uintptr_t) weapon + 0xbfc);
@ -67,12 +67,20 @@ public:
*(unsigned int *) ((uintptr_t) weapon + 0xb30) = unknown1;
*(unsigned int *) ((uintptr_t) weapon + 0xb34) = unknown2;
*(bool *) ((uintptr_t) weapon + 0xb17) = unknown3;
*(float *) ((uintptr_t) weapon + 0xb40) = unknown4;
*(float *) ((uintptr_t) weapon + 0xb40) = m_flCritTime;
*(int *) ((uintptr_t) weapon + 0xa3c) = crit_attempts;
*(int *) ((uintptr_t) weapon + 0xa40) = crit_count;
*(float *) ((uintptr_t) weapon + 0xbfc) = observed_crit_chance;
*(bool *) ((uintptr_t) weapon + 0xb18) = unknown7;
}
bool operator==(const weapon_info &B) const
{
return crit_bucket == B.crit_bucket && weapon_seed == B.weapon_seed && unknown1 == B.unknown1 && unknown2 == B.unknown2 && unknown3 == B.unknown3 && m_flCritTime == B.m_flCritTime && crit_attempts == B.crit_attempts && crit_count == B.crit_count && observed_crit_chance == B.observed_crit_chance && unknown7 == B.unknown7;
}
bool operator!=(const weapon_info &B) const
{
return !(*this == B);
}
};
inline WeaponData_t *GetWeaponData(IClientEntity *weapon)

View File

@ -51,6 +51,7 @@ public:
int m_nButtons; // Attack buttons.
int m_nOldButtons; // From host_client->oldbuttons;
float m_flForwardMove;
float m_flOldForwardMove;
float m_flSideMove;
float m_flUpMove;

View File

@ -596,7 +596,7 @@ static void fixObservedCritchance(IClientEntity *weapon)
}
static std::vector<float> crit_mult_storage;
static float last_bucket_fix = -1;
static weapon_info last_weapon_info;
// Fix bucket on non-local servers
void fixBucket(IClientEntity *weapon, CUserCmd *cmd)
{
@ -609,21 +609,24 @@ void fixBucket(IClientEntity *weapon, CUserCmd *cmd)
static int last_update_command;
fixObservedCritchance(weapon);
weapon_info original_info(weapon);
weapon_info info(weapon);
float bucket = info.crit_bucket;
// Changed bucket more than once this tick, or fastfire weapon. Note that we check if it is within 20 tick range just in case.
if (weapon->entindex() == last_weapon && bucket != last_bucket_fix && last_update_command == cmd->command_number)
bucket = last_bucket_fix;
if (weapon->entindex() == last_weapon && info != last_weapon_info && last_update_command == cmd->command_number)
{
info = last_weapon_info;
}
last_weapon = weapon->entindex();
// Bucket changed, update
if (last_bucket_fix != bucket)
if (last_weapon_info != original_info)
last_update_command = cmd->command_number;
last_bucket_fix = bucket;
info.crit_bucket = bucket;
last_weapon_info = info;
info.restore_data(weapon);
}
@ -874,7 +877,19 @@ void Draw()
else if (!can_crit)
{
if (isRapidFire(wep))
AddCritString("Crit multiplier: " + std::to_string(getWithdrawMult(wep)), colors::orange);
{
std::string crit_string = "Shots until crit: ";
weapon_info info(wep);
crit_string += std::to_string((info.crit_count + 1) * 10.0f - info.crit_attempts - 1);
if (info.m_flCritTime + 1.0f >= g_GlobalVars->curtime)
{
crit_string += ", ";
crit_string += std::to_string(info.m_flCritTime + 1.0f - g_GlobalVars->curtime) + "s";
AddCritString(crit_string, colors::red);
}
else
AddCritString(crit_string, colors::orange);
}
else
AddCritString("Shots until crit: " + std::to_string(shots_until_crit), colors::orange);
}
@ -947,7 +962,16 @@ void Draw()
bar_string = std::to_string(shots_until_crit) + " Shots until Crit!";
}
else
bar_string = "Crit multiplier: " + std::to_string(getWithdrawMult(wep));
{
weapon_info info(wep);
std::string crit_string = std::to_string((info.crit_count + 1) * 10.0f - info.crit_attempts - 1);
crit_string += " Shots until Crit! ";
if (info.m_flCritTime + 1.0f >= g_GlobalVars->curtime)
crit_string += std::to_string(info.m_flCritTime + 1.0f - g_GlobalVars->curtime) + "s";
bar_string = crit_string;
}
}
}
// Still run when out of sync
@ -1096,13 +1120,12 @@ static ProxyFnHook observed_crit_chance_hook{};
// Reset everything
void LevelShutdown()
{
last_crit_tick = -1;
cached_damage = 0;
crit_damage = 0;
melee_damage = 0;
last_bucket_fix = -1;
round_damage = 0;
is_out_of_sync = false;
last_crit_tick = -1;
cached_damage = 0;
crit_damage = 0;
melee_damage = 0;
round_damage = 0;
is_out_of_sync = false;
crit_cmds.clear();
current_index = 0;
}