add initial game packets
This commit is contained in:
1 parent
621440690f
commit
8c82990b9a
43 files changed
+1790
-100
No files matched your search
@@ -0,0 +1,29 @@
|
|||||||
|
package de.fiereu.openmmo.common
|
||||||
|
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
data class CharacterInfo(
|
||||||
|
val id: Long,
|
||||||
|
val name: String,
|
||||||
|
val namePrefix: String = "",
|
||||||
|
val userId: Int,
|
||||||
|
val rivalSex: Byte,
|
||||||
|
val lastLogin: LocalDateTime,
|
||||||
|
val createdAt: LocalDateTime,
|
||||||
|
val money: Int,
|
||||||
|
val permissions: Int,
|
||||||
|
val remainingSafariSteps: Short,
|
||||||
|
val remainingSafariBalls: Byte,
|
||||||
|
val pcExtraSlots: Byte,
|
||||||
|
val battleBoxExtraSlots: Byte,
|
||||||
|
val templateAmount: Byte,
|
||||||
|
val positionRegionId: Byte,
|
||||||
|
val positionBankId: Byte,
|
||||||
|
val positionMapId: Byte,
|
||||||
|
val positionX: Short,
|
||||||
|
val positionY: Short,
|
||||||
|
val repelLeft: Short,
|
||||||
|
val repelItemId: Short,
|
||||||
|
val lureLeft: Short,
|
||||||
|
val lureItemId: Short
|
||||||
|
)
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package de.fiereu.openmmo.common
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.enums.EVs
|
||||||
|
import de.fiereu.openmmo.common.enums.IVs
|
||||||
|
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||||
|
import de.fiereu.openmmo.common.enums.PokemonNature
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
data class Pokemon(
|
||||||
|
val id: Long,
|
||||||
|
val container: PokemonContainer,
|
||||||
|
val containerSlot: Short,
|
||||||
|
val dexId: Int,
|
||||||
|
val seed: Int,
|
||||||
|
val ot: String,
|
||||||
|
val nickname: String,
|
||||||
|
val level: Byte,
|
||||||
|
val hp: Short,
|
||||||
|
val xp: Int,
|
||||||
|
val eVs: EVs,
|
||||||
|
val iVs: IVs,
|
||||||
|
val moves: List<PokemonMove>,
|
||||||
|
val isShiny: Boolean,
|
||||||
|
val hasHiddenAbility: Boolean,
|
||||||
|
val isAlpha: Boolean,
|
||||||
|
val isSecret: Boolean,
|
||||||
|
val isFatefulEncounter: Boolean,
|
||||||
|
val isRaidEncounter: Boolean,
|
||||||
|
val caughtAt: LocalDateTime
|
||||||
|
) {
|
||||||
|
val nature: PokemonNature = PokemonNature.entries[seed % PokemonNature.entries.size]
|
||||||
|
|
||||||
|
init {
|
||||||
|
require(moves.size <= 4) { "A Pokemon can't have more than 4 moves" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class PokemonMove(val id: Short, var pp: Byte)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package de.fiereu.openmmo.common
|
||||||
|
|
||||||
|
data class Tile2D(val material: Short, val collision: Byte)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class ChatType {
|
||||||
|
NORMAL,
|
||||||
|
UNK1,
|
||||||
|
UNK2,
|
||||||
|
SHOUT,
|
||||||
|
WHISPER,
|
||||||
|
TRADE,
|
||||||
|
GLOBAL,
|
||||||
|
CHANNEL,
|
||||||
|
TEAM,
|
||||||
|
LINK,
|
||||||
|
UNK3,
|
||||||
|
UNK4,
|
||||||
|
UNK5,
|
||||||
|
UNK6,
|
||||||
|
UNK7,
|
||||||
|
UNK8,
|
||||||
|
SYSTEM_ANNOUNCEMENTS,
|
||||||
|
GAME_NOTIFICATIONS,
|
||||||
|
BATTLE
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class Direction {
|
||||||
|
NORTH,
|
||||||
|
SOUTH,
|
||||||
|
EAST,
|
||||||
|
WEST
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class EncounterType {
|
||||||
|
RANDOM,
|
||||||
|
GYM_STYLE,
|
||||||
|
VILLAIN_TEAM_STYLE,
|
||||||
|
UNKNOWN_0x03,
|
||||||
|
TOP_4_1,
|
||||||
|
TOP_4_2,
|
||||||
|
TOP_4_3,
|
||||||
|
TOP_4_4,
|
||||||
|
BIG_RED_BALL
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class EntityStatus {
|
||||||
|
NONE,
|
||||||
|
WILD,
|
||||||
|
PVP,
|
||||||
|
SPECTATE,
|
||||||
|
WANTS_REMATCH,
|
||||||
|
NO_REMATCH,
|
||||||
|
TRAINER_AGGRO,
|
||||||
|
DISCONNECTED
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class Flavor {
|
||||||
|
SPICY,
|
||||||
|
DRY,
|
||||||
|
SWEET,
|
||||||
|
BITTER,
|
||||||
|
SOUR,
|
||||||
|
/* IDK about this one. The client uses it with id -128 */
|
||||||
|
NONE
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class Lighting {
|
||||||
|
REGULAR,
|
||||||
|
DARK_FLASH_USABLE,
|
||||||
|
DARK_FLASH_UNUSABLE
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class MapType {
|
||||||
|
UNKNOWN_0x00,
|
||||||
|
UNKNOWN_0x01,
|
||||||
|
CITY,
|
||||||
|
ROUTE,
|
||||||
|
UNDERGROUND,
|
||||||
|
UNDERWATER,
|
||||||
|
UNKNOWN_0x06,
|
||||||
|
UNKNOWN_0x07,
|
||||||
|
INSIDE,
|
||||||
|
SECRET_BASE
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class PokemonContainer {
|
||||||
|
PC,
|
||||||
|
PARTY,
|
||||||
|
TRADE,
|
||||||
|
DAYCARE,
|
||||||
|
RENTAL_PARTY,
|
||||||
|
MAIL,
|
||||||
|
AUCTION,
|
||||||
|
VOID,
|
||||||
|
DELETED,
|
||||||
|
EVENT
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class PokemonNature(
|
||||||
|
val increasedStat: PokemonStat,
|
||||||
|
val decreasedStat: PokemonStat,
|
||||||
|
val favoriteFlavor: Flavor,
|
||||||
|
val dislikedFlavor: Flavor
|
||||||
|
) {
|
||||||
|
HARDY(PokemonStat.ATTACK, PokemonStat.ATTACK, Flavor.SPICY, Flavor.SPICY),
|
||||||
|
LONELY(PokemonStat.ATTACK, PokemonStat.DEFENSE, Flavor.SPICY, Flavor.SOUR),
|
||||||
|
BRAVE(PokemonStat.ATTACK, PokemonStat.SPEED, Flavor.SPICY, Flavor.SWEET),
|
||||||
|
ADAMANT(PokemonStat.ATTACK, PokemonStat.SP_ATTACK, Flavor.SPICY, Flavor.DRY),
|
||||||
|
NAUGHTY(PokemonStat.ATTACK, PokemonStat.SP_DEFENSE, Flavor.SPICY, Flavor.BITTER),
|
||||||
|
BOLD(PokemonStat.DEFENSE, PokemonStat.ATTACK, Flavor.SOUR, Flavor.SPICY),
|
||||||
|
DOCILE(PokemonStat.DEFENSE, PokemonStat.DEFENSE, Flavor.SOUR, Flavor.SOUR),
|
||||||
|
RELAXED(PokemonStat.DEFENSE, PokemonStat.SPEED, Flavor.SOUR, Flavor.SWEET),
|
||||||
|
IMPISH(PokemonStat.DEFENSE, PokemonStat.SP_ATTACK, Flavor.SOUR, Flavor.DRY),
|
||||||
|
LAX(PokemonStat.DEFENSE, PokemonStat.SP_DEFENSE, Flavor.SOUR, Flavor.BITTER),
|
||||||
|
TIMID(PokemonStat.SPEED, PokemonStat.ATTACK, Flavor.SWEET, Flavor.SPICY),
|
||||||
|
HASTY(PokemonStat.SPEED, PokemonStat.DEFENSE, Flavor.SWEET, Flavor.SOUR),
|
||||||
|
SERIOUS(PokemonStat.SPEED, PokemonStat.SPEED, Flavor.SWEET, Flavor.SWEET),
|
||||||
|
JOLLY(PokemonStat.SPEED, PokemonStat.SP_ATTACK, Flavor.SWEET, Flavor.DRY),
|
||||||
|
NAIVE(PokemonStat.SPEED, PokemonStat.SP_DEFENSE, Flavor.SWEET, Flavor.BITTER),
|
||||||
|
MODEST(PokemonStat.SP_ATTACK, PokemonStat.ATTACK, Flavor.DRY, Flavor.SPICY),
|
||||||
|
MILD(PokemonStat.SP_ATTACK, PokemonStat.DEFENSE, Flavor.DRY, Flavor.SOUR),
|
||||||
|
QUIET(PokemonStat.SP_ATTACK, PokemonStat.SPEED, Flavor.DRY, Flavor.SWEET),
|
||||||
|
BASHFUL(PokemonStat.SP_ATTACK, PokemonStat.SP_ATTACK, Flavor.DRY, Flavor.DRY),
|
||||||
|
RASH(PokemonStat.SP_ATTACK, PokemonStat.SP_DEFENSE, Flavor.DRY, Flavor.BITTER),
|
||||||
|
CALM(PokemonStat.SP_DEFENSE, PokemonStat.ATTACK, Flavor.BITTER, Flavor.SPICY),
|
||||||
|
GENTLE(PokemonStat.SP_DEFENSE, PokemonStat.DEFENSE, Flavor.BITTER, Flavor.SOUR),
|
||||||
|
SASSY(PokemonStat.SP_DEFENSE, PokemonStat.SPEED, Flavor.BITTER, Flavor.SWEET),
|
||||||
|
CAREFUL(PokemonStat.SP_DEFENSE, PokemonStat.SP_ATTACK, Flavor.BITTER, Flavor.DRY),
|
||||||
|
QUIRKY(PokemonStat.SP_DEFENSE, PokemonStat.SP_DEFENSE, Flavor.BITTER, Flavor.BITTER)
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class PokemonRarity {
|
||||||
|
SHINY,
|
||||||
|
HIDDEN_ABILITY,
|
||||||
|
ALPHA,
|
||||||
|
SECRET,
|
||||||
|
FATEFUL_ENCOUNTER,
|
||||||
|
RAID_ENCOUNTER
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
enum class PokemonStat {
|
||||||
|
HP,
|
||||||
|
ATTACK,
|
||||||
|
DEFENSE,
|
||||||
|
SP_ATTACK,
|
||||||
|
SP_DEFENSE,
|
||||||
|
SPEED
|
||||||
|
}
|
||||||
|
|
||||||
|
open class PokemonStats(private val individualCap: Int, private val totalCap: Int) :
|
||||||
|
EnumMap<PokemonStat, Byte>(PokemonStat.entries.associateWith { 0.toByte() }) {
|
||||||
|
|
||||||
|
val total
|
||||||
|
get() = hp + atk + def + spAtk + spDef + spd
|
||||||
|
|
||||||
|
private fun cr(value: Int): Byte {
|
||||||
|
if (value <= 0) error("Value can't be <= 0")
|
||||||
|
if (value > individualCap) error("Value exceeds individual capacity")
|
||||||
|
if (total > totalCap) error("Total value exceeds capacity")
|
||||||
|
return value.toByte()
|
||||||
|
}
|
||||||
|
|
||||||
|
var hp
|
||||||
|
get() = get(PokemonStat.HP)!!.toInt()
|
||||||
|
set(value) = set(PokemonStat.HP, cr(value))
|
||||||
|
|
||||||
|
var atk
|
||||||
|
get() = get(PokemonStat.ATTACK)!!.toInt()
|
||||||
|
set(value) = set(PokemonStat.ATTACK, cr(value))
|
||||||
|
|
||||||
|
var def
|
||||||
|
get() = get(PokemonStat.DEFENSE)!!.toInt()
|
||||||
|
set(value) = set(PokemonStat.DEFENSE, cr(value))
|
||||||
|
|
||||||
|
var spAtk
|
||||||
|
get() = get(PokemonStat.SP_ATTACK)!!.toInt()
|
||||||
|
set(value) = set(PokemonStat.SP_ATTACK, cr(value))
|
||||||
|
|
||||||
|
var spDef
|
||||||
|
get() = get(PokemonStat.SP_DEFENSE)!!.toInt()
|
||||||
|
set(value) = set(PokemonStat.SP_DEFENSE, cr(value))
|
||||||
|
|
||||||
|
var spd
|
||||||
|
get() = get(PokemonStat.SPEED)!!.toInt()
|
||||||
|
set(value) = set(PokemonStat.SPEED, cr(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
class EVs : PokemonStats(252, 510)
|
||||||
|
|
||||||
|
class IVs : PokemonStats(31, 155)
|
||||||
|
|
||||||
|
fun IVs.compress(): Int =
|
||||||
|
(((hp and 31) shl 0) or
|
||||||
|
((atk and 31) shl 5) or
|
||||||
|
((def and 31) shl 10) or
|
||||||
|
((spAtk and 31) shl 15) or
|
||||||
|
((spDef and 31) shl 20) or
|
||||||
|
((spd and 31) shl 25))
|
||||||
|
|
||||||
|
fun decompressIVs(value: Int): IVs =
|
||||||
|
IVs().apply {
|
||||||
|
hp = (value shr 0) and 31
|
||||||
|
atk = (value shr 5) and 31
|
||||||
|
def = (value shr 10) and 31
|
||||||
|
spAtk = (value shr 15) and 31
|
||||||
|
spDef = (value shr 20) and 31
|
||||||
|
spd = (value shr 25) and 31
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class PokemonBattleStat {
|
||||||
|
HP,
|
||||||
|
ATTACK,
|
||||||
|
DEFENSE,
|
||||||
|
SP_ATTACK,
|
||||||
|
SP_DEFENSE,
|
||||||
|
SPEED,
|
||||||
|
ACCURACY,
|
||||||
|
EVASION
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not sure if this is correct just copying from EVs here
|
||||||
|
class PokemonBattleStats :
|
||||||
|
EnumMap<PokemonBattleStat, Byte>(PokemonBattleStat.entries.associateWith { 0.toByte() }) {
|
||||||
|
private val individualCap: Int = 252
|
||||||
|
private val totalCap: Int = 510
|
||||||
|
|
||||||
|
val total
|
||||||
|
get() = hp + atk + def + spAtk + spDef + spd + acc + evs
|
||||||
|
|
||||||
|
private fun cr(value: Int): Byte {
|
||||||
|
if (value <= 0) error("Value can't be <= 0")
|
||||||
|
if (value > individualCap) error("Value exceeds individual capacity")
|
||||||
|
if (total > totalCap) error("Total value exceeds capacity")
|
||||||
|
return value.toByte()
|
||||||
|
}
|
||||||
|
|
||||||
|
var hp
|
||||||
|
get() = get(PokemonBattleStat.HP)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.HP, cr(value))
|
||||||
|
|
||||||
|
var atk
|
||||||
|
get() = get(PokemonBattleStat.ATTACK)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.ATTACK, cr(value))
|
||||||
|
|
||||||
|
var def
|
||||||
|
get() = get(PokemonBattleStat.DEFENSE)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.DEFENSE, cr(value))
|
||||||
|
|
||||||
|
var spAtk
|
||||||
|
get() = get(PokemonBattleStat.SP_ATTACK)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.SP_ATTACK, cr(value))
|
||||||
|
|
||||||
|
var spDef
|
||||||
|
get() = get(PokemonBattleStat.SP_DEFENSE)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.SP_DEFENSE, cr(value))
|
||||||
|
|
||||||
|
var spd
|
||||||
|
get() = get(PokemonBattleStat.SPEED)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.SPEED, cr(value))
|
||||||
|
|
||||||
|
var acc
|
||||||
|
get() = get(PokemonBattleStat.ACCURACY)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.SPEED, value.toByte())
|
||||||
|
|
||||||
|
var evs
|
||||||
|
get() = get(PokemonBattleStat.EVASION)!!.toInt()
|
||||||
|
set(value) = set(PokemonBattleStat.EVASION, value.toByte())
|
||||||
|
|
||||||
|
init {
|
||||||
|
// just guessing that "252 / 2" => 100%
|
||||||
|
acc = 252 / 2
|
||||||
|
evs = 252 / 2
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class PokemonType {
|
||||||
|
NORMAL,
|
||||||
|
FIGHTING,
|
||||||
|
FLYING,
|
||||||
|
POISON,
|
||||||
|
GROUND,
|
||||||
|
ROCK,
|
||||||
|
BUG,
|
||||||
|
GHOST,
|
||||||
|
STEEL,
|
||||||
|
QUESTIONQUESTIONQUESTION,
|
||||||
|
FIRE,
|
||||||
|
WATER,
|
||||||
|
GRASS,
|
||||||
|
ELECTRIC,
|
||||||
|
PSYCHIC,
|
||||||
|
ICE,
|
||||||
|
DRAGON,
|
||||||
|
DARK,
|
||||||
|
NONE
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class SkinSlot {
|
||||||
|
FOREHEAD,
|
||||||
|
HAT,
|
||||||
|
HAIR,
|
||||||
|
EYES,
|
||||||
|
FACIAL_HAIR,
|
||||||
|
BACK,
|
||||||
|
TOP,
|
||||||
|
GLOVES,
|
||||||
|
FOOTWEAR,
|
||||||
|
LEGGINGS,
|
||||||
|
FISHING_ROD,
|
||||||
|
BIKE
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package de.fiereu.openmmo.common.enums
|
||||||
|
|
||||||
|
enum class Weather(val battleWeather: BattleWeather = BattleWeather.NORMAL) {
|
||||||
|
IN_HOUSE_WEATHER,
|
||||||
|
SUNNY_WEATHER_WITH_CLOUDS_IN_WATER,
|
||||||
|
REGULAR_WEATHER,
|
||||||
|
RAINY_WEATHER(BattleWeather.SHITTY_RAIN),
|
||||||
|
THREE_SNOW_FLAKES(BattleWeather.SNOW),
|
||||||
|
RAIN_WITH_THUNDER(BattleWeather.SHITTY_RAIN),
|
||||||
|
STEADY_MIST,
|
||||||
|
STEADY_SNOW,
|
||||||
|
SAND_STORM(BattleWeather.SANDSTORM),
|
||||||
|
MIST_FROM_TOP_RIGHT,
|
||||||
|
DENSE_BRIGHT_MIST,
|
||||||
|
CLOUDY,
|
||||||
|
UNDERGROUND_FLASHES,
|
||||||
|
HEAVY_RAIN_WITH_THUNDER(BattleWeather.SHITTY_RAIN),
|
||||||
|
UNDERWATER_MIST,
|
||||||
|
UNKNOWN_THUNDER(BattleWeather.SHITTY_RAIN),
|
||||||
|
DAY_DEPENDANT,
|
||||||
|
CUSTOM_SNOW,
|
||||||
|
GEN4_NONE,
|
||||||
|
GEN4_UNK0,
|
||||||
|
GEN4_RAIN(BattleWeather.SHITTY_RAIN),
|
||||||
|
GEN4_HEAVY_RAIN(BattleWeather.SHITTY_RAIN),
|
||||||
|
GEN4_HEAVY_RAIN_WITH_THUNDER(BattleWeather.SHITTY_RAIN),
|
||||||
|
GEN4_SNOW(BattleWeather.SHITTY_RAIN),
|
||||||
|
GEN4_HEAVY_SNOW(BattleWeather.SHITTY_RAIN),
|
||||||
|
GEN4_HAIL(BattleWeather.SNOW),
|
||||||
|
GEN4_CLEAR,
|
||||||
|
GEN4_ASHDUST,
|
||||||
|
GEN4_SANDSTORM(BattleWeather.SANDSTORM),
|
||||||
|
GEN4_SPECIAL_ICY,
|
||||||
|
GEN4_SPECIAL_ROCKS,
|
||||||
|
GEN4_UNK,
|
||||||
|
GEN4_HEAVY_FOG(BattleWeather.FOG),
|
||||||
|
GEN4_HEAVY_FOG_WITH_DARKNESS,
|
||||||
|
GEN4_CAVE_FLASH,
|
||||||
|
GEN4_FOREST_TREE_SHADOWS,
|
||||||
|
GEN4_DARKNESS,
|
||||||
|
GEN4_GREEN_HAZE,
|
||||||
|
GEN4_RED_HAZE,
|
||||||
|
GEN4_BLUE_HAZE,
|
||||||
|
GEN4_RAIN2,
|
||||||
|
GEN4_UNK2,
|
||||||
|
GEN4_HEAVY_SNOW2,
|
||||||
|
GEN4_HEAVY_SNOW3,
|
||||||
|
GEN4_SNOW2
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class BattleWeather {
|
||||||
|
NORMAL,
|
||||||
|
SUNNY,
|
||||||
|
RAIN,
|
||||||
|
SANDSTORM,
|
||||||
|
FOG,
|
||||||
|
SNOW,
|
||||||
|
SHITTY_RAIN,
|
||||||
|
EVENT_HALLOWEEN_STORM,
|
||||||
|
EVENT_CNY_DARKNESS
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package de.fiereu.openmmo.common.utils
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.util.zip.GZIPInputStream
|
||||||
|
import java.util.zip.GZIPOutputStream
|
||||||
|
|
||||||
|
fun ByteArray.gzipCompress(): ByteArray {
|
||||||
|
val baos = ByteArrayOutputStream()
|
||||||
|
val gzip = GZIPOutputStream(baos)
|
||||||
|
gzip.write(this)
|
||||||
|
gzip.close()
|
||||||
|
return baos.toByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteArray.gzipDecompress(): ByteArray =
|
||||||
|
GZIPInputStream(ByteArrayInputStream(this)).buffered().readBytes()
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package de.fiereu.openmmo.common.utils
|
||||||
|
|
||||||
|
fun isNdsRegion(regionId: Int): Boolean {
|
||||||
|
return regionId == 2 || regionId == 3 || regionId == 4 || regionId == 10
|
||||||
|
}
|
||||||
@@ -1,12 +1,30 @@
|
|||||||
package de.fiereu.openmmo.protocols.game
|
package de.fiereu.openmmo.protocols.game
|
||||||
|
|
||||||
import de.fiereu.openmmo.protocols.Protocol
|
import de.fiereu.openmmo.protocols.Protocol
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinGamePacket
|
import de.fiereu.openmmo.protocols.game.packets.CharacterListDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.CharacterListSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.ChatMessageDeserialize
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.ChatMessageSerialize
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinPacketDeserializer
|
import de.fiereu.openmmo.protocols.game.packets.JoinPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinPacketSerializer
|
import de.fiereu.openmmo.protocols.game.packets.JoinPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinResponsePacket
|
import de.fiereu.openmmo.protocols.game.packets.JoinResponseDeserializer
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinResponsePacketDeserializer
|
import de.fiereu.openmmo.protocols.game.packets.JoinResponseSerializer
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinResponsePacketSerializer
|
import de.fiereu.openmmo.protocols.game.packets.LoadEntityDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.LoadEntitySerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.LoadMapPacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.LoadMapPacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.PokemonContainerDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.PokemonContainerSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RenderScreenDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RenderScreenSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RequestCharactersDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RequestCharactersPacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RequestPlayerDeserializePacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RequestPlayerSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.SelectCharacterDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.SelectCharacterSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.SelectedCharacterDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.SelectedCharacterSerializer
|
||||||
import de.fiereu.openmmo.protocols.incomingPacket
|
import de.fiereu.openmmo.protocols.incomingPacket
|
||||||
import de.fiereu.openmmo.protocols.outgoingPacket
|
import de.fiereu.openmmo.protocols.outgoingPacket
|
||||||
|
|
||||||
@@ -15,22 +33,40 @@ import de.fiereu.openmmo.protocols.outgoingPacket
|
|||||||
* is complete.
|
* is complete.
|
||||||
*/
|
*/
|
||||||
abstract class GameProtocol : Protocol() {
|
abstract class GameProtocol : Protocol() {
|
||||||
override val async: Boolean
|
override val async: Boolean = true
|
||||||
get() = true
|
override val compressed: Boolean = true
|
||||||
override val compressed: Boolean
|
|
||||||
get() = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GameServerProtocol : GameProtocol() {
|
class GameServerProtocol : GameProtocol() {
|
||||||
init {
|
init {
|
||||||
incomingPacket(0x01u, JoinPacketDeserializer())
|
incomingPacket(0x01u, JoinPacketDeserializer())
|
||||||
outgoingPacket(0x01u, JoinResponsePacketSerializer(), JoinResponsePacket::class)
|
outgoingPacket(0x01u, JoinResponseSerializer())
|
||||||
|
incomingPacket(0x02u, RequestCharactersDeserializer())
|
||||||
|
outgoingPacket(0x02u, CharacterListSerializer())
|
||||||
|
incomingPacket(0x04u, SelectCharacterDeserializer())
|
||||||
|
outgoingPacket(0x04u, SelectedCharacterSerializer())
|
||||||
|
incomingPacket(0x05u, RequestPlayerDeserializePacket())
|
||||||
|
outgoingPacket(0x05u, LoadEntitySerializer())
|
||||||
|
outgoingPacket(0x09u, ChatMessageSerialize())
|
||||||
|
outgoingPacket(0x10u, LoadMapPacketSerializer())
|
||||||
|
outgoingPacket(0x13u, PokemonContainerSerializer())
|
||||||
|
outgoingPacket(0xB4u, RenderScreenSerializer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GameClientProtocol : GameProtocol() {
|
class GameClientProtocol : GameProtocol() {
|
||||||
init {
|
init {
|
||||||
outgoingPacket(0x01u, JoinPacketSerializer(), JoinGamePacket::class)
|
outgoingPacket(0x01u, JoinPacketSerializer())
|
||||||
incomingPacket(0x01u, JoinResponsePacketDeserializer())
|
incomingPacket(0x01u, JoinResponseDeserializer())
|
||||||
|
outgoingPacket(0x02u, RequestCharactersPacketSerializer())
|
||||||
|
incomingPacket(0x02u, CharacterListDeserializer())
|
||||||
|
outgoingPacket(0x04u, SelectCharacterSerializer())
|
||||||
|
incomingPacket(0x04u, SelectedCharacterDeserializer())
|
||||||
|
outgoingPacket(0x05u, RequestPlayerSerializer())
|
||||||
|
incomingPacket(0x05u, LoadEntityDeserializer())
|
||||||
|
incomingPacket(0x09u, ChatMessageDeserialize())
|
||||||
|
incomingPacket(0x10u, LoadMapPacketDeserializer())
|
||||||
|
incomingPacket(0x13u, PokemonContainerDeserializer())
|
||||||
|
incomingPacket(0xB4u, RenderScreenDeserializer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.CharacterInfo
|
||||||
|
import de.fiereu.openmmo.common.Pokemon
|
||||||
|
import de.fiereu.openmmo.common.enums.SkinSlot
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.*
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class CharacterListPacket(val characters: List<CharacterEntry>)
|
||||||
|
|
||||||
|
data class CharacterEntry(
|
||||||
|
val characterInfo: CharacterInfo,
|
||||||
|
val skinSet: SkinSet,
|
||||||
|
val guildId: Int? = null,
|
||||||
|
val pokemon: List<Pokemon>
|
||||||
|
) {
|
||||||
|
init {
|
||||||
|
require(pokemon.size <= 6) { "Party size can't be more than 6 pokemon" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CharacterListSerializer : PacketSerializer<CharacterListPacket> {
|
||||||
|
override fun serialize(packet: CharacterListPacket, buffer: ByteBuf) =
|
||||||
|
buffer.run {
|
||||||
|
writeByte(packet.characters.size)
|
||||||
|
packet.characters.forEach { characterEntry ->
|
||||||
|
writeCharacterInfoLE(useLong = false, characterEntry.characterInfo)
|
||||||
|
writeSkinsLE(characterEntry.skinSet)
|
||||||
|
// TODO find out why we send 2 times the skin data
|
||||||
|
writeSkinsLE(characterEntry.skinSet, writeByte = false)
|
||||||
|
|
||||||
|
val hasGuild = characterEntry.guildId != null
|
||||||
|
buffer.writeBoolean(hasGuild)
|
||||||
|
if (hasGuild) {
|
||||||
|
writeUtf16LE("") // unused
|
||||||
|
writeIntLE(characterEntry.guildId)
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.writeByte(characterEntry.pokemon.size)
|
||||||
|
characterEntry.pokemon.forEach(::writePokemonLE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CharacterListDeserializer : PacketDeserializer<CharacterListPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): CharacterListPacket =
|
||||||
|
buffer.run {
|
||||||
|
val size = buffer.readByte().toInt()
|
||||||
|
val characters =
|
||||||
|
buildList(size) {
|
||||||
|
val characterInfo = readCharacterInfoLE(useLong = true)
|
||||||
|
val skinSet1 = readSkinsLE(SkinSlot.entries, readByte = true)
|
||||||
|
val skinSet2 = readSkinsLE(SkinSlot.entries, readByte = false)
|
||||||
|
|
||||||
|
val guildId =
|
||||||
|
if (readBoolean()) {
|
||||||
|
readUtf16LE() // unused
|
||||||
|
readIntLE()
|
||||||
|
} else null
|
||||||
|
|
||||||
|
val partySize = readUnsignedByte().toInt()
|
||||||
|
val pokemon = buildList(partySize) { repeat(partySize) { add(readPokemonLE()) } }
|
||||||
|
add(CharacterEntry(characterInfo, skinSet1, guildId, pokemon))
|
||||||
|
}
|
||||||
|
return CharacterListPacket(characters)
|
||||||
|
}
|
||||||
|
}
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.enums.ChatType
|
||||||
|
import de.fiereu.openmmo.common.enums.Language
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class ChatMessagePacket(
|
||||||
|
val type: ChatType,
|
||||||
|
val language: Language?,
|
||||||
|
val message: String,
|
||||||
|
val sender: String?
|
||||||
|
)
|
||||||
|
|
||||||
|
class ChatMessageSerialize : PacketSerializer<ChatMessagePacket> {
|
||||||
|
override fun serialize(packet: ChatMessagePacket, buffer: ByteBuf) {
|
||||||
|
buffer.apply {
|
||||||
|
writeByte(packet.type.ordinal)
|
||||||
|
when (packet.type) {
|
||||||
|
ChatType.TEAM -> {
|
||||||
|
writeUtf16LE(packet.message)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
require(packet.sender != null) { "sender must not be null" }
|
||||||
|
require(packet.language != null) { "language must not be null" }
|
||||||
|
writeLongLE(0) // TODO some id
|
||||||
|
writeUtf16LE(packet.sender)
|
||||||
|
writeByte(packet.language.ordinal)
|
||||||
|
writeByte(-1)
|
||||||
|
writeUtf16LE(packet.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ChatMessageDeserialize : PacketDeserializer<ChatMessagePacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): ChatMessagePacket {
|
||||||
|
when (val type = ChatType.entries[buffer.readByte().toInt()]) {
|
||||||
|
ChatType.LINK -> {
|
||||||
|
val message = buffer.readUtf16LE()
|
||||||
|
return ChatMessagePacket(type, Language.OTHER, message, null)
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
buffer.readIntLE()
|
||||||
|
val sender = buffer.readUtf16LE()
|
||||||
|
val language = Language.entries[buffer.readByte().toInt()]
|
||||||
|
buffer.readByte()
|
||||||
|
val message = buffer.readUtf16LE()
|
||||||
|
return ChatMessagePacket(type, language, message, sender)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-5
@@ -15,16 +15,16 @@ abstract class GameAuthenticationData
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Used when a player reconnects to the game server after a disconnection. This data typically
|
* Used when a player reconnects to the game server after a disconnection. This data typically
|
||||||
* includes the player's unique identifier and a session key that was issued by the login server to
|
* includes the sessions unique id and a session key that was issued by the login server to
|
||||||
* re-establish the session.
|
* re-establish the session.
|
||||||
*/
|
*/
|
||||||
data class ReconnectAuthData(val playerId: Long, val sessionKey: ByteArray) :
|
data class ReconnectAuthData(val sessionId: Long, val sessionKey: ByteArray) :
|
||||||
GameAuthenticationData()
|
GameAuthenticationData()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used when a player is joining the game server for the first time after logging in. This data
|
* Used when a player is joining the game server for the first time after logging in. This data
|
||||||
* typically includes the user's unique identifier and a session key that was issued by the login
|
* typically includes the user's unique id and a session key that was issued by the login server to
|
||||||
* server to authenticate the session.
|
* authenticate the session.
|
||||||
*/
|
*/
|
||||||
data class NewAuthData(
|
data class NewAuthData(
|
||||||
val userId: Int,
|
val userId: Int,
|
||||||
@@ -59,7 +59,7 @@ class JoinPacketSerializer : PacketSerializer<JoinGamePacket> {
|
|||||||
}
|
}
|
||||||
is ReconnectAuthData -> {
|
is ReconnectAuthData -> {
|
||||||
buffer.writeByte(0x01)
|
buffer.writeByte(0x01)
|
||||||
buffer.writeLongLE(packet.authData.playerId)
|
buffer.writeLongLE(packet.authData.sessionId)
|
||||||
buffer.writeByte(packet.authData.sessionKey.size)
|
buffer.writeByte(packet.authData.sessionKey.size)
|
||||||
buffer.writeBytes(packet.authData.sessionKey)
|
buffer.writeBytes(packet.authData.sessionKey)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-19
@@ -18,14 +18,10 @@ data class JoinResponsePacket(
|
|||||||
val stats: GameStats? = null
|
val stats: GameStats? = null
|
||||||
// we dont need TimeInfo here since it can be calculated on the fly
|
// we dont need TimeInfo here since it can be calculated on the fly
|
||||||
) {
|
) {
|
||||||
data class GameStats(
|
data class GameStats(val playtime: Int, val rewardPoints: Int, val balance: Int)
|
||||||
val playtime: Int,
|
|
||||||
val rewardPoints: Int,
|
|
||||||
val balance: Int
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class JoinResponsePacketSerializer : PacketSerializer<JoinResponsePacket> {
|
class JoinResponseSerializer : PacketSerializer<JoinResponsePacket> {
|
||||||
override fun serialize(packet: JoinResponsePacket, buffer: ByteBuf) {
|
override fun serialize(packet: JoinResponsePacket, buffer: ByteBuf) {
|
||||||
buffer.writeBoolean(packet.canJoin)
|
buffer.writeBoolean(packet.canJoin)
|
||||||
if (!packet.canJoin) return // no further data is sent
|
if (!packet.canJoin) return // no further data is sent
|
||||||
@@ -47,24 +43,16 @@ class JoinResponsePacketSerializer : PacketSerializer<JoinResponsePacket> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JoinResponsePacketDeserializer : PacketDeserializer<JoinResponsePacketDeserializer.JoinResponsePacket> {
|
class JoinResponseDeserializer : PacketDeserializer<JoinResponseDeserializer.JoinResponsePacket> {
|
||||||
data class JoinResponsePacket(
|
data class JoinResponsePacket(
|
||||||
val canJoin: Boolean,
|
val canJoin: Boolean,
|
||||||
val stats: GameStats? = null,
|
val stats: GameStats? = null,
|
||||||
val time: TimeInfo? = null
|
val time: TimeInfo? = null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
data class GameStats(
|
data class GameStats(val playtime: Int, val rewardPoints: Int, val balance: Int)
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun deserialize(buffer: ByteBuf): JoinResponsePacket {
|
override fun deserialize(buffer: ByteBuf): JoinResponsePacket {
|
||||||
@@ -86,7 +74,6 @@ class JoinResponsePacketDeserializer : PacketDeserializer<JoinResponsePacketDese
|
|||||||
return JoinResponsePacket(
|
return JoinResponsePacket(
|
||||||
true,
|
true,
|
||||||
JoinResponsePacket.GameStats(playtime, rewardPoints, balance),
|
JoinResponsePacket.GameStats(playtime, rewardPoints, balance),
|
||||||
JoinResponsePacket.TimeInfo(serverDayStartSecond, serverCurrentSecond)
|
JoinResponsePacket.TimeInfo(serverDayStartSecond, serverCurrentSecond))
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.enums.Direction
|
||||||
|
import de.fiereu.openmmo.common.enums.EntityStatus
|
||||||
|
import de.fiereu.openmmo.common.enums.SkinSlot
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.SkinSet
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.readSkinsLE
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.writeSkinsLE
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeShortLE
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class LoadEntityPacket(
|
||||||
|
val entityId: Long,
|
||||||
|
val skin: SkinSet,
|
||||||
|
val name: String,
|
||||||
|
val regionId: Int,
|
||||||
|
val bankId: Int,
|
||||||
|
val mapId: Int,
|
||||||
|
val x: Int,
|
||||||
|
val y: Int,
|
||||||
|
val facing: Direction,
|
||||||
|
val status: EntityStatus,
|
||||||
|
val hasFollower: Boolean,
|
||||||
|
val followerDexId: Short,
|
||||||
|
)
|
||||||
|
|
||||||
|
class LoadEntitySerializer : PacketSerializer<LoadEntityPacket> {
|
||||||
|
override fun serialize(packet: LoadEntityPacket, buffer: ByteBuf) =
|
||||||
|
buffer.run {
|
||||||
|
writeLong(packet.entityId)
|
||||||
|
writeByte(0)
|
||||||
|
writeSkinsLE(packet.skin)
|
||||||
|
writeUtf16LE(packet.name)
|
||||||
|
writeByte(packet.regionId)
|
||||||
|
writeByte(packet.bankId)
|
||||||
|
writeByte(packet.mapId)
|
||||||
|
writeShortLE(packet.x)
|
||||||
|
writeShortLE(packet.y)
|
||||||
|
writeByte(packet.facing.ordinal)
|
||||||
|
writeByte(0)
|
||||||
|
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(packet.status.ordinal)
|
||||||
|
|
||||||
|
var flags = 0
|
||||||
|
if (packet.hasFollower) flags = flags or 0x04
|
||||||
|
writeShortLE(flags)
|
||||||
|
if (flags and 0x01 != 0) {
|
||||||
|
writeByte(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags and 0x02 != 0) {
|
||||||
|
writeByte(0)
|
||||||
|
writeShortLE(flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags and 0x04 != 0) {
|
||||||
|
writeShortLE(packet.followerDexId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags and 0x08 != 0) {
|
||||||
|
writeByte(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags and 0x10 != 0) {
|
||||||
|
writeIntLE(0)
|
||||||
|
writeUtf16LE("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadEntityDeserializer : PacketDeserializer<LoadEntityPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): LoadEntityPacket =
|
||||||
|
buffer.run {
|
||||||
|
val entityId = readLong()
|
||||||
|
readByte() // Skip padding byte
|
||||||
|
val skin = readSkinsLE(SkinSlot.entries)
|
||||||
|
val name = readUtf16LE()
|
||||||
|
val regionId = readByte().toInt()
|
||||||
|
val bankId = readByte().toInt()
|
||||||
|
val mapId = readByte().toInt()
|
||||||
|
val x = readShortLE()
|
||||||
|
val y = readShortLE()
|
||||||
|
val facing = Direction.entries[readByte().toInt()]
|
||||||
|
readByte() // Skip padding byte
|
||||||
|
|
||||||
|
readByte() // Skip padding byte
|
||||||
|
val status = EntityStatus.entries[readByte().toInt()]
|
||||||
|
|
||||||
|
val flags = readUnsignedShortLE()
|
||||||
|
if (flags and 0x01 != 0) {
|
||||||
|
readByte()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags and 0x02 != 0) {
|
||||||
|
readByte()
|
||||||
|
readUnsignedShortLE()
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasFollower = (flags and 0x04) != 0
|
||||||
|
val followerDexId =
|
||||||
|
if (hasFollower) {
|
||||||
|
readShortLE()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags and 0x08 != 0) {
|
||||||
|
readByte()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags and 0x10 != 0) {
|
||||||
|
readInt() // Skip int value
|
||||||
|
readUtf16LE() // Skip string
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadEntityPacket(
|
||||||
|
entityId = entityId,
|
||||||
|
skin = skin,
|
||||||
|
name = name,
|
||||||
|
regionId = regionId,
|
||||||
|
bankId = bankId,
|
||||||
|
mapId = mapId,
|
||||||
|
x = x.toInt(),
|
||||||
|
y = y.toInt(),
|
||||||
|
facing = facing,
|
||||||
|
status = status,
|
||||||
|
hasFollower = hasFollower,
|
||||||
|
followerDexId = followerDexId,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+219
@@ -0,0 +1,219 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.Tile2D
|
||||||
|
import de.fiereu.openmmo.common.enums.EncounterType
|
||||||
|
import de.fiereu.openmmo.common.enums.Lighting
|
||||||
|
import de.fiereu.openmmo.common.enums.MapType
|
||||||
|
import de.fiereu.openmmo.common.enums.Weather
|
||||||
|
import de.fiereu.openmmo.common.utils.gzipCompress
|
||||||
|
import de.fiereu.openmmo.common.utils.gzipDecompress
|
||||||
|
import de.fiereu.openmmo.common.utils.isNdsRegion
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.readTile2DLE
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.writeTile2DLE
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class LoadMapPacket(
|
||||||
|
val reloadPlayer: Boolean,
|
||||||
|
val deleteCache: Boolean,
|
||||||
|
val regionId: Int,
|
||||||
|
val bankId: Int,
|
||||||
|
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" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed interface MapData {
|
||||||
|
data class NdsMapData(val lighting: Lighting, val weather: Weather, val mapType: MapType) :
|
||||||
|
MapData
|
||||||
|
|
||||||
|
data class GbaMapData(
|
||||||
|
val width: Int,
|
||||||
|
val height: Int,
|
||||||
|
val paletteIdx1: Int,
|
||||||
|
val paletteIdx2: Int,
|
||||||
|
val borderWidth: Int,
|
||||||
|
val borderHeight: Int,
|
||||||
|
val borderTiles: List<Tile2D>,
|
||||||
|
val lighting: Lighting,
|
||||||
|
val weather: Weather,
|
||||||
|
val mapType: MapType,
|
||||||
|
val encounterType: EncounterType
|
||||||
|
) : MapData {
|
||||||
|
init {
|
||||||
|
require(borderWidth * borderHeight == borderTiles.size) {
|
||||||
|
"borderTiles size doesnt match dimensions"
|
||||||
|
}
|
||||||
|
require(borderWidth * borderHeight > 0) { "BorderWidth & Height must be greater than zero" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadMapPacketSerializer : PacketSerializer<LoadMapPacket> {
|
||||||
|
override fun serialize(packet: LoadMapPacket, buffer: ByteBuf) {
|
||||||
|
buffer.apply {
|
||||||
|
var flags = 0
|
||||||
|
if (packet.deleteCache) flags = flags or 1
|
||||||
|
if (packet.reloadPlayer) flags = flags or 2
|
||||||
|
|
||||||
|
writeByte(flags)
|
||||||
|
|
||||||
|
writeByte(packet.regionId) // Client will stop parsing if the region is not loaded
|
||||||
|
writeByte(packet.bankId)
|
||||||
|
writeByte(packet.mapId)
|
||||||
|
writeByte(0)
|
||||||
|
|
||||||
|
when (packet.mapData) {
|
||||||
|
is MapData.NdsMapData -> {
|
||||||
|
writeShortLE(0)
|
||||||
|
val unk = 0
|
||||||
|
writeByte(unk)
|
||||||
|
for (i in 0 until unk) {
|
||||||
|
writeShortLE(0)
|
||||||
|
writeShortLE(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
writeByte(packet.mapData.lighting.ordinal)
|
||||||
|
writeByte(packet.mapData.weather.ordinal)
|
||||||
|
writeByte(packet.mapData.mapType.ordinal)
|
||||||
|
}
|
||||||
|
is MapData.GbaMapData -> {
|
||||||
|
writeIntLE(packet.mapData.width)
|
||||||
|
writeIntLE(packet.mapData.height)
|
||||||
|
writeIntLE(packet.mapData.paletteIdx1)
|
||||||
|
writeIntLE(packet.mapData.paletteIdx2)
|
||||||
|
writeByte(packet.mapData.borderWidth)
|
||||||
|
writeByte(packet.mapData.borderHeight)
|
||||||
|
writeShortLE(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(packet.mapData.lighting.ordinal)
|
||||||
|
writeByte(packet.mapData.weather.ordinal)
|
||||||
|
writeByte(packet.mapData.mapType.ordinal)
|
||||||
|
writeByte(packet.mapData.encounterType.ordinal)
|
||||||
|
|
||||||
|
for (tile2D in packet.mapData.borderTiles) {
|
||||||
|
writeTile2DLE(tile2D)
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasUnknown = false
|
||||||
|
writeBoolean(hasUnknown)
|
||||||
|
if (hasUnknown) {
|
||||||
|
val unknown = ByteArray(0)
|
||||||
|
writeIntLE(unknown.size)
|
||||||
|
writeBytes(unknown.gzipCompress())
|
||||||
|
}
|
||||||
|
|
||||||
|
val connectionCount = 0
|
||||||
|
writeByte(0)
|
||||||
|
for (i in 0 until connectionCount) {
|
||||||
|
writeByte(0)
|
||||||
|
writeIntLE(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasUnknown2 = false
|
||||||
|
writeBoolean(hasUnknown2)
|
||||||
|
if (hasUnknown2) {
|
||||||
|
writeLongLE(0)
|
||||||
|
writeUtf16LE("")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadMapPacketDeserializer : PacketDeserializer<LoadMapPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): LoadMapPacket =
|
||||||
|
buffer.let {
|
||||||
|
val flags = buffer.readByte().toInt()
|
||||||
|
val deleteCache = (flags and 1) != 0
|
||||||
|
val reloadPlayer = (flags and 2) != 0
|
||||||
|
|
||||||
|
val regionId = buffer.readByte().toInt()
|
||||||
|
val bankId = buffer.readByte().toInt()
|
||||||
|
val mapId = buffer.readByte().toInt()
|
||||||
|
buffer.readByte()
|
||||||
|
|
||||||
|
val mapData =
|
||||||
|
if (isNdsRegion(regionId)) {
|
||||||
|
// NDS format
|
||||||
|
buffer.readShortLE()
|
||||||
|
val unk = buffer.readByte().toInt()
|
||||||
|
for (i in 0 until unk) {
|
||||||
|
buffer.readShortLE()
|
||||||
|
buffer.readShortLE()
|
||||||
|
}
|
||||||
|
val lighting = Lighting.entries[buffer.readByte().toInt()]
|
||||||
|
val weather = Weather.entries[buffer.readByte().toInt()]
|
||||||
|
val mapType = MapType.entries[buffer.readByte().toInt()]
|
||||||
|
MapData.NdsMapData(lighting, weather, mapType)
|
||||||
|
} else {
|
||||||
|
// GBA format
|
||||||
|
val width = buffer.readIntLE()
|
||||||
|
val height = buffer.readIntLE()
|
||||||
|
val paletteIdx1 = buffer.readIntLE()
|
||||||
|
val paletteIdx2 = buffer.readIntLE()
|
||||||
|
val borderWidth = buffer.readByte().toInt()
|
||||||
|
val borderHeight = buffer.readByte().toInt()
|
||||||
|
buffer.readShortLE()
|
||||||
|
buffer.readByte()
|
||||||
|
val lighting = Lighting.entries[buffer.readByte().toInt()]
|
||||||
|
val weather = Weather.entries[buffer.readByte().toInt()]
|
||||||
|
val mapType = MapType.entries[buffer.readByte().toInt()]
|
||||||
|
val encounterType = EncounterType.entries[buffer.readByte().toInt()]
|
||||||
|
|
||||||
|
val borderTiles = mutableListOf<Tile2D>()
|
||||||
|
for (i in 0 until (borderWidth * borderHeight)) {
|
||||||
|
borderTiles.add(buffer.readTile2DLE())
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasUnknown = buffer.readBoolean()
|
||||||
|
if (hasUnknown) {
|
||||||
|
val unknownSize = buffer.readIntLE()
|
||||||
|
val unknownCompressed = ByteArray(unknownSize)
|
||||||
|
buffer.readBytes(unknownCompressed)
|
||||||
|
unknownCompressed.gzipDecompress()
|
||||||
|
}
|
||||||
|
|
||||||
|
val connectionCount = buffer.readByte().toInt()
|
||||||
|
for (i in 0 until connectionCount) {
|
||||||
|
buffer.readByte()
|
||||||
|
buffer.readIntLE()
|
||||||
|
buffer.readByte()
|
||||||
|
buffer.readByte()
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasUnknown2 = buffer.readBoolean()
|
||||||
|
if (hasUnknown2) {
|
||||||
|
buffer.readLongLE()
|
||||||
|
buffer.readUtf16LE()
|
||||||
|
}
|
||||||
|
|
||||||
|
MapData.GbaMapData(
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
paletteIdx1,
|
||||||
|
paletteIdx2,
|
||||||
|
borderWidth,
|
||||||
|
borderHeight,
|
||||||
|
borderTiles,
|
||||||
|
lighting,
|
||||||
|
weather,
|
||||||
|
mapType,
|
||||||
|
encounterType)
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadMapPacket(reloadPlayer, deleteCache, regionId, bankId, mapId, mapData)
|
||||||
|
}
|
||||||
|
}
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.Pokemon
|
||||||
|
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.readPokemonLE
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.writePokemonLE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class PokemonContainerPacket(
|
||||||
|
val container: PokemonContainer,
|
||||||
|
val hasChange: Boolean,
|
||||||
|
val delete: Boolean,
|
||||||
|
val pokemon: List<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" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PokemonContainerSerializer : PacketSerializer<PokemonContainerPacket> {
|
||||||
|
override fun serialize(packet: PokemonContainerPacket, buffer: ByteBuf) =
|
||||||
|
buffer.run {
|
||||||
|
writeByte(packet.container.ordinal)
|
||||||
|
var flags = 0
|
||||||
|
if (packet.hasChange) flags = flags or 1
|
||||||
|
if (packet.delete) flags = flags or 2
|
||||||
|
writeByte(flags)
|
||||||
|
if (packet.delete) return
|
||||||
|
writeByte(packet.pokemon.size)
|
||||||
|
for (pokemon in packet.pokemon) {
|
||||||
|
writePokemonLE(pokemon)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PokemonContainerDeserializer : PacketDeserializer<PokemonContainerPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): PokemonContainerPacket =
|
||||||
|
buffer.run {
|
||||||
|
val pokemonContainer = PokemonContainer.entries[buffer.readByte().toInt()]
|
||||||
|
val flags = buffer.readByte().toInt()
|
||||||
|
val hasChange = (flags and 1) != 0
|
||||||
|
val delete = (flags and 2) != 0
|
||||||
|
val pokemon = buildList<Pokemon>(readByte().toInt()) { readPokemonLE() }
|
||||||
|
return PokemonContainerPacket(pokemonContainer, hasChange, delete, pokemon)
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class RenderScreenPacket(val renderScreen: Boolean)
|
||||||
|
|
||||||
|
class RenderScreenSerializer : PacketSerializer<RenderScreenPacket> {
|
||||||
|
override fun serialize(packet: RenderScreenPacket, buffer: ByteBuf) {
|
||||||
|
buffer.writeBoolean(packet.renderScreen)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderScreenDeserializer : PacketDeserializer<RenderScreenPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): RenderScreenPacket {
|
||||||
|
return RenderScreenPacket(buffer.readBoolean())
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
class RequestCharactersPacket()
|
||||||
|
|
||||||
|
class RequestCharactersPacketSerializer : PacketSerializer<RequestCharactersPacket> {
|
||||||
|
override fun serialize(packet: RequestCharactersPacket, buffer: ByteBuf) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RequestCharactersDeserializer : PacketDeserializer<RequestCharactersPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): RequestCharactersPacket {
|
||||||
|
return RequestCharactersPacket()
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
class RequestPlayerPacket
|
||||||
|
|
||||||
|
class RequestPlayerSerializer : PacketSerializer<RequestPlayerPacket> {
|
||||||
|
override fun serialize(packet: RequestPlayerPacket, buffer: ByteBuf) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RequestPlayerDeserializePacket : PacketDeserializer<RequestPlayerPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): RequestPlayerPacket {
|
||||||
|
return RequestPlayerPacket()
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class SelectCharacterPacket(val characterId: Long, val characterIdHash: Long)
|
||||||
|
|
||||||
|
class SelectCharacterSerializer : PacketSerializer<SelectCharacterPacket> {
|
||||||
|
override fun serialize(packet: SelectCharacterPacket, buffer: ByteBuf) {
|
||||||
|
buffer.apply {
|
||||||
|
buffer.writeLongLE(packet.characterId)
|
||||||
|
buffer.writeLongLE(packet.characterIdHash)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SelectCharacterDeserializer : PacketDeserializer<SelectCharacterPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): SelectCharacterPacket =
|
||||||
|
buffer.run {
|
||||||
|
val characterId = buffer.readLong()
|
||||||
|
val characterIdHash = buffer.readLong()
|
||||||
|
return SelectCharacterPacket(characterId, characterIdHash)
|
||||||
|
}
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.CharacterInfo
|
||||||
|
import de.fiereu.openmmo.protocols.PacketDeserializer
|
||||||
|
import de.fiereu.openmmo.protocols.PacketSerializer
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.readCharacterInfoLE
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.writeCharacterInfoLE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
data class SelectedCharacterPacket(val character: CharacterInfo?)
|
||||||
|
|
||||||
|
class SelectedCharacterSerializer : PacketSerializer<SelectedCharacterPacket> {
|
||||||
|
override fun serialize(packet: SelectedCharacterPacket, buffer: ByteBuf) {
|
||||||
|
buffer.apply {
|
||||||
|
val hasCharacter = packet.character != null
|
||||||
|
writeBoolean(hasCharacter)
|
||||||
|
if (!hasCharacter) return
|
||||||
|
writeCharacterInfoLE(false, packet.character)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SelectedCharacterDeserializer : PacketDeserializer<SelectedCharacterPacket> {
|
||||||
|
override fun deserialize(buffer: ByteBuf): SelectedCharacterPacket =
|
||||||
|
buffer.run {
|
||||||
|
val hasCharacter = readBoolean()
|
||||||
|
val character = if (hasCharacter) readCharacterInfoLE(false) else null
|
||||||
|
return SelectedCharacterPacket(character)
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-10
@@ -2,9 +2,7 @@ package de.fiereu.openmmo.protocols.game.packets.builders
|
|||||||
|
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinResponsePacket
|
import de.fiereu.openmmo.protocols.game.packets.JoinResponsePacket
|
||||||
|
|
||||||
class JoinResponsePacketBuilder(
|
class JoinResponsePacketBuilder(private val canJoin: Boolean) {
|
||||||
private val canJoin: Boolean
|
|
||||||
) {
|
|
||||||
private var playtime: Int = 0
|
private var playtime: Int = 0
|
||||||
private var rewardPoints: Int = 0
|
private var rewardPoints: Int = 0
|
||||||
private var balance: Int = 0
|
private var balance: Int = 0
|
||||||
@@ -35,14 +33,13 @@ class JoinResponsePacketBuilder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun build(): JoinResponsePacket {
|
fun build(): JoinResponsePacket {
|
||||||
require(canJoin) { "Cannot build a JoinResponsePacket with canJoin=false. Use JoinResponsePacketBuilder.reject() instead." }
|
require(canJoin) {
|
||||||
|
"Cannot build a JoinResponsePacket with canJoin=false. Use JoinResponsePacketBuilder.reject() instead."
|
||||||
|
}
|
||||||
return JoinResponsePacket(
|
return JoinResponsePacket(
|
||||||
canJoin = true,
|
canJoin = true,
|
||||||
stats = JoinResponsePacket.GameStats(
|
stats =
|
||||||
playtime = playtime,
|
JoinResponsePacket.GameStats(
|
||||||
rewardPoints = rewardPoints,
|
playtime = playtime, rewardPoints = rewardPoints, balance = balance))
|
||||||
balance = balance
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets.codecs
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.CharacterInfo
|
||||||
|
import de.fiereu.openmmo.protocols.readEpochSeconds
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeEpochSecond
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
fun ByteBuf.writeCharacterInfoLE(useLong: Boolean, characterInfo: CharacterInfo) = apply {
|
||||||
|
writeLongLE(characterInfo.id)
|
||||||
|
writeUtf16LE(characterInfo.name)
|
||||||
|
writeUtf16LE("")
|
||||||
|
writeIntLE(characterInfo.userId)
|
||||||
|
writeByte(characterInfo.rivalSex.toInt())
|
||||||
|
writeEpochSecond(characterInfo.lastLogin)
|
||||||
|
if (useLong) {
|
||||||
|
writeLongLE(0)
|
||||||
|
}
|
||||||
|
writeEpochSecond(characterInfo.createdAt)
|
||||||
|
writeIntLE(0) // unused
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeIntLE(0)
|
||||||
|
writeIntLE(characterInfo.money)
|
||||||
|
writeShortLE(0)
|
||||||
|
writeIntLE(0)
|
||||||
|
writeByte(characterInfo.permissions)
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeByte(0)
|
||||||
|
writeIntLE(0)
|
||||||
|
repeat(8) {
|
||||||
|
writeByte(0) // unused
|
||||||
|
}
|
||||||
|
writeShortLE(characterInfo.remainingSafariSteps.toInt())
|
||||||
|
writeByte(characterInfo.remainingSafariBalls.toInt())
|
||||||
|
writeIntLE(0)
|
||||||
|
writeByte(characterInfo.pcExtraSlots.toInt())
|
||||||
|
writeByte(characterInfo.battleBoxExtraSlots.toInt())
|
||||||
|
writeByte(characterInfo.templateAmount.toInt())
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeByte(characterInfo.positionRegionId.toInt())
|
||||||
|
writeByte(characterInfo.positionBankId.toInt())
|
||||||
|
writeByte(characterInfo.positionMapId.toInt())
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeShortLE(characterInfo.positionX.toInt())
|
||||||
|
writeShortLE(characterInfo.positionY.toInt())
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeByte(0) // unused
|
||||||
|
writeShortLE(characterInfo.repelLeft.toInt())
|
||||||
|
writeShortLE(characterInfo.repelItemId.toInt())
|
||||||
|
writeByte(0) // 100
|
||||||
|
writeShortLE(characterInfo.lureItemId.toInt())
|
||||||
|
writeShortLE(characterInfo.lureLeft.toInt())
|
||||||
|
val bytes = ByteArray(0)
|
||||||
|
writeByte(bytes.size)
|
||||||
|
writeBytes(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteBuf.readCharacterInfoLE(useLong: Boolean): CharacterInfo = let {
|
||||||
|
val id = readLongLE()
|
||||||
|
val name = readUtf16LE()
|
||||||
|
val namePrefix = readUtf16LE()
|
||||||
|
val userId = readIntLE()
|
||||||
|
val rivalSex = readByte()
|
||||||
|
val lastLogin = readEpochSeconds()
|
||||||
|
if (useLong) {
|
||||||
|
readLongLE()
|
||||||
|
}
|
||||||
|
val createdAt = readEpochSeconds()
|
||||||
|
readIntLE() // unused
|
||||||
|
readByte() // unused
|
||||||
|
readIntLE()
|
||||||
|
val money = readIntLE()
|
||||||
|
readShortLE()
|
||||||
|
readIntLE()
|
||||||
|
val permissions = readByte().toInt()
|
||||||
|
readByte() // unused
|
||||||
|
readByte()
|
||||||
|
readIntLE()
|
||||||
|
repeat(8) {
|
||||||
|
readByte() // unused
|
||||||
|
}
|
||||||
|
val remainingSafariSteps = readShortLE()
|
||||||
|
val remainingSafariBalls = readByte()
|
||||||
|
readIntLE()
|
||||||
|
val pcExtraSlots = readByte()
|
||||||
|
val battleBoxExtraSlots = readByte()
|
||||||
|
val templateAmount = readByte()
|
||||||
|
readByte() // unused
|
||||||
|
readByte() // unused
|
||||||
|
readByte() // unused
|
||||||
|
val positionRegionId = readByte()
|
||||||
|
val positionBankId = readByte()
|
||||||
|
val positionMapId = readByte()
|
||||||
|
readByte() // unused
|
||||||
|
val positionX = readShortLE()
|
||||||
|
val positionY = readShortLE()
|
||||||
|
readByte() // unused
|
||||||
|
readByte() // unused
|
||||||
|
val repelLeft = readShortLE()
|
||||||
|
val repelItemId = readShortLE()
|
||||||
|
readByte()
|
||||||
|
val lureItemId = readShortLE()
|
||||||
|
val lureLeft = readShortLE()
|
||||||
|
val arraySize = readByte().toInt()
|
||||||
|
if (arraySize > 0) {
|
||||||
|
val bytes = ByteArray(arraySize)
|
||||||
|
readBytes(bytes)
|
||||||
|
}
|
||||||
|
return CharacterInfo(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
namePrefix,
|
||||||
|
userId,
|
||||||
|
rivalSex,
|
||||||
|
lastLogin,
|
||||||
|
createdAt,
|
||||||
|
money,
|
||||||
|
permissions,
|
||||||
|
remainingSafariSteps,
|
||||||
|
remainingSafariBalls,
|
||||||
|
pcExtraSlots,
|
||||||
|
battleBoxExtraSlots,
|
||||||
|
templateAmount,
|
||||||
|
positionRegionId,
|
||||||
|
positionBankId,
|
||||||
|
positionMapId,
|
||||||
|
positionX,
|
||||||
|
positionY,
|
||||||
|
repelLeft,
|
||||||
|
repelItemId,
|
||||||
|
lureLeft,
|
||||||
|
lureItemId)
|
||||||
|
}
|
||||||
+179
@@ -0,0 +1,179 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets.codecs
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.Pokemon
|
||||||
|
import de.fiereu.openmmo.common.PokemonMove
|
||||||
|
import de.fiereu.openmmo.common.enums.EVs
|
||||||
|
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||||
|
import de.fiereu.openmmo.common.enums.PokemonRarity
|
||||||
|
import de.fiereu.openmmo.common.enums.compress
|
||||||
|
import de.fiereu.openmmo.common.enums.decompressIVs
|
||||||
|
import de.fiereu.openmmo.protocols.readEpochSeconds
|
||||||
|
import de.fiereu.openmmo.protocols.readUtf16LE
|
||||||
|
import de.fiereu.openmmo.protocols.writeByte
|
||||||
|
import de.fiereu.openmmo.protocols.writeEpochSecond
|
||||||
|
import de.fiereu.openmmo.protocols.writeShortLE
|
||||||
|
import de.fiereu.openmmo.protocols.writeUtf16LE
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
fun ByteBuf.writePokemonLE(pokemon: Pokemon) = apply {
|
||||||
|
writeLongLE(pokemon.id)
|
||||||
|
writeByte(0)
|
||||||
|
writeLongLE(0)
|
||||||
|
writeLongLE(0) // unused
|
||||||
|
writeByte(pokemon.container.ordinal)
|
||||||
|
writeShortLE(pokemon.containerSlot)
|
||||||
|
writeShortLE(pokemon.dexId)
|
||||||
|
writeIntLE(pokemon.seed)
|
||||||
|
writeLongLE(0) // unused
|
||||||
|
writeUtf16LE(pokemon.ot)
|
||||||
|
writeUtf16LE(pokemon.nickname)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(pokemon.level)
|
||||||
|
writeShortLE(pokemon.hp)
|
||||||
|
writeShortLE(0)
|
||||||
|
writeIntLE(pokemon.xp)
|
||||||
|
writeByte(0)
|
||||||
|
writeShortLE(0)
|
||||||
|
pokemon.moves.forEach { move -> writeShortLE(move.id) }
|
||||||
|
pokemon.moves.forEach { move -> writeByte(move.pp) }
|
||||||
|
arrayOf(0, 0, 0, 0).forEach { writeShortLE(it) }
|
||||||
|
|
||||||
|
writeByte(pokemon.eVs.hp)
|
||||||
|
writeByte(pokemon.eVs.atk)
|
||||||
|
writeByte(pokemon.eVs.def)
|
||||||
|
writeByte(pokemon.eVs.spd)
|
||||||
|
writeByte(pokemon.eVs.spAtk)
|
||||||
|
writeByte(pokemon.eVs.spDef)
|
||||||
|
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
|
||||||
|
writeIntLE(pokemon.iVs.compress())
|
||||||
|
writeByte(0)
|
||||||
|
writeLongLE(0)
|
||||||
|
|
||||||
|
var rarityMask = 0
|
||||||
|
if (pokemon.isShiny) rarityMask = rarityMask or (1 shl PokemonRarity.SHINY.ordinal)
|
||||||
|
if (pokemon.hasHiddenAbility)
|
||||||
|
rarityMask = rarityMask or (1 shl PokemonRarity.HIDDEN_ABILITY.ordinal)
|
||||||
|
if (pokemon.isAlpha) rarityMask = rarityMask or (1 shl PokemonRarity.ALPHA.ordinal)
|
||||||
|
if (pokemon.isSecret) rarityMask = rarityMask or (1 shl PokemonRarity.SECRET.ordinal)
|
||||||
|
if (pokemon.isFatefulEncounter)
|
||||||
|
rarityMask = rarityMask or (1 shl PokemonRarity.FATEFUL_ENCOUNTER.ordinal)
|
||||||
|
if (pokemon.isRaidEncounter)
|
||||||
|
rarityMask = rarityMask or (1 shl PokemonRarity.RAID_ENCOUNTER.ordinal)
|
||||||
|
writeShortLE(rarityMask)
|
||||||
|
|
||||||
|
writeEpochSecond(pokemon.caughtAt)
|
||||||
|
writeShortLE(0)
|
||||||
|
writeByte(0)
|
||||||
|
writeByte(0)
|
||||||
|
|
||||||
|
val unk = ByteArray(0)
|
||||||
|
writeByte(unk.size)
|
||||||
|
writeBytes(unk)
|
||||||
|
|
||||||
|
writeBytes(ByteArray(12) { 0.toByte() })
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteBuf.readPokemonLE(): Pokemon {
|
||||||
|
val id = readLongLE()
|
||||||
|
readByte()
|
||||||
|
readLongLE()
|
||||||
|
readLongLE() // unused
|
||||||
|
val container = PokemonContainer.entries[readUnsignedByte().toInt()]
|
||||||
|
val containerSlot = readShortLE()
|
||||||
|
val dexId = readUnsignedShortLE().toInt()
|
||||||
|
val seed = readIntLE()
|
||||||
|
readLongLE() // unused
|
||||||
|
val ot = readUtf16LE()
|
||||||
|
val nickname = readUtf16LE()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
val level = readByte()
|
||||||
|
val currentHp = readShortLE()
|
||||||
|
readShortLE()
|
||||||
|
val xp = readIntLE()
|
||||||
|
readByte()
|
||||||
|
readShortLE()
|
||||||
|
val moves = List(4) { PokemonMove(readShortLE(), 0) }
|
||||||
|
moves.forEach { move -> move.pp = readByte() }
|
||||||
|
repeat(4) { readByte() }
|
||||||
|
val eVs =
|
||||||
|
EVs().apply {
|
||||||
|
hp = readByte().toInt()
|
||||||
|
atk = readByte().toInt()
|
||||||
|
def = readByte().toInt()
|
||||||
|
spd = readByte().toInt()
|
||||||
|
spAtk = readByte().toInt()
|
||||||
|
spDef = readByte().toInt()
|
||||||
|
}
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte() // unused
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
val iVs = decompressIVs(readIntLE())
|
||||||
|
readByte()
|
||||||
|
readLongLE()
|
||||||
|
|
||||||
|
val rarityMask = readUnsignedShortLE()
|
||||||
|
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 = readEpochSeconds()
|
||||||
|
readShortLE()
|
||||||
|
readByte()
|
||||||
|
readByte()
|
||||||
|
|
||||||
|
val unknown = ByteArray(readByte().toInt())
|
||||||
|
readBytes(unknown)
|
||||||
|
|
||||||
|
return Pokemon(
|
||||||
|
id,
|
||||||
|
container,
|
||||||
|
containerSlot,
|
||||||
|
dexId,
|
||||||
|
seed,
|
||||||
|
ot,
|
||||||
|
nickname,
|
||||||
|
level,
|
||||||
|
currentHp,
|
||||||
|
xp,
|
||||||
|
eVs,
|
||||||
|
iVs,
|
||||||
|
moves,
|
||||||
|
isShiny,
|
||||||
|
hasHiddenAbility,
|
||||||
|
isAlpha,
|
||||||
|
isSecret,
|
||||||
|
isFatefulEncounter,
|
||||||
|
isRaidEncounter,
|
||||||
|
caughtAt)
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets.codecs
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.enums.SkinSlot
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
import java.util.EnumMap
|
||||||
|
import kotlin.enums.EnumEntries
|
||||||
|
|
||||||
|
data class Skin(val slot: SkinSlot, val type: UShort?, val color: UByte?)
|
||||||
|
|
||||||
|
class SkinSet() : EnumMap<SkinSlot, Skin>(SkinSlot::class.java) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteBuf.writeSkinsLE(
|
||||||
|
skinSet: SkinSet,
|
||||||
|
slots: EnumEntries<SkinSlot> = SkinSlot.entries,
|
||||||
|
writeByte: Boolean = true
|
||||||
|
) = apply {
|
||||||
|
if (writeByte) {
|
||||||
|
writeByte(0)
|
||||||
|
}
|
||||||
|
val mask = slots.fold(0) { acc, slot -> acc or (1 shl slot.ordinal) }
|
||||||
|
writeShortLE(mask)
|
||||||
|
|
||||||
|
slots.forEach { slot ->
|
||||||
|
val skin = skinSet[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}" }
|
||||||
|
|
||||||
|
val compressed = (type and 0x3FFFu).toInt() or ((color and 0x3Fu).toInt() shl 10)
|
||||||
|
|
||||||
|
writeShortLE(compressed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteBuf.readSkinsLE(
|
||||||
|
slots: EnumEntries<SkinSlot>,
|
||||||
|
readByte: Boolean = true,
|
||||||
|
): SkinSet {
|
||||||
|
if (readByte) {
|
||||||
|
readByte()
|
||||||
|
}
|
||||||
|
val mask = readUnsignedShortLE()
|
||||||
|
val skinSet = SkinSet()
|
||||||
|
|
||||||
|
slots.forEach { slot ->
|
||||||
|
if ((mask and (1 shl slot.ordinal)) != 0) {
|
||||||
|
val compressed = readUnsignedShortLE()
|
||||||
|
val type = (compressed and 0x3FFF).toUShort()
|
||||||
|
val color = ((compressed shr 10) and 0x3F).toUByte()
|
||||||
|
skinSet.put(Skin(slot, type, color))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return skinSet
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package de.fiereu.openmmo.protocols.game.packets.codecs
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.Tile2D
|
||||||
|
import io.netty.buffer.ByteBuf
|
||||||
|
|
||||||
|
fun ByteBuf.readTile2DLE(): Tile2D {
|
||||||
|
val raw = readShortLE().toInt()
|
||||||
|
return Tile2D(material = (raw and 0x3FF).toShort(), collision = ((raw shr 10) and 0x3F).toByte())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ByteBuf.writeTile2DLE(tile: Tile2D) {
|
||||||
|
val raw = ((tile.collision.toInt() and 0x3F) shl 10) or (tile.material.toInt() and 0x3FF)
|
||||||
|
writeShortLE(raw)
|
||||||
|
}
|
||||||
@@ -3,43 +3,30 @@ package de.fiereu.openmmo.protocols.tls
|
|||||||
import de.fiereu.openmmo.protocols.Protocol
|
import de.fiereu.openmmo.protocols.Protocol
|
||||||
import de.fiereu.openmmo.protocols.incomingPacket
|
import de.fiereu.openmmo.protocols.incomingPacket
|
||||||
import de.fiereu.openmmo.protocols.outgoingPacket
|
import de.fiereu.openmmo.protocols.outgoingPacket
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ExistingSessionPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerListPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.GameServerNodesPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.JoinGameServerPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginKickPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.LoginResponsePacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaChallengePacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.MfaResponsePacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.RequestGameServerListPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.SentCredentialsPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.SentExistingSessionPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.ToSConfirmationPacketSerializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSPacket
|
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketDeserializer
|
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketDeserializer
|
||||||
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketSerializer
|
import de.fiereu.openmmo.protocols.tls.packets.ToSPacketSerializer
|
||||||
|
|
||||||
@@ -48,43 +35,40 @@ import de.fiereu.openmmo.protocols.tls.packets.ToSPacketSerializer
|
|||||||
* complete.
|
* complete.
|
||||||
*/
|
*/
|
||||||
abstract class LoginProtocol() : Protocol() {
|
abstract class LoginProtocol() : Protocol() {
|
||||||
override val async: Boolean
|
override val async: Boolean = true
|
||||||
get() = true
|
override val compressed: Boolean = false
|
||||||
override val compressed: Boolean
|
|
||||||
get() = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoginServerProtocol() : LoginProtocol() {
|
class LoginServerProtocol() : LoginProtocol() {
|
||||||
init {
|
init {
|
||||||
outgoingPacket(0x01u, LoginResponsePacketSerializer(), LoginResponsePacket::class)
|
outgoingPacket(0x01u, LoginResponsePacketSerializer())
|
||||||
incomingPacket(0x02u, RequestGameServerListPacketDeserializer())
|
incomingPacket(0x02u, RequestGameServerListPacketDeserializer())
|
||||||
incomingPacket(0x03u, JoinGameServerPacketDeserializer())
|
incomingPacket(0x03u, JoinGameServerPacketDeserializer())
|
||||||
outgoingPacket(0x03u, GameServerNodesPacketSerializer(), GameServerNodesPacket::class)
|
outgoingPacket(0x03u, GameServerNodesPacketSerializer())
|
||||||
incomingPacket(0x04u, ToSConfirmationPacketDeserializer())
|
incomingPacket(0x04u, ToSConfirmationPacketDeserializer())
|
||||||
outgoingPacket(0x05u, LoginKickPacketSerializer(), LoginKickPacket::class)
|
outgoingPacket(0x05u, LoginKickPacketSerializer())
|
||||||
outgoingPacket(0x07u, SentCredentialsPacketSerializer(), SentCredentialsPacket::class)
|
outgoingPacket(0x07u, SentCredentialsPacketSerializer())
|
||||||
outgoingPacket(0x08u, MfaChallengePacketSerializer(), MfaChallengePacket::class)
|
outgoingPacket(0x08u, MfaChallengePacketSerializer())
|
||||||
incomingPacket(0x08u, MfaResponsePacketDeserializer())
|
incomingPacket(0x08u, MfaResponsePacketDeserializer())
|
||||||
incomingPacket(0x11u, LoginRequestPacketDeserializer())
|
incomingPacket(0x11u, LoginRequestPacketDeserializer())
|
||||||
outgoingPacket(0x14u, ToSPacketSerializer(), ToSPacket::class)
|
outgoingPacket(0x14u, ToSPacketSerializer())
|
||||||
outgoingPacket(0x22u, GameServerListPacketSerializer(), GameServerListPacket::class)
|
outgoingPacket(0x22u, GameServerListPacketSerializer())
|
||||||
outgoingPacket(0x26u, SentExistingSessionPacketSerializer(), ExistingSessionPacket::class)
|
outgoingPacket(0x26u, SentExistingSessionPacketSerializer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoginClientProtocol() : LoginProtocol() {
|
class LoginClientProtocol() : LoginProtocol() {
|
||||||
init {
|
init {
|
||||||
incomingPacket(0x01u, LoginResponsePacketDeserializer())
|
incomingPacket(0x01u, LoginResponsePacketDeserializer())
|
||||||
outgoingPacket(
|
outgoingPacket(0x02u, RequestGameServerListPacketSerializer())
|
||||||
0x02u, RequestGameServerListPacketSerializer(), RequestGameServerListPacket::class)
|
outgoingPacket(0x03u, JoinGameServerPacketSerializer())
|
||||||
outgoingPacket(0x03u, JoinGameServerPacketSerializer(), JoinGameServerPacket::class)
|
|
||||||
incomingPacket(0x03u, GameServerNodesPacketDeserializer())
|
incomingPacket(0x03u, GameServerNodesPacketDeserializer())
|
||||||
outgoingPacket(0x04u, ToSConfirmationPacketSerializer(), ToSConfirmationPacket::class)
|
outgoingPacket(0x04u, ToSConfirmationPacketSerializer())
|
||||||
incomingPacket(0x05u, LoginKickPacketDeserializer())
|
incomingPacket(0x05u, LoginKickPacketDeserializer())
|
||||||
incomingPacket(0x07u, SentCredentialsPacketDeserializer())
|
incomingPacket(0x07u, SentCredentialsPacketDeserializer())
|
||||||
incomingPacket(0x08u, MfaChallengePacketDeserializer())
|
incomingPacket(0x08u, MfaChallengePacketDeserializer())
|
||||||
outgoingPacket(0x08u, MfaResponsePacketSerializer(), MfaResponsePacket::class)
|
outgoingPacket(0x08u, MfaResponsePacketSerializer())
|
||||||
outgoingPacket(0x11u, LoginRequestPacketSerializer(), LoginRequestPacket::class)
|
outgoingPacket(0x11u, LoginRequestPacketSerializer())
|
||||||
incomingPacket(0x14u, ToSPacketDeserializer())
|
incomingPacket(0x14u, ToSPacketDeserializer())
|
||||||
incomingPacket(0x22u, GameServerListPacketDeserializer())
|
incomingPacket(0x22u, GameServerListPacketDeserializer())
|
||||||
incomingPacket(0x26u, SentExistingSessionPacketDeserializer())
|
incomingPacket(0x26u, SentExistingSessionPacketDeserializer())
|
||||||
|
|||||||
@@ -22,25 +22,22 @@ import java.security.interfaces.ECPublicKey
|
|||||||
* (e.g. LoginProtocol) after the handshake is complete.
|
* (e.g. LoginProtocol) after the handshake is complete.
|
||||||
*/
|
*/
|
||||||
abstract class TlsProtocol() : Protocol() {
|
abstract class TlsProtocol() : Protocol() {
|
||||||
override val async: Boolean
|
override val async: Boolean = false
|
||||||
get() = false
|
override val compressed: Boolean = false
|
||||||
override val compressed: Boolean
|
|
||||||
get() = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TlsServerProtocol(serverKeyPair: Pair<ECPrivateKey, ECPublicKey>) : TlsProtocol() {
|
class TlsServerProtocol(serverKeyPair: Pair<ECPrivateKey, ECPublicKey>) : TlsProtocol() {
|
||||||
init {
|
init {
|
||||||
incomingPacket(0x00u, ClientHelloPacketDeserializer())
|
incomingPacket(0x00u, ClientHelloPacketDeserializer())
|
||||||
outgoingPacket(
|
outgoingPacket(0x01u, ServerHelloPacketSerializer(serverKeyPair.first))
|
||||||
0x01u, ServerHelloPacketSerializer(serverKeyPair.first), ServerHelloPacket::class)
|
|
||||||
incomingPacket(0x02u, ClientReadyPacketDeserializer())
|
incomingPacket(0x02u, ClientReadyPacketDeserializer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TlsClientProtocol() : TlsProtocol() {
|
class TlsClientProtocol() : TlsProtocol() {
|
||||||
init {
|
init {
|
||||||
outgoingPacket(0x00u, ClientHelloPacketSerializer(), ClientHelloPacket::class)
|
outgoingPacket(0x00u, ClientHelloPacketSerializer())
|
||||||
incomingPacket(0x01u, ServerHelloPacketDeserializer())
|
incomingPacket(0x01u, ServerHelloPacketDeserializer())
|
||||||
outgoingPacket(0x02u, ClientReadyPacketSerializer(), ClientReadyPacket::class)
|
outgoingPacket(0x02u, ClientReadyPacketSerializer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,12 +4,14 @@ import com.github.maltalex.ineter.base.IPAddress
|
|||||||
import com.github.maltalex.ineter.base.IPv4Address
|
import com.github.maltalex.ineter.base.IPv4Address
|
||||||
import com.github.maltalex.ineter.base.IPv6Address
|
import com.github.maltalex.ineter.base.IPv6Address
|
||||||
import io.netty.buffer.ByteBuf
|
import io.netty.buffer.ByteBuf
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
|
||||||
fun ByteBuf.readCharLE(): Char {
|
fun ByteBuf.readCharLE(): Char {
|
||||||
return ((readUnsignedByte().toInt() or (readUnsignedByte().toInt() shl 8)) and 0xFFFF).toChar()
|
return ((readUnsignedByte().toInt() or (readUnsignedByte().toInt() shl 8)) and 0xFFFF).toChar()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ByteBuf.writeCharLE(value: Char) {
|
fun ByteBuf.writeCharLE(value: Char): ByteBuf = apply {
|
||||||
writeByte(value.code and 0xFF)
|
writeByte(value.code and 0xFF)
|
||||||
writeByte((value.code shr 8) and 0xFF)
|
writeByte((value.code shr 8) and 0xFF)
|
||||||
}
|
}
|
||||||
@@ -23,7 +25,7 @@ fun ByteBuf.readUtf16LE(): String {
|
|||||||
return builder.toString()
|
return builder.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ByteBuf.writeUtf16LE(value: String) {
|
fun ByteBuf.writeUtf16LE(value: String): ByteBuf = apply {
|
||||||
for (c in value) {
|
for (c in value) {
|
||||||
writeCharLE(c)
|
writeCharLE(c)
|
||||||
}
|
}
|
||||||
@@ -46,7 +48,7 @@ fun ByteBuf.readIpLE(): IPAddress {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ByteBuf.writeIpLE(ipAddress: IPAddress) {
|
fun ByteBuf.writeIpLE(ipAddress: IPAddress): ByteBuf = apply {
|
||||||
when (ipAddress) {
|
when (ipAddress) {
|
||||||
is IPv4Address -> {
|
is IPv4Address -> {
|
||||||
writeByte(4)
|
writeByte(4)
|
||||||
@@ -71,7 +73,17 @@ fun ByteBuf.readIpRangeLE(): Pair<IPAddress, IPAddress> {
|
|||||||
return Pair(start, end)
|
return Pair(start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ByteBuf.writeIpRangeLE(start: IPAddress, end: IPAddress) {
|
fun ByteBuf.writeIpRangeLE(start: IPAddress, end: IPAddress): ByteBuf = apply {
|
||||||
writeIpLE(start)
|
writeIpLE(start)
|
||||||
writeIpLE(end)
|
writeIpLE(end)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun ByteBuf.readEpochSeconds(): LocalDateTime =
|
||||||
|
LocalDateTime.ofEpochSecond(readIntLE().toLong(), 0, ZoneOffset.UTC)
|
||||||
|
|
||||||
|
fun ByteBuf.writeEpochSecond(dateTime: LocalDateTime): ByteBuf =
|
||||||
|
writeIntLE(dateTime.toEpochSecond(ZoneOffset.UTC).toInt())
|
||||||
|
|
||||||
|
fun ByteBuf.writeByte(byte: Byte): ByteBuf = writeByte(byte.toInt())
|
||||||
|
|
||||||
|
fun ByteBuf.writeShortLE(short: Short): ByteBuf = writeShortLE(short.toInt())
|
||||||
@@ -57,7 +57,7 @@ abstract class Protocol {
|
|||||||
"Registering incoming packet: opcode=$opcode, deserializer=${deserializer::class.simpleName}"
|
"Registering incoming packet: opcode=$opcode, deserializer=${deserializer::class.simpleName}"
|
||||||
}
|
}
|
||||||
|
|
||||||
incomingPacketRegistry.put(opcode, deserializer)
|
incomingPacketRegistry[opcode] = deserializer
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Any> registerOutgoing(
|
fun <T : Any> registerOutgoing(
|
||||||
@@ -74,7 +74,7 @@ abstract class Protocol {
|
|||||||
error("Data class ${dataClass.simpleName} is already registered with an opcode!")
|
error("Data class ${dataClass.simpleName} is already registered with an opcode!")
|
||||||
}
|
}
|
||||||
dataClassToOpcode[dataClass] = opcode
|
dataClassToOpcode[dataClass] = opcode
|
||||||
outgoingPacketRegistry.put(opcode, serializer)
|
outgoingPacketRegistry[opcode] = serializer
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getSerializer(opcode: Opcode): PacketSerializer<*>? {
|
fun getSerializer(opcode: Opcode): PacketSerializer<*>? {
|
||||||
@@ -94,10 +94,9 @@ fun <T : Any> Protocol.incomingPacket(opcode: UByte, deserializer: PacketDeseria
|
|||||||
this.registerIncoming(Opcode(opcode), deserializer)
|
this.registerIncoming(Opcode(opcode), deserializer)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Any> Protocol.outgoingPacket(
|
inline fun <reified T : Any> Protocol.outgoingPacket(
|
||||||
opcode: UByte,
|
opcode: UByte,
|
||||||
serializer: PacketSerializer<T>,
|
serializer: PacketSerializer<T>
|
||||||
dataClass: KClass<T>
|
|
||||||
) {
|
) {
|
||||||
this.registerOutgoing(Opcode(opcode), serializer, dataClass)
|
this.registerOutgoing(Opcode(opcode), serializer, T::class)
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,9 @@ fun main() {
|
|||||||
.withTlsConfig(tlsConfig)
|
.withTlsConfig(tlsConfig)
|
||||||
.withPublicKey(KeyLoader.loadPemECPublicKey(resource("game.public.pem")))
|
.withPublicKey(KeyLoader.loadPemECPublicKey(resource("game.public.pem")))
|
||||||
.withPrivateKey(KeyLoader.loadPemECPrivateKey(resource("game.private.pem")))
|
.withPrivateKey(KeyLoader.loadPemECPrivateKey(resource("game.private.pem")))
|
||||||
.withChannelHandlerProvider { GameProtocolHandler(GameServerProtocol(), serverConfig, coroutineScope) }
|
.withChannelHandlerProvider {
|
||||||
|
GameProtocolHandler(GameServerProtocol(), serverConfig, coroutineScope)
|
||||||
|
}
|
||||||
.build()
|
.build()
|
||||||
server.start()
|
server.start()
|
||||||
}
|
}
|
||||||
+167
-5
@@ -1,14 +1,43 @@
|
|||||||
package de.fiereu.openmmo.server.game.protocol.game
|
package de.fiereu.openmmo.server.game.protocol.game
|
||||||
|
|
||||||
|
import de.fiereu.openmmo.common.CharacterInfo
|
||||||
|
import de.fiereu.openmmo.common.Pokemon
|
||||||
|
import de.fiereu.openmmo.common.Tile2D
|
||||||
|
import de.fiereu.openmmo.common.enums.ChatType
|
||||||
|
import de.fiereu.openmmo.common.enums.Direction
|
||||||
|
import de.fiereu.openmmo.common.enums.EVs
|
||||||
|
import de.fiereu.openmmo.common.enums.EncounterType
|
||||||
|
import de.fiereu.openmmo.common.enums.EntityStatus
|
||||||
|
import de.fiereu.openmmo.common.enums.IVs
|
||||||
|
import de.fiereu.openmmo.common.enums.Language
|
||||||
|
import de.fiereu.openmmo.common.enums.Lighting
|
||||||
|
import de.fiereu.openmmo.common.enums.MapType
|
||||||
|
import de.fiereu.openmmo.common.enums.PokemonContainer
|
||||||
|
import de.fiereu.openmmo.common.enums.Weather
|
||||||
import de.fiereu.openmmo.protocols.Protocol
|
import de.fiereu.openmmo.protocols.Protocol
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.CharacterEntry
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.CharacterListPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.ChatMessagePacket
|
||||||
import de.fiereu.openmmo.protocols.game.packets.JoinGamePacket
|
import de.fiereu.openmmo.protocols.game.packets.JoinGamePacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.LoadEntityPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.LoadMapPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.MapData
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.PokemonContainerPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RenderScreenPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RequestCharactersPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.RequestPlayerPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.SelectCharacterPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.SelectedCharacterPacket
|
||||||
|
import de.fiereu.openmmo.protocols.game.packets.codecs.SkinSet
|
||||||
import de.fiereu.openmmo.server.config.ServerConfig
|
import de.fiereu.openmmo.server.config.ServerConfig
|
||||||
import de.fiereu.openmmo.server.game.protocol.game.ext.accept
|
import de.fiereu.openmmo.server.game.protocol.game.ext.accept
|
||||||
import de.fiereu.openmmo.server.game.protocol.game.ext.buildAndRespond
|
import de.fiereu.openmmo.server.game.protocol.game.ext.buildAndRespond
|
||||||
import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler
|
import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler
|
||||||
import de.fiereu.openmmo.server.protocol.PacketEvent
|
import de.fiereu.openmmo.server.protocol.PacketEvent
|
||||||
|
import de.fiereu.openmmo.server.protocol.respond
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
import io.netty.channel.ChannelHandlerContext
|
import io.netty.channel.ChannelHandlerContext
|
||||||
|
import java.time.LocalDateTime
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@@ -29,6 +58,10 @@ class GameProtocolHandler(
|
|||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
when (event.packet) {
|
when (event.packet) {
|
||||||
is JoinGamePacket -> onJoinGame(event as PacketEvent<JoinGamePacket>)
|
is JoinGamePacket -> onJoinGame(event as PacketEvent<JoinGamePacket>)
|
||||||
|
is RequestCharactersPacket ->
|
||||||
|
onCharacterRequest(event as PacketEvent<RequestCharactersPacket>)
|
||||||
|
is SelectCharacterPacket -> onCharacterSelected(event as PacketEvent<SelectCharacterPacket>)
|
||||||
|
is RequestPlayerPacket -> onRequestPlayerPacket(event as PacketEvent<RequestPlayerPacket>)
|
||||||
else -> log.warn { "Unhandled game packet type: ${event.packet::class.simpleName}" }
|
else -> log.warn { "Unhandled game packet type: ${event.packet::class.simpleName}" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,10 +74,139 @@ class GameProtocolHandler(
|
|||||||
}
|
}
|
||||||
// TODO handle player joining the game e.g. authentication
|
// TODO handle player joining the game e.g. authentication
|
||||||
|
|
||||||
event.accept()
|
event.accept().withPlaytime(1337).withRewardPoints(420).withBalance(187).buildAndRespond(event)
|
||||||
.withPlaytime(1337)
|
}
|
||||||
.withRewardPoints(420)
|
|
||||||
.withBalance(187)
|
fun onCharacterRequest(event: PacketEvent<RequestCharactersPacket>) {
|
||||||
.buildAndRespond(event)
|
log.info { "Player requested character list." }
|
||||||
|
// TODO fetch character list from database and send it to the client
|
||||||
|
event.respond(
|
||||||
|
CharacterListPacket(
|
||||||
|
listOf(
|
||||||
|
CharacterEntry(
|
||||||
|
CharacterInfo(
|
||||||
|
id = 1,
|
||||||
|
name = "Character",
|
||||||
|
namePrefix = "Test D.",
|
||||||
|
userId = 1,
|
||||||
|
rivalSex = 0,
|
||||||
|
lastLogin = LocalDateTime.of(2025, 1, 1, 12, 0),
|
||||||
|
createdAt = LocalDateTime.of(2020, 1, 1, 12, 0),
|
||||||
|
money = 1_000_000,
|
||||||
|
permissions = 8,
|
||||||
|
remainingSafariSteps = 0,
|
||||||
|
remainingSafariBalls = 0,
|
||||||
|
pcExtraSlots = 0,
|
||||||
|
battleBoxExtraSlots = 0,
|
||||||
|
templateAmount = 0,
|
||||||
|
positionRegionId = 1,
|
||||||
|
positionBankId = 1,
|
||||||
|
positionMapId = 1,
|
||||||
|
positionX = 100,
|
||||||
|
positionY = 100,
|
||||||
|
repelLeft = 0,
|
||||||
|
repelItemId = 0,
|
||||||
|
lureLeft = 0,
|
||||||
|
lureItemId = 0),
|
||||||
|
skinSet = SkinSet(),
|
||||||
|
null,
|
||||||
|
pokemon =
|
||||||
|
listOf(
|
||||||
|
Pokemon(
|
||||||
|
id = 1,
|
||||||
|
container = PokemonContainer.PARTY,
|
||||||
|
containerSlot = 0,
|
||||||
|
dexId = 497,
|
||||||
|
seed = 0,
|
||||||
|
ot = "ich",
|
||||||
|
nickname = "whhhat?",
|
||||||
|
level = 100,
|
||||||
|
hp = 187,
|
||||||
|
xp = 0,
|
||||||
|
eVs = EVs(),
|
||||||
|
iVs = IVs(),
|
||||||
|
moves = emptyList(),
|
||||||
|
isShiny = false,
|
||||||
|
hasHiddenAbility = false,
|
||||||
|
isAlpha = true,
|
||||||
|
isSecret = false,
|
||||||
|
isFatefulEncounter = false,
|
||||||
|
isRaidEncounter = false,
|
||||||
|
caughtAt = LocalDateTime.of(2020, 1, 1, 12, 0),
|
||||||
|
))))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onCharacterSelected(event: PacketEvent<SelectCharacterPacket>) {
|
||||||
|
log.info { "Player selected character ${event.packet.characterId}" }
|
||||||
|
// We need to send the party first.
|
||||||
|
// Without the HudGui won't render
|
||||||
|
event.respond(
|
||||||
|
PokemonContainerPacket(
|
||||||
|
PokemonContainer.PARTY, hasChange = true, delete = false, pokemon = emptyList()))
|
||||||
|
event.respond(
|
||||||
|
SelectedCharacterPacket(
|
||||||
|
CharacterInfo(
|
||||||
|
id = 1,
|
||||||
|
name = "Character",
|
||||||
|
namePrefix = "Test D.",
|
||||||
|
userId = 1,
|
||||||
|
rivalSex = 0,
|
||||||
|
lastLogin = LocalDateTime.of(2025, 1, 1, 12, 0),
|
||||||
|
createdAt = LocalDateTime.of(2020, 1, 1, 12, 0),
|
||||||
|
money = 1_000_000,
|
||||||
|
permissions = 8,
|
||||||
|
remainingSafariSteps = 0,
|
||||||
|
remainingSafariBalls = 0,
|
||||||
|
pcExtraSlots = 0,
|
||||||
|
battleBoxExtraSlots = 0,
|
||||||
|
templateAmount = 0,
|
||||||
|
positionRegionId = 1,
|
||||||
|
positionBankId = 1,
|
||||||
|
positionMapId = 1,
|
||||||
|
positionX = 100,
|
||||||
|
positionY = 100,
|
||||||
|
repelLeft = 0,
|
||||||
|
repelItemId = 0,
|
||||||
|
lureLeft = 0,
|
||||||
|
lureItemId = 0)))
|
||||||
|
event.respond(
|
||||||
|
ChatMessagePacket(ChatType.GAME_NOTIFICATIONS, Language.EN, "Welcome to OpenMMO!", ""))
|
||||||
|
event.respond(
|
||||||
|
LoadMapPacket(
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
6,
|
||||||
|
6,
|
||||||
|
MapData.GbaMapData(
|
||||||
|
15,
|
||||||
|
10,
|
||||||
|
12,
|
||||||
|
14,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
listOf(Tile2D(8, 0), Tile2D(8, 0), Tile2D(8, 0), Tile2D(8, 0)),
|
||||||
|
Lighting.REGULAR,
|
||||||
|
Weather.IN_HOUSE_WEATHER,
|
||||||
|
MapType.INSIDE,
|
||||||
|
EncounterType.RANDOM)))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onRequestPlayerPacket(event: PacketEvent<RequestPlayerPacket>) {
|
||||||
|
event.respond(
|
||||||
|
LoadEntityPacket(
|
||||||
|
1,
|
||||||
|
SkinSet(),
|
||||||
|
"Character",
|
||||||
|
0,
|
||||||
|
6,
|
||||||
|
6,
|
||||||
|
8,
|
||||||
|
5,
|
||||||
|
Direction.SOUTH,
|
||||||
|
EntityStatus.NONE,
|
||||||
|
hasFollower = false,
|
||||||
|
0))
|
||||||
|
event.respond(RenderScreenPacket(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user