Skip to content

Commit 36c8745

Browse files
committed
MSG reader for MySims Agents
1 parent a2ba2e1 commit 36c8745

12 files changed

Lines changed: 1313 additions & 791 deletions

File tree

MorcuTool/MorcuTool.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="src\FileTypes\Model\DAEModel.cs" />
5353
<Compile Include="src\FileTypes\Model\RevoModel.cs" />
5454
<Compile Include="src\FileTypes\Generic\XML.cs" />
55+
<Compile Include="src\FileTypes\Subfiles\DS\MSG.cs" />
5556
<Compile Include="src\FileTypes\Subfiles\MsaAnimation.cs" />
5657
<Compile Include="src\FileTypes\Subfiles\HavokShapes\havokObject.cs" />
5758
<Compile Include="src\FileTypes\Subfiles\HavokShapes\hkArray.cs" />
@@ -64,6 +65,12 @@
6465
<Compile Include="src\FileTypes\Subfiles\MaterialSet.cs" />
6566
<Compile Include="src\FileTypes\Subfiles\MsaCollision.cs" />
6667
<Compile Include="src\FileTypes\Subfiles\TPLtexture.cs" />
68+
<Compile Include="src\Forms\MSGtexteditor.cs">
69+
<SubType>Form</SubType>
70+
</Compile>
71+
<Compile Include="src\Forms\MSGtexteditor.Designer.cs">
72+
<DependentUpon>MSGtexteditor.cs</DependentUpon>
73+
</Compile>
6774
<Compile Include="src\Forms\SavePackageForm.cs">
6875
<SubType>Form</SubType>
6976
</Compile>
@@ -78,6 +85,7 @@
7885
<DependentUpon>Form1.cs</DependentUpon>
7986
</Compile>
8087
<Compile Include="global.cs" />
88+
<Compile Include="src\Utility\Compression.cs" />
8189
<Compile Include="src\Utility\havokUtility.cs" />
8290
<Compile Include="src\Utility\imageTools.cs" />
8391
<Compile Include="src\FileTypes\Model\mdlObject.cs" />
@@ -101,6 +109,9 @@
101109
<AutoGen>True</AutoGen>
102110
<DependentUpon>Resources.resx</DependentUpon>
103111
</Compile>
112+
<EmbeddedResource Include="src\Forms\MSGtexteditor.resx">
113+
<DependentUpon>MSGtexteditor.cs</DependentUpon>
114+
</EmbeddedResource>
104115
<EmbeddedResource Include="src\Forms\SavePackageForm.resx">
105116
<DependentUpon>SavePackageForm.cs</DependentUpon>
106117
</EmbeddedResource>

MorcuTool/src/FileTypes/Package.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ public void RebuildPackage()
10381038
{
10391039
if (subfiles[f].has_been_decompressed) //if it was decompressed by the user then compress it
10401040
{
1041-
subfiles[f].filebytes = Utility.Compress_QFS(subfiles[f].filebytes);
1041+
subfiles[f].filebytes = Compression.Compress_QFS(subfiles[f].filebytes);
10421042
}
10431043
}
10441044

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace MorcuTool
8+
{
9+
public class MSG
10+
{
11+
public List<string> strings = new List<string>();
12+
byte version;
13+
14+
public string MSK_DS_string_to_normal_string(byte[] input) {
15+
16+
StringBuilder sb = new StringBuilder(input.Length);
17+
18+
foreach (byte b in input) {
19+
// sb.Append(Utility.CharFromMSKDSChar(b));
20+
Console.WriteLine("Temporarily dummied out");
21+
}
22+
23+
return sb.ToString();
24+
}
25+
26+
public string MSA_DS_string_to_normal_string(byte[] input)
27+
{
28+
29+
StringBuilder sb = new StringBuilder(input.Length);
30+
31+
foreach (byte b in input)
32+
{
33+
sb.Append(Utility.CharFromMSADSChar(b));
34+
}
35+
36+
return sb.ToString();
37+
}
38+
39+
40+
public MSG(byte[] filebytes) {
41+
42+
version = filebytes[0x08];
43+
int numTexts = BitConverter.ToInt32(filebytes, 0x09) & 0x00FFFFFF;
44+
45+
int pos = 0;
46+
47+
for (int i = 0; i < numTexts; i++) {
48+
49+
pos = BitConverter.ToInt32(filebytes, 0x10 + (i * 4));
50+
51+
int startPos = pos;
52+
53+
while (pos < filebytes.Length && filebytes[pos] != 0x02) {
54+
pos++;
55+
}
56+
57+
byte[] stringBytes = new byte[pos - startPos];
58+
59+
for (int j = startPos; j < pos; j++) {
60+
stringBytes[j - startPos] = filebytes[j];
61+
}
62+
63+
if (version == 3) {
64+
strings.Add(MSA_DS_string_to_normal_string(stringBytes));
65+
}
66+
else if (version == 4) {
67+
strings.Add(MSK_DS_string_to_normal_string(stringBytes));
68+
}
69+
}
70+
}
71+
}
72+
}

