public void WriteArrays(byte[] data) { foreach (KeyValuePair <int, Array_Structure> ptr in Structures) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } foreach (KeyValuePair <int, Array_StructurePointer> ptr in StructurePointers) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } foreach (KeyValuePair <int, Array_uint> ptr in UInts) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } foreach (KeyValuePair <int, Array_ushort> ptr in UShorts) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } foreach (KeyValuePair <int, Array_byte> ptr in UBytes) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } foreach (KeyValuePair <int, Array_float> ptr in Floats) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } foreach (KeyValuePair <int, Array_Vector3> ptr in Float_XYZs) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } foreach (KeyValuePair <int, Array_uint> ptr in Hashes) { var _data = MetaUtils.ConvertToBytes(ptr.Value); Buffer.BlockCopy(_data, 0, data, ptr.Key, _data.Length); } }
private static byte[] Traverse(XmlNode node, MetaBuilder mb, MetaName type = 0, bool isRoot = false) { if (type == 0) { type = (MetaName)(uint)GetHash(node.Name); } var infos = MetaInfo.GetStructureInfo(type); if (infos != null) { byte[] data = new byte[infos.StructureLength]; var arrayResults = new ArrayResults(); arrayResults.Structures = new Dictionary <int, Array_Structure>(); arrayResults.StructurePointers = new Dictionary <int, Array_StructurePointer>(); arrayResults.UInts = new Dictionary <int, Array_uint>(); arrayResults.UShorts = new Dictionary <int, Array_ushort>(); arrayResults.UBytes = new Dictionary <int, Array_byte>(); arrayResults.Floats = new Dictionary <int, Array_float>(); arrayResults.Float_XYZs = new Dictionary <int, Array_Vector3>(); arrayResults.Hashes = new Dictionary <int, Array_uint>(); Array.Clear(data, 0, infos.StructureLength); StructureEntryInfo arrEntry = new StructureEntryInfo(); if (isRoot) { mb.EnsureBlock(type); } for (int i = 0; i < infos.Entries.Count; i++) { var entry = infos.Entries[i]; var cnode = GetEntryNode(node.ChildNodes, entry); if ((MetaName)entry.EntryNameHash == MetaName.ARRAYINFO) { arrEntry = entry; continue; } if (cnode == null) { continue; } switch (entry.DataType) { case StructureEntryDataType.Array: { TraverseArray(cnode, mb, arrEntry, entry.DataOffset, arrayResults); break; } case StructureEntryDataType.ArrayOfBytes: { GetParsedArrayOfBytes(cnode, data, entry, arrEntry); break; } case StructureEntryDataType.ArrayOfChars: { int offset = entry.DataOffset; var split = Split(cnode.InnerText, 2); for (int j = 0; j < split.Length; j++) { byte val = Convert.ToByte(split[j], 16); data[offset] = val; offset += sizeof(byte); } break; } case StructureEntryDataType.Boolean: { byte val = (cnode.Attributes["value"].Value == "false") ? (byte)0 : (byte)1; data[entry.DataOffset] = val; break; } case StructureEntryDataType.ByteEnum: { byte val = Convert.ToByte(cnode.Attributes["value"].Value); data[entry.DataOffset] = val; break; } case StructureEntryDataType.CharPointer: { if (!string.IsNullOrEmpty(cnode.InnerText)) { var ptr = mb.AddStringPtr(cnode.InnerText); var val = MetaUtils.ConvertToBytes(ptr); Buffer.BlockCopy(val, 0, data, entry.DataOffset, val.Length); } break; } case StructureEntryDataType.DataBlockPointer: { // TODO break; } case StructureEntryDataType.Float: { float val = FloatUtil.Parse(cnode.Attributes["value"].Value); Write(val, data, entry.DataOffset); break; } case StructureEntryDataType.Float_XYZ: { float x = FloatUtil.Parse(cnode.Attributes["x"].Value); float y = FloatUtil.Parse(cnode.Attributes["y"].Value); float z = FloatUtil.Parse(cnode.Attributes["z"].Value); Write(x, data, entry.DataOffset); Write(y, data, entry.DataOffset + sizeof(float)); Write(z, data, entry.DataOffset + sizeof(float) * 2); break; } case StructureEntryDataType.Float_XYZW: { float x = FloatUtil.Parse(cnode.Attributes["x"].Value); float y = FloatUtil.Parse(cnode.Attributes["y"].Value); float z = FloatUtil.Parse(cnode.Attributes["z"].Value); float w = FloatUtil.Parse(cnode.Attributes["w"].Value); Write(x, data, entry.DataOffset); Write(y, data, entry.DataOffset + sizeof(float)); Write(z, data, entry.DataOffset + sizeof(float) * 2); Write(w, data, entry.DataOffset + sizeof(float) * 3); break; } case StructureEntryDataType.Hash: { var hash = GetHash(cnode.InnerText); Write((uint)hash, data, entry.DataOffset); break; } case StructureEntryDataType.IntEnum: case StructureEntryDataType.IntFlags1: case StructureEntryDataType.IntFlags2: { var _infos = MetaInfo.GetEnumInfo((MetaName)entry.ReferenceKey); if (_infos != null) { mb.AddEnumInfo((MetaName)_infos.EnumNameHash); } int val = GetEnumInt((MetaName)entry.ReferenceKey, cnode.InnerText, entry.DataType); Write(val, data, entry.DataOffset); break; } case StructureEntryDataType.ShortFlags: { var _infos = MetaInfo.GetEnumInfo((MetaName)entry.ReferenceKey); if (_infos != null) { mb.AddEnumInfo((MetaName)_infos.EnumNameHash); } // int val = GetEnumInt((MetaName)entry.ReferenceKey, cnode.InnerText, entry.DataType); if (short.TryParse(cnode.InnerText, out short val)) { Write(val, data, entry.DataOffset); } break; } case StructureEntryDataType.SignedByte: { var val = Convert.ToSByte(cnode.Attributes["value"].Value); data[entry.DataOffset] = (byte)val; break; } case StructureEntryDataType.SignedInt: { var val = Convert.ToInt32(cnode.Attributes["value"].Value); Write(val, data, entry.DataOffset); break; } case StructureEntryDataType.SignedShort: { var val = Convert.ToInt16(cnode.Attributes["value"].Value); Write(val, data, entry.DataOffset); break; } case StructureEntryDataType.Structure: { var struc = Traverse(cnode, mb, (MetaName)entry.ReferenceKey); if (struc != null) { Buffer.BlockCopy(struc, 0, data, entry.DataOffset, struc.Length); } break; } case StructureEntryDataType.StructurePointer: { // TODO break; } case StructureEntryDataType.UnsignedByte: { var val = Convert.ToByte(cnode.Attributes["value"].Value); data[entry.DataOffset] = val; break; } case StructureEntryDataType.UnsignedInt: { switch ((MetaName)entry.EntryNameHash) { case MetaName.color: { var val = Convert.ToUInt32(cnode.Attributes["value"].Value, 16); Write(val, data, entry.DataOffset); break; } default: { var val = Convert.ToUInt32(cnode.Attributes["value"].Value); Write(val, data, entry.DataOffset); break; } } break; } case StructureEntryDataType.UnsignedShort: { var val = Convert.ToUInt16(cnode.Attributes["value"].Value); Write(val, data, entry.DataOffset); break; } default: break; } } arrayResults.WriteArrays(data); mb.AddStructureInfo((MetaName)infos.StructureNameHash); if (isRoot) { mb.AddItem(type, data); } return(data); } return(null); }