Skip to content

Commit

Permalink
fixed some globals and more alignment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyman192 committed Oct 23, 2018
1 parent f01d302 commit 0eed756
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion libMBIN/Source/NMS/Globals/GcGraphicsGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace libMBIN.NMS.Globals
{
[NMS( GUID = 0xA2939C8D2780E13C )]
[NMS( GUID = 0xA308C69BDD3DA959)]
public class GcGraphicsGlobals : NMSTemplate
{
/* 0x0 */ public float LUTDistanceFlightMultiplier;
Expand Down
2 changes: 2 additions & 0 deletions libMBIN/Source/NMS/Globals/GcSolarGenerationGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public class GcSolarGenerationGlobals : NMSTemplate
[NMS(Size = 0x7)]
/* 0x1C4 */ public GcAISpaceshipWeightingData[] SpaceshipWeightings;
/* 0x288 */ public float PlanetRingProbability;
[NMS(Size = 0x4, Ignore = true)]
/* 0x28C */ public byte[] Padding28C;
/* 0x290 */ public GcPlanetRingData PlanetRingsMin;
/* 0x2F0 */ public GcPlanetRingData PlanetRingsMax;
}
Expand Down
41 changes: 21 additions & 20 deletions libMBIN/Source/NMS/Globals/GcUIGlobals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace libMBIN.NMS.Globals
{
[NMS( GUID = 0xD25256FB1959D22E )]
[NMS( GUID = 0x6657BC76B6378C31)]
public class GcUIGlobals : NMSTemplate
{
/* 0x0 */ public bool LoadPagesFromMetadataCache;
Expand Down Expand Up @@ -204,25 +204,26 @@ public class GcUIGlobals : NMSTemplate
/* 0x7BC */ public float ConsoleTextTimeMin;
/* 0x7C0 */ public float ConsoleTextTimeMax;
/* 0x7C4 */ public float HoverOffscreenBorder;
/* 0x7C8 */ public float TimedEventLookTime;
/* 0x7CC */ public float DamageImpactMergeTime;
/* 0x7D0 */ public float DamageImpactTimeBetweenNumbers;
/* 0x7D4 */ public float DamageImpactMinDistance;
/* 0x7D8 */ public float DamagePerSecondSampleTime;
/* 0x7DC */ public float DamageNumberTime;
/* 0x7E0 */ public float DamageNumberSizeInShip;
/* 0x7E4 */ public float DamageNumberSize;
/* 0x7E8 */ public float DamageNumberSizeCritMultiplier;
/* 0x7EC */ public float DamageNumberBlackAlpha;
/* 0x7F0 */ public float DamageNumberOutline;
/* 0x7F4 */ public float DamageNumberOutline2;
/* 0x7F8 */ public float DamageNumberOffsetX;
/* 0x7FC */ public float DamageNumberOffsetY;
/* 0x800 */ public Vector2f DamageNumberSideSpeed;
/* 0x808 */ public float DamageNumberFadeIn;
/* 0x80C */ public float DamageNumberFadeOut;
/* 0x810 */ public float DamageNumberUpOffset;
/* 0x814 */ public TkCurveType DamageNumberUpCurve;
/* 0x7C8 */ public float TransferSendOffscreenBorder;
/* 0x7CC */ public float TimedEventLookTime;
/* 0x7D0 */ public float DamageImpactMergeTime;
/* 0x7D4 */ public float DamageImpactTimeBetweenNumbers;
/* 0x7D8 */ public float DamageImpactMinDistance;
/* 0x7DC */ public float DamagePerSecondSampleTime;
/* 0x7E0 */ public float DamageNumberTime;
/* 0x7E4 */ public float DamageNumberSizeInShip;
/* 0x7E8 */ public float DamageNumberSize;
/* 0x7EC */ public float DamageNumberSizeCritMultiplier;
/* 0x7F0 */ public float DamageNumberBlackAlpha;
/* 0x7F4 */ public float DamageNumberOutline;
/* 0x7F8 */ public float DamageNumberOutline2;
/* 0x7FC */ public float DamageNumberOffsetX;
/* 0x800 */ public float DamageNumberOffsetY;
/* 0x804 */ public Vector2f DamageNumberSideSpeed;
/* 0x80C */ public float DamageNumberFadeIn;
/* 0x810 */ public float DamageNumberFadeOut;
/* 0x814 */ public float DamageNumberUpOffset;
/* 0x818 */ public TkCurveType DamageNumberUpCurve;
/* 0x820 */ public Colour DamageNumberCriticalColour;

/* 0x830 */ public Colour DamageNumberIneffectiveColour;
Expand Down
2 changes: 1 addition & 1 deletion libMBIN/Source/NMS/Toolkit/TkImGuiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace libMBIN.NMS.Toolkit
{
[NMS(Size = 0x190, GUID = 0x70F15FEDCAE3687B)]
[NMS(Size = 0x190, Alignment = 0x10, GUID = 0x70F15FEDCAE3687B)]
public class TkImGuiSettings : NMSTemplate
{
public Colour BackgroundColour;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace libMBIN.NMS.Toolkit
{
[NMS(Size = 0x60, GUID = 0x8B752B493C2190FA)]
[NMS(Size = 0x60, Alignment = 0x10, GUID = 0x8B752B493C2190FA)]
public class TkProceduralTextureChosenOption : NMSTemplate
{
[NMS(Size = 0x10)]
Expand Down
23 changes: 18 additions & 5 deletions libMBIN/Source/Template/NMSTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public static object DeserializeValue(BinaryReader reader, Type field, NMSAttrib
if (template != null)
return template;

// TODO: change fieldType to fieldName...
var fieldType = field.Name;
switch (fieldType)
{
Expand Down Expand Up @@ -212,7 +213,8 @@ public static object DeserializeValue(BinaryReader reader, Type field, NMSAttrib
}
else
{
reader.Align(0x4, templatePosition);
int alignment = field.GetCustomAttribute<NMSAttribute>()?.Alignment ?? 0x4;
reader.Align(alignment, templatePosition);
var data = DeserializeBinaryTemplate(reader, fieldType);
return data;
}
Expand Down Expand Up @@ -444,7 +446,16 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat
break;

case "NMSTemplate":
writer.Align( 8, startStructPos);
int template_alignment = settings?.Alignment ?? 0x4;

if (template_alignment == 0x4)
{
writer.Align(8, startStructPos);
}
else
{
writer.Align(template_alignment, startStructPos);
}
long refPos = writer.BaseStream.Position;

var template = (NMSTemplate) fieldData;
Expand Down Expand Up @@ -491,17 +502,17 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat
var realObj = obj;
if ( realObj == null ) realObj = Activator.CreateInstance( arrayType );

SerializeValue( writer, realObj.GetType(), realObj, settings, field, fieldPos, ref additionalData, ref addtDataIndex, structLength, listEnding );
SerializeValue( writer, realObj.GetType(), realObj, realObj.GetType().GetCustomAttribute<NMSAttribute>(), field, startStructPos, ref additionalData, ref addtDataIndex, structLength, listEnding );
}
} else if ( fieldType.IsEnum ) {
writer.Align(4, startStructPos);
writer.Write((int)Enum.Parse(field.FieldType, fieldData.ToString()));

} else if ( fieldType.BaseType == typeof( NMSTemplate ) ) {
int alignment = settings?.Alignment ?? 0x4; // this isn't 0x10 for Colour's??
writer.Align(alignment, startStructPos);
var realData = (NMSTemplate) fieldData;
if ( realData == null ) realData = (NMSTemplate) Activator.CreateInstance( fieldType );
int alignment = realData.GetType().GetCustomAttribute<NMSAttribute>()?.Alignment ?? 0x4;
writer.Align(alignment, startStructPos);
realData.AppendToWriter( writer, ref additionalData, ref addtDataIndex, GetType(), listEnding );

} else {
Expand Down Expand Up @@ -668,6 +679,8 @@ public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosit

foreach ( var entry in list ) {
DebugLogTemplate( $"[C] writing {entry.GetType().Name} to offset 0x{writer.BaseStream.Position:X}" );
int alignment = entry.GetType().GetCustomAttribute<NMSAttribute>()?.Alignment ?? 0x4;
writer.Align(alignment, 0);
SerializeValue( writer, entry.GetType(), entry, null, null, listPosition, ref additionalData, ref addtDataIndexThis, 0, listEnding );
}

Expand Down
2 changes: 1 addition & 1 deletion libMBIN/Source/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class Version {
// the Prerelease version should be reset to 1
// When the Release version is incremented:
// the Prerelease version should be reset to 0
internal const string VERSION_STRING = "1.65.0.1";
internal const string VERSION_STRING = "1.65.0.2";

/// <summary>Shorthand for AssemblyVersion.Major</summary>
public static int Major => AssemblyVersion.Major;
Expand Down

0 comments on commit 0eed756

Please sign in to comment.