public static ObjectId ParseObjectId(object value)
    {
        // ToEE encodes object handles as this crazy nested tupel bullshit
        if (value is (int idType, (int dword1, int short1, int short2, (int b1, int b2, int b3, int b4, int b5, int
                                                                        b6, int b7, int b8))))
        {
            if (idType != 2)
            {
                throw new ArgumentException($"Only persistent ids (type=2) are supported. but found:" + idType);
            }

            return(ObjectId.CreatePermanent(
                       new Guid(
                           dword1,
                           (short)short1,
                           (short)short2,
                           (byte)b1,
                           (byte)b2,
                           (byte)b3,
                           (byte)b4,
                           (byte)b5,
                           (byte)b6,
                           (byte)b7,
                           (byte)b8
                           )
                       ));
        }

        throw new ArgumentException($"Is not a serialized object id: {value}");
    }
    /// <summary>
    /// Reads a ToEE object id from the reader.
    /// </summary>
    /// <param name="reader"></param>
    /// <returns></returns>
    public static ObjectId ReadObjectId(this BinaryReader reader)
    {
        Span <byte> buffer = stackalloc byte[24];

        if (reader.Read(buffer) != buffer.Length)
        {
            throw new Exception("Failed to read 24-byte ObjectId");
        }

        var type = BitConverter.ToUInt16(buffer.Slice(0, sizeof(ushort)));

        var payload = buffer.Slice(8); // ObjectId seems to use 8-byte packed

        switch (type)
        {
        case 0:
            return(ObjectId.CreateNull());

        case 1:
            var protoId = BitConverter.ToUInt16(payload.Slice(0, sizeof(ushort)));
            return(ObjectId.CreatePrototype(protoId));

        case 2:
            var guid = MemoryMarshal.Read <Guid>(payload);
            return(ObjectId.CreatePermanent(guid));

        case 3:
            var positionalId = MemoryMarshal.Read <PositionalId>(payload);
            return(ObjectId.CreatePositional(positionalId));

        case 0xFFFE:
            throw new Exception("Cannot load 'handle' ObjectIDs because the pointers are stale!");

        case 0xFFFF:
            return(ObjectId.CreateBlocked());

        default:
            throw new Exception("Unknown ObjectId type: " + type);
        }
    }