* Fix forwards accepting arguments of the wrong type CForward::ProcessArguments returns whether the arguments are valid, but its error paths return !!SetError(...), which is true for any error code. Mismatched arguments were therefore accepted and the forward ran anyway, while m_errstate stayed set and made the next Execute() on that forward fail with a stale error. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU * Add Call_PushInt64 and Param_Int64 Since Address became an int64, plugins can no longer pass one through a forward or Call_StartFunction: an int64 parameter is passed as a reference to its value, so Call_PushCell hands the callee an invalid reference and crashes the server, and Call_PushArray hands it the heap array instead of the value. Add Call_PushInt64, which pushes the value with CallArgs::PushInt64 the way DHooks does, and Param_Int64, so forwards can declare and check 64-bit integer parameters. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU * Move the Call_PushInt64 test to the mock testsuite Run it in CI with the other hl2sdk-mock tests, on x86 and x86_64, instead of as a manual test plugin. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU * Pass int64 arguments to legacy plugins as cells Plugins compiled before Address became an int64, or with oldspcomp, take an Address as a single cell and crash when handed an int64 argument. Like DHooks, check the callee's plugin for __Int64_Address__ and pass those plugins the low 32 bits instead, so a forward can have both kinds of listeners. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU * Document how legacy plugins receive Call_PushInt64 values Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU * Don't downgrade int64 arguments for legacy plugins The forward system shouldn't know about the Address convention. Code that declares a forward parameter as an Address can handle plugins that take it as a cell. This reverts commits 345b0dcb4 and 78b7bc14b. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU * Add Param_SMAddress and Call_PushAddress Plugins compiled before Address became an int64 take an Address as one cell. Arguments declared as Param_SMAddress in a forward, or pushed with Call_PushAddress to a function, are passed to those plugins as the low 32 bits, like DHooks does. Param_Int64 arguments are always passed as int64. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU * Refuse non-Address int64 arguments for plugins compiled before 1.13 Plugins compiled before SourceMod 1.13 have no int64 type, so an int64 argument can only reach them in a parameter they declared as a cell. Only an Address has a sane value there, its low 32 bits; any other int64 does not. Report an error naming the plugin and skip it instead of passing it a reference it reads as a cell. oldspcomp with the 1.13 includes also declares Address as an int64 and __Int64_Address__, so describe these plugins as compiled before 1.13. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BxFXSTjEk7Dub57XRmVfqU --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
151 lines
5.7 KiB
C++
151 lines
5.7 KiB
C++
// vim: set ts=4 sw=4 tw=99 noet :
|
|
// =============================================================================
|
|
// SourceMod
|
|
// Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
// =============================================================================
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify it under
|
|
// the terms of the GNU General Public License, version 3.0, as published by the
|
|
// Free Software Foundation.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
// details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// this program. If not, see <http://www.gnu.org/licenses/>.
|
|
//
|
|
// As a special exception, AlliedModders LLC gives you permission to link the
|
|
// code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
// "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
// by the Valve Corporation. You must obey the GNU General Public License in
|
|
// all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
// this exception to all derivative works. AlliedModders LLC defines further
|
|
// exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
// or <http://www.sourcemod.net/license.php>.
|
|
|
|
#ifndef _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|
|
#define _INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|
|
|
|
#include <IForwardSys.h>
|
|
#include <IPluginSys.h>
|
|
#include "common_logic.h"
|
|
#include "ISourceMod.h"
|
|
#include "ReentrantList.h"
|
|
|
|
typedef ReentrantList<IPluginFunction *>::iterator FuncIter;
|
|
|
|
/* :TODO: a global name max define for sourcepawn, should mirror compiler's sNAMEMAX */
|
|
#define FORWARDS_NAME_MAX 64
|
|
|
|
// The argument positions that hold an Address, one bit per position.
|
|
using AddressMask = uint32_t;
|
|
static_assert(SP_MAX_EXEC_PARAMS <= sizeof(AddressMask) * 8, "AddressMask must have a bit for every parameter");
|
|
|
|
// Invokes a plugin function, passing the given Address arguments as one cell to plugins compiled before SourceMod 1.13,
|
|
// and refusing to pass those plugins any other int64 argument.
|
|
bool InvokePluginFunction(IPluginFunction *func, const sp::CallArgs& args, AddressMask addresses, cell_t *result);
|
|
|
|
class CForward : public IChangeableForward
|
|
{
|
|
friend class CForwardManager;
|
|
public: //IForward
|
|
virtual int PushCell(cell_t cell);
|
|
virtual int PushCellByRef(cell_t *cell, int flags);
|
|
virtual int PushFloat(float number);
|
|
virtual int PushFloatByRef(float *number, int flags);
|
|
virtual int PushArray(cell_t *inarray, unsigned int cells, int flags);
|
|
virtual int PushString(const char *string);
|
|
virtual int PushStringEx(char *buffer, size_t length, int sz_flags, int cp_flags);
|
|
virtual int PushInt64(int64_t value);
|
|
virtual void Cancel();
|
|
virtual const char *GetForwardName();
|
|
virtual unsigned int GetFunctionCount();
|
|
virtual ExecType GetExecType();
|
|
virtual int Execute(cell_t *result, IForwardFilter *filter);
|
|
virtual int Execute(const sp::CallArgs& args, cell_t *result = nullptr, IForwardFilter *filter = nullptr);
|
|
public: //IChangeableForward
|
|
virtual bool RemoveFunction(IPluginFunction *func);
|
|
virtual unsigned int RemoveFunctionsOfPlugin(IPlugin *plugin);
|
|
virtual bool AddFunction(IPluginFunction *func);
|
|
virtual bool AddFunction(IPluginContext *ctx, funcid_t index);
|
|
virtual bool RemoveFunction(IPluginContext *ctx, funcid_t index);
|
|
public:
|
|
static CForward *CreateForward(const char *name,
|
|
ExecType et,
|
|
unsigned int num_params,
|
|
const ParamType *types,
|
|
va_list ap);
|
|
bool IsFunctionRegistered(IPluginFunction *func);
|
|
private:
|
|
CForward(ExecType et, const char *name,
|
|
const ParamType *types, unsigned num_params);
|
|
|
|
inline int SetError(int err)
|
|
{
|
|
m_errstate = err;
|
|
return err;
|
|
}
|
|
bool ProcessArguments(const sp::CallArgs& args);
|
|
|
|
protected:
|
|
mutable ReentrantList<IPluginFunction *> m_functions;
|
|
mutable ReentrantList<IPluginFunction *> m_paused;
|
|
|
|
/* Type and name information */
|
|
sp::CallArgs default_args_;
|
|
ParamType m_types[SP_MAX_EXEC_PARAMS];
|
|
AddressMask m_addresses;
|
|
char m_name[FORWARDS_NAME_MAX+1];
|
|
unsigned int m_numparams;
|
|
ExecType m_ExecType;
|
|
|
|
/* State information */
|
|
int m_errstate;
|
|
|
|
/* Reentrancy protection: tracks how many nested Execute() calls are in
|
|
* progress, and whether the forward was released while still executing
|
|
* (e.g. a plugin freeing its own private forward handle from within one
|
|
* of its own callbacks). Actual destruction is deferred until the
|
|
* outermost Execute() call returns. */
|
|
unsigned int m_ExecDepth;
|
|
bool m_deleted;
|
|
};
|
|
|
|
class CForwardManager :
|
|
public IForwardManager,
|
|
public IPluginsListener,
|
|
public SMGlobalClass
|
|
{
|
|
friend class CForward;
|
|
public: //IForwardManager
|
|
IForward *CreateForward(const char *name,
|
|
ExecType et,
|
|
unsigned int num_params,
|
|
const ParamType *types,
|
|
...);
|
|
IChangeableForward *CreateForwardEx(const char *name,
|
|
ExecType et,
|
|
int num_params,
|
|
const ParamType *types,
|
|
...);
|
|
IForward *FindForward(const char *name, IChangeableForward **ifchng);
|
|
void ReleaseForward(IForward *forward);
|
|
public: //IPluginsListener
|
|
void OnPluginLoaded(IPlugin *plugin);
|
|
void OnPluginUnloaded(IPlugin *plugin);
|
|
void OnPluginPauseChange(IPlugin *plugin, bool paused);
|
|
public: //SMGlobalClass
|
|
void OnSourceModAllInitialized();
|
|
private:
|
|
ReentrantList<CForward *> m_managed;
|
|
ReentrantList<CForward *> m_unmanaged;
|
|
|
|
typedef ReentrantList<CForward *>::iterator ForwardIter;
|
|
};
|
|
|
|
extern CForwardManager g_Forwards;
|
|
|
|
#endif //_INCLUDE_SOURCEMOD_FORWARDSYSTEM_H_
|