Example #1
0
        public void Serialize(BinaryWriter writer)
        {
            writer.Write((byte)Type);

            switch (Type)
            {
            case Types.Null:
                break;

            case Types.LocalCoreUUID:
            case Types.UUIDRef:
                GUID.ToData(writer);
                break;

            case Types.ExternalCoreUUID:
            case Types.StreamingRef:
                GUID.ToData(writer);

                ExternalFile.Serialize(writer);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #2
0
        public void ToData(BinaryWriter writer, GameType gameType)
        {
            // Write to a separate memory stream buffer in order to get the block length (shaderDataLength)
            using var ms = new MemoryStream();
            using var bw = new BinaryWriter(ms);

            bw.Write(Unknown1);
            bw.Write((uint)TypeMask);
            bw.Write(Unknown2);

            if (gameType == GameType.DS)
            {
                bw.Write((uint)Programs.Count);
            }

            foreach (var entry in Programs)
            {
                entry.ToData(bw, gameType);
            }

            bw.Write((uint)RootSignatureData.Length);
            bw.Write(RootSignatureData);

            writer.Write((uint)ms.Length);
            ResourceDataHash.ToData(writer);
            ms.WriteTo(writer.BaseStream);
        }
        public void ToData(BinaryWriter writer)
        {
            var dataFormat = Buffer.Format switch
            {
                BaseDataBufferFormat.R_UINT_16 => BaseIndexFormat.Index16,
                BaseDataBufferFormat.R_UINT_32 => BaseIndexFormat.Index32,
                _ => throw new NotSupportedException("Unknown index buffer type"),
            };

            uint elementCount = Buffer?.ElementCount ?? 0;

            writer.Write(elementCount);

            if (elementCount > 0)
            {
                writer.Write(Flags);
                writer.Write((uint)dataFormat);
                writer.Write((uint)(Buffer.Streaming ? 1 : 0));
                ResourceGUID.ToData(writer);
                Buffer.ToData(writer);
            }
        }