Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafradek committed May 10, 2024
1 parent cc65f56 commit 5e3e408
Show file tree
Hide file tree
Showing 50 changed files with 211 additions and 158 deletions.
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"LINUX",
"POSIX",
"SE_TF2=11",
"SE_IS_TF2",
"SOURCE_ENGINE=11",
"COMPILER_GCC",
"NO_HOOK_MALLOC",
Expand Down
5 changes: 3 additions & 2 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,9 @@ class ExtensionConfig(object):
os.path.join(mms_path, 'sourcehook'),
]

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

paths = [
['public'],
Expand Down
5 changes: 5 additions & 0 deletions gamedata/sigsegv/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6091,7 +6091,12 @@
"CTFBall_Ornament::Explode" "_ZN16CTFBall_Ornament7ExplodeEP10CGameTracei"
"CTFBall_Ornament::PipebombTouch" "_ZN16CTFBall_Ornament13PipebombTouchEP11CBaseEntity"

"CTFPointWeaponMimic::InputFireMultiple" "_ZN19CTFPointWeaponMimic17InputFireMultipleER11inputdata_t"
"CTFPointWeaponMimic::InputFireOnce" "_ZN19CTFPointWeaponMimic13InputFireOnceER11inputdata_t"

"CTFWeaponBaseGrenadeProj::Destroy" "_ZN24CTFWeaponBaseGrenadeProj7DestroyEbb"

"CTeamRoundTimer::InputSetTime" "_ZN15CTeamRoundTimer12InputSetTimeER11inputdata_t"

"CGameMovement::FullNoClipMove" "_ZN13CGameMovement14FullNoClipMoveEff"
"CGameMovement::ResetGetPointContentsCache" "_ZN13CGameMovement26ResetGetPointContentsCacheEv"
Expand Down
14 changes: 7 additions & 7 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class IVideoRecorder;
#define RAD_TELEMETRY_DISABLED
#undef NO_STRING_T
#undef WEAK_STRING_T
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include <platform.h>
#include <const.h>
#include <interface.h>
Expand All @@ -348,7 +348,7 @@ WARN_RESTORE()
#undef COMPILE_TIME_ASSERT
#define COMPILE_TIME_ASSERT(pred) static_assert(pred)

#ifdef SE_TF2
#ifdef SE_IS_TF2
#include <Color.h>
#include "sdktf2/threadtools.h"
#include <vector2d.h>
Expand Down Expand Up @@ -393,7 +393,7 @@ WARN_RESTORE()
WARN_IGNORE__SIGN_COMPARE()
#include <utlbuffer.h>
WARN_RESTORE()
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "sdk2013/shareddefs.h"
#else
#include <shareddefs.h>
Expand Down Expand Up @@ -437,7 +437,7 @@ WARN_RESTORE()
#include <npcevent.h>
#endif
#include <bitbuf.h>
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "sdk2013/eiface.h"
#else
#include <eiface.h>
Expand All @@ -457,7 +457,7 @@ WARN_RESTORE()
#include <ai_activity.h>
#include <igameevents.h>
#include <inetmessage.h>
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "sdk2013/inetchannel.h"
#else
#include <inetchannel.h>
Expand Down Expand Up @@ -523,7 +523,7 @@ WARN_RESTORE()
#include <model_types.h>
#include <idedicatedexports.h>
#include <icommandline.h>
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "sdk2013/iserver.h"
#else
#include <iserver.h>
Expand Down Expand Up @@ -580,7 +580,7 @@ WARN_RESTORE()
#endif

#ifndef CSGO_SEPARETE_
#ifdef SE_TF2
#ifdef SE_IS_TF2
static_assert(_SIGSEGV_SDK2013_OVERRIDE__PUBLIC_SHAREDDEFS_H);
#else
static_assert(_SIGSEGV_SDK2013_OVERRIDE__PUBLIC_TIER0_PLATFORM_H);
Expand Down
4 changes: 2 additions & 2 deletions src/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//#include "disasm/disasm.h"
#include "factory.h"
#include "concolor.h"
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "re/nextbot.h"
#endif
#include "version.h"
Expand Down Expand Up @@ -135,7 +135,7 @@ void CExtSigsegv::SDK_OnUnload()

IGameSystem::Remove(this);

#ifdef SE_TF2
#ifdef SE_IS_TF2
IHotplugActionBase::UnloadAll();
// IHotplugEntity::UninstallAll();
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/link/nextbot1.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if SE_TF2
#ifdef SE_IS_TF2
#include "link/link.h"
#include "re/nextbot.h"
#include "re/path.h"
Expand Down
2 changes: 1 addition & 1 deletion src/link/nextbot2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if SE_TF2
#ifdef SE_IS_TF2
#include "link/link.h"
#include "abi.h"

Expand Down
26 changes: 15 additions & 11 deletions src/mem/detour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ void CFuncVProf::TracePost()
}
}

