Skip to content

Black Mesa support - #78

Open
MyGamepedia wants to merge 11 commits into
TF2-DMB:masterfrom
MyGamepedia:bms
Open

MyGamepedia wants to merge 11 commits into
TF2-DMB:masterfrom
MyGamepedia:bms

Conversation

@MyGamepedia

@MyGamepedia MyGamepedia commented Jul 23, 2026

Copy link
Copy Markdown

Full Black Mesa support, a couple of bug fixes, added Black Mesa nav mesh/area features. Compiles under SourceMod 1.12.
Everything was tested on Windows build, the Linux build needs some tests (cuz i was unable):

  • Does it compile ?
  • Does it work without errors ?

It's also better to check if TF2 build is working without errors.
Includes cbasenpc_bmsnavtest, so you can test bms nav features pretty quickly.
I expect this needs a review, I'm not too familiar with how extensions are coded, so I guess some things could be done better, but at very least, the Windows build is working pretty well. Didn't test absolutely everything, but overall I'm happy with how it works. Here is demo I used for the extension abilities showcase in Crowbar/HECU Collective discord servers: https://youtu.be/zxkjcR4G7MQ

Full changes log:
cbasenpc.txt:

  • added bms signs, offsets, etc.

AMBuildScript:

  • now compiles black mesa.

configure.py:

  • should work now

AMBuilder:

  • split bms and tf2 things, tf2 gameruls and tf2 nav/area to tf2, bms nav/area to bms
  • included cbasenpc_bmsnavtest.sp

cbasenpc_internal.cpp:

  • tf2 gamerules stuff is now under macro

extension.cpp:

  • tf2 stuff under tf2 macro
  • proper unload so if it doesn't load it doesn't crash the game

helpers.cpp:

  • iirc the changes for 1.12 compile

natives.cpp:

  • removed double basecombatcharacter::setup

natives\bms:

  • black mesa has custom classes for CNavMesh/CNavArea with CBlackMesa prefix.

entityfactory.cpp, behavior.cpp:

  • changed context->GetContext() to context so it can compile

nav.cpp:

  • split bms and tf2 nav.cpp version via macro

takedamageinfo.cpp:

  • throw error for black mesa if used GettDamageForForceCalc/SetDamageForForceCalc

serialrefresher.cpp:

  • used different algorithm to get framesnapshotmanager in bms

baseanimating.cpp, baseanimating.h:

  • bms wil use offset for CBaseAnimating::mSequenceDuration
  • used different algorithm to get GetAnimationEvent in bms

baseentity.cpp, baseentity.h:

  • new code to get CBaseEntity::PhysicsMarkEntitiesAsTouching and g_TouchTrace.
  • black mesa will use trigger_auto_crouch for BEGIN_VAR instead of trigger_stun.
  • added CBaseEntity::SDK_OnUnload() for proper unload.

bms_nav_area.h:

  • CBlackMesaNavArea class.

nav_mesh.cpp:

  • will give more info when unloaded for CNavMesh::Load reasons.
  • used symbols for bms linux build.

takedamageinfo.cpp:

  • m_flDamageForForce moved as tf2 only.

toolsnav_mesh.h:

  • added "vstdlib/random.h" to compile.

cbasenpc.txt:

  • new data + fixes to prev commit

PackageScript:

  • bms folder included

bms\nav.inc:

  • methodmap for CBlackMesaNavArea

pluginentityfactory.h:

  • added sensitive classname compare fix, need for newlights and gonarch spawn.

NextBotEventResponderInterface.h:

  • added OnThreatChanged(CBaseEntity*) for bms

nav_area.h:

  • bms crash fixes

NextBotGroundLocomotion.h:

  • bms crash fix

bms/activity.inc:

  • bms activity enum version, taked from SourceCoop

cbasenpc.inc:

  • added CBASENPC_BLACKMESA and CBASENPC_TF2 macro, this allows you to compile the same plugin for different games.

baseanimating.inc:

  • split tf2 and bms activity versions

takedamageinfo.inc:

  • split so crit features only in tf2 plugins

cbasenpc_bmsnavtest.sp:

  • simple plugin to test bms nav.