MorcuTool/src/FileTypes/Subfiles/MsaAnimation.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,29 @@ public class Table1Entry { //setting table 1's count to 1 turns the animati
1313

1414
public uint unk1; //start frame, possibly?
1515
public uint unk2; //flags? padding? usually 0
16-
public uint unk3; //u32 end of this frame's data, relative to the unknown section offset. The start of the frame's data is the end of the previous one (or from the unknown section offset if it's the first frame)
16+
public uint unk3; //u32 start of this frame's data, relative to the data section
17+
public FrameData frmData;
1718

18-
public Table1Entry(byte[] filebytes, int offset) {
19+
public Table1Entry(byte[] filebytes, int offset, MsaAnimation parent) {
1920
unk1 = Utility.ReadUInt32BigEndian(filebytes, offset);
20-
unk2 = Utility.ReadUInt32BigEndian(filebytes, offset+4);
21-
unk3 = Utility.ReadUInt32BigEndian(filebytes, offset+8);
21+
unk2 = Utility.ReadUInt32BigEndian(filebytes, offset + 4);
22+
unk3 = Utility.ReadUInt32BigEndian(filebytes, offset + 8);
23+
frmData = new FrameData(filebytes, parent.dataSectionOffset + unk3);
2224
}
2325
}
2426

27+
28+
public class FrameData {
29+
30+
public FrameData(byte[] filebytes, uint offset) {
31+
32+
}
33+
}
34+
2535
public class Table2Entry //setting table 2's count to 1 doesn't seem to change anything in-game
2636
{
2737
public uint unk1; // u32 flags? padding? usually 0x00000001
28-
public uint unk2; // u32 offset to something (relative to unknown section 1)
38+
public uint unk2; // u32 offset to something (relative to data section)
2939
public uint unk3; // u32 usually 0 ?
3040
public uint unk4; // u32 offset to float data for bone movement
3141

@@ -85,7 +95,7 @@ public MsaAnimation(Subfile basis) {
8595
secondTableCount = Utility.ReadUInt32BigEndian(basis.filebytes, 0x90);
8696

8797
for (int i = 0; i < firstTableCount; i++){
88-
table1.Add(new Table1Entry(basis.filebytes, (int)(firstTableOffset + (i * 0x0C))));
98+
table1.Add(new Table1Entry(basis.filebytes, (int)(firstTableOffset + (i * 0x0C)),this));
8999
}
90100

91101
for (int i = 0; i < secondTableCount; i++){

MorcuTool/src/FileTypes/Subfiles/Subfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void Load()
5151

5252
if (uncompressedsize > 0) //if it's a compressed file
5353
{
54-
filebytes = Utility.Decompress_QFS(filebytes);
54+
filebytes = Compression.Decompress_QFS(filebytes);
5555
has_been_decompressed = true;
5656
}
5757

MorcuTool/src/Forms/Form1.Designer.cs

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

MorcuTool/src/Forms/Form1.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private void decompressQFSToolStripMenuItem_Click_1(object sender, EventArgs e)
543543
{
544544
foreach (string filename in openFileDialog2.FileNames)
545545
{
546-
File.WriteAllBytes(filename+"_decomp" , Utility.Decompress_QFS(File.ReadAllBytes(filename)).ToArray());
546+
File.WriteAllBytes(filename+"_decomp" , Compression.Decompress_QFS(File.ReadAllBytes(filename)).ToArray());
547547
}
548548
}
549549
}
@@ -880,7 +880,7 @@ private void compressToQFSToolStripMenuItem_Click(object sender, EventArgs e)
880880
{
881881
foreach (string filename in openFileDialog2.FileNames)
882882
{
883-
File.WriteAllBytes(filename + "_comp", Utility.Compress_QFS(File.ReadAllBytes(filename)));
883+
File.WriteAllBytes(filename + "_comp", Compression.Compress_QFS(File.ReadAllBytes(filename)));
884884
}
885885
}
886886
}
@@ -909,5 +909,12 @@ private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
909909
s.filebytes = File.ReadAllBytes(openFileDialog1.FileName);
910910
}
911911
}
912+
913+
private void mSGTextEditorToolStripMenuItem_Click(object sender, EventArgs e)
914+
{
915+
MSGtexteditor textEdit = new MSGtexteditor();
916+
textEdit.Show();
917+
918+
}
912919
}
913920
}

MorcuTool/src/Forms/MSGtexteditor.Designer.cs

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

0 commit comments

Comments
 (0)