From 414f26ed2c29cec9109de84326d44ee77211beac Mon Sep 17 00:00:00 2001 From: alborrajo Date: Mon, 7 Feb 2022 19:48:46 +0100 Subject: [PATCH] Basic context handling (ENEMIES NOW SPAWN) --- .../Handler/ContextGetSetContextHandler.cs | 24 ++++++--- .../Handler/StageAreaChangeHandler.cs | 2 +- .../Entity/EntitySerializer.cs | 35 ++++++++++++ .../C2SContextGetSetContextReq.cs | 53 +++++++++++++++++++ .../S2CContextGetSetContextRes.cs | 25 +++++++++ .../S2CContext_35_14_16_Ntc.cs | 34 ++++++++++++ .../S2CInstanceEnemyRepopNtc.cs | 42 +++++++++++++++ .../Entity/Structure/CData_35_14_16.cs | 33 ++++++++++++ Arrowgene.Ddon.Shared/Network/PacketId.cs | 2 +- 9 files changed, 240 insertions(+), 10 deletions(-) create mode 100644 Arrowgene.Ddon.Shared/Entity/PacketStructure/C2SContextGetSetContextReq.cs create mode 100644 Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContextGetSetContextRes.cs create mode 100644 Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContext_35_14_16_Ntc.cs create mode 100644 Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CInstanceEnemyRepopNtc.cs create mode 100644 Arrowgene.Ddon.Shared/Entity/Structure/CData_35_14_16.cs diff --git a/Arrowgene.Ddon.GameServer/Handler/ContextGetSetContextHandler.cs b/Arrowgene.Ddon.GameServer/Handler/ContextGetSetContextHandler.cs index f49abc61f..89bc8e63b 100644 --- a/Arrowgene.Ddon.GameServer/Handler/ContextGetSetContextHandler.cs +++ b/Arrowgene.Ddon.GameServer/Handler/ContextGetSetContextHandler.cs @@ -1,12 +1,12 @@ -using Arrowgene.Ddon.GameServer.Dump; -using Arrowgene.Ddon.Server; +using Arrowgene.Ddon.Server; using Arrowgene.Ddon.Server.Network; -using Arrowgene.Ddon.Shared.Network; +using Arrowgene.Ddon.Shared.Entity.PacketStructure; +using Arrowgene.Ddon.Shared.Entity.Structure; using Arrowgene.Logging; namespace Arrowgene.Ddon.GameServer.Handler { - public class ContextGetSetContextHandler : PacketHandler + public class ContextGetSetContextHandler : StructurePacketHandler { private static readonly ServerLogger Logger = LogProvider.Logger(typeof(ContextGetSetContextHandler)); @@ -15,11 +15,19 @@ public ContextGetSetContextHandler(DdonGameServer server) : base(server) { } - public override PacketId Id => PacketId.C2S_CONTEXT_GET_SET_CONTEXT_REQ; - - public override void Handle(GameClient client, Packet packet) + public override void Handle(GameClient client, StructurePacket packet) { - client.Send(SelectedDump.Dump_1715); + S2CContextGetSetContextRes res = new S2CContextGetSetContextRes(); + client.Send(res); + + CData_35_14_16 ntcData = new CData_35_14_16(); + ntcData.UniqueId = packet.Structure.UniqueId; + ntcData.Unk0 = 0; + + S2CContext_35_14_16_Ntc ntc = new S2CContext_35_14_16_Ntc(); + ntc.Unk0.Add(ntcData); + + client.Send(ntc); } } } diff --git a/Arrowgene.Ddon.GameServer/Handler/StageAreaChangeHandler.cs b/Arrowgene.Ddon.GameServer/Handler/StageAreaChangeHandler.cs index 06ec01094..a1be7f9b7 100644 --- a/Arrowgene.Ddon.GameServer/Handler/StageAreaChangeHandler.cs +++ b/Arrowgene.Ddon.GameServer/Handler/StageAreaChangeHandler.cs @@ -19,7 +19,7 @@ public StageAreaChangeHandler(DdonGameServer server) : base(server) public override void Handle(GameClient client, StructurePacket packet) { S2CStageAreaChangeRes res = new S2CStageAreaChangeRes(); - res.StageNo = convertIdToStageNo(packet.Structure.StageId); // TODO: Convert StageId to StageNo + res.StageNo = convertIdToStageNo(packet.Structure.StageId); res.IsBase = false; Logger.Debug(client, Util.ToXML(res)); diff --git a/Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs b/Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs index e2a07904b..c0f9a8934 100644 --- a/Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs +++ b/Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs @@ -14,6 +14,7 @@ public abstract class EntitySerializer new[] { // Data structure serializers + Create(new CData_35_14_16.Serializer()), Create(new CDataAchievementIdentifierSerializer()), Create(new CDataArisenProfileSerializer()), Create(new CDataCharacterEquipDataSerializer()), @@ -71,6 +72,7 @@ public abstract class EntitySerializer Create(new C2SConnectionLoginReq.Serializer()), Create(new C2SConnectionMoveInServerReq.Serializer()), Create(new C2SConnectionMoveOutServerReq.Serializer()), + Create(new C2SContextGetSetContextReq.Serializer()), Create(new C2SInstanceGetEnemySetListReqSerializer()), Create(new C2SLobbyChatMsgReq.Serializer()), Create(new C2SLobbyJoinReq.Serializer()), @@ -99,6 +101,9 @@ public abstract class EntitySerializer Create(new S2CConnectionLoginRes.Serializer()), Create(new S2CConnectionLogoutRes.Serializer()), Create(new S2CConnectionMoveOutServerRes.Serializer()), + Create(new S2CContext_35_14_16_Ntc.Serializer()), + Create(new S2CContextGetSetContextRes.Serializer()), + Create(new S2CInstanceEnemyRepopNtc.Serializer()), Create(new S2CInstanceGetEnemySetListRes.Serializer()), Create(new S2CLobbyChatMsgRes.Serializer()), Create(new S2CLobbyChatMsgNotice.Serializer()), @@ -207,6 +212,36 @@ protected ushort ReadUInt16(IBuffer buffer) return buffer.ReadUInt16(Endianness.Big); } + protected void WriteInt64(IBuffer buffer, long value) + { + buffer.WriteInt64(value, Endianness.Big); + } + + protected long ReadInt64(IBuffer buffer) + { + return buffer.ReadInt64(Endianness.Big); + } + + protected void WriteInt32(IBuffer buffer, int value) + { + buffer.WriteInt32(value, Endianness.Big); + } + + protected int ReadInt32(IBuffer buffer) + { + return buffer.ReadInt32(Endianness.Big); + } + + protected void WriteInt16(IBuffer buffer, short value) + { + buffer.WriteInt16(value, Endianness.Big); + } + + protected short ReadInt16(IBuffer buffer) + { + return buffer.ReadInt16(Endianness.Big); + } + protected void WriteBool(IBuffer buffer, bool value) { buffer.WriteBool(value); diff --git a/Arrowgene.Ddon.Shared/Entity/PacketStructure/C2SContextGetSetContextReq.cs b/Arrowgene.Ddon.Shared/Entity/PacketStructure/C2SContextGetSetContextReq.cs new file mode 100644 index 000000000..16f622245 --- /dev/null +++ b/Arrowgene.Ddon.Shared/Entity/PacketStructure/C2SContextGetSetContextReq.cs @@ -0,0 +1,53 @@ +using Arrowgene.Buffers; +using Arrowgene.Ddon.Shared.Network; + +namespace Arrowgene.Ddon.Shared.Entity.PacketStructure +{ + public class C2SContextGetSetContextReq : IPacketStructure + { + public PacketId Id => PacketId.C2S_CONTEXT_GET_SET_CONTEXT_REQ; + + public C2SContextGetSetContextReq() + { + ContextId=0; + UniqueId=0; + StageNo=0; + EncountArea=0; + MasterIndex=0; + Unk0=0; + } + + public uint ContextId { get; set; } // "Id" in the client code, renamed to ContextId to avoid collision with PacketId + public ulong UniqueId { get; set; } + public int StageNo { get; set; } + public int EncountArea { get; set; } + public int MasterIndex { get; set; } + public uint Unk0 { get; set; } + + public class Serializer : EntitySerializer + { + public override void Write(IBuffer buffer, C2SContextGetSetContextReq obj) + { + WriteUInt32(buffer, obj.ContextId); + WriteUInt64(buffer, obj.UniqueId); + WriteInt32(buffer, obj.StageNo); + WriteInt32(buffer, obj.EncountArea); + WriteInt32(buffer, obj.MasterIndex); + WriteUInt32(buffer, obj.Unk0); + } + + public override C2SContextGetSetContextReq Read(IBuffer buffer) + { + C2SContextGetSetContextReq obj = new C2SContextGetSetContextReq(); + obj.ContextId = ReadUInt32(buffer); + obj.UniqueId = ReadUInt64(buffer); + obj.StageNo = ReadInt32(buffer); + obj.EncountArea = ReadInt32(buffer); + obj.MasterIndex = ReadInt32(buffer); + obj.Unk0 = ReadUInt32(buffer); + return obj; + } + } + + } +} \ No newline at end of file diff --git a/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContextGetSetContextRes.cs b/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContextGetSetContextRes.cs new file mode 100644 index 000000000..6fdef00f6 --- /dev/null +++ b/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContextGetSetContextRes.cs @@ -0,0 +1,25 @@ +using Arrowgene.Buffers; +using Arrowgene.Ddon.Shared.Network; + +namespace Arrowgene.Ddon.Shared.Entity.PacketStructure +{ + public class S2CContextGetSetContextRes : ServerResponse + { + public override PacketId Id => PacketId.S2C_CONTEXT_GET_SET_CONTEXT_RES; + + public class Serializer : EntitySerializer + { + public override void Write(IBuffer buffer, S2CContextGetSetContextRes obj) + { + WriteServerResponse(buffer, obj); + } + + public override S2CContextGetSetContextRes Read(IBuffer buffer) + { + S2CContextGetSetContextRes obj = new S2CContextGetSetContextRes(); + ReadServerResponse(buffer, obj); + return obj; + } + } + } +} \ No newline at end of file diff --git a/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContext_35_14_16_Ntc.cs b/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContext_35_14_16_Ntc.cs new file mode 100644 index 000000000..cc6735f3a --- /dev/null +++ b/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CContext_35_14_16_Ntc.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using Arrowgene.Buffers; +using Arrowgene.Ddon.Shared.Entity.Structure; +using Arrowgene.Ddon.Shared.Network; + +namespace Arrowgene.Ddon.Shared.Entity.PacketStructure +{ + public class S2CContext_35_14_16_Ntc : IPacketStructure + { + public PacketId Id => PacketId.S2C_CONTEXT_35_14_16_NTC; + + public S2CContext_35_14_16_Ntc() + { + Unk0 = new List(); + } + + public List Unk0 { get; set; } // Probably a list of heartbeats for the different contexts? + + public class Serializer : EntitySerializer + { + public override void Write(IBuffer buffer, S2CContext_35_14_16_Ntc obj) + { + WriteEntityList(buffer, obj.Unk0); + } + + public override S2CContext_35_14_16_Ntc Read(IBuffer buffer) + { + S2CContext_35_14_16_Ntc obj = new S2CContext_35_14_16_Ntc(); + obj.Unk0 = ReadEntityList(buffer); + return obj; + } + } + } +} \ No newline at end of file diff --git a/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CInstanceEnemyRepopNtc.cs b/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CInstanceEnemyRepopNtc.cs new file mode 100644 index 000000000..182dfef4c --- /dev/null +++ b/Arrowgene.Ddon.Shared/Entity/PacketStructure/S2CInstanceEnemyRepopNtc.cs @@ -0,0 +1,42 @@ +using Arrowgene.Buffers; +using Arrowgene.Ddon.Shared.Entity.Structure; +using Arrowgene.Ddon.Shared.Network; + +namespace Arrowgene.Ddon.Shared.Entity.PacketStructure +{ + public class S2CInstanceEnemyRepopNtc : IPacketStructure + { + public PacketId Id => PacketId.S2C_INSTANCE_13_40_16_NTC; + + public S2CInstanceEnemyRepopNtc() + { + LayoutId = new CStageLayoutID(); + EnemyData = new CDataLayoutEnemyData(); + WaitSecond = 0; + } + + public CStageLayoutID LayoutId { get; set; } + public CDataLayoutEnemyData EnemyData { get; set; } + public uint WaitSecond { get; set; } + + public class Serializer : EntitySerializer + { + public override void Write(IBuffer buffer, S2CInstanceEnemyRepopNtc obj) + { + WriteEntity(buffer, obj.LayoutId); + WriteEntity(buffer, obj.EnemyData); + WriteUInt32(buffer, obj.WaitSecond); + } + + public override S2CInstanceEnemyRepopNtc Read(IBuffer buffer) + { + S2CInstanceEnemyRepopNtc obj = new S2CInstanceEnemyRepopNtc(); + obj.LayoutId = ReadEntity(buffer); + obj.EnemyData = ReadEntity(buffer); + obj.WaitSecond = ReadUInt32(buffer); + return obj; + } + } + + } +} \ No newline at end of file diff --git a/Arrowgene.Ddon.Shared/Entity/Structure/CData_35_14_16.cs b/Arrowgene.Ddon.Shared/Entity/Structure/CData_35_14_16.cs new file mode 100644 index 000000000..640d05ba6 --- /dev/null +++ b/Arrowgene.Ddon.Shared/Entity/Structure/CData_35_14_16.cs @@ -0,0 +1,33 @@ +using Arrowgene.Buffers; + +namespace Arrowgene.Ddon.Shared.Entity.Structure +{ + public class CData_35_14_16 + { + public CData_35_14_16() + { + UniqueId=0; + Unk0=0; + } + + public ulong UniqueId { get; set; } + public byte Unk0 { get; set; } + + public class Serializer : EntitySerializer + { + public override void Write(IBuffer buffer, CData_35_14_16 obj) + { + WriteUInt64(buffer, obj.UniqueId); + WriteByte(buffer, obj.Unk0); + } + + public override CData_35_14_16 Read(IBuffer buffer) + { + CData_35_14_16 obj = new CData_35_14_16(); + obj.UniqueId = ReadUInt64(buffer); + obj.Unk0 = ReadByte(buffer); + return obj; + } + } + } +} \ No newline at end of file diff --git a/Arrowgene.Ddon.Shared/Network/PacketId.cs b/Arrowgene.Ddon.Shared/Network/PacketId.cs index 6e2f33890..45fb27d94 100644 --- a/Arrowgene.Ddon.Shared/Network/PacketId.cs +++ b/Arrowgene.Ddon.Shared/Network/PacketId.cs @@ -874,7 +874,7 @@ private static Dictionary InitializeLoginPacketIds() public static readonly PacketId S2C_INSTANCE_13_37_16_NTC = new PacketId(13, 37, 16, "S2C_INSTANCE_13_37_16_NTC", ServerType.Game, PacketSource.Server); public static readonly PacketId S2C_INSTANCE_13_38_16_NTC = new PacketId(13, 38, 16, "S2C_INSTANCE_13_38_16_NTC", ServerType.Game, PacketSource.Server); public static readonly PacketId S2C_INSTANCE_13_39_16_NTC = new PacketId(13, 39, 16, "S2C_INSTANCE_13_39_16_NTC", ServerType.Game, PacketSource.Server); - public static readonly PacketId S2C_INSTANCE_13_40_16_NTC = new PacketId(13, 40, 16, "S2C_INSTANCE_13_40_16_NTC", ServerType.Game, PacketSource.Server); + public static readonly PacketId S2C_INSTANCE_13_40_16_NTC = new PacketId(13, 40, 16, "S2C_INSTANCE_ENEMY_REPOP_NTC", ServerType.Game, PacketSource.Server, "S2C_INSTANCE_13_40_16_NTC"); public static readonly PacketId S2C_INSTANCE_13_41_16_NTC = new PacketId(13, 41, 16, "S2C_INSTANCE_13_41_16_NTC", ServerType.Game, PacketSource.Server); public static readonly PacketId S2C_INSTANCE_13_42_16_NTC = new PacketId(13, 42, 16, "S2C_INSTANCE_13_42_16_NTC", ServerType.Game, PacketSource.Server); public static readonly PacketId C2S_INSTANCE_GET_EX_OM_INFO_REQ = new PacketId(13, 43, 1, "C2S_INSTANCE_GET_EX_OM_INFO_REQ", ServerType.Game, PacketSource.Client);