Update:
Added Kenzzer requested changes, added Devin (AI) review red flag requested changes (see pluginentityfactory.cpp list of changes), fixed plugin compile time issues. I also reworked a bit the way extension loads itself, so it can be safe and work properly for SourceMod forks that support very early plugin loads (before a valid map is available).
Full list of changes:
cbasenpc.inc:

  • All things like "const Thing INVALID_THING= view_as(-1);" are now replaced with "#define INVALID_THING view_as(-1)", so 1.13 can compile.
  • Added forward OnCBaseNPCInitialized() that fires when all offsets and data are loaded, fired only once, allows safe classes setup for plugins.
    baseanimating.inc:
  • Solved compile error caused by using "tf2/activity.inc" and not "tf/activity.inc".
    baseanimatingoverlay.inc:
  • Now CAnimationOverlay doesn't prevent 1.13 compile due to some errors.
    baseentity.inc:
  • Removed RefreshNetwork native, because removed entire serialrefresher (asked by Kenzzer).
    takedamageinfo.inc:
  • Changed returrn value from float to int for GetDamageCustom(), this is duplicate of Change GetDamageCustom return value #79.
    cbasenpc.txt:
  • Removed everything related to snapshot manager.
  • Reworked the way TheNavAreas and TheNavMesh are loaded.
  • Removed sign of CBaseAnimating::SequenceDuration for Black Mesa. Not used.
    AMBuilder:
  • Removed serialrefresher.cpp from the list.
    extension:
  • Reworked how extension loads in case engine doesn't provide entity slots when it's loaded, this is needed for SourceMod forks that can launch extensions and plugins before a valid map is available, otherwise the entire game will crash with "ED_Alloc: No edicts yet" engine error, because extension attempts to create a few entities for data. If engine->GetEntityCount() < 1, extension creates a temp hook on IServerGameDLL::LevelInit, once it happens - it loads data that needs an active server with valid map, this still happens before entity lump read. The hook removes itself once fired.
  • Dummy NPC test is moved to TestDummyNPC() method, I also added nullptr checks to make it safe.
  • SDK_OnUnload() now removes hook (in case it isn't), checks if certain data loaded.
  • Data load that needs a valid map is moved now to Initialize(char* error, size_t maxlength) method.
  • Added a few blanks for IntervalTimer datamap, so extension can be compiled for Black Mesa.
    extension.h:
  • Added new methods and m_iLevelInitHookID var that stores LevelInit hook ID, used to remove the hook later.
    \NextBotGroundLocomotion.h:
  • Removed hack for fixed timer size under Black Mesa.
    nav_mesh.cpp/.h:
  • New load method for TheNavMesh and TheNavAreas.
  • CNavMesh::SDK_OnUnload renamed to CNavMesh::Unload.
    nav_area.h:
  • Used the same code to get m_hidingSpots for for TF2 and Black Mesa.
    baseentity.cpp/.h:
  • Used trigger entity for both TF2 and Black Mesa instead of using trigger_auto_crouch for Black Mesa and trigger_stun for TF2.
  • CBaseEntity::SDK_OnUnload renamed to CBaseEntity::Unload.
    serialrefresher.cpp/.h:
  • Both files are now removed, requested by reviewer.
    pluginentityfactory.cpp:
  • CPluginEntityFactories::CPluginEntityFactories now sets nulls for m_FactoryType, m_fwdInstalledFactory, m_fwdUninstalledFactory.
  • CPluginEntityFactories::Init now removes hooks in case registration returned 0.
  • CPluginEntityFactories::SDK_OnAllLoaded fires OnCBaseNPCInitialized as the save point for all plugins, this ensures that all necessary data is loaded and new classes creation will be safe.
  • CPluginEntityFactories::SDK_OnUnload nulls some data and removes hooks.
    takedamageinfo.cpp:
  • Changed "CTakeDamageInfo.GetDamageForForceCalc is only supported in TF2." to "Not supported for this mod.".
    cbasenpc.cpp:
  • Now it checks if it's safe to create base_npc (just in case).
    baseentity.cpp:
  • Removed RefreshNetwork native.
    helpers.cpp/.h:
  • Removed GetFunctionByNameEx.

AMBuildScript:
- now compiles black mesa.
configure.py
- should work now
AMBuilder:
- split bms and tf2 things, tf2 gameruls and tf2 nav/area to tf2, bms nav/area to bms
cbasenpc_internal.cpp:
- tf2 gamerules stuff is now under macro
extension.cpp:
- tf2 stuff under tf2 macro
- proper unload so if it doesn't load it doesn't crash the game
helpers.cpp:
- iirc the changes for 1.12 compile
natives.cpp:
- removed double basecombatcharacter::setup
natives\bms:
- black mesa has custom classes for CNavMesh/CNavArea with CBlackMesa prefix.
entityfactory.cpp, behavior.cpp:
- changed context->GetContext() to context so it can compile
nav.cpp:
- split bms and tf2 nav.cpp version via macro
takedamageinfo.cpp:
- throw error for black mesa if used GettDamageForForceCalc/SetDamageForForceCalc
serialrefresher.cpp:
- used different algorithm to get framesnapshotmanager in bms
baseanimating.cpp, baseanimating.h:
- bms wil use offset for CBaseAnimating::mSequenceDuration
- used different algorithm to get GetAnimationEvent in bms
baseentity.cpp, baseentity.h:
- new code to get CBaseEntity::PhysicsMarkEntitiesAsTouching and g_TouchTrace.
- black mesa will use trigger_auto_crouch for BEGIN_VAR instead of trigger_stun.
- added CBaseEntity::SDK_OnUnload() for proper unload.
bms_nav_area.h:
- CBlackMesaNavArea class.
nav_mesh.cpp:
- will give more info when unloaded for CNavMesh::Load reasons.
takedamageinfo.cpp:
- m_flDamageForForce moved as tf2 only.
toolsnav_mesh.h:
- added "vstdlib/random.h" to compile.
cbasenpc.txt:
- new data + fixes to prev commit
PackageScript:
- bms folder included
bms\nav.inc:
- methodmap for CBlackMesaNavArea
black mesa doesn't always use lowercase only classnames, so newlights and gonarch doesn't appear, newlight_point will appear but newLight_Point won't (the second case used by maps). this fixes the issue.
nav area map crash fix, fixed offsets for UpdateLastKnownArea and OnNavAreaChanged, nextbot spawn crashes
- fixed "Host_Error: DLL_SetView: not a client" error, the reason is silly... the sign was for OnRestore and not for LookupPoseParameter, i wasted my entire day on this...
- cbasenpc_example.sp now will compile.
- added bmsnavtest.sp for black mesa nav mesh/area test goals.
- Now the compiler will split Black Mesa and TF2 features, this is taked from SourceCoop. By default, TF2 version compiled. Currently this affect activity.inc file include and damage crit type natives.
- Moved TF2 activity.inc version to tf subfolder.
- moved bmsnavtest.sp.
- added cbasenpc_bmsnavtest.sp to AMBuilder from scripting folder.
@Kenzzer

Kenzzer commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Everything was tested on Windows build, the Linux build needs some tests

Even if it's half broken/no linux support, PR like these are always a welcomed addition.

I'm quite busy currently, so I'm going to review the PR over several days. Still thanks for your work!

@Kenzzer Kenzzer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here's the review, thank you for your work.

Comment thread extension/sourcesdk/NextBot/NextBotGroundLocomotion.h Outdated
Comment thread extension/natives/takedamageinfo.cpp Outdated
Comment thread extension/natives/takedamageinfo.cpp Outdated
Comment thread extension/sourcesdk/baseanimating.cpp
Comment thread extension/sourcesdk/baseentity.cpp Outdated
Comment thread scripting/include/cbasenpc/takedamageinfo.inc
Comment thread scripting/include/cbasenpc/takedamageinfo.inc
Comment thread scripting/include/cbasenpc/baseanimating.inc
Comment thread extension/sourcesdk/nav_mesh.cpp Outdated
Comment thread extension/serialrefresher.cpp Outdated
Added  Kenzzer requested changes, added Devin (AI) review red flag requested changes (see pluginentityfactory.cpp list of changes), fixed plugin compile time issues. I also reworked a bit the way extension loads itself, so it can be safe and work properly for SourceMod forks that support very early plugin loads (before a valid map is available).
Full list of changes:
cbasenpc.inc:
- All things like "const Thing INVALID_THING= view_as<Thing>(-1);" are now replaced with "#define INVALID_THING view_as<Thing>(-1)", so 1.13 can compile.
- Added forward OnCBaseNPCInitialized() that fires when all offsets and data are loaded, fired only once, allows safe classes setup for plugins.
baseanimating.inc:
- Solved compile error caused by using "tf2/activity.inc" and not "tf/activity.inc".
baseanimatingoverlay.inc:
- Now CAnimationOverlay doesn't prevent 1.13 compile due to some errors.
baseentity.inc:
- Removed RefreshNetwork native, because removed entire serialrefresher (asked by Kenzzer).
takedamageinfo.inc:
- Changed returrn value from  float to int for GetDamageCustom(), this is duplicate of TF2-DMB#79.
cbasenpc.txt:
- Removed everything related to snapshot manager.
- Reworked the way TheNavAreas and TheNavMesh are loaded.
- Removed sign of CBaseAnimating::SequenceDuration for Black Mesa. Not used.
AMBuilder:
- Removed serialrefresher.cpp from the list.
extension:
- Reworked how extension loads in case engine doesn't provide entity slots when it's loaded, this is needed for SourceMod forks that can launch extensions and plugins before a valid map is available, otherwise the entire game will crash with "ED_Alloc: No edicts yet" engine error, because extension attempts to create a few entities for data. If engine->GetEntityCount() < 1, extension creates a temp hook on IServerGameDLL::LevelInit, once it happens - it loads data that needs an active server with valid map, this still happens before entity lump read. The hook removes itself once fired.
- Dummy NPC test is moved to TestDummyNPC() method, I also added nullptr checks to make it safe.
- SDK_OnUnload() now removes hook (in case it isn't), checks if certain data loaded.
- Data load that needs a valid map is moved now to Initialize(char* error, size_t maxlength) method.
- Added a few blanks for IntervalTimer datamap, so extension can be compiled for Black Mesa.
extension.h:
- Added new methods and m_iLevelInitHookID  var that stores LevelInit hook ID, used to remove the hook later.
\NextBotGroundLocomotion.h:
- Removed hack for fixed timer size under Black Mesa.
nav_mesh.cpp/.h:
- New load method for TheNavMesh and TheNavAreas.
- CNavMesh::SDK_OnUnload renamed to CNavMesh::Unload.
nav_area.h:
- Used the same code to get m_hidingSpots for for TF2 and Black Mesa.
baseentity.cpp/.h:
- Used trigger entity for both TF2 and Black Mesa instead of using trigger_auto_crouch for Black Mesa and trigger_stun for TF2.
- CBaseEntity::SDK_OnUnload renamed to CBaseEntity::Unload.
serialrefresher.cpp/.h:
- Both files are now removed, requested by reviewer.
pluginentityfactory.cpp:
- CPluginEntityFactories::CPluginEntityFactories now sets nulls for m_FactoryType, m_fwdInstalledFactory, m_fwdUninstalledFactory.
- CPluginEntityFactories::Init now removes hooks in case registration returned 0.
- CPluginEntityFactories::SDK_OnAllLoaded fires OnCBaseNPCInitialized as the save point for all plugins, this ensures that all necessary data is loaded and new classes creation will be safe.
- CPluginEntityFactories::SDK_OnUnload nulls some data and removes hooks.
takedamageinfo.cpp:
- Changed "CTakeDamageInfo.GetDamageForForceCalc is only supported in TF2." to "Not supported for this mod.".
cbasenpc.cpp:
- Now it checks if it's safe to create base_npc (just in case).
baseentity.cpp:
- Removed RefreshNetwork native.
helpers.cpp/.h:
- Removed GetFunctionByNameEx.
@MyGamepedia
MyGamepedia requested a review from Kenzzer September 13, 2026 11:29
@MyGamepedia

Copy link
Copy Markdown
Author

@Kenzzer I'm sorry for such a long delay, I was doing some things that made this project not a priority for me, although I made half of the changes from the previous ones a long time ago.
Anyway, I did all changes I agreed with. Also, I hope you are not against a small support for my SourceMod fork. I short, I made it so it loads plugins and extensions before a valid map exists, together with VGUI, which is a good point for client side things I need for my Black Mesa mod. The problem is that this extension creates edicts on start, which is not possible with such SM rework (causes engine error), so I added a small workaround + forward that tells all plugins that this extension loaded everything needed and safe to use. This change won't affect dedicated servers or general SourceMod forks, cuz engine->GetEntityCount() will return proper value.
All the changes I did was tested in Black Mesa current build, seems to work pretty well,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants