Skip to content

Commit

Permalink
Merge pull request #16 from alborrajo/feature/npcs
Browse files Browse the repository at this point in the history
Working enemies and other NPCs
  • Loading branch information
alborrajo authored Feb 7, 2022
2 parents 63c6365 + 5b77b25 commit 4e5fac5
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 13 deletions.
1 change: 1 addition & 0 deletions Arrowgene.Ddon.GameServer/DdonGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ private void LoadPacketHandler()

AddHandler(new GroupChatGroupChatGetMemberListHandler(this));

AddHandler(new InstanceEnemyKillHandler(this));
AddHandler(new InstanceGetEnemySetListHandler(this));
AddHandler(new InstanceGetItemSetListHandler(this));

Expand Down
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);
}
}
}
23 changes: 23 additions & 0 deletions Arrowgene.Ddon.GameServer/Handler/InstanceEnemyKillHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Arrowgene.Ddon.Server;
using Arrowgene.Ddon.Server.Network;
using Arrowgene.Ddon.Shared.Entity.PacketStructure;
using Arrowgene.Ddon.Shared.Network;
using Arrowgene.Logging;

namespace Arrowgene.Ddon.GameServer.Handler
{
public class InstanceEnemyKillHandler : StructurePacketHandler<GameClient, C2SInstanceEnemyKillReq>
{
private static readonly ServerLogger Logger = LogProvider.Logger<ServerLogger>(typeof(InstanceEnemyKillHandler));


public InstanceEnemyKillHandler(DdonGameServer server) : base(server)
{
}

public override void Handle(GameClient client, StructurePacket<C2SInstanceEnemyKillReq> packet)
{
client.Send(new S2CInstanceEnemyKillRes());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public override void Handle(GameClient client, StructurePacket<C2SInstanceGetEne
CDataLayoutEnemyData layoutEnemyData = new CDataLayoutEnemyData();
layoutEnemyData.EnemyInfo.EnemyId = 0x010314;
layoutEnemyData.EnemyInfo.NamedEnemyParamsId = 0x8FA;
layoutEnemyData.EnemyInfo.Scale = 0x64; // Normal
layoutEnemyData.EnemyInfo.Lv = 0x5E;
layoutEnemyData.EnemyInfo.Scale = 100;
layoutEnemyData.EnemyInfo.Lv = 94;
layoutEnemyData.EnemyInfo.EnemyTargetTypesId = 1;
response.EnemyList.Add(layoutEnemyData);

Expand Down
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
37 changes: 37 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,8 @@ public abstract class EntitySerializer
Create(new C2SConnectionLoginReq.Serializer()),
Create(new C2SConnectionMoveInServerReq.Serializer()),
Create(new C2SConnectionMoveOutServerReq.Serializer()),
Create(new C2SContextGetSetContextReq.Serializer()),
Create(new C2SInstanceEnemyKillReq.Serializer()),
Create(new C2SInstanceGetEnemySetListReqSerializer()),
Create(new C2SLobbyChatMsgReq.Serializer()),
Create(new C2SLobbyJoinReq.Serializer()),
Expand Down Expand Up @@ -99,6 +102,10 @@ 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 S2CInstanceEnemyKillRes.Serializer()),
Create(new S2CInstanceEnemyRepopNtc.Serializer()),
Create(new S2CInstanceGetEnemySetListRes.Serializer()),
Create(new S2CLobbyChatMsgRes.Serializer()),
Create(new S2CLobbyChatMsgNotice.Serializer()),
Expand Down Expand Up @@ -207,6 +214,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,65 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Entity.Structure;
using Arrowgene.Ddon.Shared.Network;

namespace Arrowgene.Ddon.Shared.Entity.PacketStructure
{
public class C2SInstanceEnemyKillReq : IPacketStructure
{
public PacketId Id => PacketId.C2S_INSTANCE_ENEMY_KILL_REQ;

public C2SInstanceEnemyKillReq()
{
LayoutId=new CStageLayoutID();
SetId=0;
InnerId=0;
DropPosX=0;
DropPosY=0;
DropPosZ=0;
IsNoBattleReword=false;
Unk0=false;
RegionFlag=0;
}

public CStageLayoutID LayoutId { get; set; }
public uint SetId { get; set; }
public uint InnerId { get; set; }
public double DropPosX { get; set; }
public float DropPosY { get; set; }
public double DropPosZ { get; set; }
public bool IsNoBattleReword { get; set; }
public bool Unk0 { get; set; } // It's possible that IsNoBattleReword is this data instead
public uint RegionFlag { get; set; }

public class Serializer : EntitySerializer<C2SInstanceEnemyKillReq>
{
public override void Write(IBuffer buffer, C2SInstanceEnemyKillReq obj)
{
WriteEntity<CStageLayoutID>(buffer, obj.LayoutId);
WriteUInt32(buffer, obj.SetId);
WriteUInt32(buffer, obj.InnerId);
WriteDouble(buffer, obj.DropPosX);
WriteFloat(buffer, obj.DropPosY);
WriteDouble(buffer, obj.DropPosZ);
WriteBool(buffer, obj.IsNoBattleReword);
WriteBool(buffer, obj.Unk0);
WriteUInt32(buffer, obj.RegionFlag);
}

public override C2SInstanceEnemyKillReq Read(IBuffer buffer)
{
C2SInstanceEnemyKillReq obj = new C2SInstanceEnemyKillReq();
obj.LayoutId = ReadEntity<CStageLayoutID>(buffer);
obj.SetId = ReadUInt32(buffer);
obj.InnerId = ReadUInt32(buffer);
obj.DropPosX = ReadDouble(buffer);
obj.DropPosY = ReadFloat(buffer);
obj.DropPosZ = ReadDouble(buffer);
obj.IsNoBattleReword = ReadBool(buffer);
obj.Unk0 = ReadBool(buffer);
obj.RegionFlag = 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,36 @@
using Arrowgene.Buffers;
using Arrowgene.Ddon.Shared.Network;

namespace Arrowgene.Ddon.Shared.Entity.PacketStructure
{
public class S2CInstanceEnemyKillRes : ServerResponse
{
public override PacketId Id => PacketId.S2C_INSTANCE_ENEMY_KILL_RES;

public S2CInstanceEnemyKillRes()
{
EnemyId = 0;
KillNum = 0;
}

public uint EnemyId { get; set; }
public uint KillNum { get; set; }

public class Serializer : EntitySerializer<S2CInstanceEnemyKillRes>
{
public override void Write(IBuffer buffer, S2CInstanceEnemyKillRes obj)
{
WriteUInt32(buffer, obj.EnemyId);
WriteUInt32(buffer, obj.KillNum);
}

public override S2CInstanceEnemyKillRes Read(IBuffer buffer)
{
S2CInstanceEnemyKillRes obj = new S2CInstanceEnemyKillRes();
obj.EnemyId = ReadUInt32(buffer);
obj.KillNum = ReadUInt32(buffer);
return obj;
}
}
}
}
Loading

0 comments on commit 4e5fac5

Please sign in to comment.