Skip to content

Commit

Permalink
Fixup some classes which never recompiled 1:1
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyman192 committed Apr 24, 2024
1 parent 7510b39 commit fb64a74
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override object CustomDeserialize(BinaryReader reader, Type field, NMSAtt
return null;
}

public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex)
public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object, ushort>> additionalData, ref int addtDataIndex)
{
if (field == null || fieldInfo == null)
return false;
Expand Down Expand Up @@ -154,7 +154,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie

}

additionalData.Insert(addtDataIndex, new Tuple<long, object>(listPos, outputData));
additionalData.Insert(addtDataIndex, new Tuple<long, object, ushort>(listPos, outputData, 0));
addtDataIndex++;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameHalfData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override object CustomDeserialize(BinaryReader reader, Type field, NMSAtt
return null;
}

public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex)
public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object, ushort>> additionalData, ref int addtDataIndex)
{
if (field == null || fieldInfo == null)
return false;
Expand Down Expand Up @@ -153,7 +153,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie

}

additionalData.Insert(addtDataIndex, new Tuple<long, object>(listPos, outputData));
additionalData.Insert(addtDataIndex, new Tuple<long, object, ushort>(listPos, outputData, 0));
addtDataIndex++;
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions libMBIN/Source/NMS/Toolkit/TkGeometryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TkGeometryData : NMSTemplate
/* 0x13C */ public int VertexCount;

// TODO: add the list ending to this??
public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex) {
public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object, ushort>> additionalData, ref int addtDataIndex) {
if (field == null || fieldInfo == null) return false;

Dictionary<int, int> TypeMap = new Dictionary<int, int> { { 5131, 8 }, { 36255, 4 }, { 5121, 4 } };
Expand All @@ -51,7 +51,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie
IList data = (IList)fieldData;

if (Indices16Bit != 1) { // if 32bit indices, we can just pass it directly
additionalData.Insert(addtDataIndex, new Tuple<long, object>(listPos, data));
additionalData.Insert(addtDataIndex, new Tuple<long, object, ushort>(listPos, data, 0));
}
else {
// otherwise we have to create 32bit indices from the 16bit ones
Expand All @@ -70,7 +70,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie
list32Bit.Add(val32Bit);
}

additionalData.Insert(addtDataIndex, new Tuple<long, object>(listPos, list32Bit));
additionalData.Insert(addtDataIndex, new Tuple<long, object, ushort>(listPos, list32Bit, 0));
}
addtDataIndex++;
return true;
Expand Down
4 changes: 2 additions & 2 deletions libMBIN/Source/NMS/Toolkit/TkMeshData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override object CustomDeserialize( BinaryReader reader, Type field, NMSAt
return null;
}

public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex)
public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object, ushort>> additionalData, ref int addtDataIndex)
{
var fieldName = fieldInfo.Name;
switch (fieldName)
Expand All @@ -54,7 +54,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie
writer.Write((Int32) (MeshDataStream?.Length ?? 0)); // size of data chunk in bytes
writer.Write((UInt32) 0xFEFEFE01);

additionalData.Insert(addtDataIndex, new Tuple<long, object>(listPos, fieldData));
additionalData.Insert(addtDataIndex, new Tuple<long, object, ushort>(listPos, fieldData, 0x4));
addtDataIndex++;
return true;
}
Expand Down
27 changes: 16 additions & 11 deletions libMBIN/Source/Template/NMSTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public int GetDataSize() {
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
var addt = new List<Tuple<long, object>>();
var addt = new List<Tuple<long, object, ushort>>();
int addtIdx = 0;

var prevState = isDebugLogTemplateEnabled;
Expand Down Expand Up @@ -583,7 +583,7 @@ public static List<T> DeserializeList<T>( BinaryReader reader, FieldInfo field,
return list;
}

public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldData, NMSAttribute settings, FieldInfo field, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex, UInt32 listEnding = 0xAAAAAA01 ) {
public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldData, NMSAttribute settings, FieldInfo field, ref List<Tuple<long, object, ushort>> additionalData, ref int addtDataIndex, UInt32 listEnding = 0xAAAAAA01 ) {
//Logger.LogDebug( $"{field?.DeclaringType.Name}.{field?.Name}\ttype:\t{fieldType.Name}\tadditionalData.Count:\t{additionalData?.Count ?? 0}\taddtDataIndex:\t{addtDataIndex}" );

if (CustomSerialize(writer, fieldType, fieldData, settings, field, ref additionalData, ref addtDataIndex)) return;
Expand Down Expand Up @@ -656,7 +656,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat
if ( listData == null ) break;
if ( listData.Count == 0 ) break;

var data = new Tuple<long, object>( listPos, listData );
var data = new Tuple<long, object, ushort>( listPos, listData, 0 );
if ( addtDataIndex >= additionalData.Count ) {
additionalData.Add( data );
} else {
Expand Down Expand Up @@ -689,7 +689,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat
throw new InvalidGUIDException(template);
}

var data = new Tuple<long, object>( refPos, template );
var data = new Tuple<long, object, ushort>( refPos, template, 0 );
if ( addtDataIndex >= additionalData.Count ) {
additionalData.Add( data );
} else {
Expand All @@ -712,7 +712,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat
writer.Write( listEnding );

var fieldValue = (NMS.VariableSizeString) fieldData;
additionalData.Insert( addtDataIndex++, new Tuple<long, object>( fieldPos, fieldValue ) );
additionalData.Insert( addtDataIndex++, new Tuple<long, object, ushort>( fieldPos, fieldValue, 0 ) );

} else if ( fieldType.IsArray ) {
var arrayType = fieldType.GetElementType();
Expand Down Expand Up @@ -754,7 +754,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat
}
}

