feat(dialog): generate per-location gba dialog enums from the rom and drop the old script params (#64)

This commit is contained in:
Fiereu authored and GitHub committed 2026-07-25 21:26:43 +02:00
1 parent e89ae6e6df
commit 9c52eeb8c6
13 files changed
+419 -132

No files matched your search

@@ -1,13 +1,10 @@
package de.fiereu.openmmo.server.game.services
import de.fiereu.network.PacketEvent
import de.fiereu.network.SessionContext
import de.fiereu.openmmo.net.game.packets.DialogChoicePacket
import de.fiereu.openmmo.net.game.packets.DialogStatePacket
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionPacket
import de.fiereu.openmmo.net.game.packets.dialog.DialogActionResponsePacket
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
import de.fiereu.openmmo.server.game.session.ScriptPage
import io.github.oshai.kotlinlogging.KotlinLogging
import javax.inject.Inject
import javax.inject.Singleton
@@ -17,85 +14,13 @@ private val log = KotlinLogging.logger {}
@Singleton
class DialogService @Inject constructor() {
fun scriptParams(script: String): List<ScriptPage>? {
if (script == "0x0") return null
val known =
mapOf<String, List<ScriptPage>>(
"LittlerootTown_ProfessorBirchsLab_EventScript_Birch" to
listOf(ScriptPage(type = 0x04, unk1 = 0xAA74, unk2 = 0x1F10, unk3 = 0x0708)),
"LittlerootTown_ProfessorBirchsLab_EventScript_Aide" to
listOf(ScriptPage(type = 0x04, unk1 = 0xA6CE, unk2 = 0x1F10, unk3 = 0x04B0)),
"PlayersHouse_1F_EventScript_Mom" to
listOf(
ScriptPage(type = 0x04, unk1 = 0x087D, unk2 = 0x1F10, unk3 = 0x04B0),
ScriptPage(type = 0x04, unk1 = 0x7D5C, unk2 = 0x1F10, unk3 = 0x02BC),
),
"RivalsHouse_1F_EventScript_RivalMom" to
listOf(ScriptPage(type = 0x04, unk1 = 0x8CE3, unk2 = 0x1E10, unk3 = 0x02BC)),
"RivalsHouse_1F_EventScript_RivalSibling" to
listOf(ScriptPage(type = 0x04, unk1 = 0x8B25, unk2 = 0x1E10, unk3 = 0x0708)),
"LittlerootTown_EventScript_Twin" to
listOf(ScriptPage(type = 0x04, unk1 = 0x6292, unk2 = 0x1F10, unk3 = 0x04B0)),
"LittlerootTown_EventScript_Boy" to
listOf(ScriptPage(type = 0x04, unk1 = 0x938D, unk2 = 0x1F10, unk3 = 0x04B0)),
)
return known[script]
}
fun sendInteractive(
ctx: SessionContext,
id: Int,
entityId: Long,
type: Int = 0x04,
unk1: Int = 0xAA74,
unk2: Int = 0x1F10,
unk3: Int = 0x0708,
) {
ctx.send(
DialogActionPacket(
flags = id.toByte(),
actionType = type.toByte(),
// The client reads the text id as one little endian int whose two halves the scripts
// carry as unk1 (low) and unk2 (high).
textId = unk1 or (unk2 shl 16),
entityId = entityId,
contextValue = unk3,
messageArgs = emptyList(),
detail = ByteArray(0),
))
}
fun onInteractive(event: PacketEvent<DialogActionResponsePacket>) {
val ctx = event.session
val state = ctx.attributes[PLAYER_STATE] ?: return
val charId = state.characterId ?: return
if (state.inDialog) {
val respId = event.packet.id
log.info {
"Interactive response: id=$respId for char $charId (page ${state.dialogPageIndex + 1}/${state.dialogPages.size})"
}
val nextPageIndex = state.dialogPageIndex + 1
if (nextPageIndex < state.dialogPages.size) {
val seqId = state.dialogSeqId++
val page = state.dialogPages[nextPageIndex]
state.dialogPageIndex = nextPageIndex
sendInteractive(
ctx,
seqId,
state.dialogNpcEntityId,
page.type,
page.unk1,
page.unk2,
page.unk3,
)
} else {
ctx.send(DialogStatePacket(false))
state.inDialog = false
state.dialogNpcEntityId = 0
state.dialogPages = emptyList()
state.dialogPageIndex = 0
}
ctx.send(DialogStatePacket(false))
state.inDialog = false
state.dialogNpcEntityId = 0
}
}
@@ -3,7 +3,6 @@ package de.fiereu.openmmo.server.game.services
import de.fiereu.network.PacketEvent
import de.fiereu.openmmo.common.enums.Direction
import de.fiereu.openmmo.maps.MapManager
import de.fiereu.openmmo.net.game.packets.DialogStatePacket
import de.fiereu.openmmo.net.game.packets.EntityInteractPacket
import de.fiereu.openmmo.server.game.session.PLAYER_STATE
import de.fiereu.openmmo.server.game.storage.CharacterStore
@@ -18,7 +17,6 @@ class InteractionService
@Inject
constructor(
private val npcService: NpcService,
private val dialogService: DialogService,
private val mapManager: MapManager,
private val characterStore: CharacterStore,
) {
@@ -40,33 +38,10 @@ constructor(
val bankId = stored.info.positionBankId.toInt()
val mapId = stored.info.positionMapId.toInt()
for (npc in currentMap.npcs) {
val expectedId = npcService.getNpcEntityId(bankId, mapId, npc.entityIdx)
if (expectedId == npcEntityId) {
if (npcService.getNpcEntityId(bankId, mapId, npc.entityIdx) == npcEntityId) {
log.info {
"Entity interaction: NPC entityIdx=${npc.entityIdx} entityId=$npcEntityId script=${npc.script}"
}
if (npc.script != "0x0") {
val params = dialogService.scriptParams(npc.script)
if (params != null) {
state.inDialog = true
state.dialogNpcEntityId = npcEntityId
state.dialogPages = params
state.dialogPageIndex = 0
val seqId = state.dialogSeqId++
val page = params[0]
ctx.send(DialogStatePacket(true))
dialogService.sendInteractive(
ctx,
seqId,
npcEntityId,
page.type,
page.unk1,
page.unk2,
page.unk3,
)
}
}
return
}
}
@@ -93,25 +68,7 @@ constructor(
val bgEvent =
currentMap.bgEvents.find { it.x == facingX && it.y == facingY && facingDirOk(it.facingDir) }
if (bgEvent != null) {
val params = dialogService.scriptParams(bgEvent.script)
if (params != null) {
state.inDialog = true
state.dialogNpcEntityId = npcEntityId
state.dialogPages = params
state.dialogPageIndex = 0
val seqId = state.dialogSeqId++
val page = params[0]
ctx.send(DialogStatePacket(true))
dialogService.sendInteractive(
ctx,
seqId,
npcEntityId,
page.type,
page.unk1,
page.unk2,
page.unk3,
)
}
log.info { "Entity interaction: bg event at ($facingX, $facingY) script=${bgEvent.script}" }
return
}
@@ -2,13 +2,6 @@ package de.fiereu.openmmo.server.game.session
import de.fiereu.openmmo.common.enums.Direction
data class ScriptPage(
val type: Int = 0x04,
val unk1: Int,
val unk2: Int,
val unk3: Int,
)
data class PlayerState(
val userId: Int,
var characterId: Long? = null,
@@ -17,8 +10,6 @@ data class PlayerState(
var inDialog: Boolean = false,
var dialogNpcEntityId: Long = 0,
var dialogSeqId: Int = 0,
var dialogPages: List<ScriptPage> = emptyList(),
var dialogPageIndex: Int = 0,
var regionId: Int = 1,
var bankId: Int = 51,
var mapId: Int = 3,