simbroadcasts / node-insim

A NodeJS library for Live For Speed InSim protocol
https://simbroadcasts.github.io/node-insim/
13 stars 1 forks source link

CName returns random gibberish for modded vehicles #31

Closed aymanhilal closed 6 months ago

aymanhilal commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

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

mkapal commented 6 months ago

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.

github-actions[bot] commented 6 months ago

:tada: This issue has been resolved in version 4.0.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: