mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-16 08:11:35 +02:00
G2 support
This commit is contained in:
@@ -396,10 +396,14 @@ local function encodeStatus(status)
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Def rows share a generated table's top level with provenance scalars on
|
||||
-- some data sets (src/import/RomExtractorGen2.lua stamps `generation` and
|
||||
-- `source` beside the entries), so every pairs(defs) walk here must keep
|
||||
-- to table rows: indexing a scalar row raises instead of skipping it.
|
||||
local function buildIndexCrosswalk(defs)
|
||||
local byIndex, byId = {}, {}
|
||||
for id, def in pairs(defs or {}) do
|
||||
if def.index ~= nil then
|
||||
if type(def) == "table" and def.index ~= nil then
|
||||
byIndex[def.index] = id
|
||||
byId[id] = def.index
|
||||
end
|
||||
@@ -420,7 +424,8 @@ end
|
||||
local function buildDexCrosswalk(defs)
|
||||
local byDex, dexOf = {}, {}
|
||||
for id, def in pairs(defs or {}) do
|
||||
local n = def.source and tonumber(def.source:match("BaseStats%[(%d+)%]"))
|
||||
local n = type(def) == "table" and def.source
|
||||
and tonumber(def.source:match("BaseStats%[(%d+)%]"))
|
||||
if n then
|
||||
byDex[n] = id
|
||||
dexOf[id] = n
|
||||
@@ -438,7 +443,8 @@ end
|
||||
-- per slot -- i.e. HM01=196+.. , TM01=201+(number-1).
|
||||
local function addMachineIndices(defs, byIndex, byId)
|
||||
for id, def in pairs(defs or {}) do
|
||||
if byId[id] == nil and def.machine and def.machine.number then
|
||||
if type(def) == "table" and byId[id] == nil
|
||||
and def.machine and def.machine.number then
|
||||
local base = def.machine.kind == "HM" and 195 or 200
|
||||
local idx = base + def.machine.number
|
||||
byIndex[idx] = id
|
||||
|
||||
@@ -214,6 +214,15 @@ SaveConvert.mergeDefaults = mergeDefaults
|
||||
-- Public API
|
||||
-- ------------------------------------------------------------------
|
||||
|
||||
-- GenSave models Gen 1 SRAM and nothing else: a Gen 2 cart save is a
|
||||
-- different bank map, party struct and checksum scheme (pokegold
|
||||
-- ram/sram.asm sOptions/sCheckValue1/sPlayerData/sBox1-sBox14 vs
|
||||
-- pokered's single sPlayerName..sMainDataCheckSum window), and no Gen 2
|
||||
-- codec exists yet. Both directions answer with a plain message the
|
||||
-- launcher's save card renders as-is, instead of pushing a Gen 2 save
|
||||
-- table through Gen 1 offsets and surfacing a codec traceback.
|
||||
local GEN2_SAV_UNSUPPORTED = { gold = "Pokemon Gold" }
|
||||
|
||||
-- importSav(bytes, version, gameVersion) -> saveTable, err
|
||||
-- bytes: the raw 32768-byte SRAM string. Validates size and the main-data
|
||||
-- checksum, decodes through GenSave, and returns a save table fully merged
|
||||
@@ -226,6 +235,10 @@ function SaveConvert.importSav(bytes, version, gameVersion)
|
||||
if type(bytes) ~= "string" then
|
||||
return nil, "expected raw save bytes as a string"
|
||||
end
|
||||
local gen2Name = GEN2_SAV_UNSUPPORTED[gameVersion]
|
||||
if gen2Name then
|
||||
return nil, gen2Name .. " uses a Gen 2 cart save; importing one is not supported yet."
|
||||
end
|
||||
if #bytes ~= GenSave.SAVE_SIZE then
|
||||
return nil, ("save must be %d bytes, got %d"):format(GenSave.SAVE_SIZE, #bytes)
|
||||
end
|
||||
@@ -258,6 +271,10 @@ function SaveConvert.exportSav(saveTable, gameVersion)
|
||||
if type(saveTable) ~= "table" then
|
||||
return nil, "expected a save table"
|
||||
end
|
||||
local gen2Name = GEN2_SAV_UNSUPPORTED[gameVersion]
|
||||
if gen2Name then
|
||||
return nil, gen2Name .. " uses a Gen 2 cart save; exporting one is not supported yet."
|
||||
end
|
||||
local data, derr = ensureData(gameVersion)
|
||||
if not data then return nil, derr end
|
||||
local ok, bytes = pcall(GenSave.encode, saveTable, data, nil)
|
||||
|
||||
Reference in New Issue
Block a user