-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dat structures and tests for UILayout and DbProperties (#4208)
- Loading branch information
Showing
13 changed files
with
563 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using ACE.Entity.Enum; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Numerics; | ||
|
||
namespace ACE.DatLoader.Entity | ||
{ | ||
public class BaseProperty : IUnpackable | ||
{ | ||
// If this is in a collection/hashtable, this will actually match the key in that table. | ||
// The enum value of this can be looked up in MasterProperty | ||
public uint Id; | ||
|
||
public BasePropertyType PropertyType; // This is read from the MasterProperty table | ||
|
||
// Depending on the PropertyType, one of these values will be populated | ||
public uint ValueEnum; | ||
public bool ValueBool; | ||
public uint ValueDataFile; | ||
public float ValueFloat; | ||
public StringInfo ValueString; | ||
public uint ValueColor; | ||
public List<BaseProperty> ValueArray; | ||
public int ValueInt; | ||
public Dictionary<uint, BaseProperty> ValueStruct; | ||
public Vector3 ValueVector; | ||
public uint ValueBitfield32; | ||
public ulong ValueBitfield64; | ||
public uint ValueInstanceId; | ||
|
||
public void Unpack(BinaryReader reader) | ||
{ | ||
Id = reader.ReadUInt32(); | ||
|
||
if (!DatManager.PortalDat.MasterProperty.m_properties.ContainsKey(Id)) | ||
throw (new Exception("Unable to locate BaseProperty type in the MasterProperty table")); | ||
|
||
PropertyType = DatManager.PortalDat.MasterProperty.m_properties[Id].m_propertyType; | ||
switch(PropertyType) | ||
{ | ||
case BasePropertyType.Enum: | ||
ValueEnum = reader.ReadUInt32(); | ||
break; | ||
case BasePropertyType.Bool: | ||
ValueBool = reader.ReadBoolean(); | ||
break; | ||
case BasePropertyType.DataFile: | ||
ValueDataFile = reader.ReadUInt32(); | ||
break; | ||
case BasePropertyType.Float: | ||
ValueFloat = reader.ReadSingle(); | ||
break; | ||
case BasePropertyType.StringInfo: | ||
ValueString = new StringInfo(); | ||
ValueString.Unpack(reader); | ||
break; | ||
case BasePropertyType.Color: | ||
ValueColor = reader.ReadUInt32(); | ||
break; | ||
case BasePropertyType.Array: | ||
ValueArray = new List<BaseProperty>(); | ||
ValueArray.Unpack(reader); | ||
break; | ||
case BasePropertyType.Integer: | ||
ValueInt = reader.ReadInt32(); | ||
break; | ||
case BasePropertyType.Struct: | ||
ValueStruct = new Dictionary<uint, BaseProperty>(); | ||
|
||
// This packed list uses a little different format not handled in the unpackable extensions | ||
reader.ReadByte(); // bucketSize? | ||
var totalObjects = reader.ReadByte(); | ||
for (int i = 0; i < totalObjects; i++) | ||
{ | ||
var key = reader.ReadUInt32(); | ||
|
||
var item = new BaseProperty(); | ||
item.Unpack(reader); | ||
ValueStruct.Add(key, item); | ||
} | ||
break; | ||
case BasePropertyType.String: | ||
// No use cases in end-of-retail Dat files. | ||
// While there are a couple of MasterProperty entries of this type, there are no BaseProperty entries that use them. | ||
break; | ||
case BasePropertyType.Vector: | ||
ValueVector = reader.ReadVector3(); | ||
break; | ||
case BasePropertyType.Bitfield32: | ||
ValueBitfield32 = reader.ReadUInt32(); | ||
break; | ||
case BasePropertyType.Bitfield64: | ||
ValueBitfield64 = reader.ReadUInt64(); | ||
break; | ||
case BasePropertyType.InstanceID: | ||
ValueInstanceId = reader.ReadUInt32(); | ||
break; | ||
default: | ||
// Should never hit this! | ||
throw new NotImplementedException(); | ||
break; | ||
} | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using ACE.Entity.Enum; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace ACE.DatLoader.Entity | ||
{ | ||
public class ElementDesc : StateDesc | ||
{ | ||
public uint UiReadOrder; | ||
|
||
// Enum names for these are in EnumMapper 0x2200001B (UIElementID) | ||
public uint ElementId; | ||
public uint Type; | ||
public uint BaseElement; | ||
public uint BaseLayout; | ||
public uint DefaultState; | ||
|
||
public uint X; | ||
public uint Y; | ||
public uint Width; | ||
public uint Height; | ||
public uint ZLevel; | ||
public uint LeftEdge; | ||
public uint TopEdge; | ||
public uint RightEdge; | ||
public uint BottomEdge; | ||
|
||
public Dictionary<uint, StateDesc> States = new Dictionary<uint, StateDesc>(); | ||
public Dictionary<uint, ElementDesc> Children = new Dictionary<uint, ElementDesc>(); | ||
|
||
public override void Unpack(BinaryReader reader) | ||
{ | ||
base.Unpack(reader); | ||
UnpackElementDesc(reader); | ||
} | ||
|
||
public void UnpackElementDesc(BinaryReader reader) | ||
{ | ||
UiReadOrder = reader.ReadUInt32(); | ||
ElementId = reader.ReadUInt32(); | ||
Type = reader.ReadUInt32(); | ||
BaseElement = reader.ReadUInt32(); | ||
BaseLayout = reader.ReadUInt32(); | ||
DefaultState = reader.ReadUInt32(); | ||
|
||
if ((UiIncorporationFlags & IncorporationFlags.X) != 0) | ||
X = reader.ReadUInt32(); | ||
if ((UiIncorporationFlags & IncorporationFlags.Y) != 0) | ||
Y = reader.ReadUInt32(); | ||
if ((UiIncorporationFlags & IncorporationFlags.Width) != 0) | ||
Width = reader.ReadUInt32(); | ||
if ((UiIncorporationFlags & IncorporationFlags.Height) != 0) | ||
Height = reader.ReadUInt32(); | ||
if ((UiIncorporationFlags & IncorporationFlags.ZLevel) != 0) | ||
ZLevel = reader.ReadUInt32(); | ||
|
||
LeftEdge = reader.ReadUInt32(); | ||
TopEdge = reader.ReadUInt32(); | ||
RightEdge = reader.ReadUInt32(); | ||
BottomEdge = reader.ReadUInt32(); | ||
|
||
reader.ReadByte(); | ||
var totalObjects = reader.ReadByte(); | ||
for (int i = 0; i < totalObjects; i++) | ||
{ | ||
var key = reader.ReadUInt32(); | ||
|
||
var item = new StateDesc(); | ||
item.Unpack(reader); | ||
States.Add(key, item); | ||
} | ||
|
||
reader.ReadByte(); | ||
var totalChildren = reader.ReadByte(); | ||
for (int i = 0; i < totalChildren; i++) | ||
{ | ||
var key = reader.ReadUInt32(); | ||
|
||
var item = new ElementDesc(); | ||
item.Unpack(reader); | ||
Children.Add(key, item); | ||
} | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.