constexpr bool s_bGameHasOptimizedVirtuals = SOURCE_ENGINE == SE_TF2;

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

bool found = false;
for (auto &[vtname, pVTInfo] : RTTI::GetAllVTableInfo()) {
auto pVT = pVTInfo.vtable;
auto size = pVTInfo.size / sizeof(void *);
for (int i = 0; i < size; ++i) {
if (pVT[i] == func_ptr) {
this->m_FoundFuncPtrAndVTablePtr.emplace(const_cast<void **>(pVT + i), pVT);
found = true;
// 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
if (s_bGameHasOptimizedVirtuals) {
bool found = false;
for (auto &[vtname, pVTInfo] : RTTI::GetAllVTableInfo()) {
auto pVT = pVTInfo.vtable;
auto size = pVTInfo.size / sizeof(void *);
for (int i = 0; i < size; ++i) {
if (pVT[i] == func_ptr) {
this->m_FoundFuncPtrAndVTablePtr.emplace(const_cast<void **>(pVT + i), pVT);
found = true;
}
}
}
}

if (found) {
this->m_VirtualHookOptional = CVirtualHookBase(nullptr, CVirtualHookBase::DETOUR_HOOK);
if (found) {
this->m_VirtualHookOptional = CVirtualHookBase(nullptr, CVirtualHookBase::DETOUR_HOOK);
}
}
}
CDetouredFunc::~CDetouredFunc()
Expand Down
2 changes: 1 addition & 1 deletion src/mod/common/commands.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _INCLUDE_SIGSEGV_MOD_COMMON_COMMANDS_H_
#define _INCLUDE_SIGSEGV_MOD_COMMON_COMMANDS_H_

#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "stub/tfplayer.h"
#define CCommandPlayer CTFPlayer
#else
Expand Down
17 changes: 14 additions & 3 deletions src/mod/cond/reprogrammed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ namespace Mod::Cond::Reprogrammed

RefCount rc_CBaseObject_FindSnapToBuildPos;
RefCount rc_CBaseObject_FindSnapToBuildPos_spec;
RefCount rc_CollectPlayers_Enemy;
RefCount rc_CollectPlayers_SpecEnemy;
RefCount rc_CollectPlayers_SpecFriend;
DETOUR_DECL_STATIC(int, CollectPlayers_CTFPlayer, CUtlVector<CTFPlayer *> *playerVector, int team, bool isAlive, bool shouldAppend)
{
static bool reentrancy = false;
Expand Down Expand Up @@ -876,9 +877,15 @@ namespace Mod::Cond::Reprogrammed
// reentrancy = false;
// }

if (team == TEAM_SPECTATOR && isAlive && !reentrancy) {
if (team == TEAM_SPECTATOR && isAlive && !reentrancy && !rc_CollectPlayers_SpecFriend && !rc_CollectPlayers_SpecEnemy) {
team = RandomInt(TEAM_SPECTATOR, TF_TEAM_BLUE);
}

if (team == TEAM_SPECTATOR && rc_CollectPlayers_SpecEnemy) {

CollectPlayers(playerVector, TF_TEAM_RED, isAlive, shouldAppend);
CollectPlayers(playerVector, TF_TEAM_BLUE, isAlive, true);
}
return DETOUR_STATIC_CALL(CollectPlayers_CTFPlayer)(playerVector, team, isAlive, shouldAppend);
}

Expand Down Expand Up @@ -1128,8 +1135,12 @@ namespace Mod::Cond::Reprogrammed
{
auto me = reinterpret_cast<CBaseObject *>(this);
bool success = DETOUR_MEMBER_CALL(CBaseObject_FindSnapToBuildPos)(pObjectOverride);

if (pObjectOverride != nullptr) return success;

if (success) return true;

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

Expand Down Expand Up @@ -1261,7 +1272,7 @@ namespace Mod::Cond::Reprogrammed

DETOUR_DECL_MEMBER(void, CTFPistol_ScoutPrimary_Push)
{
SCOPED_INCREMENT(rc_CollectPlayers_Enemy);
SCOPED_INCREMENT(rc_CollectPlayers_SpecEnemy);
DETOUR_MEMBER_CALL(CTFPistol_ScoutPrimary_Push)();
}

Expand Down
6 changes: 3 additions & 3 deletions src/mod/etc/extra_player_slots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class SVC_ServerInfo

namespace Mod::Etc::Extra_Player_Slots
{
#ifdef SE_TF2
#ifdef SE_IS_TF2
constexpr int DEFAULT_MAX_PLAYERS = 101;
#elif definded(SE_CSS)
#elif definded(SE_IS_CSS)
constexpr int DEFAULT_MAX_PLAYERS = 65;
#endif
inline bool ExtraSlotsEnabled();
Expand Down Expand Up @@ -1125,7 +1125,7 @@ namespace Mod::Etc::Extra_Player_Slots

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

#ifdef SE_TF2
#ifdef SE_IS_TF2
MOD_ADD_DETOUR_MEMBER(CServerGameClients_ClientPutInServer, "CServerGameClients::ClientPutInServer");

MOD_ADD_DETOUR_MEMBER(CBaseServer_FillServerInfo, "CBaseServer::FillServerInfo");
Expand Down
33 changes: 16 additions & 17 deletions src/mod/etc/mapentity_additions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,23 +590,8 @@ namespace Mod::Etc::Mapentity_Additions
bool last_entity_name_wildcard = false;
string_t last_entity_lowercase = NULL_STRING;

ConVar cvar_fast_lookup("sig_etc_fast_entity_name_lookup", "1", FCVAR_GAMEDLL, "Converts all entity names to lowercase for faster lookup",
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",
[](IConVar *pConVar, const char *pOldValue, float flOldValue){
// Immediately convert every name and classname to lowercase
// if (static_cast<ConVar *>(pConVar)->GetBool()) {
// ForEachEntity([](CBaseEntity *entity){
// if (entity->GetEntityName() != NULL_STRING) {
// char *lowercase = stackalloc(strlen(STRING(entity->GetEntityName())) + 1);
// StrLowerCopy(STRING(entity->GetEntityName()), lowercase);
// entity->SetName(AllocPooledString(lowercase));
// }
// if (entity->GetClassnameString() != NULL_STRING) {
// char *lowercase = stackalloc(strlen(STRING(entity->GetClassnameString())) + 1);
// StrLowerCopy(STRING(entity->GetClassnameString()), lowercase);
// entity->SetClassname(AllocPooledString(lowercase));
// }
// });
// }
});


Expand Down Expand Up @@ -727,7 +712,7 @@ namespace Mod::Etc::Mapentity_Additions
}
}
}
return nullptr;
return nullptr;
}

DETOUR_DECL_MEMBER(void, CTFMedigunShield_RemoveShield)
Expand Down Expand Up @@ -965,6 +950,18 @@ namespace Mod::Etc::Mapentity_Additions
return result;
}


