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

CName returns random gibberish for modded vehicles #31

Closed
aymanhilal opened this issue Mar 29, 2024 · 4 comments · Fixed by #32
Closed

CName returns random gibberish for modded vehicles #31

aymanhilal opened this issue Mar 29, 2024 · 4 comments · Fixed by #32
Assignees
Labels
bug Something isn't working released

Comments

@aymanhilal
Copy link

aymanhilal commented Mar 29, 2024

Hi,

I'm using useOnPacket which is a react-node-insim hook, the issue is CName returns random gibberish for modded vehicles only and this does not happen with default LFS vehicles. The same behavior occurs when using inSim.on() method and capturing ISP_NPL packets as well.

I'm capturing ISP_NPL packet to make an API call to retrieve the modded vehicle name in order to save it.

useOnPacket(PacketType.ISP_NPL, async (packet) => {
    console.log(packet.CName); // e.g: MZG Sedan shows as ]*p instead of skin id

    try {
      const req = await fetch(`https://api.lfs.net/vehiclemod/${packet.CName}`, options);
      const res = await req.json();

      setPlayers((prevPlayers) => {
        return prevPlayers.map ... etc
      });
    } catch (error) {
      // ..
    }
  });

Any help is greatly appreciated.

@Degats
Copy link

Degats commented Mar 29, 2024

You can't use the CName value directly from the packet if it's a mod, it will need converting to hex.

If all three characters in CName are alphanumeric (0-9,A-Z,a-z), then it is compatible with stock LFS cars and you can use it as is. Otherwise, you need to use the hex representation of the binary value of CName to get the mod Skin ID

I don't know if there's a helper already in Node InSim to do this for you, but I couldn't find one at first glance.

@theangryangel
Copy link

For ref - https://www.lfs.net/forum/thread/95662-New-InSim-packet-size-byte-and-mod-info explains, from the dev team.

mkapal added a commit that referenced this issue Mar 29, 2024
…s correctly

Changed the decorator of `CName` property to `@carName()` which converts the Skin ID binary
representation to a HEX string internally.

fix #31
@mkapal
Copy link
Member

mkapal commented Mar 29, 2024

Thanks for the report, it is a bug. The CName property in the IS_NPL packet class was wrongly annotated as a @stringNull() data type when being unpacked. I have changed the annotation to @carName() which converts the binary Skin ID to a HEX string correctly. This data type is already used in IS_SLC.

mkapal added a commit that referenced this issue Mar 29, 2024
…s correctly (#32)

Changed the decorator of `CName` property to `@carName()` which converts the Skin ID binary representation to a HEX string internally.

fix #31
Copy link

🎉 This issue has been resolved in version 4.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mkapal mkapal added the bug Something isn't working label Jul 29, 2024
@mkapal mkapal self-assigned this Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
4 participants