Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Late spring-clean #39

Merged
merged 5 commits into from
Jun 5, 2023
Merged
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
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ jobs:
build:
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-latest, windows-2019]
os: [ubuntu-20.04, ubuntu-latest, windows-2019, windows-latest]
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
release: true
cc: clang-8
cxx: clang++-8
- os: ubuntu-latest
release: false
cc: clang
cxx: clang++
- os: windows-2019
release: true
cc: msvc
- os: windows-latest
release: false
cc: msvc
fail-fast: false

Expand Down Expand Up @@ -121,7 +127,7 @@ jobs:
ambuild

- name: Upload artifact
if: github.event_name == 'push' && (startsWith(matrix.os, 'ubuntu-18.04') || startsWith(matrix.os, 'windows-2019'))
if: github.event_name == 'push' && matrix.release
uses: actions/upload-artifact@v1
with:
name: cbasenpc_${{ runner.os }}
Expand Down
13 changes: 3 additions & 10 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ class ExtensionConfig(object):
if builder.options.sm_path:
self.sm_root = builder.options.sm_path
else:
self.sm_root = ResolveEnvPath('SOURCEMOD18', 'sourcemod-1.8')
if not self.sm_root:
self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod')
if not self.sm_root:
self.sm_root = ResolveEnvPath('SOURCEMOD_DEV', 'sourcemod-central')
self.sm_root = ResolveEnvPath('SOURCEMOD', 'sourcemod')

if not self.sm_root or not os.path.isdir(self.sm_root):
raise Exception('Could not find a source copy of SourceMod')
Expand All @@ -182,11 +178,7 @@ class ExtensionConfig(object):
if builder.options.mms_path:
self.mms_root = builder.options.mms_path
else:
self.mms_root = ResolveEnvPath('MMSOURCE110', 'mmsource-1.10')
if not self.mms_root:
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
if not self.mms_root:
self.mms_root = ResolveEnvPath('MMSOURCE_DEV', 'mmsource-central')
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')

if not self.mms_root or not os.path.isdir(self.mms_root):
raise Exception('Could not find a source copy of Metamod:Source')
Expand Down Expand Up @@ -256,6 +248,7 @@ class ExtensionConfig(object):
cxx.cflags += [
'-pipe',
'-fno-strict-aliasing',
#'-Werror',
'-Wall',
'-Wno-unused',
'-Wno-switch',
Expand Down
2 changes: 1 addition & 1 deletion extension/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ project.sources = [
'sourcesdk/basedoor.cpp',
'sourcesdk/basetoggle.cpp',
'sourcesdk/funcbrush.cpp',
os.path.join(Extension.sm_root, 'public', 'smsdk_ext.cpp')
'smsdk_ext.cpp'
]

for sdk_name in Extension.sdks:
Expand Down
3 changes: 3 additions & 0 deletions extension/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ IServerTools* servertools = nullptr;
IMDLCache* mdlcache = nullptr;
CSharedEdictChangeInfo* g_pSharedChangeInfo = nullptr;
IStaticPropMgrServer* staticpropmgr = nullptr;
ConVar* sourcemod_version = nullptr;
IBaseNPC_Tools* g_pBaseNPCTools = new BaseNPC_Tools_API;

DEFINEHANDLEOBJ(SurroundingAreasCollector, CUtlVector< CNavArea* >);
Expand Down Expand Up @@ -119,6 +120,8 @@ bool CBaseNPCExt::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, b

ConVar_Register(0, this);

sourcemod_version = g_pCVar->FindVar("sourcemod_version");

g_cvDeveloper = g_pCVar->FindVar("developer");

NextBotSpeedLookAheadRange = g_pCVar->FindVar("nb_speed_look_ahead_range");
Expand Down
29 changes: 0 additions & 29 deletions extension/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void VectorToPawnVector(cell_t* angAddr, const QAngle* angle)
angAddr[2] = sp_ftoc(angle->z);
}

#if SOURCEPAWN_API_VERSION >= 0x0211
void MatrixToPawnMatrix(IPluginContext* context, cell_t* matAddr, const matrix3x4_t& mat)
{
for ( int r = 0; r < 3; r++ )
Expand Down Expand Up @@ -120,34 +119,6 @@ void PawnMatrixToMatrix(IPluginContext* context, cell_t* matAddr, matrix3x4_t& m
}
}
}
#else
// https://github.com/alliedmodders/sourcemod/blob/b3672916dee4bc6ad4368e31bc6f9b2779b36d79/core/logic/smn_sorting.cpp#L43
void MatrixToPawnMatrix(IPluginContext* context, cell_t* matAddr, const matrix3x4_t& mat)
{
for ( int r = 0; r < 3; r++ )
{
cell_t* row = (cell_t *)( (uint8_t *)( &matAddr[r] ) + matAddr[r] );

for ( int c = 0; c < 4; c++ )
{
row[c] = sp_ftoc( mat[r][c] );
}
}
}

