Skip to content

Commit

Permalink
Various fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rafradek committed Oct 10, 2024
1 parent b70ae32 commit efbb1cf
Show file tree
Hide file tree
Showing 40 changed files with 5,330 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++20",
"cppStandard": "gnu++23",
"intelliSenseMode": "linux-gcc-x86",
"compilerArgs": [
"-m64"
Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,7 @@
"lowercase-global"
],
"terminal.integrated.copyOnSelection": true,
"cmake.configureOnOpen": false
"cmake.configureOnOpen": false,
"C_Cpp.default.cppStandard": "c++23",
"C_Cpp.default.cStandard": "c17"
}
3 changes: 3 additions & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ if not Extension.optimize_mods_only:
'src/mod/etc/target_changegravity_improved.cpp',
'src/mod/etc/vehicle_fix.cpp',
'src/mod/etc/weapon_mimic_teamnum.cpp',
'src/mod/etc/workshop_map_fix.cpp',
'src/mod/etc/trigger_filter_fix.cpp',
'src/mod/etc/spectator_vote_fix.cpp',
'src/mod/etc/unintended_class_weapon_improvements.cpp',
Expand Down Expand Up @@ -504,6 +505,8 @@ for sdk_name in Extension.sdks:
if builder.options.optimize_mods_only:
binary.compiler.defines += ['OPTIMIZE_MODS_ONLY']

binary.sources += ['/fdf']

## build libstrcompat
#if builder.target.platform == 'linux':
# _, libstrcompat = builder.AddCommand(
Expand Down
14 changes: 14 additions & 0 deletions PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ folder_list = [
'addons/sourcemod/gamedata',
'addons/sourcemod/gamedata/sigsegv',
'addons/sourcemod/translations',
'addons/sourcemod/translations/zho',
'addons/sourcemod/translations/chi',
# 'addons/sourcemod/configs',
'cfg',
]
Expand Down Expand Up @@ -123,6 +125,18 @@ CopyFiles('translations', 'addons/sourcemod/translations',
'sigsegvattributes.phrases.txt'
]
)
CopyFiles('translations/zho', 'addons/sourcemod/translations/zho',
[
'sigsegv.phrases.txt',
'sigsegvattributes.phrases.txt'
]
)
CopyFiles('translations/chi', 'addons/sourcemod/translations/chi',
[
'sigsegv.phrases.txt',
'sigsegvattributes.phrases.txt'
]
)

