Skip to content

Commit 515f02b

Browse files
committed
Loads of little fixes; Symbol encoding improvements
1 parent 8dc13a3 commit 515f02b

11 files changed

Lines changed: 68 additions & 34 deletions

File tree

MiloLib/Assets/Band/BandDirector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p
4646
base.Write(writer, false, parent, entry);
4747

4848
poll.Write(writer, false, parent, entry);
49-
draw.Write(writer, false, parent, entry);
49+
draw.Write(writer, false, true);
5050
if (revision < 5)
5151
obj3.Write(writer, false, parent, entry);
5252
if (revision < 6)

MiloLib/Assets/DirectoryMeta.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ public void Write(EndianWriter writer)
484484
case "P9Character":
485485
((P9Character)directory).Write(writer, true, this, new Entry(type, name, directory));
486486
break;
487+
case "CharBoneDir":
488+
((CharBoneDir)directory).Write(writer, true, this, new Entry(type, name, directory));
489+
break;
487490
case "CharClipSet":
488491
((CharClipSet)directory).Write(writer, true, this, new Entry(type, name, directory));
489492
break;
@@ -1307,6 +1310,11 @@ public void WriteEntry(EndianWriter writer, DirectoryMeta.Entry entry)
13071310
entry.dir.Write(writer);
13081311
}
13091312
break;
1313+
case "CharBoneDir":
1314+
((CharBoneDir)entry.obj).Write(writer, true, this, entry);
1315+
entry.isProxy = false;
1316+
entry.dir.Write(writer);
1317+
break;
13101318
case "CharClipSet":
13111319
writer.WriteUInt32(0x18);
13121320
((ObjectDir)entry.obj).Write(writer, true, this, entry);

MiloLib/Assets/Rnd/RndMotionBlur.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p
4040
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));
4141

4242
base.Write(writer, false, parent, entry);
43-
draw.Write(writer, false, parent, entry);
43+
draw.Write(writer, false, true);
4444

4545
writer.WriteUInt32((uint)draws.Count);
4646
foreach (Symbol draw in draws)

MiloLib/Assets/Rnd/RndTexBlender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p
6060
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));
6161

6262
base.Write(writer, false, parent, entry);
63-
draw.Write(writer, false, parent, entry);
63+
draw.Write(writer, false, true);
6464

6565
Symbol.Write(writer, outputTexture);
6666
Symbol.Write(writer, baseMap);

MiloLib/Assets/UI/UIFontImporter.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ public void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, Di
223223
writer.WriteInt32(fontQuality);
224224

225225
writer.WriteInt32(fontCharSet);
226-
writer.WriteInt32((int)fontSupersample);
226+
if (revision > 1)
227+
writer.WriteInt32((int)fontSupersample);
227228

228229
Symbol.Write(writer, bitmapPath);
229230
Symbol.Write(writer, bitmapFilename);
@@ -240,7 +241,7 @@ public void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, Di
240241

