Skip to content
This repository was archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pisex committed Apr 4, 2024
1 parent 1657cba commit 6f439c5
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 95 deletions.
3 changes: 3 additions & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ for sdk_target in MMSPlugin.sdk_targets:
os.path.join('sdk', 'memaddr.cpp')
]

if binary.compiler.target.platform == 'linux':
binary.compiler.linkflags += ['-Wl,--version-script=' + os.path.join(builder.currentSourcePath, 'ExportMap')]

if cxx.target.arch == 'x86':
binary.sources += ['sourcehook/sourcehook_hookmangen.cpp']
nodes = builder.Add(binary)
Expand Down
4 changes: 4 additions & 0 deletions ExportMap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
global: CreateInterface;
local: *;
};
48 changes: 17 additions & 31 deletions admin_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
#include "admin_system.h"
#include "metamod_oslink.h"

#include "schemasystem/schemasystem.h"

AdminSystem g_AdminSystem;
PLUGIN_EXPOSE(AdminSystem, g_AdminSystem);

CGameEntitySystem* g_pGameEntitySystem = nullptr;
CSchemaSystem* g_pCSchemaSystem = nullptr;
CEntitySystem* g_pEntitySystem = nullptr;
IVEngineServer2* engine = nullptr;
CGlobalVars *gpGlobals = nullptr;
Expand Down Expand Up @@ -672,14 +673,13 @@ void MapMenuHandle(const char* szBack, const char* szFront, int iItem, int iSlot
}
else
{
char szBuffer[256], sCommand[128];
g_SMAPI->Format(sCommand, sizeof(sCommand), "changelevel %s", szMap);
char szBuffer[256];
g_SMAPI->Format(szBuffer, sizeof(szBuffer), g_AdminSystem.Translate("Changing map"), szFront);
ClientPrintAll( "%s", szBuffer);

new CTimer(5.0, [sCommand]()
new CTimer(5.0, [szMap]()
{
engine->ServerCommand(sCommand);
engine->ChangeLevel(szMap, nullptr);
return -1.0f;
});
}
Expand Down Expand Up @@ -774,8 +774,6 @@ void AdminSystem::AllPluginsLoaded()

for (KeyValues *pKey = kvPhrases->GetFirstTrueSubKey(); pKey; pKey = pKey->GetNextTrueSubKey())
g_vecPhrases[std::string(pKey->GetName())] = std::string(pKey->GetString(g_pszLanguage));

delete kvPhrases;
}

{
Expand All @@ -792,8 +790,6 @@ void AdminSystem::AllPluginsLoaded()
{
g_vecMaps[std::string(pValue->GetName())] = std::string(pValue->GetString(nullptr, nullptr));
}

delete kvMaps;
}


Expand Down Expand Up @@ -831,9 +827,6 @@ void AdminSystem::AllPluginsLoaded()
g_Times[std::stoi(pValue->GetName())] = std::string(pValue->GetString(nullptr, nullptr));
}
}

delete pKVRule;
delete g_kvSettings;
}

g_pUtils->StartupServer(g_PLID, StartupServer);
Expand Down Expand Up @@ -862,7 +855,6 @@ void AdminSystem::AllPluginsLoaded()
g_pAdminCore->RegAdminItem("ServerCommands", "map", g_vecPhrases[std::string("ChangeMap")].c_str(), ADMFLAG_CHANGEMAP, OnServerCommands);

KeyValues* pKVConfig = new KeyValues("Databases");

if (!pKVConfig->LoadFromFile(g_pFullFileSystem, "addons/configs/databases.cfg"))
{
V_strncpy(error, "Failed to load admin_system config 'addons/config/databases.cfg'", 64);
Expand Down Expand Up @@ -918,13 +910,13 @@ bool AdminSystem::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, b
PLUGIN_SAVEVARS();

GET_V_IFACE_CURRENT(GetEngineFactory, g_pCVar, ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetEngineFactory, g_pCSchemaSystem, CSchemaSystem, SCHEMASYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pSchemaSystem, ISchemaSystem, SCHEMASYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetFileSystemFactory, g_pFullFileSystem, IFileSystem, FILESYSTEM_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer2, SOURCE2ENGINETOSERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetServerFactory, g_pSource2Server, ISource2Server, SOURCE2SERVER_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2GameClients, IServerGameClients, SOURCE2GAMECLIENTS_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pNetworkServerService, INetworkServerService, NETWORKSERVERSERVICE_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pGameResourceServiceServer, IGameResourceServiceServer, GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
GET_V_IFACE_CURRENT(GetEngineFactory, g_pGameResourceServiceServer, IGameResourceService, GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_pSource2GameClients, IServerGameClients, SOURCE2GAMECLIENTS_INTERFACE_VERSION);

g_SMAPI->AddListener( this, this );

Expand Down Expand Up @@ -1000,10 +992,6 @@ void AdminSystem::Hook_GameFrame(bool simulating, bool bFirstTick, bool bLastTic
{
g_flUniversalTime += gpGlobals->curtime - g_flLastTickedTime;
}
else
{
g_flUniversalTime += gpGlobals->interval_per_tick;
}

g_flLastTickedTime = gpGlobals->curtime;
g_bHasTicked = true;
Expand Down Expand Up @@ -1659,15 +1647,15 @@ CON_COMMAND_CHAT_FLAGS(noclip, "noclip a player", ADMFLAG_CHEATS)
return;
}

if(pPlayer->m_MoveType() == MOVETYPE_NOCLIP)
if(pPlayer->m_nActualMoveType() == MOVETYPE_NOCLIP)
{
ClientPrintAll(g_AdminSystem.Translate("ANoclipDisable"), iSlot == -1?"Console":player->m_iszPlayerName());
pPlayer->m_MoveType() = MOVETYPE_WALK;
pPlayer->SetMoveType(MOVETYPE_WALK);
}
else
{
ClientPrintAll(g_AdminSystem.Translate("ANoclipEnable"), iSlot == -1?"Console":player->m_iszPlayerName());
pPlayer->m_MoveType() = MOVETYPE_NOCLIP;
pPlayer->SetMoveType(MOVETYPE_NOCLIP);
}
}
else
Expand Down Expand Up @@ -1699,14 +1687,14 @@ CON_COMMAND_CHAT_FLAGS(noclip, "noclip a player", ADMFLAG_CHEATS)
return;
}

