Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PossibleSDKs = {
# 'hl2dm': SDK('HL2SDKHL2DM', '2.hl2dm', '7', 'HL2DM', WinLinuxMac, 'hl2dm'),
# 'dods': SDK('HL2SDKDODS', '2.dods', '8', 'DODS', WinLinuxMac, 'dods'),
# 'sdk2013': SDK('HL2SDK2013', '2.sdk2013', '9', 'SDK2013', WinLinuxMac, 'sdk2013'),
'tf2': SDK('HL2SDKTF2', '2.tf2', '11', 'TF2', WinLinuxMac, 'tf2')
'tf2': SDK('HL2SDKTF2', '2.tf2', '11', 'TF2', WinLinuxMac, 'tf2'),
# 'l4d': SDK('HL2SDKL4D', '2.l4d', '12', 'LEFT4DEAD', WinLinuxMac, 'l4d'),
# 'nucleardawn': SDK('HL2SDKND', '2.nd', '13', 'NUCLEARDAWN', WinLinuxMac, 'nucleardawn'),
# 'l4d2': SDK('HL2SDKL4D2', '2.l4d2', '15', 'LEFT4DEAD2', WinLinuxMac, 'l4d2'),
Expand All @@ -53,7 +53,7 @@ PossibleSDKs = {
# 'blade': SDK('HL2SDKBLADE', '2.blade', '18', 'BLADE', WinLinux, 'blade'),
# 'insurgency': SDK('HL2SDKINSURGENCY', '2.insurgency', '19', 'INSURGENCY', WinLinuxMac, 'insurgency'),
# 'contagion': SDK('HL2SDKCONTAGION', '2.contagion', '14', 'CONTAGION', WinOnly, 'contagion'),
# 'bms': SDK('HL2SDKBMS', '2.bms', '10', 'BMS', WinLinux, 'bms'),
'bms': SDK('HL2SDKBMS', '2.bms', '10', 'BMS', WinLinux, 'bms'),
}

def ResolveEnvPath(env, folder=None):
Expand Down Expand Up @@ -545,8 +545,19 @@ class ExtensionConfig(object):
for lib in libs:
if compiler.target.arch == 'x86':
lib_path = os.path.join(sdk.path, 'lib', 'public', 'x86', lib) + '.lib'

# Older SDK layouts, including BMS, store Win32 libraries
# directly in lib/public rather than lib/public/x86.
if not os.path.isfile(lib_path):
lib_path = os.path.join(sdk.path, 'lib', 'public', lib) + '.lib'
elif compiler.target.arch == 'x86_64':
lib_path = os.path.join(sdk.path, 'lib', 'public', 'x64', lib) + '.lib'
else:
raise Exception('Unsupported Windows architecture: {0}'.format(compiler.target.arch))

if not os.path.isfile(lib_path):
raise Exception('Could not find SDK library: {0}'.format(lib_path))

compiler.linkflags.append(lib_path)

for library in dynamic_libs:
Expand Down
2 changes: 2 additions & 0 deletions PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ folder_list = [
'addons/sourcemod/scripting/include',
'addons/sourcemod/scripting/include/cbasenpc',
'addons/sourcemod/scripting/include/cbasenpc/tf',
'addons/sourcemod/scripting/include/cbasenpc/bms',
'addons/sourcemod/scripting/include/cbasenpc/nextbot',
'addons/sourcemod/scripting/include/cbasenpc/nextbot/path',
'addons/sourcemod/gamedata',
Expand Down Expand Up @@ -47,6 +48,7 @@ for smx_file in Extension.smx_files:
CopyDirContent('scripting/include', 'addons/sourcemod/scripting/include')
CopyDirContent('scripting/include/cbasenpc', 'addons/sourcemod/scripting/include/cbasenpc')
CopyDirContent('scripting/include/cbasenpc/tf', 'addons/sourcemod/scripting/include/cbasenpc/tf')
CopyDirContent('scripting/include/cbasenpc/bms', 'addons/sourcemod/scripting/include/cbasenpc/bms')
CopyDirContent('scripting/include/cbasenpc/nextbot', 'addons/sourcemod/scripting/include/cbasenpc/nextbot')
CopyDirContent('scripting/include/cbasenpc/nextbot/path', 'addons/sourcemod/scripting/include/cbasenpc/nextbot/path')
CopyDirContent('gamedata', 'addons/sourcemod/gamedata')
Expand Down
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
default=True, help='Enables the auto versioning script')
parser.options.add_argument('-s', '--sdks', default='all', dest='sdks',
help='Build against specified SDKs; valid args are "all", "present", or '
'comma-delimited list of engine names (default: %default)')
'comma-delimited list of engine names (default: %(default)s)')
parser.options.add_argument('--targets', type=str, dest='targets', default=None,
help="Override the target architecture (use commas to separate multiple targets).")
parser.options.add_argument('--extension-only', action='store_true', dest='extension_only', default=False,
Expand Down
15 changes: 12 additions & 3 deletions extension/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ project.sources = [
'sourcesdk/basecombatcharacter.cpp',
'sourcesdk/servernetworkproperty.cpp',
'sourcesdk/collisionproperty.cpp',
'sourcesdk/tf_gamerules.cpp',
'sourcesdk/tracefilter_simple.cpp',
'sourcesdk/basedoor.cpp',
'sourcesdk/basetoggle.cpp',
Expand Down Expand Up @@ -66,8 +65,6 @@ project.sources = [
'natives/nextbot/path/chase.cpp',
'natives/nextbot/path/follower.cpp',
'natives/nextbotplayer.cpp',
'natives/tf/nav.cpp',
'natives/tf/nav/area.cpp',
os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp')
]

Expand All @@ -79,6 +76,18 @@ for sdk_name in Extension.sdks:
continue

binary = Extension.HL2ExtConfig(project, builder, cxx, 'cbasenpc.ext.' + sdk.ext, sdk)

if sdk_name == 'tf2':
binary.sources += [
'sourcesdk/tf_gamerules.cpp',
'natives/tf/nav.cpp',
'natives/tf/nav/area.cpp',
]
elif sdk_name == 'bms':
binary.sources += [
'natives/bms/nav.cpp',
'natives/bms/nav/area.cpp',
]
Extension.AddCDetour(binary)
binary.compiler.cxxincludes += [
os.path.join(builder.currentSourcePath, 'sourcesdk'),
Expand Down
26 changes: 16 additions & 10 deletions extension/cbasenpc_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "cbasenpc_behavior.h"
#include "pluginentityfactory.h"
#include "sourcesdk/baseentity.h"
#include "sourcesdk/tf_gamerules.h"
#if SOURCE_ENGINE == SE_TF2
#include "sourcesdk/tf_gamerules.h"
#endif
#include "NextBot/Path/NextBotPathFollow.h"
#include <bspflags.h>
#include <ai_activity.h>
Expand Down Expand Up @@ -160,21 +162,25 @@ void CBaseNPC_Entity::BotThink(void)
int CBaseNPC_Entity::OnTakeDamage(const CTakeDamageInfo& info)
{
CTakeDamageInfo newInfo = info;
if (TFGameRules())
{
TFGameRules()->ApplyOnDamageModifyRules(newInfo, this, true);
}
#if SOURCE_ENGINE == SE_TF2
if (TFGameRules())
{
TFGameRules()->ApplyOnDamageModifyRules(newInfo, this, true);
}
#endif
return mOriginalOnTakeDamage(this, newInfo);
}

int CBaseNPC_Entity::OnTakeDamage_Alive(const CTakeDamageInfo& info)
{
CTakeDamageInfo newInfo = info;
if (TFGameRules())
{
CTFGameRules::DamageModifyExtras_t outParams;
newInfo.SetDamage(TFGameRules()->ApplyOnDamageAliveModifyRules(info, this, outParams));
}
#if SOURCE_ENGINE == SE_TF2
if (TFGameRules())
{
CTFGameRules::DamageModifyExtras_t outParams;
newInfo.SetDamage(TFGameRules()->ApplyOnDamageAliveModifyRules(info, this, outParams));
}
#endif
return mOriginalOnTakeDamage_Alive(this, newInfo);
}

Expand Down
24 changes: 18 additions & 6 deletions extension/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <CDetour/detours.h>
#include "helpers.h"
#include "sourcesdk/nav_mesh.h"
#include "sourcesdk/tf_gamerules.h"
#if SOURCE_ENGINE == SE_TF2
#include "sourcesdk/tf_gamerules.h"
#endif
#include "sourcesdk/basetoggle.h"
#include "sourcesdk/funcbrush.h"
#include "natives.hpp"
Expand Down Expand Up @@ -80,12 +82,20 @@ bool CBaseNPCExt::SDK_OnLoad(char* error, size_t maxlength, bool late) {
|| !CNavMesh::Init(g_pGameConf, error, maxlength)
|| !CBaseCombatCharacter::Init(g_pGameConf, error, maxlength)
|| !ToolsTraceFilterSimple::Init(g_pGameConf, error, maxlength)
|| !CTFGameRules::Init(g_pGameConf, error, maxlength)
#if SOURCE_ENGINE == SE_TF2
|| !CTFGameRules::Init(g_pGameConf, error, maxlength)
#endif
|| !CBaseEntityOutput::Init(g_pGameConf, error, maxlength)
|| !CBaseNPC_Locomotion::Init(g_pGameConf, error, maxlength)
|| !ToolsNextBot::Init(g_pGameConf, error, maxlength)
|| !Tools_Refresh_Init(g_pGameConf, error, maxlength)
) {
)
{
// Some initialization stages install detours before all later
// stages have succeeded. Roll them back before SourceMod unloads
// the extension DLL.
CNavMesh::SDK_OnUnload();
CBaseEntity::SDK_OnUnload();
return false;

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.

Rename to Unload and this is good.

}

Expand Down Expand Up @@ -284,7 +294,11 @@ void CBaseNPCExt::NotifyInterfaceDrop(SMInterface* interface) {
}
}

void CBaseNPCExt::SDK_OnUnload() {
void CBaseNPCExt::SDK_OnUnload()
{
CNavMesh::SDK_OnUnload();
CBaseEntity::SDK_OnUnload();
Comment on lines +299 to +300

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.

Ditto


gameconfs->CloseGameConfigFile(g_pGameConf);
forwards->ReleaseForward(g_pForwardEventKilled);

Expand All @@ -299,8 +313,6 @@ void CBaseNPCExt::SDK_OnUnload() {
if (g_pSDKHooks) {
g_pSDKHooks->RemoveEntityListener(this);
}

CNavMesh::SDK_OnUnload();

FOR_EACH_MAP_FAST(g_EntitiesHooks, iHookID)
SH_REMOVE_HOOK_ID(iHookID);
Expand Down
15 changes: 4 additions & 11 deletions extension/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@ int nothing;

IPluginFunction *GetFunctionByNameEx(IPluginContext *pContext, const char *name)

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.

Is this helper even used anywhere anymore ? if it isn't, feel free to delete it outright. Otherwise ignore this comment.

{
IPluginRuntime *pRuntime = pContext->GetRuntime();
for(uint32_t i = 0; i < pRuntime->GetPublicsNum(); i++)
if (!pContext || !name)
{
sp_public_t *pub = nullptr;
if(pRuntime->GetPublicByIndex(i, &pub) == SP_ERROR_NONE)
{
if(strstr(pub->name, name) != nullptr)
{
return pRuntime->GetFunctionById(pub->funcid);
}
}
return nullptr;
}
return nullptr;

return pContext->GetRuntime()->GetFunctionByName(name);
}

void MatrixToPawnMatrix(IPluginContext* context, cell_t* matAddr, const matrix3x4_t& mat)
Expand Down
1 change: 0 additions & 1 deletion extension/natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ void setup(std::vector<sp_nativeinfo_t>& natives) {
baseanimating::setup(natives);
baseanimatingoverlay::setup(natives);
basecombatcharacter::setup(natives);
basecombatcharacter::setup(natives);
baseentity::setup(natives);
cbasenpc::setup(natives);
entityfactory::setup(natives);
Expand Down
11 changes: 11 additions & 0 deletions extension/natives/bms/nav.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "nav.hpp"
#include "nav/area.hpp"

namespace natives::bms::nav {

void setup(std::vector<sp_nativeinfo_t>& natives)
{
area::setup(natives);
}

} // namespace natives::bms::nav
9 changes: 9 additions & 0 deletions extension/natives/bms/nav.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "natives.hpp"

namespace natives::bms::nav {

void setup(std::vector<sp_nativeinfo_t>& natives);

} // namespace natives::bms::nav
67 changes: 67 additions & 0 deletions extension/natives/bms/nav/area.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "area.hpp"

#include <cstdint>

#include "sourcesdk/bms_nav_area.h"

namespace natives::bms::nav::area {

inline CBlackMesaNavArea* Get(IPluginContext* context, const cell_t param)
{
auto* area = reinterpret_cast<CBlackMesaNavArea*>(PawnAddressToPtr(param));
if (!area)
{
context->ThrowNativeError("Black Mesa nav area pointer is null!");
return nullptr;
}

return area;
}

cell_t GetGameAttributes(IPluginContext* context, const cell_t* params)
{
auto* area = Get(context, params[1]);
return area ? static_cast<cell_t>(area->GetGameAttributes()) : 0;
}

cell_t SetGameAttribute(IPluginContext* context, const cell_t* params)
{
auto* area = Get(context, params[1]);
if (area)
{
area->SetGameAttribute(static_cast<std::uint32_t>(params[2]));
}

return 0;
}

cell_t ClearGameAttribute(IPluginContext* context, const cell_t* params)
{
auto* area = Get(context, params[1]);
if (area)
{
area->ClearGameAttribute(static_cast<std::uint32_t>(params[2]));
}

return 0;
}

cell_t HasGameAttribute(IPluginContext* context, const cell_t* params)
{
auto* area = Get(context, params[1]);
return area && area->HasGameAttribute(static_cast<std::uint32_t>(params[2]));
}

void setup(std::vector<sp_nativeinfo_t>& natives)
{
sp_nativeinfo_t list[] = {
{"CBlackMesaNavArea.GetGameAttributes", GetGameAttributes},
{"CBlackMesaNavArea.SetGameAttribute", SetGameAttribute},
{"CBlackMesaNavArea.ClearGameAttribute", ClearGameAttribute},
{"CBlackMesaNavArea.HasGameAttribute", HasGameAttribute},
};

natives.insert(natives.end(), std::begin(list), std::end(list));
}

} // namespace natives::bms::nav::area
9 changes: 9 additions & 0 deletions extension/natives/bms/nav/area.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "natives.hpp"

namespace natives::bms::nav::area {

void setup(std::vector<sp_nativeinfo_t>& natives);

} // namespace natives::bms::nav::area
2 changes: 1 addition & 1 deletion extension/natives/entityfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cell_t CPluginEntityFactory_Ctor(IPluginContext * context, const cell_t * params
return context->ThrowNativeError("Entity factory must have a classname");
}

IPlugin* plugin = plsys->FindPluginByContext( context->GetContext() );
IPlugin* plugin = plsys->FindPluginByContext(context);
IPluginFunction *postConstructor = context->GetFunctionById(params[2]);
IPluginFunction *onRemove = context->GetFunctionById(params[3]);

Expand Down
10 changes: 9 additions & 1 deletion extension/natives/nav.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "nav.hpp"
#include "nav/area.hpp"
#if SOURCE_ENGINE == SE_TF2
#include "tf/nav.hpp"
#elif SOURCE_ENGINE == SE_BMS
#include "bms/nav.hpp"
#endif

#include "sourcesdk/nav_mesh.h"
#include "toolsnav_mesh.h"
Expand Down Expand Up @@ -257,8 +261,12 @@ cell_t BuildPath(IPluginContext* context, const cell_t* params) {
void setup(std::vector<sp_nativeinfo_t>& natives) {
area::setup(natives);
collector::setup(natives);


#if SOURCE_ENGINE == SE_TF2
tf::nav::setup(natives);
#elif SOURCE_ENGINE == SE_BMS
bms::nav::setup(natives);
#endif

sp_nativeinfo_t list[] = {
{"CNavMesh.Address.get", GetAddress},
Expand Down
2 changes: 1 addition & 1 deletion extension/natives/nextbot/behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cell_t NextBotActionFactory_Ctor(IPluginContext* context, const cell_t* params)
return context->ThrowNativeError("Action must have a name");
}

IPlugin* plugin = plsys->FindPluginByContext(context->GetContext());
IPlugin* plugin = plsys->FindPluginByContext(context);
CBaseNPCPluginActionFactory* factory = new CBaseNPCPluginActionFactory(plugin, name);
return factory->m_Handle;
}
Expand Down
Loading