Skip to content

Commit

Permalink
DataForge support
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-dolkens committed Feb 23, 2016
1 parent 239b021 commit 27966f5
Show file tree
Hide file tree
Showing 32 changed files with 1,499 additions and 53,418 deletions.
3 changes: 3 additions & 0 deletions HoloXPLOR.Data/XML/ItemPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ public IEnumerable<CategoryEnum> ItemCategories
case "Armor":
yield return CategoryEnum.Armor;
break;
case "Cooler":
yield return CategoryEnum.Cooler;
break;
case "Shield":
yield return CategoryEnum.Shield;
break;
Expand Down
5 changes: 5 additions & 0 deletions HoloXPLOR.Data/XML/Spaceships/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,10 @@ public String HTML_Attributes
return sb.ToString();
}
}

public override String ToString()
{
return String.Format("{0}", this.DisplayName); // base.ToString();
}
}
}
12 changes: 9 additions & 3 deletions HoloXPLOR.Data/XML/Spaceships/Pipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ namespace HoloXPLOR.Data.XML.Spaceships
public partial class PipePool
{
[XmlAttribute(AttributeName = "capacity")]
public Double Capacity { get; set; }
public String _capacity { get; set; }
[XmlIgnore]
public Double Capacity { get { return this._capacity.ToDouble(0); } }

[XmlAttribute(AttributeName = "rate")]
public Double Rate { get; set; }
public String _rate { get; set; }
[XmlIgnore]
public Double Rate { get { return this._rate.ToDouble(0); } }

[XmlAttribute(AttributeName = "critical")]
public Double Critical { get; set; }
public String _critical { get; set; }
[XmlIgnore]
public Double Critical { get { return this._critical.ToDouble(0); } }
}

[XmlRoot(ElementName = "Pipe")]
Expand Down
14 changes: 10 additions & 4 deletions HoloXPLOR.Data/XML/Spaceships/Thruster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ public partial class Thruster
public String Flags { get; set; }

[XmlAttribute(AttributeName = "maxThrust")]
public Double MaxThrust { get; set; }
public String _maxThrust { get; set; }
[XmlIgnore]
public Double MaxThrust { get { return _maxThrust.ToDouble(0); } }

[XmlAttribute(AttributeName = "boostScale")]
public Double BoostScale { get; set; }
public String _boostScale { get; set; }
[XmlIgnore]
public Double BoostScale { get { return _boostScale.ToDouble(0); } }

[XmlAttribute(AttributeName = "rotationScale")]
public Double RotationScale { get; set; }
public String _rotationScale { get; set; }
[XmlIgnore]
public Double RotationScale { get { return _rotationScale.ToDouble(0); } }

//<thrusters>
// <thruster flags="maneuver orientation" maxThrust ="1000000" rotationScale="1" boostScale="1.3" >
Expand All @@ -45,6 +51,6 @@ public partial class Thruster
// </exhausts>
// </thruster>
//</thrusters>

}
}
6 changes: 5 additions & 1 deletion HoloXPLOR.Data/XML/Spaceships/_Calculated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum CategoryEnum

AmmoBox,
Armor,
Cooler,
CounterMeasure,
Missile,
MissileRack,
Expand Down Expand Up @@ -86,6 +87,10 @@ public CategoryEnum ItemCategory
case "VehicleWeapon:VehicleMissileRack":
return CategoryEnum.MissileRack;
#endregion
#region Coolers
case "VehicleItem:VehicleItemCooler":
return CategoryEnum.Cooler;
#endregion
#region Ammo/Consumables
case "VehicleItem:VehicleItemAmmoBox":
return CategoryEnum.AmmoBox;
Expand Down Expand Up @@ -140,7 +145,6 @@ public CategoryEnum ItemCategory
case "VehicleItem:VehicleItemTurretAIModule":
case "VehicleItem:VehicleItem":
case "VehicleItem:VehicleItemLight":
case "VehicleItem:VehicleItemCooler":
case "VehicleItem:VehicleItemSeat":
case "VehicleItem:VehicleItemLandingGearSystem":
case "VehicleItem:VehicleItemQDrive":
Expand Down
6 changes: 6 additions & 0 deletions HoloXPLOR.DataForge/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
21 changes: 21 additions & 0 deletions HoloXPLOR.DataForge/BinaryNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HoloXPLOR.DataForge
{
public class BinaryNode
{
public Int32 NodeID { get; set; }
public Int32 NodeNameOffset { get; set; }
public Int32 Item2 { get; set; }
public Int16 AttributeCount { get; set; }
public Int16 ChildCount { get; set; }
public Int32 ParentNodeID { get; set; }
public Int32 Item6 { get; set; }
public Int32 Item7 { get; set; }
public Int32 Item8 { get; set; }
}
}
14 changes: 14 additions & 0 deletions HoloXPLOR.DataForge/BinaryReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HoloXPLOR.DataForge
{
public class BinaryReference
{
public Int32 NameOffset { get; set; }
public Int32 ValueOffset { get; set; }
}
}
14 changes: 14 additions & 0 deletions HoloXPLOR.DataForge/BinaryValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HoloXPLOR.DataForge
{
public class BinaryValue
{
public Int32 Offset { get; set; }
public String Value { get; set; }
}
}
181 changes: 181 additions & 0 deletions HoloXPLOR.DataForge/DataForge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace HoloXPLOR.DataForge
{
public static class DataForgeSerializer
{
public static TObject Deserialize<TObject>(String inFile) where TObject : class
{
using (BinaryReader br = new BinaryReader(File.OpenRead(inFile)))
{
String header = br.ReadCString();
var headerLength = br.BaseStream.Position;
var fileLength = br.ReadInt32();

var nodeTableOffset = br.ReadInt32();
var nodeTableCount = br.ReadInt32();
var nodeTableSize = 28;

var referenceTableOffset = br.ReadInt32();
var referenceTableCount = br.ReadInt32();
var referenceTableSize = 8;

var offset3 = br.ReadInt32();
var count3 = br.ReadInt32();
var length3 = 4;

var contentOffset = br.ReadInt32();
var contentLength = br.ReadInt32();

// Regex byteFormatter = new Regex("([0-9A-F]{8})");

Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x00, fileLength);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x04, nodeTableOffset);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x08, nodeTableCount);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x12, referenceTableOffset);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x16, referenceTableCount);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x20, offset3);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x24, count3);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x28, contentOffset);
Debug.WriteLine("0x{0:X6}: {1:X8} (Dec: {1:D8})", headerLength + 0x32, contentLength);

