From 9bb8cc816f257fc36c710efef365708100fdde03 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Sat, 28 Nov 2015 20:56:22 -0500 Subject: [PATCH] Finished SetCompletedAchievementsPacket and renamed CutsceneBookSetPacket to SetCutsceneBookPacket in line with other "set" packets. Moved a lot of the hardcoded packets into the coded login part under PacketProcessor. --- .gitignore | 2 + .../FFXIVClassic Map Server.csproj | 3 +- FFXIVClassic Map Server/PacketProcessor.cs | 17 +- FFXIVClassic Map Server/common/Utils.cs | 18 ++ .../send/player/CutsceneBookSetPacket.cs | 167 ------------------ .../player/SetCompletedAchievementsPacket.cs | 53 ++++++ .../send/player/SetCutsceneBookPacket.cs | 52 ++++++ 7 files changed, 143 insertions(+), 169 deletions(-) delete mode 100644 FFXIVClassic Map Server/packets/send/player/CutsceneBookSetPacket.cs create mode 100644 FFXIVClassic Map Server/packets/send/player/SetCompletedAchievementsPacket.cs create mode 100644 FFXIVClassic Map Server/packets/send/player/SetCutsceneBookPacket.cs diff --git a/.gitignore b/.gitignore index dc0fe642..eaa75434 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ FFXIVClassic Map Server/bin/Debug/packets/wireshark packets/ +FFXIVClassic Map Server/bin/ +FFXIVClassic Map Server/obj/ diff --git a/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj b/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj index 113e9c2d..8bdf643d 100644 --- a/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj +++ b/FFXIVClassic Map Server/FFXIVClassic Map Server.csproj @@ -106,8 +106,9 @@ + - + diff --git a/FFXIVClassic Map Server/PacketProcessor.cs b/FFXIVClassic Map Server/PacketProcessor.cs index 9b29fc07..194262f3 100644 --- a/FFXIVClassic Map Server/PacketProcessor.cs +++ b/FFXIVClassic Map Server/PacketProcessor.cs @@ -19,6 +19,7 @@ using FFXIVClassic_Map_Server.packets.send.Actor; using FFXIVClassic_Map_Server.packets.send.actor; using FFXIVClassic_Map_Server; using FFXIVClassic_Map_Server.packets.send.script; +using FFXIVClassic_Map_Server.packets.send.player; namespace FFXIVClassic_Lobby_Server { @@ -250,11 +251,25 @@ namespace FFXIVClassic_Lobby_Server ////////ITEMS//////// //The rest of hardcode + //client.queuePacket(BasePacket.createPacket(SetGCInfoPacket.buildPacket(player.actorID), true, false)); + //client.queuePacket(BasePacket.createPacket(SetGCInfoPacket.buildPacket(player.actorID), true, false)); + client.queuePacket(BasePacket.createPacket(SetPlayerTitlePacket.buildPacket(player.actorID, player.actorID, 0x00), true, false)); + client.queuePacket(BasePacket.createPacket(SetPlayerTitlePacket.buildPacket(player.actorID, player.actorID, 0x00), true, false)); + //client.queuePacket(BasePacket.createPacket(SetCurrentJobPacket.buildPacket(player.actorID, player.actorID, 0x00), true, false)); //196 + client.queuePacket(BasePacket.createPacket(SetChocoboNamePacket.buildPacket(player.actorID, player.actorID, "Boco"), true, false)); + //client.queuePacket(BasePacket.createPacket(SetPlayerTitlePacket.buildPacket(player.actorID, player.actorID, 0x00), true, false)); //199 + client.queuePacket(BasePacket.createPacket(SetPlayerTitlePacket.buildPacket(player.actorID, player.actorID, 0x00), true, false)); + client.queuePacket(BasePacket.createPacket(new SetCompletedAchievementsPacket().buildPacket(player.actorID), true, false)); + client.queuePacket(BasePacket.createPacket(SetLatestAchievementsPacket.buildPacket(player.actorID, new uint[5]), true, false)); + client.queuePacket(BasePacket.createPacket(SetAchievementPointsPacket.buildPacket(player.actorID, 0x00), true, false)); + //client.queuePacket(BasePacket.createPacket(new SetCutsceneBookPacket().buildPacket(player.actorID), true, false)); + //client.queuePacket(BasePacket.createPacket(SetPlayerDreamPacket.buildPacket(player.actorID, player.actorID, 0x00), true, false)); + client.queuePacket(reply7); client.queuePacket(reply8); client.queuePacket(reply9); client.queuePacket(reply10); - //client.queuePacket(reply11); + // client.queuePacket(reply11); client.queuePacket(reply12); inn.addActorToZone(player.getActor()); diff --git a/FFXIVClassic Map Server/common/Utils.cs b/FFXIVClassic Map Server/common/Utils.cs index 0ce7a84e..3d85fcb3 100644 --- a/FFXIVClassic Map Server/common/Utils.cs +++ b/FFXIVClassic Map Server/common/Utils.cs @@ -118,5 +118,23 @@ namespace FFXIVClassic_Lobby_Server.common return h; } + public static byte[] ConvertBoolArrayToBinaryStream(bool[] array) + { + byte[] data = new byte[(array.Length/8)+(array.Length%8 != 0 ? 1 : 0)]; + + int dataCounter = 0; + for (int i = 0; i < array.Length; i+=8) + { + for (int bitCount = 0; bitCount < 8; bitCount++) + { + if (i + bitCount >= array.Length) + break; + data[dataCounter] = (byte)(((array[i + bitCount] ? 1 : 0) << 7-bitCount) | data[dataCounter]); + } + dataCounter++; + } + + return data; + } } } diff --git a/FFXIVClassic Map Server/packets/send/player/CutsceneBookSetPacket.cs b/FFXIVClassic Map Server/packets/send/player/CutsceneBookSetPacket.cs deleted file mode 100644 index b0cf66b9..00000000 --- a/FFXIVClassic Map Server/packets/send/player/CutsceneBookSetPacket.cs +++ /dev/null @@ -1,167 +0,0 @@ -using FFXIVClassic_Lobby_Server.packets; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FFXIVClassic_Map_Server.packets.send.player -{ - class CutsceneBookSetPacket - { - public const ushort OPCODE = 0x01A3; - public const uint PACKET_SIZE = 0150; - - private byte[] mainstoryFlags = new byte[7]; - private byte[] classFlags = new byte[2*17]; - - public static SubPacket buildPacket(uint playerActorID) - { - byte[] data = new byte[PACKET_SIZE - 0x20]; - - byte currentOut = 0; - int byteIndex = 0; - int currentBit = 0; - - //Main Scenario - for (int i = 0; i < 60; i++) - { - currentOut = (byte) (1|(currentOut << currentBit)); - currentBit++; - - if (currentBit >= 8) - { - currentBit = 0; - data[byteIndex] = currentOut; - byteIndex++; - currentOut = 0; - } - } - - //Classes - for (int i = 0; i < 340; i++) - { - currentOut = (byte)(1 | (currentOut << currentBit)); - currentBit++; - - if (currentBit >= 8) - { - currentBit = 0; - data[byteIndex] = currentOut; - byteIndex++; - currentOut = 0; - } - } - - //GAP - for (int i = 0; i < 60; i++) - { - currentBit++; - if (currentBit >= 8) - { - currentBit = 0; - byteIndex++; - } - } - - //Side Quests - for (int i = 0; i < 372; i++) - { - currentOut = (byte)(1 | (currentOut << currentBit)); - currentBit++; - - if (currentBit >= 8) - { - currentBit = 0; - data[byteIndex] = currentOut; - byteIndex++; - currentOut = 0; - } - } - - //GAP - for (int i = 0; i < 228; i++) - { - currentBit++; - if (currentBit >= 8) - { - currentBit = 0; - byteIndex++; - } - } - - //Jobs - for (int i = 0; i < 140; i++) - { - currentOut = (byte)(1 | (currentOut << currentBit)); - currentBit++; - - if (currentBit >= 8) - { - currentBit = 0; - data[byteIndex] = currentOut; - byteIndex++; - currentOut = 0; - } - } - - //GAP - for (int i = 0; i < 61; i++) - { - currentBit++; - if (currentBit >= 8) - { - currentBit = 0; - byteIndex++; - } - } - - //Maelstrom - for (int i = 0; i < 200; i++) - { - currentOut = (byte)(1 | (currentOut << currentBit)); - currentBit++; - - if (currentBit >= 8) - { - currentBit = 0; - data[byteIndex] = currentOut; - byteIndex++; - currentOut = 0; - } - } - - //Adders - for (int i = 0; i < 200; i++) - { - currentOut = (byte)(1 | (currentOut << currentBit)); - currentBit++; - - if (currentBit >= 8) - { - currentBit = 0; - data[byteIndex] = currentOut; - byteIndex++; - currentOut = 0; - } - } - - //Flames - for (int i = 0; i < 200; i++) - { - currentOut = (byte)(1 | (currentOut << currentBit)); - currentBit++; - - if (currentBit >= 8) - { - currentBit = 0; - data[byteIndex] = currentOut; - byteIndex++; - currentOut = 0; - } - } - - return new SubPacket(OPCODE, playerActorID, playerActorID, data); - } - } -} diff --git a/FFXIVClassic Map Server/packets/send/player/SetCompletedAchievementsPacket.cs b/FFXIVClassic Map Server/packets/send/player/SetCompletedAchievementsPacket.cs new file mode 100644 index 00000000..25479a70 --- /dev/null +++ b/FFXIVClassic Map Server/packets/send/player/SetCompletedAchievementsPacket.cs @@ -0,0 +1,53 @@ +using FFXIVClassic_Lobby_Server.common; +using FFXIVClassic_Lobby_Server.packets; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FFXIVClassic_Map_Server.packets.send.player +{ + class SetCompletedAchievementsPacket + { + //Achievenments are +1 and up, except for Quests and GCs which is +2 + public const int CATEGORY_BATTLE = 000; + public const int CATEGORY_CHARACTER = 050; + public const int CATEGORY_CURRENCY = 200; + public const int CATEGORY_ITEMS = 250; + public const int CATEGORY_SYNTHESIS = 300; + public const int CATEGORY_GATHERING = 400; + public const int CATEGORY_MATERIA = 550; + public const int CATEGORY_QUESTS = 600; + public const int CATEGORY_SEASONAL_EVENTS = 700; + public const int CATEGORY_DUNGEONS = 750; + public const int CATEGORY_EXPLORATION = 800; + public const int CATEGORY_GRAND_COMPANY = 820; + + public const ushort OPCODE = 0x019A; + public const uint PACKET_SIZE = 0xA0; + + public bool[] achievementFlags = new bool[1024]; + + public SubPacket buildPacket(uint playerActorID) + { + byte[] data = new byte[PACKET_SIZE - 0x20]; + + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryWriter binWriter = new BinaryWriter(mem)) + { + byte[] binStream = Utils.ConvertBoolArrayToBinaryStream(achievementFlags); + if (binStream.Length <= PACKET_SIZE - 0x20) + binWriter.Write(binStream); + else + Log.error("Failed making SetCompletedAchievements packet. Bin Stream was too big!"); + } + } + + return new SubPacket(OPCODE, playerActorID, playerActorID, data); + } + + } +} \ No newline at end of file diff --git a/FFXIVClassic Map Server/packets/send/player/SetCutsceneBookPacket.cs b/FFXIVClassic Map Server/packets/send/player/SetCutsceneBookPacket.cs new file mode 100644 index 00000000..f7c2eb65 --- /dev/null +++ b/FFXIVClassic Map Server/packets/send/player/SetCutsceneBookPacket.cs @@ -0,0 +1,52 @@ +using FFXIVClassic_Lobby_Server.common; +using FFXIVClassic_Lobby_Server.packets; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FFXIVClassic_Map_Server.packets.send.player +{ + class SetCutsceneBookPacket + { + public const int CATEGORY_BATTLE = 000; + public const int CATEGORY_CHARACTER = 050; + public const int CATEGORY_CURRENCY = 200; + public const int CATEGORY_ITEMS = 250; + public const int CATEGORY_SYNTHESIS = 300; + public const int CATEGORY_GATHERING = 400; + public const int CATEGORY_MATERIA = 550; + public const int CATEGORY_QUESTS = 600; + public const int CATEGORY_SEASONAL_EVENTS = 700; + public const int CATEGORY_DUNGEONS = 750; + public const int CATEGORY_EXPLORATION = 800; + public const int CATEGORY_GRAND_COMPANY = 820; + + public const ushort OPCODE = 0x01A3; + public const uint PACKET_SIZE = 0150; + + public bool[] cutsceneFlags = new bool[2432]; + + public SubPacket buildPacket(uint playerActorID) + { + byte[] data = new byte[PACKET_SIZE - 0x20]; + + using (MemoryStream mem = new MemoryStream(data)) + { + using (BinaryWriter binWriter = new BinaryWriter(mem)) + { + byte[] binStream = Utils.ConvertBoolArrayToBinaryStream(cutsceneFlags); + if (binStream.Length <= PACKET_SIZE - 0x20) + binWriter.Write(binStream); + else + Log.error("Failed making SetCutsceneBook packet. Bin Stream was too big!"); + } + } + + return new SubPacket(OPCODE, playerActorID, playerActorID, data); + } + + } +}