roflmuffin / CounterStrikeSharp

CounterStrikeSharp allows you to write server plugins in C# for Counter-Strike 2/Source2/CS2
https://docs.cssharp.dev
Other
714 stars 111 forks source link

[BUG] GiveNamedItem parameters are incorrect (?) #466

Open K4ryuu opened 1 month ago

K4ryuu commented 1 month ago

GiveNamedItem function returns wrong values to the VirtualFunctions.GiveNamedItemFunc.Hook

In the older versions it also returned the classname properly.

When you purchase and item or give by console cmd with sv_cheats and you log the first three params of the DynamicHook you see this (which is correct):

0. �9�P
1. weapon_m4a1
2. �νP

But when you give an item with GiveNamedItem CSS functions, you see this (and you cannot get the classname of weapon)

0. �9�P
1. @6Y�\U
2. Empty (null)

In my case I want to use the classname for further validations, but its just like not exists if GiveNamedItem is being used to give weapon

The code I added at the first lines of GiveNamedItemFunc.Hook:

for (int i = 0; i < 3; i++)
{
      var paramValue = hook.GetParam<string>(i);
      if (string.IsNullOrWhiteSpace(paramValue))
      {
          Logger.LogWarning($"{i}. Empty");
      }
      else
      {
          Logger.LogWarning($"{i}. {paramValue}");
      }
}
ianlucas commented 1 month ago

By "older versions" you mean pre-Fire Sale update, right? I also use that hook in one my plugins and updated the signature for CSSharp via #463. Previously the hook was not being triggered as I think we were hooking another function that also gives items (but that is not called when purchasing/receiving items on spawn).

K4ryuu commented 1 month ago

It was working completely fine until the latest big update that broke the signs. Since then only the item purchase and console give triggers it well. This could be possibly caused by dynohook in CSS(?), but I'm not sure

xLeviNx commented 1 month ago

Also I thought we were using offsets for this?

ianlucas commented 1 month ago

We're using offsets for calling GiveNamedItem, but I think memory function hooking currently just works for signatures, that's why CSSharp still maintains the GiveNamedItem signature.

ianlucas commented 1 month ago

It was working completely fine until the latest big update that broke the signs. Since then only the item purchase and console give triggers it well. This could be possibly caused by dynohook in CSS(?), but I'm not sure

Yeah I'm also not sure if this is related to DynoHook, but I'd guess it's not.