DETOUR_DECL_MEMBER(void, CTeamRoundTimer_InputSetTime, inputdata_t& inputdata)
{
auto timer = reinterpret_cast<CBaseEntity *>(this);

DETOUR_MEMBER_CALL(CTeamRoundTimer_InputSetTime)(inputdata);

// On some gamemodes, the game spawns timers automatically, the names are not pooled and need to be in order for fast lookup to work
if (cvar_fast_lookup.GetBool()) {
timer->SetName(AllocPooledString(STRING(timer->GetEntityName())));
}
}
// DETOUR_DECL_MEMBER(void, CBaseEntity_PostConstructor, const char *classname)
// {
// if (cvar_fast_lookup.GetBool() && !IsStrLower(classname)) {
Expand Down Expand Up @@ -2417,6 +2414,8 @@ namespace Mod::Etc::Mapentity_Additions
MOD_ADD_DETOUR_MEMBER(CTFPlayer_StateLeave, "CTFPlayer::StateLeave");
MOD_ADD_DETOUR_MEMBER(CTFBot_Spawn, "CTFBot::Spawn");

MOD_ADD_DETOUR_MEMBER(CTeamRoundTimer_InputSetTime, "CTeamRoundTimer::InputSetTime");

#ifndef NO_MVM
MOD_ADD_DETOUR_MEMBER(CPopulationManager_UpdateObjectiveResource, "CPopulationManager::UpdateObjectiveResource");
#endif
Expand Down
38 changes: 35 additions & 3 deletions src/mod/etc/weapon_mimic_teamnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum

