From b551220a9a85afa18cdfad7bbd541649f582b9c7 Mon Sep 17 00:00:00 2001 From: FateJH Date: Sun, 18 Sep 2016 20:10:24 -0400 Subject: [PATCH 1/4] added ChangeShortcutBankMessage packet and tests --- .../psforever/packet/GamePacketOpcode.scala | 2 +- .../game/ChangeShortcutBankMessage.scala | 38 +++++++++++++++++++ common/src/test/scala/GamePacketTest.scala | 21 ++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala diff --git a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala index 6e9984e5d..97e92e021 100644 --- a/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala +++ b/common/src/main/scala/net/psforever/packet/GamePacketOpcode.scala @@ -367,7 +367,7 @@ object GamePacketOpcode extends Enumeration { case 0x27 => noDecoder(ObjectDetachMessage) // 0x28 case 0x28 => noDecoder(CreateShortcutMessage) - case 0x29 => noDecoder(ChangeShortcutBankMessage) + case 0x29 => game.ChangeShortcutBankMessage.decode case 0x2a => noDecoder(ObjectAttachMessage) case 0x2b => noDecoder(UnknownMessage43) case 0x2c => noDecoder(PlanetsideAttributeMessage) diff --git a/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala new file mode 100644 index 000000000..efaaa85b8 --- /dev/null +++ b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala @@ -0,0 +1,38 @@ +// Copyright (c) 2016 PSForever.net to present +package net.psforever.packet.game + +import net.psforever.packet.{GamePacketOpcode, Marshallable, PlanetSideGamePacket} +import scodec.Codec +import scodec.codecs._ + +/** + * Switch the reference group of shortcuts on the HUD's hotbar.
+ *
+ * The hotbar contains eight slots for user shortcuts - medkits, implants, and text macros. + * Next to the first slot are up and down arrow buttons with a number. + * By progressing through the options available from the arrows, eight sets of eight shortcut slots are revealed. + * Which set is visible determines the effect of the activating the respective of eight binding keys for the hotbar. + * Each set is called a "bank."
+ *
+ * When shortcuts are manipulated, the bank acts as a reference point to the set and moves that set of eight shortcuts onto the HUD. + * Adding a shortcut to the first slot when viewing the second bank is the same as added a shortcut to the ninth slot when viewing the first bank. + * Obviously, there is no ninth slot. + * The slot value merely wraps back around into the next bank. + * The `bank` value can also wrap around through the first set, so requesting bank 8 (`80`) is the equivalent of requesting bank 1 (`00`). + * @param player_guid the player + * @param bank the shortcut bank (zero-indexed) + */ +final case class ChangeShortcutBankMessage(player_guid : PlanetSideGUID, + bank : Int) + extends PlanetSideGamePacket { + type Packet = ChangeShortcutBankMessage + def opcode = GamePacketOpcode.ChangeShortcutBankMessage + def encode = ChangeShortcutBankMessage.encode(this) +} + +object ChangeShortcutBankMessage extends Marshallable[ChangeShortcutBankMessage] { + implicit val codec : Codec[ChangeShortcutBankMessage] = ( + ("unk1" | PlanetSideGUID.codec) :: + ("bank" | uintL(4)) + ).as[ChangeShortcutBankMessage] +} diff --git a/common/src/test/scala/GamePacketTest.scala b/common/src/test/scala/GamePacketTest.scala index 2f7e8a11d..e144209a9 100644 --- a/common/src/test/scala/GamePacketTest.scala +++ b/common/src/test/scala/GamePacketTest.scala @@ -299,6 +299,27 @@ class GamePacketTest extends Specification { } } + "ChangeShortcutBankMessage" should { + val string = hex"29 4B00 20" + + "decode" in { + PacketCoding.DecodePacket(string).require match { + case ChangeShortcutBankMessage(player_guid, bank) => + player_guid mustEqual PlanetSideGUID(75) + bank mustEqual 2 + case default => + ko + } + } + + "encode" in { + val msg = ChangeShortcutBankMessage(PlanetSideGUID(75), 2) + val pkt = PacketCoding.EncodePacket(msg).require.toByteVector + + pkt mustEqual string + } + } + "DropItemMessage" should { val string = hex"37 4C00" From 1624ca6a10b6f551ada2da426107386c0de3ca58 Mon Sep 17 00:00:00 2001 From: FateJH Date: Sun, 18 Sep 2016 20:11:39 -0400 Subject: [PATCH 2/4] minor field name correction --- .../net/psforever/packet/game/ChangeShortcutBankMessage.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala index efaaa85b8..3a3fceb72 100644 --- a/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala +++ b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala @@ -32,7 +32,7 @@ final case class ChangeShortcutBankMessage(player_guid : PlanetSideGUID, object ChangeShortcutBankMessage extends Marshallable[ChangeShortcutBankMessage] { implicit val codec : Codec[ChangeShortcutBankMessage] = ( - ("unk1" | PlanetSideGUID.codec) :: + ("player_guid" | PlanetSideGUID.codec) :: ("bank" | uintL(4)) ).as[ChangeShortcutBankMessage] } From 7052f1319156a584cdd18b7109eeb7b9d144a068 Mon Sep 17 00:00:00 2001 From: FateJH Date: Sun, 18 Sep 2016 22:35:07 -0400 Subject: [PATCH 3/4] corrected comments --- .../packet/game/ChangeShortcutBankMessage.scala | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala index 3a3fceb72..99e3b6f5b 100644 --- a/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala +++ b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala @@ -6,21 +6,16 @@ import scodec.Codec import scodec.codecs._ /** - * Switch the reference group of shortcuts on the HUD's hotbar.
+ * Switch the set of shortcuts displayed on the HUD's hotbar.
*
* The hotbar contains eight slots for user shortcuts - medkits, implants, and text macros. * Next to the first slot are up and down arrow buttons with a number. * By progressing through the options available from the arrows, eight sets of eight shortcut slots are revealed. - * Which set is visible determines the effect of the activating the respective of eight binding keys for the hotbar. - * Each set is called a "bank."
- *
- * When shortcuts are manipulated, the bank acts as a reference point to the set and moves that set of eight shortcuts onto the HUD. - * Adding a shortcut to the first slot when viewing the second bank is the same as added a shortcut to the ninth slot when viewing the first bank. - * Obviously, there is no ninth slot. - * The slot value merely wraps back around into the next bank. - * The `bank` value can also wrap around through the first set, so requesting bank 8 (`80`) is the equivalent of requesting bank 1 (`00`). + * Which set is visible determines the effect of the activating the respective of eight binding keys (the Function keys) for the hotbar. + * Each set is called a "bank." * @param player_guid the player - * @param bank the shortcut bank (zero-indexed) + * @param bank the shortcut bank (zero-indexed); + * 0-7 are the valid banks */ final case class ChangeShortcutBankMessage(player_guid : PlanetSideGUID, bank : Int) From f081e40f7036c0c64482acfb2a8d6fec3bf3c062 Mon Sep 17 00:00:00 2001 From: FateJH Date: Tue, 10 Jan 2017 07:54:49 -0500 Subject: [PATCH 4/4] modifications to packet before merging --- .../packet/game/ChangeShortcutBankMessage.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala index 99e3b6f5b..c2a097bba 100644 --- a/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala +++ b/common/src/main/scala/net/psforever/packet/game/ChangeShortcutBankMessage.scala @@ -11,14 +11,16 @@ import scodec.codecs._ * The hotbar contains eight slots for user shortcuts - medkits, implants, and text macros. * Next to the first slot are up and down arrow buttons with a number. * By progressing through the options available from the arrows, eight sets of eight shortcut slots are revealed. - * Which set is visible determines the effect of the activating the respective of eight binding keys (the Function keys) for the hotbar. - * Each set is called a "bank." + * Which set is visible determines the effect of the respective binding keys (the Function keys) for the hotbar. + * Each set is called a "bank," obviously.
+ *
+ * This packet coordinates the bank number both as an upstream and as a downstream packet. * @param player_guid the player * @param bank the shortcut bank (zero-indexed); * 0-7 are the valid banks */ final case class ChangeShortcutBankMessage(player_guid : PlanetSideGUID, - bank : Int) + bank : Int) extends PlanetSideGamePacket { type Packet = ChangeShortcutBankMessage def opcode = GamePacketOpcode.ChangeShortcutBankMessage @@ -28,6 +30,6 @@ final case class ChangeShortcutBankMessage(player_guid : PlanetSideGUID, object ChangeShortcutBankMessage extends Marshallable[ChangeShortcutBankMessage] { implicit val codec : Codec[ChangeShortcutBankMessage] = ( ("player_guid" | PlanetSideGUID.codec) :: - ("bank" | uintL(4)) + ("bank" | uint4L) ).as[ChangeShortcutBankMessage] }