feat(game): implement Hoenn story through Rustboro (#77)
* feat(game): implement Hoenn story through Rustboro * fix(game): group dialog presentation options * fix(game): address review feedback and running movement
This commit is contained in:
1 parent
f57149eae3
commit
3b19a81201
85 files changed
+4064
-358
No files matched your search
@@ -123,7 +123,7 @@ object GameProtocol : Protocol() {
|
||||
s2c<ShopPriceTablePacket>(0x29u, ShopPriceTablePacketCodec)
|
||||
|
||||
c2s<TeamNameChangePacket>(0x2Au, TeamNameChangePacketCodec)
|
||||
s2c<BattleStatusFlagPacket>(0x2Au, BattleStatusFlagPacketCodec)
|
||||
s2c<StoryFlagUpdatePacket>(0x2Au, StoryFlagUpdatePacketCodec)
|
||||
|
||||
c2s<SetCharacterNamePacket>(0x2Bu, SetCharacterNamePacketCodec)
|
||||
s2c<FollowerAdvancePacket>(0x2Bu, FollowerAdvancePacketCodec)
|
||||
@@ -276,12 +276,12 @@ object GameProtocol : Protocol() {
|
||||
s2c<EntityCoordSyncPacket>(0x61u, EntityCoordSyncPacketCodec)
|
||||
|
||||
c2s<AddFriendPacket>(0x62u, AddFriendPacketCodec)
|
||||
s2c<SocialActionOutcomePacket>(0x62u, SocialActionOutcomePacketCodec)
|
||||
s2c<DeleteCharacterResultPacket>(0x62u, DeleteCharacterResultPacketCodec)
|
||||
|
||||
c2s<RemoveFriendPacket>(0x63u, RemoveFriendPacketCodec)
|
||||
s2c<FriendListPacket>(0x63u, FriendListPacketCodec)
|
||||
|
||||
c2s<FriendProfileRequestPacket>(0x64u, FriendProfileRequestPacketCodec)
|
||||
c2s<DeleteCharacterPacket>(0x64u, DeleteCharacterPacketCodec)
|
||||
s2c<ContactInsertPacket>(0x64u, ContactInsertPacketCodec)
|
||||
|
||||
s2c<ContactDeletePacket>(0x65u, ContactDeletePacketCodec)
|
||||
@@ -567,6 +567,8 @@ object GameProtocol : Protocol() {
|
||||
c2s<BattleChallengeRequestPacket>(0xE4u, BattleChallengeRequestPacketCodec)
|
||||
s2c<EntityMovePacket>(0xE4u, EntityMovePacketCodec)
|
||||
|
||||
s2c<GbaEntityMovePacket>(0xEAu, GbaEntityMovePacketCodec)
|
||||
|
||||
s2c<QueuePositionPacket>(0xF0u, QueuePositionPacketCodec)
|
||||
|
||||
c2s<ChunkedTransferDataPacket>(0xF1u, ChunkedTransferDataPacketCodec)
|
||||
|
||||
+8
-5
@@ -41,16 +41,19 @@ class CharacterInfoCodec(private val withExtraLong: Boolean) : PacketCodec<Chara
|
||||
val battleBoxExtraSlots = field(S8, CharacterInfo::battleBoxExtraSlots)
|
||||
val templateAmount = field(S8, CharacterInfo::templateAmount)
|
||||
field(S8) { 0 }
|
||||
field(S8) { 0 }
|
||||
field(S8) { 0 }
|
||||
// Captured markers precede the complete position block.
|
||||
field(S8, CharacterInfo::positionRegionId)
|
||||
field(S8) { -1 }
|
||||
field(S8) { 2 }
|
||||
val positionRegionId = field(S8, CharacterInfo::positionRegionId)
|
||||
val positionBankId = field(S8, CharacterInfo::positionBankId)
|
||||
val positionMapId = field(S8, CharacterInfo::positionMapId)
|
||||
field(S8) { 0 }
|
||||
val positionMapId =
|
||||
field(
|
||||
S16LE.imap(decode = { it.toByte() }, encode = { it.toShort() }),
|
||||
CharacterInfo::positionMapId)
|
||||
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 }
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.*
|
||||
|
||||
data class Skin(val slot: SkinSlot, val type: UShort?, val color: UByte?)
|
||||
|
||||
class SkinSet : EnumMap<SkinSlot, Skin>(SkinSlot::class.java) {
|
||||
class SkinSet(var regionSelectionIndex: Int = 0) : EnumMap<SkinSlot, Skin>(SkinSlot::class.java) {
|
||||
fun put(skin: Skin) {
|
||||
this[skin.slot] = skin
|
||||
}
|
||||
@@ -22,9 +22,12 @@ class SkinSetCodec(
|
||||
private val withLeadingByte: Boolean = true,
|
||||
) : PacketCodec<SkinSet>() {
|
||||
override fun CodecScope<SkinSet>.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()
|
||||
val regionSelectionIndex = if (withLeadingByte) field(U8) { it.regionSelectionIndex } else 0
|
||||
val mask =
|
||||
field(U16LE) { skins ->
|
||||
skins.keys.filter { it in slots }.fold(0) { acc, slot -> acc or (1 shl slot.ordinal) }
|
||||
}
|
||||
val skins = SkinSet(regionSelectionIndex)
|
||||
slots.forEach { slot ->
|
||||
if ((mask and (1 shl slot.ordinal)) != 0) {
|
||||
val compressed =
|
||||
|
||||
+14
-2
@@ -2,13 +2,25 @@ package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S8
|
||||
import de.fiereu.bytecodec.Utf16LeNullTerminated
|
||||
import de.fiereu.openmmo.net.game.codecs.DefaultSkinSetCodec
|
||||
import de.fiereu.openmmo.net.game.codecs.SkinSet
|
||||
|
||||
data class CreateCharacterPacket(val name: String)
|
||||
/** The choices submitted by the client's character creator. */
|
||||
data class CreateCharacterPacket(
|
||||
val name: String,
|
||||
val gender: Byte,
|
||||
val startingRegion: Byte,
|
||||
val appearance: SkinSet,
|
||||
)
|
||||
|
||||
object CreateCharacterPacketCodec : PacketCodec<CreateCharacterPacket>() {
|
||||
override fun CodecScope<CreateCharacterPacket>.body(): CreateCharacterPacket {
|
||||
val name = field(Utf16LeNullTerminated) { it.name }
|
||||
return CreateCharacterPacket(name)
|
||||
val gender = field(S8) { it.gender }
|
||||
val startingRegion = field(S8) { it.startingRegion }
|
||||
val appearance = field(DefaultSkinSetCodec) { it.appearance }
|
||||
return CreateCharacterPacket(name, gender, startingRegion, appearance)
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S64LE
|
||||
import de.fiereu.bytecodec.U8
|
||||
|
||||
/** Character-selection deletion request, captured as opcode 0x64 followed by the character id. */
|
||||
data class DeleteCharacterPacket(val characterId: Long)
|
||||
|
||||
object DeleteCharacterPacketCodec : PacketCodec<DeleteCharacterPacket>() {
|
||||
override fun CodecScope<DeleteCharacterPacket>.body(): DeleteCharacterPacket =
|
||||
DeleteCharacterPacket(field(S64LE) { it.characterId })
|
||||
}
|
||||
|
||||
/** Captured character deletion result. */
|
||||
data class DeleteCharacterResultPacket(val result: Int, val characterId: Long)
|
||||
|
||||
object DeleteCharacterResultPacketCodec : PacketCodec<DeleteCharacterResultPacket>() {
|
||||
override fun CodecScope<DeleteCharacterResultPacket>.body(): DeleteCharacterResultPacket {
|
||||
val result = field(U8) { it.result }
|
||||
val characterId = field(S64LE) { it.characterId }
|
||||
return DeleteCharacterResultPacket(result, characterId)
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S64LE
|
||||
import de.fiereu.bytecodec.U8
|
||||
import de.fiereu.bytecodec.enumByOrdinalByte
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
|
||||
/** Opcode 0xEA (s2c). A GBA-map entity's new tile after one step. */
|
||||
data class GbaEntityMovePacket(
|
||||
val entityId: Long,
|
||||
val bankId: Int,
|
||||
val mapId: Int,
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val movementMode: Int = 2,
|
||||
val direction: Direction,
|
||||
)
|
||||
|
||||
object GbaEntityMovePacketCodec : PacketCodec<GbaEntityMovePacket>() {
|
||||
private val DirectionCodec = enumByOrdinalByte<Direction>()
|
||||
|
||||
override fun CodecScope<GbaEntityMovePacket>.body(): GbaEntityMovePacket {
|
||||
val entityId = field(S64LE) { it.entityId }
|
||||
val bankId = field(U8) { it.bankId }
|
||||
val mapId = field(U8) { it.mapId }
|
||||
val x = field(U8) { it.x }
|
||||
val y = field(U8) { it.y }
|
||||
val movementMode = field(U8) { it.movementMode }
|
||||
val direction = field(DirectionCodec) { it.direction }
|
||||
return GbaEntityMovePacket(entityId, bankId, mapId, x, y, movementMode, direction)
|
||||
}
|
||||
}
|
||||
+22
-4
@@ -1,12 +1,30 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.*
|
||||
|
||||
class MapLoadedAckPacket
|
||||
/** Empty payload means the client is ready. */
|
||||
data class MapLoadedAckPacket(val data: ByteArray = byteArrayOf()) {
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is MapLoadedAckPacket && data.contentEquals(other.data)
|
||||
|
||||
override fun hashCode(): Int = data.contentHashCode()
|
||||
}
|
||||
|
||||
private val MapLoadedAckBytes: Codec<ByteArray> =
|
||||
object : Codec<ByteArray> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
object MapLoadedAckPacketCodec : PacketCodec<MapLoadedAckPacket>() {
|
||||
override fun CodecScope<MapLoadedAckPacket>.body(): MapLoadedAckPacket {
|
||||
return MapLoadedAckPacket()
|
||||
return MapLoadedAckPacket(field(MapLoadedAckBytes, MapLoadedAckPacket::data))
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -3,18 +3,23 @@ package de.fiereu.openmmo.net.game.packets
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S16LE
|
||||
import de.fiereu.bytecodec.enumByOrdinalByte
|
||||
import de.fiereu.bytecodec.U8
|
||||
import de.fiereu.openmmo.common.enums.Direction
|
||||
|
||||
data class MovementPacket(val x: Int, val y: Int, val direction: Direction)
|
||||
data class MovementPacket(
|
||||
val x: Int,
|
||||
val y: Int,
|
||||
val direction: Direction,
|
||||
val running: Boolean = false,
|
||||
)
|
||||
|
||||
object MovementPacketCodec : PacketCodec<MovementPacket>() {
|
||||
private val DirectionCodec = enumByOrdinalByte<Direction>()
|
||||
|
||||
override fun CodecScope<MovementPacket>.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)
|
||||
val state = field(U8) { it.direction.ordinal or (if (it.running) 0x80 else 0) }
|
||||
val direction = Direction.entries[state and 0x03]
|
||||
val running = state and 0x80 != 0
|
||||
return MovementPacket(x.toInt(), y.toInt(), direction, running)
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package de.fiereu.openmmo.net.game.packets
|
||||
|
||||
import de.fiereu.bytecodec.CodecScope
|
||||
import de.fiereu.bytecodec.PacketCodec
|
||||
import de.fiereu.bytecodec.S16LE
|
||||
import de.fiereu.bytecodec.S8
|
||||
|
||||
/** Opcode 0x2A (s2c). Sets or clears one region-specific GBA story flag. */
|
||||
data class StoryFlagUpdatePacket(
|
||||
val regionId: Byte,
|
||||
val flagId: Int,
|
||||
val enabled: Boolean,
|
||||
)
|
||||
|
||||
object StoryFlagUpdatePacketCodec : PacketCodec<StoryFlagUpdatePacket>() {
|
||||
override fun CodecScope<StoryFlagUpdatePacket>.body(): StoryFlagUpdatePacket {
|
||||
val regionId = field(S8) { it.regionId }
|
||||
val flagId = field(S16LE) { it.flagId.toShort() }.toInt() and 0xffff
|
||||
val enabled = field(S16LE) { if (it.enabled) 1 else 0 }.toInt() != 0
|
||||
return StoryFlagUpdatePacket(regionId, flagId, enabled)
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -10,8 +10,12 @@ data class CreatureDataArg(val value: Int, val args: List<DialogMessageArg>) : D
|
||||
|
||||
data class CreatureMovesArg(val team: Byte, val moveIds: List<Short>) : DialogMessageArg()
|
||||
|
||||
data class MoveAnimationArg(val sourceSlot: Byte, val targetSlot: Byte, val moveId: Short) :
|
||||
DialogMessageArg()
|
||||
/** Fills a ROM string variable with a species name. */
|
||||
data class TextPokemonSpeciesArg(
|
||||
val partySlot: Byte,
|
||||
val stringVariable: Byte,
|
||||
val speciesId: Short,
|
||||
) : DialogMessageArg()
|
||||
|
||||
data class TextCreatureArg(
|
||||
val slot: Byte,
|
||||
@@ -38,8 +42,7 @@ private val DialogMessageArgCodec: Codec<DialogMessageArg> =
|
||||
}
|
||||
|
||||
2 -> {
|
||||
val moveId = S16LE.read(buf)
|
||||
MoveAnimationArg(buf.readByte(), buf.readByte(), moveId)
|
||||
TextPokemonSpeciesArg(buf.readByte(), buf.readByte(), S16LE.read(buf))
|
||||
}
|
||||
|
||||
3 -> TextCreatureArg(buf.readByte(), buf.readByte(), S16LE.read(buf), S16LE.read(buf))
|
||||
@@ -63,11 +66,11 @@ private val DialogMessageArgCodec: Codec<DialogMessageArg> =
|
||||
value.moveIds.forEach { S16LE.write(buf, it) }
|
||||
}
|
||||
|
||||
is MoveAnimationArg -> {
|
||||
is TextPokemonSpeciesArg -> {
|
||||
buf.writeByte(2)
|
||||
S16LE.write(buf, value.moveId)
|
||||
buf.writeByte(value.sourceSlot)
|
||||
buf.writeByte(value.targetSlot)
|
||||
buf.writeByte(value.partySlot)
|
||||
buf.writeByte(value.stringVariable)
|
||||
S16LE.write(buf, value.speciesId)
|
||||
}
|
||||
|
||||
is TextCreatureArg -> {
|
||||
|
||||
Reference in new issue
Block a user