Skip to content

Commit 5e3e408

Browse files
committed
Fixes
1 parent cc65f56 commit 5e3e408

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+211
-158
lines changed

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"LINUX",
4040
"POSIX",
4141
"SE_TF2=11",
42+
"SE_IS_TF2",
4243
"SOURCE_ENGINE=11",
4344
"COMPILER_GCC",
4445
"NO_HOOK_MALLOC",

AMBuildScript

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,9 @@ class ExtensionConfig(object):
442442
os.path.join(mms_path, 'sourcehook'),
443443
]
444444

445-
defines = 'SE_' + sdk.define + '=' + sdk.code
446-
compiler.defines.append(defines)
445+
defines = ['SE_' + PossibleSDKs[i].define + '=' + PossibleSDKs[i].code for i in PossibleSDKs]
446+
compiler.defines += defines
447+
compiler.defines += ['SE_IS_' + sdk.define]
447448

448449
paths = [
449450
['public'],

gamedata/sigsegv/misc.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6091,7 +6091,12 @@
60916091
"CTFBall_Ornament::Explode" "_ZN16CTFBall_Ornament7ExplodeEP10CGameTracei"
60926092
"CTFBall_Ornament::PipebombTouch" "_ZN16CTFBall_Ornament13PipebombTouchEP11CBaseEntity"
60936093

6094+
"CTFPointWeaponMimic::InputFireMultiple" "_ZN19CTFPointWeaponMimic17InputFireMultipleER11inputdata_t"
6095+
"CTFPointWeaponMimic::InputFireOnce" "_ZN19CTFPointWeaponMimic13InputFireOnceER11inputdata_t"
6096+
60946097
"CTFWeaponBaseGrenadeProj::Destroy" "_ZN24CTFWeaponBaseGrenadeProj7DestroyEbb"
6098+
6099+
"CTeamRoundTimer::InputSetTime" "_ZN15CTeamRoundTimer12InputSetTimeER11inputdata_t"
60956100

60966101
"CGameMovement::FullNoClipMove" "_ZN13CGameMovement14FullNoClipMoveEff"
60976102
"CGameMovement::ResetGetPointContentsCache" "_ZN13CGameMovement26ResetGetPointContentsCacheEv"

src/common.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class IVideoRecorder;
321321
#define RAD_TELEMETRY_DISABLED
322322
#undef NO_STRING_T
323323
#undef WEAK_STRING_T
324-
#ifdef SE_TF2
324+
#ifdef SE_IS_TF2
325325
#include <platform.h>
326326
#include <const.h>
327327
#include <interface.h>
@@ -348,7 +348,7 @@ WARN_RESTORE()
348348
#undef COMPILE_TIME_ASSERT
349349
#define COMPILE_TIME_ASSERT(pred) static_assert(pred)
350350

351-
#ifdef SE_TF2
351+
#ifdef SE_IS_TF2
352352
#include <Color.h>
353353
#include "sdktf2/threadtools.h"
354354
#include <vector2d.h>
@@ -393,7 +393,7 @@ WARN_RESTORE()
393393
WARN_IGNORE__SIGN_COMPARE()
394394
#include <utlbuffer.h>
395395
WARN_RESTORE()
396-
#ifdef SE_TF2
396+
#ifdef SE_IS_TF2
397397
#include "sdk2013/shareddefs.h"
398398
#else
399399
#include <shareddefs.h>
@@ -437,7 +437,7 @@ WARN_RESTORE()
437437
#include <npcevent.h>
438438
#endif
439439
#include <bitbuf.h>
440-
#ifdef SE_TF2
440+
#ifdef SE_IS_TF2
441441
#include "sdk2013/eiface.h"
442442
#else
443443
#include <eiface.h>
@@ -457,7 +457,7 @@ WARN_RESTORE()
457457
#include <ai_activity.h>
458458
#include <igameevents.h>
459459
#include <inetmessage.h>
460-
#ifdef SE_TF2
460+
#ifdef SE_IS_TF2
461461
#include "sdk2013/inetchannel.h"
462462
#else
463463
#include <inetchannel.h>
@@ -523,7 +523,7 @@ WARN_RESTORE()
523523
#include <model_types.h>
524524
#include <idedicatedexports.h>
525525
#include <icommandline.h>
526-
#ifdef SE_TF2
526+
#ifdef SE_IS_TF2
527527
#include "sdk2013/iserver.h"
528528
#else
529529
#include <iserver.h>
@@ -580,7 +580,7 @@ WARN_RESTORE()
580580
#endif
581581

582582
#ifndef CSGO_SEPARETE_
583-
#ifdef SE_TF2
583+
#ifdef SE_IS_TF2
584584
static_assert(_SIGSEGV_SDK2013_OVERRIDE__PUBLIC_SHAREDDEFS_H);
585585
#else
586586
static_assert(_SIGSEGV_SDK2013_OVERRIDE__PUBLIC_TIER0_PLATFORM_H);

src/extension.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//#include "disasm/disasm.h"
1414
#include "factory.h"
1515
#include "concolor.h"
16-
#ifdef SE_TF2
16+
#ifdef SE_IS_TF2
1717
#include "re/nextbot.h"
1818
#endif
1919
#include "version.h"
@@ -135,7 +135,7 @@ void CExtSigsegv::SDK_OnUnload()
135135

136136
IGameSystem::Remove(this);
137137

138-
#ifdef SE_TF2
138+
#ifdef SE_IS_TF2
139139
IHotplugActionBase::UnloadAll();
140140
// IHotplugEntity::UninstallAll();
141141
#endif

src/link/nextbot1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if SE_TF2
1+
#ifdef SE_IS_TF2
22
#include "link/link.h"
33
#include "re/nextbot.h"
44
#include "re/path.h"

src/link/nextbot2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if SE_TF2
1+
#ifdef SE_IS_TF2
22
#include "link/link.h"
33
#include "abi.h"
44

src/mem/detour.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ void CFuncVProf::TracePost()
531531
}
532532
}
533533

