Skip to content

Instantly share code, notes, and snippets.

View sigsegv-mvm's full-sized avatar

sigsegv sigsegv-mvm

View GitHub Profile
@sigsegv-mvm
sigsegv-mvm / CTFPlayer_RegenThink.cpp
Created November 10, 2016 21:51
How TF2 health regen works, in detail
// Health regen stuff
// Based on server_srv.so version 20151007a
// Reverse engineering by sigsegv
/* this Think function is called once per second */
void CTFPlayer::RegenThink()
{
if (!this->IsAlive())
{
@sigsegv-mvm
sigsegv-mvm / gatebot_wall_of_text.md
Last active March 16, 2017 13:01
A wall of text about how Mannhattan gatebots work, and why certain related bugs happen

This wall-of-text will describe how Mannhattan gatebots work, and then based on that, the reason why bots with special AI (e.g. sentry busters, engie bots) that walk near the gate areas do weird things.

Part 1: func_nav_prerequisite

There's a type of map entity called func_nav_prerequisite, which is integral to how gatebots work. You can put one of these entities in a particular portion of a map, and it will make bots stop what they're doing and do something else before they proceed. (They're only a "prerequisite" in the sense that a bot who walks through one is commanded to do something else before it can proceed with what it was doing before.) There are three possible things a func_nav_prerequisite can be set to make bots do:

  • Destroy entity. In theory, this would make bots switch to the CTFBotNavEntDestroyEntity AI action, but the (apparently working) code for it was never actually hooked up for whatever reason. The map designer specifies which entity the bo
@sigsegv-mvm
sigsegv-mvm / tf_collision_groups.txt
Created November 1, 2016 02:59
TF2 collision group definitions
enum Collision_Group_t:
00 COLLISION_GROUP_NONE
01 COLLISION_GROUP_DEBRIS
02 COLLISION_GROUP_DEBRIS_TRIGGER
03 COLLISION_GROUP_INTERACTIVE_DEBRIS
04 COLLISION_GROUP_INTERACTIVE
05 COLLISION_GROUP_PLAYER
06 COLLISION_GROUP_BREAKABLE_GLASS
07 COLLISION_GROUP_VEHICLE
@sigsegv-mvm
sigsegv-mvm / tf_projectile_class_tree__deflectable.txt
Created October 26, 2016 23:42
TF2 projectile entity class inheritance tree (with deflectable annotations)
TF projectile class hierarchy as of 20161025a
(reverse engineering by sigsegv)
Each projectile class has a 'yes' or 'no' after it to show whether it IsDeflectable() by airblast.
A capitalized YES/NO means that the class specifically overrides IsDeflectable().
A non-capitalized yes/no means that the class inherits IsDeflectable() from a parent class.
CBaseProjectile NO
@sigsegv-mvm
sigsegv-mvm / tf_projectile_class_tree.txt
Last active March 30, 2024 04:34
TF2 projectile entity class inheritance tree
TF projectile class hierarchy as of 20161025a
(reverse engineering by sigsegv)
CBaseProjectile
|
+-- CBaseGrenade
| |
| +-- CTFWeaponBaseGrenadeProj
| |
@sigsegv-mvm
sigsegv-mvm / ctfknife_isbehindandfacingtarget.cpp
Created October 18, 2016 05:53
Backstabs, brought to you by 2D vector dot products
// reverse engineered from TF2 ServerLinux 20151007a by sigsegv
bool CTFKnife::IsBehindAndFacingTarget(CTFPlayer *pVictim)
{
CTFPlayer *pSpy = ToTFPlayer(this->GetPlayerOwner());
if (pSpy == nullptr) return false;
Vector2D wsc_spy_to_victim = (pVictim->WorldSpaceCenter() - pSpy->WorldSpaceCenter()).AsVector2D();
wsc_spy_to_victim.NormalizeInPlace();
@sigsegv-mvm
sigsegv-mvm / tfbot_path_cost_route_types.txt
Created September 22, 2016 05:19
TFBot Path Cost: Route Types by Action
TFBot Path Cost: Route Types by Action
DEFAULT_ROUTE:
- In MvM, non-MiniBoss bots get a large random factor applied to their path cost to make them spread out more randomly.
FASTEST_ROUTE:
- No special path cost modifiers.
SAFEST_ROUTE:
@sigsegv-mvm
sigsegv-mvm / airblast_impulse_magnitude.cpp
Created September 19, 2016 20:36
Airblast impulse magnitude
// this function either does not really exist or is consistently inlined
// the logic comes from CTFFlameThrower::DeflectPlayer, shortly before the call to CTFPlayer::ApplyAirBlastImpulse
float CalculateAirblastImpulseMagnitude(CTFPlayer *pVictim)
{
// OBBSize() = m_vecMaxs - m_vecMins
Vector vecSize = pVictim->CollisionProp()->OBBSize();
return (float)(188928.0 / (vecSize.x * vecSize.y * vecSize.z) * 360.0);
}
@sigsegv-mvm
sigsegv-mvm / c_soldier_animations.diff
Created August 30, 2016 01:56
Soldier animations diff: 20160823b vs 20160830a
--- T:/c_soldier_animations_before.qc Mon Aug 29 18:49:19 2016
+++ T:/c_soldier_animations_after.qc Mon Aug 29 18:49:25 2016
@@ -307,40 +307,41 @@
snap
}
$sequence "mangler_fire_super" "c_soldier_animations_anims\mangler_fire_super.smd" {
fps 30
activity "ACT_PRIMARY_VM_PRIMARYATTACK_3" 1
snap
@sigsegv-mvm
sigsegv-mvm / lagcompensation_raii.cpp
Last active March 30, 2024 04:38
A fancy-pants RAII helper class to reduce chances of lag compensation screwups
// example RAII class to help ensure that FinishLagCompensation is called upon leaving scope
class CLagCompensatedSection
{
public:
// start lag compensation upon construction
CLagCompensatedSection(CBasePlayer *player, CUserCmd *cmd) :
m_pPlayer(player)
{
lagcompensation->StartLagCompensation(player, cmd);
}