List<BinaryNode> nodeTable = new List<BinaryNode> { };
br.BaseStream.Seek(nodeTableOffset, SeekOrigin.Begin);
Int32 nodeID = 0;
while (br.BaseStream.Position < nodeTableOffset + nodeTableCount * nodeTableSize)
{
var position = br.BaseStream.Position;
var value = new BinaryNode
{
NodeID = nodeID++,
NodeNameOffset = br.ReadInt32(),
Item2 = br.ReadInt32(),
AttributeCount = br.ReadInt16(),
ChildCount = br.ReadInt16(),
ParentNodeID = br.ReadInt32(),
Item6 = br.ReadInt32(),
Item7 = br.ReadInt32(),
Item8 = br.ReadInt32(),
};

nodeTable.Add(value);
Debug.WriteLine(
"0x{0:X6}: {1:X8} {2:X8} {3:X4} {4:X4} {5:X8} {6:X8} {7:X8} {8:X8}",
position,
value.NodeNameOffset,
value.Item2,
value.AttributeCount,
value.ChildCount,
value.ParentNodeID,
value.Item6,
value.Item7,
value.Item8);
}

List<BinaryReference> attributeTable = new List<BinaryReference> { };
br.BaseStream.Seek(referenceTableOffset, SeekOrigin.Begin);
while (br.BaseStream.Position < referenceTableOffset + referenceTableCount * referenceTableSize)
{
var position = br.BaseStream.Position;
var value = new BinaryReference
{
NameOffset = br.ReadInt32(),
ValueOffset = br.ReadInt32()
};

attributeTable.Add(value);
Debug.WriteLine("0x{0:X6}: {1:X8} {2:X8}", position, value.NameOffset, value.ValueOffset);
}

List<Int32> table3 = new List<Int32> { };
br.BaseStream.Seek(offset3, SeekOrigin.Begin);
while (br.BaseStream.Position < offset3 + count3 * length3)
{
var position = br.BaseStream.Position;
var value = br.ReadInt32();

table3.Add(value);
Debug.WriteLine("0x{0:X6}: {1:X8}", position, value);
}

List<BinaryValue> dataTable = new List<BinaryValue> { };
br.BaseStream.Seek(contentOffset, SeekOrigin.Begin);
while (br.BaseStream.Position < br.BaseStream.Length)
{
var position = br.BaseStream.Position;
var value = new BinaryValue
{
Offset = (Int32)position - contentOffset,
Value = br.ReadCString(),
};
dataTable.Add(value);
Debug.WriteLine("0x{0:X6}: {1:X8} {2}", position, value.Offset, value.Value);
}

var dataMap = dataTable.ToDictionary(k => k.Offset, v => v.Value);

var attributeIndex = 0;

var xmlDoc = new XmlDocument();

var bugged = false;

Dictionary<Int32, XmlElement> xmlMap = new Dictionary<Int32, XmlElement> { };
foreach (var node in nodeTable)
{
XmlElement element = xmlDoc.CreateElement(dataMap[node.NodeNameOffset]);

for (Int32 i = 0, j = node.AttributeCount; i < j; i++)
{
if (dataMap.ContainsKey(attributeTable[attributeIndex].ValueOffset))
{
element.SetAttribute(dataMap[attributeTable[attributeIndex].NameOffset], dataMap[attributeTable[attributeIndex].ValueOffset]);
}
else
{
bugged = true;
element.SetAttribute(dataMap[attributeTable[attributeIndex].NameOffset], "BUGGED");
}
attributeIndex++;
}

xmlMap[node.NodeID] = element;
if (xmlMap.ContainsKey(node.ParentNodeID))
xmlMap[node.ParentNodeID].AppendChild(element);
else
xmlDoc.AppendChild(element);
}

using (MemoryStream ms = new MemoryStream())
{
// if (bugged)
// {
// xmlDoc.Save(Path.ChangeExtension(inFile, "bug"));
// }
// else
// {
// xmlDoc.Save(Path.ChangeExtension(inFile, "raw"));
// }

xmlDoc.Save(ms);

ms.Seek(0, SeekOrigin.Begin);

XmlSerializer xs = new XmlSerializer(typeof(TObject));

return xs.Deserialize(ms) as TObject;
}
}
}
}
}
Loading

0 comments on commit 27966f5

Please sign in to comment.