Skip to content

Commit 4b7e6a9

Browse files
committed
added versioning
also some minor fixes to some tempates
1 parent 49f1eb2 commit 4b7e6a9

15 files changed

+1365
-670
lines changed

MBINCompiler/EXmlFile.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Globalization;
1+
using System;
2+
using System.Globalization;
23
using System.IO;
34
using System.Text;
45
using System.Threading;
@@ -80,6 +81,8 @@ public static string WriteTemplate(NMSTemplate template)
8081
using (var stringWriter = new EncodedStringWriter(Encoding.UTF8))
8182
using (var xmlTextWriter = XmlWriter.Create(stringWriter, xmlSettings))
8283
{
84+
string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
85+
xmlTextWriter.WriteComment(String.Format("File created using MBINCompiler version ({0})", ver.Substring(0, ver.Length - 2)));
8386
var data = template.SerializeEXml(false);
8487
Serializer.Serialize(xmlTextWriter, data, Namespaces);
8588
xmlTextWriter.Flush();

MBINCompiler/MBINCompiler.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<Compile Include="Models\Structs\GcPlanetSize.cs" />
117117
<Compile Include="Models\Structs\TkInstanceWindComponentData.cs" />
118118
<Compile Include="Models\Structs\GcGalaxyVoxelAttributesData.cs" />
119+
<Compile Include="Models\Structs\TkListedPaletteTexture.cs" />
119120
<Compile Include="Models\Structs\TkProceduralModelList.cs" />
120121
<Compile Include="Models\Structs\TkRandomComponentData.cs" />
121122
<Compile Include="Models\Structs\TkVolumeTriggerType.cs" />
@@ -642,6 +643,7 @@
642643
<Compile Include="Models\Structs\Unfinished\GcAISpaceshipGlobals.cs" />
643644
<Compile Include="Models\Structs\Unfinished\GcCameraGlobals.cs" />
644645
<Compile Include="Models\Structs\Unfinished\GcPlayerGlobals.cs" />
646+
<Compile Include="Models\Structs\Unfinished\GcPlayerGlobals_old.cs" />
645647
<Compile Include="Models\Structs\Unfinished\GcUIGlobals.cs" />
646648
<Compile Include="Models\Structs\Unfinished\GcCreatureGlobals.cs" />
647649
<Compile Include="Models\Structs\Unfinished\GcAudioGlobals.cs" />
@@ -671,6 +673,7 @@
671673
<Compile Include="Models\Structs\GcPlayerSpaceshipWarpData.cs" />
672674
<Compile Include="Models\Structs\Unused\GcPlayerStickData.cs" />
673675
<Compile Include="Models\Structs\Unused\GcSpaceshipTravelData.cs" />
676+
<Compile Include="Models\Structs\Unused\GcTerrainOverlyColours.cs" />
674677
<Compile Include="Models\Structs\VariableSizeString.cs" />
675678
<Compile Include="Models\Structs\Vector2f.cs" />
676679
<Compile Include="Models\Structs\Vector3i.cs" />

MBINCompiler/MBINFile.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,27 @@ public MBINFile(Stream stream, bool keepOpen = false)
3030
_keepOpen = keepOpen;
3131
}
3232

33-
public bool Load()
33+
public bool Load(bool getVersion = false)
3434
{
3535
_io.Stream.Position = 0;
3636
Header = (MBINHeader)NMSTemplate.DeserializeBinaryTemplate(_io.Reader, "MBINHeader");
37+
if (getVersion)
38+
{
39+
string mbinVer = Header.Tag;
40+
Console.WriteLine(mbinVer.Substring(8));
41+
}
42+
else
43+
{
44+
if (Header.Tag.Contains("MBIN")) // check whether the file has been generated by MBINCompiler basically
45+
{
46+
string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
47+
if (Header.Tag != String.Format("MBINCver{0}", ver.Substring(0, ver.Length - 2)))
48+
{
49+
Console.WriteLine("Incorrect version");
50+
return false;
51+
}
52+
}
53+
}
3754
return true;
3855
}
3956

