Files
gen1recomp/src/core/LaunchOptions.lua
T
bryanthaboi ca4d3d283c Add Pokemon Crystal as a sixth supported version
Crystal boots from a user-supplied ROM, imports a full cache and is playable:
copyright, the Crystal intro movie, the animated title, gender select, Oak,
and out into Johto. 122 of the cart's 169 script specials are implemented.

Import and data
- tools/make_crystal_manifest.py derives the manifest by importing
  make_gold_manifest as a library, with three additive keyword seams. Gold and
  Silver still regenerate byte-identical, which is the standing requirement for
  touching that generator.
- crystal_symbol_deltas.py and crystal_movie_symbols.py carry the symbol delta:
  Crystal renames the credits mons, splits the trainer card, Pokegear and
  pack-pal blocks by gender, and replaces the intro and title outright.
- Crystal-only manifest keys: engineFlagOrder (162 flags to Gold's 93, so the
  badge block sits one higher) and unownCharmap (the main charmap parser stops
  at the first newcharmap so the two cannot contaminate each other).

Extractor
- RomExtractorGen2 becomes three-edition. Crystal corrections: PAL_MAP_BANK
  0x13, a flat PICS_FIX pic bank, audio bank 0x5e, the mapSongs id-100 hole,
  seven NPC trades, a TradeTexts stride of 8, the five Crystal tileset anim
  steps with per-row degrade, and the column-major trainer card portraits.
- New: animated front sprites (frames, bitmasks, play and idle scripts), the
  Battle Tower roster, Kris assets, Mobile System GB art, and the Crystal
  intro and title via src/import/CrystalMovie.lua.

Engine
- GameVersion gains engine(id) and fixes(id). Gold and Silver keep their
  original bugs where the bug is not hardware dependent; Crystal gets the fixes
  Crystal shipped: Lucky Number boxes 10-14, surfing onto an NPC, and the
  Reflect and Light Screen defence overflow.
- Crystal story: Suicune and Eusine, Celebi behind the GS Ball flag, the Ruins
  of Alph chambers, Buena, the Move Tutor, the Poke Seer, and the Battle Tower
  including the wInBattleTowerBattle badge-boost guard.
- Kris and the gender flag, animated fronts in battle and the summary screen,
  and mon caught data.

Verification
- Every extracted asset is pixel-compared against pret's own source PNGs.
- Gold caches are byte-identical before and after, file for file.
- New Crystal suites plus a T2 Gen 2 tier; the full suite passes.
2026-08-23 12:10:28 -04:00

137 lines
4.8 KiB
Lua

-- Launch options: boot straight into a game, skipping the launcher.
--
-- love . --game=red -- boot Red
-- love . --game=yellow --slot=2 -- boot Yellow on save slot 2
-- love . --game=gold -- boot Gold (src/core/Game2.lua)
-- love . --game=red --launcher -- open the launcher anyway (a shortcut
-- the player wants to edit)
-- POKEPORT_GAME=blue love . -- same, for launchers that only pass env
--
-- The "--flag value" spelling parses here (argValue reads argv[i + 1]), but it
-- does not survive LOVE: boot.lua takes the first bare argument as a path to a
-- game to run, so `--game red` dies with "Cannot load game at path .../red"
-- before love.load is ever called, fused or not. Only the "=" spelling is
-- reachable, so that is the one the docs quote.
--
-- This exists for the click-once cases: a desktop shortcut per game, a Steam
-- entry, an EmulationStation/Playnite entry, a handheld frontend. Those all
-- want "start the thing" and treat any menu in between as a defect.
--
-- Everything here is pure resolution and validation -- no love.* beyond the
-- filesystem read that slot selection needs -- so the engine test tier can
-- cover the parsing without a window.
local GameVersion = require("src.core.GameVersion")
local LaunchOptions = {}
-- Set by main.lua when a requested game turns out not to be importable yet:
-- the launcher opens on that tab instead of booting.
LaunchOptions.pendingTab = nil
local function normalizeVersion(v)
if type(v) ~= "string" then return nil end
v = v:lower():gsub("^%s+", ""):gsub("%s+$", "")
if v == "" then return nil end
-- Accept the aliases people actually type.
local alias = {
r = "red", red = "red",
b = "blue", blue = "blue",
y = "yellow", yellow = "yellow",
g = "gold", gold = "gold",
s = "silver", silver = "silver",
c = "crystal", crystal = "crystal",
}
v = alias[v] or v
if GameVersion.VERSIONS and not GameVersion.VERSIONS[v] then return nil end
return v
end
-- Pull "--flag value" (and "--flag=value") out of LOVE's arg table.
local function argValue(argv, name)
if type(argv) ~= "table" then return nil end
for i = 1, #argv do
local a = argv[i]
if a == "--" .. name then
return argv[i + 1]
end
local inline = type(a) == "string" and a:match("^%-%-" .. name .. "=(.*)$")
if inline then return inline end
end
return nil
end
local function argFlag(argv, name)
if type(argv) ~= "table" then return false end
for i = 1, #argv do
if argv[i] == "--" .. name then return true end
end
return false
end
local cachedIntentGame = nil
-- Returns version, slotId (either may be nil). Command line wins over env,
-- so a shortcut can override a machine-wide default.
function LaunchOptions.resolve(argv)
if cachedIntentGame == nil then
if love.system and love.system.getOS and love.system.getOS() == "Android"
and love.system.getLaunchGame then
cachedIntentGame = normalizeVersion(love.system.getLaunchGame()) or false
else
cachedIntentGame = false
end
end
local intentGame = cachedIntentGame or nil
local game = normalizeVersion(argValue(argv, "game"))
or intentGame
or normalizeVersion(os.getenv("POKEPORT_GAME"))
or normalizeVersion(os.getenv("POKEPORT_LAUNCH"))
local slot = argValue(argv, "slot") or os.getenv("POKEPORT_SLOT")
if type(slot) == "string" then
slot = slot:gsub("^%s+", ""):gsub("%s+$", "")
if slot == "" then slot = nil end
end
return game, slot
end
function LaunchOptions.forceLauncher(argv)
return argFlag(argv, "launcher") or os.getenv("POKEPORT_FORCE_LAUNCHER") == "1"
end
-- Point a version at a save slot before it boots. Accepts either a slot id
-- ("slot2") or a 1-based index ("2"), because a shortcut author should not
-- have to know the internal id scheme. A slot that does not exist is
-- ignored: booting the game on its previous slot beats refusing to start.
-- Returns the id actually selected, or nil.
function LaunchOptions.selectSlot(version, slot)
local ok, SaveData = pcall(require, "src.core.SaveData")
if not ok then return nil end
local listed = SaveData.listSlots and SaveData.listSlots(version) or nil
if type(listed) ~= "table" or #listed == 0 then return nil end
local target
local index = tonumber(slot)
if index and listed[index] then
target = listed[index].id
else
for _, s in ipairs(listed) do
if s.id == slot then target = s.id break end
end
end
if not target then return nil end
pcall(SaveData.setActiveSlot, version, target)
return target
end
-- The shortcut command a player would use for this game, for the launcher to
-- show and for docs to quote.
function LaunchOptions.commandFor(version, slot)
local cmd = "--game " .. tostring(version)
if slot then cmd = cmd .. " --slot " .. tostring(slot) end
return cmd
end
return LaunchOptions