public void AppendToWriter( BinaryWriter writer, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex, Type parent, UInt32 listEnding = 0xAAAAAA01 ) {
public void AppendToWriter( BinaryWriter writer, ref List<Tuple<long, object, ushort>> additionalData, ref int addtDataIndex, Type parent, UInt32 listEnding = 0xAAAAAA01 ) {
long templatePosition = writer.BaseStream.Position;
//Logger.LogDebug( $"[C] writing {GetType().Name} to offset 0x{templatePosition:X} (parent: {parent.Name})" );
var type = GetType();
Expand All @@ -777,7 +777,7 @@ public void AppendToWriter( BinaryWriter writer, ref List<Tuple<long, object>> a
}
}

public void SerializeGenericList( BinaryWriter writer, IList list, long listHeaderPosition, ref List<Tuple<long, object>> additionalData, int addtDataIndex, UInt32 listEnding )
public void SerializeGenericList( BinaryWriter writer, IList list, long listHeaderPosition, ref List<Tuple<long, object, ushort>> additionalData, int addtDataIndex, UInt32 listEnding )
// This serialises a List of NMSTemplate objects
{
writer.Align( 0x8, list.GetType().Name ); // Make sure that all c~ names are offset at 0x8. // make rel to listHeaderPosition?
Expand Down Expand Up @@ -814,7 +814,7 @@ public void SerializeGenericList( BinaryWriter writer, IList list, long listHead
entryOffsetNamePairs.Add( new KeyValuePair<long, string>( writer.BaseStream.Position, entryName) );

var template = (NMSTemplate) entry;
var listObjects = new List<Tuple<long, object>>(); // new list of objects so that this data is serialised first
var listObjects = new List<Tuple<long, object, ushort>>(); // new list of objects so that this data is serialised first
var addtData = new Dictionary<long, object>();
//Logger.LogDebug( $"[C] writing {template.GetType().Name} to offset 0x{writer.BaseStream.Position:X}" );
// pass the new listObject object in place of additionalData so that this branch is serialised before the whole layer
Expand Down Expand Up @@ -882,7 +882,7 @@ public void SerializeGenericList( BinaryWriter writer, IList list, long listHead
writer.BaseStream.Position = dataEndOffset;
}

public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosition, ref List<Tuple<long, object>> additionalData, int addtDataIndex, UInt32 listEnding = (UInt32) 0xAAAAAA01 ) {
public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosition, ref List<Tuple<long, object, ushort>> additionalData, int addtDataIndex, UInt32 listEnding = (UInt32) 0xAAAAAA01 ) {
// first thing we want to do is align the writer with the location of the first element of the list
if ( list.Count != 0 ) {
writer.Align( AlignOf(list[0].GetType()), list[0].GetType().Name );
Expand Down Expand Up @@ -917,7 +917,7 @@ public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosit
public byte[] SerializeBytes() {
using ( var stream = new MemoryStream() )
using ( var writer = new BinaryWriter( stream, Encoding.ASCII ) ) {
var additionalData = new List<Tuple<long, object>>();
var additionalData = new List<Tuple<long, object, ushort>>();

UInt32 listEnding = 0xAAAAAA01;

Expand Down Expand Up @@ -991,6 +991,11 @@ public byte[] SerializeBytes() {

} else if ( data.Item2.GetType() == typeof( byte[] ) ) {
// write the offset in the list header
// The 3rd item in the tuple is the alignment override.
// 0 indicates no override, but a non-zero value can be used to force an alignment.
if (data.Item3 > 0) {
writer.Align(data.Item3, data.Item2.GetType().Name);
}
long dataPosition = writer.BaseStream.Position;
writer.BaseStream.Position = data.Item1;
writer.Write( dataPosition - data.Item1 );
Expand Down Expand Up @@ -1551,7 +1556,7 @@ public virtual object CustomDeserialize( BinaryReader reader, Type field, NMSAtt
return null;
}

public virtual bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex)
public virtual bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List<Tuple<long, object, ushort>> additionalData, ref int addtDataIndex)
{
return false;
}
Expand Down

0 comments on commit fb64a74

Please sign in to comment.