if Extension.optimize_mods_only:
builder.AddCopy('cfg/sigsegv_convars_optimize_only.cfg', 'cfg/sigsegv_convars.cfg')
Expand Down
4 changes: 4 additions & 0 deletions cfg/sigsegv_convars.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ sig_etc_server_redirects_redirect_only "0" // This server is for redirects only
sig_etc_target_changegravity_improved "0" // Mod: improve the target_changegravity entity so that it's actually usable
sig_etc_vehicle_fix "1" // "Mod: fix prop_vehicle_driveable"
sig_etc_weapon_mimic_teamnum "1" // Mod: weapon mimic teamnum fix
sig_etc_workshop_map_fix "0" // Mod: automatically install workshop maps into maps directory, allowing to use workshop maps without prefix. Need to run tf_workshop_map_sync command for each workshop map. Clients can still benefit from workshop download
sig_etc_workshop_map_fix_install_location "maps" // Install location for workshop maps links relative to tf directory. Creates missing directories
sig_etc_workshop_map_fix_fix_remove_old_links "1" // Remove workshop links from install location than are not currently added
sig_etc_trigger_filter_fix "1" // Mod: Deleted entities trigger filtering crash fix
sig_etc_spectator_vote_fix "1" // Mod: Respect sv_vote_allow_spectators when counting votes
sig_etc_unintended_class_weapon_viewmodel 0 // Mod: use proper class viewmodel animations for unintended player class weapons
Expand Down Expand Up @@ -260,6 +263,7 @@ sig_mvm_blacklist_givenameditem "1" // Use item blacklist in GiveNamedItem for
sig_mvm_print_parse_errors "1" // Print mission parse errors in console
sig_banned_missions_file "banned_missions.txt" // Location of a file containing banned missions list
sig_send_bots_to_spectator_immediately "0" // Bots should be send to spectator immediately after dying
sig_only_read_missions_from_directory "" // Only read missions from specified directory relative to tf/. Also removes maps with no available missions from voting
sig_pop_popmgr_extensions "1" // Mod: enable extended KV in CPopulationManager::Parse
sig_mvm_robot_multiplier "0" // Multiply robot count in missions
sig_mvm_robot_multiplier_tank_hp "0.5" // Tank HP multiplier for robot multiplier mode
Expand Down
3 changes: 3 additions & 0 deletions cfg/sigsegv_convars_no_mvm.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ sig_etc_suppress_nb_event_messages "0" // Mod: suppress NextBot event RESULT_CR
sig_etc_target_changegravity_improved "0" // Mod: improve the target_changegravity entity so that it's actually usable
sig_etc_vehicle_fix "1" // Etc: fix prop_vehicle_driveable
sig_etc_weapon_mimic_teamnum "1" // Mod: weapon mimic teamnum fix
sig_etc_workshop_map_fix "0" // Mod: automatically install workshop maps into maps directory, allowing to use workshop maps without prefix. Need to run tf_workshop_map_sync command for each workshop map. Clients can still benefit from workshop download
sig_etc_workshop_map_fix_install_location "maps" // Install location for workshop maps links relative to tf directory. Creates missing directories
sig_etc_workshop_map_fix_fix_remove_old_links "1" // Remove workshop links from install location than are not currently added
sig_etc_trigger_filter_fix "1" // Mod: Deleted entities trigger filtering crash fix
sig_etc_unintended_class_weapon_viewmodel 0 // Mod: use proper class viewmodel animations for unintended player class weapons
sig_etc_unintended_class_weapon_player_model 0 // Mod: use proper class player animations for unintended player class weapons
Expand Down
2 changes: 2 additions & 0 deletions gamedata/sigsegv/entities.txt
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@
"CWeaponMedigun::CycleResistType" "_ZN14CWeaponMedigun15CycleResistTypeEv"
"CWeaponMedigun::FindAndHealTargets" "_ZN14CWeaponMedigun18FindAndHealTargetsEv"
"CWeaponMedigun::Deploy" "_ZN14CWeaponMedigun6DeployEv"
"CWeaponMedigun::PrimaryAttack" "_ZN14CWeaponMedigun13PrimaryAttackEv"

"CTFWeaponFlameBall::FireProjectile" "_ZN18CTFWeaponFlameBall14FireProjectileEP9CTFPlayer"

Expand Down Expand Up @@ -884,6 +885,7 @@
"CTFFlameThrower::GetDeflectionRadius" "_ZNK15CTFFlameThrower19GetDeflectionRadiusEv"
"CTFFlameThrower::GetFlameOriginPos" "_ZN15CTFFlameThrower17GetFlameOriginPosEv"
"CTFFlameThrower::GetMuzzlePosHelper" "_ZN15CTFFlameThrower18GetMuzzlePosHelperEb"
"CTFFlameThrower::PrimaryAttack" "_ZN15CTFFlameThrower13PrimaryAttackEv"
"CTFFlareGun_Revenge::Deploy" "_ZN19CTFFlareGun_Revenge6DeployEv"
"CTFFlareGun_Revenge::Holster" "_ZN19CTFFlareGun_Revenge7HolsterEP17CBaseCombatWeapon"
"CTFGasManager::OnCollide" "_ZN13CTFGasManager9OnCollideEP11CBaseEntityi"
Expand Down
85 changes: 84 additions & 1 deletion gamedata/sigsegv/misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3169,7 +3169,89 @@
type "sym"
sym "_ZN11CBaseServer13ConnectClientER8netadr_siiiiPKcS3_S3_i"
}


"CTFGameStats::Event_PlayerFiredWeapon"
{
type "sym"
sym "_ZN12CTFGameStats23Event_PlayerFiredWeaponEP9CTFPlayerb"
}

