Skip to content

Commit

Permalink
Change archive file name encoding to Shift-JIS
Browse files Browse the repository at this point in the history
  • Loading branch information
AtomCrafty committed Feb 17, 2021
1 parent a343903 commit 2e58d1f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/yukatool/Data/Factory/ArchiveFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Yuka.Data.Factory {
class ArchiveFactory : FileFactory<YukaArchive> {
public static readonly ArchiveFactory Instance = new ArchiveFactory();
private static readonly Encoding ShiftJis = Encoding.GetEncoding("Shift-JIS");

public ArchiveFactory() : base(DataType.Archive) { }

Expand All @@ -28,7 +29,7 @@ public override YukaArchive FromBinary(Stream s) {
uint datalength = br.ReadUInt32();

s.Seek(nameoffset, SeekOrigin.Begin);
string name = Encoding.ASCII.GetString(br.ReadBytes((int)namelength - 1)).ToLower();
string name = ShiftJis.GetString(br.ReadBytes((int)namelength - 1)).ToLower();
s.Seek(dataoffset, SeekOrigin.Begin);
byte[] data = br.ReadBytes((int)datalength);

Expand Down Expand Up @@ -59,13 +60,14 @@ public override long ToBinary(YukaArchive data, Stream s) {
MemoryStream ms = data.GetInputStream(file.Key);
ms.CopyTo(s);
//s.Write(data, 0, data.Length);
offsets[file.Key] = (new uint[] { dataoffset, (uint)file.Value.Length, 0, (uint)file.Key.Length + 1 });
offsets[file.Key] = (new uint[] { dataoffset, (uint)file.Value.Length, 0, (uint)ShiftJis.GetByteCount(file.Key) + 1 });
}

// Write name table
foreach(var entry in offsets) {
uint nameoffset = (uint)s.Position;
s.Write(Encoding.ASCII.GetBytes(entry.Key), 0, Encoding.ASCII.GetByteCount(entry.Key));
var bytes = ShiftJis.GetBytes(entry.Key);
s.Write(bytes, 0, bytes.Length);
s.WriteByte(0);
entry.Value[2] = nameoffset;
}
Expand Down

0 comments on commit 2e58d1f

Please sign in to comment.