Skip to content

Commit 63a9cac

Browse files
OlivercometOlivercomet
authored andcommitted
Beginnings of a package rebuilder
1 parent ea7d1a7 commit 63a9cac

10 files changed

Lines changed: 531 additions & 15 deletions

File tree

MorcuTool/MorcuTool.csproj

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@
4646
<Reference Include="System.Xml" />
4747
</ItemGroup>
4848
<ItemGroup>
49+
<Compile Include="src\Forms\SavePackageForm.cs">
50+
<SubType>Form</SubType>
51+
</Compile>
52+
<Compile Include="src\Forms\SavePackageForm.Designer.cs">
53+
<DependentUpon>SavePackageForm.cs</DependentUpon>
54+
</Compile>
4955
<Compile Include="src\FileTypes\Model\face.cs" />
50-
<Compile Include="Form1.cs">
56+
<Compile Include="src\Forms\Form1.cs">
5157
<SubType>Form</SubType>
5258
</Compile>
53-
<Compile Include="Form1.Designer.cs">
59+
<Compile Include="src\Forms\Form1.Designer.cs">
5460
<DependentUpon>Form1.cs</DependentUpon>
5561
</Compile>
5662
<Compile Include="global.cs" />
@@ -63,7 +69,7 @@
6369
<Compile Include="src\Utility\utility.cs" />
6470
<Compile Include="src\FileTypes\Vault.cs" />
6571
<Compile Include="src\FileTypes\Model\Vertex.cs" />
66-
<EmbeddedResource Include="Form1.resx">
72+
<EmbeddedResource Include="src\Forms\Form1.resx">
6773
<DependentUpon>Form1.cs</DependentUpon>
6874
</EmbeddedResource>
6975
<EmbeddedResource Include="Properties\Resources.resx">
@@ -75,6 +81,9 @@
7581
<AutoGen>True</AutoGen>
7682
<DependentUpon>Resources.resx</DependentUpon>
7783
</Compile>
84+
<EmbeddedResource Include="src\Forms\SavePackageForm.resx">
85+
<DependentUpon>SavePackageForm.cs</DependentUpon>
86+
</EmbeddedResource>
7887
<None Include="Properties\Settings.settings">
7988
<Generator>SettingsSingleFileGenerator</Generator>
8089
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -88,9 +97,7 @@
8897
<ItemGroup>
8998
<None Include="App.config" />
9099
</ItemGroup>
91-
<ItemGroup>
92-
<Folder Include="src\Forms\" />
93-
</ItemGroup>
100+
<ItemGroup />
94101
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
95102
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
96103
Other similar extension points exist, see Microsoft.Common.targets.

MorcuTool/src/FileTypes/Package.cs

Lines changed: 144 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class Package
3939
public uint reserved1 = 0x00;
4040
public uint reserved2 = 0x00;
4141

42+
uint MSKindexversion = 0x00;
43+
4244
public List<IndexEntry> IndexEntries = new List<IndexEntry>();
4345
public ulong indexnumberofentries = 0x00;
4446

@@ -203,9 +205,9 @@ public void LoadPackage()
203205
}
204206
else //MySims and MySims Kingdom use these
205207
{
206-
uint indexversion = reader.ReadUInt32();
208+
MSKindexversion = reader.ReadUInt32();
207209

208-
if (indexversion == 0)
210+
if (MSKindexversion == 0)
209211
{
210212
Console.WriteLine("index version 0");
211213
for (uint i = 0; i < filecount; i++)
@@ -228,12 +230,12 @@ public void LoadPackage()
228230
subfiles.Add(newSubfile);
229231
}
230232
}
231-
else if (indexversion == 1)
233+
else if (MSKindexversion == 1)
232234
{
233235
MessageBox.Show("Index version 1 not implemented!");
234236

235237
}
236-
else if (indexversion == 2)
238+
else if (MSKindexversion == 2)
237239
{
238240
Console.WriteLine("index version 2");
239241

@@ -259,7 +261,7 @@ public void LoadPackage()
259261
subfiles.Add(newSubfile);
260262
}
261263
}
262-
else if (indexversion == 3)
264+
else if (MSKindexversion == 3)
263265
{
264266
Console.WriteLine("index version 3");
265267
uint allFilesTypeID = reader.ReadUInt32();
@@ -284,7 +286,7 @@ public void LoadPackage()
284286
subfiles.Add(newSubfile);
285287
}
286288
}
287-
if (indexversion == 4)
289+
if (MSKindexversion == 4)
288290
{
289291
Console.WriteLine("index version 4");
290292
reader.BaseStream.Position += 4;
@@ -309,7 +311,7 @@ public void LoadPackage()
309311
}
310312
else
311313
{
312-
MessageBox.Show("Unknown index version: "+indexversion);
314+
MessageBox.Show("Unknown index version: "+ MSKindexversion);
313315
return;
314316
}
315317
}
@@ -787,6 +789,141 @@ public void LoadSkyHeroesPackage()
787789
}
788790

