From f5b8da104ce01f1bcfdac1137b9ce72c103ebbc9 Mon Sep 17 00:00:00 2001 From: Carmine Date: Thu, 1 Mar 2018 23:09:15 +0100 Subject: [PATCH 1/3] Added GetParsedArrayOfBytes WriteParsedArrayOfBytesNode to handle ArrayOfBytes when converting to/from XML --- .../GameFiles/MetaTypes/MetaXml.cs | 88 +++++++++++++++++-- .../GameFiles/MetaTypes/XmlMeta.cs | 79 +++++++++++++++++ 2 files changed, 158 insertions(+), 9 deletions(-) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs b/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs index b85e24a..5560d87 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs @@ -189,15 +189,9 @@ namespace CodeWalker.GameFiles break; case MetaStructureEntryDataType.ArrayOfBytes: - OpenTag(sb, cind, ename, false); - var byteArrLen = (int)entry.ReferenceKey; - for (int n = 0; n < byteArrLen; n++) - { - var bidx = eoffset + n; - byte b = ((bidx >= 0) && (bidx < data.Length)) ? data[bidx] : (byte)0; - sb.Append(b.ToString("X").PadLeft(2, '0')); - } - CloseTag(sb, 0, ename); + + WriteParsedArrayOfBytesNode(sb, cind, data, ename, eoffset, entry, arrEntry); + break; case MetaStructureEntryDataType.ArrayOfChars: OpenTag(sb, cind, ename, false); @@ -429,6 +423,82 @@ namespace CodeWalker.GameFiles } } + private static void WriteParsedArrayOfBytesNode(StringBuilder sb, int indent, byte[] data, string ename, int eoffset, MetaStructureEntryInfo_s entry, MetaStructureEntryInfo_s arrEntry) + { + OpenTag(sb, indent, ename, false); + + var byteArrLen = ((int)entry.ReferenceKey); + + switch (arrEntry.DataType) + { + default: + case MetaStructureEntryDataType.SignedByte: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n; + byte b = ((bidx >= 0) && (bidx < data.Length)) ? data[bidx] : (byte)0; + sb.Append(b.ToString("X").PadLeft(2, '0')); + } + break; + + case MetaStructureEntryDataType.UnsignedByte: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n; + byte b = ((bidx >= 0) && (bidx < data.Length)) ? data[bidx] : (byte)0; + sb.Append(b.ToString()); + if (n < byteArrLen - 1) sb.Append(" "); + } + break; + case MetaStructureEntryDataType.SignedShort: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n * 2; + short b = ((bidx >= 0) && (bidx < data.Length)) ? BitConverter.ToInt16(data, bidx) : (short)0; + sb.Append(b.ToString()); + if (n < byteArrLen - 1) sb.Append(" "); + } + break; + case MetaStructureEntryDataType.UnsignedShort: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n * 2; + ushort b = ((bidx >= 0) && (bidx < data.Length)) ? BitConverter.ToUInt16(data, bidx) : (ushort)0; + sb.Append(b.ToString()); + if (n < byteArrLen - 1) sb.Append(" "); + } + break; + case MetaStructureEntryDataType.SignedInt: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n * 4; + int b = ((bidx >= 0) && (bidx < data.Length)) ? BitConverter.ToInt32(data, bidx) : (int)0; + sb.Append(b.ToString()); + if (n < byteArrLen - 1) sb.Append(" "); + } + break; + case MetaStructureEntryDataType.UnsignedInt: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n * 4; + uint b = ((bidx >= 0) && (bidx < data.Length)) ? BitConverter.ToUInt32(data, bidx) : (uint)0; + sb.Append(b.ToString()); + if (n < byteArrLen - 1) sb.Append(" "); + } + break; + case MetaStructureEntryDataType.Float: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n * 4; + float b = ((bidx >= 0) && (bidx < data.Length)) ? BitConverter.ToSingle(data, bidx) : (float)0; + sb.Append(FloatUtil.ToString(b)); + if (n < byteArrLen - 1) sb.Append(" "); + } + break; + } + + CloseTag(sb, 0, ename); + } diff --git a/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs b/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs index 3eab7e8..c8c057b 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs @@ -77,6 +77,11 @@ namespace CodeWalker.GameFiles } case MetaStructureEntryDataType.ArrayOfBytes: + { + GetParsedArrayOfBytes(cnode, data, entry, arrEntry); + break; + } + case MetaStructureEntryDataType.ArrayOfChars: { int offset = entry.DataOffset; @@ -288,6 +293,80 @@ namespace CodeWalker.GameFiles return null; } + private static void GetParsedArrayOfBytes(XmlNode node, byte[] data, MetaStructureEntryInfo_s entry, MetaStructureEntryInfo_s arrEntry) + { + int offset = entry.DataOffset; + string[] split; + + switch (arrEntry.DataType) + { + default: + case MetaStructureEntryDataType.SignedByte: + split = Split(node.InnerText, 2); + for (int j = 0; j < split.Length; j++) + { + byte val = Convert.ToByte(split[j], 16); + data[offset] = val; + offset += sizeof(sbyte); + } + break; + case MetaStructureEntryDataType.UnsignedByte: + split = node.InnerText.Split(); + for (int j = 0; j < split.Length; j++) + { + byte val = Convert.ToByte(split[j], 10); + data[offset] = val; + offset += sizeof(byte); + } + break; + case MetaStructureEntryDataType.SignedShort: + split = node.InnerText.Split(); + for (int j = 0; j < split.Length; j++) + { + short val = Convert.ToInt16(split[j], 10); + Write(val, data, offset); + offset += sizeof(short); + } + break; + case MetaStructureEntryDataType.UnsignedShort: + split = node.InnerText.Split(); + for (int j = 0; j < split.Length; j++) + { + ushort val = Convert.ToUInt16(split[j], 10); + Write(val, data, offset); + offset += sizeof(ushort); + } + break; + case MetaStructureEntryDataType.SignedInt: + split = node.InnerText.Split(); + for (int j = 0; j < split.Length; j++) + { + int val = Convert.ToInt32(split[j], 10); + Write(val, data, offset); + offset += sizeof(int); + } + break; + case MetaStructureEntryDataType.UnsignedInt: + split = node.InnerText.Split(); + for (int j = 0; j < split.Length; j++) + { + uint val = Convert.ToUInt32(split[j], 10); + Write(val, data, offset); + offset += sizeof(uint); + } + break; + case MetaStructureEntryDataType.Float: + split = node.InnerText.Split(); + for (int j = 0; j < split.Length; j++) + { + float val = FloatUtil.Parse(split[j]); + Write(val, data, offset); + offset += sizeof(float); + } + break; + } + } + private static void TraverseArray(XmlNode node, MetaBuilder mb, MetaStructureEntryInfo_s arrEntry, int offset, ArrayResults results) { switch (arrEntry.DataType) From 8baef77ecd27a00592ecbee621ebc2ca604a9b70 Mon Sep 17 00:00:00 2001 From: Carmine Date: Thu, 1 Mar 2018 23:13:19 +0100 Subject: [PATCH 2/3] Added some missing hashes taken from dav90's PSO_RBF_XMLExport_V5.7 --- .../GameFiles/MetaTypes/MetaNames.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/MetaNames.cs b/CodeWalker.Core/GameFiles/MetaTypes/MetaNames.cs index 45fad0f..a5fbf36 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/MetaNames.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/MetaNames.cs @@ -3401,7 +3401,24 @@ namespace CodeWalker.GameFiles + //from dav90's PSO_RBF_XMLExport_V5.7 + AutoJunctionAdjustments = 1352439928, + vLocation = 929088795, + fCycleOffset = 1883372816, + fCycleDuration = 3328650398, + registerAs = 1419376801, + + CreditItems = 1705522053, + LineType = 660169259, + cTextId1 = 4188319879, + cTextId2 = 2913343627, + JOB_BIG = 1035407208, + + flee_left = 204999120, + flee_right = 1266046331, + flee_forward = 1547194093, + flee_back = 1622623046, From e2b59d2ca5f83b609a5e55d3c377424dce4997b0 Mon Sep 17 00:00:00 2001 From: Carmine Date: Fri, 2 Mar 2018 01:15:55 +0100 Subject: [PATCH 3/3] Fixed sbyte types in handler of ArrayOfBytes --- CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs | 10 +++++++++- CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs b/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs index 5560d87..8b5a07b 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/MetaXml.cs @@ -432,7 +432,6 @@ namespace CodeWalker.GameFiles switch (arrEntry.DataType) { default: - case MetaStructureEntryDataType.SignedByte: for (int n = 0; n < byteArrLen; n++) { var bidx = eoffset + n; @@ -440,6 +439,15 @@ namespace CodeWalker.GameFiles sb.Append(b.ToString("X").PadLeft(2, '0')); } break; + case MetaStructureEntryDataType.SignedByte: + for (int n = 0; n < byteArrLen; n++) + { + var bidx = eoffset + n; + sbyte b = ((bidx >= 0) && (bidx < data.Length)) ? (sbyte)data[bidx] : (sbyte)0; + sb.Append(b.ToString()); //sb.Append(b.ToString("X").PadLeft(2, '0')); to show HEX values + if (n < byteArrLen - 1) sb.Append(" "); + } + break; case MetaStructureEntryDataType.UnsignedByte: for (int n = 0; n < byteArrLen; n++) diff --git a/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs b/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs index c8c057b..d56b39a 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/XmlMeta.cs @@ -301,12 +301,20 @@ namespace CodeWalker.GameFiles switch (arrEntry.DataType) { default: - case MetaStructureEntryDataType.SignedByte: split = Split(node.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 MetaStructureEntryDataType.SignedByte: + split = node.InnerText.Split(); //split = Split(node.InnerText, 2); to read as unsplitted HEX + for (int j = 0; j < split.Length; j++) + { + sbyte val = Convert.ToSByte(split[j], 10); + data[offset] = (byte)val; offset += sizeof(sbyte); } break;