From fa09fcaf3f659ae4da835ca747a9277384843452 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Thu, 11 Feb 2021 07:45:50 -0500 Subject: [PATCH 1/3] Start inlining encoding stuff --- rattletrap.cabal | 2 +- src/lib/Rattletrap/Encode/AttributeMapping.hs | 2 +- src/lib/Rattletrap/Encode/Cache.hs | 2 +- src/lib/Rattletrap/Encode/ClassMapping.hs | 2 +- src/lib/Rattletrap/Encode/Content.hs | 1 - .../Rattletrap/Encode/DemolishAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Header.hs | 2 +- src/lib/Rattletrap/Encode/KeyFrame.hs | 2 +- src/lib/Rattletrap/Encode/List.hs | 1 - src/lib/Rattletrap/Encode/LoadoutAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Mark.hs | 2 +- src/lib/Rattletrap/Encode/Message.hs | 2 +- .../Encode/MusicStingerAttribute.hs | 2 +- src/lib/Rattletrap/Encode/PickupAttribute.hs | 2 +- .../Rattletrap/Encode/PickupAttributeNew.hs | 2 +- .../Encode/PrivateMatchSettingsAttribute.hs | 2 +- src/lib/Rattletrap/Encode/ProductAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Section.hs | 1 - .../Rattletrap/Encode/SpawnedReplication.hs | 2 +- .../Rattletrap/Encode/TeamPaintAttribute.hs | 2 +- src/lib/Rattletrap/Encode/TitleAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Word32le.hs | 21 +------------------ src/lib/Rattletrap/Type/Word32le.hs | 18 +++++++++++++--- 23 files changed, 34 insertions(+), 44 deletions(-) diff --git a/rattletrap.cabal b/rattletrap.cabal index 43de541c..a180547d 100644 --- a/rattletrap.cabal +++ b/rattletrap.cabal @@ -195,7 +195,6 @@ library Rattletrap.Encode.UpdatedReplication Rattletrap.Encode.Vector Rattletrap.Encode.WeldedInfoAttribute - Rattletrap.Encode.Word32le Rattletrap.Encode.Word64le Rattletrap.Encode.Word8le Rattletrap.Type.AppliedDamageAttribute @@ -285,6 +284,7 @@ library -Wno-all-missed-specialisations -Wno-implicit-prelude -Wno-missing-deriving-strategies + -Wno-missing-export-lists -Wno-missing-exported-signatures -Wno-missing-import-lists -Wno-safe diff --git a/src/lib/Rattletrap/Encode/AttributeMapping.hs b/src/lib/Rattletrap/Encode/AttributeMapping.hs index ca459ab5..c4e9ebfc 100644 --- a/src/lib/Rattletrap/Encode/AttributeMapping.hs +++ b/src/lib/Rattletrap/Encode/AttributeMapping.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.AttributeMapping ( putAttributeMapping ) where -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.AttributeMapping import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/Cache.hs b/src/lib/Rattletrap/Encode/Cache.hs index 842856f3..74025970 100644 --- a/src/lib/Rattletrap/Encode/Cache.hs +++ b/src/lib/Rattletrap/Encode/Cache.hs @@ -4,7 +4,7 @@ module Rattletrap.Encode.Cache import Rattletrap.Encode.AttributeMapping import Rattletrap.Encode.List -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.Cache import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/ClassMapping.hs b/src/lib/Rattletrap/Encode/ClassMapping.hs index 59acfc43..7c16e24c 100644 --- a/src/lib/Rattletrap/Encode/ClassMapping.hs +++ b/src/lib/Rattletrap/Encode/ClassMapping.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.ClassMapping ) where import Rattletrap.Encode.Str -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.ClassMapping import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/Content.hs b/src/lib/Rattletrap/Encode/Content.hs index fb6958b4..d3f5ea40 100644 --- a/src/lib/Rattletrap/Encode/Content.hs +++ b/src/lib/Rattletrap/Encode/Content.hs @@ -10,7 +10,6 @@ import Rattletrap.Encode.List import Rattletrap.Encode.Mark import Rattletrap.Encode.Message import Rattletrap.Encode.Str -import Rattletrap.Encode.Word32le import Rattletrap.Type.Content import Rattletrap.Type.Word32le import Rattletrap.Utility.Bytes diff --git a/src/lib/Rattletrap/Encode/DemolishAttribute.hs b/src/lib/Rattletrap/Encode/DemolishAttribute.hs index bde70607..246fa2b4 100644 --- a/src/lib/Rattletrap/Encode/DemolishAttribute.hs +++ b/src/lib/Rattletrap/Encode/DemolishAttribute.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.DemolishAttribute ) where import Rattletrap.Encode.Vector -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.DemolishAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/Header.hs b/src/lib/Rattletrap/Encode/Header.hs index 0e3f42aa..b6ca0e2a 100644 --- a/src/lib/Rattletrap/Encode/Header.hs +++ b/src/lib/Rattletrap/Encode/Header.hs @@ -5,7 +5,7 @@ module Rattletrap.Encode.Header import Rattletrap.Encode.Dictionary import Rattletrap.Encode.Property import Rattletrap.Encode.Str -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.Header import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/KeyFrame.hs b/src/lib/Rattletrap/Encode/KeyFrame.hs index a84393bf..89681692 100644 --- a/src/lib/Rattletrap/Encode/KeyFrame.hs +++ b/src/lib/Rattletrap/Encode/KeyFrame.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.KeyFrame ) where import Rattletrap.Encode.Float32le -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.KeyFrame import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/List.hs b/src/lib/Rattletrap/Encode/List.hs index fe0b5034..1c44eefd 100644 --- a/src/lib/Rattletrap/Encode/List.hs +++ b/src/lib/Rattletrap/Encode/List.hs @@ -2,7 +2,6 @@ module Rattletrap.Encode.List ( putList ) where -import Rattletrap.Encode.Word32le import Rattletrap.Type.List import Rattletrap.Type.Word32le diff --git a/src/lib/Rattletrap/Encode/LoadoutAttribute.hs b/src/lib/Rattletrap/Encode/LoadoutAttribute.hs index 550a57bc..01eb34c9 100644 --- a/src/lib/Rattletrap/Encode/LoadoutAttribute.hs +++ b/src/lib/Rattletrap/Encode/LoadoutAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.LoadoutAttribute ( putLoadoutAttribute ) where -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Encode.Word8le import Rattletrap.Type.LoadoutAttribute diff --git a/src/lib/Rattletrap/Encode/Mark.hs b/src/lib/Rattletrap/Encode/Mark.hs index 152f8731..6639ca06 100644 --- a/src/lib/Rattletrap/Encode/Mark.hs +++ b/src/lib/Rattletrap/Encode/Mark.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.Mark ) where import Rattletrap.Encode.Str -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.Mark import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/Message.hs b/src/lib/Rattletrap/Encode/Message.hs index af24e5e4..8364204e 100644 --- a/src/lib/Rattletrap/Encode/Message.hs +++ b/src/lib/Rattletrap/Encode/Message.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.Message ) where import Rattletrap.Encode.Str -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.Message import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/MusicStingerAttribute.hs b/src/lib/Rattletrap/Encode/MusicStingerAttribute.hs index 6cb15a05..f2c1d9c2 100644 --- a/src/lib/Rattletrap/Encode/MusicStingerAttribute.hs +++ b/src/lib/Rattletrap/Encode/MusicStingerAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.MusicStingerAttribute ( putMusicStingerAttribute ) where -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Encode.Word8le import Rattletrap.Type.MusicStingerAttribute diff --git a/src/lib/Rattletrap/Encode/PickupAttribute.hs b/src/lib/Rattletrap/Encode/PickupAttribute.hs index 5e803a2b..ac5fd8f2 100644 --- a/src/lib/Rattletrap/Encode/PickupAttribute.hs +++ b/src/lib/Rattletrap/Encode/PickupAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.PickupAttribute ( putPickupAttribute ) where -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.PickupAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/PickupAttributeNew.hs b/src/lib/Rattletrap/Encode/PickupAttributeNew.hs index 64bf5370..c1d7d251 100644 --- a/src/lib/Rattletrap/Encode/PickupAttributeNew.hs +++ b/src/lib/Rattletrap/Encode/PickupAttributeNew.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.PickupAttributeNew ( putPickupAttributeNew ) where -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Encode.Word8le import Rattletrap.Type.PickupAttributeNew diff --git a/src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs b/src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs index 3792eb0f..c82e044f 100644 --- a/src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs +++ b/src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.PrivateMatchSettingsAttribute ) where import Rattletrap.Encode.Str -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.PrivateMatchSettingsAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/ProductAttribute.hs b/src/lib/Rattletrap/Encode/ProductAttribute.hs index 196755a2..e312e565 100644 --- a/src/lib/Rattletrap/Encode/ProductAttribute.hs +++ b/src/lib/Rattletrap/Encode/ProductAttribute.hs @@ -5,7 +5,7 @@ module Rattletrap.Encode.ProductAttribute import Rattletrap.Encode.Common import Rattletrap.Encode.CompressedWord import Rattletrap.Encode.Str -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Encode.Word8le import Rattletrap.Type.ProductAttribute import Rattletrap.Type.Word8le diff --git a/src/lib/Rattletrap/Encode/Section.hs b/src/lib/Rattletrap/Encode/Section.hs index c625bc8a..52b65eac 100644 --- a/src/lib/Rattletrap/Encode/Section.hs +++ b/src/lib/Rattletrap/Encode/Section.hs @@ -2,7 +2,6 @@ module Rattletrap.Encode.Section ( putSection ) where -import Rattletrap.Encode.Word32le import Rattletrap.Type.Section import Rattletrap.Type.Word32le import Rattletrap.Utility.Crc diff --git a/src/lib/Rattletrap/Encode/SpawnedReplication.hs b/src/lib/Rattletrap/Encode/SpawnedReplication.hs index 07b400f5..2d6d898b 100644 --- a/src/lib/Rattletrap/Encode/SpawnedReplication.hs +++ b/src/lib/Rattletrap/Encode/SpawnedReplication.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.SpawnedReplication ) where import Rattletrap.Encode.Initialization -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.SpawnedReplication import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/TeamPaintAttribute.hs b/src/lib/Rattletrap/Encode/TeamPaintAttribute.hs index c6b6e8a0..f5f7c25d 100644 --- a/src/lib/Rattletrap/Encode/TeamPaintAttribute.hs +++ b/src/lib/Rattletrap/Encode/TeamPaintAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.TeamPaintAttribute ( putTeamPaintAttribute ) where -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Encode.Word8le import Rattletrap.Type.TeamPaintAttribute diff --git a/src/lib/Rattletrap/Encode/TitleAttribute.hs b/src/lib/Rattletrap/Encode/TitleAttribute.hs index 0f80be4f..626fc772 100644 --- a/src/lib/Rattletrap/Encode/TitleAttribute.hs +++ b/src/lib/Rattletrap/Encode/TitleAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.TitleAttribute ( putTitleAttribute ) where -import Rattletrap.Encode.Word32le +import Rattletrap.Type.Word32le import Rattletrap.Type.TitleAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/Word32le.hs b/src/lib/Rattletrap/Encode/Word32le.hs index 908a3ad1..ead5a7c0 100644 --- a/src/lib/Rattletrap/Encode/Word32le.hs +++ b/src/lib/Rattletrap/Encode/Word32le.hs @@ -1,20 +1 @@ -module Rattletrap.Encode.Word32le - ( putWord32 - , putWord32Bits - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString.Lazy as LazyBytes - -putWord32 :: Word32le -> Binary.Put -putWord32 word32 = Binary.putWord32le (word32leValue word32) - -putWord32Bits :: Word32le -> BinaryBits.BitPut () -putWord32Bits word32 = do - let bytes = LazyBytes.toStrict (Binary.runPut (putWord32 word32)) - BinaryBits.putByteString (reverseBytes bytes) +module Rattletrap.Encode.Word32le where diff --git a/src/lib/Rattletrap/Type/Word32le.hs b/src/lib/Rattletrap/Type/Word32le.hs index 990fee3d..cad9b0b4 100644 --- a/src/lib/Rattletrap/Type/Word32le.hs +++ b/src/lib/Rattletrap/Type/Word32le.hs @@ -1,13 +1,25 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Word32le - ( Word32le(..) - ) where +module Rattletrap.Type.Word32le where import Rattletrap.Type.Common +import Rattletrap.Utility.Bytes + +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString.Lazy as LazyBytes newtype Word32le = Word32le { word32leValue :: Word32 } deriving (Eq, Ord, Show) $(deriveJson ''Word32le) + +putWord32 :: Word32le -> Binary.Put +putWord32 word32 = Binary.putWord32le (word32leValue word32) + +putWord32Bits :: Word32le -> BinaryBits.BitPut () +putWord32Bits word32 = do + let bytes = LazyBytes.toStrict (Binary.runPut (putWord32 word32)) + BinaryBits.putByteString (reverseBytes bytes) From 15e360bab630fe42accdf6b47953d01c93c68617 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Thu, 11 Feb 2021 22:35:07 -0500 Subject: [PATCH 2/3] Inline more encoding stuff --- rattletrap.cabal | 48 ----------------- .../Encode/AppliedDamageAttribute.hs | 6 +-- src/lib/Rattletrap/Encode/AttributeValue.hs | 44 ++++++++-------- src/lib/Rattletrap/Encode/ByteAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Cache.hs | 2 +- src/lib/Rattletrap/Encode/ClassMapping.hs | 2 +- .../Rattletrap/Encode/ClubColorsAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Content.hs | 10 ++-- .../Encode/CustomDemolishAttribute.hs | 2 +- .../Rattletrap/Encode/DamageStateAttribute.hs | 6 +-- .../Rattletrap/Encode/DemolishAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Dictionary.hs | 2 +- .../Rattletrap/Encode/ExplosionAttribute.hs | 4 +- .../Rattletrap/Encode/FlaggedByteAttribute.hs | 2 +- .../Rattletrap/Encode/FlaggedIntAttribute.hs | 2 +- src/lib/Rattletrap/Encode/Frame.hs | 2 +- src/lib/Rattletrap/Encode/Header.hs | 21 -------- src/lib/Rattletrap/Encode/Initialization.hs | 18 ------- src/lib/Rattletrap/Encode/Int32le.hs | 20 ------- src/lib/Rattletrap/Encode/Int64Attribute.hs | 12 ----- src/lib/Rattletrap/Encode/Int64le.hs | 19 ------- src/lib/Rattletrap/Encode/Int8Vector.hs | 22 -------- src/lib/Rattletrap/Encode/Int8le.hs | 18 ------- src/lib/Rattletrap/Encode/IntAttribute.hs | 11 ---- src/lib/Rattletrap/Encode/KeyFrame.hs | 15 ------ src/lib/Rattletrap/Encode/List.hs | 14 ----- src/lib/Rattletrap/Encode/LoadoutAttribute.hs | 34 ------------ .../Encode/LoadoutOnlineAttribute.hs | 16 ------ .../Rattletrap/Encode/LoadoutsAttribute.hs | 13 ----- .../Encode/LoadoutsOnlineAttribute.hs | 17 ------ .../Rattletrap/Encode/LocationAttribute.hs | 12 ----- src/lib/Rattletrap/Encode/Mark.hs | 14 ----- src/lib/Rattletrap/Encode/Message.hs | 15 ------ .../Encode/MusicStingerAttribute.hs | 15 ------ .../Rattletrap/Encode/PartyLeaderAttribute.hs | 18 ------- src/lib/Rattletrap/Encode/PickupAttribute.hs | 17 ------ .../Rattletrap/Encode/PickupAttributeNew.hs | 18 ------- .../Encode/PlayerHistoryKeyAttribute.hs | 12 ----- .../Encode/PrivateMatchSettingsAttribute.hs | 25 --------- src/lib/Rattletrap/Encode/ProductAttribute.hs | 36 ------------- src/lib/Rattletrap/Encode/Property.hs | 16 ------ src/lib/Rattletrap/Encode/PropertyValue.hs | 29 ----------- src/lib/Rattletrap/Encode/QWordAttribute.hs | 12 ----- src/lib/Rattletrap/Encode/Quaternion.hs | 40 -------------- src/lib/Rattletrap/Encode/RemoteId.hs | 36 ------------- src/lib/Rattletrap/Encode/Replay.hs | 20 ------- src/lib/Rattletrap/Encode/Replication.hs | 25 --------- src/lib/Rattletrap/Encode/ReplicationValue.hs | 24 --------- .../Rattletrap/Encode/ReservationAttribute.hs | 23 -------- .../Encode/RigidBodyStateAttribute.hs | 21 -------- src/lib/Rattletrap/Encode/Rotation.hs | 14 ----- src/lib/Rattletrap/Encode/Section.hs | 29 ----------- .../Rattletrap/Encode/SpawnedReplication.hs | 18 ------- .../Rattletrap/Encode/StatEventAttribute.hs | 13 ----- src/lib/Rattletrap/Encode/Str.hs | 52 ------------------- src/lib/Rattletrap/Encode/StringAttribute.hs | 12 ----- .../Rattletrap/Encode/TeamPaintAttribute.hs | 17 ------ src/lib/Rattletrap/Encode/TitleAttribute.hs | 19 ------- .../Rattletrap/Encode/UniqueIdAttribute.hs | 15 ------ .../Rattletrap/Encode/UpdatedReplication.hs | 12 ----- src/lib/Rattletrap/Encode/Vector.hs | 26 ---------- .../Rattletrap/Encode/WeldedInfoAttribute.hs | 19 ------- src/lib/Rattletrap/Encode/Word32le.hs | 1 - src/lib/Rattletrap/Encode/Word64le.hs | 20 ------- src/lib/Rattletrap/Encode/Word8le.hs | 20 ------- src/lib/Rattletrap/Type/Header.hs | 17 ++++-- src/lib/Rattletrap/Type/Initialization.hs | 15 ++++-- src/lib/Rattletrap/Type/Int32le.hs | 18 +++++-- src/lib/Rattletrap/Type/Int64Attribute.hs | 10 ++-- src/lib/Rattletrap/Type/Int64le.hs | 18 +++++-- src/lib/Rattletrap/Type/Int8Vector.hs | 19 +++++-- src/lib/Rattletrap/Type/Int8le.hs | 17 ++++-- src/lib/Rattletrap/Type/IntAttribute.hs | 9 ++-- src/lib/Rattletrap/Type/KeyFrame.hs | 13 +++-- src/lib/Rattletrap/Type/List.hs | 13 +++-- src/lib/Rattletrap/Type/LoadoutAttribute.hs | 31 +++++++++-- .../Rattletrap/Type/LoadoutOnlineAttribute.hs | 13 +++-- src/lib/Rattletrap/Type/LoadoutsAttribute.hs | 11 ++-- .../Type/LoadoutsOnlineAttribute.hs | 15 ++++-- src/lib/Rattletrap/Type/LocationAttribute.hs | 10 ++-- src/lib/Rattletrap/Type/Mark.hs | 11 ++-- src/lib/Rattletrap/Type/Message.hs | 12 +++-- .../Rattletrap/Type/MusicStingerAttribute.hs | 12 +++-- .../Rattletrap/Type/PartyLeaderAttribute.hs | 15 ++++-- src/lib/Rattletrap/Type/PickupAttribute.hs | 15 ++++-- src/lib/Rattletrap/Type/PickupAttributeNew.hs | 15 ++++-- .../Type/PlayerHistoryKeyAttribute.hs | 11 ++-- .../Type/PrivateMatchSettingsAttribute.hs | 22 ++++++-- src/lib/Rattletrap/Type/ProductAttribute.hs | 33 ++++++++++-- src/lib/Rattletrap/Type/Property.hs | 12 +++-- src/lib/Rattletrap/Type/PropertyValue.hs | 23 ++++++-- src/lib/Rattletrap/Type/QWordAttribute.hs | 10 ++-- src/lib/Rattletrap/Type/Quaternion.hs | 43 +++++++++++---- src/lib/Rattletrap/Type/RemoteId.hs | 32 ++++++++++-- src/lib/Rattletrap/Type/Replay.hs | 18 +++++-- src/lib/Rattletrap/Type/Replication.hs | 23 ++++++-- src/lib/Rattletrap/Type/ReplicationValue.hs | 21 ++++++-- .../Rattletrap/Type/ReservationAttribute.hs | 20 +++++-- .../Type/RigidBodyStateAttribute.hs | 18 +++++-- src/lib/Rattletrap/Type/Rotation.hs | 12 +++-- src/lib/Rattletrap/Type/Section.hs | 22 ++++++-- src/lib/Rattletrap/Type/SpawnedReplication.hs | 15 ++++-- src/lib/Rattletrap/Type/StatEventAttribute.hs | 11 ++-- src/lib/Rattletrap/Type/Str.hs | 48 +++++++++++++++-- src/lib/Rattletrap/Type/StringAttribute.hs | 10 ++-- src/lib/Rattletrap/Type/TeamPaintAttribute.hs | 14 +++-- src/lib/Rattletrap/Type/TitleAttribute.hs | 17 ++++-- src/lib/Rattletrap/Type/UniqueIdAttribute.hs | 12 +++-- src/lib/Rattletrap/Type/UpdatedReplication.hs | 11 ++-- src/lib/Rattletrap/Type/Vector.hs | 24 +++++++-- .../Rattletrap/Type/WeldedInfoAttribute.hs | 15 ++++-- src/lib/Rattletrap/Type/Word64le.hs | 18 +++++-- src/lib/Rattletrap/Type/Word8le.hs | 18 +++++-- src/lib/Rattletrap/Utility/Helper.hs | 1 - 114 files changed, 732 insertions(+), 1214 deletions(-) delete mode 100644 src/lib/Rattletrap/Encode/Header.hs delete mode 100644 src/lib/Rattletrap/Encode/Initialization.hs delete mode 100644 src/lib/Rattletrap/Encode/Int32le.hs delete mode 100644 src/lib/Rattletrap/Encode/Int64Attribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Int64le.hs delete mode 100644 src/lib/Rattletrap/Encode/Int8Vector.hs delete mode 100644 src/lib/Rattletrap/Encode/Int8le.hs delete mode 100644 src/lib/Rattletrap/Encode/IntAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/KeyFrame.hs delete mode 100644 src/lib/Rattletrap/Encode/List.hs delete mode 100644 src/lib/Rattletrap/Encode/LoadoutAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/LoadoutOnlineAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/LoadoutsAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/LoadoutsOnlineAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/LocationAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Mark.hs delete mode 100644 src/lib/Rattletrap/Encode/Message.hs delete mode 100644 src/lib/Rattletrap/Encode/MusicStingerAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/PartyLeaderAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/PickupAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/PickupAttributeNew.hs delete mode 100644 src/lib/Rattletrap/Encode/PlayerHistoryKeyAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/ProductAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Property.hs delete mode 100644 src/lib/Rattletrap/Encode/PropertyValue.hs delete mode 100644 src/lib/Rattletrap/Encode/QWordAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Quaternion.hs delete mode 100644 src/lib/Rattletrap/Encode/RemoteId.hs delete mode 100644 src/lib/Rattletrap/Encode/Replay.hs delete mode 100644 src/lib/Rattletrap/Encode/Replication.hs delete mode 100644 src/lib/Rattletrap/Encode/ReplicationValue.hs delete mode 100644 src/lib/Rattletrap/Encode/ReservationAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/RigidBodyStateAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Rotation.hs delete mode 100644 src/lib/Rattletrap/Encode/Section.hs delete mode 100644 src/lib/Rattletrap/Encode/SpawnedReplication.hs delete mode 100644 src/lib/Rattletrap/Encode/StatEventAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Str.hs delete mode 100644 src/lib/Rattletrap/Encode/StringAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/TeamPaintAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/TitleAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/UniqueIdAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/UpdatedReplication.hs delete mode 100644 src/lib/Rattletrap/Encode/Vector.hs delete mode 100644 src/lib/Rattletrap/Encode/WeldedInfoAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Word32le.hs delete mode 100644 src/lib/Rattletrap/Encode/Word64le.hs delete mode 100644 src/lib/Rattletrap/Encode/Word8le.hs diff --git a/rattletrap.cabal b/rattletrap.cabal index a180547d..27438784 100644 --- a/rattletrap.cabal +++ b/rattletrap.cabal @@ -149,54 +149,6 @@ library Rattletrap.Encode.FloatAttribute Rattletrap.Encode.Frame Rattletrap.Encode.GameModeAttribute - Rattletrap.Encode.Header - Rattletrap.Encode.Initialization - Rattletrap.Encode.Int32le - Rattletrap.Encode.Int64Attribute - Rattletrap.Encode.Int64le - Rattletrap.Encode.Int8le - Rattletrap.Encode.Int8Vector - Rattletrap.Encode.IntAttribute - Rattletrap.Encode.KeyFrame - Rattletrap.Encode.List - Rattletrap.Encode.LoadoutAttribute - Rattletrap.Encode.LoadoutOnlineAttribute - Rattletrap.Encode.LoadoutsAttribute - Rattletrap.Encode.LoadoutsOnlineAttribute - Rattletrap.Encode.LocationAttribute - Rattletrap.Encode.Mark - Rattletrap.Encode.Message - Rattletrap.Encode.MusicStingerAttribute - Rattletrap.Encode.PartyLeaderAttribute - Rattletrap.Encode.PickupAttribute - Rattletrap.Encode.PickupAttributeNew - Rattletrap.Encode.PlayerHistoryKeyAttribute - Rattletrap.Encode.PrivateMatchSettingsAttribute - Rattletrap.Encode.ProductAttribute - Rattletrap.Encode.Property - Rattletrap.Encode.PropertyValue - Rattletrap.Encode.Quaternion - Rattletrap.Encode.QWordAttribute - Rattletrap.Encode.RemoteId - Rattletrap.Encode.Replay - Rattletrap.Encode.Replication - Rattletrap.Encode.ReplicationValue - Rattletrap.Encode.ReservationAttribute - Rattletrap.Encode.RigidBodyStateAttribute - Rattletrap.Encode.Rotation - Rattletrap.Encode.Section - Rattletrap.Encode.SpawnedReplication - Rattletrap.Encode.StatEventAttribute - Rattletrap.Encode.Str - Rattletrap.Encode.StringAttribute - Rattletrap.Encode.TeamPaintAttribute - Rattletrap.Encode.TitleAttribute - Rattletrap.Encode.UniqueIdAttribute - Rattletrap.Encode.UpdatedReplication - Rattletrap.Encode.Vector - Rattletrap.Encode.WeldedInfoAttribute - Rattletrap.Encode.Word64le - Rattletrap.Encode.Word8le Rattletrap.Type.AppliedDamageAttribute Rattletrap.Type.Attribute Rattletrap.Type.AttributeMapping diff --git a/src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs b/src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs index 6bc7d674..fa176f43 100644 --- a/src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs +++ b/src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs @@ -2,9 +2,9 @@ module Rattletrap.Encode.AppliedDamageAttribute ( putAppliedDamageAttribute ) where -import Rattletrap.Encode.Int32le -import Rattletrap.Encode.Vector -import Rattletrap.Encode.Word8le +import Rattletrap.Type.Int32le +import Rattletrap.Type.Vector +import Rattletrap.Type.Word8le import Rattletrap.Type.AppliedDamageAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/AttributeValue.hs b/src/lib/Rattletrap/Encode/AttributeValue.hs index d055da05..fcfcaeeb 100644 --- a/src/lib/Rattletrap/Encode/AttributeValue.hs +++ b/src/lib/Rattletrap/Encode/AttributeValue.hs @@ -17,28 +17,28 @@ import Rattletrap.Encode.FlaggedByteAttribute import Rattletrap.Encode.FlaggedIntAttribute import Rattletrap.Encode.FloatAttribute import Rattletrap.Encode.GameModeAttribute -import Rattletrap.Encode.Int64Attribute -import Rattletrap.Encode.IntAttribute -import Rattletrap.Encode.LoadoutAttribute -import Rattletrap.Encode.LoadoutOnlineAttribute -import Rattletrap.Encode.LoadoutsAttribute -import Rattletrap.Encode.LoadoutsOnlineAttribute -import Rattletrap.Encode.LocationAttribute -import Rattletrap.Encode.MusicStingerAttribute -import Rattletrap.Encode.PartyLeaderAttribute -import Rattletrap.Encode.PickupAttribute -import Rattletrap.Encode.PickupAttributeNew -import Rattletrap.Encode.PlayerHistoryKeyAttribute -import Rattletrap.Encode.PrivateMatchSettingsAttribute -import Rattletrap.Encode.QWordAttribute -import Rattletrap.Encode.ReservationAttribute -import Rattletrap.Encode.RigidBodyStateAttribute -import Rattletrap.Encode.StatEventAttribute -import Rattletrap.Encode.StringAttribute -import Rattletrap.Encode.TeamPaintAttribute -import Rattletrap.Encode.TitleAttribute -import Rattletrap.Encode.UniqueIdAttribute -import Rattletrap.Encode.WeldedInfoAttribute +import Rattletrap.Type.Int64Attribute +import Rattletrap.Type.IntAttribute +import Rattletrap.Type.LoadoutAttribute +import Rattletrap.Type.LoadoutOnlineAttribute +import Rattletrap.Type.LoadoutsAttribute +import Rattletrap.Type.LoadoutsOnlineAttribute +import Rattletrap.Type.LocationAttribute +import Rattletrap.Type.MusicStingerAttribute +import Rattletrap.Type.PartyLeaderAttribute +import Rattletrap.Type.PickupAttribute +import Rattletrap.Type.PickupAttributeNew +import Rattletrap.Type.PlayerHistoryKeyAttribute +import Rattletrap.Type.PrivateMatchSettingsAttribute +import Rattletrap.Type.QWordAttribute +import Rattletrap.Type.ReservationAttribute +import Rattletrap.Type.RigidBodyStateAttribute +import Rattletrap.Type.StatEventAttribute +import Rattletrap.Type.StringAttribute +import Rattletrap.Type.TeamPaintAttribute +import Rattletrap.Type.TitleAttribute +import Rattletrap.Type.UniqueIdAttribute +import Rattletrap.Type.WeldedInfoAttribute import Rattletrap.Type.AttributeValue import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/ByteAttribute.hs b/src/lib/Rattletrap/Encode/ByteAttribute.hs index 7948db01..df1fcd03 100644 --- a/src/lib/Rattletrap/Encode/ByteAttribute.hs +++ b/src/lib/Rattletrap/Encode/ByteAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.ByteAttribute ( putByteAttribute ) where -import Rattletrap.Encode.Word8le +import Rattletrap.Type.Word8le import Rattletrap.Type.ByteAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/Cache.hs b/src/lib/Rattletrap/Encode/Cache.hs index 74025970..86cfdb6c 100644 --- a/src/lib/Rattletrap/Encode/Cache.hs +++ b/src/lib/Rattletrap/Encode/Cache.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.Cache ) where import Rattletrap.Encode.AttributeMapping -import Rattletrap.Encode.List +import Rattletrap.Type.List import Rattletrap.Type.Word32le import Rattletrap.Type.Cache diff --git a/src/lib/Rattletrap/Encode/ClassMapping.hs b/src/lib/Rattletrap/Encode/ClassMapping.hs index 7c16e24c..b85bf81e 100644 --- a/src/lib/Rattletrap/Encode/ClassMapping.hs +++ b/src/lib/Rattletrap/Encode/ClassMapping.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.ClassMapping ( putClassMapping ) where -import Rattletrap.Encode.Str +import Rattletrap.Type.Str import Rattletrap.Type.Word32le import Rattletrap.Type.ClassMapping diff --git a/src/lib/Rattletrap/Encode/ClubColorsAttribute.hs b/src/lib/Rattletrap/Encode/ClubColorsAttribute.hs index 9c277818..d91450e0 100644 --- a/src/lib/Rattletrap/Encode/ClubColorsAttribute.hs +++ b/src/lib/Rattletrap/Encode/ClubColorsAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.ClubColorsAttribute ( putClubColorsAttribute ) where -import Rattletrap.Encode.Word8le +import Rattletrap.Type.Word8le import Rattletrap.Type.ClubColorsAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/Content.hs b/src/lib/Rattletrap/Encode/Content.hs index d3f5ea40..9f26b873 100644 --- a/src/lib/Rattletrap/Encode/Content.hs +++ b/src/lib/Rattletrap/Encode/Content.hs @@ -5,11 +5,11 @@ module Rattletrap.Encode.Content import Rattletrap.Encode.Cache import Rattletrap.Encode.ClassMapping import Rattletrap.Encode.Frame -import Rattletrap.Encode.KeyFrame -import Rattletrap.Encode.List -import Rattletrap.Encode.Mark -import Rattletrap.Encode.Message -import Rattletrap.Encode.Str +import Rattletrap.Type.KeyFrame +import Rattletrap.Type.List +import Rattletrap.Type.Mark +import Rattletrap.Type.Message +import Rattletrap.Type.Str import Rattletrap.Type.Content import Rattletrap.Type.Word32le import Rattletrap.Utility.Bytes diff --git a/src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs b/src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs index 87045fac..c38595bf 100644 --- a/src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs +++ b/src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.CustomDemolishAttribute ) where import Rattletrap.Encode.DemolishAttribute -import Rattletrap.Encode.Int32le +import Rattletrap.Type.Int32le import Rattletrap.Type.CustomDemolishAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/DamageStateAttribute.hs b/src/lib/Rattletrap/Encode/DamageStateAttribute.hs index 0ff00f39..799b8ba4 100644 --- a/src/lib/Rattletrap/Encode/DamageStateAttribute.hs +++ b/src/lib/Rattletrap/Encode/DamageStateAttribute.hs @@ -2,9 +2,9 @@ module Rattletrap.Encode.DamageStateAttribute ( putDamageStateAttribute ) where -import Rattletrap.Encode.Int32le -import Rattletrap.Encode.Vector -import Rattletrap.Encode.Word8le +import Rattletrap.Type.Int32le +import Rattletrap.Type.Vector +import Rattletrap.Type.Word8le import Rattletrap.Type.DamageStateAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/DemolishAttribute.hs b/src/lib/Rattletrap/Encode/DemolishAttribute.hs index 246fa2b4..c6db8643 100644 --- a/src/lib/Rattletrap/Encode/DemolishAttribute.hs +++ b/src/lib/Rattletrap/Encode/DemolishAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.DemolishAttribute ( putDemolishAttribute ) where -import Rattletrap.Encode.Vector +import Rattletrap.Type.Vector import Rattletrap.Type.Word32le import Rattletrap.Type.DemolishAttribute diff --git a/src/lib/Rattletrap/Encode/Dictionary.hs b/src/lib/Rattletrap/Encode/Dictionary.hs index f27beb52..f94514d6 100644 --- a/src/lib/Rattletrap/Encode/Dictionary.hs +++ b/src/lib/Rattletrap/Encode/Dictionary.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.Dictionary ( putDictionary ) where -import Rattletrap.Encode.Str +import Rattletrap.Type.Str import Rattletrap.Type.Dictionary import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Encode/ExplosionAttribute.hs b/src/lib/Rattletrap/Encode/ExplosionAttribute.hs index 4421291c..d5a066cd 100644 --- a/src/lib/Rattletrap/Encode/ExplosionAttribute.hs +++ b/src/lib/Rattletrap/Encode/ExplosionAttribute.hs @@ -2,8 +2,8 @@ module Rattletrap.Encode.ExplosionAttribute ( putExplosionAttribute ) where -import Rattletrap.Encode.Int32le -import Rattletrap.Encode.Vector +import Rattletrap.Type.Int32le +import Rattletrap.Type.Vector import Rattletrap.Type.ExplosionAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs b/src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs index 83d2ca6e..55ab3f78 100644 --- a/src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs +++ b/src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.FlaggedByteAttribute ( putFlaggedByteAttribute ) where -import Rattletrap.Encode.Word8le +import Rattletrap.Type.Word8le import Rattletrap.Type.FlaggedByteAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs b/src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs index 962b04b3..0076867f 100644 --- a/src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs +++ b/src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs @@ -2,7 +2,7 @@ module Rattletrap.Encode.FlaggedIntAttribute ( putFlaggedIntAttribute ) where -import Rattletrap.Encode.Int32le +import Rattletrap.Type.Int32le import Rattletrap.Type.FlaggedIntAttribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/Frame.hs b/src/lib/Rattletrap/Encode/Frame.hs index ffc78e78..6cae024b 100644 --- a/src/lib/Rattletrap/Encode/Frame.hs +++ b/src/lib/Rattletrap/Encode/Frame.hs @@ -3,7 +3,7 @@ module Rattletrap.Encode.Frame ) where import Rattletrap.Encode.Float32le -import Rattletrap.Encode.Replication +import Rattletrap.Type.Replication import Rattletrap.Type.Frame import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Encode/Header.hs b/src/lib/Rattletrap/Encode/Header.hs deleted file mode 100644 index b6ca0e2a..00000000 --- a/src/lib/Rattletrap/Encode/Header.hs +++ /dev/null @@ -1,21 +0,0 @@ -module Rattletrap.Encode.Header - ( putHeader - ) where - -import Rattletrap.Encode.Dictionary -import Rattletrap.Encode.Property -import Rattletrap.Encode.Str -import Rattletrap.Type.Word32le -import Rattletrap.Type.Header - -import qualified Data.Binary as Binary - -putHeader :: Header -> Binary.Put -putHeader header = do - putWord32 (headerEngineVersion header) - putWord32 (headerLicenseeVersion header) - case headerPatchVersion header of - Nothing -> pure () - Just patchVersion -> putWord32 patchVersion - putText (headerLabel header) - putDictionary putProperty (headerProperties header) diff --git a/src/lib/Rattletrap/Encode/Initialization.hs b/src/lib/Rattletrap/Encode/Initialization.hs deleted file mode 100644 index 4c8f8402..00000000 --- a/src/lib/Rattletrap/Encode/Initialization.hs +++ /dev/null @@ -1,18 +0,0 @@ -module Rattletrap.Encode.Initialization - ( putInitialization - ) where - -import Rattletrap.Encode.Int8Vector -import Rattletrap.Encode.Vector -import Rattletrap.Type.Initialization - -import qualified Data.Binary.Bits.Put as BinaryBits - -putInitialization :: Initialization -> BinaryBits.BitPut () -putInitialization initialization = do - case initializationLocation initialization of - Nothing -> pure () - Just location -> putVector location - case initializationRotation initialization of - Nothing -> pure () - Just rotation -> putInt8Vector rotation diff --git a/src/lib/Rattletrap/Encode/Int32le.hs b/src/lib/Rattletrap/Encode/Int32le.hs deleted file mode 100644 index b682fd0b..00000000 --- a/src/lib/Rattletrap/Encode/Int32le.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Rattletrap.Encode.Int32le - ( putInt32 - , putInt32Bits - ) where - -import Rattletrap.Type.Int32le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString.Lazy as LazyBytes - -putInt32 :: Int32le -> Binary.Put -putInt32 int32 = Binary.putInt32le (int32leValue int32) - -putInt32Bits :: Int32le -> BinaryBits.BitPut () -putInt32Bits int32 = do - let bytes = LazyBytes.toStrict (Binary.runPut (putInt32 int32)) - BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Encode/Int64Attribute.hs b/src/lib/Rattletrap/Encode/Int64Attribute.hs deleted file mode 100644 index b41b6d34..00000000 --- a/src/lib/Rattletrap/Encode/Int64Attribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.Int64Attribute - ( putInt64Attribute - ) where - -import Rattletrap.Encode.Int64le -import Rattletrap.Type.Int64Attribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putInt64Attribute :: Int64Attribute -> BinaryBits.BitPut () -putInt64Attribute int64Attribute = - putInt64Bits (int64AttributeValue int64Attribute) diff --git a/src/lib/Rattletrap/Encode/Int64le.hs b/src/lib/Rattletrap/Encode/Int64le.hs deleted file mode 100644 index fc231e17..00000000 --- a/src/lib/Rattletrap/Encode/Int64le.hs +++ /dev/null @@ -1,19 +0,0 @@ -module Rattletrap.Encode.Int64le - ( putInt64Bits - ) where - -import Rattletrap.Type.Int64le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString.Lazy as LazyBytes - -putInt64 :: Int64le -> Binary.Put -putInt64 int64 = Binary.putInt64le (int64leValue int64) - -putInt64Bits :: Int64le -> BinaryBits.BitPut () -putInt64Bits int64 = do - let bytes = LazyBytes.toStrict (Binary.runPut (putInt64 int64)) - BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Encode/Int8Vector.hs b/src/lib/Rattletrap/Encode/Int8Vector.hs deleted file mode 100644 index c253d64e..00000000 --- a/src/lib/Rattletrap/Encode/Int8Vector.hs +++ /dev/null @@ -1,22 +0,0 @@ -module Rattletrap.Encode.Int8Vector - ( putInt8Vector - ) where - -import Rattletrap.Encode.Int8le -import Rattletrap.Type.Int8Vector -import Rattletrap.Type.Int8le - -import qualified Data.Binary.Bits.Put as BinaryBits - -putInt8Vector :: Int8Vector -> BinaryBits.BitPut () -putInt8Vector int8Vector = do - putInt8VectorField (int8VectorX int8Vector) - putInt8VectorField (int8VectorY int8Vector) - putInt8VectorField (int8VectorZ int8Vector) - -putInt8VectorField :: Maybe Int8le -> BinaryBits.BitPut () -putInt8VectorField maybeField = case maybeField of - Nothing -> BinaryBits.putBool False - Just field -> do - BinaryBits.putBool True - putInt8Bits field diff --git a/src/lib/Rattletrap/Encode/Int8le.hs b/src/lib/Rattletrap/Encode/Int8le.hs deleted file mode 100644 index 1228cad3..00000000 --- a/src/lib/Rattletrap/Encode/Int8le.hs +++ /dev/null @@ -1,18 +0,0 @@ -module Rattletrap.Encode.Int8le - ( putInt8Bits - ) where - -import Rattletrap.Type.Int8le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString.Lazy as LazyBytes - -putInt8 :: Int8le -> Binary.Put -putInt8 int8 = Binary.putInt8 (int8leValue int8) - -putInt8Bits :: Int8le -> BinaryBits.BitPut () -putInt8Bits int8 = do - let bytes = LazyBytes.toStrict (Binary.runPut (putInt8 int8)) - BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Encode/IntAttribute.hs b/src/lib/Rattletrap/Encode/IntAttribute.hs deleted file mode 100644 index c2284ff9..00000000 --- a/src/lib/Rattletrap/Encode/IntAttribute.hs +++ /dev/null @@ -1,11 +0,0 @@ -module Rattletrap.Encode.IntAttribute - ( putIntAttribute - ) where - -import Rattletrap.Encode.Int32le -import Rattletrap.Type.IntAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putIntAttribute :: IntAttribute -> BinaryBits.BitPut () -putIntAttribute intAttribute = putInt32Bits (intAttributeValue intAttribute) diff --git a/src/lib/Rattletrap/Encode/KeyFrame.hs b/src/lib/Rattletrap/Encode/KeyFrame.hs deleted file mode 100644 index 89681692..00000000 --- a/src/lib/Rattletrap/Encode/KeyFrame.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.KeyFrame - ( putKeyFrame - ) where - -import Rattletrap.Encode.Float32le -import Rattletrap.Type.Word32le -import Rattletrap.Type.KeyFrame - -import qualified Data.Binary as Binary - -putKeyFrame :: KeyFrame -> Binary.Put -putKeyFrame keyFrame = do - putFloat32 (keyFrameTime keyFrame) - putWord32 (keyFrameFrame keyFrame) - putWord32 (keyFramePosition keyFrame) diff --git a/src/lib/Rattletrap/Encode/List.hs b/src/lib/Rattletrap/Encode/List.hs deleted file mode 100644 index 1c44eefd..00000000 --- a/src/lib/Rattletrap/Encode/List.hs +++ /dev/null @@ -1,14 +0,0 @@ -module Rattletrap.Encode.List - ( putList - ) where - -import Rattletrap.Type.List -import Rattletrap.Type.Word32le - -import qualified Data.Binary as Binary - -putList :: (a -> Binary.Put) -> List a -> Binary.Put -putList putElement list = do - let elements = listValue list - putWord32 (Word32le (fromIntegral (length elements))) - mapM_ putElement elements diff --git a/src/lib/Rattletrap/Encode/LoadoutAttribute.hs b/src/lib/Rattletrap/Encode/LoadoutAttribute.hs deleted file mode 100644 index 01eb34c9..00000000 --- a/src/lib/Rattletrap/Encode/LoadoutAttribute.hs +++ /dev/null @@ -1,34 +0,0 @@ -module Rattletrap.Encode.LoadoutAttribute - ( putLoadoutAttribute - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Encode.Word8le -import Rattletrap.Type.LoadoutAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putLoadoutAttribute :: LoadoutAttribute -> BinaryBits.BitPut () -putLoadoutAttribute loadoutAttribute = do - putWord8Bits (loadoutAttributeVersion loadoutAttribute) - putWord32Bits (loadoutAttributeBody loadoutAttribute) - putWord32Bits (loadoutAttributeDecal loadoutAttribute) - putWord32Bits (loadoutAttributeWheels loadoutAttribute) - putWord32Bits (loadoutAttributeRocketTrail loadoutAttribute) - putWord32Bits (loadoutAttributeAntenna loadoutAttribute) - putWord32Bits (loadoutAttributeTopper loadoutAttribute) - putWord32Bits (loadoutAttributeUnknown1 loadoutAttribute) - putOptional (loadoutAttributeUnknown2 loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeEngineAudio loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeTrail loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeGoalExplosion loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeBanner loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeUnknown3 loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeUnknown4 loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeUnknown5 loadoutAttribute) putWord32Bits - putOptional (loadoutAttributeUnknown6 loadoutAttribute) putWord32Bits - -putOptional :: Maybe a -> (a -> BinaryBits.BitPut ()) -> BinaryBits.BitPut () -putOptional m f = case m of - Just x -> f x - Nothing -> pure () diff --git a/src/lib/Rattletrap/Encode/LoadoutOnlineAttribute.hs b/src/lib/Rattletrap/Encode/LoadoutOnlineAttribute.hs deleted file mode 100644 index 80d9dd39..00000000 --- a/src/lib/Rattletrap/Encode/LoadoutOnlineAttribute.hs +++ /dev/null @@ -1,16 +0,0 @@ -module Rattletrap.Encode.LoadoutOnlineAttribute - ( putLoadoutOnlineAttribute - ) where - -import Rattletrap.Encode.ProductAttribute -import Rattletrap.Encode.Word8le -import Rattletrap.Type.LoadoutOnlineAttribute -import Rattletrap.Type.Word8le - -import qualified Data.Binary.Bits.Put as BinaryBits - -putLoadoutOnlineAttribute :: LoadoutOnlineAttribute -> BinaryBits.BitPut () -putLoadoutOnlineAttribute loadoutAttribute = do - let attributes = loadoutAttributeValue loadoutAttribute - putWord8Bits (Word8le (fromIntegral (length attributes))) - mapM_ putProductAttributes attributes diff --git a/src/lib/Rattletrap/Encode/LoadoutsAttribute.hs b/src/lib/Rattletrap/Encode/LoadoutsAttribute.hs deleted file mode 100644 index 0ef73e52..00000000 --- a/src/lib/Rattletrap/Encode/LoadoutsAttribute.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Rattletrap.Encode.LoadoutsAttribute - ( putLoadoutsAttribute - ) where - -import Rattletrap.Encode.LoadoutAttribute -import Rattletrap.Type.LoadoutsAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putLoadoutsAttribute :: LoadoutsAttribute -> BinaryBits.BitPut () -putLoadoutsAttribute loadoutsAttribute = do - putLoadoutAttribute (loadoutsAttributeBlue loadoutsAttribute) - putLoadoutAttribute (loadoutsAttributeOrange loadoutsAttribute) diff --git a/src/lib/Rattletrap/Encode/LoadoutsOnlineAttribute.hs b/src/lib/Rattletrap/Encode/LoadoutsOnlineAttribute.hs deleted file mode 100644 index aefbe637..00000000 --- a/src/lib/Rattletrap/Encode/LoadoutsOnlineAttribute.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Rattletrap.Encode.LoadoutsOnlineAttribute - ( putLoadoutsOnlineAttribute - ) where - -import Rattletrap.Encode.LoadoutOnlineAttribute -import Rattletrap.Type.LoadoutsOnlineAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putLoadoutsOnlineAttribute :: LoadoutsOnlineAttribute -> BinaryBits.BitPut () -putLoadoutsOnlineAttribute loadoutsOnlineAttribute = do - putLoadoutOnlineAttribute - (loadoutsOnlineAttributeBlue loadoutsOnlineAttribute) - putLoadoutOnlineAttribute - (loadoutsOnlineAttributeOrange loadoutsOnlineAttribute) - BinaryBits.putBool (loadoutsOnlineAttributeUnknown1 loadoutsOnlineAttribute) - BinaryBits.putBool (loadoutsOnlineAttributeUnknown2 loadoutsOnlineAttribute) diff --git a/src/lib/Rattletrap/Encode/LocationAttribute.hs b/src/lib/Rattletrap/Encode/LocationAttribute.hs deleted file mode 100644 index 4453c321..00000000 --- a/src/lib/Rattletrap/Encode/LocationAttribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.LocationAttribute - ( putLocationAttribute - ) where - -import Rattletrap.Encode.Vector -import Rattletrap.Type.LocationAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putLocationAttribute :: LocationAttribute -> BinaryBits.BitPut () -putLocationAttribute locationAttribute = - putVector (locationAttributeValue locationAttribute) diff --git a/src/lib/Rattletrap/Encode/Mark.hs b/src/lib/Rattletrap/Encode/Mark.hs deleted file mode 100644 index 6639ca06..00000000 --- a/src/lib/Rattletrap/Encode/Mark.hs +++ /dev/null @@ -1,14 +0,0 @@ -module Rattletrap.Encode.Mark - ( putMark - ) where - -import Rattletrap.Encode.Str -import Rattletrap.Type.Word32le -import Rattletrap.Type.Mark - -import qualified Data.Binary as Binary - -putMark :: Mark -> Binary.Put -putMark mark = do - putText (markValue mark) - putWord32 (markFrame mark) diff --git a/src/lib/Rattletrap/Encode/Message.hs b/src/lib/Rattletrap/Encode/Message.hs deleted file mode 100644 index 8364204e..00000000 --- a/src/lib/Rattletrap/Encode/Message.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.Message - ( putMessage - ) where - -import Rattletrap.Encode.Str -import Rattletrap.Type.Word32le -import Rattletrap.Type.Message - -import qualified Data.Binary as Binary - -putMessage :: Message -> Binary.Put -putMessage message = do - putWord32 (messageFrame message) - putText (messageName message) - putText (messageValue message) diff --git a/src/lib/Rattletrap/Encode/MusicStingerAttribute.hs b/src/lib/Rattletrap/Encode/MusicStingerAttribute.hs deleted file mode 100644 index f2c1d9c2..00000000 --- a/src/lib/Rattletrap/Encode/MusicStingerAttribute.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.MusicStingerAttribute - ( putMusicStingerAttribute - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Encode.Word8le -import Rattletrap.Type.MusicStingerAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putMusicStingerAttribute :: MusicStingerAttribute -> BinaryBits.BitPut () -putMusicStingerAttribute musicStingerAttribute = do - BinaryBits.putBool (musicStingerAttributeFlag musicStingerAttribute) - putWord32Bits (musicStingerAttributeCue musicStingerAttribute) - putWord8Bits (musicStingerAttributeTrigger musicStingerAttribute) diff --git a/src/lib/Rattletrap/Encode/PartyLeaderAttribute.hs b/src/lib/Rattletrap/Encode/PartyLeaderAttribute.hs deleted file mode 100644 index 564ec251..00000000 --- a/src/lib/Rattletrap/Encode/PartyLeaderAttribute.hs +++ /dev/null @@ -1,18 +0,0 @@ -module Rattletrap.Encode.PartyLeaderAttribute - ( putPartyLeaderAttribute - ) where - -import Rattletrap.Encode.RemoteId -import Rattletrap.Encode.Word8le -import Rattletrap.Type.PartyLeaderAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putPartyLeaderAttribute :: PartyLeaderAttribute -> BinaryBits.BitPut () -putPartyLeaderAttribute partyLeaderAttribute = do - putWord8Bits (partyLeaderAttributeSystemId partyLeaderAttribute) - case partyLeaderAttributeId partyLeaderAttribute of - Nothing -> pure () - Just (remoteId, localId) -> do - putRemoteId remoteId - putWord8Bits localId diff --git a/src/lib/Rattletrap/Encode/PickupAttribute.hs b/src/lib/Rattletrap/Encode/PickupAttribute.hs deleted file mode 100644 index ac5fd8f2..00000000 --- a/src/lib/Rattletrap/Encode/PickupAttribute.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Rattletrap.Encode.PickupAttribute - ( putPickupAttribute - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Type.PickupAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putPickupAttribute :: PickupAttribute -> BinaryBits.BitPut () -putPickupAttribute pickupAttribute = do - case pickupAttributeInstigatorId pickupAttribute of - Nothing -> BinaryBits.putBool False - Just instigatorId -> do - BinaryBits.putBool True - putWord32Bits instigatorId - BinaryBits.putBool (pickupAttributePickedUp pickupAttribute) diff --git a/src/lib/Rattletrap/Encode/PickupAttributeNew.hs b/src/lib/Rattletrap/Encode/PickupAttributeNew.hs deleted file mode 100644 index c1d7d251..00000000 --- a/src/lib/Rattletrap/Encode/PickupAttributeNew.hs +++ /dev/null @@ -1,18 +0,0 @@ -module Rattletrap.Encode.PickupAttributeNew - ( putPickupAttributeNew - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Encode.Word8le -import Rattletrap.Type.PickupAttributeNew - -import qualified Data.Binary.Bits.Put as BinaryBits - -putPickupAttributeNew :: PickupAttributeNew -> BinaryBits.BitPut () -putPickupAttributeNew pickupAttributeNew = do - case pickupAttributeNewInstigatorId pickupAttributeNew of - Nothing -> BinaryBits.putBool False - Just instigatorId -> do - BinaryBits.putBool True - putWord32Bits instigatorId - putWord8Bits (pickupAttributeNewPickedUp pickupAttributeNew) diff --git a/src/lib/Rattletrap/Encode/PlayerHistoryKeyAttribute.hs b/src/lib/Rattletrap/Encode/PlayerHistoryKeyAttribute.hs deleted file mode 100644 index c921d3a2..00000000 --- a/src/lib/Rattletrap/Encode/PlayerHistoryKeyAttribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.PlayerHistoryKeyAttribute - ( putPlayerHistoryKeyAttribute - ) where - -import Rattletrap.Encode.Common -import Rattletrap.Type.PlayerHistoryKeyAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putPlayerHistoryKeyAttribute - :: PlayerHistoryKeyAttribute -> BinaryBits.BitPut () -putPlayerHistoryKeyAttribute = putBitsLE 14 . playerHistoryKeyAttributeUnknown diff --git a/src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs b/src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs deleted file mode 100644 index c82e044f..00000000 --- a/src/lib/Rattletrap/Encode/PrivateMatchSettingsAttribute.hs +++ /dev/null @@ -1,25 +0,0 @@ -module Rattletrap.Encode.PrivateMatchSettingsAttribute - ( putPrivateMatchSettingsAttribute - ) where - -import Rattletrap.Encode.Str -import Rattletrap.Type.Word32le -import Rattletrap.Type.PrivateMatchSettingsAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putPrivateMatchSettingsAttribute - :: PrivateMatchSettingsAttribute -> BinaryBits.BitPut () -putPrivateMatchSettingsAttribute privateMatchSettingsAttribute = do - putTextBits - (privateMatchSettingsAttributeMutators privateMatchSettingsAttribute) - putWord32Bits - (privateMatchSettingsAttributeJoinableBy privateMatchSettingsAttribute) - putWord32Bits - (privateMatchSettingsAttributeMaxPlayers privateMatchSettingsAttribute) - putTextBits - (privateMatchSettingsAttributeGameName privateMatchSettingsAttribute) - putTextBits - (privateMatchSettingsAttributePassword privateMatchSettingsAttribute) - BinaryBits.putBool - (privateMatchSettingsAttributeFlag privateMatchSettingsAttribute) diff --git a/src/lib/Rattletrap/Encode/ProductAttribute.hs b/src/lib/Rattletrap/Encode/ProductAttribute.hs deleted file mode 100644 index e312e565..00000000 --- a/src/lib/Rattletrap/Encode/ProductAttribute.hs +++ /dev/null @@ -1,36 +0,0 @@ -module Rattletrap.Encode.ProductAttribute - ( putProductAttributes - ) where - -import Rattletrap.Encode.Common -import Rattletrap.Encode.CompressedWord -import Rattletrap.Encode.Str -import Rattletrap.Type.Word32le -import Rattletrap.Encode.Word8le -import Rattletrap.Type.ProductAttribute -import Rattletrap.Type.Word8le - -import qualified Data.Binary.Bits.Put as BinaryBits - -putProductAttributes :: [ProductAttribute] -> BinaryBits.BitPut () -putProductAttributes attributes = do - putWord8Bits (Word8le (fromIntegral (length attributes))) - mapM_ putProductAttribute attributes - -putProductAttribute :: ProductAttribute -> BinaryBits.BitPut () -putProductAttribute attribute = do - BinaryBits.putBool (productAttributeUnknown attribute) - putWord32Bits (productAttributeObjectId attribute) - case productAttributeValue attribute of - ProductAttributeValuePaintedOld x -> putCompressedWord x - ProductAttributeValuePaintedNew x -> putBitsLE 31 x - ProductAttributeValueTeamEditionOld x -> putCompressedWord x - ProductAttributeValueTeamEditionNew x -> putBitsLE 31 x - ProductAttributeValueSpecialEdition x -> putBitsLE 31 x - ProductAttributeValueUserColorOld x -> case x of - Nothing -> BinaryBits.putBool False - Just y -> do - BinaryBits.putBool True - putBitsLE 31 y - ProductAttributeValueUserColorNew x -> putWord32Bits x - ProductAttributeValueTitleId x -> putTextBits x diff --git a/src/lib/Rattletrap/Encode/Property.hs b/src/lib/Rattletrap/Encode/Property.hs deleted file mode 100644 index e85d7a71..00000000 --- a/src/lib/Rattletrap/Encode/Property.hs +++ /dev/null @@ -1,16 +0,0 @@ -module Rattletrap.Encode.Property - ( putProperty - ) where - -import Rattletrap.Encode.PropertyValue -import Rattletrap.Encode.Str -import Rattletrap.Encode.Word64le -import Rattletrap.Type.Property - -import qualified Data.Binary as Binary - -putProperty :: Property -> Binary.Put -putProperty property = do - putText (propertyKind property) - putWord64 (propertySize property) - putPropertyValue putProperty (propertyValue property) diff --git a/src/lib/Rattletrap/Encode/PropertyValue.hs b/src/lib/Rattletrap/Encode/PropertyValue.hs deleted file mode 100644 index cc75bb03..00000000 --- a/src/lib/Rattletrap/Encode/PropertyValue.hs +++ /dev/null @@ -1,29 +0,0 @@ -module Rattletrap.Encode.PropertyValue - ( putPropertyValue - ) where - -import Rattletrap.Encode.Dictionary -import Rattletrap.Encode.Float32le -import Rattletrap.Encode.Int32le -import Rattletrap.Encode.List -import Rattletrap.Encode.Str -import Rattletrap.Encode.Word64le -import Rattletrap.Encode.Word8le -import Rattletrap.Type.PropertyValue - -import qualified Data.Binary as Binary - -putPropertyValue :: (a -> Binary.Put) -> PropertyValue a -> Binary.Put -putPropertyValue putProperty value = case value of - PropertyValueArray list -> putList (putDictionary putProperty) list - PropertyValueBool word8 -> putWord8 word8 - PropertyValueByte k mv -> do - putText k - case mv of - Nothing -> pure () - Just v -> putText v - PropertyValueFloat float32 -> putFloat32 float32 - PropertyValueInt int32 -> putInt32 int32 - PropertyValueName text -> putText text - PropertyValueQWord word64 -> putWord64 word64 - PropertyValueStr text -> putText text diff --git a/src/lib/Rattletrap/Encode/QWordAttribute.hs b/src/lib/Rattletrap/Encode/QWordAttribute.hs deleted file mode 100644 index c273330e..00000000 --- a/src/lib/Rattletrap/Encode/QWordAttribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.QWordAttribute - ( putQWordAttribute - ) where - -import Rattletrap.Encode.Word64le -import Rattletrap.Type.QWordAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putQWordAttribute :: QWordAttribute -> BinaryBits.BitPut () -putQWordAttribute qWordAttribute = - putWord64Bits (qWordAttributeValue qWordAttribute) diff --git a/src/lib/Rattletrap/Encode/Quaternion.hs b/src/lib/Rattletrap/Encode/Quaternion.hs deleted file mode 100644 index 905e7920..00000000 --- a/src/lib/Rattletrap/Encode/Quaternion.hs +++ /dev/null @@ -1,40 +0,0 @@ -module Rattletrap.Encode.Quaternion - ( putQuaternion - ) where - -import Rattletrap.Encode.CompressedWord -import Rattletrap.Type.CompressedWord -import Rattletrap.Type.Quaternion - -import qualified Data.Binary.Bits.Put as BinaryBits - -putQuaternion :: Quaternion -> BinaryBits.BitPut () -putQuaternion q = do - let c = maxComponent q - putComponent c - case c of - ComponentX -> putParts (quaternionY q) (quaternionZ q) (quaternionW q) - ComponentY -> putParts (quaternionX q) (quaternionZ q) (quaternionW q) - ComponentZ -> putParts (quaternionX q) (quaternionY q) (quaternionW q) - ComponentW -> putParts (quaternionX q) (quaternionY q) (quaternionZ q) - -putComponent :: Component -> BinaryBits.BitPut () -putComponent component = putCompressedWord - (CompressedWord - 3 - (case component of - ComponentX -> 0 - ComponentY -> 1 - ComponentZ -> 2 - ComponentW -> 3 - ) - ) - -putParts :: Double -> Double -> Double -> BinaryBits.BitPut () -putParts a b c = do - putPart a - putPart b - putPart c - -putPart :: Double -> BinaryBits.BitPut () -putPart = putCompressedWord . compressPart diff --git a/src/lib/Rattletrap/Encode/RemoteId.hs b/src/lib/Rattletrap/Encode/RemoteId.hs deleted file mode 100644 index 94a4426a..00000000 --- a/src/lib/Rattletrap/Encode/RemoteId.hs +++ /dev/null @@ -1,36 +0,0 @@ -module Rattletrap.Encode.RemoteId - ( putRemoteId - ) where - -import Rattletrap.Encode.Common -import Rattletrap.Encode.Str -import Rattletrap.Encode.Word64le -import Rattletrap.Type.RemoteId -import Rattletrap.Type.Word64le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.ByteString as Bytes - -putRemoteId :: RemoteId -> BinaryBits.BitPut () -putRemoteId remoteId = case remoteId of - RemoteIdPlayStation name bytes -> do - let rawName = reverseBytes (padBytes (16 :: Int) (encodeLatin1 name)) - BinaryBits.putByteString rawName - BinaryBits.putByteString (Bytes.pack bytes) - RemoteIdPsyNet e -> case e of - Left l -> putWord64Bits l - Right (a, b, c, d) -> putWord256 a b c d - RemoteIdSplitscreen word24 -> putBitsLE 24 word24 - RemoteIdSteam word64 -> putWord64Bits word64 - RemoteIdSwitch a b c d -> putWord256 a b c d - RemoteIdXbox word64 -> putWord64Bits word64 - RemoteIdEpic str -> putTextBits str - -putWord256 - :: Word64le -> Word64le -> Word64le -> Word64le -> BinaryBits.BitPut () -putWord256 a b c d = do - putWord64Bits a - putWord64Bits b - putWord64Bits c - putWord64Bits d diff --git a/src/lib/Rattletrap/Encode/Replay.hs b/src/lib/Rattletrap/Encode/Replay.hs deleted file mode 100644 index 7cb94bca..00000000 --- a/src/lib/Rattletrap/Encode/Replay.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Rattletrap.Encode.Replay - ( putReplay - ) where - -import Rattletrap.Encode.Content -import Rattletrap.Encode.Header -import Rattletrap.Encode.Section -import Rattletrap.Type.Replay - -import qualified Data.Binary as Binary - --- | Generates a raw replay. Use this with 'Data.Binary.Put.runPut'. --- --- @ --- let bytes = 'Data.Binary.Put.runPut' ('putReplay' replay) --- @ -putReplay :: FullReplay -> Binary.Put -putReplay replay = do - putSection putHeader (replayHeader replay) - putSection putContent (replayContent replay) diff --git a/src/lib/Rattletrap/Encode/Replication.hs b/src/lib/Rattletrap/Encode/Replication.hs deleted file mode 100644 index b316e9bf..00000000 --- a/src/lib/Rattletrap/Encode/Replication.hs +++ /dev/null @@ -1,25 +0,0 @@ -module Rattletrap.Encode.Replication - ( putReplications - ) where - -import Rattletrap.Encode.CompressedWord -import Rattletrap.Encode.ReplicationValue -import Rattletrap.Type.Replication - -import qualified Data.Binary.Bits.Put as BinaryBits - -putReplications :: [Replication] -> BinaryBits.BitPut () -putReplications replications = case replications of - [] -> BinaryBits.putBool False - [replication] -> do - putReplication replication - BinaryBits.putBool False - first : rest -> do - putReplication first - putReplications rest - -putReplication :: Replication -> BinaryBits.BitPut () -putReplication replication = do - BinaryBits.putBool True - putCompressedWord (replicationActorId replication) - putReplicationValue (replicationValue replication) diff --git a/src/lib/Rattletrap/Encode/ReplicationValue.hs b/src/lib/Rattletrap/Encode/ReplicationValue.hs deleted file mode 100644 index afdbeb10..00000000 --- a/src/lib/Rattletrap/Encode/ReplicationValue.hs +++ /dev/null @@ -1,24 +0,0 @@ -module Rattletrap.Encode.ReplicationValue - ( putReplicationValue - ) where - -import Rattletrap.Encode.DestroyedReplication -import Rattletrap.Encode.SpawnedReplication -import Rattletrap.Encode.UpdatedReplication -import Rattletrap.Type.ReplicationValue - -import qualified Data.Binary.Bits.Put as BinaryBits - -putReplicationValue :: ReplicationValue -> BinaryBits.BitPut () -putReplicationValue value = case value of - ReplicationValueSpawned x -> do - BinaryBits.putBool True - BinaryBits.putBool True - putSpawnedReplication x - ReplicationValueUpdated x -> do - BinaryBits.putBool True - BinaryBits.putBool False - putUpdatedReplication x - ReplicationValueDestroyed x -> do - BinaryBits.putBool False - putDestroyedReplication x diff --git a/src/lib/Rattletrap/Encode/ReservationAttribute.hs b/src/lib/Rattletrap/Encode/ReservationAttribute.hs deleted file mode 100644 index 2b165943..00000000 --- a/src/lib/Rattletrap/Encode/ReservationAttribute.hs +++ /dev/null @@ -1,23 +0,0 @@ -module Rattletrap.Encode.ReservationAttribute - ( putReservationAttribute - ) where - -import Rattletrap.Encode.CompressedWord -import Rattletrap.Encode.Str -import Rattletrap.Encode.UniqueIdAttribute -import Rattletrap.Type.ReservationAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putReservationAttribute :: ReservationAttribute -> BinaryBits.BitPut () -putReservationAttribute reservationAttribute = do - putCompressedWord (reservationAttributeNumber reservationAttribute) - putUniqueIdAttribute (reservationAttributeUniqueId reservationAttribute) - case reservationAttributeName reservationAttribute of - Nothing -> pure () - Just name -> putTextBits name - BinaryBits.putBool (reservationAttributeUnknown1 reservationAttribute) - BinaryBits.putBool (reservationAttributeUnknown2 reservationAttribute) - case reservationAttributeUnknown3 reservationAttribute of - Nothing -> pure () - Just c -> BinaryBits.putWord8 6 c diff --git a/src/lib/Rattletrap/Encode/RigidBodyStateAttribute.hs b/src/lib/Rattletrap/Encode/RigidBodyStateAttribute.hs deleted file mode 100644 index fbc32345..00000000 --- a/src/lib/Rattletrap/Encode/RigidBodyStateAttribute.hs +++ /dev/null @@ -1,21 +0,0 @@ -module Rattletrap.Encode.RigidBodyStateAttribute - ( putRigidBodyStateAttribute - ) where - -import Rattletrap.Encode.Rotation -import Rattletrap.Encode.Vector -import Rattletrap.Type.RigidBodyStateAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putRigidBodyStateAttribute :: RigidBodyStateAttribute -> BinaryBits.BitPut () -putRigidBodyStateAttribute rigidBodyStateAttribute = do - BinaryBits.putBool (rigidBodyStateAttributeSleeping rigidBodyStateAttribute) - putVector (rigidBodyStateAttributeLocation rigidBodyStateAttribute) - putRotation (rigidBodyStateAttributeRotation rigidBodyStateAttribute) - case rigidBodyStateAttributeLinearVelocity rigidBodyStateAttribute of - Nothing -> pure () - Just linearVelocity -> putVector linearVelocity - case rigidBodyStateAttributeAngularVelocity rigidBodyStateAttribute of - Nothing -> pure () - Just angularVelocity -> putVector angularVelocity diff --git a/src/lib/Rattletrap/Encode/Rotation.hs b/src/lib/Rattletrap/Encode/Rotation.hs deleted file mode 100644 index 775af7af..00000000 --- a/src/lib/Rattletrap/Encode/Rotation.hs +++ /dev/null @@ -1,14 +0,0 @@ -module Rattletrap.Encode.Rotation - ( putRotation - ) where - -import Rattletrap.Encode.CompressedWordVector -import Rattletrap.Encode.Quaternion -import Rattletrap.Type.Rotation - -import qualified Data.Binary.Bits.Put as BinaryBits - -putRotation :: Rotation -> BinaryBits.BitPut () -putRotation r = case r of - RotationCompressedWordVector cwv -> putCompressedWordVector cwv - RotationQuaternion q -> putQuaternion q diff --git a/src/lib/Rattletrap/Encode/Section.hs b/src/lib/Rattletrap/Encode/Section.hs deleted file mode 100644 index 52b65eac..00000000 --- a/src/lib/Rattletrap/Encode/Section.hs +++ /dev/null @@ -1,29 +0,0 @@ -module Rattletrap.Encode.Section - ( putSection - ) where - -import Rattletrap.Type.Section -import Rattletrap.Type.Word32le -import Rattletrap.Utility.Crc - -import qualified Data.Binary as Binary -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString as Bytes -import qualified Data.ByteString.Lazy as LazyBytes - --- | Given a way to put the 'sectionBody', puts a section. This will also put --- the size and CRC. --- --- @ --- let bytes = 'Data.Binary.Put.runPut' ('putSection' 'Rattletrap.Content.putContent' content) --- @ -putSection :: (a -> Binary.Put) -> Section a -> Binary.Put -putSection putBody section = do - let - rawBody = - LazyBytes.toStrict (Binary.runPut (putBody (sectionBody section))) - let size = Bytes.length rawBody - let crc = getCrc32 rawBody - putWord32 (Word32le (fromIntegral size)) - putWord32 (Word32le crc) - Binary.putByteString rawBody diff --git a/src/lib/Rattletrap/Encode/SpawnedReplication.hs b/src/lib/Rattletrap/Encode/SpawnedReplication.hs deleted file mode 100644 index 2d6d898b..00000000 --- a/src/lib/Rattletrap/Encode/SpawnedReplication.hs +++ /dev/null @@ -1,18 +0,0 @@ -module Rattletrap.Encode.SpawnedReplication - ( putSpawnedReplication - ) where - -import Rattletrap.Encode.Initialization -import Rattletrap.Type.Word32le -import Rattletrap.Type.SpawnedReplication - -import qualified Data.Binary.Bits.Put as BinaryBits - -putSpawnedReplication :: SpawnedReplication -> BinaryBits.BitPut () -putSpawnedReplication spawnedReplication = do - BinaryBits.putBool (spawnedReplicationFlag spawnedReplication) - case spawnedReplicationNameIndex spawnedReplication of - Nothing -> pure () - Just nameIndex -> putWord32Bits nameIndex - putWord32Bits (spawnedReplicationObjectId spawnedReplication) - putInitialization (spawnedReplicationInitialization spawnedReplication) diff --git a/src/lib/Rattletrap/Encode/StatEventAttribute.hs b/src/lib/Rattletrap/Encode/StatEventAttribute.hs deleted file mode 100644 index 6efb99a4..00000000 --- a/src/lib/Rattletrap/Encode/StatEventAttribute.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Rattletrap.Encode.StatEventAttribute - ( putStatEventAttribute - ) where - -import Rattletrap.Encode.Int32le -import Rattletrap.Type.StatEventAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putStatEventAttribute :: StatEventAttribute -> BinaryBits.BitPut () -putStatEventAttribute statEventAttribute = do - BinaryBits.putBool (statEventAttributeUnknown statEventAttribute) - putInt32Bits (statEventAttributeObjectId statEventAttribute) diff --git a/src/lib/Rattletrap/Encode/Str.hs b/src/lib/Rattletrap/Encode/Str.hs deleted file mode 100644 index 5254cc7b..00000000 --- a/src/lib/Rattletrap/Encode/Str.hs +++ /dev/null @@ -1,52 +0,0 @@ -module Rattletrap.Encode.Str - ( putText - , putTextBits - ) where - -import Rattletrap.Encode.Int32le -import Rattletrap.Type.Common -import Rattletrap.Type.Int32le -import Rattletrap.Type.Str -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString as Bytes -import qualified Data.Char as Char -import qualified Data.Text as Text -import qualified Data.Text.Encoding as Text - -putText :: Str -> Binary.Put -putText text = do - let size = getTextSize text - let encode = getTextEncoder size - putInt32 size - Binary.putByteString (encode (addNull (strValue text))) - -putTextBits :: Str -> BinaryBits.BitPut () -putTextBits text = do - let size = getTextSize text - let encode = getTextEncoder size - putInt32Bits size - BinaryBits.putByteString (reverseBytes (encode (addNull (strValue text)))) - -getTextSize :: Str -> Int32le -getTextSize text = - let - value = strValue text - scale = if Text.all Char.isLatin1 value then 1 else -1 :: Int32 - rawSize = if Text.null value - then 0 - else fromIntegral (Text.length value) + 1 :: Int32 - size = if value == Text.pack "\x00\x00\x00None" - then 0x05000000 - else scale * rawSize :: Int32 - in Int32le size - -getTextEncoder :: Int32le -> Text.Text -> Bytes.ByteString -getTextEncoder size text = - if size < Int32le 0 then Text.encodeUtf16LE text else encodeLatin1 text - -addNull :: Text.Text -> Text.Text -addNull text = if Text.null text then text else Text.snoc text '\x00' diff --git a/src/lib/Rattletrap/Encode/StringAttribute.hs b/src/lib/Rattletrap/Encode/StringAttribute.hs deleted file mode 100644 index d9dadd29..00000000 --- a/src/lib/Rattletrap/Encode/StringAttribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.StringAttribute - ( putStringAttribute - ) where - -import Rattletrap.Encode.Str -import Rattletrap.Type.StringAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putStringAttribute :: StringAttribute -> BinaryBits.BitPut () -putStringAttribute stringAttribute = - putTextBits (stringAttributeValue stringAttribute) diff --git a/src/lib/Rattletrap/Encode/TeamPaintAttribute.hs b/src/lib/Rattletrap/Encode/TeamPaintAttribute.hs deleted file mode 100644 index f5f7c25d..00000000 --- a/src/lib/Rattletrap/Encode/TeamPaintAttribute.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Rattletrap.Encode.TeamPaintAttribute - ( putTeamPaintAttribute - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Encode.Word8le -import Rattletrap.Type.TeamPaintAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putTeamPaintAttribute :: TeamPaintAttribute -> BinaryBits.BitPut () -putTeamPaintAttribute teamPaintAttribute = do - putWord8Bits (teamPaintAttributeTeam teamPaintAttribute) - putWord8Bits (teamPaintAttributePrimaryColor teamPaintAttribute) - putWord8Bits (teamPaintAttributeAccentColor teamPaintAttribute) - putWord32Bits (teamPaintAttributePrimaryFinish teamPaintAttribute) - putWord32Bits (teamPaintAttributeAccentFinish teamPaintAttribute) diff --git a/src/lib/Rattletrap/Encode/TitleAttribute.hs b/src/lib/Rattletrap/Encode/TitleAttribute.hs deleted file mode 100644 index 626fc772..00000000 --- a/src/lib/Rattletrap/Encode/TitleAttribute.hs +++ /dev/null @@ -1,19 +0,0 @@ -module Rattletrap.Encode.TitleAttribute - ( putTitleAttribute - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Type.TitleAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putTitleAttribute :: TitleAttribute -> BinaryBits.BitPut () -putTitleAttribute titleAttribute = do - BinaryBits.putBool (titleAttributeUnknown1 titleAttribute) - BinaryBits.putBool (titleAttributeUnknown2 titleAttribute) - putWord32Bits (titleAttributeUnknown3 titleAttribute) - putWord32Bits (titleAttributeUnknown4 titleAttribute) - putWord32Bits (titleAttributeUnknown5 titleAttribute) - putWord32Bits (titleAttributeUnknown6 titleAttribute) - putWord32Bits (titleAttributeUnknown7 titleAttribute) - BinaryBits.putBool (titleAttributeUnknown8 titleAttribute) diff --git a/src/lib/Rattletrap/Encode/UniqueIdAttribute.hs b/src/lib/Rattletrap/Encode/UniqueIdAttribute.hs deleted file mode 100644 index 2d0dc09d..00000000 --- a/src/lib/Rattletrap/Encode/UniqueIdAttribute.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.UniqueIdAttribute - ( putUniqueIdAttribute - ) where - -import Rattletrap.Encode.RemoteId -import Rattletrap.Encode.Word8le -import Rattletrap.Type.UniqueIdAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putUniqueIdAttribute :: UniqueIdAttribute -> BinaryBits.BitPut () -putUniqueIdAttribute uniqueIdAttribute = do - putWord8Bits (uniqueIdAttributeSystemId uniqueIdAttribute) - putRemoteId (uniqueIdAttributeRemoteId uniqueIdAttribute) - putWord8Bits (uniqueIdAttributeLocalId uniqueIdAttribute) diff --git a/src/lib/Rattletrap/Encode/UpdatedReplication.hs b/src/lib/Rattletrap/Encode/UpdatedReplication.hs deleted file mode 100644 index 00aba3c8..00000000 --- a/src/lib/Rattletrap/Encode/UpdatedReplication.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.UpdatedReplication - ( putUpdatedReplication - ) where - -import Rattletrap.Encode.Attribute -import Rattletrap.Type.UpdatedReplication - -import qualified Data.Binary.Bits.Put as BinaryBits - -putUpdatedReplication :: UpdatedReplication -> BinaryBits.BitPut () -putUpdatedReplication updatedReplication = - putAttributes (updatedReplicationAttributes updatedReplication) diff --git a/src/lib/Rattletrap/Encode/Vector.hs b/src/lib/Rattletrap/Encode/Vector.hs deleted file mode 100644 index 598db201..00000000 --- a/src/lib/Rattletrap/Encode/Vector.hs +++ /dev/null @@ -1,26 +0,0 @@ -module Rattletrap.Encode.Vector - ( putVector - ) where - -import Rattletrap.Encode.CompressedWord -import Rattletrap.Type.CompressedWord -import Rattletrap.Type.Vector - -import qualified Data.Binary.Bits.Put as BinaryBits - -putVector :: Vector -> BinaryBits.BitPut () -putVector vector = do - let - bitSize = - round (logBase (2 :: Float) (fromIntegral (vectorBias vector))) - 1 :: Word - dx = - fromIntegral (vectorX vector + fromIntegral (vectorBias vector)) :: Word - dy = - fromIntegral (vectorY vector + fromIntegral (vectorBias vector)) :: Word - dz = - fromIntegral (vectorZ vector + fromIntegral (vectorBias vector)) :: Word - limit = 2 ^ (bitSize + 2) :: Word - putCompressedWord (vectorSize vector) - putCompressedWord (CompressedWord limit dx) - putCompressedWord (CompressedWord limit dy) - putCompressedWord (CompressedWord limit dz) diff --git a/src/lib/Rattletrap/Encode/WeldedInfoAttribute.hs b/src/lib/Rattletrap/Encode/WeldedInfoAttribute.hs deleted file mode 100644 index 4cd8bfaa..00000000 --- a/src/lib/Rattletrap/Encode/WeldedInfoAttribute.hs +++ /dev/null @@ -1,19 +0,0 @@ -module Rattletrap.Encode.WeldedInfoAttribute - ( putWeldedInfoAttribute - ) where - -import Rattletrap.Encode.Float32le -import Rattletrap.Encode.Int32le -import Rattletrap.Encode.Int8Vector -import Rattletrap.Encode.Vector -import Rattletrap.Type.WeldedInfoAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putWeldedInfoAttribute :: WeldedInfoAttribute -> BinaryBits.BitPut () -putWeldedInfoAttribute weldedInfoAttribute = do - BinaryBits.putBool (weldedInfoAttributeActive weldedInfoAttribute) - putInt32Bits (weldedInfoAttributeActorId weldedInfoAttribute) - putVector (weldedInfoAttributeOffset weldedInfoAttribute) - putFloat32Bits (weldedInfoAttributeMass weldedInfoAttribute) - putInt8Vector (weldedInfoAttributeRotation weldedInfoAttribute) diff --git a/src/lib/Rattletrap/Encode/Word32le.hs b/src/lib/Rattletrap/Encode/Word32le.hs deleted file mode 100644 index ead5a7c0..00000000 --- a/src/lib/Rattletrap/Encode/Word32le.hs +++ /dev/null @@ -1 +0,0 @@ -module Rattletrap.Encode.Word32le where diff --git a/src/lib/Rattletrap/Encode/Word64le.hs b/src/lib/Rattletrap/Encode/Word64le.hs deleted file mode 100644 index ded3bb1b..00000000 --- a/src/lib/Rattletrap/Encode/Word64le.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Rattletrap.Encode.Word64le - ( putWord64 - , putWord64Bits - ) where - -import Rattletrap.Type.Word64le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString.Lazy as LazyBytes - -putWord64 :: Word64le -> Binary.Put -putWord64 word64 = Binary.putWord64le (word64leValue word64) - -putWord64Bits :: Word64le -> BinaryBits.BitPut () -putWord64Bits word64 = do - let bytes = LazyBytes.toStrict (Binary.runPut (putWord64 word64)) - BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Encode/Word8le.hs b/src/lib/Rattletrap/Encode/Word8le.hs deleted file mode 100644 index 434bd817..00000000 --- a/src/lib/Rattletrap/Encode/Word8le.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Rattletrap.Encode.Word8le - ( putWord8 - , putWord8Bits - ) where - -import Rattletrap.Type.Word8le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString.Lazy as LazyBytes - -putWord8 :: Word8le -> Binary.Put -putWord8 word8 = Binary.putWord8 (word8leValue word8) - -putWord8Bits :: Word8le -> BinaryBits.BitPut () -putWord8Bits word8 = do - let bytes = LazyBytes.toStrict (Binary.runPut (putWord8 word8)) - BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Type/Header.hs b/src/lib/Rattletrap/Type/Header.hs index 13b1e0e5..919366b2 100644 --- a/src/lib/Rattletrap/Type/Header.hs +++ b/src/lib/Rattletrap/Type/Header.hs @@ -1,14 +1,15 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Header - ( Header(..) - ) where +module Rattletrap.Type.Header where import Rattletrap.Type.Common import Rattletrap.Type.Dictionary import Rattletrap.Type.Property import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import Rattletrap.Encode.Dictionary + +import qualified Data.Binary as Binary -- | Contains high-level metadata about a 'Rattletrap.Replay.Replay'. data Header = Header @@ -59,3 +60,13 @@ data Header = Header deriving (Eq, Ord, Show) $(deriveJson ''Header) + +putHeader :: Header -> Binary.Put +putHeader header = do + putWord32 (headerEngineVersion header) + putWord32 (headerLicenseeVersion header) + case headerPatchVersion header of + Nothing -> pure () + Just patchVersion -> putWord32 patchVersion + putText (headerLabel header) + putDictionary putProperty (headerProperties header) diff --git a/src/lib/Rattletrap/Type/Initialization.hs b/src/lib/Rattletrap/Type/Initialization.hs index 9bad3020..7de2a4f4 100644 --- a/src/lib/Rattletrap/Type/Initialization.hs +++ b/src/lib/Rattletrap/Type/Initialization.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Initialization - ( Initialization(..) - ) where +module Rattletrap.Type.Initialization where import Rattletrap.Type.Common import Rattletrap.Type.Int8Vector import Rattletrap.Type.Vector +import qualified Data.Binary.Bits.Put as BinaryBits + data Initialization = Initialization { initializationLocation :: Maybe Vector -- ^ Not every class has an initial location. See @@ -19,3 +19,12 @@ data Initialization = Initialization deriving (Eq, Ord, Show) $(deriveJson ''Initialization) + +putInitialization :: Initialization -> BinaryBits.BitPut () +putInitialization initialization = do + case initializationLocation initialization of + Nothing -> pure () + Just location -> putVector location + case initializationRotation initialization of + Nothing -> pure () + Just rotation -> putInt8Vector rotation diff --git a/src/lib/Rattletrap/Type/Int32le.hs b/src/lib/Rattletrap/Type/Int32le.hs index fd7eec01..ad0d2d91 100644 --- a/src/lib/Rattletrap/Type/Int32le.hs +++ b/src/lib/Rattletrap/Type/Int32le.hs @@ -1,13 +1,25 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Int32le - ( Int32le(..) - ) where +module Rattletrap.Type.Int32le where import Rattletrap.Type.Common +import Rattletrap.Utility.Bytes + +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString.Lazy as LazyBytes newtype Int32le = Int32le { int32leValue :: Int32 } deriving (Eq, Ord, Show) $(deriveJson ''Int32le) + +putInt32 :: Int32le -> Binary.Put +putInt32 int32 = Binary.putInt32le (int32leValue int32) + +putInt32Bits :: Int32le -> BinaryBits.BitPut () +putInt32Bits int32 = do + let bytes = LazyBytes.toStrict (Binary.runPut (putInt32 int32)) + BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Type/Int64Attribute.hs b/src/lib/Rattletrap/Type/Int64Attribute.hs index 9090e58e..9adfdc52 100644 --- a/src/lib/Rattletrap/Type/Int64Attribute.hs +++ b/src/lib/Rattletrap/Type/Int64Attribute.hs @@ -1,14 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Int64Attribute - ( Int64Attribute(..) - ) where +module Rattletrap.Type.Int64Attribute where import Rattletrap.Type.Common import Rattletrap.Type.Int64le +import qualified Data.Binary.Bits.Put as BinaryBits + newtype Int64Attribute = Int64Attribute { int64AttributeValue :: Int64le } deriving (Eq, Ord, Show) $(deriveJson ''Int64Attribute) + +putInt64Attribute :: Int64Attribute -> BinaryBits.BitPut () +putInt64Attribute int64Attribute = + putInt64Bits (int64AttributeValue int64Attribute) diff --git a/src/lib/Rattletrap/Type/Int64le.hs b/src/lib/Rattletrap/Type/Int64le.hs index 5630c332..a0b91261 100644 --- a/src/lib/Rattletrap/Type/Int64le.hs +++ b/src/lib/Rattletrap/Type/Int64le.hs @@ -1,7 +1,11 @@ -module Rattletrap.Type.Int64le - ( Int64le(..) - ) where +module Rattletrap.Type.Int64le where +import Rattletrap.Utility.Bytes + +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString.Lazy as LazyBytes import qualified Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson import qualified Data.Int as Int @@ -25,3 +29,11 @@ instance Aeson.FromJSON Int64le where instance Aeson.ToJSON Int64le where toJSON = Aeson.toJSON . show . int64leValue + +putInt64 :: Int64le -> Binary.Put +putInt64 int64 = Binary.putInt64le (int64leValue int64) + +putInt64Bits :: Int64le -> BinaryBits.BitPut () +putInt64Bits int64 = do + let bytes = LazyBytes.toStrict (Binary.runPut (putInt64 int64)) + BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Type/Int8Vector.hs b/src/lib/Rattletrap/Type/Int8Vector.hs index dc235d39..39dc3e69 100644 --- a/src/lib/Rattletrap/Type/Int8Vector.hs +++ b/src/lib/Rattletrap/Type/Int8Vector.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Int8Vector - ( Int8Vector(..) - ) where +module Rattletrap.Type.Int8Vector where import Rattletrap.Type.Common import Rattletrap.Type.Int8le +import qualified Data.Binary.Bits.Put as BinaryBits + data Int8Vector = Int8Vector { int8VectorX :: Maybe Int8le , int8VectorY :: Maybe Int8le @@ -15,3 +15,16 @@ data Int8Vector = Int8Vector deriving (Eq, Ord, Show) $(deriveJson ''Int8Vector) + +putInt8Vector :: Int8Vector -> BinaryBits.BitPut () +putInt8Vector int8Vector = do + putInt8VectorField (int8VectorX int8Vector) + putInt8VectorField (int8VectorY int8Vector) + putInt8VectorField (int8VectorZ int8Vector) + +putInt8VectorField :: Maybe Int8le -> BinaryBits.BitPut () +putInt8VectorField maybeField = case maybeField of + Nothing -> BinaryBits.putBool False + Just field -> do + BinaryBits.putBool True + putInt8Bits field diff --git a/src/lib/Rattletrap/Type/Int8le.hs b/src/lib/Rattletrap/Type/Int8le.hs index 9e83da1e..8bf3441d 100644 --- a/src/lib/Rattletrap/Type/Int8le.hs +++ b/src/lib/Rattletrap/Type/Int8le.hs @@ -1,13 +1,24 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Int8le - ( Int8le(..) - ) where +module Rattletrap.Type.Int8le where import Rattletrap.Type.Common +import Rattletrap.Utility.Bytes + +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString.Lazy as LazyBytes newtype Int8le = Int8le { int8leValue :: Int8 } deriving (Eq, Ord, Show) $(deriveJson ''Int8le) + +putInt8 :: Int8le -> Binary.Put +putInt8 int8 = Binary.putInt8 (int8leValue int8) + +putInt8Bits :: Int8le -> BinaryBits.BitPut () +putInt8Bits int8 = do + let bytes = LazyBytes.toStrict (Binary.runPut (putInt8 int8)) + BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Type/IntAttribute.hs b/src/lib/Rattletrap/Type/IntAttribute.hs index ce1a0c44..307a4291 100644 --- a/src/lib/Rattletrap/Type/IntAttribute.hs +++ b/src/lib/Rattletrap/Type/IntAttribute.hs @@ -1,14 +1,17 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.IntAttribute - ( IntAttribute(..) - ) where +module Rattletrap.Type.IntAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Int32le +import qualified Data.Binary.Bits.Put as BinaryBits + newtype IntAttribute = IntAttribute { intAttributeValue :: Int32le } deriving (Eq, Ord, Show) $(deriveJson ''IntAttribute) + +putIntAttribute :: IntAttribute -> BinaryBits.BitPut () +putIntAttribute intAttribute = putInt32Bits (intAttributeValue intAttribute) diff --git a/src/lib/Rattletrap/Type/KeyFrame.hs b/src/lib/Rattletrap/Type/KeyFrame.hs index 790c2866..4399f43b 100644 --- a/src/lib/Rattletrap/Type/KeyFrame.hs +++ b/src/lib/Rattletrap/Type/KeyFrame.hs @@ -1,12 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.KeyFrame - ( KeyFrame(..) - ) where +module Rattletrap.Type.KeyFrame where import Rattletrap.Type.Common import Rattletrap.Type.Float32le import Rattletrap.Type.Word32le +import Rattletrap.Encode.Float32le + +import qualified Data.Binary as Binary data KeyFrame = KeyFrame { keyFrameTime :: Float32le @@ -19,3 +20,9 @@ data KeyFrame = KeyFrame deriving (Eq, Ord, Show) $(deriveJson ''KeyFrame) + +putKeyFrame :: KeyFrame -> Binary.Put +putKeyFrame keyFrame = do + putFloat32 (keyFrameTime keyFrame) + putWord32 (keyFrameFrame keyFrame) + putWord32 (keyFramePosition keyFrame) diff --git a/src/lib/Rattletrap/Type/List.hs b/src/lib/Rattletrap/Type/List.hs index 7c9cb491..9508f6f3 100644 --- a/src/lib/Rattletrap/Type/List.hs +++ b/src/lib/Rattletrap/Type/List.hs @@ -1,13 +1,20 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.List - ( List(..) - ) where +module Rattletrap.Type.List where import Rattletrap.Type.Common +import Rattletrap.Type.Word32le + +import qualified Data.Binary as Binary newtype List a = List { listValue :: [a] } deriving (Eq, Ord, Show) $(deriveJson ''List) + +putList :: (a -> Binary.Put) -> List a -> Binary.Put +putList putElement list = do + let elements = listValue list + putWord32 (Word32le (fromIntegral (length elements))) + mapM_ putElement elements diff --git a/src/lib/Rattletrap/Type/LoadoutAttribute.hs b/src/lib/Rattletrap/Type/LoadoutAttribute.hs index 3163334a..decfbd28 100644 --- a/src/lib/Rattletrap/Type/LoadoutAttribute.hs +++ b/src/lib/Rattletrap/Type/LoadoutAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.LoadoutAttribute - ( LoadoutAttribute(..) - ) where +module Rattletrap.Type.LoadoutAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word32le import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data LoadoutAttribute = LoadoutAttribute { loadoutAttributeVersion :: Word8le , loadoutAttributeBody :: Word32le @@ -31,3 +31,28 @@ data LoadoutAttribute = LoadoutAttribute deriving (Eq, Ord, Show) $(deriveJson ''LoadoutAttribute) + +putLoadoutAttribute :: LoadoutAttribute -> BinaryBits.BitPut () +putLoadoutAttribute loadoutAttribute = do + putWord8Bits (loadoutAttributeVersion loadoutAttribute) + putWord32Bits (loadoutAttributeBody loadoutAttribute) + putWord32Bits (loadoutAttributeDecal loadoutAttribute) + putWord32Bits (loadoutAttributeWheels loadoutAttribute) + putWord32Bits (loadoutAttributeRocketTrail loadoutAttribute) + putWord32Bits (loadoutAttributeAntenna loadoutAttribute) + putWord32Bits (loadoutAttributeTopper loadoutAttribute) + putWord32Bits (loadoutAttributeUnknown1 loadoutAttribute) + putOptional (loadoutAttributeUnknown2 loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeEngineAudio loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeTrail loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeGoalExplosion loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeBanner loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeUnknown3 loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeUnknown4 loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeUnknown5 loadoutAttribute) putWord32Bits + putOptional (loadoutAttributeUnknown6 loadoutAttribute) putWord32Bits + +putOptional :: Maybe a -> (a -> BinaryBits.BitPut ()) -> BinaryBits.BitPut () +putOptional m f = case m of + Just x -> f x + Nothing -> pure () diff --git a/src/lib/Rattletrap/Type/LoadoutOnlineAttribute.hs b/src/lib/Rattletrap/Type/LoadoutOnlineAttribute.hs index ff70a0c3..2eb52554 100644 --- a/src/lib/Rattletrap/Type/LoadoutOnlineAttribute.hs +++ b/src/lib/Rattletrap/Type/LoadoutOnlineAttribute.hs @@ -1,14 +1,21 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.LoadoutOnlineAttribute - ( LoadoutOnlineAttribute(..) - ) where +module Rattletrap.Type.LoadoutOnlineAttribute where import Rattletrap.Type.Common import Rattletrap.Type.ProductAttribute +import Rattletrap.Type.Word8le + +import qualified Data.Binary.Bits.Put as BinaryBits newtype LoadoutOnlineAttribute = LoadoutOnlineAttribute { loadoutAttributeValue :: [[ProductAttribute]] } deriving (Eq, Ord, Show) $(deriveJson ''LoadoutOnlineAttribute) + +putLoadoutOnlineAttribute :: LoadoutOnlineAttribute -> BinaryBits.BitPut () +putLoadoutOnlineAttribute loadoutAttribute = do + let attributes = loadoutAttributeValue loadoutAttribute + putWord8Bits (Word8le (fromIntegral (length attributes))) + mapM_ putProductAttributes attributes diff --git a/src/lib/Rattletrap/Type/LoadoutsAttribute.hs b/src/lib/Rattletrap/Type/LoadoutsAttribute.hs index 11407198..c8b7d4df 100644 --- a/src/lib/Rattletrap/Type/LoadoutsAttribute.hs +++ b/src/lib/Rattletrap/Type/LoadoutsAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.LoadoutsAttribute - ( LoadoutsAttribute(..) - ) where +module Rattletrap.Type.LoadoutsAttribute where import Rattletrap.Type.Common import Rattletrap.Type.LoadoutAttribute +import qualified Data.Binary.Bits.Put as BinaryBits + data LoadoutsAttribute = LoadoutsAttribute { loadoutsAttributeBlue :: LoadoutAttribute , loadoutsAttributeOrange :: LoadoutAttribute @@ -14,3 +14,8 @@ data LoadoutsAttribute = LoadoutsAttribute deriving (Eq, Ord, Show) $(deriveJson ''LoadoutsAttribute) + +putLoadoutsAttribute :: LoadoutsAttribute -> BinaryBits.BitPut () +putLoadoutsAttribute loadoutsAttribute = do + putLoadoutAttribute (loadoutsAttributeBlue loadoutsAttribute) + putLoadoutAttribute (loadoutsAttributeOrange loadoutsAttribute) diff --git a/src/lib/Rattletrap/Type/LoadoutsOnlineAttribute.hs b/src/lib/Rattletrap/Type/LoadoutsOnlineAttribute.hs index 199f7c97..afd9627f 100644 --- a/src/lib/Rattletrap/Type/LoadoutsOnlineAttribute.hs +++ b/src/lib/Rattletrap/Type/LoadoutsOnlineAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.LoadoutsOnlineAttribute - ( LoadoutsOnlineAttribute(..) - ) where +module Rattletrap.Type.LoadoutsOnlineAttribute where import Rattletrap.Type.Common import Rattletrap.Type.LoadoutOnlineAttribute +import qualified Data.Binary.Bits.Put as BinaryBits + data LoadoutsOnlineAttribute = LoadoutsOnlineAttribute { loadoutsOnlineAttributeBlue :: LoadoutOnlineAttribute , loadoutsOnlineAttributeOrange :: LoadoutOnlineAttribute @@ -16,3 +16,12 @@ data LoadoutsOnlineAttribute = LoadoutsOnlineAttribute deriving (Eq, Ord, Show) $(deriveJson ''LoadoutsOnlineAttribute) + +putLoadoutsOnlineAttribute :: LoadoutsOnlineAttribute -> BinaryBits.BitPut () +putLoadoutsOnlineAttribute loadoutsOnlineAttribute = do + putLoadoutOnlineAttribute + (loadoutsOnlineAttributeBlue loadoutsOnlineAttribute) + putLoadoutOnlineAttribute + (loadoutsOnlineAttributeOrange loadoutsOnlineAttribute) + BinaryBits.putBool (loadoutsOnlineAttributeUnknown1 loadoutsOnlineAttribute) + BinaryBits.putBool (loadoutsOnlineAttributeUnknown2 loadoutsOnlineAttribute) diff --git a/src/lib/Rattletrap/Type/LocationAttribute.hs b/src/lib/Rattletrap/Type/LocationAttribute.hs index 2ce5b270..b447d2f0 100644 --- a/src/lib/Rattletrap/Type/LocationAttribute.hs +++ b/src/lib/Rattletrap/Type/LocationAttribute.hs @@ -1,14 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.LocationAttribute - ( LocationAttribute(..) - ) where +module Rattletrap.Type.LocationAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Vector +import qualified Data.Binary.Bits.Put as BinaryBits + newtype LocationAttribute = LocationAttribute { locationAttributeValue :: Vector } deriving (Eq, Ord, Show) $(deriveJson ''LocationAttribute) + +putLocationAttribute :: LocationAttribute -> BinaryBits.BitPut () +putLocationAttribute locationAttribute = + putVector (locationAttributeValue locationAttribute) diff --git a/src/lib/Rattletrap/Type/Mark.hs b/src/lib/Rattletrap/Type/Mark.hs index f5f2654f..94420ff6 100644 --- a/src/lib/Rattletrap/Type/Mark.hs +++ b/src/lib/Rattletrap/Type/Mark.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Mark - ( Mark(..) - ) where +module Rattletrap.Type.Mark where import Rattletrap.Type.Common import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import qualified Data.Binary as Binary + data Mark = Mark { markValue :: Str -- ^ Which type of mark this is, like @Team0Goal@. @@ -17,3 +17,8 @@ data Mark = Mark deriving (Eq, Ord, Show) $(deriveJson ''Mark) + +putMark :: Mark -> Binary.Put +putMark mark = do + putText (markValue mark) + putWord32 (markFrame mark) diff --git a/src/lib/Rattletrap/Type/Message.hs b/src/lib/Rattletrap/Type/Message.hs index 2682e5fe..a70c078c 100644 --- a/src/lib/Rattletrap/Type/Message.hs +++ b/src/lib/Rattletrap/Type/Message.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Message - ( Message(..) - ) where +module Rattletrap.Type.Message where import Rattletrap.Type.Common import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import qualified Data.Binary as Binary + data Message = Message { messageFrame :: Word32le -- ^ Which frame this message belongs to, starting from 0. @@ -19,3 +19,9 @@ data Message = Message deriving (Eq, Ord, Show) $(deriveJson ''Message) + +putMessage :: Message -> Binary.Put +putMessage message = do + putWord32 (messageFrame message) + putText (messageName message) + putText (messageValue message) diff --git a/src/lib/Rattletrap/Type/MusicStingerAttribute.hs b/src/lib/Rattletrap/Type/MusicStingerAttribute.hs index 1675df7f..95397250 100644 --- a/src/lib/Rattletrap/Type/MusicStingerAttribute.hs +++ b/src/lib/Rattletrap/Type/MusicStingerAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.MusicStingerAttribute - ( MusicStingerAttribute(..) - ) where +module Rattletrap.Type.MusicStingerAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word32le import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data MusicStingerAttribute = MusicStingerAttribute { musicStingerAttributeFlag :: Bool , musicStingerAttributeCue :: Word32le @@ -16,3 +16,9 @@ data MusicStingerAttribute = MusicStingerAttribute deriving (Eq, Ord, Show) $(deriveJson ''MusicStingerAttribute) + +putMusicStingerAttribute :: MusicStingerAttribute -> BinaryBits.BitPut () +putMusicStingerAttribute musicStingerAttribute = do + BinaryBits.putBool (musicStingerAttributeFlag musicStingerAttribute) + putWord32Bits (musicStingerAttributeCue musicStingerAttribute) + putWord8Bits (musicStingerAttributeTrigger musicStingerAttribute) diff --git a/src/lib/Rattletrap/Type/PartyLeaderAttribute.hs b/src/lib/Rattletrap/Type/PartyLeaderAttribute.hs index 04104c47..14c465e4 100644 --- a/src/lib/Rattletrap/Type/PartyLeaderAttribute.hs +++ b/src/lib/Rattletrap/Type/PartyLeaderAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.PartyLeaderAttribute - ( PartyLeaderAttribute(..) - ) where +module Rattletrap.Type.PartyLeaderAttribute where import Rattletrap.Type.Common import Rattletrap.Type.RemoteId import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data PartyLeaderAttribute = PartyLeaderAttribute { partyLeaderAttributeSystemId :: Word8le , partyLeaderAttributeId :: Maybe (RemoteId, Word8le) @@ -15,3 +15,12 @@ data PartyLeaderAttribute = PartyLeaderAttribute deriving (Eq, Ord, Show) $(deriveJson ''PartyLeaderAttribute) + +putPartyLeaderAttribute :: PartyLeaderAttribute -> BinaryBits.BitPut () +putPartyLeaderAttribute partyLeaderAttribute = do + putWord8Bits (partyLeaderAttributeSystemId partyLeaderAttribute) + case partyLeaderAttributeId partyLeaderAttribute of + Nothing -> pure () + Just (remoteId, localId) -> do + putRemoteId remoteId + putWord8Bits localId diff --git a/src/lib/Rattletrap/Type/PickupAttribute.hs b/src/lib/Rattletrap/Type/PickupAttribute.hs index 0145469c..b3a06a95 100644 --- a/src/lib/Rattletrap/Type/PickupAttribute.hs +++ b/src/lib/Rattletrap/Type/PickupAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.PickupAttribute - ( PickupAttribute(..) - ) where +module Rattletrap.Type.PickupAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word32le +import qualified Data.Binary.Bits.Put as BinaryBits + data PickupAttribute = PickupAttribute { pickupAttributeInstigatorId :: Maybe Word32le , pickupAttributePickedUp :: Bool @@ -14,3 +14,12 @@ data PickupAttribute = PickupAttribute deriving (Eq, Ord, Show) $(deriveJson ''PickupAttribute) + +putPickupAttribute :: PickupAttribute -> BinaryBits.BitPut () +putPickupAttribute pickupAttribute = do + case pickupAttributeInstigatorId pickupAttribute of + Nothing -> BinaryBits.putBool False + Just instigatorId -> do + BinaryBits.putBool True + putWord32Bits instigatorId + BinaryBits.putBool (pickupAttributePickedUp pickupAttribute) diff --git a/src/lib/Rattletrap/Type/PickupAttributeNew.hs b/src/lib/Rattletrap/Type/PickupAttributeNew.hs index 9b766296..132b6b46 100644 --- a/src/lib/Rattletrap/Type/PickupAttributeNew.hs +++ b/src/lib/Rattletrap/Type/PickupAttributeNew.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.PickupAttributeNew - ( PickupAttributeNew(..) - ) where +module Rattletrap.Type.PickupAttributeNew where import Rattletrap.Type.Common import Rattletrap.Type.Word32le import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data PickupAttributeNew = PickupAttributeNew { pickupAttributeNewInstigatorId :: Maybe Word32le , pickupAttributeNewPickedUp :: Word8le @@ -15,3 +15,12 @@ data PickupAttributeNew = PickupAttributeNew deriving (Eq, Ord, Show) $(deriveJson ''PickupAttributeNew) + +putPickupAttributeNew :: PickupAttributeNew -> BinaryBits.BitPut () +putPickupAttributeNew pickupAttributeNew = do + case pickupAttributeNewInstigatorId pickupAttributeNew of + Nothing -> BinaryBits.putBool False + Just instigatorId -> do + BinaryBits.putBool True + putWord32Bits instigatorId + putWord8Bits (pickupAttributeNewPickedUp pickupAttributeNew) diff --git a/src/lib/Rattletrap/Type/PlayerHistoryKeyAttribute.hs b/src/lib/Rattletrap/Type/PlayerHistoryKeyAttribute.hs index 9ec79848..e38f0696 100644 --- a/src/lib/Rattletrap/Type/PlayerHistoryKeyAttribute.hs +++ b/src/lib/Rattletrap/Type/PlayerHistoryKeyAttribute.hs @@ -1,13 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.PlayerHistoryKeyAttribute - ( PlayerHistoryKeyAttribute(..) - ) where +module Rattletrap.Type.PlayerHistoryKeyAttribute where import Rattletrap.Type.Common +import Rattletrap.Encode.Common + +import qualified Data.Binary.Bits.Put as BinaryBits newtype PlayerHistoryKeyAttribute = PlayerHistoryKeyAttribute { playerHistoryKeyAttributeUnknown :: Word16 } deriving (Eq, Ord, Show) $(deriveJson ''PlayerHistoryKeyAttribute) + +putPlayerHistoryKeyAttribute + :: PlayerHistoryKeyAttribute -> BinaryBits.BitPut () +putPlayerHistoryKeyAttribute = putBitsLE 14 . playerHistoryKeyAttributeUnknown diff --git a/src/lib/Rattletrap/Type/PrivateMatchSettingsAttribute.hs b/src/lib/Rattletrap/Type/PrivateMatchSettingsAttribute.hs index 9016b0c7..b01722ba 100644 --- a/src/lib/Rattletrap/Type/PrivateMatchSettingsAttribute.hs +++ b/src/lib/Rattletrap/Type/PrivateMatchSettingsAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.PrivateMatchSettingsAttribute - ( PrivateMatchSettingsAttribute(..) - ) where +module Rattletrap.Type.PrivateMatchSettingsAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import qualified Data.Binary.Bits.Put as BinaryBits + data PrivateMatchSettingsAttribute = PrivateMatchSettingsAttribute { privateMatchSettingsAttributeMutators :: Str , privateMatchSettingsAttributeJoinableBy :: Word32le @@ -19,3 +19,19 @@ data PrivateMatchSettingsAttribute = PrivateMatchSettingsAttribute deriving (Eq, Ord, Show) $(deriveJson ''PrivateMatchSettingsAttribute) + +putPrivateMatchSettingsAttribute + :: PrivateMatchSettingsAttribute -> BinaryBits.BitPut () +putPrivateMatchSettingsAttribute privateMatchSettingsAttribute = do + putTextBits + (privateMatchSettingsAttributeMutators privateMatchSettingsAttribute) + putWord32Bits + (privateMatchSettingsAttributeJoinableBy privateMatchSettingsAttribute) + putWord32Bits + (privateMatchSettingsAttributeMaxPlayers privateMatchSettingsAttribute) + putTextBits + (privateMatchSettingsAttributeGameName privateMatchSettingsAttribute) + putTextBits + (privateMatchSettingsAttributePassword privateMatchSettingsAttribute) + BinaryBits.putBool + (privateMatchSettingsAttributeFlag privateMatchSettingsAttribute) diff --git a/src/lib/Rattletrap/Type/ProductAttribute.hs b/src/lib/Rattletrap/Type/ProductAttribute.hs index 8aa9decb..6df0ec3b 100644 --- a/src/lib/Rattletrap/Type/ProductAttribute.hs +++ b/src/lib/Rattletrap/Type/ProductAttribute.hs @@ -1,14 +1,16 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ProductAttribute - ( ProductAttribute(..) - , ProductAttributeValue(..) - ) where +module Rattletrap.Type.ProductAttribute where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import Rattletrap.Encode.Common +import Rattletrap.Encode.CompressedWord +import Rattletrap.Type.Word8le + +import qualified Data.Binary.Bits.Put as BinaryBits data ProductAttributeValue = ProductAttributeValuePaintedOld CompressedWord @@ -33,3 +35,26 @@ data ProductAttribute = ProductAttribute deriving (Eq, Ord, Show) $(deriveJson ''ProductAttribute) + +putProductAttributes :: [ProductAttribute] -> BinaryBits.BitPut () +putProductAttributes attributes = do + putWord8Bits (Word8le (fromIntegral (length attributes))) + mapM_ putProductAttribute attributes + +putProductAttribute :: ProductAttribute -> BinaryBits.BitPut () +putProductAttribute attribute = do + BinaryBits.putBool (productAttributeUnknown attribute) + putWord32Bits (productAttributeObjectId attribute) + case productAttributeValue attribute of + ProductAttributeValuePaintedOld x -> putCompressedWord x + ProductAttributeValuePaintedNew x -> putBitsLE 31 x + ProductAttributeValueTeamEditionOld x -> putCompressedWord x + ProductAttributeValueTeamEditionNew x -> putBitsLE 31 x + ProductAttributeValueSpecialEdition x -> putBitsLE 31 x + ProductAttributeValueUserColorOld x -> case x of + Nothing -> BinaryBits.putBool False + Just y -> do + BinaryBits.putBool True + putBitsLE 31 y + ProductAttributeValueUserColorNew x -> putWord32Bits x + ProductAttributeValueTitleId x -> putTextBits x diff --git a/src/lib/Rattletrap/Type/Property.hs b/src/lib/Rattletrap/Type/Property.hs index 4f2b14c1..2f7cc524 100644 --- a/src/lib/Rattletrap/Type/Property.hs +++ b/src/lib/Rattletrap/Type/Property.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Property - ( Property(..) - ) where +module Rattletrap.Type.Property where import Rattletrap.Type.Common import Rattletrap.Type.PropertyValue import Rattletrap.Type.Str import Rattletrap.Type.Word64le +import qualified Data.Binary as Binary + data Property = Property { propertyKind :: Str , propertySize :: Word64le @@ -18,3 +18,9 @@ data Property = Property deriving (Eq, Ord, Show) $(deriveJson ''Property) + +putProperty :: Property -> Binary.Put +putProperty property = do + putText (propertyKind property) + putWord64 (propertySize property) + putPropertyValue putProperty (propertyValue property) diff --git a/src/lib/Rattletrap/Type/PropertyValue.hs b/src/lib/Rattletrap/Type/PropertyValue.hs index 7277b0b9..084aff6d 100644 --- a/src/lib/Rattletrap/Type/PropertyValue.hs +++ b/src/lib/Rattletrap/Type/PropertyValue.hs @@ -1,8 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.PropertyValue - ( PropertyValue(..) - ) where +module Rattletrap.Type.PropertyValue where import Rattletrap.Type.Common import Rattletrap.Type.Dictionary @@ -12,6 +10,10 @@ import Rattletrap.Type.List import Rattletrap.Type.Str import Rattletrap.Type.Word64le import Rattletrap.Type.Word8le +import Rattletrap.Encode.Dictionary +import Rattletrap.Encode.Float32le + +import qualified Data.Binary as Binary data PropertyValue a = PropertyValueArray (List (Dictionary a)) @@ -29,3 +31,18 @@ data PropertyValue a deriving (Eq, Ord, Show) $(deriveJson ''PropertyValue) + +putPropertyValue :: (a -> Binary.Put) -> PropertyValue a -> Binary.Put +putPropertyValue putProperty value = case value of + PropertyValueArray list -> putList (putDictionary putProperty) list + PropertyValueBool word8 -> putWord8 word8 + PropertyValueByte k mv -> do + putText k + case mv of + Nothing -> pure () + Just v -> putText v + PropertyValueFloat float32 -> putFloat32 float32 + PropertyValueInt int32 -> putInt32 int32 + PropertyValueName text -> putText text + PropertyValueQWord word64 -> putWord64 word64 + PropertyValueStr text -> putText text diff --git a/src/lib/Rattletrap/Type/QWordAttribute.hs b/src/lib/Rattletrap/Type/QWordAttribute.hs index 641ab255..a02f97ca 100644 --- a/src/lib/Rattletrap/Type/QWordAttribute.hs +++ b/src/lib/Rattletrap/Type/QWordAttribute.hs @@ -1,14 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.QWordAttribute - ( QWordAttribute(..) - ) where +module Rattletrap.Type.QWordAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word64le +import qualified Data.Binary.Bits.Put as BinaryBits + newtype QWordAttribute = QWordAttribute { qWordAttributeValue :: Word64le } deriving (Eq, Ord, Show) $(deriveJson ''QWordAttribute) + +putQWordAttribute :: QWordAttribute -> BinaryBits.BitPut () +putQWordAttribute qWordAttribute = + putWord64Bits (qWordAttributeValue qWordAttribute) diff --git a/src/lib/Rattletrap/Type/Quaternion.hs b/src/lib/Rattletrap/Type/Quaternion.hs index e1a55cf9..2be62986 100644 --- a/src/lib/Rattletrap/Type/Quaternion.hs +++ b/src/lib/Rattletrap/Type/Quaternion.hs @@ -1,18 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Quaternion - ( Quaternion(..) - , Component(..) - , toQuaternion - , compressPart - , decompressPart - , maxComponent - , maxCompressedValue - ) where +module Rattletrap.Type.Quaternion where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord +import Rattletrap.Encode.CompressedWord +import qualified Data.Binary.Bits.Put as BinaryBits import qualified Data.List as List import qualified Data.Maybe as Maybe @@ -96,3 +90,34 @@ maxCompressedValue = (2 ^ numBits) - 1 maxValue :: Double maxValue = 1.0 / sqrt 2.0 + +putQuaternion :: Quaternion -> BinaryBits.BitPut () +putQuaternion q = do + let c = maxComponent q + putComponent c + case c of + ComponentX -> putParts (quaternionY q) (quaternionZ q) (quaternionW q) + ComponentY -> putParts (quaternionX q) (quaternionZ q) (quaternionW q) + ComponentZ -> putParts (quaternionX q) (quaternionY q) (quaternionW q) + ComponentW -> putParts (quaternionX q) (quaternionY q) (quaternionZ q) + +putComponent :: Component -> BinaryBits.BitPut () +putComponent component = putCompressedWord + (CompressedWord + 3 + (case component of + ComponentX -> 0 + ComponentY -> 1 + ComponentZ -> 2 + ComponentW -> 3 + ) + ) + +putParts :: Double -> Double -> Double -> BinaryBits.BitPut () +putParts a b c = do + putPart a + putPart b + putPart c + +putPart :: Double -> BinaryBits.BitPut () +putPart = putCompressedWord . compressPart diff --git a/src/lib/Rattletrap/Type/RemoteId.hs b/src/lib/Rattletrap/Type/RemoteId.hs index 4bf663f1..9ed5cd28 100644 --- a/src/lib/Rattletrap/Type/RemoteId.hs +++ b/src/lib/Rattletrap/Type/RemoteId.hs @@ -1,12 +1,15 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.RemoteId - ( RemoteId(..) - ) where +module Rattletrap.Type.RemoteId where import Rattletrap.Type.Common import Rattletrap.Type.Str import Rattletrap.Type.Word64le +import Rattletrap.Encode.Common +import Rattletrap.Utility.Bytes + +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.ByteString as Bytes data RemoteId = RemoteIdPlayStation Text [Word8] @@ -20,3 +23,26 @@ data RemoteId deriving (Eq, Ord, Show) $(deriveJson ''RemoteId) + +putRemoteId :: RemoteId -> BinaryBits.BitPut () +putRemoteId remoteId = case remoteId of + RemoteIdPlayStation name bytes -> do + let rawName = reverseBytes (padBytes (16 :: Int) (encodeLatin1 name)) + BinaryBits.putByteString rawName + BinaryBits.putByteString (Bytes.pack bytes) + RemoteIdPsyNet e -> case e of + Left l -> putWord64Bits l + Right (a, b, c, d) -> putWord256 a b c d + RemoteIdSplitscreen word24 -> putBitsLE 24 word24 + RemoteIdSteam word64 -> putWord64Bits word64 + RemoteIdSwitch a b c d -> putWord256 a b c d + RemoteIdXbox word64 -> putWord64Bits word64 + RemoteIdEpic str -> putTextBits str + +putWord256 + :: Word64le -> Word64le -> Word64le -> Word64le -> BinaryBits.BitPut () +putWord256 a b c d = do + putWord64Bits a + putWord64Bits b + putWord64Bits c + putWord64Bits d diff --git a/src/lib/Rattletrap/Type/Replay.hs b/src/lib/Rattletrap/Type/Replay.hs index f3b48508..9b757cde 100644 --- a/src/lib/Rattletrap/Type/Replay.hs +++ b/src/lib/Rattletrap/Type/Replay.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Replay - ( FullReplay - , Replay(..) - ) where +module Rattletrap.Type.Replay where import Rattletrap.Type.Common import Rattletrap.Type.Content import Rattletrap.Type.Header import Rattletrap.Type.Section +import Rattletrap.Encode.Content + +import qualified Data.Binary as Binary type FullReplay = Replay Content @@ -22,3 +22,13 @@ data Replay content = Replay deriving (Eq, Ord, Show) $(deriveJson ''Replay) + +-- | Generates a raw replay. Use this with 'Data.Binary.Put.runPut'. +-- +-- @ +-- let bytes = 'Data.Binary.Put.runPut' ('putReplay' replay) +-- @ +putReplay :: FullReplay -> Binary.Put +putReplay replay = do + putSection putHeader (replayHeader replay) + putSection putContent (replayContent replay) diff --git a/src/lib/Rattletrap/Type/Replication.hs b/src/lib/Rattletrap/Type/Replication.hs index 04ad61e7..f0dc97cd 100644 --- a/src/lib/Rattletrap/Type/Replication.hs +++ b/src/lib/Rattletrap/Type/Replication.hs @@ -1,12 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Replication - ( Replication(..) - ) where +module Rattletrap.Type.Replication where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord import Rattletrap.Type.ReplicationValue +import Rattletrap.Encode.CompressedWord + +import qualified Data.Binary.Bits.Put as BinaryBits data Replication = Replication { replicationActorId :: CompressedWord @@ -15,3 +16,19 @@ data Replication = Replication deriving (Eq, Ord, Show) $(deriveJson ''Replication) + +putReplications :: [Replication] -> BinaryBits.BitPut () +putReplications replications = case replications of + [] -> BinaryBits.putBool False + [replication] -> do + putReplication replication + BinaryBits.putBool False + first : rest -> do + putReplication first + putReplications rest + +putReplication :: Replication -> BinaryBits.BitPut () +putReplication replication = do + BinaryBits.putBool True + putCompressedWord (replicationActorId replication) + putReplicationValue (replicationValue replication) diff --git a/src/lib/Rattletrap/Type/ReplicationValue.hs b/src/lib/Rattletrap/Type/ReplicationValue.hs index f1d0ade3..dace2122 100644 --- a/src/lib/Rattletrap/Type/ReplicationValue.hs +++ b/src/lib/Rattletrap/Type/ReplicationValue.hs @@ -1,13 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ReplicationValue - ( ReplicationValue(..) - ) where +module Rattletrap.Type.ReplicationValue where import Rattletrap.Type.Common import Rattletrap.Type.DestroyedReplication import Rattletrap.Type.SpawnedReplication import Rattletrap.Type.UpdatedReplication +import Rattletrap.Encode.DestroyedReplication + +import qualified Data.Binary.Bits.Put as BinaryBits data ReplicationValue = ReplicationValueSpawned SpawnedReplication @@ -19,3 +20,17 @@ data ReplicationValue deriving (Eq, Ord, Show) $(deriveJson ''ReplicationValue) + +putReplicationValue :: ReplicationValue -> BinaryBits.BitPut () +putReplicationValue value = case value of + ReplicationValueSpawned x -> do + BinaryBits.putBool True + BinaryBits.putBool True + putSpawnedReplication x + ReplicationValueUpdated x -> do + BinaryBits.putBool True + BinaryBits.putBool False + putUpdatedReplication x + ReplicationValueDestroyed x -> do + BinaryBits.putBool False + putDestroyedReplication x diff --git a/src/lib/Rattletrap/Type/ReservationAttribute.hs b/src/lib/Rattletrap/Type/ReservationAttribute.hs index 54b1a698..47f3d521 100644 --- a/src/lib/Rattletrap/Type/ReservationAttribute.hs +++ b/src/lib/Rattletrap/Type/ReservationAttribute.hs @@ -1,14 +1,15 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ReservationAttribute - ( ReservationAttribute(..) - ) where +module Rattletrap.Type.ReservationAttribute where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord +import Rattletrap.Encode.CompressedWord import Rattletrap.Type.Str import Rattletrap.Type.UniqueIdAttribute +import qualified Data.Binary.Bits.Put as BinaryBits + data ReservationAttribute = ReservationAttribute { reservationAttributeNumber :: CompressedWord , reservationAttributeUniqueId :: UniqueIdAttribute @@ -20,3 +21,16 @@ data ReservationAttribute = ReservationAttribute deriving (Eq, Ord, Show) $(deriveJson ''ReservationAttribute) + +putReservationAttribute :: ReservationAttribute -> BinaryBits.BitPut () +putReservationAttribute reservationAttribute = do + putCompressedWord (reservationAttributeNumber reservationAttribute) + putUniqueIdAttribute (reservationAttributeUniqueId reservationAttribute) + case reservationAttributeName reservationAttribute of + Nothing -> pure () + Just name -> putTextBits name + BinaryBits.putBool (reservationAttributeUnknown1 reservationAttribute) + BinaryBits.putBool (reservationAttributeUnknown2 reservationAttribute) + case reservationAttributeUnknown3 reservationAttribute of + Nothing -> pure () + Just c -> BinaryBits.putWord8 6 c diff --git a/src/lib/Rattletrap/Type/RigidBodyStateAttribute.hs b/src/lib/Rattletrap/Type/RigidBodyStateAttribute.hs index 1a82c1a7..d8f5cfa4 100644 --- a/src/lib/Rattletrap/Type/RigidBodyStateAttribute.hs +++ b/src/lib/Rattletrap/Type/RigidBodyStateAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.RigidBodyStateAttribute - ( RigidBodyStateAttribute(..) - ) where +module Rattletrap.Type.RigidBodyStateAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Rotation import Rattletrap.Type.Vector +import qualified Data.Binary.Bits.Put as BinaryBits + data RigidBodyStateAttribute = RigidBodyStateAttribute { rigidBodyStateAttributeSleeping :: Bool , rigidBodyStateAttributeLocation :: Vector @@ -18,3 +18,15 @@ data RigidBodyStateAttribute = RigidBodyStateAttribute deriving (Eq, Ord, Show) $(deriveJson ''RigidBodyStateAttribute) + +putRigidBodyStateAttribute :: RigidBodyStateAttribute -> BinaryBits.BitPut () +putRigidBodyStateAttribute rigidBodyStateAttribute = do + BinaryBits.putBool (rigidBodyStateAttributeSleeping rigidBodyStateAttribute) + putVector (rigidBodyStateAttributeLocation rigidBodyStateAttribute) + putRotation (rigidBodyStateAttributeRotation rigidBodyStateAttribute) + case rigidBodyStateAttributeLinearVelocity rigidBodyStateAttribute of + Nothing -> pure () + Just linearVelocity -> putVector linearVelocity + case rigidBodyStateAttributeAngularVelocity rigidBodyStateAttribute of + Nothing -> pure () + Just angularVelocity -> putVector angularVelocity diff --git a/src/lib/Rattletrap/Type/Rotation.hs b/src/lib/Rattletrap/Type/Rotation.hs index 4e9179ca..818a4184 100644 --- a/src/lib/Rattletrap/Type/Rotation.hs +++ b/src/lib/Rattletrap/Type/Rotation.hs @@ -1,12 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Rotation - ( Rotation(..) - ) where +module Rattletrap.Type.Rotation where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWordVector import Rattletrap.Type.Quaternion +import Rattletrap.Encode.CompressedWordVector + +import qualified Data.Binary.Bits.Put as BinaryBits data Rotation = RotationCompressedWordVector CompressedWordVector @@ -14,3 +15,8 @@ data Rotation deriving (Eq, Ord, Show) $(deriveJson ''Rotation) + +putRotation :: Rotation -> BinaryBits.BitPut () +putRotation r = case r of + RotationCompressedWordVector cwv -> putCompressedWordVector cwv + RotationQuaternion q -> putQuaternion q diff --git a/src/lib/Rattletrap/Type/Section.hs b/src/lib/Rattletrap/Type/Section.hs index 2d3851af..5af87c9a 100644 --- a/src/lib/Rattletrap/Type/Section.hs +++ b/src/lib/Rattletrap/Type/Section.hs @@ -1,9 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Section - ( Section(..) - , toSection - ) where +module Rattletrap.Type.Section where import Rattletrap.Type.Common import Rattletrap.Type.Word32le @@ -39,3 +36,20 @@ toSection encode body = , sectionCrc = Word32le $ getCrc32 bytes , sectionBody = body } + +-- | Given a way to put the 'sectionBody', puts a section. This will also put +-- the size and CRC. +-- +-- @ +-- let bytes = 'Data.Binary.Put.runPut' ('putSection' 'Rattletrap.Content.putContent' content) +-- @ +putSection :: (a -> Binary.Put) -> Section a -> Binary.Put +putSection putBody section = do + let + rawBody = + LazyBytes.toStrict (Binary.runPut (putBody (sectionBody section))) + let size = Bytes.length rawBody + let crc = getCrc32 rawBody + putWord32 (Word32le (fromIntegral size)) + putWord32 (Word32le crc) + Binary.putByteString rawBody diff --git a/src/lib/Rattletrap/Type/SpawnedReplication.hs b/src/lib/Rattletrap/Type/SpawnedReplication.hs index 989fc1e4..d4eb167b 100644 --- a/src/lib/Rattletrap/Type/SpawnedReplication.hs +++ b/src/lib/Rattletrap/Type/SpawnedReplication.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.SpawnedReplication - ( SpawnedReplication(..) - ) where +module Rattletrap.Type.SpawnedReplication where import Rattletrap.Type.Common import Rattletrap.Type.Initialization import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import qualified Data.Binary.Bits.Put as BinaryBits + data SpawnedReplication = SpawnedReplication { spawnedReplicationFlag :: Bool -- ^ Unclear what this is. @@ -28,3 +28,12 @@ data SpawnedReplication = SpawnedReplication deriving (Eq, Ord, Show) $(deriveJson ''SpawnedReplication) + +putSpawnedReplication :: SpawnedReplication -> BinaryBits.BitPut () +putSpawnedReplication spawnedReplication = do + BinaryBits.putBool (spawnedReplicationFlag spawnedReplication) + case spawnedReplicationNameIndex spawnedReplication of + Nothing -> pure () + Just nameIndex -> putWord32Bits nameIndex + putWord32Bits (spawnedReplicationObjectId spawnedReplication) + putInitialization (spawnedReplicationInitialization spawnedReplication) diff --git a/src/lib/Rattletrap/Type/StatEventAttribute.hs b/src/lib/Rattletrap/Type/StatEventAttribute.hs index 7d7c9a21..f700fd7e 100644 --- a/src/lib/Rattletrap/Type/StatEventAttribute.hs +++ b/src/lib/Rattletrap/Type/StatEventAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.StatEventAttribute - ( StatEventAttribute(..) - ) where +module Rattletrap.Type.StatEventAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Int32le +import qualified Data.Binary.Bits.Put as BinaryBits + data StatEventAttribute = StatEventAttribute { statEventAttributeUnknown :: Bool , statEventAttributeObjectId :: Int32le @@ -14,3 +14,8 @@ data StatEventAttribute = StatEventAttribute deriving (Eq, Ord, Show) $(deriveJson ''StatEventAttribute) + +putStatEventAttribute :: StatEventAttribute -> BinaryBits.BitPut () +putStatEventAttribute statEventAttribute = do + BinaryBits.putBool (statEventAttributeUnknown statEventAttribute) + putInt32Bits (statEventAttributeObjectId statEventAttribute) diff --git a/src/lib/Rattletrap/Type/Str.hs b/src/lib/Rattletrap/Type/Str.hs index 17923222..123ab38b 100644 --- a/src/lib/Rattletrap/Type/Str.hs +++ b/src/lib/Rattletrap/Type/Str.hs @@ -1,14 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Str - ( Str(..) - , toStr - , fromStr - ) where +module Rattletrap.Type.Str where import Rattletrap.Type.Common +import Rattletrap.Type.Int32le +import Rattletrap.Utility.Bytes +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString as Bytes +import qualified Data.Char as Char import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text newtype Str = Str { strValue :: Text @@ -21,3 +25,37 @@ toStr string = Str (Text.pack string) fromStr :: Str -> String fromStr text = Text.unpack (strValue text) + +putText :: Str -> Binary.Put +putText text = do + let size = getTextSize text + let encode = getTextEncoder size + putInt32 size + Binary.putByteString (encode (addNull (strValue text))) + +putTextBits :: Str -> BinaryBits.BitPut () +putTextBits text = do + let size = getTextSize text + let encode = getTextEncoder size + putInt32Bits size + BinaryBits.putByteString (reverseBytes (encode (addNull (strValue text)))) + +getTextSize :: Str -> Int32le +getTextSize text = + let + value = strValue text + scale = if Text.all Char.isLatin1 value then 1 else -1 :: Int32 + rawSize = if Text.null value + then 0 + else fromIntegral (Text.length value) + 1 :: Int32 + size = if value == Text.pack "\x00\x00\x00None" + then 0x05000000 + else scale * rawSize :: Int32 + in Int32le size + +getTextEncoder :: Int32le -> Text.Text -> Bytes.ByteString +getTextEncoder size text = + if size < Int32le 0 then Text.encodeUtf16LE text else encodeLatin1 text + +addNull :: Text.Text -> Text.Text +addNull text = if Text.null text then text else Text.snoc text '\x00' diff --git a/src/lib/Rattletrap/Type/StringAttribute.hs b/src/lib/Rattletrap/Type/StringAttribute.hs index 9eec8cb5..544a72eb 100644 --- a/src/lib/Rattletrap/Type/StringAttribute.hs +++ b/src/lib/Rattletrap/Type/StringAttribute.hs @@ -1,14 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.StringAttribute - ( StringAttribute(..) - ) where +module Rattletrap.Type.StringAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Str +import qualified Data.Binary.Bits.Put as BinaryBits + newtype StringAttribute = StringAttribute { stringAttributeValue :: Str } deriving (Eq, Ord, Show) $(deriveJson ''StringAttribute) + +putStringAttribute :: StringAttribute -> BinaryBits.BitPut () +putStringAttribute stringAttribute = + putTextBits (stringAttributeValue stringAttribute) diff --git a/src/lib/Rattletrap/Type/TeamPaintAttribute.hs b/src/lib/Rattletrap/Type/TeamPaintAttribute.hs index 1425cf51..869b27fb 100644 --- a/src/lib/Rattletrap/Type/TeamPaintAttribute.hs +++ b/src/lib/Rattletrap/Type/TeamPaintAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.TeamPaintAttribute - ( TeamPaintAttribute(..) - ) where +module Rattletrap.Type.TeamPaintAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word32le import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data TeamPaintAttribute = TeamPaintAttribute { teamPaintAttributeTeam :: Word8le , teamPaintAttributePrimaryColor :: Word8le @@ -18,3 +18,11 @@ data TeamPaintAttribute = TeamPaintAttribute deriving (Eq, Ord, Show) $(deriveJson ''TeamPaintAttribute) + +putTeamPaintAttribute :: TeamPaintAttribute -> BinaryBits.BitPut () +putTeamPaintAttribute teamPaintAttribute = do + putWord8Bits (teamPaintAttributeTeam teamPaintAttribute) + putWord8Bits (teamPaintAttributePrimaryColor teamPaintAttribute) + putWord8Bits (teamPaintAttributeAccentColor teamPaintAttribute) + putWord32Bits (teamPaintAttributePrimaryFinish teamPaintAttribute) + putWord32Bits (teamPaintAttributeAccentFinish teamPaintAttribute) diff --git a/src/lib/Rattletrap/Type/TitleAttribute.hs b/src/lib/Rattletrap/Type/TitleAttribute.hs index 13e38d85..1912603e 100644 --- a/src/lib/Rattletrap/Type/TitleAttribute.hs +++ b/src/lib/Rattletrap/Type/TitleAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.TitleAttribute - ( TitleAttribute(..) - ) where +module Rattletrap.Type.TitleAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word32le +import qualified Data.Binary.Bits.Put as BinaryBits + data TitleAttribute = TitleAttribute { titleAttributeUnknown1 :: Bool , titleAttributeUnknown2 :: Bool @@ -20,3 +20,14 @@ data TitleAttribute = TitleAttribute deriving (Eq, Ord, Show) $(deriveJson ''TitleAttribute) + +putTitleAttribute :: TitleAttribute -> BinaryBits.BitPut () +putTitleAttribute titleAttribute = do + BinaryBits.putBool (titleAttributeUnknown1 titleAttribute) + BinaryBits.putBool (titleAttributeUnknown2 titleAttribute) + putWord32Bits (titleAttributeUnknown3 titleAttribute) + putWord32Bits (titleAttributeUnknown4 titleAttribute) + putWord32Bits (titleAttributeUnknown5 titleAttribute) + putWord32Bits (titleAttributeUnknown6 titleAttribute) + putWord32Bits (titleAttributeUnknown7 titleAttribute) + BinaryBits.putBool (titleAttributeUnknown8 titleAttribute) diff --git a/src/lib/Rattletrap/Type/UniqueIdAttribute.hs b/src/lib/Rattletrap/Type/UniqueIdAttribute.hs index 7869e5aa..f024772c 100644 --- a/src/lib/Rattletrap/Type/UniqueIdAttribute.hs +++ b/src/lib/Rattletrap/Type/UniqueIdAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.UniqueIdAttribute - ( UniqueIdAttribute(..) - ) where +module Rattletrap.Type.UniqueIdAttribute where import Rattletrap.Type.Common import Rattletrap.Type.RemoteId import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data UniqueIdAttribute = UniqueIdAttribute { uniqueIdAttributeSystemId :: Word8le , uniqueIdAttributeRemoteId :: RemoteId @@ -16,3 +16,9 @@ data UniqueIdAttribute = UniqueIdAttribute deriving (Eq, Ord, Show) $(deriveJson ''UniqueIdAttribute) + +putUniqueIdAttribute :: UniqueIdAttribute -> BinaryBits.BitPut () +putUniqueIdAttribute uniqueIdAttribute = do + putWord8Bits (uniqueIdAttributeSystemId uniqueIdAttribute) + putRemoteId (uniqueIdAttributeRemoteId uniqueIdAttribute) + putWord8Bits (uniqueIdAttributeLocalId uniqueIdAttribute) diff --git a/src/lib/Rattletrap/Type/UpdatedReplication.hs b/src/lib/Rattletrap/Type/UpdatedReplication.hs index 301de10b..cfbda36c 100644 --- a/src/lib/Rattletrap/Type/UpdatedReplication.hs +++ b/src/lib/Rattletrap/Type/UpdatedReplication.hs @@ -1,14 +1,19 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.UpdatedReplication - ( UpdatedReplication(..) - ) where +module Rattletrap.Type.UpdatedReplication where import Rattletrap.Type.Attribute import Rattletrap.Type.Common +import Rattletrap.Encode.Attribute + +import qualified Data.Binary.Bits.Put as BinaryBits newtype UpdatedReplication = UpdatedReplication { updatedReplicationAttributes :: [Attribute] } deriving (Eq, Ord, Show) $(deriveJson ''UpdatedReplication) + +putUpdatedReplication :: UpdatedReplication -> BinaryBits.BitPut () +putUpdatedReplication updatedReplication = + putAttributes (updatedReplicationAttributes updatedReplication) diff --git a/src/lib/Rattletrap/Type/Vector.hs b/src/lib/Rattletrap/Type/Vector.hs index 4c52ce27..37e911c6 100644 --- a/src/lib/Rattletrap/Type/Vector.hs +++ b/src/lib/Rattletrap/Type/Vector.hs @@ -1,11 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Vector - ( Vector(..) - ) where +module Rattletrap.Type.Vector where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord +import Rattletrap.Encode.CompressedWord + +import qualified Data.Binary.Bits.Put as BinaryBits data Vector = Vector { vectorSize :: CompressedWord @@ -24,3 +25,20 @@ data Vector = Vector deriving (Eq, Ord, Show) $(deriveJson ''Vector) + +putVector :: Vector -> BinaryBits.BitPut () +putVector vector = do + let + bitSize = + round (logBase (2 :: Float) (fromIntegral (vectorBias vector))) - 1 :: Word + dx = + fromIntegral (vectorX vector + fromIntegral (vectorBias vector)) :: Word + dy = + fromIntegral (vectorY vector + fromIntegral (vectorBias vector)) :: Word + dz = + fromIntegral (vectorZ vector + fromIntegral (vectorBias vector)) :: Word + limit = 2 ^ (bitSize + 2) :: Word + putCompressedWord (vectorSize vector) + putCompressedWord (CompressedWord limit dx) + putCompressedWord (CompressedWord limit dy) + putCompressedWord (CompressedWord limit dz) diff --git a/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs b/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs index 23fb3052..f96324a3 100644 --- a/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs +++ b/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs @@ -1,14 +1,15 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.WeldedInfoAttribute - ( WeldedInfoAttribute(..) - ) where +module Rattletrap.Type.WeldedInfoAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Float32le import Rattletrap.Type.Int32le import Rattletrap.Type.Int8Vector import Rattletrap.Type.Vector +import Rattletrap.Encode.Float32le + +import qualified Data.Binary.Bits.Put as BinaryBits data WeldedInfoAttribute = WeldedInfoAttribute { weldedInfoAttributeActive :: Bool @@ -20,3 +21,11 @@ data WeldedInfoAttribute = WeldedInfoAttribute deriving (Eq, Ord, Show) $(deriveJson ''WeldedInfoAttribute) + +putWeldedInfoAttribute :: WeldedInfoAttribute -> BinaryBits.BitPut () +putWeldedInfoAttribute weldedInfoAttribute = do + BinaryBits.putBool (weldedInfoAttributeActive weldedInfoAttribute) + putInt32Bits (weldedInfoAttributeActorId weldedInfoAttribute) + putVector (weldedInfoAttributeOffset weldedInfoAttribute) + putFloat32Bits (weldedInfoAttributeMass weldedInfoAttribute) + putInt8Vector (weldedInfoAttributeRotation weldedInfoAttribute) diff --git a/src/lib/Rattletrap/Type/Word64le.hs b/src/lib/Rattletrap/Type/Word64le.hs index 35d7d42e..eb853e4b 100644 --- a/src/lib/Rattletrap/Type/Word64le.hs +++ b/src/lib/Rattletrap/Type/Word64le.hs @@ -1,7 +1,11 @@ -module Rattletrap.Type.Word64le - ( Word64le(..) - ) where +module Rattletrap.Type.Word64le where +import Rattletrap.Utility.Bytes + +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString.Lazy as LazyBytes import qualified Data.Aeson as Aeson import qualified Data.Aeson.Types as Aeson import qualified Data.Scientific as Scientific @@ -25,3 +29,11 @@ instance Aeson.FromJSON Word64le where instance Aeson.ToJSON Word64le where toJSON = Aeson.toJSON . show . word64leValue + +putWord64 :: Word64le -> Binary.Put +putWord64 word64 = Binary.putWord64le (word64leValue word64) + +putWord64Bits :: Word64le -> BinaryBits.BitPut () +putWord64Bits word64 = do + let bytes = LazyBytes.toStrict (Binary.runPut (putWord64 word64)) + BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Type/Word8le.hs b/src/lib/Rattletrap/Type/Word8le.hs index df85fdc9..886cb513 100644 --- a/src/lib/Rattletrap/Type/Word8le.hs +++ b/src/lib/Rattletrap/Type/Word8le.hs @@ -1,13 +1,25 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Word8le - ( Word8le(..) - ) where +module Rattletrap.Type.Word8le where import Rattletrap.Type.Common +import Rattletrap.Utility.Bytes + +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString.Lazy as LazyBytes newtype Word8le = Word8le { word8leValue :: Word8 } deriving (Eq, Ord, Show) $(deriveJson ''Word8le) + +putWord8 :: Word8le -> Binary.Put +putWord8 word8 = Binary.putWord8 (word8leValue word8) + +putWord8Bits :: Word8le -> BinaryBits.BitPut () +putWord8Bits word8 = do + let bytes = LazyBytes.toStrict (Binary.runPut (putWord8 word8)) + BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Utility/Helper.hs b/src/lib/Rattletrap/Utility/Helper.hs index f5369770..c3c41f71 100644 --- a/src/lib/Rattletrap/Utility/Helper.hs +++ b/src/lib/Rattletrap/Utility/Helper.hs @@ -10,7 +10,6 @@ module Rattletrap.Utility.Helper import Rattletrap.Decode.Common import Rattletrap.Decode.Replay import Rattletrap.Encode.Content -import Rattletrap.Encode.Replay import Rattletrap.Type.Content import Rattletrap.Type.Replay import Rattletrap.Type.Section From a74fcab1d5e6847a2dfb561eebe4872fda801433 Mon Sep 17 00:00:00 2001 From: Taylor Fausak Date: Fri, 12 Feb 2021 19:18:58 -0500 Subject: [PATCH 3/3] Finish inlining encoding stuff --- rattletrap.cabal | 27 ------ src/lib/Rattletrap/Decode/CompressedWord.hs | 2 +- src/lib/Rattletrap/Decode/Replay.hs | 1 - .../Encode/AppliedDamageAttribute.hs | 17 ---- src/lib/Rattletrap/Encode/Attribute.hs | 25 ------ src/lib/Rattletrap/Encode/AttributeMapping.hs | 13 --- src/lib/Rattletrap/Encode/AttributeValue.hs | 84 ------------------- src/lib/Rattletrap/Encode/BooleanAttribute.hs | 11 --- src/lib/Rattletrap/Encode/ByteAttribute.hs | 12 --- src/lib/Rattletrap/Encode/Cache.hs | 17 ---- .../Rattletrap/Encode/CamSettingsAttribute.hs | 20 ----- src/lib/Rattletrap/Encode/ClassMapping.hs | 14 ---- .../Rattletrap/Encode/ClubColorsAttribute.hs | 15 ---- src/lib/Rattletrap/Encode/CompressedWord.hs | 43 ---------- .../Rattletrap/Encode/CompressedWordVector.hs | 14 ---- src/lib/Rattletrap/Encode/Content.hs | 56 ------------- .../Encode/CustomDemolishAttribute.hs | 15 ---- .../Rattletrap/Encode/DamageStateAttribute.hs | 19 ----- .../Rattletrap/Encode/DemolishAttribute.hs | 18 ---- .../Rattletrap/Encode/DestroyedReplication.hs | 10 --- src/lib/Rattletrap/Encode/Dictionary.hs | 16 ---- src/lib/Rattletrap/Encode/EnumAttribute.hs | 12 --- .../Rattletrap/Encode/ExplosionAttribute.hs | 15 ---- .../Encode/ExtendedExplosionAttribute.hs | 15 ---- .../Rattletrap/Encode/FlaggedByteAttribute.hs | 13 --- .../Rattletrap/Encode/FlaggedIntAttribute.hs | 13 --- src/lib/Rattletrap/Encode/Float32le.hs | 20 ----- src/lib/Rattletrap/Encode/FloatAttribute.hs | 12 --- src/lib/Rattletrap/Encode/Frame.hs | 23 ----- .../Rattletrap/Encode/GameModeAttribute.hs | 13 --- .../Rattletrap/Type/AppliedDamageAttribute.hs | 13 ++- src/lib/Rattletrap/Type/Attribute.hs | 22 ++++- src/lib/Rattletrap/Type/AttributeMapping.hs | 11 ++- src/lib/Rattletrap/Type/AttributeValue.hs | 46 +++++++++- src/lib/Rattletrap/Type/BooleanAttribute.hs | 10 ++- src/lib/Rattletrap/Type/ByteAttribute.hs | 10 ++- src/lib/Rattletrap/Type/Cache.hs | 13 ++- .../Rattletrap/Type/CamSettingsAttribute.hs | 18 +++- src/lib/Rattletrap/Type/ClassMapping.hs | 11 ++- .../Rattletrap/Type/ClubColorsAttribute.hs | 13 ++- src/lib/Rattletrap/Type/CompressedWord.hs | 42 +++++++++- .../Rattletrap/Type/CompressedWordVector.hs | 12 ++- src/lib/Rattletrap/Type/Content.hs | 47 ++++++++++- .../Type/CustomDemolishAttribute.hs | 12 ++- .../Rattletrap/Type/DamageStateAttribute.hs | 15 +++- src/lib/Rattletrap/Type/DemolishAttribute.hs | 15 +++- .../Rattletrap/Type/DestroyedReplication.hs | 9 +- src/lib/Rattletrap/Type/Dictionary.hs | 14 +++- src/lib/Rattletrap/Type/EnumAttribute.hs | 11 ++- src/lib/Rattletrap/Type/ExplosionAttribute.hs | 12 ++- .../Type/ExtendedExplosionAttribute.hs | 12 ++- .../Rattletrap/Type/FlaggedByteAttribute.hs | 11 ++- .../Rattletrap/Type/FlaggedIntAttribute.hs | 11 ++- src/lib/Rattletrap/Type/Float32le.hs | 18 +++- src/lib/Rattletrap/Type/FloatAttribute.hs | 10 ++- src/lib/Rattletrap/Type/Frame.hs | 20 ++++- src/lib/Rattletrap/Type/GameModeAttribute.hs | 12 ++- src/lib/Rattletrap/Type/Header.hs | 1 - src/lib/Rattletrap/Type/KeyFrame.hs | 1 - src/lib/Rattletrap/Type/ProductAttribute.hs | 1 - src/lib/Rattletrap/Type/PropertyValue.hs | 2 - src/lib/Rattletrap/Type/Quaternion.hs | 1 - src/lib/Rattletrap/Type/Replay.hs | 1 - src/lib/Rattletrap/Type/Replication.hs | 1 - src/lib/Rattletrap/Type/ReplicationValue.hs | 1 - .../Rattletrap/Type/ReservationAttribute.hs | 1 - src/lib/Rattletrap/Type/Rotation.hs | 1 - src/lib/Rattletrap/Type/UpdatedReplication.hs | 1 - src/lib/Rattletrap/Type/Vector.hs | 1 - .../Rattletrap/Type/WeldedInfoAttribute.hs | 1 - src/lib/Rattletrap/Utility/Helper.hs | 1 - 71 files changed, 368 insertions(+), 682 deletions(-) delete mode 100644 src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Attribute.hs delete mode 100644 src/lib/Rattletrap/Encode/AttributeMapping.hs delete mode 100644 src/lib/Rattletrap/Encode/AttributeValue.hs delete mode 100644 src/lib/Rattletrap/Encode/BooleanAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/ByteAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Cache.hs delete mode 100644 src/lib/Rattletrap/Encode/CamSettingsAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/ClassMapping.hs delete mode 100644 src/lib/Rattletrap/Encode/ClubColorsAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/CompressedWord.hs delete mode 100644 src/lib/Rattletrap/Encode/CompressedWordVector.hs delete mode 100644 src/lib/Rattletrap/Encode/Content.hs delete mode 100644 src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/DamageStateAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/DemolishAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/DestroyedReplication.hs delete mode 100644 src/lib/Rattletrap/Encode/Dictionary.hs delete mode 100644 src/lib/Rattletrap/Encode/EnumAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/ExplosionAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/ExtendedExplosionAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Float32le.hs delete mode 100644 src/lib/Rattletrap/Encode/FloatAttribute.hs delete mode 100644 src/lib/Rattletrap/Encode/Frame.hs delete mode 100644 src/lib/Rattletrap/Encode/GameModeAttribute.hs diff --git a/rattletrap.cabal b/rattletrap.cabal index 27438784..719caffa 100644 --- a/rattletrap.cabal +++ b/rattletrap.cabal @@ -121,34 +121,7 @@ library Rattletrap.Decode.Word32le Rattletrap.Decode.Word64le Rattletrap.Decode.Word8le - Rattletrap.Encode.AppliedDamageAttribute - Rattletrap.Encode.Attribute - Rattletrap.Encode.AttributeMapping - Rattletrap.Encode.AttributeValue - Rattletrap.Encode.BooleanAttribute - Rattletrap.Encode.ByteAttribute - Rattletrap.Encode.Cache - Rattletrap.Encode.CamSettingsAttribute - Rattletrap.Encode.ClassMapping - Rattletrap.Encode.ClubColorsAttribute Rattletrap.Encode.Common - Rattletrap.Encode.CompressedWord - Rattletrap.Encode.CompressedWordVector - Rattletrap.Encode.Content - Rattletrap.Encode.CustomDemolishAttribute - Rattletrap.Encode.DamageStateAttribute - Rattletrap.Encode.DemolishAttribute - Rattletrap.Encode.DestroyedReplication - Rattletrap.Encode.Dictionary - Rattletrap.Encode.EnumAttribute - Rattletrap.Encode.ExplosionAttribute - Rattletrap.Encode.ExtendedExplosionAttribute - Rattletrap.Encode.FlaggedByteAttribute - Rattletrap.Encode.FlaggedIntAttribute - Rattletrap.Encode.Float32le - Rattletrap.Encode.FloatAttribute - Rattletrap.Encode.Frame - Rattletrap.Encode.GameModeAttribute Rattletrap.Type.AppliedDamageAttribute Rattletrap.Type.Attribute Rattletrap.Type.AttributeMapping diff --git a/src/lib/Rattletrap/Decode/CompressedWord.hs b/src/lib/Rattletrap/Decode/CompressedWord.hs index 5c4aabab..9a39ef79 100644 --- a/src/lib/Rattletrap/Decode/CompressedWord.hs +++ b/src/lib/Rattletrap/Decode/CompressedWord.hs @@ -3,7 +3,7 @@ module Rattletrap.Decode.CompressedWord ) where import Rattletrap.Decode.Common -import Rattletrap.Type.CompressedWord +import Rattletrap.Type.CompressedWord hiding (getMaxBits) import qualified Data.Bits as Bits diff --git a/src/lib/Rattletrap/Decode/Replay.hs b/src/lib/Rattletrap/Decode/Replay.hs index 7c5394ca..39529c0a 100644 --- a/src/lib/Rattletrap/Decode/Replay.hs +++ b/src/lib/Rattletrap/Decode/Replay.hs @@ -6,7 +6,6 @@ import Rattletrap.Decode.Common import Rattletrap.Decode.Content import Rattletrap.Decode.Header import Rattletrap.Decode.Section -import Rattletrap.Encode.Content import Rattletrap.Type.Content import Rattletrap.Type.Dictionary import Rattletrap.Type.Header diff --git a/src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs b/src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs deleted file mode 100644 index fa176f43..00000000 --- a/src/lib/Rattletrap/Encode/AppliedDamageAttribute.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Rattletrap.Encode.AppliedDamageAttribute - ( putAppliedDamageAttribute - ) where - -import Rattletrap.Type.Int32le -import Rattletrap.Type.Vector -import Rattletrap.Type.Word8le -import Rattletrap.Type.AppliedDamageAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putAppliedDamageAttribute :: AppliedDamageAttribute -> BinaryBits.BitPut () -putAppliedDamageAttribute appliedDamageAttribute = do - putWord8Bits (appliedDamageAttributeUnknown1 appliedDamageAttribute) - putVector (appliedDamageAttributeLocation appliedDamageAttribute) - putInt32Bits (appliedDamageAttributeUnknown3 appliedDamageAttribute) - putInt32Bits (appliedDamageAttributeUnknown4 appliedDamageAttribute) diff --git a/src/lib/Rattletrap/Encode/Attribute.hs b/src/lib/Rattletrap/Encode/Attribute.hs deleted file mode 100644 index 007b14e6..00000000 --- a/src/lib/Rattletrap/Encode/Attribute.hs +++ /dev/null @@ -1,25 +0,0 @@ -module Rattletrap.Encode.Attribute - ( putAttributes - ) where - -import Rattletrap.Encode.AttributeValue -import Rattletrap.Encode.CompressedWord -import Rattletrap.Type.Attribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putAttributes :: [Attribute] -> BinaryBits.BitPut () -putAttributes attributes = case attributes of - [] -> BinaryBits.putBool False - [attribute] -> do - putAttribute attribute - BinaryBits.putBool False - first : rest -> do - putAttribute first - putAttributes rest - -putAttribute :: Attribute -> BinaryBits.BitPut () -putAttribute attribute = do - BinaryBits.putBool True - putCompressedWord (attributeId attribute) - putAttributeValue (attributeValue attribute) diff --git a/src/lib/Rattletrap/Encode/AttributeMapping.hs b/src/lib/Rattletrap/Encode/AttributeMapping.hs deleted file mode 100644 index c4e9ebfc..00000000 --- a/src/lib/Rattletrap/Encode/AttributeMapping.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Rattletrap.Encode.AttributeMapping - ( putAttributeMapping - ) where - -import Rattletrap.Type.Word32le -import Rattletrap.Type.AttributeMapping - -import qualified Data.Binary as Binary - -putAttributeMapping :: AttributeMapping -> Binary.Put -putAttributeMapping attributeMapping = do - putWord32 (attributeMappingObjectId attributeMapping) - putWord32 (attributeMappingStreamId attributeMapping) diff --git a/src/lib/Rattletrap/Encode/AttributeValue.hs b/src/lib/Rattletrap/Encode/AttributeValue.hs deleted file mode 100644 index fcfcaeeb..00000000 --- a/src/lib/Rattletrap/Encode/AttributeValue.hs +++ /dev/null @@ -1,84 +0,0 @@ -module Rattletrap.Encode.AttributeValue - ( putAttributeValue - ) where - -import Rattletrap.Encode.AppliedDamageAttribute -import Rattletrap.Encode.BooleanAttribute -import Rattletrap.Encode.ByteAttribute -import Rattletrap.Encode.CamSettingsAttribute -import Rattletrap.Encode.ClubColorsAttribute -import Rattletrap.Encode.CustomDemolishAttribute -import Rattletrap.Encode.DamageStateAttribute -import Rattletrap.Encode.DemolishAttribute -import Rattletrap.Encode.EnumAttribute -import Rattletrap.Encode.ExplosionAttribute -import Rattletrap.Encode.ExtendedExplosionAttribute -import Rattletrap.Encode.FlaggedByteAttribute -import Rattletrap.Encode.FlaggedIntAttribute -import Rattletrap.Encode.FloatAttribute -import Rattletrap.Encode.GameModeAttribute -import Rattletrap.Type.Int64Attribute -import Rattletrap.Type.IntAttribute -import Rattletrap.Type.LoadoutAttribute -import Rattletrap.Type.LoadoutOnlineAttribute -import Rattletrap.Type.LoadoutsAttribute -import Rattletrap.Type.LoadoutsOnlineAttribute -import Rattletrap.Type.LocationAttribute -import Rattletrap.Type.MusicStingerAttribute -import Rattletrap.Type.PartyLeaderAttribute -import Rattletrap.Type.PickupAttribute -import Rattletrap.Type.PickupAttributeNew -import Rattletrap.Type.PlayerHistoryKeyAttribute -import Rattletrap.Type.PrivateMatchSettingsAttribute -import Rattletrap.Type.QWordAttribute -import Rattletrap.Type.ReservationAttribute -import Rattletrap.Type.RigidBodyStateAttribute -import Rattletrap.Type.StatEventAttribute -import Rattletrap.Type.StringAttribute -import Rattletrap.Type.TeamPaintAttribute -import Rattletrap.Type.TitleAttribute -import Rattletrap.Type.UniqueIdAttribute -import Rattletrap.Type.WeldedInfoAttribute -import Rattletrap.Type.AttributeValue - -import qualified Data.Binary.Bits.Put as BinaryBits - -putAttributeValue :: AttributeValue -> BinaryBits.BitPut () -putAttributeValue value = case value of - AttributeValueAppliedDamage x -> putAppliedDamageAttribute x - AttributeValueBoolean x -> putBooleanAttribute x - AttributeValueByte x -> putByteAttribute x - AttributeValueCamSettings x -> putCamSettingsAttribute x - AttributeValueClubColors x -> putClubColorsAttribute x - AttributeValueCustomDemolish x -> putCustomDemolishAttribute x - AttributeValueDamageState x -> putDamageStateAttribute x - AttributeValueDemolish x -> putDemolishAttribute x - AttributeValueEnum x -> putEnumAttribute x - AttributeValueExplosion x -> putExplosionAttribute x - AttributeValueExtendedExplosion x -> putExtendedExplosionAttribute x - AttributeValueFlaggedInt x -> putFlaggedIntAttribute x - AttributeValueFlaggedByte x -> putFlaggedByteAttribute x - AttributeValueFloat x -> putFloatAttribute x - AttributeValueGameMode x -> putGameModeAttribute x - AttributeValueInt x -> putIntAttribute x - AttributeValueInt64 x -> putInt64Attribute x - AttributeValueLoadout x -> putLoadoutAttribute x - AttributeValueLoadoutOnline x -> putLoadoutOnlineAttribute x - AttributeValueLoadouts x -> putLoadoutsAttribute x - AttributeValueLoadoutsOnline x -> putLoadoutsOnlineAttribute x - AttributeValueLocation x -> putLocationAttribute x - AttributeValueMusicStinger x -> putMusicStingerAttribute x - AttributeValuePartyLeader x -> putPartyLeaderAttribute x - AttributeValuePickup x -> putPickupAttribute x - AttributeValuePickupNew x -> putPickupAttributeNew x - AttributeValuePlayerHistoryKey x -> putPlayerHistoryKeyAttribute x - AttributeValuePrivateMatchSettings x -> putPrivateMatchSettingsAttribute x - AttributeValueQWord x -> putQWordAttribute x - AttributeValueReservation x -> putReservationAttribute x - AttributeValueRigidBodyState x -> putRigidBodyStateAttribute x - AttributeValueStatEvent x -> putStatEventAttribute x - AttributeValueString x -> putStringAttribute x - AttributeValueTeamPaint x -> putTeamPaintAttribute x - AttributeValueTitle x -> putTitleAttribute x - AttributeValueUniqueId x -> putUniqueIdAttribute x - AttributeValueWeldedInfo x -> putWeldedInfoAttribute x diff --git a/src/lib/Rattletrap/Encode/BooleanAttribute.hs b/src/lib/Rattletrap/Encode/BooleanAttribute.hs deleted file mode 100644 index 5f40d4a5..00000000 --- a/src/lib/Rattletrap/Encode/BooleanAttribute.hs +++ /dev/null @@ -1,11 +0,0 @@ -module Rattletrap.Encode.BooleanAttribute - ( putBooleanAttribute - ) where - -import Rattletrap.Type.BooleanAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putBooleanAttribute :: BooleanAttribute -> BinaryBits.BitPut () -putBooleanAttribute booleanAttribute = - BinaryBits.putBool (booleanAttributeValue booleanAttribute) diff --git a/src/lib/Rattletrap/Encode/ByteAttribute.hs b/src/lib/Rattletrap/Encode/ByteAttribute.hs deleted file mode 100644 index df1fcd03..00000000 --- a/src/lib/Rattletrap/Encode/ByteAttribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.ByteAttribute - ( putByteAttribute - ) where - -import Rattletrap.Type.Word8le -import Rattletrap.Type.ByteAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putByteAttribute :: ByteAttribute -> BinaryBits.BitPut () -putByteAttribute byteAttribute = - putWord8Bits (byteAttributeValue byteAttribute) diff --git a/src/lib/Rattletrap/Encode/Cache.hs b/src/lib/Rattletrap/Encode/Cache.hs deleted file mode 100644 index 86cfdb6c..00000000 --- a/src/lib/Rattletrap/Encode/Cache.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Rattletrap.Encode.Cache - ( putCache - ) where - -import Rattletrap.Encode.AttributeMapping -import Rattletrap.Type.List -import Rattletrap.Type.Word32le -import Rattletrap.Type.Cache - -import qualified Data.Binary as Binary - -putCache :: Cache -> Binary.Put -putCache cache = do - putWord32 (cacheClassId cache) - putWord32 (cacheParentCacheId cache) - putWord32 (cacheCacheId cache) - putList putAttributeMapping (cacheAttributeMappings cache) diff --git a/src/lib/Rattletrap/Encode/CamSettingsAttribute.hs b/src/lib/Rattletrap/Encode/CamSettingsAttribute.hs deleted file mode 100644 index 791dddfd..00000000 --- a/src/lib/Rattletrap/Encode/CamSettingsAttribute.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Rattletrap.Encode.CamSettingsAttribute - ( putCamSettingsAttribute - ) where - -import Rattletrap.Encode.Float32le -import Rattletrap.Type.CamSettingsAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putCamSettingsAttribute :: CamSettingsAttribute -> BinaryBits.BitPut () -putCamSettingsAttribute camSettingsAttribute = do - putFloat32Bits (camSettingsAttributeFov camSettingsAttribute) - putFloat32Bits (camSettingsAttributeHeight camSettingsAttribute) - putFloat32Bits (camSettingsAttributeAngle camSettingsAttribute) - putFloat32Bits (camSettingsAttributeDistance camSettingsAttribute) - putFloat32Bits (camSettingsAttributeStiffness camSettingsAttribute) - putFloat32Bits (camSettingsAttributeSwivelSpeed camSettingsAttribute) - case camSettingsAttributeTransitionSpeed camSettingsAttribute of - Nothing -> pure () - Just transitionSpeed -> putFloat32Bits transitionSpeed diff --git a/src/lib/Rattletrap/Encode/ClassMapping.hs b/src/lib/Rattletrap/Encode/ClassMapping.hs deleted file mode 100644 index b85bf81e..00000000 --- a/src/lib/Rattletrap/Encode/ClassMapping.hs +++ /dev/null @@ -1,14 +0,0 @@ -module Rattletrap.Encode.ClassMapping - ( putClassMapping - ) where - -import Rattletrap.Type.Str -import Rattletrap.Type.Word32le -import Rattletrap.Type.ClassMapping - -import qualified Data.Binary as Binary - -putClassMapping :: ClassMapping -> Binary.Put -putClassMapping classMapping = do - putText (classMappingName classMapping) - putWord32 (classMappingStreamId classMapping) diff --git a/src/lib/Rattletrap/Encode/ClubColorsAttribute.hs b/src/lib/Rattletrap/Encode/ClubColorsAttribute.hs deleted file mode 100644 index d91450e0..00000000 --- a/src/lib/Rattletrap/Encode/ClubColorsAttribute.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.ClubColorsAttribute - ( putClubColorsAttribute - ) where - -import Rattletrap.Type.Word8le -import Rattletrap.Type.ClubColorsAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putClubColorsAttribute :: ClubColorsAttribute -> BinaryBits.BitPut () -putClubColorsAttribute clubColorsAttribute = do - BinaryBits.putBool (clubColorsAttributeBlueFlag clubColorsAttribute) - putWord8Bits (clubColorsAttributeBlueColor clubColorsAttribute) - BinaryBits.putBool (clubColorsAttributeOrangeFlag clubColorsAttribute) - putWord8Bits (clubColorsAttributeOrangeColor clubColorsAttribute) diff --git a/src/lib/Rattletrap/Encode/CompressedWord.hs b/src/lib/Rattletrap/Encode/CompressedWord.hs deleted file mode 100644 index 952c18cf..00000000 --- a/src/lib/Rattletrap/Encode/CompressedWord.hs +++ /dev/null @@ -1,43 +0,0 @@ -module Rattletrap.Encode.CompressedWord - ( putCompressedWord - ) where - -import Rattletrap.Type.CompressedWord - -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Bits as Bits - -putCompressedWord :: CompressedWord -> BinaryBits.BitPut () -putCompressedWord compressedWord = - let - limit = compressedWordLimit compressedWord - value = compressedWordValue compressedWord - maxBits = getMaxBits limit - in putCompressedWordStep limit value maxBits 0 0 - -putCompressedWordStep - :: Word -> Word -> Int -> Int -> Word -> BinaryBits.BitPut () -putCompressedWordStep limit value maxBits position soFar = - if position < maxBits - then do - let x = Bits.shiftL 1 position :: Word - if maxBits > 1 && position == maxBits - 1 && soFar + x > limit - then pure () - else do - let bit = Bits.testBit value position - BinaryBits.putBool bit - let delta = if bit then x else 0 - putCompressedWordStep - limit - value - maxBits - (position + 1) - (soFar + delta) - else pure () - -getMaxBits :: Word -> Int -getMaxBits x = - let - n :: Int - n = max 1 (ceiling (logBase (2 :: Double) (fromIntegral (max 1 x)))) - in if x < 1024 && x == 2 ^ n then n + 1 else n diff --git a/src/lib/Rattletrap/Encode/CompressedWordVector.hs b/src/lib/Rattletrap/Encode/CompressedWordVector.hs deleted file mode 100644 index ac8ec7c7..00000000 --- a/src/lib/Rattletrap/Encode/CompressedWordVector.hs +++ /dev/null @@ -1,14 +0,0 @@ -module Rattletrap.Encode.CompressedWordVector - ( putCompressedWordVector - ) where - -import Rattletrap.Encode.CompressedWord -import Rattletrap.Type.CompressedWordVector - -import qualified Data.Binary.Bits.Put as BinaryBits - -putCompressedWordVector :: CompressedWordVector -> BinaryBits.BitPut () -putCompressedWordVector compressedWordVector = do - putCompressedWord (compressedWordVectorX compressedWordVector) - putCompressedWord (compressedWordVectorY compressedWordVector) - putCompressedWord (compressedWordVectorZ compressedWordVector) diff --git a/src/lib/Rattletrap/Encode/Content.hs b/src/lib/Rattletrap/Encode/Content.hs deleted file mode 100644 index 9f26b873..00000000 --- a/src/lib/Rattletrap/Encode/Content.hs +++ /dev/null @@ -1,56 +0,0 @@ -module Rattletrap.Encode.Content - ( putContent - ) where - -import Rattletrap.Encode.Cache -import Rattletrap.Encode.ClassMapping -import Rattletrap.Encode.Frame -import Rattletrap.Type.KeyFrame -import Rattletrap.Type.List -import Rattletrap.Type.Mark -import Rattletrap.Type.Message -import Rattletrap.Type.Str -import Rattletrap.Type.Content -import Rattletrap.Type.Word32le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString as Bytes -import qualified Data.ByteString.Lazy as LazyBytes - -putContent :: Content -> Binary.Put -putContent content = do - putList putText (contentLevels content) - putList putKeyFrame (contentKeyFrames content) - let - stream = LazyBytes.toStrict - (Binary.runPut (BinaryBits.runBitPut (putFrames (contentFrames content))) - ) - -- This is a little strange. When parsing a binary replay, the stream size - -- is given before the stream itself. When generating the JSON, the stream - -- size is included. That allows a bit-for-bit identical binary replay to - -- be generated from the JSON. However if you modify the JSON before - -- converting it back into binary, the stream size might be different. - -- - -- If it was possible to know how much padding the stream required without - -- carrying it along as extra data on the side, this logic could go away. - -- Unforunately that isn't currently known. See this issue for details: - -- . - expectedStreamSize = contentStreamSize content - actualStreamSize = Word32le . fromIntegral $ Bytes.length stream - streamSize = Word32le $ max - (word32leValue expectedStreamSize) - (word32leValue actualStreamSize) - putWord32 streamSize - Binary.putByteString - (reverseBytes (padBytes (word32leValue streamSize) stream)) - putList putMessage (contentMessages content) - putList putMark (contentMarks content) - putList putText (contentPackages content) - putList putText (contentObjects content) - putList putText (contentNames content) - putList putClassMapping (contentClassMappings content) - putList putCache (contentCaches content) - mapM_ Binary.putWord8 (contentUnknown content) diff --git a/src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs b/src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs deleted file mode 100644 index c38595bf..00000000 --- a/src/lib/Rattletrap/Encode/CustomDemolishAttribute.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.CustomDemolishAttribute - ( putCustomDemolishAttribute - ) where - -import Rattletrap.Encode.DemolishAttribute -import Rattletrap.Type.Int32le -import Rattletrap.Type.CustomDemolishAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putCustomDemolishAttribute :: CustomDemolishAttribute -> BinaryBits.BitPut () -putCustomDemolishAttribute x = do - BinaryBits.putBool (customDemolishAttributeFlag x) - putInt32Bits (customDemolishAttributeId x) - putDemolishAttribute (customDemolishAttributeDemolish x) diff --git a/src/lib/Rattletrap/Encode/DamageStateAttribute.hs b/src/lib/Rattletrap/Encode/DamageStateAttribute.hs deleted file mode 100644 index 799b8ba4..00000000 --- a/src/lib/Rattletrap/Encode/DamageStateAttribute.hs +++ /dev/null @@ -1,19 +0,0 @@ -module Rattletrap.Encode.DamageStateAttribute - ( putDamageStateAttribute - ) where - -import Rattletrap.Type.Int32le -import Rattletrap.Type.Vector -import Rattletrap.Type.Word8le -import Rattletrap.Type.DamageStateAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putDamageStateAttribute :: DamageStateAttribute -> BinaryBits.BitPut () -putDamageStateAttribute damageStateAttribute = do - putWord8Bits (damageStateAttributeUnknown1 damageStateAttribute) - BinaryBits.putBool (damageStateAttributeUnknown2 damageStateAttribute) - putInt32Bits (damageStateAttributeUnknown3 damageStateAttribute) - putVector (damageStateAttributeUnknown4 damageStateAttribute) - BinaryBits.putBool (damageStateAttributeUnknown5 damageStateAttribute) - BinaryBits.putBool (damageStateAttributeUnknown6 damageStateAttribute) diff --git a/src/lib/Rattletrap/Encode/DemolishAttribute.hs b/src/lib/Rattletrap/Encode/DemolishAttribute.hs deleted file mode 100644 index c6db8643..00000000 --- a/src/lib/Rattletrap/Encode/DemolishAttribute.hs +++ /dev/null @@ -1,18 +0,0 @@ -module Rattletrap.Encode.DemolishAttribute - ( putDemolishAttribute - ) where - -import Rattletrap.Type.Vector -import Rattletrap.Type.Word32le -import Rattletrap.Type.DemolishAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putDemolishAttribute :: DemolishAttribute -> BinaryBits.BitPut () -putDemolishAttribute demolishAttribute = do - BinaryBits.putBool (demolishAttributeAttackerFlag demolishAttribute) - putWord32Bits (demolishAttributeAttackerActorId demolishAttribute) - BinaryBits.putBool (demolishAttributeVictimFlag demolishAttribute) - putWord32Bits (demolishAttributeVictimActorId demolishAttribute) - putVector (demolishAttributeAttackerVelocity demolishAttribute) - putVector (demolishAttributeVictimVelocity demolishAttribute) diff --git a/src/lib/Rattletrap/Encode/DestroyedReplication.hs b/src/lib/Rattletrap/Encode/DestroyedReplication.hs deleted file mode 100644 index ec85ff32..00000000 --- a/src/lib/Rattletrap/Encode/DestroyedReplication.hs +++ /dev/null @@ -1,10 +0,0 @@ -module Rattletrap.Encode.DestroyedReplication - ( putDestroyedReplication - ) where - -import Rattletrap.Type.DestroyedReplication - -import qualified Data.Binary.Bits.Put as BinaryBits - -putDestroyedReplication :: DestroyedReplication -> BinaryBits.BitPut () -putDestroyedReplication _ = pure () diff --git a/src/lib/Rattletrap/Encode/Dictionary.hs b/src/lib/Rattletrap/Encode/Dictionary.hs deleted file mode 100644 index f94514d6..00000000 --- a/src/lib/Rattletrap/Encode/Dictionary.hs +++ /dev/null @@ -1,16 +0,0 @@ -module Rattletrap.Encode.Dictionary - ( putDictionary - ) where - -import Rattletrap.Type.Str -import Rattletrap.Type.Dictionary - -import qualified Data.Binary as Binary - -putDictionary :: (a -> Binary.Put) -> Dictionary a -> Binary.Put -putDictionary f x = case x of - DictionaryElement k v y -> do - putText k - f v - putDictionary f y - DictionaryEnd y -> putText y diff --git a/src/lib/Rattletrap/Encode/EnumAttribute.hs b/src/lib/Rattletrap/Encode/EnumAttribute.hs deleted file mode 100644 index ac9f7cd8..00000000 --- a/src/lib/Rattletrap/Encode/EnumAttribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.EnumAttribute - ( putEnumAttribute - ) where - -import Rattletrap.Encode.Common -import Rattletrap.Type.EnumAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putEnumAttribute :: EnumAttribute -> BinaryBits.BitPut () -putEnumAttribute enumAttribute = - putBitsLE 11 (enumAttributeValue enumAttribute) diff --git a/src/lib/Rattletrap/Encode/ExplosionAttribute.hs b/src/lib/Rattletrap/Encode/ExplosionAttribute.hs deleted file mode 100644 index d5a066cd..00000000 --- a/src/lib/Rattletrap/Encode/ExplosionAttribute.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.ExplosionAttribute - ( putExplosionAttribute - ) where - -import Rattletrap.Type.Int32le -import Rattletrap.Type.Vector -import Rattletrap.Type.ExplosionAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putExplosionAttribute :: ExplosionAttribute -> BinaryBits.BitPut () -putExplosionAttribute explosionAttribute = do - BinaryBits.putBool False - putInt32Bits (explosionAttributeActorId explosionAttribute) - putVector (explosionAttributeLocation explosionAttribute) diff --git a/src/lib/Rattletrap/Encode/ExtendedExplosionAttribute.hs b/src/lib/Rattletrap/Encode/ExtendedExplosionAttribute.hs deleted file mode 100644 index 5d8bd7ca..00000000 --- a/src/lib/Rattletrap/Encode/ExtendedExplosionAttribute.hs +++ /dev/null @@ -1,15 +0,0 @@ -module Rattletrap.Encode.ExtendedExplosionAttribute - ( putExtendedExplosionAttribute - ) where - -import Rattletrap.Encode.ExplosionAttribute -import Rattletrap.Encode.FlaggedIntAttribute -import Rattletrap.Type.ExtendedExplosionAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putExtendedExplosionAttribute - :: ExtendedExplosionAttribute -> BinaryBits.BitPut () -putExtendedExplosionAttribute x = do - putExplosionAttribute (extendedExplosionAttributeExplosion x) - putFlaggedIntAttribute (extendedExplosionAttributeUnknown x) diff --git a/src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs b/src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs deleted file mode 100644 index 55ab3f78..00000000 --- a/src/lib/Rattletrap/Encode/FlaggedByteAttribute.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Rattletrap.Encode.FlaggedByteAttribute - ( putFlaggedByteAttribute - ) where - -import Rattletrap.Type.Word8le -import Rattletrap.Type.FlaggedByteAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putFlaggedByteAttribute :: FlaggedByteAttribute -> BinaryBits.BitPut () -putFlaggedByteAttribute flaggedByteAttribute = do - BinaryBits.putBool (flaggedByteAttributeFlag flaggedByteAttribute) - putWord8Bits (flaggedByteAttributeByte flaggedByteAttribute) diff --git a/src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs b/src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs deleted file mode 100644 index 0076867f..00000000 --- a/src/lib/Rattletrap/Encode/FlaggedIntAttribute.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Rattletrap.Encode.FlaggedIntAttribute - ( putFlaggedIntAttribute - ) where - -import Rattletrap.Type.Int32le -import Rattletrap.Type.FlaggedIntAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putFlaggedIntAttribute :: FlaggedIntAttribute -> BinaryBits.BitPut () -putFlaggedIntAttribute flaggedIntAttribute = do - BinaryBits.putBool (flaggedIntAttributeFlag flaggedIntAttribute) - putInt32Bits (flaggedIntAttributeInt flaggedIntAttribute) diff --git a/src/lib/Rattletrap/Encode/Float32le.hs b/src/lib/Rattletrap/Encode/Float32le.hs deleted file mode 100644 index 6361e2d3..00000000 --- a/src/lib/Rattletrap/Encode/Float32le.hs +++ /dev/null @@ -1,20 +0,0 @@ -module Rattletrap.Encode.Float32le - ( putFloat32 - , putFloat32Bits - ) where - -import Rattletrap.Type.Float32le -import Rattletrap.Utility.Bytes - -import qualified Data.Binary as Binary -import qualified Data.Binary.Bits.Put as BinaryBits -import qualified Data.Binary.Put as Binary -import qualified Data.ByteString.Lazy as LazyBytes - -putFloat32 :: Float32le -> Binary.Put -putFloat32 = Binary.putFloatle . float32leValue - -putFloat32Bits :: Float32le -> BinaryBits.BitPut () -putFloat32Bits float32 = do - let bytes = LazyBytes.toStrict (Binary.runPut (putFloat32 float32)) - BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Encode/FloatAttribute.hs b/src/lib/Rattletrap/Encode/FloatAttribute.hs deleted file mode 100644 index dc095fd1..00000000 --- a/src/lib/Rattletrap/Encode/FloatAttribute.hs +++ /dev/null @@ -1,12 +0,0 @@ -module Rattletrap.Encode.FloatAttribute - ( putFloatAttribute - ) where - -import Rattletrap.Encode.Float32le -import Rattletrap.Type.FloatAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putFloatAttribute :: FloatAttribute -> BinaryBits.BitPut () -putFloatAttribute floatAttribute = - putFloat32Bits (floatAttributeValue floatAttribute) diff --git a/src/lib/Rattletrap/Encode/Frame.hs b/src/lib/Rattletrap/Encode/Frame.hs deleted file mode 100644 index 6cae024b..00000000 --- a/src/lib/Rattletrap/Encode/Frame.hs +++ /dev/null @@ -1,23 +0,0 @@ -module Rattletrap.Encode.Frame - ( putFrames - ) where - -import Rattletrap.Encode.Float32le -import Rattletrap.Type.Replication -import Rattletrap.Type.Frame - -import qualified Data.Binary.Bits.Put as BinaryBits - -putFrames :: [Frame] -> BinaryBits.BitPut () -putFrames frames = case frames of - [] -> pure () - [frame] -> putFrame frame - first : rest -> do - putFrame first - putFrames rest - -putFrame :: Frame -> BinaryBits.BitPut () -putFrame frame = do - putFloat32Bits (frameTime frame) - putFloat32Bits (frameDelta frame) - putReplications (frameReplications frame) diff --git a/src/lib/Rattletrap/Encode/GameModeAttribute.hs b/src/lib/Rattletrap/Encode/GameModeAttribute.hs deleted file mode 100644 index a945c5de..00000000 --- a/src/lib/Rattletrap/Encode/GameModeAttribute.hs +++ /dev/null @@ -1,13 +0,0 @@ -module Rattletrap.Encode.GameModeAttribute - ( putGameModeAttribute - ) where - -import Rattletrap.Type.GameModeAttribute - -import qualified Data.Binary.Bits.Put as BinaryBits - -putGameModeAttribute :: GameModeAttribute -> BinaryBits.BitPut () -putGameModeAttribute gameModeAttribute = do - let numBits = gameModeAttributeNumBits gameModeAttribute - let word = gameModeAttributeWord gameModeAttribute - BinaryBits.putWord8 numBits word diff --git a/src/lib/Rattletrap/Type/AppliedDamageAttribute.hs b/src/lib/Rattletrap/Type/AppliedDamageAttribute.hs index 6ea14d4d..8483732b 100644 --- a/src/lib/Rattletrap/Type/AppliedDamageAttribute.hs +++ b/src/lib/Rattletrap/Type/AppliedDamageAttribute.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.AppliedDamageAttribute - ( AppliedDamageAttribute(..) - ) where +module Rattletrap.Type.AppliedDamageAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Int32le import Rattletrap.Type.Vector import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data AppliedDamageAttribute = AppliedDamageAttribute { appliedDamageAttributeUnknown1 :: Word8le , appliedDamageAttributeLocation :: Vector @@ -18,3 +18,10 @@ data AppliedDamageAttribute = AppliedDamageAttribute deriving (Eq, Ord, Show) $(deriveJson ''AppliedDamageAttribute) + +putAppliedDamageAttribute :: AppliedDamageAttribute -> BinaryBits.BitPut () +putAppliedDamageAttribute appliedDamageAttribute = do + putWord8Bits (appliedDamageAttributeUnknown1 appliedDamageAttribute) + putVector (appliedDamageAttributeLocation appliedDamageAttribute) + putInt32Bits (appliedDamageAttributeUnknown3 appliedDamageAttribute) + putInt32Bits (appliedDamageAttributeUnknown4 appliedDamageAttribute) diff --git a/src/lib/Rattletrap/Type/Attribute.hs b/src/lib/Rattletrap/Type/Attribute.hs index 0428b5a2..5b2008c0 100644 --- a/src/lib/Rattletrap/Type/Attribute.hs +++ b/src/lib/Rattletrap/Type/Attribute.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Attribute - ( Attribute(..) - ) where +module Rattletrap.Type.Attribute where import Rattletrap.Type.AttributeValue import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord import Rattletrap.Type.Str +import qualified Data.Binary.Bits.Put as BinaryBits + data Attribute = Attribute { attributeId :: CompressedWord , attributeName :: Str @@ -19,3 +19,19 @@ data Attribute = Attribute deriving (Eq, Ord, Show) $(deriveJson ''Attribute) + +putAttributes :: [Attribute] -> BinaryBits.BitPut () +putAttributes attributes = case attributes of + [] -> BinaryBits.putBool False + [attribute] -> do + putAttribute attribute + BinaryBits.putBool False + first : rest -> do + putAttribute first + putAttributes rest + +putAttribute :: Attribute -> BinaryBits.BitPut () +putAttribute attribute = do + BinaryBits.putBool True + putCompressedWord (attributeId attribute) + putAttributeValue (attributeValue attribute) diff --git a/src/lib/Rattletrap/Type/AttributeMapping.hs b/src/lib/Rattletrap/Type/AttributeMapping.hs index 23ac65ee..3c4040d0 100644 --- a/src/lib/Rattletrap/Type/AttributeMapping.hs +++ b/src/lib/Rattletrap/Type/AttributeMapping.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.AttributeMapping - ( AttributeMapping(..) - ) where +module Rattletrap.Type.AttributeMapping where import Rattletrap.Type.Common import Rattletrap.Type.Word32le +import qualified Data.Binary as Binary + data AttributeMapping = AttributeMapping { attributeMappingObjectId :: Word32le , attributeMappingStreamId :: Word32le @@ -14,3 +14,8 @@ data AttributeMapping = AttributeMapping deriving (Eq, Ord, Show) $(deriveJson ''AttributeMapping) + +putAttributeMapping :: AttributeMapping -> Binary.Put +putAttributeMapping attributeMapping = do + putWord32 (attributeMappingObjectId attributeMapping) + putWord32 (attributeMappingStreamId attributeMapping) diff --git a/src/lib/Rattletrap/Type/AttributeValue.hs b/src/lib/Rattletrap/Type/AttributeValue.hs index 0fbff349..3f9b0af5 100644 --- a/src/lib/Rattletrap/Type/AttributeValue.hs +++ b/src/lib/Rattletrap/Type/AttributeValue.hs @@ -1,8 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.AttributeValue - ( AttributeValue(..) - ) where +module Rattletrap.Type.AttributeValue where import Rattletrap.Type.AppliedDamageAttribute import Rattletrap.Type.BooleanAttribute @@ -43,6 +41,8 @@ import Rattletrap.Type.TitleAttribute import Rattletrap.Type.UniqueIdAttribute import Rattletrap.Type.WeldedInfoAttribute +import qualified Data.Binary.Bits.Put as BinaryBits + data AttributeValue = AttributeValueAppliedDamage AppliedDamageAttribute | AttributeValueBoolean BooleanAttribute @@ -84,3 +84,43 @@ data AttributeValue deriving (Eq, Ord, Show) $(deriveJson ''AttributeValue) + +putAttributeValue :: AttributeValue -> BinaryBits.BitPut () +putAttributeValue value = case value of + AttributeValueAppliedDamage x -> putAppliedDamageAttribute x + AttributeValueBoolean x -> putBooleanAttribute x + AttributeValueByte x -> putByteAttribute x + AttributeValueCamSettings x -> putCamSettingsAttribute x + AttributeValueClubColors x -> putClubColorsAttribute x + AttributeValueCustomDemolish x -> putCustomDemolishAttribute x + AttributeValueDamageState x -> putDamageStateAttribute x + AttributeValueDemolish x -> putDemolishAttribute x + AttributeValueEnum x -> putEnumAttribute x + AttributeValueExplosion x -> putExplosionAttribute x + AttributeValueExtendedExplosion x -> putExtendedExplosionAttribute x + AttributeValueFlaggedInt x -> putFlaggedIntAttribute x + AttributeValueFlaggedByte x -> putFlaggedByteAttribute x + AttributeValueFloat x -> putFloatAttribute x + AttributeValueGameMode x -> putGameModeAttribute x + AttributeValueInt x -> putIntAttribute x + AttributeValueInt64 x -> putInt64Attribute x + AttributeValueLoadout x -> putLoadoutAttribute x + AttributeValueLoadoutOnline x -> putLoadoutOnlineAttribute x + AttributeValueLoadouts x -> putLoadoutsAttribute x + AttributeValueLoadoutsOnline x -> putLoadoutsOnlineAttribute x + AttributeValueLocation x -> putLocationAttribute x + AttributeValueMusicStinger x -> putMusicStingerAttribute x + AttributeValuePartyLeader x -> putPartyLeaderAttribute x + AttributeValuePickup x -> putPickupAttribute x + AttributeValuePickupNew x -> putPickupAttributeNew x + AttributeValuePlayerHistoryKey x -> putPlayerHistoryKeyAttribute x + AttributeValuePrivateMatchSettings x -> putPrivateMatchSettingsAttribute x + AttributeValueQWord x -> putQWordAttribute x + AttributeValueReservation x -> putReservationAttribute x + AttributeValueRigidBodyState x -> putRigidBodyStateAttribute x + AttributeValueStatEvent x -> putStatEventAttribute x + AttributeValueString x -> putStringAttribute x + AttributeValueTeamPaint x -> putTeamPaintAttribute x + AttributeValueTitle x -> putTitleAttribute x + AttributeValueUniqueId x -> putUniqueIdAttribute x + AttributeValueWeldedInfo x -> putWeldedInfoAttribute x diff --git a/src/lib/Rattletrap/Type/BooleanAttribute.hs b/src/lib/Rattletrap/Type/BooleanAttribute.hs index d3e94f54..fcb6589b 100644 --- a/src/lib/Rattletrap/Type/BooleanAttribute.hs +++ b/src/lib/Rattletrap/Type/BooleanAttribute.hs @@ -1,13 +1,17 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.BooleanAttribute - ( BooleanAttribute(..) - ) where +module Rattletrap.Type.BooleanAttribute where import Rattletrap.Type.Common +import qualified Data.Binary.Bits.Put as BinaryBits + newtype BooleanAttribute = BooleanAttribute { booleanAttributeValue :: Bool } deriving (Eq, Ord, Show) $(deriveJson ''BooleanAttribute) + +putBooleanAttribute :: BooleanAttribute -> BinaryBits.BitPut () +putBooleanAttribute booleanAttribute = + BinaryBits.putBool (booleanAttributeValue booleanAttribute) diff --git a/src/lib/Rattletrap/Type/ByteAttribute.hs b/src/lib/Rattletrap/Type/ByteAttribute.hs index bc5e0d74..f9b08dd5 100644 --- a/src/lib/Rattletrap/Type/ByteAttribute.hs +++ b/src/lib/Rattletrap/Type/ByteAttribute.hs @@ -1,14 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ByteAttribute - ( ByteAttribute(..) - ) where +module Rattletrap.Type.ByteAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + newtype ByteAttribute = ByteAttribute { byteAttributeValue :: Word8le } deriving (Eq, Ord, Show) $(deriveJson ''ByteAttribute) + +putByteAttribute :: ByteAttribute -> BinaryBits.BitPut () +putByteAttribute byteAttribute = + putWord8Bits (byteAttributeValue byteAttribute) diff --git a/src/lib/Rattletrap/Type/Cache.hs b/src/lib/Rattletrap/Type/Cache.hs index d1d2ce46..62ae90f7 100644 --- a/src/lib/Rattletrap/Type/Cache.hs +++ b/src/lib/Rattletrap/Type/Cache.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Cache - ( Cache(..) - ) where +module Rattletrap.Type.Cache where import Rattletrap.Type.AttributeMapping import Rattletrap.Type.Common import Rattletrap.Type.List import Rattletrap.Type.Word32le +import qualified Data.Binary as Binary + data Cache = Cache { cacheClassId :: Word32le , cacheParentCacheId :: Word32le @@ -18,3 +18,10 @@ data Cache = Cache deriving (Eq, Ord, Show) $(deriveJson ''Cache) + +putCache :: Cache -> Binary.Put +putCache cache = do + putWord32 (cacheClassId cache) + putWord32 (cacheParentCacheId cache) + putWord32 (cacheCacheId cache) + putList putAttributeMapping (cacheAttributeMappings cache) diff --git a/src/lib/Rattletrap/Type/CamSettingsAttribute.hs b/src/lib/Rattletrap/Type/CamSettingsAttribute.hs index cf09f8d9..2e88b863 100644 --- a/src/lib/Rattletrap/Type/CamSettingsAttribute.hs +++ b/src/lib/Rattletrap/Type/CamSettingsAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.CamSettingsAttribute - ( CamSettingsAttribute(..) - ) where +module Rattletrap.Type.CamSettingsAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Float32le +import qualified Data.Binary.Bits.Put as BinaryBits + data CamSettingsAttribute = CamSettingsAttribute { camSettingsAttributeFov :: Float32le , camSettingsAttributeHeight :: Float32le @@ -19,3 +19,15 @@ data CamSettingsAttribute = CamSettingsAttribute deriving (Eq, Ord, Show) $(deriveJson ''CamSettingsAttribute) + +putCamSettingsAttribute :: CamSettingsAttribute -> BinaryBits.BitPut () +putCamSettingsAttribute camSettingsAttribute = do + putFloat32Bits (camSettingsAttributeFov camSettingsAttribute) + putFloat32Bits (camSettingsAttributeHeight camSettingsAttribute) + putFloat32Bits (camSettingsAttributeAngle camSettingsAttribute) + putFloat32Bits (camSettingsAttributeDistance camSettingsAttribute) + putFloat32Bits (camSettingsAttributeStiffness camSettingsAttribute) + putFloat32Bits (camSettingsAttributeSwivelSpeed camSettingsAttribute) + case camSettingsAttributeTransitionSpeed camSettingsAttribute of + Nothing -> pure () + Just transitionSpeed -> putFloat32Bits transitionSpeed diff --git a/src/lib/Rattletrap/Type/ClassMapping.hs b/src/lib/Rattletrap/Type/ClassMapping.hs index 685f4d52..d07d83b4 100644 --- a/src/lib/Rattletrap/Type/ClassMapping.hs +++ b/src/lib/Rattletrap/Type/ClassMapping.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ClassMapping - ( ClassMapping(..) - ) where +module Rattletrap.Type.ClassMapping where import Rattletrap.Type.Common import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import qualified Data.Binary as Binary + data ClassMapping = ClassMapping { classMappingName :: Str , classMappingStreamId :: Word32le @@ -15,3 +15,8 @@ data ClassMapping = ClassMapping deriving (Eq, Ord, Show) $(deriveJson ''ClassMapping) + +putClassMapping :: ClassMapping -> Binary.Put +putClassMapping classMapping = do + putText (classMappingName classMapping) + putWord32 (classMappingStreamId classMapping) diff --git a/src/lib/Rattletrap/Type/ClubColorsAttribute.hs b/src/lib/Rattletrap/Type/ClubColorsAttribute.hs index 1d7b76c3..9d83c63e 100644 --- a/src/lib/Rattletrap/Type/ClubColorsAttribute.hs +++ b/src/lib/Rattletrap/Type/ClubColorsAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ClubColorsAttribute - ( ClubColorsAttribute(..) - ) where +module Rattletrap.Type.ClubColorsAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data ClubColorsAttribute = ClubColorsAttribute { clubColorsAttributeBlueFlag :: Bool , clubColorsAttributeBlueColor :: Word8le @@ -16,3 +16,10 @@ data ClubColorsAttribute = ClubColorsAttribute deriving (Eq, Ord, Show) $(deriveJson ''ClubColorsAttribute) + +putClubColorsAttribute :: ClubColorsAttribute -> BinaryBits.BitPut () +putClubColorsAttribute clubColorsAttribute = do + BinaryBits.putBool (clubColorsAttributeBlueFlag clubColorsAttribute) + putWord8Bits (clubColorsAttributeBlueColor clubColorsAttribute) + BinaryBits.putBool (clubColorsAttributeOrangeFlag clubColorsAttribute) + putWord8Bits (clubColorsAttributeOrangeColor clubColorsAttribute) diff --git a/src/lib/Rattletrap/Type/CompressedWord.hs b/src/lib/Rattletrap/Type/CompressedWord.hs index d9180409..750753c6 100644 --- a/src/lib/Rattletrap/Type/CompressedWord.hs +++ b/src/lib/Rattletrap/Type/CompressedWord.hs @@ -1,11 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.CompressedWord - ( CompressedWord(..) - ) where +module Rattletrap.Type.CompressedWord where import Rattletrap.Type.Common +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Bits as Bits + -- | Although there's no guarantee that these values will not overflow, it's -- exceptionally unlikely. Most 'CompressedWord's are very small. data CompressedWord = CompressedWord @@ -15,3 +16,38 @@ data CompressedWord = CompressedWord deriving (Eq, Ord, Show) $(deriveJson ''CompressedWord) + +putCompressedWord :: CompressedWord -> BinaryBits.BitPut () +putCompressedWord compressedWord = + let + limit = compressedWordLimit compressedWord + value = compressedWordValue compressedWord + maxBits = getMaxBits limit + in putCompressedWordStep limit value maxBits 0 0 + +putCompressedWordStep + :: Word -> Word -> Int -> Int -> Word -> BinaryBits.BitPut () +putCompressedWordStep limit value maxBits position soFar = + if position < maxBits + then do + let x = Bits.shiftL 1 position :: Word + if maxBits > 1 && position == maxBits - 1 && soFar + x > limit + then pure () + else do + let bit = Bits.testBit value position + BinaryBits.putBool bit + let delta = if bit then x else 0 + putCompressedWordStep + limit + value + maxBits + (position + 1) + (soFar + delta) + else pure () + +getMaxBits :: Word -> Int +getMaxBits x = + let + n :: Int + n = max 1 (ceiling (logBase (2 :: Double) (fromIntegral (max 1 x)))) + in if x < 1024 && x == 2 ^ n then n + 1 else n diff --git a/src/lib/Rattletrap/Type/CompressedWordVector.hs b/src/lib/Rattletrap/Type/CompressedWordVector.hs index cc3a4cb5..d8ac0b9f 100644 --- a/src/lib/Rattletrap/Type/CompressedWordVector.hs +++ b/src/lib/Rattletrap/Type/CompressedWordVector.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.CompressedWordVector - ( CompressedWordVector(..) - ) where +module Rattletrap.Type.CompressedWordVector where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord +import qualified Data.Binary.Bits.Put as BinaryBits + data CompressedWordVector = CompressedWordVector { compressedWordVectorX :: CompressedWord , compressedWordVectorY :: CompressedWord @@ -15,3 +15,9 @@ data CompressedWordVector = CompressedWordVector deriving (Eq, Ord, Show) $(deriveJson ''CompressedWordVector) + +putCompressedWordVector :: CompressedWordVector -> BinaryBits.BitPut () +putCompressedWordVector compressedWordVector = do + putCompressedWord (compressedWordVectorX compressedWordVector) + putCompressedWord (compressedWordVectorY compressedWordVector) + putCompressedWord (compressedWordVectorZ compressedWordVector) diff --git a/src/lib/Rattletrap/Type/Content.hs b/src/lib/Rattletrap/Type/Content.hs index 2d1e13e8..b8442d75 100644 --- a/src/lib/Rattletrap/Type/Content.hs +++ b/src/lib/Rattletrap/Type/Content.hs @@ -1,9 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Content - ( Content(..) - , defaultContent - ) where +module Rattletrap.Type.Content where import Rattletrap.Type.Cache import Rattletrap.Type.ClassMapping @@ -15,6 +12,13 @@ import Rattletrap.Type.Mark import Rattletrap.Type.Message import Rattletrap.Type.Str import Rattletrap.Type.Word32le +import Rattletrap.Utility.Bytes + +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString as Bytes +import qualified Data.ByteString.Lazy as LazyBytes -- | Contains low-level game data about a 'Rattletrap.Replay.Replay'. data Content = Content @@ -69,3 +73,38 @@ defaultContent = Content , contentCaches = List [] , contentUnknown = [] } + +putContent :: Content -> Binary.Put +putContent content = do + putList putText (contentLevels content) + putList putKeyFrame (contentKeyFrames content) + let + stream = LazyBytes.toStrict + (Binary.runPut (BinaryBits.runBitPut (putFrames (contentFrames content))) + ) + -- This is a little strange. When parsing a binary replay, the stream size + -- is given before the stream itself. When generating the JSON, the stream + -- size is included. That allows a bit-for-bit identical binary replay to + -- be generated from the JSON. However if you modify the JSON before + -- converting it back into binary, the stream size might be different. + -- + -- If it was possible to know how much padding the stream required without + -- carrying it along as extra data on the side, this logic could go away. + -- Unforunately that isn't currently known. See this issue for details: + -- . + expectedStreamSize = contentStreamSize content + actualStreamSize = Word32le . fromIntegral $ Bytes.length stream + streamSize = Word32le $ max + (word32leValue expectedStreamSize) + (word32leValue actualStreamSize) + putWord32 streamSize + Binary.putByteString + (reverseBytes (padBytes (word32leValue streamSize) stream)) + putList putMessage (contentMessages content) + putList putMark (contentMarks content) + putList putText (contentPackages content) + putList putText (contentObjects content) + putList putText (contentNames content) + putList putClassMapping (contentClassMappings content) + putList putCache (contentCaches content) + mapM_ Binary.putWord8 (contentUnknown content) diff --git a/src/lib/Rattletrap/Type/CustomDemolishAttribute.hs b/src/lib/Rattletrap/Type/CustomDemolishAttribute.hs index 17b93e91..100e8ac6 100644 --- a/src/lib/Rattletrap/Type/CustomDemolishAttribute.hs +++ b/src/lib/Rattletrap/Type/CustomDemolishAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.CustomDemolishAttribute - ( CustomDemolishAttribute(..) - ) where +module Rattletrap.Type.CustomDemolishAttribute where import Rattletrap.Type.Common import Rattletrap.Type.DemolishAttribute import Rattletrap.Type.Int32le +import qualified Data.Binary.Bits.Put as BinaryBits + data CustomDemolishAttribute = CustomDemolishAttribute { customDemolishAttributeFlag :: Bool , customDemolishAttributeId :: Int32le @@ -16,3 +16,9 @@ data CustomDemolishAttribute = CustomDemolishAttribute deriving (Eq, Ord, Show) $(deriveJson ''CustomDemolishAttribute) + +putCustomDemolishAttribute :: CustomDemolishAttribute -> BinaryBits.BitPut () +putCustomDemolishAttribute x = do + BinaryBits.putBool (customDemolishAttributeFlag x) + putInt32Bits (customDemolishAttributeId x) + putDemolishAttribute (customDemolishAttributeDemolish x) diff --git a/src/lib/Rattletrap/Type/DamageStateAttribute.hs b/src/lib/Rattletrap/Type/DamageStateAttribute.hs index eb30ace9..f1c0d381 100644 --- a/src/lib/Rattletrap/Type/DamageStateAttribute.hs +++ b/src/lib/Rattletrap/Type/DamageStateAttribute.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.DamageStateAttribute - ( DamageStateAttribute(..) - ) where +module Rattletrap.Type.DamageStateAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Int32le import Rattletrap.Type.Vector import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data DamageStateAttribute = DamageStateAttribute { damageStateAttributeUnknown1 :: Word8le , damageStateAttributeUnknown2 :: Bool @@ -20,3 +20,12 @@ data DamageStateAttribute = DamageStateAttribute deriving (Eq, Ord, Show) $(deriveJson ''DamageStateAttribute) + +putDamageStateAttribute :: DamageStateAttribute -> BinaryBits.BitPut () +putDamageStateAttribute damageStateAttribute = do + putWord8Bits (damageStateAttributeUnknown1 damageStateAttribute) + BinaryBits.putBool (damageStateAttributeUnknown2 damageStateAttribute) + putInt32Bits (damageStateAttributeUnknown3 damageStateAttribute) + putVector (damageStateAttributeUnknown4 damageStateAttribute) + BinaryBits.putBool (damageStateAttributeUnknown5 damageStateAttribute) + BinaryBits.putBool (damageStateAttributeUnknown6 damageStateAttribute) diff --git a/src/lib/Rattletrap/Type/DemolishAttribute.hs b/src/lib/Rattletrap/Type/DemolishAttribute.hs index e9094ee7..540783ba 100644 --- a/src/lib/Rattletrap/Type/DemolishAttribute.hs +++ b/src/lib/Rattletrap/Type/DemolishAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.DemolishAttribute - ( DemolishAttribute(..) - ) where +module Rattletrap.Type.DemolishAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Vector import Rattletrap.Type.Word32le +import qualified Data.Binary.Bits.Put as BinaryBits + data DemolishAttribute = DemolishAttribute { demolishAttributeAttackerFlag :: Bool , demolishAttributeAttackerActorId :: Word32le @@ -19,3 +19,12 @@ data DemolishAttribute = DemolishAttribute deriving (Eq, Ord, Show) $(deriveJson ''DemolishAttribute) + +putDemolishAttribute :: DemolishAttribute -> BinaryBits.BitPut () +putDemolishAttribute demolishAttribute = do + BinaryBits.putBool (demolishAttributeAttackerFlag demolishAttribute) + putWord32Bits (demolishAttributeAttackerActorId demolishAttribute) + BinaryBits.putBool (demolishAttributeVictimFlag demolishAttribute) + putWord32Bits (demolishAttributeVictimActorId demolishAttribute) + putVector (demolishAttributeAttackerVelocity demolishAttribute) + putVector (demolishAttributeVictimVelocity demolishAttribute) diff --git a/src/lib/Rattletrap/Type/DestroyedReplication.hs b/src/lib/Rattletrap/Type/DestroyedReplication.hs index 52c79ac7..af8c0b5c 100644 --- a/src/lib/Rattletrap/Type/DestroyedReplication.hs +++ b/src/lib/Rattletrap/Type/DestroyedReplication.hs @@ -1,11 +1,11 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.DestroyedReplication - ( DestroyedReplication(..) - ) where +module Rattletrap.Type.DestroyedReplication where import Rattletrap.Type.Common +import qualified Data.Binary.Bits.Put as BinaryBits + -- | Destroyed replications don't actually contain any extra information. All -- you need to know is the actor's ID, which is given by the -- 'Rattletrap.Replication.Replication'. @@ -13,3 +13,6 @@ data DestroyedReplication = DestroyedReplication deriving (Eq, Ord, Show) $(deriveJson ''DestroyedReplication) + +putDestroyedReplication :: DestroyedReplication -> BinaryBits.BitPut () +putDestroyedReplication _ = pure () diff --git a/src/lib/Rattletrap/Type/Dictionary.hs b/src/lib/Rattletrap/Type/Dictionary.hs index 2f0d90ae..2cfbb43b 100644 --- a/src/lib/Rattletrap/Type/Dictionary.hs +++ b/src/lib/Rattletrap/Type/Dictionary.hs @@ -1,11 +1,9 @@ -module Rattletrap.Type.Dictionary - ( Dictionary(..) - , dictionaryLookup - ) where +module Rattletrap.Type.Dictionary where import Rattletrap.Type.Common import Rattletrap.Type.Str +import qualified Data.Binary as Binary import qualified Control.Monad as Monad import qualified Data.Aeson as Json import qualified Data.Aeson.Types as Json @@ -66,3 +64,11 @@ toList :: Dictionary a -> [(Str, a)] toList x = case x of DictionaryElement k v y -> (k, v) : toList y DictionaryEnd _ -> [] + +putDictionary :: (a -> Binary.Put) -> Dictionary a -> Binary.Put +putDictionary f x = case x of + DictionaryElement k v y -> do + putText k + f v + putDictionary f y + DictionaryEnd y -> putText y diff --git a/src/lib/Rattletrap/Type/EnumAttribute.hs b/src/lib/Rattletrap/Type/EnumAttribute.hs index 587654c0..d2430549 100644 --- a/src/lib/Rattletrap/Type/EnumAttribute.hs +++ b/src/lib/Rattletrap/Type/EnumAttribute.hs @@ -1,13 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.EnumAttribute - ( EnumAttribute(..) - ) where +module Rattletrap.Type.EnumAttribute where import Rattletrap.Type.Common +import Rattletrap.Encode.Common + +import qualified Data.Binary.Bits.Put as BinaryBits newtype EnumAttribute = EnumAttribute { enumAttributeValue :: Word16 } deriving (Eq, Ord, Show) $(deriveJson ''EnumAttribute) + +putEnumAttribute :: EnumAttribute -> BinaryBits.BitPut () +putEnumAttribute enumAttribute = + putBitsLE 11 (enumAttributeValue enumAttribute) diff --git a/src/lib/Rattletrap/Type/ExplosionAttribute.hs b/src/lib/Rattletrap/Type/ExplosionAttribute.hs index bc2c0ff8..eba3c0b6 100644 --- a/src/lib/Rattletrap/Type/ExplosionAttribute.hs +++ b/src/lib/Rattletrap/Type/ExplosionAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ExplosionAttribute - ( ExplosionAttribute(..) - ) where +module Rattletrap.Type.ExplosionAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Int32le import Rattletrap.Type.Vector +import qualified Data.Binary.Bits.Put as BinaryBits + data ExplosionAttribute = ExplosionAttribute { explosionAttributeFlag :: Bool , explosionAttributeActorId :: Int32le @@ -16,3 +16,9 @@ data ExplosionAttribute = ExplosionAttribute deriving (Eq, Ord, Show) $(deriveJson ''ExplosionAttribute) + +putExplosionAttribute :: ExplosionAttribute -> BinaryBits.BitPut () +putExplosionAttribute explosionAttribute = do + BinaryBits.putBool False + putInt32Bits (explosionAttributeActorId explosionAttribute) + putVector (explosionAttributeLocation explosionAttribute) diff --git a/src/lib/Rattletrap/Type/ExtendedExplosionAttribute.hs b/src/lib/Rattletrap/Type/ExtendedExplosionAttribute.hs index fb3d6aa4..33bf08da 100644 --- a/src/lib/Rattletrap/Type/ExtendedExplosionAttribute.hs +++ b/src/lib/Rattletrap/Type/ExtendedExplosionAttribute.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.ExtendedExplosionAttribute - ( ExtendedExplosionAttribute(..) - ) where +module Rattletrap.Type.ExtendedExplosionAttribute where import Rattletrap.Type.Common import Rattletrap.Type.ExplosionAttribute import Rattletrap.Type.FlaggedIntAttribute +import qualified Data.Binary.Bits.Put as BinaryBits + data ExtendedExplosionAttribute = ExtendedExplosionAttribute { extendedExplosionAttributeExplosion :: ExplosionAttribute , extendedExplosionAttributeUnknown :: FlaggedIntAttribute @@ -15,3 +15,9 @@ data ExtendedExplosionAttribute = ExtendedExplosionAttribute deriving (Eq, Ord, Show) $(deriveJson ''ExtendedExplosionAttribute) + +putExtendedExplosionAttribute + :: ExtendedExplosionAttribute -> BinaryBits.BitPut () +putExtendedExplosionAttribute x = do + putExplosionAttribute (extendedExplosionAttributeExplosion x) + putFlaggedIntAttribute (extendedExplosionAttributeUnknown x) diff --git a/src/lib/Rattletrap/Type/FlaggedByteAttribute.hs b/src/lib/Rattletrap/Type/FlaggedByteAttribute.hs index b420c5de..74a5f067 100644 --- a/src/lib/Rattletrap/Type/FlaggedByteAttribute.hs +++ b/src/lib/Rattletrap/Type/FlaggedByteAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.FlaggedByteAttribute - ( FlaggedByteAttribute(..) - ) where +module Rattletrap.Type.FlaggedByteAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Word8le +import qualified Data.Binary.Bits.Put as BinaryBits + data FlaggedByteAttribute = FlaggedByteAttribute { flaggedByteAttributeFlag :: Bool , flaggedByteAttributeByte :: Word8le @@ -14,3 +14,8 @@ data FlaggedByteAttribute = FlaggedByteAttribute deriving (Eq, Ord, Show) $(deriveJson ''FlaggedByteAttribute) + +putFlaggedByteAttribute :: FlaggedByteAttribute -> BinaryBits.BitPut () +putFlaggedByteAttribute flaggedByteAttribute = do + BinaryBits.putBool (flaggedByteAttributeFlag flaggedByteAttribute) + putWord8Bits (flaggedByteAttributeByte flaggedByteAttribute) diff --git a/src/lib/Rattletrap/Type/FlaggedIntAttribute.hs b/src/lib/Rattletrap/Type/FlaggedIntAttribute.hs index 2f5316c1..b06f473f 100644 --- a/src/lib/Rattletrap/Type/FlaggedIntAttribute.hs +++ b/src/lib/Rattletrap/Type/FlaggedIntAttribute.hs @@ -1,12 +1,12 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.FlaggedIntAttribute - ( FlaggedIntAttribute(..) - ) where +module Rattletrap.Type.FlaggedIntAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Int32le +import qualified Data.Binary.Bits.Put as BinaryBits + data FlaggedIntAttribute = FlaggedIntAttribute { flaggedIntAttributeFlag :: Bool , flaggedIntAttributeInt :: Int32le @@ -14,3 +14,8 @@ data FlaggedIntAttribute = FlaggedIntAttribute deriving (Eq, Ord, Show) $(deriveJson ''FlaggedIntAttribute) + +putFlaggedIntAttribute :: FlaggedIntAttribute -> BinaryBits.BitPut () +putFlaggedIntAttribute flaggedIntAttribute = do + BinaryBits.putBool (flaggedIntAttributeFlag flaggedIntAttribute) + putInt32Bits (flaggedIntAttributeInt flaggedIntAttribute) diff --git a/src/lib/Rattletrap/Type/Float32le.hs b/src/lib/Rattletrap/Type/Float32le.hs index 569cb248..68461d30 100644 --- a/src/lib/Rattletrap/Type/Float32le.hs +++ b/src/lib/Rattletrap/Type/Float32le.hs @@ -1,13 +1,25 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Float32le - ( Float32le(..) - ) where +module Rattletrap.Type.Float32le where import Rattletrap.Type.Common +import Rattletrap.Utility.Bytes + +import qualified Data.Binary as Binary +import qualified Data.Binary.Bits.Put as BinaryBits +import qualified Data.Binary.Put as Binary +import qualified Data.ByteString.Lazy as LazyBytes newtype Float32le = Float32le { float32leValue :: Float } deriving (Eq, Ord, Show) $(deriveJson ''Float32le) + +putFloat32 :: Float32le -> Binary.Put +putFloat32 = Binary.putFloatle . float32leValue + +putFloat32Bits :: Float32le -> BinaryBits.BitPut () +putFloat32Bits float32 = do + let bytes = LazyBytes.toStrict (Binary.runPut (putFloat32 float32)) + BinaryBits.putByteString (reverseBytes bytes) diff --git a/src/lib/Rattletrap/Type/FloatAttribute.hs b/src/lib/Rattletrap/Type/FloatAttribute.hs index b7d96637..95bdee63 100644 --- a/src/lib/Rattletrap/Type/FloatAttribute.hs +++ b/src/lib/Rattletrap/Type/FloatAttribute.hs @@ -1,14 +1,18 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.FloatAttribute - ( FloatAttribute(..) - ) where +module Rattletrap.Type.FloatAttribute where import Rattletrap.Type.Common import Rattletrap.Type.Float32le +import qualified Data.Binary.Bits.Put as BinaryBits + newtype FloatAttribute = FloatAttribute { floatAttributeValue :: Float32le } deriving (Eq, Ord, Show) $(deriveJson ''FloatAttribute) + +putFloatAttribute :: FloatAttribute -> BinaryBits.BitPut () +putFloatAttribute floatAttribute = + putFloat32Bits (floatAttributeValue floatAttribute) diff --git a/src/lib/Rattletrap/Type/Frame.hs b/src/lib/Rattletrap/Type/Frame.hs index 29ca5ecc..2efa2a10 100644 --- a/src/lib/Rattletrap/Type/Frame.hs +++ b/src/lib/Rattletrap/Type/Frame.hs @@ -1,13 +1,13 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.Frame - ( Frame(..) - ) where +module Rattletrap.Type.Frame where import Rattletrap.Type.Common import Rattletrap.Type.Float32le import Rattletrap.Type.Replication +import qualified Data.Binary.Bits.Put as BinaryBits + data Frame = Frame { frameTime :: Float32le -- ^ Time in seconds since the beginning of the match. @@ -19,3 +19,17 @@ data Frame = Frame deriving (Eq, Ord, Show) $(deriveJson ''Frame) + +putFrames :: [Frame] -> BinaryBits.BitPut () +putFrames frames = case frames of + [] -> pure () + [frame] -> putFrame frame + first : rest -> do + putFrame first + putFrames rest + +putFrame :: Frame -> BinaryBits.BitPut () +putFrame frame = do + putFloat32Bits (frameTime frame) + putFloat32Bits (frameDelta frame) + putReplications (frameReplications frame) diff --git a/src/lib/Rattletrap/Type/GameModeAttribute.hs b/src/lib/Rattletrap/Type/GameModeAttribute.hs index 74c37c18..2fe92690 100644 --- a/src/lib/Rattletrap/Type/GameModeAttribute.hs +++ b/src/lib/Rattletrap/Type/GameModeAttribute.hs @@ -1,11 +1,11 @@ {-# LANGUAGE TemplateHaskell #-} -module Rattletrap.Type.GameModeAttribute - ( GameModeAttribute(..) - ) where +module Rattletrap.Type.GameModeAttribute where import Rattletrap.Type.Common +import qualified Data.Binary.Bits.Put as BinaryBits + data GameModeAttribute = GameModeAttribute { gameModeAttributeNumBits :: Int -- ^ This field is guaranteed to be small. In other words, it won't overflow. @@ -17,3 +17,9 @@ data GameModeAttribute = GameModeAttribute deriving (Eq, Ord, Show) $(deriveJson ''GameModeAttribute) + +putGameModeAttribute :: GameModeAttribute -> BinaryBits.BitPut () +putGameModeAttribute gameModeAttribute = do + let numBits = gameModeAttributeNumBits gameModeAttribute + let word = gameModeAttributeWord gameModeAttribute + BinaryBits.putWord8 numBits word diff --git a/src/lib/Rattletrap/Type/Header.hs b/src/lib/Rattletrap/Type/Header.hs index 919366b2..d9359191 100644 --- a/src/lib/Rattletrap/Type/Header.hs +++ b/src/lib/Rattletrap/Type/Header.hs @@ -7,7 +7,6 @@ import Rattletrap.Type.Dictionary import Rattletrap.Type.Property import Rattletrap.Type.Str import Rattletrap.Type.Word32le -import Rattletrap.Encode.Dictionary import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Type/KeyFrame.hs b/src/lib/Rattletrap/Type/KeyFrame.hs index 4399f43b..63d06e9d 100644 --- a/src/lib/Rattletrap/Type/KeyFrame.hs +++ b/src/lib/Rattletrap/Type/KeyFrame.hs @@ -5,7 +5,6 @@ module Rattletrap.Type.KeyFrame where import Rattletrap.Type.Common import Rattletrap.Type.Float32le import Rattletrap.Type.Word32le -import Rattletrap.Encode.Float32le import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Type/ProductAttribute.hs b/src/lib/Rattletrap/Type/ProductAttribute.hs index 6df0ec3b..eea86a2c 100644 --- a/src/lib/Rattletrap/Type/ProductAttribute.hs +++ b/src/lib/Rattletrap/Type/ProductAttribute.hs @@ -7,7 +7,6 @@ import Rattletrap.Type.CompressedWord import Rattletrap.Type.Str import Rattletrap.Type.Word32le import Rattletrap.Encode.Common -import Rattletrap.Encode.CompressedWord import Rattletrap.Type.Word8le import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Type/PropertyValue.hs b/src/lib/Rattletrap/Type/PropertyValue.hs index 084aff6d..56b93979 100644 --- a/src/lib/Rattletrap/Type/PropertyValue.hs +++ b/src/lib/Rattletrap/Type/PropertyValue.hs @@ -10,8 +10,6 @@ import Rattletrap.Type.List import Rattletrap.Type.Str import Rattletrap.Type.Word64le import Rattletrap.Type.Word8le -import Rattletrap.Encode.Dictionary -import Rattletrap.Encode.Float32le import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Type/Quaternion.hs b/src/lib/Rattletrap/Type/Quaternion.hs index 2be62986..dce0eb72 100644 --- a/src/lib/Rattletrap/Type/Quaternion.hs +++ b/src/lib/Rattletrap/Type/Quaternion.hs @@ -4,7 +4,6 @@ module Rattletrap.Type.Quaternion where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord -import Rattletrap.Encode.CompressedWord import qualified Data.Binary.Bits.Put as BinaryBits import qualified Data.List as List diff --git a/src/lib/Rattletrap/Type/Replay.hs b/src/lib/Rattletrap/Type/Replay.hs index 9b757cde..beadd4eb 100644 --- a/src/lib/Rattletrap/Type/Replay.hs +++ b/src/lib/Rattletrap/Type/Replay.hs @@ -6,7 +6,6 @@ import Rattletrap.Type.Common import Rattletrap.Type.Content import Rattletrap.Type.Header import Rattletrap.Type.Section -import Rattletrap.Encode.Content import qualified Data.Binary as Binary diff --git a/src/lib/Rattletrap/Type/Replication.hs b/src/lib/Rattletrap/Type/Replication.hs index f0dc97cd..4a9bdf78 100644 --- a/src/lib/Rattletrap/Type/Replication.hs +++ b/src/lib/Rattletrap/Type/Replication.hs @@ -5,7 +5,6 @@ module Rattletrap.Type.Replication where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord import Rattletrap.Type.ReplicationValue -import Rattletrap.Encode.CompressedWord import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Type/ReplicationValue.hs b/src/lib/Rattletrap/Type/ReplicationValue.hs index dace2122..f58af442 100644 --- a/src/lib/Rattletrap/Type/ReplicationValue.hs +++ b/src/lib/Rattletrap/Type/ReplicationValue.hs @@ -6,7 +6,6 @@ import Rattletrap.Type.Common import Rattletrap.Type.DestroyedReplication import Rattletrap.Type.SpawnedReplication import Rattletrap.Type.UpdatedReplication -import Rattletrap.Encode.DestroyedReplication import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Type/ReservationAttribute.hs b/src/lib/Rattletrap/Type/ReservationAttribute.hs index 47f3d521..c6cc0525 100644 --- a/src/lib/Rattletrap/Type/ReservationAttribute.hs +++ b/src/lib/Rattletrap/Type/ReservationAttribute.hs @@ -4,7 +4,6 @@ module Rattletrap.Type.ReservationAttribute where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord -import Rattletrap.Encode.CompressedWord import Rattletrap.Type.Str import Rattletrap.Type.UniqueIdAttribute diff --git a/src/lib/Rattletrap/Type/Rotation.hs b/src/lib/Rattletrap/Type/Rotation.hs index 818a4184..17f2b83e 100644 --- a/src/lib/Rattletrap/Type/Rotation.hs +++ b/src/lib/Rattletrap/Type/Rotation.hs @@ -5,7 +5,6 @@ module Rattletrap.Type.Rotation where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWordVector import Rattletrap.Type.Quaternion -import Rattletrap.Encode.CompressedWordVector import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Type/UpdatedReplication.hs b/src/lib/Rattletrap/Type/UpdatedReplication.hs index cfbda36c..f069c065 100644 --- a/src/lib/Rattletrap/Type/UpdatedReplication.hs +++ b/src/lib/Rattletrap/Type/UpdatedReplication.hs @@ -4,7 +4,6 @@ module Rattletrap.Type.UpdatedReplication where import Rattletrap.Type.Attribute import Rattletrap.Type.Common -import Rattletrap.Encode.Attribute import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Type/Vector.hs b/src/lib/Rattletrap/Type/Vector.hs index 37e911c6..e78d84b0 100644 --- a/src/lib/Rattletrap/Type/Vector.hs +++ b/src/lib/Rattletrap/Type/Vector.hs @@ -4,7 +4,6 @@ module Rattletrap.Type.Vector where import Rattletrap.Type.Common import Rattletrap.Type.CompressedWord -import Rattletrap.Encode.CompressedWord import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs b/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs index f96324a3..dba5f9b7 100644 --- a/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs +++ b/src/lib/Rattletrap/Type/WeldedInfoAttribute.hs @@ -7,7 +7,6 @@ import Rattletrap.Type.Float32le import Rattletrap.Type.Int32le import Rattletrap.Type.Int8Vector import Rattletrap.Type.Vector -import Rattletrap.Encode.Float32le import qualified Data.Binary.Bits.Put as BinaryBits diff --git a/src/lib/Rattletrap/Utility/Helper.hs b/src/lib/Rattletrap/Utility/Helper.hs index c3c41f71..c442ac40 100644 --- a/src/lib/Rattletrap/Utility/Helper.hs +++ b/src/lib/Rattletrap/Utility/Helper.hs @@ -9,7 +9,6 @@ module Rattletrap.Utility.Helper import Rattletrap.Decode.Common import Rattletrap.Decode.Replay -import Rattletrap.Encode.Content import Rattletrap.Type.Content import Rattletrap.Type.Replay import Rattletrap.Type.Section