Skip to content

Commit

Permalink
Basic context handling (ENEMIES NOW SPAWN)
Browse files Browse the repository at this point in the history
  • Loading branch information
alborrajo committed Feb 7, 2022
1 parent 5e19700 commit 414f26e
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 10 deletions.
24 changes: 16 additions & 8 deletions Arrowgene.Ddon.GameServer/Handler/ContextGetSetContextHandler.cs
Original file line number Diff line number Diff line change
@@ -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<GameClient>
public class ContextGetSetContextHandler : StructurePacketHandler<GameClient, C2SContextGetSetContextReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(ContextGetSetContextHandler));

Expand All @@ -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<C2SContextGetSetContextReq> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public StageAreaChangeHandler(DdonGameServer server) : base(server)
public override void Handle(GameClient client, StructurePacket<C2SStageAreaChangeReq> 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));
Expand Down
35 changes: 35 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/EntitySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<C2SContextGetSetContextReq>
{
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;
}
}

}
}
Original file line number Diff line number Diff line change
@@ -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<S2CContextGetSetContextRes>
{
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;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<CData_35_14_16>();
}

public List<CData_35_14_16> Unk0 { get; set; } // Probably a list of heartbeats for the different contexts?

public class Serializer : EntitySerializer<S2CContext_35_14_16_Ntc>
{
public override void Write(IBuffer buffer, S2CContext_35_14_16_Ntc obj)
{
WriteEntityList<CData_35_14_16>(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<CData_35_14_16>(buffer);
return obj;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<S2CInstanceEnemyRepopNtc>
{
public override void Write(IBuffer buffer, S2CInstanceEnemyRepopNtc obj)
{
WriteEntity<CStageLayoutID>(buffer, obj.LayoutId);
WriteEntity<CDataLayoutEnemyData>(buffer, obj.EnemyData);
WriteUInt32(buffer, obj.WaitSecond);
}

public override S2CInstanceEnemyRepopNtc Read(IBuffer buffer)
{
S2CInstanceEnemyRepopNtc obj = new S2CInstanceEnemyRepopNtc();
obj.LayoutId = ReadEntity<CStageLayoutID>(buffer);
obj.EnemyData = ReadEntity<CDataLayoutEnemyData>(buffer);
obj.WaitSecond = ReadUInt32(buffer);
return obj;
}
}

}
}
33 changes: 33 additions & 0 deletions Arrowgene.Ddon.Shared/Entity/Structure/CData_35_14_16.cs
Original file line number Diff line number Diff line change
@@ -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<CData_35_14_16>
{
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;
}
}
}
}
2 changes: 1 addition & 1 deletion Arrowgene.Ddon.Shared/Network/PacketId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ private static Dictionary<int, PacketId> 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);
Expand Down

0 comments on commit 414f26e

Please sign in to comment.