Skip to content

Commit d6dda52

Browse files
committed
Improved compatibility with earlier DBPF index formats
1 parent 9772abb commit d6dda52

12 files changed

Lines changed: 153 additions & 72 deletions

File tree

MorcuTool/App.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<startup>
4-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
55
</startup>
6-
</configuration>
6+
</configuration>

MorcuTool/MorcuTool.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>MorcuTool</RootNamespace>
1111
<AssemblyName>MorcuTool</AssemblyName>
12-
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<TargetFrameworkProfile />
1516
</PropertyGroup>
1617
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1718
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -108,6 +109,7 @@
108109
<Compile Include="Properties\Resources.Designer.cs">
109110
<AutoGen>True</AutoGen>
110111
<DependentUpon>Resources.resx</DependentUpon>
112+
<DesignTime>True</DesignTime>
111113
</Compile>
112114
<EmbeddedResource Include="src\Forms\MSGtexteditor.resx">
113115
<DependentUpon>MSGtexteditor.cs</DependentUpon>

MorcuTool/Properties/Resources.Designer.cs

Lines changed: 18 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MorcuTool/Properties/Settings.Designer.cs

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MorcuTool/global.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public enum TypeID : uint
1616
{
1717

1818
RMDL_MSK = 0xF9E50586, //"ModelData" very accomodating of the gamecube/wii gpu and uses many of its display list conventions
19-
RMDL_MSA = 0x2954E734,
19+
RMDL_MSA = 0x2954E734,
20+
WMDL_MSPC = 0xB359C791, //WindowsModel instead of RevoModel?
2021
MATD_MSK = 0x01D0E75D, //"MaterialData"
2122
MATD_MSA = 0xE6640542,
2223
TPL_MSK = 0x00B2D882, //"TextureData" very similar to Nintendo tpl (just has a different header)
@@ -67,6 +68,7 @@ public enum TypeID : uint
6768
LIGHTSETXML_MS = 0x50182640, //Light set XML MySims
6869
LIGHTSETBIN_MSK = 0x50002128, //"LightSetData"
6970
XML_MS = 0xdc37e964,
71+
XML2_MS = 0x6d3e3fb4,
7072
OBJECTCONSTRUCTIONXML_MS = 0xc876c85e,
7173
OBJECTCONSTRUCTIONBIN_MS = 0xc08ec0ee,
7274
SLOTXML_MS = 0x4045d294,

MorcuTool/src/FileTypes/Model/RevoModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ public Face AddAttrToFace(byte[] filebytes, int pos, VertexAttributeArrayType at
738738
case 3: f.vt4 = Utility.ReadUInt16BigEndian(filebytes, pos); pos += 2; break;
739739
}
740740
break;
741-
case VertexAttributeArrayType.GX_VA_TEX1:
741+
case VertexAttributeArrayType.GX_VA_TEX1:
742742
pos += 2; //skip for now until multiple UVs are implemented
743743
break;
744744
case VertexAttributeArrayType.GX_VA_TEX2:

MorcuTool/src/FileTypes/Package.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,15 @@ public void LoadPackage()
218218

219219
newSubfile.typeID = reader.ReadUInt32();
220220
newSubfile.groupID = reader.ReadUInt32();
221-
newSubfile.hash = (ulong)(reader.ReadUInt32()) << 32;
222-
newSubfile.hash |= (ulong)(reader.ReadUInt32());
223-
224-
newSubfile.fileoffset = reader.ReadUInt32();
221+
reader.BaseStream.Position += 8;
222+
223+
newSubfile.fileoffset = reader.ReadUInt32();
225224
newSubfile.filesize = reader.ReadUInt32() & 0x7FFFFFFF;
226225
newSubfile.uncompressedsize = reader.ReadUInt32();
227226
reader.BaseStream.Position += 0x04; //flags
228227

228+
newSubfile.hash = (ulong)newSubfile.fileoffset;
229+
229230
if (newSubfile.filesize == newSubfile.uncompressedsize)
230231
{
231232
newSubfile.uncompressedsize = 0;
@@ -402,6 +403,10 @@ public void LoadPackage()
402403
fileextension = ".rmdl"; // "ModelData"
403404
break;
404405

406+
case global.TypeID.WMDL_MSPC: //WMDL MySims PC
407+
fileextension = ".wmdl";
408+
break;
409+
405410
case global.TypeID.MATD_MSA: //MATD MSA
406411
fileextension = ".matd"; //TYPE ID E6 64 05 42
407412
break;
@@ -595,6 +600,10 @@ public void LoadPackage()
595600
fileextension = ".xml";
596601
break;
597602

603+
case global.TypeID.XML2_MS: //another xml
604+
fileextension = ".xml2";
605+
break;
606+
598607
case global.TypeID.FPST_MS: //footprint set MySims
599608
fileextension = ".footprintSet";
600609
break;

MorcuTool/src/FileTypes/Subfiles/MaterialData.cs

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace MorcuTool
99
public class MaterialData
1010
{
1111
public string filename;
12+
1213

1314
public List<Param> parameters = new List<Param>();
1415
public enum MaterialParameter : uint {
@@ -37,12 +38,22 @@ public class Param {
3738
public Subfile diffuse_texture;
3839

3940

40-
public Param(byte[] bytes, int pos) {
41+
public Param(byte[] bytes, int pos, bool useBigEndian) {
4142

42-
paramType = (MaterialParameter)Utility.ReadInt32BigEndian(bytes, pos); pos += 4;
43-
unk = Utility.ReadInt32BigEndian(bytes, pos); pos += 4;
44-
dataSizeDividedBy4 = Utility.ReadInt32BigEndian(bytes, pos); pos += 4;
45-
dataOffset = Utility.ReadInt32BigEndian(bytes, pos);
43+
if (useBigEndian)
44+
{
45+
paramType = (MaterialParameter)Utility.ReadInt32BigEndian(bytes, pos); pos += 4;
46+
unk = Utility.ReadInt32BigEndian(bytes, pos); pos += 4;
47+
dataSizeDividedBy4 = Utility.ReadInt32BigEndian(bytes, pos); pos += 4;
48+
dataOffset = Utility.ReadInt32BigEndian(bytes, pos);
49+
}
50+
else {
51+
paramType = (MaterialParameter)BitConverter.ToInt32(bytes, pos); pos += 4;
52+
unk = BitConverter.ToInt32(bytes, pos); pos += 4;
53+
dataSizeDividedBy4 = BitConverter.ToInt32(bytes, pos); pos += 4;
54+
dataOffset = BitConverter.ToInt32(bytes, pos);
55+
}
56+
4657
}
4758
}
4859

@@ -51,21 +62,44 @@ public MaterialData(Subfile basis)
5162
parameters = new List<Param>();
5263
filename = basis.filename;
5364

54-
int pos = 0x10;
65+
int pos = 0x04;
66+
67+
bool useBigEndian = false;
68+
69+
if (Utility.ReadInt32BigEndian(basis.filebytes, pos) == 0x01)
70+
{
71+
//msk and msa; subsequent data is big-endian
72+
pos = 0x10;
73+
useBigEndian = true;
74+
}
75+
else {
76+
//mysims; subsequent data is little-endian
77+
pos = 0x40; //while it doesn't look like it, MySims MATD files start with 0x2C of extra data, even before the MATD magic. So in total there are 0x40 bytes before the actual data start (including 4 extra ones just after the MATD magic)
78+
useBigEndian = false;
79+
}
5580

5681
// a lot of the offsets are measured from 0x10
5782

5883
//now read the parameters!
5984

6085
pos += 0x08;
86+
int lengthOfDataSection;
87+
int numberOfParams;
6188

62-
int lengthOfDataSection = Utility.ReadInt32BigEndian(basis.filebytes,pos); pos += 4;
63-
int numberOfParams = Utility.ReadInt32BigEndian(basis.filebytes, pos); pos += 4;
89+
if (useBigEndian)
90+
{
91+
lengthOfDataSection = Utility.ReadInt32BigEndian(basis.filebytes, pos); pos += 4;
92+
numberOfParams = Utility.ReadInt32BigEndian(basis.filebytes, pos); pos += 4;
93+
}
94+
else {
95+
lengthOfDataSection = BitConverter.ToInt32(basis.filebytes, pos); pos += 4;
96+
numberOfParams = BitConverter.ToInt32(basis.filebytes, pos); pos += 4;
97+
}
6498

6599
//now the param list begins. Each param has 0x10 bytes describing it, with an offset to later in the file (falling within the data section, but measured from 0x10)
66100

67101
for (int i = 0; i < numberOfParams; i++) {
68-
parameters.Add(new Param(basis.filebytes,pos));
102+
parameters.Add(new Param(basis.filebytes,pos,useBigEndian));
69103
pos += 0x10;
70104
}
71105

@@ -77,13 +111,20 @@ public MaterialData(Subfile basis)
77111

78112
switch (parameter.paramType) {
79113
case MaterialParameter.diffuseMap:
80-
ulong hash_of_diffuse_texture = (ulong)Utility.ReadUInt32BigEndian(basis.filebytes,pos); pos += 4;
81-
hash_of_diffuse_texture |= ((ulong)Utility.ReadUInt32BigEndian(basis.filebytes, pos)) << 32; pos += 4;
82-
if (hash_of_diffuse_texture == 0x58CC31A1AC11E901) {
83-
Console.WriteLine("Here it is!!");
114+
ulong hash_of_diffuse_texture;
115+
uint typeID_of_diffuse_texture;
116+
117+
if (useBigEndian)
118+
{
119+
hash_of_diffuse_texture = (ulong)Utility.ReadUInt32BigEndian(basis.filebytes, pos); pos += 4;
120+
hash_of_diffuse_texture |= ((ulong)Utility.ReadUInt32BigEndian(basis.filebytes, pos)) << 32; pos += 4;
121+
typeID_of_diffuse_texture = Utility.ReadUInt32BigEndian(basis.filebytes, pos); pos += 4;
122+
}
123+
else {
124+
hash_of_diffuse_texture = (ulong)BitConverter.ToUInt32(basis.filebytes, pos); pos += 4;
125+
hash_of_diffuse_texture |= ((ulong)BitConverter.ToUInt32(basis.filebytes, pos)) << 32; pos += 4;
126+
typeID_of_diffuse_texture = BitConverter.ToUInt32(basis.filebytes, pos); pos += 4;
84127
}
85-
86-
uint typeID_of_diffuse_texture = Utility.ReadUInt32BigEndian(basis.filebytes, pos); pos += 4;
87128

88129
parameter.diffuse_texture = global.activePackage.FindFileByHashAndTypeID(hash_of_diffuse_texture,typeID_of_diffuse_texture);
89130
break;

MorcuTool/src/FileTypes/Subfiles/MaterialSet.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ public class MaterialSet
1212

1313
public MaterialSet(Subfile basis) {
1414

15-
int number_of_materials = Utility.ReadInt32BigEndian(basis.filebytes,0x0C);
15+
bool useBigEndian = true;
16+
int start = 0x00;
1617

18+
if (basis.filebytes[0] == 0x01) {
19+
useBigEndian = false;
20+
return; //Processing these MTSTs not yet implemented
21+
}
22+
23+
int number_of_materials = Utility.ReadInt32BigEndian(basis.filebytes, start + 0x0C);
24+
1725
List<ulong> hashes = new List<ulong>();
1826

1927
for (int i = 0; i < number_of_materials; i++) {
20-
hashes.Add(Utility.ReadUInt64BigEndian(basis.filebytes, 0x18 + (i * 8)));
28+
hashes.Add(Utility.ReadUInt64BigEndian(basis.filebytes, start + 0x18 + (i * 8)));
2129
}
2230

2331
foreach (Subfile s in global.activePackage.subfiles) {

0 commit comments

Comments
 (0)