void PawnMatrixToMatrix(IPluginContext* context, cell_t* matAddr, matrix3x4_t& mat)
{
for ( int r = 0; r < 3; r++ )
{
cell_t* row = (cell_t *)( (uint8_t *)( &matAddr[r] ) + matAddr[r] );

for ( int c = 0; c < 4; c++ )
{
mat[r][c] = sp_ctof( row[c] );
}
}
}
#endif

const char *HandleErrorToString(HandleError err)
{
Expand Down
77 changes: 63 additions & 14 deletions extension/idatamapcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <sm_namehashset.h>
#include <sh_stack.h>

extern ConVar* sourcemod_version;

IDataMapContainer::IDataMapContainer()
{
m_pDataMap = nullptr;
Expand Down Expand Up @@ -796,9 +798,30 @@ void IEntityDataMapContainer::DestroyDataDesc()
}

// https://github.com/alliedmodders/sourcemod/blob/38eecd5ece26b2469560db1822511a7e2685286e/core/HalfLife2.h#L263
struct CHalfLife2Hack
struct CHalfLife2
{
struct DataMapCachePolicy
struct DataMapCacheInfo12
{
static inline bool matches(const char *name, const DataMapCacheInfo12 &info)
{
return strcmp(name, info.name.c_str()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}

DataMapCacheInfo12()
: name(), info{nullptr, 0}
{
}

std::string name;
sm_datatable_info_t info;
};
typedef NameHashSet<DataMapCacheInfo12> DataMapCache12;

struct DataMapCachePolicy11
{
static inline bool matches(const char *name, const sm_datatable_info_t &info)
{
Expand All @@ -809,35 +832,61 @@ struct CHalfLife2Hack
return key.hash();
}
};
typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy11> DataMapCache11;

typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy> DataMapCache;
typedef ke::HashMap<datamap_t *, DataMapCache *, ke::PointerPolicy<datamap_t> > DataTableMap;
typedef ke::HashMap<datamap_t *, void *, ke::PointerPolicy<datamap_t> > DataTableMap;
typedef ke::HashMap<datamap_t *, DataMapCache11 *, ke::PointerPolicy<datamap_t> > DataTableMap11;
typedef ke::HashMap<datamap_t *, DataMapCache12 *, ke::PointerPolicy<datamap_t> > DataTableMap12;

void** vptr;
NameHashSet<void *> m_Classes;
DataTableMap m_Maps;
int m_MsgTextMsg;
int m_HinTextMsg;
int m_SayTextMsg;
int m_VGUIMenu;
};

void IEntityDataMapContainer::DestroyDataDescMap()
{
if (!m_pDataMap)
{
return;
}

// HACK: Force gamehelpers (CHalfLife2 *) to delete the cache of our datamap if it exists.
CHalfLife2Hack* pHL2 = reinterpret_cast<CHalfLife2Hack*>(gamehelpers);
auto result = pHL2->m_Maps.find( m_pDataMap );
if (result.found())
CHalfLife2* pHL2 = reinterpret_cast<CHalfLife2*>(gamehelpers);

const char* value = sourcemod_version->GetString();
if (strncmp("1.12.0.", value, 7) == 0)
{
CHalfLife2Hack::DataMapCache* cache = result->value;
if (cache) delete cache;
int rev = std::atoi(&value[7]);
if (rev >= 6998)
{
auto maps12 = (CHalfLife2::DataTableMap12*)(&(pHL2->m_Maps));
auto result = maps12->find( m_pDataMap );
if (result.found())
{
auto cache = result->value;
if (cache)
{
delete cache;
}

pHL2->m_Maps.remove( result );
maps12->remove( result );
}
IDataMapContainer::DestroyDataDescMap();
return;
}
}

auto maps11 = (CHalfLife2::DataTableMap11*)(&(pHL2->m_Maps));
auto result = maps11->find( m_pDataMap );
if (result.found())
{
auto cache = result->value;
if (cache)
{
delete cache;
}
maps11->remove( result );
}
IDataMapContainer::DestroyDataDescMap();
}

Expand Down
Loading