if(pPlayer->m_MoveType() == MOVETYPE_NOCLIP)
if(pPlayer->m_nActualMoveType() == MOVETYPE_NOCLIP)
{
pPlayer->m_MoveType() = MOVETYPE_WALK;
pPlayer->SetMoveType(MOVETYPE_WALK);
ClientPrintAll(g_AdminSystem.Translate("NoclipDisable"), iSlot == -1?"Console":player->m_iszPlayerName(), pTarget->m_iszPlayerName());
}
else
{
pPlayer->m_MoveType() = MOVETYPE_NOCLIP;
pPlayer->SetMoveType(MOVETYPE_NOCLIP);
ClientPrintAll(g_AdminSystem.Translate("NoclipEnable"), iSlot == -1?"Console":player->m_iszPlayerName(), pTarget->m_iszPlayerName());
}
}
Expand Down Expand Up @@ -1872,7 +1860,7 @@ CON_COMMAND_CHAT_FLAGS(map, "change map", ADMFLAG_CHANGEMAP)
if (!engine->IsMapValid(szMapName))
{
char sCommand[128];
g_SMAPI->Format(sCommand, sizeof(sCommand), "host_workshop_map %s", args[1]);
g_SMAPI->Format(sCommand, sizeof(sCommand), "ds_workshop_changelevel %s", args[1]);
char szBuffer[256];
g_SMAPI->Format(szBuffer, sizeof(szBuffer), g_AdminSystem.Translate("Changing map workshop"), args[1]);
ClientPrint(iSlot, "%s", szBuffer);
Expand All @@ -1891,10 +1879,8 @@ CON_COMMAND_CHAT_FLAGS(map, "change map", ADMFLAG_CHANGEMAP)
ClientPrintAll( "%s", szBuffer);

new CTimer(5.0, [szMapName]()
{
char sCommand[128];
g_SMAPI->Format(sCommand, sizeof(sCommand), "changelevel %s", szMapName);
engine->ServerCommand(sCommand);
{
engine->ChangeLevel(szMapName, nullptr);
return -1.0f;
});
}
Expand Down
6 changes: 4 additions & 2 deletions hl2sdk-manifests/manifests/cs2.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
"public/tier1",
"public/entity2",
"public/game/server",
"game/server",
"game/shared",
"game/server",
"common"
],
"linux": {
"x86_64": {
"postlink_libs": [
"lib/linux64/mathlib.a",
"lib/linux64/tier1.a",
"lib/linux64/interfaces.a",
"lib/linux64/release/libprotobuf.a"
Expand All @@ -41,13 +42,14 @@
"defines": [
"_GLIBCXX_USE_CXX11_ABI=0"
],
"uses_system_cxxlib": true,
"uses_system_cxxlib": false,
"protoc_path": "devtools/bin/linux/protoc"
},
"windows": {
"x86_64": {
"libs": [
"lib/public/win64/2015/libprotobuf.lib",
"lib/public/win64/mathlib.lib",
"lib/public/win64/tier0.lib",
"lib/public/win64/tier1.lib",
"lib/public/win64/interfaces.lib"
Expand Down
7 changes: 7 additions & 0 deletions sdk/CBaseEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class SC_CBaseEntity : public CBaseEntity
SCHEMA_FIELD(int32_t, CBaseEntity, m_iHealth);
SCHEMA_FIELD(Vector, CBaseEntity, m_vecAbsVelocity);
SCHEMA_FIELD(MoveType_t, CBaseEntity, m_MoveType);
SCHEMA_FIELD(MoveType_t, CBaseEntity, m_nActualMoveType);

void SetMoveType(MoveType_t nMoveType)
{
m_MoveType() = nMoveType;
m_nActualMoveType() = nMoveType;
}

void SetAbsVelocity(Vector vecVelocity) { m_vecAbsVelocity() = vecVelocity; }

Expand Down
36 changes: 15 additions & 21 deletions sdk/schemasystem.cpp
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@

#include "schemasystem/schemasystem.h"
#include "schemasystem/schematypes.h"
#include "schemasystem.h"
#include "utils.hpp"
#include <cstring>

void CSchemaSystemTypeScope::FindDeclaredClass(SchemaClassInfoData_t*& pClassInfo, const char* pszClassName)
{
#if defined _WIN32 && _M_X64
CallVFunc<void, 2, SchemaClassInfoData_t*&, const char*>(this, pClassInfo, pszClassName);
#ifdef _WIN32
#define MODULE_PREFIX ""
#define MODULE_EXT ".dll"
#else
pClassInfo = CallVFunc<SchemaClassInfoData_t*, 2, const char*>(this, pszClassName);
#define MODULE_PREFIX "lib"
#define MODULE_EXT ".so"
#endif
}

CSchemaSystemTypeScope* CSchemaSystem::FindTypeScopeForModule(const char* szpModuleName)
namespace schema
{
return CallVFunc<CSchemaSystemTypeScope*, 13, const char*, void*>(this, szpModuleName, nullptr);
}

CSchemaSystemTypeScope* CSchemaSystem::GetServerTypeScope()
{
static CSchemaSystemTypeScope* pServerTypeScope = FindTypeScopeForModule(WIN_LINUX("server.dll", "libserver.so"));

return pServerTypeScope;
int32_t GetServerOffset(const char* pszClassName, const char* pszPropName);
}

int32_t CSchemaSystem::GetServerOffset(const char* pszClassName, const char* pszPropName)
int32_t schema::GetServerOffset(const char* pszClassName, const char* pszPropName)
{
SchemaClassInfoData_t* pClassInfo = nullptr;
GetServerTypeScope()->FindDeclaredClass(pClassInfo, pszClassName);
SchemaClassInfoData_t* pClassInfo = g_pSchemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT)->FindDeclaredClass(pszClassName).Get();
if (pClassInfo)
{
for (int i = 0; i < pClassInfo->m_iFieldsCount; i++)
for (int i = 0; i < pClassInfo->m_nFieldCount; i++)
{
auto& pFieldData = pClassInfo->m_pFieldsData[i];
auto& pFieldData = pClassInfo->m_pFields[i];

if (std::strcmp(pFieldData.m_pszName, pszPropName) == 0)
{
return pFieldData.m_iOffset;
return pFieldData.m_nSingleInheritanceOffset;
}
}
}
Expand Down
47 changes: 6 additions & 41 deletions sdk/schemasystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,22 @@
#pragma once
#endif

// #include "schemasystem/schemasystem.h"
// #include "schemasystem/schematypes.h"
#include <cstdint>
#include <type_traits>

struct SchemaClassFieldData_t
{
const char* m_pszName; // 0x0000
void* m_pSchemaType; // 0x0008
int32_t m_iOffset; // 0x0010
int32_t m_iMetaDataSize; // 0x0014
void* m_pMetaData; // 0x0018
};

struct SchemaClassInfoData_t
{
char pad_0x0000[0x8]; // 0x0000

const char* m_pszName; // 0x0008
const char* m_pszModule; // 0x0010

int m_iSize; // 0x0018
int16_t m_iFieldsCount; // 0x001C
#undef schema

int16_t m_iStaticSize; // 0x001E
int16_t m_iMetadataSize; // 0x0020
int16_t m_iUnk1; // 0x0022
int16_t m_iUnk2; // 0x0024
int16_t m_iUnk3; // 0x0026

SchemaClassFieldData_t* m_pFieldsData; // 0x0028
};

class CSchemaSystemTypeScope
namespace schema
{
public:
void FindDeclaredClass(SchemaClassInfoData_t*& pClassInfo, const char* pszClassName);
};

class CSchemaSystem
{
public:
CSchemaSystemTypeScope* FindTypeScopeForModule(const char* szpModuleName);
CSchemaSystemTypeScope* GetServerTypeScope();
int32_t GetServerOffset(const char* pszClassName, const char* pszPropName);
};

extern CSchemaSystem* g_pCSchemaSystem;
}

#define SCHEMA_FIELD(type, className, propName) \
std::add_lvalue_reference_t<type> propName() \
{ \
static const int32_t offset = g_pCSchemaSystem->GetServerOffset(#className, #propName); \
static const int32_t offset = schema::GetServerOffset(#className, #propName); \
if(offset == -1) \
std::runtime_error("Failed to find " #propName " in " #className); \
return *reinterpret_cast<std::add_pointer_t<type>>(reinterpret_cast<intptr_t>(this) + offset); \
Expand Down

0 comments on commit 6f439c5

Please sign in to comment.