CounterStrikeSharp
CounterStrikeSharp copied to clipboard
`hook.SetParam<string>(...)` won't change hook's parameter
Consider the sample code below. I expect an AUG to be given instead of an AK-47 whenever an AK-47 is given to the player, however the game still gives the player an AK-47 instead. I wasn't able to find a usage of SetParam passing string, so I'm not sure if this is an existing issue.
public override void Load(bool hotReload)
{
VirtualFunctions.GiveNamedItemFunc.Hook(hook =>
{
var itemServices = hook.GetParam<CCSPlayer_ItemServices>(0);
var className = hook.GetParam<string>(1);
var pawn = itemServices.Pawn.Value;
if (pawn.IsValid && pawn.Controller.IsValid && pawn.Controller.Value != null)
{
var player = new CCSPlayerController(pawn.Controller.Value.Handle);
if (className == "weapon_ak47")
{
hook.SetParam<string>(1, "weapon_aug");
return HookResult.Changed;
}
}
return HookResult.Continue;
}, HookMode.Pre);
}
Note I'm using HookMode.Pre there.
DynamicHooks currently have a problem with strings in general, thats why hooking print related functions turns into garbage in the end, even if you change nothing related to any string
DynamicHookscurrently have a problem with strings in general, thats why hooking print related functions turns into garbage in the end, even if you change nothing related to any string
Just to be clear, is this an issue within DynamicHooks API (C# and/or C++) or DynoHook? I'm trying to understand the current implementation, and so far I don't see where it could be failing.
DynamicHookscurrently have a problem with strings in general, thats why hooking print related functions turns into garbage in the end, even if you change nothing related to any stringJust to be clear, is this an issue within DynamicHooks API (C# and/or C++) or DynoHook? I'm trying to understand the current implementation, and so far I don't see where it could be failing.
DynoHook should be fine, if I'd have to guess its somewhere where the type is set maybe?
I don't really see anything wrong here in general, not sure if it causes any anomaly that we interpret strings and pointers differently
we would have to debug it more for information