citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.41k stars 2.01k forks source link

Adding a component to a weapon object after trying to add and remove a VARMOD component causes native exception to be thrown #2500

Open Lxk3y opened 2 months ago

Lxk3y commented 2 months ago

What happened?

When trying to add a component using GiveWeaponComponentToWeaponObject to a weapon object created with CreateWeaponObject after trying to add and remove a VARMOD component using GiveWeaponComponentToWeaponObject and RemoveWeaponComponentFromWeaponObject (and it not working?), it causes a native level exception to be thrown. The exception is the following:

image

I am unsure of how varmods work exactly, but it doesnt appear to be super well documented so this may well be a case of "not adding them correctly causes this exception". Either way, this seems funky and I don't think this should be happening.

Script to use for the reproduction scripts: test_script.zip

Expected result

Native exception should not be thrown. Instead, a more clear error indicating the issue (or no error at all?) should be shown.

Reproduction steps

  1. Type /spawnweapon. This will create a weapon object (weapon_pistol) inside your ped (just walk forward to see it)
  2. Type /addvarmod. You will see that it doesnt appear to do anything
  3. Type /removevarmod. Again, this will appear to do nothing
  4. Type /addsupp. This should add a suppressor to the pistol but doesnt. Instead, check F8 to observe the error thrown

Importancy

Slight inconvenience

Area(s)

FiveM, Natives, ScRT: Lua

Specific version(s)

FiveM, b2699

Additional information

Again, i am not sure whats so different about these varmods but they seem to cause some funky behaviour. They dont seem to work when trying to add them using the same method used to add non varmod components, and they also throw this native exception if you try and add them and then remove them from a weapon, and then try to add a standard component.

You will also notice that if you follow step 1 and 2, but then skip to step 4, the component again does NOT get added, but no exception is thrown. This suggests there's something funky going on when trying to remove the varmod component.

Lxk3y commented 2 months ago

I would just like to add that, if VARMODs work differently, some documentation on how exactly they differ from standard components would be much appreciated. As my repo steps show, they are definitely not working the same as standard components in some way when it comes to adding them to weapon objects.