diff --git a/OpenKh.Bbs/Ctd.cs b/OpenKh.Bbs/Ctd.cs index f1a348642..987dd0be4 100644 --- a/OpenKh.Bbs/Ctd.cs +++ b/OpenKh.Bbs/Ctd.cs @@ -22,15 +22,15 @@ private class Header [Data] public int Version { get; set; } [Data] public short Unknown08 { get; set; } [Data] public short Unknown0a { get; set; } - [Data] public short Entry2Count { get; set; } - [Data] public short Entry1Count { get; set; } - [Data] public int Entry1Offset { get; set; } - [Data] public int Entry2Offset { get; set; } + [Data] public short LayoutCount { get; set; } + [Data] public short MessageCount { get; set; } + [Data] public int MessageOffset { get; set; } + [Data] public int LayoutOffset { get; set; } [Data] public int TextOffset { get; set; } [Data] public int Unknown1c { get; set; } } - private class Entry + private class _Message { [Data] public short Id { get; set; } [Data] public short Unknown02 { get; set; } @@ -38,13 +38,14 @@ private class Entry [Data] public int Entry2Index { get; set; } } - public class FakeEntry + public class Message { - [Data] public short Id { get; set; } - [Data] public short Unknown02 { get; set; } - [Data] public int Entry2Index { get; set; } + public short Id { get; set; } + public short Unknown02 { get; set; } + public int Entry2Index { get; set; } public byte[] Data { get; set; } + public string Text { get => CtdEncoders.International.Decode(Data); @@ -55,7 +56,7 @@ public override string ToString() => $"{Id:X04} {Unknown02:X04} {Entry2Index:X08}: {Text}"; } - public class Entry2 + public class Layout { [Data] public ushort textX { get; set; } [Data] public ushort textY { get; set; } @@ -78,12 +79,12 @@ public class Entry2 } public short Unknown { get; set; } - public List Entries1 { get; set; } - public List Entries2 { get; set; } + public List Messages { get; set; } + public List Layouts { get; set; } public string GetString(int id) { - var entry = Entries1.FirstOrDefault(x => x.Id == id); + var entry = Messages.FirstOrDefault(x => x.Id == id); if (entry == null) return null; @@ -92,9 +93,9 @@ public string GetString(int id) public void Write(Stream stream) { - var entry1Offset = HeaderLength; - var entry2Offset = Helpers.Align(entry1Offset + Entries1.Count * Entry1Length, 16); - var textOffset = entry2Offset + Entries2.Count * Entry2Length; + var messageOffset = HeaderLength; + var layoutOffset = Helpers.Align(messageOffset + Messages.Count * Entry1Length, 16); + var textOffset = layoutOffset + Layouts.Count * Entry2Length; BinaryMapping.WriteObject(stream, new Header { @@ -102,23 +103,23 @@ public void Write(Stream stream) Version = Version, Unknown08 = 0, Unknown0a = Unknown, - Entry2Count = (short)Entries2.Count, - Entry1Count = (short)Entries1.Count, - Entry1Offset = entry1Offset, - Entry2Offset = entry2Offset, + LayoutCount = (short)Layouts.Count, + MessageCount = (short)Messages.Count, + MessageOffset = messageOffset, + LayoutOffset = layoutOffset, TextOffset = textOffset, Unknown1c = 0, }); - stream.Position = entry1Offset; + stream.Position = messageOffset; var textStream = new MemoryStream(4096); var nextTextOffset = textOffset; - foreach (var item in Entries1) + foreach (var item in Messages) { textStream.Write(item.Data, 0, item.Data.Length); textStream.WriteByte(0); - BinaryMapping.WriteObject(stream, new Entry + BinaryMapping.WriteObject(stream, new _Message { Id = item.Id, Unknown02 = item.Unknown02, @@ -129,12 +130,12 @@ public void Write(Stream stream) nextTextOffset += item.Data.Length + 1; } - stream.Position = entry2Offset; - foreach (var item in Entries2) + stream.Position = layoutOffset; + foreach (var item in Layouts) BinaryMapping.WriteObject(stream, item); stream.Position = textOffset; - foreach (var entry in Entries1) + foreach (var entry in Messages) { stream.Write(entry.Data, 0, entry.Data.Length); stream.WriteByte(0); @@ -144,8 +145,8 @@ public void Write(Stream stream) public Ctd() { Unknown = 0; - Entries1 = new List(); - Entries2 = new List(); + Messages = new List(); + Layouts = new List(); } private Ctd(Stream stream) @@ -153,21 +154,21 @@ private Ctd(Stream stream) var header = BinaryMapping.ReadObject
(stream); Unknown = header.Unknown0a; - stream.Position = header.Entry1Offset; - var textEntries = Enumerable.Range(0, header.Entry1Count) - .Select(x => BinaryMapping.ReadObject(stream)) + stream.Position = header.MessageOffset; + var textEntries = Enumerable.Range(0, header.MessageCount) + .Select(x => BinaryMapping.ReadObject<_Message>(stream)) .ToList(); - stream.Position = header.Entry2Offset; - Entries2 = Enumerable.Range(0, header.Entry2Count) - .Select(x => BinaryMapping.ReadObject(stream)) + stream.Position = header.LayoutOffset; + Layouts = Enumerable.Range(0, header.LayoutCount) + .Select(x => BinaryMapping.ReadObject(stream)) .ToList(); - Entries1 = textEntries + Messages = textEntries .Select(x => { stream.SetPosition(x.Offset); - return new FakeEntry + return new Message { Id = x.Id, Unknown02 = x.Unknown02, diff --git a/OpenKh.Tests/Bbs/CtdTests.cs b/OpenKh.Tests/Bbs/CtdTests.cs index fb8424ce7..94f635546 100644 --- a/OpenKh.Tests/Bbs/CtdTests.cs +++ b/OpenKh.Tests/Bbs/CtdTests.cs @@ -43,14 +43,14 @@ public void IsNotValidTest() public void ReadCorrectAmountOfEntry1() => FileOpenRead(FileName, stream => { var ctd = Ctd.Read(stream); - Assert.Equal(41, ctd.Entries1.Count); + Assert.Equal(41, ctd.Messages.Count); }); [Fact] public void ReadCorrectAmountOfEntry2() => FileOpenRead(FileName, stream => { var ctd = Ctd.Read(stream); - Assert.Equal(14, ctd.Entries2.Count); + Assert.Equal(14, ctd.Layouts.Count); }); [Theory] @@ -81,10 +81,10 @@ public void WritesBackCorrectly() => FileOpenRead(FileName, stream => public void CreateEmptyCtdWithoutNullValues() { var ctd = new Ctd(); - Assert.NotNull(ctd.Entries1); - Assert.NotNull(ctd.Entries2); - Assert.Empty(ctd.Entries1); - Assert.Empty(ctd.Entries2); + Assert.NotNull(ctd.Messages); + Assert.NotNull(ctd.Layouts); + Assert.Empty(ctd.Messages); + Assert.Empty(ctd.Layouts); Assert.Equal(0, ctd.Unknown); } } diff --git a/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs index 494992c92..d3bc66dea 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/CtdViewModel.cs @@ -15,8 +15,8 @@ public Ctd Ctd { get { - _ctd.Entries1.Clear(); - _ctd.Entries1.AddRange(Items.Select(x => x.Message)); + _ctd.Messages.Clear(); + _ctd.Messages.AddRange(Items.Select(x => x.Message)); return _ctd; } } @@ -36,10 +36,10 @@ public CtdViewModel() : { } public CtdViewModel(Ctd ctd) : - this(ctd, ctd.Entries1) + this(ctd, ctd.Messages) { } - private CtdViewModel(Ctd ctd, IEnumerable messages) : + private CtdViewModel(Ctd ctd, IEnumerable messages) : base(messages.Select(x => new MessageViewModel(ctd, x))) { _ctd = ctd; @@ -51,7 +51,7 @@ protected override void OnSelectedItem(MessageViewModel item) } protected override MessageViewModel OnNewItem() => - new MessageViewModel(_ctd, new Ctd.FakeEntry + new MessageViewModel(_ctd, new Ctd.Message { Id = (short)(Items.Max(x => x.Message.Id) + 1), Data = new byte[0], diff --git a/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs b/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs index f9fef28b5..087de82fc 100644 --- a/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs +++ b/OpenKh.Tools.CtdEditor/ViewModels/MessageViewModel.cs @@ -8,13 +8,13 @@ public class MessageViewModel : BaseNotifyPropertyChanged { private readonly Ctd _ctd; - public MessageViewModel(Ctd ctd, Ctd.FakeEntry message) + public MessageViewModel(Ctd ctd, Ctd.Message message) { _ctd = ctd; Message = message; } - public Ctd.FakeEntry Message { get; } + public Ctd.Message Message { get; } public short Id {