Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ianlucas opened this issue Feb 28, 2024 · 4 comments
Open

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

ianlucas opened this issue Feb 28, 2024 · 4 comments
Labels
area-Core-DynamicHooks untriaged New issue has not been triaged

Comments

@ianlucas
Copy link
Contributor

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.

@github-actions github-actions bot added the untriaged New issue has not been triaged label Feb 28, 2024
@KillStr3aK
Copy link
Contributor

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

@ianlucas
Copy link
Contributor Author

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.

@KillStr3aK
Copy link
Contributor

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
Copy link
Contributor

we would have to debug it more for information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Core-DynamicHooks untriaged New issue has not been triaged
Projects
None yet
Development

No branches or pull requests

3 participants