Add int64 support to forwards (#2594)
* 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]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8ba0672cd9
commit
e7ac9b013d
@@ -48,7 +48,9 @@ enum ParamType
|
||||
Param_String = (3<<1)|SP_PARAMFLAG_BYREF, /**< Only strings can be pushed */
|
||||
Param_Array = (4<<1)|SP_PARAMFLAG_BYREF, /**< Only arrays can be pushed */
|
||||
Param_CellByRef = (1<<1)|SP_PARAMFLAG_BYREF, /**< Only a cell by reference can be pushed */
|
||||
Param_FloatByRef = (2<<1)|SP_PARAMFLAG_BYREF /**< Only a float by reference can be pushed */
|
||||
Param_FloatByRef = (2<<1)|SP_PARAMFLAG_BYREF, /**< Only a float by reference can be pushed */
|
||||
Param_Int64 = (5<<1), /**< Only 64-bit integers can be pushed */
|
||||
Param_SMAddress = (6<<1) /**< Only Addresses can be pushed */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -302,6 +304,31 @@ native void Call_StartFunction(Handle plugin, Function func);
|
||||
*/
|
||||
native void Call_PushCell(any value);
|
||||
|
||||
/**
|
||||
* Pushes a 64-bit integer onto the current call.
|
||||
*
|
||||
* @note Plugins compiled before SourceMod 1.13 cannot receive a 64-bit integer.
|
||||
* Calling one of them fails with an error. Use Call_PushAddress for an
|
||||
* Address.
|
||||
* @note Cannot be used before a call has been started.
|
||||
*
|
||||
* @param value 64-bit integer value to push.
|
||||
* @error Called before a call has been started.
|
||||
*/
|
||||
native void Call_PushInt64(int64 value);
|
||||
|
||||
/**
|
||||
* Pushes an Address onto the current call.
|
||||
*
|
||||
* @note Unlike Call_PushInt64, plugins compiled before SourceMod 1.13
|
||||
* receive the low 32 bits of the address.
|
||||
* @note Cannot be used before a call has been started.
|
||||
*
|
||||
* @param value Address to push.
|
||||
* @error Called before a call has been started.
|
||||
*/
|
||||
native void Call_PushAddress(Address value);
|
||||
|
||||
/**
|
||||
* Pushes a cell by reference onto the current call.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
|
||||
#include <sourcemod>
|
||||
#include <testing>
|
||||
|
||||
// Has both halves set, so a value truncated to one cell fails the check.
|
||||
int64 g_Value;
|
||||
int g_Calls;
|
||||
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
g_Value = (view_as<int64>(0x12345678) << 32) | view_as<int64>(0x0badf00d);
|
||||
|
||||
Test_PushInt64ToFunction();
|
||||
Test_PushInt64ToGlobalForward();
|
||||
Test_PushInt64ToAnyParam();
|
||||
Test_PushInt64ToCellParam();
|
||||
Test_PushAddressToFunction();
|
||||
Test_PushAddressToGlobalForward();
|
||||
}
|
||||
|
||||
|
||||
void Test_PushInt64ToFunction()
|
||||
{
|
||||
SetTestContext("Test Call_PushInt64 to a function");
|
||||
|
||||
g_Calls = 0;
|
||||
Call_StartFunction(INVALID_HANDLE, __OnInt64);
|
||||
Call_PushInt64(g_Value);
|
||||
Call_PushCell(2);
|
||||
AssertEq("Call_Finish", Call_Finish(), SP_ERROR_NONE);
|
||||
AssertEq("Calls", g_Calls, 1);
|
||||
}
|
||||
|
||||
|
||||
void Test_PushInt64ToGlobalForward()
|
||||
{
|
||||
SetTestContext("Test Call_PushInt64 to a Param_Int64 forward");
|
||||
|
||||
GlobalForward fwd = new GlobalForward("__OnInt64", ET_Ignore, Param_Int64, Param_Cell);
|
||||
|
||||
g_Calls = 0;
|
||||
Call_StartForward(fwd);
|
||||
Call_PushInt64(g_Value);
|
||||
Call_PushCell(2);
|
||||
AssertEq("Call_Finish", Call_Finish(), SP_ERROR_NONE);
|
||||
AssertEq("Calls", g_Calls, 1);
|
||||
|
||||
delete fwd;
|
||||
}
|
||||
|
||||
|
||||
void Test_PushInt64ToAnyParam()
|
||||
{
|
||||
SetTestContext("Test Call_PushInt64 to a Param_Any forward");
|
||||
|
||||
PrivateForward fwd = new PrivateForward(ET_Ignore, Param_Any, Param_Cell);
|
||||
fwd.AddFunction(INVALID_HANDLE, __OnInt64);
|
||||
|
||||
g_Calls = 0;
|
||||
Call_StartForward(fwd);
|
||||
Call_PushInt64(g_Value);
|
||||
Call_PushCell(2);
|
||||
AssertEq("Call_Finish", Call_Finish(), SP_ERROR_NONE);
|
||||
AssertEq("Calls", g_Calls, 1);
|
||||
|
||||
delete fwd;
|
||||
}
|
||||
|
||||
|
||||
void Test_PushInt64ToCellParam()
|
||||
{
|
||||
SetTestContext("Test Call_PushInt64 to a Param_Cell forward");
|
||||
|
||||
PrivateForward fwd = new PrivateForward(ET_Ignore, Param_Cell, Param_Cell);
|
||||
fwd.AddFunction(INVALID_HANDLE, __OnInt64);
|
||||
|
||||
g_Calls = 0;
|
||||
Call_StartForward(fwd);
|
||||
Call_PushInt64(g_Value);
|
||||
Call_PushCell(2);
|
||||
AssertEq("Call_Finish", Call_Finish(), SP_ERROR_PARAM);
|
||||
AssertEq("Calls", g_Calls, 0);
|
||||
|
||||
delete fwd;
|
||||
}
|
||||
|
||||
|
||||
void Test_PushAddressToFunction()
|
||||
{
|
||||
SetTestContext("Test Call_PushAddress to a function");
|
||||
|
||||
g_Calls = 0;
|
||||
Call_StartFunction(INVALID_HANDLE, __OnAddress);
|
||||
Call_PushAddress(view_as<Address>(g_Value));
|
||||
Call_PushCell(2);
|
||||
AssertEq("Call_Finish", Call_Finish(), SP_ERROR_NONE);
|
||||
AssertEq("Calls", g_Calls, 1);
|
||||
}
|
||||
|
||||
|
||||
void Test_PushAddressToGlobalForward()
|
||||
{
|
||||
SetTestContext("Test Call_PushAddress to a Param_SMAddress forward");
|
||||
|
||||
GlobalForward fwd = new GlobalForward("__OnAddress", ET_Ignore, Param_SMAddress, Param_Cell);
|
||||
|
||||
g_Calls = 0;
|
||||
Call_StartForward(fwd);
|
||||
Call_PushAddress(view_as<Address>(g_Value));
|
||||
Call_PushCell(2);
|
||||
AssertEq("Call_Finish", Call_Finish(), SP_ERROR_NONE);
|
||||
AssertEq("Calls", g_Calls, 1);
|
||||
|
||||
delete fwd;
|
||||
}
|
||||
|
||||
public void __OnInt64(int64 value, int marker)
|
||||
{
|
||||
g_Calls++;
|
||||
AssertInt64Eq("__OnInt64 param value", value, g_Value);
|
||||
AssertEq("__OnInt64 param marker", marker, 2);
|
||||
}
|
||||
|
||||
|
||||
public void __OnAddress(Address value, int marker)
|
||||
{
|
||||
g_Calls++;
|
||||
AssertInt64Eq("__OnAddress param value", view_as<int64>(value), g_Value);
|
||||
AssertEq("__OnAddress param marker", marker, 2);
|
||||
}
|
||||
Reference in New Issue
Block a user