Skip to content

Commit

Permalink
Merge pull request #118 from tfausak/gh-115-new-psy-net-id
Browse files Browse the repository at this point in the history
Handle new PsyNet IDs
  • Loading branch information
tfausak authored May 25, 2019
2 parents cf61dfb + abc1aba commit 5630bba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions library/Rattletrap/Decode/RemoteId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ import qualified Data.Text.Encoding as Text
import qualified Data.Word as Word

decodeRemoteIdBits :: (Int, Int, Int) -> Word8le -> DecodeBits RemoteId
decodeRemoteIdBits (_, _, patch) systemId = case word8leValue systemId of
decodeRemoteIdBits version systemId = case word8leValue systemId of
0 -> RemoteIdSplitscreen <$> getWord32be 24
1 -> RemoteIdSteam <$> decodeWord64leBits
2 -> RemoteIdPlayStation <$> decodePsName <*> decodePsBytes patch
2 -> RemoteIdPlayStation <$> decodePsName <*> decodePsBytes version
4 -> RemoteIdXbox <$> decodeWord64leBits
6 -> RemoteIdSwitch <$> decodeBitstreamBits 256
7 -> RemoteIdPsyNet <$> decodeBitstreamBits 256
7 -> RemoteIdPsyNet
<$> decodeBitstreamBits (if version >= (868, 24, 10) then 64 else 256)
_ -> fail ("unknown system id " <> show systemId)

decodePsName :: DecodeBits Text.Text
decodePsName = fmap
(Text.dropWhileEnd (== '\x00') . Text.decodeLatin1 . reverseBytes)
(getByteStringBits 16)

decodePsBytes :: Int -> DecodeBits [Word.Word8]
decodePsBytes patch =
Bytes.unpack <$> getByteStringBits (if patch >= 1 then 24 else 16)
decodePsBytes :: (Int, Int, Int) -> DecodeBits [Word.Word8]
decodePsBytes version = Bytes.unpack
<$> getByteStringBits (if version >= (868, 20, 1) then 24 else 16)
Binary file added replays/c23b.replay
Binary file not shown.
1 change: 1 addition & 0 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ replays =
, ("afb1", "patch 1.37")
, ("b9f9", "a party leader")
, ("c14f", "some mutators")
, ("c23b", "new psynet id")
, ("c837", "a spectator")
, ("cc4c", "after Starbase ARC")
, ("d044", "hoops mutators")
Expand Down

0 comments on commit 5630bba

Please sign in to comment.