diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/GameProtocol.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/GameProtocol.kt index 006d47f..bb442b7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/GameProtocol.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/GameProtocol.kt @@ -7,593 +7,592 @@ import de.fiereu.network.s2c import de.fiereu.openmmo.net.game.packets.* object GameProtocol : Protocol() { - override val compressed: Boolean = true + override val compressed: Boolean = true - init { - c2s(0x01u, JoinPacketCodec) - s2c(0x01u, JoinResponsePacketCodec) + init { + c2s(0x01u, JoinPacketCodec) + s2c(0x01u, JoinResponsePacketCodec) - c2s(0x02u, RequestCharactersPacketCodec) - s2c(0x02u, CharactersListPacketCodec) + c2s(0x02u, RequestCharactersPacketCodec) + s2c(0x02u, CharactersListPacketCodec) - c2s(0x03u, CreateCharacterPacketCodec) - s2c(0x03u, FriendRosterDeltaPacketCodec) + c2s(0x03u, CreateCharacterPacketCodec) + s2c(0x03u, FriendRosterDeltaPacketCodec) - c2s(0x04u, SelectCharacterPacketCodec) - s2c(0x04u, SelectedCharacterPacketCodec) + c2s(0x04u, SelectCharacterPacketCodec) + s2c(0x04u, SelectedCharacterPacketCodec) - c2s(0x05u, RequestPlayerPacketCodec) - s2c(0x05u, LoadEntityPacketCodec) + c2s(0x05u, RequestPlayerPacketCodec) + s2c(0x05u, LoadEntityPacketCodec) - c2s(0x06u, MovementPacketCodec) + c2s(0x06u, MovementPacketCodec) - c2s(0x07u, FaceDirectionPacketCodec) - s2c(0x07u, EntityFaceTurnPacketCodec) + c2s(0x07u, FaceDirectionPacketCodec) + s2c(0x07u, EntityFaceTurnPacketCodec) - c2s(0x08u, ChatMessageSendPacketCodec) - s2c(0x08u, EntityLeavePacketCodec) + c2s(0x08u, ChatMessageSendPacketCodec) + s2c(0x08u, EntityLeavePacketCodec) - bidi(0x09u, ChatMessagePacketCodec) + bidi(0x09u, ChatMessagePacketCodec) - c2s(0x0Au, BattleMoveUsePacketCodec) - s2c(0x0Au, WorldFlagTableResetPacketCodec) + c2s(0x0Au, BattleMoveUsePacketCodec) + s2c(0x0Au, WorldFlagTableResetPacketCodec) - c2s(0x0Bu, EvolutionPromptResponsePacketCodec) - s2c(0x0Bu, WorldFlagSetPacketCodec) + c2s(0x0Bu, EvolutionPromptResponsePacketCodec) + s2c(0x0Bu, WorldFlagSetPacketCodec) - c2s(0x0Cu, BattlePartySwitchPacketCodec) - s2c(0x0Cu, LocalCharacterDeltaPacketCodec) + c2s(0x0Cu, BattlePartySwitchPacketCodec) + s2c(0x0Cu, LocalCharacterDeltaPacketCodec) - bidi(0x0Du, DialogDataPacketCodec) + bidi(0x0Du, DialogDataPacketCodec) - bidi(0x0Eu, DialogStatePacketCodec) + bidi(0x0Eu, DialogStatePacketCodec) - c2s(0x0Fu, PokemonListAddPacketCodec) - s2c(0x0Fu, EntityPresencePacketCodec) + c2s(0x0Fu, PokemonListAddPacketCodec) + s2c(0x0Fu, EntityPresencePacketCodec) - bidi(0x10u, LoadMapPacketCodec) + bidi(0x10u, LoadMapPacketCodec) - c2s(0x11u, PartyMemberSelectPacketCodec) - s2c(0x11u, NpcUpdatePacketCodec) + c2s(0x11u, PartyMemberSelectPacketCodec) + s2c(0x11u, NpcUpdatePacketCodec) - bidi(0x12u, NpcSpawnPacketCodec) + bidi(0x12u, NpcSpawnPacketCodec) - bidi(0x13u, PokemonContainerPacketCodec) + bidi(0x13u, PokemonContainerPacketCodec) - c2s(0x14u, EntityActionRequestPacketCodec) - s2c(0x14u, SocialListEntryAddPacketCodec) + c2s(0x14u, EntityActionRequestPacketCodec) + s2c(0x14u, SocialListEntryAddPacketCodec) - c2s(0x15u, ChatLocalePreferencesPacketCodec) - s2c(0x15u, SocialListEntryRemovePacketCodec) + c2s(0x15u, ChatLocalePreferencesPacketCodec) + s2c(0x15u, SocialListEntryRemovePacketCodec) - c2s(0x16u, InGameChallengeResponsePacketCodec) - s2c(0x16u, BattleEntityDeltaPacketCodec) + c2s(0x16u, InGameChallengeResponsePacketCodec) + s2c(0x16u, BattleEntityDeltaPacketCodec) - c2s(0x17u, StorageBoxClosePacketCodec) - s2c(0x17u, SocialEntryFlagSetPacketCodec) + c2s(0x17u, StorageBoxClosePacketCodec) + s2c(0x17u, SocialEntryFlagSetPacketCodec) - c2s(0x18u, MonsterStatusConditionPacketCodec) - s2c(0x18u, SocialEntryPresencePacketCodec) + c2s(0x18u, MonsterStatusConditionPacketCodec) + s2c(0x18u, SocialEntryPresencePacketCodec) - c2s(0x19u, MonsterFormActionPacketCodec) - s2c(0x19u, SocialEntryRenamePacketCodec) + c2s(0x19u, MonsterFormActionPacketCodec) + s2c(0x19u, SocialEntryRenamePacketCodec) - s2c(0x1Au, EntityMovePpPacketCodec) + s2c(0x1Au, EntityMovePpPacketCodec) - bidi(0x1Bu, MapTransitionPacketCodec) + bidi(0x1Bu, MapTransitionPacketCodec) - c2s(0x1Cu, StorageBoxFilterPacketCodec) - s2c(0x1Cu, PokedexSpeciesResetPacketCodec) + c2s(0x1Cu, StorageBoxFilterPacketCodec) + s2c(0x1Cu, PokedexSpeciesResetPacketCodec) - c2s(0x1Du, PokemonFlagsUpdatePacketCodec) - s2c(0x1Du, PokedexSpeciesUnlockPacketCodec) + c2s(0x1Du, PokemonFlagsUpdatePacketCodec) + s2c(0x1Du, PokedexSpeciesUnlockPacketCodec) - s2c(0x1Eu, OverworldWeatherControlPacketCodec) + s2c(0x1Eu, OverworldWeatherControlPacketCodec) - s2c(0x1Fu, OverworldParticleSpawnPacketCodec) + s2c(0x1Fu, OverworldParticleSpawnPacketCodec) - c2s(0x20u, NullPacketCodec) - s2c(0x20u, TokenPayloadPacketCodec) + c2s(0x20u, NullPacketCodec) + s2c(0x20u, TokenPayloadPacketCodec) - c2s(0x21u, WarpTileInteractPacketCodec) - s2c(0x21u, DialogActionPacketCodec) + c2s(0x21u, WarpTileInteractPacketCodec) + s2c(0x21u, DialogActionPacketCodec) - bidi(0x22u, EntityInteractPacketCodec) + bidi(0x22u, EntityInteractPacketCodec) - c2s(0x23u, ExchangeItemRequestPacketCodec) - s2c(0x23u, EventOverlayStatePacketCodec) + c2s(0x23u, ExchangeItemRequestPacketCodec) + s2c(0x23u, EventOverlayStatePacketCodec) - c2s(0x24u, ShopSellRequestPacketCodec) - s2c(0x24u, NpcPanelTogglePacketCodec) + c2s(0x24u, ShopSellRequestPacketCodec) + s2c(0x24u, NpcPanelTogglePacketCodec) - bidi(0x25u, DialogChoicePacketCodec) + bidi(0x25u, DialogChoicePacketCodec) - bidi(0x26u, DialogOptionPacketCodec) + bidi(0x26u, DialogOptionPacketCodec) - c2s(0x27u, PlayerStopMovingPacketCodec) - s2c(0x27u, BattlePromptSwitchPacketCodec) + c2s(0x27u, PlayerStopMovingPacketCodec) + s2c(0x27u, BattlePromptSwitchPacketCodec) - c2s(0x28u, TypedBinaryDataPacketCodec) - s2c(0x28u, EntityInteractionFlagPacketCodec) + c2s(0x28u, TypedBinaryDataPacketCodec) + s2c(0x28u, EntityInteractionFlagPacketCodec) - c2s(0x29u, CustomizeCharacterAppearancePacketCodec) - s2c(0x29u, ShopPriceTablePacketCodec) + c2s(0x29u, CustomizeCharacterAppearancePacketCodec) + s2c(0x29u, ShopPriceTablePacketCodec) - c2s(0x2Au, TeamNameChangePacketCodec) - s2c(0x2Au, BattleStatusFlagPacketCodec) + c2s(0x2Au, TeamNameChangePacketCodec) + s2c(0x2Au, BattleStatusFlagPacketCodec) - c2s(0x2Bu, SetCharacterNamePacketCodec) - s2c(0x2Bu, FollowerAdvancePacketCodec) + c2s(0x2Bu, SetCharacterNamePacketCodec) + s2c(0x2Bu, FollowerAdvancePacketCodec) - c2s(0x2Cu, NpcDialogResponsePacketCodec) - s2c(0x2Cu, EntityTitleTagPacketCodec) + c2s(0x2Cu, NpcDialogResponsePacketCodec) + s2c(0x2Cu, EntityTitleTagPacketCodec) - c2s(0x2Du, EntityInteractRequestPacketCodec) - s2c(0x2Du, MapCellTilesetPacketCodec) + c2s(0x2Du, EntityInteractRequestPacketCodec) + s2c(0x2Du, MapCellTilesetPacketCodec) - c2s(0x2Eu, SendDirectMessagePacketCodec) - s2c(0x2Eu, EntityRenamePacketCodec) + c2s(0x2Eu, SendDirectMessagePacketCodec) + s2c(0x2Eu, EntityRenamePacketCodec) - c2s(0x2Fu, DialogResponsePacketCodec) - s2c(0x2Fu, WorldJoinConfirmPacketCodec) + c2s(0x2Fu, DialogResponsePacketCodec) + s2c(0x2Fu, WorldJoinConfirmPacketCodec) - c2s(0x30u, BattleActionPacketCodec) + c2s(0x30u, BattleActionPacketCodec) - s2c(0x31u, BattleBulkStatePacketCodec) + s2c(0x31u, BattleBulkStatePacketCodec) - c2s(0x32u, BattleActionSelectPacketCodec) - s2c(0x32u, BattleQueuedEventPacketCodec) + c2s(0x32u, BattleActionSelectPacketCodec) + s2c(0x32u, BattleQueuedEventPacketCodec) - c2s(0x33u, MapLoadedAckPacketCodec) - s2c(0x33u, BattleEntityMoveEventPacketCodec) + c2s(0x33u, MapLoadedAckPacketCodec) + s2c(0x33u, BattleEntityMoveEventPacketCodec) - c2s(0x34u, SpectateRequestPacketCodec) - s2c(0x34u, BattleSlotEventEnumPacketCodec) + c2s(0x34u, SpectateRequestPacketCodec) + s2c(0x34u, BattleSlotEventEnumPacketCodec) - c2s(0x35u, LeaveBattlePacketCodec) - s2c(0x35u, BattleSlotMoveEventPacketCodec) + c2s(0x35u, LeaveBattlePacketCodec) + s2c(0x35u, BattleSlotMoveEventPacketCodec) - c2s(0x36u, RequestNextBattleSequencePacketCodec) - s2c(0x36u, BattleSlotFlagEventPacketCodec) + c2s(0x36u, RequestNextBattleSequencePacketCodec) + s2c(0x36u, BattleSlotFlagEventPacketCodec) - c2s(0x37u, BattleSlotActionPacketCodec) - s2c(0x37u, BattleListEventPacketCodec) + c2s(0x37u, BattleSlotActionPacketCodec) + s2c(0x37u, BattleListEventPacketCodec) - c2s(0x38u, BattleSwitchSelectionsPacketCodec) - s2c(0x38u, BattleEntityActionEventPacketCodec) + c2s(0x38u, BattleSwitchSelectionsPacketCodec) + s2c(0x38u, BattleEntityActionEventPacketCodec) - c2s(0x39u, BattleUseItemPacketCodec) - s2c(0x39u, BattleLabeledMoveEventPacketCodec) + c2s(0x39u, BattleUseItemPacketCodec) + s2c(0x39u, BattleLabeledMoveEventPacketCodec) - c2s(0x3Au, SetBattleMonsterAppearancePacketCodec) - s2c(0x3Au, BattleEnumPairEventPacketCodec) + c2s(0x3Au, SetBattleMonsterAppearancePacketCodec) + s2c(0x3Au, BattleEnumPairEventPacketCodec) - c2s(0x3Bu, PrismaticPearlTransferPacketCodec) - s2c(0x3Bu, BattleEmptyEventPacketCodec) + c2s(0x3Bu, PrismaticPearlTransferPacketCodec) + s2c(0x3Bu, BattleEmptyEventPacketCodec) - c2s(0x3Cu, SetActiveMovesetPacketCodec) - s2c(0x3Cu, ServerChatTemplate5002PacketCodec) + c2s(0x3Cu, SetActiveMovesetPacketCodec) + s2c(0x3Cu, ServerChatTemplate5002PacketCodec) - c2s(0x3Du, BattleCancelRequestPacketCodec) - s2c(0x3Du, ServerChatTemplate5003PacketCodec) + c2s(0x3Du, BattleCancelRequestPacketCodec) + s2c(0x3Du, ServerChatTemplate5003PacketCodec) - s2c(0x3Eu, BattleSlotSwitchEventPacketCodec) + s2c(0x3Eu, BattleSlotSwitchEventPacketCodec) - c2s(0x3Fu, BattleSimulationRequestPacketCodec) - s2c(0x3Fu, BattleMoveDisableUpdatePacketCodec) + c2s(0x3Fu, BattleSimulationRequestPacketCodec) + s2c(0x3Fu, BattleMoveDisableUpdatePacketCodec) - c2s(0x40u, SubmitBreedingPartyPacketCodec) - s2c(0x40u, BattleSidePartyPacketCodec) + c2s(0x40u, SubmitBreedingPartyPacketCodec) + s2c(0x40u, BattleSidePartyPacketCodec) - c2s(0x41u, MonsterFavoriteTogglePacketCodec) - s2c(0x41u, BattlePokemonSpritePacketCodec) + c2s(0x41u, MonsterFavoriteTogglePacketCodec) + s2c(0x41u, BattlePokemonSpritePacketCodec) - c2s(0x42u, LeaveChatChannelPacketCodec) - s2c(0x42u, BattleSideAddPokemonPacketCodec) + c2s(0x42u, LeaveChatChannelPacketCodec) + s2c(0x42u, BattleSideAddPokemonPacketCodec) - c2s(0x43u, SetChatUserIgnoredPacketCodec) - s2c(0x43u, BattleSideRemovePokemonPacketCodec) + c2s(0x43u, SetChatUserIgnoredPacketCodec) + s2c(0x43u, BattleSideRemovePokemonPacketCodec) - c2s(0x44u, TournamentTeleportAcceptPacketCodec) - s2c(0x44u, BattlePokemonStatusPacketCodec) + c2s(0x44u, TournamentTeleportAcceptPacketCodec) + s2c(0x44u, BattlePokemonStatusPacketCodec) - c2s(0x45u, NpcDialogueChoicePacketCodec) - s2c(0x45u, WorldStateControlPacketCodec) + c2s(0x45u, NpcDialogueChoicePacketCodec) + s2c(0x45u, WorldStateControlPacketCodec) - c2s(0x46u, BattleReadyPacketCodec) - s2c(0x46u, BattleControlBytesPacketCodec) + c2s(0x46u, BattleReadyPacketCodec) + s2c(0x46u, BattleControlBytesPacketCodec) - c2s(0x47u, LeaveMatchmakingQueuePacketCodec) - s2c(0x47u, BattleScreenOpenPacketCodec) + c2s(0x47u, LeaveMatchmakingQueuePacketCodec) + s2c(0x47u, BattleScreenOpenPacketCodec) - c2s(0x48u, BattleActionSubmitPacketCodec) - s2c(0x48u, BattleActionResultPacketCodec) + c2s(0x48u, BattleActionSubmitPacketCodec) + s2c(0x48u, BattleActionResultPacketCodec) - c2s(0x49u, JoinMatchmakingQueuePacketCodec) - s2c(0x49u, BattleMoveSelectionCancelPacketCodec) + c2s(0x49u, JoinMatchmakingQueuePacketCodec) + s2c(0x49u, BattleMoveSelectionCancelPacketCodec) - c2s(0x4Au, BattleTierSelectPacketCodec) - s2c(0x4Au, BattleRatingBulkPacketCodec) + c2s(0x4Au, BattleTierSelectPacketCodec) + s2c(0x4Au, BattleRatingBulkPacketCodec) - c2s(0x4Bu, BattleChatMessagePacketCodec) - s2c(0x4Bu, BattleRatingUpdatePacketCodec) + c2s(0x4Bu, BattleChatMessagePacketCodec) + s2c(0x4Bu, BattleRatingUpdatePacketCodec) - c2s(0x4Cu, MatchmakingActionPacketCodec) - s2c(0x4Cu, BattleMoveTargetsPacketCodec) + c2s(0x4Cu, MatchmakingActionPacketCodec) + s2c(0x4Cu, BattleMoveTargetsPacketCodec) - c2s(0x4Du, MarketListingsRequestPacketCodec) - s2c(0x4Du, BattleStateBytePacketCodec) + c2s(0x4Du, MarketListingsRequestPacketCodec) + s2c(0x4Du, BattleStateBytePacketCodec) - s2c(0x4Eu, BattleMoveListPacketCodec) + s2c(0x4Eu, BattleMoveListPacketCodec) - c2s(0x4Fu, MarketSearchFilterPacketCodec) - s2c(0x4Fu, ChannelAssignmentsPacketCodec) + c2s(0x4Fu, MarketSearchFilterPacketCodec) + s2c(0x4Fu, ChannelAssignmentsPacketCodec) - c2s(0x50u, TradeActionPacketCodec) - s2c(0x50u, DuelInvitePacketCodec) + c2s(0x50u, TradeActionPacketCodec) + s2c(0x50u, DuelInvitePacketCodec) - c2s(0x51u, StringCommandPacketCodec) - s2c(0x51u, DuelInviteOutcomePacketCodec) + c2s(0x51u, StringCommandPacketCodec) + s2c(0x51u, DuelInviteOutcomePacketCodec) - c2s(0x52u, TradeSelectMonPacketCodec) - s2c(0x52u, TradeListEntryPacketCodec) + c2s(0x52u, TradeSelectMonPacketCodec) + s2c(0x52u, TradeListEntryPacketCodec) - c2s(0x53u, BattlePartySlotSelectPacketCodec) - s2c(0x53u, BattleStateSlotIntPacketCodec) + c2s(0x53u, BattlePartySlotSelectPacketCodec) + s2c(0x53u, BattleStateSlotIntPacketCodec) - s2c(0x54u, BattleBoardCellPacketCodec) + s2c(0x54u, BattleBoardCellPacketCodec) - s2c(0x55u, SpatialGroupSnapshotPacketCodec) + s2c(0x55u, SpatialGroupSnapshotPacketCodec) - s2c(0x56u, SpatialGroupInsertPacketCodec) + s2c(0x56u, SpatialGroupInsertPacketCodec) - s2c(0x57u, SpatialGroupDeletePacketCodec) + s2c(0x57u, SpatialGroupDeletePacketCodec) - s2c(0x58u, MenuVisibilityPacketCodec) + s2c(0x58u, MenuVisibilityPacketCodec) - s2c(0x59u, MenuPagePayloadPacketCodec) + s2c(0x59u, MenuPagePayloadPacketCodec) - s2c(0x5Au, EntityNameChoicesPacketCodec) + s2c(0x5Au, EntityNameChoicesPacketCodec) - s2c(0x5Bu, OptionListWindowPacketCodec) + s2c(0x5Bu, OptionListWindowPacketCodec) - s2c(0x5Cu, ListWindowPagePacketCodec) + s2c(0x5Cu, ListWindowPagePacketCodec) - s2c(0x5Du, MarketBoardPagePacketCodec) + s2c(0x5Du, MarketBoardPagePacketCodec) - s2c(0x5Eu, SceneObjectStatesPacketCodec) + s2c(0x5Eu, SceneObjectStatesPacketCodec) - s2c(0x5Fu, StorageInventoryPacketCodec) + s2c(0x5Fu, StorageInventoryPacketCodec) - c2s(0x60u, BlockPlayerPacketCodec) - s2c(0x60u, StorageContextWindowPacketCodec) + c2s(0x60u, BlockPlayerPacketCodec) + s2c(0x60u, StorageContextWindowPacketCodec) - c2s(0x61u, UnblockPlayerPacketCodec) - s2c(0x61u, EntityCoordSyncPacketCodec) + c2s(0x61u, UnblockPlayerPacketCodec) + s2c(0x61u, EntityCoordSyncPacketCodec) - c2s(0x62u, RemoveFriendPacketCodec) - s2c(0x62u, SocialActionOutcomePacketCodec) + c2s(0x62u, AddFriendPacketCodec) + s2c(0x62u, SocialActionOutcomePacketCodec) - c2s(0x63u, SetPlayerTitlePacketCodec) - s2c(0x63u, ContactRosterPacketCodec) + c2s(0x63u, RemoveFriendPacketCodec) + s2c(0x63u, FriendListPacketCodec) - c2s(0x64u, FriendProfileRequestPacketCodec) - s2c(0x64u, ContactInsertPacketCodec) + c2s(0x64u, FriendProfileRequestPacketCodec) + s2c(0x64u, ContactInsertPacketCodec) - s2c(0x65u, ContactDeletePacketCodec) + s2c(0x65u, ContactDeletePacketCodec) - s2c(0x66u, ContactOnlineStatePacketCodec) + s2c(0x66u, ContactOnlineStatePacketCodec) - s2c(0x67u, PartyRosterPacketCodec) + s2c(0x67u, PartyRosterPacketCodec) - s2c(0x68u, PartyMemberJoinPacketCodec) + s2c(0x68u, PartyMemberJoinPacketCodec) - s2c(0x69u, PartyMemberLeavePacketCodec) + s2c(0x69u, PartyMemberLeavePacketCodec) - c2s(0x6Au, InstanceReadyCheckPacketCodec) + c2s(0x6Au, InstanceReadyCheckPacketCodec) - c2s(0x6Bu, CancelMatchmakingSearchPacketCodec) - s2c(0x6Bu, ActiveBattleSidePacketCodec) + c2s(0x6Bu, CancelMatchmakingSearchPacketCodec) + s2c(0x6Bu, ActiveBattleSidePacketCodec) - c2s(0x6Cu, MatchmakingLanguagePrefsPacketCodec) - s2c(0x6Cu, MountMoveCooldownPacketCodec) + c2s(0x6Cu, MatchmakingLanguagePrefsPacketCodec) + s2c(0x6Cu, MountMoveCooldownPacketCodec) - s2c(0x6Du, ClientCookieUpdatePacketCodec) + s2c(0x6Du, ClientCookieUpdatePacketCodec) - s2c(0x6Eu, WorldToggleFlagsPacketCodec) + s2c(0x6Eu, WorldToggleFlagsPacketCodec) - s2c(0x6Fu, NamedCategoryEntriesPacketCodec) + s2c(0x6Fu, NamedCategoryEntriesPacketCodec) - c2s(0x70u, StorageBoxRequestPacketCodec) - s2c(0x70u, GtlMarketListingsPacketCodec) + c2s(0x70u, StorageBoxRequestPacketCodec) + s2c(0x70u, GtlMarketListingsPacketCodec) - c2s(0x71u, GtlPurchaseListingPacketCodec) - s2c(0x71u, MatchmakingRentalsPacketCodec) + c2s(0x71u, GtlPurchaseListingPacketCodec) + s2c(0x71u, MatchmakingRentalsPacketCodec) - s2c(0x72u, WorldStateValuePacketCodec) + s2c(0x72u, WorldStateValuePacketCodec) - c2s(0x73u, AssignBreedingSlotPacketCodec) - s2c(0x73u, BreedingForecastPacketCodec) + c2s(0x73u, AssignBreedingSlotPacketCodec) + s2c(0x73u, BreedingForecastPacketCodec) - c2s(0x74u, LeaderboardViewRequestPacketCodec) - s2c(0x74u, ServerNoticePacketCodec) + c2s(0x74u, LeaderboardViewRequestPacketCodec) + s2c(0x74u, ServerNoticePacketCodec) - c2s(0x75u, TourneyRegistrationPacketCodec) - s2c(0x75u, MatchmakingSideTeamPacketCodec) + c2s(0x75u, TourneyRegistrationPacketCodec) + s2c(0x75u, MatchmakingSideTeamPacketCodec) - c2s(0x76u, NpcInteractionChoicePacketCodec) - s2c(0x76u, ActivePokemonSummaryPacketCodec) + c2s(0x76u, NpcInteractionChoicePacketCodec) + s2c(0x76u, ActivePokemonSummaryPacketCodec) - c2s(0x77u, BattleTargetPickPacketCodec) - s2c(0x77u, StreamChunkPacketCodec) + c2s(0x77u, BattleTargetPickPacketCodec) + s2c(0x77u, StreamChunkPacketCodec) - s2c(0x78u, MatchmakingMemberProgressPacketCodec) + s2c(0x78u, MatchmakingMemberProgressPacketCodec) - c2s(0x79u, PcBoxStorePacketCodec) - s2c(0x79u, BattleStatCountersPacketCodec) + c2s(0x79u, PcBoxStorePacketCodec) + s2c(0x79u, BattleStatCountersPacketCodec) - c2s(0x7Au, PcBoxRenamePacketCodec) - s2c(0x7Au, LearnedMovesetPacketCodec) + c2s(0x7Au, PcBoxRenamePacketCodec) + s2c(0x7Au, LearnedMovesetPacketCodec) - c2s(0x7Bu, CoopScoreboardRequestPacketCodec) - s2c(0x7Bu, TournamentMatchupsPacketCodec) + c2s(0x7Bu, CoopScoreboardRequestPacketCodec) + s2c(0x7Bu, TournamentMatchupsPacketCodec) - c2s(0x7Cu, GtlListingSearchPacketCodec) - s2c(0x7Cu, GtlItemMarketPacketCodec) + c2s(0x7Cu, GtlListingSearchPacketCodec) + s2c(0x7Cu, GtlItemMarketPacketCodec) - s2c(0x7Du, GameShopCatalogPacketCodec) + s2c(0x7Du, GameShopCatalogPacketCodec) - s2c(0x7Eu, EggIncubatorSlotsPacketCodec) + s2c(0x7Eu, EggIncubatorSlotsPacketCodec) - s2c(0x7Fu, GtlPriceHistoryPacketCodec) + s2c(0x7Fu, GtlPriceHistoryPacketCodec) - c2s(0x80u, TeamFoundPacketCodec) - s2c(0x80u, GuildMembershipPacketCodec) + c2s(0x80u, TeamFoundPacketCodec) + s2c(0x80u, GuildMembershipPacketCodec) - c2s(0x81u, GuildMotdUpdatePacketCodec) - s2c(0x81u, GuildProfileSyncPacketCodec) + c2s(0x81u, GuildMotdUpdatePacketCodec) + s2c(0x81u, GuildProfileSyncPacketCodec) - c2s(0x82u, GuildDepartPacketCodec) + c2s(0x82u, GuildDepartPacketCodec) - c2s(0x83u, GuildChatSendPacketCodec) - s2c(0x83u, GuildRosterAddPacketCodec) + c2s(0x83u, GuildChatSendPacketCodec) + s2c(0x83u, GuildRosterAddPacketCodec) - c2s(0x84u, GuildMemberRankAssignPacketCodec) - s2c(0x84u, GuildMemberRankChangePacketCodec) + c2s(0x84u, GuildMemberRankAssignPacketCodec) + s2c(0x84u, GuildMemberRankChangePacketCodec) - c2s(0x85u, GuildMemberExpelPacketCodec) - s2c(0x85u, GuildRosterRemovePacketCodec) + c2s(0x85u, GuildMemberExpelPacketCodec) + s2c(0x85u, GuildRosterRemovePacketCodec) - c2s(0x86u, GuildRankPermissionUpdatePacketCodec) - s2c(0x86u, GuildMemberPresencePacketCodec) + c2s(0x86u, GuildRankPermissionUpdatePacketCodec) + s2c(0x86u, GuildMemberPresencePacketCodec) - c2s(0x87u, GuildDisbandToggleRequestPacketCodec) - s2c(0x87u, ContactCategoryGroupPacketCodec) + c2s(0x87u, GuildDisbandToggleRequestPacketCodec) + s2c(0x87u, ContactCategoryGroupPacketCodec) - c2s(0x88u, GuildRankLabelUpdatePacketCodec) - s2c(0x88u, GuildRosterBulkPacketCodec) + c2s(0x88u, GuildRankLabelUpdatePacketCodec) + s2c(0x88u, GuildRosterBulkPacketCodec) - c2s(0x89u, GuildActivityLogPageRequestPacketCodec) - s2c(0x89u, GuildActivityLogPacketCodec) + c2s(0x89u, GuildActivityLogPageRequestPacketCodec) + s2c(0x89u, GuildActivityLogPacketCodec) - c2s(0x8Au, MailAttachmentRequestPacketCodec) + c2s(0x8Au, MailAttachmentRequestPacketCodec) - s2c(0x8Bu, MonsterRecordBookPacketCodec) + s2c(0x8Bu, MonsterRecordBookPacketCodec) - s2c(0x8Cu, ChatChannelMessagesPacketCodec) + s2c(0x8Cu, ChatChannelMessagesPacketCodec) - s2c(0x8Du, ChatChannelUserListPacketCodec) + s2c(0x8Du, ChatChannelUserListPacketCodec) - s2c(0x8Eu, ChannelCountDeltaPacketCodec) + s2c(0x8Eu, ChannelCountDeltaPacketCodec) - s2c(0x8Fu, ChatMessageWithdrawPacketCodec) + s2c(0x8Fu, ChatMessageWithdrawPacketCodec) - c2s(0x90u, OverworldPathToTilePacketCodec) - s2c(0x90u, EntitySpriteChangePacketCodec) + c2s(0x90u, OverworldPathToTilePacketCodec) + s2c(0x90u, EntitySpriteChangePacketCodec) - c2s(0x91u, OverworldStepMovePacketCodec) - s2c(0x91u, OpenAppearanceEditorPacketCodec) + c2s(0x91u, OverworldStepMovePacketCodec) + s2c(0x91u, OpenAppearanceEditorPacketCodec) - c2s(0x92u, BattleTransitionReadyPacketCodec) - s2c(0x92u, AppearanceRequestResultPacketCodec) + c2s(0x92u, BattleTransitionReadyPacketCodec) + s2c(0x92u, AppearanceRequestResultPacketCodec) - c2s(0x93u, PendingRequestCancelPacketCodec) - s2c(0x93u, BattleStatStagePacketCodec) + c2s(0x93u, PendingRequestCancelPacketCodec) + s2c(0x93u, BattleStatStagePacketCodec) - c2s(0x94u, PartyInfoRequestPacketCodec) - s2c(0x94u, EntityAppearanceSyncPacketCodec) + c2s(0x94u, PartyInfoRequestPacketCodec) + s2c(0x94u, EntityAppearanceSyncPacketCodec) - c2s(0x95u, MailComposeSendPacketCodec) - s2c(0x95u, BattleSwitchPromptTogglePacketCodec) + c2s(0x95u, MailComposeSendPacketCodec) + s2c(0x95u, BattleSwitchPromptTogglePacketCodec) - c2s(0x96u, TeamPreviewRevealPickPacketCodec) - s2c(0x96u, BattleEndDisconnectPacketCodec) + c2s(0x96u, TeamPreviewRevealPickPacketCodec) + s2c(0x96u, BattleEndDisconnectPacketCodec) - c2s(0x97u, TeamPreviewSidePickPacketCodec) - s2c(0x97u, BattleTeamPreviewListPacketCodec) + c2s(0x97u, TeamPreviewSidePickPacketCodec) + s2c(0x97u, BattleTeamPreviewListPacketCodec) - c2s(0x98u, TeamPreviewLeadSubmitPacketCodec) - s2c(0x98u, WorldVersionPacketCodec) + c2s(0x98u, TeamPreviewLeadSubmitPacketCodec) + s2c(0x98u, WorldVersionPacketCodec) - c2s(0x99u, BattleTeamPreviewConfirmPacketCodec) - s2c(0x99u, BattleSendOutActivePacketCodec) + c2s(0x99u, BattleTeamPreviewConfirmPacketCodec) + s2c(0x99u, BattleSendOutActivePacketCodec) - c2s(0x9Au, CreateMarketListingPacketCodec) - s2c(0x9Au, BattleSlotAnimationResetPacketCodec) + c2s(0x9Au, CreateMarketListingPacketCodec) + s2c(0x9Au, BattleSlotAnimationResetPacketCodec) - c2s(0x9Bu, GtlSellPokemonListingPacketCodec) - s2c(0x9Bu, BattleActionOutcomePacketCodec) + c2s(0x9Bu, GtlSellPokemonListingPacketCodec) + s2c(0x9Bu, BattleActionOutcomePacketCodec) - c2s(0x9Cu, GtlConfirmPurchasePacketCodec) - s2c(0x9Cu, BattleDisconnectMessagePacketCodec) + c2s(0x9Cu, GtlConfirmPurchasePacketCodec) + s2c(0x9Cu, BattleDisconnectMessagePacketCodec) - c2s(0x9Du, SelectSinglePokemonPacketCodec) - s2c(0x9Du, BattleActionPromptTogglePacketCodec) + c2s(0x9Du, SelectSinglePokemonPacketCodec) + s2c(0x9Du, BattleActionPromptTogglePacketCodec) - c2s(0x9Eu, SelectPartyPokemonPacketCodec) - s2c(0x9Eu, EntityEmoteBubblePacketCodec) + c2s(0x9Eu, SelectPartyPokemonPacketCodec) + s2c(0x9Eu, EntityEmoteBubblePacketCodec) - c2s(0x9Fu, GtlTradeLogRequestPacketCodec) + c2s(0x9Fu, GtlTradeLogRequestPacketCodec) - c2s(0xA0u, PlayerChatInputPacketCodec) - s2c(0xA0u, FriendRosterPacketCodec) + c2s(0xA0u, PlayerChatInputPacketCodec) + s2c(0xA0u, FriendRosterPacketCodec) - c2s(0xA1u, GtlListingCancelPacketCodec) - s2c(0xA1u, GmPlayerLookupPacketCodec) + c2s(0xA1u, GtlListingCancelPacketCodec) + s2c(0xA1u, GmPlayerLookupPacketCodec) - c2s(0xA2u, AdminNoteActionPacketCodec) - s2c(0xA2u, GmPanelVariantPacketCodec) + c2s(0xA2u, AdminNoteActionPacketCodec) + s2c(0xA2u, GmPanelVariantPacketCodec) - c2s(0xA3u, GtlPurchasePacketCodec) - s2c(0xA3u, EntityNameVisibilityPacketCodec) + c2s(0xA3u, GtlPurchasePacketCodec) + s2c(0xA3u, EntityNameVisibilityPacketCodec) - c2s(0xA4u, GtlListingActionPacketCodec) - s2c(0xA4u, HighScoreBoardPacketCodec) + c2s(0xA4u, GtlListingActionPacketCodec) + s2c(0xA4u, HighScoreBoardPacketCodec) - c2s(0xA5u, GtlOpenSessionPacketCodec) - s2c(0xA5u, WorldNoticeSlotPacketCodec) + c2s(0xA5u, GtlOpenSessionPacketCodec) + s2c(0xA5u, WorldNoticeSlotPacketCodec) - c2s(0xA6u, DataDigestSyncResponsePacketCodec) - s2c(0xA6u, DataDigestSyncPacketCodec) + c2s(0xA6u, DataDigestSyncResponsePacketCodec) + s2c(0xA6u, DataDigestSyncPacketCodec) - c2s(0xA7u, DataContentSyncBatchPacketCodec) - s2c(0xA7u, DataDigestSyncBatchedPacketCodec) + c2s(0xA7u, DataContentSyncBatchPacketCodec) + s2c(0xA7u, DataDigestSyncBatchedPacketCodec) - c2s(0xA8u, BatchInputEventsPacketCodec) - s2c(0xA8u, SelectionListWindowOpenPacketCodec) + c2s(0xA8u, BatchInputEventsPacketCodec) + s2c(0xA8u, SelectionListWindowOpenPacketCodec) - c2s(0xA9u, ModerationActionConfirmPacketCodec) - s2c(0xA9u, EntityAttributeChangePacketCodec) + c2s(0xA9u, ModerationActionConfirmPacketCodec) + s2c(0xA9u, EntityAttributeChangePacketCodec) - s2c(0xAAu, WorldFlagStateUpdatePacketCodec) + s2c(0xAAu, WorldFlagStateUpdatePacketCodec) - s2c(0xABu, ChunkedTransferBeginPacketCodec) + s2c(0xABu, ChunkedTransferBeginPacketCodec) - s2c(0xACu, ChunkedTransferAppendPacketCodec) + s2c(0xACu, ChunkedTransferAppendPacketCodec) - s2c(0xADu, WorldTimedEventStatusPacketCodec) + s2c(0xADu, WorldTimedEventStatusPacketCodec) - s2c(0xAEu, GroupMemberRosterPacketCodec) + s2c(0xAEu, GroupMemberRosterPacketCodec) - s2c(0xB0u, SceneEntityActionDispatchPacketCodec) + s2c(0xB0u, SceneEntityActionDispatchPacketCodec) - s2c(0xB1u, SocialProfileDialogOpenPacketCodec) + s2c(0xB1u, SocialProfileDialogOpenPacketCodec) - bidi(0xB2u, NpcAnimationPacketCodec) + bidi(0xB2u, NpcAnimationPacketCodec) - s2c(0xB3u, MapTileAttributeSetPacketCodec) + s2c(0xB3u, MapTileAttributeSetPacketCodec) - bidi(0xB4u, RenderScreenPacketCodec) + bidi(0xB4u, RenderScreenPacketCodec) - s2c(0xB5u, EntityAppearancePatchPacketCodec) + s2c(0xB5u, EntityAppearancePatchPacketCodec) - s2c(0xB6u, WorldActionDispatchPacketCodec) + s2c(0xB6u, WorldActionDispatchPacketCodec) - s2c(0xB7u, EntityDespawnPacketCodec) + s2c(0xB7u, EntityDespawnPacketCodec) - s2c(0xB8u, MapTileEntityStateSetPacketCodec) + s2c(0xB8u, MapTileEntityStateSetPacketCodec) - bidi(0xB9u, MapTransitionAckPacketCodec) + bidi(0xB9u, MapTransitionAckPacketCodec) - s2c(0xBAu, MapTileObjectSlotSetPacketCodec) + s2c(0xBAu, MapTileObjectSlotSetPacketCodec) - s2c(0xBBu, CameraFollowEntityPacketCodec) + s2c(0xBBu, CameraFollowEntityPacketCodec) - s2c(0xBCu, MapTileObjectRepositionPacketCodec) + s2c(0xBCu, MapTileObjectRepositionPacketCodec) - s2c(0xBDu, WorldEntityStateResetPacketCodec) + s2c(0xBDu, WorldEntityStateResetPacketCodec) - s2c(0xBEu, WorldOverlayObjectSetPacketCodec) + s2c(0xBEu, WorldOverlayObjectSetPacketCodec) - s2c(0xC0u, MapTileAnimationTogglePacketCodec) + s2c(0xC0u, MapTileAnimationTogglePacketCodec) - c2s(0xC1u, TournamentRegistrationPacketCodec) - s2c(0xC1u, MapWeatherModeSetPacketCodec) + c2s(0xC1u, TournamentRegistrationPacketCodec) + s2c(0xC1u, MapWeatherModeSetPacketCodec) - bidi(0xC2u, KeepAlivePacketCodec) + bidi(0xC2u, KeepAlivePacketCodec) - s2c(0xC3u, FieldMapTilePaletteApplyPacketCodec) + s2c(0xC3u, FieldMapTilePaletteApplyPacketCodec) - s2c(0xC4u, FieldMapBattleSlotTileMapPacketCodec) + s2c(0xC4u, FieldMapBattleSlotTileMapPacketCodec) - s2c(0xC5u, FieldMapBattleSlotMarkerPacketCodec) + s2c(0xC5u, FieldMapBattleSlotMarkerPacketCodec) - s2c(0xC8u, WorldObjectInstanceDespawnPacketCodec) + s2c(0xC8u, WorldObjectInstanceDespawnPacketCodec) - s2c(0xCAu, BattleStartScenePacketCodec) + s2c(0xCAu, BattleStartScenePacketCodec) - c2s(0xD0u, SendChatCommandPacketCodec) - s2c(0xD0u, EntityGroupSnapshotPacketCodec) + c2s(0xD0u, SendChatCommandPacketCodec) + s2c(0xD0u, EntityGroupSnapshotPacketCodec) - c2s(0xD1u, LinkKickMemberPacketCodec) - s2c(0xD1u, EntityGroupMemberAddPacketCodec) + c2s(0xD1u, LinkKickMemberPacketCodec) + s2c(0xD1u, EntityGroupMemberAddPacketCodec) - s2c(0xD2u, EntityGroupMemberRemovePacketCodec) + s2c(0xD2u, EntityGroupMemberRemovePacketCodec) - c2s(0xD3u, CancelSocialInteractionPacketCodec) - s2c(0xD3u, ObjectiveProgressBulkPacketCodec) + c2s(0xD3u, CancelSocialInteractionPacketCodec) + s2c(0xD3u, ObjectiveProgressBulkPacketCodec) - c2s(0xD4u, RequestSocialProfilePacketCodec) - s2c(0xD4u, ObjectiveProgressPacketCodec) + c2s(0xD4u, RequestSocialProfilePacketCodec) + s2c(0xD4u, ObjectiveProgressPacketCodec) - s2c(0xD5u, TrackedEntitySlotsPacketCodec) + s2c(0xD5u, TrackedEntitySlotsPacketCodec) - s2c(0xD6u, MenuPromptOpenPacketCodec) + s2c(0xD6u, MenuPromptOpenPacketCodec) - s2c(0xD7u, EntityChecklistPromptPacketCodec) + s2c(0xD7u, EntityChecklistPromptPacketCodec) - s2c(0xD8u, MenuPromptClosePacketCodec) + s2c(0xD8u, MenuPromptClosePacketCodec) - s2c(0xD9u, RequestConfirmationPromptPacketCodec) + s2c(0xD9u, RequestConfirmationPromptPacketCodec) - s2c(0xDAu, EntityPanelSelectPacketCodec) + s2c(0xDAu, EntityPanelSelectPacketCodec) - s2c(0xDBu, EntityFramesUpdatePacketCodec) + s2c(0xDBu, EntityFramesUpdatePacketCodec) - s2c(0xDCu, CategoryFlagsPacketCodec) + s2c(0xDCu, CategoryFlagsPacketCodec) - c2s(0xE0u, SaveTemplateEntryPacketCodec) + c2s(0xE0u, SaveTemplateEntryPacketCodec) - c2s(0xE1u, GtlCreateListingPacketCodec) + c2s(0xE1u, GtlCreateListingPacketCodec) - c2s(0xE2u, GtlSearchFilterPacketCodec) + c2s(0xE2u, GtlSearchFilterPacketCodec) - c2s(0xE3u, BattleRewardSelectPacketCodec) + c2s(0xE3u, BattleRewardSelectPacketCodec) - c2s(0xE4u, BattleChallengeRequestPacketCodec) + c2s(0xE4u, BattleChallengeRequestPacketCodec) - s2c(0xEAu, EntityMovePacketCodec) + s2c(0xEAu, EntityMovePacketCodec) - s2c(0xF0u, QueuePositionPacketCodec) + s2c(0xF0u, QueuePositionPacketCodec) - c2s(0xF1u, ChunkedTransferDataPacketCodec) - s2c(0xF1u, ViewScalePacketCodec) + c2s(0xF1u, ChunkedTransferDataPacketCodec) + s2c(0xF1u, ViewScalePacketCodec) - s2c(0xF2u, SessionExpiryInitPacketCodec) + s2c(0xF2u, SessionExpiryInitPacketCodec) - s2c(0xF3u, LocalPlayerStatePacketCodec) + s2c(0xF3u, LocalPlayerStatePacketCodec) - s2c(0xF4u, CurrencyBalancePacketCodec) + s2c(0xF4u, CurrencyBalancePacketCodec) - s2c(0xF5u, ServerMessagePacketCodec) + s2c(0xF5u, ServerMessagePacketCodec) - s2c(0xF6u, ChunkedImagePacketCodec) + s2c(0xF6u, ChunkedImagePacketCodec) - s2c(0xF7u, GmPanelEntryPacketCodec) + s2c(0xF7u, GmPanelEntryPacketCodec) - s2c(0xF8u, DisconnectNoticePacketCodec) + s2c(0xF8u, DisconnectNoticePacketCodec) - s2c(0xF9u, RosterCooldownPacketCodec) + s2c(0xF9u, RosterCooldownPacketCodec) - s2c(0xFAu, CancelEntityMessagePacketCodec) + s2c(0xFAu, CancelEntityMessagePacketCodec) - s2c(0xFBu, PlayerInputLockPacketCodec) + s2c(0xFBu, PlayerInputLockPacketCodec) - s2c(0xFCu, ServerEndpointListPacketCodec) + s2c(0xFCu, ServerEndpointListPacketCodec) - s2c(0xFEu, GtlListingsPagePacketCodec) + s2c(0xFEu, GtlListingsPagePacketCodec) - s2c(0xFFu, WorldSessionStatePacketCodec) - - } + s2c(0xFFu, WorldSessionStatePacketCodec) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodec.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodec.kt index 193740f..45d0c34 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodec.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/CharacterInfoCodec.kt @@ -14,75 +14,75 @@ internal val EpochSecondsS32LE: Codec = private val TrailingBytes = bytesPrefixed(U16LE) class CharacterInfoCodec(private val withExtraLong: Boolean) : PacketCodec() { - override fun CodecScope.body(): CharacterInfo { - val id = field(S64LE, CharacterInfo::id) - val name = field(Utf16LeNullTerminated, CharacterInfo::name) - val namePrefix = field(Utf16LeNullTerminated) { "" } - val userId = field(S32LE, CharacterInfo::userId) - val rivalSex = field(S8, CharacterInfo::rivalSex) - val lastLogin = field(EpochSecondsS32LE, CharacterInfo::lastLogin) - if (withExtraLong) field(S64LE) { 0L } - val createdAt = field(EpochSecondsS32LE, CharacterInfo::createdAt) - field(S32LE) { 0 } - field(S8) { 0 } - field(S32LE) { 0 } - val money = field(S32LE, CharacterInfo::money) - field(S16LE) { 0 } - field(S32LE) { 0 } - val permissions = field(U8) { it.permissions and 0xFF } - field(S8) { 0 } - field(S8) { 0 } - field(S32LE) { 0 } - repeat(8) { field(S8) { 0 } } - val remainingSafariSteps = field(S16LE, CharacterInfo::remainingSafariSteps) - val remainingSafariBalls = field(S8, CharacterInfo::remainingSafariBalls) - field(S32LE) { 0 } - val pcExtraSlots = field(S8, CharacterInfo::pcExtraSlots) - val battleBoxExtraSlots = field(S8, CharacterInfo::battleBoxExtraSlots) - val templateAmount = field(S8, CharacterInfo::templateAmount) - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - val positionRegionId = field(S8, CharacterInfo::positionRegionId) - val positionBankId = field(S8, CharacterInfo::positionBankId) - val positionMapId = field(S8, CharacterInfo::positionMapId) - field(S8) { 0 } - val positionX = field(S16LE, CharacterInfo::positionX) - val positionY = field(S16LE, CharacterInfo::positionY) - field(S8) { 0 } - field(S8) { 0 } - val repelLeft = field(S16LE, CharacterInfo::repelLeft) - val repelItemId = field(S16LE, CharacterInfo::repelItemId) - field(S8) { 0 } - val lureItemId = field(S16LE, CharacterInfo::lureItemId) - val lureLeft = field(S16LE, CharacterInfo::lureLeft) - field(TrailingBytes) { ByteArray(0) } - return CharacterInfo( - id = id, - name = name, - namePrefix = namePrefix, - userId = userId, - rivalSex = rivalSex, - lastLogin = lastLogin, - createdAt = createdAt, - money = money, - permissions = permissions, - remainingSafariSteps = remainingSafariSteps, - remainingSafariBalls = remainingSafariBalls, - pcExtraSlots = pcExtraSlots, - battleBoxExtraSlots = battleBoxExtraSlots, - templateAmount = templateAmount, - positionRegionId = positionRegionId, - positionBankId = positionBankId, - positionMapId = positionMapId, - positionX = positionX, - positionY = positionY, - repelLeft = repelLeft, - repelItemId = repelItemId, - lureLeft = lureLeft, - lureItemId = lureItemId, - ) - } + override fun CodecScope.body(): CharacterInfo { + val id = field(S64LE, CharacterInfo::id) + val name = field(Utf16LeNullTerminated, CharacterInfo::name) + val namePrefix = field(Utf16LeNullTerminated) { "" } + val userId = field(S32LE, CharacterInfo::userId) + val rivalSex = field(S8, CharacterInfo::rivalSex) + val lastLogin = field(EpochSecondsS32LE, CharacterInfo::lastLogin) + if (withExtraLong) field(S64LE) { 0L } + val createdAt = field(EpochSecondsS32LE, CharacterInfo::createdAt) + field(S32LE) { 0 } + field(S8) { 0 } + field(S32LE) { 0 } + val money = field(S32LE, CharacterInfo::money) + field(S16LE) { 0 } + field(S32LE) { 0 } + val permissions = field(U8) { it.permissions and 0xFF } + field(S8) { 0 } + field(S8) { 0 } + field(S32LE) { 0 } + repeat(8) { field(S8) { 0 } } + val remainingSafariSteps = field(S16LE, CharacterInfo::remainingSafariSteps) + val remainingSafariBalls = field(S8, CharacterInfo::remainingSafariBalls) + field(S32LE) { 0 } + val pcExtraSlots = field(S8, CharacterInfo::pcExtraSlots) + val battleBoxExtraSlots = field(S8, CharacterInfo::battleBoxExtraSlots) + val templateAmount = field(S8, CharacterInfo::templateAmount) + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + val positionRegionId = field(S8, CharacterInfo::positionRegionId) + val positionBankId = field(S8, CharacterInfo::positionBankId) + val positionMapId = field(S8, CharacterInfo::positionMapId) + field(S8) { 0 } + val positionX = field(S16LE, CharacterInfo::positionX) + val positionY = field(S16LE, CharacterInfo::positionY) + field(S8) { 0 } + field(S8) { 0 } + val repelLeft = field(S16LE, CharacterInfo::repelLeft) + val repelItemId = field(S16LE, CharacterInfo::repelItemId) + field(S8) { 0 } + val lureItemId = field(S16LE, CharacterInfo::lureItemId) + val lureLeft = field(S16LE, CharacterInfo::lureLeft) + field(TrailingBytes) { ByteArray(0) } + return CharacterInfo( + id = id, + name = name, + namePrefix = namePrefix, + userId = userId, + rivalSex = rivalSex, + lastLogin = lastLogin, + createdAt = createdAt, + money = money, + permissions = permissions, + remainingSafariSteps = remainingSafariSteps, + remainingSafariBalls = remainingSafariBalls, + pcExtraSlots = pcExtraSlots, + battleBoxExtraSlots = battleBoxExtraSlots, + templateAmount = templateAmount, + positionRegionId = positionRegionId, + positionBankId = positionBankId, + positionMapId = positionMapId, + positionX = positionX, + positionY = positionY, + repelLeft = repelLeft, + repelItemId = repelItemId, + lureLeft = lureLeft, + lureItemId = lureItemId, + ) + } } val CharacterInfoCodecShort: Codec = CharacterInfoCodec(withExtraLong = false) diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/PokemonCodec.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/PokemonCodec.kt index cfc4ac4..38ce53e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/PokemonCodec.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/PokemonCodec.kt @@ -8,87 +8,87 @@ import de.fiereu.openmmo.common.enums.* private val PokemonUnknownBytes: Codec = bytesPrefixed(U8) object PokemonCodec : PacketCodec() { - override fun CodecScope.body(): Pokemon { - val id = field(S64LE, Pokemon::id) - field(S8) { 0 } - field(S64LE) { 0L } - field(S64LE) { 0L } - val container = PokemonContainer.entries[field(U8) { it.container.ordinal }] - val containerSlot = field(S16LE, Pokemon::containerSlot) - val dexId = field(U16LE, Pokemon::dexId) - val seed = field(S32LE, Pokemon::seed) - field(S64LE) { 0L } - val ot = field(Utf16LeNullTerminated, Pokemon::ot) - val nickname = field(Utf16LeNullTerminated, Pokemon::nickname) - field(S8) { 0 } - field(S8) { 0 } - val level = field(S8, Pokemon::level) - val currentHp = field(S16LE, Pokemon::hp) - field(S16LE) { 0 } - val xp = field(S32LE, Pokemon::xp) - field(S8) { 0 } - field(S16LE) { 0 } - val moveIds = List(4) { i -> field(S16LE) { it.moves[i].id } } - val movePps = List(4) { i -> field(S8) { it.moves[i].pp } } - val moves = List(4) { PokemonMove(moveIds[it], movePps[it]) } - repeat(4) { field(S16LE) { 0 } } - val eVs = - EVs().apply { - hp = field(U8) { it.eVs.hp } - atk = field(U8) { it.eVs.atk } - def = field(U8) { it.eVs.def } - spd = field(U8) { it.eVs.spd } - spAtk = field(U8) { it.eVs.spAtk } - spDef = field(U8) { it.eVs.spDef } - } - repeat(11) { field(S8) { 0 } } - val iVs = decompressIVs(field(S32LE) { it.iVs.compress() }) - field(S8) { 0 } - field(S64LE) { 0L } - val rarityMask = - field(U16LE) { - var m = 0 - if (it.isShiny) m = m or (1 shl PokemonRarity.SHINY.ordinal) - if (it.hasHiddenAbility) m = m or (1 shl PokemonRarity.HIDDEN_ABILITY.ordinal) - if (it.isAlpha) m = m or (1 shl PokemonRarity.ALPHA.ordinal) - if (it.isSecret) m = m or (1 shl PokemonRarity.SECRET.ordinal) - if (it.isFatefulEncounter) m = m or (1 shl PokemonRarity.FATEFUL_ENCOUNTER.ordinal) - if (it.isRaidEncounter) m = m or (1 shl PokemonRarity.RAID_ENCOUNTER.ordinal) - m - } - val isShiny = (rarityMask and (1 shl PokemonRarity.SHINY.ordinal)) != 0 - val hasHiddenAbility = (rarityMask and (1 shl PokemonRarity.HIDDEN_ABILITY.ordinal)) != 0 - val isAlpha = (rarityMask and (1 shl PokemonRarity.ALPHA.ordinal)) != 0 - val isSecret = (rarityMask and (1 shl PokemonRarity.SECRET.ordinal)) != 0 - val isFatefulEncounter = (rarityMask and (1 shl PokemonRarity.FATEFUL_ENCOUNTER.ordinal)) != 0 - val isRaidEncounter = (rarityMask and (1 shl PokemonRarity.RAID_ENCOUNTER.ordinal)) != 0 - val caughtAt = field(EpochSecondsS32LE, Pokemon::caughtAt) - field(S16LE) { 0 } - field(S8) { 0 } - field(S8) { 0 } - field(PokemonUnknownBytes) { ByteArray(0) } - repeat(12) { field(S8) { 0 } } - return Pokemon( - id, - container, - containerSlot, - dexId, - seed, - ot, - nickname, - level, - currentHp, - xp, - eVs, - iVs, - moves, - isShiny, - hasHiddenAbility, - isAlpha, - isSecret, - isFatefulEncounter, - isRaidEncounter, - caughtAt, - ) - } + override fun CodecScope.body(): Pokemon { + val id = field(S64LE, Pokemon::id) + field(S8) { 0 } + field(S64LE) { 0L } + field(S64LE) { 0L } + val container = PokemonContainer.entries[field(U8) { it.container.ordinal }] + val containerSlot = field(S16LE, Pokemon::containerSlot) + val dexId = field(U16LE, Pokemon::dexId) + val seed = field(S32LE, Pokemon::seed) + field(S64LE) { 0L } + val ot = field(Utf16LeNullTerminated, Pokemon::ot) + val nickname = field(Utf16LeNullTerminated, Pokemon::nickname) + field(S8) { 0 } + field(S8) { 0 } + val level = field(S8, Pokemon::level) + val currentHp = field(S16LE, Pokemon::hp) + field(S16LE) { 0 } + val xp = field(S32LE, Pokemon::xp) + field(S8) { 0 } + field(S16LE) { 0 } + val moveIds = List(4) { i -> field(S16LE) { it.moves[i].id } } + val movePps = List(4) { i -> field(S8) { it.moves[i].pp } } + val moves = List(4) { PokemonMove(moveIds[it], movePps[it]) } + repeat(4) { field(S16LE) { 0 } } + val eVs = + EVs().apply { + hp = field(U8) { it.eVs.hp } + atk = field(U8) { it.eVs.atk } + def = field(U8) { it.eVs.def } + spd = field(U8) { it.eVs.spd } + spAtk = field(U8) { it.eVs.spAtk } + spDef = field(U8) { it.eVs.spDef } + } + repeat(11) { field(S8) { 0 } } + val iVs = decompressIVs(field(S32LE) { it.iVs.compress() }) + field(S8) { 0 } + field(S64LE) { 0L } + val rarityMask = + field(U16LE) { + var m = 0 + if (it.isShiny) m = m or (1 shl PokemonRarity.SHINY.ordinal) + if (it.hasHiddenAbility) m = m or (1 shl PokemonRarity.HIDDEN_ABILITY.ordinal) + if (it.isAlpha) m = m or (1 shl PokemonRarity.ALPHA.ordinal) + if (it.isSecret) m = m or (1 shl PokemonRarity.SECRET.ordinal) + if (it.isFatefulEncounter) m = m or (1 shl PokemonRarity.FATEFUL_ENCOUNTER.ordinal) + if (it.isRaidEncounter) m = m or (1 shl PokemonRarity.RAID_ENCOUNTER.ordinal) + m + } + val isShiny = (rarityMask and (1 shl PokemonRarity.SHINY.ordinal)) != 0 + val hasHiddenAbility = (rarityMask and (1 shl PokemonRarity.HIDDEN_ABILITY.ordinal)) != 0 + val isAlpha = (rarityMask and (1 shl PokemonRarity.ALPHA.ordinal)) != 0 + val isSecret = (rarityMask and (1 shl PokemonRarity.SECRET.ordinal)) != 0 + val isFatefulEncounter = (rarityMask and (1 shl PokemonRarity.FATEFUL_ENCOUNTER.ordinal)) != 0 + val isRaidEncounter = (rarityMask and (1 shl PokemonRarity.RAID_ENCOUNTER.ordinal)) != 0 + val caughtAt = field(EpochSecondsS32LE, Pokemon::caughtAt) + field(S16LE) { 0 } + field(S8) { 0 } + field(S8) { 0 } + field(PokemonUnknownBytes) { ByteArray(0) } + repeat(12) { field(S8) { 0 } } + return Pokemon( + id, + container, + containerSlot, + dexId, + seed, + ot, + nickname, + level, + currentHp, + xp, + eVs, + iVs, + moves, + isShiny, + hasHiddenAbility, + isAlpha, + isSecret, + isFatefulEncounter, + isRaidEncounter, + caughtAt, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/SkinCodec.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/SkinCodec.kt index 5da75e8..85d4b4a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/SkinCodec.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/SkinCodec.kt @@ -7,43 +7,43 @@ import java.util.* data class Skin(val slot: SkinSlot, val type: UShort?, val color: UByte?) class SkinSet : EnumMap(SkinSlot::class.java) { - fun put(skin: Skin) { - this[skin.slot] = skin - } + fun put(skin: Skin) { + this[skin.slot] = skin + } - override fun put(key: SkinSlot, value: Skin): Skin? { - require(key == value.slot) { "Slot mismatch: $key != ${value.slot}" } - return super.put(key, value) - } + override fun put(key: SkinSlot, value: Skin): Skin? { + require(key == value.slot) { "Slot mismatch: $key != ${value.slot}" } + return super.put(key, value) + } } class SkinSetCodec( private val slots: List = SkinSlot.entries, private val withLeadingByte: Boolean = true, ) : PacketCodec() { - override fun CodecScope.body(): SkinSet { - if (withLeadingByte) field(U8) { 0 } - val mask = field(U16LE) { slots.fold(0) { acc, slot -> acc or (1 shl slot.ordinal) } } - val skins = SkinSet() - slots.forEach { slot -> - if ((mask and (1 shl slot.ordinal)) != 0) { - val compressed = - field(U16LE) { - val skin = it[slot] ?: Skin(slot, 0u, 0u) - val type = skin.type ?: 0x3FFFu - val color = skin.color ?: 0x3Fu - require(type <= 0x3FFFu) { "Skin type too large: ${skin.type}" } - require(color <= 0x3Fu) { "Skin color too large: ${skin.color}" } - (type and 0x3FFFu).toInt() or ((color and 0x3Fu).toInt() shl 10) - } - val type = (compressed and 0x3FFF).toUShort() - val color = ((compressed shr 10) and 0x3F).toUByte() - skins.put(Skin(slot, type, color)) + override fun CodecScope.body(): SkinSet { + if (withLeadingByte) field(U8) { 0 } + val mask = field(U16LE) { slots.fold(0) { acc, slot -> acc or (1 shl slot.ordinal) } } + val skins = SkinSet() + slots.forEach { slot -> + if ((mask and (1 shl slot.ordinal)) != 0) { + val compressed = + field(U16LE) { + val skin = it[slot] ?: Skin(slot, 0u, 0u) + val type = skin.type ?: 0x3FFFu + val color = skin.color ?: 0x3Fu + require(type <= 0x3FFFu) { "Skin type too large: ${skin.type}" } + require(color <= 0x3Fu) { "Skin color too large: ${skin.color}" } + (type and 0x3FFFu).toInt() or ((color and 0x3Fu).toInt() shl 10) } - } - return skins + val type = (compressed and 0x3FFF).toUShort() + val color = ((compressed shr 10) and 0x3F).toUByte() + skins.put(Skin(slot, type, color)) + } } + return skins + } } val DefaultSkinSetCodec: Codec = SkinSetCodec() -val SkinSetCodecNoLeading: Codec = SkinSetCodec(withLeadingByte = false) \ No newline at end of file +val SkinSetCodecNoLeading: Codec = SkinSetCodec(withLeadingByte = false) diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/Tile2DCodec.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/Tile2DCodec.kt index 90dc927..29df5fb 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/Tile2DCodec.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/codecs/Tile2DCodec.kt @@ -8,12 +8,12 @@ import de.fiereu.openmmo.common.Tile2D val Tile2DCodec: Codec = U16LE.imap( decode = { raw -> - Tile2D( - material = (raw and 0x3FF).toShort(), - collision = ((raw shr 10) and 0x3F).toByte(), - ) + Tile2D( + material = (raw and 0x3FF).toShort(), + collision = ((raw shr 10) and 0x3F).toByte(), + ) }, encode = { tile -> - ((tile.collision.toInt() and 0x3F) shl 10) or (tile.material.toInt() and 0x3FF) + ((tile.collision.toInt() and 0x3F) shl 10) or (tile.material.toInt() and 0x3FF) }, ) diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActiveBattleSidePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActiveBattleSidePacket.kt index bbee91c..f02d793 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActiveBattleSidePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActiveBattleSidePacket.kt @@ -9,8 +9,8 @@ data class ActiveBattleSidePacket( ) object ActiveBattleSidePacketCodec : PacketCodec() { - override fun CodecScope.body(): ActiveBattleSidePacket { - val side = field(S8) { it.side } - return ActiveBattleSidePacket(side) - } + override fun CodecScope.body(): ActiveBattleSidePacket { + val side = field(S8) { it.side } + return ActiveBattleSidePacket(side) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActivePokemonSummaryPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActivePokemonSummaryPacket.kt index 47fa0cf..a42b896 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActivePokemonSummaryPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ActivePokemonSummaryPacket.kt @@ -60,155 +60,155 @@ data class ActivePokemonSummaryPacket( ) private object SummaryRankingEntryCodec : PacketCodec() { - override fun CodecScope.body(): SummaryRankingEntry { - val entityId = field(S64LE, SummaryRankingEntry::entityId) - val rank = field(S8, SummaryRankingEntry::rank) - val flags = field(S8, SummaryRankingEntry::flags) - val name = field(Utf16LeNullTerminated, SummaryRankingEntry::name) - val value1 = field(S16LE, SummaryRankingEntry::value1) - val species = field(S16LE, SummaryRankingEntry::species) - reserved(byte = 0) - val ribbons = field(S64LE, SummaryRankingEntry::ribbons) - val value2 = field(S8, SummaryRankingEntry::value2) - val value3 = field(S32LE, SummaryRankingEntry::value3) - val value4 = field(S8, SummaryRankingEntry::value4) - val flag1 = field(Bool, SummaryRankingEntry::flag1) - val flag2 = field(Bool, SummaryRankingEntry::flag2) - reserved(byte = 0) - return SummaryRankingEntry( - entityId, - rank, - flags, - name, - value1, - species, - ribbons, - value2, - value3, - value4, - flag1, - flag2, - ) - } + override fun CodecScope.body(): SummaryRankingEntry { + val entityId = field(S64LE, SummaryRankingEntry::entityId) + val rank = field(S8, SummaryRankingEntry::rank) + val flags = field(S8, SummaryRankingEntry::flags) + val name = field(Utf16LeNullTerminated, SummaryRankingEntry::name) + val value1 = field(S16LE, SummaryRankingEntry::value1) + val species = field(S16LE, SummaryRankingEntry::species) + reserved(byte = 0) + val ribbons = field(S64LE, SummaryRankingEntry::ribbons) + val value2 = field(S8, SummaryRankingEntry::value2) + val value3 = field(S32LE, SummaryRankingEntry::value3) + val value4 = field(S8, SummaryRankingEntry::value4) + val flag1 = field(Bool, SummaryRankingEntry::flag1) + val flag2 = field(Bool, SummaryRankingEntry::flag2) + reserved(byte = 0) + return SummaryRankingEntry( + entityId, + rank, + flags, + name, + value1, + species, + ribbons, + value2, + value3, + value4, + flag1, + flag2, + ) + } } private object SummaryAppearanceCodec : PacketCodec() { - override fun CodecScope.body(): SummaryAppearance { - val name = field(Utf16LeNullTerminated, SummaryAppearance::name) - val gender = field(S8, SummaryAppearance::gender) - val formId = field(S32LE, SummaryAppearance::formId) - val kind = field(S8, SummaryAppearance::kind) - val palettePack = field(S8, SummaryAppearance::palettePack) - val slots = field(S16LE.repeat(4), SummaryAppearance::slots) - return SummaryAppearance(name, gender, formId, kind, palettePack, slots) - } + override fun CodecScope.body(): SummaryAppearance { + val name = field(Utf16LeNullTerminated, SummaryAppearance::name) + val gender = field(S8, SummaryAppearance::gender) + val formId = field(S32LE, SummaryAppearance::formId) + val kind = field(S8, SummaryAppearance::kind) + val palettePack = field(S8, SummaryAppearance::palettePack) + val slots = field(S16LE.repeat(4), SummaryAppearance::slots) + return SummaryAppearance(name, gender, formId, kind, palettePack, slots) + } } private object SummaryAbilityCodec : PacketCodec() { - override fun CodecScope.body(): SummaryAbility { - val slot = field(S8, SummaryAbility::slot) - val sourceId = field(S64LE, SummaryAbility::sourceId) - val appearance = field(SummaryAppearanceCodec, SummaryAbility::appearance) - return SummaryAbility(slot, sourceId, appearance) - } + override fun CodecScope.body(): SummaryAbility { + val slot = field(S8, SummaryAbility::slot) + val sourceId = field(S64LE, SummaryAbility::sourceId) + val appearance = field(SummaryAppearanceCodec, SummaryAbility::appearance) + return SummaryAbility(slot, sourceId, appearance) + } } private object SummaryMoveCodec : PacketCodec() { - override fun CodecScope.body(): SummaryMove { - val moveId = field(S8, SummaryMove::moveId) - val slot = field(S8, SummaryMove::slot) - val locked = field(Bool, SummaryMove::locked) - if (!locked) { - val intA = field(S32LE, SummaryMove::intA) - val intB = field(S32LE, SummaryMove::intB) - val intC = field(S32LE, SummaryMove::intC) - val shortA = field(S16LE, SummaryMove::shortA) - val shortB = field(S16LE, SummaryMove::shortB) - val byteA = field(S8, SummaryMove::byteA) - return SummaryMove( - moveId, - slot, - locked, - intA, - intB, - intC, - shortA, - shortB, - byteA, - 0, - false, - false, - 0, - false, - false, - 0, - 0, - 0, - ) - } - val unlockedShort = field(S16LE, SummaryMove::unlockedShort) - val boolA = field(Bool, SummaryMove::boolA) - val boolB = field(Bool, SummaryMove::boolB) - val unlockedByteA = field(S8, SummaryMove::unlockedByteA) - val boolC = field(Bool, SummaryMove::boolC) - val boolD = field(Bool, SummaryMove::boolD) - val unlockedByteB = field(S8, SummaryMove::unlockedByteB) - val unlockedByteC = field(S8, SummaryMove::unlockedByteC) - val unlockedByteD = field(S8, SummaryMove::unlockedByteD) - return SummaryMove( - moveId, - slot, - locked, - 0, - 0, - 0, - 0, - 0, - 0, - unlockedShort, - boolA, - boolB, - unlockedByteA, - boolC, - boolD, - unlockedByteB, - unlockedByteC, - unlockedByteD, - ) + override fun CodecScope.body(): SummaryMove { + val moveId = field(S8, SummaryMove::moveId) + val slot = field(S8, SummaryMove::slot) + val locked = field(Bool, SummaryMove::locked) + if (!locked) { + val intA = field(S32LE, SummaryMove::intA) + val intB = field(S32LE, SummaryMove::intB) + val intC = field(S32LE, SummaryMove::intC) + val shortA = field(S16LE, SummaryMove::shortA) + val shortB = field(S16LE, SummaryMove::shortB) + val byteA = field(S8, SummaryMove::byteA) + return SummaryMove( + moveId, + slot, + locked, + intA, + intB, + intC, + shortA, + shortB, + byteA, + 0, + false, + false, + 0, + false, + false, + 0, + 0, + 0, + ) } + val unlockedShort = field(S16LE, SummaryMove::unlockedShort) + val boolA = field(Bool, SummaryMove::boolA) + val boolB = field(Bool, SummaryMove::boolB) + val unlockedByteA = field(S8, SummaryMove::unlockedByteA) + val boolC = field(Bool, SummaryMove::boolC) + val boolD = field(Bool, SummaryMove::boolD) + val unlockedByteB = field(S8, SummaryMove::unlockedByteB) + val unlockedByteC = field(S8, SummaryMove::unlockedByteC) + val unlockedByteD = field(S8, SummaryMove::unlockedByteD) + return SummaryMove( + moveId, + slot, + locked, + 0, + 0, + 0, + 0, + 0, + 0, + unlockedShort, + boolA, + boolB, + unlockedByteA, + boolC, + boolD, + unlockedByteB, + unlockedByteC, + unlockedByteD, + ) + } } private val SummaryAbilityListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { SummaryAbilityCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { SummaryAbilityCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { SummaryAbilityCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { SummaryAbilityCodec.write(buf, it) } + } } private val SummaryMoveListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { SummaryMoveCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { SummaryMoveCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { SummaryMoveCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { SummaryMoveCodec.write(buf, it) } + } } object ActivePokemonSummaryPacketCodec : PacketCodec() { - override fun CodecScope.body(): ActivePokemonSummaryPacket { - val pokemon = field(SummaryRankingEntryCodec, ActivePokemonSummaryPacket::pokemon) - val abilities = field(SummaryAbilityListPrefixedU8, ActivePokemonSummaryPacket::abilities) - val moves = field(SummaryMoveListPrefixedU8, ActivePokemonSummaryPacket::moves) - return ActivePokemonSummaryPacket(pokemon, abilities, moves) - } + override fun CodecScope.body(): ActivePokemonSummaryPacket { + val pokemon = field(SummaryRankingEntryCodec, ActivePokemonSummaryPacket::pokemon) + val abilities = field(SummaryAbilityListPrefixedU8, ActivePokemonSummaryPacket::abilities) + val moves = field(SummaryMoveListPrefixedU8, ActivePokemonSummaryPacket::moves) + return ActivePokemonSummaryPacket(pokemon, abilities, moves) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AddFriendPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AddFriendPacket.kt new file mode 100644 index 0000000..dac087b --- /dev/null +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AddFriendPacket.kt @@ -0,0 +1,14 @@ +package de.fiereu.openmmo.net.game.packets + +import de.fiereu.bytecodec.CodecScope +import de.fiereu.bytecodec.PacketCodec +import de.fiereu.bytecodec.Utf16LeNullTerminated + +data class AddFriendPacket(val username: String) + +object AddFriendPacketCodec : PacketCodec() { + override fun CodecScope.body(): AddFriendPacket { + val username = field(Utf16LeNullTerminated) { it.username } + return AddFriendPacket(username) + } +} diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AdminNoteActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AdminNoteActionPacket.kt index c063c62..efceec7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AdminNoteActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AdminNoteActionPacket.kt @@ -10,34 +10,34 @@ data class AdminNoteActionPacket( ) object AdminNoteActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): AdminNoteActionPacket { - val actionType = field(S8) { it.actionType } - return when (actionType.toInt()) { - 1 -> { - val targetEntityId = - field(S64LE) { - it.targetEntityId ?: throw MalformedPacketException("targetEntityId required") - } - val noteText = - field(Utf16LeNullTerminated) { - it.noteText ?: throw MalformedPacketException("noteText required") - } - AdminNoteActionPacket(actionType, targetEntityId, null, noteText) + override fun CodecScope.body(): AdminNoteActionPacket { + val actionType = field(S8) { it.actionType } + return when (actionType.toInt()) { + 1 -> { + val targetEntityId = + field(S64LE) { + it.targetEntityId ?: throw MalformedPacketException("targetEntityId required") } - - 2 -> { - val targetEntityId = - field(S64LE) { - it.targetEntityId ?: throw MalformedPacketException("targetEntityId required") - } - val noteEntityId = - field(S64LE) { - it.noteEntityId ?: throw MalformedPacketException("noteEntityId required") - } - AdminNoteActionPacket(actionType, targetEntityId, noteEntityId, null) + val noteText = + field(Utf16LeNullTerminated) { + it.noteText ?: throw MalformedPacketException("noteText required") } + AdminNoteActionPacket(actionType, targetEntityId, null, noteText) + } - else -> AdminNoteActionPacket(actionType, null, null, null) - } + 2 -> { + val targetEntityId = + field(S64LE) { + it.targetEntityId ?: throw MalformedPacketException("targetEntityId required") + } + val noteEntityId = + field(S64LE) { + it.noteEntityId ?: throw MalformedPacketException("noteEntityId required") + } + AdminNoteActionPacket(actionType, targetEntityId, noteEntityId, null) + } + + else -> AdminNoteActionPacket(actionType, null, null, null) } + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AppearanceRequestResultPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AppearanceRequestResultPacket.kt index d3c544b..08c91c8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AppearanceRequestResultPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AppearanceRequestResultPacket.kt @@ -11,9 +11,9 @@ data class AppearanceRequestResultPacket( ) object AppearanceRequestResultPacketCodec : PacketCodec() { - override fun CodecScope.body(): AppearanceRequestResultPacket { - val entityId = field(S64LE) { it.entityId } - val accepted = field(Bool) { it.accepted } - return AppearanceRequestResultPacket(entityId, accepted) - } + override fun CodecScope.body(): AppearanceRequestResultPacket { + val entityId = field(S64LE) { it.entityId } + val accepted = field(Bool) { it.accepted } + return AppearanceRequestResultPacket(entityId, accepted) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AssignBreedingSlotPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AssignBreedingSlotPacket.kt index 2b3a11f..e509e96 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AssignBreedingSlotPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/AssignBreedingSlotPacket.kt @@ -12,10 +12,10 @@ data class AssignBreedingSlotPacket( ) object AssignBreedingSlotPacketCodec : PacketCodec() { - override fun CodecScope.body(): AssignBreedingSlotPacket { - val ownPokemonEntityId = field(S64LE) { it.ownPokemonEntityId } - val partnerPokemonEntityId = field(S64LE) { it.partnerPokemonEntityId } - val slotIndex = field(S8) { it.slotIndex } - return AssignBreedingSlotPacket(ownPokemonEntityId, partnerPokemonEntityId, slotIndex) - } + override fun CodecScope.body(): AssignBreedingSlotPacket { + val ownPokemonEntityId = field(S64LE) { it.ownPokemonEntityId } + val partnerPokemonEntityId = field(S64LE) { it.partnerPokemonEntityId } + val slotIndex = field(S8) { it.slotIndex } + return AssignBreedingSlotPacket(ownPokemonEntityId, partnerPokemonEntityId, slotIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BatchInputEventsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BatchInputEventsPacket.kt index 6e0ea35..85b90ee 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BatchInputEventsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BatchInputEventsPacket.kt @@ -20,132 +20,130 @@ data class BatchInputEventsPacket( private val EventsCodec: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val count = S16LE.read(buf).toInt() - if (count == 0) return emptyList() - var previous = S64LE.read(buf) - val result = ArrayList(count) - for (i in 0 until count) { - val type = S8.read(buf) - val delta = S16LE.read(buf).toInt() - val timestamp = if (delta == -1) S64LE.read(buf) else previous + delta - var byteA: Byte = 0 - var byteB: Byte = 0 - var intA = 0 - var shortA: Short = 0 - var shortB: Short = 0 - var intB = 0 - when (type.toInt()) { - 0, - 1 -> { - byteA = S8.read(buf) - byteB = S8.read(buf) - intA = S32LE.read(buf) - intB = S32LE.read(buf) - } - - 2, - 3 -> { - byteA = S8.read(buf) - byteB = S8.read(buf) - shortA = S16LE.read(buf) - shortB = S16LE.read(buf) - intA = S32LE.read(buf) - intB = S32LE.read(buf) - } - - 4, - 14 -> { - byteB = S8.read(buf) - shortA = S16LE.read(buf) - shortB = S16LE.read(buf) - intA = S32LE.read(buf) - intB = S32LE.read(buf) - } - - 5, - 6, - 7, - 8 -> { - byteB = S8.read(buf) - } - - 9 -> { - shortA = S16LE.read(buf) - shortB = S16LE.read(buf) - } - } - result.add( - InputEventSample(type, timestamp, byteA, byteB, intA, shortA, shortB, intB) - ) - previous = timestamp + override fun read(buf: ReadBuffer): List { + val count = S16LE.read(buf).toInt() + if (count == 0) return emptyList() + var previous = S64LE.read(buf) + val result = ArrayList(count) + for (i in 0 until count) { + val type = S8.read(buf) + val delta = S16LE.read(buf).toInt() + val timestamp = if (delta == -1) S64LE.read(buf) else previous + delta + var byteA: Byte = 0 + var byteB: Byte = 0 + var intA = 0 + var shortA: Short = 0 + var shortB: Short = 0 + var intB = 0 + when (type.toInt()) { + 0, + 1 -> { + byteA = S8.read(buf) + byteB = S8.read(buf) + intA = S32LE.read(buf) + intB = S32LE.read(buf) } - return result - } - override fun write(buf: WriteBuffer, value: List) { - S16LE.write(buf, value.size.toShort()) - if (value.isEmpty()) return - var previous = value[0].timestamp - S64LE.write(buf, previous) - for (event in value) { - S8.write(buf, event.type) - val delta = event.timestamp - previous - if (delta > 32767L) { - S16LE.write(buf, (-1).toShort()) - S64LE.write(buf, event.timestamp) - } else { - S16LE.write(buf, delta.toShort()) - } - when (event.type.toInt()) { - 0, - 1 -> { - S8.write(buf, event.byteA) - S8.write(buf, event.byteB) - S32LE.write(buf, event.intA) - S32LE.write(buf, event.intB) - } - - 2, - 3 -> { - S8.write(buf, event.byteA) - S8.write(buf, event.byteB) - S16LE.write(buf, event.shortA) - S16LE.write(buf, event.shortB) - S32LE.write(buf, event.intA) - S32LE.write(buf, event.intB) - } - - 4, - 14 -> { - S8.write(buf, event.byteB) - S16LE.write(buf, event.shortA) - S16LE.write(buf, event.shortB) - S32LE.write(buf, event.intA) - S32LE.write(buf, event.intB) - } - - 5, - 6, - 7, - 8 -> { - S8.write(buf, event.byteB) - } - - 9 -> { - S16LE.write(buf, event.shortA) - S16LE.write(buf, event.shortB) - } - } - previous = event.timestamp + 2, + 3 -> { + byteA = S8.read(buf) + byteB = S8.read(buf) + shortA = S16LE.read(buf) + shortB = S16LE.read(buf) + intA = S32LE.read(buf) + intB = S32LE.read(buf) } + + 4, + 14 -> { + byteB = S8.read(buf) + shortA = S16LE.read(buf) + shortB = S16LE.read(buf) + intA = S32LE.read(buf) + intB = S32LE.read(buf) + } + + 5, + 6, + 7, + 8 -> { + byteB = S8.read(buf) + } + + 9 -> { + shortA = S16LE.read(buf) + shortB = S16LE.read(buf) + } + } + result.add(InputEventSample(type, timestamp, byteA, byteB, intA, shortA, shortB, intB)) + previous = timestamp } + return result + } + + override fun write(buf: WriteBuffer, value: List) { + S16LE.write(buf, value.size.toShort()) + if (value.isEmpty()) return + var previous = value[0].timestamp + S64LE.write(buf, previous) + for (event in value) { + S8.write(buf, event.type) + val delta = event.timestamp - previous + if (delta > 32767L) { + S16LE.write(buf, (-1).toShort()) + S64LE.write(buf, event.timestamp) + } else { + S16LE.write(buf, delta.toShort()) + } + when (event.type.toInt()) { + 0, + 1 -> { + S8.write(buf, event.byteA) + S8.write(buf, event.byteB) + S32LE.write(buf, event.intA) + S32LE.write(buf, event.intB) + } + + 2, + 3 -> { + S8.write(buf, event.byteA) + S8.write(buf, event.byteB) + S16LE.write(buf, event.shortA) + S16LE.write(buf, event.shortB) + S32LE.write(buf, event.intA) + S32LE.write(buf, event.intB) + } + + 4, + 14 -> { + S8.write(buf, event.byteB) + S16LE.write(buf, event.shortA) + S16LE.write(buf, event.shortB) + S32LE.write(buf, event.intA) + S32LE.write(buf, event.intB) + } + + 5, + 6, + 7, + 8 -> { + S8.write(buf, event.byteB) + } + + 9 -> { + S16LE.write(buf, event.shortA) + S16LE.write(buf, event.shortB) + } + } + previous = event.timestamp + } + } } object BatchInputEventsPacketCodec : PacketCodec() { - override fun CodecScope.body(): BatchInputEventsPacket { - val hasEvents = field(Bool) { it.hasEvents } - val events = field(EventsCodec) { it.events } - return BatchInputEventsPacket(hasEvents, events) - } + override fun CodecScope.body(): BatchInputEventsPacket { + val hasEvents = field(Bool) { it.hasEvents } + val events = field(EventsCodec) { it.events } + return BatchInputEventsPacket(hasEvents, events) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionOutcomePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionOutcomePacket.kt index fa9a7ff..973d9e2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionOutcomePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionOutcomePacket.kt @@ -29,56 +29,68 @@ data class BattleActionParticipant( private val BattleRewardEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleActionRewardEntry { - val itemId = field(S32LE) { it.itemId } - val quantity = field(S16LE) { it.quantity } - return BattleActionRewardEntry(itemId, quantity) - } + override fun CodecScope.body(): BattleActionRewardEntry { + val itemId = field(S32LE) { it.itemId } + val quantity = field(S16LE) { it.quantity } + return BattleActionRewardEntry(itemId, quantity) + } } private class BattleParticipantCodec(private val isCapture: Boolean) : PacketCodec() { - override fun CodecScope.body(): BattleActionParticipant { - val entityId = field(S64LE) { it.entityId } - val kind = field(U8) { it.kind } - val intA = field(S32LE) { it.intA } - val intB = field(S32LE) { it.intB } - val intC = field(S32LE) { it.intC } - val shortA = field(S16LE) { it.shortA } - var critByte: Byte? = null - var critShort: Short? = null - if (isCapture) { - critByte = field(S8) { it.critByte!! } - critShort = field(S16LE) { it.critShort!! } - } - var capturedShort: Short? = null - var capturedByte: Byte? = null - if (isCapture || kind == 1) { - capturedShort = field(S16LE) { it.capturedShort!! } - capturedByte = field(S8) { it.capturedByte!! } - } - var xpShort: Short? = null - var xpByteA: Byte? = null - var xpByteB: Byte? = null - if (isCapture && kind == 0) { - xpShort = field(S16LE) { it.xpShort!! } - xpByteA = field(S8) { it.xpByteA!! } - xpByteB = field(S8) { it.xpByteB!! } - } - var pokemon: Pokemon? = null - var statStages: List? = null - if (kind == 0) { - val present = field(U8) { if (it.pokemon != null) 1 else 0 } - if (present == 1) { - pokemon = field(PokemonCodec) { it.pokemon!! } - statStages = (0 until 6).map { i -> field(S16LE) { it.statStages!![i] } } - } - } - return BattleActionParticipant( - entityId, kind, intA, intB, intC, shortA, critByte, critShort, capturedShort, capturedByte, - xpShort, xpByteA, xpByteB, pokemon, statStages - ) + override fun CodecScope.body(): BattleActionParticipant { + val entityId = field(S64LE) { it.entityId } + val kind = field(U8) { it.kind } + val intA = field(S32LE) { it.intA } + val intB = field(S32LE) { it.intB } + val intC = field(S32LE) { it.intC } + val shortA = field(S16LE) { it.shortA } + var critByte: Byte? = null + var critShort: Short? = null + if (isCapture) { + critByte = field(S8) { it.critByte!! } + critShort = field(S16LE) { it.critShort!! } } + var capturedShort: Short? = null + var capturedByte: Byte? = null + if (isCapture || kind == 1) { + capturedShort = field(S16LE) { it.capturedShort!! } + capturedByte = field(S8) { it.capturedByte!! } + } + var xpShort: Short? = null + var xpByteA: Byte? = null + var xpByteB: Byte? = null + if (isCapture && kind == 0) { + xpShort = field(S16LE) { it.xpShort!! } + xpByteA = field(S8) { it.xpByteA!! } + xpByteB = field(S8) { it.xpByteB!! } + } + var pokemon: Pokemon? = null + var statStages: List? = null + if (kind == 0) { + val present = field(U8) { if (it.pokemon != null) 1 else 0 } + if (present == 1) { + pokemon = field(PokemonCodec) { it.pokemon!! } + statStages = (0 until 6).map { i -> field(S16LE) { it.statStages!![i] } } + } + } + return BattleActionParticipant( + entityId, + kind, + intA, + intB, + intC, + shortA, + critByte, + critShort, + capturedShort, + capturedByte, + xpShort, + xpByteA, + xpByteB, + pokemon, + statStages) + } } data class BattleActionOutcomePacket( @@ -91,20 +103,20 @@ data class BattleActionOutcomePacket( ) object BattleActionOutcomePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleActionOutcomePacket { - val side = field(S8) { it.side } - val category = field(U8) { it.category } - val value = field(S16LE) { it.value } - val extra = field(S32LE) { it.extra } - val isCapture = category == 2 - val participantCodec = BattleParticipantCodec(isCapture) - val count = field(U8) { it.participants.size } - val participants = (0 until count).map { i -> field(participantCodec) { it.participants[i] } } - val rewards = - if (category == 1) { - val rewardCount = field(U8) { it.rewards!!.size } - (0 until rewardCount).map { i -> field(BattleRewardEntryCodec) { it.rewards!![i] } } - } else null - return BattleActionOutcomePacket(side, category, value, extra, participants, rewards) - } + override fun CodecScope.body(): BattleActionOutcomePacket { + val side = field(S8) { it.side } + val category = field(U8) { it.category } + val value = field(S16LE) { it.value } + val extra = field(S32LE) { it.extra } + val isCapture = category == 2 + val participantCodec = BattleParticipantCodec(isCapture) + val count = field(U8) { it.participants.size } + val participants = (0 until count).map { i -> field(participantCodec) { it.participants[i] } } + val rewards = + if (category == 1) { + val rewardCount = field(U8) { it.rewards!!.size } + (0 until rewardCount).map { i -> field(BattleRewardEntryCodec) { it.rewards!![i] } } + } else null + return BattleActionOutcomePacket(side, category, value, extra, participants, rewards) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPacket.kt index de7b2d2..363aefe 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPacket.kt @@ -11,12 +11,12 @@ data class BattleActionPacket( ) object BattleActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleActionPacket { - val actionTypeId = field(S8) { it.actionTypeId } - val isSlotTarget = field(Bool) { it.isSlotTarget } - val targetSlot: Short? = if (isSlotTarget) field(S16LE) { it.targetSlot!! } else null - val targetEntityId: Long? = if (!isSlotTarget) field(S64LE) { it.targetEntityId!! } else null - val extraFlag = field(S8) { it.extraFlag } - return BattleActionPacket(actionTypeId, isSlotTarget, targetSlot, targetEntityId, extraFlag) - } + override fun CodecScope.body(): BattleActionPacket { + val actionTypeId = field(S8) { it.actionTypeId } + val isSlotTarget = field(Bool) { it.isSlotTarget } + val targetSlot: Short? = if (isSlotTarget) field(S16LE) { it.targetSlot!! } else null + val targetEntityId: Long? = if (!isSlotTarget) field(S64LE) { it.targetEntityId!! } else null + val extraFlag = field(S8) { it.extraFlag } + return BattleActionPacket(actionTypeId, isSlotTarget, targetSlot, targetEntityId, extraFlag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPromptTogglePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPromptTogglePacket.kt index 40e3423..30827a7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPromptTogglePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionPromptTogglePacket.kt @@ -9,8 +9,8 @@ data class BattleActionPromptTogglePacket( ) object BattleActionPromptTogglePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleActionPromptTogglePacket { - val shown = field(Bool) { it.shown } - return BattleActionPromptTogglePacket(shown) - } + override fun CodecScope.body(): BattleActionPromptTogglePacket { + val shown = field(Bool) { it.shown } + return BattleActionPromptTogglePacket(shown) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionResultPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionResultPacket.kt index abcced0..24c8593 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionResultPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionResultPacket.kt @@ -12,20 +12,20 @@ data class BattleActionResultPacket( ) object BattleActionResultPacketCodec : PacketCodec() { - private const val MESSAGE_TYPE_WITH_MOVE: Int = 0 + private const val MESSAGE_TYPE_WITH_MOVE: Int = 0 - override fun CodecScope.body(): BattleActionResultPacket { - val targetCount = field(S8) { it.targetCount } - val targets = ArrayList() - var entityId = 0L - if (targetCount < 0) { - entityId = field(S64LE) { it.entityId } - } else { - repeat(targetCount.toInt()) { i -> targets.add(field(S8) { p -> p.targets[i] }) } - } - val value = field(S32LE) { it.value } - val messageType = field(S8) { it.messageType } - val move = if (messageType.toInt() == MESSAGE_TYPE_WITH_MOVE) field(S8) { it.move!! } else null - return BattleActionResultPacket(targetCount, targets, entityId, value, messageType, move) + override fun CodecScope.body(): BattleActionResultPacket { + val targetCount = field(S8) { it.targetCount } + val targets = ArrayList() + var entityId = 0L + if (targetCount < 0) { + entityId = field(S64LE) { it.entityId } + } else { + repeat(targetCount.toInt()) { i -> targets.add(field(S8) { p -> p.targets[i] }) } } + val value = field(S32LE) { it.value } + val messageType = field(S8) { it.messageType } + val move = if (messageType.toInt() == MESSAGE_TYPE_WITH_MOVE) field(S8) { it.move!! } else null + return BattleActionResultPacket(targetCount, targets, entityId, value, messageType, move) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSelectPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSelectPacket.kt index 99129ff..4594e2c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSelectPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSelectPacket.kt @@ -13,36 +13,37 @@ data class BattleActionSelectPacket( private val BattleActionSelectBody: Codec = object : Codec { - override fun read(buf: ReadBuffer): BattleActionSelectPacket { - val slotRefPacked = S8.read(buf) - val actionKindId = S8.read(buf) - return BattleActionSelectPacket(slotRefPacked, actionKindId, 0, 0, 0, 0) - } + override fun read(buf: ReadBuffer): BattleActionSelectPacket { + val slotRefPacked = S8.read(buf) + val actionKindId = S8.read(buf) + return BattleActionSelectPacket(slotRefPacked, actionKindId, 0, 0, 0, 0) + } - override fun write(buf: WriteBuffer, value: BattleActionSelectPacket) { - S8.write(buf, value.slotRefPacked) - S8.write(buf, value.actionKindId) - when (value.payloadVariant) { - 1 -> { - S16LE.write(buf, value.moveOrItemId) - S8.write(buf, value.extraFlag) - } + override fun write(buf: WriteBuffer, value: BattleActionSelectPacket) { + S8.write(buf, value.slotRefPacked) + S8.write(buf, value.actionKindId) + when (value.payloadVariant) { + 1 -> { + S16LE.write(buf, value.moveOrItemId) + S8.write(buf, value.extraFlag) + } - 2, 3 -> { - S16LE.write(buf, value.moveOrItemId) - } + 2, + 3 -> { + S16LE.write(buf, value.moveOrItemId) + } - 4 -> { - S16LE.write(buf, value.moveOrItemId) - S64LE.write(buf, value.targetEntityId) - S8.write(buf, value.extraFlag) - } - } + 4 -> { + S16LE.write(buf, value.moveOrItemId) + S64LE.write(buf, value.targetEntityId) + S8.write(buf, value.extraFlag) + } } + } } object BattleActionSelectPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleActionSelectPacket { - return field(BattleActionSelectBody) { it } - } + override fun CodecScope.body(): BattleActionSelectPacket { + return field(BattleActionSelectBody) { it } + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSubmitPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSubmitPacket.kt index fd41425..ff558f6 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSubmitPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleActionSubmitPacket.kt @@ -12,54 +12,54 @@ data class MultiTierAction(val selections: List) : BattleActi private val BattleActionCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): BattleAction { - val first = buf.readByte().toInt() and 0xFF - return if (first == 0) { - var id = 0L - for (i in 0 until 8) { - id = id or ((buf.readByte().toLong() and 0xFF) shl (i * 8)) - } - val moveSlot = buf.readByte() - SinglePokemonAction(id, moveSlot) - } else { - val selections = ArrayList(first) - repeat(first) { - val tierIndex = buf.readByte() - val slot = buf.readByte() - selections.add(TierSlotSelection(tierIndex, slot)) - } - MultiTierAction(selections) - } + override fun read(buf: ReadBuffer): BattleAction { + val first = buf.readByte().toInt() and 0xFF + return if (first == 0) { + var id = 0L + for (i in 0 until 8) { + id = id or ((buf.readByte().toLong() and 0xFF) shl (i * 8)) + } + val moveSlot = buf.readByte() + SinglePokemonAction(id, moveSlot) + } else { + val selections = ArrayList(first) + repeat(first) { + val tierIndex = buf.readByte() + val slot = buf.readByte() + selections.add(TierSlotSelection(tierIndex, slot)) + } + MultiTierAction(selections) } + } - override fun write(buf: WriteBuffer, value: BattleAction) { - when (value) { - is SinglePokemonAction -> { - buf.writeByte(0.toByte()) - var v = value.pokemonEntityId - for (i in 0 until 8) { - buf.writeByte((v and 0xFF).toByte()) - v = v ushr 8 - } - buf.writeByte(value.moveSlot) - } - - is MultiTierAction -> { - buf.writeByte(value.selections.size.toByte()) - for (s in value.selections) { - buf.writeByte(s.tierIndex) - buf.writeByte(s.slot) - } - } + override fun write(buf: WriteBuffer, value: BattleAction) { + when (value) { + is SinglePokemonAction -> { + buf.writeByte(0.toByte()) + var v = value.pokemonEntityId + for (i in 0 until 8) { + buf.writeByte((v and 0xFF).toByte()) + v = v ushr 8 } + buf.writeByte(value.moveSlot) + } + + is MultiTierAction -> { + buf.writeByte(value.selections.size.toByte()) + for (s in value.selections) { + buf.writeByte(s.tierIndex) + buf.writeByte(s.slot) + } + } } + } } data class BattleActionSubmitPacket(val action: BattleAction) object BattleActionSubmitPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleActionSubmitPacket { - val action = field(BattleActionCodec) { it.action } - return BattleActionSubmitPacket(action) - } + override fun CodecScope.body(): BattleActionSubmitPacket { + val action = field(BattleActionCodec) { it.action } + return BattleActionSubmitPacket(action) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBoardCellPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBoardCellPacket.kt index b79be5a..c9ea257 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBoardCellPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBoardCellPacket.kt @@ -12,13 +12,13 @@ data class BattleBoardCellPacket( ) object BattleBoardCellPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleBoardCellPacket { - val row = field(S8) { it.row } - val column = field(S16LE) { it.column } - val entityId = field(S64LE) { it.entityId } - val valueA = field(S16LE) { it.valueA } - val valueB = field(S16LE) { it.valueB } - val flags = field(S8) { it.flags } - return BattleBoardCellPacket(row, column, entityId, valueA, valueB, flags) - } + override fun CodecScope.body(): BattleBoardCellPacket { + val row = field(S8) { it.row } + val column = field(S16LE) { it.column } + val entityId = field(S64LE) { it.entityId } + val valueA = field(S16LE) { it.valueA } + val valueB = field(S16LE) { it.valueB } + val flags = field(S8) { it.flags } + return BattleBoardCellPacket(row, column, entityId, valueA, valueB, flags) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBulkStatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBulkStatePacket.kt index 75fe9d1..e330ec0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBulkStatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleBulkStatePacket.kt @@ -24,51 +24,51 @@ internal data class BattleMessageArg( internal val BattleMessageArgCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): BattleMessageArg { - val id = S8.read(buf) - var type = S8.read(buf) - var hasExtra = false - var extra: Byte = 0 - if (type.toInt() and 0x80 != 0) { - type = (type.toInt() and 0x7F).toByte() - hasExtra = true - extra = S8.read(buf) - } - val t = type.toInt() - val payload: BattleMessageArgPayload = - when { - t == 5 -> StringArgPayload(Utf16LeNullTerminated.read(buf)) - t == 28 -> EmptyArgPayload - t == 30 -> LongArgPayload(S64LE.read(buf)) - t == 9 || t == 10 || t == 17 -> IntArgPayload(S32LE.read(buf)) - t == 18 -> StringArgPayload(Utf16LeNullTerminated.read(buf)) - else -> { - val n = U8.read(buf) - ShortListArgPayload((0 until n).map { S16LE.read(buf) }) - } - } - return BattleMessageArg(id, type, hasExtra, extra, payload) + override fun read(buf: ReadBuffer): BattleMessageArg { + val id = S8.read(buf) + var type = S8.read(buf) + var hasExtra = false + var extra: Byte = 0 + if (type.toInt() and 0x80 != 0) { + type = (type.toInt() and 0x7F).toByte() + hasExtra = true + extra = S8.read(buf) } - - override fun write(buf: WriteBuffer, value: BattleMessageArg) { - S8.write(buf, value.id) - val rawType = if (value.hasExtra) (value.type.toInt() or 0x80).toByte() else value.type - S8.write(buf, rawType) - if (value.hasExtra) S8.write(buf, value.extra) - val t = value.type.toInt() + val t = type.toInt() + val payload: BattleMessageArgPayload = when { - t == 5 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value) - t == 28 -> {} - t == 30 -> S64LE.write(buf, (value.payload as LongArgPayload).value) - t == 9 || t == 10 || t == 17 -> S32LE.write(buf, (value.payload as IntArgPayload).value) - t == 18 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value) - else -> { - val values = (value.payload as ShortListArgPayload).values - U8.write(buf, values.size) - for (s in values) S16LE.write(buf, s) - } + t == 5 -> StringArgPayload(Utf16LeNullTerminated.read(buf)) + t == 28 -> EmptyArgPayload + t == 30 -> LongArgPayload(S64LE.read(buf)) + t == 9 || t == 10 || t == 17 -> IntArgPayload(S32LE.read(buf)) + t == 18 -> StringArgPayload(Utf16LeNullTerminated.read(buf)) + else -> { + val n = U8.read(buf) + ShortListArgPayload((0 until n).map { S16LE.read(buf) }) + } } + return BattleMessageArg(id, type, hasExtra, extra, payload) + } + + override fun write(buf: WriteBuffer, value: BattleMessageArg) { + S8.write(buf, value.id) + val rawType = if (value.hasExtra) (value.type.toInt() or 0x80).toByte() else value.type + S8.write(buf, rawType) + if (value.hasExtra) S8.write(buf, value.extra) + val t = value.type.toInt() + when { + t == 5 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value) + t == 28 -> {} + t == 30 -> S64LE.write(buf, (value.payload as LongArgPayload).value) + t == 9 || t == 10 || t == 17 -> S32LE.write(buf, (value.payload as IntArgPayload).value) + t == 18 -> Utf16LeNullTerminated.write(buf, (value.payload as StringArgPayload).value) + else -> { + val values = (value.payload as ShortListArgPayload).values + U8.write(buf, values.size) + for (s in values) S16LE.write(buf, s) + } } + } } sealed class BattleSerializedEntry @@ -91,75 +91,76 @@ internal object EmptyCreatureDataEntry : BattleSerializedEntry() internal val BattleSerializedEntryCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): BattleSerializedEntry { - return when (val tag = S8.read(buf).toInt()) { - -1 -> NullSerializedEntry - 0 -> { - val value = S32LE.read(buf) - val n = U8.read(buf) - CreatureDataEntry(value, (0 until n).map { BattleMessageArgCodec.read(buf) }) - } + override fun read(buf: ReadBuffer): BattleSerializedEntry { + return when (val tag = S8.read(buf).toInt()) { + -1 -> NullSerializedEntry + 0 -> { + val value = S32LE.read(buf) + val n = U8.read(buf) + CreatureDataEntry(value, (0 until n).map { BattleMessageArgCodec.read(buf) }) + } - 1 -> { - val v = S8.read(buf) - val n = U8.read(buf) - CreatureMovesEntry(v, (0 until n).map { S16LE.read(buf) }) - } + 1 -> { + val v = S8.read(buf) + val n = U8.read(buf) + CreatureMovesEntry(v, (0 until n).map { S16LE.read(buf) }) + } - 2 -> { - val moveId = S16LE.read(buf) - val a = S8.read(buf) - val b = S8.read(buf) - MoveAnimationEntry(a, b, moveId) - } + 2 -> { + val moveId = S16LE.read(buf) + val a = S8.read(buf) + val b = S8.read(buf) + MoveAnimationEntry(a, b, moveId) + } - 3 -> { - val a = S8.read(buf) - val typeId = S8.read(buf) - val x = S16LE.read(buf) - val y = S16LE.read(buf) - TextCreatureEntry(a, typeId, x, y) - } + 3 -> { + val a = S8.read(buf) + val typeId = S8.read(buf) + val x = S16LE.read(buf) + val y = S16LE.read(buf) + TextCreatureEntry(a, typeId, x, y) + } - else -> EmptyCreatureDataEntry - } + else -> EmptyCreatureDataEntry } + } - override fun write(buf: WriteBuffer, value: BattleSerializedEntry) { - when (value) { - is NullSerializedEntry -> S8.write(buf, (-1).toByte()) - is CreatureDataEntry -> { - S8.write(buf, 0) - S32LE.write(buf, value.value) - U8.write(buf, value.args.size) - for (a in value.args) BattleMessageArgCodec.write(buf, a) - } + override fun write(buf: WriteBuffer, value: BattleSerializedEntry) { + when (value) { + is NullSerializedEntry -> S8.write(buf, (-1).toByte()) + is CreatureDataEntry -> { + S8.write(buf, 0) + S32LE.write(buf, value.value) + U8.write(buf, value.args.size) + for (a in value.args) BattleMessageArgCodec.write(buf, a) + } - is CreatureMovesEntry -> { - S8.write(buf, 1) - S8.write(buf, value.value) - U8.write(buf, value.moves.size) - for (m in value.moves) S16LE.write(buf, m) - } + is CreatureMovesEntry -> { + S8.write(buf, 1) + S8.write(buf, value.value) + U8.write(buf, value.moves.size) + for (m in value.moves) S16LE.write(buf, m) + } - is MoveAnimationEntry -> { - S8.write(buf, 2) - S16LE.write(buf, value.moveId) - S8.write(buf, value.a) - S8.write(buf, value.b) - } + is MoveAnimationEntry -> { + S8.write(buf, 2) + S16LE.write(buf, value.moveId) + S8.write(buf, value.a) + S8.write(buf, value.b) + } - is TextCreatureEntry -> { - S8.write(buf, 3) - S8.write(buf, value.a) - S8.write(buf, value.typeId) - S16LE.write(buf, value.x) - S16LE.write(buf, value.y) - } + is TextCreatureEntry -> { + S8.write(buf, 3) + S8.write(buf, value.a) + S8.write(buf, value.typeId) + S16LE.write(buf, value.x) + S16LE.write(buf, value.y) + } - is EmptyCreatureDataEntry -> throw MalformedPacketException("cannot encode default battle entry") - } + is EmptyCreatureDataEntry -> + throw MalformedPacketException("cannot encode default battle entry") } + } } data class BattleBulkStatePacket( @@ -173,14 +174,14 @@ data class BattleBulkStatePacket( ) object BattleBulkStatePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleBulkStatePacket { - val phase = field(S8) { it.phase } - val firstGroup = field(BattleSerializedEntryCodec.listPrefixed(U8)) { it.firstGroup } - val secondGroup = field(BattleSerializedEntryCodec.listPrefixed(U8)) { it.secondGroup } - val valueA = field(S32LE) { it.valueA } - val valueB = field(S32LE) { it.valueB } - val flag = field(S8) { it.flag } - val thirdGroup = field(BattleSerializedEntryCodec.listPrefixed(U8)) { it.thirdGroup } - return BattleBulkStatePacket(phase, firstGroup, secondGroup, valueA, valueB, flag, thirdGroup) - } + override fun CodecScope.body(): BattleBulkStatePacket { + val phase = field(S8) { it.phase } + val firstGroup = field(BattleSerializedEntryCodec.listPrefixed(U8)) { it.firstGroup } + val secondGroup = field(BattleSerializedEntryCodec.listPrefixed(U8)) { it.secondGroup } + val valueA = field(S32LE) { it.valueA } + val valueB = field(S32LE) { it.valueB } + val flag = field(S8) { it.flag } + val thirdGroup = field(BattleSerializedEntryCodec.listPrefixed(U8)) { it.thirdGroup } + return BattleBulkStatePacket(phase, firstGroup, secondGroup, valueA, valueB, flag, thirdGroup) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleCancelRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleCancelRequestPacket.kt index 04de2cd..7b421f4 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleCancelRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleCancelRequestPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class BattleCancelRequestPacket object BattleCancelRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleCancelRequestPacket { - return BattleCancelRequestPacket() - } + override fun CodecScope.body(): BattleCancelRequestPacket { + return BattleCancelRequestPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChallengeRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChallengeRequestPacket.kt index a41bb68..5b27da5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChallengeRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChallengeRequestPacket.kt @@ -12,70 +12,70 @@ data class BattleChallengeRequestPacket( val ruleParam: Short, val extraRule: ByteArray?, ) { - override fun equals(other: Any?): Boolean = - other is BattleChallengeRequestPacket && - flags == other.flags && - entryKindId == other.entryKindId && - battleFormat == other.battleFormat && - levelCap == other.levelCap && - allowedSpecies == other.allowedSpecies && - ruleSet == other.ruleSet && - ruleParam == other.ruleParam && - (extraRule?.contentEquals(other.extraRule ?: ByteArray(0)) ?: (other.extraRule == null)) + override fun equals(other: Any?): Boolean = + other is BattleChallengeRequestPacket && + flags == other.flags && + entryKindId == other.entryKindId && + battleFormat == other.battleFormat && + levelCap == other.levelCap && + allowedSpecies == other.allowedSpecies && + ruleSet == other.ruleSet && + ruleParam == other.ruleParam && + (extraRule?.contentEquals(other.extraRule ?: ByteArray(0)) ?: (other.extraRule == null)) - override fun hashCode(): Int { - var r = flags.toInt() - r = r * 31 + entryKindId - r = r * 31 + battleFormat - r = r * 31 + levelCap - r = r * 31 + allowedSpecies.hashCode() - r = r * 31 + ruleSet - r = r * 31 + ruleParam - r = r * 31 + (extraRule?.contentHashCode() ?: 0) - return r - } + override fun hashCode(): Int { + var r = flags.toInt() + r = r * 31 + entryKindId + r = r * 31 + battleFormat + r = r * 31 + levelCap + r = r * 31 + allowedSpecies.hashCode() + r = r * 31 + ruleSet + r = r * 31 + ruleParam + r = r * 31 + (extraRule?.contentHashCode() ?: 0) + return r + } } private val ExtraRuleBytes: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object BattleChallengeRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleChallengeRequestPacket { - val flags = field(S8) { it.flags } - val entryKindId = field(S8) { it.entryKindId } - val battleFormat = field(S8) { it.battleFormat } - val levelCap = field(S16LE) { it.levelCap } - val allowedSpecies = field(S16LE.listPrefixed(U8)) { it.allowedSpecies } - val ruleSet = field(S8) { it.ruleSet } - val ruleParam = field(S16LE) { it.ruleParam } - val present = field(U8) { if (it.extraRule != null) 1 else 0 } - val extraRule = - if (present != 0) { - field(ExtraRuleBytes) { - it.extraRule ?: throw MalformedPacketException("extraRule required") - } - } else { - null - } - return BattleChallengeRequestPacket( - flags, - entryKindId, - battleFormat, - levelCap, - allowedSpecies, - ruleSet, - ruleParam, - extraRule, - ) - } + override fun CodecScope.body(): BattleChallengeRequestPacket { + val flags = field(S8) { it.flags } + val entryKindId = field(S8) { it.entryKindId } + val battleFormat = field(S8) { it.battleFormat } + val levelCap = field(S16LE) { it.levelCap } + val allowedSpecies = field(S16LE.listPrefixed(U8)) { it.allowedSpecies } + val ruleSet = field(S8) { it.ruleSet } + val ruleParam = field(S16LE) { it.ruleParam } + val present = field(U8) { if (it.extraRule != null) 1 else 0 } + val extraRule = + if (present != 0) { + field(ExtraRuleBytes) { + it.extraRule ?: throw MalformedPacketException("extraRule required") + } + } else { + null + } + return BattleChallengeRequestPacket( + flags, + entryKindId, + battleFormat, + levelCap, + allowedSpecies, + ruleSet, + ruleParam, + extraRule, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChatMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChatMessagePacket.kt index 0156000..7f940f8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChatMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleChatMessagePacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class BattleChatMessagePacket(val channelOrSlot: Byte, val message: String) object BattleChatMessagePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleChatMessagePacket { - val channelOrSlot = field(S8) { it.channelOrSlot } - val message = field(Utf16LeNullTerminated) { it.message } - return BattleChatMessagePacket(channelOrSlot, message) - } + override fun CodecScope.body(): BattleChatMessagePacket { + val channelOrSlot = field(S8) { it.channelOrSlot } + val message = field(Utf16LeNullTerminated) { it.message } + return BattleChatMessagePacket(channelOrSlot, message) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleControlBytesPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleControlBytesPacket.kt index 33195bc..28e194b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleControlBytesPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleControlBytesPacket.kt @@ -7,17 +7,17 @@ import de.fiereu.bytecodec.fixedBytes data class BattleControlBytesPacket( val controlBytes: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is BattleControlBytesPacket && controlBytes.contentEquals(other.controlBytes) + override fun equals(other: Any?): Boolean = + other is BattleControlBytesPacket && controlBytes.contentEquals(other.controlBytes) - override fun hashCode(): Int = controlBytes.contentHashCode() + override fun hashCode(): Int = controlBytes.contentHashCode() } private val ControlBytes = fixedBytes(3) object BattleControlBytesPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleControlBytesPacket { - val controlBytes = field(ControlBytes) { it.controlBytes } - return BattleControlBytesPacket(controlBytes) - } + override fun CodecScope.body(): BattleControlBytesPacket { + val controlBytes = field(ControlBytes) { it.controlBytes } + return BattleControlBytesPacket(controlBytes) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleDisconnectMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleDisconnectMessagePacket.kt index 0591ced..1af07b1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleDisconnectMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleDisconnectMessagePacket.kt @@ -15,28 +15,32 @@ data class MessageArg( internal val MessageArgCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): MessageArg { - val argId = field(S8) { it.argId } - val rawType = field(U8) { if (it.hasExtra) it.type or 128 else it.type } - val hasExtra = rawType and 128 != 0 - val type = if (hasExtra) rawType and 127 else rawType - val extra = if (hasExtra) field(S8) { it.extra } else 0 - var longValue: Long? = null - var intValue: Int? = null - var stringValue: String? = null - var shortValues: List? = null - when (type) { - 28 -> {} - 30 -> longValue = field(S64LE) { it.longValue!! } - 9, 10, 17 -> intValue = field(S32LE) { it.intValue!! } - 5, 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! } - else -> { - val count = field(U8) { it.shortValues!!.size } - shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } } - } - } - return MessageArg(argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues) + override fun CodecScope.body(): MessageArg { + val argId = field(S8) { it.argId } + val rawType = field(U8) { if (it.hasExtra) it.type or 128 else it.type } + val hasExtra = rawType and 128 != 0 + val type = if (hasExtra) rawType and 127 else rawType + val extra = if (hasExtra) field(S8) { it.extra } else 0 + var longValue: Long? = null + var intValue: Int? = null + var stringValue: String? = null + var shortValues: List? = null + when (type) { + 28 -> {} + 30 -> longValue = field(S64LE) { it.longValue!! } + 9, + 10, + 17 -> intValue = field(S32LE) { it.intValue!! } + 5, + 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! } + else -> { + val count = field(U8) { it.shortValues!!.size } + shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } } + } } + return MessageArg( + argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues) + } } data class BattleDisconnectMessagePacket( @@ -45,10 +49,10 @@ data class BattleDisconnectMessagePacket( ) object BattleDisconnectMessagePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleDisconnectMessagePacket { - val reason = field(S8) { it.reason } - val count = field(U8) { it.args.size } - val args = (0 until count).map { i -> field(MessageArgCodec) { it.args[i] } } - return BattleDisconnectMessagePacket(reason, args) - } + override fun CodecScope.body(): BattleDisconnectMessagePacket { + val reason = field(S8) { it.reason } + val count = field(U8) { it.args.size } + val args = (0 until count).map { i -> field(MessageArgCodec) { it.args[i] } } + return BattleDisconnectMessagePacket(reason, args) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEmptyEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEmptyEventPacket.kt index c104b9f..5eb130a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEmptyEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEmptyEventPacket.kt @@ -8,7 +8,7 @@ data class BattleEmptyEventPacket( ) object BattleEmptyEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleEmptyEventPacket { - return BattleEmptyEventPacket() - } + override fun CodecScope.body(): BattleEmptyEventPacket { + return BattleEmptyEventPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEndDisconnectPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEndDisconnectPacket.kt index c64cdc2..5e9344f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEndDisconnectPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEndDisconnectPacket.kt @@ -9,8 +9,8 @@ data class BattleEndDisconnectPacket( ) object BattleEndDisconnectPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleEndDisconnectPacket { - val reason = field(S8) { it.reason } - return BattleEndDisconnectPacket(reason) - } + override fun CodecScope.body(): BattleEndDisconnectPacket { + val reason = field(S8) { it.reason } + return BattleEndDisconnectPacket(reason) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityActionEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityActionEventPacket.kt index 3524997..3c65a08 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityActionEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityActionEventPacket.kt @@ -10,9 +10,9 @@ data class BattleEntityActionEventPacket( ) object BattleEntityActionEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleEntityActionEventPacket { - val sourceId = field(S64LE) { it.sourceId } - val targetId = field(S64LE) { it.targetId } - return BattleEntityActionEventPacket(sourceId, targetId) - } + override fun CodecScope.body(): BattleEntityActionEventPacket { + val sourceId = field(S64LE) { it.sourceId } + val targetId = field(S64LE) { it.targetId } + return BattleEntityActionEventPacket(sourceId, targetId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityDeltaPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityDeltaPacket.kt index 9e7ca08..8337f18 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityDeltaPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityDeltaPacket.kt @@ -46,90 +46,91 @@ data class BattleEntityDeltaPacket( ) object BattleEntityDeltaPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleEntityDeltaPacket { - val entityId = field(S64LE) { it.entityId } - val fieldMask = field(S32LE) { it.fieldMask } - val m = fieldMask + override fun CodecScope.body(): BattleEntityDeltaPacket { + val entityId = field(S64LE) { it.entityId } + val fieldMask = field(S32LE) { it.fieldMask } + val m = fieldMask - val experienceLevel = if (m and 1 != 0) field(S8) { it.experienceLevel!! } else null - val experiencePoints = if (m and 1 != 0) field(S32LE) { it.experiencePoints!! } else null - val statValues = if (m and 2 != 0) field(S16LE.repeat(6)) { it.statValues!! } else null - val moveSlots = if (m and 4 != 0) field(MoveSlotCodec.repeat(4)) { it.moveSlots!! } else null - val ppUps = if (m and 4 != 0) field(S8) { it.ppUps!! } else null - val currentHp = if (m and 8 != 0) field(S16LE) { it.currentHp!! } else null - val faintFlag = if (m and 16 != 0) field(S8) { it.faintFlag!! } else null - val speciesId = if (m and 32 != 0) field(S16LE) { it.speciesId!! } else null - val forme = if (m and 32 != 0) field(S8) { it.forme!! } else null - val listType = if (m and 64 != 0) field(S8) { it.listType!! } else null - val sortKey = if (m and 64 != 0) field(S16LE) { it.sortKey!! } else null - val evValues = if (m and 128 != 0) field(S16LE.repeat(6)) { it.evValues!! } else null - val level = if (m and 256 != 0) field(S16LE) { it.level!! } else null - val happiness = if (m and 512 != 0) field(S16LE) { it.happiness!! } else null - val shininessSeed = if (m and 1024 != 0) field(S32LE) { it.shininessSeed!! } else null - val experience = if (m and 1024 != 0) field(S32LE) { it.experience!! } else null - val flagA = if (m and 1024 != 0) field(S8) { it.flagA!! } else null - val flagB = if (m and 1024 != 0) field(S8) { it.flagB!! } else null - val encounterType = if (m and 1024 != 0) field(S8) { it.encounterType!! } else null - val statusFlagsValue = if (m and 2048 != 0) field(S16LE) { it.statusFlagsValue!! } else null - val warnA = if (m and 4096 != 0) field(S16LE) { it.warnA!! } else null - val warnB = if (m and 4096 != 0) field(S16LE) { it.warnB!! } else null - val natureId = if (m and 8192 != 0) field(S8) { it.natureId!! } else null - val ribbons = if (m and 16384 != 0) field(S64LE) { it.ribbons!! } else null - val packedIvs = if (m and 2097152 != 0) field(S32LE) { it.packedIvs!! } else null + val experienceLevel = if (m and 1 != 0) field(S8) { it.experienceLevel!! } else null + val experiencePoints = if (m and 1 != 0) field(S32LE) { it.experiencePoints!! } else null + val statValues = if (m and 2 != 0) field(S16LE.repeat(6)) { it.statValues!! } else null + val moveSlots = if (m and 4 != 0) field(MoveSlotCodec.repeat(4)) { it.moveSlots!! } else null + val ppUps = if (m and 4 != 0) field(S8) { it.ppUps!! } else null + val currentHp = if (m and 8 != 0) field(S16LE) { it.currentHp!! } else null + val faintFlag = if (m and 16 != 0) field(S8) { it.faintFlag!! } else null + val speciesId = if (m and 32 != 0) field(S16LE) { it.speciesId!! } else null + val forme = if (m and 32 != 0) field(S8) { it.forme!! } else null + val listType = if (m and 64 != 0) field(S8) { it.listType!! } else null + val sortKey = if (m and 64 != 0) field(S16LE) { it.sortKey!! } else null + val evValues = if (m and 128 != 0) field(S16LE.repeat(6)) { it.evValues!! } else null + val level = if (m and 256 != 0) field(S16LE) { it.level!! } else null + val happiness = if (m and 512 != 0) field(S16LE) { it.happiness!! } else null + val shininessSeed = if (m and 1024 != 0) field(S32LE) { it.shininessSeed!! } else null + val experience = if (m and 1024 != 0) field(S32LE) { it.experience!! } else null + val flagA = if (m and 1024 != 0) field(S8) { it.flagA!! } else null + val flagB = if (m and 1024 != 0) field(S8) { it.flagB!! } else null + val encounterType = if (m and 1024 != 0) field(S8) { it.encounterType!! } else null + val statusFlagsValue = if (m and 2048 != 0) field(S16LE) { it.statusFlagsValue!! } else null + val warnA = if (m and 4096 != 0) field(S16LE) { it.warnA!! } else null + val warnB = if (m and 4096 != 0) field(S16LE) { it.warnB!! } else null + val natureId = if (m and 8192 != 0) field(S8) { it.natureId!! } else null + val ribbons = if (m and 16384 != 0) field(S64LE) { it.ribbons!! } else null + val packedIvs = if (m and 2097152 != 0) field(S32LE) { it.packedIvs!! } else null - val effortValues = if (m and 32768 != 0) field(S16LE.repeat(4)) { it.effortValues!! } else null - val originalSpecies = if (m and 32768 != 0) field(S64LE) { it.originalSpecies!! } else null - val originalTrainerName = - if (m and 32768 != 0) field(Utf16LeNullTerminated) { it.originalTrainerName!! } else null - val originalTrainerId = if (m and 32768 != 0) field(S32LE) { it.originalTrainerId!! } else null + val effortValues = if (m and 32768 != 0) field(S16LE.repeat(4)) { it.effortValues!! } else null + val originalSpecies = if (m and 32768 != 0) field(S64LE) { it.originalSpecies!! } else null + val originalTrainerName = + if (m and 32768 != 0) field(Utf16LeNullTerminated) { it.originalTrainerName!! } else null + val originalTrainerId = if (m and 32768 != 0) field(S32LE) { it.originalTrainerId!! } else null - val shininessType = if (m and 65536 != 0) field(S8) { it.shininessType!! } else null - val gender = if (m and 131072 != 0) field(S8) { it.gender!! } else null - val ivs = if (m and 262144 != 0) field(S16LE.repeat(5)) { it.ivs!! } else null - val caughtBall = if (m and 524288 != 0) field(S8) { it.caughtBall!! } else null - val statusFlags2 = if (m and 1048576 != 0) field(S16LE) { it.statusFlags2!! } else null - val statusList = if (m and 4194304 != 0) field(S8.listPrefixed(U8)) { it.statusList!! } else null - val status = if (m and 8388608 != 0) field(S8) { it.status!! } else null + val shininessType = if (m and 65536 != 0) field(S8) { it.shininessType!! } else null + val gender = if (m and 131072 != 0) field(S8) { it.gender!! } else null + val ivs = if (m and 262144 != 0) field(S16LE.repeat(5)) { it.ivs!! } else null + val caughtBall = if (m and 524288 != 0) field(S8) { it.caughtBall!! } else null + val statusFlags2 = if (m and 1048576 != 0) field(S16LE) { it.statusFlags2!! } else null + val statusList = + if (m and 4194304 != 0) field(S8.listPrefixed(U8)) { it.statusList!! } else null + val status = if (m and 8388608 != 0) field(S8) { it.status!! } else null - return BattleEntityDeltaPacket( - entityId = entityId, - fieldMask = fieldMask, - experienceLevel = experienceLevel, - experiencePoints = experiencePoints, - statValues = statValues, - moveSlots = moveSlots, - ppUps = ppUps, - currentHp = currentHp, - faintFlag = faintFlag, - speciesId = speciesId, - forme = forme, - listType = listType, - sortKey = sortKey, - evValues = evValues, - level = level, - happiness = happiness, - shininessSeed = shininessSeed, - experience = experience, - flagA = flagA, - flagB = flagB, - encounterType = encounterType, - statusFlagsValue = statusFlagsValue, - warnA = warnA, - warnB = warnB, - natureId = natureId, - ribbons = ribbons, - packedIvs = packedIvs, - effortValues = effortValues, - originalSpecies = originalSpecies, - originalTrainerName = originalTrainerName, - originalTrainerId = originalTrainerId, - shininessType = shininessType, - gender = gender, - ivs = ivs, - caughtBall = caughtBall, - statusFlags2 = statusFlags2, - statusList = statusList, - status = status, - ) - } + return BattleEntityDeltaPacket( + entityId = entityId, + fieldMask = fieldMask, + experienceLevel = experienceLevel, + experiencePoints = experiencePoints, + statValues = statValues, + moveSlots = moveSlots, + ppUps = ppUps, + currentHp = currentHp, + faintFlag = faintFlag, + speciesId = speciesId, + forme = forme, + listType = listType, + sortKey = sortKey, + evValues = evValues, + level = level, + happiness = happiness, + shininessSeed = shininessSeed, + experience = experience, + flagA = flagA, + flagB = flagB, + encounterType = encounterType, + statusFlagsValue = statusFlagsValue, + warnA = warnA, + warnB = warnB, + natureId = natureId, + ribbons = ribbons, + packedIvs = packedIvs, + effortValues = effortValues, + originalSpecies = originalSpecies, + originalTrainerName = originalTrainerName, + originalTrainerId = originalTrainerId, + shininessType = shininessType, + gender = gender, + ivs = ivs, + caughtBall = caughtBall, + statusFlags2 = statusFlags2, + statusList = statusList, + status = status, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityMoveEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityMoveEventPacket.kt index 19d3ad2..bf12871 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityMoveEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEntityMoveEventPacket.kt @@ -10,12 +10,12 @@ data class BattleMoveDataEntry( private val BattleMoveDataEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleMoveDataEntry { - val entityId = field(S64LE) { it.entityId } - val value = field(S16LE) { it.value } - val actionCount = field(U8) { it.actionCount } - return BattleMoveDataEntry(entityId, value, actionCount) - } + override fun CodecScope.body(): BattleMoveDataEntry { + val entityId = field(S64LE) { it.entityId } + val value = field(S16LE) { it.value } + val actionCount = field(U8) { it.actionCount } + return BattleMoveDataEntry(entityId, value, actionCount) + } } data class BattleEntityMoveEventPacket( @@ -26,11 +26,11 @@ data class BattleEntityMoveEventPacket( ) object BattleEntityMoveEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleEntityMoveEventPacket { - val entityId = field(S64LE) { it.entityId } - val value = field(S16LE) { it.value } - val kind = field(S8) { it.kind } - val entries = field(BattleMoveDataEntryCodec.listPrefixed(U8)) { it.entries } - return BattleEntityMoveEventPacket(entityId, value, kind, entries) - } + override fun CodecScope.body(): BattleEntityMoveEventPacket { + val entityId = field(S64LE) { it.entityId } + val value = field(S16LE) { it.value } + val kind = field(S8) { it.kind } + val entries = field(BattleMoveDataEntryCodec.listPrefixed(U8)) { it.entries } + return BattleEntityMoveEventPacket(entityId, value, kind, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEnumPairEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEnumPairEventPacket.kt index 1c6db12..1459d63 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEnumPairEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleEnumPairEventPacket.kt @@ -11,10 +11,10 @@ data class BattleEnumPairEventPacket( ) object BattleEnumPairEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleEnumPairEventPacket { - val eventType = field(S8) { it.eventType } - val first = field(S8) { it.first } - val second = field(S8) { it.second } - return BattleEnumPairEventPacket(eventType, first, second) - } + override fun CodecScope.body(): BattleEnumPairEventPacket { + val eventType = field(S8) { it.eventType } + val first = field(S8) { it.first } + val second = field(S8) { it.second } + return BattleEnumPairEventPacket(eventType, first, second) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleLabeledMoveEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleLabeledMoveEventPacket.kt index cf1797f..cf98f04 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleLabeledMoveEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleLabeledMoveEventPacket.kt @@ -10,12 +10,12 @@ data class BattleLabeledMoveEntry( private val BattleLabeledMoveEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleLabeledMoveEntry { - val entityId = field(S64LE) { it.entityId } - val value = field(S16LE) { it.value } - val actionCount = field(U8) { it.actionCount } - return BattleLabeledMoveEntry(entityId, value, actionCount) - } + override fun CodecScope.body(): BattleLabeledMoveEntry { + val entityId = field(S64LE) { it.entityId } + val value = field(S16LE) { it.value } + val actionCount = field(U8) { it.actionCount } + return BattleLabeledMoveEntry(entityId, value, actionCount) + } } data class BattleLabeledMoveEventPacket( @@ -29,14 +29,14 @@ data class BattleLabeledMoveEventPacket( ) object BattleLabeledMoveEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleLabeledMoveEventPacket { - val byte1 = field(S8) { it.byte1 } - val byte2 = field(S8) { it.byte2 } - val value = field(S16LE) { it.value } - val byte3 = field(S8) { it.byte3 } - val short2 = field(S16LE) { it.short2 } - val label = field(Utf16LeNullTerminated) { it.label } - val entries = field(BattleLabeledMoveEntryCodec.listPrefixed(U8)) { it.entries } - return BattleLabeledMoveEventPacket(byte1, byte2, value, byte3, short2, label, entries) - } + override fun CodecScope.body(): BattleLabeledMoveEventPacket { + val byte1 = field(S8) { it.byte1 } + val byte2 = field(S8) { it.byte2 } + val value = field(S16LE) { it.value } + val byte3 = field(S8) { it.byte3 } + val short2 = field(S16LE) { it.short2 } + val label = field(Utf16LeNullTerminated) { it.label } + val entries = field(BattleLabeledMoveEntryCodec.listPrefixed(U8)) { it.entries } + return BattleLabeledMoveEventPacket(byte1, byte2, value, byte3, short2, label, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleListEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleListEventPacket.kt index 16c33cf..3e8104c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleListEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleListEventPacket.kt @@ -18,16 +18,16 @@ data class BattleListEventPacket( ) object BattleListEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleListEventPacket { - val kind = field(S8) { it.kind } - val value = field(S16LE) { it.value } - val subKind = field(S8) { it.subKind } - val detail = - if (subKind.toInt() == 4) { - val listType = field(S8) { it.detail!!.listType } - val detailValue = field(S16LE) { it.detail!!.value } - BattleListEventDetail(listType, detailValue) - } else null - return BattleListEventPacket(kind, value, subKind, detail) - } + override fun CodecScope.body(): BattleListEventPacket { + val kind = field(S8) { it.kind } + val value = field(S16LE) { it.value } + val subKind = field(S8) { it.subKind } + val detail = + if (subKind.toInt() == 4) { + val listType = field(S8) { it.detail!!.listType } + val detailValue = field(S16LE) { it.detail!!.value } + BattleListEventDetail(listType, detailValue) + } else null + return BattleListEventPacket(kind, value, subKind, detail) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveDisableUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveDisableUpdatePacket.kt index cce4aea..946aa95 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveDisableUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveDisableUpdatePacket.kt @@ -18,29 +18,29 @@ data class BattleMoveDisableUpdatePacket( private val BattleMoveDisableEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleMoveDisableEntry { - val present = field(Bool) { it.present } - return if (present) { - val disabled = field(Bool) { it.disabled } - val disableTurns = field(S16LE) { it.disableTurns } - BattleMoveDisableEntry(true, disabled, disableTurns) - } else { - BattleMoveDisableEntry(false, false, 0) - } + override fun CodecScope.body(): BattleMoveDisableEntry { + val present = field(Bool) { it.present } + return if (present) { + val disabled = field(Bool) { it.disabled } + val disableTurns = field(S16LE) { it.disableTurns } + BattleMoveDisableEntry(true, disabled, disableTurns) + } else { + BattleMoveDisableEntry(false, false, 0) } + } } private val BattleMoveDisableSideCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleMoveDisableSide { - val entries = field(BattleMoveDisableEntryCodec.listPrefixed(U8)) { it.entries } - return BattleMoveDisableSide(entries) - } + override fun CodecScope.body(): BattleMoveDisableSide { + val entries = field(BattleMoveDisableEntryCodec.listPrefixed(U8)) { it.entries } + return BattleMoveDisableSide(entries) + } } object BattleMoveDisableUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleMoveDisableUpdatePacket { - val sides = field(BattleMoveDisableSideCodec.repeat(2)) { it.sides } - return BattleMoveDisableUpdatePacket(sides) - } + override fun CodecScope.body(): BattleMoveDisableUpdatePacket { + val sides = field(BattleMoveDisableSideCodec.repeat(2)) { it.sides } + return BattleMoveDisableUpdatePacket(sides) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveListPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveListPacket.kt index 690cbf1..3015770 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveListPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveListPacket.kt @@ -13,15 +13,15 @@ data class BattleMoveAppearance( private val BattleMoveAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleMoveAppearance { - val name = field(Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val id = field(S32LE) { it.id } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return BattleMoveAppearance(name, gender, id, kind, palettePack, slots) - } + override fun CodecScope.body(): BattleMoveAppearance { + val name = field(Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val id = field(S32LE) { it.id } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return BattleMoveAppearance(name, gender, id, kind, palettePack, slots) + } } data class BattleMoveEntry( @@ -34,14 +34,14 @@ data class BattleMoveEntry( private val BattleMoveEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleMoveEntry { - val moveId = field(S32LE) { it.moveId } - val tier = field(S8) { it.tier } - val int1 = field(S32LE) { it.int1 } - val int2 = field(S32LE) { it.int2 } - val appearances = field(BattleMoveAppearanceCodec.listPrefixed(U8)) { it.appearances } - return BattleMoveEntry(moveId, tier, int1, int2, appearances) - } + override fun CodecScope.body(): BattleMoveEntry { + val moveId = field(S32LE) { it.moveId } + val tier = field(S8) { it.tier } + val int1 = field(S32LE) { it.int1 } + val int2 = field(S32LE) { it.int2 } + val appearances = field(BattleMoveAppearanceCodec.listPrefixed(U8)) { it.appearances } + return BattleMoveEntry(moveId, tier, int1, int2, appearances) + } } data class BattleMoveListPacket( @@ -51,10 +51,10 @@ data class BattleMoveListPacket( ) object BattleMoveListPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleMoveListPacket { - val actionId = field(S16LE) { it.actionId } - val slot = field(S8) { it.slot } - val moves = field(BattleMoveEntryCodec.listPrefixed(U8)) { it.moves } - return BattleMoveListPacket(actionId, slot, moves) - } + override fun CodecScope.body(): BattleMoveListPacket { + val actionId = field(S16LE) { it.actionId } + val slot = field(S8) { it.slot } + val moves = field(BattleMoveEntryCodec.listPrefixed(U8)) { it.moves } + return BattleMoveListPacket(actionId, slot, moves) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSelectionCancelPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSelectionCancelPacket.kt index c21b64b..41d3678 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSelectionCancelPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSelectionCancelPacket.kt @@ -9,8 +9,8 @@ data class BattleMoveSelectionCancelPacket( ) object BattleMoveSelectionCancelPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleMoveSelectionCancelPacket { - reserved(byte = 0) - return BattleMoveSelectionCancelPacket() - } + override fun CodecScope.body(): BattleMoveSelectionCancelPacket { + reserved(byte = 0) + return BattleMoveSelectionCancelPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSlotChoicePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSlotChoicePacket.kt index 1104000..0997a1c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSlotChoicePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveSlotChoicePacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S8 data class BattleMoveSlotChoicePacket(val moveSlotIndex: Byte) object BattleMoveSlotChoicePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleMoveSlotChoicePacket { - val moveSlotIndex = field(S8) { it.moveSlotIndex } - return BattleMoveSlotChoicePacket(moveSlotIndex) - } + override fun CodecScope.body(): BattleMoveSlotChoicePacket { + val moveSlotIndex = field(S8) { it.moveSlotIndex } + return BattleMoveSlotChoicePacket(moveSlotIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveTargetsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveTargetsPacket.kt index 35bec77..d739280 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveTargetsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveTargetsPacket.kt @@ -13,15 +13,15 @@ data class BattleTargetAppearance( private val BattleTargetAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleTargetAppearance { - val name = field(Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val id = field(S32LE) { it.id } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return BattleTargetAppearance(name, gender, id, kind, palettePack, slots) - } + override fun CodecScope.body(): BattleTargetAppearance { + val name = field(Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val id = field(S32LE) { it.id } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return BattleTargetAppearance(name, gender, id, kind, palettePack, slots) + } } data class BattleMoveTargetEntry( @@ -35,15 +35,15 @@ data class BattleMoveTargetEntry( private val BattleMoveTargetEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleMoveTargetEntry { - val entityId = field(S64LE) { it.entityId } - val weight = field(F32LE) { it.weight } - val short1 = field(S16LE) { it.short1 } - val int1 = field(S32LE) { it.int1 } - val int2 = field(S32LE) { it.int2 } - val appearance = field(BattleTargetAppearanceCodec) { it.appearance } - return BattleMoveTargetEntry(entityId, weight, short1, int1, int2, appearance) - } + override fun CodecScope.body(): BattleMoveTargetEntry { + val entityId = field(S64LE) { it.entityId } + val weight = field(F32LE) { it.weight } + val short1 = field(S16LE) { it.short1 } + val int1 = field(S32LE) { it.int1 } + val int2 = field(S32LE) { it.int2 } + val appearance = field(BattleTargetAppearanceCodec) { it.appearance } + return BattleMoveTargetEntry(entityId, weight, short1, int1, int2, appearance) + } } data class BattleMoveTargetsPacket( @@ -54,11 +54,11 @@ data class BattleMoveTargetsPacket( ) object BattleMoveTargetsPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleMoveTargetsPacket { - val actionId = field(S32LE) { it.actionId } - val slot = field(S8) { it.slot } - val tier = field(S8) { it.tier } - val targets = field(BattleMoveTargetEntryCodec.listPrefixed(U16LE)) { it.targets } - return BattleMoveTargetsPacket(actionId, slot, tier, targets) - } + override fun CodecScope.body(): BattleMoveTargetsPacket { + val actionId = field(S32LE) { it.actionId } + val slot = field(S8) { it.slot } + val tier = field(S8) { it.tier } + val targets = field(BattleMoveTargetEntryCodec.listPrefixed(U16LE)) { it.targets } + return BattleMoveTargetsPacket(actionId, slot, tier, targets) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveUsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveUsePacket.kt index 6b2dec9..88ee2dd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveUsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleMoveUsePacket.kt @@ -9,10 +9,10 @@ data class BattleMoveUsePacket( ) object BattleMoveUsePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleMoveUsePacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - val moveSlotIndex = field(S8) { it.moveSlotIndex } - val moveId = field(S16LE) { it.moveId } - return BattleMoveUsePacket(targetEntityId, moveSlotIndex, moveId) - } + override fun CodecScope.body(): BattleMoveUsePacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + val moveSlotIndex = field(S8) { it.moveSlotIndex } + val moveId = field(S16LE) { it.moveId } + return BattleMoveUsePacket(targetEntityId, moveSlotIndex, moveId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySlotSelectPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySlotSelectPacket.kt index 850a877..dabfbd9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySlotSelectPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySlotSelectPacket.kt @@ -12,10 +12,10 @@ data class BattlePartySlotSelectPacket( ) object BattlePartySlotSelectPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattlePartySlotSelectPacket { - val slotIndex = field(S16LE) { it.slotIndex } - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val contextId = field(S16LE) { it.contextId } - return BattlePartySlotSelectPacket(slotIndex, pokemonEntityId, contextId) - } + override fun CodecScope.body(): BattlePartySlotSelectPacket { + val slotIndex = field(S16LE) { it.slotIndex } + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val contextId = field(S16LE) { it.contextId } + return BattlePartySlotSelectPacket(slotIndex, pokemonEntityId, contextId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySwitchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySwitchPacket.kt index a4900aa..b07fc1e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySwitchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePartySwitchPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S64LE data class BattlePartySwitchPacket(val monsterEntityId: Long) object BattlePartySwitchPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattlePartySwitchPacket { - val monsterEntityId = field(S64LE) { it.monsterEntityId } - return BattlePartySwitchPacket(monsterEntityId) - } + override fun CodecScope.body(): BattlePartySwitchPacket { + val monsterEntityId = field(S64LE) { it.monsterEntityId } + return BattlePartySwitchPacket(monsterEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonSpritePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonSpritePacket.kt index 48f8998..20043c0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonSpritePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonSpritePacket.kt @@ -11,9 +11,9 @@ data class BattlePokemonSpritePacket( ) object BattlePokemonSpritePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattlePokemonSpritePacket { - val entityId = field(S64LE) { it.entityId } - val spriteId = field(S16LE) { it.spriteId } - return BattlePokemonSpritePacket(entityId, spriteId) - } + override fun CodecScope.body(): BattlePokemonSpritePacket { + val entityId = field(S64LE) { it.entityId } + val spriteId = field(S16LE) { it.spriteId } + return BattlePokemonSpritePacket(entityId, spriteId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonStatusPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonStatusPacket.kt index 5778fc2..7428e85 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonStatusPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePokemonStatusPacket.kt @@ -15,17 +15,17 @@ data class BattlePokemonStatusPacket( ) object BattlePokemonStatusPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattlePokemonStatusPacket { - val entityId = field(S64LE) { it.entityId } - val statusId = field(S8) { it.statusId } - val present = field(U8) { if (it.statusEffect != null) 1 else 0 } == 1 - val statusEffect = - if (present) { - val durationTurns = field(S32LE) { it.statusEffect!!.durationTurns } - val effectType = field(S8) { it.statusEffect!!.effectType } - val sourceSlot = field(S8) { it.statusEffect!!.sourceSlot } - BattleStatusEffectData(durationTurns, effectType, sourceSlot) - } else null - return BattlePokemonStatusPacket(entityId, statusId, statusEffect) - } + override fun CodecScope.body(): BattlePokemonStatusPacket { + val entityId = field(S64LE) { it.entityId } + val statusId = field(S8) { it.statusId } + val present = field(U8) { if (it.statusEffect != null) 1 else 0 } == 1 + val statusEffect = + if (present) { + val durationTurns = field(S32LE) { it.statusEffect!!.durationTurns } + val effectType = field(S8) { it.statusEffect!!.effectType } + val sourceSlot = field(S8) { it.statusEffect!!.sourceSlot } + BattleStatusEffectData(durationTurns, effectType, sourceSlot) + } else null + return BattlePokemonStatusPacket(entityId, statusId, statusEffect) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePromptSwitchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePromptSwitchPacket.kt index 62ca430..afbcda0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePromptSwitchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattlePromptSwitchPacket.kt @@ -9,8 +9,8 @@ data class BattlePromptSwitchPacket( ) object BattlePromptSwitchPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattlePromptSwitchPacket { - val enabled = field(Bool) { it.enabled } - return BattlePromptSwitchPacket(enabled) - } + override fun CodecScope.body(): BattlePromptSwitchPacket { + val enabled = field(Bool) { it.enabled } + return BattlePromptSwitchPacket(enabled) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleQueuedEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleQueuedEventPacket.kt index e85a577..56fce3e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleQueuedEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleQueuedEventPacket.kt @@ -7,16 +7,16 @@ import de.fiereu.bytecodec.S8 data class BattleQueuedEventPacket( val packed: Byte, ) { - val value: Byte - get() = (packed.toInt() and 0x7F).toByte() + val value: Byte + get() = (packed.toInt() and 0x7F).toByte() - val flag: Boolean - get() = (packed.toInt() and 0x80) != 0 + val flag: Boolean + get() = (packed.toInt() and 0x80) != 0 } object BattleQueuedEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleQueuedEventPacket { - val packed = field(S8) { it.packed } - return BattleQueuedEventPacket(packed) - } + override fun CodecScope.body(): BattleQueuedEventPacket { + val packed = field(S8) { it.packed } + return BattleQueuedEventPacket(packed) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingBulkPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingBulkPacket.kt index 43fdf3f..78038fa 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingBulkPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingBulkPacket.kt @@ -15,17 +15,17 @@ data class BattleRatingEntry( private val BattleRatingEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleRatingEntry { - val entityId = field(S64LE) { it.entityId } - val tier = field(S8) { it.tier } - val bracket = field(S8) { it.bracket } - val elo = field(F32LE) { it.elo } - val short1 = field(S16LE) { it.short1 } - val byte1 = field(S8) { it.byte1 } - val int1 = field(S32LE) { it.int1 } - val int2 = field(S32LE) { it.int2 } - return BattleRatingEntry(entityId, tier, bracket, elo, short1, byte1, int1, int2) - } + override fun CodecScope.body(): BattleRatingEntry { + val entityId = field(S64LE) { it.entityId } + val tier = field(S8) { it.tier } + val bracket = field(S8) { it.bracket } + val elo = field(F32LE) { it.elo } + val short1 = field(S16LE) { it.short1 } + val byte1 = field(S8) { it.byte1 } + val int1 = field(S32LE) { it.int1 } + val int2 = field(S32LE) { it.int2 } + return BattleRatingEntry(entityId, tier, bracket, elo, short1, byte1, int1, int2) + } } data class BattleRatingBulkPacket( @@ -33,8 +33,8 @@ data class BattleRatingBulkPacket( ) object BattleRatingBulkPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleRatingBulkPacket { - val ratings = field(BattleRatingEntryCodec.listPrefixed(U8)) { it.ratings } - return BattleRatingBulkPacket(ratings) - } + override fun CodecScope.body(): BattleRatingBulkPacket { + val ratings = field(BattleRatingEntryCodec.listPrefixed(U8)) { it.ratings } + return BattleRatingBulkPacket(ratings) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingUpdatePacket.kt index fadf9f2..c163890 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRatingUpdatePacket.kt @@ -14,15 +14,15 @@ data class BattleRatingUpdatePacket( ) object BattleRatingUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleRatingUpdatePacket { - val entityId = field(S64LE) { it.entityId } - val tier = field(S8) { it.tier } - val bracket = field(S8) { it.bracket } - val elo = field(F32LE) { it.elo } - val short1 = field(S16LE) { it.short1 } - val byte1 = field(S8) { it.byte1 } - val int1 = field(S32LE) { it.int1 } - val int2 = field(S32LE) { it.int2 } - return BattleRatingUpdatePacket(entityId, tier, bracket, elo, short1, byte1, int1, int2) - } + override fun CodecScope.body(): BattleRatingUpdatePacket { + val entityId = field(S64LE) { it.entityId } + val tier = field(S8) { it.tier } + val bracket = field(S8) { it.bracket } + val elo = field(F32LE) { it.elo } + val short1 = field(S16LE) { it.short1 } + val byte1 = field(S8) { it.byte1 } + val int1 = field(S32LE) { it.int1 } + val int2 = field(S32LE) { it.int2 } + return BattleRatingUpdatePacket(entityId, tier, bracket, elo, short1, byte1, int1, int2) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleReadyPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleReadyPacket.kt index 882646c..e6e1b07 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleReadyPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleReadyPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.PacketCodec data class BattleReadyPacket(val ready: Boolean) object BattleReadyPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleReadyPacket { - val ready = field(Bool) { it.ready } - return BattleReadyPacket(ready) - } + override fun CodecScope.body(): BattleReadyPacket { + val ready = field(Bool) { it.ready } + return BattleReadyPacket(ready) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRewardSelectPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRewardSelectPacket.kt index 10cf0e7..d896649 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRewardSelectPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleRewardSelectPacket.kt @@ -11,9 +11,9 @@ data class BattleRewardSelectPacket( ) object BattleRewardSelectPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleRewardSelectPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - val rewardIndex = field(S32LE) { it.rewardIndex } - return BattleRewardSelectPacket(targetEntityId, rewardIndex) - } + override fun CodecScope.body(): BattleRewardSelectPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + val rewardIndex = field(S32LE) { it.rewardIndex } + return BattleRewardSelectPacket(targetEntityId, rewardIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleScreenOpenPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleScreenOpenPacket.kt index 1f63763..98fcfb2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleScreenOpenPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleScreenOpenPacket.kt @@ -19,26 +19,35 @@ data class BattleRankingEntry( private val BattleRankingEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleRankingEntry { - val entityId = field(S64LE) { it.entityId } - val flag1 = field(S8) { it.flag1 } - val flag2 = field(S8) { it.flag2 } - val name = field(de.fiereu.bytecodec.Utf16LeNullTerminated) { it.name } - val value1 = field(S16LE) { it.value1 } - val genderId = field(S16LE) { it.genderId } - field(S8) { 0 } - val ribbons = field(S64LE) { it.ribbons } - val byte1 = field(S8) { it.byte1 } - val int1 = field(S32LE) { it.int1 } - val byte2 = field(S8) { it.byte2 } - val bool1 = field(Bool) { it.bool1 } - val bool2 = field(Bool) { it.bool2 } - field(S8) { 0 } - return BattleRankingEntry( - entityId, flag1, flag2, name, value1, genderId, ribbons, byte1, int1, byte2, bool1, - bool2 - ) - } + override fun CodecScope.body(): BattleRankingEntry { + val entityId = field(S64LE) { it.entityId } + val flag1 = field(S8) { it.flag1 } + val flag2 = field(S8) { it.flag2 } + val name = field(de.fiereu.bytecodec.Utf16LeNullTerminated) { it.name } + val value1 = field(S16LE) { it.value1 } + val genderId = field(S16LE) { it.genderId } + field(S8) { 0 } + val ribbons = field(S64LE) { it.ribbons } + val byte1 = field(S8) { it.byte1 } + val int1 = field(S32LE) { it.int1 } + val byte2 = field(S8) { it.byte2 } + val bool1 = field(Bool) { it.bool1 } + val bool2 = field(Bool) { it.bool2 } + field(S8) { 0 } + return BattleRankingEntry( + entityId, + flag1, + flag2, + name, + value1, + genderId, + ribbons, + byte1, + int1, + byte2, + bool1, + bool2) + } } data class BattleTierUpdate( @@ -49,13 +58,13 @@ data class BattleTierUpdate( private val BattleTierUpdateCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleTierUpdate { - val tierIndex = field(S8) { it.tierIndex } - val unlocked = field(Bool) { it.unlocked } - val expiry = field(S64LE) { it.expiry } - field(S64LE) { 0L } - return BattleTierUpdate(tierIndex, unlocked, expiry) - } + override fun CodecScope.body(): BattleTierUpdate { + val tierIndex = field(S8) { it.tierIndex } + val unlocked = field(Bool) { it.unlocked } + val expiry = field(S64LE) { it.expiry } + field(S64LE) { 0L } + return BattleTierUpdate(tierIndex, unlocked, expiry) + } } data class BattleMoveTarget( @@ -71,34 +80,34 @@ data class BattleMoveTarget( private val BattleMoveTargetCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleMoveTarget { - val targetType = field(S8) { it.targetType } - return when (targetType.toInt()) { - 0 -> { - val short1 = field(S16LE) { it.short1 } - val short2 = field(S16LE) { it.short2 } - val short3 = field(S16LE) { it.short3 } - BattleMoveTarget(targetType, short1, short2, short3, 0, 0, false, false) - } + override fun CodecScope.body(): BattleMoveTarget { + val targetType = field(S8) { it.targetType } + return when (targetType.toInt()) { + 0 -> { + val short1 = field(S16LE) { it.short1 } + val short2 = field(S16LE) { it.short2 } + val short3 = field(S16LE) { it.short3 } + BattleMoveTarget(targetType, short1, short2, short3, 0, 0, false, false) + } - 1 -> { - val short1 = field(S16LE) { it.short1 } - field(S8) { 0 } - val byte1 = field(S8) { it.byte1 } - val byte2 = field(S8) { it.byte2 } - val flag1 = field(Bool) { it.flag1 } - val flag2 = field(Bool) { it.flag2 } - val short2 = field(S16LE) { it.short2 } - BattleMoveTarget(targetType, short1, short2, 0, byte1, byte2, flag1, flag2) - } + 1 -> { + val short1 = field(S16LE) { it.short1 } + field(S8) { 0 } + val byte1 = field(S8) { it.byte1 } + val byte2 = field(S8) { it.byte2 } + val flag1 = field(Bool) { it.flag1 } + val flag2 = field(Bool) { it.flag2 } + val short2 = field(S16LE) { it.short2 } + BattleMoveTarget(targetType, short1, short2, 0, byte1, byte2, flag1, flag2) + } - else -> { - val short1 = field(S16LE) { it.short1 } - val short2 = field(S16LE) { it.short2 } - BattleMoveTarget(targetType, short1, short2, 0, 0, 0, false, false) - } - } + else -> { + val short1 = field(S16LE) { it.short1 } + val short2 = field(S16LE) { it.short2 } + BattleMoveTarget(targetType, short1, short2, 0, 0, 0, false, false) + } } + } } data class BattleSelectablePokemon( @@ -113,16 +122,16 @@ data class BattleSelectablePokemon( private val BattleSelectablePokemonCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleSelectablePokemon { - val int1 = field(S32LE) { it.int1 } - val int2 = field(S32LE) { it.int2 } - val short1 = field(S16LE) { it.short1 } - val short2 = field(S16LE) { it.short2 } - val tierIndex = field(S8) { it.tierIndex } - val targetsA = field(BattleMoveTargetCodec.listPrefixed(U8)) { it.targetsA } - val targetsB = field(BattleMoveTargetCodec.listPrefixed(U8)) { it.targetsB } - return BattleSelectablePokemon(int1, int2, short1, short2, tierIndex, targetsA, targetsB) - } + override fun CodecScope.body(): BattleSelectablePokemon { + val int1 = field(S32LE) { it.int1 } + val int2 = field(S32LE) { it.int2 } + val short1 = field(S16LE) { it.short1 } + val short2 = field(S16LE) { it.short2 } + val tierIndex = field(S8) { it.tierIndex } + val targetsA = field(BattleMoveTargetCodec.listPrefixed(U8)) { it.targetsA } + val targetsB = field(BattleMoveTargetCodec.listPrefixed(U8)) { it.targetsB } + return BattleSelectablePokemon(int1, int2, short1, short2, tierIndex, targetsA, targetsB) + } } data class BattleStorageItem( @@ -138,19 +147,18 @@ data class BattleStorageItem( private val BattleStorageItemCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleStorageItem { - val typeByte = field(S8) { it.typeByte } - val short1 = field(S16LE) { it.short1 } - val short2 = field(S16LE) { it.short2 } - val short3 = field(S16LE) { it.short3 } - val short4 = field(S16LE) { it.short4 } - val byte1 = field(S8) { it.byte1 } - val pokemonByte = field(S8) { it.pokemonByte } - val boxByte = field(S8) { it.boxByte } - return BattleStorageItem( - typeByte, short1, short2, short3, short4, byte1, pokemonByte, boxByte - ) - } + override fun CodecScope.body(): BattleStorageItem { + val typeByte = field(S8) { it.typeByte } + val short1 = field(S16LE) { it.short1 } + val short2 = field(S16LE) { it.short2 } + val short3 = field(S16LE) { it.short3 } + val short4 = field(S16LE) { it.short4 } + val byte1 = field(S8) { it.byte1 } + val pokemonByte = field(S8) { it.pokemonByte } + val boxByte = field(S8) { it.boxByte } + return BattleStorageItem( + typeByte, short1, short2, short3, short4, byte1, pokemonByte, boxByte) + } } data class BattleScreenOpenPacket( @@ -163,24 +171,23 @@ data class BattleScreenOpenPacket( ) object BattleScreenOpenPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleScreenOpenPacket { - val active = field(U8) { if (it.active) 1 else 0 } == 1 - if (!active) { - return BattleScreenOpenPacket( - false, false, emptyList(), emptyList(), emptyList(), emptyList() - ) - } - val wild = field(U8) { if (it.wild) 1 else 0 } == 1 - var participants = emptyList() - var tierUpdates = emptyList() - var pokemon = emptyList() - if (wild) { - participants = field(BattleRankingEntryCodec.listPrefixed(U8)) { it.participants } - } else { - tierUpdates = field(BattleTierUpdateCodec.listPrefixed(U8)) { it.tierUpdates } - pokemon = field(BattleSelectablePokemonCodec.listPrefixed(U8)) { it.pokemon } - } - val storageItems = field(BattleStorageItemCodec.listPrefixed(U8)) { it.storageItems } - return BattleScreenOpenPacket(active, wild, participants, tierUpdates, pokemon, storageItems) + override fun CodecScope.body(): BattleScreenOpenPacket { + val active = field(U8) { if (it.active) 1 else 0 } == 1 + if (!active) { + return BattleScreenOpenPacket( + false, false, emptyList(), emptyList(), emptyList(), emptyList()) } + val wild = field(U8) { if (it.wild) 1 else 0 } == 1 + var participants = emptyList() + var tierUpdates = emptyList() + var pokemon = emptyList() + if (wild) { + participants = field(BattleRankingEntryCodec.listPrefixed(U8)) { it.participants } + } else { + tierUpdates = field(BattleTierUpdateCodec.listPrefixed(U8)) { it.tierUpdates } + pokemon = field(BattleSelectablePokemonCodec.listPrefixed(U8)) { it.pokemon } + } + val storageItems = field(BattleStorageItemCodec.listPrefixed(U8)) { it.storageItems } + return BattleScreenOpenPacket(active, wild, participants, tierUpdates, pokemon, storageItems) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSendOutActivePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSendOutActivePacket.kt index 41e4e30..8bf1ad2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSendOutActivePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSendOutActivePacket.kt @@ -22,27 +22,34 @@ data class BattleSendOutActivePacket( ) object BattleSendOutActivePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSendOutActivePacket { - val present = field(U8) { if (it.member != null) 1 else 0 } - if (present != 1) return BattleSendOutActivePacket(false, null) - val opponent = field(Bool) { it.opponent } - val entityIdA = field(S64LE) { it.member!!.entityIdA } - val entityIdB = field(S64LE) { it.member!!.entityIdB } - val entityIdC = field(S64LE) { it.member!!.entityIdC } - val speciesByte = field(S8) { it.member!!.speciesByte } - val nickname = if (!opponent) field(Utf16LeNullTerminated) { it.member!!.nickname } else "" - val ownerName = if (opponent) field(Utf16LeNullTerminated) { it.member!!.ownerName } else "" - val value = field(S32LE) { it.member!!.value } - val nameA = field(Utf16LeNullTerminated) { it.member!!.nameA } - val nameB = field(Utf16LeNullTerminated) { it.member!!.nameB } - val levelByte = field(S8) { it.member!!.levelByte } - val flag = field(Bool) { it.member!!.flag } - return BattleSendOutActivePacket( - opponent, - BattleSendOutMember( - entityIdA, entityIdB, entityIdC, speciesByte, nickname, ownerName, value, nameA, nameB, - levelByte, flag - ) - ) - } + override fun CodecScope.body(): BattleSendOutActivePacket { + val present = field(U8) { if (it.member != null) 1 else 0 } + if (present != 1) return BattleSendOutActivePacket(false, null) + val opponent = field(Bool) { it.opponent } + val entityIdA = field(S64LE) { it.member!!.entityIdA } + val entityIdB = field(S64LE) { it.member!!.entityIdB } + val entityIdC = field(S64LE) { it.member!!.entityIdC } + val speciesByte = field(S8) { it.member!!.speciesByte } + val nickname = if (!opponent) field(Utf16LeNullTerminated) { it.member!!.nickname } else "" + val ownerName = if (opponent) field(Utf16LeNullTerminated) { it.member!!.ownerName } else "" + val value = field(S32LE) { it.member!!.value } + val nameA = field(Utf16LeNullTerminated) { it.member!!.nameA } + val nameB = field(Utf16LeNullTerminated) { it.member!!.nameB } + val levelByte = field(S8) { it.member!!.levelByte } + val flag = field(Bool) { it.member!!.flag } + return BattleSendOutActivePacket( + opponent, + BattleSendOutMember( + entityIdA, + entityIdB, + entityIdC, + speciesByte, + nickname, + ownerName, + value, + nameA, + nameB, + levelByte, + flag)) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideAddPokemonPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideAddPokemonPacket.kt index b95b8f6..e83c4d5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideAddPokemonPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideAddPokemonPacket.kt @@ -20,32 +20,31 @@ data class BattleAddPokemon( private val BattleAddPokemonCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattleAddPokemon { - val flags = - field(U8) { - (if (it.slot.toInt() != 0) 4 else 0) or - (if (it.partyIndex.toInt() != -1) 8 else 0) or - (if (it.statusEffect != null) 16 else 0) - } - val entityId = field(S64LE) { it.entityId } - if (flags and 1 != 0) field(S64LE) { 0L } - val frontSpriteId = field(S16LE) { it.frontSpriteId } - val backSpriteId = field(S16LE) { it.backSpriteId } - val side = field(S8) { it.side } - if (flags and 2 != 0) field(S8) { 0 } - val slot = if (flags and 4 != 0) field(S8) { it.slot } else 0 - val partyIndex = if (flags and 8 != 0) field(S8) { it.partyIndex } else -1 - val statusEffect = - if (flags and 16 != 0) { - val durationTurns = field(S32LE) { it.statusEffect!!.durationTurns } - val effectType = field(S8) { it.statusEffect!!.effectType } - val sourceSlot = field(S8) { it.statusEffect!!.sourceSlot } - BattleAddStatusEffect(durationTurns, effectType, sourceSlot) - } else null - return BattleAddPokemon( - entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect - ) - } + override fun CodecScope.body(): BattleAddPokemon { + val flags = + field(U8) { + (if (it.slot.toInt() != 0) 4 else 0) or + (if (it.partyIndex.toInt() != -1) 8 else 0) or + (if (it.statusEffect != null) 16 else 0) + } + val entityId = field(S64LE) { it.entityId } + if (flags and 1 != 0) field(S64LE) { 0L } + val frontSpriteId = field(S16LE) { it.frontSpriteId } + val backSpriteId = field(S16LE) { it.backSpriteId } + val side = field(S8) { it.side } + if (flags and 2 != 0) field(S8) { 0 } + val slot = if (flags and 4 != 0) field(S8) { it.slot } else 0 + val partyIndex = if (flags and 8 != 0) field(S8) { it.partyIndex } else -1 + val statusEffect = + if (flags and 16 != 0) { + val durationTurns = field(S32LE) { it.statusEffect!!.durationTurns } + val effectType = field(S8) { it.statusEffect!!.effectType } + val sourceSlot = field(S8) { it.statusEffect!!.sourceSlot } + BattleAddStatusEffect(durationTurns, effectType, sourceSlot) + } else null + return BattleAddPokemon( + entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect) + } } data class BattleSideAddPokemonPacket( @@ -54,9 +53,9 @@ data class BattleSideAddPokemonPacket( ) object BattleSideAddPokemonPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSideAddPokemonPacket { - val side = field(S8) { it.side } - val pokemon = field(BattleAddPokemonCodec) { it.pokemon } - return BattleSideAddPokemonPacket(side, pokemon) - } + override fun CodecScope.body(): BattleSideAddPokemonPacket { + val side = field(S8) { it.side } + val pokemon = field(BattleAddPokemonCodec) { it.pokemon } + return BattleSideAddPokemonPacket(side, pokemon) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSidePartyPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSidePartyPacket.kt index ee5b53b..3ff945c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSidePartyPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSidePartyPacket.kt @@ -20,34 +20,33 @@ data class BattlePartyPokemon( private val BattlePartyPokemonCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): BattlePartyPokemon { - val flags = - field(U8) { - (if (false) 1 else 0) or - (if (false) 2 else 0) or - (if (it.slot.toInt() != 0) 4 else 0) or - (if (it.partyIndex.toInt() != -1) 8 else 0) or - (if (it.statusEffect != null) 16 else 0) - } - val entityId = field(S64LE) { it.entityId } - if (flags and 1 != 0) field(S64LE) { 0L } - val frontSpriteId = field(S16LE) { it.frontSpriteId } - val backSpriteId = field(S16LE) { it.backSpriteId } - val side = field(S8) { it.side } - if (flags and 2 != 0) field(S8) { 0 } - val slot = if (flags and 4 != 0) field(S8) { it.slot } else 0 - val partyIndex = if (flags and 8 != 0) field(S8) { it.partyIndex } else -1 - val statusEffect = - if (flags and 16 != 0) { - val durationTurns = field(S32LE) { it.statusEffect!!.durationTurns } - val effectType = field(S8) { it.statusEffect!!.effectType } - val sourceSlot = field(S8) { it.statusEffect!!.sourceSlot } - BattlePartyStatusEffect(durationTurns, effectType, sourceSlot) - } else null - return BattlePartyPokemon( - entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect - ) - } + override fun CodecScope.body(): BattlePartyPokemon { + val flags = + field(U8) { + (if (false) 1 else 0) or + (if (false) 2 else 0) or + (if (it.slot.toInt() != 0) 4 else 0) or + (if (it.partyIndex.toInt() != -1) 8 else 0) or + (if (it.statusEffect != null) 16 else 0) + } + val entityId = field(S64LE) { it.entityId } + if (flags and 1 != 0) field(S64LE) { 0L } + val frontSpriteId = field(S16LE) { it.frontSpriteId } + val backSpriteId = field(S16LE) { it.backSpriteId } + val side = field(S8) { it.side } + if (flags and 2 != 0) field(S8) { 0 } + val slot = if (flags and 4 != 0) field(S8) { it.slot } else 0 + val partyIndex = if (flags and 8 != 0) field(S8) { it.partyIndex } else -1 + val statusEffect = + if (flags and 16 != 0) { + val durationTurns = field(S32LE) { it.statusEffect!!.durationTurns } + val effectType = field(S8) { it.statusEffect!!.effectType } + val sourceSlot = field(S8) { it.statusEffect!!.sourceSlot } + BattlePartyStatusEffect(durationTurns, effectType, sourceSlot) + } else null + return BattlePartyPokemon( + entityId, frontSpriteId, backSpriteId, side, slot, partyIndex, statusEffect) + } } data class BattleSidePartyPacket( @@ -57,10 +56,10 @@ data class BattleSidePartyPacket( ) object BattleSidePartyPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSidePartyPacket { - val side = field(S8) { it.side } - val replace = field(U8) { if (it.replace) 1 else 0 } == 1 - val pokemon = field(BattlePartyPokemonCodec.listPrefixed(U16LE)) { it.pokemon } - return BattleSidePartyPacket(side, replace, pokemon) - } + override fun CodecScope.body(): BattleSidePartyPacket { + val side = field(S8) { it.side } + val replace = field(U8) { if (it.replace) 1 else 0 } == 1 + val pokemon = field(BattlePartyPokemonCodec.listPrefixed(U16LE)) { it.pokemon } + return BattleSidePartyPacket(side, replace, pokemon) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideRemovePokemonPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideRemovePokemonPacket.kt index 6c23773..23efc17 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideRemovePokemonPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSideRemovePokemonPacket.kt @@ -11,9 +11,9 @@ data class BattleSideRemovePokemonPacket( ) object BattleSideRemovePokemonPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSideRemovePokemonPacket { - val side = field(S8) { it.side } - val entityId = field(S64LE) { it.entityId } - return BattleSideRemovePokemonPacket(side, entityId) - } + override fun CodecScope.body(): BattleSideRemovePokemonPacket { + val side = field(S8) { it.side } + val entityId = field(S64LE) { it.entityId } + return BattleSideRemovePokemonPacket(side, entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSimulationRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSimulationRequestPacket.kt index dba47ac..14d8b5b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSimulationRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSimulationRequestPacket.kt @@ -4,27 +4,28 @@ import de.fiereu.bytecodec.* private val SimulationConfigPayload: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val arr = ByteArray(buf.remaining()) - if (arr.isNotEmpty()) buf.readBytes(arr) - return arr - } + override fun read(buf: ReadBuffer): ByteArray { + val arr = ByteArray(buf.remaining()) + if (arr.isNotEmpty()) buf.readBytes(arr) + return arr + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } data class BattleSimulationRequestPacket(val simulationConfig: ByteArray) { - override fun equals(other: Any?): Boolean = - other is BattleSimulationRequestPacket && simulationConfig.contentEquals(other.simulationConfig) + override fun equals(other: Any?): Boolean = + other is BattleSimulationRequestPacket && + simulationConfig.contentEquals(other.simulationConfig) - override fun hashCode(): Int = simulationConfig.contentHashCode() + override fun hashCode(): Int = simulationConfig.contentHashCode() } object BattleSimulationRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSimulationRequestPacket { - val simulationConfig = field(SimulationConfigPayload) { it.simulationConfig } - return BattleSimulationRequestPacket(simulationConfig) - } + override fun CodecScope.body(): BattleSimulationRequestPacket { + val simulationConfig = field(SimulationConfigPayload) { it.simulationConfig } + return BattleSimulationRequestPacket(simulationConfig) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotActionPacket.kt index f3cb9be..5aa90ba 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotActionPacket.kt @@ -10,9 +10,9 @@ data class BattleSlotActionPacket( ) object BattleSlotActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSlotActionPacket { - val slotRefPacked = field(S8) { it.slotRefPacked } - val actionByte = field(S8) { it.actionByte } - return BattleSlotActionPacket(slotRefPacked, actionByte) - } + override fun CodecScope.body(): BattleSlotActionPacket { + val slotRefPacked = field(S8) { it.slotRefPacked } + val actionByte = field(S8) { it.actionByte } + return BattleSlotActionPacket(slotRefPacked, actionByte) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotAnimationResetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotAnimationResetPacket.kt index 0b5b85d..4d159ba 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotAnimationResetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotAnimationResetPacket.kt @@ -11,9 +11,9 @@ data class BattleSlotAnimationResetPacket( ) object BattleSlotAnimationResetPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSlotAnimationResetPacket { - val entityId = field(S64LE) { it.entityId } - val slot = field(S8) { it.slot } - return BattleSlotAnimationResetPacket(entityId, slot) - } + override fun CodecScope.body(): BattleSlotAnimationResetPacket { + val entityId = field(S64LE) { it.entityId } + val slot = field(S8) { it.slot } + return BattleSlotAnimationResetPacket(entityId, slot) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotEventEnumPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotEventEnumPacket.kt index 50b8a2e..b8cbbbd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotEventEnumPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotEventEnumPacket.kt @@ -10,9 +10,9 @@ data class BattleSlotEventEnumPacket( ) object BattleSlotEventEnumPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSlotEventEnumPacket { - val slot = field(S8) { it.slot } - val eventType = field(S8) { it.eventType } - return BattleSlotEventEnumPacket(slot, eventType) - } + override fun CodecScope.body(): BattleSlotEventEnumPacket { + val slot = field(S8) { it.slot } + val eventType = field(S8) { it.eventType } + return BattleSlotEventEnumPacket(slot, eventType) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotFlagEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotFlagEventPacket.kt index 1deb01d..70ba36d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotFlagEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotFlagEventPacket.kt @@ -12,10 +12,10 @@ data class BattleSlotFlagEventPacket( ) object BattleSlotFlagEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSlotFlagEventPacket { - val slot = field(S8) { it.slot } - val flag = field(Bool) { it.flag } - val immediate = field(Bool) { it.immediate } - return BattleSlotFlagEventPacket(slot, flag, immediate) - } + override fun CodecScope.body(): BattleSlotFlagEventPacket { + val slot = field(S8) { it.slot } + val flag = field(Bool) { it.flag } + val immediate = field(Bool) { it.immediate } + return BattleSlotFlagEventPacket(slot, flag, immediate) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotMoveEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotMoveEventPacket.kt index 29602a8..f32e343 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotMoveEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotMoveEventPacket.kt @@ -12,10 +12,10 @@ data class BattleSlotMoveEventPacket( ) object BattleSlotMoveEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSlotMoveEventPacket { - val slot = field(S8) { it.slot } - val moveType = field(S8) { it.moveType } - val resolved = field(Bool) { it.resolved } - return BattleSlotMoveEventPacket(slot, moveType, resolved) - } + override fun CodecScope.body(): BattleSlotMoveEventPacket { + val slot = field(S8) { it.slot } + val moveType = field(S8) { it.moveType } + val resolved = field(Bool) { it.resolved } + return BattleSlotMoveEventPacket(slot, moveType, resolved) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotSwitchEventPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotSwitchEventPacket.kt index 3e925f1..25ab69c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotSwitchEventPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSlotSwitchEventPacket.kt @@ -12,10 +12,10 @@ data class BattleSlotSwitchEventPacket( ) object BattleSlotSwitchEventPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSlotSwitchEventPacket { - val slot = field(S8) { it.slot } - val switchType = field(S8) { it.switchType } - val immediate = field(Bool) { it.immediate } - return BattleSlotSwitchEventPacket(slot, switchType, immediate) - } + override fun CodecScope.body(): BattleSlotSwitchEventPacket { + val slot = field(S8) { it.slot } + val switchType = field(S8) { it.switchType } + val immediate = field(Bool) { it.immediate } + return BattleSlotSwitchEventPacket(slot, switchType, immediate) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStartScenePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStartScenePacket.kt index f8e3368..2cbddcc 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStartScenePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStartScenePacket.kt @@ -12,10 +12,10 @@ data class BattleStartScenePacket( ) object BattleStartScenePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleStartScenePacket { - val battleType = field(S8) { it.battleType } - val doubleBattle = field(U8) { if (it.doubleBattle) 1 else 0 } == 1 - val perspective = field(S8) { it.perspective } - return BattleStartScenePacket(battleType, doubleBattle, perspective) - } + override fun CodecScope.body(): BattleStartScenePacket { + val battleType = field(S8) { it.battleType } + val doubleBattle = field(U8) { if (it.doubleBattle) 1 else 0 } == 1 + val perspective = field(S8) { it.perspective } + return BattleStartScenePacket(battleType, doubleBattle, perspective) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatCountersPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatCountersPacket.kt index 750b49e..c5b8688 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatCountersPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatCountersPacket.kt @@ -14,33 +14,33 @@ data class BattleStatCountersPacket( ) object BattleStatCountersPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleStatCountersPacket { - val entityId = field(S64LE, BattleStatCountersPacket::entityId) - val baseCounter = field(S32LE, BattleStatCountersPacket::baseCounter) - val flags = - field(U8) { - (if (it.counter1 != null) 1 else 0) or - (if (it.counter2 != null) 2 else 0) or - (if (it.counter3 != null) 4 else 0) or - (if (it.counter4 != null) 8 else 0) or - (if (it.counter5 != null) 16 else 0) or - (if (it.counter6 != null) 32 else 0) - } - val counter1 = if (flags and 1 != 0) field(S32LE) { it.counter1!! } else null - val counter2 = if (flags and 2 != 0) field(S32LE) { it.counter2!! } else null - val counter3 = if (flags and 4 != 0) field(S32LE) { it.counter3!! } else null - val counter4 = if (flags and 8 != 0) field(S32LE) { it.counter4!! } else null - val counter5 = if (flags and 16 != 0) field(S32LE) { it.counter5!! } else null - val counter6 = if (flags and 32 != 0) field(S32LE) { it.counter6!! } else null - return BattleStatCountersPacket( - entityId, - baseCounter, - counter1, - counter2, - counter3, - counter4, - counter5, - counter6, - ) - } + override fun CodecScope.body(): BattleStatCountersPacket { + val entityId = field(S64LE, BattleStatCountersPacket::entityId) + val baseCounter = field(S32LE, BattleStatCountersPacket::baseCounter) + val flags = + field(U8) { + (if (it.counter1 != null) 1 else 0) or + (if (it.counter2 != null) 2 else 0) or + (if (it.counter3 != null) 4 else 0) or + (if (it.counter4 != null) 8 else 0) or + (if (it.counter5 != null) 16 else 0) or + (if (it.counter6 != null) 32 else 0) + } + val counter1 = if (flags and 1 != 0) field(S32LE) { it.counter1!! } else null + val counter2 = if (flags and 2 != 0) field(S32LE) { it.counter2!! } else null + val counter3 = if (flags and 4 != 0) field(S32LE) { it.counter3!! } else null + val counter4 = if (flags and 8 != 0) field(S32LE) { it.counter4!! } else null + val counter5 = if (flags and 16 != 0) field(S32LE) { it.counter5!! } else null + val counter6 = if (flags and 32 != 0) field(S32LE) { it.counter6!! } else null + return BattleStatCountersPacket( + entityId, + baseCounter, + counter1, + counter2, + counter3, + counter4, + counter5, + counter6, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatStagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatStagePacket.kt index c2d02ef..088477f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatStagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatStagePacket.kt @@ -11,12 +11,12 @@ data class BattleStatStagePacket( ) object BattleStatStagePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleStatStagePacket { - val entityId = field(S64LE) { it.entityId } - val stat = field(S8) { it.stat } - val value = field(S16LE) { it.value } - val stage = field(S8) { it.stage } - val flags = field(S8) { it.flags } - return BattleStatStagePacket(entityId, stat, value, stage, flags) - } + override fun CodecScope.body(): BattleStatStagePacket { + val entityId = field(S64LE) { it.entityId } + val stat = field(S8) { it.stat } + val value = field(S16LE) { it.value } + val stage = field(S8) { it.stage } + val flags = field(S8) { it.flags } + return BattleStatStagePacket(entityId, stat, value, stage, flags) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateBytePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateBytePacket.kt index 9a49f16..6020c26 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateBytePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateBytePacket.kt @@ -9,8 +9,8 @@ data class BattleStateBytePacket( ) object BattleStateBytePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleStateBytePacket { - val state = field(S8) { it.state } - return BattleStateBytePacket(state) - } + override fun CodecScope.body(): BattleStateBytePacket { + val state = field(S8) { it.state } + return BattleStateBytePacket(state) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateSlotIntPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateSlotIntPacket.kt index 260e5be..b6f1690 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateSlotIntPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStateSlotIntPacket.kt @@ -11,9 +11,9 @@ data class BattleStateSlotIntPacket( ) object BattleStateSlotIntPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleStateSlotIntPacket { - val index = field(S8) { it.index } - val value = field(S32LE) { it.value } - return BattleStateSlotIntPacket(index, value) - } + override fun CodecScope.body(): BattleStateSlotIntPacket { + val index = field(S8) { it.index } + val value = field(S32LE) { it.value } + return BattleStateSlotIntPacket(index, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatusFlagPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatusFlagPacket.kt index 9fdb90a..7091915 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatusFlagPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleStatusFlagPacket.kt @@ -12,10 +12,10 @@ data class BattleStatusFlagPacket( ) object BattleStatusFlagPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleStatusFlagPacket { - val scope = field(S8) { it.scope } - val flagId = field(S16LE) { it.flagId } - val flagValue = field(S16LE) { it.flagValue } - return BattleStatusFlagPacket(scope, flagId, flagValue) - } + override fun CodecScope.body(): BattleStatusFlagPacket { + val scope = field(S8) { it.scope } + val flagId = field(S16LE) { it.flagId } + val flagValue = field(S16LE) { it.flagValue } + return BattleStatusFlagPacket(scope, flagId, flagValue) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchPromptTogglePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchPromptTogglePacket.kt index 5d06a82..46aa259 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchPromptTogglePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchPromptTogglePacket.kt @@ -9,8 +9,8 @@ data class BattleSwitchPromptTogglePacket( ) object BattleSwitchPromptTogglePacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSwitchPromptTogglePacket { - val shown = field(Bool) { it.shown } - return BattleSwitchPromptTogglePacket(shown) - } + override fun CodecScope.body(): BattleSwitchPromptTogglePacket { + val shown = field(Bool) { it.shown } + return BattleSwitchPromptTogglePacket(shown) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchSelectionsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchSelectionsPacket.kt index f93d9cf..081a3d8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchSelectionsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleSwitchSelectionsPacket.kt @@ -9,8 +9,8 @@ data class BattleSwitchSelectionsPacket( private val SelectedEntityIdsCodec = S64LE.listPrefixed(U8) object BattleSwitchSelectionsPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleSwitchSelectionsPacket { - val selectedEntityIds = field(SelectedEntityIdsCodec) { it.selectedEntityIds } - return BattleSwitchSelectionsPacket(selectedEntityIds) - } + override fun CodecScope.body(): BattleSwitchSelectionsPacket { + val selectedEntityIds = field(SelectedEntityIdsCodec) { it.selectedEntityIds } + return BattleSwitchSelectionsPacket(selectedEntityIds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTargetPickPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTargetPickPacket.kt index 6dc4c88..3fa7d4d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTargetPickPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTargetPickPacket.kt @@ -9,8 +9,8 @@ data class BattleTargetPickPacket( ) object BattleTargetPickPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleTargetPickPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - return BattleTargetPickPacket(targetEntityId) - } + override fun CodecScope.body(): BattleTargetPickPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + return BattleTargetPickPacket(targetEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewConfirmPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewConfirmPacket.kt index 5e9a57c..5b5f8e5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewConfirmPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewConfirmPacket.kt @@ -11,9 +11,9 @@ data class BattleTeamPreviewConfirmPacket( ) object BattleTeamPreviewConfirmPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleTeamPreviewConfirmPacket { - val side = field(S16LE) { it.side } - val isOwnTeam = field(Bool) { it.isOwnTeam } - return BattleTeamPreviewConfirmPacket(side, isOwnTeam) - } + override fun CodecScope.body(): BattleTeamPreviewConfirmPacket { + val side = field(S16LE) { it.side } + val isOwnTeam = field(Bool) { it.isOwnTeam } + return BattleTeamPreviewConfirmPacket(side, isOwnTeam) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewListPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewListPacket.kt index 3f57552..8e3b46a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewListPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTeamPreviewListPacket.kt @@ -20,23 +20,31 @@ private class BattlePreviewMemberCodec( private val opponent: Boolean, private val withDetails: Boolean, ) : PacketCodec() { - override fun CodecScope.body(): BattlePreviewMember { - val entityIdA = field(S64LE) { it.entityIdA } - val entityIdB = field(S64LE) { it.entityIdB } - val entityIdC = field(S64LE) { it.entityIdC } - val speciesByte = field(S8) { it.speciesByte } - val nickname = if (!opponent) field(Utf16LeNullTerminated) { it.nickname } else "" - val ownerName = if (opponent) field(Utf16LeNullTerminated) { it.ownerName } else "" - val value = field(S32LE) { it.value } - val nameA = field(Utf16LeNullTerminated) { it.nameA } - val nameB = if (withDetails) field(Utf16LeNullTerminated) { it.nameB } else "" - val levelByte = field(S8) { it.levelByte } - val flag = field(Bool) { it.flag } - return BattlePreviewMember( - entityIdA, entityIdB, entityIdC, speciesByte, nickname, ownerName, value, nameA, nameB, - levelByte, flag - ) - } + override fun CodecScope.body(): BattlePreviewMember { + val entityIdA = field(S64LE) { it.entityIdA } + val entityIdB = field(S64LE) { it.entityIdB } + val entityIdC = field(S64LE) { it.entityIdC } + val speciesByte = field(S8) { it.speciesByte } + val nickname = if (!opponent) field(Utf16LeNullTerminated) { it.nickname } else "" + val ownerName = if (opponent) field(Utf16LeNullTerminated) { it.ownerName } else "" + val value = field(S32LE) { it.value } + val nameA = field(Utf16LeNullTerminated) { it.nameA } + val nameB = if (withDetails) field(Utf16LeNullTerminated) { it.nameB } else "" + val levelByte = field(S8) { it.levelByte } + val flag = field(Bool) { it.flag } + return BattlePreviewMember( + entityIdA, + entityIdB, + entityIdC, + speciesByte, + nickname, + ownerName, + value, + nameA, + nameB, + levelByte, + flag) + } } data class BattleTeamPreviewListPacket( @@ -46,12 +54,12 @@ data class BattleTeamPreviewListPacket( ) object BattleTeamPreviewListPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleTeamPreviewListPacket { - val side = field(S16LE) { it.side } - val opponent = field(Bool) { it.opponent } - val memberCodec = BattlePreviewMemberCodec(opponent, false) - val count = field(S16LE) { it.members.size.toShort() }.toInt() - val members = (0 until count).map { i -> field(memberCodec) { it.members[i] } } - return BattleTeamPreviewListPacket(side, opponent, members) - } + override fun CodecScope.body(): BattleTeamPreviewListPacket { + val side = field(S16LE) { it.side } + val opponent = field(Bool) { it.opponent } + val memberCodec = BattlePreviewMemberCodec(opponent, false) + val count = field(S16LE) { it.members.size.toShort() }.toInt() + val members = (0 until count).map { i -> field(memberCodec) { it.members[i] } } + return BattleTeamPreviewListPacket(side, opponent, members) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTierSelectPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTierSelectPacket.kt index 8ad2e7b..4c389e0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTierSelectPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTierSelectPacket.kt @@ -7,9 +7,9 @@ import de.fiereu.bytecodec.S8 data class BattleTierSelectPacket(val pokemonSlotIndex: Byte, val tierIndex: Byte) object BattleTierSelectPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleTierSelectPacket { - val pokemonSlotIndex = field(S8) { it.pokemonSlotIndex } - val tierIndex = field(S8) { it.tierIndex } - return BattleTierSelectPacket(pokemonSlotIndex, tierIndex) - } + override fun CodecScope.body(): BattleTierSelectPacket { + val pokemonSlotIndex = field(S8) { it.pokemonSlotIndex } + val tierIndex = field(S8) { it.tierIndex } + return BattleTierSelectPacket(pokemonSlotIndex, tierIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTransitionReadyPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTransitionReadyPacket.kt index 7c208e6..ba3994d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTransitionReadyPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleTransitionReadyPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class BattleTransitionReadyPacket object BattleTransitionReadyPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleTransitionReadyPacket { - return BattleTransitionReadyPacket() - } + override fun CodecScope.body(): BattleTransitionReadyPacket { + return BattleTransitionReadyPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleUseItemPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleUseItemPacket.kt index 2cdc55d..32ca882 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleUseItemPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BattleUseItemPacket.kt @@ -11,9 +11,9 @@ data class BattleUseItemPacket( ) object BattleUseItemPacketCodec : PacketCodec() { - override fun CodecScope.body(): BattleUseItemPacket { - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val quantity = field(S16LE) { it.quantity } - return BattleUseItemPacket(pokemonEntityId, quantity) - } + override fun CodecScope.body(): BattleUseItemPacket { + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val quantity = field(S16LE) { it.quantity } + return BattleUseItemPacket(pokemonEntityId, quantity) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BlockPlayerPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BlockPlayerPacket.kt index c926e79..9395b6e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BlockPlayerPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BlockPlayerPacket.kt @@ -7,9 +7,9 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class BlockPlayerPacket(val username: String, val reason: String) object BlockPlayerPacketCodec : PacketCodec() { - override fun CodecScope.body(): BlockPlayerPacket { - val username = field(Utf16LeNullTerminated) { it.username } - val reason = field(Utf16LeNullTerminated) { it.reason } - return BlockPlayerPacket(username, reason) - } + override fun CodecScope.body(): BlockPlayerPacket { + val username = field(Utf16LeNullTerminated) { it.username } + val reason = field(Utf16LeNullTerminated) { it.reason } + return BlockPlayerPacket(username, reason) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BreedingForecastPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BreedingForecastPacket.kt index 0d97bec..2c5d4fa 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BreedingForecastPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/BreedingForecastPacket.kt @@ -32,89 +32,89 @@ data class BreedingForecastPacket( ) private object BreedingStatContributionCodec : PacketCodec() { - override fun CodecScope.body(): BreedingStatContribution { - val source = field(S8, BreedingStatContribution::source) - val weight = field(F32LE, BreedingStatContribution::weight) - val amount = field(S32LE, BreedingStatContribution::amount) - return BreedingStatContribution(source, weight, amount) - } + override fun CodecScope.body(): BreedingStatContribution { + val source = field(S8, BreedingStatContribution::source) + val weight = field(F32LE, BreedingStatContribution::weight) + val amount = field(S32LE, BreedingStatContribution::amount) + return BreedingStatContribution(source, weight, amount) + } } private val BreedingStatContributionListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { BreedingStatContributionCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { BreedingStatContributionCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { BreedingStatContributionCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { BreedingStatContributionCodec.write(buf, it) } + } } private object BreedingStatEntryCodec : PacketCodec() { - override fun CodecScope.body(): BreedingStatEntry { - val guaranteed = field(Bool, BreedingStatEntry::guaranteed) - val statId = field(S16LE, BreedingStatEntry::statId) - val contributions = - field(BreedingStatContributionListPrefixedU8, BreedingStatEntry::contributions) - return BreedingStatEntry(guaranteed, statId, contributions) - } + override fun CodecScope.body(): BreedingStatEntry { + val guaranteed = field(Bool, BreedingStatEntry::guaranteed) + val statId = field(S16LE, BreedingStatEntry::statId) + val contributions = + field(BreedingStatContributionListPrefixedU8, BreedingStatEntry::contributions) + return BreedingStatEntry(guaranteed, statId, contributions) + } } object BreedingForecastPacketCodec : PacketCodec() { - override fun CodecScope.body(): BreedingForecastPacket { - val parentA = field(S64LE, BreedingForecastPacket::parentA) - val parentB = field(S64LE, BreedingForecastPacket::parentB) - val hasPreview = field(Bool, BreedingForecastPacket::hasPreview) - if (!hasPreview) { - return BreedingForecastPacket( - parentA, - parentB, - hasPreview, - 0, - 0, - emptyList(), - emptyList(), - emptyList(), - emptyList(), - 0, - 0, - false, - 0, - 0, - ) - } - val species = field(S16LE, BreedingForecastPacket::species) - val form = field(S8, BreedingForecastPacket::form) - val statCount = field(U8) { it.statEntries.size } - val statEntries = List(statCount) { i -> field(BreedingStatEntryCodec) { it.statEntries[i] } } - val shininessCount = field(U8) { it.shininessTypes.size } - val shininessTypes = List(shininessCount) { i -> field(S8) { it.shininessTypes[i] } } - val valueCount = field(U8) { it.valueIds.size } - val valueIds = List(valueCount) { i -> field(S16LE) { it.valueIds[i] } } - val valueSources = List(valueCount) { i -> field(S8) { it.valueSources[i] } } - val gender = field(S8, BreedingForecastPacket::gender) - val nature = field(S16LE, BreedingForecastPacket::nature) - val shiny = field(Bool, BreedingForecastPacket::shiny) - val cost = field(S32LE, BreedingForecastPacket::cost) - val secondaryCost = field(S32LE, BreedingForecastPacket::secondaryCost) - return BreedingForecastPacket( - parentA, - parentB, - hasPreview, - species, - form, - statEntries, - shininessTypes, - valueIds, - valueSources, - gender, - nature, - shiny, - cost, - secondaryCost, - ) + override fun CodecScope.body(): BreedingForecastPacket { + val parentA = field(S64LE, BreedingForecastPacket::parentA) + val parentB = field(S64LE, BreedingForecastPacket::parentB) + val hasPreview = field(Bool, BreedingForecastPacket::hasPreview) + if (!hasPreview) { + return BreedingForecastPacket( + parentA, + parentB, + hasPreview, + 0, + 0, + emptyList(), + emptyList(), + emptyList(), + emptyList(), + 0, + 0, + false, + 0, + 0, + ) } + val species = field(S16LE, BreedingForecastPacket::species) + val form = field(S8, BreedingForecastPacket::form) + val statCount = field(U8) { it.statEntries.size } + val statEntries = List(statCount) { i -> field(BreedingStatEntryCodec) { it.statEntries[i] } } + val shininessCount = field(U8) { it.shininessTypes.size } + val shininessTypes = List(shininessCount) { i -> field(S8) { it.shininessTypes[i] } } + val valueCount = field(U8) { it.valueIds.size } + val valueIds = List(valueCount) { i -> field(S16LE) { it.valueIds[i] } } + val valueSources = List(valueCount) { i -> field(S8) { it.valueSources[i] } } + val gender = field(S8, BreedingForecastPacket::gender) + val nature = field(S16LE, BreedingForecastPacket::nature) + val shiny = field(Bool, BreedingForecastPacket::shiny) + val cost = field(S32LE, BreedingForecastPacket::cost) + val secondaryCost = field(S32LE, BreedingForecastPacket::secondaryCost) + return BreedingForecastPacket( + parentA, + parentB, + hasPreview, + species, + form, + statEntries, + shininessTypes, + valueIds, + valueSources, + gender, + nature, + shiny, + cost, + secondaryCost, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteArgumentPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteArgumentPacket.kt index 8e85e5f..0fd2f94 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteArgumentPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteArgumentPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S8 data class ByteArgumentPacket(val value: Byte) object ByteArgumentPacketCodec : PacketCodec() { - override fun CodecScope.body(): ByteArgumentPacket { - val value = field(S8) { it.value } - return ByteArgumentPacket(value) - } + override fun CodecScope.body(): ByteArgumentPacket { + val value = field(S8) { it.value } + return ByteArgumentPacket(value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteChoicePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteChoicePacket.kt index dbbc782..18bf50d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteChoicePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ByteChoicePacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S8 data class ByteChoicePacket(val value: Byte) object ByteChoicePacketCodec : PacketCodec() { - override fun CodecScope.body(): ByteChoicePacket { - val value = field(S8) { it.value } - return ByteChoicePacket(value) - } + override fun CodecScope.body(): ByteChoicePacket { + val value = field(S8) { it.value } + return ByteChoicePacket(value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CameraFollowEntityPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CameraFollowEntityPacket.kt index 1912b7f..3f859ef 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CameraFollowEntityPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CameraFollowEntityPacket.kt @@ -9,8 +9,8 @@ data class CameraFollowEntityPacket( ) object CameraFollowEntityPacketCodec : PacketCodec() { - override fun CodecScope.body(): CameraFollowEntityPacket { - val entityId = field(S64LE) { it.entityId } - return CameraFollowEntityPacket(entityId) - } + override fun CodecScope.body(): CameraFollowEntityPacket { + val entityId = field(S64LE) { it.entityId } + return CameraFollowEntityPacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelEntityMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelEntityMessagePacket.kt index aa90375..c5c7463 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelEntityMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelEntityMessagePacket.kt @@ -9,8 +9,8 @@ data class CancelEntityMessagePacket( ) object CancelEntityMessagePacketCodec : PacketCodec() { - override fun CodecScope.body(): CancelEntityMessagePacket { - val entityId = field(S64LE) { it.entityId } - return CancelEntityMessagePacket(entityId) - } + override fun CodecScope.body(): CancelEntityMessagePacket { + val entityId = field(S64LE) { it.entityId } + return CancelEntityMessagePacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelMatchmakingSearchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelMatchmakingSearchPacket.kt index c047299..d92fdbe 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelMatchmakingSearchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelMatchmakingSearchPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class CancelMatchmakingSearchPacket object CancelMatchmakingSearchPacketCodec : PacketCodec() { - override fun CodecScope.body(): CancelMatchmakingSearchPacket { - return CancelMatchmakingSearchPacket() - } + override fun CodecScope.body(): CancelMatchmakingSearchPacket { + return CancelMatchmakingSearchPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelSocialInteractionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelSocialInteractionPacket.kt index 7e117cf..d5ce129 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelSocialInteractionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CancelSocialInteractionPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class CancelSocialInteractionPacket object CancelSocialInteractionPacketCodec : PacketCodec() { - override fun CodecScope.body(): CancelSocialInteractionPacket { - return CancelSocialInteractionPacket() - } + override fun CodecScope.body(): CancelSocialInteractionPacket { + return CancelSocialInteractionPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CategoryFlagsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CategoryFlagsPacket.kt index 0adaf48..0f802b7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CategoryFlagsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CategoryFlagsPacket.kt @@ -7,25 +7,25 @@ data class CategoryFlagsPacket( val timestampMillis: Long, val flagBits: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is CategoryFlagsPacket && - entryKind == other.entryKind && - timestampMillis == other.timestampMillis && - flagBits.contentEquals(other.flagBits) + override fun equals(other: Any?): Boolean = + other is CategoryFlagsPacket && + entryKind == other.entryKind && + timestampMillis == other.timestampMillis && + flagBits.contentEquals(other.flagBits) - override fun hashCode(): Int { - var r = entryKind - r = r * 31 + timestampMillis.hashCode() - r = r * 31 + flagBits.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = entryKind + r = r * 31 + timestampMillis.hashCode() + r = r * 31 + flagBits.contentHashCode() + return r + } } object CategoryFlagsPacketCodec : PacketCodec() { - override fun CodecScope.body(): CategoryFlagsPacket { - val entryKind = field(U8) { it.entryKind } - val timestampMillis = field(S64LE) { it.timestampMillis } - val flagBits = field(bytesPrefixed(U16LE)) { it.flagBits } - return CategoryFlagsPacket(entryKind, timestampMillis, flagBits) - } + override fun CodecScope.body(): CategoryFlagsPacket { + val entryKind = field(U8) { it.entryKind } + val timestampMillis = field(S64LE) { it.timestampMillis } + val flagBits = field(bytesPrefixed(U16LE)) { it.flagBits } + return CategoryFlagsPacket(entryKind, timestampMillis, flagBits) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelAssignmentsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelAssignmentsPacket.kt index 7cd3471..1ddcc08 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelAssignmentsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelAssignmentsPacket.kt @@ -13,26 +13,26 @@ data class ChannelAssignmentsPacket( private val ChannelTypeBindingCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ChannelTypeBinding { - val chatType = field(S16LE) { it.chatType } - val channel = field(S8) { it.channel } - return ChannelTypeBinding(chatType, channel) - } + override fun CodecScope.body(): ChannelTypeBinding { + val chatType = field(S16LE) { it.chatType } + val channel = field(S8) { it.channel } + return ChannelTypeBinding(chatType, channel) + } } private val ChannelGroupBindingCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ChannelGroupBinding { - val channel = field(S8) { it.channel } - val members = field(S16LE.listPrefixed(U16LE)) { it.members } - return ChannelGroupBinding(channel, members) - } + override fun CodecScope.body(): ChannelGroupBinding { + val channel = field(S8) { it.channel } + val members = field(S16LE.listPrefixed(U16LE)) { it.members } + return ChannelGroupBinding(channel, members) + } } object ChannelAssignmentsPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChannelAssignmentsPacket { - val typeBindings = field(ChannelTypeBindingCodec.listPrefixed(U16LE)) { it.typeBindings } - val groupBindings = field(ChannelGroupBindingCodec.listPrefixed(U8)) { it.groupBindings } - return ChannelAssignmentsPacket(typeBindings, groupBindings) - } + override fun CodecScope.body(): ChannelAssignmentsPacket { + val typeBindings = field(ChannelTypeBindingCodec.listPrefixed(U16LE)) { it.typeBindings } + val groupBindings = field(ChannelGroupBindingCodec.listPrefixed(U8)) { it.groupBindings } + return ChannelAssignmentsPacket(typeBindings, groupBindings) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelCountDeltaPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelCountDeltaPacket.kt index 7594d03..045dc87 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelCountDeltaPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelCountDeltaPacket.kt @@ -15,19 +15,19 @@ data class ChannelCountDeltaPacket( private val ChannelCountEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ChannelCountEntry { - val channelId = field(S16LE) { it.channelId } - val flag = field(Bool) { it.flag } - return ChannelCountEntry(channelId, flag) - } + override fun CodecScope.body(): ChannelCountEntry { + val channelId = field(S16LE) { it.channelId } + val flag = field(Bool) { it.flag } + return ChannelCountEntry(channelId, flag) + } } object ChannelCountDeltaPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChannelCountDeltaPacket { - val category = field(S8) { it.category } - val count = field(U8) { it.entries.size } - val entries = (0 until count).map { i -> field(ChannelCountEntryCodec) { it.entries[i] } } - val delta = field(S8) { it.delta } - return ChannelCountDeltaPacket(category, entries, delta) - } + override fun CodecScope.body(): ChannelCountDeltaPacket { + val category = field(S8) { it.category } + val count = field(U8) { it.entries.size } + val entries = (0 until count).map { i -> field(ChannelCountEntryCodec) { it.entries[i] } } + val delta = field(S8) { it.delta } + return ChannelCountDeltaPacket(category, entries, delta) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelSwitchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelSwitchPacket.kt index 3a6cce2..b82d13c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelSwitchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChannelSwitchPacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.S8 data class ChannelSwitchPacket(val channelId: Byte, val silent: Boolean) object ChannelSwitchPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChannelSwitchPacket { - val channelId = field(S8) { it.channelId } - val silent = field(Bool) { it.silent } - return ChannelSwitchPacket(channelId, silent) - } + override fun CodecScope.body(): ChannelSwitchPacket { + val channelId = field(S8) { it.channelId } + val silent = field(Bool) { it.silent } + return ChannelSwitchPacket(channelId, silent) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharacterAppearanceApplyPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharacterAppearanceApplyPacket.kt index a9a6173..371865c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharacterAppearanceApplyPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharacterAppearanceApplyPacket.kt @@ -14,38 +14,39 @@ data class CharacterAppearanceApplyPacket( ) object CharacterAppearanceApplyPacketCodec : PacketCodec() { - override fun CodecScope.body(): CharacterAppearanceApplyPacket { - val characterName = field(Utf16LeNullTerminated) { it.characterName } - val appearanceTypeA = field(S8) { it.appearanceTypeA } - val appearanceTypeB = field(S8) { it.appearanceTypeB } + override fun CodecScope.body(): CharacterAppearanceApplyPacket { + val characterName = field(Utf16LeNullTerminated) { it.characterName } + val appearanceTypeA = field(S8) { it.appearanceTypeA } + val appearanceTypeB = field(S8) { it.appearanceTypeB } - val categoryByte = field(S8) { it.creatureMoves.categoryByte } - val bitmask = - field(S16LE) { - var m = 0 - for (move in it.creatureMoves.moves) { - m = m or (1 shl move.slot) - if (move.ppUp != null) m = m or 0x8000 - } - m.toShort() - } - val mask = bitmask.toInt() and 0xFFFF - val hasPp = (mask and 0x8000) != 0 - val moves = mutableListOf() - for (slot in 0 until 15) { - if (mask and (1 shl slot) != 0) { - val packed = field(S16LE) { v -> v.creatureMoves.moves.first { it.slot == slot }.packedMove } - val pp: Byte? = - if (hasPp) field(S8) { v -> v.creatureMoves.moves.first { it.slot == slot }.ppUp ?: 0 } - else null - moves.add(AppearanceMoveEntry(slot, packed, pp)) - } + val categoryByte = field(S8) { it.creatureMoves.categoryByte } + val bitmask = + field(S16LE) { + var m = 0 + for (move in it.creatureMoves.moves) { + m = m or (1 shl move.slot) + if (move.ppUp != null) m = m or 0x8000 + } + m.toShort() } - return CharacterAppearanceApplyPacket( - characterName, - appearanceTypeA, - appearanceTypeB, - AppearanceMoveSet(categoryByte, moves), - ) + val mask = bitmask.toInt() and 0xFFFF + val hasPp = (mask and 0x8000) != 0 + val moves = mutableListOf() + for (slot in 0 until 15) { + if (mask and (1 shl slot) != 0) { + val packed = + field(S16LE) { v -> v.creatureMoves.moves.first { it.slot == slot }.packedMove } + val pp: Byte? = + if (hasPp) field(S8) { v -> v.creatureMoves.moves.first { it.slot == slot }.ppUp ?: 0 } + else null + moves.add(AppearanceMoveEntry(slot, packed, pp)) + } } + return CharacterAppearanceApplyPacket( + characterName, + appearanceTypeA, + appearanceTypeB, + AppearanceMoveSet(categoryByte, moves), + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharactersListPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharactersListPacket.kt index e82569a..99c836e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharactersListPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CharactersListPacket.kt @@ -11,57 +11,57 @@ data class CharacterEntry( val guildId: Int? = null, val pokemon: List, ) { - init { - require(pokemon.size <= 6) { "Party size can't be more than 6 pokemon" } - } + init { + require(pokemon.size <= 6) { "Party size can't be more than 6 pokemon" } + } } data class CharactersListPacket(val characters: List) private val CharacterInfoAsymmetric: Codec = object : Codec { - override fun read(buf: ReadBuffer): CharacterInfo = CharacterInfoCodecLong.read(buf) + override fun read(buf: ReadBuffer): CharacterInfo = CharacterInfoCodecLong.read(buf) - override fun write(buf: WriteBuffer, value: CharacterInfo) { - CharacterInfoCodecShort.write(buf, value) - } + override fun write(buf: WriteBuffer, value: CharacterInfo) { + CharacterInfoCodecShort.write(buf, value) + } } private object CharacterEntryCodec : PacketCodec() { - override fun CodecScope.body(): CharacterEntry { - val info = field(CharacterInfoAsymmetric, CharacterEntry::characterInfo) - val skin = field(DefaultSkinSetCodec, CharacterEntry::skinSet) - field(SkinSetCodecNoLeading, CharacterEntry::skinSet) - val hasGuild = field(Bool) { it.guildId != null } - val guildId = - if (hasGuild) { - field(Utf16LeNullTerminated) { "" } - field(S32LE) { it.guildId!! } - } else { - null - } - val partySize = field(U8) { it.pokemon.size } - val party = List(partySize) { field(PokemonCodec) { entry -> entry.pokemon[it] } } - return CharacterEntry(info, skin, guildId, party) - } + override fun CodecScope.body(): CharacterEntry { + val info = field(CharacterInfoAsymmetric, CharacterEntry::characterInfo) + val skin = field(DefaultSkinSetCodec, CharacterEntry::skinSet) + field(SkinSetCodecNoLeading, CharacterEntry::skinSet) + val hasGuild = field(Bool) { it.guildId != null } + val guildId = + if (hasGuild) { + field(Utf16LeNullTerminated) { "" } + field(S32LE) { it.guildId!! } + } else { + null + } + val partySize = field(U8) { it.pokemon.size } + val party = List(partySize) { field(PokemonCodec) { entry -> entry.pokemon[it] } } + return CharacterEntry(info, skin, guildId, party) + } } private val CharacterEntryListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { CharacterEntryCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { CharacterEntryCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { CharacterEntryCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { CharacterEntryCodec.write(buf, it) } + } } object CharactersListPacketCodec : PacketCodec() { - override fun CodecScope.body() = - CharactersListPacket( - characters = field(CharacterEntryListPrefixedU8, CharactersListPacket::characters), - ) + override fun CodecScope.body() = + CharactersListPacket( + characters = field(CharacterEntryListPrefixedU8, CharactersListPacket::characters), + ) } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelMessagesPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelMessagesPacket.kt index 6edc70a..67f7600 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelMessagesPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelMessagesPacket.kt @@ -10,11 +10,11 @@ data class ChatChannelMessagesPacket( ) object ChatChannelMessagesPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChatChannelMessagesPacket { - val channelType = field(S8, ChatChannelMessagesPacket::channelType) - val clear = field(Bool, ChatChannelMessagesPacket::clear) - val refresh = field(Bool, ChatChannelMessagesPacket::refresh) - val messageCount = field(U16LE, ChatChannelMessagesPacket::messageCount) - return ChatChannelMessagesPacket(channelType, clear, refresh, messageCount) - } + override fun CodecScope.body(): ChatChannelMessagesPacket { + val channelType = field(S8, ChatChannelMessagesPacket::channelType) + val clear = field(Bool, ChatChannelMessagesPacket::clear) + val refresh = field(Bool, ChatChannelMessagesPacket::refresh) + val messageCount = field(U16LE, ChatChannelMessagesPacket::messageCount) + return ChatChannelMessagesPacket(channelType, clear, refresh, messageCount) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelUserListPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelUserListPacket.kt index f67aa00..c9374d5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelUserListPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatChannelUserListPacket.kt @@ -18,29 +18,29 @@ data class ChatChannelUserListPacket( private val ChatChannelUserCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ChatChannelUser { - val channelId = field(S16LE) { it.channelId } - val rank = field(S8) { it.rank } - return ChatChannelUser(channelId, rank) - } + override fun CodecScope.body(): ChatChannelUser { + val channelId = field(S16LE) { it.channelId } + val rank = field(S8) { it.rank } + return ChatChannelUser(channelId, rank) + } } object ChatChannelUserListPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChatChannelUserListPacket { - val channelType = field(S8) { it.channelType } - val clear = field(Bool) { it.clear } - val refresh = field(Bool) { it.refresh } - val unreadCount = if (clear) field(S32LE) { it.unreadCount } else 0 - val unreadMentionCount = if (clear) field(S32LE) { it.unreadMentionCount } else 0 - val count = field(S16LE) { it.users.size.toShort() }.toInt() and 0xFFFF - val users = (0 until count).map { i -> field(ChatChannelUserCodec) { it.users[i] } } - return ChatChannelUserListPacket( - channelType = channelType, - clear = clear, - refresh = refresh, - unreadCount = unreadCount, - unreadMentionCount = unreadMentionCount, - users = users, - ) - } + override fun CodecScope.body(): ChatChannelUserListPacket { + val channelType = field(S8) { it.channelType } + val clear = field(Bool) { it.clear } + val refresh = field(Bool) { it.refresh } + val unreadCount = if (clear) field(S32LE) { it.unreadCount } else 0 + val unreadMentionCount = if (clear) field(S32LE) { it.unreadMentionCount } else 0 + val count = field(S16LE) { it.users.size.toShort() }.toInt() and 0xFFFF + val users = (0 until count).map { i -> field(ChatChannelUserCodec) { it.users[i] } } + return ChatChannelUserListPacket( + channelType = channelType, + clear = clear, + refresh = refresh, + unreadCount = unreadCount, + unreadMentionCount = unreadMentionCount, + users = users, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatLocalePreferencesPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatLocalePreferencesPacket.kt index b922ad5..4bfb901 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatLocalePreferencesPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatLocalePreferencesPacket.kt @@ -12,10 +12,10 @@ data class ChatLocalePreferencesPacket( ) object ChatLocalePreferencesPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChatLocalePreferencesPacket { - val languageId = field(S8) { it.languageId } - val chatChannelMask = field(S16LE) { it.chatChannelMask } - val languageFilterMask = field(S16LE) { it.languageFilterMask } - return ChatLocalePreferencesPacket(languageId, chatChannelMask, languageFilterMask) - } + override fun CodecScope.body(): ChatLocalePreferencesPacket { + val languageId = field(S8) { it.languageId } + val chatChannelMask = field(S16LE) { it.chatChannelMask } + val languageFilterMask = field(S16LE) { it.languageFilterMask } + return ChatLocalePreferencesPacket(languageId, chatChannelMask, languageFilterMask) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessagePacket.kt index 7ed35d1..a30ba55 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessagePacket.kt @@ -12,35 +12,35 @@ data class ChatMessagePacket( ) object ChatMessagePacketCodec : PacketCodec() { - override fun CodecScope.body(): ChatMessagePacket { - val type = ChatType.entries[field(U8) { it.type.ordinal }] - return if (type == ChatType.TEAM) { - ChatMessagePacket( - type = type, - language = null, - message = field(Utf16LeNullTerminated, ChatMessagePacket::message), - sender = null, - ) - } else { - field(S64LE) { 0L } - val sender = - field(Utf16LeNullTerminated) { - it.sender ?: throw MalformedPacketException("sender must not be null") - } - val language = - Language.entries[ - field(U8) { - (it.language ?: throw MalformedPacketException("language must not be null")) - .ordinal - }] - field(S8) { -1 } - val message = field(Utf16LeNullTerminated, ChatMessagePacket::message) - ChatMessagePacket( - type = type, - language = language, - message = message, - sender = sender, - ) - } + override fun CodecScope.body(): ChatMessagePacket { + val type = ChatType.entries[field(U8) { it.type.ordinal }] + return if (type == ChatType.TEAM) { + ChatMessagePacket( + type = type, + language = null, + message = field(Utf16LeNullTerminated, ChatMessagePacket::message), + sender = null, + ) + } else { + field(S64LE) { 0L } + val sender = + field(Utf16LeNullTerminated) { + it.sender ?: throw MalformedPacketException("sender must not be null") + } + val language = + Language.entries[ + field(U8) { + (it.language ?: throw MalformedPacketException("language must not be null")) + .ordinal + }] + field(S8) { -1 } + val message = field(Utf16LeNullTerminated, ChatMessagePacket::message) + ChatMessagePacket( + type = type, + language = language, + message = message, + sender = sender, + ) } + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageSendPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageSendPacket.kt index 8502ed5..ea99636 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageSendPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageSendPacket.kt @@ -12,11 +12,10 @@ data class ChatMessageSendPacket( ) object ChatMessageSendPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChatMessageSendPacket { - val mode = field(S8) { it.mode } - val target = field(Utf16LeNullTerminated) { it.target } - val message = - if (mode.toInt() == 4) field(Utf16LeNullTerminated) { it.message ?: "" } else null - return ChatMessageSendPacket(mode, target, message) - } + override fun CodecScope.body(): ChatMessageSendPacket { + val mode = field(S8) { it.mode } + val target = field(Utf16LeNullTerminated) { it.target } + val message = if (mode.toInt() == 4) field(Utf16LeNullTerminated) { it.message ?: "" } else null + return ChatMessageSendPacket(mode, target, message) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageWithdrawPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageWithdrawPacket.kt index b8f33c1..3ebc01c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageWithdrawPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChatMessageWithdrawPacket.kt @@ -9,8 +9,8 @@ data class ChatMessageWithdrawPacket( ) object ChatMessageWithdrawPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChatMessageWithdrawPacket { - val authorId = field(S64LE) { it.authorId } - return ChatMessageWithdrawPacket(authorId) - } + override fun CodecScope.body(): ChatMessageWithdrawPacket { + val authorId = field(S64LE) { it.authorId } + return ChatMessageWithdrawPacket(authorId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedImagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedImagePacket.kt index 2214d1d..22f8233 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedImagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedImagePacket.kt @@ -9,33 +9,33 @@ data class ChunkedImagePacket( val last: Boolean?, val data: ByteArray?, ) { - override fun equals(other: Any?): Boolean = - other is ChunkedImagePacket && - controlType == other.controlType && - imageType == other.imageType && - chunkIndex == other.chunkIndex && - last == other.last && - (if (data == null) other.data == null - else other.data != null && data.contentEquals(other.data)) + override fun equals(other: Any?): Boolean = + other is ChunkedImagePacket && + controlType == other.controlType && + imageType == other.imageType && + chunkIndex == other.chunkIndex && + last == other.last && + (if (data == null) other.data == null + else other.data != null && data.contentEquals(other.data)) - override fun hashCode(): Int { - var r = controlType.toInt() - r = r * 31 + (imageType?.toInt() ?: 0) - r = r * 31 + (chunkIndex ?: 0) - r = r * 31 + (last?.hashCode() ?: 0) - r = r * 31 + (data?.contentHashCode() ?: 0) - return r - } + override fun hashCode(): Int { + var r = controlType.toInt() + r = r * 31 + (imageType?.toInt() ?: 0) + r = r * 31 + (chunkIndex ?: 0) + r = r * 31 + (last?.hashCode() ?: 0) + r = r * 31 + (data?.contentHashCode() ?: 0) + return r + } } object ChunkedImagePacketCodec : PacketCodec() { - override fun CodecScope.body(): ChunkedImagePacket { - val controlType = field(S8) { it.controlType } - val present = controlType.toInt() != 2 - val imageType = if (present) field(S8) { it.imageType!! } else null - val chunkIndex = if (present) field(U8) { it.chunkIndex!! } else null - val last = if (present) field(U8) { if (it.last!!) 1 else 0 } == 1 else null - val data = if (present) field(bytesPrefixed(U16LE)) { it.data!! } else null - return ChunkedImagePacket(controlType, imageType, chunkIndex, last, data) - } + override fun CodecScope.body(): ChunkedImagePacket { + val controlType = field(S8) { it.controlType } + val present = controlType.toInt() != 2 + val imageType = if (present) field(S8) { it.imageType!! } else null + val chunkIndex = if (present) field(U8) { it.chunkIndex!! } else null + val last = if (present) field(U8) { if (it.last!!) 1 else 0 } == 1 else null + val data = if (present) field(bytesPrefixed(U16LE)) { it.data!! } else null + return ChunkedImagePacket(controlType, imageType, chunkIndex, last, data) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferAppendPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferAppendPacket.kt index 14a8e08..72bdb49 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferAppendPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferAppendPacket.kt @@ -8,15 +8,15 @@ import de.fiereu.bytecodec.bytesPrefixed data class ChunkedTransferAppendPacket( val data: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is ChunkedTransferAppendPacket && data.contentEquals(other.data) + override fun equals(other: Any?): Boolean = + other is ChunkedTransferAppendPacket && data.contentEquals(other.data) - override fun hashCode(): Int = data.contentHashCode() + override fun hashCode(): Int = data.contentHashCode() } object ChunkedTransferAppendPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChunkedTransferAppendPacket { - val data = field(bytesPrefixed(U16LE)) { it.data } - return ChunkedTransferAppendPacket(data) - } + override fun CodecScope.body(): ChunkedTransferAppendPacket { + val data = field(bytesPrefixed(U16LE)) { it.data } + return ChunkedTransferAppendPacket(data) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferBeginPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferBeginPacket.kt index 6ed384c..293d6b7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferBeginPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferBeginPacket.kt @@ -7,25 +7,25 @@ data class ChunkedTransferBeginPacket( val totalSize: Int, val data: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is ChunkedTransferBeginPacket && - transferId == other.transferId && - totalSize == other.totalSize && - data.contentEquals(other.data) + override fun equals(other: Any?): Boolean = + other is ChunkedTransferBeginPacket && + transferId == other.transferId && + totalSize == other.totalSize && + data.contentEquals(other.data) - override fun hashCode(): Int { - var r = transferId.hashCode() - r = r * 31 + totalSize - r = r * 31 + data.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = transferId.hashCode() + r = r * 31 + totalSize + r = r * 31 + data.contentHashCode() + return r + } } object ChunkedTransferBeginPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChunkedTransferBeginPacket { - val transferId = field(S64LE) { it.transferId } - val totalSize = field(S32LE) { it.totalSize } - val data = field(bytesPrefixed(U16LE)) { it.data } - return ChunkedTransferBeginPacket(transferId, totalSize, data) - } + override fun CodecScope.body(): ChunkedTransferBeginPacket { + val transferId = field(S64LE) { it.transferId } + val totalSize = field(S32LE) { it.totalSize } + val data = field(bytesPrefixed(U16LE)) { it.data } + return ChunkedTransferBeginPacket(transferId, totalSize, data) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferDataPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferDataPacket.kt index e14e09e..240ffab 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferDataPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ChunkedTransferDataPacket.kt @@ -7,40 +7,40 @@ data class ChunkedTransferDataPacket( val totalSize: Int, val chunkData: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is ChunkedTransferDataPacket && - transferId == other.transferId && - totalSize == other.totalSize && - chunkData.contentEquals(other.chunkData) + override fun equals(other: Any?): Boolean = + other is ChunkedTransferDataPacket && + transferId == other.transferId && + totalSize == other.totalSize && + chunkData.contentEquals(other.chunkData) - override fun hashCode(): Int { - var r = transferId.hashCode() - r = r * 31 + totalSize - r = r * 31 + chunkData.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = transferId.hashCode() + r = r * 31 + totalSize + r = r * 31 + chunkData.contentHashCode() + return r + } } private val ChunkBytes: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val length = S16LE.read(buf).toInt() - val data = ByteArray(length) - if (length > 0) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val length = S16LE.read(buf).toInt() + val data = ByteArray(length) + if (length > 0) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - S16LE.write(buf, value.size.toShort()) - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + S16LE.write(buf, value.size.toShort()) + if (value.isNotEmpty()) buf.writeBytes(value) + } } object ChunkedTransferDataPacketCodec : PacketCodec() { - override fun CodecScope.body(): ChunkedTransferDataPacket { - val transferId = field(S64LE) { it.transferId } - val totalSize = field(S32LE) { it.totalSize } - val chunkData = field(ChunkBytes) { it.chunkData } - return ChunkedTransferDataPacket(transferId, totalSize, chunkData) - } + override fun CodecScope.body(): ChunkedTransferDataPacket { + val transferId = field(S64LE) { it.transferId } + val totalSize = field(S32LE) { it.totalSize } + val chunkData = field(ChunkBytes) { it.chunkData } + return ChunkedTransferDataPacket(transferId, totalSize, chunkData) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientCookieUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientCookieUpdatePacket.kt index 58884d8..d2bc389 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientCookieUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientCookieUpdatePacket.kt @@ -8,50 +8,50 @@ data class ClientCookieUpdatePacket( val blob: ByteArray?, val namedValues: List?, ) { - override fun equals(other: Any?): Boolean { - if (other !is ClientCookieUpdatePacket) return false - if (namedValues != other.namedValues) return false - if (blob == null) return other.blob == null - return other.blob != null && blob.contentEquals(other.blob) - } + override fun equals(other: Any?): Boolean { + if (other !is ClientCookieUpdatePacket) return false + if (namedValues != other.namedValues) return false + if (blob == null) return other.blob == null + return other.blob != null && blob.contentEquals(other.blob) + } - override fun hashCode(): Int { - var r = blob?.contentHashCode() ?: 0 - r = r * 31 + (namedValues?.hashCode() ?: 0) - return r - } + override fun hashCode(): Int { + var r = blob?.contentHashCode() ?: 0 + r = r * 31 + (namedValues?.hashCode() ?: 0) + return r + } } private val CookieBlob = bytesPrefixed(U8) private val CookieNamedValueCodec: Codec = (S8.then(Utf16LeNullTerminated)).let { pair -> - object : Codec { - override fun read(buf: de.fiereu.bytecodec.ReadBuffer): CookieNamedValue { - val (k, v) = pair.read(buf) - return CookieNamedValue(k, v) - } - - override fun write(buf: de.fiereu.bytecodec.WriteBuffer, value: CookieNamedValue) { - pair.write(buf, value.key to value.value) - } + object : Codec { + override fun read(buf: de.fiereu.bytecodec.ReadBuffer): CookieNamedValue { + val (k, v) = pair.read(buf) + return CookieNamedValue(k, v) } + + override fun write(buf: de.fiereu.bytecodec.WriteBuffer, value: CookieNamedValue) { + pair.write(buf, value.key to value.value) + } + } } object ClientCookieUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): ClientCookieUpdatePacket { - val flags = - field(S8) { - var f = 0 - if (it.blob != null) f = f or 1 - if (it.namedValues != null) f = f or 2 - f.toByte() - } - val blob: ByteArray? = if (flags.toInt() and 1 != 0) field(CookieBlob) { it.blob!! } else null - val namedValues: List? = - if (flags.toInt() and 2 != 0) - field(CookieNamedValueCodec.listPrefixed(U8)) { it.namedValues!! } - else null - return ClientCookieUpdatePacket(blob, namedValues) - } + override fun CodecScope.body(): ClientCookieUpdatePacket { + val flags = + field(S8) { + var f = 0 + if (it.blob != null) f = f or 1 + if (it.namedValues != null) f = f or 2 + f.toByte() + } + val blob: ByteArray? = if (flags.toInt() and 1 != 0) field(CookieBlob) { it.blob!! } else null + val namedValues: List? = + if (flags.toInt() and 2 != 0) + field(CookieNamedValueCodec.listPrefixed(U8)) { it.namedValues!! } + else null + return ClientCookieUpdatePacket(blob, namedValues) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientDiagnosticsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientDiagnosticsPacket.kt index 29d473f..4839287 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientDiagnosticsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientDiagnosticsPacket.kt @@ -16,57 +16,57 @@ data class ClientDiagnosticsPacket( val localIp: ByteArray, val trackedEntityIds: List, ) { - override fun equals(other: Any?): Boolean = - other is ClientDiagnosticsPacket && - worldStateFlags == other.worldStateFlags && - renderMetric0 == other.renderMetric0 && - renderMetric1 == other.renderMetric1 && - renderMetric2 == other.renderMetric2 && - renderMetric3 == other.renderMetric3 && - knownEntityCount == other.knownEntityCount && - timestampMillis == other.timestampMillis && - timestampNanos == other.timestampNanos && - localIp.contentEquals(other.localIp) && - trackedEntityIds == other.trackedEntityIds + override fun equals(other: Any?): Boolean = + other is ClientDiagnosticsPacket && + worldStateFlags == other.worldStateFlags && + renderMetric0 == other.renderMetric0 && + renderMetric1 == other.renderMetric1 && + renderMetric2 == other.renderMetric2 && + renderMetric3 == other.renderMetric3 && + knownEntityCount == other.knownEntityCount && + timestampMillis == other.timestampMillis && + timestampNanos == other.timestampNanos && + localIp.contentEquals(other.localIp) && + trackedEntityIds == other.trackedEntityIds - override fun hashCode(): Int { - var r = worldStateFlags - r = r * 31 + renderMetric0 - r = r * 31 + renderMetric1 - r = r * 31 + renderMetric2 - r = r * 31 + renderMetric3 - r = r * 31 + knownEntityCount - r = r * 31 + timestampMillis.hashCode() - r = r * 31 + timestampNanos.hashCode() - r = r * 31 + localIp.contentHashCode() - r = r * 31 + trackedEntityIds.hashCode() - return r - } + override fun hashCode(): Int { + var r = worldStateFlags + r = r * 31 + renderMetric0 + r = r * 31 + renderMetric1 + r = r * 31 + renderMetric2 + r = r * 31 + renderMetric3 + r = r * 31 + knownEntityCount + r = r * 31 + timestampMillis.hashCode() + r = r * 31 + timestampNanos.hashCode() + r = r * 31 + localIp.contentHashCode() + r = r * 31 + trackedEntityIds.hashCode() + return r + } } object ClientDiagnosticsPacketCodec : PacketCodec() { - override fun CodecScope.body(): ClientDiagnosticsPacket { - val worldStateFlags = field(S32LE) { it.worldStateFlags } - val renderMetric0 = field(S8) { it.renderMetric0 } - val renderMetric1 = field(S8) { it.renderMetric1 } - val renderMetric2 = field(S8) { it.renderMetric2 } - val renderMetric3 = field(S8) { it.renderMetric3 } - val knownEntityCount = field(S16LE) { it.knownEntityCount } - val timestampMillis = field(S64LE) { it.timestampMillis } - val timestampNanos = field(S64LE) { it.timestampNanos } - val localIp = field(LocalIpBytes) { it.localIp } - val trackedEntityIds = field(S64LE.listPrefixed(U8)) { it.trackedEntityIds } - return ClientDiagnosticsPacket( - worldStateFlags, - renderMetric0, - renderMetric1, - renderMetric2, - renderMetric3, - knownEntityCount, - timestampMillis, - timestampNanos, - localIp, - trackedEntityIds, - ) - } + override fun CodecScope.body(): ClientDiagnosticsPacket { + val worldStateFlags = field(S32LE) { it.worldStateFlags } + val renderMetric0 = field(S8) { it.renderMetric0 } + val renderMetric1 = field(S8) { it.renderMetric1 } + val renderMetric2 = field(S8) { it.renderMetric2 } + val renderMetric3 = field(S8) { it.renderMetric3 } + val knownEntityCount = field(S16LE) { it.knownEntityCount } + val timestampMillis = field(S64LE) { it.timestampMillis } + val timestampNanos = field(S64LE) { it.timestampNanos } + val localIp = field(LocalIpBytes) { it.localIp } + val trackedEntityIds = field(S64LE.listPrefixed(U8)) { it.trackedEntityIds } + return ClientDiagnosticsPacket( + worldStateFlags, + renderMetric0, + renderMetric1, + renderMetric2, + renderMetric3, + knownEntityCount, + timestampMillis, + timestampNanos, + localIp, + trackedEntityIds, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientSettingUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientSettingUpdatePacket.kt index 489b25f..a6f4529 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientSettingUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ClientSettingUpdatePacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S32LE data class ClientSettingUpdatePacket(val settingsValue: Int) object ClientSettingUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): ClientSettingUpdatePacket { - val settingsValue = field(S32LE) { it.settingsValue } - return ClientSettingUpdatePacket(settingsValue) - } + override fun CodecScope.body(): ClientSettingUpdatePacket { + val settingsValue = field(S32LE) { it.settingsValue } + return ClientSettingUpdatePacket(settingsValue) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactCategoryGroupPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactCategoryGroupPacket.kt index b4cf1ae..dd6505b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactCategoryGroupPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactCategoryGroupPacket.kt @@ -9,10 +9,10 @@ data class ContactCategoryGroupPacket( ) object ContactCategoryGroupPacketCodec : PacketCodec() { - override fun CodecScope.body(): ContactCategoryGroupPacket { - val category = field(S8, ContactCategoryGroupPacket::category) - val name = field(Utf16LeNullTerminated, ContactCategoryGroupPacket::name) - val memberIds = field(S64LE.repeat(6), ContactCategoryGroupPacket::memberIds) - return ContactCategoryGroupPacket(category, name, memberIds) - } + override fun CodecScope.body(): ContactCategoryGroupPacket { + val category = field(S8, ContactCategoryGroupPacket::category) + val name = field(Utf16LeNullTerminated, ContactCategoryGroupPacket::name) + val memberIds = field(S64LE.repeat(6), ContactCategoryGroupPacket::memberIds) + return ContactCategoryGroupPacket(category, name, memberIds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactDeletePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactDeletePacket.kt index e3665d1..824dace 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactDeletePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactDeletePacket.kt @@ -9,8 +9,8 @@ data class ContactDeletePacket( ) object ContactDeletePacketCodec : PacketCodec() { - override fun CodecScope.body(): ContactDeletePacket { - val entityId = field(S64LE) { it.entityId } - return ContactDeletePacket(entityId) - } + override fun CodecScope.body(): ContactDeletePacket { + val entityId = field(S64LE) { it.entityId } + return ContactDeletePacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactInsertPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactInsertPacket.kt index 08c7ed6..01f919d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactInsertPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactInsertPacket.kt @@ -20,23 +20,23 @@ data class ContactInsertPacket( private val ContactInsertAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ContactInsertAppearance { - val name = field(Utf16LeNullTerminated) { it.name } - val valueA = field(S8) { it.valueA } - val valueB = field(S32LE) { it.valueB } - val kind = field(S8) { it.kind } - val packedSlots = field(S8) { it.packedSlots } - val spriteData = field(S16LE.repeat(12)) { it.spriteData } - return ContactInsertAppearance(name, valueA, valueB, kind, packedSlots, spriteData) - } + override fun CodecScope.body(): ContactInsertAppearance { + val name = field(Utf16LeNullTerminated) { it.name } + val valueA = field(S8) { it.valueA } + val valueB = field(S32LE) { it.valueB } + val kind = field(S8) { it.kind } + val packedSlots = field(S8) { it.packedSlots } + val spriteData = field(S16LE.repeat(12)) { it.spriteData } + return ContactInsertAppearance(name, valueA, valueB, kind, packedSlots, spriteData) + } } object ContactInsertPacketCodec : PacketCodec() { - override fun CodecScope.body(): ContactInsertPacket { - val player = field(S64LE) { it.player } - val value = field(S32LE) { it.value } - val online = field(U8) { if (it.online) 1 else 0 } == 1 - val appearance = field(ContactInsertAppearanceCodec) { it.appearance } - return ContactInsertPacket(player, value, online, appearance) - } + override fun CodecScope.body(): ContactInsertPacket { + val player = field(S64LE) { it.player } + val value = field(S32LE) { it.value } + val online = field(U8) { if (it.online) 1 else 0 } == 1 + val appearance = field(ContactInsertAppearanceCodec) { it.appearance } + return ContactInsertPacket(player, value, online, appearance) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactOnlineStatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactOnlineStatePacket.kt index ffb862c..304dd93 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactOnlineStatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactOnlineStatePacket.kt @@ -11,9 +11,9 @@ data class ContactOnlineStatePacket( ) object ContactOnlineStatePacketCodec : PacketCodec() { - override fun CodecScope.body(): ContactOnlineStatePacket { - val contactId = field(S64LE) { it.contactId } - val online = field(U8) { if (it.online) 1 else 0 } == 1 - return ContactOnlineStatePacket(contactId, online) - } + override fun CodecScope.body(): ContactOnlineStatePacket { + val contactId = field(S64LE) { it.contactId } + val online = field(U8) { if (it.online) 1 else 0 } == 1 + return ContactOnlineStatePacket(contactId, online) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactRosterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactRosterPacket.kt deleted file mode 100644 index 7e90303..0000000 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ContactRosterPacket.kt +++ /dev/null @@ -1,56 +0,0 @@ -package de.fiereu.openmmo.net.game.packets - -import de.fiereu.bytecodec.* - -data class ContactAppearance( - val name: String, - val valueA: Byte, - val valueB: Int, - val kind: Byte, - val packedSlots: Byte, - val spriteData: List, -) - -data class ContactRosterEntry( - val player: Long, - val value: Int, - val online: Boolean, - val appearance: ContactAppearance, -) - -data class ContactRosterPacket( - val mode: Int, - val entries: List, -) - -private val ContactAppearanceCodec: Codec = - object : PacketCodec() { - override fun CodecScope.body(): ContactAppearance { - val name = field(Utf16LeNullTerminated) { it.name } - val valueA = field(S8) { it.valueA } - val valueB = field(S32LE) { it.valueB } - val kind = field(S8) { it.kind } - val packedSlots = field(S8) { it.packedSlots } - val spriteData = field(S16LE.repeat(12)) { it.spriteData } - return ContactAppearance(name, valueA, valueB, kind, packedSlots, spriteData) - } - } - -private val ContactRosterEntryCodec: Codec = - object : PacketCodec() { - override fun CodecScope.body(): ContactRosterEntry { - val player = field(S64LE) { it.player } - val value = field(S32LE) { it.value } - val online = field(U8) { if (it.online) 1 else 0 } == 1 - val appearance = field(ContactAppearanceCodec) { it.appearance } - return ContactRosterEntry(player, value, online, appearance) - } - } - -object ContactRosterPacketCodec : PacketCodec() { - override fun CodecScope.body(): ContactRosterPacket { - val mode = field(U8) { it.mode } - val entries = field(ContactRosterEntryCodec.listPrefixed(U8)) { it.entries } - return ContactRosterPacket(mode, entries) - } -} diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CoopScoreboardRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CoopScoreboardRequestPacket.kt index a88ff38..b45da47 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CoopScoreboardRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CoopScoreboardRequestPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class CoopScoreboardRequestPacket object CoopScoreboardRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): CoopScoreboardRequestPacket { - return CoopScoreboardRequestPacket() - } + override fun CodecScope.body(): CoopScoreboardRequestPacket { + return CoopScoreboardRequestPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateCharacterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateCharacterPacket.kt index 6547345..02e50bd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateCharacterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateCharacterPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class CreateCharacterPacket(val name: String) object CreateCharacterPacketCodec : PacketCodec() { - override fun CodecScope.body(): CreateCharacterPacket { - val name = field(Utf16LeNullTerminated) { it.name } - return CreateCharacterPacket(name) - } + override fun CodecScope.body(): CreateCharacterPacket { + val name = field(Utf16LeNullTerminated) { it.name } + return CreateCharacterPacket(name) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateMarketListingPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateMarketListingPacket.kt index 7dc1623..a7464b0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateMarketListingPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CreateMarketListingPacket.kt @@ -10,11 +10,11 @@ data class CreateMarketListingPacket( ) object CreateMarketListingPacketCodec : PacketCodec() { - override fun CodecScope.body(): CreateMarketListingPacket { - val entryKind = field(S8) { it.entryKind } - val entityId = field(S64LE) { it.entityId } - val price = field(S32LE) { it.price } - val quantity = field(S16LE) { it.quantity } - return CreateMarketListingPacket(entryKind, entityId, price, quantity) - } + override fun CodecScope.body(): CreateMarketListingPacket { + val entryKind = field(S8) { it.entryKind } + val entityId = field(S64LE) { it.entityId } + val price = field(S32LE) { it.price } + val quantity = field(S16LE) { it.quantity } + return CreateMarketListingPacket(entryKind, entityId, price, quantity) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CurrencyBalancePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CurrencyBalancePacket.kt index cd8501d..f640761 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CurrencyBalancePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CurrencyBalancePacket.kt @@ -10,9 +10,9 @@ data class CurrencyBalancePacket( ) object CurrencyBalancePacketCodec : PacketCodec() { - override fun CodecScope.body(): CurrencyBalancePacket { - val primaryBalance = field(S32LE) { it.primaryBalance } - val secondaryBalance = field(S32LE) { it.secondaryBalance } - return CurrencyBalancePacket(primaryBalance, secondaryBalance) - } + override fun CodecScope.body(): CurrencyBalancePacket { + val primaryBalance = field(S32LE) { it.primaryBalance } + val secondaryBalance = field(S32LE) { it.secondaryBalance } + return CurrencyBalancePacket(primaryBalance, secondaryBalance) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizationAcceptPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizationAcceptPacket.kt index 9577f99..d6be365 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizationAcceptPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizationAcceptPacket.kt @@ -7,9 +7,9 @@ import de.fiereu.bytecodec.S64LE data class CustomizationAcceptPacket(val entityId: Long, val verificationToken: Long) object CustomizationAcceptPacketCodec : PacketCodec() { - override fun CodecScope.body(): CustomizationAcceptPacket { - val entityId = field(S64LE) { it.entityId } - val verificationToken = field(S64LE) { it.verificationToken } - return CustomizationAcceptPacket(entityId, verificationToken) - } + override fun CodecScope.body(): CustomizationAcceptPacket { + val entityId = field(S64LE) { it.entityId } + val verificationToken = field(S64LE) { it.verificationToken } + return CustomizationAcceptPacket(entityId, verificationToken) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizeCharacterAppearancePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizeCharacterAppearancePacket.kt index 19fc36a..d5b7062 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizeCharacterAppearancePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/CustomizeCharacterAppearancePacket.kt @@ -15,30 +15,30 @@ data class CreatureMoveset( private val CreatureMovesetCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): CreatureMoveset { - val headerByte = S8.read(buf) - val moveMask = S16LE.read(buf) - val hasExtra = (moveMask.toInt() and 0x8000) != 0 - val moves = ArrayList() - for (slot in 0 until 15) { - if ((moveMask.toInt() and (1 shl slot)) != 0) { - val packed = S16LE.read(buf) - val extra = if (hasExtra) S8.read(buf) else null - moves.add(CreatureMoveEntry(packed, extra)) - } - } - return CreatureMoveset(headerByte, moveMask, moves) + override fun read(buf: ReadBuffer): CreatureMoveset { + val headerByte = S8.read(buf) + val moveMask = S16LE.read(buf) + val hasExtra = (moveMask.toInt() and 0x8000) != 0 + val moves = ArrayList() + for (slot in 0 until 15) { + if ((moveMask.toInt() and (1 shl slot)) != 0) { + val packed = S16LE.read(buf) + val extra = if (hasExtra) S8.read(buf) else null + moves.add(CreatureMoveEntry(packed, extra)) + } } + return CreatureMoveset(headerByte, moveMask, moves) + } - override fun write(buf: WriteBuffer, value: CreatureMoveset) { - S8.write(buf, value.headerByte) - S16LE.write(buf, value.moveMask) - val hasExtra = (value.moveMask.toInt() and 0x8000) != 0 - for (move in value.moves) { - S16LE.write(buf, move.packed) - if (hasExtra && move.extra != null) S8.write(buf, move.extra) - } + override fun write(buf: WriteBuffer, value: CreatureMoveset) { + S8.write(buf, value.headerByte) + S16LE.write(buf, value.moveMask) + val hasExtra = (value.moveMask.toInt() and 0x8000) != 0 + for (move in value.moves) { + S16LE.write(buf, move.packed) + if (hasExtra && move.extra != null) S8.write(buf, move.extra) } + } } data class CustomizeCharacterAppearancePacket( @@ -49,17 +49,15 @@ data class CustomizeCharacterAppearancePacket( val paletteIndex: Byte, ) -object CustomizeCharacterAppearancePacketCodec : - PacketCodec() { - override fun CodecScope.body(): - CustomizeCharacterAppearancePacket { - val entityId = field(S64LE) { it.entityId } - val colorCategoryId = field(S8) { it.colorCategoryId } - val colorSlot = field(S8) { it.colorSlot } - val moveSet = field(CreatureMovesetCodec) { it.moveSet } - val paletteIndex = field(S8) { it.paletteIndex } - return CustomizeCharacterAppearancePacket( - entityId, colorCategoryId, colorSlot, moveSet, paletteIndex - ) - } +object CustomizeCharacterAppearancePacketCodec : PacketCodec() { + override fun CodecScope.body(): + CustomizeCharacterAppearancePacket { + val entityId = field(S64LE) { it.entityId } + val colorCategoryId = field(S8) { it.colorCategoryId } + val colorSlot = field(S8) { it.colorSlot } + val moveSet = field(CreatureMovesetCodec) { it.moveSet } + val paletteIndex = field(S8) { it.paletteIndex } + return CustomizeCharacterAppearancePacket( + entityId, colorCategoryId, colorSlot, moveSet, paletteIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataContentSyncBatchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataContentSyncBatchPacket.kt index e305847..16a4667 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataContentSyncBatchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataContentSyncBatchPacket.kt @@ -6,31 +6,31 @@ data class DataContentSyncBatchPacket( val count: Int, val recordsData: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is DataContentSyncBatchPacket && - count == other.count && - recordsData.contentEquals(other.recordsData) + override fun equals(other: Any?): Boolean = + other is DataContentSyncBatchPacket && + count == other.count && + recordsData.contentEquals(other.recordsData) - override fun hashCode(): Int = count * 31 + recordsData.contentHashCode() + override fun hashCode(): Int = count * 31 + recordsData.contentHashCode() } private val ContentRecordsBytes: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object DataContentSyncBatchPacketCodec : PacketCodec() { - override fun CodecScope.body(): DataContentSyncBatchPacket { - val count = field(U8) { it.count } - val recordsData = field(ContentRecordsBytes) { it.recordsData } - return DataContentSyncBatchPacket(count, recordsData) - } + override fun CodecScope.body(): DataContentSyncBatchPacket { + val count = field(U8) { it.count } + val recordsData = field(ContentRecordsBytes) { it.recordsData } + return DataContentSyncBatchPacket(count, recordsData) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncBatchedPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncBatchedPacket.kt index 4f73a18..c02a789 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncBatchedPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncBatchedPacket.kt @@ -9,20 +9,20 @@ data class DataDigestSyncBatchedPacket( val bitCount: Int, val digest: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is DataDigestSyncBatchedPacket && - bitCount == other.bitCount && - digest.contentEquals(other.digest) + override fun equals(other: Any?): Boolean = + other is DataDigestSyncBatchedPacket && + bitCount == other.bitCount && + digest.contentEquals(other.digest) - override fun hashCode(): Int = bitCount * 31 + digest.contentHashCode() + override fun hashCode(): Int = bitCount * 31 + digest.contentHashCode() } private val DigestBytes = bytesPrefixed(U16LE) object DataDigestSyncBatchedPacketCodec : PacketCodec() { - override fun CodecScope.body(): DataDigestSyncBatchedPacket { - val bitCount = field(U16LE) { it.bitCount } - val digest = field(DigestBytes) { it.digest } - return DataDigestSyncBatchedPacket(bitCount, digest) - } + override fun CodecScope.body(): DataDigestSyncBatchedPacket { + val bitCount = field(U16LE) { it.bitCount } + val digest = field(DigestBytes) { it.digest } + return DataDigestSyncBatchedPacket(bitCount, digest) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncPacket.kt index 6aab452..c10444f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncPacket.kt @@ -9,20 +9,20 @@ data class DataDigestSyncPacket( val bitCount: Int, val digest: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is DataDigestSyncPacket && - bitCount == other.bitCount && - digest.contentEquals(other.digest) + override fun equals(other: Any?): Boolean = + other is DataDigestSyncPacket && + bitCount == other.bitCount && + digest.contentEquals(other.digest) - override fun hashCode(): Int = bitCount * 31 + digest.contentHashCode() + override fun hashCode(): Int = bitCount * 31 + digest.contentHashCode() } private val DigestBytes = bytesPrefixed(U16LE) object DataDigestSyncPacketCodec : PacketCodec() { - override fun CodecScope.body(): DataDigestSyncPacket { - val bitCount = field(U16LE) { it.bitCount } - val digest = field(DigestBytes) { it.digest } - return DataDigestSyncPacket(bitCount, digest) - } + override fun CodecScope.body(): DataDigestSyncPacket { + val bitCount = field(U16LE) { it.bitCount } + val digest = field(DigestBytes) { it.digest } + return DataDigestSyncPacket(bitCount, digest) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncResponsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncResponsePacket.kt index b7e808d..3e08bfb 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncResponsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DataDigestSyncResponsePacket.kt @@ -6,31 +6,31 @@ data class DataDigestSyncResponsePacket( val count: Int, val entriesData: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is DataDigestSyncResponsePacket && - count == other.count && - entriesData.contentEquals(other.entriesData) + override fun equals(other: Any?): Boolean = + other is DataDigestSyncResponsePacket && + count == other.count && + entriesData.contentEquals(other.entriesData) - override fun hashCode(): Int = count * 31 + entriesData.contentHashCode() + override fun hashCode(): Int = count * 31 + entriesData.contentHashCode() } private val DigestEntriesBytes: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object DataDigestSyncResponsePacketCodec : PacketCodec() { - override fun CodecScope.body(): DataDigestSyncResponsePacket { - val count = field(U8) { it.count } - val entriesData = field(DigestEntriesBytes) { it.entriesData } - return DataDigestSyncResponsePacket(count, entriesData) - } + override fun CodecScope.body(): DataDigestSyncResponsePacket { + val count = field(U8) { it.count } + val entriesData = field(DigestEntriesBytes) { it.entriesData } + return DataDigestSyncResponsePacket(count, entriesData) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt index f5a50d6..2d4a40c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogActionPacket.kt @@ -9,10 +9,10 @@ object NullMessageArg : DialogMessageArg() data class CreatureDataArg(val value: Int, val args: List) : DialogMessageArg() data class CreatureMovesArg(val team: Byte, val moveIds: List) : DialogMessageArg() { - override fun equals(other: Any?): Boolean = - other is CreatureMovesArg && team == other.team && moveIds == other.moveIds + override fun equals(other: Any?): Boolean = + other is CreatureMovesArg && team == other.team && moveIds == other.moveIds - override fun hashCode(): Int = team * 31 + moveIds.hashCode() + override fun hashCode(): Int = team * 31 + moveIds.hashCode() } data class MoveAnimationArg(val sourceSlot: Byte, val targetSlot: Byte, val moveId: Short) : @@ -27,76 +27,76 @@ data class TextCreatureArg( private val DialogMessageArgCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): DialogMessageArg = - when (val tag = buf.readByte().toInt()) { - -1 -> NullMessageArg - 0 -> { - val value = S32LE.read(buf) - val count = U8.read(buf) - CreatureDataArg(value, List(count) { read(buf) }) - } - - 1 -> { - val team = buf.readByte() - val count = U8.read(buf) - CreatureMovesArg(team, List(count) { S16LE.read(buf) }) - } - - 2 -> { - val moveId = S16LE.read(buf) - MoveAnimationArg(buf.readByte(), buf.readByte(), moveId) - } - - 3 -> TextCreatureArg(buf.readByte(), buf.readByte(), S16LE.read(buf), S16LE.read(buf)) - else -> throw MalformedPacketException("unknown dialog message arg tag $tag") + override fun read(buf: ReadBuffer): DialogMessageArg = + when (val tag = buf.readByte().toInt()) { + -1 -> NullMessageArg + 0 -> { + val value = S32LE.read(buf) + val count = U8.read(buf) + CreatureDataArg(value, List(count) { read(buf) }) } - override fun write(buf: WriteBuffer, value: DialogMessageArg) { - when (value) { - is NullMessageArg -> buf.writeByte((-1).toByte()) - is CreatureDataArg -> { - buf.writeByte(0) - S32LE.write(buf, value.value) - U8.write(buf, value.args.size) - value.args.forEach { write(buf, it) } - } - - is CreatureMovesArg -> { - buf.writeByte(1) - buf.writeByte(value.team) - U8.write(buf, value.moveIds.size) - value.moveIds.forEach { S16LE.write(buf, it) } - } - - is MoveAnimationArg -> { - buf.writeByte(2) - S16LE.write(buf, value.moveId) - buf.writeByte(value.sourceSlot) - buf.writeByte(value.targetSlot) - } - - is TextCreatureArg -> { - buf.writeByte(3) - buf.writeByte(value.slot) - buf.writeByte(value.statusId) - S16LE.write(buf, value.value1) - S16LE.write(buf, value.value2) - } + 1 -> { + val team = buf.readByte() + val count = U8.read(buf) + CreatureMovesArg(team, List(count) { S16LE.read(buf) }) } + + 2 -> { + val moveId = S16LE.read(buf) + MoveAnimationArg(buf.readByte(), buf.readByte(), moveId) + } + + 3 -> TextCreatureArg(buf.readByte(), buf.readByte(), S16LE.read(buf), S16LE.read(buf)) + else -> throw MalformedPacketException("unknown dialog message arg tag $tag") + } + + override fun write(buf: WriteBuffer, value: DialogMessageArg) { + when (value) { + is NullMessageArg -> buf.writeByte((-1).toByte()) + is CreatureDataArg -> { + buf.writeByte(0) + S32LE.write(buf, value.value) + U8.write(buf, value.args.size) + value.args.forEach { write(buf, it) } + } + + is CreatureMovesArg -> { + buf.writeByte(1) + buf.writeByte(value.team) + U8.write(buf, value.moveIds.size) + value.moveIds.forEach { S16LE.write(buf, it) } + } + + is MoveAnimationArg -> { + buf.writeByte(2) + S16LE.write(buf, value.moveId) + buf.writeByte(value.sourceSlot) + buf.writeByte(value.targetSlot) + } + + is TextCreatureArg -> { + buf.writeByte(3) + buf.writeByte(value.slot) + buf.writeByte(value.statusId) + S16LE.write(buf, value.value1) + S16LE.write(buf, value.value2) + } } + } } private val DialogActionDetail: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } data class DialogActionPacket( @@ -108,45 +108,45 @@ data class DialogActionPacket( val messageArgs: List, val detail: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is DialogActionPacket && - flags == other.flags && - actionType == other.actionType && - textId == other.textId && - entityId == other.entityId && - contextValue == other.contextValue && - messageArgs == other.messageArgs && - detail.contentEquals(other.detail) + override fun equals(other: Any?): Boolean = + other is DialogActionPacket && + flags == other.flags && + actionType == other.actionType && + textId == other.textId && + entityId == other.entityId && + contextValue == other.contextValue && + messageArgs == other.messageArgs && + detail.contentEquals(other.detail) - override fun hashCode(): Int { - var r = flags.toInt() - r = r * 31 + actionType - r = r * 31 + textId - r = r * 31 + entityId.hashCode() - r = r * 31 + contextValue - r = r * 31 + messageArgs.hashCode() - r = r * 31 + detail.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = flags.toInt() + r = r * 31 + actionType + r = r * 31 + textId + r = r * 31 + entityId.hashCode() + r = r * 31 + contextValue + r = r * 31 + messageArgs.hashCode() + r = r * 31 + detail.contentHashCode() + return r + } } object DialogActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): DialogActionPacket { - val flags = field(S8) { it.flags } - val actionType = field(S8) { it.actionType } - val textId = field(S32LE) { it.textId } - val entityId = field(S64LE) { it.entityId } - val contextValue = field(S32LE) { it.contextValue } - val messageArgs = field(DialogMessageArgCodec.listPrefixed(U8)) { it.messageArgs } - val detail = field(DialogActionDetail) { it.detail } - return DialogActionPacket( - flags = flags, - actionType = actionType, - textId = textId, - entityId = entityId, - contextValue = contextValue, - messageArgs = messageArgs, - detail = detail, - ) - } -} \ No newline at end of file + override fun CodecScope.body(): DialogActionPacket { + val flags = field(S8) { it.flags } + val actionType = field(S8) { it.actionType } + val textId = field(S32LE) { it.textId } + val entityId = field(S64LE) { it.entityId } + val contextValue = field(S32LE) { it.contextValue } + val messageArgs = field(DialogMessageArgCodec.listPrefixed(U8)) { it.messageArgs } + val detail = field(DialogActionDetail) { it.detail } + return DialogActionPacket( + flags = flags, + actionType = actionType, + textId = textId, + entityId = entityId, + contextValue = contextValue, + messageArgs = messageArgs, + detail = detail, + ) + } +} diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogChoicePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogChoicePacket.kt index c660907..b3ef395 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogChoicePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogChoicePacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.U8 data class DialogChoicePacket(val unk1: Int, val unk2: Int) object DialogChoicePacketCodec : PacketCodec() { - override fun CodecScope.body(): DialogChoicePacket { - val unk1 = field(U8) { it.unk1 } - val unk2 = field(U16LE) { it.unk2 } - return DialogChoicePacket(unk1, unk2) - } + override fun CodecScope.body(): DialogChoicePacket { + val unk1 = field(U8) { it.unk1 } + val unk2 = field(U16LE) { it.unk2 } + return DialogChoicePacket(unk1, unk2) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogDataPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogDataPacket.kt index 2ff8581..c97b060 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogDataPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogDataPacket.kt @@ -8,41 +8,41 @@ data class DialogDataPacket( val type: Int, val data: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is DialogDataPacket && - entityId == other.entityId && - unk1 == other.unk1 && - type == other.type && - data.contentEquals(other.data) + override fun equals(other: Any?): Boolean = + other is DialogDataPacket && + entityId == other.entityId && + unk1 == other.unk1 && + type == other.type && + data.contentEquals(other.data) - override fun hashCode(): Int { - var result = entityId.hashCode() - result = 31 * result + unk1 - result = 31 * result + type - result = 31 * result + data.contentHashCode() - return result - } + override fun hashCode(): Int { + var result = entityId.hashCode() + result = 31 * result + unk1 + result = 31 * result + type + result = 31 * result + data.contentHashCode() + return result + } } object RemainingBytes : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val n = buf.remaining() - val arr = ByteArray(n) - if (n > 0) buf.readBytes(arr) - return arr - } + override fun read(buf: ReadBuffer): ByteArray { + val n = buf.remaining() + val arr = ByteArray(n) + if (n > 0) buf.readBytes(arr) + return arr + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object DialogDataPacketCodec : PacketCodec() { - override fun CodecScope.body(): DialogDataPacket { - val entityId = field(S64LE) { it.entityId } - val unk1 = field(U8) { it.unk1 } - val type = field(U8) { it.type } - val data = field(RemainingBytes) { it.data } - return DialogDataPacket(entityId, unk1, type, data) - } + override fun CodecScope.body(): DialogDataPacket { + val entityId = field(S64LE) { it.entityId } + val unk1 = field(U8) { it.unk1 } + val type = field(U8) { it.type } + val data = field(RemainingBytes) { it.data } + return DialogDataPacket(entityId, unk1, type, data) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogResponsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogResponsePacket.kt index c92ae41..fdb21a8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogResponsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DialogResponsePacket.kt @@ -11,9 +11,9 @@ data class DialogResponsePacket( ) object DialogResponsePacketCodec : PacketCodec() { - override fun CodecScope.body(): DialogResponsePacket { - val accepted = field(Bool) { it.accepted } - val dialogActionId = field(S16LE) { it.dialogActionId } - return DialogResponsePacket(accepted, dialogActionId) - } + override fun CodecScope.body(): DialogResponsePacket { + val accepted = field(Bool) { it.accepted } + val dialogActionId = field(S16LE) { it.dialogActionId } + return DialogResponsePacket(accepted, dialogActionId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DisconnectNoticePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DisconnectNoticePacket.kt index 03e8fb4..51705a0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DisconnectNoticePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DisconnectNoticePacket.kt @@ -12,12 +12,12 @@ data class DisconnectNoticePacket( ) object DisconnectNoticePacketCodec : PacketCodec() { - override fun CodecScope.body(): DisconnectNoticePacket { - val hasBuildInfo = field(U8) { if (it.buildInfo != null) 1 else 0 } == 1 - val buildInfo = if (hasBuildInfo) field(S8) { it.buildInfo!! } else null - val hasReasonMode = field(U8) { if (it.reasonMode != null) 1 else 0 } == 1 - val reasonMode = if (hasReasonMode) field(S8) { it.reasonMode!! } else null - val forced = field(U8) { if (it.forced) 1 else 0 } == 1 - return DisconnectNoticePacket(buildInfo, reasonMode, forced) - } + override fun CodecScope.body(): DisconnectNoticePacket { + val hasBuildInfo = field(U8) { if (it.buildInfo != null) 1 else 0 } == 1 + val buildInfo = if (hasBuildInfo) field(S8) { it.buildInfo!! } else null + val hasReasonMode = field(U8) { if (it.reasonMode != null) 1 else 0 } == 1 + val reasonMode = if (hasReasonMode) field(S8) { it.reasonMode!! } else null + val forced = field(U8) { if (it.forced) 1 else 0 } == 1 + return DisconnectNoticePacket(buildInfo, reasonMode, forced) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelChallengePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelChallengePacket.kt index a998f13..d7ecd56 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelChallengePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelChallengePacket.kt @@ -23,62 +23,62 @@ data class DuelChallengePacket( private val DuelItemRestrictionCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): DuelItemRestriction { - val typeId = S8.read(buf) - return DuelItemRestriction(typeId, null) - } + override fun read(buf: ReadBuffer): DuelItemRestriction { + val typeId = S8.read(buf) + return DuelItemRestriction(typeId, null) + } - override fun write(buf: WriteBuffer, value: DuelItemRestriction) { - S8.write(buf, value.typeId) - if (value.extra != null) S8.write(buf, value.extra) - } + override fun write(buf: WriteBuffer, value: DuelItemRestriction) { + S8.write(buf, value.typeId) + if (value.extra != null) S8.write(buf, value.extra) + } } object DuelChallengePacketCodec : PacketCodec() { - override fun CodecScope.body(): DuelChallengePacket { - val targetPlayerName = field(Utf16LeNullTerminated) { it.targetPlayerName } - val battleTypeId = field(S8) { it.battleTypeId } - val flags = - field(U8) { v -> - var f = 0 - if (v.timed) f = f or 1 - if (v.itemLevelCap != null) f = f or 8 - if (v.natureCap != null) f = f or 16 - if (v.items != null) f = f or 32 - if (v.tier != null) f = f or 64 - f - } - val battleFormat = field(S8) { it.battleFormat } - val typeRestriction = field(S8) { it.typeRestriction } - val natureRestriction = field(S8) { it.natureRestriction } - val allowedFormat = field(S8) { it.allowedFormat } - val timed = flags and 1 != 0 - val itemLevelCap: Byte? = if (flags and 8 != 0) field(S8) { it.itemLevelCap!! } else null - val natureCap: Byte? = if (flags and 16 != 0) field(S8) { it.natureCap!! } else null - val items: List? = - if (flags and 32 != 0) { - val count = field(U8) { it.items!!.size } - val list = ArrayList(count) - var i = 0 - while (i < count) { - list.add(field(DuelItemRestrictionCodec) { v -> v.items!![list.size] }) - i++ - } - list - } else null - val tier: Byte? = if (flags and 64 != 0) field(S8) { it.tier!! } else null - return DuelChallengePacket( - targetPlayerName = targetPlayerName, - battleTypeId = battleTypeId, - timed = timed, - battleFormat = battleFormat, - typeRestriction = typeRestriction, - natureRestriction = natureRestriction, - allowedFormat = allowedFormat, - itemLevelCap = itemLevelCap, - natureCap = natureCap, - items = items, - tier = tier, - ) - } + override fun CodecScope.body(): DuelChallengePacket { + val targetPlayerName = field(Utf16LeNullTerminated) { it.targetPlayerName } + val battleTypeId = field(S8) { it.battleTypeId } + val flags = + field(U8) { v -> + var f = 0 + if (v.timed) f = f or 1 + if (v.itemLevelCap != null) f = f or 8 + if (v.natureCap != null) f = f or 16 + if (v.items != null) f = f or 32 + if (v.tier != null) f = f or 64 + f + } + val battleFormat = field(S8) { it.battleFormat } + val typeRestriction = field(S8) { it.typeRestriction } + val natureRestriction = field(S8) { it.natureRestriction } + val allowedFormat = field(S8) { it.allowedFormat } + val timed = flags and 1 != 0 + val itemLevelCap: Byte? = if (flags and 8 != 0) field(S8) { it.itemLevelCap!! } else null + val natureCap: Byte? = if (flags and 16 != 0) field(S8) { it.natureCap!! } else null + val items: List? = + if (flags and 32 != 0) { + val count = field(U8) { it.items!!.size } + val list = ArrayList(count) + var i = 0 + while (i < count) { + list.add(field(DuelItemRestrictionCodec) { v -> v.items!![list.size] }) + i++ + } + list + } else null + val tier: Byte? = if (flags and 64 != 0) field(S8) { it.tier!! } else null + return DuelChallengePacket( + targetPlayerName = targetPlayerName, + battleTypeId = battleTypeId, + timed = timed, + battleFormat = battleFormat, + typeRestriction = typeRestriction, + natureRestriction = natureRestriction, + allowedFormat = allowedFormat, + itemLevelCap = itemLevelCap, + natureCap = natureCap, + items = items, + tier = tier, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInviteOutcomePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInviteOutcomePacket.kt index 6e555c3..728d3d8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInviteOutcomePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInviteOutcomePacket.kt @@ -9,8 +9,8 @@ data class DuelInviteOutcomePacket( ) object DuelInviteOutcomePacketCodec : PacketCodec() { - override fun CodecScope.body(): DuelInviteOutcomePacket { - val packed = field(S8) { it.packed } - return DuelInviteOutcomePacket(packed) - } + override fun CodecScope.body(): DuelInviteOutcomePacket { + val packed = field(S8) { it.packed } + return DuelInviteOutcomePacket(packed) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInvitePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInvitePacket.kt index d797ace..8613874 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInvitePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/DuelInvitePacket.kt @@ -12,10 +12,10 @@ data class DuelInvitePacket( ) object DuelInvitePacketCodec : PacketCodec() { - override fun CodecScope.body(): DuelInvitePacket { - val flags = field(S8) { it.flags } - val requestType = field(S8) { it.requestType } - val name = field(Utf16LeNullTerminated) { it.name } - return DuelInvitePacket(flags, requestType, name) - } + override fun CodecScope.body(): DuelInvitePacket { + val flags = field(S8) { it.flags } + val requestType = field(S8) { it.requestType } + val name = field(Utf16LeNullTerminated) { it.name } + return DuelInvitePacket(flags, requestType, name) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EggIncubatorSlotsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EggIncubatorSlotsPacket.kt index d751dee..4279dbe 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EggIncubatorSlotsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EggIncubatorSlotsPacket.kt @@ -11,29 +11,29 @@ data class EggIncubatorSlotsPacket( ) private object EggIncubatorSlotCodec : PacketCodec() { - override fun CodecScope.body(): EggIncubatorSlot { - field(S64LE) { 0L } - val value = field(S16LE, EggIncubatorSlot::value) - return EggIncubatorSlot(value) - } + override fun CodecScope.body(): EggIncubatorSlot { + field(S64LE) { 0L } + val value = field(S16LE, EggIncubatorSlot::value) + return EggIncubatorSlot(value) + } } private val EggIncubatorSlotListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { EggIncubatorSlotCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { EggIncubatorSlotCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { EggIncubatorSlotCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { EggIncubatorSlotCodec.write(buf, it) } + } } object EggIncubatorSlotsPacketCodec : PacketCodec() { - override fun CodecScope.body(): EggIncubatorSlotsPacket { - val slots = field(EggIncubatorSlotListPrefixedU8, EggIncubatorSlotsPacket::slots) - return EggIncubatorSlotsPacket(slots) - } + override fun CodecScope.body(): EggIncubatorSlotsPacket { + val slots = field(EggIncubatorSlotListPrefixedU8, EggIncubatorSlotsPacket::slots) + return EggIncubatorSlotsPacket(slots) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityActionRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityActionRequestPacket.kt index 566920c..b97bb7f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityActionRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityActionRequestPacket.kt @@ -13,11 +13,11 @@ data class EntityActionRequestPacket( ) object EntityActionRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityActionRequestPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - val actionType = field(S16LE) { it.actionType } - val sourceEntityId = field(S64LE) { it.sourceEntityId } - val entityId = field(S64LE) { it.entityId } - return EntityActionRequestPacket(targetEntityId, actionType, sourceEntityId, entityId) - } + override fun CodecScope.body(): EntityActionRequestPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + val actionType = field(S16LE) { it.actionType } + val sourceEntityId = field(S64LE) { it.sourceEntityId } + val entityId = field(S64LE) { it.entityId } + return EntityActionRequestPacket(targetEntityId, actionType, sourceEntityId, entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearancePatchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearancePatchPacket.kt index 2136c9c..9c0b96f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearancePatchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearancePatchPacket.kt @@ -13,15 +13,15 @@ data class EntityAppearance( private val EntityAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityAppearance { - val name = field(Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val formId = field(S32LE) { it.formId } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return EntityAppearance(name, gender, formId, kind, palettePack, slots) - } + override fun CodecScope.body(): EntityAppearance { + val name = field(Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val formId = field(S32LE) { it.formId } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return EntityAppearance(name, gender, formId, kind, palettePack, slots) + } } data class EntityCosmetic( @@ -39,32 +39,32 @@ data class EntityAppearancePatchPacket( ) object EntityAppearancePatchPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityAppearancePatchPacket { - val entityId = field(S64LE) { it.entityId } - val spriteId = field(S16LE) { it.spriteId } - val flags = - field(S8) { v -> - ((if (v.direction != null) 1 else 0) or - (if (v.animation != null) 2 else 0) or - (if (v.appearance != null) 4 else 0) or - (if (v.cosmetics != null) 8 else 0)) - .toByte() - } - val flagsInt = flags.toInt() - val direction = if (flagsInt and 1 != 0) field(S8) { it.direction!! } else null - val animation = if (flagsInt and 2 != 0) field(S16LE) { it.animation!! } else null - val appearance = if (flagsInt and 4 != 0) field(EntityAppearanceCodec) { it.appearance!! } else null - val cosmetics = - if (flagsInt and 8 != 0) { - val count = field(S8) { it.cosmetics!!.size.toByte() }.toInt() - (0 until count).map { i -> - val cosmeticId = field(S16LE) { it.cosmetics!![i].cosmeticId } - val cosmeticValue = field(S8) { it.cosmetics!![i].cosmeticValue } - EntityCosmetic(cosmeticId, cosmeticValue) - } - } else null - return EntityAppearancePatchPacket( - entityId, spriteId, direction, animation, appearance, cosmetics - ) - } + override fun CodecScope.body(): EntityAppearancePatchPacket { + val entityId = field(S64LE) { it.entityId } + val spriteId = field(S16LE) { it.spriteId } + val flags = + field(S8) { v -> + ((if (v.direction != null) 1 else 0) or + (if (v.animation != null) 2 else 0) or + (if (v.appearance != null) 4 else 0) or + (if (v.cosmetics != null) 8 else 0)) + .toByte() + } + val flagsInt = flags.toInt() + val direction = if (flagsInt and 1 != 0) field(S8) { it.direction!! } else null + val animation = if (flagsInt and 2 != 0) field(S16LE) { it.animation!! } else null + val appearance = + if (flagsInt and 4 != 0) field(EntityAppearanceCodec) { it.appearance!! } else null + val cosmetics = + if (flagsInt and 8 != 0) { + val count = field(S8) { it.cosmetics!!.size.toByte() }.toInt() + (0 until count).map { i -> + val cosmeticId = field(S16LE) { it.cosmetics!![i].cosmeticId } + val cosmeticValue = field(S8) { it.cosmetics!![i].cosmeticValue } + EntityCosmetic(cosmeticId, cosmeticValue) + } + } else null + return EntityAppearancePatchPacket( + entityId, spriteId, direction, animation, appearance, cosmetics) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearanceSyncPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearanceSyncPacket.kt index 61caf42..c2414aa 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearanceSyncPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAppearanceSyncPacket.kt @@ -18,21 +18,21 @@ data class EntityAppearanceSyncPacket( private val EntitySpriteAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntitySpriteAppearance { - val name = field(de.fiereu.bytecodec.Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val id = field(S32LE) { it.id } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return EntitySpriteAppearance(name, gender, id, kind, palettePack, slots) - } + override fun CodecScope.body(): EntitySpriteAppearance { + val name = field(de.fiereu.bytecodec.Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val id = field(S32LE) { it.id } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return EntitySpriteAppearance(name, gender, id, kind, palettePack, slots) + } } object EntityAppearanceSyncPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityAppearanceSyncPacket { - val entityId = field(S64LE) { it.entityId } - val appearance = field(EntitySpriteAppearanceCodec) { it.appearance } - return EntityAppearanceSyncPacket(entityId, appearance) - } + override fun CodecScope.body(): EntityAppearanceSyncPacket { + val entityId = field(S64LE) { it.entityId } + val appearance = field(EntitySpriteAppearanceCodec) { it.appearance } + return EntityAppearanceSyncPacket(entityId, appearance) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAttributeChangePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAttributeChangePacket.kt index 98afe5c..cf08fb7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAttributeChangePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityAttributeChangePacket.kt @@ -16,27 +16,27 @@ data class EntityAttributeChangePacket( ) object EntityAttributeChangePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityAttributeChangePacket { - val entityId = field(S64LE) { it.entityId } - val type = field(S8) { it.type } - var text: String? = null - var item: Byte? = null - var value: Int? = null - when (type.toInt()) { - ENTITY_ATTRIBUTE_TYPE_NAME -> { - text = field(Utf16LeNullTerminated) { it.text!! } - } + override fun CodecScope.body(): EntityAttributeChangePacket { + val entityId = field(S64LE) { it.entityId } + val type = field(S8) { it.type } + var text: String? = null + var item: Byte? = null + var value: Int? = null + when (type.toInt()) { + ENTITY_ATTRIBUTE_TYPE_NAME -> { + text = field(Utf16LeNullTerminated) { it.text!! } + } - ENTITY_ATTRIBUTE_TYPE_ITEM -> { - item = field(S8) { it.item!! } - } + ENTITY_ATTRIBUTE_TYPE_ITEM -> { + item = field(S8) { it.item!! } + } - ENTITY_ATTRIBUTE_TYPE_INT_TEXT_A, - ENTITY_ATTRIBUTE_TYPE_INT_TEXT_B -> { - value = field(S32LE) { it.value!! } - text = field(Utf16LeNullTerminated) { it.text!! } - } - } - return EntityAttributeChangePacket(entityId, type, text, item, value) + ENTITY_ATTRIBUTE_TYPE_INT_TEXT_A, + ENTITY_ATTRIBUTE_TYPE_INT_TEXT_B -> { + value = field(S32LE) { it.value!! } + text = field(Utf16LeNullTerminated) { it.text!! } + } } + return EntityAttributeChangePacket(entityId, type, text, item, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityChecklistPromptPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityChecklistPromptPacket.kt index ee90b9b..f272032 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityChecklistPromptPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityChecklistPromptPacket.kt @@ -15,19 +15,19 @@ data class EntityChecklistPromptPacket( private val EntityChecklistItemCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityChecklistItem { - val entityId = field(S64LE) { it.entityId } - val checked = field(U8) { if (it.checked) 1 else 0 } == 1 - return EntityChecklistItem(entityId, checked) - } + override fun CodecScope.body(): EntityChecklistItem { + val entityId = field(S64LE) { it.entityId } + val checked = field(U8) { if (it.checked) 1 else 0 } == 1 + return EntityChecklistItem(entityId, checked) + } } object EntityChecklistPromptPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityChecklistPromptPacket { - val titleId = field(S32LE) { it.titleId } - val kind = if (titleId > 0) field(S8) { it.kind!! } else null - val items = - if (titleId > 0) field(EntityChecklistItemCodec.listPrefixed(U8)) { it.items!! } else null - return EntityChecklistPromptPacket(titleId, kind, items) - } + override fun CodecScope.body(): EntityChecklistPromptPacket { + val titleId = field(S32LE) { it.titleId } + val kind = if (titleId > 0) field(S8) { it.kind!! } else null + val items = + if (titleId > 0) field(EntityChecklistItemCodec.listPrefixed(U8)) { it.items!! } else null + return EntityChecklistPromptPacket(titleId, kind, items) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityCoordSyncPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityCoordSyncPacket.kt index 9b7573f..801accd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityCoordSyncPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityCoordSyncPacket.kt @@ -10,12 +10,12 @@ data class EntityCoordSyncPacket( ) object EntityCoordSyncPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityCoordSyncPacket { - val entityId = field(S64LE) { it.entityId } - val valueA = field(S32LE) { it.valueA } - val flag = field(U8) { if (it.flag) 1 else 0 } == 1 - field(S8) { 0 } - val valueB = field(S32LE) { it.valueB } - return EntityCoordSyncPacket(entityId, valueA, flag, valueB) - } + override fun CodecScope.body(): EntityCoordSyncPacket { + val entityId = field(S64LE) { it.entityId } + val valueA = field(S32LE) { it.valueA } + val flag = field(U8) { if (it.flag) 1 else 0 } == 1 + field(S8) { 0 } + val valueB = field(S32LE) { it.valueB } + return EntityCoordSyncPacket(entityId, valueA, flag, valueB) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityDespawnPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityDespawnPacket.kt index 287fcc3..fd73d72 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityDespawnPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityDespawnPacket.kt @@ -10,9 +10,9 @@ data class EntityDespawnPacket( ) object EntityDespawnPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityDespawnPacket { - reserved(byte = 0) - val entityId = field(S16LE) { it.entityId } - return EntityDespawnPacket(entityId) - } + override fun CodecScope.body(): EntityDespawnPacket { + reserved(byte = 0) + val entityId = field(S16LE) { it.entityId } + return EntityDespawnPacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityEmoteBubblePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityEmoteBubblePacket.kt index 2c76337..f2bf3d6 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityEmoteBubblePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityEmoteBubblePacket.kt @@ -9,16 +9,16 @@ data class EntityEmoteBubblePacket( ) object EntityEmoteBubblePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityEmoteBubblePacket { - val entityId = field(S64LE) { it.entityId } - val icon = field(S8) { it.icon } - val param = - if (icon != (-1).toByte()) { - val p = field(S16LE) { it.param!! } - field(S8) { 0 } - field(S8) { 0 } - p - } else null - return EntityEmoteBubblePacket(entityId, icon, param) - } + override fun CodecScope.body(): EntityEmoteBubblePacket { + val entityId = field(S64LE) { it.entityId } + val icon = field(S8) { it.icon } + val param = + if (icon != (-1).toByte()) { + val p = field(S16LE) { it.param!! } + field(S8) { 0 } + field(S8) { 0 } + p + } else null + return EntityEmoteBubblePacket(entityId, icon, param) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFaceTurnPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFaceTurnPacket.kt index 7d3868f..6c6302e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFaceTurnPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFaceTurnPacket.kt @@ -11,9 +11,9 @@ data class EntityFaceTurnPacket( ) object EntityFaceTurnPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityFaceTurnPacket { - val entityId = field(S64LE) { it.entityId } - val facing = field(S8) { it.facing } - return EntityFaceTurnPacket(entityId, facing) - } + override fun CodecScope.body(): EntityFaceTurnPacket { + val entityId = field(S64LE) { it.entityId } + val facing = field(S8) { it.facing } + return EntityFaceTurnPacket(entityId, facing) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFramesUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFramesUpdatePacket.kt index fe5eea0..348eb00 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFramesUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityFramesUpdatePacket.kt @@ -9,30 +9,30 @@ data class EntityFramesUpdatePacket( private val FramesFrameCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupListFrame { - val typeId = field(S16LE) { it.typeId } - val packed = field(S16LE) { it.packed } - val byteA = field(S8) { it.byteA } - val byteB = field(S8) { it.byteB } - val packed2 = field(S16LE) { it.packed2 } - return GroupListFrame(typeId, packed, byteA, byteB, packed2) - } + override fun CodecScope.body(): GroupListFrame { + val typeId = field(S16LE) { it.typeId } + val packed = field(S16LE) { it.packed } + val byteA = field(S8) { it.byteA } + val byteB = field(S8) { it.byteB } + val packed2 = field(S16LE) { it.packed2 } + return GroupListFrame(typeId, packed, byteA, byteB, packed2) + } } private val FramesSetCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupListFrameSet { - val count = field(U8) { it.frames.size } - val listType = if (count >= 1) field(S8) { it.listType ?: 0 } else null - val frames = (0 until count).map { i -> field(FramesFrameCodec) { it.frames[i] } } - return GroupListFrameSet(listType, frames) - } + override fun CodecScope.body(): GroupListFrameSet { + val count = field(U8) { it.frames.size } + val listType = if (count >= 1) field(S8) { it.listType ?: 0 } else null + val frames = (0 until count).map { i -> field(FramesFrameCodec) { it.frames[i] } } + return GroupListFrameSet(listType, frames) + } } object EntityFramesUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityFramesUpdatePacket { - val entityId = field(S64LE) { it.entityId } - val frames = field(FramesSetCodec) { it.frames } - return EntityFramesUpdatePacket(entityId, frames) - } + override fun CodecScope.body(): EntityFramesUpdatePacket { + val entityId = field(S64LE) { it.entityId } + val frames = field(FramesSetCodec) { it.frames } + return EntityFramesUpdatePacket(entityId, frames) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberAddPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberAddPacket.kt index 763a591..59626cd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberAddPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberAddPacket.kt @@ -8,52 +8,52 @@ data class EntityGroupMemberAddPacket( private val AddAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityAppearanceInfo { - val name = field(Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val formId = field(S32LE) { it.formId } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return EntityAppearanceInfo(name, gender, formId, kind, palettePack, slots) - } + override fun CodecScope.body(): EntityAppearanceInfo { + val name = field(Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val formId = field(S32LE) { it.formId } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return EntityAppearanceInfo(name, gender, formId, kind, palettePack, slots) + } } private val AddFrameCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupListFrame { - val typeId = field(S16LE) { it.typeId } - val packed = field(S16LE) { it.packed } - val byteA = field(S8) { it.byteA } - val byteB = field(S8) { it.byteB } - val packed2 = field(S16LE) { it.packed2 } - return GroupListFrame(typeId, packed, byteA, byteB, packed2) - } + override fun CodecScope.body(): GroupListFrame { + val typeId = field(S16LE) { it.typeId } + val packed = field(S16LE) { it.packed } + val byteA = field(S8) { it.byteA } + val byteB = field(S8) { it.byteB } + val packed2 = field(S16LE) { it.packed2 } + return GroupListFrame(typeId, packed, byteA, byteB, packed2) + } } private val AddFrameSetCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupListFrameSet { - val count = field(U8) { it.frames.size } - val listType = if (count >= 1) field(S8) { it.listType ?: 0 } else null - val frames = (0 until count).map { i -> field(AddFrameCodec) { it.frames[i] } } - return GroupListFrameSet(listType, frames) - } + override fun CodecScope.body(): GroupListFrameSet { + val count = field(U8) { it.frames.size } + val listType = if (count >= 1) field(S8) { it.listType ?: 0 } else null + val frames = (0 until count).map { i -> field(AddFrameCodec) { it.frames[i] } } + return GroupListFrameSet(listType, frames) + } } private val AddMemberCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityGroupMember { - val entityId = field(S64LE) { it.entityId } - val appearance = field(AddAppearanceCodec) { it.appearance } - val frames = field(AddFrameSetCodec) { it.frames } - return EntityGroupMember(entityId, appearance, frames) - } + override fun CodecScope.body(): EntityGroupMember { + val entityId = field(S64LE) { it.entityId } + val appearance = field(AddAppearanceCodec) { it.appearance } + val frames = field(AddFrameSetCodec) { it.frames } + return EntityGroupMember(entityId, appearance, frames) + } } object EntityGroupMemberAddPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityGroupMemberAddPacket { - val member = field(AddMemberCodec) { it.member } - return EntityGroupMemberAddPacket(member) - } + override fun CodecScope.body(): EntityGroupMemberAddPacket { + val member = field(AddMemberCodec) { it.member } + return EntityGroupMemberAddPacket(member) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberRemovePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberRemovePacket.kt index 4cdf912..7941351 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberRemovePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupMemberRemovePacket.kt @@ -10,9 +10,9 @@ data class EntityGroupMemberRemovePacket( ) object EntityGroupMemberRemovePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityGroupMemberRemovePacket { - val removedId = field(S64LE) { it.removedId } - val leaderId = field(S64LE) { it.leaderId } - return EntityGroupMemberRemovePacket(removedId, leaderId) - } + override fun CodecScope.body(): EntityGroupMemberRemovePacket { + val removedId = field(S64LE) { it.removedId } + val leaderId = field(S64LE) { it.leaderId } + return EntityGroupMemberRemovePacket(removedId, leaderId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupSnapshotPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupSnapshotPacket.kt index 875d311..5fe5081 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupSnapshotPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityGroupSnapshotPacket.kt @@ -38,55 +38,55 @@ data class EntityGroupSnapshotPacket( private val EntityAppearanceInfoCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityAppearanceInfo { - val name = field(Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val formId = field(S32LE) { it.formId } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return EntityAppearanceInfo(name, gender, formId, kind, palettePack, slots) - } + override fun CodecScope.body(): EntityAppearanceInfo { + val name = field(Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val formId = field(S32LE) { it.formId } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return EntityAppearanceInfo(name, gender, formId, kind, palettePack, slots) + } } private val GroupListFrameCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupListFrame { - val typeId = field(S16LE) { it.typeId } - val packed = field(S16LE) { it.packed } - val byteA = field(S8) { it.byteA } - val byteB = field(S8) { it.byteB } - val packed2 = field(S16LE) { it.packed2 } - return GroupListFrame(typeId, packed, byteA, byteB, packed2) - } + override fun CodecScope.body(): GroupListFrame { + val typeId = field(S16LE) { it.typeId } + val packed = field(S16LE) { it.packed } + val byteA = field(S8) { it.byteA } + val byteB = field(S8) { it.byteB } + val packed2 = field(S16LE) { it.packed2 } + return GroupListFrame(typeId, packed, byteA, byteB, packed2) + } } private val GroupListFrameSetCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupListFrameSet { - val count = field(U8) { it.frames.size } - val listType = if (count >= 1) field(S8) { it.listType ?: 0 } else null - val frames = (0 until count).map { i -> field(GroupListFrameCodec) { it.frames[i] } } - return GroupListFrameSet(listType, frames) - } + override fun CodecScope.body(): GroupListFrameSet { + val count = field(U8) { it.frames.size } + val listType = if (count >= 1) field(S8) { it.listType ?: 0 } else null + val frames = (0 until count).map { i -> field(GroupListFrameCodec) { it.frames[i] } } + return GroupListFrameSet(listType, frames) + } } private val EntityGroupMemberCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityGroupMember { - val entityId = field(S64LE) { it.entityId } - val appearance = field(EntityAppearanceInfoCodec) { it.appearance } - val frames = field(GroupListFrameSetCodec) { it.frames } - return EntityGroupMember(entityId, appearance, frames) - } + override fun CodecScope.body(): EntityGroupMember { + val entityId = field(S64LE) { it.entityId } + val appearance = field(EntityAppearanceInfoCodec) { it.appearance } + val frames = field(GroupListFrameSetCodec) { it.frames } + return EntityGroupMember(entityId, appearance, frames) + } } object EntityGroupSnapshotPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityGroupSnapshotPacket { - val present = field(U8) { if (it.present) 1 else 0 } == 1 - val leaderId = if (present) field(S64LE) { it.leaderId!! } else null - val members = - if (present) field(EntityGroupMemberCodec.listPrefixed(U8)) { it.members!! } else null - return EntityGroupSnapshotPacket(present, leaderId, members) - } + override fun CodecScope.body(): EntityGroupSnapshotPacket { + val present = field(U8) { if (it.present) 1 else 0 } == 1 + val leaderId = if (present) field(S64LE) { it.leaderId!! } else null + val members = + if (present) field(EntityGroupMemberCodec.listPrefixed(U8)) { it.members!! } else null + return EntityGroupSnapshotPacket(present, leaderId, members) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractPacket.kt index f214b67..f658f4e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractPacket.kt @@ -7,9 +7,9 @@ import de.fiereu.bytecodec.S64LE data class EntityInteractPacket(val entityId: Long, val token: Long) object EntityInteractPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityInteractPacket { - val entityId = field(S64LE) { it.entityId } - val token = field(S64LE) { it.token } - return EntityInteractPacket(entityId, token) - } + override fun CodecScope.body(): EntityInteractPacket { + val entityId = field(S64LE) { it.entityId } + val token = field(S64LE) { it.token } + return EntityInteractPacket(entityId, token) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractRequestPacket.kt index aa0dd55..9223641 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractRequestPacket.kt @@ -13,24 +13,24 @@ data class EntityInteractRequestPacket( ) object EntityInteractRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityInteractRequestPacket { - val interactionType = field(S8) { it.interactionType } - val hasSecondEntity = field(Bool) { it.secondaryEntityId != null } - val primaryEntityId = field(S64LE) { it.primaryEntityId } - val primaryX = field(S16LE) { it.primaryX } - val primaryY = field(S16LE) { it.primaryY } - val secondaryEntityId: Long? = - if (hasSecondEntity) field(S64LE) { it.secondaryEntityId!! } else null - val secondaryX: Short? = if (hasSecondEntity) field(S16LE) { it.secondaryX!! } else null - val secondaryY: Short? = if (hasSecondEntity) field(S16LE) { it.secondaryY!! } else null - return EntityInteractRequestPacket( - interactionType, - primaryEntityId, - primaryX, - primaryY, - secondaryEntityId, - secondaryX, - secondaryY, - ) - } + override fun CodecScope.body(): EntityInteractRequestPacket { + val interactionType = field(S8) { it.interactionType } + val hasSecondEntity = field(Bool) { it.secondaryEntityId != null } + val primaryEntityId = field(S64LE) { it.primaryEntityId } + val primaryX = field(S16LE) { it.primaryX } + val primaryY = field(S16LE) { it.primaryY } + val secondaryEntityId: Long? = + if (hasSecondEntity) field(S64LE) { it.secondaryEntityId!! } else null + val secondaryX: Short? = if (hasSecondEntity) field(S16LE) { it.secondaryX!! } else null + val secondaryY: Short? = if (hasSecondEntity) field(S16LE) { it.secondaryY!! } else null + return EntityInteractRequestPacket( + interactionType, + primaryEntityId, + primaryX, + primaryY, + secondaryEntityId, + secondaryX, + secondaryY, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractionFlagPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractionFlagPacket.kt index 18f9050..9aba694 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractionFlagPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityInteractionFlagPacket.kt @@ -11,9 +11,9 @@ data class EntityInteractionFlagPacket( ) object EntityInteractionFlagPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityInteractionFlagPacket { - val entityId = field(S64LE) { it.entityId } - val flag = field(S8) { it.flag } - return EntityInteractionFlagPacket(entityId, flag) - } + override fun CodecScope.body(): EntityInteractionFlagPacket { + val entityId = field(S64LE) { it.entityId } + val flag = field(S8) { it.flag } + return EntityInteractionFlagPacket(entityId, flag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityLeavePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityLeavePacket.kt index 1e71d7a..1489228 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityLeavePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityLeavePacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S64BE data class EntityLeavePacket(val entityId: Long) object EntityLeavePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityLeavePacket { - val entityId = field(S64BE) { it.entityId } - return EntityLeavePacket(entityId) - } + override fun CodecScope.body(): EntityLeavePacket { + val entityId = field(S64BE) { it.entityId } + return EntityLeavePacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePacket.kt index c6d488b..6fceaea 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePacket.kt @@ -14,16 +14,16 @@ data class EntityMovePacket( ) object EntityMovePacketCodec : PacketCodec() { - private val DirectionCodec = enumByOrdinalByte() + private val DirectionCodec = enumByOrdinalByte() - override fun CodecScope.body(): EntityMovePacket { - val entityId = field(S64BE) { it.entityId } - val marker = field(S8) { it.marker } - val subtype = field(S8) { it.subtype } - val seq = field(S8) { it.seq } - val x = field(S8) { it.x } - val y = field(S8) { it.y } - val direction = field(DirectionCodec) { it.direction } - return EntityMovePacket(entityId, marker, subtype, seq, x, y, direction) - } + override fun CodecScope.body(): EntityMovePacket { + val entityId = field(S64BE) { it.entityId } + val marker = field(S8) { it.marker } + val subtype = field(S8) { it.subtype } + val seq = field(S8) { it.seq } + val x = field(S8) { it.x } + val y = field(S8) { it.y } + val direction = field(DirectionCodec) { it.direction } + return EntityMovePacket(entityId, marker, subtype, seq, x, y, direction) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePpPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePpPacket.kt index 45fb3fc..caab7dd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePpPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityMovePpPacket.kt @@ -12,10 +12,10 @@ data class EntityMovePpPacket( ) object EntityMovePpPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityMovePpPacket { - val entityId = field(S64LE) { it.entityId } - val moveSlot = field(S8) { it.moveSlot } - val ppValue = field(S8) { it.ppValue } - return EntityMovePpPacket(entityId, moveSlot, ppValue) - } + override fun CodecScope.body(): EntityMovePpPacket { + val entityId = field(S64LE) { it.entityId } + val moveSlot = field(S8) { it.moveSlot } + val ppValue = field(S8) { it.ppValue } + return EntityMovePpPacket(entityId, moveSlot, ppValue) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameChoicesPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameChoicesPacket.kt index bb51843..4df90e8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameChoicesPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameChoicesPacket.kt @@ -12,18 +12,18 @@ data class EntityNameChoicesPacket( private val NamedEntityChoiceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): NamedEntityChoice { - val entityId = field(S64LE) { it.entityId } - val name = field(Utf16LeNullTerminated) { it.name } - return NamedEntityChoice(entityId, name) - } + override fun CodecScope.body(): NamedEntityChoice { + val entityId = field(S64LE) { it.entityId } + val name = field(Utf16LeNullTerminated) { it.name } + return NamedEntityChoice(entityId, name) + } } object EntityNameChoicesPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityNameChoicesPacket { - val kind = field(S8) { it.kind } - val flag = field(U8) { if (it.flag) 1 else 0 } == 1 - val choices = field(NamedEntityChoiceCodec.listPrefixed(U8)) { it.choices } - return EntityNameChoicesPacket(kind, flag, choices) - } + override fun CodecScope.body(): EntityNameChoicesPacket { + val kind = field(S8) { it.kind } + val flag = field(U8) { if (it.flag) 1 else 0 } == 1 + val choices = field(NamedEntityChoiceCodec.listPrefixed(U8)) { it.choices } + return EntityNameChoicesPacket(kind, flag, choices) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameVisibilityPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameVisibilityPacket.kt index c5f23ae..0eb51ea 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameVisibilityPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityNameVisibilityPacket.kt @@ -13,11 +13,11 @@ data class EntityNameVisibilityPacket( ) object EntityNameVisibilityPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityNameVisibilityPacket { - val entityId = field(S64LE) { it.entityId } - val hidden = field(Bool) { it.hidden } - val gmMode = field(Bool) { it.gmMode } - val marked = field(Bool) { it.marked } - return EntityNameVisibilityPacket(entityId, hidden, gmMode, marked) - } + override fun CodecScope.body(): EntityNameVisibilityPacket { + val entityId = field(S64LE) { it.entityId } + val hidden = field(Bool) { it.hidden } + val gmMode = field(Bool) { it.gmMode } + val marked = field(Bool) { it.marked } + return EntityNameVisibilityPacket(entityId, hidden, gmMode, marked) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPanelSelectPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPanelSelectPacket.kt index dea6a42..6f21833 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPanelSelectPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPanelSelectPacket.kt @@ -9,8 +9,8 @@ data class EntityPanelSelectPacket( ) object EntityPanelSelectPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityPanelSelectPacket { - val entityId = field(S64LE) { it.entityId } - return EntityPanelSelectPacket(entityId) - } + override fun CodecScope.body(): EntityPanelSelectPacket { + val entityId = field(S64LE) { it.entityId } + return EntityPanelSelectPacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPresencePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPresencePacket.kt index 4c0b72d..bccff30 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPresencePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityPresencePacket.kt @@ -11,9 +11,9 @@ data class EntityPresencePacket( ) object EntityPresencePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityPresencePacket { - val entityId = field(S64LE) { it.entityId } - val status = field(S8) { it.status } - return EntityPresencePacket(entityId, status) - } + override fun CodecScope.body(): EntityPresencePacket { + val entityId = field(S64LE) { it.entityId } + val status = field(S8) { it.status } + return EntityPresencePacket(entityId, status) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityRenamePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityRenamePacket.kt index 76fb83a..2ed87af 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityRenamePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityRenamePacket.kt @@ -11,9 +11,9 @@ data class EntityRenamePacket( ) object EntityRenamePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityRenamePacket { - val entityId = field(S64LE) { it.entityId } - val name = field(Utf16LeNullTerminated) { it.name } - return EntityRenamePacket(entityId, name) - } + override fun CodecScope.body(): EntityRenamePacket { + val entityId = field(S64LE) { it.entityId } + val name = field(Utf16LeNullTerminated) { it.name } + return EntityRenamePacket(entityId, name) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntitySpriteChangePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntitySpriteChangePacket.kt index e695261..e9092f4 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntitySpriteChangePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntitySpriteChangePacket.kt @@ -12,11 +12,11 @@ data class EntitySpriteChangePacket( ) object EntitySpriteChangePacketCodec : PacketCodec() { - override fun CodecScope.body(): EntitySpriteChangePacket { - val entityId = field(S64LE) { it.entityId } - val facingFront = field(Bool) { it.facingFront } - val appearance = field(DefaultSkinSetCodec) { it.appearance } - val direction = field(S8) { it.direction } - return EntitySpriteChangePacket(entityId, facingFront, appearance, direction) - } + override fun CodecScope.body(): EntitySpriteChangePacket { + val entityId = field(S64LE) { it.entityId } + val facingFront = field(Bool) { it.facingFront } + val appearance = field(DefaultSkinSetCodec) { it.appearance } + val direction = field(S8) { it.direction } + return EntitySpriteChangePacket(entityId, facingFront, appearance, direction) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityTitleTagPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityTitleTagPacket.kt index 9e0d108..1c082de 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityTitleTagPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EntityTitleTagPacket.kt @@ -11,9 +11,9 @@ data class EntityTitleTagPacket( ) object EntityTitleTagPacketCodec : PacketCodec() { - override fun CodecScope.body(): EntityTitleTagPacket { - val entityId = field(S64LE) { it.entityId } - val nameTag = field(Utf16LeNullTerminated) { it.nameTag } - return EntityTitleTagPacket(entityId, nameTag) - } + override fun CodecScope.body(): EntityTitleTagPacket { + val entityId = field(S64LE) { it.entityId } + val nameTag = field(Utf16LeNullTerminated) { it.nameTag } + return EntityTitleTagPacket(entityId, nameTag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EventOverlayStatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EventOverlayStatePacket.kt index 8f868b7..dc18954 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EventOverlayStatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EventOverlayStatePacket.kt @@ -29,105 +29,106 @@ data class EventOverlayStatePacket( ) object EventOverlayStatePacketCodec : PacketCodec() { - override fun CodecScope.body(): EventOverlayStatePacket { - val codec = EventOverlayStateCodec - return field(codec) { it } - } + override fun CodecScope.body(): EventOverlayStatePacket { + val codec = EventOverlayStateCodec + return field(codec) { it } + } } private val EventOverlayStateCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): EventOverlayStatePacket { - val typeByte = S8.read(buf) - val active = typeByte.toInt() != -1 - if (!active) { - return EventOverlayStatePacket( - active = false, - overlayType = typeByte, - flagBits = 0, - ignoredEnum = 0, - timeRemaining = null, - valueA = null, - valueB = null, - anchorEntityId = null, - regions = emptyList(), - holes = emptyList(), - ) - } - val grid = typeByte.toInt() == GRID_OVERLAY_TYPE - val flagBits = S8.read(buf) - val fb = flagBits.toInt() - val ignoredEnum = S8.read(buf) - val timeRemaining = if (fb and 32 != 0) S32LE.read(buf) else null - val valueA = if (fb and 8 != 0) S32LE.read(buf) else null - val valueB = if (fb and 16 != 0) S32LE.read(buf) else null - val anchorEntityId = if (fb and 64 != 0) S64LE.read(buf) else null - val regionCount = U16LE.read(buf) - val regions = ArrayList(regionCount) - repeat(regionCount) { - val regionId = S16LE.read(buf) - val secondary = S16LE.read(buf) - if (grid) { - val n = U8.read(buf) - val points = ArrayList(n) - repeat(n) { points.add(OverlayGridPoint(S16LE.read(buf), S16LE.read(buf))) } - regions.add(OverlayRegion(regionId, secondary, points, null)) - } else { - val v = S32LE.read(buf) - regions.add(OverlayRegion(regionId, secondary, null, v)) - } - } - val holes = ArrayList() - if (grid && fb and 4 != 0) { - val holeCount = U16LE.read(buf) - repeat(holeCount) { holes.add(OverlayHole(S16LE.read(buf), S16LE.read(buf))) } - } - return EventOverlayStatePacket( - active = true, - overlayType = typeByte, - flagBits = flagBits, - ignoredEnum = ignoredEnum, - timeRemaining = timeRemaining, - valueA = valueA, - valueB = valueB, - anchorEntityId = anchorEntityId, - regions = regions, - holes = holes, - ) + override fun read(buf: ReadBuffer): EventOverlayStatePacket { + val typeByte = S8.read(buf) + val active = typeByte.toInt() != -1 + if (!active) { + return EventOverlayStatePacket( + active = false, + overlayType = typeByte, + flagBits = 0, + ignoredEnum = 0, + timeRemaining = null, + valueA = null, + valueB = null, + anchorEntityId = null, + regions = emptyList(), + holes = emptyList(), + ) } + val grid = typeByte.toInt() == GRID_OVERLAY_TYPE + val flagBits = S8.read(buf) + val fb = flagBits.toInt() + val ignoredEnum = S8.read(buf) + val timeRemaining = if (fb and 32 != 0) S32LE.read(buf) else null + val valueA = if (fb and 8 != 0) S32LE.read(buf) else null + val valueB = if (fb and 16 != 0) S32LE.read(buf) else null + val anchorEntityId = if (fb and 64 != 0) S64LE.read(buf) else null + val regionCount = U16LE.read(buf) + val regions = ArrayList(regionCount) + repeat(regionCount) { + val regionId = S16LE.read(buf) + val secondary = S16LE.read(buf) + if (grid) { + val n = U8.read(buf) + val points = ArrayList(n) + repeat(n) { points.add(OverlayGridPoint(S16LE.read(buf), S16LE.read(buf))) } + regions.add(OverlayRegion(regionId, secondary, points, null)) + } else { + val v = S32LE.read(buf) + regions.add(OverlayRegion(regionId, secondary, null, v)) + } + } + val holes = ArrayList() + if (grid && fb and 4 != 0) { + val holeCount = U16LE.read(buf) + repeat(holeCount) { holes.add(OverlayHole(S16LE.read(buf), S16LE.read(buf))) } + } + return EventOverlayStatePacket( + active = true, + overlayType = typeByte, + flagBits = flagBits, + ignoredEnum = ignoredEnum, + timeRemaining = timeRemaining, + valueA = valueA, + valueB = valueB, + anchorEntityId = anchorEntityId, + regions = regions, + holes = holes, + ) + } - override fun write(buf: WriteBuffer, value: EventOverlayStatePacket) { - S8.write(buf, value.overlayType) - if (!value.active) return - val grid = value.overlayType.toInt() == GRID_OVERLAY_TYPE - S8.write(buf, value.flagBits) - val fb = value.flagBits.toInt() - S8.write(buf, value.ignoredEnum) - if (fb and 32 != 0) S32LE.write(buf, value.timeRemaining!!) - if (fb and 8 != 0) S32LE.write(buf, value.valueA!!) - if (fb and 16 != 0) S32LE.write(buf, value.valueB!!) - if (fb and 64 != 0) S64LE.write(buf, value.anchorEntityId!!) - U16LE.write(buf, value.regions.size) - for (r in value.regions) { - S16LE.write(buf, r.regionId) - S16LE.write(buf, r.secondary) - if (grid) { - val points = r.gridPoints ?: throw MalformedPacketException("grid overlay region missing points") - U8.write(buf, points.size) - for (p in points) { - S16LE.write(buf, p.x) - S16LE.write(buf, p.y) - } - } else { - S32LE.write(buf, r.value!!) - } - } - if (grid && fb and 4 != 0) { - U16LE.write(buf, value.holes.size) - for (h in value.holes) { - S16LE.write(buf, h.regionId) - S16LE.write(buf, h.secondary) - } + override fun write(buf: WriteBuffer, value: EventOverlayStatePacket) { + S8.write(buf, value.overlayType) + if (!value.active) return + val grid = value.overlayType.toInt() == GRID_OVERLAY_TYPE + S8.write(buf, value.flagBits) + val fb = value.flagBits.toInt() + S8.write(buf, value.ignoredEnum) + if (fb and 32 != 0) S32LE.write(buf, value.timeRemaining!!) + if (fb and 8 != 0) S32LE.write(buf, value.valueA!!) + if (fb and 16 != 0) S32LE.write(buf, value.valueB!!) + if (fb and 64 != 0) S64LE.write(buf, value.anchorEntityId!!) + U16LE.write(buf, value.regions.size) + for (r in value.regions) { + S16LE.write(buf, r.regionId) + S16LE.write(buf, r.secondary) + if (grid) { + val points = + r.gridPoints ?: throw MalformedPacketException("grid overlay region missing points") + U8.write(buf, points.size) + for (p in points) { + S16LE.write(buf, p.x) + S16LE.write(buf, p.y) } + } else { + S32LE.write(buf, r.value!!) + } } + if (grid && fb and 4 != 0) { + U16LE.write(buf, value.holes.size) + for (h in value.holes) { + S16LE.write(buf, h.regionId) + S16LE.write(buf, h.secondary) + } + } + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EvolutionPromptResponsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EvolutionPromptResponsePacket.kt index 2672a09..bd1a876 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EvolutionPromptResponsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/EvolutionPromptResponsePacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.S64LE data class EvolutionPromptResponsePacket(val pokemonEntityId: Long, val accepted: Boolean) object EvolutionPromptResponsePacketCodec : PacketCodec() { - override fun CodecScope.body(): EvolutionPromptResponsePacket { - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val accepted = field(Bool) { it.accepted } - return EvolutionPromptResponsePacket(pokemonEntityId, accepted) - } + override fun CodecScope.body(): EvolutionPromptResponsePacket { + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val accepted = field(Bool) { it.accepted } + return EvolutionPromptResponsePacket(pokemonEntityId, accepted) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ExchangeItemRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ExchangeItemRequestPacket.kt index 2230e24..96ae490 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ExchangeItemRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ExchangeItemRequestPacket.kt @@ -12,10 +12,10 @@ data class ExchangeItemRequestPacket( ) object ExchangeItemRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): ExchangeItemRequestPacket { - val itemEntityRef = field(S16LE) { it.itemEntityRef } - val quantity = field(S16LE) { it.quantity } - val exchangeTypeIndex = field(S8) { it.exchangeTypeIndex } - return ExchangeItemRequestPacket(itemEntityRef, quantity, exchangeTypeIndex) - } + override fun CodecScope.body(): ExchangeItemRequestPacket { + val itemEntityRef = field(S16LE) { it.itemEntityRef } + val quantity = field(S16LE) { it.quantity } + val exchangeTypeIndex = field(S8) { it.exchangeTypeIndex } + return ExchangeItemRequestPacket(itemEntityRef, quantity, exchangeTypeIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FaceDirectionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FaceDirectionPacket.kt index b3bf3e0..0c262b9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FaceDirectionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FaceDirectionPacket.kt @@ -8,10 +8,10 @@ import de.fiereu.openmmo.common.enums.Direction data class FaceDirectionPacket(val direction: Direction) object FaceDirectionPacketCodec : PacketCodec() { - private val DirectionCodec = enumByOrdinalByte() + private val DirectionCodec = enumByOrdinalByte() - override fun CodecScope.body(): FaceDirectionPacket { - val direction = field(DirectionCodec) { it.direction } - return FaceDirectionPacket(direction) - } + override fun CodecScope.body(): FaceDirectionPacket { + val direction = field(DirectionCodec) { it.direction } + return FaceDirectionPacket(direction) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotMarkerPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotMarkerPacket.kt index bafef2e..a8ba95d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotMarkerPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotMarkerPacket.kt @@ -12,10 +12,10 @@ data class FieldMapBattleSlotMarkerPacket( ) object FieldMapBattleSlotMarkerPacketCodec : PacketCodec() { - override fun CodecScope.body(): FieldMapBattleSlotMarkerPacket { - val slot = field(S8) { it.slot } - val markerType = field(S8) { it.markerType } - val value = field(S16LE) { it.value } - return FieldMapBattleSlotMarkerPacket(slot, markerType, value) - } + override fun CodecScope.body(): FieldMapBattleSlotMarkerPacket { + val slot = field(S8) { it.slot } + val markerType = field(S8) { it.markerType } + val value = field(S16LE) { it.value } + return FieldMapBattleSlotMarkerPacket(slot, markerType, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotTileMapPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotTileMapPacket.kt index 085b24d..795cef1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotTileMapPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapBattleSlotTileMapPacket.kt @@ -13,18 +13,18 @@ data class FieldMapBattleSlotTileMapPacket( ) object FieldMapBattleSlotTileMapPacketCodec : PacketCodec() { - override fun CodecScope.body(): FieldMapBattleSlotTileMapPacket { - val groupId = field(S16LE) { it.groupId } - val present = field(U8) { if (it.slotTiles != null) 1 else 0 } == 1 - val slotTiles = - if (present) { - val count = field(S8) { it.slotTiles!!.size.toByte() }.toInt() - (0 until count).map { i -> - val slot = field(S8) { it.slotTiles!![i].slot } - val value = field(S8) { it.slotTiles!![i].value } - BattleSlotTile(slot, value) - } - } else null - return FieldMapBattleSlotTileMapPacket(groupId, slotTiles) - } + override fun CodecScope.body(): FieldMapBattleSlotTileMapPacket { + val groupId = field(S16LE) { it.groupId } + val present = field(U8) { if (it.slotTiles != null) 1 else 0 } == 1 + val slotTiles = + if (present) { + val count = field(S8) { it.slotTiles!!.size.toByte() }.toInt() + (0 until count).map { i -> + val slot = field(S8) { it.slotTiles!![i].slot } + val value = field(S8) { it.slotTiles!![i].value } + BattleSlotTile(slot, value) + } + } else null + return FieldMapBattleSlotTileMapPacket(groupId, slotTiles) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapTilePaletteApplyPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapTilePaletteApplyPacket.kt index d051122..44a188b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapTilePaletteApplyPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FieldMapTilePaletteApplyPacket.kt @@ -8,28 +8,28 @@ data class FieldMapTilePaletteApplyPacket( val values: ByteArray, val tiles: List, ) { - override fun equals(other: Any?): Boolean = - other is FieldMapTilePaletteApplyPacket && - layer == other.layer && - keys.contentEquals(other.keys) && - values.contentEquals(other.values) && - tiles == other.tiles + override fun equals(other: Any?): Boolean = + other is FieldMapTilePaletteApplyPacket && + layer == other.layer && + keys.contentEquals(other.keys) && + values.contentEquals(other.values) && + tiles == other.tiles - override fun hashCode(): Int { - var r = layer.toInt() - r = r * 31 + keys.contentHashCode() - r = r * 31 + values.contentHashCode() - r = r * 31 + tiles.hashCode() - return r - } + override fun hashCode(): Int { + var r = layer.toInt() + r = r * 31 + keys.contentHashCode() + r = r * 31 + values.contentHashCode() + r = r * 31 + tiles.hashCode() + return r + } } object FieldMapTilePaletteApplyPacketCodec : PacketCodec() { - override fun CodecScope.body(): FieldMapTilePaletteApplyPacket { - val layer = field(S8) { it.layer } - val keys = field(bytesPrefixed(U8)) { it.keys } - val values = field(bytesPrefixed(U8)) { it.values } - val tiles = field(S16LE.listPrefixed(U8)) { it.tiles } - return FieldMapTilePaletteApplyPacket(layer, keys, values, tiles) - } + override fun CodecScope.body(): FieldMapTilePaletteApplyPacket { + val layer = field(S8) { it.layer } + val keys = field(bytesPrefixed(U8)) { it.keys } + val values = field(bytesPrefixed(U8)) { it.values } + val tiles = field(S16LE.listPrefixed(U8)) { it.tiles } + return FieldMapTilePaletteApplyPacket(layer, keys, values, tiles) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FollowerAdvancePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FollowerAdvancePacket.kt index 7c6fec4..1b70cc9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FollowerAdvancePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FollowerAdvancePacket.kt @@ -10,11 +10,11 @@ data class FollowerAdvancePacket( ) object FollowerAdvancePacketCodec : PacketCodec() { - override fun CodecScope.body(): FollowerAdvancePacket { - val entityId = field(S64LE) { it.entityId } - val step = field(S16LE) { it.step } - val direction = field(S8) { it.direction } - val flag = field(Bool) { it.flag } - return FollowerAdvancePacket(entityId, step, direction, flag) - } + override fun CodecScope.body(): FollowerAdvancePacket { + val entityId = field(S64LE) { it.entityId } + val step = field(S16LE) { it.step } + val direction = field(S8) { it.direction } + val flag = field(Bool) { it.flag } + return FollowerAdvancePacket(entityId, step, direction, flag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendListPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendListPacket.kt new file mode 100644 index 0000000..d7c373b --- /dev/null +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendListPacket.kt @@ -0,0 +1,40 @@ +package de.fiereu.openmmo.net.game.packets + +import de.fiereu.bytecodec.* + +data class FriendListEntry( + val player: Long, + val friendsSince: Int, + val online: Boolean, + val name: String, + val unk: Byte, + val lastSeen: Int, + val appearance: List, +) + +data class FriendListPacket( + val mode: Int, + val entries: List, +) + +private val FriendListEntryCodec: Codec = + object : PacketCodec() { + override fun CodecScope.body(): FriendListEntry { + val player = field(S64LE) { it.player } + val friendsSince = field(S32LE) { it.friendsSince } + val online = field(Bool) { it.online } + val name = field(Utf16LeNullTerminated) { it.name } + val unk = field(S8) { it.unk } + val lastSeen = field(S32LE) { it.lastSeen } + val appearance = field(S16LE.repeat(5)) { it.appearance } + return FriendListEntry(player, friendsSince, online, name, unk, lastSeen, appearance) + } + } + +object FriendListPacketCodec : PacketCodec() { + override fun CodecScope.body(): FriendListPacket { + val mode = field(U8) { it.mode } + val entries = field(FriendListEntryCodec.listPrefixed(U8)) { it.entries } + return FriendListPacket(mode, entries) + } +} diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendProfileRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendProfileRequestPacket.kt index 89c11ea..1d61e14 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendProfileRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendProfileRequestPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S64LE data class FriendProfileRequestPacket(val targetEntityId: Long) object FriendProfileRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): FriendProfileRequestPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - return FriendProfileRequestPacket(targetEntityId) - } + override fun CodecScope.body(): FriendProfileRequestPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + return FriendProfileRequestPacket(targetEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterDeltaPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterDeltaPacket.kt index ff1ed71..64ad407 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterDeltaPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterDeltaPacket.kt @@ -9,8 +9,8 @@ data class FriendRosterDeltaPacket( ) object FriendRosterDeltaPacketCodec : PacketCodec() { - override fun CodecScope.body(): FriendRosterDeltaPacket { - val action = field(S8) { it.action } - return FriendRosterDeltaPacket(action) - } + override fun CodecScope.body(): FriendRosterDeltaPacket { + val action = field(S8) { it.action } + return FriendRosterDeltaPacket(action) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterPacket.kt index d15faaa..01b065a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/FriendRosterPacket.kt @@ -13,18 +13,18 @@ data class FriendRosterPacket( private val FriendRosterEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): FriendRosterEntry { - field(S64LE) { 0L } - val name = field(Utf16LeNullTerminated) { it.name } - val online = field(Bool) { it.online } - return FriendRosterEntry(name, online) - } + override fun CodecScope.body(): FriendRosterEntry { + field(S64LE) { 0L } + val name = field(Utf16LeNullTerminated) { it.name } + val online = field(Bool) { it.online } + return FriendRosterEntry(name, online) + } } object FriendRosterPacketCodec : PacketCodec() { - override fun CodecScope.body(): FriendRosterPacket { - val count = field(U8) { it.friends.size } - val friends = (0 until count).map { i -> field(FriendRosterEntryCodec) { it.friends[i] } } - return FriendRosterPacket(friends) - } + override fun CodecScope.body(): FriendRosterPacket { + val count = field(U8) { it.friends.size } + val friends = (0 until count).map { i -> field(FriendRosterEntryCodec) { it.friends[i] } } + return FriendRosterPacket(friends) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameHandshakeHelloPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameHandshakeHelloPacket.kt index 8199727..d25bd76 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameHandshakeHelloPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameHandshakeHelloPacket.kt @@ -5,19 +5,21 @@ import de.fiereu.bytecodec.* sealed class HelloAuthData data class ReconnectHelloAuth(val entityId: Long, val sessionToken: ByteArray) : HelloAuthData() { - override fun equals(other: Any?): Boolean = - other is ReconnectHelloAuth && - entityId == other.entityId && - sessionToken.contentEquals(other.sessionToken) + override fun equals(other: Any?): Boolean = + other is ReconnectHelloAuth && + entityId == other.entityId && + sessionToken.contentEquals(other.sessionToken) - override fun hashCode(): Int = entityId.hashCode() * 31 + sessionToken.contentHashCode() + override fun hashCode(): Int = entityId.hashCode() * 31 + sessionToken.contentHashCode() } data class NewHelloAuth(val userId: Int, val sessionToken: ByteArray) : HelloAuthData() { - override fun equals(other: Any?): Boolean = - other is NewHelloAuth && userId == other.userId && sessionToken.contentEquals(other.sessionToken) + override fun equals(other: Any?): Boolean = + other is NewHelloAuth && + userId == other.userId && + sessionToken.contentEquals(other.sessionToken) - override fun hashCode(): Int = userId * 31 + sessionToken.contentHashCode() + override fun hashCode(): Int = userId * 31 + sessionToken.contentHashCode() } data class LanguagePackEntry(val name: String, val version: Byte, val kind: Byte) @@ -41,71 +43,71 @@ data class GameHandshakeHelloPacket( val capabilityFlagA: Byte, val capabilityFlagB: Byte, ) { - override fun equals(other: Any?): Boolean = - other is GameHandshakeHelloPacket && - authData == other.authData && - localIp.contentEquals(other.localIp) && - magic == other.magic && - clientRevision == other.clientRevision && - languageId == other.languageId && - chatChannelMask == other.chatChannelMask && - languageFilterMask == other.languageFilterMask && - languagePackMask == other.languagePackMask && - languagePacks == other.languagePacks && - graphicsModes == other.graphicsModes && - mapDataState == other.mapDataState && - platformOrdinal == other.platformOrdinal && - osOrdinal == other.osOrdinal && - capabilityFlagA == other.capabilityFlagA && - capabilityFlagB == other.capabilityFlagB + override fun equals(other: Any?): Boolean = + other is GameHandshakeHelloPacket && + authData == other.authData && + localIp.contentEquals(other.localIp) && + magic == other.magic && + clientRevision == other.clientRevision && + languageId == other.languageId && + chatChannelMask == other.chatChannelMask && + languageFilterMask == other.languageFilterMask && + languagePackMask == other.languagePackMask && + languagePacks == other.languagePacks && + graphicsModes == other.graphicsModes && + mapDataState == other.mapDataState && + platformOrdinal == other.platformOrdinal && + osOrdinal == other.osOrdinal && + capabilityFlagA == other.capabilityFlagA && + capabilityFlagB == other.capabilityFlagB - override fun hashCode(): Int { - var r = authData.hashCode() - r = r * 31 + localIp.contentHashCode() - r = r * 31 + magic - r = r * 31 + clientRevision - r = r * 31 + languageId - r = r * 31 + chatChannelMask - r = r * 31 + languageFilterMask - r = r * 31 + languagePackMask - r = r * 31 + languagePacks.hashCode() - r = r * 31 + graphicsModes.hashCode() - r = r * 31 + mapDataState - r = r * 31 + platformOrdinal - r = r * 31 + osOrdinal - r = r * 31 + capabilityFlagA - r = r * 31 + capabilityFlagB - return r - } + override fun hashCode(): Int { + var r = authData.hashCode() + r = r * 31 + localIp.contentHashCode() + r = r * 31 + magic + r = r * 31 + clientRevision + r = r * 31 + languageId + r = r * 31 + chatChannelMask + r = r * 31 + languageFilterMask + r = r * 31 + languagePackMask + r = r * 31 + languagePacks.hashCode() + r = r * 31 + graphicsModes.hashCode() + r = r * 31 + mapDataState + r = r * 31 + platformOrdinal + r = r * 31 + osOrdinal + r = r * 31 + capabilityFlagA + r = r * 31 + capabilityFlagB + return r + } } private val HelloToken = bytesPrefixed(U8) private val HelloLocalIp = fixedBytes(4) private object NewHelloAuthCodec : PacketCodec() { - override fun CodecScope.body(): NewHelloAuth { - val userId = field(S32LE) { it.userId } - val sessionToken = field(HelloToken) { it.sessionToken } - return NewHelloAuth(userId, sessionToken) - } + override fun CodecScope.body(): NewHelloAuth { + val userId = field(S32LE) { it.userId } + val sessionToken = field(HelloToken) { it.sessionToken } + return NewHelloAuth(userId, sessionToken) + } } private object ReconnectHelloAuthCodec : PacketCodec() { - override fun CodecScope.body(): ReconnectHelloAuth { - val entityId = field(S64LE) { it.entityId } - val sessionToken = field(HelloToken) { it.sessionToken } - return ReconnectHelloAuth(entityId, sessionToken) - } + override fun CodecScope.body(): ReconnectHelloAuth { + val entityId = field(S64LE) { it.entityId } + val sessionToken = field(HelloToken) { it.sessionToken } + return ReconnectHelloAuth(entityId, sessionToken) + } } private val HelloAuthCodec: Codec = choose( tag = U8, identify = { data -> - when (data) { - is NewHelloAuth -> 0x00 - is ReconnectHelloAuth -> 0x01 - } + when (data) { + is NewHelloAuth -> 0x00 + is ReconnectHelloAuth -> 0x01 + } }, 0x00 to NewHelloAuthCodec, 0x01 to ReconnectHelloAuthCodec, @@ -113,56 +115,56 @@ private val HelloAuthCodec: Codec = private val LanguagePackEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): LanguagePackEntry { - val name = field(Utf16LeNullTerminated) { it.name } - val version = field(S8) { it.version } - val kind = field(S8) { it.kind } - return LanguagePackEntry(name, version, kind) - } + override fun CodecScope.body(): LanguagePackEntry { + val name = field(Utf16LeNullTerminated) { it.name } + val version = field(S8) { it.version } + val kind = field(S8) { it.kind } + return LanguagePackEntry(name, version, kind) + } } private val GraphicsModeEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GraphicsModeEntry { - val id = field(S8) { it.id } - val name = field(Utf16LeNullTerminated) { it.name } - return GraphicsModeEntry(id, name) - } + override fun CodecScope.body(): GraphicsModeEntry { + val id = field(S8) { it.id } + val name = field(Utf16LeNullTerminated) { it.name } + return GraphicsModeEntry(id, name) + } } object GameHandshakeHelloPacketCodec : PacketCodec() { - override fun CodecScope.body(): GameHandshakeHelloPacket { - val authData = field(HelloAuthCodec) { it.authData } - val localIp = field(HelloLocalIp) { it.localIp } - val magic = field(S32LE) { it.magic } - val clientRevision = field(S32LE) { it.clientRevision } - val languageId = field(S8) { it.languageId } - val chatChannelMask = field(S16LE) { it.chatChannelMask } - val languageFilterMask = field(S16LE) { it.languageFilterMask } - val languagePackMask = field(S8) { it.languagePackMask } - val languagePacks = field(LanguagePackEntryCodec.listPrefixed(U8)) { it.languagePacks } - val graphicsModes = field(GraphicsModeEntryCodec.listPrefixed(U8)) { it.graphicsModes } - val mapDataState = field(S8) { it.mapDataState } - val platformOrdinal = field(S8) { it.platformOrdinal } - val osOrdinal = field(S8) { it.osOrdinal } - val capabilityFlagA = field(S8) { it.capabilityFlagA } - val capabilityFlagB = field(S8) { it.capabilityFlagB } - return GameHandshakeHelloPacket( - authData, - localIp, - magic, - clientRevision, - languageId, - chatChannelMask, - languageFilterMask, - languagePackMask, - languagePacks, - graphicsModes, - mapDataState, - platformOrdinal, - osOrdinal, - capabilityFlagA, - capabilityFlagB, - ) - } + override fun CodecScope.body(): GameHandshakeHelloPacket { + val authData = field(HelloAuthCodec) { it.authData } + val localIp = field(HelloLocalIp) { it.localIp } + val magic = field(S32LE) { it.magic } + val clientRevision = field(S32LE) { it.clientRevision } + val languageId = field(S8) { it.languageId } + val chatChannelMask = field(S16LE) { it.chatChannelMask } + val languageFilterMask = field(S16LE) { it.languageFilterMask } + val languagePackMask = field(S8) { it.languagePackMask } + val languagePacks = field(LanguagePackEntryCodec.listPrefixed(U8)) { it.languagePacks } + val graphicsModes = field(GraphicsModeEntryCodec.listPrefixed(U8)) { it.graphicsModes } + val mapDataState = field(S8) { it.mapDataState } + val platformOrdinal = field(S8) { it.platformOrdinal } + val osOrdinal = field(S8) { it.osOrdinal } + val capabilityFlagA = field(S8) { it.capabilityFlagA } + val capabilityFlagB = field(S8) { it.capabilityFlagB } + return GameHandshakeHelloPacket( + authData, + localIp, + magic, + clientRevision, + languageId, + chatChannelMask, + languageFilterMask, + languagePackMask, + languagePacks, + graphicsModes, + mapDataState, + platformOrdinal, + osOrdinal, + capabilityFlagA, + capabilityFlagB, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameShopCatalogPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameShopCatalogPacket.kt index 4a0210d..f687098 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameShopCatalogPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GameShopCatalogPacket.kt @@ -16,37 +16,37 @@ data class GameShopCatalogPacket( ) private object GameShopItemCodec : PacketCodec() { - override fun CodecScope.body(): GameShopItem { - field(S64LE) { 0L } - field(S32LE) { 0 } - val itemId = field(S64LE, GameShopItem::itemId) - val value1 = field(S32LE, GameShopItem::value1) - val value2 = field(S32LE, GameShopItem::value2) - reserved(byte = 0) - val category = field(S8, GameShopItem::category) - val cost = field(S32LE, GameShopItem::cost) - field(S32LE) { 0 } - return GameShopItem(itemId, value1, value2, category, cost) - } + override fun CodecScope.body(): GameShopItem { + field(S64LE) { 0L } + field(S32LE) { 0 } + val itemId = field(S64LE, GameShopItem::itemId) + val value1 = field(S32LE, GameShopItem::value1) + val value2 = field(S32LE, GameShopItem::value2) + reserved(byte = 0) + val category = field(S8, GameShopItem::category) + val cost = field(S32LE, GameShopItem::cost) + field(S32LE) { 0 } + return GameShopItem(itemId, value1, value2, category, cost) + } } private val GameShopItemListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { GameShopItemCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { GameShopItemCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { GameShopItemCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { GameShopItemCodec.write(buf, it) } + } } object GameShopCatalogPacketCodec : PacketCodec() { - override fun CodecScope.body(): GameShopCatalogPacket { - val points = field(S32LE, GameShopCatalogPacket::points) - val items = field(GameShopItemListPrefixedU8, GameShopCatalogPacket::items) - return GameShopCatalogPacket(points, items) - } + override fun CodecScope.body(): GameShopCatalogPacket { + val points = field(S32LE, GameShopCatalogPacket::points) + val items = field(GameShopItemListPrefixedU8, GameShopCatalogPacket::items) + return GameShopCatalogPacket(points, items) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelEntryPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelEntryPacket.kt index 14be342..2eb1b4e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelEntryPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelEntryPacket.kt @@ -10,11 +10,11 @@ data class GmPanelEntryPacket( ) object GmPanelEntryPacketCodec : PacketCodec() { - override fun CodecScope.body(): GmPanelEntryPacket { - val clearFlag = field(S8) { it.clearFlag } - val label = if (clearFlag.toInt() == 0) field(Utf16LeNullTerminated) { it.label!! } else null - val value = if (clearFlag.toInt() == 0) field(Utf16LeNullTerminated) { it.value!! } else null - val count = if (clearFlag.toInt() == 0) field(S32LE) { it.count!! } else null - return GmPanelEntryPacket(clearFlag, label, value, count) - } + override fun CodecScope.body(): GmPanelEntryPacket { + val clearFlag = field(S8) { it.clearFlag } + val label = if (clearFlag.toInt() == 0) field(Utf16LeNullTerminated) { it.label!! } else null + val value = if (clearFlag.toInt() == 0) field(Utf16LeNullTerminated) { it.value!! } else null + val count = if (clearFlag.toInt() == 0) field(S32LE) { it.count!! } else null + return GmPanelEntryPacket(clearFlag, label, value, count) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelVariantPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelVariantPacket.kt index 96b73f2..af8f9b2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelVariantPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPanelVariantPacket.kt @@ -9,8 +9,8 @@ data class GmPanelVariantPacket( ) object GmPanelVariantPacketCodec : PacketCodec() { - override fun CodecScope.body(): GmPanelVariantPacket { - val variant = field(S8) { it.variant } - return GmPanelVariantPacket(variant) - } + override fun CodecScope.body(): GmPanelVariantPacket { + val variant = field(S8) { it.variant } + return GmPanelVariantPacket(variant) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPlayerLookupPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPlayerLookupPacket.kt index a04333d..54e19f3 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPlayerLookupPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GmPlayerLookupPacket.kt @@ -37,62 +37,88 @@ data class GmCharacterSession( private val GmCharacterSessionCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GmCharacterSession { - val entityId = field(S64LE) { it.entityId } - val name = field(Utf16LeNullTerminated) { it.name } - val secondaryName = field(Utf16LeNullTerminated) { it.secondaryName } - val intA = field(S32LE) { it.intA } - val byteA = field(S8) { it.byteA } - val intB = field(S32LE) { it.intB } - val longA = field(S64LE) { it.longA } - val intC = field(S32LE) { it.intC } - field(S32LE) { 0 } - field(S8) { 0 } - val intD = field(S32LE) { it.intD } - val intE = field(S32LE) { it.intE } - val shortA = field(S16LE) { it.shortA } - val intF = field(S32LE) { it.intF } - val byteB = field(S8) { it.byteB } - val byteC = field(S8) { it.byteC } - field(S8) { 0 } - val byteD = field(S8) { it.byteD } - field(S32LE) { 0 } - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - val shortB = field(S16LE) { it.shortB } - val byteE = field(S8) { it.byteE } - val intG = field(S32LE) { it.intG } - val byteF = field(S8) { it.byteF } - val byteG = field(S8) { it.byteG } - val byteH = field(S8) { it.byteH } - field(S8) { 0 } - field(S8) { 0 } - field(S8) { 0 } - val byteI = field(S8) { it.byteI } - val byteJ = field(S8) { it.byteJ } - field(S8) { 0 } - val shortC = field(S16LE) { it.shortC } - val shortD = field(S16LE) { it.shortD } - field(S8) { 0 } - field(S8) { 0 } - val shortE = field(S16LE) { it.shortE } - val statusByte = field(S8) { it.statusByte } - val shortF = field(S16LE) { it.shortF } - val shortG = field(S16LE) { it.shortG } - val statusCount = field(U8) { it.statusList.size } - val statusList = (0 until statusCount).map { i -> field(S8) { it.statusList[i] } } - return GmCharacterSession( - entityId, name, secondaryName, intA, byteA, intB, longA, intC, intD, intE, shortA, intF, - byteB, byteC, byteD, shortB, byteE, intG, byteF, byteG, byteH, byteI, byteJ, shortC, - shortD, shortE, statusByte, shortF, shortG, statusList - ) - } + override fun CodecScope.body(): GmCharacterSession { + val entityId = field(S64LE) { it.entityId } + val name = field(Utf16LeNullTerminated) { it.name } + val secondaryName = field(Utf16LeNullTerminated) { it.secondaryName } + val intA = field(S32LE) { it.intA } + val byteA = field(S8) { it.byteA } + val intB = field(S32LE) { it.intB } + val longA = field(S64LE) { it.longA } + val intC = field(S32LE) { it.intC } + field(S32LE) { 0 } + field(S8) { 0 } + val intD = field(S32LE) { it.intD } + val intE = field(S32LE) { it.intE } + val shortA = field(S16LE) { it.shortA } + val intF = field(S32LE) { it.intF } + val byteB = field(S8) { it.byteB } + val byteC = field(S8) { it.byteC } + field(S8) { 0 } + val byteD = field(S8) { it.byteD } + field(S32LE) { 0 } + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + val shortB = field(S16LE) { it.shortB } + val byteE = field(S8) { it.byteE } + val intG = field(S32LE) { it.intG } + val byteF = field(S8) { it.byteF } + val byteG = field(S8) { it.byteG } + val byteH = field(S8) { it.byteH } + field(S8) { 0 } + field(S8) { 0 } + field(S8) { 0 } + val byteI = field(S8) { it.byteI } + val byteJ = field(S8) { it.byteJ } + field(S8) { 0 } + val shortC = field(S16LE) { it.shortC } + val shortD = field(S16LE) { it.shortD } + field(S8) { 0 } + field(S8) { 0 } + val shortE = field(S16LE) { it.shortE } + val statusByte = field(S8) { it.statusByte } + val shortF = field(S16LE) { it.shortF } + val shortG = field(S16LE) { it.shortG } + val statusCount = field(U8) { it.statusList.size } + val statusList = (0 until statusCount).map { i -> field(S8) { it.statusList[i] } } + return GmCharacterSession( + entityId, + name, + secondaryName, + intA, + byteA, + intB, + longA, + intC, + intD, + intE, + shortA, + intF, + byteB, + byteC, + byteD, + shortB, + byteE, + intG, + byteF, + byteG, + byteH, + byteI, + byteJ, + shortC, + shortD, + shortE, + statusByte, + shortF, + shortG, + statusList) + } } data class GmCharacterListing( @@ -103,12 +129,12 @@ data class GmCharacterListing( private val GmCharacterListingCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GmCharacterListing { - val entityId = field(S64LE) { it.entityId } - val value = field(S32LE) { it.value } - val name = field(Utf16LeNullTerminated) { it.name } - return GmCharacterListing(entityId, value, name) - } + override fun CodecScope.body(): GmCharacterListing { + val entityId = field(S64LE) { it.entityId } + val value = field(S32LE) { it.value } + val name = field(Utf16LeNullTerminated) { it.name } + return GmCharacterListing(entityId, value, name) + } } data class GmAccountInfo( @@ -138,38 +164,45 @@ data class GmPlayerLookupPacket( ) object GmPlayerLookupPacketCodec : PacketCodec() { - override fun CodecScope.body(): GmPlayerLookupPacket { - val foundByte = field(U8) { if (it.found) 1 else 0 } - if (foundByte != 1) { - return GmPlayerLookupPacket(false, null, 0, null, null, emptyList()) - } - val session = field(GmCharacterSessionCodec) { it.session!! } - val rank = field(S8) { it.rank } - val account = - if (rank > 0) { - val rankExtraA = field(S8) { it.account!!.rankExtraA } - val rankExtraB = field(S8) { it.account!!.rankExtraB } - val rankExtraC = field(S8) { it.account!!.rankExtraC } - val ipAddress = field(Utf16LeNullTerminated) { it.account!!.ipAddress } - val playtime = field(S64LE) { it.account!!.playtime } - val accountId = field(S32LE) { it.account!!.accountId } - val stringA = field(Utf16LeNullTerminated) { it.account!!.stringA } - val stringB = field(Utf16LeNullTerminated) { it.account!!.stringB } - val stringC = field(Utf16LeNullTerminated) { it.account!!.stringC } - GmAccountInfo( - rankExtraA, rankExtraB, rankExtraC, ipAddress, playtime, accountId, stringA, stringB, - stringC - ) - } else null - val extraByte = field(U8) { if (it.extra != null) 1 else 0 } - val extra = - if (extraByte == 1) { - val value = field(S32LE) { it.extra!!.value } - val text = field(Utf16LeNullTerminated) { it.extra!!.text } - GmExtraDetail(value, text) - } else null - val charCount = field(U16LE) { it.characters.size } - val characters = (0 until charCount).map { i -> field(GmCharacterListingCodec) { it.characters[i] } } - return GmPlayerLookupPacket(true, session, rank, account, extra, characters) + override fun CodecScope.body(): GmPlayerLookupPacket { + val foundByte = field(U8) { if (it.found) 1 else 0 } + if (foundByte != 1) { + return GmPlayerLookupPacket(false, null, 0, null, null, emptyList()) } + val session = field(GmCharacterSessionCodec) { it.session!! } + val rank = field(S8) { it.rank } + val account = + if (rank > 0) { + val rankExtraA = field(S8) { it.account!!.rankExtraA } + val rankExtraB = field(S8) { it.account!!.rankExtraB } + val rankExtraC = field(S8) { it.account!!.rankExtraC } + val ipAddress = field(Utf16LeNullTerminated) { it.account!!.ipAddress } + val playtime = field(S64LE) { it.account!!.playtime } + val accountId = field(S32LE) { it.account!!.accountId } + val stringA = field(Utf16LeNullTerminated) { it.account!!.stringA } + val stringB = field(Utf16LeNullTerminated) { it.account!!.stringB } + val stringC = field(Utf16LeNullTerminated) { it.account!!.stringC } + GmAccountInfo( + rankExtraA, + rankExtraB, + rankExtraC, + ipAddress, + playtime, + accountId, + stringA, + stringB, + stringC) + } else null + val extraByte = field(U8) { if (it.extra != null) 1 else 0 } + val extra = + if (extraByte == 1) { + val value = field(S32LE) { it.extra!!.value } + val text = field(Utf16LeNullTerminated) { it.extra!!.text } + GmExtraDetail(value, text) + } else null + val charCount = field(U16LE) { it.characters.size } + val characters = + (0 until charCount).map { i -> field(GmCharacterListingCodec) { it.characters[i] } } + return GmPlayerLookupPacket(true, session, rank, account, extra, characters) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GroupMemberRosterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GroupMemberRosterPacket.kt index 92535c2..3f9c102 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GroupMemberRosterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GroupMemberRosterPacket.kt @@ -13,15 +13,15 @@ data class GroupMemberAppearance( private val GroupMemberAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupMemberAppearance { - val name = field(Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val formId = field(S32LE) { it.formId } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return GroupMemberAppearance(name, gender, formId, kind, palettePack, slots) - } + override fun CodecScope.body(): GroupMemberAppearance { + val name = field(Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val formId = field(S32LE) { it.formId } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return GroupMemberAppearance(name, gender, formId, kind, palettePack, slots) + } } data class GroupMemberTrackedEntity( @@ -31,11 +31,11 @@ data class GroupMemberTrackedEntity( private val GroupMemberTrackedEntityCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupMemberTrackedEntity { - val entityId = field(S64LE) { it.entityId } - val appearance = field(GroupMemberAppearanceCodec) { it.appearance } - return GroupMemberTrackedEntity(entityId, appearance) - } + override fun CodecScope.body(): GroupMemberTrackedEntity { + val entityId = field(S64LE) { it.entityId } + val appearance = field(GroupMemberAppearanceCodec) { it.appearance } + return GroupMemberTrackedEntity(entityId, appearance) + } } data class GroupRosterMember( @@ -47,14 +47,14 @@ data class GroupRosterMember( private val GroupRosterMemberCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GroupRosterMember { - val entityId = field(S64LE) { it.entityId } - val name = field(Utf16LeNullTerminated) { it.name } - val guildName = field(Utf16LeNullTerminated) { it.guildName } - val trackedEntities = - field(GroupMemberTrackedEntityCodec.listPrefixed(U8)) { it.trackedEntities } - return GroupRosterMember(entityId, name, guildName, trackedEntities) - } + override fun CodecScope.body(): GroupRosterMember { + val entityId = field(S64LE) { it.entityId } + val name = field(Utf16LeNullTerminated) { it.name } + val guildName = field(Utf16LeNullTerminated) { it.guildName } + val trackedEntities = + field(GroupMemberTrackedEntityCodec.listPrefixed(U8)) { it.trackedEntities } + return GroupRosterMember(entityId, name, guildName, trackedEntities) + } } data class GroupMemberRosterPacket( @@ -65,11 +65,11 @@ data class GroupMemberRosterPacket( ) object GroupMemberRosterPacketCodec : PacketCodec() { - override fun CodecScope.body(): GroupMemberRosterPacket { - val reset = field(U8) { if (it.reset) 1 else 0 } == 1 - val updateState = field(U8) { if (it.updateState) 1 else 0 } == 1 - val state = field(S8) { it.state } - val members = field(GroupRosterMemberCodec.listPrefixed(U8)) { it.members } - return GroupMemberRosterPacket(reset, updateState, state, members) - } + override fun CodecScope.body(): GroupMemberRosterPacket { + val reset = field(U8) { if (it.reset) 1 else 0 } == 1 + val updateState = field(U8) { if (it.updateState) 1 else 0 } == 1 + val state = field(S8) { it.state } + val members = field(GroupRosterMemberCodec.listPrefixed(U8)) { it.members } + return GroupMemberRosterPacket(reset, updateState, state, members) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlConfirmPurchasePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlConfirmPurchasePacket.kt index ac48552..3da1ddd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlConfirmPurchasePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlConfirmPurchasePacket.kt @@ -11,9 +11,9 @@ data class GtlConfirmPurchasePacket( ) object GtlConfirmPurchasePacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlConfirmPurchasePacket { - val listingEntityId = field(S64LE) { it.listingEntityId } - val quantity = field(S16LE) { it.quantity } - return GtlConfirmPurchasePacket(listingEntityId, quantity) - } + override fun CodecScope.body(): GtlConfirmPurchasePacket { + val listingEntityId = field(S64LE) { it.listingEntityId } + val quantity = field(S16LE) { it.quantity } + return GtlConfirmPurchasePacket(listingEntityId, quantity) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlCreateListingPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlCreateListingPacket.kt index 76721f4..a6cd781 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlCreateListingPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlCreateListingPacket.kt @@ -9,46 +9,44 @@ data class GtlCreateListingPacket( val priceShort: Short, val filterCriteria: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is GtlCreateListingPacket && - categoryIndex == other.categoryIndex && - listingCount == other.listingCount && - itemKind == other.itemKind && - priceShort == other.priceShort && - filterCriteria.contentEquals(other.filterCriteria) + override fun equals(other: Any?): Boolean = + other is GtlCreateListingPacket && + categoryIndex == other.categoryIndex && + listingCount == other.listingCount && + itemKind == other.itemKind && + priceShort == other.priceShort && + filterCriteria.contentEquals(other.filterCriteria) - override fun hashCode(): Int { - var r = categoryIndex.toInt() - r = r * 31 + listingCount - r = r * 31 + itemKind - r = r * 31 + priceShort - r = r * 31 + filterCriteria.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = categoryIndex.toInt() + r = r * 31 + listingCount + r = r * 31 + itemKind + r = r * 31 + priceShort + r = r * 31 + filterCriteria.contentHashCode() + return r + } } private val FilterCriteriaBytes: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object GtlCreateListingPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlCreateListingPacket { - val categoryIndex = field(S8) { it.categoryIndex } - val listingCount = field(S8) { it.listingCount } - val itemKind = field(S8) { it.itemKind } - val priceShort = field(S16LE) { it.priceShort } - val filterCriteria = field(FilterCriteriaBytes) { it.filterCriteria } - return GtlCreateListingPacket( - categoryIndex, listingCount, itemKind, priceShort, filterCriteria - ) - } + override fun CodecScope.body(): GtlCreateListingPacket { + val categoryIndex = field(S8) { it.categoryIndex } + val listingCount = field(S8) { it.listingCount } + val itemKind = field(S8) { it.itemKind } + val priceShort = field(S16LE) { it.priceShort } + val filterCriteria = field(FilterCriteriaBytes) { it.filterCriteria } + return GtlCreateListingPacket(categoryIndex, listingCount, itemKind, priceShort, filterCriteria) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlItemMarketPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlItemMarketPacket.kt index f676b70..ca7b7e1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlItemMarketPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlItemMarketPacket.kt @@ -16,33 +16,33 @@ data class GtlItemMarketPacket( ) private object GtlMarketEntryCodec : PacketCodec() { - override fun CodecScope.body(): GtlMarketEntry { - val price = field(S32LE, GtlMarketEntry::price) - val quantity = field(S64LE, GtlMarketEntry::quantity) - return GtlMarketEntry(price, quantity) - } + override fun CodecScope.body(): GtlMarketEntry { + val price = field(S32LE, GtlMarketEntry::price) + val quantity = field(S64LE, GtlMarketEntry::quantity) + return GtlMarketEntry(price, quantity) + } } private val GtlMarketEntryListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { GtlMarketEntryCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { GtlMarketEntryCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { GtlMarketEntryCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { GtlMarketEntryCodec.write(buf, it) } + } } object GtlItemMarketPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlItemMarketPacket { - val itemType = field(U8, GtlItemMarketPacket::itemType) - val variant = field(S16LE, GtlItemMarketPacket::variant) - val count = field(S32LE, GtlItemMarketPacket::count) - val quantities = field(S32LE.repeat(3), GtlItemMarketPacket::quantities) - val entries = field(GtlMarketEntryListPrefixedU8, GtlItemMarketPacket::entries) - return GtlItemMarketPacket(itemType, variant, count, quantities, entries) - } + override fun CodecScope.body(): GtlItemMarketPacket { + val itemType = field(U8, GtlItemMarketPacket::itemType) + val variant = field(S16LE, GtlItemMarketPacket::variant) + val count = field(S32LE, GtlItemMarketPacket::count) + val quantities = field(S32LE.repeat(3), GtlItemMarketPacket::quantities) + val entries = field(GtlMarketEntryListPrefixedU8, GtlItemMarketPacket::entries) + return GtlItemMarketPacket(itemType, variant, count, quantities, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingActionPacket.kt index 142f675..e945d0b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingActionPacket.kt @@ -11,9 +11,9 @@ data class GtlListingActionPacket( ) object GtlListingActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlListingActionPacket { - val entryKindId = field(S8) { it.entryKindId } - val itemId = field(S16LE) { it.itemId } - return GtlListingActionPacket(entryKindId, itemId) - } + override fun CodecScope.body(): GtlListingActionPacket { + val entryKindId = field(S8) { it.entryKindId } + val itemId = field(S16LE) { it.itemId } + return GtlListingActionPacket(entryKindId, itemId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingCancelPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingCancelPacket.kt index be2215d..94f4bcd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingCancelPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingCancelPacket.kt @@ -9,8 +9,8 @@ data class GtlListingCancelPacket( ) object GtlListingCancelPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlListingCancelPacket { - val listingId = field(Utf16LeNullTerminated) { it.listingId } - return GtlListingCancelPacket(listingId) - } + override fun CodecScope.body(): GtlListingCancelPacket { + val listingId = field(Utf16LeNullTerminated) { it.listingId } + return GtlListingCancelPacket(listingId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingSearchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingSearchPacket.kt index 8378bb0..095069f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingSearchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingSearchPacket.kt @@ -9,8 +9,8 @@ data class GtlListingSearchPacket( ) object GtlListingSearchPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlListingSearchPacket { - val searchId = field(S32LE) { it.searchId } - return GtlListingSearchPacket(searchId) - } + override fun CodecScope.body(): GtlListingSearchPacket { + val searchId = field(S32LE) { it.searchId } + return GtlListingSearchPacket(searchId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingsPagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingsPagePacket.kt index d61d04e..9616934 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingsPagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlListingsPagePacket.kt @@ -26,34 +26,34 @@ data class GtlListingsPagePacket( private val TradeListingEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): TradeListingEntry { - val a = field(S32LE) { it.a } - val b = field(S32LE) { it.b } - val c = field(S64LE) { it.c } - return TradeListingEntry(a, b, c) - } + override fun CodecScope.body(): TradeListingEntry { + val a = field(S32LE) { it.a } + val b = field(S32LE) { it.b } + val c = field(S64LE) { it.c } + return TradeListingEntry(a, b, c) + } } private val TradeListingCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): TradeListing { - val typeId = field(S16LE) { it.typeId } - val price = field(S32LE) { it.price } - val fieldB = field(S32LE) { it.fieldB } - val fieldC = field(S32LE) { it.fieldC } - val fieldD = field(S32LE) { it.fieldD } - val entries = field(TradeListingEntryCodec.listPrefixed(U8)) { it.entries } - return TradeListing(typeId, price, fieldB, fieldC, fieldD, entries) - } + override fun CodecScope.body(): TradeListing { + val typeId = field(S16LE) { it.typeId } + val price = field(S32LE) { it.price } + val fieldB = field(S32LE) { it.fieldB } + val fieldC = field(S32LE) { it.fieldC } + val fieldD = field(S32LE) { it.fieldD } + val entries = field(TradeListingEntryCodec.listPrefixed(U8)) { it.entries } + return TradeListing(typeId, price, fieldB, fieldC, fieldD, entries) + } } object GtlListingsPagePacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlListingsPagePacket { - val page = field(S8) { it.page } - val entryKind = field(U8) { it.entryKind } - field(S16LE) { 0 } - val totalCount = field(S32LE) { it.totalCount } - val listings = field(TradeListingCodec.listPrefixed(U8)) { it.listings } - return GtlListingsPagePacket(page, entryKind, totalCount, listings) - } + override fun CodecScope.body(): GtlListingsPagePacket { + val page = field(S8) { it.page } + val entryKind = field(U8) { it.entryKind } + field(S16LE) { 0 } + val totalCount = field(S32LE) { it.totalCount } + val listings = field(TradeListingCodec.listPrefixed(U8)) { it.listings } + return GtlListingsPagePacket(page, entryKind, totalCount, listings) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlMarketListingsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlMarketListingsPacket.kt index 5c01881..cbf1574 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlMarketListingsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlMarketListingsPacket.kt @@ -25,80 +25,80 @@ data class GtlMarketListingsPacket( val referenceData: ByteArray?, val listings: List, ) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is GtlMarketListingsPacket) return false - return fullReset == other.fullReset && - applyToBoards == other.applyToBoards && - (referenceData?.contentEquals(other.referenceData) ?: (other.referenceData == null)) && - listings == other.listings - } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is GtlMarketListingsPacket) return false + return fullReset == other.fullReset && + applyToBoards == other.applyToBoards && + (referenceData?.contentEquals(other.referenceData) ?: (other.referenceData == null)) && + listings == other.listings + } - override fun hashCode(): Int { - var result = fullReset.hashCode() - result = 31 * result + applyToBoards.hashCode() - result = 31 * result + (referenceData?.contentHashCode() ?: 0) - result = 31 * result + listings.hashCode() - return result - } + override fun hashCode(): Int { + var result = fullReset.hashCode() + result = 31 * result + applyToBoards.hashCode() + result = 31 * result + (referenceData?.contentHashCode() ?: 0) + result = 31 * result + listings.hashCode() + return result + } } private object GtlMarketListingCodec : PacketCodec() { - override fun CodecScope.body(): GtlMarketListing { - val listingId = field(S32LE, GtlMarketListing::listingId) - val typeId = field(S8, GtlMarketListing::typeId) - val sellerId = field(S8, GtlMarketListing::sellerId) - val speciesId = field(S16LE, GtlMarketListing::speciesId) - val value1 = field(S32LE, GtlMarketListing::value1) - val value2 = field(S32LE, GtlMarketListing::value2) - val value3 = field(S32LE, GtlMarketListing::value3) - val ownListing = field(Bool, GtlMarketListing::ownListing) - val value4 = field(S32LE, GtlMarketListing::value4) - val value5 = field(S32LE, GtlMarketListing::value5) - val value6 = field(S32LE, GtlMarketListing::value6) - val value7 = field(S32LE, GtlMarketListing::value7) - val form = field(S8, GtlMarketListing::form) - reserved(byte = 0) - val rowIndex = field(S32LE, GtlMarketListing::rowIndex) - return GtlMarketListing( - listingId, - typeId, - sellerId, - speciesId, - value1, - value2, - value3, - ownListing, - value4, - value5, - value6, - value7, - form, - rowIndex, - ) - } + override fun CodecScope.body(): GtlMarketListing { + val listingId = field(S32LE, GtlMarketListing::listingId) + val typeId = field(S8, GtlMarketListing::typeId) + val sellerId = field(S8, GtlMarketListing::sellerId) + val speciesId = field(S16LE, GtlMarketListing::speciesId) + val value1 = field(S32LE, GtlMarketListing::value1) + val value2 = field(S32LE, GtlMarketListing::value2) + val value3 = field(S32LE, GtlMarketListing::value3) + val ownListing = field(Bool, GtlMarketListing::ownListing) + val value4 = field(S32LE, GtlMarketListing::value4) + val value5 = field(S32LE, GtlMarketListing::value5) + val value6 = field(S32LE, GtlMarketListing::value6) + val value7 = field(S32LE, GtlMarketListing::value7) + val form = field(S8, GtlMarketListing::form) + reserved(byte = 0) + val rowIndex = field(S32LE, GtlMarketListing::rowIndex) + return GtlMarketListing( + listingId, + typeId, + sellerId, + speciesId, + value1, + value2, + value3, + ownListing, + value4, + value5, + value6, + value7, + form, + rowIndex, + ) + } } private val GtlMarketListingListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { GtlMarketListingCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { GtlMarketListingCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { GtlMarketListingCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { GtlMarketListingCodec.write(buf, it) } + } } object GtlMarketListingsPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlMarketListingsPacket { - val fullReset = field(Bool, GtlMarketListingsPacket::fullReset) - val applyToBoards = field(Bool, GtlMarketListingsPacket::applyToBoards) - val referenceData = - if (fullReset) field(bytesPrefixed(U8)) { it.referenceData ?: ByteArray(0) } else null - val listings = field(GtlMarketListingListPrefixedU8, GtlMarketListingsPacket::listings) - return GtlMarketListingsPacket(fullReset, applyToBoards, referenceData, listings) - } + override fun CodecScope.body(): GtlMarketListingsPacket { + val fullReset = field(Bool, GtlMarketListingsPacket::fullReset) + val applyToBoards = field(Bool, GtlMarketListingsPacket::applyToBoards) + val referenceData = + if (fullReset) field(bytesPrefixed(U8)) { it.referenceData ?: ByteArray(0) } else null + val listings = field(GtlMarketListingListPrefixedU8, GtlMarketListingsPacket::listings) + return GtlMarketListingsPacket(fullReset, applyToBoards, referenceData, listings) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlOpenSessionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlOpenSessionPacket.kt index 9ffc21f..9996be7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlOpenSessionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlOpenSessionPacket.kt @@ -11,9 +11,9 @@ data class GtlOpenSessionPacket( ) object GtlOpenSessionPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlOpenSessionPacket { - val entryKindId = field(S8) { it.entryKindId } - val sessionTimestamp = field(S64LE) { it.sessionTimestamp } - return GtlOpenSessionPacket(entryKindId, sessionTimestamp) - } + override fun CodecScope.body(): GtlOpenSessionPacket { + val entryKindId = field(S8) { it.entryKindId } + val sessionTimestamp = field(S64LE) { it.sessionTimestamp } + return GtlOpenSessionPacket(entryKindId, sessionTimestamp) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPriceHistoryPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPriceHistoryPacket.kt index 187123c..7d9ccf7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPriceHistoryPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPriceHistoryPacket.kt @@ -14,31 +14,31 @@ data class GtlPriceHistoryPacket( ) private object GtlPriceHistoryPointCodec : PacketCodec() { - override fun CodecScope.body(): GtlPriceHistoryPoint { - val timestampSeconds = field(S32LE, GtlPriceHistoryPoint::timestampSeconds) - val price = field(S32LE, GtlPriceHistoryPoint::price) - return GtlPriceHistoryPoint(timestampSeconds, price) - } + override fun CodecScope.body(): GtlPriceHistoryPoint { + val timestampSeconds = field(S32LE, GtlPriceHistoryPoint::timestampSeconds) + val price = field(S32LE, GtlPriceHistoryPoint::price) + return GtlPriceHistoryPoint(timestampSeconds, price) + } } private val GtlPriceHistoryPointListPrefixedU16: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U16LE.read(buf) - return List(n) { GtlPriceHistoryPointCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U16LE.read(buf) + return List(n) { GtlPriceHistoryPointCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U16LE.write(buf, value.size) - value.forEach { GtlPriceHistoryPointCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U16LE.write(buf, value.size) + value.forEach { GtlPriceHistoryPointCodec.write(buf, it) } + } } object GtlPriceHistoryPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlPriceHistoryPacket { - val itemType = field(U8, GtlPriceHistoryPacket::itemType) - val variant = field(S16LE, GtlPriceHistoryPacket::variant) - val points = field(GtlPriceHistoryPointListPrefixedU16, GtlPriceHistoryPacket::points) - return GtlPriceHistoryPacket(itemType, variant, points) - } + override fun CodecScope.body(): GtlPriceHistoryPacket { + val itemType = field(U8, GtlPriceHistoryPacket::itemType) + val variant = field(S16LE, GtlPriceHistoryPacket::variant) + val points = field(GtlPriceHistoryPointListPrefixedU16, GtlPriceHistoryPacket::points) + return GtlPriceHistoryPacket(itemType, variant, points) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchaseListingPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchaseListingPacket.kt index 8a9036b..f9e24c0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchaseListingPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchaseListingPacket.kt @@ -12,10 +12,10 @@ data class GtlPurchaseListingPacket( ) object GtlPurchaseListingPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlPurchaseListingPacket { - val listingId = field(S32LE) { it.listingId } - val price = field(S32LE) { it.price } - val action = field(S8) { it.action } - return GtlPurchaseListingPacket(listingId, price, action) - } + override fun CodecScope.body(): GtlPurchaseListingPacket { + val listingId = field(S32LE) { it.listingId } + val price = field(S32LE) { it.price } + val action = field(S8) { it.action } + return GtlPurchaseListingPacket(listingId, price, action) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchasePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchasePacket.kt index ca9fa0e..6f99e9e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchasePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlPurchasePacket.kt @@ -11,12 +11,12 @@ data class GtlPurchasePacket( ) object GtlPurchasePacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlPurchasePacket { - val entryKindId = field(S8) { it.entryKindId } - val itemTypeId = field(S16LE) { it.itemTypeId } - val quantity = field(S16LE) { it.quantity } - val totalPrice = field(S32LE) { it.totalPrice } - val listingFlag = field(S8) { it.listingFlag } - return GtlPurchasePacket(entryKindId, itemTypeId, quantity, totalPrice, listingFlag) - } + override fun CodecScope.body(): GtlPurchasePacket { + val entryKindId = field(S8) { it.entryKindId } + val itemTypeId = field(S16LE) { it.itemTypeId } + val quantity = field(S16LE) { it.quantity } + val totalPrice = field(S32LE) { it.totalPrice } + val listingFlag = field(S8) { it.listingFlag } + return GtlPurchasePacket(entryKindId, itemTypeId, quantity, totalPrice, listingFlag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSearchFilterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSearchFilterPacket.kt index eac0c6c..983a5bc 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSearchFilterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSearchFilterPacket.kt @@ -9,8 +9,8 @@ data class GtlSearchFilterPacket( ) object GtlSearchFilterPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlSearchFilterPacket { - val filterState = field(S8) { it.filterState } - return GtlSearchFilterPacket(filterState) - } + override fun CodecScope.body(): GtlSearchFilterPacket { + val filterState = field(S8) { it.filterState } + return GtlSearchFilterPacket(filterState) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSellPokemonListingPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSellPokemonListingPacket.kt index 75d0b80..decb088 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSellPokemonListingPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlSellPokemonListingPacket.kt @@ -10,36 +10,35 @@ data class GtlSellPokemonListingPacket( val criteriaCount: Int, val criteriaData: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is GtlSellPokemonListingPacket && - listingType == other.listingType && - entryKindId == other.entryKindId && - listingCategory == other.listingCategory && - itemTypeId == other.itemTypeId && - criteriaCount == other.criteriaCount && - criteriaData.contentEquals(other.criteriaData) + override fun equals(other: Any?): Boolean = + other is GtlSellPokemonListingPacket && + listingType == other.listingType && + entryKindId == other.entryKindId && + listingCategory == other.listingCategory && + itemTypeId == other.itemTypeId && + criteriaCount == other.criteriaCount && + criteriaData.contentEquals(other.criteriaData) - override fun hashCode(): Int { - var r = listingType.toInt() - r = r * 31 + entryKindId - r = r * 31 + listingCategory - r = r * 31 + itemTypeId - r = r * 31 + criteriaCount - r = r * 31 + criteriaData.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = listingType.toInt() + r = r * 31 + entryKindId + r = r * 31 + listingCategory + r = r * 31 + itemTypeId + r = r * 31 + criteriaCount + r = r * 31 + criteriaData.contentHashCode() + return r + } } object GtlSellPokemonListingPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlSellPokemonListingPacket { - val listingType = field(S8) { it.listingType } - val entryKindId = field(S8) { it.entryKindId } - val listingCategory = field(S8) { it.listingCategory } - val itemTypeId = field(S16LE) { it.itemTypeId } - val criteriaCount = field(U8) { it.criteriaCount } - val criteriaData = field(RemainingBytes) { it.criteriaData } - return GtlSellPokemonListingPacket( - listingType, entryKindId, listingCategory, itemTypeId, criteriaCount, criteriaData - ) - } + override fun CodecScope.body(): GtlSellPokemonListingPacket { + val listingType = field(S8) { it.listingType } + val entryKindId = field(S8) { it.entryKindId } + val listingCategory = field(S8) { it.listingCategory } + val itemTypeId = field(S16LE) { it.itemTypeId } + val criteriaCount = field(U8) { it.criteriaCount } + val criteriaData = field(RemainingBytes) { it.criteriaData } + return GtlSellPokemonListingPacket( + listingType, entryKindId, listingCategory, itemTypeId, criteriaCount, criteriaData) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlTradeLogRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlTradeLogRequestPacket.kt index dfae39b..3703b30 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlTradeLogRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GtlTradeLogRequestPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class GtlTradeLogRequestPacket object GtlTradeLogRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): GtlTradeLogRequestPacket { - return GtlTradeLogRequestPacket() - } + override fun CodecScope.body(): GtlTradeLogRequestPacket { + return GtlTradeLogRequestPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPacket.kt index 322c7fb..a04e94a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPacket.kt @@ -15,32 +15,32 @@ data class GuildActivityLogPacket( ) private object GuildActivityLogEntryCodec : PacketCodec() { - override fun CodecScope.body(): GuildActivityLogEntry { - val type = field(U8, GuildActivityLogEntry::type) - val actor = field(Utf16LeNullTerminated, GuildActivityLogEntry::actor) - val target = field(Utf16LeNullTerminated, GuildActivityLogEntry::target) - val timestamp = field(S32LE, GuildActivityLogEntry::timestamp) - return GuildActivityLogEntry(type, actor, target, timestamp) - } + override fun CodecScope.body(): GuildActivityLogEntry { + val type = field(U8, GuildActivityLogEntry::type) + val actor = field(Utf16LeNullTerminated, GuildActivityLogEntry::actor) + val target = field(Utf16LeNullTerminated, GuildActivityLogEntry::target) + val timestamp = field(S32LE, GuildActivityLogEntry::timestamp) + return GuildActivityLogEntry(type, actor, target, timestamp) + } } private val GuildActivityLogEntryListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { GuildActivityLogEntryCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { GuildActivityLogEntryCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { GuildActivityLogEntryCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { GuildActivityLogEntryCodec.write(buf, it) } + } } object GuildActivityLogPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildActivityLogPacket { - val totalCount = field(S16LE, GuildActivityLogPacket::totalCount) - val entries = field(GuildActivityLogEntryListPrefixedU8, GuildActivityLogPacket::entries) - return GuildActivityLogPacket(totalCount, entries) - } + override fun CodecScope.body(): GuildActivityLogPacket { + val totalCount = field(S16LE, GuildActivityLogPacket::totalCount) + val entries = field(GuildActivityLogEntryListPrefixedU8, GuildActivityLogPacket::entries) + return GuildActivityLogPacket(totalCount, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPageRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPageRequestPacket.kt index c7fc284..5c90743 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPageRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildActivityLogPageRequestPacket.kt @@ -9,9 +9,9 @@ data class GuildActivityLogPageRequestPacket( ) object GuildActivityLogPageRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): - GuildActivityLogPageRequestPacket { - val pageIndex = field(S16LE) { it.pageIndex } - return GuildActivityLogPageRequestPacket(pageIndex) - } + override fun CodecScope.body(): + GuildActivityLogPageRequestPacket { + val pageIndex = field(S16LE) { it.pageIndex } + return GuildActivityLogPageRequestPacket(pageIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildChatSendPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildChatSendPacket.kt index e27abf6..e0e9fcc 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildChatSendPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildChatSendPacket.kt @@ -9,8 +9,8 @@ data class GuildChatSendPacket( ) object GuildChatSendPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildChatSendPacket { - val message = field(Utf16LeNullTerminated) { it.message } - return GuildChatSendPacket(message) - } + override fun CodecScope.body(): GuildChatSendPacket { + val message = field(Utf16LeNullTerminated) { it.message } + return GuildChatSendPacket(message) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDepartPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDepartPacket.kt index e78b0f5..f6f397b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDepartPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDepartPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class GuildDepartPacket object GuildDepartPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildDepartPacket { - return GuildDepartPacket() - } + override fun CodecScope.body(): GuildDepartPacket { + return GuildDepartPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDisbandToggleRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDisbandToggleRequestPacket.kt index ff0495a..ca62e8f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDisbandToggleRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildDisbandToggleRequestPacket.kt @@ -11,9 +11,9 @@ data class GuildDisbandToggleRequestPacket( ) object GuildDisbandToggleRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildDisbandToggleRequestPacket { - val initiate = field(Bool) { it.initiate } - val ownerEntityId = field(S64LE) { it.ownerEntityId } - return GuildDisbandToggleRequestPacket(initiate, ownerEntityId) - } + override fun CodecScope.body(): GuildDisbandToggleRequestPacket { + val initiate = field(Bool) { it.initiate } + val ownerEntityId = field(S64LE) { it.ownerEntityId } + return GuildDisbandToggleRequestPacket(initiate, ownerEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberExpelPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberExpelPacket.kt index c99026b..908b3a9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberExpelPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberExpelPacket.kt @@ -9,8 +9,8 @@ data class GuildMemberExpelPacket( ) object GuildMemberExpelPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildMemberExpelPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - return GuildMemberExpelPacket(targetEntityId) - } + override fun CodecScope.body(): GuildMemberExpelPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + return GuildMemberExpelPacket(targetEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberPresencePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberPresencePacket.kt index 43b4bc3..f657bcf 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberPresencePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberPresencePacket.kt @@ -11,9 +11,9 @@ data class GuildMemberPresencePacket( ) object GuildMemberPresencePacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildMemberPresencePacket { - val memberId = field(S64LE, GuildMemberPresencePacket::memberId) - val online = field(Bool, GuildMemberPresencePacket::online) - return GuildMemberPresencePacket(memberId, online) - } + override fun CodecScope.body(): GuildMemberPresencePacket { + val memberId = field(S64LE, GuildMemberPresencePacket::memberId) + val online = field(Bool, GuildMemberPresencePacket::online) + return GuildMemberPresencePacket(memberId, online) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankAssignPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankAssignPacket.kt index 9188613..bf9ad72 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankAssignPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankAssignPacket.kt @@ -11,9 +11,9 @@ data class GuildMemberRankAssignPacket( ) object GuildMemberRankAssignPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildMemberRankAssignPacket { - val memberEntityId = field(S64LE) { it.memberEntityId } - val rankOrdinal = field(U8) { it.rankOrdinal } - return GuildMemberRankAssignPacket(memberEntityId, rankOrdinal) - } + override fun CodecScope.body(): GuildMemberRankAssignPacket { + val memberEntityId = field(S64LE) { it.memberEntityId } + val rankOrdinal = field(U8) { it.rankOrdinal } + return GuildMemberRankAssignPacket(memberEntityId, rankOrdinal) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankChangePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankChangePacket.kt index edb07f1..43d247a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankChangePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMemberRankChangePacket.kt @@ -11,10 +11,10 @@ data class GuildMemberRankChangePacket( ) object GuildMemberRankChangePacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildMemberRankChangePacket { - field(S64LE) { 0L } - val memberId = field(S64LE, GuildMemberRankChangePacket::memberId) - val rank = field(S8, GuildMemberRankChangePacket::rank) - return GuildMemberRankChangePacket(memberId, rank) - } + override fun CodecScope.body(): GuildMemberRankChangePacket { + field(S64LE) { 0L } + val memberId = field(S64LE, GuildMemberRankChangePacket::memberId) + val rank = field(S8, GuildMemberRankChangePacket::rank) + return GuildMemberRankChangePacket(memberId, rank) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMembershipPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMembershipPacket.kt index ee786b4..9bab227 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMembershipPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMembershipPacket.kt @@ -24,43 +24,44 @@ data class GuildMembershipPacket( ) private object GuildProfileDataCodec : PacketCodec() { - override fun CodecScope.body(): GuildProfileData { - val guildId = field(S64LE, GuildProfileData::guildId) - val name = field(Utf16LeNullTerminated, GuildProfileData::name) - val tag = field(Utf16LeNullTerminated, GuildProfileData::tag) - val memberCount = field(S32LE, GuildProfileData::memberCount) - val description = field(Utf16LeNullTerminated, GuildProfileData::description) - val motd = field(S32LE, GuildProfileData::motd) - val value1 = field(S16LE, GuildProfileData::value1) - val value2 = field(S16LE, GuildProfileData::value2) - val value3 = field(S16LE, GuildProfileData::value3) - val value4 = field(S16LE, GuildProfileData::value4) - val value5 = field(S16LE, GuildProfileData::value5) - val value6 = field(S32LE, GuildProfileData::value6) - val rankCount = field(S8) { it.rankNames.size.toByte() } - val rankNames = List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } } - return GuildProfileData( - guildId, - name, - tag, - memberCount, - description, - motd, - value1, - value2, - value3, - value4, - value5, - value6, - rankNames, - ) - } + override fun CodecScope.body(): GuildProfileData { + val guildId = field(S64LE, GuildProfileData::guildId) + val name = field(Utf16LeNullTerminated, GuildProfileData::name) + val tag = field(Utf16LeNullTerminated, GuildProfileData::tag) + val memberCount = field(S32LE, GuildProfileData::memberCount) + val description = field(Utf16LeNullTerminated, GuildProfileData::description) + val motd = field(S32LE, GuildProfileData::motd) + val value1 = field(S16LE, GuildProfileData::value1) + val value2 = field(S16LE, GuildProfileData::value2) + val value3 = field(S16LE, GuildProfileData::value3) + val value4 = field(S16LE, GuildProfileData::value4) + val value5 = field(S16LE, GuildProfileData::value5) + val value6 = field(S32LE, GuildProfileData::value6) + val rankCount = field(S8) { it.rankNames.size.toByte() } + val rankNames = + List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } } + return GuildProfileData( + guildId, + name, + tag, + memberCount, + description, + motd, + value1, + value2, + value3, + value4, + value5, + value6, + rankNames, + ) + } } object GuildMembershipPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildMembershipPacket { - val inGuild = field(Bool, GuildMembershipPacket::inGuild) - val profile = if (inGuild) field(GuildProfileDataCodec) { it.profile!! } else null - return GuildMembershipPacket(inGuild, profile) - } + override fun CodecScope.body(): GuildMembershipPacket { + val inGuild = field(Bool, GuildMembershipPacket::inGuild) + val profile = if (inGuild) field(GuildProfileDataCodec) { it.profile!! } else null + return GuildMembershipPacket(inGuild, profile) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMotdUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMotdUpdatePacket.kt index f71a0da..96b5648 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMotdUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildMotdUpdatePacket.kt @@ -9,8 +9,8 @@ data class GuildMotdUpdatePacket( ) object GuildMotdUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildMotdUpdatePacket { - val motdText = field(Utf16LeNullTerminated) { it.motdText } - return GuildMotdUpdatePacket(motdText) - } + override fun CodecScope.body(): GuildMotdUpdatePacket { + val motdText = field(Utf16LeNullTerminated) { it.motdText } + return GuildMotdUpdatePacket(motdText) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildProfileSyncPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildProfileSyncPacket.kt index 72b1a58..854d479 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildProfileSyncPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildProfileSyncPacket.kt @@ -19,35 +19,36 @@ data class GuildProfileSyncPacket( ) object GuildProfileSyncPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildProfileSyncPacket { - val guildId = field(S64LE, GuildProfileSyncPacket::guildId) - val name = field(Utf16LeNullTerminated, GuildProfileSyncPacket::name) - val tag = field(Utf16LeNullTerminated, GuildProfileSyncPacket::tag) - val memberCount = field(S32LE, GuildProfileSyncPacket::memberCount) - val description = field(Utf16LeNullTerminated, GuildProfileSyncPacket::description) - val motd = field(S32LE, GuildProfileSyncPacket::motd) - val value1 = field(S16LE, GuildProfileSyncPacket::value1) - val value2 = field(S16LE, GuildProfileSyncPacket::value2) - val value3 = field(S16LE, GuildProfileSyncPacket::value3) - val value4 = field(S16LE, GuildProfileSyncPacket::value4) - val value5 = field(S16LE, GuildProfileSyncPacket::value5) - val value6 = field(S32LE, GuildProfileSyncPacket::value6) - val rankCount = field(S8) { it.rankNames.size.toByte() } - val rankNames = List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } } - return GuildProfileSyncPacket( - guildId, - name, - tag, - memberCount, - description, - motd, - value1, - value2, - value3, - value4, - value5, - value6, - rankNames, - ) - } + override fun CodecScope.body(): GuildProfileSyncPacket { + val guildId = field(S64LE, GuildProfileSyncPacket::guildId) + val name = field(Utf16LeNullTerminated, GuildProfileSyncPacket::name) + val tag = field(Utf16LeNullTerminated, GuildProfileSyncPacket::tag) + val memberCount = field(S32LE, GuildProfileSyncPacket::memberCount) + val description = field(Utf16LeNullTerminated, GuildProfileSyncPacket::description) + val motd = field(S32LE, GuildProfileSyncPacket::motd) + val value1 = field(S16LE, GuildProfileSyncPacket::value1) + val value2 = field(S16LE, GuildProfileSyncPacket::value2) + val value3 = field(S16LE, GuildProfileSyncPacket::value3) + val value4 = field(S16LE, GuildProfileSyncPacket::value4) + val value5 = field(S16LE, GuildProfileSyncPacket::value5) + val value6 = field(S32LE, GuildProfileSyncPacket::value6) + val rankCount = field(S8) { it.rankNames.size.toByte() } + val rankNames = + List(rankCount.toInt()) { i -> field(Utf16LeNullTerminated) { it.rankNames[i] } } + return GuildProfileSyncPacket( + guildId, + name, + tag, + memberCount, + description, + motd, + value1, + value2, + value3, + value4, + value5, + value6, + rankNames, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankLabelUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankLabelUpdatePacket.kt index 267707e..b205652 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankLabelUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankLabelUpdatePacket.kt @@ -11,9 +11,9 @@ data class GuildRankLabelUpdatePacket( ) object GuildRankLabelUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildRankLabelUpdatePacket { - val rankOrdinal = field(U8) { it.rankOrdinal } - val rankLabel = field(Utf16LeNullTerminated) { it.rankLabel } - return GuildRankLabelUpdatePacket(rankOrdinal, rankLabel) - } + override fun CodecScope.body(): GuildRankLabelUpdatePacket { + val rankOrdinal = field(U8) { it.rankOrdinal } + val rankLabel = field(Utf16LeNullTerminated) { it.rankLabel } + return GuildRankLabelUpdatePacket(rankOrdinal, rankLabel) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankPermissionUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankPermissionUpdatePacket.kt index cfdcaab..c989135 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankPermissionUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRankPermissionUpdatePacket.kt @@ -13,18 +13,18 @@ data class GuildRankPermissionUpdatePacket( ) object GuildRankPermissionUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildRankPermissionUpdatePacket { - val permCategory1 = field(S16LE) { it.permCategory1 } - val permCategory2 = field(S16LE) { it.permCategory2 } - val permCategory3 = field(S16LE) { it.permCategory3 } - val permCategory4 = field(S16LE) { it.permCategory4 } - val permCategory5 = field(S16LE) { it.permCategory5 } - return GuildRankPermissionUpdatePacket( - permCategory1, - permCategory2, - permCategory3, - permCategory4, - permCategory5, - ) - } + override fun CodecScope.body(): GuildRankPermissionUpdatePacket { + val permCategory1 = field(S16LE) { it.permCategory1 } + val permCategory2 = field(S16LE) { it.permCategory2 } + val permCategory3 = field(S16LE) { it.permCategory3 } + val permCategory4 = field(S16LE) { it.permCategory4 } + val permCategory5 = field(S16LE) { it.permCategory5 } + return GuildRankPermissionUpdatePacket( + permCategory1, + permCategory2, + permCategory3, + permCategory4, + permCategory5, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterAddPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterAddPacket.kt index 21242c8..46ea264 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterAddPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterAddPacket.kt @@ -20,24 +20,24 @@ data class GuildRosterAddPacket( ) internal object GuildMemberAppearanceCodec : PacketCodec() { - override fun CodecScope.body(): GuildMemberAppearance { - val name = field(Utf16LeNullTerminated, GuildMemberAppearance::name) - val gender = field(S8, GuildMemberAppearance::gender) - val formId = field(S32LE, GuildMemberAppearance::formId) - val kind = field(S8, GuildMemberAppearance::kind) - val palettePack = field(S8, GuildMemberAppearance::palettePack) - val slots = field(S16LE.repeat(4), GuildMemberAppearance::slots) - return GuildMemberAppearance(name, gender, formId, kind, palettePack, slots) - } + override fun CodecScope.body(): GuildMemberAppearance { + val name = field(Utf16LeNullTerminated, GuildMemberAppearance::name) + val gender = field(S8, GuildMemberAppearance::gender) + val formId = field(S32LE, GuildMemberAppearance::formId) + val kind = field(S8, GuildMemberAppearance::kind) + val palettePack = field(S8, GuildMemberAppearance::palettePack) + val slots = field(S16LE.repeat(4), GuildMemberAppearance::slots) + return GuildMemberAppearance(name, gender, formId, kind, palettePack, slots) + } } object GuildRosterAddPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildRosterAddPacket { - val rank = field(S8, GuildRosterAddPacket::rank) - val entityId = field(S64LE, GuildRosterAddPacket::entityId) - val value = field(S32LE, GuildRosterAddPacket::value) - val appearance = field(GuildMemberAppearanceCodec, GuildRosterAddPacket::appearance) - val leader = field(Bool, GuildRosterAddPacket::leader) - return GuildRosterAddPacket(rank, entityId, value, appearance, leader) - } + override fun CodecScope.body(): GuildRosterAddPacket { + val rank = field(S8, GuildRosterAddPacket::rank) + val entityId = field(S64LE, GuildRosterAddPacket::entityId) + val value = field(S32LE, GuildRosterAddPacket::value) + val appearance = field(GuildMemberAppearanceCodec, GuildRosterAddPacket::appearance) + val leader = field(Bool, GuildRosterAddPacket::leader) + return GuildRosterAddPacket(rank, entityId, value, appearance, leader) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterBulkPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterBulkPacket.kt index 9fdc1ef..5e42a4d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterBulkPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterBulkPacket.kt @@ -16,33 +16,33 @@ data class GuildRosterBulkPacket( ) private object GuildRosterMemberCodec : PacketCodec() { - override fun CodecScope.body(): GuildRosterMember { - val rank = field(S8, GuildRosterMember::rank) - val entityId = field(S64LE, GuildRosterMember::entityId) - val value = field(S32LE, GuildRosterMember::value) - val appearance = field(GuildMemberAppearanceCodec, GuildRosterMember::appearance) - val leader = field(Bool, GuildRosterMember::leader) - return GuildRosterMember(rank, entityId, value, appearance, leader) - } + override fun CodecScope.body(): GuildRosterMember { + val rank = field(S8, GuildRosterMember::rank) + val entityId = field(S64LE, GuildRosterMember::entityId) + val value = field(S32LE, GuildRosterMember::value) + val appearance = field(GuildMemberAppearanceCodec, GuildRosterMember::appearance) + val leader = field(Bool, GuildRosterMember::leader) + return GuildRosterMember(rank, entityId, value, appearance, leader) + } } private val GuildRosterMemberListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { GuildRosterMemberCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { GuildRosterMemberCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { GuildRosterMemberCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { GuildRosterMemberCodec.write(buf, it) } + } } object GuildRosterBulkPacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildRosterBulkPacket { - val replace = field(Bool, GuildRosterBulkPacket::replace) - val members = field(GuildRosterMemberListPrefixedU8, GuildRosterBulkPacket::members) - return GuildRosterBulkPacket(replace, members) - } + override fun CodecScope.body(): GuildRosterBulkPacket { + val replace = field(Bool, GuildRosterBulkPacket::replace) + val members = field(GuildRosterMemberListPrefixedU8, GuildRosterBulkPacket::members) + return GuildRosterBulkPacket(replace, members) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterRemovePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterRemovePacket.kt index 75a7ec0..aa6a68c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterRemovePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/GuildRosterRemovePacket.kt @@ -9,9 +9,9 @@ data class GuildRosterRemovePacket( ) object GuildRosterRemovePacketCodec : PacketCodec() { - override fun CodecScope.body(): GuildRosterRemovePacket { - field(S64LE) { 0L } - val memberId = field(S64LE, GuildRosterRemovePacket::memberId) - return GuildRosterRemovePacket(memberId) - } + override fun CodecScope.body(): GuildRosterRemovePacket { + field(S64LE) { 0L } + val memberId = field(S64LE, GuildRosterRemovePacket::memberId) + return GuildRosterRemovePacket(memberId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HeartbeatRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HeartbeatRequestPacket.kt index 46aedf5..d4f50ca 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HeartbeatRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HeartbeatRequestPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec data class HeartbeatRequestPacket(val placeholder: Unit = Unit) object HeartbeatRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): HeartbeatRequestPacket { - return HeartbeatRequestPacket() - } + override fun CodecScope.body(): HeartbeatRequestPacket { + return HeartbeatRequestPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HighScoreBoardPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HighScoreBoardPacket.kt index 5015d01..87ea8d8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HighScoreBoardPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/HighScoreBoardPacket.kt @@ -25,35 +25,36 @@ data class HighScoreBoardPacket( private val HighScoreAppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): HighScoreAppearance { - val name = field(Utf16LeNullTerminated) { it.name } - val gender = field(S8) { it.gender } - val id = field(S32LE) { it.id } - val kind = field(S8) { it.kind } - val palettePack = field(S8) { it.palettePack } - val slots = field(S16LE.repeat(4)) { it.slots } - return HighScoreAppearance(name, gender, id, kind, palettePack, slots) - } + override fun CodecScope.body(): HighScoreAppearance { + val name = field(Utf16LeNullTerminated) { it.name } + val gender = field(S8) { it.gender } + val id = field(S32LE) { it.id } + val kind = field(S8) { it.kind } + val palettePack = field(S8) { it.palettePack } + val slots = field(S16LE.repeat(4)) { it.slots } + return HighScoreAppearance(name, gender, id, kind, palettePack, slots) + } } private val HighScoreEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): HighScoreEntry { - val entityId = field(S64LE) { it.entityId } - val rank = field(S32LE) { it.rank } - val score = field(S32LE) { it.score } - val count = field(U8) { it.appearances.size } - val appearances = (0 until count).map { i -> field(HighScoreAppearanceCodec) { it.appearances[i] } } - return HighScoreEntry(entityId, rank, score, appearances) - } + override fun CodecScope.body(): HighScoreEntry { + val entityId = field(S64LE) { it.entityId } + val rank = field(S32LE) { it.rank } + val score = field(S32LE) { it.score } + val count = field(U8) { it.appearances.size } + val appearances = + (0 until count).map { i -> field(HighScoreAppearanceCodec) { it.appearances[i] } } + return HighScoreEntry(entityId, rank, score, appearances) + } } object HighScoreBoardPacketCodec : PacketCodec() { - override fun CodecScope.body(): HighScoreBoardPacket { - val category = field(S8) { it.category } - field(S32LE) { 0 } - val count = field(S32LE) { it.entries.size } - val entries = (0 until count).map { i -> field(HighScoreEntryCodec) { it.entries[i] } } - return HighScoreBoardPacket(category, entries) - } + override fun CodecScope.body(): HighScoreBoardPacket { + val category = field(S8) { it.category } + field(S32LE) { 0 } + val count = field(S32LE) { it.entries.size } + val entries = (0 until count).map { i -> field(HighScoreEntryCodec) { it.entries[i] } } + return HighScoreBoardPacket(category, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InGameChallengeResponsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InGameChallengeResponsePacket.kt index 30288ad..e41f2f6 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InGameChallengeResponsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InGameChallengeResponsePacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class InGameChallengeResponsePacket(val accepted: Boolean, val responseText: String) object InGameChallengeResponsePacketCodec : PacketCodec() { - override fun CodecScope.body(): InGameChallengeResponsePacket { - val declined = field(U8) { if (it.accepted) 0 else 1 } - val responseText = field(Utf16LeNullTerminated) { it.responseText } - return InGameChallengeResponsePacket(declined == 0, responseText) - } + override fun CodecScope.body(): InGameChallengeResponsePacket { + val declined = field(U8) { if (it.accepted) 0 else 1 } + val responseText = field(Utf16LeNullTerminated) { it.responseText } + return InGameChallengeResponsePacket(declined == 0, responseText) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InstanceReadyCheckPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InstanceReadyCheckPacket.kt index eaf91f8..6c48ac1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InstanceReadyCheckPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InstanceReadyCheckPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.PacketCodec data class InstanceReadyCheckPacket(val isReady: Boolean) object InstanceReadyCheckPacketCodec : PacketCodec() { - override fun CodecScope.body(): InstanceReadyCheckPacket { - val isReady = field(Bool) { it.isReady } - return InstanceReadyCheckPacket(isReady) - } + override fun CodecScope.body(): InstanceReadyCheckPacket { + val isReady = field(Bool) { it.isReady } + return InstanceReadyCheckPacket(isReady) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractivePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractivePacket.kt index e749469..beaf559 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractivePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractivePacket.kt @@ -13,14 +13,14 @@ data class InteractivePacket( ) object InteractivePacketCodec : PacketCodec() { - override fun CodecScope.body(): InteractivePacket { - val id = field(U8) { it.id } - val type = field(U8) { it.type } - val unk1 = field(S32LE) { it.unk1 } - val unk2 = field(S32LE) { it.unk2 } - val targetEntityId = field(S64LE) { it.targetEntityId } - val unk3 = field(U16LE) { it.unk3 } - val unk4 = field(U16LE) { it.unk4 } - return InteractivePacket(id, type, unk1, unk2, targetEntityId, unk3, unk4) - } + override fun CodecScope.body(): InteractivePacket { + val id = field(U8) { it.id } + val type = field(U8) { it.type } + val unk1 = field(S32LE) { it.unk1 } + val unk2 = field(S32LE) { it.unk2 } + val targetEntityId = field(S64LE) { it.targetEntityId } + val unk3 = field(U16LE) { it.unk3 } + val unk4 = field(U16LE) { it.unk4 } + return InteractivePacket(id, type, unk1, unk2, targetEntityId, unk3, unk4) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractiveResponsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractiveResponsePacket.kt index 11babb9..8467366 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractiveResponsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/InteractiveResponsePacket.kt @@ -7,9 +7,9 @@ import de.fiereu.bytecodec.U8 data class InteractiveResponsePacket(val id: Int, val unk: Int) object InteractiveResponsePacketCodec : PacketCodec() { - override fun CodecScope.body(): InteractiveResponsePacket { - val id = field(U8) { it.id } - val unk = field(U8) { it.unk } - return InteractiveResponsePacket(id, unk) - } + override fun CodecScope.body(): InteractiveResponsePacket { + val id = field(U8) { it.id } + val unk = field(U8) { it.unk } + return InteractiveResponsePacket(id, unk) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinMatchmakingQueuePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinMatchmakingQueuePacket.kt index 9802ef6..a62a99b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinMatchmakingQueuePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinMatchmakingQueuePacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class JoinMatchmakingQueuePacket object JoinMatchmakingQueuePacketCodec : PacketCodec() { - override fun CodecScope.body(): JoinMatchmakingQueuePacket { - return JoinMatchmakingQueuePacket() - } + override fun CodecScope.body(): JoinMatchmakingQueuePacket { + return JoinMatchmakingQueuePacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinPacket.kt index 4c1417d..40208e9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinPacket.kt @@ -11,19 +11,19 @@ sealed class GameAuthenticationData data class ReconnectAuthData(val sessionId: Long, val sessionKey: ByteArray) : GameAuthenticationData() { - override fun equals(other: Any?): Boolean = - other is ReconnectAuthData && - sessionId == other.sessionId && - sessionKey.contentEquals(other.sessionKey) + override fun equals(other: Any?): Boolean = + other is ReconnectAuthData && + sessionId == other.sessionId && + sessionKey.contentEquals(other.sessionKey) - override fun hashCode(): Int = sessionId.hashCode() * 31 + sessionKey.contentHashCode() + override fun hashCode(): Int = sessionId.hashCode() * 31 + sessionKey.contentHashCode() } data class NewAuthData(val userId: Int, val sessionKey: ByteArray) : GameAuthenticationData() { - override fun equals(other: Any?): Boolean = - other is NewAuthData && userId == other.userId && sessionKey.contentEquals(other.sessionKey) + override fun equals(other: Any?): Boolean = + other is NewAuthData && userId == other.userId && sessionKey.contentEquals(other.sessionKey) - override fun hashCode(): Int = userId * 31 + sessionKey.contentHashCode() + override fun hashCode(): Int = userId * 31 + sessionKey.contentHashCode() } data class JoinPacket( @@ -43,70 +43,70 @@ data class JoinPacket( val unk1: ByteArray, val unk2: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is JoinPacket && - authData == other.authData && - mac.contentEquals(other.mac) && - clientRevision == other.clientRevision && - installationRevision == other.installationRevision && - currentChatLanguage == other.currentChatLanguage && - chatLanguages == other.chatLanguages && - matchmakingLanguages == other.matchmakingLanguages && - romMask == other.romMask && - roms == other.roms && - clientInfo == other.clientInfo && - platform == other.platform && - arch == other.arch && - bitness == other.bitness && - unk1.contentEquals(other.unk1) && - unk2.contentEquals(other.unk2) + override fun equals(other: Any?): Boolean = + other is JoinPacket && + authData == other.authData && + mac.contentEquals(other.mac) && + clientRevision == other.clientRevision && + installationRevision == other.installationRevision && + currentChatLanguage == other.currentChatLanguage && + chatLanguages == other.chatLanguages && + matchmakingLanguages == other.matchmakingLanguages && + romMask == other.romMask && + roms == other.roms && + clientInfo == other.clientInfo && + platform == other.platform && + arch == other.arch && + bitness == other.bitness && + unk1.contentEquals(other.unk1) && + unk2.contentEquals(other.unk2) - override fun hashCode(): Int { - var r = authData.hashCode() - r = r * 31 + mac.contentHashCode() - r = r * 31 + clientRevision - r = r * 31 + installationRevision - r = r * 31 + currentChatLanguage - r = r * 31 + chatLanguages - r = r * 31 + matchmakingLanguages - r = r * 31 + romMask - r = r * 31 + roms.hashCode() - r = r * 31 + clientInfo.hashCode() - r = r * 31 + platform.hashCode() - r = r * 31 + arch.hashCode() - r = r * 31 + bitness.hashCode() - r = r * 31 + unk1.contentHashCode() - r = r * 31 + unk2.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = authData.hashCode() + r = r * 31 + mac.contentHashCode() + r = r * 31 + clientRevision + r = r * 31 + installationRevision + r = r * 31 + currentChatLanguage + r = r * 31 + chatLanguages + r = r * 31 + matchmakingLanguages + r = r * 31 + romMask + r = r * 31 + roms.hashCode() + r = r * 31 + clientInfo.hashCode() + r = r * 31 + platform.hashCode() + r = r * 31 + arch.hashCode() + r = r * 31 + bitness.hashCode() + r = r * 31 + unk1.contentHashCode() + r = r * 31 + unk2.contentHashCode() + return r + } } private val SessionKey = bytesPrefixed(U8) private object NewAuthDataCodec : PacketCodec() { - override fun CodecScope.body(): NewAuthData { - val userId = field(S32LE) { it.userId } - val sessionKey = field(SessionKey) { it.sessionKey } - return NewAuthData(userId, sessionKey) - } + override fun CodecScope.body(): NewAuthData { + val userId = field(S32LE) { it.userId } + val sessionKey = field(SessionKey) { it.sessionKey } + return NewAuthData(userId, sessionKey) + } } private object ReconnectAuthDataCodec : PacketCodec() { - override fun CodecScope.body(): ReconnectAuthData { - val sessionId = field(S64LE) { it.sessionId } - val sessionKey = field(SessionKey) { it.sessionKey } - return ReconnectAuthData(sessionId, sessionKey) - } + override fun CodecScope.body(): ReconnectAuthData { + val sessionId = field(S64LE) { it.sessionId } + val sessionKey = field(SessionKey) { it.sessionKey } + return ReconnectAuthData(sessionId, sessionKey) + } } private val AuthDataCodec: Codec = choose( tag = U8, identify = { data -> - when (data) { - is NewAuthData -> 0x00 - is ReconnectAuthData -> 0x01 - } + when (data) { + is NewAuthData -> 0x00 + is ReconnectAuthData -> 0x01 + } }, 0x00 to NewAuthDataCodec, 0x01 to ReconnectAuthDataCodec, @@ -116,14 +116,14 @@ private val PlatformCodec: Codec = U8.imap( decode = { Platform.from(it) }, encode = { p -> - when (p) { - Platform.WINDOWS -> 0x00 - Platform.LINUX -> 0x01 - Platform.MACOS -> 0x02 - Platform.IOS -> 0x03 - Platform.ANDROID -> 0x04 - Platform.UNKNOWN -> 0xFF - } + when (p) { + Platform.WINDOWS -> 0x00 + Platform.LINUX -> 0x01 + Platform.MACOS -> 0x02 + Platform.IOS -> 0x03 + Platform.ANDROID -> 0x04 + Platform.UNKNOWN -> 0xFF + } }, ) @@ -132,12 +132,12 @@ private val BitnessCodec: Codec = enumByOrdinalByte() private val RomInfoCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): RomInfo { - val code = field(Utf16LeNullTerminated) { it.code } - val id = field(S8) { it.id } - val type = field(S8) { it.type } - return RomInfo(code, id, type) - } + override fun CodecScope.body(): RomInfo { + val code = field(Utf16LeNullTerminated) { it.code } + val id = field(S8) { it.id } + val type = field(S8) { it.type } + return RomInfo(code, id, type) + } } private val ClientInfoEntryCodec: Codec> = S8.then(Utf16LeNullTerminated) @@ -151,38 +151,38 @@ private val Unk1Bytes = bytesPrefixed(U8) private val Unk2Bytes = fixedBytes(32) object JoinPacketCodec : PacketCodec() { - override fun CodecScope.body(): JoinPacket { - val authData = field(AuthDataCodec) { it.authData } - val mac = field(MacBytes) { it.mac } - val clientRevision = field(S32LE) { it.clientRevision } - val installationRevision = field(S32LE) { it.installationRevision } - val currentChatLanguage = field(S8) { it.currentChatLanguage } - val chatLanguages = field(S16LE) { it.chatLanguages } - val matchmakingLanguages = field(S16LE) { it.matchmakingLanguages } - val romMask = field(S8) { it.romMask } - val roms = field(RomInfoCodec.listPrefixed(U8)) { it.roms } - val clientInfo = field(ClientInfoMapCodec) { it.clientInfo } - val platform = field(PlatformCodec) { it.platform } - val arch = field(ArchCodec) { it.arch } - val bitness = field(BitnessCodec) { it.bitness } - val unk1 = field(Unk1Bytes) { it.unk1 } - val unk2 = field(Unk2Bytes) { it.unk2 } - return JoinPacket( - authData = authData, - mac = mac, - clientRevision = clientRevision, - installationRevision = installationRevision, - currentChatLanguage = currentChatLanguage, - chatLanguages = chatLanguages, - matchmakingLanguages = matchmakingLanguages, - romMask = romMask, - roms = roms, - clientInfo = clientInfo, - platform = platform, - arch = arch, - bitness = bitness, - unk1 = unk1, - unk2 = unk2, - ) - } + override fun CodecScope.body(): JoinPacket { + val authData = field(AuthDataCodec) { it.authData } + val mac = field(MacBytes) { it.mac } + val clientRevision = field(S32LE) { it.clientRevision } + val installationRevision = field(S32LE) { it.installationRevision } + val currentChatLanguage = field(S8) { it.currentChatLanguage } + val chatLanguages = field(S16LE) { it.chatLanguages } + val matchmakingLanguages = field(S16LE) { it.matchmakingLanguages } + val romMask = field(S8) { it.romMask } + val roms = field(RomInfoCodec.listPrefixed(U8)) { it.roms } + val clientInfo = field(ClientInfoMapCodec) { it.clientInfo } + val platform = field(PlatformCodec) { it.platform } + val arch = field(ArchCodec) { it.arch } + val bitness = field(BitnessCodec) { it.bitness } + val unk1 = field(Unk1Bytes) { it.unk1 } + val unk2 = field(Unk2Bytes) { it.unk2 } + return JoinPacket( + authData = authData, + mac = mac, + clientRevision = clientRevision, + installationRevision = installationRevision, + currentChatLanguage = currentChatLanguage, + chatLanguages = chatLanguages, + matchmakingLanguages = matchmakingLanguages, + romMask = romMask, + roms = roms, + clientInfo = clientInfo, + platform = platform, + arch = arch, + bitness = bitness, + unk1 = unk1, + unk2 = unk2, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinResponsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinResponsePacket.kt index bb0c5e8..5ba5eb1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinResponsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/JoinResponsePacket.kt @@ -9,26 +9,26 @@ data class JoinResponsePacket( val stats: GameStats? = null, val time: TimeInfo? = null, ) { - data class GameStats(val playtime: Int, val rewardPoints: Int, val balance: Int) + data class GameStats(val playtime: Int, val rewardPoints: Int, val balance: Int) - data class TimeInfo(val serverDayStartSecond: Int, val serverCurrentSecond: Int) + data class TimeInfo(val serverDayStartSecond: Int, val serverCurrentSecond: Int) - companion object { - fun reject(): JoinResponsePacket = JoinResponsePacket(false) + companion object { + fun reject(): JoinResponsePacket = JoinResponsePacket(false) - fun accept(stats: GameStats, time: TimeInfo? = null): JoinResponsePacket = - JoinResponsePacket(true, stats, time) + fun accept(stats: GameStats, time: TimeInfo? = null): JoinResponsePacket = + JoinResponsePacket(true, stats, time) - fun acceptNow(playtime: Int, rewardPoints: Int, balance: Int): JoinResponsePacket { - val dayStart = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toEpochSecond().toInt() - val now = (System.currentTimeMillis() / 1000).toInt() - return JoinResponsePacket( - canJoin = true, - stats = GameStats(playtime, rewardPoints, balance), - time = TimeInfo(dayStart, now), - ) - } + fun acceptNow(playtime: Int, rewardPoints: Int, balance: Int): JoinResponsePacket { + val dayStart = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toEpochSecond().toInt() + val now = (System.currentTimeMillis() / 1000).toInt() + return JoinResponsePacket( + canJoin = true, + stats = GameStats(playtime, rewardPoints, balance), + time = TimeInfo(dayStart, now), + ) } + } } private fun nowTimeInfo(): JoinResponsePacket.TimeInfo = @@ -39,31 +39,31 @@ private fun nowTimeInfo(): JoinResponsePacket.TimeInfo = ) object JoinResponsePacketCodec : PacketCodec() { - override fun CodecScope.body(): JoinResponsePacket { - val canJoin = field(Bool, JoinResponsePacket::canJoin) - if (!canJoin) return JoinResponsePacket(false) - field(Utf16LeNullTerminated) { "" } - field(S8) { 0 } - val playtime = - field(S32LE) { - (it.stats - ?: throw MalformedPacketException("stats must be provided when canJoin is true")) - .playtime - } - val rewardPoints = field(S32LE) { it.stats!!.rewardPoints } - val balance = field(S32LE) { it.stats!!.balance } - var resolvedTime: JoinResponsePacket.TimeInfo? = null - val dayStart = - field(S32LE) { - val t = it.time ?: nowTimeInfo() - resolvedTime = t - t.serverDayStartSecond - } - val now = field(S32LE) { resolvedTime!!.serverCurrentSecond } - return JoinResponsePacket( - canJoin = true, - stats = JoinResponsePacket.GameStats(playtime, rewardPoints, balance), - time = JoinResponsePacket.TimeInfo(dayStart, now), - ) - } + override fun CodecScope.body(): JoinResponsePacket { + val canJoin = field(Bool, JoinResponsePacket::canJoin) + if (!canJoin) return JoinResponsePacket(false) + field(Utf16LeNullTerminated) { "" } + field(S8) { 0 } + val playtime = + field(S32LE) { + (it.stats + ?: throw MalformedPacketException("stats must be provided when canJoin is true")) + .playtime + } + val rewardPoints = field(S32LE) { it.stats!!.rewardPoints } + val balance = field(S32LE) { it.stats!!.balance } + var resolvedTime: JoinResponsePacket.TimeInfo? = null + val dayStart = + field(S32LE) { + val t = it.time ?: nowTimeInfo() + resolvedTime = t + t.serverDayStartSecond + } + val now = field(S32LE) { resolvedTime!!.serverCurrentSecond } + return JoinResponsePacket( + canJoin = true, + stats = JoinResponsePacket.GameStats(playtime, rewardPoints, balance), + time = JoinResponsePacket.TimeInfo(dayStart, now), + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/KeepAlivePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/KeepAlivePacket.kt index eeae76a..783bac6 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/KeepAlivePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/KeepAlivePacket.kt @@ -3,31 +3,31 @@ package de.fiereu.openmmo.net.game.packets import de.fiereu.bytecodec.* data class KeepAlivePacket(val canJoin: Boolean, val sessionData: ByteArray) { - override fun equals(other: Any?): Boolean = - other is KeepAlivePacket && - canJoin == other.canJoin && - sessionData.contentEquals(other.sessionData) + override fun equals(other: Any?): Boolean = + other is KeepAlivePacket && + canJoin == other.canJoin && + sessionData.contentEquals(other.sessionData) - override fun hashCode(): Int = canJoin.hashCode() * 31 + sessionData.contentHashCode() + override fun hashCode(): Int = canJoin.hashCode() * 31 + sessionData.contentHashCode() } private val KeepAliveSessionDataBytes: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object KeepAlivePacketCodec : PacketCodec() { - override fun CodecScope.body() = - KeepAlivePacket( - canJoin = field(Bool, KeepAlivePacket::canJoin), - sessionData = field(KeepAliveSessionDataBytes, KeepAlivePacket::sessionData), - ) + override fun CodecScope.body() = + KeepAlivePacket( + canJoin = field(Bool, KeepAlivePacket::canJoin), + sessionData = field(KeepAliveSessionDataBytes, KeepAlivePacket::sessionData), + ) } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaderboardViewRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaderboardViewRequestPacket.kt index 8c7d52a..0386d61 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaderboardViewRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaderboardViewRequestPacket.kt @@ -9,8 +9,8 @@ data class LeaderboardViewRequestPacket( ) object LeaderboardViewRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): LeaderboardViewRequestPacket { - val categoryId = field(S8) { it.categoryId } - return LeaderboardViewRequestPacket(categoryId) - } + override fun CodecScope.body(): LeaderboardViewRequestPacket { + val categoryId = field(S8) { it.categoryId } + return LeaderboardViewRequestPacket(categoryId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LearnedMovesetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LearnedMovesetPacket.kt index 3f6cc57..cc2475a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LearnedMovesetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LearnedMovesetPacket.kt @@ -22,45 +22,45 @@ data class LearnedMovesetPacket( ) private object LearnedMoveAppearanceCodec : PacketCodec() { - override fun CodecScope.body(): LearnedMoveAppearance { - val name = field(Utf16LeNullTerminated, LearnedMoveAppearance::name) - val gender = field(S8, LearnedMoveAppearance::gender) - val formId = field(S32LE, LearnedMoveAppearance::formId) - val kind = field(S8, LearnedMoveAppearance::kind) - val palettePack = field(S8, LearnedMoveAppearance::palettePack) - val slots = field(S16LE.repeat(4), LearnedMoveAppearance::slots) - return LearnedMoveAppearance(name, gender, formId, kind, palettePack, slots) - } + override fun CodecScope.body(): LearnedMoveAppearance { + val name = field(Utf16LeNullTerminated, LearnedMoveAppearance::name) + val gender = field(S8, LearnedMoveAppearance::gender) + val formId = field(S32LE, LearnedMoveAppearance::formId) + val kind = field(S8, LearnedMoveAppearance::kind) + val palettePack = field(S8, LearnedMoveAppearance::palettePack) + val slots = field(S16LE.repeat(4), LearnedMoveAppearance::slots) + return LearnedMoveAppearance(name, gender, formId, kind, palettePack, slots) + } } private object LearnedMoveSlotCodec : PacketCodec() { - override fun CodecScope.body(): LearnedMoveSlot { - val moveId = field(S16LE, LearnedMoveSlot::moveId) - if (moveId < 0) { - return LearnedMoveSlot(moveId, null, null) - } - val sourceId = field(S64LE) { it.sourceId!! } - val appearance = field(LearnedMoveAppearanceCodec) { it.appearance!! } - return LearnedMoveSlot(moveId, sourceId, appearance) + override fun CodecScope.body(): LearnedMoveSlot { + val moveId = field(S16LE, LearnedMoveSlot::moveId) + if (moveId < 0) { + return LearnedMoveSlot(moveId, null, null) } + val sourceId = field(S64LE) { it.sourceId!! } + val appearance = field(LearnedMoveAppearanceCodec) { it.appearance!! } + return LearnedMoveSlot(moveId, sourceId, appearance) + } } private val LearnedMoveSlotListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { LearnedMoveSlotCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { LearnedMoveSlotCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { LearnedMoveSlotCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { LearnedMoveSlotCodec.write(buf, it) } + } } object LearnedMovesetPacketCodec : PacketCodec() { - override fun CodecScope.body(): LearnedMovesetPacket { - val moves = field(LearnedMoveSlotListPrefixedU8, LearnedMovesetPacket::moves) - return LearnedMovesetPacket(moves) - } + override fun CodecScope.body(): LearnedMovesetPacket { + val moves = field(LearnedMoveSlotListPrefixedU8, LearnedMovesetPacket::moves) + return LearnedMovesetPacket(moves) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveBattlePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveBattlePacket.kt index 9218643..cb688ae 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveBattlePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveBattlePacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class LeaveBattlePacket object LeaveBattlePacketCodec : PacketCodec() { - override fun CodecScope.body(): LeaveBattlePacket { - return LeaveBattlePacket() - } + override fun CodecScope.body(): LeaveBattlePacket { + return LeaveBattlePacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveChatChannelPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveChatChannelPacket.kt index dad660c..fbb4099 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveChatChannelPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveChatChannelPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class LeaveChatChannelPacket object LeaveChatChannelPacketCodec : PacketCodec() { - override fun CodecScope.body(): LeaveChatChannelPacket { - return LeaveChatChannelPacket() - } + override fun CodecScope.body(): LeaveChatChannelPacket { + return LeaveChatChannelPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveMatchmakingQueuePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveMatchmakingQueuePacket.kt index fc6648e..4ef05ac 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveMatchmakingQueuePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LeaveMatchmakingQueuePacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class LeaveMatchmakingQueuePacket object LeaveMatchmakingQueuePacketCodec : PacketCodec() { - override fun CodecScope.body(): LeaveMatchmakingQueuePacket { - return LeaveMatchmakingQueuePacket() - } + override fun CodecScope.body(): LeaveMatchmakingQueuePacket { + return LeaveMatchmakingQueuePacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LinkKickMemberPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LinkKickMemberPacket.kt index 745e366..e3e362a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LinkKickMemberPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LinkKickMemberPacket.kt @@ -9,8 +9,8 @@ data class LinkKickMemberPacket( ) object LinkKickMemberPacketCodec : PacketCodec() { - override fun CodecScope.body(): LinkKickMemberPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - return LinkKickMemberPacket(targetEntityId) - } + override fun CodecScope.body(): LinkKickMemberPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + return LinkKickMemberPacket(targetEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ListWindowPagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ListWindowPagePacket.kt index a6525fa..d16dc58 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ListWindowPagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ListWindowPagePacket.kt @@ -25,30 +25,28 @@ data class ListWindowPagePacket( private val ListWindowRowCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ListWindowRow { - val rowType = field(S8) { it.rowType } - val valueA = field(S16LE) { it.valueA } - val valueB = field(S16LE) { it.valueB } - val valueC = field(S16LE) { it.valueC } - val valueD = field(S16LE) { it.valueD } - val valueE = field(S16LE) { it.valueE } - val label = field(Utf16LeNullTerminated) { it.label } - val valueF = field(S16LE) { it.valueF } - return ListWindowRow(rowType, valueA, valueB, valueC, valueD, valueE, label, valueF) - } + override fun CodecScope.body(): ListWindowRow { + val rowType = field(S8) { it.rowType } + val valueA = field(S16LE) { it.valueA } + val valueB = field(S16LE) { it.valueB } + val valueC = field(S16LE) { it.valueC } + val valueD = field(S16LE) { it.valueD } + val valueE = field(S16LE) { it.valueE } + val label = field(Utf16LeNullTerminated) { it.label } + val valueF = field(S16LE) { it.valueF } + return ListWindowRow(rowType, valueA, valueB, valueC, valueD, valueE, label, valueF) + } } object ListWindowPagePacketCodec : PacketCodec() { - override fun CodecScope.body(): ListWindowPagePacket { - val windowId = field(S32LE) { it.windowId } - val firstPage = field(U8) { if (it.firstPage) 1 else 0 } == 1 - val lastPage = field(U8) { if (it.lastPage) 1 else 0 } == 1 - val headerA = field(S8) { it.headerA } - val headerB = field(S8) { it.headerB } - val headerC = field(S8) { it.headerC } - val rows = field(ListWindowRowCodec.listPrefixed(U16LE)) { it.rows } - return ListWindowPagePacket( - windowId, firstPage, lastPage, headerA, headerB, headerC, rows - ) - } + override fun CodecScope.body(): ListWindowPagePacket { + val windowId = field(S32LE) { it.windowId } + val firstPage = field(U8) { if (it.firstPage) 1 else 0 } == 1 + val lastPage = field(U8) { if (it.lastPage) 1 else 0 } == 1 + val headerA = field(S8) { it.headerA } + val headerB = field(S8) { it.headerB } + val headerC = field(S8) { it.headerC } + val rows = field(ListWindowRowCodec.listPrefixed(U16LE)) { it.rows } + return ListWindowPagePacket(windowId, firstPage, lastPage, headerA, headerB, headerC, rows) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadEntityPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadEntityPacket.kt index 4750d22..32733d3 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadEntityPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadEntityPacket.kt @@ -25,49 +25,49 @@ data class LoadEntityPacket( ) object LoadEntityPacketCodec : PacketCodec() { - override fun CodecScope.body(): LoadEntityPacket { - val entityId = field(S64LE, LoadEntityPacket::entityId) - reserved(byte = 0) - val skin = field(DefaultSkinSetCodec, LoadEntityPacket::skin) - val name = field(Utf16LeNullTerminated, LoadEntityPacket::name) - val regionId = field(U8, LoadEntityPacket::regionId) - val bankId = field(U8, LoadEntityPacket::bankId) - val mapId = field(U8, LoadEntityPacket::mapId) - val x = field(S16LE) { it.x.toShort() }.toInt() - val y = field(S16LE) { it.y.toShort() }.toInt() - val z = field(U8, LoadEntityPacket::z) - val facing = Direction.entries[field(U8) { it.facing.ordinal }] - val transportation = field(U8, LoadEntityPacket::transportation) - val entityNameplateType = field(U8, LoadEntityPacket::entityNameplateType) - val flags = field(U16LE) { if (it.hasFollower) 0x04 else 0 } - if (flags and 0x01 != 0) field(S8) { 0 } - if (flags and 0x02 != 0) { - field(S8) { 0 } - field(U16LE) { 0 } - } - val hasFollower = (flags and 0x04) != 0 - val followerDexId: Short = if (hasFollower) field(S16LE, LoadEntityPacket::followerDexId) else 0 - if (flags and 0x08 != 0) field(S8) { 0 } - if (flags and 0x10 != 0) { - field(S32LE) { 0 } - field(Utf16LeNullTerminated) { "" } - } - return LoadEntityPacket( - entityId = entityId, - skin = skin, - name = name, - regionId = regionId, - bankId = bankId, - mapId = mapId, - x = x, - y = y, - z = z, - facing = facing, - transportation = transportation, - entityNameplateType = entityNameplateType, - status = EntityStatus.NONE, - hasFollower = hasFollower, - followerDexId = followerDexId, - ) + override fun CodecScope.body(): LoadEntityPacket { + val entityId = field(S64LE, LoadEntityPacket::entityId) + reserved(byte = 0) + val skin = field(DefaultSkinSetCodec, LoadEntityPacket::skin) + val name = field(Utf16LeNullTerminated, LoadEntityPacket::name) + val regionId = field(U8, LoadEntityPacket::regionId) + val bankId = field(U8, LoadEntityPacket::bankId) + val mapId = field(U8, LoadEntityPacket::mapId) + val x = field(S16LE) { it.x.toShort() }.toInt() + val y = field(S16LE) { it.y.toShort() }.toInt() + val z = field(U8, LoadEntityPacket::z) + val facing = Direction.entries[field(U8) { it.facing.ordinal }] + val transportation = field(U8, LoadEntityPacket::transportation) + val entityNameplateType = field(U8, LoadEntityPacket::entityNameplateType) + val flags = field(U16LE) { if (it.hasFollower) 0x04 else 0 } + if (flags and 0x01 != 0) field(S8) { 0 } + if (flags and 0x02 != 0) { + field(S8) { 0 } + field(U16LE) { 0 } } + val hasFollower = (flags and 0x04) != 0 + val followerDexId: Short = if (hasFollower) field(S16LE, LoadEntityPacket::followerDexId) else 0 + if (flags and 0x08 != 0) field(S8) { 0 } + if (flags and 0x10 != 0) { + field(S32LE) { 0 } + field(Utf16LeNullTerminated) { "" } + } + return LoadEntityPacket( + entityId = entityId, + skin = skin, + name = name, + regionId = regionId, + bankId = bankId, + mapId = mapId, + x = x, + y = y, + z = z, + facing = facing, + transportation = transportation, + entityNameplateType = entityNameplateType, + status = EntityStatus.NONE, + hasFollower = hasFollower, + followerDexId = followerDexId, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadMapPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadMapPacket.kt index a508125..e4be530 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadMapPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LoadMapPacket.kt @@ -11,39 +11,39 @@ import de.fiereu.openmmo.common.utils.isNdsRegion import de.fiereu.openmmo.net.game.codecs.Tile2DCodec sealed interface MapData { - data class NdsMapData(val lighting: Lighting, val weather: Weather, val mapType: MapType) : - MapData + data class NdsMapData(val lighting: Lighting, val weather: Weather, val mapType: MapType) : + MapData - data class GbaConnection( - val direction: Int, - val unknown: Int, - val targetBank: Int, - val targetMap: Int, - ) + data class GbaConnection( + val direction: Int, + val unknown: Int, + val targetBank: Int, + val targetMap: Int, + ) - data class GbaMapData( - val width: Int, - val height: Int, - val paletteIdx1: Int, - val paletteIdx2: Int, - val borderWidth: Int, - val borderHeight: Int, - val unknownShort: Int = 0, - val unknownByte: Int = 0, - val borderTiles: List, - val lighting: Lighting, - val weather: Weather, - val mapType: MapType, - val encounterType: EncounterType, - val connections: List = emptyList(), - ) : MapData { - init { - require(borderWidth * borderHeight == borderTiles.size) { - "borderTiles size doesnt match dimensions" - } - require(borderWidth * borderHeight > 0) { "BorderWidth & Height must be greater than zero" } - } + data class GbaMapData( + val width: Int, + val height: Int, + val paletteIdx1: Int, + val paletteIdx2: Int, + val borderWidth: Int, + val borderHeight: Int, + val unknownShort: Int = 0, + val unknownByte: Int = 0, + val borderTiles: List, + val lighting: Lighting, + val weather: Weather, + val mapType: MapType, + val encounterType: EncounterType, + val connections: List = emptyList(), + ) : MapData { + init { + require(borderWidth * borderHeight == borderTiles.size) { + "borderTiles size doesnt match dimensions" + } + require(borderWidth * borderHeight > 0) { "BorderWidth & Height must be greater than zero" } } + } } data class LoadMapPacket( @@ -54,126 +54,126 @@ data class LoadMapPacket( val mapId: Int, val mapData: MapData, ) { - init { - when (mapData) { - is MapData.NdsMapData -> require(isNdsRegion(regionId)) { "MapData is invalid" } - is MapData.GbaMapData -> require(!isNdsRegion(regionId)) { "MapData is invalid" } - } + init { + when (mapData) { + is MapData.NdsMapData -> require(isNdsRegion(regionId)) { "MapData is invalid" } + is MapData.GbaMapData -> require(!isNdsRegion(regionId)) { "MapData is invalid" } } + } } private object GbaConnectionCodec : PacketCodec() { - override fun CodecScope.body() = - MapData.GbaConnection( - direction = field(U8, MapData.GbaConnection::direction), - unknown = field(S32LE, MapData.GbaConnection::unknown), - targetBank = field(U8, MapData.GbaConnection::targetBank), - targetMap = field(U8, MapData.GbaConnection::targetMap), - ) + override fun CodecScope.body() = + MapData.GbaConnection( + direction = field(U8, MapData.GbaConnection::direction), + unknown = field(S32LE, MapData.GbaConnection::unknown), + targetBank = field(U8, MapData.GbaConnection::targetBank), + targetMap = field(U8, MapData.GbaConnection::targetMap), + ) } private val GbaConnectionListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { GbaConnectionCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { GbaConnectionCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { GbaConnectionCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { GbaConnectionCodec.write(buf, it) } + } } object LoadMapPacketCodec : PacketCodec() { - override fun CodecScope.body(): LoadMapPacket { - val flags = - field(U8) { - var f = 0 - if (it.deleteCache) f = f or 1 - if (it.reloadPlayer) f = f or 2 - f - } - val deleteCache = (flags and 1) != 0 - val reloadPlayer = (flags and 2) != 0 - val regionId = field(U8, LoadMapPacket::regionId) - val bankId = field(U8, LoadMapPacket::bankId) - val mapId = field(U8, LoadMapPacket::mapId) - field(S8) { 0 } - val mapData: MapData = - if (isNdsRegion(regionId)) { - field(S16LE) { 0 } - field(U8) { 0 } - val lighting = - Lighting.entries[field(U8) { (it.mapData as MapData.NdsMapData).lighting.ordinal }] - val weather = - Weather.entries[field(U8) { (it.mapData as MapData.NdsMapData).weather.ordinal }] - val mapType = - MapType.entries[field(U8) { (it.mapData as MapData.NdsMapData).mapType.ordinal }] - MapData.NdsMapData(lighting, weather, mapType) - } else { - val getGba: (LoadMapPacket) -> MapData.GbaMapData = { - it.mapData as? MapData.GbaMapData - ?: throw MalformedPacketException("expected GbaMapData for region $regionId") - } - val width = field(S32LE) { getGba(it).width } - val height = field(S32LE) { getGba(it).height } - val paletteIdx1 = field(S32LE) { getGba(it).paletteIdx1 } - val paletteIdx2 = field(S32LE) { getGba(it).paletteIdx2 } - val borderWidth = field(U8) { getGba(it).borderWidth } - val borderHeight = field(U8) { getGba(it).borderHeight } - val unknownShort = field(S16LE) { getGba(it).unknownShort.toShort() }.toInt() - val unknownByte = field(U8) { getGba(it).unknownByte } - val lighting = Lighting.entries[field(U8) { getGba(it).lighting.ordinal }] - val weather = Weather.entries[field(U8) { getGba(it).weather.ordinal }] - val mapType = MapType.entries[field(U8) { getGba(it).mapType.ordinal }] - val encounterType = EncounterType.entries[field(U8) { getGba(it).encounterType.ordinal }] - val borderTiles = - List(borderWidth * borderHeight) { - field(Tile2DCodec) { entry -> getGba(entry).borderTiles[it] } - } - val hasCompressed = field(Bool) { false } - if (hasCompressed) { - val size = field(S32LE) { 0 } - val compressed = field(FixedReadBytes(size)) { ByteArray(0) } - compressed.gzipDecompress() - } - val connections = field(GbaConnectionListPrefixedU8) { getGba(it).connections } - val hasTrailer = field(Bool) { false } - if (hasTrailer) { - field(S64LE) { 0L } - field(Utf16LeNullTerminated) { "" } - } - MapData.GbaMapData( - width = width, - height = height, - paletteIdx1 = paletteIdx1, - paletteIdx2 = paletteIdx2, - borderWidth = borderWidth, - borderHeight = borderHeight, - unknownShort = unknownShort, - unknownByte = unknownByte, - borderTiles = borderTiles, - lighting = lighting, - weather = weather, - mapType = mapType, - encounterType = encounterType, - connections = connections, - ) - } - return LoadMapPacket(reloadPlayer, deleteCache, regionId, bankId, mapId, mapData) - } + override fun CodecScope.body(): LoadMapPacket { + val flags = + field(U8) { + var f = 0 + if (it.deleteCache) f = f or 1 + if (it.reloadPlayer) f = f or 2 + f + } + val deleteCache = (flags and 1) != 0 + val reloadPlayer = (flags and 2) != 0 + val regionId = field(U8, LoadMapPacket::regionId) + val bankId = field(U8, LoadMapPacket::bankId) + val mapId = field(U8, LoadMapPacket::mapId) + field(S8) { 0 } + val mapData: MapData = + if (isNdsRegion(regionId)) { + field(S16LE) { 0 } + field(U8) { 0 } + val lighting = + Lighting.entries[field(U8) { (it.mapData as MapData.NdsMapData).lighting.ordinal }] + val weather = + Weather.entries[field(U8) { (it.mapData as MapData.NdsMapData).weather.ordinal }] + val mapType = + MapType.entries[field(U8) { (it.mapData as MapData.NdsMapData).mapType.ordinal }] + MapData.NdsMapData(lighting, weather, mapType) + } else { + val getGba: (LoadMapPacket) -> MapData.GbaMapData = { + it.mapData as? MapData.GbaMapData + ?: throw MalformedPacketException("expected GbaMapData for region $regionId") + } + val width = field(S32LE) { getGba(it).width } + val height = field(S32LE) { getGba(it).height } + val paletteIdx1 = field(S32LE) { getGba(it).paletteIdx1 } + val paletteIdx2 = field(S32LE) { getGba(it).paletteIdx2 } + val borderWidth = field(U8) { getGba(it).borderWidth } + val borderHeight = field(U8) { getGba(it).borderHeight } + val unknownShort = field(S16LE) { getGba(it).unknownShort.toShort() }.toInt() + val unknownByte = field(U8) { getGba(it).unknownByte } + val lighting = Lighting.entries[field(U8) { getGba(it).lighting.ordinal }] + val weather = Weather.entries[field(U8) { getGba(it).weather.ordinal }] + val mapType = MapType.entries[field(U8) { getGba(it).mapType.ordinal }] + val encounterType = EncounterType.entries[field(U8) { getGba(it).encounterType.ordinal }] + val borderTiles = + List(borderWidth * borderHeight) { + field(Tile2DCodec) { entry -> getGba(entry).borderTiles[it] } + } + val hasCompressed = field(Bool) { false } + if (hasCompressed) { + val size = field(S32LE) { 0 } + val compressed = field(FixedReadBytes(size)) { ByteArray(0) } + compressed.gzipDecompress() + } + val connections = field(GbaConnectionListPrefixedU8) { getGba(it).connections } + val hasTrailer = field(Bool) { false } + if (hasTrailer) { + field(S64LE) { 0L } + field(Utf16LeNullTerminated) { "" } + } + MapData.GbaMapData( + width = width, + height = height, + paletteIdx1 = paletteIdx1, + paletteIdx2 = paletteIdx2, + borderWidth = borderWidth, + borderHeight = borderHeight, + unknownShort = unknownShort, + unknownByte = unknownByte, + borderTiles = borderTiles, + lighting = lighting, + weather = weather, + mapType = mapType, + encounterType = encounterType, + connections = connections, + ) + } + return LoadMapPacket(reloadPlayer, deleteCache, regionId, bankId, mapId, mapData) + } } private fun FixedReadBytes(n: Int): Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val arr = ByteArray(n) - if (n > 0) buf.readBytes(arr) - return arr - } + override fun read(buf: ReadBuffer): ByteArray { + val arr = ByteArray(n) + if (n > 0) buf.readBytes(arr) + return arr + } - override fun write(buf: WriteBuffer, value: ByteArray) { - error("FixedReadBytes is read-only") - } + override fun write(buf: WriteBuffer, value: ByteArray) { + error("FixedReadBytes is read-only") + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalCharacterDeltaPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalCharacterDeltaPacket.kt index ec879e5..bf58527 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalCharacterDeltaPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalCharacterDeltaPacket.kt @@ -22,55 +22,56 @@ data class LocalCharacterDeltaPacket( ) object LocalCharacterDeltaPacketCodec : PacketCodec() { - override fun CodecScope.body(): LocalCharacterDeltaPacket { - val mask = field(S16LE) { it.mask } - val m = mask.toInt() - val money = if (m and 1 != 0) field(S32LE) { it.money!! } else null - val mapId = if (m and 2 != 0) field(S16LE) { it.mapId!! } else null - val mapFlag = if (m and 2 != 0) field(S8) { it.mapFlag!! } else null - val value4 = if (m and 4 != 0) field(S16LE) { it.value4!! } else null - val value8a = if (m and 8 != 0) field(S8) { it.value8a!! } else null - val value8b = if (m and 8 != 0) field(S8) { it.value8b!! } else null - val value8c = if (m and 8 != 0) field(S8) { it.value8c!! } else null - val value16a = if (m and 16 != 0) field(S16LE) { it.value16a!! } else null - val value16b = if (m and 16 != 0) field(S16LE) { it.value16b!! } else null - val value32 = if (m and 32 != 0) field(S32LE) { it.value32!! } else null - val value64Enum: Byte? - val value64a: Short? - val value64b: Short? - if (m and 64 != 0) { - value64Enum = field(S8) { it.value64Enum!! } - if (value64Enum.toInt() != 0) { - value64a = field(S16LE) { it.value64a!! } - value64b = field(S16LE) { it.value64b!! } - } else { - value64a = null - value64b = null - } - } else { - value64Enum = null - value64a = null - value64b = null - } - val statusConditions = if (m and 128 != 0) field(S8.listPrefixed(U8)) { it.statusConditions!! } else null - val value256 = if (m and 256 != 0) field(S8) { it.value256!! } else null - return LocalCharacterDeltaPacket( - mask = mask, - money = money, - mapId = mapId, - mapFlag = mapFlag, - value4 = value4, - value8a = value8a, - value8b = value8b, - value8c = value8c, - value16a = value16a, - value16b = value16b, - value32 = value32, - value64Enum = value64Enum, - value64a = value64a, - value64b = value64b, - statusConditions = statusConditions, - value256 = value256, - ) + override fun CodecScope.body(): LocalCharacterDeltaPacket { + val mask = field(S16LE) { it.mask } + val m = mask.toInt() + val money = if (m and 1 != 0) field(S32LE) { it.money!! } else null + val mapId = if (m and 2 != 0) field(S16LE) { it.mapId!! } else null + val mapFlag = if (m and 2 != 0) field(S8) { it.mapFlag!! } else null + val value4 = if (m and 4 != 0) field(S16LE) { it.value4!! } else null + val value8a = if (m and 8 != 0) field(S8) { it.value8a!! } else null + val value8b = if (m and 8 != 0) field(S8) { it.value8b!! } else null + val value8c = if (m and 8 != 0) field(S8) { it.value8c!! } else null + val value16a = if (m and 16 != 0) field(S16LE) { it.value16a!! } else null + val value16b = if (m and 16 != 0) field(S16LE) { it.value16b!! } else null + val value32 = if (m and 32 != 0) field(S32LE) { it.value32!! } else null + val value64Enum: Byte? + val value64a: Short? + val value64b: Short? + if (m and 64 != 0) { + value64Enum = field(S8) { it.value64Enum!! } + if (value64Enum.toInt() != 0) { + value64a = field(S16LE) { it.value64a!! } + value64b = field(S16LE) { it.value64b!! } + } else { + value64a = null + value64b = null + } + } else { + value64Enum = null + value64a = null + value64b = null } + val statusConditions = + if (m and 128 != 0) field(S8.listPrefixed(U8)) { it.statusConditions!! } else null + val value256 = if (m and 256 != 0) field(S8) { it.value256!! } else null + return LocalCharacterDeltaPacket( + mask = mask, + money = money, + mapId = mapId, + mapFlag = mapFlag, + value4 = value4, + value8a = value8a, + value8b = value8b, + value8c = value8c, + value16a = value16a, + value16b = value16b, + value32 = value32, + value64Enum = value64Enum, + value64a = value64a, + value64b = value64b, + statusConditions = statusConditions, + value256 = value256, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalPlayerStatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalPlayerStatePacket.kt index 43617c2..3fc1e20 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalPlayerStatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/LocalPlayerStatePacket.kt @@ -30,52 +30,52 @@ data class LocalPlayerStatePacket( private val PlayerVariableEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): PlayerVariableEntry { - val key = field(S8) { it.key } - val value = field(S16LE) { it.value } - return PlayerVariableEntry(key, value) - } + override fun CodecScope.body(): PlayerVariableEntry { + val key = field(S8) { it.key } + val value = field(S16LE) { it.value } + return PlayerVariableEntry(key, value) + } } object LocalPlayerStatePacketCodec : PacketCodec() { - override fun CodecScope.body(): LocalPlayerStatePacket { - val region = field(S8) { it.region } - val mapId = field(S16LE) { it.mapId } - val moveSpeed = field(F32LE) { it.moveSpeed } - val x = field(S16LE) { it.x } - val y = field(S16LE) { it.y } - val z = field(S16LE) { it.z } - val money = field(S32LE) { it.money } - val gender = field(S8) { it.gender } - val skinTone = field(S16LE) { it.skinTone } - val hairColor = field(S16LE) { it.hairColor } - val playtime = field(F64LE) { it.playtime } - val flags = field(S8) { it.flags } - val partyDex = field(S16LE.listPrefixed(U16LE)) { it.partyDex } - val partyForms = field(S8.listPrefixed(U8)) { it.partyForms } - val pokedexSeen = field(S16LE.listPrefixed(U16LE)) { it.pokedexSeen } - val pokedexCaught = field(S16LE.listPrefixed(U16LE)) { it.pokedexCaught } - val badges = field(S16LE.listPrefixed(U8)) { it.badges } - val variables = field(PlayerVariableEntryCodec.listPrefixed(U16LE)) { it.variables } - return LocalPlayerStatePacket( - region, - mapId, - moveSpeed, - x, - y, - z, - money, - gender, - skinTone, - hairColor, - playtime, - flags, - partyDex, - partyForms, - pokedexSeen, - pokedexCaught, - badges, - variables, - ) - } + override fun CodecScope.body(): LocalPlayerStatePacket { + val region = field(S8) { it.region } + val mapId = field(S16LE) { it.mapId } + val moveSpeed = field(F32LE) { it.moveSpeed } + val x = field(S16LE) { it.x } + val y = field(S16LE) { it.y } + val z = field(S16LE) { it.z } + val money = field(S32LE) { it.money } + val gender = field(S8) { it.gender } + val skinTone = field(S16LE) { it.skinTone } + val hairColor = field(S16LE) { it.hairColor } + val playtime = field(F64LE) { it.playtime } + val flags = field(S8) { it.flags } + val partyDex = field(S16LE.listPrefixed(U16LE)) { it.partyDex } + val partyForms = field(S8.listPrefixed(U8)) { it.partyForms } + val pokedexSeen = field(S16LE.listPrefixed(U16LE)) { it.pokedexSeen } + val pokedexCaught = field(S16LE.listPrefixed(U16LE)) { it.pokedexCaught } + val badges = field(S16LE.listPrefixed(U8)) { it.badges } + val variables = field(PlayerVariableEntryCodec.listPrefixed(U16LE)) { it.variables } + return LocalPlayerStatePacket( + region, + mapId, + moveSpeed, + x, + y, + z, + money, + gender, + skinTone, + hairColor, + playtime, + flags, + partyDex, + partyForms, + pokedexSeen, + pokedexCaught, + badges, + variables, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailAttachmentRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailAttachmentRequestPacket.kt index feffccf..4d7a5c2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailAttachmentRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailAttachmentRequestPacket.kt @@ -9,8 +9,8 @@ data class MailAttachmentRequestPacket( ) object MailAttachmentRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): MailAttachmentRequestPacket { - val targetId = field(S64LE) { it.targetId } - return MailAttachmentRequestPacket(targetId) - } + override fun CodecScope.body(): MailAttachmentRequestPacket { + val targetId = field(S64LE) { it.targetId } + return MailAttachmentRequestPacket(targetId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailComposeSendPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailComposeSendPacket.kt index 5d73834..c994d1f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailComposeSendPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MailComposeSendPacket.kt @@ -3,7 +3,7 @@ package de.fiereu.openmmo.net.game.packets import de.fiereu.bytecodec.* sealed class MailAttachment { - abstract val typeByte: Byte + abstract val typeByte: Byte } data class ItemMailAttachment( @@ -24,22 +24,22 @@ data class PokemonMailAttachment( private val MailAttachmentCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): MailAttachment { - throw MalformedPacketException("MailComposeSendPacket is a client-encoded packet") - } + override fun read(buf: ReadBuffer): MailAttachment { + throw MalformedPacketException("MailComposeSendPacket is a client-encoded packet") + } - override fun write(buf: WriteBuffer, value: MailAttachment) { - S8.write(buf, value.typeByte) - when (value) { - is ItemMailAttachment -> S32LE.write(buf, value.itemId) - is PokemonQuantityMailAttachment -> { - S64LE.write(buf, value.pokemonEntityId) - S16LE.write(buf, value.quantity) - } + override fun write(buf: WriteBuffer, value: MailAttachment) { + S8.write(buf, value.typeByte) + when (value) { + is ItemMailAttachment -> S32LE.write(buf, value.itemId) + is PokemonQuantityMailAttachment -> { + S64LE.write(buf, value.pokemonEntityId) + S16LE.write(buf, value.quantity) + } - is PokemonMailAttachment -> S64LE.write(buf, value.pokemonEntityId) - } + is PokemonMailAttachment -> S64LE.write(buf, value.pokemonEntityId) } + } } data class MailComposeSendPacket( @@ -50,11 +50,11 @@ data class MailComposeSendPacket( ) object MailComposeSendPacketCodec : PacketCodec() { - override fun CodecScope.body(): MailComposeSendPacket { - val recipientName = field(Utf16LeNullTerminated) { it.recipientName } - val subject = field(Utf16LeNullTerminated) { it.subject } - val body = field(Utf16LeNullTerminated) { it.body } - val attachments = field(MailAttachmentCodec.listPrefixed(U8)) { it.attachments } - return MailComposeSendPacket(recipientName, subject, body, attachments) - } + override fun CodecScope.body(): MailComposeSendPacket { + val recipientName = field(Utf16LeNullTerminated) { it.recipientName } + val subject = field(Utf16LeNullTerminated) { it.subject } + val body = field(Utf16LeNullTerminated) { it.body } + val attachments = field(MailAttachmentCodec.listPrefixed(U8)) { it.attachments } + return MailComposeSendPacket(recipientName, subject, body, attachments) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapCellTilesetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapCellTilesetPacket.kt index b0f4602..effd51c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapCellTilesetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapCellTilesetPacket.kt @@ -13,11 +13,11 @@ data class MapCellTilesetPacket( ) object MapCellTilesetPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapCellTilesetPacket { - val chunkX = field(S8) { it.chunkX } - val chunkY = field(S8) { it.chunkY } - val chunkLevel = field(S8) { it.chunkLevel } - val tilesetIndex = field(S16LE) { it.tilesetIndex } - return MapCellTilesetPacket(chunkX, chunkY, chunkLevel, tilesetIndex) - } + override fun CodecScope.body(): MapCellTilesetPacket { + val chunkX = field(S8) { it.chunkX } + val chunkY = field(S8) { it.chunkY } + val chunkLevel = field(S8) { it.chunkLevel } + val tilesetIndex = field(S16LE) { it.tilesetIndex } + return MapCellTilesetPacket(chunkX, chunkY, chunkLevel, tilesetIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapLoadedAckPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapLoadedAckPacket.kt index 1184eda..e7ad022 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapLoadedAckPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapLoadedAckPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class MapLoadedAckPacket object MapLoadedAckPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapLoadedAckPacket { - return MapLoadedAckPacket() - } + override fun CodecScope.body(): MapLoadedAckPacket { + return MapLoadedAckPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapReadySignalPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapReadySignalPacket.kt index 297d6e6..60ada81 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapReadySignalPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapReadySignalPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec data class MapReadySignalPacket(val placeholder: Unit = Unit) object MapReadySignalPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapReadySignalPacket { - return MapReadySignalPacket() - } + override fun CodecScope.body(): MapReadySignalPacket { + return MapReadySignalPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAnimationTogglePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAnimationTogglePacket.kt index 164cdf9..f35c126 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAnimationTogglePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAnimationTogglePacket.kt @@ -12,10 +12,10 @@ data class MapTileAnimationTogglePacket( ) object MapTileAnimationTogglePacketCodec : PacketCodec() { - override fun CodecScope.body(): MapTileAnimationTogglePacket { - val x = field(S16LE) { it.x } - val y = field(S16LE) { it.y } - val enabled = field(U8) { if (it.enabled) 1 else 0 } == 1 - return MapTileAnimationTogglePacket(x, y, enabled) - } + override fun CodecScope.body(): MapTileAnimationTogglePacket { + val x = field(S16LE) { it.x } + val y = field(S16LE) { it.y } + val enabled = field(U8) { if (it.enabled) 1 else 0 } == 1 + return MapTileAnimationTogglePacket(x, y, enabled) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAttributeSetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAttributeSetPacket.kt index 116d76e..8928ad0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAttributeSetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileAttributeSetPacket.kt @@ -12,11 +12,11 @@ data class MapTileAttributeSetPacket( ) object MapTileAttributeSetPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapTileAttributeSetPacket { - val blockX = field(S8) { it.blockX } - val blockY = field(S8) { it.blockY } - val blockZ = field(S8) { it.blockZ } - val attribute = field(S8) { it.attribute } - return MapTileAttributeSetPacket(blockX, blockY, blockZ, attribute) - } + override fun CodecScope.body(): MapTileAttributeSetPacket { + val blockX = field(S8) { it.blockX } + val blockY = field(S8) { it.blockY } + val blockZ = field(S8) { it.blockZ } + val attribute = field(S8) { it.attribute } + return MapTileAttributeSetPacket(blockX, blockY, blockZ, attribute) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileEntityStateSetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileEntityStateSetPacket.kt index a59886d..c080edd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileEntityStateSetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileEntityStateSetPacket.kt @@ -13,11 +13,11 @@ data class MapTileEntityStateSetPacket( ) object MapTileEntityStateSetPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapTileEntityStateSetPacket { - val mode = field(S8) { it.mode } - val entityId = field(S16LE) { it.entityId } - val value = field(S16LE) { it.value } - val key = if (mode.toInt() == 0) field(S16LE) { it.key!! } else null - return MapTileEntityStateSetPacket(mode, entityId, value, key) - } + override fun CodecScope.body(): MapTileEntityStateSetPacket { + val mode = field(S8) { it.mode } + val entityId = field(S16LE) { it.entityId } + val value = field(S16LE) { it.value } + val key = if (mode.toInt() == 0) field(S16LE) { it.key!! } else null + return MapTileEntityStateSetPacket(mode, entityId, value, key) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectRepositionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectRepositionPacket.kt index 8fd031c..f6281f1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectRepositionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectRepositionPacket.kt @@ -16,14 +16,14 @@ data class MapTileObjectRepositionPacket( ) object MapTileObjectRepositionPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapTileObjectRepositionPacket { - val chunkX = field(S8) { it.chunkX } - val chunkY = field(S8) { it.chunkY } - val chunkZ = field(S8) { it.chunkZ } - val tileX = field(S16LE) { it.tileX } - val tileY = field(S16LE) { it.tileY } - val tileZ = field(S8) { it.tileZ } - val objectIndex = field(S8) { it.objectIndex } - return MapTileObjectRepositionPacket(chunkX, chunkY, chunkZ, tileX, tileY, tileZ, objectIndex) - } + override fun CodecScope.body(): MapTileObjectRepositionPacket { + val chunkX = field(S8) { it.chunkX } + val chunkY = field(S8) { it.chunkY } + val chunkZ = field(S8) { it.chunkZ } + val tileX = field(S16LE) { it.tileX } + val tileY = field(S16LE) { it.tileY } + val tileZ = field(S8) { it.tileZ } + val objectIndex = field(S8) { it.objectIndex } + return MapTileObjectRepositionPacket(chunkX, chunkY, chunkZ, tileX, tileY, tileZ, objectIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectSlotSetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectSlotSetPacket.kt index de475df..1286457 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectSlotSetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTileObjectSlotSetPacket.kt @@ -15,18 +15,17 @@ data class MapTileObjectSlotSetPacket( ) object MapTileObjectSlotSetPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapTileObjectSlotSetPacket { - val blockX = field(S8) { it.blockX } - val blockY = field(S8) { it.blockY } - val blockZ = field(S8) { it.blockZ } - val slot = field(S8) { it.slot } - val present = field(U8) { if (it.present) 1 else 0 } == 1 - val objectX = if (present) field(S16LE) { it.objectX!! } else null - val objectY = if (present) field(S16LE) { it.objectY!! } else null - val objectZ = if (present) field(S8) { it.objectZ!! } else null - val relative = if (present) field(U8) { if (it.relative == true) 1 else 0 } == 1 else null - return MapTileObjectSlotSetPacket( - blockX, blockY, blockZ, slot, present, objectX, objectY, objectZ, relative - ) - } + override fun CodecScope.body(): MapTileObjectSlotSetPacket { + val blockX = field(S8) { it.blockX } + val blockY = field(S8) { it.blockY } + val blockZ = field(S8) { it.blockZ } + val slot = field(S8) { it.slot } + val present = field(U8) { if (it.present) 1 else 0 } == 1 + val objectX = if (present) field(S16LE) { it.objectX!! } else null + val objectY = if (present) field(S16LE) { it.objectY!! } else null + val objectZ = if (present) field(S8) { it.objectZ!! } else null + val relative = if (present) field(U8) { if (it.relative == true) 1 else 0 } == 1 else null + return MapTileObjectSlotSetPacket( + blockX, blockY, blockZ, slot, present, objectX, objectY, objectZ, relative) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTransitionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTransitionPacket.kt index 9d8a164..6844d52 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTransitionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapTransitionPacket.kt @@ -4,11 +4,11 @@ import de.fiereu.bytecodec.CodecScope import de.fiereu.bytecodec.PacketCodec class MapTransitionPacket { - override fun equals(other: Any?): Boolean = other is MapTransitionPacket + override fun equals(other: Any?): Boolean = other is MapTransitionPacket - override fun hashCode(): Int = MapTransitionPacket::class.hashCode() + override fun hashCode(): Int = MapTransitionPacket::class.hashCode() } object MapTransitionPacketCodec : PacketCodec() { - override fun CodecScope.body() = MapTransitionPacket() + override fun CodecScope.body() = MapTransitionPacket() } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapWeatherModeSetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapWeatherModeSetPacket.kt index 1215925..7df9caf 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapWeatherModeSetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MapWeatherModeSetPacket.kt @@ -11,9 +11,9 @@ data class MapWeatherModeSetPacket( ) object MapWeatherModeSetPacketCodec : PacketCodec() { - override fun CodecScope.body(): MapWeatherModeSetPacket { - val mode = field(S8) { it.mode } - val enabled = field(U8) { if (it.enabled) 1 else 0 } == 1 - return MapWeatherModeSetPacket(mode, enabled) - } + override fun CodecScope.body(): MapWeatherModeSetPacket { + val mode = field(S8) { it.mode } + val enabled = field(U8) { if (it.enabled) 1 else 0 } == 1 + return MapWeatherModeSetPacket(mode, enabled) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketBoardPagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketBoardPagePacket.kt index 147d43a..6ecc52b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketBoardPagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketBoardPagePacket.kt @@ -21,28 +21,27 @@ data class MarketBoardPagePacket( ) object MarketBoardPagePacketCodec : PacketCodec() { - override fun CodecScope.body(): MarketBoardPagePacket { - val hasData = field(S8) { it.hasData } - if (hasData < 1) { - return MarketBoardPagePacket(hasData, null, null, null, null, null, false, emptyList()) - } - val page = field(S8) { it.page!! } - val category = field(S8) { it.category!! } - val total = field(S32LE) { it.total!! } - val expiryOffsetMillis = field(S64LE) { it.expiryOffsetMillis!! } - val count = field(S32LE) { it.count!! } - val categoryRanked = false - val entryCount = field(S16LE) { it.entries.size.toShort() }.toInt() - val entries = ArrayList(entryCount) - repeat(entryCount) { i -> - val itemId = field(S16LE) { it.entries[i].itemId } - val valueA = field(S32LE) { it.entries[i].valueA } - val valueB = field(S32LE) { it.entries[i].valueB } - val rank: Byte? = if (categoryRanked) field(S8) { it.entries[i].rank ?: 0 } else null - entries.add(MarketBoardEntry(itemId, valueA, valueB, rank)) - } - return MarketBoardPagePacket( - hasData, page, category, total, expiryOffsetMillis, count, categoryRanked, entries - ) + override fun CodecScope.body(): MarketBoardPagePacket { + val hasData = field(S8) { it.hasData } + if (hasData < 1) { + return MarketBoardPagePacket(hasData, null, null, null, null, null, false, emptyList()) } + val page = field(S8) { it.page!! } + val category = field(S8) { it.category!! } + val total = field(S32LE) { it.total!! } + val expiryOffsetMillis = field(S64LE) { it.expiryOffsetMillis!! } + val count = field(S32LE) { it.count!! } + val categoryRanked = false + val entryCount = field(S16LE) { it.entries.size.toShort() }.toInt() + val entries = ArrayList(entryCount) + repeat(entryCount) { i -> + val itemId = field(S16LE) { it.entries[i].itemId } + val valueA = field(S32LE) { it.entries[i].valueA } + val valueB = field(S32LE) { it.entries[i].valueB } + val rank: Byte? = if (categoryRanked) field(S8) { it.entries[i].rank ?: 0 } else null + entries.add(MarketBoardEntry(itemId, valueA, valueB, rank)) + } + return MarketBoardPagePacket( + hasData, page, category, total, expiryOffsetMillis, count, categoryRanked, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketListingsRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketListingsRequestPacket.kt index 3a119ea..03b13f8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketListingsRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketListingsRequestPacket.kt @@ -7,9 +7,9 @@ import de.fiereu.bytecodec.S8 data class MarketListingsRequestPacket(val tab: Byte, val categoryId: Byte) object MarketListingsRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): MarketListingsRequestPacket { - val tab = field(S8) { it.tab } - val categoryId = field(S8) { it.categoryId } - return MarketListingsRequestPacket(tab, categoryId) - } + override fun CodecScope.body(): MarketListingsRequestPacket { + val tab = field(S8) { it.tab } + val categoryId = field(S8) { it.categoryId } + return MarketListingsRequestPacket(tab, categoryId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketSearchFilterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketSearchFilterPacket.kt index 31544a5..6481444 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketSearchFilterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MarketSearchFilterPacket.kt @@ -12,10 +12,10 @@ data class MarketSearchFilterPacket( ) object MarketSearchFilterPacketCodec : PacketCodec() { - override fun CodecScope.body(): MarketSearchFilterPacket { - val tab = field(S8) { it.tab } - val categoryId = field(S8) { it.categoryId } - val speciesFilter = field(S16LE) { it.speciesFilter } - return MarketSearchFilterPacket(tab, categoryId, speciesFilter) - } + override fun CodecScope.body(): MarketSearchFilterPacket { + val tab = field(S8) { it.tab } + val categoryId = field(S8) { it.categoryId } + val speciesFilter = field(S16LE) { it.speciesFilter } + return MarketSearchFilterPacket(tab, categoryId, speciesFilter) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt index f8bfe74..bcceadd 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingActionPacket.kt @@ -3,7 +3,7 @@ package de.fiereu.openmmo.net.game.packets import de.fiereu.bytecodec.* sealed class MatchmakingActionKind { - abstract val actionId: Byte + abstract val actionId: Byte } data class TeleportAction(override val actionId: Byte) : MatchmakingActionKind() @@ -18,62 +18,62 @@ data class SelectTargetAction( private val MatchmakingActionCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): MatchmakingActionKind { - val actionId = buf.readByte() - return when (actionId.toInt()) { - 1 -> { - var v = 0 - for (i in 0 until 4) { - v = v or ((buf.readByte().toInt() and 0xFF) shl (i * 8)) - } - SelectTierAction(actionId, v) - } - - 2 -> { - var id = 0L - for (i in 0 until 8) { - id = id or ((buf.readByte().toLong() and 0xFF) shl (i * 8)) - } - val lo = buf.readByte().toInt() and 0xFF - val hi = buf.readByte().toInt() and 0xFF - SelectTargetAction(actionId, id, ((hi shl 8) or lo).toShort()) - } - - else -> TeleportAction(actionId) + override fun read(buf: ReadBuffer): MatchmakingActionKind { + val actionId = buf.readByte() + return when (actionId.toInt()) { + 1 -> { + var v = 0 + for (i in 0 until 4) { + v = v or ((buf.readByte().toInt() and 0xFF) shl (i * 8)) } - } + SelectTierAction(actionId, v) + } - override fun write(buf: WriteBuffer, value: MatchmakingActionKind) { - buf.writeByte(value.actionId) - when (value) { - is TeleportAction -> {} - is SelectTierAction -> { - var v = value.tierId - for (i in 0 until 4) { - buf.writeByte((v and 0xFF).toByte()) - v = v ushr 8 - } - } - - is SelectTargetAction -> { - var id = value.targetEntityId - for (i in 0 until 8) { - buf.writeByte((id and 0xFF).toByte()) - id = id ushr 8 - } - val s = value.targetSlot.toInt() - buf.writeByte((s and 0xFF).toByte()) - buf.writeByte(((s ushr 8) and 0xFF).toByte()) - } + 2 -> { + var id = 0L + for (i in 0 until 8) { + id = id or ((buf.readByte().toLong() and 0xFF) shl (i * 8)) } + val lo = buf.readByte().toInt() and 0xFF + val hi = buf.readByte().toInt() and 0xFF + SelectTargetAction(actionId, id, ((hi shl 8) or lo).toShort()) + } + + else -> TeleportAction(actionId) } + } + + override fun write(buf: WriteBuffer, value: MatchmakingActionKind) { + buf.writeByte(value.actionId) + when (value) { + is TeleportAction -> {} + is SelectTierAction -> { + var v = value.tierId + for (i in 0 until 4) { + buf.writeByte((v and 0xFF).toByte()) + v = v ushr 8 + } + } + + is SelectTargetAction -> { + var id = value.targetEntityId + for (i in 0 until 8) { + buf.writeByte((id and 0xFF).toByte()) + id = id ushr 8 + } + val s = value.targetSlot.toInt() + buf.writeByte((s and 0xFF).toByte()) + buf.writeByte(((s ushr 8) and 0xFF).toByte()) + } + } + } } data class MatchmakingActionPacket(val action: MatchmakingActionKind) object MatchmakingActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): MatchmakingActionPacket { - val action = field(MatchmakingActionCodec) { it.action } - return MatchmakingActionPacket(action) - } + override fun CodecScope.body(): MatchmakingActionPacket { + val action = field(MatchmakingActionCodec) { it.action } + return MatchmakingActionPacket(action) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingLanguagePrefsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingLanguagePrefsPacket.kt index 03e752e..b5f3cae 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingLanguagePrefsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingLanguagePrefsPacket.kt @@ -5,8 +5,8 @@ import de.fiereu.bytecodec.* data class MatchmakingLanguagePrefsPacket(val languageIds: List) object MatchmakingLanguagePrefsPacketCodec : PacketCodec() { - override fun CodecScope.body(): MatchmakingLanguagePrefsPacket { - val languageIds = field(S8.listPrefixed(U8)) { it.languageIds } - return MatchmakingLanguagePrefsPacket(languageIds) - } + override fun CodecScope.body(): MatchmakingLanguagePrefsPacket { + val languageIds = field(S8.listPrefixed(U8)) { it.languageIds } + return MatchmakingLanguagePrefsPacket(languageIds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingMemberProgressPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingMemberProgressPacket.kt index fe8234b..00fc37c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingMemberProgressPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingMemberProgressPacket.kt @@ -12,10 +12,10 @@ data class MatchmakingMemberProgressPacket( ) object MatchmakingMemberProgressPacketCodec : PacketCodec() { - override fun CodecScope.body(): MatchmakingMemberProgressPacket { - val entityId = field(S64LE, MatchmakingMemberProgressPacket::entityId) - val current = field(S16LE, MatchmakingMemberProgressPacket::current) - val total = field(S16LE, MatchmakingMemberProgressPacket::total) - return MatchmakingMemberProgressPacket(entityId, current, total) - } + override fun CodecScope.body(): MatchmakingMemberProgressPacket { + val entityId = field(S64LE, MatchmakingMemberProgressPacket::entityId) + val current = field(S16LE, MatchmakingMemberProgressPacket::current) + val total = field(S16LE, MatchmakingMemberProgressPacket::total) + return MatchmakingMemberProgressPacket(entityId, current, total) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingRentalsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingRentalsPacket.kt index 776ee70..ac412e5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingRentalsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingRentalsPacket.kt @@ -19,51 +19,51 @@ data class MatchmakingRentalsPacket( ) private object MatchmakingRentalPreviewCodec : PacketCodec() { - override fun CodecScope.body(): MatchmakingRentalPreview { - val speciesId = field(S16LE, MatchmakingRentalPreview::speciesId) - val level = field(S16LE, MatchmakingRentalPreview::level) - return MatchmakingRentalPreview(speciesId, level) - } + override fun CodecScope.body(): MatchmakingRentalPreview { + val speciesId = field(S16LE, MatchmakingRentalPreview::speciesId) + val level = field(S16LE, MatchmakingRentalPreview::level) + return MatchmakingRentalPreview(speciesId, level) + } } private val MatchmakingRentalPreviewListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { MatchmakingRentalPreviewCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { MatchmakingRentalPreviewCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { MatchmakingRentalPreviewCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { MatchmakingRentalPreviewCodec.write(buf, it) } + } } private val PokemonListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { PokemonCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { PokemonCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { PokemonCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { PokemonCodec.write(buf, it) } + } } object MatchmakingRentalsPacketCodec : PacketCodec() { - override fun CodecScope.body(): MatchmakingRentalsPacket { - val mode = field(S8, MatchmakingRentalsPacket::mode) - val param1 = field(S8, MatchmakingRentalsPacket::param1) - val param2 = field(S8, MatchmakingRentalsPacket::param2) - val param3 = field(S8, MatchmakingRentalsPacket::param3) - val previews = - if (mode.toInt() == 2) - field(MatchmakingRentalPreviewListPrefixedU8) { it.previews ?: emptyList() } - else null - val pokemon = - if (mode.toInt() == 0) field(PokemonListPrefixedU8) { it.pokemon ?: emptyList() } else null - return MatchmakingRentalsPacket(mode, param1, param2, param3, previews, pokemon) - } + override fun CodecScope.body(): MatchmakingRentalsPacket { + val mode = field(S8, MatchmakingRentalsPacket::mode) + val param1 = field(S8, MatchmakingRentalsPacket::param1) + val param2 = field(S8, MatchmakingRentalsPacket::param2) + val param3 = field(S8, MatchmakingRentalsPacket::param3) + val previews = + if (mode.toInt() == 2) + field(MatchmakingRentalPreviewListPrefixedU8) { it.previews ?: emptyList() } + else null + val pokemon = + if (mode.toInt() == 0) field(PokemonListPrefixedU8) { it.pokemon ?: emptyList() } else null + return MatchmakingRentalsPacket(mode, param1, param2, param3, previews, pokemon) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingSideTeamPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingSideTeamPacket.kt index f0e962f..8845790 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingSideTeamPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MatchmakingSideTeamPacket.kt @@ -26,58 +26,58 @@ data class MatchmakingSideTeamPacket( ) private object MatchmakingRankingEntryCodec : PacketCodec() { - override fun CodecScope.body(): MatchmakingRankingEntry { - val entityId = field(S64LE, MatchmakingRankingEntry::entityId) - val rank = field(S8, MatchmakingRankingEntry::rank) - val flags = field(S8, MatchmakingRankingEntry::flags) - val name = field(Utf16LeNullTerminated, MatchmakingRankingEntry::name) - val value1 = field(S16LE, MatchmakingRankingEntry::value1) - val species = field(S16LE, MatchmakingRankingEntry::species) - reserved(byte = 0) - val ribbons = field(S64LE, MatchmakingRankingEntry::ribbons) - val value2 = field(S8, MatchmakingRankingEntry::value2) - val value3 = field(S32LE, MatchmakingRankingEntry::value3) - val value4 = field(S8, MatchmakingRankingEntry::value4) - val flag1 = field(Bool, MatchmakingRankingEntry::flag1) - val flag2 = field(Bool, MatchmakingRankingEntry::flag2) - reserved(byte = 0) - return MatchmakingRankingEntry( - entityId, - rank, - flags, - name, - value1, - species, - ribbons, - value2, - value3, - value4, - flag1, - flag2, - ) - } + override fun CodecScope.body(): MatchmakingRankingEntry { + val entityId = field(S64LE, MatchmakingRankingEntry::entityId) + val rank = field(S8, MatchmakingRankingEntry::rank) + val flags = field(S8, MatchmakingRankingEntry::flags) + val name = field(Utf16LeNullTerminated, MatchmakingRankingEntry::name) + val value1 = field(S16LE, MatchmakingRankingEntry::value1) + val species = field(S16LE, MatchmakingRankingEntry::species) + reserved(byte = 0) + val ribbons = field(S64LE, MatchmakingRankingEntry::ribbons) + val value2 = field(S8, MatchmakingRankingEntry::value2) + val value3 = field(S32LE, MatchmakingRankingEntry::value3) + val value4 = field(S8, MatchmakingRankingEntry::value4) + val flag1 = field(Bool, MatchmakingRankingEntry::flag1) + val flag2 = field(Bool, MatchmakingRankingEntry::flag2) + reserved(byte = 0) + return MatchmakingRankingEntry( + entityId, + rank, + flags, + name, + value1, + species, + ribbons, + value2, + value3, + value4, + flag1, + flag2, + ) + } } private val MatchmakingRankingEntryListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { MatchmakingRankingEntryCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { MatchmakingRankingEntryCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { MatchmakingRankingEntryCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { MatchmakingRankingEntryCodec.write(buf, it) } + } } object MatchmakingSideTeamPacketCodec : PacketCodec() { - override fun CodecScope.body(): MatchmakingSideTeamPacket { - val sessionId = field(S8, MatchmakingSideTeamPacket::sessionId) - val opponentSide = field(Bool, MatchmakingSideTeamPacket::opponentSide) - val page = field(S16LE, MatchmakingSideTeamPacket::page) - val slot = field(S32LE, MatchmakingSideTeamPacket::slot) - val team = field(MatchmakingRankingEntryListPrefixedU8, MatchmakingSideTeamPacket::team) - return MatchmakingSideTeamPacket(sessionId, opponentSide, page, slot, team) - } + override fun CodecScope.body(): MatchmakingSideTeamPacket { + val sessionId = field(S8, MatchmakingSideTeamPacket::sessionId) + val opponentSide = field(Bool, MatchmakingSideTeamPacket::opponentSide) + val page = field(S16LE, MatchmakingSideTeamPacket::page) + val slot = field(S32LE, MatchmakingSideTeamPacket::slot) + val team = field(MatchmakingRankingEntryListPrefixedU8, MatchmakingSideTeamPacket::team) + return MatchmakingSideTeamPacket(sessionId, opponentSide, page, slot, team) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPagePayloadPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPagePayloadPacket.kt index 57ecefa..ae79b9f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPagePayloadPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPagePayloadPacket.kt @@ -6,33 +6,33 @@ data class MenuPagePayloadPacket( val menuType: Byte, val page: ByteArray?, ) { - override fun equals(other: Any?): Boolean { - if (other !is MenuPagePayloadPacket) return false - if (menuType != other.menuType) return false - if (page == null) return other.page == null - return other.page != null && page.contentEquals(other.page) - } + override fun equals(other: Any?): Boolean { + if (other !is MenuPagePayloadPacket) return false + if (menuType != other.menuType) return false + if (page == null) return other.page == null + return other.page != null && page.contentEquals(other.page) + } - override fun hashCode(): Int { - var r = menuType.toInt() - r = r * 31 + (page?.contentHashCode() ?: 0) - return r - } + override fun hashCode(): Int { + var r = menuType.toInt() + r = r * 31 + (page?.contentHashCode() ?: 0) + return r + } } private val MenuPageBlob = bytesPrefixed(U16LE) object MenuPagePayloadPacketCodec : PacketCodec() { - override fun CodecScope.body(): MenuPagePayloadPacket { - val menuType = field(S8) { it.menuType } - val present = field(U8) { if (it.page != null) 1 else 0 } == 1 - val page: ByteArray? = - if (present) { - field(S64LE) { 0L } - field(S8) { 0 } - field(S8) { 0 } - field(MenuPageBlob) { it.page!! } - } else null - return MenuPagePayloadPacket(menuType, page) - } + override fun CodecScope.body(): MenuPagePayloadPacket { + val menuType = field(S8) { it.menuType } + val present = field(U8) { if (it.page != null) 1 else 0 } == 1 + val page: ByteArray? = + if (present) { + field(S64LE) { 0L } + field(S8) { 0 } + field(S8) { 0 } + field(MenuPageBlob) { it.page!! } + } else null + return MenuPagePayloadPacket(menuType, page) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptClosePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptClosePacket.kt index 6b0b53a..fb4bf6e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptClosePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptClosePacket.kt @@ -9,8 +9,8 @@ data class MenuPromptClosePacket( ) object MenuPromptClosePacketCodec : PacketCodec() { - override fun CodecScope.body(): MenuPromptClosePacket { - val promptType = field(S8) { it.promptType } - return MenuPromptClosePacket(promptType) - } + override fun CodecScope.body(): MenuPromptClosePacket { + val promptType = field(S8) { it.promptType } + return MenuPromptClosePacket(promptType) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptOpenPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptOpenPacket.kt index 221e23e..5fdceba 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptOpenPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuPromptOpenPacket.kt @@ -22,43 +22,43 @@ data class MenuPromptOpenPacket( private val EntityRelationStatCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityRelationStat { - val stat = field(S8) { it.stat } - val value = field(S8) { it.value } - val relatedIds = field(S64LE.listPrefixed(U8)) { it.relatedIds } - return EntityRelationStat(stat, value, relatedIds) - } + override fun CodecScope.body(): EntityRelationStat { + val stat = field(S8) { it.stat } + val value = field(S8) { it.value } + val relatedIds = field(S64LE.listPrefixed(U8)) { it.relatedIds } + return EntityRelationStat(stat, value, relatedIds) + } } private val EntityRelationCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): EntityRelation { - val entityId = field(S64LE) { it.entityId } - val stats = field(EntityRelationStatCodec.listPrefixed(U8)) { it.stats } - return EntityRelation(entityId, stats) - } + override fun CodecScope.body(): EntityRelation { + val entityId = field(S64LE) { it.entityId } + val stats = field(EntityRelationStatCodec.listPrefixed(U8)) { it.stats } + return EntityRelation(entityId, stats) + } } object MenuPromptOpenPacketCodec : PacketCodec() { - override fun CodecScope.body(): MenuPromptOpenPacket { - val menuKind = field(S8) { it.menuKind } - var promptType: Byte? = null - var value: Short? = null - var relations: List? = null - when { - menuKind.toInt() == 6 -> { - relations = field(EntityRelationCodec.listPrefixed(U8)) { it.relations!! } - } + override fun CodecScope.body(): MenuPromptOpenPacket { + val menuKind = field(S8) { it.menuKind } + var promptType: Byte? = null + var value: Short? = null + var relations: List? = null + when { + menuKind.toInt() == 6 -> { + relations = field(EntityRelationCodec.listPrefixed(U8)) { it.relations!! } + } - menuKind.toInt() in 3..5 -> { - promptType = field(S8) { it.promptType!! } - value = field(S16LE) { it.value!! } - } + menuKind.toInt() in 3..5 -> { + promptType = field(S8) { it.promptType!! } + value = field(S16LE) { it.value!! } + } - menuKind.toInt() in 1..2 -> { - promptType = field(S8) { it.promptType!! } - } - } - return MenuPromptOpenPacket(menuKind, promptType, value, relations) + menuKind.toInt() in 1..2 -> { + promptType = field(S8) { it.promptType!! } + } } + return MenuPromptOpenPacket(menuKind, promptType, value, relations) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuVisibilityPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuVisibilityPacket.kt index 036cb3e..db2462f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuVisibilityPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MenuVisibilityPacket.kt @@ -11,9 +11,9 @@ data class MenuVisibilityPacket( ) object MenuVisibilityPacketCodec : PacketCodec() { - override fun CodecScope.body(): MenuVisibilityPacket { - val enabled = field(U8) { if (it.enabled) 1 else 0 } == 1 - val menuType: Byte? = if (enabled) field(S8) { it.menuType!! } else null - return MenuVisibilityPacket(enabled, menuType) - } + override fun CodecScope.body(): MenuVisibilityPacket { + val enabled = field(U8) { if (it.enabled) 1 else 0 } == 1 + val menuType: Byte? = if (enabled) field(S8) { it.menuType!! } else null + return MenuVisibilityPacket(enabled, menuType) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ModerationActionConfirmPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ModerationActionConfirmPacket.kt index 6f6c7b9..63a6989 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ModerationActionConfirmPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ModerationActionConfirmPacket.kt @@ -9,8 +9,8 @@ data class ModerationActionConfirmPacket( ) object ModerationActionConfirmPacketCodec : PacketCodec() { - override fun CodecScope.body(): ModerationActionConfirmPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - return ModerationActionConfirmPacket(targetEntityId) - } + override fun CodecScope.body(): ModerationActionConfirmPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + return ModerationActionConfirmPacket(targetEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFavoriteTogglePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFavoriteTogglePacket.kt index 170055d..c298124 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFavoriteTogglePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFavoriteTogglePacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.S64LE data class MonsterFavoriteTogglePacket(val pokemonEntityId: Long, val favorite: Boolean) object MonsterFavoriteTogglePacketCodec : PacketCodec() { - override fun CodecScope.body(): MonsterFavoriteTogglePacket { - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val favorite = field(Bool) { it.favorite } - return MonsterFavoriteTogglePacket(pokemonEntityId, favorite) - } + override fun CodecScope.body(): MonsterFavoriteTogglePacket { + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val favorite = field(Bool) { it.favorite } + return MonsterFavoriteTogglePacket(pokemonEntityId, favorite) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFormActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFormActionPacket.kt index b390a11..08e4351 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFormActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterFormActionPacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.S64LE data class MonsterFormActionPacket(val monsterEntityId: Long, val stateValue: Short) object MonsterFormActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): MonsterFormActionPacket { - val monsterEntityId = field(S64LE) { it.monsterEntityId } - val stateValue = field(S16LE) { it.stateValue } - return MonsterFormActionPacket(monsterEntityId, stateValue) - } + override fun CodecScope.body(): MonsterFormActionPacket { + val monsterEntityId = field(S64LE) { it.monsterEntityId } + val stateValue = field(S16LE) { it.stateValue } + return MonsterFormActionPacket(monsterEntityId, stateValue) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterInspectRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterInspectRequestPacket.kt index 7345579..474f682 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterInspectRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterInspectRequestPacket.kt @@ -12,10 +12,10 @@ data class MonsterInspectRequestPacket( ) object MonsterInspectRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): MonsterInspectRequestPacket { - val entityId = field(S64LE) { it.entityId } - val contextType = field(S8) { it.contextType } - val viewMode = field(S8) { it.viewMode } - return MonsterInspectRequestPacket(entityId, contextType, viewMode) - } + override fun CodecScope.body(): MonsterInspectRequestPacket { + val entityId = field(S64LE) { it.entityId } + val contextType = field(S8) { it.contextType } + val viewMode = field(S8) { it.viewMode } + return MonsterInspectRequestPacket(entityId, contextType, viewMode) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRecordBookPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRecordBookPacket.kt index 1d161de..12b8e6e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRecordBookPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRecordBookPacket.kt @@ -10,20 +10,20 @@ data class MonsterRecordBookPacket( private val PokemonRecordListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { PokemonCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { PokemonCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { PokemonCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { PokemonCodec.write(buf, it) } + } } object MonsterRecordBookPacketCodec : PacketCodec() { - override fun CodecScope.body(): MonsterRecordBookPacket { - val records = field(PokemonRecordListPrefixedU8, MonsterRecordBookPacket::records) - return MonsterRecordBookPacket(records) - } + override fun CodecScope.body(): MonsterRecordBookPacket { + val records = field(PokemonRecordListPrefixedU8, MonsterRecordBookPacket::records) + return MonsterRecordBookPacket(records) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRenamePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRenamePacket.kt index 6e2e18c..0f5b1f7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRenamePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterRenamePacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class MonsterRenamePacket(val pokemonEntityId: Long, val nickname: String) object MonsterRenamePacketCodec : PacketCodec() { - override fun CodecScope.body(): MonsterRenamePacket { - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val nickname = field(Utf16LeNullTerminated) { it.nickname } - return MonsterRenamePacket(pokemonEntityId, nickname) - } + override fun CodecScope.body(): MonsterRenamePacket { + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val nickname = field(Utf16LeNullTerminated) { it.nickname } + return MonsterRenamePacket(pokemonEntityId, nickname) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterStatusConditionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterStatusConditionPacket.kt index 33c861c..7bf8ae4 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterStatusConditionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MonsterStatusConditionPacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.S8 data class MonsterStatusConditionPacket(val targetId: Long, val statusCondition: Byte) object MonsterStatusConditionPacketCodec : PacketCodec() { - override fun CodecScope.body(): MonsterStatusConditionPacket { - val targetId = field(S64LE) { it.targetId } - val statusCondition = field(S8) { it.statusCondition } - return MonsterStatusConditionPacket(targetId, statusCondition) - } + override fun CodecScope.body(): MonsterStatusConditionPacket { + val targetId = field(S64LE) { it.targetId } + val statusCondition = field(S8) { it.statusCondition } + return MonsterStatusConditionPacket(targetId, statusCondition) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MountMoveCooldownPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MountMoveCooldownPacket.kt index c1b149e..d7e68a7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MountMoveCooldownPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MountMoveCooldownPacket.kt @@ -10,11 +10,11 @@ data class MountMoveCooldownPacket( ) object MountMoveCooldownPacketCodec : PacketCodec() { - override fun CodecScope.body(): MountMoveCooldownPacket { - val entityId = field(S64LE) { it.entityId } - val category = field(S8) { it.category } - val moveId = field(S16LE) { it.moveId } - val playAudio = field(U8) { if (it.playAudio) 1 else 0 } == 1 - return MountMoveCooldownPacket(entityId, category, moveId, playAudio) - } + override fun CodecScope.body(): MountMoveCooldownPacket { + val entityId = field(S64LE) { it.entityId } + val category = field(S8) { it.category } + val moveId = field(S16LE) { it.moveId } + val playAudio = field(U8) { if (it.playAudio) 1 else 0 } == 1 + return MountMoveCooldownPacket(entityId, category, moveId, playAudio) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MovementPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MovementPacket.kt index 390aac7..4ddbbcb 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MovementPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/MovementPacket.kt @@ -9,12 +9,12 @@ import de.fiereu.openmmo.common.enums.Direction data class MovementPacket(val x: Int, val y: Int, val direction: Direction) object MovementPacketCodec : PacketCodec() { - private val DirectionCodec = enumByOrdinalByte() + private val DirectionCodec = enumByOrdinalByte() - override fun CodecScope.body(): MovementPacket { - val x = field(S16LE) { it.x.toShort() } - val y = field(S16LE) { it.y.toShort() } - val direction = field(DirectionCodec) { it.direction } - return MovementPacket(x.toInt(), y.toInt(), direction) - } + override fun CodecScope.body(): MovementPacket { + val x = field(S16LE) { it.x.toShort() } + val y = field(S16LE) { it.y.toShort() } + val direction = field(DirectionCodec) { it.direction } + return MovementPacket(x.toInt(), y.toInt(), direction) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NamedCategoryEntriesPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NamedCategoryEntriesPacket.kt index 04f0fe1..f772894 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NamedCategoryEntriesPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NamedCategoryEntriesPacket.kt @@ -8,22 +8,22 @@ data class NamedCategoryEntry( val kind: Byte, val payload: ByteArray, ) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is NamedCategoryEntry) return false - return category == other.category && - name == other.name && - kind == other.kind && - payload.contentEquals(other.payload) - } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is NamedCategoryEntry) return false + return category == other.category && + name == other.name && + kind == other.kind && + payload.contentEquals(other.payload) + } - override fun hashCode(): Int { - var result = category.toInt() - result = 31 * result + name.hashCode() - result = 31 * result + kind.toInt() - result = 31 * result + payload.contentHashCode() - return result - } + override fun hashCode(): Int { + var result = category.toInt() + result = 31 * result + name.hashCode() + result = 31 * result + kind.toInt() + result = 31 * result + payload.contentHashCode() + return result + } } data class NamedCategoryEntriesPacket( @@ -31,31 +31,31 @@ data class NamedCategoryEntriesPacket( ) private object NamedCategoryEntryCodec : PacketCodec() { - override fun CodecScope.body(): NamedCategoryEntry { - val category = field(S8, NamedCategoryEntry::category) - val name = field(Utf16LeNullTerminated, NamedCategoryEntry::name) - val kind = field(S8, NamedCategoryEntry::kind) - val payload = field(bytesPrefixed(U8), NamedCategoryEntry::payload) - return NamedCategoryEntry(category, name, kind, payload) - } + override fun CodecScope.body(): NamedCategoryEntry { + val category = field(S8, NamedCategoryEntry::category) + val name = field(Utf16LeNullTerminated, NamedCategoryEntry::name) + val kind = field(S8, NamedCategoryEntry::kind) + val payload = field(bytesPrefixed(U8), NamedCategoryEntry::payload) + return NamedCategoryEntry(category, name, kind, payload) + } } private val NamedCategoryEntryListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { NamedCategoryEntryCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { NamedCategoryEntryCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { NamedCategoryEntryCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { NamedCategoryEntryCodec.write(buf, it) } + } } object NamedCategoryEntriesPacketCodec : PacketCodec() { - override fun CodecScope.body(): NamedCategoryEntriesPacket { - val entries = field(NamedCategoryEntryListPrefixedU8, NamedCategoryEntriesPacket::entries) - return NamedCategoryEntriesPacket(entries) - } + override fun CodecScope.body(): NamedCategoryEntriesPacket { + val entries = field(NamedCategoryEntryListPrefixedU8, NamedCategoryEntriesPacket::entries) + return NamedCategoryEntriesPacket(entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcAnimationPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcAnimationPacket.kt index de6bc6c..ebee33f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcAnimationPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcAnimationPacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.U8 data class NpcAnimationPacket(val entityId: Long, val animation: Int) object NpcAnimationPacketCodec : PacketCodec() { - override fun CodecScope.body(): NpcAnimationPacket { - val entityId = field(S64LE) { it.entityId } - val animation = field(U8) { it.animation } - return NpcAnimationPacket(entityId, animation) - } + override fun CodecScope.body(): NpcAnimationPacket { + val entityId = field(S64LE) { it.entityId } + val animation = field(U8) { it.animation } + return NpcAnimationPacket(entityId, animation) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogResponsePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogResponsePacket.kt index f298684..c23e4a2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogResponsePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogResponsePacket.kt @@ -11,9 +11,9 @@ data class NpcDialogResponsePacket( ) object NpcDialogResponsePacketCodec : PacketCodec() { - override fun CodecScope.body(): NpcDialogResponsePacket { - val dialogType = field(S8) { it.dialogType } - val responseText = field(Utf16LeNullTerminated) { it.responseText } - return NpcDialogResponsePacket(dialogType, responseText) - } + override fun CodecScope.body(): NpcDialogResponsePacket { + val dialogType = field(S8) { it.dialogType } + val responseText = field(Utf16LeNullTerminated) { it.responseText } + return NpcDialogResponsePacket(dialogType, responseText) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogueChoicePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogueChoicePacket.kt index 88fd932..31e5270 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogueChoicePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcDialogueChoicePacket.kt @@ -12,15 +12,15 @@ data class NpcDialogueChoicePacket( ) object NpcDialogueChoicePacketCodec : PacketCodec() { - override fun CodecScope.body(): NpcDialogueChoicePacket { - val dialogueType = field(S8) { it.dialogueType } - val choiceIndex = field(S8) { it.choiceIndex } - val subOption = - if (choiceIndex != 0.toByte() && dialogueType == BRANCHING_DIALOGUE_TYPE) - field(S16LE) { it.subOption ?: 0 } - else null - return NpcDialogueChoicePacket(dialogueType, choiceIndex, subOption) - } + override fun CodecScope.body(): NpcDialogueChoicePacket { + val dialogueType = field(S8) { it.dialogueType } + val choiceIndex = field(S8) { it.choiceIndex } + val subOption = + if (choiceIndex != 0.toByte() && dialogueType == BRANCHING_DIALOGUE_TYPE) + field(S16LE) { it.subOption ?: 0 } + else null + return NpcDialogueChoicePacket(dialogueType, choiceIndex, subOption) + } - private const val BRANCHING_DIALOGUE_TYPE: Byte = 1 + private const val BRANCHING_DIALOGUE_TYPE: Byte = 1 } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcInteractionChoicePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcInteractionChoicePacket.kt index 17d68d3..f71f1fb 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcInteractionChoicePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcInteractionChoicePacket.kt @@ -9,8 +9,8 @@ data class NpcInteractionChoicePacket( ) object NpcInteractionChoicePacketCodec : PacketCodec() { - override fun CodecScope.body(): NpcInteractionChoicePacket { - val targetId = field(S64LE) { it.targetId } - return NpcInteractionChoicePacket(targetId) - } + override fun CodecScope.body(): NpcInteractionChoicePacket { + val targetId = field(S64LE) { it.targetId } + return NpcInteractionChoicePacket(targetId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcPanelTogglePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcPanelTogglePacket.kt index 949f7f5..051e9da 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcPanelTogglePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcPanelTogglePacket.kt @@ -9,17 +9,17 @@ data class NpcPanelTogglePacket( ) object NpcPanelTogglePacketCodec : PacketCodec() { - override fun CodecScope.body(): NpcPanelTogglePacket { - val npcId = field(S16LE) { it.npcId } - val npcType: Byte? - val visible: Boolean? - if (npcId > 0) { - npcType = field(S8) { it.npcType!! } - visible = field(Bool) { it.visible!! } - } else { - npcType = null - visible = null - } - return NpcPanelTogglePacket(npcId, npcType, visible) + override fun CodecScope.body(): NpcPanelTogglePacket { + val npcId = field(S16LE) { it.npcId } + val npcType: Byte? + val visible: Boolean? + if (npcId > 0) { + npcType = field(S8) { it.npcType!! } + visible = field(Bool) { it.visible!! } + } else { + npcType = null + visible = null } + return NpcPanelTogglePacket(npcId, npcType, visible) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt index 2299560..2938132 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcSpawnPacket.kt @@ -19,22 +19,21 @@ data class NpcSpawnPacket( ) object NpcSpawnPacketCodec : PacketCodec() { - override fun CodecScope.body(): NpcSpawnPacket { - val entityId = field(S64LE) { it.entityId } - val unk1 = field(U8) { it.unk1 } - val unk2 = field(U16LE) { it.unk2 } - val unk3 = field(U16LE) { it.unk3 } - val unk4 = field(U16LE) { it.unk4 } - val regionId = field(U8) { it.regionId } - val bankId = field(U8) { it.bankId } - val mapId = field(U8) { it.mapId } - val x = field(U16LE) { it.x } - val y = field(U16LE) { it.y } - val unk5 = field(U8) { it.unk5 } - val facing = field(U8) { it.facing } - val unk6 = field(U16LE) { it.unk6 } - return NpcSpawnPacket( - entityId, unk1, unk2, unk3, unk4, regionId, bankId, mapId, x, y, facing, unk5, unk6 - ) - } + override fun CodecScope.body(): NpcSpawnPacket { + val entityId = field(S64LE) { it.entityId } + val unk1 = field(U8) { it.unk1 } + val unk2 = field(U16LE) { it.unk2 } + val unk3 = field(U16LE) { it.unk3 } + val unk4 = field(U16LE) { it.unk4 } + val regionId = field(U8) { it.regionId } + val bankId = field(U8) { it.bankId } + val mapId = field(U8) { it.mapId } + val x = field(U16LE) { it.x } + val y = field(U16LE) { it.y } + val unk5 = field(U8) { it.unk5 } + val facing = field(U8) { it.facing } + val unk6 = field(U16LE) { it.unk6 } + return NpcSpawnPacket( + entityId, unk1, unk2, unk3, unk4, regionId, bankId, mapId, x, y, facing, unk5, unk6) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcUpdatePacket.kt index 957c46d..b9dfa31 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NpcUpdatePacket.kt @@ -14,15 +14,15 @@ data class NpcUpdatePacket( ) object NpcUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): NpcUpdatePacket { - val entityId = field(S64LE) { it.entityId } - val regionId = field(U8) { it.regionId } - val bankId = field(U8) { it.bankId } - val mapId = field(U8) { it.mapId } - val x = field(U16LE) { it.x } - val y = field(U16LE) { it.y } - val facing = field(U8) { it.facing } - val unk = field(U8) { it.unk } - return NpcUpdatePacket(entityId, regionId, bankId, mapId, x, y, facing, unk) - } + override fun CodecScope.body(): NpcUpdatePacket { + val entityId = field(S64LE) { it.entityId } + val regionId = field(U8) { it.regionId } + val bankId = field(U8) { it.bankId } + val mapId = field(U8) { it.mapId } + val x = field(U16LE) { it.x } + val y = field(U16LE) { it.y } + val facing = field(U8) { it.facing } + val unk = field(U8) { it.unk } + return NpcUpdatePacket(entityId, regionId, bankId, mapId, x, y, facing, unk) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NullPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NullPacket.kt index 401d0e2..28c3644 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NullPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/NullPacket.kt @@ -5,16 +5,16 @@ import de.fiereu.bytecodec.* class NullPacket private object DrainRemaining : Codec { - override fun read(buf: ReadBuffer) { - if (buf.remaining() > 0) buf.skip(buf.remaining()) - } + override fun read(buf: ReadBuffer) { + if (buf.remaining() > 0) buf.skip(buf.remaining()) + } - override fun write(buf: WriteBuffer, value: Unit) {} + override fun write(buf: WriteBuffer, value: Unit) {} } object NullPacketCodec : PacketCodec() { - override fun CodecScope.body(): NullPacket { - structural(DrainRemaining) - return NullPacket() - } + override fun CodecScope.body(): NullPacket { + structural(DrainRemaining) + return NullPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressBulkPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressBulkPacket.kt index 086edd0..ab94665 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressBulkPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressBulkPacket.kt @@ -14,17 +14,17 @@ data class ObjectiveProgressBulkPacket( private val ObjectiveProgressEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ObjectiveProgressEntry { - val id = field(S8) { it.id } - val value = field(S32LE) { it.value } - val count = field(S16LE) { it.count } - return ObjectiveProgressEntry(id, value, count) - } + override fun CodecScope.body(): ObjectiveProgressEntry { + val id = field(S8) { it.id } + val value = field(S32LE) { it.value } + val count = field(S16LE) { it.count } + return ObjectiveProgressEntry(id, value, count) + } } object ObjectiveProgressBulkPacketCodec : PacketCodec() { - override fun CodecScope.body(): ObjectiveProgressBulkPacket { - val entries = field(ObjectiveProgressEntryCodec.listPrefixed(U8)) { it.entries } - return ObjectiveProgressBulkPacket(entries) - } + override fun CodecScope.body(): ObjectiveProgressBulkPacket { + val entries = field(ObjectiveProgressEntryCodec.listPrefixed(U8)) { it.entries } + return ObjectiveProgressBulkPacket(entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressPacket.kt index 1eb9a7c..9c66f35 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ObjectiveProgressPacket.kt @@ -9,10 +9,10 @@ data class ObjectiveProgressPacket( ) object ObjectiveProgressPacketCodec : PacketCodec() { - override fun CodecScope.body(): ObjectiveProgressPacket { - val id = field(S8) { it.id } - val value = field(S32LE) { it.value } - val count = field(S16LE) { it.count } - return ObjectiveProgressPacket(id, value, count) - } + override fun CodecScope.body(): ObjectiveProgressPacket { + val id = field(S8) { it.id } + val value = field(S32LE) { it.value } + val count = field(S16LE) { it.count } + return ObjectiveProgressPacket(id, value, count) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OpenAppearanceEditorPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OpenAppearanceEditorPacket.kt index 9ca64fd..859f624 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OpenAppearanceEditorPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OpenAppearanceEditorPacket.kt @@ -9,8 +9,8 @@ data class OpenAppearanceEditorPacket( ) object OpenAppearanceEditorPacketCodec : PacketCodec() { - override fun CodecScope.body(): OpenAppearanceEditorPacket { - val entityId = field(S64LE) { it.entityId } - return OpenAppearanceEditorPacket(entityId) - } + override fun CodecScope.body(): OpenAppearanceEditorPacket { + val entityId = field(S64LE) { it.entityId } + return OpenAppearanceEditorPacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OptionListWindowPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OptionListWindowPacket.kt index 6428c51..6084844 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OptionListWindowPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OptionListWindowPacket.kt @@ -19,24 +19,24 @@ data class OptionListWindowPacket( private val OptionMenuEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): OptionMenuEntry { - field(S64LE) { 0L } - field(S8) { 0 } - val typeId = field(S8) { it.typeId } - val subType = field(S8) { it.subType } - val valueA = field(S16LE) { it.valueA } - val valueB = field(S16LE) { it.valueB } - val valueC = field(S16LE) { it.valueC } - val valueD = field(S16LE) { it.valueD } - val valueE = field(S16LE) { it.valueE } - return OptionMenuEntry(typeId, subType, valueA, valueB, valueC, valueD, valueE) - } + override fun CodecScope.body(): OptionMenuEntry { + field(S64LE) { 0L } + field(S8) { 0 } + val typeId = field(S8) { it.typeId } + val subType = field(S8) { it.subType } + val valueA = field(S16LE) { it.valueA } + val valueB = field(S16LE) { it.valueB } + val valueC = field(S16LE) { it.valueC } + val valueD = field(S16LE) { it.valueD } + val valueE = field(S16LE) { it.valueE } + return OptionMenuEntry(typeId, subType, valueA, valueB, valueC, valueD, valueE) + } } object OptionListWindowPacketCodec : PacketCodec() { - override fun CodecScope.body(): OptionListWindowPacket { - val kind = field(S8) { it.kind } - val options = field(OptionMenuEntryCodec.listPrefixed(U8)) { it.options } - return OptionListWindowPacket(kind, options) - } + override fun CodecScope.body(): OptionListWindowPacket { + val kind = field(S8) { it.kind } + val options = field(OptionMenuEntryCodec.listPrefixed(U8)) { it.options } + return OptionListWindowPacket(kind, options) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldParticleSpawnPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldParticleSpawnPacket.kt index b723946..e3ee092 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldParticleSpawnPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldParticleSpawnPacket.kt @@ -14,12 +14,12 @@ data class OverworldParticleSpawnPacket( ) object OverworldParticleSpawnPacketCodec : PacketCodec() { - override fun CodecScope.body(): OverworldParticleSpawnPacket { - val effectType = field(S8) { it.effectType } - val x = field(S16LE) { it.x } - val y = field(S16LE) { it.y } - val z = field(S16LE) { it.z } - val variant = field(S16LE) { it.variant } - return OverworldParticleSpawnPacket(effectType, x, y, z, variant) - } + override fun CodecScope.body(): OverworldParticleSpawnPacket { + val effectType = field(S8) { it.effectType } + val x = field(S16LE) { it.x } + val y = field(S16LE) { it.y } + val z = field(S16LE) { it.z } + val variant = field(S16LE) { it.variant } + return OverworldParticleSpawnPacket(effectType, x, y, z, variant) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldPathToTilePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldPathToTilePacket.kt index 477a560..71e0f14 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldPathToTilePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldPathToTilePacket.kt @@ -12,10 +12,10 @@ data class OverworldPathToTilePacket( ) object OverworldPathToTilePacketCodec : PacketCodec() { - override fun CodecScope.body(): OverworldPathToTilePacket { - val zoneId = field(S16LE) { it.zoneId } - val targetX = field(S8) { it.targetX } - val targetY = field(S8) { it.targetY } - return OverworldPathToTilePacket(zoneId, targetX, targetY) - } + override fun CodecScope.body(): OverworldPathToTilePacket { + val zoneId = field(S16LE) { it.zoneId } + val targetX = field(S8) { it.targetX } + val targetY = field(S8) { it.targetY } + return OverworldPathToTilePacket(zoneId, targetX, targetY) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldStepMovePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldStepMovePacket.kt index c9ab0c1..dea1e6b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldStepMovePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldStepMovePacket.kt @@ -10,9 +10,9 @@ data class OverworldStepMovePacket( ) object OverworldStepMovePacketCodec : PacketCodec() { - override fun CodecScope.body(): OverworldStepMovePacket { - val targetX = field(S8) { it.targetX } - val targetY = field(S8) { it.targetY } - return OverworldStepMovePacket(targetX, targetY) - } + override fun CodecScope.body(): OverworldStepMovePacket { + val targetX = field(S8) { it.targetX } + val targetY = field(S8) { it.targetY } + return OverworldStepMovePacket(targetX, targetY) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt index bf844a2..0661ce5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/OverworldWeatherControlPacket.kt @@ -16,43 +16,43 @@ data class OverworldWeatherControlPacket( ) object OverworldWeatherControlPacketCodec : PacketCodec() { - override fun CodecScope.body(): OverworldWeatherControlPacket { - val effectType = field(S8) { it.effectType } - val t = effectType.toInt() - var skyId: Short? = null - var skyVariant: Short? = null - var particleId: Short? = null - var particleVariant: Short? = null - var paramA: Float? = null - var paramB: Float? = null - var paramC: Float? = null - var paramD: Float? = null - var duration: Short? = null - if (t == 0) { - skyId = field(S16LE) { it.skyId!! } - skyVariant = field(S16LE) { it.skyVariant!! } - } else if (t == 4) { - particleId = field(S16LE) { it.particleId!! } - particleVariant = field(S16LE) { it.particleVariant!! } - paramA = field(F32LE) { it.paramA!! } - paramB = field(F32LE) { it.paramB!! } - paramC = field(F32LE) { it.paramC!! } - paramD = field(F32LE) { it.paramD!! } - duration = field(S16LE) { it.duration!! } - } else if (t == 5) { - duration = field(S16LE) { it.duration!! } - } - return OverworldWeatherControlPacket( - effectType = effectType, - skyId = skyId, - skyVariant = skyVariant, - particleId = particleId, - particleVariant = particleVariant, - paramA = paramA, - paramB = paramB, - paramC = paramC, - paramD = paramD, - duration = duration, - ) + override fun CodecScope.body(): OverworldWeatherControlPacket { + val effectType = field(S8) { it.effectType } + val t = effectType.toInt() + var skyId: Short? = null + var skyVariant: Short? = null + var particleId: Short? = null + var particleVariant: Short? = null + var paramA: Float? = null + var paramB: Float? = null + var paramC: Float? = null + var paramD: Float? = null + var duration: Short? = null + if (t == 0) { + skyId = field(S16LE) { it.skyId!! } + skyVariant = field(S16LE) { it.skyVariant!! } + } else if (t == 4) { + particleId = field(S16LE) { it.particleId!! } + particleVariant = field(S16LE) { it.particleVariant!! } + paramA = field(F32LE) { it.paramA!! } + paramB = field(F32LE) { it.paramB!! } + paramC = field(F32LE) { it.paramC!! } + paramD = field(F32LE) { it.paramD!! } + duration = field(S16LE) { it.duration!! } + } else if (t == 5) { + duration = field(S16LE) { it.duration!! } } + return OverworldWeatherControlPacket( + effectType = effectType, + skyId = skyId, + skyVariant = skyVariant, + particleId = particleId, + particleVariant = particleVariant, + paramA = paramA, + paramB = paramB, + paramC = paramC, + paramD = paramD, + duration = duration, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyInfoRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyInfoRequestPacket.kt index 814fcb0..420eb0c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyInfoRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyInfoRequestPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class PartyInfoRequestPacket object PartyInfoRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): PartyInfoRequestPacket { - return PartyInfoRequestPacket() - } + override fun CodecScope.body(): PartyInfoRequestPacket { + return PartyInfoRequestPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberJoinPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberJoinPacket.kt index 7460c1e..4eb1ee0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberJoinPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberJoinPacket.kt @@ -10,11 +10,11 @@ data class PartyMemberJoinPacket( ) object PartyMemberJoinPacketCodec : PacketCodec() { - override fun CodecScope.body(): PartyMemberJoinPacket { - val player = field(S64LE) { it.player } - val name = field(Utf16LeNullTerminated) { it.name } - val secondaryName = field(Utf16LeNullTerminated) { it.secondaryName } - val value = field(S32LE) { it.value } - return PartyMemberJoinPacket(player, name, secondaryName, value) - } + override fun CodecScope.body(): PartyMemberJoinPacket { + val player = field(S64LE) { it.player } + val name = field(Utf16LeNullTerminated) { it.name } + val secondaryName = field(Utf16LeNullTerminated) { it.secondaryName } + val value = field(S32LE) { it.value } + return PartyMemberJoinPacket(player, name, secondaryName, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberLeavePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberLeavePacket.kt index e0205ea..1bfc14a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberLeavePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberLeavePacket.kt @@ -9,8 +9,8 @@ data class PartyMemberLeavePacket( ) object PartyMemberLeavePacketCodec : PacketCodec() { - override fun CodecScope.body(): PartyMemberLeavePacket { - val memberId = field(S64LE) { it.memberId } - return PartyMemberLeavePacket(memberId) - } + override fun CodecScope.body(): PartyMemberLeavePacket { + val memberId = field(S64LE) { it.memberId } + return PartyMemberLeavePacket(memberId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberSelectPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberSelectPacket.kt index f68ddef..683838d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberSelectPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyMemberSelectPacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.S8 data class PartyMemberSelectPacket(val selectionType: Byte, val entityId: Long) object PartyMemberSelectPacketCodec : PacketCodec() { - override fun CodecScope.body(): PartyMemberSelectPacket { - val selectionType = field(S8) { it.selectionType } - val entityId = field(S64LE) { it.entityId } - return PartyMemberSelectPacket(selectionType, entityId) - } + override fun CodecScope.body(): PartyMemberSelectPacket { + val selectionType = field(S8) { it.selectionType } + val entityId = field(S64LE) { it.entityId } + return PartyMemberSelectPacket(selectionType, entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyRosterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyRosterPacket.kt index 3e343d4..0e11d5d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyRosterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PartyRosterPacket.kt @@ -16,19 +16,19 @@ data class PartyRosterPacket( private val PartyMemberCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): PartyMember { - val player = field(S64LE) { it.player } - val name = field(Utf16LeNullTerminated) { it.name } - val secondaryName = field(Utf16LeNullTerminated) { it.secondaryName } - val value = field(S32LE) { it.value } - return PartyMember(player, name, secondaryName, value) - } + override fun CodecScope.body(): PartyMember { + val player = field(S64LE) { it.player } + val name = field(Utf16LeNullTerminated) { it.name } + val secondaryName = field(Utf16LeNullTerminated) { it.secondaryName } + val value = field(S32LE) { it.value } + return PartyMember(player, name, secondaryName, value) + } } object PartyRosterPacketCodec : PacketCodec() { - override fun CodecScope.body(): PartyRosterPacket { - val mergeMode = field(U8) { it.mergeMode } - val members = field(PartyMemberCodec.listPrefixed(U8)) { it.members } - return PartyRosterPacket(mergeMode, members) - } + override fun CodecScope.body(): PartyRosterPacket { + val mergeMode = field(U8) { it.mergeMode } + val members = field(PartyMemberCodec.listPrefixed(U8)) { it.members } + return PartyRosterPacket(mergeMode, members) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxRenamePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxRenamePacket.kt index 96d735b..1c0196a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxRenamePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxRenamePacket.kt @@ -11,9 +11,9 @@ data class PcBoxRenamePacket( ) object PcBoxRenamePacketCodec : PacketCodec() { - override fun CodecScope.body(): PcBoxRenamePacket { - val boxIndex = field(S8) { it.boxIndex } - val newName = field(Utf16LeNullTerminated) { it.newName } - return PcBoxRenamePacket(boxIndex, newName) - } + override fun CodecScope.body(): PcBoxRenamePacket { + val boxIndex = field(S8) { it.boxIndex } + val newName = field(Utf16LeNullTerminated) { it.newName } + return PcBoxRenamePacket(boxIndex, newName) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxStorePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxStorePacket.kt index 5065516..c69e48c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxStorePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PcBoxStorePacket.kt @@ -12,10 +12,10 @@ data class PcBoxStorePacket( ) object PcBoxStorePacketCodec : PacketCodec() { - override fun CodecScope.body(): PcBoxStorePacket { - val boxId = field(S8) { it.boxId } - val slotIndex = field(S8) { it.slotIndex } - val pokemonId = field(S64LE) { it.pokemonId } - return PcBoxStorePacket(boxId, slotIndex, pokemonId) - } + override fun CodecScope.body(): PcBoxStorePacket { + val boxId = field(S8) { it.boxId } + val slotIndex = field(S8) { it.slotIndex } + val pokemonId = field(S64LE) { it.pokemonId } + return PcBoxStorePacket(boxId, slotIndex, pokemonId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PendingRequestCancelPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PendingRequestCancelPacket.kt index 0ff2124..a669e1b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PendingRequestCancelPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PendingRequestCancelPacket.kt @@ -9,8 +9,8 @@ data class PendingRequestCancelPacket( ) object PendingRequestCancelPacketCodec : PacketCodec() { - override fun CodecScope.body(): PendingRequestCancelPacket { - val requestEntityId = field(S64LE) { it.requestEntityId } - return PendingRequestCancelPacket(requestEntityId) - } + override fun CodecScope.body(): PendingRequestCancelPacket { + val requestEntityId = field(S64LE) { it.requestEntityId } + return PendingRequestCancelPacket(requestEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerChatInputPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerChatInputPacket.kt index 4963e8b..1d4f38d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerChatInputPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerChatInputPacket.kt @@ -9,8 +9,8 @@ data class PlayerChatInputPacket( ) object PlayerChatInputPacketCodec : PacketCodec() { - override fun CodecScope.body(): PlayerChatInputPacket { - val message = field(Utf16LeNullTerminated) { it.message } - return PlayerChatInputPacket(message) - } + override fun CodecScope.body(): PlayerChatInputPacket { + val message = field(Utf16LeNullTerminated) { it.message } + return PlayerChatInputPacket(message) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerFacingChangePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerFacingChangePacket.kt index 424a541..1eb6323 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerFacingChangePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerFacingChangePacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S8 data class PlayerFacingChangePacket(val facingDirection: Byte) object PlayerFacingChangePacketCodec : PacketCodec() { - override fun CodecScope.body(): PlayerFacingChangePacket { - val facingDirection = field(S8) { it.facingDirection } - return PlayerFacingChangePacket(facingDirection) - } + override fun CodecScope.body(): PlayerFacingChangePacket { + val facingDirection = field(S8) { it.facingDirection } + return PlayerFacingChangePacket(facingDirection) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerInputLockPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerInputLockPacket.kt index 6703a5b..166c00a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerInputLockPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerInputLockPacket.kt @@ -9,8 +9,8 @@ data class PlayerInputLockPacket( ) object PlayerInputLockPacketCodec : PacketCodec() { - override fun CodecScope.body(): PlayerInputLockPacket { - val inputEnabled = field(U8) { if (it.inputEnabled) 1 else 0 } == 1 - return PlayerInputLockPacket(inputEnabled) - } + override fun CodecScope.body(): PlayerInputLockPacket { + val inputEnabled = field(U8) { if (it.inputEnabled) 1 else 0 } == 1 + return PlayerInputLockPacket(inputEnabled) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerPositionUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerPositionUpdatePacket.kt index 495dcf5..2d52db8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerPositionUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerPositionUpdatePacket.kt @@ -14,19 +14,19 @@ data class PlayerPositionUpdatePacket( ) object PlayerPositionUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): PlayerPositionUpdatePacket { - val x = field(S16LE) { it.x } - val y = field(S16LE) { it.y } - val packedFacing = - field(U8) { - var f = it.facing.toInt() and 0xFF - if (it.isRunning) f = f or 0x80 - if (it.isOnBike) f = f or 0x40 - f - } - val isRunning = (packedFacing and 0x80) != 0 - val isOnBike = (packedFacing and 0x40) != 0 - val facing = (packedFacing and 0x3F).toByte() - return PlayerPositionUpdatePacket(x, y, facing, isRunning, isOnBike) - } + override fun CodecScope.body(): PlayerPositionUpdatePacket { + val x = field(S16LE) { it.x } + val y = field(S16LE) { it.y } + val packedFacing = + field(U8) { + var f = it.facing.toInt() and 0xFF + if (it.isRunning) f = f or 0x80 + if (it.isOnBike) f = f or 0x40 + f + } + val isRunning = (packedFacing and 0x80) != 0 + val isOnBike = (packedFacing and 0x40) != 0 + val facing = (packedFacing and 0x3F).toByte() + return PlayerPositionUpdatePacket(x, y, facing, isRunning, isOnBike) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerStopMovingPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerStopMovingPacket.kt index 8614c2a..2673ef9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerStopMovingPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PlayerStopMovingPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class PlayerStopMovingPacket object PlayerStopMovingPacketCodec : PacketCodec() { - override fun CodecScope.body(): PlayerStopMovingPacket { - return PlayerStopMovingPacket() - } + override fun CodecScope.body(): PlayerStopMovingPacket { + return PlayerStopMovingPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesResetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesResetPacket.kt index b1f9f5e..9ca004d 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesResetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesResetPacket.kt @@ -7,8 +7,8 @@ data class PokedexSpeciesResetPacket( ) object PokedexSpeciesResetPacketCodec : PacketCodec() { - override fun CodecScope.body(): PokedexSpeciesResetPacket { - val speciesIds = field(S16LE.listPrefixed(U16LE)) { it.speciesIds } - return PokedexSpeciesResetPacket(speciesIds) - } + override fun CodecScope.body(): PokedexSpeciesResetPacket { + val speciesIds = field(S16LE.listPrefixed(U16LE)) { it.speciesIds } + return PokedexSpeciesResetPacket(speciesIds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesUnlockPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesUnlockPacket.kt index 7a895b3..aee3db1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesUnlockPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokedexSpeciesUnlockPacket.kt @@ -9,8 +9,8 @@ data class PokedexSpeciesUnlockPacket( ) object PokedexSpeciesUnlockPacketCodec : PacketCodec() { - override fun CodecScope.body(): PokedexSpeciesUnlockPacket { - val speciesId = field(S16LE) { it.speciesId } - return PokedexSpeciesUnlockPacket(speciesId) - } + override fun CodecScope.body(): PokedexSpeciesUnlockPacket { + val speciesId = field(S16LE) { it.speciesId } + return PokedexSpeciesUnlockPacket(speciesId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonContainerPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonContainerPacket.kt index cdd7479..e416e4e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonContainerPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonContainerPacket.kt @@ -11,45 +11,45 @@ data class PokemonContainerPacket( val delete: Boolean, val pokemon: List, ) { - init { - if (delete) - require(hasChange) { - "Pokemon container cannot be deleted if the packet doesn't change anything" - } - if (delete) - require(pokemon.isEmpty()) { "Deleting a Pokemon container shouldn't have any pokemon" } - } + init { + if (delete) + require(hasChange) { + "Pokemon container cannot be deleted if the packet doesn't change anything" + } + if (delete) + require(pokemon.isEmpty()) { "Deleting a Pokemon container shouldn't have any pokemon" } + } } private val PokemonListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { PokemonCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { PokemonCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { PokemonCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { PokemonCodec.write(buf, it) } + } } object PokemonContainerPacketCodec : PacketCodec() { - override fun CodecScope.body(): PokemonContainerPacket { - val container = PokemonContainer.entries[field(U8) { it.container.ordinal }] - val flags = - field(U8) { - var f = 0 - if (it.hasChange) f = f or 1 - if (it.delete) f = f or 2 - f - } - val hasChange = (flags and 1) != 0 - val delete = (flags and 2) != 0 - if (delete) { - return PokemonContainerPacket(container, hasChange, true, emptyList()) + override fun CodecScope.body(): PokemonContainerPacket { + val container = PokemonContainer.entries[field(U8) { it.container.ordinal }] + val flags = + field(U8) { + var f = 0 + if (it.hasChange) f = f or 1 + if (it.delete) f = f or 2 + f } - val pokemon = field(PokemonListPrefixedU8, PokemonContainerPacket::pokemon) - return PokemonContainerPacket(container, hasChange, false, pokemon) + val hasChange = (flags and 1) != 0 + val delete = (flags and 2) != 0 + if (delete) { + return PokemonContainerPacket(container, hasChange, true, emptyList()) } + val pokemon = field(PokemonListPrefixedU8, PokemonContainerPacket::pokemon) + return PokemonContainerPacket(container, hasChange, false, pokemon) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonFlagsUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonFlagsUpdatePacket.kt index a829dc8..7fc16f0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonFlagsUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonFlagsUpdatePacket.kt @@ -8,9 +8,9 @@ import de.fiereu.bytecodec.S8 data class PokemonFlagsUpdatePacket(val entityId: Long, val flags: Byte) object PokemonFlagsUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): PokemonFlagsUpdatePacket { - val entityId = field(S64LE) { it.entityId } - val flags = field(S8) { it.flags } - return PokemonFlagsUpdatePacket(entityId, flags) - } + override fun CodecScope.body(): PokemonFlagsUpdatePacket { + val entityId = field(S64LE) { it.entityId } + val flags = field(S8) { it.flags } + return PokemonFlagsUpdatePacket(entityId, flags) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonListAddPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonListAddPacket.kt index db08ba7..3d5f1ed 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonListAddPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PokemonListAddPacket.kt @@ -9,10 +9,10 @@ data class PokemonListAddPacket( ) object PokemonListAddPacketCodec : PacketCodec() { - override fun CodecScope.body(): PokemonListAddPacket { - val entityId = field(S64LE) { it.entityId } - val slot = field(S16LE) { it.slot } - val listType = field(S8) { it.listType } - return PokemonListAddPacket(entityId, slot, listType) - } + override fun CodecScope.body(): PokemonListAddPacket { + val entityId = field(S64LE) { it.entityId } + val slot = field(S16LE) { it.slot } + val listType = field(S8) { it.listType } + return PokemonListAddPacket(entityId, slot, listType) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PongPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PongPacket.kt index 8f2345e..da079f4 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PongPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PongPacket.kt @@ -11,14 +11,14 @@ data class PongPacket( ) object PongPacketCodec : PacketCodec() { - override fun CodecScope.body(): PongPacket { - val isServerPong = field(Bool) { it.isServerPong } - val timestamp = - if (isServerPong) { - field(S64LE) { it.timestamp } - } else { - field(S64LE) { if (it.timestamp == -1L) System.currentTimeMillis() else it.timestamp } - } - return PongPacket(isServerPong, timestamp) - } + override fun CodecScope.body(): PongPacket { + val isServerPong = field(Bool) { it.isServerPong } + val timestamp = + if (isServerPong) { + field(S64LE) { it.timestamp } + } else { + field(S64LE) { if (it.timestamp == -1L) System.currentTimeMillis() else it.timestamp } + } + return PongPacket(isServerPong, timestamp) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PrismaticPearlTransferPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PrismaticPearlTransferPacket.kt index 94b037e..f028d71 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PrismaticPearlTransferPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/PrismaticPearlTransferPacket.kt @@ -10,9 +10,9 @@ data class PrismaticPearlTransferPacket( ) object PrismaticPearlTransferPacketCodec : PacketCodec() { - override fun CodecScope.body(): PrismaticPearlTransferPacket { - val sourceEntityId = field(S64LE) { it.sourceEntityId } - val targetEntityId = field(S64LE) { it.targetEntityId } - return PrismaticPearlTransferPacket(sourceEntityId, targetEntityId) - } + override fun CodecScope.body(): PrismaticPearlTransferPacket { + val sourceEntityId = field(S64LE) { it.sourceEntityId } + val targetEntityId = field(S64LE) { it.targetEntityId } + return PrismaticPearlTransferPacket(sourceEntityId, targetEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/QueuePositionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/QueuePositionPacket.kt index d1d8be0..abee0ee 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/QueuePositionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/QueuePositionPacket.kt @@ -10,9 +10,9 @@ data class QueuePositionPacket( ) object QueuePositionPacketCodec : PacketCodec() { - override fun CodecScope.body(): QueuePositionPacket { - val position = field(S16LE) { it.position } - val total = field(S16LE) { it.total } - return QueuePositionPacket(position, total) - } + override fun CodecScope.body(): QueuePositionPacket { + val position = field(S16LE) { it.position } + val total = field(S16LE) { it.total } + return QueuePositionPacket(position, total) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RemoveFriendPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RemoveFriendPacket.kt index 77069f0..10c636c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RemoveFriendPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RemoveFriendPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class RemoveFriendPacket(val username: String) object RemoveFriendPacketCodec : PacketCodec() { - override fun CodecScope.body(): RemoveFriendPacket { - val username = field(Utf16LeNullTerminated) { it.username } - return RemoveFriendPacket(username) - } + override fun CodecScope.body(): RemoveFriendPacket { + val username = field(Utf16LeNullTerminated) { it.username } + return RemoveFriendPacket(username) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RenderScreenPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RenderScreenPacket.kt index d1e1bde..5cc0312 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RenderScreenPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RenderScreenPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.PacketCodec data class RenderScreenPacket(val renderScreen: Boolean) object RenderScreenPacketCodec : PacketCodec() { - override fun CodecScope.body(): RenderScreenPacket { - val renderScreen = field(Bool) { it.renderScreen } - return RenderScreenPacket(renderScreen) - } + override fun CodecScope.body(): RenderScreenPacket { + val renderScreen = field(Bool) { it.renderScreen } + return RenderScreenPacket(renderScreen) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestCharactersPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestCharactersPacket.kt index 4af0c95..62b45ce 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestCharactersPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestCharactersPacket.kt @@ -6,5 +6,5 @@ import de.fiereu.bytecodec.PacketCodec class RequestCharactersPacket object RequestCharactersPacketCodec : PacketCodec() { - override fun CodecScope.body() = RequestCharactersPacket() + override fun CodecScope.body() = RequestCharactersPacket() } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestConfirmationPromptPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestConfirmationPromptPacket.kt index 13990b9..af34830 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestConfirmationPromptPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestConfirmationPromptPacket.kt @@ -10,13 +10,12 @@ data class RequestConfirmationPromptPacket( ) object RequestConfirmationPromptPacketCodec : PacketCodec() { - override fun CodecScope.body(): RequestConfirmationPromptPacket { - val visible = field(U8) { if (it.visible) 1 else 0 } == 1 - val entityId = if (visible) field(S64LE) { it.entityId!! } else null - val requestTimeoutSeconds = if (visible) field(U16LE) { it.requestTimeoutSeconds!! } else null - val responseTimeoutSeconds = if (visible) field(U16LE) { it.responseTimeoutSeconds!! } else null - return RequestConfirmationPromptPacket( - visible, entityId, requestTimeoutSeconds, responseTimeoutSeconds - ) - } + override fun CodecScope.body(): RequestConfirmationPromptPacket { + val visible = field(U8) { if (it.visible) 1 else 0 } == 1 + val entityId = if (visible) field(S64LE) { it.entityId!! } else null + val requestTimeoutSeconds = if (visible) field(U16LE) { it.requestTimeoutSeconds!! } else null + val responseTimeoutSeconds = if (visible) field(U16LE) { it.responseTimeoutSeconds!! } else null + return RequestConfirmationPromptPacket( + visible, entityId, requestTimeoutSeconds, responseTimeoutSeconds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestEntityInteractionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestEntityInteractionPacket.kt index 9e550bc..87a322a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestEntityInteractionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestEntityInteractionPacket.kt @@ -10,9 +10,9 @@ data class RequestEntityInteractionPacket( ) object RequestEntityInteractionPacketCodec : PacketCodec() { - override fun CodecScope.body(): RequestEntityInteractionPacket { - val entityId = field(S64LE) { it.entityId } - val checksum = field(S64LE) { it.checksum } - return RequestEntityInteractionPacket(entityId, checksum) - } + override fun CodecScope.body(): RequestEntityInteractionPacket { + val entityId = field(S64LE) { it.entityId } + val checksum = field(S64LE) { it.checksum } + return RequestEntityInteractionPacket(entityId, checksum) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestNextBattleSequencePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestNextBattleSequencePacket.kt index 2922168..99fb6b5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestNextBattleSequencePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestNextBattleSequencePacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class RequestNextBattleSequencePacket object RequestNextBattleSequencePacketCodec : PacketCodec() { - override fun CodecScope.body(): RequestNextBattleSequencePacket { - return RequestNextBattleSequencePacket() - } + override fun CodecScope.body(): RequestNextBattleSequencePacket { + return RequestNextBattleSequencePacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestPlayerPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestPlayerPacket.kt index 2e0357f..b3f6f5c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestPlayerPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestPlayerPacket.kt @@ -6,5 +6,5 @@ import de.fiereu.bytecodec.PacketCodec class RequestPlayerPacket object RequestPlayerPacketCodec : PacketCodec() { - override fun CodecScope.body() = RequestPlayerPacket() + override fun CodecScope.body() = RequestPlayerPacket() } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestSocialProfilePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestSocialProfilePacket.kt index aeab71e..28f79e3 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestSocialProfilePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RequestSocialProfilePacket.kt @@ -9,8 +9,8 @@ data class RequestSocialProfilePacket( ) object RequestSocialProfilePacketCodec : PacketCodec() { - override fun CodecScope.body(): RequestSocialProfilePacket { - val targetId = field(S64LE) { it.targetId } - return RequestSocialProfilePacket(targetId) - } + override fun CodecScope.body(): RequestSocialProfilePacket { + val targetId = field(S64LE) { it.targetId } + return RequestSocialProfilePacket(targetId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RosterCooldownPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RosterCooldownPacket.kt index 78d8d77..29b3a92 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RosterCooldownPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/RosterCooldownPacket.kt @@ -9,8 +9,8 @@ data class RosterCooldownPacket( ) object RosterCooldownPacketCodec : PacketCodec() { - override fun CodecScope.body(): RosterCooldownPacket { - val cooldownOffsetSeconds = field(S32LE) { it.cooldownOffsetSeconds } - return RosterCooldownPacket(cooldownOffsetSeconds) - } + override fun CodecScope.body(): RosterCooldownPacket { + val cooldownOffsetSeconds = field(S32LE) { it.cooldownOffsetSeconds } + return RosterCooldownPacket(cooldownOffsetSeconds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SaveTemplateEntryPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SaveTemplateEntryPacket.kt index 9ff94b2..a0684af 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SaveTemplateEntryPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SaveTemplateEntryPacket.kt @@ -8,28 +8,28 @@ data class SaveTemplateEntryPacket( val entryKindId: Byte, val data: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is SaveTemplateEntryPacket && - templateSlot == other.templateSlot && - name == other.name && - entryKindId == other.entryKindId && - data.contentEquals(other.data) + override fun equals(other: Any?): Boolean = + other is SaveTemplateEntryPacket && + templateSlot == other.templateSlot && + name == other.name && + entryKindId == other.entryKindId && + data.contentEquals(other.data) - override fun hashCode(): Int { - var r = templateSlot.toInt() - r = r * 31 + name.hashCode() - r = r * 31 + entryKindId - r = r * 31 + data.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = templateSlot.toInt() + r = r * 31 + name.hashCode() + r = r * 31 + entryKindId + r = r * 31 + data.contentHashCode() + return r + } } object SaveTemplateEntryPacketCodec : PacketCodec() { - override fun CodecScope.body(): SaveTemplateEntryPacket { - val templateSlot = field(S8) { it.templateSlot } - val name = field(Utf16LeNullTerminated) { it.name } - val entryKindId = field(S8) { it.entryKindId } - val data = field(bytesPrefixed(U8)) { it.data } - return SaveTemplateEntryPacket(templateSlot, name, entryKindId, data) - } + override fun CodecScope.body(): SaveTemplateEntryPacket { + val templateSlot = field(S8) { it.templateSlot } + val name = field(Utf16LeNullTerminated) { it.name } + val entryKindId = field(S8) { it.entryKindId } + val data = field(bytesPrefixed(U8)) { it.data } + return SaveTemplateEntryPacket(templateSlot, name, entryKindId, data) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneEntityActionDispatchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneEntityActionDispatchPacket.kt index 7af7eda..96593a2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneEntityActionDispatchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneEntityActionDispatchPacket.kt @@ -11,9 +11,9 @@ data class SceneEntityActionDispatchPacket( ) object SceneEntityActionDispatchPacketCodec : PacketCodec() { - override fun CodecScope.body(): SceneEntityActionDispatchPacket { - val entityId = field(S64LE) { it.entityId } - val action = field(S8) { it.action } - return SceneEntityActionDispatchPacket(entityId, action) - } + override fun CodecScope.body(): SceneEntityActionDispatchPacket { + val entityId = field(S64LE) { it.entityId } + val action = field(S8) { it.action } + return SceneEntityActionDispatchPacket(entityId, action) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneObjectStatesPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneObjectStatesPacket.kt index fbdd506..51e92f8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneObjectStatesPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SceneObjectStatesPacket.kt @@ -21,28 +21,28 @@ data class SceneObjectStatesPacket( private val SceneObjectFrameCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): SceneObjectFrame { - val valueA = field(S16LE) { it.valueA } - val valueB = field(S16LE) { it.valueB } - val valueC = field(S32LE) { it.valueC } - val flag = field(U8) { if (it.flag) 1 else 0 } == 1 - return SceneObjectFrame(valueA, valueB, valueC, flag) - } + override fun CodecScope.body(): SceneObjectFrame { + val valueA = field(S16LE) { it.valueA } + val valueB = field(S16LE) { it.valueB } + val valueC = field(S32LE) { it.valueC } + val flag = field(U8) { if (it.flag) 1 else 0 } == 1 + return SceneObjectFrame(valueA, valueB, valueC, flag) + } } private val SceneObjectStateCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): SceneObjectState { - val objectId = field(S64LE) { it.objectId } - val type = field(S8) { it.type } - val frames = field(SceneObjectFrameCodec.listPrefixed(U8)) { it.frames } - return SceneObjectState(objectId, type, frames) - } + override fun CodecScope.body(): SceneObjectState { + val objectId = field(S64LE) { it.objectId } + val type = field(S8) { it.type } + val frames = field(SceneObjectFrameCodec.listPrefixed(U8)) { it.frames } + return SceneObjectState(objectId, type, frames) + } } object SceneObjectStatesPacketCodec : PacketCodec() { - override fun CodecScope.body(): SceneObjectStatesPacket { - val objects = field(SceneObjectStateCodec.listPrefixed(U8)) { it.objects } - return SceneObjectStatesPacket(objects) - } + override fun CodecScope.body(): SceneObjectStatesPacket { + val objects = field(SceneObjectStateCodec.listPrefixed(U8)) { it.objects } + return SceneObjectStatesPacket(objects) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectCharacterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectCharacterPacket.kt index 1e96938..a090376 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectCharacterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectCharacterPacket.kt @@ -7,9 +7,9 @@ import de.fiereu.bytecodec.S64LE data class SelectCharacterPacket(val characterId: Long, val characterIdHash: Long) object SelectCharacterPacketCodec : PacketCodec() { - override fun CodecScope.body(): SelectCharacterPacket { - val characterId = field(S64LE) { it.characterId } - val characterIdHash = field(S64LE) { it.characterIdHash } - return SelectCharacterPacket(characterId, characterIdHash) - } + override fun CodecScope.body(): SelectCharacterPacket { + val characterId = field(S64LE) { it.characterId } + val characterIdHash = field(S64LE) { it.characterIdHash } + return SelectCharacterPacket(characterId, characterIdHash) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectPartyPokemonPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectPartyPokemonPacket.kt index c1e3945..9a2ea20 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectPartyPokemonPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectPartyPokemonPacket.kt @@ -7,8 +7,8 @@ data class SelectPartyPokemonPacket( ) object SelectPartyPokemonPacketCodec : PacketCodec() { - override fun CodecScope.body(): SelectPartyPokemonPacket { - val entityIds = field(S64LE.listPrefixed(U8)) { it.entityIds } - return SelectPartyPokemonPacket(entityIds) - } + override fun CodecScope.body(): SelectPartyPokemonPacket { + val entityIds = field(S64LE.listPrefixed(U8)) { it.entityIds } + return SelectPartyPokemonPacket(entityIds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectSinglePokemonPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectSinglePokemonPacket.kt index b8cd195..7bad624 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectSinglePokemonPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectSinglePokemonPacket.kt @@ -9,8 +9,8 @@ data class SelectSinglePokemonPacket( ) object SelectSinglePokemonPacketCodec : PacketCodec() { - override fun CodecScope.body(): SelectSinglePokemonPacket { - val entityId = field(S64LE) { it.entityId } - return SelectSinglePokemonPacket(entityId) - } + override fun CodecScope.body(): SelectSinglePokemonPacket { + val entityId = field(S64LE) { it.entityId } + return SelectSinglePokemonPacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectedCharacterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectedCharacterPacket.kt index 86c819d..01ea582 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectedCharacterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectedCharacterPacket.kt @@ -11,8 +11,8 @@ data class SelectedCharacterPacket(val character: CharacterInfo?) private val OptionalCharacterInfo = CharacterInfoCodecShort.optional() object SelectedCharacterPacketCodec : PacketCodec() { - override fun CodecScope.body() = - SelectedCharacterPacket( - character = field(OptionalCharacterInfo, SelectedCharacterPacket::character), - ) + override fun CodecScope.body() = + SelectedCharacterPacket( + character = field(OptionalCharacterInfo, SelectedCharacterPacket::character), + ) } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectionListWindowOpenPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectionListWindowOpenPacket.kt index 72dbce9..956abe3 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectionListWindowOpenPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SelectionListWindowOpenPacket.kt @@ -3,10 +3,10 @@ package de.fiereu.openmmo.net.game.packets import de.fiereu.bytecodec.* sealed class ListWindowMessageArg { - abstract val argId: Byte - abstract val typeTag: Byte - abstract val hasExtra: Boolean - abstract val extra: Byte + abstract val argId: Byte + abstract val typeTag: Byte + abstract val hasExtra: Boolean + abstract val extra: Byte } data class ListWindowByteArg( @@ -50,41 +50,41 @@ data class ListWindowShortsArg( internal val ListWindowMessageArgCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ListWindowMessageArg { - val argId = field(S8) { it.argId } - val rawType = - field(S8) { v -> if (v.hasExtra) (v.typeTag.toInt() or 128).toByte() else v.typeTag } - val hasExtra = (rawType.toInt() and 128) != 0 - val typeTag = if (hasExtra) (rawType.toInt() and 127).toByte() else rawType - val extra: Byte = if (hasExtra) field(S8) { it.extra } else 0 - return when (typeTag.toInt()) { - 28 -> ListWindowByteArg(argId, typeTag, hasExtra, extra) - 30 -> { - val value = field(S64LE) { (it as ListWindowLongArg).value } - ListWindowLongArg(argId, typeTag, hasExtra, extra, value) - } + override fun CodecScope.body(): ListWindowMessageArg { + val argId = field(S8) { it.argId } + val rawType = + field(S8) { v -> if (v.hasExtra) (v.typeTag.toInt() or 128).toByte() else v.typeTag } + val hasExtra = (rawType.toInt() and 128) != 0 + val typeTag = if (hasExtra) (rawType.toInt() and 127).toByte() else rawType + val extra: Byte = if (hasExtra) field(S8) { it.extra } else 0 + return when (typeTag.toInt()) { + 28 -> ListWindowByteArg(argId, typeTag, hasExtra, extra) + 30 -> { + val value = field(S64LE) { (it as ListWindowLongArg).value } + ListWindowLongArg(argId, typeTag, hasExtra, extra, value) + } - 9, - 10, - 17 -> { - val value = field(S32LE) { (it as ListWindowIntArg).value } - ListWindowIntArg(argId, typeTag, hasExtra, extra, value) - } + 9, + 10, + 17 -> { + val value = field(S32LE) { (it as ListWindowIntArg).value } + ListWindowIntArg(argId, typeTag, hasExtra, extra, value) + } - 5, - 18 -> { - val text = field(Utf16LeNullTerminated) { (it as ListWindowStringArg).text } - ListWindowStringArg(argId, typeTag, hasExtra, extra, text) - } + 5, + 18 -> { + val text = field(Utf16LeNullTerminated) { (it as ListWindowStringArg).text } + ListWindowStringArg(argId, typeTag, hasExtra, extra, text) + } - else -> { - val count = field(U8) { (it as ListWindowShortsArg).values.size } - val values = - (0 until count).map { i -> field(S16LE) { (it as ListWindowShortsArg).values[i] } } - ListWindowShortsArg(argId, typeTag, hasExtra, extra, values) - } - } + else -> { + val count = field(U8) { (it as ListWindowShortsArg).values.size } + val values = + (0 until count).map { i -> field(S16LE) { (it as ListWindowShortsArg).values[i] } } + ListWindowShortsArg(argId, typeTag, hasExtra, extra, values) + } } + } } data class ListWindowEntry( @@ -101,19 +101,19 @@ data class SelectionListWindowOpenPacket( ) object SelectionListWindowOpenPacketCodec : PacketCodec() { - override fun CodecScope.body(): SelectionListWindowOpenPacket { - val windowId = field(S32LE) { it.windowId } - val type = field(S8) { it.type } - val flag = field(U8) { if (it.flag) 1 else 0 } == 1 - val count = field(S8) { it.entries.size.toByte() }.toInt() - val entries = - (0 until count).map { i -> - val id = field(S32LE) { it.entries[i].id } - val value = field(S32LE) { it.entries[i].value } - val present = field(U8) { if (it.entries[i].arg != null) 1 else 0 } == 1 - val arg = if (present) field(ListWindowMessageArgCodec) { it.entries[i].arg!! } else null - ListWindowEntry(id, value, arg) - } - return SelectionListWindowOpenPacket(windowId, type, flag, entries) - } + override fun CodecScope.body(): SelectionListWindowOpenPacket { + val windowId = field(S32LE) { it.windowId } + val type = field(S8) { it.type } + val flag = field(U8) { if (it.flag) 1 else 0 } == 1 + val count = field(S8) { it.entries.size.toByte() }.toInt() + val entries = + (0 until count).map { i -> + val id = field(S32LE) { it.entries[i].id } + val value = field(S32LE) { it.entries[i].value } + val present = field(U8) { if (it.entries[i].arg != null) 1 else 0 } == 1 + val arg = if (present) field(ListWindowMessageArgCodec) { it.entries[i].arg!! } else null + ListWindowEntry(id, value, arg) + } + return SelectionListWindowOpenPacket(windowId, type, flag, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendChatCommandPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendChatCommandPacket.kt index a4df2f3..bf9eab0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendChatCommandPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendChatCommandPacket.kt @@ -9,8 +9,8 @@ data class SendChatCommandPacket( ) object SendChatCommandPacketCodec : PacketCodec() { - override fun CodecScope.body(): SendChatCommandPacket { - val message = field(Utf16LeNullTerminated) { it.message } - return SendChatCommandPacket(message) - } + override fun CodecScope.body(): SendChatCommandPacket { + val message = field(Utf16LeNullTerminated) { it.message } + return SendChatCommandPacket(message) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendDirectMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendDirectMessagePacket.kt index f4e8a5c..6b0a33c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendDirectMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SendDirectMessagePacket.kt @@ -10,9 +10,9 @@ data class SendDirectMessagePacket( ) object SendDirectMessagePacketCodec : PacketCodec() { - override fun CodecScope.body(): SendDirectMessagePacket { - val senderContextId = field(S64LE) { it.senderContextId } - val recipientId = field(S64LE) { it.recipientId } - return SendDirectMessagePacket(senderContextId, recipientId) - } + override fun CodecScope.body(): SendDirectMessagePacket { + val senderContextId = field(S64LE) { it.senderContextId } + val recipientId = field(S64LE) { it.recipientId } + return SendDirectMessagePacket(senderContextId, recipientId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5002Packet.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5002Packet.kt index 76c413d..6ae7721 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5002Packet.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5002Packet.kt @@ -10,9 +10,9 @@ data class ServerChatTemplate5002Packet( ) object ServerChatTemplate5002PacketCodec : PacketCodec() { - override fun CodecScope.body(): ServerChatTemplate5002Packet { - field(S64LE) { 0L } - val argument = field(Utf16LeNullTerminated) { it.argument } - return ServerChatTemplate5002Packet(argument) - } + override fun CodecScope.body(): ServerChatTemplate5002Packet { + field(S64LE) { 0L } + val argument = field(Utf16LeNullTerminated) { it.argument } + return ServerChatTemplate5002Packet(argument) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5003Packet.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5003Packet.kt index caf868e..c10477a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5003Packet.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerChatTemplate5003Packet.kt @@ -10,9 +10,9 @@ data class ServerChatTemplate5003Packet( ) object ServerChatTemplate5003PacketCodec : PacketCodec() { - override fun CodecScope.body(): ServerChatTemplate5003Packet { - field(S64LE) { 0L } - val argument = field(Utf16LeNullTerminated) { it.argument } - return ServerChatTemplate5003Packet(argument) - } + override fun CodecScope.body(): ServerChatTemplate5003Packet { + field(S64LE) { 0L } + val argument = field(Utf16LeNullTerminated) { it.argument } + return ServerChatTemplate5003Packet(argument) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerEndpointListPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerEndpointListPacket.kt index e3500f1..47487e9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerEndpointListPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerEndpointListPacket.kt @@ -20,45 +20,45 @@ data class ServerEndpointListPacket( val digest: ByteArray, val endpoints: List, ) { - override fun equals(other: Any?): Boolean = - other is ServerEndpointListPacket && - digest.contentEquals(other.digest) && - endpoints == other.endpoints + override fun equals(other: Any?): Boolean = + other is ServerEndpointListPacket && + digest.contentEquals(other.digest) && + endpoints == other.endpoints - override fun hashCode(): Int = digest.contentHashCode() * 31 + endpoints.hashCode() + override fun hashCode(): Int = digest.contentHashCode() * 31 + endpoints.hashCode() } private val NetAddressCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): NetAddress { - val tag = field(U8) { it.tag } - return if (tag == 4) { - val handle = field(S32LE) { it.handle!! } - NetAddress(tag, handle, null, null) - } else { - val idHigh = field(S64LE) { it.idHigh!! } - val idLow = field(S64LE) { it.idLow!! } - NetAddress(tag, null, idHigh, idLow) - } + override fun CodecScope.body(): NetAddress { + val tag = field(U8) { it.tag } + return if (tag == 4) { + val handle = field(S32LE) { it.handle!! } + NetAddress(tag, handle, null, null) + } else { + val idHigh = field(S64LE) { it.idHigh!! } + val idLow = field(S64LE) { it.idLow!! } + NetAddress(tag, null, idHigh, idLow) } + } } private val GameServerEndpointCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): GameServerEndpoint { - field(S8) { 0 } - val publicAddress = field(NetAddressCodec) { it.publicAddress } - val privateAddress = field(NetAddressCodec) { it.privateAddress } - val port = field(S16LE) { it.port } - val flags = field(S8) { it.flags } - return GameServerEndpoint(publicAddress, privateAddress, port, flags) - } + override fun CodecScope.body(): GameServerEndpoint { + field(S8) { 0 } + val publicAddress = field(NetAddressCodec) { it.publicAddress } + val privateAddress = field(NetAddressCodec) { it.privateAddress } + val port = field(S16LE) { it.port } + val flags = field(S8) { it.flags } + return GameServerEndpoint(publicAddress, privateAddress, port, flags) + } } object ServerEndpointListPacketCodec : PacketCodec() { - override fun CodecScope.body(): ServerEndpointListPacket { - val digest = field(bytesPrefixed(U8)) { it.digest } - val endpoints = field(GameServerEndpointCodec.listPrefixed(U8)) { it.endpoints } - return ServerEndpointListPacket(digest, endpoints) - } + override fun CodecScope.body(): ServerEndpointListPacket { + val digest = field(bytesPrefixed(U8)) { it.digest } + val endpoints = field(GameServerEndpointCodec.listPrefixed(U8)) { it.endpoints } + return ServerEndpointListPacket(digest, endpoints) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt index 5b0017c..dbdf451 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerMessagePacket.kt @@ -22,42 +22,41 @@ data class ServerMessagePacket( private val ServerMessageArgCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): ServerMessageArg { - val argId = field(S8) { it.argId } - val typeRaw = field(U8) { if (it.hasExtra) it.type or 128 else it.type } - val hasExtra = (typeRaw and 128) != 0 - val type = if (hasExtra) typeRaw and 127 else typeRaw - val extra = if (hasExtra) field(S8) { it.extra } else 0 - var longValue: Long? = null - var intValue: Int? = null - var stringValue: String? = null - var shortValues: List? = null - when { - type == 5 || type == 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! } - type == 28 -> {} - type == 30 -> longValue = field(S64LE) { it.longValue!! } - type == 9 || type == 10 || type == 17 -> intValue = field(S32LE) { it.intValue!! } - else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! } - } - return ServerMessageArg( - argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues - ) + override fun CodecScope.body(): ServerMessageArg { + val argId = field(S8) { it.argId } + val typeRaw = field(U8) { if (it.hasExtra) it.type or 128 else it.type } + val hasExtra = (typeRaw and 128) != 0 + val type = if (hasExtra) typeRaw and 127 else typeRaw + val extra = if (hasExtra) field(S8) { it.extra } else 0 + var longValue: Long? = null + var intValue: Int? = null + var stringValue: String? = null + var shortValues: List? = null + when { + type == 5 || type == 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! } + type == 28 -> {} + type == 30 -> longValue = field(S64LE) { it.longValue!! } + type == 9 || type == 10 || type == 17 -> intValue = field(S32LE) { it.intValue!! } + else -> shortValues = field(S16LE.listPrefixed(U8)) { it.shortValues!! } } + return ServerMessageArg( + argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues) + } } object ServerMessagePacketCodec : PacketCodec() { - override fun CodecScope.body(): ServerMessagePacket { - val stringId = field(S32LE) { it.stringId } - val flags = - field(U8) { - (it.args.size and 63) or - (if (it.showOnMap) 64 else 0) or - (if (it.mode != null) 128 else 0) - } - val count = flags and 63 - val args = (0 until count).map { i -> field(ServerMessageArgCodec) { it.args[i] } } - val showOnMap = (flags and 64) != 0 - val mode = if (flags and 128 != 0) field(S8) { it.mode!! } else null - return ServerMessagePacket(stringId, args, showOnMap, mode) - } + override fun CodecScope.body(): ServerMessagePacket { + val stringId = field(S32LE) { it.stringId } + val flags = + field(U8) { + (it.args.size and 63) or + (if (it.showOnMap) 64 else 0) or + (if (it.mode != null) 128 else 0) + } + val count = flags and 63 + val args = (0 until count).map { i -> field(ServerMessageArgCodec) { it.args[i] } } + val showOnMap = (flags and 64) != 0 + val mode = if (flags and 128 != 0) field(S8) { it.mode!! } else null + return ServerMessagePacket(stringId, args, showOnMap, mode) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerNoticePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerNoticePacket.kt index 3a828c3..a936f06 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerNoticePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ServerNoticePacket.kt @@ -9,10 +9,10 @@ data class ServerNoticePacket( ) object ServerNoticePacketCodec : PacketCodec() { - override fun CodecScope.body(): ServerNoticePacket { - val type = field(S16LE, ServerNoticePacket::type) - val id = field(S32LE, ServerNoticePacket::id) - val message = field(Utf16LeNullTerminated, ServerNoticePacket::message) - return ServerNoticePacket(type, id, message) - } + override fun CodecScope.body(): ServerNoticePacket { + val type = field(S16LE, ServerNoticePacket::type) + val id = field(S32LE, ServerNoticePacket::id) + val message = field(Utf16LeNullTerminated, ServerNoticePacket::message) + return ServerNoticePacket(type, id, message) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionExpiryInitPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionExpiryInitPacket.kt index 072e512..38c5d75 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionExpiryInitPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionExpiryInitPacket.kt @@ -11,9 +11,9 @@ data class SessionExpiryInitPacket( ) object SessionExpiryInitPacketCodec : PacketCodec() { - override fun CodecScope.body(): SessionExpiryInitPacket { - val tileSessionByte = field(S8) { it.tileSessionByte } - val expirySeconds = field(S16LE) { it.expirySeconds } - return SessionExpiryInitPacket(tileSessionByte, expirySeconds) - } + override fun CodecScope.body(): SessionExpiryInitPacket { + val tileSessionByte = field(S8) { it.tileSessionByte } + val expirySeconds = field(S16LE) { it.expirySeconds } + return SessionExpiryInitPacket(tileSessionByte, expirySeconds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionInitAcknowledgePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionInitAcknowledgePacket.kt index 6336652..1318f9e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionInitAcknowledgePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SessionInitAcknowledgePacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec data class SessionInitAcknowledgePacket(val placeholder: Unit = Unit) object SessionInitAcknowledgePacketCodec : PacketCodec() { - override fun CodecScope.body(): SessionInitAcknowledgePacket { - return SessionInitAcknowledgePacket() - } + override fun CodecScope.body(): SessionInitAcknowledgePacket { + return SessionInitAcknowledgePacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetActiveMovesetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetActiveMovesetPacket.kt index e114e01..cf1db96 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetActiveMovesetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetActiveMovesetPacket.kt @@ -7,38 +7,38 @@ data class SetActiveMovesetPacket( val pokemonEntityId: Long, val moveIds: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is SetActiveMovesetPacket && - partySlot == other.partySlot && - pokemonEntityId == other.pokemonEntityId && - moveIds.contentEquals(other.moveIds) + override fun equals(other: Any?): Boolean = + other is SetActiveMovesetPacket && + partySlot == other.partySlot && + pokemonEntityId == other.pokemonEntityId && + moveIds.contentEquals(other.moveIds) - override fun hashCode(): Int { - var r = partySlot.toInt() - r = r * 31 + pokemonEntityId.hashCode() - r = r * 31 + moveIds.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = partySlot.toInt() + r = r * 31 + pokemonEntityId.hashCode() + r = r * 31 + moveIds.contentHashCode() + return r + } } private val MoveIdsCodec: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object SetActiveMovesetPacketCodec : PacketCodec() { - override fun CodecScope.body(): SetActiveMovesetPacket { - val partySlot = field(S16LE) { it.partySlot } - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val moveIds = field(MoveIdsCodec) { it.moveIds } - return SetActiveMovesetPacket(partySlot, pokemonEntityId, moveIds) - } + override fun CodecScope.body(): SetActiveMovesetPacket { + val partySlot = field(S16LE) { it.partySlot } + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val moveIds = field(MoveIdsCodec) { it.moveIds } + return SetActiveMovesetPacket(partySlot, pokemonEntityId, moveIds) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetBattleMonsterAppearancePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetBattleMonsterAppearancePacket.kt index 1e8d85d..67d06d9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetBattleMonsterAppearancePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetBattleMonsterAppearancePacket.kt @@ -11,29 +11,26 @@ data class SetBattleMonsterAppearancePacket( private val ColorPaletteCodec: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val list = ArrayList() - while (buf.remaining() >= 2) { - list.add(S16LE.read(buf)) - } - return list + override fun read(buf: ReadBuffer): List { + val list = ArrayList() + while (buf.remaining() >= 2) { + list.add(S16LE.read(buf)) } + return list + } - override fun write(buf: WriteBuffer, value: List) { - for (entry in value) S16LE.write(buf, entry) - } + override fun write(buf: WriteBuffer, value: List) { + for (entry in value) S16LE.write(buf, entry) + } } -object SetBattleMonsterAppearancePacketCodec : - PacketCodec() { - override fun CodecScope.body(): - SetBattleMonsterAppearancePacket { - val partySlot = field(S16LE) { it.partySlot } - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val shininessType = field(S8) { it.shininessType } - val colorPalette = field(ColorPaletteCodec) { it.colorPalette } - return SetBattleMonsterAppearancePacket( - partySlot, pokemonEntityId, shininessType, colorPalette - ) - } +object SetBattleMonsterAppearancePacketCodec : PacketCodec() { + override fun CodecScope.body(): + SetBattleMonsterAppearancePacket { + val partySlot = field(S16LE) { it.partySlot } + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val shininessType = field(S8) { it.shininessType } + val colorPalette = field(ColorPaletteCodec) { it.colorPalette } + return SetBattleMonsterAppearancePacket(partySlot, pokemonEntityId, shininessType, colorPalette) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetCharacterNamePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetCharacterNamePacket.kt index 86b699b..ba78caa 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetCharacterNamePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetCharacterNamePacket.kt @@ -11,9 +11,9 @@ data class SetCharacterNamePacket( ) object SetCharacterNamePacketCodec : PacketCodec() { - override fun CodecScope.body(): SetCharacterNamePacket { - val characterEntityId = field(S64LE) { it.characterEntityId } - val newName = field(Utf16LeNullTerminated) { it.newName } - return SetCharacterNamePacket(characterEntityId, newName) - } + override fun CodecScope.body(): SetCharacterNamePacket { + val characterEntityId = field(S64LE) { it.characterEntityId } + val newName = field(Utf16LeNullTerminated) { it.newName } + return SetCharacterNamePacket(characterEntityId, newName) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetChatUserIgnoredPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetChatUserIgnoredPacket.kt index 809822d..865f4ca 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetChatUserIgnoredPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetChatUserIgnoredPacket.kt @@ -9,10 +9,10 @@ data class SetChatUserIgnoredPacket( ) object SetChatUserIgnoredPacketCodec : PacketCodec() { - override fun CodecScope.body(): SetChatUserIgnoredPacket { - val channelType = field(S8) { it.channelType } - val userId = field(S16LE) { it.userId } - val ignored = field(Bool) { it.ignored } - return SetChatUserIgnoredPacket(channelType, userId, ignored) - } + override fun CodecScope.body(): SetChatUserIgnoredPacket { + val channelType = field(S8) { it.channelType } + val userId = field(S16LE) { it.userId } + val ignored = field(Bool) { it.ignored } + return SetChatUserIgnoredPacket(channelType, userId, ignored) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetPlayerTitlePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetPlayerTitlePacket.kt deleted file mode 100644 index d5770f5..0000000 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SetPlayerTitlePacket.kt +++ /dev/null @@ -1,14 +0,0 @@ -package de.fiereu.openmmo.net.game.packets - -import de.fiereu.bytecodec.CodecScope -import de.fiereu.bytecodec.PacketCodec -import de.fiereu.bytecodec.Utf16LeNullTerminated - -data class SetPlayerTitlePacket(val titleText: String) - -object SetPlayerTitlePacketCodec : PacketCodec() { - override fun CodecScope.body(): SetPlayerTitlePacket { - val titleText = field(Utf16LeNullTerminated) { it.titleText } - return SetPlayerTitlePacket(titleText) - } -} diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopPriceTablePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopPriceTablePacket.kt index b60f7ab..5fe85b1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopPriceTablePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopPriceTablePacket.kt @@ -10,9 +10,9 @@ data class ShopPriceTablePacket( private val PriceEntryCodec: Codec> = S16LE.then(S16LE) object ShopPriceTablePacketCodec : PacketCodec() { - override fun CodecScope.body(): ShopPriceTablePacket { - val category = field(S8) { it.category } - val prices = field(PriceEntryCodec.listPrefixed(U16LE)) { it.prices } - return ShopPriceTablePacket(category, prices) - } + override fun CodecScope.body(): ShopPriceTablePacket { + val category = field(S8) { it.category } + val prices = field(PriceEntryCodec.listPrefixed(U16LE)) { it.prices } + return ShopPriceTablePacket(category, prices) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopSellRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopSellRequestPacket.kt index 12a4bf5..5c79c35 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopSellRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ShopSellRequestPacket.kt @@ -11,9 +11,9 @@ data class ShopSellRequestPacket( ) object ShopSellRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): ShopSellRequestPacket { - val itemEntityId = field(S64LE) { it.itemEntityId } - val quantity = field(S16LE) { it.quantity } - return ShopSellRequestPacket(itemEntityId, quantity) - } + override fun CodecScope.body(): ShopSellRequestPacket { + val itemEntityId = field(S64LE) { it.itemEntityId } + val quantity = field(S16LE) { it.quantity } + return ShopSellRequestPacket(itemEntityId, quantity) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt index f0e37e3..0bd13a7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialActionOutcomePacket.kt @@ -9,14 +9,12 @@ data class SocialActionOutcomePacket( ) object SocialActionOutcomePacketCodec : PacketCodec() { - override fun CodecScope.body(): SocialActionOutcomePacket { - val action = field(U8) { it.action } - val entityId: Long? = - if (resolveKind(action) == 1) field(S64LE) { it.entityId!! } else null - val value: Short? = - if (resolveKind(action) == 2) field(S16LE) { it.value!! } else null - return SocialActionOutcomePacket(action, entityId, value) - } + override fun CodecScope.body(): SocialActionOutcomePacket { + val action = field(U8) { it.action } + val entityId: Long? = if (resolveKind(action) == 1) field(S64LE) { it.entityId!! } else null + val value: Short? = if (resolveKind(action) == 2) field(S16LE) { it.value!! } else null + return SocialActionOutcomePacket(action, entityId, value) + } - private fun resolveKind(action: Int): Int = 0 + private fun resolveKind(action: Int): Int = 0 } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryFlagSetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryFlagSetPacket.kt index 02aa5ff..c0769ed 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryFlagSetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryFlagSetPacket.kt @@ -9,10 +9,10 @@ data class SocialEntryFlagSetPacket( ) object SocialEntryFlagSetPacketCodec : PacketCodec() { - override fun CodecScope.body(): SocialEntryFlagSetPacket { - val playerId = field(S64LE) { it.playerId } - val flag = field(S8) { it.flag } - val value = field(S16LE) { it.value } - return SocialEntryFlagSetPacket(playerId, flag, value) - } + override fun CodecScope.body(): SocialEntryFlagSetPacket { + val playerId = field(S64LE) { it.playerId } + val flag = field(S8) { it.flag } + val value = field(S16LE) { it.value } + return SocialEntryFlagSetPacket(playerId, flag, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryPresencePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryPresencePacket.kt index ed1956a..df464ea 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryPresencePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryPresencePacket.kt @@ -9,10 +9,10 @@ data class SocialEntryPresencePacket( ) object SocialEntryPresencePacketCodec : PacketCodec() { - override fun CodecScope.body(): SocialEntryPresencePacket { - val playerId = field(S64LE) { it.playerId } - val status = field(S16LE) { it.status } - val online = field(Bool) { it.online } - return SocialEntryPresencePacket(playerId, status, online) - } + override fun CodecScope.body(): SocialEntryPresencePacket { + val playerId = field(S64LE) { it.playerId } + val status = field(S16LE) { it.status } + val online = field(Bool) { it.online } + return SocialEntryPresencePacket(playerId, status, online) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryRenamePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryRenamePacket.kt index b95fb1f..9ecd1d8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryRenamePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialEntryRenamePacket.kt @@ -9,10 +9,10 @@ data class SocialEntryRenamePacket( ) object SocialEntryRenamePacketCodec : PacketCodec() { - override fun CodecScope.body(): SocialEntryRenamePacket { - val playerId = field(S64LE) { it.playerId } - val errorCode = field(S8) { it.errorCode } - val name = if (errorCode.toInt() == 0) field(Utf16LeNullTerminated) { it.name!! } else null - return SocialEntryRenamePacket(playerId, errorCode, name) - } + override fun CodecScope.body(): SocialEntryRenamePacket { + val playerId = field(S64LE) { it.playerId } + val errorCode = field(S8) { it.errorCode } + val name = if (errorCode.toInt() == 0) field(Utf16LeNullTerminated) { it.name!! } else null + return SocialEntryRenamePacket(playerId, errorCode, name) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryAddPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryAddPacket.kt index f8f66d8..6c44f1b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryAddPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryAddPacket.kt @@ -10,8 +10,8 @@ data class SocialListEntryAddPacket( ) object SocialListEntryAddPacketCodec : PacketCodec() { - override fun CodecScope.body(): SocialListEntryAddPacket { - val pokemon = field(PokemonCodec) { it.pokemon } - return SocialListEntryAddPacket(pokemon) - } + override fun CodecScope.body(): SocialListEntryAddPacket { + val pokemon = field(PokemonCodec) { it.pokemon } + return SocialListEntryAddPacket(pokemon) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryRemovePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryRemovePacket.kt index f5f8d5d..b184682 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryRemovePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialListEntryRemovePacket.kt @@ -11,9 +11,9 @@ data class SocialListEntryRemovePacket( ) object SocialListEntryRemovePacketCodec : PacketCodec() { - override fun CodecScope.body(): SocialListEntryRemovePacket { - val listType = field(S8) { it.listType } - val entityId = field(S64LE) { it.entityId } - return SocialListEntryRemovePacket(listType, entityId) - } + override fun CodecScope.body(): SocialListEntryRemovePacket { + val listType = field(S8) { it.listType } + val entityId = field(S64LE) { it.entityId } + return SocialListEntryRemovePacket(listType, entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialProfileDialogOpenPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialProfileDialogOpenPacket.kt index d003d14..aef6069 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialProfileDialogOpenPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SocialProfileDialogOpenPacket.kt @@ -12,9 +12,9 @@ data class SocialProfileDialogOpenPacket( ) object SocialProfileDialogOpenPacketCodec : PacketCodec() { - override fun CodecScope.body(): SocialProfileDialogOpenPacket { - val status = field(S8) { it.status } - val content = if (status.toInt() == 0) field(PokemonCodec) { it.content!! } else null - return SocialProfileDialogOpenPacket(status, content) - } + override fun CodecScope.body(): SocialProfileDialogOpenPacket { + val status = field(S8) { it.status } + val content = if (status.toInt() == 0) field(PokemonCodec) { it.content!! } else null + return SocialProfileDialogOpenPacket(status, content) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupDeletePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupDeletePacket.kt index 0fb0b37..4c0aae1 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupDeletePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupDeletePacket.kt @@ -11,9 +11,9 @@ data class SpatialGroupDeletePacket( ) object SpatialGroupDeletePacketCodec : PacketCodec() { - override fun CodecScope.body(): SpatialGroupDeletePacket { - val group = field(U8) { it.group } - val entityId = field(S64LE) { it.entityId } - return SpatialGroupDeletePacket(group, entityId) - } + override fun CodecScope.body(): SpatialGroupDeletePacket { + val group = field(U8) { it.group } + val entityId = field(S64LE) { it.entityId } + return SpatialGroupDeletePacket(group, entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupInsertPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupInsertPacket.kt index f9bc354..0e004be 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupInsertPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupInsertPacket.kt @@ -11,13 +11,12 @@ data class SpatialGroupInsertPacket( ) object SpatialGroupInsertPacketCodec : PacketCodec() { - override fun CodecScope.body(): SpatialGroupInsertPacket { - val group = field(U8) { it.group } - val entityId = field(S64LE) { it.entityId } - val value = field(S16LE) { it.value } - val extraCoordPresent = false - val extraValue: Short? = - if (extraCoordPresent) field(S16LE) { it.extraValue ?: 0 } else null - return SpatialGroupInsertPacket(group, entityId, value, extraCoordPresent, extraValue) - } + override fun CodecScope.body(): SpatialGroupInsertPacket { + val group = field(U8) { it.group } + val entityId = field(S64LE) { it.entityId } + val value = field(S16LE) { it.value } + val extraCoordPresent = false + val extraValue: Short? = if (extraCoordPresent) field(S16LE) { it.extraValue ?: 0 } else null + return SpatialGroupInsertPacket(group, entityId, value, extraCoordPresent, extraValue) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupSnapshotPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupSnapshotPacket.kt index c732669..5329de3 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupSnapshotPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpatialGroupSnapshotPacket.kt @@ -15,18 +15,18 @@ data class SpatialGroupSnapshotPacket( ) object SpatialGroupSnapshotPacketCodec : PacketCodec() { - override fun CodecScope.body(): SpatialGroupSnapshotPacket { - val group = field(U8) { it.group } - val extraCoordPresent = false - val count = field(U16LE) { it.entries.size } - val entries = ArrayList(count) - repeat(count) { i -> - val entityId = field(S64LE) { it.entries[i].entityId } - val value = field(S16LE) { it.entries[i].value } - val extraValue: Short? = - if (extraCoordPresent) field(S16LE) { it.entries[i].extraValue ?: 0 } else null - entries.add(SpatialGroupEntry(entityId, value, extraValue)) - } - return SpatialGroupSnapshotPacket(group, extraCoordPresent, entries) + override fun CodecScope.body(): SpatialGroupSnapshotPacket { + val group = field(U8) { it.group } + val extraCoordPresent = false + val count = field(U16LE) { it.entries.size } + val entries = ArrayList(count) + repeat(count) { i -> + val entityId = field(S64LE) { it.entries[i].entityId } + val value = field(S16LE) { it.entries[i].value } + val extraValue: Short? = + if (extraCoordPresent) field(S16LE) { it.entries[i].extraValue ?: 0 } else null + entries.add(SpatialGroupEntry(entityId, value, extraValue)) } + return SpatialGroupSnapshotPacket(group, extraCoordPresent, entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpectateRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpectateRequestPacket.kt index 1aa2997..09f1820 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpectateRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SpectateRequestPacket.kt @@ -9,8 +9,8 @@ data class SpectateRequestPacket( ) object SpectateRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): SpectateRequestPacket { - val targetEntityId = field(S64LE) { it.targetEntityId } - return SpectateRequestPacket(targetEntityId) - } + override fun CodecScope.body(): SpectateRequestPacket { + val targetEntityId = field(S64LE) { it.targetEntityId } + return SpectateRequestPacket(targetEntityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxClosePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxClosePacket.kt index b786d8f..df59d55 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxClosePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxClosePacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec data class StorageBoxClosePacket(val placeholder: Unit = Unit) object StorageBoxClosePacketCodec : PacketCodec() { - override fun CodecScope.body(): StorageBoxClosePacket { - return StorageBoxClosePacket() - } + override fun CodecScope.body(): StorageBoxClosePacket { + return StorageBoxClosePacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxEntriesRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxEntriesRequestPacket.kt index ddf3c99..93e506f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxEntriesRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxEntriesRequestPacket.kt @@ -9,10 +9,10 @@ data class StorageBoxEntriesRequestPacket( ) object StorageBoxEntriesRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): StorageBoxEntriesRequestPacket { - val listType = field(S8) { it.listType } - val itemIds = field(S32LE.listPrefixed(U8)) { it.itemIds } - val flags = field(S16LE) { it.flags } - return StorageBoxEntriesRequestPacket(listType, itemIds, flags) - } + override fun CodecScope.body(): StorageBoxEntriesRequestPacket { + val listType = field(S8) { it.listType } + val itemIds = field(S32LE.listPrefixed(U8)) { it.itemIds } + val flags = field(S16LE) { it.flags } + return StorageBoxEntriesRequestPacket(listType, itemIds, flags) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxFilterPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxFilterPacket.kt index 5fa6804..3e248f2 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxFilterPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxFilterPacket.kt @@ -7,34 +7,33 @@ data class StorageBoxFilterPacket( val boxName: String?, val cookieData: ByteArray?, ) { - override fun equals(other: Any?): Boolean = - other is StorageBoxFilterPacket && - listTypeIndex == other.listTypeIndex && - boxName == other.boxName && - (cookieData?.contentEquals(other.cookieData ?: ByteArray(0)) ?: (other.cookieData == null)) + override fun equals(other: Any?): Boolean = + other is StorageBoxFilterPacket && + listTypeIndex == other.listTypeIndex && + boxName == other.boxName && + (cookieData?.contentEquals(other.cookieData ?: ByteArray(0)) + ?: (other.cookieData == null)) - override fun hashCode(): Int { - var r = listTypeIndex?.hashCode() ?: 0 - r = r * 31 + (boxName?.hashCode() ?: 0) - r = r * 31 + (cookieData?.contentHashCode() ?: 0) - return r - } + override fun hashCode(): Int { + var r = listTypeIndex?.hashCode() ?: 0 + r = r * 31 + (boxName?.hashCode() ?: 0) + r = r * 31 + (cookieData?.contentHashCode() ?: 0) + return r + } } private val CookieBytes = bytesPrefixed(U8) object StorageBoxFilterPacketCodec : PacketCodec() { - override fun CodecScope.body(): StorageBoxFilterPacket { - val typeFlags = - field(U8) { - (if (it.boxName != null) 1 else 0) or (if (it.cookieData != null) 2 else 0) - } - val listTypeIndex: Byte? = - if (typeFlags and 1 != 0) field(S8) { it.listTypeIndex ?: 0 } else null - val boxName: String? = - if (typeFlags and 1 != 0) field(Utf16LeNullTerminated) { it.boxName ?: "" } else null - val cookieData: ByteArray? = - if (typeFlags and 2 != 0) field(CookieBytes) { it.cookieData ?: ByteArray(0) } else null - return StorageBoxFilterPacket(listTypeIndex, boxName, cookieData) - } + override fun CodecScope.body(): StorageBoxFilterPacket { + val typeFlags = + field(U8) { (if (it.boxName != null) 1 else 0) or (if (it.cookieData != null) 2 else 0) } + val listTypeIndex: Byte? = + if (typeFlags and 1 != 0) field(S8) { it.listTypeIndex ?: 0 } else null + val boxName: String? = + if (typeFlags and 1 != 0) field(Utf16LeNullTerminated) { it.boxName ?: "" } else null + val cookieData: ByteArray? = + if (typeFlags and 2 != 0) field(CookieBytes) { it.cookieData ?: ByteArray(0) } else null + return StorageBoxFilterPacket(listTypeIndex, boxName, cookieData) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxRequestPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxRequestPacket.kt index 277aa25..197351c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxRequestPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageBoxRequestPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class StorageBoxRequestPacket object StorageBoxRequestPacketCodec : PacketCodec() { - override fun CodecScope.body(): StorageBoxRequestPacket { - return StorageBoxRequestPacket() - } + override fun CodecScope.body(): StorageBoxRequestPacket { + return StorageBoxRequestPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageContextWindowPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageContextWindowPacket.kt index 07cfb7c..7cedebc 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageContextWindowPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageContextWindowPacket.kt @@ -22,23 +22,21 @@ data class StorageContextWindowPacket( ) object StorageContextWindowPacketCodec : PacketCodec() { - override fun CodecScope.body(): StorageContextWindowPacket { - val kind = field(S8) { it.kind } - val count = field(S8) { it.items.size.toByte() }.toInt() - val items = ArrayList(if (count > 0) count else 0) - repeat(if (count > 0) count else 0) { i -> - val slot = field(S8) { it.items[i].slot } - val valueA = field(S16LE) { it.items[i].valueA } - val valueB = field(S16LE) { it.items[i].valueB } - val valueC = field(S16LE) { it.items[i].valueC } - val valueD = field(S16LE) { it.items[i].valueD } - val quantity = field(S8) { it.items[i].quantity } - val ball = field(S8) { it.items[i].ball } - val location = field(S8) { it.items[i].location } - items.add( - StorageBoxItem(slot, valueA, valueB, valueC, valueD, quantity, ball, location) - ) - } - return StorageContextWindowPacket(kind, items) + override fun CodecScope.body(): StorageContextWindowPacket { + val kind = field(S8) { it.kind } + val count = field(S8) { it.items.size.toByte() }.toInt() + val items = ArrayList(if (count > 0) count else 0) + repeat(if (count > 0) count else 0) { i -> + val slot = field(S8) { it.items[i].slot } + val valueA = field(S16LE) { it.items[i].valueA } + val valueB = field(S16LE) { it.items[i].valueB } + val valueC = field(S16LE) { it.items[i].valueC } + val valueD = field(S16LE) { it.items[i].valueD } + val quantity = field(S8) { it.items[i].quantity } + val ball = field(S8) { it.items[i].ball } + val location = field(S8) { it.items[i].location } + items.add(StorageBoxItem(slot, valueA, valueB, valueC, valueD, quantity, ball, location)) } + return StorageContextWindowPacket(kind, items) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageInventoryPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageInventoryPacket.kt index 7551103..52ecf22 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageInventoryPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StorageInventoryPacket.kt @@ -21,36 +21,35 @@ data class StorageInventoryPacket( private val StorageQuantityCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): StorageQuantity { - val id = field(S16LE) { it.id } - val count = field(S32LE) { it.count } - return StorageQuantity(id, count) - } + override fun CodecScope.body(): StorageQuantity { + val id = field(S16LE) { it.id } + val count = field(S32LE) { it.count } + return StorageQuantity(id, count) + } } private val StorageByteQuantityCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): StorageByteQuantity { - val id = field(S8) { it.id } - val count = field(S32LE) { it.count } - return StorageByteQuantity(id, count) - } + override fun CodecScope.body(): StorageByteQuantity { + val id = field(S8) { it.id } + val count = field(S32LE) { it.count } + return StorageByteQuantity(id, count) + } } object StorageInventoryPacketCodec : PacketCodec() { - override fun CodecScope.body(): StorageInventoryPacket { - val header = field(S16LE) { it.header } - val totalA = field(S32LE) { it.totalA } - val totalB = field(S32LE) { it.totalB } - val valueC = field(S32LE) { it.valueC } - val usedA = field(S32LE) { it.usedA } - val usedB = field(S32LE) { it.usedB } - val listA = field(StorageQuantityCodec.listPrefixed(U8)) { it.listA } - val listB = field(StorageByteQuantityCodec.listPrefixed(U8)) { it.listB } - val listC = field(StorageQuantityCodec.listPrefixed(U8)) { it.listC } - val listD = field(StorageQuantityCodec.listPrefixed(U8)) { it.listD } - return StorageInventoryPacket( - header, totalA, totalB, valueC, usedA, usedB, listA, listB, listC, listD - ) - } + override fun CodecScope.body(): StorageInventoryPacket { + val header = field(S16LE) { it.header } + val totalA = field(S32LE) { it.totalA } + val totalB = field(S32LE) { it.totalB } + val valueC = field(S32LE) { it.valueC } + val usedA = field(S32LE) { it.usedA } + val usedB = field(S32LE) { it.usedB } + val listA = field(StorageQuantityCodec.listPrefixed(U8)) { it.listA } + val listB = field(StorageByteQuantityCodec.listPrefixed(U8)) { it.listB } + val listC = field(StorageQuantityCodec.listPrefixed(U8)) { it.listC } + val listD = field(StorageQuantityCodec.listPrefixed(U8)) { it.listD } + return StorageInventoryPacket( + header, totalA, totalB, valueC, usedA, usedB, listA, listB, listC, listD) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StreamChunkPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StreamChunkPacket.kt index d029eaa..e9ee07c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StreamChunkPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StreamChunkPacket.kt @@ -7,27 +7,27 @@ data class StreamChunkPacket( val finalChunk: Boolean, val chunk: ByteArray, ) { - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (other !is StreamChunkPacket) return false - return streamId == other.streamId && - finalChunk == other.finalChunk && - chunk.contentEquals(other.chunk) - } + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is StreamChunkPacket) return false + return streamId == other.streamId && + finalChunk == other.finalChunk && + chunk.contentEquals(other.chunk) + } - override fun hashCode(): Int { - var result = streamId.hashCode() - result = 31 * result + finalChunk.hashCode() - result = 31 * result + chunk.contentHashCode() - return result - } + override fun hashCode(): Int { + var result = streamId.hashCode() + result = 31 * result + finalChunk.hashCode() + result = 31 * result + chunk.contentHashCode() + return result + } } object StreamChunkPacketCodec : PacketCodec() { - override fun CodecScope.body(): StreamChunkPacket { - val streamId = field(S64LE, StreamChunkPacket::streamId) - val finalChunk = field(Bool, StreamChunkPacket::finalChunk) - val chunk = field(bytesPrefixed(U16LE), StreamChunkPacket::chunk) - return StreamChunkPacket(streamId, finalChunk, chunk) - } + override fun CodecScope.body(): StreamChunkPacket { + val streamId = field(S64LE, StreamChunkPacket::streamId) + val finalChunk = field(Bool, StreamChunkPacket::finalChunk) + val chunk = field(bytesPrefixed(U16LE), StreamChunkPacket::chunk) + return StreamChunkPacket(streamId, finalChunk, chunk) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StringCommandPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StringCommandPacket.kt index a166c8f..bf8d329 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StringCommandPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/StringCommandPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class StringCommandPacket(val command: String) object StringCommandPacketCodec : PacketCodec() { - override fun CodecScope.body(): StringCommandPacket { - val command = field(Utf16LeNullTerminated) { it.command } - return StringCommandPacket(command) - } + override fun CodecScope.body(): StringCommandPacket { + val command = field(Utf16LeNullTerminated) { it.command } + return StringCommandPacket(command) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SubmitBreedingPartyPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SubmitBreedingPartyPacket.kt index e6a7b6c..0619845 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SubmitBreedingPartyPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SubmitBreedingPartyPacket.kt @@ -4,26 +4,26 @@ import de.fiereu.bytecodec.* private val BreedingPartyEntityIds: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val count = (buf.remaining() - 2) / 8 - val result = ArrayList(count) - repeat(count) { - var v = 0L - for (i in 0 until 8) { - v = v or ((buf.readByte().toLong() and 0xFF) shl (i * 8)) - } - result.add(v) - } - return result + override fun read(buf: ReadBuffer): List { + val count = (buf.remaining() - 2) / 8 + val result = ArrayList(count) + repeat(count) { + var v = 0L + for (i in 0 until 8) { + v = v or ((buf.readByte().toLong() and 0xFF) shl (i * 8)) + } + result.add(v) } + return result + } - override fun write(buf: WriteBuffer, value: List) { - for (id in value) { - for (i in 0 until 8) { - buf.writeByte(((id shr (i * 8)) and 0xFF).toByte()) - } - } + override fun write(buf: WriteBuffer, value: List) { + for (id in value) { + for (i in 0 until 8) { + buf.writeByte(((id shr (i * 8)) and 0xFF).toByte()) + } } + } } data class SubmitBreedingPartyPacket( @@ -34,11 +34,11 @@ data class SubmitBreedingPartyPacket( ) object SubmitBreedingPartyPacketCodec : PacketCodec() { - override fun CodecScope.body(): SubmitBreedingPartyPacket { - val sessionId = field(S8) { it.sessionId } - val pokemonEntityIds = field(BreedingPartyEntityIds) { it.pokemonEntityIds } - val slotIndex = field(S8) { it.slotIndex } - val stateFlag = field(S8) { it.stateFlag } - return SubmitBreedingPartyPacket(sessionId, pokemonEntityIds, slotIndex, stateFlag) - } + override fun CodecScope.body(): SubmitBreedingPartyPacket { + val sessionId = field(S8) { it.sessionId } + val pokemonEntityIds = field(BreedingPartyEntityIds) { it.pokemonEntityIds } + val slotIndex = field(S8) { it.slotIndex } + val stateFlag = field(S8) { it.stateFlag } + return SubmitBreedingPartyPacket(sessionId, pokemonEntityIds, slotIndex, stateFlag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SwapInventorySlotsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SwapInventorySlotsPacket.kt index c8468f8..65755d7 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SwapInventorySlotsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/SwapInventorySlotsPacket.kt @@ -11,20 +11,20 @@ data class SlotSwap( private val SlotSwapCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): SlotSwap { - val sourceListType = field(S8) { it.sourceListType } - val sourceSlot = field(S16LE) { it.sourceSlot } - val destinationListType = field(S8) { it.destinationListType } - val destinationSlot = field(S16LE) { it.destinationSlot } - return SlotSwap(sourceListType, sourceSlot, destinationListType, destinationSlot) - } + override fun CodecScope.body(): SlotSwap { + val sourceListType = field(S8) { it.sourceListType } + val sourceSlot = field(S16LE) { it.sourceSlot } + val destinationListType = field(S8) { it.destinationListType } + val destinationSlot = field(S16LE) { it.destinationSlot } + return SlotSwap(sourceListType, sourceSlot, destinationListType, destinationSlot) + } } data class SwapInventorySlotsPacket(val swaps: List) object SwapInventorySlotsPacketCodec : PacketCodec() { - override fun CodecScope.body(): SwapInventorySlotsPacket { - val swaps = field(SlotSwapCodec.listPrefixed(U8)) { it.swaps } - return SwapInventorySlotsPacket(swaps) - } + override fun CodecScope.body(): SwapInventorySlotsPacket { + val swaps = field(SlotSwapCodec.listPrefixed(U8)) { it.swaps } + return SwapInventorySlotsPacket(swaps) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamFoundPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamFoundPacket.kt index 6dc5962..718bf23 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamFoundPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamFoundPacket.kt @@ -10,9 +10,9 @@ data class TeamFoundPacket( ) object TeamFoundPacketCodec : PacketCodec() { - override fun CodecScope.body(): TeamFoundPacket { - val teamName = field(Utf16LeNullTerminated) { it.teamName } - val teamTag = field(Utf16LeNullTerminated) { it.teamTag } - return TeamFoundPacket(teamName, teamTag) - } + override fun CodecScope.body(): TeamFoundPacket { + val teamName = field(Utf16LeNullTerminated) { it.teamName } + val teamTag = field(Utf16LeNullTerminated) { it.teamTag } + return TeamFoundPacket(teamName, teamTag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamNameChangePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamNameChangePacket.kt index 1ff3b80..524de60 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamNameChangePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamNameChangePacket.kt @@ -10,11 +10,11 @@ data class TeamNameChangePacket( ) object TeamNameChangePacketCodec : PacketCodec() { - override fun CodecScope.body(): TeamNameChangePacket { - val checkOnly = field(Bool) { it.checkOnly } - val teamId = field(S16LE) { it.teamId } - val teamName = field(Utf16LeNullTerminated) { it.teamName } - val teamTag = field(Utf16LeNullTerminated) { it.teamTag } - return TeamNameChangePacket(checkOnly, teamId, teamName, teamTag) - } + override fun CodecScope.body(): TeamNameChangePacket { + val checkOnly = field(Bool) { it.checkOnly } + val teamId = field(S16LE) { it.teamId } + val teamName = field(Utf16LeNullTerminated) { it.teamName } + val teamTag = field(Utf16LeNullTerminated) { it.teamTag } + return TeamNameChangePacket(checkOnly, teamId, teamName, teamTag) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewLeadSubmitPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewLeadSubmitPacket.kt index 1a28b9f..7885a5c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewLeadSubmitPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewLeadSubmitPacket.kt @@ -9,11 +9,11 @@ data class RibbonEntry( private val RibbonEntryCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): RibbonEntry { - val ribbonId = field(S8) { it.ribbonId } - val value = field(S8) { it.value } - return RibbonEntry(ribbonId, value) - } + override fun CodecScope.body(): RibbonEntry { + val ribbonId = field(S8) { it.ribbonId } + val value = field(S8) { it.value } + return RibbonEntry(ribbonId, value) + } } data class TeamPreviewAppearance( @@ -27,20 +27,20 @@ data class TeamPreviewAppearance( private val AppearanceCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): TeamPreviewAppearance { - val kind = field(S8) { it.kind } - if (kind.toInt() == 1) { - val shinyTypeId = field(S8) { it.shinyTypeId ?: -1 } - val form = field(S8) { it.form ?: 0 } - val moveIds = field(S16LE.listPrefixed(U8)) { it.moveIds ?: emptyList() } - val ribbons = field(RibbonEntryCodec.listPrefixed(U8)) { it.ribbons ?: emptyList() } - return TeamPreviewAppearance(kind, shinyTypeId, form, moveIds, ribbons, null) - } else if (kind.toInt() == 6) { - val simpleForm = field(S8) { it.simpleForm ?: 0 } - return TeamPreviewAppearance(kind, null, null, null, null, simpleForm) - } - return TeamPreviewAppearance(kind, null, null, null, null, null) + override fun CodecScope.body(): TeamPreviewAppearance { + val kind = field(S8) { it.kind } + if (kind.toInt() == 1) { + val shinyTypeId = field(S8) { it.shinyTypeId ?: -1 } + val form = field(S8) { it.form ?: 0 } + val moveIds = field(S16LE.listPrefixed(U8)) { it.moveIds ?: emptyList() } + val ribbons = field(RibbonEntryCodec.listPrefixed(U8)) { it.ribbons ?: emptyList() } + return TeamPreviewAppearance(kind, shinyTypeId, form, moveIds, ribbons, null) + } else if (kind.toInt() == 6) { + val simpleForm = field(S8) { it.simpleForm ?: 0 } + return TeamPreviewAppearance(kind, null, null, null, null, simpleForm) } + return TeamPreviewAppearance(kind, null, null, null, null, null) + } } data class TeamPreviewLeadSubmitPacket( @@ -52,20 +52,19 @@ data class TeamPreviewLeadSubmitPacket( ) object TeamPreviewLeadSubmitPacketCodec : PacketCodec() { - override fun CodecScope.body(): TeamPreviewLeadSubmitPacket { - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val battleSlot = field(S8) { it.battleSlot } - val present = field(U8) { if (it.appearance != null) 1 else 0 } - val appearance = - if (present != 0) field(AppearanceCodec) { it.appearance!! } else null - val teamSide = field(S16LE) { it.teamSide } - val reserved = field(S8) { it.reserved } - return TeamPreviewLeadSubmitPacket( - pokemonEntityId, - battleSlot, - appearance, - teamSide, - reserved, - ) - } + override fun CodecScope.body(): TeamPreviewLeadSubmitPacket { + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val battleSlot = field(S8) { it.battleSlot } + val present = field(U8) { if (it.appearance != null) 1 else 0 } + val appearance = if (present != 0) field(AppearanceCodec) { it.appearance!! } else null + val teamSide = field(S16LE) { it.teamSide } + val reserved = field(S8) { it.reserved } + return TeamPreviewLeadSubmitPacket( + pokemonEntityId, + battleSlot, + appearance, + teamSide, + reserved, + ) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewRevealPickPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewRevealPickPacket.kt index f5b30b9..f7805eb 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewRevealPickPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewRevealPickPacket.kt @@ -9,8 +9,8 @@ data class TeamPreviewRevealPickPacket( ) object TeamPreviewRevealPickPacketCodec : PacketCodec() { - override fun CodecScope.body(): TeamPreviewRevealPickPacket { - val entityId = field(S64LE) { it.entityId } - return TeamPreviewRevealPickPacket(entityId) - } + override fun CodecScope.body(): TeamPreviewRevealPickPacket { + val entityId = field(S64LE) { it.entityId } + return TeamPreviewRevealPickPacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewSidePickPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewSidePickPacket.kt index f081198..246e068 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewSidePickPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TeamPreviewSidePickPacket.kt @@ -11,9 +11,9 @@ data class TeamPreviewSidePickPacket( ) object TeamPreviewSidePickPacketCodec : PacketCodec() { - override fun CodecScope.body(): TeamPreviewSidePickPacket { - val pokemonEntityId = field(S64LE) { it.pokemonEntityId } - val side = field(S16LE) { it.side } - return TeamPreviewSidePickPacket(pokemonEntityId, side) - } + override fun CodecScope.body(): TeamPreviewSidePickPacket { + val pokemonEntityId = field(S64LE) { it.pokemonEntityId } + val side = field(S16LE) { it.side } + return TeamPreviewSidePickPacket(pokemonEntityId, side) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TextArgumentPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TextArgumentPacket.kt index c0d0919..029ea41 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TextArgumentPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TextArgumentPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class TextArgumentPacket(val text: String) object TextArgumentPacketCodec : PacketCodec() { - override fun CodecScope.body(): TextArgumentPacket { - val text = field(Utf16LeNullTerminated) { it.text } - return TextArgumentPacket(text) - } + override fun CodecScope.body(): TextArgumentPacket { + val text = field(Utf16LeNullTerminated) { it.text } + return TextArgumentPacket(text) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TokenPayloadPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TokenPayloadPacket.kt index 21ad7d3..c9f6bab 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TokenPayloadPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TokenPayloadPacket.kt @@ -3,28 +3,28 @@ package de.fiereu.openmmo.net.game.packets import de.fiereu.bytecodec.* data class TokenPayloadPacket(val payload: ByteArray) { - override fun equals(other: Any?): Boolean = - other is TokenPayloadPacket && payload.contentEquals(other.payload) + override fun equals(other: Any?): Boolean = + other is TokenPayloadPacket && payload.contentEquals(other.payload) - override fun hashCode(): Int = payload.contentHashCode() + override fun hashCode(): Int = payload.contentHashCode() } private val TokenPayloadBytes: Codec = object : Codec { - override fun read(buf: ReadBuffer): ByteArray { - val data = ByteArray(buf.remaining()) - if (data.isNotEmpty()) buf.readBytes(data) - return data - } + override fun read(buf: ReadBuffer): ByteArray { + val data = ByteArray(buf.remaining()) + if (data.isNotEmpty()) buf.readBytes(data) + return data + } - override fun write(buf: WriteBuffer, value: ByteArray) { - if (value.isNotEmpty()) buf.writeBytes(value) - } + override fun write(buf: WriteBuffer, value: ByteArray) { + if (value.isNotEmpty()) buf.writeBytes(value) + } } object TokenPayloadPacketCodec : PacketCodec() { - override fun CodecScope.body() = - TokenPayloadPacket( - payload = field(TokenPayloadBytes, TokenPayloadPacket::payload), - ) + override fun CodecScope.body() = + TokenPayloadPacket( + payload = field(TokenPayloadBytes, TokenPayloadPacket::payload), + ) } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentMatchupsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentMatchupsPacket.kt index 20b0081..cf24d37 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentMatchupsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentMatchupsPacket.kt @@ -15,35 +15,35 @@ data class TournamentMatchupsPacket( ) private object TournamentMatchupCodec : PacketCodec() { - override fun CodecScope.body(): TournamentMatchup { - val value = field(S16LE, TournamentMatchup::value) - val type = field(S8, TournamentMatchup::type) - val entityId = field(S64LE, TournamentMatchup::entityId) - if (type.toInt() != 0) { - val moveRefA = field(S16LE) { it.moveRefA!! } - val moveRefB = field(S16LE) { it.moveRefB!! } - return TournamentMatchup(value, type, entityId, moveRefA, moveRefB) - } - return TournamentMatchup(value, type, entityId, null, null) + override fun CodecScope.body(): TournamentMatchup { + val value = field(S16LE, TournamentMatchup::value) + val type = field(S8, TournamentMatchup::type) + val entityId = field(S64LE, TournamentMatchup::entityId) + if (type.toInt() != 0) { + val moveRefA = field(S16LE) { it.moveRefA!! } + val moveRefB = field(S16LE) { it.moveRefB!! } + return TournamentMatchup(value, type, entityId, moveRefA, moveRefB) } + return TournamentMatchup(value, type, entityId, null, null) + } } private val TournamentMatchupListPrefixedU16: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U16LE.read(buf) - return List(n) { TournamentMatchupCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U16LE.read(buf) + return List(n) { TournamentMatchupCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U16LE.write(buf, value.size) - value.forEach { TournamentMatchupCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U16LE.write(buf, value.size) + value.forEach { TournamentMatchupCodec.write(buf, it) } + } } object TournamentMatchupsPacketCodec : PacketCodec() { - override fun CodecScope.body(): TournamentMatchupsPacket { - val matchups = field(TournamentMatchupListPrefixedU16, TournamentMatchupsPacket::matchups) - return TournamentMatchupsPacket(matchups) - } + override fun CodecScope.body(): TournamentMatchupsPacket { + val matchups = field(TournamentMatchupListPrefixedU16, TournamentMatchupsPacket::matchups) + return TournamentMatchupsPacket(matchups) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentRegistrationPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentRegistrationPacket.kt index 88584dc..f3d0506 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentRegistrationPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentRegistrationPacket.kt @@ -9,8 +9,8 @@ data class TournamentRegistrationPacket( ) object TournamentRegistrationPacketCodec : PacketCodec() { - override fun CodecScope.body(): TournamentRegistrationPacket { - val register = field(Bool) { it.register } - return TournamentRegistrationPacket(register) - } + override fun CodecScope.body(): TournamentRegistrationPacket { + val register = field(Bool) { it.register } + return TournamentRegistrationPacket(register) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentTeleportAcceptPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentTeleportAcceptPacket.kt index 3251394..fc2d37c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentTeleportAcceptPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TournamentTeleportAcceptPacket.kt @@ -6,7 +6,7 @@ import de.fiereu.bytecodec.PacketCodec class TournamentTeleportAcceptPacket object TournamentTeleportAcceptPacketCodec : PacketCodec() { - override fun CodecScope.body(): TournamentTeleportAcceptPacket { - return TournamentTeleportAcceptPacket() - } + override fun CodecScope.body(): TournamentTeleportAcceptPacket { + return TournamentTeleportAcceptPacket() + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TourneyRegistrationPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TourneyRegistrationPacket.kt index 61d36df..ec5d9fe 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TourneyRegistrationPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TourneyRegistrationPacket.kt @@ -9,10 +9,10 @@ data class TourneyRegistrationPacket( ) object TourneyRegistrationPacketCodec : PacketCodec() { - override fun CodecScope.body(): TourneyRegistrationPacket { - val tournamentId = field(S8) { it.tournamentId } - val isActive = field(Bool) { it.isActive } - val tabIndex = field(S16LE) { it.tabIndex } - return TourneyRegistrationPacket(tournamentId, isActive, tabIndex) - } + override fun CodecScope.body(): TourneyRegistrationPacket { + val tournamentId = field(S8) { it.tournamentId } + val isActive = field(Bool) { it.isActive } + val tabIndex = field(S16LE) { it.tabIndex } + return TourneyRegistrationPacket(tournamentId, isActive, tabIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TrackedEntitySlotsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TrackedEntitySlotsPacket.kt index 1e20866..c9bacba 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TrackedEntitySlotsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TrackedEntitySlotsPacket.kt @@ -13,16 +13,16 @@ data class TrackedEntitySlotsPacket( private val TrackedEntitySlotCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): TrackedEntitySlot { - val count = field(S16LE) { it.count } - val entityId = field(S64LE) { it.entityId } - return TrackedEntitySlot(count, entityId) - } + override fun CodecScope.body(): TrackedEntitySlot { + val count = field(S16LE) { it.count } + val entityId = field(S64LE) { it.entityId } + return TrackedEntitySlot(count, entityId) + } } object TrackedEntitySlotsPacketCodec : PacketCodec() { - override fun CodecScope.body(): TrackedEntitySlotsPacket { - val slots = field(TrackedEntitySlotCodec.listPrefixed(U8)) { it.slots } - return TrackedEntitySlotsPacket(slots) - } + override fun CodecScope.body(): TrackedEntitySlotsPacket { + val slots = field(TrackedEntitySlotCodec.listPrefixed(U8)) { it.slots } + return TrackedEntitySlotsPacket(slots) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeActionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeActionPacket.kt index 322f7a4..67ef17f 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeActionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeActionPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S8 data class TradeActionPacket(val action: Byte) object TradeActionPacketCodec : PacketCodec() { - override fun CodecScope.body(): TradeActionPacket { - val action = field(S8) { it.action } - return TradeActionPacket(action) - } + override fun CodecScope.body(): TradeActionPacket { + val action = field(S8) { it.action } + return TradeActionPacket(action) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeListEntryPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeListEntryPacket.kt index 6315ca9..b765de0 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeListEntryPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeListEntryPacket.kt @@ -10,8 +10,8 @@ data class TradeListEntryPacket( ) object TradeListEntryPacketCodec : PacketCodec() { - override fun CodecScope.body(): TradeListEntryPacket { - val pokemon = field(PokemonCodec) { it.pokemon } - return TradeListEntryPacket(pokemon) - } + override fun CodecScope.body(): TradeListEntryPacket { + val pokemon = field(PokemonCodec) { it.pokemon } + return TradeListEntryPacket(pokemon) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeSelectMonPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeSelectMonPacket.kt index deda549..3d396ee 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeSelectMonPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TradeSelectMonPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.S32LE data class TradeSelectMonPacket(val slotIndex: Int) object TradeSelectMonPacketCodec : PacketCodec() { - override fun CodecScope.body(): TradeSelectMonPacket { - val slotIndex = field(S32LE) { it.slotIndex } - return TradeSelectMonPacket(slotIndex) - } + override fun CodecScope.body(): TradeSelectMonPacket { + val slotIndex = field(S32LE) { it.slotIndex } + return TradeSelectMonPacket(slotIndex) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TypedBinaryDataPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TypedBinaryDataPacket.kt index 78a49f8..f9f77e9 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TypedBinaryDataPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/TypedBinaryDataPacket.kt @@ -6,20 +6,18 @@ data class TypedBinaryDataPacket( val dataType: Byte, val data: ByteArray, ) { - override fun equals(other: Any?): Boolean = - other is TypedBinaryDataPacket && - dataType == other.dataType && - data.contentEquals(other.data) + override fun equals(other: Any?): Boolean = + other is TypedBinaryDataPacket && dataType == other.dataType && data.contentEquals(other.data) - override fun hashCode(): Int = dataType * 31 + data.contentHashCode() + override fun hashCode(): Int = dataType * 31 + data.contentHashCode() } private val TypedBinaryDataBytes = bytesPrefixed(U8) object TypedBinaryDataPacketCodec : PacketCodec() { - override fun CodecScope.body(): TypedBinaryDataPacket { - val dataType = field(S8) { it.dataType } - val data = field(TypedBinaryDataBytes) { it.data } - return TypedBinaryDataPacket(dataType, data) - } + override fun CodecScope.body(): TypedBinaryDataPacket { + val dataType = field(S8) { it.dataType } + val data = field(TypedBinaryDataBytes) { it.data } + return TypedBinaryDataPacket(dataType, data) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/UnblockPlayerPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/UnblockPlayerPacket.kt index 72d740e..44e8bca 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/UnblockPlayerPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/UnblockPlayerPacket.kt @@ -7,8 +7,8 @@ import de.fiereu.bytecodec.Utf16LeNullTerminated data class UnblockPlayerPacket(val username: String) object UnblockPlayerPacketCodec : PacketCodec() { - override fun CodecScope.body(): UnblockPlayerPacket { - val username = field(Utf16LeNullTerminated) { it.username } - return UnblockPlayerPacket(username) - } + override fun CodecScope.body(): UnblockPlayerPacket { + val username = field(Utf16LeNullTerminated) { it.username } + return UnblockPlayerPacket(username) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ViewScalePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ViewScalePacket.kt index 84b8120..60d784c 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ViewScalePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/ViewScalePacket.kt @@ -9,8 +9,8 @@ data class ViewScalePacket( ) object ViewScalePacketCodec : PacketCodec() { - override fun CodecScope.body(): ViewScalePacket { - val viewScale = field(S8) { it.viewScale } - return ViewScalePacket(viewScale) - } + override fun CodecScope.body(): ViewScalePacket { + val viewScale = field(S8) { it.viewScale } + return ViewScalePacket(viewScale) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WarpTileInteractPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WarpTileInteractPacket.kt index 2113869..a94be11 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WarpTileInteractPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WarpTileInteractPacket.kt @@ -10,9 +10,9 @@ data class WarpTileInteractPacket( ) object WarpTileInteractPacketCodec : PacketCodec() { - override fun CodecScope.body(): WarpTileInteractPacket { - val floorId = field(S8) { it.floorId } - val warpMode = field(S8) { it.warpMode } - return WarpTileInteractPacket(floorId, warpMode) - } + override fun CodecScope.body(): WarpTileInteractPacket { + val floorId = field(S8) { it.floorId } + val warpMode = field(S8) { it.warpMode } + return WarpTileInteractPacket(floorId, warpMode) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldActionDispatchPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldActionDispatchPacket.kt index 48af3b3..bab0e1b 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldActionDispatchPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldActionDispatchPacket.kt @@ -9,10 +9,10 @@ data class WorldActionDispatchPacket( ) object WorldActionDispatchPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldActionDispatchPacket { - val action = field(S8) { it.action } - val subject = field(S8) { it.subject } - val args = field(S16LE.listPrefixed(U8)) { it.args } - return WorldActionDispatchPacket(action, subject, args) - } + override fun CodecScope.body(): WorldActionDispatchPacket { + val action = field(S8) { it.action } + val subject = field(S8) { it.subject } + val args = field(S16LE.listPrefixed(U8)) { it.args } + return WorldActionDispatchPacket(action, subject, args) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityInteractPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityInteractPacket.kt index 6548b99..95d7a17 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityInteractPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityInteractPacket.kt @@ -11,12 +11,12 @@ data class WorldEntityInteractPacket( ) object WorldEntityInteractPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldEntityInteractPacket { - val itemTypeId = field(S16LE) { it.itemTypeId } - val targetEntityId = field(S64LE) { it.targetEntityId } - val quantity = field(S16LE) { it.quantity } - val actionFlag = field(S8) { it.actionFlag } - val reserved = field(S8) { it.reserved } - return WorldEntityInteractPacket(itemTypeId, targetEntityId, quantity, actionFlag, reserved) - } + override fun CodecScope.body(): WorldEntityInteractPacket { + val itemTypeId = field(S16LE) { it.itemTypeId } + val targetEntityId = field(S64LE) { it.targetEntityId } + val quantity = field(S16LE) { it.quantity } + val actionFlag = field(S8) { it.actionFlag } + val reserved = field(S8) { it.reserved } + return WorldEntityInteractPacket(itemTypeId, targetEntityId, quantity, actionFlag, reserved) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityStateResetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityStateResetPacket.kt index 1dcd48d..c8a2c66 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityStateResetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldEntityStateResetPacket.kt @@ -9,8 +9,8 @@ data class WorldEntityStateResetPacket( ) object WorldEntityStateResetPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldEntityStateResetPacket { - val entityType = field(S16LE) { it.entityType } - return WorldEntityStateResetPacket(entityType) - } + override fun CodecScope.body(): WorldEntityStateResetPacket { + val entityType = field(S16LE) { it.entityType } + return WorldEntityStateResetPacket(entityType) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagSetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagSetPacket.kt index e858dd0..ed67c31 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagSetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagSetPacket.kt @@ -12,10 +12,10 @@ data class WorldFlagSetPacket( ) object WorldFlagSetPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldFlagSetPacket { - val group = field(S8) { it.group } - val index = field(S16LE) { it.index } - val value = field(S8) { it.value } - return WorldFlagSetPacket(group, index, value) - } + override fun CodecScope.body(): WorldFlagSetPacket { + val group = field(S8) { it.group } + val index = field(S16LE) { it.index } + val value = field(S8) { it.value } + return WorldFlagSetPacket(group, index, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagStateUpdatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagStateUpdatePacket.kt index 897817a..3f8242e 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagStateUpdatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagStateUpdatePacket.kt @@ -12,10 +12,10 @@ data class WorldFlagStateUpdatePacket( ) object WorldFlagStateUpdatePacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldFlagStateUpdatePacket { - val key = field(S8) { it.key } - val state = field(S8) { it.state } - val value = field(S32LE) { it.value } - return WorldFlagStateUpdatePacket(key, state, value) - } + override fun CodecScope.body(): WorldFlagStateUpdatePacket { + val key = field(S8) { it.key } + val state = field(S8) { it.state } + val value = field(S32LE) { it.value } + return WorldFlagStateUpdatePacket(key, state, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagTableResetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagTableResetPacket.kt index 1a87a5e..86765c3 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagTableResetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldFlagTableResetPacket.kt @@ -5,23 +5,23 @@ import de.fiereu.bytecodec.* data class WorldFlagTableResetPacket( val flagGroups: List, ) { - override fun equals(other: Any?): Boolean = - other is WorldFlagTableResetPacket && - flagGroups.size == other.flagGroups.size && - flagGroups.indices.all { flagGroups[it].contentEquals(other.flagGroups[it]) } + override fun equals(other: Any?): Boolean = + other is WorldFlagTableResetPacket && + flagGroups.size == other.flagGroups.size && + flagGroups.indices.all { flagGroups[it].contentEquals(other.flagGroups[it]) } - override fun hashCode(): Int { - var r = 1 - for (g in flagGroups) r = r * 31 + g.contentHashCode() - return r - } + override fun hashCode(): Int { + var r = 1 + for (g in flagGroups) r = r * 31 + g.contentHashCode() + return r + } } private val FlagGroupBytes = bytesPrefixed(U16LE) object WorldFlagTableResetPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldFlagTableResetPacket { - val flagGroups = field(FlagGroupBytes.listPrefixed(U8)) { it.flagGroups } - return WorldFlagTableResetPacket(flagGroups) - } + override fun CodecScope.body(): WorldFlagTableResetPacket { + val flagGroups = field(FlagGroupBytes.listPrefixed(U8)) { it.flagGroups } + return WorldFlagTableResetPacket(flagGroups) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldJoinConfirmPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldJoinConfirmPacket.kt index 33db47b..e6ef19a 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldJoinConfirmPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldJoinConfirmPacket.kt @@ -9,17 +9,17 @@ data class WorldJoinConfirmPacket( ) object WorldJoinConfirmPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldJoinConfirmPacket { - val success = field(Bool) { it.success } - val entityId: Long? - val name: String? - if (success) { - entityId = field(S64LE) { it.entityId!! } - name = field(Utf16LeNullTerminated) { it.name!! } - } else { - entityId = null - name = null - } - return WorldJoinConfirmPacket(success, entityId, name) + override fun CodecScope.body(): WorldJoinConfirmPacket { + val success = field(Bool) { it.success } + val entityId: Long? + val name: String? + if (success) { + entityId = field(S64LE) { it.entityId!! } + name = field(Utf16LeNullTerminated) { it.name!! } + } else { + entityId = null + name = null } + return WorldJoinConfirmPacket(success, entityId, name) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt index b72c7cb..4d5e018 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldNoticeSlotPacket.kt @@ -15,30 +15,32 @@ data class WorldNoticeArg( private val WorldNoticeArgCodec: Codec = object : PacketCodec() { - override fun CodecScope.body(): WorldNoticeArg { - val argId = field(S8) { it.argId } - val rawType = field(U8) { if (it.hasExtra) it.type or 128 else it.type } - val hasExtra = rawType and 128 != 0 - val type = if (hasExtra) rawType and 127 else rawType - val extra = if (hasExtra) field(S8) { it.extra } else 0 - var longValue: Long? = null - var intValue: Int? = null - var stringValue: String? = null - var shortValues: List? = null - when (type) { - 28 -> {} - 30 -> longValue = field(S64LE) { it.longValue!! } - 9, 10, 17 -> intValue = field(S32LE) { it.intValue!! } - 5, 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! } - else -> { - val count = field(U8) { it.shortValues!!.size } - shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } } - } - } - return WorldNoticeArg( - argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues - ) + override fun CodecScope.body(): WorldNoticeArg { + val argId = field(S8) { it.argId } + val rawType = field(U8) { if (it.hasExtra) it.type or 128 else it.type } + val hasExtra = rawType and 128 != 0 + val type = if (hasExtra) rawType and 127 else rawType + val extra = if (hasExtra) field(S8) { it.extra } else 0 + var longValue: Long? = null + var intValue: Int? = null + var stringValue: String? = null + var shortValues: List? = null + when (type) { + 28 -> {} + 30 -> longValue = field(S64LE) { it.longValue!! } + 9, + 10, + 17 -> intValue = field(S32LE) { it.intValue!! } + 5, + 18 -> stringValue = field(Utf16LeNullTerminated) { it.stringValue!! } + else -> { + val count = field(U8) { it.shortValues!!.size } + shortValues = (0 until count).map { i -> field(S16LE) { it.shortValues!![i] } } + } } + return WorldNoticeArg( + argId, type, hasExtra, extra, longValue, intValue, stringValue, shortValues) + } } data class WorldNoticeSlotPacket( @@ -51,21 +53,21 @@ data class WorldNoticeSlotPacket( ) object WorldNoticeSlotPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldNoticeSlotPacket { - val slot = field(S8) { it.slot } - val flags = field(S8) { it.flags } - if (flags.toInt() != 0) { - field(S8) { 0 } - val severity = field(S8) { it.severity } - val stringId = if (flags.toInt() and 1 != 0) field(S32LE) { it.stringId!! } else null - val args = - if (flags.toInt() and 2 != 0) { - val count = field(S8) { it.args.size.toByte() }.toInt() - (0 until count).map { i -> field(WorldNoticeArgCodec) { it.args[i] } } - } else emptyList() - val text = if (flags.toInt() and 4 != 0) field(Utf16LeNullTerminated) { it.text!! } else null - return WorldNoticeSlotPacket(slot, flags, severity, stringId, args, text) - } - return WorldNoticeSlotPacket(slot, flags, 0, null, emptyList(), null) + override fun CodecScope.body(): WorldNoticeSlotPacket { + val slot = field(S8) { it.slot } + val flags = field(S8) { it.flags } + if (flags.toInt() != 0) { + field(S8) { 0 } + val severity = field(S8) { it.severity } + val stringId = if (flags.toInt() and 1 != 0) field(S32LE) { it.stringId!! } else null + val args = + if (flags.toInt() and 2 != 0) { + val count = field(S8) { it.args.size.toByte() }.toInt() + (0 until count).map { i -> field(WorldNoticeArgCodec) { it.args[i] } } + } else emptyList() + val text = if (flags.toInt() and 4 != 0) field(Utf16LeNullTerminated) { it.text!! } else null + return WorldNoticeSlotPacket(slot, flags, severity, stringId, args, text) } + return WorldNoticeSlotPacket(slot, flags, 0, null, emptyList(), null) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldObjectInstanceDespawnPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldObjectInstanceDespawnPacket.kt index d6ae71e..a15c5c6 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldObjectInstanceDespawnPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldObjectInstanceDespawnPacket.kt @@ -9,8 +9,9 @@ data class WorldObjectInstanceDespawnPacket( ) object WorldObjectInstanceDespawnPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldObjectInstanceDespawnPacket { - val entityId = field(S64LE) { it.entityId } - return WorldObjectInstanceDespawnPacket(entityId) - } + override fun CodecScope.body(): + WorldObjectInstanceDespawnPacket { + val entityId = field(S64LE) { it.entityId } + return WorldObjectInstanceDespawnPacket(entityId) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldOverlayObjectSetPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldOverlayObjectSetPacket.kt index 5228a1a..1ac38c4 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldOverlayObjectSetPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldOverlayObjectSetPacket.kt @@ -17,16 +17,16 @@ data class WorldOverlayObjectSetPacket( ) object WorldOverlayObjectSetPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldOverlayObjectSetPacket { - val objectId = field(S8) { it.objectId } - val action = field(S8) { it.action } - val present = action.toInt() != 0 - val byteA = if (present) field(S8) { it.byteA!! } else null - val byteB = if (present) field(S8) { it.byteB!! } else null - val typeId = if (present) field(S16LE) { it.typeId!! } else null - val flag = if (present) field(S8) { it.flag!! } else null - val x = if (present) field(S16LE) { it.x!! } else null - val y = if (present) field(S16LE) { it.y!! } else null - return WorldOverlayObjectSetPacket(objectId, action, byteA, byteB, typeId, flag, x, y) - } + override fun CodecScope.body(): WorldOverlayObjectSetPacket { + val objectId = field(S8) { it.objectId } + val action = field(S8) { it.action } + val present = action.toInt() != 0 + val byteA = if (present) field(S8) { it.byteA!! } else null + val byteB = if (present) field(S8) { it.byteB!! } else null + val typeId = if (present) field(S16LE) { it.typeId!! } else null + val flag = if (present) field(S8) { it.flag!! } else null + val x = if (present) field(S16LE) { it.x!! } else null + val y = if (present) field(S16LE) { it.y!! } else null + return WorldOverlayObjectSetPacket(objectId, action, byteA, byteB, typeId, flag, x, y) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldSessionStatePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldSessionStatePacket.kt index d0373db..3238106 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldSessionStatePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldSessionStatePacket.kt @@ -6,31 +6,31 @@ data class WorldSessionStatePacket( val worldState: Int, val payloadBlocks: List?, ) { - override fun equals(other: Any?): Boolean { - if (other !is WorldSessionStatePacket) return false - if (worldState != other.worldState) return false - val a = payloadBlocks - val b = other.payloadBlocks - if (a == null) return b == null - if (b == null || a.size != b.size) return false - for (i in a.indices) if (!a[i].contentEquals(b[i])) return false - return true - } + override fun equals(other: Any?): Boolean { + if (other !is WorldSessionStatePacket) return false + if (worldState != other.worldState) return false + val a = payloadBlocks + val b = other.payloadBlocks + if (a == null) return b == null + if (b == null || a.size != b.size) return false + for (i in a.indices) if (!a[i].contentEquals(b[i])) return false + return true + } - override fun hashCode(): Int { - var r = worldState - payloadBlocks?.forEach { r = r * 31 + it.contentHashCode() } - return r - } + override fun hashCode(): Int { + var r = worldState + payloadBlocks?.forEach { r = r * 31 + it.contentHashCode() } + return r + } } object WorldSessionStatePacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldSessionStatePacket { - val worldState = field(U8) { it.worldState } - val payloadBlocks = - if (worldState == 11) { - field(bytesPrefixed(U8).listPrefixed(U8)) { it.payloadBlocks!! } - } else null - return WorldSessionStatePacket(worldState, payloadBlocks) - } + override fun CodecScope.body(): WorldSessionStatePacket { + val worldState = field(U8) { it.worldState } + val payloadBlocks = + if (worldState == 11) { + field(bytesPrefixed(U8).listPrefixed(U8)) { it.payloadBlocks!! } + } else null + return WorldSessionStatePacket(worldState, payloadBlocks) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateControlPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateControlPacket.kt index e3b457e..96f07d5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateControlPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateControlPacket.kt @@ -11,9 +11,9 @@ data class WorldStateControlPacket( ) object WorldStateControlPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldStateControlPacket { - val actionType = field(S8) { it.actionType } - val value = field(S32LE) { it.value } - return WorldStateControlPacket(actionType, value) - } + override fun CodecScope.body(): WorldStateControlPacket { + val actionType = field(S8) { it.actionType } + val value = field(S32LE) { it.value } + return WorldStateControlPacket(actionType, value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateValuePacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateValuePacket.kt index d879b3c..4414bc8 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateValuePacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldStateValuePacket.kt @@ -9,8 +9,8 @@ data class WorldStateValuePacket( ) object WorldStateValuePacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldStateValuePacket { - val value = field(S16LE, WorldStateValuePacket::value) - return WorldStateValuePacket(value) - } + override fun CodecScope.body(): WorldStateValuePacket { + val value = field(S16LE, WorldStateValuePacket::value) + return WorldStateValuePacket(value) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldTimedEventStatusPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldTimedEventStatusPacket.kt index 3d21bc8..96f40a5 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldTimedEventStatusPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldTimedEventStatusPacket.kt @@ -11,12 +11,12 @@ data class WorldTimedEventStatusPacket( ) object WorldTimedEventStatusPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldTimedEventStatusPacket { - val active = field(U8) { if (it.active) 1 else 0 } == 1 - val startTime = if (active) field(S64LE) { it.startTime!! } else null - val endTime = if (active) field(S64LE) { it.endTime!! } else null - val value = if (active) field(S16LE) { it.value!! } else null - val shininessType = if (active) field(S8) { it.shininessType!! } else null - return WorldTimedEventStatusPacket(active, startTime, endTime, value, shininessType) - } + override fun CodecScope.body(): WorldTimedEventStatusPacket { + val active = field(U8) { if (it.active) 1 else 0 } == 1 + val startTime = if (active) field(S64LE) { it.startTime!! } else null + val endTime = if (active) field(S64LE) { it.endTime!! } else null + val value = if (active) field(S16LE) { it.value!! } else null + val shininessType = if (active) field(S8) { it.shininessType!! } else null + return WorldTimedEventStatusPacket(active, startTime, endTime, value, shininessType) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldToggleFlagsPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldToggleFlagsPacket.kt index 8da6c44..8b22483 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldToggleFlagsPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldToggleFlagsPacket.kt @@ -12,29 +12,29 @@ data class WorldToggleFlagsPacket( ) private object WorldToggleFlagsEntryCodec : PacketCodec() { - override fun CodecScope.body(): WorldToggleFlagsEntry { - val id = field(S16LE, WorldToggleFlagsEntry::id) - val state = field(Bool, WorldToggleFlagsEntry::state) - return WorldToggleFlagsEntry(id, state) - } + override fun CodecScope.body(): WorldToggleFlagsEntry { + val id = field(S16LE, WorldToggleFlagsEntry::id) + val state = field(Bool, WorldToggleFlagsEntry::state) + return WorldToggleFlagsEntry(id, state) + } } private val WorldToggleFlagsEntryListPrefixedU8: Codec> = object : Codec> { - override fun read(buf: ReadBuffer): List { - val n = U8.read(buf) - return List(n) { WorldToggleFlagsEntryCodec.read(buf) } - } + override fun read(buf: ReadBuffer): List { + val n = U8.read(buf) + return List(n) { WorldToggleFlagsEntryCodec.read(buf) } + } - override fun write(buf: WriteBuffer, value: List) { - U8.write(buf, value.size) - value.forEach { WorldToggleFlagsEntryCodec.write(buf, it) } - } + override fun write(buf: WriteBuffer, value: List) { + U8.write(buf, value.size) + value.forEach { WorldToggleFlagsEntryCodec.write(buf, it) } + } } object WorldToggleFlagsPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldToggleFlagsPacket { - val entries = field(WorldToggleFlagsEntryListPrefixedU8, WorldToggleFlagsPacket::entries) - return WorldToggleFlagsPacket(entries) - } + override fun CodecScope.body(): WorldToggleFlagsPacket { + val entries = field(WorldToggleFlagsEntryListPrefixedU8, WorldToggleFlagsPacket::entries) + return WorldToggleFlagsPacket(entries) + } } diff --git a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldVersionPacket.kt b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldVersionPacket.kt index efb143d..039f135 100644 --- a/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldVersionPacket.kt +++ b/protocols.game/src/main/kotlin/de/fiereu/openmmo/net/game/packets/WorldVersionPacket.kt @@ -11,10 +11,10 @@ data class WorldVersionPacket( ) object WorldVersionPacketCodec : PacketCodec() { - override fun CodecScope.body(): WorldVersionPacket { - val major = field(S16LE) { it.major } - val build = field(S16LE) { it.build } - val minor = field(S16LE) { it.minor } - return WorldVersionPacket(major, build, minor) - } + override fun CodecScope.body(): WorldVersionPacket { + val major = field(S16LE) { it.major } + val build = field(S16LE) { it.build } + val minor = field(S16LE) { it.minor } + return WorldVersionPacket(major, build, minor) + } } diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/FriendListPacketTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/FriendListPacketTest.kt new file mode 100644 index 0000000..b46ab45 --- /dev/null +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/FriendListPacketTest.kt @@ -0,0 +1,44 @@ +package de.fiereu.openmmo.net.game + +import de.fiereu.bytecodec.test.decodeBytes +import de.fiereu.bytecodec.test.encodeToBytes +import de.fiereu.openmmo.net.game.packets.FriendListEntry +import de.fiereu.openmmo.net.game.packets.FriendListPacket +import de.fiereu.openmmo.net.game.packets.FriendListPacketCodec +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class FriendListPacketTest : + FunSpec({ + test("roundtrips entries with mixed online state and variable-length names") { + val pkt = + FriendListPacket( + mode = 0, + entries = + listOf( + FriendListEntry( + player = 0x0102030405069000L, + friendsSince = 1_600_000_000, + online = false, + name = "Alpha", + unk = 0, + lastSeen = 1_700_000_000, + appearance = listOf(1, 2, 3, 4, 5), + ), + FriendListEntry( + player = 0xA7L, + friendsSince = 1_650_000_000, + online = true, + name = "BravoBravoBravo", + unk = 0, + lastSeen = 1_710_000_000, + appearance = listOf(0, 0, 0, 0, 0), + ), + ), + ) + val decoded = FriendListPacketCodec.decodeBytes(FriendListPacketCodec.encodeToBytes(pkt)) + decoded shouldBe pkt + decoded.entries.map { it.name } shouldBe listOf("Alpha", "BravoBravoBravo") + decoded.entries.map { it.online } shouldBe listOf(false, true) + } + }) diff --git a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameProtocolTest.kt b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameProtocolTest.kt index 7b1e85a..6d553ac 100644 --- a/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameProtocolTest.kt +++ b/protocols.game/src/test/kotlin/de/fiereu/openmmo/net/game/GameProtocolTest.kt @@ -11,13 +11,14 @@ import de.fiereu.openmmo.net.game.packets.LoadMapPacket import de.fiereu.openmmo.net.game.packets.NullPacket import de.fiereu.openmmo.net.game.packets.TokenPayloadPacket import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.collections.shouldContainAll import io.kotest.matchers.shouldBe class GameProtocolTest : FunSpec({ test("at least one registration per known opcode") { val opcodes = GameProtocol.registrations.map { it.opcode }.toSet() - opcodes shouldBe + opcodes shouldContainAll setOf( 0x01u.toUByte(), 0x02u.toUByte(), diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/GameServer.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/GameServer.kt index 34fb777..9c06c9b 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/GameServer.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/GameServer.kt @@ -30,8 +30,8 @@ class GameServer @Inject constructor( private val config: GameServerConfig, - @Named("boss") private val bossGroup: EventLoopGroup, - @Named("worker") private val workerGroup: EventLoopGroup, + @param:Named("boss") private val bossGroup: EventLoopGroup, + @param:Named("worker") private val workerGroup: EventLoopGroup, private val rootKey: ECPrivateKey, private val handlerProvider: Provider, private val sessionRegistry: SessionRegistry, diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandler.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandler.kt index 648a7a1..1a1ac28 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandler.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandler.kt @@ -6,24 +6,32 @@ import de.fiereu.network.coroutines.CoroutineProtocolHandler import de.fiereu.openmmo.common.enums.ChatType import de.fiereu.openmmo.common.enums.Language import de.fiereu.openmmo.net.game.GameProtocol +import de.fiereu.openmmo.net.game.packets.AddFriendPacket +import de.fiereu.openmmo.net.game.packets.BlockPlayerPacket +import de.fiereu.openmmo.net.game.packets.CancelSocialInteractionPacket import de.fiereu.openmmo.net.game.packets.ChatMessagePacket import de.fiereu.openmmo.net.game.packets.CreateCharacterPacket import de.fiereu.openmmo.net.game.packets.DialogChoicePacket import de.fiereu.openmmo.net.game.packets.EntityInteractPacket import de.fiereu.openmmo.net.game.packets.EntityLeavePacket import de.fiereu.openmmo.net.game.packets.FaceDirectionPacket +import de.fiereu.openmmo.net.game.packets.FriendProfileRequestPacket import de.fiereu.openmmo.net.game.packets.InteractiveResponsePacket import de.fiereu.openmmo.net.game.packets.JoinPacket import de.fiereu.openmmo.net.game.packets.KeepAlivePacket import de.fiereu.openmmo.net.game.packets.MovementPacket +import de.fiereu.openmmo.net.game.packets.RemoveFriendPacket import de.fiereu.openmmo.net.game.packets.RequestCharactersPacket import de.fiereu.openmmo.net.game.packets.RequestPlayerPacket +import de.fiereu.openmmo.net.game.packets.RequestSocialProfilePacket import de.fiereu.openmmo.net.game.packets.SelectCharacterPacket +import de.fiereu.openmmo.net.game.packets.UnblockPlayerPacket import de.fiereu.openmmo.server.game.services.DialogService import de.fiereu.openmmo.server.game.services.InteractionService import de.fiereu.openmmo.server.game.services.LoginService import de.fiereu.openmmo.server.game.services.MovementService import de.fiereu.openmmo.server.game.services.MultiplayerService +import de.fiereu.openmmo.server.game.services.SocialService import de.fiereu.openmmo.server.game.session.PLAYER_STATE import de.fiereu.openmmo.server.game.session.SessionRegistry import de.fiereu.openmmo.server.game.storage.CharacterStore @@ -41,6 +49,7 @@ constructor( private val dialogService: DialogService, private val interactionService: InteractionService, private val multiplayerService: MultiplayerService, + private val socialService: SocialService, private val sessionRegistry: SessionRegistry, private val characterStore: CharacterStore, scope: CoroutineScope, @@ -60,6 +69,14 @@ constructor( onSuspend { event -> dialogService.onInteractive(event) } onSuspend { event -> dialogService.onDialogChoice(event) } + on { event -> socialService.onAddFriend(event) } + on { event -> socialService.onRemoveFriend(event) } + on { event -> socialService.onBlockPlayer(event) } + on { event -> socialService.onUnblockPlayer(event) } + on { event -> socialService.onFriendProfileRequest(event) } + on { event -> socialService.onRequestSocialProfile(event) } + on { event -> socialService.onCancelSocialInteraction(event) } + on { event -> event.session.send(event.packet) } on { event -> onChatMessage(event) } } diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt index 8ac9f93..30deb42 100644 --- a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/LoginService.kt @@ -42,6 +42,7 @@ constructor( private val mapLoadService: MapLoadService, private val npcService: NpcService, private val multiplayerService: MultiplayerService, + private val socialService: SocialService, private val sessionRegistry: SessionRegistry, private val mapManager: MapManager, private val characterStore: CharacterStore, @@ -283,6 +284,9 @@ constructor( } ctx.send(RenderScreenPacket(true)) + + socialService.sendFriendList(ctx) + log.info { "Player $charId spawned in bank=$bankId map=$mapId; ${others.size} others present" } } } diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/SocialService.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/SocialService.kt new file mode 100644 index 0000000..6aa3e5e --- /dev/null +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/services/SocialService.kt @@ -0,0 +1,118 @@ +package de.fiereu.openmmo.server.game.services + +import de.fiereu.network.PacketEvent +import de.fiereu.network.SessionContext +import de.fiereu.openmmo.net.game.packets.AddFriendPacket +import de.fiereu.openmmo.net.game.packets.BlockPlayerPacket +import de.fiereu.openmmo.net.game.packets.CancelSocialInteractionPacket +import de.fiereu.openmmo.net.game.packets.FriendListEntry +import de.fiereu.openmmo.net.game.packets.FriendListPacket +import de.fiereu.openmmo.net.game.packets.FriendProfileRequestPacket +import de.fiereu.openmmo.net.game.packets.PartyMemberJoinPacket +import de.fiereu.openmmo.net.game.packets.PartyMemberLeavePacket +import de.fiereu.openmmo.net.game.packets.RemoveFriendPacket +import de.fiereu.openmmo.net.game.packets.RequestSocialProfilePacket +import de.fiereu.openmmo.net.game.packets.UnblockPlayerPacket +import de.fiereu.openmmo.server.game.session.PLAYER_STATE +import de.fiereu.openmmo.server.game.session.SessionRegistry +import de.fiereu.openmmo.server.game.storage.CharacterStore +import de.fiereu.openmmo.server.game.storage.SocialStore +import io.github.oshai.kotlinlogging.KotlinLogging +import javax.inject.Inject +import javax.inject.Singleton + +private val log = KotlinLogging.logger {} + +@Singleton +class SocialService +@Inject +constructor( + private val socialStore: SocialStore, + private val sessionRegistry: SessionRegistry, + private val characterStore: CharacterStore, +) { + + fun sendFriendList(ctx: SessionContext) { + val state = ctx.attributes[PLAYER_STATE] ?: return + ctx.send(buildFriendList(state.userId)) + } + + fun onAddFriend(event: PacketEvent) { + val ctx = event.session + val state = ctx.attributes[PLAYER_STATE] ?: return + val name = event.packet.username + socialStore.addFriend(state.userId, name) + log.info { "AddFriend user=${state.userId} name='$name'" } + ctx.send(buildFriendList(state.userId)) + } + + fun onRemoveFriend(event: PacketEvent) { + val ctx = event.session + val state = ctx.attributes[PLAYER_STATE] ?: return + val name = event.packet.username + val removed = socialStore.removeFriend(state.userId, name) + log.info { "RemoveFriend user=${state.userId} name='$name' removed=$removed" } + ctx.send(buildFriendList(state.userId)) + } + + fun onBlockPlayer(event: PacketEvent) { + val ctx = event.session + val state = ctx.attributes[PLAYER_STATE] ?: return + val packet = event.packet + socialStore.block(state.userId, packet.username) + log.info { + "BlockPlayer user=${state.userId} name='${packet.username}' reason='${packet.reason}'" + } + ctx.send( + PartyMemberJoinPacket( + player = syntheticId(packet.username), + name = packet.username, + secondaryName = packet.reason, + value = 0, + )) + } + + fun onUnblockPlayer(event: PacketEvent) { + val ctx = event.session + val state = ctx.attributes[PLAYER_STATE] ?: return + val name = event.packet.username + val removed = socialStore.unblock(state.userId, name) + log.info { "UnblockPlayer user=${state.userId} name='$name' removed=$removed" } + ctx.send(PartyMemberLeavePacket(memberId = syntheticId(name))) + } + + fun onFriendProfileRequest(event: PacketEvent) { + log.info { "FriendProfileRequest targetEntityId=${event.packet.targetEntityId}" } + } + + fun onRequestSocialProfile(event: PacketEvent) { + log.info { "RequestSocialProfile targetId=${event.packet.targetId}" } + } + + fun onCancelSocialInteraction(event: PacketEvent) { + log.info { "CancelSocialInteraction from ${event.session.remoteAddress}" } + } + + private fun buildFriendList(userId: Int): FriendListPacket { + val entries = + socialStore.getFriends(userId).map { name -> + FriendListEntry( + player = syntheticId(name), + friendsSince = 0, + online = isOnlineByName(name), + name = name, + unk = 0, + lastSeen = 0, + appearance = List(5) { 0 }, + ) + } + return FriendListPacket(mode = 0, entries = entries) + } + + private fun isOnlineByName(name: String): Boolean = + sessionRegistry.onlineCharacterIds().any { id -> + characterStore.getCharacter(id)?.info?.name == name + } + + private fun syntheticId(name: String): Long = (name.hashCode().toLong() shl 16) or 0x9000L +} diff --git a/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/storage/SocialStore.kt b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/storage/SocialStore.kt new file mode 100644 index 0000000..f5ada5f --- /dev/null +++ b/server.game/src/main/kotlin/de/fiereu/openmmo/server/game/storage/SocialStore.kt @@ -0,0 +1,31 @@ +package de.fiereu.openmmo.server.game.storage + +import java.util.concurrent.ConcurrentHashMap +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class SocialStore @Inject constructor() { + private val friendsByUser = ConcurrentHashMap>() + private val blockedByUser = ConcurrentHashMap>() + + fun getFriends(userId: Int): Set = friendsByUser.getOrPut(userId) { seedFriends() } + + fun addFriend(userId: Int, name: String) { + friendsByUser.getOrPut(userId) { seedFriends() }.add(name) + } + + fun removeFriend(userId: Int, name: String): Boolean = + friendsByUser.getOrPut(userId) { seedFriends() }.remove(name) + + fun getBlocked(userId: Int): Set = blockedByUser.getOrPut(userId) { mutableSetOf() } + + fun block(userId: Int, name: String) { + blockedByUser.getOrPut(userId) { mutableSetOf() }.add(name) + } + + fun unblock(userId: Int, name: String): Boolean = + blockedByUser.getOrPut(userId) { mutableSetOf() }.remove(name) + + private fun seedFriends(): MutableSet = linkedSetOf("Red", "Blue", "Green") +} diff --git a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandlerTest.kt b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandlerTest.kt index 6d959c3..bb7cec8 100644 --- a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandlerTest.kt +++ b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/handler/GameAppHandlerTest.kt @@ -1,9 +1,12 @@ package de.fiereu.openmmo.server.game.handler +import de.fiereu.openmmo.net.game.packets.AddFriendPacket +import de.fiereu.openmmo.net.game.packets.BlockPlayerPacket import de.fiereu.openmmo.net.game.packets.ChatMessagePacket import de.fiereu.openmmo.net.game.packets.JoinPacket import de.fiereu.openmmo.net.game.packets.KeepAlivePacket import de.fiereu.openmmo.net.game.packets.MovementPacket +import de.fiereu.openmmo.net.game.packets.RemoveFriendPacket import de.fiereu.openmmo.server.game.config.GameServerConfig import de.fiereu.openmmo.server.game.di.DaggerGameServerComponent import io.kotest.core.spec.style.FunSpec @@ -26,5 +29,8 @@ class GameAppHandlerTest : handler.isRegistered(MovementPacket::class) shouldBe true handler.isRegistered(ChatMessagePacket::class) shouldBe true handler.isRegistered(KeepAlivePacket::class) shouldBe true + handler.isRegistered(AddFriendPacket::class) shouldBe true + handler.isRegistered(RemoveFriendPacket::class) shouldBe true + handler.isRegistered(BlockPlayerPacket::class) shouldBe true } }) diff --git a/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/storage/SocialStoreTest.kt b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/storage/SocialStoreTest.kt new file mode 100644 index 0000000..5727b94 --- /dev/null +++ b/server.game/src/test/kotlin/de/fiereu/openmmo/server/game/storage/SocialStoreTest.kt @@ -0,0 +1,31 @@ +package de.fiereu.openmmo.server.game.storage + +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe + +class SocialStoreTest : + FunSpec({ + test("friends are seeded per user and survive add/remove") { + val store = SocialStore() + store.getFriends(1) shouldBe linkedSetOf("Red", "Blue", "Green") + + store.addFriend(1, "Yellow") + store.getFriends(1).contains("Yellow") shouldBe true + + store.removeFriend(1, "Red") shouldBe true + store.getFriends(1).contains("Red") shouldBe false + store.removeFriend(1, "Red") shouldBe false + } + + test("block list is independent per user") { + val store = SocialStore() + store.getBlocked(1) shouldBe emptySet() + + store.block(1, "Troll") + store.getBlocked(1) shouldBe setOf("Troll") + store.getBlocked(2) shouldBe emptySet() + + store.unblock(1, "Troll") shouldBe true + store.getBlocked(1) shouldBe emptySet() + } + }) diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt index 736e024..8561870 100644 --- a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt @@ -24,8 +24,8 @@ class LoginServer @Inject constructor( private val config: LoginServerConfig, - @Named("boss") private val bossGroup: EventLoopGroup, - @Named("worker") private val workerGroup: EventLoopGroup, + @param:Named("boss") private val bossGroup: EventLoopGroup, + @param:Named("worker") private val workerGroup: EventLoopGroup, private val rootKey: ECPrivateKey, private val handlerProvider: Provider, ) {