241242
if (revision > 2)
242243
{
243-
writer.WriteInt32(genedFontsCount);
244+
writer.WriteInt32(genFonts.Count);
244245
foreach (var genFont in genFonts)
245246
{
246247
Symbol.Write(writer, genFont);
@@ -256,7 +257,7 @@ public void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, Di
256257

257258
if (revision > 3)
258259
{
259-
writer.WriteInt32(matVariationsCount);
260+
writer.WriteInt32(matVariations.Count);
260261
foreach (var matVariation in matVariations)
261262
{
262263
Symbol.Write(writer, matVariation);

MiloLib/Assets/UI/UILabel.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public enum LabelFitTypes
100100
[Name("Alternate Font Resource Name"), Description("path to alt font resource file for this component"), MinVersion(0x16)]
101101
public Symbol altFontResourceName = new(0, "");
102102

103+
public Symbol unkSymbol = new(0, "");
104+
public bool unkBool, unkBool2;
105+
public int unkIntA, unkIntC, unkIntD;
106+
103107

104108

105109
public UILabel Read(EndianReader reader, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry entry)
@@ -111,13 +115,13 @@ public UILabel Read(EndianReader reader, bool standalone, DirectoryMeta parent,
111115
base.Read(reader, false, parent, entry);
112116
if (revision != 0 && revision < 0xE)
113117
{
114-
reader.ReadBoolean(); //b
118+
unkBool = reader.ReadBoolean();
115119
}
116120
textToken = Symbol.Read(reader);
117121

118122
if (revision > 0xD)
119123
{
120-
Symbol.Read(reader);
124+
unkSymbol = Symbol.Read(reader);
121125
}
122126

123127
if (revision > 0xE)
@@ -158,10 +162,10 @@ public UILabel Read(EndianReader reader, bool standalone, DirectoryMeta parent,
158162
}
159163
if (revision >= 9 && revision <= 15)
160164
{
161-
reader.ReadBoolean(); //b
162-
reader.ReadInt32(); //a
163-
reader.ReadInt32(); //c
164-
reader.ReadInt32(); //d
165+
unkBool2 = reader.ReadBoolean();
166+
unkIntA = reader.ReadInt32();
167+
unkIntC = reader.ReadInt32();
168+
unkIntD = reader.ReadInt32();
165169
}
166170

167171
if (revision > 9)
@@ -231,13 +235,13 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p
231235

232236
if (revision != 0 && revision < 0xE)
233237
{
234-
writer.WriteBoolean(false);
238+
writer.WriteBoolean(unkBool);
235239
}
236240
Symbol.Write(writer, textToken);
237241

238242
if (revision > 0xD)
239243
{
240-
Symbol.Write(writer, new Symbol(0, ""));
244+
Symbol.Write(writer, unkSymbol);
241245
}
242246

243247
if (revision > 0xE)
@@ -278,10 +282,10 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p
278282
}
279283
if (revision >= 9 && revision <= 15)
280284
{
281-
writer.WriteBoolean(false);
282-
writer.WriteInt32(0);
283-
writer.WriteInt32(0);
284-
writer.WriteInt32(0);
285+
writer.WriteBoolean(unkBool2);
286+
writer.WriteInt32(unkIntA);
287+
writer.WriteInt32(unkIntC);
288+
writer.WriteInt32(unkIntD);
285289
}
286290
if (revision > 9)
287291
{

MiloLib/Assets/UI/UITrigger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p
5555
Symbol.Write(writer, animRef);
5656
}
5757

58-
base.Write(writer, standalone, parent, entry);
58+
base.Write(writer, false, parent, entry);
5959
writer.WriteBoolean(blockTransition);
6060

6161
if (standalone)

MiloLib/Classes/Symbol.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@ public override string ToString()
3131

3232
public static Symbol Read(EndianReader reader)
3333
{
34+
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
35+
3436
uint length = reader.ReadUInt32();
3537

36-
// sanity check on length, if this is something really high we are probably reading garbage
37-
// as there are no symbols of this length
3838
if (length > 512)
3939
{
4040
throw new InvalidDataException($"Symbol length is too high: {length}");
4141
}
4242

43-
string value = reader.ReadUTF8((int)length);
43+
// use windows-1252 encoding to support extended characters
44+
string value = reader.ReadBytesWithEncoding((int)length, Encoding.GetEncoding("Windows-1252"));
4445
return new Symbol(length, value);
4546
}
4647

4748
public static void Write(EndianWriter writer, Symbol lengthString)
4849
{
49-
writer.WriteUInt32(lengthString.length);
50-
51-
writer.WriteBlock(Encoding.UTF8.GetBytes(lengthString.chars));
50+
byte[] bytes = Encoding.GetEncoding("Windows-1252").GetBytes(lengthString.chars);
51+
writer.WriteUInt32((uint)bytes.Length);
52+
writer.WriteBlock(bytes);
5253
}
5354
}

MiloLib/MiloFile.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using MiloLib.Assets;
2-
using MiloLib.Utils;
1+
using ICSharpCode.SharpZipLib.GZip;
32
using ICSharpCode.SharpZipLib.Zip.Compression;
43
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
5-
using ICSharpCode.SharpZipLib.GZip;
4+
using MiloLib.Assets;
5+
using MiloLib.Utils;
66
using System.IO;
7-
using System.Reflection.PortableExecutable;
87
using System.Linq;
8+
using System.Reflection.PortableExecutable;
99
using System.Security.Cryptography.X509Certificates;
10+
using System.Text;
1011

1112
namespace MiloLib
1213
{
@@ -87,6 +88,7 @@ public enum Type : uint
8788
/// </summary>
8889
public MiloFile(string path)
8990
{
91+
9092
filePath = path;
9193

9294
using (EndianReader reader = new EndianReader(File.OpenRead(path), Endian.LittleEndian))

MiloLib/Utils/Endian/EndianReader.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,23 @@ public string ReadUTF16(int size)
421421
return _currentString.ToString();
422422
}
423423

424+
public string ReadBytesWithEncoding(int size, Encoding encoding)
425+
{
426+
byte[] bytes = new byte[size];
427+
for (int i = 0; i < size; i++)
428+
{
429+
bytes[i] = ReadByte();
430+
}
431+
432+
int nullIndex = Array.IndexOf<byte>(bytes, 0);
433+
if (nullIndex >= 0)
434+
{
435+
size = nullIndex;
436+
}
437+
438+
return encoding.GetString(bytes, 0, size);
439+
}
440+
424441

425442
/// <summary>
426443
/// Reads an array of bytes from the stream.

0 commit comments

Comments
 (0)