534+
constexpr bool s_bGameHasOptimizedVirtuals = SOURCE_ENGINE == SE_TF2;
534535

535536
CDetouredFunc::CDetouredFunc(void *func_ptr) :
536537
m_pFunc(reinterpret_cast<uint8_t *>(func_ptr))
@@ -540,20 +541,23 @@ CDetouredFunc::CDetouredFunc(void *func_ptr) :
540541
this->m_TrueOriginalPrologue.resize(len_prologue);
541542
memcpy(this->m_TrueOriginalPrologue.data(), this->m_pFunc, len_prologue);
542543

543-
bool found = false;
544-
for (auto &[vtname, pVTInfo] : RTTI::GetAllVTableInfo()) {
545-
auto pVT = pVTInfo.vtable;
546-
auto size = pVTInfo.size / sizeof(void *);
547-
for (int i = 0; i < size; ++i) {
548-
if (pVT[i] == func_ptr) {
549-
this->m_FoundFuncPtrAndVTablePtr.emplace(const_cast<void **>(pVT + i), pVT);
550-
found = true;
544+
// For TF2, virtual calls can be optimized to be not called if the function is not overridden. Because of this detours also have to modify the vtables with matching functions
545+
if (s_bGameHasOptimizedVirtuals) {
546+
bool found = false;
547+
for (auto &[vtname, pVTInfo] : RTTI::GetAllVTableInfo()) {
548+
auto pVT = pVTInfo.vtable;
549+
auto size = pVTInfo.size / sizeof(void *);
550+
for (int i = 0; i < size; ++i) {
551+
if (pVT[i] == func_ptr) {
552+
this->m_FoundFuncPtrAndVTablePtr.emplace(const_cast<void **>(pVT + i), pVT);
553+
found = true;
554+
}
551555
}
552556
}
553-
}
554557

555-
if (found) {
556-
this->m_VirtualHookOptional = CVirtualHookBase(nullptr, CVirtualHookBase::DETOUR_HOOK);
558+
if (found) {
559+
this->m_VirtualHookOptional = CVirtualHookBase(nullptr, CVirtualHookBase::DETOUR_HOOK);
560+
}
557561
}
558562
}
559563
CDetouredFunc::~CDetouredFunc()

src/mod/common/commands.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _INCLUDE_SIGSEGV_MOD_COMMON_COMMANDS_H_
22
#define _INCLUDE_SIGSEGV_MOD_COMMON_COMMANDS_H_
33

4-
#ifdef SE_TF2
4+
#ifdef SE_IS_TF2
55
#include "stub/tfplayer.h"
66
#define CCommandPlayer CTFPlayer
77
#else

src/mod/cond/reprogrammed.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,8 @@ namespace Mod::Cond::Reprogrammed
831831

832832
RefCount rc_CBaseObject_FindSnapToBuildPos;
833833
RefCount rc_CBaseObject_FindSnapToBuildPos_spec;
834-
RefCount rc_CollectPlayers_Enemy;
834+
RefCount rc_CollectPlayers_SpecEnemy;
835+
RefCount rc_CollectPlayers_SpecFriend;
835836
DETOUR_DECL_STATIC(int, CollectPlayers_CTFPlayer, CUtlVector<CTFPlayer *> *playerVector, int team, bool isAlive, bool shouldAppend)
836837
{
837838
static bool reentrancy = false;
@@ -876,9 +877,15 @@ namespace Mod::Cond::Reprogrammed
876877
// reentrancy = false;
877878
// }
878879

879-
if (team == TEAM_SPECTATOR && isAlive && !reentrancy) {
880+
if (team == TEAM_SPECTATOR && isAlive && !reentrancy && !rc_CollectPlayers_SpecFriend && !rc_CollectPlayers_SpecEnemy) {
880881
team = RandomInt(TEAM_SPECTATOR, TF_TEAM_BLUE);
881882
}
883+
884+
if (team == TEAM_SPECTATOR && rc_CollectPlayers_SpecEnemy) {
885+
886+
CollectPlayers(playerVector, TF_TEAM_RED, isAlive, shouldAppend);
887+
CollectPlayers(playerVector, TF_TEAM_BLUE, isAlive, true);
888+
}
882889
return DETOUR_STATIC_CALL(CollectPlayers_CTFPlayer)(playerVector, team, isAlive, shouldAppend);
883890
}
884891

@@ -1128,8 +1135,12 @@ namespace Mod::Cond::Reprogrammed
11281135
{
11291136
auto me = reinterpret_cast<CBaseObject *>(this);
11301137
bool success = DETOUR_MEMBER_CALL(CBaseObject_FindSnapToBuildPos)(pObjectOverride);
1138+
1139+
if (pObjectOverride != nullptr) return success;
1140+
11311141
if (success) return true;
11321142

1143+
SCOPED_INCREMENT(rc_CollectPlayers_SpecFriend);
11331144
//SCOPED_INCREMENT(rc_CBaseObject_FindSnapToBuildPos);
11341145
//SCOPED_INCREMENT_IF(rc_CBaseObject_FindSnapToBuildPos_spec, me->GetBuilder() != nullptr && me->GetBuilder()->GetTeamNumber() == TEAM_SPECTATOR);
11351146

@@ -1261,7 +1272,7 @@ namespace Mod::Cond::Reprogrammed
12611272

12621273
DETOUR_DECL_MEMBER(void, CTFPistol_ScoutPrimary_Push)
12631274
{
1264-
SCOPED_INCREMENT(rc_CollectPlayers_Enemy);
1275+
SCOPED_INCREMENT(rc_CollectPlayers_SpecEnemy);
12651276
DETOUR_MEMBER_CALL(CTFPistol_ScoutPrimary_Push)();
12661277
}
12671278

src/mod/etc/extra_player_slots.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class SVC_ServerInfo
4545

4646
namespace Mod::Etc::Extra_Player_Slots
4747
{
48-
#ifdef SE_TF2
48+
#ifdef SE_IS_TF2
4949
constexpr int DEFAULT_MAX_PLAYERS = 101;
50-
#elif definded(SE_CSS)
50+
#elif definded(SE_IS_CSS)
5151
constexpr int DEFAULT_MAX_PLAYERS = 65;
5252
#endif
5353
inline bool ExtraSlotsEnabled();
@@ -1125,7 +1125,7 @@ namespace Mod::Etc::Extra_Player_Slots
11251125

11261126
MOD_ADD_DETOUR_MEMBER(CTriggerCatapult_OnLaunchedVictim, "CTriggerCatapult::OnLaunchedVictim");
11271127

1128-
#ifdef SE_TF2
1128+
#ifdef SE_IS_TF2
11291129
MOD_ADD_DETOUR_MEMBER(CServerGameClients_ClientPutInServer, "CServerGameClients::ClientPutInServer");
11301130

11311131
MOD_ADD_DETOUR_MEMBER(CBaseServer_FillServerInfo, "CBaseServer::FillServerInfo");

src/mod/etc/mapentity_additions.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -590,23 +590,8 @@ namespace Mod::Etc::Mapentity_Additions
590590
bool last_entity_name_wildcard = false;
591591
string_t last_entity_lowercase = NULL_STRING;
592592

593-
ConVar cvar_fast_lookup("sig_etc_fast_entity_name_lookup", "1", FCVAR_GAMEDLL, "Converts all entity names to lowercase for faster lookup",
593+
ConVar cvar_fast_lookup("sig_etc_fast_entity_name_lookup", "1", FCVAR_GAMEDLL, "Speeds up entity lookup by name, but may cause issues with some maps or plugins",
594594
[](IConVar *pConVar, const char *pOldValue, float flOldValue){
595-
// Immediately convert every name and classname to lowercase
596-
// if (static_cast<ConVar *>(pConVar)->GetBool()) {
597-
// ForEachEntity([](CBaseEntity *entity){
598-
// if (entity->GetEntityName() != NULL_STRING) {
599-
// char *lowercase = stackalloc(strlen(STRING(entity->GetEntityName())) + 1);
600-
// StrLowerCopy(STRING(entity->GetEntityName()), lowercase);
601-
// entity->SetName(AllocPooledString(lowercase));
602-
// }
603-
// if (entity->GetClassnameString() != NULL_STRING) {
604-
// char *lowercase = stackalloc(strlen(STRING(entity->GetClassnameString())) + 1);
605-
// StrLowerCopy(STRING(entity->GetClassnameString()), lowercase);
606-
// entity->SetClassname(AllocPooledString(lowercase));
607-
// }
608-
// });
609-
// }
610595
});
611596

612597

@@ -727,7 +712,7 @@ namespace Mod::Etc::Mapentity_Additions
727712
}
728713
}
729714
}
730-
return nullptr;
715+
return nullptr;
731716
}
732717

733718
DETOUR_DECL_MEMBER(void, CTFMedigunShield_RemoveShield)
@@ -965,6 +950,18 @@ namespace Mod::Etc::Mapentity_Additions
965950
return result;
966951
}
967952

953+
954+
DETOUR_DECL_MEMBER(void, CTeamRoundTimer_InputSetTime, inputdata_t& inputdata)
955+
{
956+
auto timer = reinterpret_cast<CBaseEntity *>(this);
957+
958+
DETOUR_MEMBER_CALL(CTeamRoundTimer_InputSetTime)(inputdata);
959+
960+
// On some gamemodes, the game spawns timers automatically, the names are not pooled and need to be in order for fast lookup to work
961+
if (cvar_fast_lookup.GetBool()) {
962+
timer->SetName(AllocPooledString(STRING(timer->GetEntityName())));
963+
}
964+
}
968965
// DETOUR_DECL_MEMBER(void, CBaseEntity_PostConstructor, const char *classname)
969966
// {
970967
// if (cvar_fast_lookup.GetBool() && !IsStrLower(classname)) {
@@ -2417,6 +2414,8 @@ namespace Mod::Etc::Mapentity_Additions
24172414
MOD_ADD_DETOUR_MEMBER(CTFPlayer_StateLeave, "CTFPlayer::StateLeave");
24182415
MOD_ADD_DETOUR_MEMBER(CTFBot_Spawn, "CTFBot::Spawn");
24192416

2417+
MOD_ADD_DETOUR_MEMBER(CTeamRoundTimer_InputSetTime, "CTeamRoundTimer::InputSetTime");
2418+
24202419
#ifndef NO_MVM
24212420
MOD_ADD_DETOUR_MEMBER(CPopulationManager_UpdateObjectiveResource, "CPopulationManager::UpdateObjectiveResource");
24222421
#endif

src/mod/etc/weapon_mimic_teamnum.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
105105

106106
CVirtualHook bulletDamageHook(TypeName<CBaseEntity>(), "CBaseEntity::ModifyFireBulletsDamage", GET_VHOOK_CALLBACK(CBaseEntity_ModifyFireBulletsDamage), GET_VHOOK_INNERPTR(CBaseEntity_ModifyFireBulletsDamage));
107107
CTFWeaponBase *shooting_weapon = nullptr;
108-
DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_Fire)
108+
109+
void MimicFire(CTFPointWeaponMimic *mimic)
109110
{
110111
SCOPED_INCREMENT(rc_CTFPointWeaponMimic_Fire);
111-
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
112112
mimicFire = mimic;
113113
projectile = nullptr;
114114
grenade = false;
@@ -118,6 +118,7 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
118118
if (mimic->GetOwnerEntity() != nullptr && mimic->GetOwnerEntity()->IsPlayer()) {
119119
scorer = mimic->GetOwnerEntity();
120120
}
121+
Msg("Mimic fire\n");
121122

122123
const char *weaponName = mimic->GetCustomVariable<"weaponname">();
123124
if (weaponName != nullptr) {
@@ -208,7 +209,7 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
208209

209210
}
210211
else {
211-
DETOUR_MEMBER_CALL(CTFPointWeaponMimic_Fire)();
212+
mimic->Fire();
212213
}
213214

214215
if (projectile != nullptr) {
@@ -260,6 +261,35 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
260261
mimicFire = nullptr;
261262
}
262263

264+
// CTFPointWeaponMimic::Fire gets inlined, need to detour inputfireonce/inputfiremultiple
265+
DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_Fire)
266+
{
267+
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
268+
if (!rc_CTFPointWeaponMimic_Fire) {
269+
MimicFire(mimic);
270+
}
271+
else {
272+
DETOUR_MEMBER_CALL(CTFPointWeaponMimic_Fire)();
273+
}
274+
}
275+
276+
277+
DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_InputFireOnce, inputdata_t& inputdata)
278+
{
279+
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
280+
MimicFire(mimic);
281+
}
282+
283+
DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_InputFireMultiple, inputdata_t& inputdata)
284+
{
285+
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
286+
int nNumFires = Max( 1, abs(inputdata.value.Int()) );
287+
288+
while( nNumFires-- ) {
289+
MimicFire(mimic);
290+
}
291+
}
292+
263293
DETOUR_DECL_STATIC(CBaseEntity *, CTFProjectile_Rocket_Create, CBaseEntity *pLauncher, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner, CBaseEntity *pScorer)
264294
{
265295
if (scorer != nullptr) {
@@ -394,6 +424,8 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
394424
{
395425
bulletDamageHook.DoLoad();
396426
MOD_ADD_DETOUR_MEMBER(CTFPointWeaponMimic_Fire, "CTFPointWeaponMimic::Fire");
427+
MOD_ADD_DETOUR_MEMBER(CTFPointWeaponMimic_InputFireOnce, "CTFPointWeaponMimic::InputFireOnce");
428+
MOD_ADD_DETOUR_MEMBER(CTFPointWeaponMimic_InputFireMultiple, "CTFPointWeaponMimic::InputFireMultiple");
397429
MOD_ADD_DETOUR_STATIC(CTFProjectile_Rocket_Create, "CTFProjectile_Rocket::Create");
398430
MOD_ADD_DETOUR_STATIC(CTFProjectile_Arrow_Create, "CTFProjectile_Arrow::Create");
399431
MOD_ADD_DETOUR_STATIC(CBaseEntity_CreateNoSpawn, "CBaseEntity::CreateNoSpawn");

src/mod/perf/attributes_optimize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifdef SE_TF2
1+
#ifdef SE_IS_TF2
22
#include "mod.h"
33
#include "util/scope.h"
44
#include "stub/tfplayer.h"

src/mod/perf/clientside_wearable_optimize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifdef SE_TF2
1+
#ifdef SE_IS_TF2
22
#include "mod.h"
33
#include "stub/tfplayer.h"
44
#include "stub/tfentities.h"

0 commit comments

Comments
 (0)