CVirtualHook bulletDamageHook(TypeName<CBaseEntity>(), "CBaseEntity::ModifyFireBulletsDamage", GET_VHOOK_CALLBACK(CBaseEntity_ModifyFireBulletsDamage), GET_VHOOK_INNERPTR(CBaseEntity_ModifyFireBulletsDamage));
CTFWeaponBase *shooting_weapon = nullptr;
DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_Fire)

void MimicFire(CTFPointWeaponMimic *mimic)
{
SCOPED_INCREMENT(rc_CTFPointWeaponMimic_Fire);
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
mimicFire = mimic;
projectile = nullptr;
grenade = false;
Expand All @@ -118,6 +118,7 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
if (mimic->GetOwnerEntity() != nullptr && mimic->GetOwnerEntity()->IsPlayer()) {
scorer = mimic->GetOwnerEntity();
}
Msg("Mimic fire\n");

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

}
else {
DETOUR_MEMBER_CALL(CTFPointWeaponMimic_Fire)();
mimic->Fire();
}

if (projectile != nullptr) {
Expand Down Expand Up @@ -260,6 +261,35 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
mimicFire = nullptr;
}

// CTFPointWeaponMimic::Fire gets inlined, need to detour inputfireonce/inputfiremultiple
DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_Fire)
{
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
if (!rc_CTFPointWeaponMimic_Fire) {
MimicFire(mimic);
}
else {
DETOUR_MEMBER_CALL(CTFPointWeaponMimic_Fire)();
}
}


DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_InputFireOnce, inputdata_t& inputdata)
{
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
MimicFire(mimic);
}

DETOUR_DECL_MEMBER(void, CTFPointWeaponMimic_InputFireMultiple, inputdata_t& inputdata)
{
auto *mimic = reinterpret_cast<CTFPointWeaponMimic *>(this);
int nNumFires = Max( 1, abs(inputdata.value.Int()) );

while( nNumFires-- ) {
MimicFire(mimic);
}
}

DETOUR_DECL_STATIC(CBaseEntity *, CTFProjectile_Rocket_Create, CBaseEntity *pLauncher, const Vector &vecOrigin, const QAngle &vecAngles, CBaseEntity *pOwner, CBaseEntity *pScorer)
{
if (scorer != nullptr) {
Expand Down Expand Up @@ -394,6 +424,8 @@ namespace Mod::Etc::Weapon_Mimic_Teamnum
{
bulletDamageHook.DoLoad();
MOD_ADD_DETOUR_MEMBER(CTFPointWeaponMimic_Fire, "CTFPointWeaponMimic::Fire");
MOD_ADD_DETOUR_MEMBER(CTFPointWeaponMimic_InputFireOnce, "CTFPointWeaponMimic::InputFireOnce");
MOD_ADD_DETOUR_MEMBER(CTFPointWeaponMimic_InputFireMultiple, "CTFPointWeaponMimic::InputFireMultiple");
MOD_ADD_DETOUR_STATIC(CTFProjectile_Rocket_Create, "CTFProjectile_Rocket::Create");
MOD_ADD_DETOUR_STATIC(CTFProjectile_Arrow_Create, "CTFProjectile_Arrow::Create");
MOD_ADD_DETOUR_STATIC(CBaseEntity_CreateNoSpawn, "CBaseEntity::CreateNoSpawn");
Expand Down
2 changes: 1 addition & 1 deletion src/mod/perf/attributes_optimize.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "mod.h"
#include "util/scope.h"
#include "stub/tfplayer.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mod/perf/clientside_wearable_optimize.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef SE_TF2
#ifdef SE_IS_TF2
#include "mod.h"
#include "stub/tfplayer.h"
#include "stub/tfentities.h"
Expand Down
Loading

0 comments on commit 5e3e408

Please sign in to comment.