"Msg [vscript]"
{
lib "vscript"
type "sym"
sym "Msg"
}

"Msg"
{
lib "tier0"
type "sym"
sym "Msg"
}

"SQVM::Call"
{
lib "vscript"
type "sym"
sym64 "_ZN4SQVM4CallER11SQObjectPtrxxS1_y"
sym "_ZN4SQVM4CallER11SQObjectPtriiS1_j"
}

"CTestScriptMgr::CheckPoint"
{
lib "engine"
type "sym"
sym "_ZN14CTestScriptMgr10CheckPointEPKc"
}

"TFMapsWorkshop"
{
type "sym"
sym "_Z14TFMapsWorkshopv"
}
"CTFMapsWorkshop::GetMapName"
{
type "sym"
sym "_ZN15CTFMapsWorkshop10GetMapNameEyR10CUtlString"
}
"CTFMapsWorkshop::FindOrCreateMapByNames"
{
type "sym"
sym "_ZN15CTFMapsWorkshop21FindOrCreateMapByNameEPKc"
}
"CTFWorkshopMap::GetLocalFile"
{
type "sym"
sym "_ZN14CTFWorkshopMap12GetLocalFileER10CUtlString"
}
"CTFWorkshopMap::OnUGCItemInstalled"
{
type "sym"
sym "_ZN14CTFWorkshopMap18OnUGCItemInstalledEP15ItemInstalled_t"
}
"CTFMapsWorkshop::AddMap"
{
type "sym"
sym "_ZN15CTFMapsWorkshop6AddMapEy"
}
"CTFMapsWorkshop::Steam_OnUGCItemInstalled"
{
type "sym"
sym "_ZN15CTFMapsWorkshop24Steam_OnUGCItemInstalledEP15ItemInstalled_t"
}
"CDownloadListGenerator::OnResourcePrecachedFullPath"
{
lib "engine"
type "sym"
sym "_ZN22CDownloadListGenerator27OnResourcePrecachedFullPathEPcPKc"
}
"CVEngineServer::FindMap"
{
lib "engine"
type "sym"
sym "_ZN14CVEngineServer7FindMapEPci"
}
}
"addrs_group"
{
Expand Down Expand Up @@ -3248,6 +3330,7 @@
"IgnoreActorsTraceFilterFunction" "_Z31IgnoreActorsTraceFilterFunctionP13IHandleEntityi"
"CKickIssue::RequestCallVote" "_ZN10CKickIssue15RequestCallVoteEiPKcR20vote_create_failed_tRi"

"UTIL_SetOrigin" "_Z14UTIL_SetOriginP11CBaseEntityRK6Vectorb"
"UTIL_TraceEntity [IHandleEntity]" "_Z16UTIL_TraceEntityP11CBaseEntityRK6VectorS3_jPK13IHandleEntityiP10CGameTrace"

"CEconItemSchema::Reset" "_ZN15CEconItemSchema5ResetEv"
Expand Down
12 changes: 12 additions & 0 deletions src/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#endif
#include "version.h"
#include "convar_restore.h"
#include "vscript/ivscript.h"
//#include "entity.h"

CExtSigsegv g_Ext;
Expand Down Expand Up @@ -85,6 +86,9 @@ IPhraseFile *phrasesFile = nullptr;
IPhraseCollection *phrasesAttribs = nullptr;
IPhraseFile *phrasesAttribsFile = nullptr;

IScriptManager *scriptManager = nullptr;

extern int laserSprite;
bool CExtSigsegv::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
#ifndef OPTIMIZE_MODS_ONLY
Expand Down Expand Up @@ -129,6 +133,8 @@ bool CExtSigsegv::SDK_OnLoad(char *error, size_t maxlength, bool late)
phrasesAttribsFile = phrases->AddPhraseFile("sigsegvattributes.phrases");

identity = sharesys->CreateIdentity(sharesys->CreateIdentType("Sigsegv"), this);

laserSprite = CBaseEntity::PrecacheModel("materials/sprites/laser.vmt");
// for (int i = 0; i < 255; ++i) {
// ConColorMsg(Color(0xff, i, 0x00), "%02x%02x%02x\n", 0xff, i, 0x00);
// }
Expand Down Expand Up @@ -229,6 +235,10 @@ bool CExtSigsegv::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength

GET_IFACE_OPTIONAL(Engine, debugoverlay, VDEBUG_OVERLAY_INTERFACE_VERSION);
GET_IFACE_OPTIONAL(Engine, enginetools, VENGINETOOL_INTERFACE_VERSION);

if (VScriptManagerFactory() != nullptr) {
GET_IFACE_OPTIONAL(VScriptManager, scriptManager, VSCRIPT_INTERFACE_VERSION);
}

if (SoundEmitterSystemFactory() != nullptr) {
GET_IFACE_OPTIONAL(SoundEmitterSystem, soundemitterbase, SOUNDEMITTERSYSTEM_INTERFACE_VERSION);
Expand Down Expand Up @@ -291,6 +301,7 @@ bool CExtSigsegv::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength
LibMgr::SetPtr(Library::VGUI, VGUIFactory());
LibMgr::SetPtr(Library::VPHYSICS, VPhysicsFactory());
LibMgr::SetPtr(Library::VSTDLIB, icvar);
LibMgr::SetPtr(Library::VSCRIPT, VScriptManagerFactory());

return true;
}
Expand Down Expand Up @@ -321,6 +332,7 @@ void CExtSigsegv::LevelInitPreEntity()
void CExtSigsegv::LevelInitPostEntity()
{
g_pWorldEdict = engine->PEntityOfEntIndex(0);
laserSprite = CBaseEntity::PrecacheModel("materials/sprites/laser.vmt");
}

void CExtSigsegv::LoadSoundOverrides()
Expand Down
1 change: 1 addition & 0 deletions src/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ DEF_GET_FACTORY(VGUI, "vgui2");
DEF_GET_FACTORY(VGUIMatSurface, "vguimatsurface");
DEF_GET_FACTORY(Dedicated, "dedicated");
DEF_GET_FACTORY(DataCache, "datacache");
DEF_GET_FACTORY(VScriptManager, "vscript");
1 change: 1 addition & 0 deletions src/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CreateInterfaceFn VGUIFactory();
CreateInterfaceFn VGUIMatSurfaceFactory();
CreateInterfaceFn DedicatedFactory();
CreateInterfaceFn DataCacheFactory();
CreateInterfaceFn VScriptManagerFactory();


#endif
3 changes: 2 additions & 1 deletion src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static std::map<Library, const char *> libnames{
{ Library::VPHYSICS, "vphysics" },
{ Library::VSTDLIB, "vstdlib" },
{ Library::SOURCEMODCORE, "sourcemodcore" },
{ Library::VSCRIPT, "vscript" },
};

static std::map<Segment, const char *> segnames{
Expand Down Expand Up @@ -341,7 +342,7 @@ CON_COMMAND(sig_list_signatures, "") {
for (auto &[lib, libname] : libnames) {
LibMgr::ForEachSym(lib, [&](const Symbol& sym){
if (std::regex_match(sym.name, filter, std::regex_constants::match_any)) {
Msg("Match: %s\n", sym.name.c_str());
Msg("Match: %s | %s\n", sym.name.c_str(), libname);
}
return true;
});
Expand Down
1 change: 1 addition & 0 deletions src/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum class Library : int
VPHYSICS,
VSTDLIB,
SOURCEMODCORE,
VSCRIPT,
};


Expand Down
53 changes: 33 additions & 20 deletions src/mod/ai/npc_nextbot/npc_nextbot_unlag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "stub/usermessages_sv.h"
#include "stub/particles.h"
#include "stub/lagcompensation.h"
#include "collisionutils.h"

#define LAG_COMPENSATION_EPS_SQR ( 0.1f * 0.1f )
// Allow 4 units of error ( about 1 / 8 bbox width )
Expand All @@ -35,6 +36,11 @@ float g_flFractionScale = 0.95;
#define LC_SIZE_CHANGED (1<<10)
#define LC_ANIMATION_CHANGED (1<<11)

namespace Mod::Perf::Func_Optimize
{
extern float coneOfAttack;
}

namespace Mod::AI::NPC_Nextbot
{
ConVar *sv_unlag;
Expand Down Expand Up @@ -443,33 +449,38 @@ namespace Mod::AI::NPC_Nextbot
{
if (pEntityTransmitBits && !pEntityTransmitBits->Get(entity->entindex())) return false;

const Vector &vMyOrigin = player->GetAbsOrigin();
const Vector &vHisOrigin = entity->GetAbsOrigin();

float maxDistance = 1.5 * entity->GetAbsVelocity().Length() * sv_maxunlag->GetFloat();

// If the player is within this distance, lag compensate them in case they're running past us.
if ( vHisOrigin.DistTo( vMyOrigin ) < maxDistance )
return true;

// If their origin is not within a 45 degree cone in front of us, no need to lag compensate.
Vector vForward;
AngleVectors( pCmd->viewangles, &vForward );

Vector vDiff = vHisOrigin - vMyOrigin;
VectorNormalize( vDiff );
Vector start = player->EyePosition();
const Vector &ourPos = player->GetAbsOrigin();
Vector forward;
AngleVectors(pCmd->viewangles, &forward);

auto cprop = this->entity->CollisionProp();
const Vector &entityPos = this->entity->GetAbsOrigin();
const Vector &velocity = this->entity->GetAbsVelocity();
float backTime = (gpGlobals->tickcount - pCmd->tick_count + 1) * gpGlobals->interval_per_tick + player->m_fLerpTime;
const float speed = Max(fabs(velocity.x), fabs(velocity.y))* 1.4f;
Vector range(speed, speed, Max(50.0f, fabs(velocity.z) * 2.0f));
range *= backTime;
range.x += 25.0f;
range.y += 25.0f;
float cone = Mod::Perf::Func_Optimize::coneOfAttack != -1 ? Mod::Perf::Func_Optimize::coneOfAttack : 0.15f;
if (cone > 0.0f) {
float dist = (entityPos - ourPos).Length();
range += Vector(dist * cone, dist * cone, dist * cone);
}

float flCosAngle = 0.707107f; // 45 degree angle
if ( vForward.Dot( vDiff ) < flCosAngle ) return false;
if (IsBoxIntersectingRay(entityPos+cprop->OBBMins() - range, entityPos+cprop->OBBMaxs() + range, start, forward * 8192, 0.0f)) {
return true;
}

return true;
return false;
}

bool MyNextbotModule::WantsLagCompensation(CBasePlayer *player, const CUserCmd *pCmd, const CBitVec<MAX_EDICTS> *pEntityTransmitBits)
{
if (!LagCompensatedEntity::WantsLagCompensation(player, pCmd, pEntityTransmitBits)) return false;
if (!this->m_bAllowTakeFriendlyFire && this->m_pEntity->GetTeamNumber() == player->GetTeamNumber()) return false;

return this->m_bAllowTakeFriendlyFire || this->m_pEntity->GetTeamNumber() != player->GetTeamNumber();
return LagCompensatedEntity::WantsLagCompensation(player, pCmd, pEntityTransmitBits);
}
// Called during player movement to set up/restore after lag compensation

Expand All @@ -479,6 +490,8 @@ namespace Mod::AI::NPC_Nextbot
if (reinterpret_cast<CLagCompensationManager *>(this) != &g_LagCompensationManager.GetRef()) return;

if (cmd == nullptr) return;

if (AutoList<LagCompensatedEntity>::List().empty()) return;
//DONT LAG COMP AGAIN THIS FRAME IF THERES ALREADY ONE IN PROGRESS
//IF YOU'RE HITTING THIS THEN IT MEANS THERES A CODE BUG
if (currentPlayer)
Expand Down
Loading

0 comments on commit efbb1cf

Please sign in to comment.