Skip to content

Commit 462ca52

Browse files
authored
chore(deps): upgrade metamod & hl2sdk (#856)
1 parent d7e23e8 commit 462ca52

File tree

10 files changed

+69
-81
lines changed

10 files changed

+69
-81
lines changed

libraries/hl2sdk-cs2

Submodule hl2sdk-cs2 updated 54 files

libraries/metamod-source

Submodule metamod-source updated 72 files

src/core/gameconfig.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <fstream>
44

55
#include "log.h"
6-
#include "metamod_oslink.h"
76

87
namespace counterstrikesharp {
98

src/core/globals.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#pragma once
22

3-
#define protected public
4-
#define private public
53
#include <tier1/convar.h>
6-
#undef protected
7-
#undef private
84

95
#include <sourcehook/sourcehook.h>
106

src/core/managers/con_command_manager.cpp

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ CON_COMMAND(dump_schema, "dump schema symbols")
179179
output << std::setw(2) << j << std::endl;
180180
}
181181

182-
SH_DECL_HOOK3_void(ICvar, DispatchConCommand, SH_NOATTRIB, 0, ConCommandHandle, const CCommandContext&, const CCommand&);
182+
SH_DECL_HOOK3_void(ICvar, DispatchConCommand, SH_NOATTRIB, 0, ConCommandRef, const CCommandContext&, const CCommand&);
183183

184184
ConCommandInfo::ConCommandInfo()
185185
{
@@ -222,45 +222,31 @@ void UnlockConVars()
222222
{
223223
int unhiddenConVars = 0;
224224

225-
ConVar* currentCvar = nullptr;
226-
ConVarHandle currentCvarHandle;
227-
currentCvarHandle.Set(0);
228-
229-
do
225+
for (ConVarRefAbstract ref(ConVarRef((uint16)0)); ref.IsValidRef(); ref = ConVarRefAbstract(ConVarRef(ref.GetAccessIndex() + 1)))
230226
{
231-
currentCvar = globals::cvars->GetConVar(currentCvarHandle);
232-
233-
currentCvarHandle.Set(currentCvarHandle.Get() + 1);
234-
235-
if (!currentCvar) continue;
236-
237-
if (!(currentCvar->flags & flagsToRemove)) continue;
227+
if (!ref.IsFlagSet(flagsToRemove)) continue;
238228

239-
currentCvar->flags &= ~flagsToRemove;
229+
ref.RemoveFlags(flagsToRemove);
240230
unhiddenConVars++;
241-
} while (currentCvar);
231+
}
242232
}
243233

244234
void UnlockConCommands()
245235
{
246236
int unhiddenConCommands = 0;
247237

248-
ConCommand* currentConCommand = nullptr;
249-
ConCommand* invalidConCommand = globals::cvars->GetCommand(ConCommandHandle());
250-
ConCommandHandle conCommandHandle;
251-
conCommandHandle.Set(0);
238+
ConCommandData* currentConCommand = nullptr;
239+
ConCommandData* invalidConCommand = globals::cvars->GetConCommandData(ConCommandRef());
240+
ConCommandRef ref = ConCommandRef((uint16)0);
252241

253-
do
242+
ConCommandData* data = g_pCVar->GetConCommandData(ConCommandRef());
243+
for (ConCommandRef ref = ConCommandRef((uint16)0); ref.GetRawData() != data; ref = ConCommandRef(ref.GetAccessIndex() + 1))
254244
{
255-
currentConCommand = globals::cvars->GetCommand(conCommandHandle);
256-
257-
conCommandHandle.Set(conCommandHandle.Get() + 1);
245+
if (!ref.IsFlagSet(flagsToRemove)) continue;
258246

259-
if (!currentConCommand || currentConCommand == invalidConCommand || !(currentConCommand->GetFlags() & flagsToRemove)) continue;
260-
261-
currentConCommand->RemoveFlags(flagsToRemove);
247+
ref.RemoveFlags(flagsToRemove);
262248
unhiddenConCommands++;
263-
} while (currentConCommand && currentConCommand != invalidConCommand);
249+
}
264250
}
265251

266252
void ConCommandManager::OnShutdown()
@@ -301,10 +287,10 @@ void ConCommandManager::AddCommandListener(const char* name, CallbackT callback,
301287
pInfo = new ConCommandInfo();
302288
m_cmd_lookup[strName] = pInfo;
303289

304-
ConCommandHandle hExistingCommand = globals::cvars->FindCommand(name);
305-
if (hExistingCommand.IsValid())
290+
ConCommandRef hExistingCommand = globals::cvars->FindConCommand(name);
291+
if (hExistingCommand.IsValidRef())
306292
{
307-
pInfo->command = globals::cvars->GetCommand(hExistingCommand);
293+
pInfo->command = globals::cvars->GetConCommandData(hExistingCommand);
308294
}
309295
}
310296

