From 7116c96b2f34f84e743665b49d443cb9d6a73c0a Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Tue, 13 Oct 2015 22:57:16 -0400 Subject: [PATCH] Fixed packet creators in Actor. Added replace id overload. Fixed Zone class, should work correctly. --- FFXIVClassic Map Server/Zone.cs | 40 ++++++++++--------- FFXIVClassic Map Server/dataobjects/Actor.cs | 31 +++++++++----- FFXIVClassic Map Server/packets/BasePacket.cs | 23 +++++++++++ 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/FFXIVClassic Map Server/Zone.cs b/FFXIVClassic Map Server/Zone.cs index 7b2a7cd1..b305e400 100644 --- a/FFXIVClassic Map Server/Zone.cs +++ b/FFXIVClassic Map Server/Zone.cs @@ -1,4 +1,5 @@ -using FFXIVClassic_Map_Server.dataobjects; +using FFXIVClassic_Lobby_Server.common; +using FFXIVClassic_Map_Server.dataobjects; using System; using System.Collections.Generic; using System.Linq; @@ -12,8 +13,8 @@ namespace FFXIVClassic_Map_Server public uint mapId; public ushort weatherNormal, weatherCommon, weatherRare; public ushort bgmDay, bgmNight, bgmBattle; - public int boundingGridSize = 200; - public int minX = -1000, minY = -1000, maxX = 1000, maxY = 1000; + public int boundingGridSize = 50; + public int minX = -100, minY = -100, maxX = 100, maxY = 100; private int numXBlocks, numYBlocks; private int halfWidth, halfHeight; private List[,] actorBlock; @@ -25,6 +26,15 @@ namespace FFXIVClassic_Map_Server actorBlock = new List[numXBlocks, numYBlocks]; halfWidth = numXBlocks / 2; halfHeight = numYBlocks / 2; + + for (int y = 0; y < numYBlocks; y++) + { + for (int x = 0; x < numXBlocks; x++ ) + { + actorBlock[x, y] = new List(); + } + } + } #region Actor Management @@ -32,7 +42,7 @@ namespace FFXIVClassic_Map_Server public void addActorToZone(Actor actor) { int gridX = (int)actor.positionX / boundingGridSize; - int gridY = (int)actor.positionY / boundingGridSize; + int gridY = (int)actor.positionZ / boundingGridSize; gridX += halfWidth; gridY += halfHeight; @@ -54,7 +64,7 @@ namespace FFXIVClassic_Map_Server public void removeActorToZone(Actor actor) { int gridX = (int)actor.positionX / boundingGridSize; - int gridY = (int)actor.positionY / boundingGridSize; + int gridY = (int)actor.positionZ / boundingGridSize; gridX += halfWidth; gridY += halfHeight; @@ -76,7 +86,7 @@ namespace FFXIVClassic_Map_Server public void updateActorPosition(Actor actor) { int gridX = (int)actor.positionX / boundingGridSize; - int gridY = (int)actor.positionY / boundingGridSize; + int gridY = (int)actor.positionZ / boundingGridSize; gridX += halfWidth; gridY += halfHeight; @@ -92,7 +102,7 @@ namespace FFXIVClassic_Map_Server gridY = numYBlocks - 1; int gridOldX = (int)actor.oldPositionX / boundingGridSize; - int gridOldY = (int)actor.oldPositionY / boundingGridSize; + int gridOldY = (int)actor.oldPositionZ / boundingGridSize; gridOldX += halfWidth; gridOldY += halfHeight; @@ -151,26 +161,18 @@ namespace FFXIVClassic_Map_Server public List getActorsAroundActor(Actor actor, int checkDistance) { int gridX = (int)actor.positionX / boundingGridSize; - int gridY = (int)actor.positionY / boundingGridSize; + int gridY = (int)actor.positionZ / boundingGridSize; gridX += halfWidth; gridY += halfHeight; - //Boundries - if (gridX < 0) - gridX = 0; - if (gridX >= numXBlocks) - gridX = numXBlocks - 1; - if (gridY < 0) - gridY = 0; - if (gridY >= numYBlocks) - gridY = numYBlocks - 1; + List result = new List(); - for (int gx = gridX - checkDistance; gx <= gridX + checkDistance; gx++) + for (int gy = ((gridY - checkDistance) < 0 ? 0 : (gridY - checkDistance)); gy <= ((gridY + checkDistance) >= numYBlocks ? numYBlocks - 1 : (gridY + checkDistance)); gy++) { - for (int gy = gridY - checkDistance; gy <= gridY + checkDistance; gy++) + for (int gx = ((gridX - checkDistance) < 0 ? 0 : (gridX - checkDistance)); gx <= ((gridX + checkDistance) >= numXBlocks ? numXBlocks - 1 : (gridX + checkDistance)); gx++) { result.AddRange(actorBlock[gx, gy]); } diff --git a/FFXIVClassic Map Server/dataobjects/Actor.cs b/FFXIVClassic Map Server/dataobjects/Actor.cs index 93817ea0..34f63a18 100644 --- a/FFXIVClassic Map Server/dataobjects/Actor.cs +++ b/FFXIVClassic Map Server/dataobjects/Actor.cs @@ -6,6 +6,7 @@ using FFXIVClassic_Map_Server.packets.send.actor; using FFXIVClassic_Map_Server.packets.send.Actor; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; @@ -108,33 +109,33 @@ namespace FFXIVClassic_Map_Server.dataobjects public SubPacket createNamePacket(uint playerActorID) { - return SetActorNamePacket.buildPacket(playerActorID, actorID, displayNameID, displayNameID == 0xFFFFFFFF ? customDisplayName : ""); + return SetActorNamePacket.buildPacket(actorID, playerActorID, displayNameID, displayNameID == 0xFFFFFFFF ? customDisplayName : ""); } public SubPacket createAppearancePacket(uint playerActorID) { SetActorAppearancePacket setappearance = new SetActorAppearancePacket(modelID, appearanceIDs); - return setappearance.buildPacket(playerActorID, actorID); + return setappearance.buildPacket(actorID, playerActorID); } public SubPacket createStatePacket(uint playerActorID) { - return SetActorStatePacket.buildPacket(playerActorID, actorID, currentState); + return SetActorStatePacket.buildPacket(actorID, playerActorID, currentState); } public SubPacket createSpeedPacket(uint playerActorID) { - return SetActorSpeedPacket.buildPacket(playerActorID, actorID); + return SetActorSpeedPacket.buildPacket(actorID, playerActorID); } public SubPacket createSpawnPositonPacket(uint playerActorID, uint spawnType) { - return SetActorPositionPacket.buildPacket(playerActorID, actorID, positionX, positionY, positionZ, rotation, spawnType); + return SetActorPositionPacket.buildPacket(actorID, playerActorID, positionX, positionY, positionZ, rotation, spawnType); } public SubPacket createPositionUpdatePacket(uint playerActorID) { - return MoveActorToPositionPacket.buildPacket(playerActorID, actorID, positionX, positionY, positionZ, rotation, moveState); + return MoveActorToPositionPacket.buildPacket(actorID, playerActorID, positionX, positionY, positionZ, rotation, moveState); } public SubPacket createScriptBindPacket(uint playerActorID) @@ -145,15 +146,27 @@ namespace FFXIVClassic_Map_Server.dataobjects public BasePacket createActorSpawnPackets(uint playerActorID) { List subpackets = new List(); - subpackets.Add(AddActorPacket.buildPacket(playerActorID, actorID)); + subpackets.Add(AddActorPacket.buildPacket(actorID, playerActorID, 8)); subpackets.Add(createSpeedPacket(playerActorID)); subpackets.Add(createSpawnPositonPacket(playerActorID, 0)); subpackets.Add(createAppearancePacket(playerActorID)); subpackets.Add(createNamePacket(playerActorID)); subpackets.Add(createStatePacket(playerActorID)); - subpackets.Add(createScriptBindPacket(playerActorID)); + //subpackets.Add(createScriptBindPacket(playerActorID)); + subpackets.Add(new SubPacket(0xCC, actorID, playerActorID, File.ReadAllBytes("./packets/playerscript"))); + subpackets.Add(new SubPacket(0x137, actorID, playerActorID, File.ReadAllBytes("./packets/playerscript2"))); + subpackets.Add(new SubPacket(0x137, actorID, playerActorID, File.ReadAllBytes("./packets/playerscript3"))); return BasePacket.createPacket(subpackets, true, false); - } + } + + public override bool Equals(Object obj) + { + Actor actorObj = obj as Actor; + if (actorObj == null) + return false; + else + return actorID == actorObj.actorID; + } } } diff --git a/FFXIVClassic Map Server/packets/BasePacket.cs b/FFXIVClassic Map Server/packets/BasePacket.cs index cf4c192f..fd2e2c62 100644 --- a/FFXIVClassic Map Server/packets/BasePacket.cs +++ b/FFXIVClassic Map Server/packets/BasePacket.cs @@ -166,6 +166,29 @@ namespace FFXIVClassic_Lobby_Server.packets } } + //Replaces all instances of the sniffed actorID with the given one + public void replaceActorID(uint fromActorID, uint actorID) + { + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryWriter binWriter = new BinaryWriter(mem)) + { + using (BinaryReader binreader = new BinaryReader(mem)) + { + while (binreader.BaseStream.Position + 4 < data.Length) + { + uint read = binreader.ReadUInt32(); + if (read == fromActorID) //Original ID + { + binWriter.BaseStream.Seek(binreader.BaseStream.Position - 0x4, SeekOrigin.Begin); + binWriter.Write(actorID); + } + } + } + } + } + } + #region Utility Functions public static BasePacket createPacket(List subpackets, bool isAuthed, bool isEncrypted) {