CounterStrikeSharp icon indicating copy to clipboard operation
CounterStrikeSharp copied to clipboard

[BUG] GiveNamedItem parameters are incorrect (?)

Open K4ryuu opened this issue 1 year ago • 9 comments

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}");
      }
}

K4ryuu avatar May 26 '24 15:05 K4ryuu

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).

ianlucas avatar May 26 '24 23:05 ianlucas

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

K4ryuu avatar May 28 '24 08:05 K4ryuu

Also I thought we were using offsets for this?

xLeviNx avatar May 28 '24 12:05 xLeviNx

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 avatar May 28 '24 13:05 ianlucas

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.

ianlucas avatar May 28 '24 13:05 ianlucas

This issue has been marked needs-author-action and may be missing some important information.

github-actions[bot] avatar Jul 27 '24 06:07 github-actions[bot]

@K4ryuu Can you confirm if there are still issues with this?

roflmuffin avatar Jul 27 '24 06:07 roflmuffin

CleanShot 2024-07-27 at 20 05 46@2x

Weapons are visible again. Perfect job! Issue is solved. Thanks for your work!

K4ryuu avatar Jul 27 '24 18:07 K4ryuu

Apologise, but I was wrong with the feedback as I checked on player spawn for some reason. On spawn it works well, but when you use GiveNamedItem, it still returns the following data:

CleanShot 2024-08-07 at 00 55 52@2x

K4ryuu avatar Aug 06 '24 22:08 K4ryuu

Seems like it's working perfectly since then. I don't know when it got fixed exactly

K4ryuu avatar Jan 31 '25 23:01 K4ryuu