MBINCompiler/Models/MBINHeader.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
2+
using System.Reflection;
23

34
namespace MBINCompiler.Models
45
{
56
public class MBINHeader : NMSTemplate
67
{
78
public uint Magic; // can be 0xCCCCCCCC, or 0xDDDDDDDD for MBIN.PC files, probably used to seperate PC files from PS4
89
public int Version; // seems to be a version field, game checks this under certain conditions to make sure it's equal to 2500
9-
public long BuildDateTime; // 0x0 for most files, 0xFFFF.. for TkGeometryData files, timestamp eg. 201607201542 (decimal) on global files and older MBINs, likely removed the code that set it at some stage
10-
public long TemplateGUID; // seems to be unique across templates (files using the same template share the same GUID)
10+
//public long BuildDateTime; // 0x0 for most files, 0xFFFF.. for TkGeometryData files, timestamp eg. 201607201542 (decimal) on global files and older MBINs, likely removed the code that set it at some stage
11+
//public long TemplateGUID; // seems to be unique across templates (files using the same template share the same GUID)
12+
[NMS(Size = 0x10)]
13+
public string Tag;
1114

1215
[NMS(Size = 0x40)]
1316
public string TemplateName;
@@ -28,8 +31,10 @@ public void SetDefaults()
2831
Version = 2500;
2932

3033
// these two values aren't checked, so we can set them to whatever we like
31-
BuildDateTime = 0x706D6F434E49424D;
32-
TemplateGUID = 0x302E3172656C69;
34+
//BuildDateTime = 0x706D6F434E49424D;
35+
//TemplateGUID = 0x302E3172656C69;
36+
string ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
37+
Tag = String.Format("MBINCver{0}", ver.Substring(0, ver.Length - 2));
3338

3439
TemplateName = string.Empty;
3540
Padding58 = ulong.Parse($"{DateTime.Now:yyyyMMddhhmm}"); // may as well make use of this field too

MBINCompiler/Models/NMSTemplate.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ public static NMSTemplate DeserializeBinaryTemplate(BinaryReader reader, string
164164

165165
NMSTemplate obj = TemplateFromName(templateName);
166166

167-
//using (System.IO.StreamWriter file =
168-
// new System.IO.StreamWriter(@"T:\mbincompiler_debug.txt", true))
169-
//{
170-
// file.WriteLine("Deserializing Template: " + templateName);
171-
//}
167+
/*using (System.IO.StreamWriter file =
168+
new System.IO.StreamWriter(@"T:\mbincompiler_debug.txt", true))
169+
{
170+
file.WriteLine("Deserializing Template: " + templateName);
171+
}*/
172172

173-
//Console.WriteLine("Gk Hack: " + "Deserializing Template: " + templateName);
173+
Console.WriteLine("Gk Hack: " + "Deserializing Template: " + templateName);
174174

175175
if (obj == null)
176176
return null;
@@ -195,14 +195,14 @@ public static NMSTemplate DeserializeBinaryTemplate(BinaryReader reader, string
195195
{
196196
NMSAttribute settings = field.GetCustomAttribute<NMSAttribute>();
197197
field.SetValue(obj, DeserializeValue(reader, field.FieldType, settings, templatePosition, field, obj));
198-
//Console.WriteLine("Gk Hack: " + templateName + " Deserialized Value: " + field.Name + " value: " + field.GetValue(obj));
199-
//Console.WriteLine($"{templateName} position: 0x{reader.BaseStream.Position:X}");
200-
//using (System.IO.StreamWriter file =
201-
// new System.IO.StreamWriter(@"T:\mbincompiler_debug.txt", true))
202-
//{
203-
// file.WriteLine(" Deserialized Value: " + field.Name + " value: " + field.GetValue(obj));
204-
// file.WriteLine($"{templateName} position: 0x{templatePosition:X}");
205-
//}
198+
Console.WriteLine("Gk Hack: " + templateName + " Deserialized Value: " + field.Name + " value: " + field.GetValue(obj));
199+
Console.WriteLine($"{templateName} position: 0x{reader.BaseStream.Position:X}");
200+
/*using (System.IO.StreamWriter file =
201+
new System.IO.StreamWriter(@"T:\mbincompiler_debug.txt", true))
202+
{
203+
file.WriteLine(" Deserialized Value: " + field.Name + " value: " + field.GetValue(obj));
204+
file.WriteLine($"{templateName} position: 0x{reader.BaseStream.Position:X}");
205+
}*/
206206
}
207207

208208

MBINCompiler/Models/Structs/GcOutpostLSystemPair.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class GcOutpostLSystemPair : NMSTemplate // 0x320 bytes
44
{
55
[NMS(Size = 0x20)]
66
public string Locator;
7-
[NMS(Size = 6)]
7+
[NMS(Size = 7)]
88
public NMSString0x80[] LSystems;
99
}
1010
}

MBINCompiler/Models/Structs/GcPlanetData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class GcPlanetData : NMSTemplate
3535
public string TerrainFile;
3636
public TkVoxelGeneratorData Terrain;
3737
[NMS(Size = 0xA)]
38-
public TkPaletteTexture[] TileTypes;
38+
public TkListedPaletteTexture[] TileTypes;
3939
[NMS(Size = 0x80)]
4040
public string DiffuseTexture;
4141
[NMS(Size = 0x80)]

MBINCompiler/Models/Structs/GcPlayerStateData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public class GcPlayerStateData : NMSTemplate
3131

3232
/* 0x003D8 */ public GcExactResource CurrentWeapon;
3333

34-
/* 0x00468 */ public List<string> KnownTech;
35-
/* 0x00478 */ public List<string> KnownProducts;
34+
/* 0x00468 */ public List<NMSString0x10> KnownTech;
35+
/* 0x00478 */ public List<NMSString0x10> KnownProducts;
3636

3737
/* 0x00488 */ public List<GcWordKnowledge> KnownWords;
3838

MBINCompiler/Models/Structs/GcTerrainControls.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class GcTerrainControls : NMSTemplate
99
[NMS(Size = 7, EnumValue = new[] { "River", "Crater", "Arches", "ArchesSmall", "Blobs", "BlobsSmall", "Substance" })]
1010
public float[] Features;
1111

12+
// Caves should be an Enum like the ones above but just with one value...
1213
public float UndergroundCaves;
1314
public float WaterActiveFrequency;
1415
public float HighWaterActiveFrequency;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace MBINCompiler.Models.Structs
2+
{
3+
public class TkListedPaletteTexture : NMSTemplate
4+
{
5+
public int Palette;
6+
public string[] PaletteValues()
7+
{
8+
return new[]
9+
{
10+
"Grass", "Plant", "Leaf", "Wood", "Rock", "Stone", "Crystal", "Sand",
11+
"Dirt", "Metal", "Paint", "Plastic", "Fur", "Scale", "Feather", "Water",
12+
"Cloud", "Sky", "Space", "Underbelly", "Undercoat", "Snow", "SkyHorizon", "SkyFog",
13+
"SkyHeightFog", "SkySunset", "SkyNight", "WaterNear", "SpaceCloud", "SpaceBottom", "SpaceSolar", "SpaceLight",
14+
"Warrior", "Scientific", "Trader", "WarriorAlt", "ScientificAlt", "TraderAlt", "RockSaturated", "RockLight", "RockDark"
15+
};
16+
}
17+
18+
public int ColourAlt;
19+
public string[] ColourAltValues()
20+
{
21+
return new[] { "Primary", "Alternative1", "Alternative2", "Alternative3", "Alternative4", "Unique", "MatchGround", "None" };
22+
}
23+
24+
[NMS(Size = 0x4, Ignore = true)]
25+
public byte[] padding0x8; // this is needed when it is in a list... but not when it isn't...
26+
}
27+
}

0 commit comments

Comments
 (0)