Template
*
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public class PogFile
|
||||
{
|
||||
[Serializable]
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct ObjectRecord {
|
||||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
|
||||
public string Name;
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
|
||||
public byte[] SomeData;
|
||||
|
||||
public short XOffset;
|
||||
public short YOffset;
|
||||
public short ZOffset;
|
||||
|
||||
public short ID;
|
||||
public short XRotation; // 4096 = 360°
|
||||
public short YRotation; // 4096 = 360°
|
||||
public short ZRotation; // 4096 = 360°
|
||||
public short TypeID; // Model type id (instancing)
|
||||
|
||||
public short BoundingBoxWidth;
|
||||
public short BoundingBoxHeight;
|
||||
public short BoundingBoxLength;
|
||||
|
||||
public short BoundingBoxType;
|
||||
|
||||
public short Short0;
|
||||
public byte Byte0;
|
||||
|
||||
public byte Team;
|
||||
|
||||
public short ScriptType;
|
||||
|
||||
public byte ScriptGroup;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 19)]
|
||||
public byte[] ScriptParamters;
|
||||
public short ScriptXOffset;
|
||||
public short ScriptYOffset;
|
||||
public short ScriptZOffset;
|
||||
|
||||
public short Flag;
|
||||
|
||||
public short Short1;
|
||||
public short Short2;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private ObjectRecord[] _objects;
|
||||
|
||||
public ObjectRecord[] Objects {
|
||||
get { return _objects; }
|
||||
}
|
||||
|
||||
public static PogFile Parse(byte[] data) {
|
||||
PogFile result = new PogFile();
|
||||
|
||||
MemoryStream src = new MemoryStream(data);
|
||||
|
||||
BinaryReader r = new BinaryReader(src);
|
||||
var count = r.ReadUInt16();
|
||||
|
||||
var itemSize = Marshal.SizeOf<ObjectRecord>();
|
||||
|
||||
|
||||
List<ObjectRecord> records = new List<ObjectRecord>();
|
||||
for (int i = 0; i < count; ++i) {
|
||||
var itemData = r.ReadBytes(itemSize);
|
||||
|
||||
var handle = GCHandle.Alloc(itemData, GCHandleType.Pinned);
|
||||
records.Add( Marshal.PtrToStructure<ObjectRecord>(handle.AddrOfPinnedObject()));
|
||||
|
||||
|
||||
}
|
||||
result._objects = records.ToArray();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user