@@ -353,11 +339,10 @@ void ConCommandManager::RemoveCommandListener(const char* name, CallbackT callba
353339

354340
bool ConCommandManager::AddValveCommand(const char* name, const char* description, bool server_only, int flags)
355341
{
356-
ConCommandHandle hExistingCommand = globals::cvars->FindCommand(name);
357-
if (hExistingCommand.IsValid()) return false;
342+
ConCommandRef hExistingCommand = globals::cvars->FindConCommand(name);
343+
if (hExistingCommand.IsValidRef()) return false;
358344

359-
ConCommandRefAbstract conCommandRefAbstract;
360-
auto conCommand = new ConCommand(&conCommandRefAbstract, strdup(name), CommandCallback, description ? strdup(description) : "", flags);
345+
auto conCommand = new ConCommand(strdup(name), CommandCallback, description ? strdup(description) : "", flags);
361346

362347
ConCommandInfo* pInfo = m_cmd_lookup[std::string(name)];
363348

@@ -367,23 +352,22 @@ bool ConCommandManager::AddValveCommand(const char* name, const char* descriptio
367352
m_cmd_lookup[std::string(name)] = pInfo;
368353
}
369354

370-
pInfo->p_cmd = conCommandRefAbstract;
371-
pInfo->command = conCommand;
355+
pInfo->command = conCommand->GetRawData();
372356
pInfo->server_only = server_only;
373357

374358
return true;
375359
}
376360

377361
bool ConCommandManager::RemoveValveCommand(const char* name)
378362
{
379-
auto hFoundCommand = globals::cvars->FindCommand(name);
363+
auto hFoundCommand = globals::cvars->FindConCommand(name);
380364

381-
if (!hFoundCommand.IsValid())
365+
if (!hFoundCommand.IsValidRef())
382366
{
383367
return false;
384368
}
385369

386-
globals::cvars->UnregisterConCommand(hFoundCommand);
370+
globals::cvars->UnregisterConCommandCallbacks(hFoundCommand);
387371

388372
auto pInfo = m_cmd_lookup[std::string(name)];
389373
if (!pInfo)
@@ -474,7 +458,7 @@ HookResult ConCommandManager::ExecuteCommandCallbacks(
474458
return result;
475459
}
476460

477-
void ConCommandManager::Hook_DispatchConCommand(ConCommandHandle cmd, const CCommandContext& ctx, const CCommand& args)
461+
void ConCommandManager::Hook_DispatchConCommand(ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args)
478462
{
479463
const char* name = args.Arg(0);
480464

@@ -486,7 +470,7 @@ void ConCommandManager::Hook_DispatchConCommand(ConCommandHandle cmd, const CCom
486470
RETURN_META(MRES_SUPERCEDE);
487471
}
488472
}
489-
void ConCommandManager::Hook_DispatchConCommand_Post(ConCommandHandle cmd, const CCommandContext& ctx, const CCommand& args)
473+
void ConCommandManager::Hook_DispatchConCommand_Post(ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args)
490474
{
491475
const char* name = args.Arg(0);
492476

@@ -498,8 +482,8 @@ void ConCommandManager::Hook_DispatchConCommand_Post(ConCommandHandle cmd, const
498482
}
499483
bool ConCommandManager::IsValidValveCommand(const char* name)
500484
{
501-
ConCommandHandle pCmd = globals::cvars->FindCommand(name);
502-
return pCmd.IsValid();
485+
ConCommandRef pCmd = globals::cvars->FindConCommand(name);
486+
return pCmd.IsValidRef();
503487
}
504488

505489
CommandCallingContext ConCommandManager::GetCommandCallingContext(CCommand* args) { return m_cmd_contexts[args]; }

src/core/managers/con_command_manager.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class ConCommandInfo
7878
ScriptCallback* GetCallback() { return callback_pre; }
7979

8080
private:
81-
ConCommandRefAbstract p_cmd;
82-
ConCommand* command;
81+
ConCommandData* command;
8382
ScriptCallback* callback_pre;
8483
ScriptCallback* callback_post;
8584
bool server_only;
@@ -100,8 +99,8 @@ class ConCommandManager : public GlobalClass
10099
bool IsValidValveCommand(const char* name);
101100
bool AddValveCommand(const char* name, const char* description, bool server_only, int flags);
102101
bool RemoveValveCommand(const char* name);
103-
void Hook_DispatchConCommand(ConCommandHandle cmd, const CCommandContext& ctx, const CCommand& args);
104-
void Hook_DispatchConCommand_Post(ConCommandHandle cmd, const CCommandContext& ctx, const CCommand& args);
102+
void Hook_DispatchConCommand(ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args);
103+
void Hook_DispatchConCommand_Post(ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args);
105104
HookResult ExecuteCommandCallbacks(
106105
const char* name, const CCommandContext& ctx, const CCommand& args, HookMode mode, CommandCallingContext callingContext);
107106

src/core/memory_module.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
#include "interface.h"
3434
#include "strtools.h"
35-
#include "metamod_oslink.h"
3635
#undef snprintf
3736

3837
namespace counterstrikesharp::modules {

src/mm_plugin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class GameSessionConfiguration_t
6666
{
6767
};
6868

69+
PLUGIN_EXPOSE(CounterStrikeSharpMMPlugin, counterstrikesharp::gPlugin);
70+
6971
namespace counterstrikesharp {
7072

7173
SH_DECL_HOOK3_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool, bool, bool);
@@ -81,7 +83,6 @@ CounterStrikeSharpMMPlugin gPlugin;
8183
ConVar sample_cvar("sample_cvar", "42", 0);
8284
#endif
8385

84-
PLUGIN_EXPOSE(CounterStrikeSharpMMPlugin, gPlugin);
8586
bool CounterStrikeSharpMMPlugin::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool late)
8687
{
8788
PLUGIN_SAVEVARS();

src/mm_plugin.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ static ScriptCallback* on_activate_callback;
7474
static ScriptCallback* on_metamod_all_plugins_loaded_callback;
7575
extern CounterStrikeSharpMMPlugin gPlugin;
7676

77-
PLUGIN_GLOBALVARS();
7877

7978
#endif //_INCLUDE_METAMOD_SOURCE_STUB_PLUGIN_H_
8079
}
80+
81+
PLUGIN_GLOBALVARS();
82+

src/scripting/natives/natives_commands.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
#include <eiface.h>
1818
#include <networksystem/inetworkmessages.h>
1919

20-
#include "scripting/autonative.h"
21-
#include "scripting/callback_manager.h"
20+
#include "core/log.h"
2221
#include "core/managers/con_command_manager.h"
2322
#include "core/managers/player_manager.h"
2423
#include "core/recipientfilters.h"
2524
#include "igameeventsystem.h"
25+
#include "scripting/autonative.h"
26+
#include "scripting/callback_manager.h"
2627
#include "scripting/script_engine.h"
27-
#include "core/log.h"
2828
#include <networkbasetypes.pb.h>
2929

3030
namespace counterstrikesharp {
@@ -37,8 +37,7 @@ static void AddCommand(ScriptContext& script_context)
3737
auto flags = script_context.GetArgument<int>(3);
3838
auto callback = script_context.GetArgument<CallbackT>(4);
3939

40-
CSSHARP_CORE_TRACE("Adding command {}, {}, {}, {}, {}", name, description, server_only, flags,
41-
(void*)callback);
40+
CSSHARP_CORE_TRACE("Adding command {}, {}, {}, {}, {}", name, description, server_only, flags, (void*)callback);
4241

4342
globals::conCommandManager.AddValveCommand(name, description, server_only, flags);
4443
globals::conCommandManager.AddCommandListener(name, callback, HookMode::Pre);
@@ -59,8 +58,7 @@ static void AddCommandListener(ScriptContext& script_context)
5958
auto callback = script_context.GetArgument<CallbackT>(1);
6059
auto post = script_context.GetArgument<bool>(2);
6160

62-
globals::conCommandManager.AddCommandListener(name, callback,
63-
post ? HookMode::Post : HookMode::Pre);
61+
globals::conCommandManager.AddCommandListener(name, callback, post ? HookMode::Post : HookMode::Pre);
6462
}
6563

6664
static void RemoveCommandListener(ScriptContext& script_context)
@@ -69,15 +67,15 @@ static void RemoveCommandListener(ScriptContext& script_context)
6967
auto callback = script_context.GetArgument<CallbackT>(1);
7068
auto post = script_context.GetArgument<bool>(2);
7169

72-
globals::conCommandManager.RemoveCommandListener(name, callback,
73-
post ? HookMode::Post : HookMode::Pre);
70+
globals::conCommandManager.RemoveCommandListener(name, callback, post ? HookMode::Post : HookMode::Pre);
7471
}
7572

7673
static int CommandGetArgCount(ScriptContext& script_context)
7774
{
7875
auto command = script_context.GetArgument<CCommand*>(0);
7976

80-
if (!command) {
77+
if (!command)
78+
{
8179
script_context.ThrowNativeError("Invalid command.");
8280
return -1;
8381
}
@@ -89,7 +87,8 @@ static const char* CommandGetArgString(ScriptContext& script_context)
8987
{
9088
auto command = script_context.GetArgument<CCommand*>(0);
9189

92-
if (!command) {
90+
if (!command)
91+
{
9392
script_context.ThrowNativeError("Invalid command.");
9493
return nullptr;
9594
}
@@ -101,7 +100,8 @@ static const char* CommandGetCommandString(ScriptContext& script_context)
101100
{
102101
auto* command = script_context.GetArgument<CCommand*>(0);
103102

104-
if (!command) {
103+
if (!command)
104+
{
105105
script_context.ThrowNativeError("Invalid command.");
106106
return nullptr;
107107
}
@@ -114,7 +114,8 @@ static const char* CommandGetArgByIndex(ScriptContext& script_context)
114114
auto* command = script_context.GetArgument<CCommand*>(0);
115115
auto index = script_context.GetArgument<int>(1);
116116

117-
if (!command) {
117+
if (!command)
118+
{
118119
script_context.ThrowNativeError("Invalid command.");
119120
return nullptr;
120121
}
@@ -145,9 +146,8 @@ static void IssueClientCommandFromServer(ScriptContext& script_context)
145146
CCommand args;
146147
args.Tokenize(pszCommand);
147148

148-
auto handle = globals::cvars->FindCommand(args.Arg(0));
149-
if (!handle.IsValid())
150-
return;
149+
auto handle = globals::cvars->FindConCommand(args.Arg(0));
150+
if (!handle.IsValidRef()) return;
151151

152152
CCommandContext context(CommandTarget_t::CT_NO_TARGET, CPlayerSlot(slot));
153153

@@ -171,28 +171,37 @@ static void SetFakeClientConVarValue(ScriptContext& script_context)
171171
globals::engine->SetFakeClientConVarValue(CPlayerSlot(playerSlot), convarName, convarValue);
172172
}
173173

174-
ConVar* FindConVar(ScriptContext& script_context)
174+
ConVarData* FindConVar(ScriptContext& script_context)
175175
{
176176
auto name = script_context.GetArgument<const char*>(0);
177177
auto hCvarHandle = globals::cvars->FindConVar(name, true);
178178

179-
if (!hCvarHandle.IsValid()) {
179+
if (!hCvarHandle.IsValidRef())
180+
{
180181
return nullptr;
181182
}
182183

183-
return globals::cvars->GetConVar(hCvarHandle);
184+
return globals::cvars->GetConVarData(hCvarHandle);
184185
}
185186

186187
void SetConVarStringValue(ScriptContext& script_context)
187188
{
188-
auto pCvar = script_context.GetArgument<ConVar*>(0);
189+
auto pCvar = script_context.GetArgument<ConVarData*>(0);
189190
auto value = script_context.GetArgument<const char*>(1);
190191

191-
if (!pCvar) {
192+
if (!pCvar)
193+
{
194+
script_context.ThrowNativeError("Invalid cvar.");
195+
}
196+
197+
ConVarRefAbstract cvarRef(pCvar->GetName());
198+
199+
if (!cvarRef.IsValidRef() || !cvarRef.IsConVarDataAvailable())
200+
{
192201
script_context.ThrowNativeError("Invalid cvar.");
193202
}
194203

195-
pCvar->values = reinterpret_cast<CVValue_t**>((char*)value);
204+
cvarRef.SetString(value);
196205
}
197206

198207
void ReplicateConVar(ScriptContext& script_context)
@@ -230,8 +239,7 @@ REGISTER_NATIVES(commands, {
230239
ScriptEngine::RegisterNativeHandler("SET_CONVAR_STRING_VALUE", SetConVarStringValue);
231240

232241
ScriptEngine::RegisterNativeHandler("ISSUE_CLIENT_COMMAND", IssueClientCommand);
233-
ScriptEngine::RegisterNativeHandler("ISSUE_CLIENT_COMMAND_FROM_SERVER",
234-
IssueClientCommandFromServer);
242+
ScriptEngine::RegisterNativeHandler("ISSUE_CLIENT_COMMAND_FROM_SERVER", IssueClientCommandFromServer);
235243
ScriptEngine::RegisterNativeHandler("GET_CLIENT_CONVAR_VALUE", GetClientConVarValue);
236244
ScriptEngine::RegisterNativeHandler("SET_FAKE_CLIENT_CONVAR_VALUE", SetFakeClientConVarValue);
237245
ScriptEngine::RegisterNativeHandler("REPLICATE_CONVAR", ReplicateConVar);

0 commit comments

Comments
 (0)