789791
MessageBox.Show("Files extracted. They are in the same folder as the original archive.", "Extraction complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
792+
}
793+
794+
795+
public uint ReverseEndianIfNeeded(uint input) {
796+
if (packageType == PackageType.Agents)
797+
{
798+
input = utility.ReverseEndian(input);
799+
}
800+
return input;
801+
}
802+
803+
804+
public void RebuildPackage()
805+
{
806+
807+
List<byte> output = new List<byte>();
808+
809+
uint packageVersion = 0;
810+
811+
if (packageType == PackageType.Kingdom)
812+
{
813+
output.Add((byte)'D');
814+
output.Add((byte)'B');
815+
output.Add((byte)'P');
816+
output.Add((byte)'F');
817+
packageVersion = 2;
818+
}
819+
else if(packageType == PackageType.Agents)
820+
{
821+
output.Add((byte)'F');
822+
output.Add((byte)'P');
823+
output.Add((byte)'B');
824+
output.Add((byte)'D');
825+
packageVersion = 3;
826+
}
827+
828+
//offset 0x04
829+
830+
utility.AddUIntToList(output, ReverseEndianIfNeeded(packageVersion));
831+
832+
//offset 0x08
833+
834+
for (int i = 0; i < 0x10; i++)
835+
{
836+
output.Add(0x00);
837+
}
838+
839+
//offset 0x18
840+
841+
if (packageType == PackageType.Kingdom)
842+
{
843+
for (int i = 0; i < 8; i++)
844+
{
845+
output.Add(0x00); //pad
846+
}
847+
}
848+
else if (packageType == PackageType.Agents)
849+
{
850+
utility.AddLongToList(output, utility.ReverseEndianLong(DateTime.Now.ToBinary()));
851+
}
852+
853+
utility.AddUIntToList(output, ReverseEndianIfNeeded(indexmajorversion));
854+
855+
utility.AddUIntToList(output, ReverseEndianIfNeeded(filecount));
856+
857+
//offset 0x28
858+
859+
if (packageType == PackageType.Kingdom)
860+
{
861+
for (int i = 0; i < 4; i++)
862+
{
863+
output.Add(0x00); //pad
864+
}
865+
}
866+
else if (packageType == PackageType.Agents)
867+
{
868+
utility.AddUIntToList(output, ReverseEndianIfNeeded(indexoffset)); //this will be returned to later once we know what it is
869+
}
870+
871+
utility.AddUIntToList(output, ReverseEndianIfNeeded(indexsize)); //this will be returned to later once we know what it is
872+
utility.AddUIntToList(output, ReverseEndianIfNeeded(holeentrycount));
873+
utility.AddUIntToList(output, ReverseEndianIfNeeded(holeoffset));
874+
utility.AddUIntToList(output, ReverseEndianIfNeeded(holesize));
875+
utility.AddUIntToList(output, ReverseEndianIfNeeded(indexminorversion));
876+
877+
if (packageType == PackageType.Agents)
878+
{
879+
utility.AddUIntToList(output, ReverseEndianIfNeeded(unknown4));
880+
}
881+
882+
utility.AddUIntToList(output, ReverseEndianIfNeeded(indexoffset)); //this will be returned to later once we know what it is
883+
utility.AddUIntToList(output, ReverseEndianIfNeeded(unknown5));
884+
utility.AddUIntToList(output, ReverseEndianIfNeeded(unknown6));
885+
utility.AddUIntToList(output, ReverseEndianIfNeeded(reserved1));
886+
utility.AddUIntToList(output, ReverseEndianIfNeeded(reserved2));
887+
888+
while (output.Count < 0x60)
889+
{
890+
output.Add(0x00);
891+
}
892+
893+
//=====================================================================================
894+
//ACTUALLY, ISN'T IT ORGANISED BY TYPE ID? (IN MSA, AT LEAST?) THAT MIGHT BE IMPORTANT
895+
//and then, within a type id, it's alphabetical
896+
//=====================================================================================
897+
898+
foreach (Subfile f in subfiles)
899+
{
900+
if (f.filebytes == null || f.filebytes.Length == 0) //then the file was not modified or read, so transfer it directly from the old package
901+
{
902+
for (int i = 0; i < f.filesize; i++)
903+
{
904+
output.Add(filebytes[f.fileoffset + i]);
905+
}
906+
}
907+
else //if it was modified or read, use the bytes from its filebytes array
908+
{
909+
for (int i = 0; i < f.filebytes.Length; i++)
910+
{
911+
output.Add(f.filebytes[i]);
912+
}
913+
}
914+
}
915+
916+
//that should bring us up to the start of the index table
917+
918+
//=====================================================================================
919+
//ACTUALLY, ISN'T IT ORGANISED BY TYPE ID? (IN MSA, AT LEAST?) THAT MIGHT BE IMPORTANT.
920+
//and then, within a type id, it's alphabetical
921+
//=====================================================================================
922+
923+
924+
925+
926+
790927
}
791928
}
792929

MorcuTool/src/FileTypes/Subfiles/Subfile.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace MorcuTool
1010
{
1111
public class Subfile
1212
{
13-
byte[] filebytes; //will only contain bytes if the file has been exported or modified by the user.
13+
public byte[] filebytes = new byte[0]; //will only contain bytes if the file has been exported or modified by the user.
1414

1515
public ulong hash;
1616
public uint fileoffset;
@@ -56,6 +56,11 @@ public void ExportFile() {
5656
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
5757
{
5858
File.WriteAllBytes(saveFileDialog1.FileName, filebytes);
59+
if (global.activePackage.date.Year > 0)
60+
{
61+
File.SetLastWriteTime(saveFileDialog1.FileName, global.activePackage.date);
62+
}
63+
5964
}
6065
}
6166
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ public void MakeFileTree()
10921092
treeNodesAndSubfiles.Add(newestNode, file);
10931093
}
10941094

1095-
FileTree.Sort();
1095+
//FileTree.Sort();
10961096
FileTree.CollapseAll();
10971097
FileTree.EndUpdate();
10981098
}

0 commit comments

Comments
 (0)