From e38ea1d36e80a4bdd2e2d87786391b31fdc0cf6d Mon Sep 17 00:00:00 2001 From: Megghy Date: Wed, 20 Oct 2021 18:02:15 +0800 Subject: [PATCH 1/2] add TileSquare packet, fix liquid update --- TrProtocol/Models/SimpleTileData.cs | 16 + TrProtocol/Models/SquareData.cs | 12 + TrProtocol/Models/TileChangeType.cs | 13 + TrProtocol/PacketSerializer.cs | 133 ++-- TrProtocol/Packets/LiquidUpdate.cs | 11 + TrProtocol/Packets/TileSquare.cs | 6 +- .../Serializers/SectionDataSerializer.cs | 708 +++++++++--------- .../Serializers/SquareDataSerializer.cs | 109 +++ 8 files changed, 589 insertions(+), 419 deletions(-) create mode 100644 TrProtocol/Models/SimpleTileData.cs create mode 100644 TrProtocol/Models/SquareData.cs create mode 100644 TrProtocol/Models/TileChangeType.cs create mode 100644 TrProtocol/Packets/LiquidUpdate.cs create mode 100644 TrProtocol/Serializers/SquareDataSerializer.cs diff --git a/TrProtocol/Models/SimpleTileData.cs b/TrProtocol/Models/SimpleTileData.cs new file mode 100644 index 00000000..2e5f980d --- /dev/null +++ b/TrProtocol/Models/SimpleTileData.cs @@ -0,0 +1,16 @@ +namespace TrProtocol.Models +{ + public struct SimpleTileData + { + public BitsByte Flags1; + public BitsByte Flags2; + public byte TileColor { get; set; } + public byte WallColor { get; set; } + public ushort TileType { get; set; } + public short FrameX { get; set; } + public short FrameY { get; set; } + public ushort WallType { get; set; } + public byte Liquid { get; set; } + public byte LiquidType { get; set; } + } +} diff --git a/TrProtocol/Models/SquareData.cs b/TrProtocol/Models/SquareData.cs new file mode 100644 index 00000000..b0c0c7c1 --- /dev/null +++ b/TrProtocol/Models/SquareData.cs @@ -0,0 +1,12 @@ +namespace TrProtocol.Models +{ + public partial class SquareData + { + public short TilePosX { get; set; } + public short TilePosY { get; set; } + public byte Width { get; set; } + public byte Height { get; set; } + public TileChangeType ChangeType { get; set; } + public SimpleTileData[,] Tiles { get; set; } + } +} diff --git a/TrProtocol/Models/TileChangeType.cs b/TrProtocol/Models/TileChangeType.cs new file mode 100644 index 00000000..1bb1faf4 --- /dev/null +++ b/TrProtocol/Models/TileChangeType.cs @@ -0,0 +1,13 @@ +using TrProtocol.Serializers; + +namespace TrProtocol.Models +{ + [Serializer(typeof(ByteEnumSerializer))] + public enum TileChangeType : byte + { + None, + LavaWater, + HoneyWater, + HoneyLava + } +} diff --git a/TrProtocol/PacketSerializer.cs b/TrProtocol/PacketSerializer.cs index 2b4e9ab9..594e7516 100644 --- a/TrProtocol/PacketSerializer.cs +++ b/TrProtocol/PacketSerializer.cs @@ -16,88 +16,95 @@ public partial class PacketSerializer private Dictionary> deserializers = new(); private Dictionary> moduledeserializers = new(); - public void LoadPackets(Assembly asm) + private void LoadPackets(Assembly asm) { foreach (var type in asm.GetTypes()) { - if (type.IsAbstract || !type.IsSubclassOf(typeof(Packet))) continue; - Serializer serializer = null; - Deserializer deserializer = null; + RegisterPacket(type); + } + } + public void RegisterPacket() where T : Packet + { + RegisterPacket(typeof(T)); + } + private void RegisterPacket(Type type) + { + if (type.IsAbstract || !type.IsSubclassOf(typeof(Packet))) return; + Serializer serializer = null; + Deserializer deserializer = null; - var dict = new Dictionary(); - var empty = Array.Empty(); + var dict = new Dictionary(); + var empty = Array.Empty(); - foreach (var prop in type.GetProperties()) - { - dict.Add(prop.Name, prop); + foreach (var prop in type.GetProperties()) + { + dict.Add(prop.Name, prop); - if (prop.IsDefined(typeof(IgnoreAttribute))) continue; + if (prop.IsDefined(typeof(IgnoreAttribute))) continue; - var get = prop.GetMethod; - var set = prop.SetMethod; - var t = prop.PropertyType; + var get = prop.GetMethod; + var set = prop.SetMethod; + var t = prop.PropertyType; - Func condition = _ => true; + Func condition = _ => true; - var cond = prop.GetCustomAttribute(); + var cond = prop.GetCustomAttribute(); - var shouldSerialize = (client - ? (object)prop.GetCustomAttribute() - : prop.GetCustomAttribute()) == null; - var shouldDeserialize = (!client - ? (object)prop.GetCustomAttribute() - : prop.GetCustomAttribute()) == null && set != null; + var shouldSerialize = (client + ? (object)prop.GetCustomAttribute() + : prop.GetCustomAttribute()) == null; + var shouldDeserialize = (!client + ? (object)prop.GetCustomAttribute() + : prop.GetCustomAttribute()) == null && set != null; - if (cond != null) - { - var get2 = dict[cond.field].GetMethod; - if (cond.bit == -1) - condition = o => ((bool)get2.Invoke(o, empty)); - else - condition = o => ((BitsByte)get2.Invoke(o, empty))[cond.bit] == cond.pred; - } - - - var attr = t.GetCustomAttribute(); - IFieldSerializer ser; - if (attr != null) ser = attr.serializer; - else if (!fieldSerializers.TryGetValue(t, out ser)) - throw new Exception("No valid serializer for type: " + t.FullName); - if (ser is IConfigurable conf) ser = conf.Configure(prop); - - if (shouldSerialize) - serializer += (o, bw) => { if (condition(o)) ser.Write(bw, get.Invoke(o, empty)); }; - if (shouldDeserialize) - deserializer += (o, br) => { if (condition(o)) set.Invoke(o, new[] { ser.Read(br) }); }; + if (cond != null) + { + var get2 = dict[cond.field].GetMethod; + if (cond.bit == -1) + condition = o => ((bool)get2.Invoke(o, empty)); + else + condition = o => ((BitsByte)get2.Invoke(o, empty))[cond.bit] == cond.pred; } - var inst = Activator.CreateInstance(type); - if (client ? (type.GetCustomAttribute() == null) : (type.GetCustomAttribute()) == null) - serializers[type] = (bw, o) => serializer?.Invoke(o, bw); + var attr = t.GetCustomAttribute(); + IFieldSerializer ser; + if (attr != null) ser = attr.serializer; + else if (!fieldSerializers.TryGetValue(t, out ser)) + throw new Exception("No valid serializer for type: " + t.FullName); + if (ser is IConfigurable conf) ser = conf.Configure(prop); - if ((!client) ? (type.GetCustomAttribute() == null) : (type.GetCustomAttribute()) == null) + if (shouldSerialize) + serializer += (o, bw) => { if (condition(o)) ser.Write(bw, get.Invoke(o, empty)); }; + if (shouldDeserialize) + deserializer += (o, br) => { if (condition(o)) set.Invoke(o, new[] { ser.Read(br) }); }; + } + + var inst = Activator.CreateInstance(type); + + if (client ? (type.GetCustomAttribute() == null) : (type.GetCustomAttribute()) == null) + serializers[type] = (bw, o) => serializer?.Invoke(o, bw); + + if ((!client) ? (type.GetCustomAttribute() == null) : (type.GetCustomAttribute()) == null) + { + if (inst is NetModulesPacket p) { - if (inst is NetModulesPacket p) + moduledeserializers.Add(p.ModuleType, br => { - moduledeserializers.Add(p.ModuleType, br => - { - var result = Activator.CreateInstance(type) as NetModulesPacket; - deserializer?.Invoke(result, br); - return result; - }); - } - else if (inst is Packet p2) + var result = Activator.CreateInstance(type) as NetModulesPacket; + deserializer?.Invoke(result, br); + return result; + }); + } + else if (inst is Packet p2) + { + deserializers.Add(p2.Type, br => { - deserializers.Add(p2.Type, br => - { - var result = Activator.CreateInstance(type) as Packet; - deserializer?.Invoke(result, br); - return result; - }); - } + var result = Activator.CreateInstance(type) as Packet; + deserializer?.Invoke(result, br); + return result; + }); } - } } diff --git a/TrProtocol/Packets/LiquidUpdate.cs b/TrProtocol/Packets/LiquidUpdate.cs new file mode 100644 index 00000000..37e80119 --- /dev/null +++ b/TrProtocol/Packets/LiquidUpdate.cs @@ -0,0 +1,11 @@ +namespace TrProtocol.Packets +{ + public class LiquidUpdate : Packet + { + public override MessageID Type => MessageID.LiquidUpdate; + public short TileX { get; set; } + public short TileY { get; set; } + public byte Liquid { get; set; } + public byte LiquidType { get; set; } + } +} diff --git a/TrProtocol/Packets/TileSquare.cs b/TrProtocol/Packets/TileSquare.cs index 33e97b44..2150ca6a 100644 --- a/TrProtocol/Packets/TileSquare.cs +++ b/TrProtocol/Packets/TileSquare.cs @@ -1,8 +1,10 @@ -namespace TrProtocol.Packets +using TrProtocol.Models; + +namespace TrProtocol.Packets { public class TileSquare : Packet { public override MessageID Type => MessageID.TileSquare; - public byte[] Data { get; set; } + public SquareData Data { get; set; } } } diff --git a/TrProtocol/Serializers/SectionDataSerializer.cs b/TrProtocol/Serializers/SectionDataSerializer.cs index 50da56e2..2d167cd5 100644 --- a/TrProtocol/Serializers/SectionDataSerializer.cs +++ b/TrProtocol/Serializers/SectionDataSerializer.cs @@ -8,362 +8,362 @@ namespace TrProtocol.Models [Serializer(typeof(SectionDataSerializer))] public partial struct SectionData { + public static List tileFrameImportant = new() + { + 3, + 4, + 5, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 24, + 26, + 27, + 28, + 29, + 31, + 33, + 34, + 35, + 36, + 42, + 49, + 50, + 55, + 61, + 71, + 72, + 73, + 74, + 77, + 78, + 79, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 110, + 113, + 114, + 125, + 126, + 128, + 129, + 132, + 133, + 134, + 135, + 136, + 137, + 138, + 139, + 141, + 142, + 143, + 144, + 149, + 165, + 171, + 172, + 173, + 174, + 178, + 184, + 185, + 186, + 187, + 201, + 207, + 209, + 210, + 212, + 215, + 216, + 217, + 218, + 219, + 220, + 227, + 228, + 231, + 233, + 235, + 236, + 237, + 238, + 239, + 240, + 241, + 242, + 243, + 244, + 245, + 246, + 247, + 254, + 269, + 270, + 271, + 275, + 276, + 277, + 278, + 279, + 280, + 281, + 282, + 283, + 285, + 286, + 287, + 288, + 289, + 290, + 291, + 292, + 293, + 294, + 295, + 296, + 297, + 298, + 299, + 300, + 301, + 302, + 303, + 304, + 305, + 306, + 307, + 308, + 309, + 310, + 314, + 316, + 317, + 318, + 319, + 320, + 323, + 324, + 334, + 335, + 337, + 338, + 339, + 349, + 354, + 355, + 356, + 358, + 359, + 360, + 361, + 362, + 363, + 364, + 372, + 373, + 374, + 375, + 376, + 377, + 378, + 380, + 386, + 387, + 388, + 389, + 390, + 391, + 392, + 393, + 394, + 395, + 405, + 406, + 410, + 411, + 412, + 413, + 414, + 419, + 420, + 423, + 424, + 425, + 427, + 428, + 429, + 435, + 436, + 437, + 438, + 439, + 440, + 441, + 442, + 443, + 444, + 445, + 452, + 453, + 454, + 455, + 456, + 457, + 461, + 462, + 463, + 464, + 465, + 466, + 467, + 468, + 469, + 470, + 471, + 475, + 476, + 480, + 484, + 485, + 486, + 487, + 488, + 489, + 490, + 491, + 493, + 494, + 497, + 499, + 505, + 506, + 509, + 510, + 511, + 518, + 519, + 520, + 521, + 522, + 523, + 524, + 525, + 526, + 527, + 529, + 530, + 531, + 532, + 533, + 538, + 542, + 543, + 544, + 545, + 547, + 548, + 549, + 550, + 551, + 552, + 553, + 554, + 555, + 556, + 558, + 559, + 560, + 564, + 565, + 567, + 568, + 569, + 570, + 571, + 572, + 573, + 579, + 580, + 581, + 582, + 583, + 584, + 585, + 586, + 587, + 588, + 589, + 590, + 591, + 592, + 593, + 594, + 595, + 596, + 597, + 598, + 599, + 600, + 601, + 602, + 603, + 604, + 605, + 606, + 607, + 608, + 609, + 610, + 611, + 612, + 613, + 614, + 615, + 616, + 617, + 619, + 620, + 621, + 622, + 623 + }; private class SectionDataSerializer : FieldSerializer { - static List tileFrameImportant = new() - { - 3, - 4, - 5, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 24, - 26, - 27, - 28, - 29, - 31, - 33, - 34, - 35, - 36, - 42, - 49, - 50, - 55, - 61, - 71, - 72, - 73, - 74, - 77, - 78, - 79, - 81, - 82, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 91, - 92, - 93, - 94, - 95, - 96, - 97, - 98, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 110, - 113, - 114, - 125, - 126, - 128, - 129, - 132, - 133, - 134, - 135, - 136, - 137, - 138, - 139, - 141, - 142, - 143, - 144, - 149, - 165, - 171, - 172, - 173, - 174, - 178, - 184, - 185, - 186, - 187, - 201, - 207, - 209, - 210, - 212, - 215, - 216, - 217, - 218, - 219, - 220, - 227, - 228, - 231, - 233, - 235, - 236, - 237, - 238, - 239, - 240, - 241, - 242, - 243, - 244, - 245, - 246, - 247, - 254, - 269, - 270, - 271, - 275, - 276, - 277, - 278, - 279, - 280, - 281, - 282, - 283, - 285, - 286, - 287, - 288, - 289, - 290, - 291, - 292, - 293, - 294, - 295, - 296, - 297, - 298, - 299, - 300, - 301, - 302, - 303, - 304, - 305, - 306, - 307, - 308, - 309, - 310, - 314, - 316, - 317, - 318, - 319, - 320, - 323, - 324, - 334, - 335, - 337, - 338, - 339, - 349, - 354, - 355, - 356, - 358, - 359, - 360, - 361, - 362, - 363, - 364, - 372, - 373, - 374, - 375, - 376, - 377, - 378, - 380, - 386, - 387, - 388, - 389, - 390, - 391, - 392, - 393, - 394, - 395, - 405, - 406, - 410, - 411, - 412, - 413, - 414, - 419, - 420, - 423, - 424, - 425, - 427, - 428, - 429, - 435, - 436, - 437, - 438, - 439, - 440, - 441, - 442, - 443, - 444, - 445, - 452, - 453, - 454, - 455, - 456, - 457, - 461, - 462, - 463, - 464, - 465, - 466, - 467, - 468, - 469, - 470, - 471, - 475, - 476, - 480, - 484, - 485, - 486, - 487, - 488, - 489, - 490, - 491, - 493, - 494, - 497, - 499, - 505, - 506, - 509, - 510, - 511, - 518, - 519, - 520, - 521, - 522, - 523, - 524, - 525, - 526, - 527, - 529, - 530, - 531, - 532, - 533, - 538, - 542, - 543, - 544, - 545, - 547, - 548, - 549, - 550, - 551, - 552, - 553, - 554, - 555, - 556, - 558, - 559, - 560, - 564, - 565, - 567, - 568, - 569, - 570, - 571, - 572, - 573, - 579, - 580, - 581, - 582, - 583, - 584, - 585, - 586, - 587, - 588, - 589, - 590, - 591, - 592, - 593, - 594, - 595, - 596, - 597, - 598, - 599, - 600, - 601, - 602, - 603, - 604, - 605, - 606, - 607, - 608, - 609, - 610, - 611, - 612, - 613, - 614, - 615, - 616, - 617, - 619, - 620, - 621, - 622, - 623 - }; protected override SectionData _Read(BinaryReader reader) { reader.BaseStream.Position = 1L; diff --git a/TrProtocol/Serializers/SquareDataSerializer.cs b/TrProtocol/Serializers/SquareDataSerializer.cs new file mode 100644 index 00000000..2a75e947 --- /dev/null +++ b/TrProtocol/Serializers/SquareDataSerializer.cs @@ -0,0 +1,109 @@ +using System.IO; + +namespace TrProtocol.Models +{ + [Serializer(typeof(SquareDataSerializer))] + public partial class SquareData + { + private class SquareDataSerializer : FieldSerializer + { + protected override SquareData _Read(BinaryReader br) + { + var square = new SquareData() + { + TilePosX = br.ReadInt16(), + TilePosY = br.ReadInt16(), + Width = br.ReadByte(), + Height = br.ReadByte(), + ChangeType = (TileChangeType)br.ReadByte(), + }; + square.Tiles = new SimpleTileData[square.Width, square.Height]; + for (int i = 0; i < square.Width; i++) + { + for (int j = 0; j < square.Height; j++) + { + var tile = new SimpleTileData + { + Flags1 = br.ReadByte(), + Flags2 = br.ReadByte() + }; + if (tile.Flags2[2]) + { + tile.TileColor = br.ReadByte(); + } + if (tile.Flags2[3]) + { + tile.WallColor = br.ReadByte(); + } + if (tile.Flags1[0]) + { + tile.TileType = br.ReadUInt16(); + if (SectionData.tileFrameImportant.Contains(tile.TileType)) + { + tile.FrameX = br.ReadInt16(); + tile.FrameY = br.ReadInt16(); + } + } + if (tile.Flags1[2]) + { + tile.WallType = br.ReadUInt16(); + } + if (tile.Flags1[3]) + { + tile.Liquid = br.ReadByte(); + tile.LiquidType = br.ReadByte(); + } + square.Tiles[i, j] = tile; + } + } + return square; + } + protected override void _Write(BinaryWriter bw, SquareData t) + { + bw.Write(t.TilePosX); + bw.Write(t.TilePosY); + bw.Write(t.Width); + bw.Write(t.Height); + bw.Write((byte)t.ChangeType); + for (int i = 0; i < t.Tiles.GetLength(0); i++) + { + for (int j = 0; j < t.Tiles.GetLength(1); j++) + { + var tile = t.Tiles[i, j]; + var flags1 = tile.Flags1; + var flags2 = tile.Flags2; + bw.Write(flags1); + bw.Write(flags2); + + if (flags2[2]) + { + bw.Write(tile.TileColor); + } + if (flags2[3]) + { + bw.Write(tile.WallColor); + } + if (flags1[0]) + { + bw.Write(tile.TileType); + if (SectionData.tileFrameImportant.Contains(tile.TileType)) + { + bw.Write(tile.FrameX); + bw.Write(tile.FrameY); + } + } + if (flags1[2]) + { + bw.Write(tile.WallType); + } + if (flags1[3]) + { + bw.Write(tile.Liquid); + bw.Write(tile.LiquidType); + } + } + } + } + } + } +} From 35f66ae275fb91e70bca3ecf2d901aa6da740e65 Mon Sep 17 00:00:00 2001 From: Megghy Date: Wed, 20 Oct 2021 19:03:36 +0800 Subject: [PATCH 2/2] change tileFrameImportant --- TrProtocol/Constants.cs | 22 ++ TrProtocol/Models/Position.cs | 9 + TrProtocol/Models/ShortPosition.cs | 5 + .../Serializers/SectionDataSerializer.cs | 358 +----------------- .../Serializers/SquareDataSerializer.cs | 4 +- 5 files changed, 40 insertions(+), 358 deletions(-) create mode 100644 TrProtocol/Constants.cs diff --git a/TrProtocol/Constants.cs b/TrProtocol/Constants.cs new file mode 100644 index 00000000..d9dd469b --- /dev/null +++ b/TrProtocol/Constants.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TrProtocol +{ + public static class Constants + { + public static readonly bool[] tileFrameImportant = Create(624, true, 3, 4, 5, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 26, 27, 28, 29, 31, 33, 34, 35, 36, 42, 49, 50, 55, 61, 71, 72, 73, 74, 77, 78, 79, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 110, 113, 114, 125, 126, 128, 129, 132, 133, 134, 135, 136, 137, 138, 139, 141, 142, 143, 144, 149, 165, 171, 172, 173, 174, 178, 184, 185, 186, 187, 201, 207, 209, 210, 212, 215, 216, 217, 218, 219, 220, 227, 228, 231, 233, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 254, 269, 270, 271, 275, 276, 277, 278, 279, 280, 281, 282, 283, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 314, 316, 317, 318, 319, 320, 323, 324, 334, 335, 337, 338, 339, 349, 354, 355, 356, 358, 359, 360, 361, 362, 363, 364, 372, 373, 374, 375, 376, 377, 378, 380, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 405, 406, 410, 411, 412, 413, 414, 419, 420, 423, 424, 425, 427, 428, 429, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 452, 453, 454, 455, 456, 457, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 475, 476, 480, 484, 485, 486, 487, 488, 489, 490, 491, 493, 494, 497, 499, 505, 506, 509, 510, 511, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 529, 530, 531, 532, 533, 538, 542, 543, 544, 545, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 558, 559, 560, 564, 565, 567, 568, 569, 570, 571, 572, 573, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 619, 620, 621, 622, 623); + private static T[] Create(int count, T nonDefaultValue, params int[] indexes) + { + var result = new T[count]; + foreach (var item in indexes) + { + result[item] = nonDefaultValue; + } + return result; + } + } +} diff --git a/TrProtocol/Models/Position.cs b/TrProtocol/Models/Position.cs index cab22998..3705f588 100644 --- a/TrProtocol/Models/Position.cs +++ b/TrProtocol/Models/Position.cs @@ -2,6 +2,15 @@ { public partial struct Position { + public Position(int x, int y) + { + X = x; + Y = y; + } public int X, Y; + public override string ToString() + { + return $"[{X}, {Y}]"; + } } } diff --git a/TrProtocol/Models/ShortPosition.cs b/TrProtocol/Models/ShortPosition.cs index 5eb00c20..64f2ad6e 100644 --- a/TrProtocol/Models/ShortPosition.cs +++ b/TrProtocol/Models/ShortPosition.cs @@ -2,6 +2,11 @@ { public partial struct ShortPosition { + public ShortPosition(short x, short y) + { + X = x; + Y = y; + } public short X, Y; public override string ToString() { diff --git a/TrProtocol/Serializers/SectionDataSerializer.cs b/TrProtocol/Serializers/SectionDataSerializer.cs index 2d167cd5..ad14b212 100644 --- a/TrProtocol/Serializers/SectionDataSerializer.cs +++ b/TrProtocol/Serializers/SectionDataSerializer.cs @@ -8,360 +8,6 @@ namespace TrProtocol.Models [Serializer(typeof(SectionDataSerializer))] public partial struct SectionData { - public static List tileFrameImportant = new() - { - 3, - 4, - 5, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 24, - 26, - 27, - 28, - 29, - 31, - 33, - 34, - 35, - 36, - 42, - 49, - 50, - 55, - 61, - 71, - 72, - 73, - 74, - 77, - 78, - 79, - 81, - 82, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 91, - 92, - 93, - 94, - 95, - 96, - 97, - 98, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 110, - 113, - 114, - 125, - 126, - 128, - 129, - 132, - 133, - 134, - 135, - 136, - 137, - 138, - 139, - 141, - 142, - 143, - 144, - 149, - 165, - 171, - 172, - 173, - 174, - 178, - 184, - 185, - 186, - 187, - 201, - 207, - 209, - 210, - 212, - 215, - 216, - 217, - 218, - 219, - 220, - 227, - 228, - 231, - 233, - 235, - 236, - 237, - 238, - 239, - 240, - 241, - 242, - 243, - 244, - 245, - 246, - 247, - 254, - 269, - 270, - 271, - 275, - 276, - 277, - 278, - 279, - 280, - 281, - 282, - 283, - 285, - 286, - 287, - 288, - 289, - 290, - 291, - 292, - 293, - 294, - 295, - 296, - 297, - 298, - 299, - 300, - 301, - 302, - 303, - 304, - 305, - 306, - 307, - 308, - 309, - 310, - 314, - 316, - 317, - 318, - 319, - 320, - 323, - 324, - 334, - 335, - 337, - 338, - 339, - 349, - 354, - 355, - 356, - 358, - 359, - 360, - 361, - 362, - 363, - 364, - 372, - 373, - 374, - 375, - 376, - 377, - 378, - 380, - 386, - 387, - 388, - 389, - 390, - 391, - 392, - 393, - 394, - 395, - 405, - 406, - 410, - 411, - 412, - 413, - 414, - 419, - 420, - 423, - 424, - 425, - 427, - 428, - 429, - 435, - 436, - 437, - 438, - 439, - 440, - 441, - 442, - 443, - 444, - 445, - 452, - 453, - 454, - 455, - 456, - 457, - 461, - 462, - 463, - 464, - 465, - 466, - 467, - 468, - 469, - 470, - 471, - 475, - 476, - 480, - 484, - 485, - 486, - 487, - 488, - 489, - 490, - 491, - 493, - 494, - 497, - 499, - 505, - 506, - 509, - 510, - 511, - 518, - 519, - 520, - 521, - 522, - 523, - 524, - 525, - 526, - 527, - 529, - 530, - 531, - 532, - 533, - 538, - 542, - 543, - 544, - 545, - 547, - 548, - 549, - 550, - 551, - 552, - 553, - 554, - 555, - 556, - 558, - 559, - 560, - 564, - 565, - 567, - 568, - 569, - 570, - 571, - 572, - 573, - 579, - 580, - 581, - 582, - 583, - 584, - 585, - 586, - 587, - 588, - 589, - 590, - 591, - 592, - 593, - 594, - 595, - 596, - 597, - 598, - 599, - 600, - 601, - 602, - 603, - 604, - 605, - 606, - 607, - 608, - 609, - 610, - 611, - 612, - 613, - 614, - 615, - 616, - 617, - 619, - 620, - 621, - 622, - 623 - }; private class SectionDataSerializer : FieldSerializer { protected override SectionData _Read(BinaryReader reader) @@ -468,7 +114,7 @@ ComplexTileData deserializeTile(BinaryReader br) // read a byte when this flag is false tile.TileType = flags1[5] ? br.ReadUInt16() : br.ReadByte(); - if (tileFrameImportant.Contains(tile.TileType)) + if (Constants.tileFrameImportant[tile.TileType]) { tile.FrameX = br.ReadInt16(); tile.FrameY = br.ReadInt16(); @@ -597,7 +243,7 @@ void serializeTile(BinaryWriter bw, ComplexTileData tile) bw.Write((byte)tile.TileType); - if (tileFrameImportant.Contains(tile.TileType)) + if (Constants.tileFrameImportant[tile.TileType]) { bw.Write(tile.FrameX); bw.Write(tile.FrameY); diff --git a/TrProtocol/Serializers/SquareDataSerializer.cs b/TrProtocol/Serializers/SquareDataSerializer.cs index 2a75e947..6db3ab9b 100644 --- a/TrProtocol/Serializers/SquareDataSerializer.cs +++ b/TrProtocol/Serializers/SquareDataSerializer.cs @@ -38,7 +38,7 @@ protected override SquareData _Read(BinaryReader br) if (tile.Flags1[0]) { tile.TileType = br.ReadUInt16(); - if (SectionData.tileFrameImportant.Contains(tile.TileType)) + if (Constants.tileFrameImportant[tile.TileType]) { tile.FrameX = br.ReadInt16(); tile.FrameY = br.ReadInt16(); @@ -86,7 +86,7 @@ protected override void _Write(BinaryWriter bw, SquareData t) if (flags1[0]) { bw.Write(tile.TileType); - if (SectionData.tileFrameImportant.Contains(tile.TileType)) + if (Constants.tileFrameImportant[tile.TileType]) { bw.Write(tile.FrameX); bw.Write(tile.FrameY);