0xD8 invalid MsgPack type


#1

I’m currently trying to debug a problem in someone else’s code that occurs when you spam the shit out of NUI $.post and SET_NUI_FOCUS requests (it will always happen on nui focus = true, never on nui focus = false). AFAIK this would not occur until recent-ish. 0xD8 or 216 is the message type which indeed isn’t present in GetUnpacker(). The resource completely crashes the client is in a NUI input lock until the resource is restarted. The thrown exception is not catchable at resource level unforunately:

throw new InvalidOperationException($"Tried to decode invalid MsgPack type {type}");

Would it be possible to catch the exception at public static object Deserialize(byte[] data, string netSource = null) level and return a null / nil object in case the type is not recognized, while printing the error to console instead?

[   4163282] System.InvalidOperationException: Tried to decode invalid MsgPack type 216
[   4163282]   at CitizenFX.Core.MsgPackDeserializer.GetUnpacker (System.Byte type) [0x00232] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:387 
[   4163297]   at CitizenFX.Core.MsgPackDeserializer.UnpackAny (System.IO.BinaryReader reader) [0x00007] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:30 
[   4163297]   at CitizenFX.Core.MsgPackDeserializer.UnpackArray (System.IO.BinaryReader reader, System.Int32 length) [0x0000a] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:56 
[   4163297]   at CitizenFX.Core.MsgPackDeserializer.UnpackFixArray (System.Byte a, System.IO.BinaryReader reader) [0x00005] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:217 
[   4163297]   at CitizenFX.Core.MsgPackDeserializer.UnpackAny (System.IO.BinaryReader reader) [0x0000f] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:32 
[   4163297]   at CitizenFX.Core.MsgPackDeserializer.Deserialize (System.Byte[] data, System.String netSource) [0x0001b] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\MsgPackDeserializer.cs:24 
[   4163313]   at CitizenFX.Core.InternalManager.TriggerEvent (System.String eventName, System.Byte[] argsSerialized, System.String sourceString) [0x00021] in C:\gl\builds\aaf2d114\0\cfx\fivem\code\client\clrcore\InternalManager.cs:194

C# Exports Issue
#2

Workaround is to have the resource name to something bigger. In my case the resource name was “chat”. Renaming it to something larger fixed the issue. (Discovered by @blcd)


#3

The issue here is that the fivem msgpack deserializer doesn’t support the full spec. 216 is an optimized type used when packing an extended type value that is exactly 16 bytes long. This happens in the following code when the CanonicalizeRef is 16 bytes long.

                var funcRefDetails = FunctionReference.Create(objectTree);
                var refType = InternalManager.CanonicalizeRef(funcRefDetails.Identifier);

                packer.PackExtendedTypeValue(10, Encoding.UTF8.GetBytes(refType));

#4

I had a similar issue here: C# Exports Issue

So the resource name (only?) needs to be longer than 16 bytes in size? An element mentioned it couldn’t be 16 characters, but I was a bit confused by that.

Edit: I’ve made the resource and method names all pretty long, and I still have the same issue. :confused:


#5