Black Mesa support - #78
Conversation
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.
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
left a comment
There was a problem hiding this comment.
And here's the review, thank you for your work.
| #if SOURCE_ENGINE == SE_BMS | ||
| /* | ||
| * The timer classes in the actual Black Mesa binary contain an | ||
| * additional 4-byte vtable pointer which is absent from the SDK | ||
| * declarations used to build the extension. | ||
| * | ||
| * ILocomotion: | ||
| * 2 IntervalTimer = 8 missing bytes | ||
| * 1 CountdownTimer = 4 missing bytes | ||
| * | ||
| * NextBotGroundLocomotion: | ||
| * 3 CountdownTimer = 12 missing bytes | ||
| * | ||
| * Total: 24 bytes, or 0x18. | ||
| * | ||
| * This storage must not be initialized or cleared. The game's | ||
| * NextBotGroundLocomotion constructor uses this memory. | ||
| */ | ||
| unsigned char m_bmsTimerLayoutPadding[0x18]; | ||
| #endif |
There was a problem hiding this comment.
Well, you're in luck I can edit the hl2sdks. So feel free to open an issue or PR over there for the bms branch, and we can fix this.
| return sp_ftoc(info->GetDamageForForceCalc()); | ||
| #else | ||
| return context->ThrowNativeError( | ||
| "CTakeDamageInfo.GetDamageForForceCalc is only supported in TF2." |
There was a problem hiding this comment.
Let's rephrase this as "Not supported for this mod." so we're in line with what SourceMod does as well when a base scripting native it has doesn't function on a certain game.
| return 0; | ||
| #else | ||
| return context->ThrowNativeError( | ||
| "CTakeDamageInfo.SetDamageForForceCalc is only supported in TF2." |
| #if SOURCE_ENGINE == SE_BMS | ||
| VCall<float, CStudioHdr*, int> CBaseAnimating::mSequenceDuration; | ||
| #else | ||
| MCall<float, CStudioHdr*, int> CBaseAnimating::mSequenceDuration; | ||
| #endif |
There was a problem hiding this comment.
Need some explanation on this. I understand you prefer to call the virtual function, because it exists. But then why having added a signature for it in the gamedata ?
| #if SOURCE_ENGINE == SE_BMS | ||
| BEGIN_VAR("trigger_auto_crouch"); | ||
| #else | ||
| BEGIN_VAR("trigger_stun"); | ||
| #endif |
There was a problem hiding this comment.
Instead of having an if/else here, let's see if we can't just pick a shared entity between the two games. prop_dynamic should work, even if it isn't directly CBaseEntity
| #endif | ||
| #define _CBASENPC_TAKEDAMAGEINFO_INC_ | ||
|
|
||
| #if defined CBASENPC_TF2 |
| */ | ||
| public native void SetDamagedOtherPlayers(int value); | ||
|
|
||
| #if defined CBASENPC_TF2 |
| #if defined CBASENPC_BLACKMESA | ||
| #include "bms/activity.inc" | ||
| #elseif defined CBASENPC_TF2 | ||
| #include "tf2/activity.inc" | ||
| #endif |
There was a problem hiding this comment.
As is, I don't like that. But it's my fault this is necessary in the first place. This can be kept.
| #if SOURCE_ENGINE == SE_BMS && defined(__linux__) | ||
| void* navMeshAddress = nullptr; | ||
| if (!config->GetMemSig("TheNavMesh_Linux", &navMeshAddress) || !navMeshAddress) | ||
| { | ||
| snprintf(error, maxlength, "Couldn't resolve TheNavMesh_Linux symbol!"); | ||
| return false; | ||
| } | ||
| else | ||
|
|
||
| void* navAreasAddress = nullptr; | ||
| if (!config->GetMemSig("TheNavAreas_Linux", &navAreasAddress) || !navAreasAddress) | ||
| { | ||
| snprintf(error, maxlength, "Failed to retrieve TheNavMesh ptr!"); | ||
| snprintf(error, maxlength, "Couldn't resolve TheNavAreas_Linux symbol!"); | ||
| return false; | ||
| } | ||
|
|
||
| g_pNavMeshLoad = DETOUR_CREATE_MEMBER(CNavMesh_Load, "CNavMesh::Load"); | ||
| if (g_pNavMeshLoad != nullptr) | ||
| // TheNavMesh is a global CNavMesh* variable. | ||
| CNavMesh** navMeshGlobal = reinterpret_cast<CNavMesh**>(navMeshAddress); | ||
| resolvedNavMesh = *navMeshGlobal; | ||
|
|
||
| // TheNavAreas is the global NavAreaVector object itself. | ||
| resolvedNavAreas = reinterpret_cast<NavAreaVector*>(navAreasAddress); | ||
| #else |
There was a problem hiding this comment.
This is probably going to be a big blocking span of code in this review. Ideally I want the lookup method to be shared between all games, if it needs to be adapted I can make a concession. But TheNavAreas & TheNavMesh should be both possible to resolve in assembly with CNavMesh::Load signature, yes it does mean a little more gamedata but this keeps everything clear.
I can shoulder that part of the work if you can provide me the server.dll/srv.so for bms.
| @@ -84,35 +84,103 @@ void Tools_RefreshEntity(CBaseEntity* entity, int player, bool toggle) { | |||
|
|
|||
| bool Tools_Refresh_Init(SourceMod::IGameConfig* config, char* error, size_t maxlength) | |||
There was a problem hiding this comment.
This whole thing was an experiment that didn't turn out as well as I hoped. So we can delete everything here if you're not using on bms.
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):
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:
AMBuildScript:
configure.py:
AMBuilder:
cbasenpc_internal.cpp:
extension.cpp:
helpers.cpp:
natives.cpp:
natives\bms:
entityfactory.cpp, behavior.cpp:
nav.cpp:
takedamageinfo.cpp:
serialrefresher.cpp:
baseanimating.cpp, baseanimating.h:
baseentity.cpp, baseentity.h:
bms_nav_area.h:
nav_mesh.cpp:
takedamageinfo.cpp:
toolsnav_mesh.h:
cbasenpc.txt:
PackageScript:
bms\nav.inc:
pluginentityfactory.h:
NextBotEventResponderInterface.h:
nav_area.h:
NextBotGroundLocomotion.h:
bms/activity.inc:
cbasenpc.inc:
baseanimating.inc:
takedamageinfo.inc:
cbasenpc_bmsnavtest.sp: