CounterStrikeSharp icon indicating copy to clipboard operation
CounterStrikeSharp copied to clipboard

`hook.SetParam<string>(...)` won't change hook's parameter

Open ianlucas opened this issue 1 year ago • 4 comments

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.

ianlucas avatar Feb 28 '24 21:02 ianlucas

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

KillStr3aK avatar Feb 28 '24 21:02 KillStr3aK

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

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.

ianlucas avatar Apr 17 '24 15:04 ianlucas

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

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.

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

KillStr3aK avatar Apr 17 '24 20:04 KillStr3aK

we would have to debug it more for information

KillStr3aK avatar Apr 17 '24 20:04 KillStr3aK