User File #638733922610971066

Upload All User Files

#638733922610971066 - [DQ9] Random Battlefield in Grottoes (USA)

DQ9_RandomBattlefield_USA.lua
11 downloads
Uploaded 7 days ago by TKG (see all 11)
-- Memory map by eidako/yab:
-- https://gamefaqs.gamespot.com/ds/937281-dragon-quest-ix-sentinels-of-the-starry-skies/faqs/68804

local tbl_assetBattle = {
   {0x82C8, "(SPECIAL) several texture grids (from TBL_ASSETLOCATION)"},
   {0x82D8, "(SPECIAL) number grid (1 to 100) (from TBL_ASSETLOCATION)"},
   {0x82E8, "(SPECIAL) number grid (101 to 179) (from TBL_ASSETLOCATION)"},
   {0xB2D8, "field -> hills -> mts"},
   {0xB2E8, "flower -> forest -> mts"},
   {0xB2F8, "(void)"},
   {0xB308, "forest"},
   {0xB318, "hills -> mts"},
   {0xB338, "desert -> grass/ocean"},
   {0xB348, "desert -> hills -> mts"},
   {0xB368, "field -> hills -> mts"},
   {0xB378, "forest -> hills"},
   {0xB388, "field -> crops -> mts"},
   {0xB398, "field -> poison swamp"},
   {0xB3A8, "flowers -> water -> mts"},
   {0xB3C8, "clay -> forest -> mts"},
   {0xB3D8, "field -> forested hill"},
   {0xB3E8, "clay -> poison swamp"},
   {0xB3F8, "clay -> forest -> mts"},
   {0xB418, "gloomy field -> mts"},
   {0xB428, "autumn field -> mts"},
   {0xB438, "gloomy field -> mts"},
   {0xB458, "cracked ground -> water"},
   {0xB468, "flat ground -> mts"},
   {0xB478, "hills -> forest"},
   {0xB498, "grassy basin"},
   {0xB4A8, "forested hills"},
   {0xB4B8, "clay -> fields -> mts"},
   {0xB4C8, "scorched -> ocean"},
   {0xB4E8, "flowery hills -> river"},
   {0xB4F8, "flowery hills -> waterfall"},
   {0xB508, "beach -> forest -> mts"},
   {0xB528, "field -> flowery hills"},
   {0xB538, "field -> forest -> hills"},
   {0xB548, "clay -> cliffs"},
   {0xB558, "lighthouse beach"},
   {0xB578, "field -> river"},
   {0xB588, "hills -> forest"},
   {0xB598, "wasteland hills"},
   {0xB5A8, "kelp beach"},
   {0xB5C8, "sand dunes"},
   {0xB5D8, "desert wasteland"},
   {0xB5E8, "desert oasis"},
   {0xB5F8, "red hills -> forest"},
   {0xB618, "field -> mts"},
   {0xB628, "hilly field -> forest"},
   {0xB638, "clay beach"},
   {0xB658, "rainy forest"},
   {0xB668, "rainy forest basin"},
   {0xB678, "forested hills"},
   {0xB688, "forest basin"},
   {0xB6A8, "snow graves"},
   {0xB6B8, "snow -> forest"},
   {0xB6D8, "grass -> snow"},
   {0xB6F8, "snowblown beach"},
   {0xB718, "swampy bridges"},
   {0xB738, "grassy hills"},
   {0xB758, "blighted field -> rugged mts"},
   {0xB768, "dead earth -> poison swamp"},
   {0xB778, "dead earth -> poison swamp"},
   {0xB798, "yellow grass -> lake"},
   {0xB7A8, "sparse grass -> trees"},
   {0xB7C8, "grassy hills -> trees"},
   {0xB7E8, "dry mounds"},
   {0xB808, "dead grave hills"},
   {0xB818, "cabin field -> forest"},
   {0xB838, "grassy hills"},
   {0xB848, "forest basin"},
   {0xB858, "tidepool beach"},
   {0xB878, "yellowish field -> hills"},
   {0xB888, "yellowish forest basin"},
   {0xB898, "wasteland"},
   {0xB8A8, "wasteland"},
   {0xB8C8, "shrubby clay"},
   {0xB8D8, "red shrubby clay"},
   {0xB8E8, "dry beach"},
   {0xB8F8, "rocky cliffs"},
   {0xB908, "shrubby cliffs"},
   {0xB918, "rocky cliffs"},
   {0xB938, "poison rocks -> volcano"},
   {0xB948, "rocky beach"},
   {0xB958, "poison rocks -> volcano"},
   {0xB988, "desolate rocky hills"},
   {0xB9A8, "in front of Brigadoom"},
   {0xB9B8, "Brigadoom tower"},
   {0xB9C8, "Brigadoom throne room"},
   {0xB9D8, "Brigadoom hallway"},
   {0xB9F8, "Trades Tower mirror"},
   {0xBA08, "tower hallway"},
   {0xBA28, "volcanic vents"},
   {0xBA38, "volcano ruins"},
   {0xBA48, "volcanic cliff"},
   {0xBA58, "volcano dragon lair"},
   {0xBA78, "shoal beach"},
   {0xBA88, "inlet island"},
   {0xBA98, "water stepping stones"},
   {0xBAB8, "Hexagon ruins"},
   {0xBAC8, "Hexagon murals"},
   {0xBAE8, "gloomy hills"},
   {0xBAF8, "cave intersection"},
   {0xBB08, "purple dungeon"},
   {0xBB18, "ugly purple statues"},
   {0xBB38, "sewer walkways"},
   {0xBB48, "underground graveyard"},
   {0xBB58, "sewer room"},
   {0xBB78, "mountain bridges"},
   {0xBB88, "inside big tent"},
   {0xBB98, "bottom of huge cliff"},
   {0xBBA8, "cave with iron gate"},
   {0xBBC8, "Old Swinedimples library"},
   {0xBBD8, "Old Swinedimples altar"},
   {0xBBE8, "Old Swinedimples classroom"},
   {0xBC08, "mossy cave"},
   {0xBC18, "mossy cave spring"},
   {0xBC28, "mossy cave poison spring"},
   {0xBC48, "mountain bridges"},
   {0xBC58, "cave monolith"},
   {0xBC68, "under a large bridge"},
   {0xBC78, "base of large bridge"},
   {0xBC98, "Loch Storn"},
   {0xBCB8, "brick dungeon"},
   {0xBCC8, "brick throne room"},
   {0xBCE8, "on top of cliff?"},
   {0xBD08, "Starflight Express?"},
   {0xBD28, "cave grotto"},
   {0xBD38, "cave grotto boss"},
   {0xBD48, "ruins grotto"},
   {0xBD58, "ruins grotto boss"},
   {0xBD68, "ice grotto"},
   {0xBD78, "ice grotto boss"},
   {0xBD88, "water grotto"},
   {0xBD98, "water grotto boss"},
   {0xBDA8, "lava grotto"},
   {0xBDB8, "lava grotto boss"},
   {0xBDD8, "castle ruins hall"},
   {0xBDE8, "castle ruins ballroom"},
   {0xBDF8, "castle ruins courtyard"},
   {0xBE18, "yellow brick dungeon"},
   {0xBE28, "yellow brick hall"},
   {0xBE38, "Oubliette seal insignia"},
   {0xBE58, "Gittingham backdrop"},
   {0xBE68, "front of Gittingham"},
   {0xBE78, "Gittingham courtyard"},
   {0xBE88, "Gittingham doorway"},
   {0xBE98, "Gittingham intersection"},
   {0xBEA8, "Gittingham throne room"},
   {0xBEC8, "brick prison"},
   {0xBED8, "cave stairs"},
   {0xBEE8, "cave island"},
   {0xBEF8, "brick intersection"},
   {0xBF08, "tapestry room"},
   {0xBF28, "stone vines"},
   {0xBF38, "Mighty's Realm cave"},
   {0xBF48, "Mighty's Realm outside"},
   {0xBF58, "lava waterfalls"},
   {0xBF68, "blue carpet door"},
   {0xBF78, "Mighty's Realm gargoyles poison"},
   {0xBF88, "Mighty's Realm platform"},
   {0xBF98, "Mighty's Realm gargoyles"},
   {0xBFA8, "Mighty's Realm throne"},
   {0xBFB8, "rocks floating in sky"},
   {0xBFC8, "sky rock tempest"},
   {0xBFE8, "throne room"},
   {0xBFF8, "another throne room"},
   {0xC008, "sinister throne room"},
   {0xC018, "blue throne room"},
   {0xC028, "cinders throne"},
   {0xC038, "lava platform"},
   {0xC048, "lightning statues"},
   {0xC058, "evil throne room"},
   {0xC068, "rising evil souls"},
   {0xC078, "flashing magic seal"},
   {0xC088, "giant torch sconces"},
   {0xC098, "beating hearts cave"},
   {0xC0A8, "floating rocks cyclone"},
   {0xC0B8, "treasure hoard"},
   {0xC0C8, "cosmic mists"},
   {0xC0D8, "briar nest"},
   {0xC0E8, "bandaged sarcophagus"},
   {0xC108, "grassy stairs"},
   {0xC128, "Zere Rocks"},
   {0xC148, "yurts wasteland"},
   {0xC168, "deck of ship"},
   {0xC188, "(SPECIAL) hardwood stage"},
   {0xC198, "(SPECIAL) a volcano"}
}

local tbl_addr = {
   mapCount = 0x020F98CC, -- (uint8) number of maps in inventory (0-99)
   mapBase = 0x020F98CE,   -- (uint8) treasure map base addr (status + current map + type)

   -- added for battlefield
   currentType = 0x020FD7DD, -- (uint8) normal/legacy flag
   battleFlag = 0x022A44C6, -- (uint8) in battle flag (can also use 0x022A44E4)
   currentSeed = 0x020FD828, -- (uint16) current map seed
   battlefield = 0x02392920  -- (uint16) battlefield ID
}

local tbl_offset = {
   mapIndex = 0x1C,
   discover = 0x1,      -- Ascii2f[10] same as ascii but characters are 0x2F less(?)
   conquer = 0xB,       -- Ascii2f[10] same as ascii but characters are 0x2F less(?)
   location = 0x15,
   treasure = 0x16,
   fqOrLegacyId = 0x17, -- (uint8) final quality (normal), boss number (legacy)
   bossLv = 0x18,       -- (uint8) legacy only
   seedOrTurns = 0x1A   -- (uint16) map seed (normal), minimum turns (legacy)
}

-- mult/inc parameters for AT positions
local tbl_param = {
   {2371908317, 2518396845}, -- 13th (environment)
   {2298363417, 639546082},  -- 14th (depth)
   {729943717, 1381971571},  -- 15th (starting monster rank)
   {1601471041, 1695770928}, -- 16th (boss)
   {4009059357, 1588911645}, -- 29th (prefix)
   {1315599961, 2518522002}, -- 30th (suffix)
   {4114186725, 33727075},   -- 31st (locale)
   {2335052929, 1680572000}, -- 32nd (level)

   -- added for battlefield
   {3919841517, 88489753}    -- 33rd (battlefield)
}

local tbl_ascii = {
   {0x00, 0x04, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x4D, 0x53, 0x54, 0x55, 0x58, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x65, 0x66, 0x67, 0x69, 0x6A, 0x6B, 0x6D, 0x6F, 0x71, 0x72, 0x74, 0x76, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xF0, 0xFF},

   {"", "'", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "EUR", ",", ",,", "OE", "oe", "!", "GBP", "<<", ">>", "?", "!", '"', "#", "$", "%", "&", "(", ")", "+", "-", ".", "/", ";", "=", "?", "[", "]", "_", "A", "A", "A", "A", "AE", "C", "E", "E", "E", "E", "I", "I", "I", "I", "N", "O", "O", "O", "O", "O", "U", "U", "U", "U", "ss", "a", "a", "a", "a", "ae", "c", "e", "e", "e", "e", "i", "i", "i", "i", "n", "o", "o", "o", "o", "o", "o", "o", "o", "o", "~", ":-)", "*", "@", "cent", "a", "deg", "<-", "^", "->", "v", "-", " "}
}

local tbl_contents = {
   statusId = {0x09, 0x0A, 0x0C, 0x11, 0x12, 0x14}, -- If a map is currently being followed: +0x20
   statusName = {"New", "Discovered", "Cleared", "New", "Discovered", "Cleared"}, -- Normal/Normal/Normal/Legacy/Legacy/Legacy

   dropId = {0, 1, 3, 5, 7}, -- 1st = +1, 2nd = +2, 3rd = +4
   dropName = {"-/-/-", "1/-/-", "1/2/-", "1/-/3", "1/2/3"},

   legacyName = {"Dragonlord", "Malroth", "Baramos", "Zoma", "Psaro", "Estark", "Nimzo", "Murdaw", "Mortamor", "Nokturnus", "Orgodemir", "Dhoulmagus", "Rhapthorne"},

   rankMin = {2, 56, 61, 76, 81, 101, 121, 141, 161, 181, 201, 221},
   rankMax = {55, 60, 75, 80, 100, 120, 140, 160, 180, 200, 220, 248},

   envMin = {0, 30, 70, 80, 90},
   envMax = {29, 69, 79, 89, 99},
   envName = {"Caves", "Ruins", "Ice", "Water", "Fire"},

   depthMod = {3, 3, 3, 5, 5, 5, 5, 7, 7, 6, 5, 3},
   depthInc = {2, 4, 4, 6, 6, 8, 10, 10, 10, 11, 12, 14},

   smrMod = {3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 2, 1},
   smrInc = {1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 8, 9},

   bossMod = {275, 275, 300, 300, 280, 205, 170, 120, 90, 80, 560, 560},
   bossInc = {0, 0, 100, 100, 200, 275, 350, 400, 450, 480, 0, 0},
   bossMin = {0, 100, 200, 275, 350, 400, 450, 480, 500, 520, 540, 550},
   bossMax = {99, 199, 274, 349, 399, 449, 479, 499, 519, 539, 549, 559},
   bossName = {"Equinox", "Nemean", "Shogum", "Trauminator", "Elusid", "Sir Sanguinus", "Atlas", "Hammibal", "Fowleye", "Excalipurr", "T-Wrecks", "Greygnarl"},

   prefixMod = {5, 5, 5, 5, 6, 6, 10, 10, 5},
   prefixInc = {1, 1, 4, 4, 7, 7, 7, 7, 12},
   prefixName = {"Clay", "Rock", "Granite", "Basalt", "Graphite", "Iron", "Copper", "Bronze", "Steel", "Silver", "Gold", "Platinum", "Ruby", "Emerald", "Sapphire", "Diamond"},

   localeMod = {2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 3},
   localeInc = {1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 4, 6},
   localeName = {"Cave", "Tunnel", "Cave", "Cave", "Cave", "Mine", "Mine", "Crevasse", "Marsh", "Mine", "Lair", "Lair", "Icepit", "Lake", "Crater", "Path", "Path", "Snowhall", "Moor", "Dungeon", "Crypt", "Crypt", "Crypt", "Crypt", "Crypt", "Nest", "Ruins", "Tundra", "Waterway", "Nest", "World", "World", "World", "World", "World", "Abyss", "Maze", "Glacier", "Chasm", "Void"},

   suffixInc = {1, 1, 1, 4, 4, 4, 7, 7, 7, 10, 10, 10},
   suffixName = {"Joy", "Bliss", "Glee", "Doubt", "Woe", "Dolour", "Regret", "Bane", "Fear", "Dread", "Hurt", "Gloom", "Doom", "Evil", "Ruin", "Death"}
}

-- Store globally to only print once
local scriptComplete = false

-- Store outside of replaceBattlefield()
local previousSeed = nil
local id = nil

local function getHex(decimal, digits)
   return decimal and string.format("%0" .. digits .. "X", decimal) or "?"
end

local function lookup(searchKey, searchTbl1, searchTbl2, returnTbl, searchMode)
   for i = 1, #searchTbl1 do
       if (searchMode == "exact" and searchKey == searchTbl1[i]) or
          (searchMode == "range" and searchKey >= searchTbl1[i] and searchKey <= searchTbl2[i]) then
           return {index = i, value = returnTbl[i]}
       end
   end
   return {index = 1, value = "?"}
end

local function maskCurrentMap(statusType)
   local currentMap = 0x20
   return bit.band(statusType, currentMap) == currentMap and statusType - currentMap or statusType
end

local function getAscii(nameBase)
   local ascii = ""
   for i = 0, 9 do
      local char = lookup(memory.readbyte(nameBase + i), tbl_ascii[1], nil, tbl_ascii[2], "exact")
      ascii = ascii..char.value
   end
   return ascii == "" and "?????" or ascii
end

local function getOutput(seed, a, c)
   local hi = bit.rshift(seed, 16)
   local lo = bit.band(seed, 65535) * a + c
   local cr = bit.rshift(lo, 16)
   hi = bit.band(hi * a + cr, 65535)
   return bit.band(hi, 32767)
end

local function getMR(smr, depth)
   if depth >= 13 then return smr.."/"..(smr + 1).."/"..(smr + 2).."/"..(smr + 3)
   elseif depth >= 9 then return smr.."/"..(smr + 1).."/"..(smr + 2)
   elseif depth >= 5 then return smr.."/"..(smr + 1)
   end
   return smr
end

local function getSuffix(rand, bossIndex)
   local mod = 6
   if bossIndex > 9 then mod = 7 end
   local suffixIndex = rand % mod + tbl_contents.suffixInc[bossIndex]
   return tbl_contents.suffixName[suffixIndex]
end

local function getLv(rand, depth, smr, bossIndex)
   local lv = rand % 11 - 5 + (depth + smr + bossIndex - 4) * 3
   if lv < 1 then return 1
   elseif lv > 99 then return 99
   end
   return lv
end

-- added for battlefield
local function getBfIndex(rand)
   return rand % #tbl_assetBattle + 1
end

local function scrapeData()
   if scriptComplete then return end
   scriptComplete = true

   local maps = memory.readbyte(tbl_addr.mapCount)
   if maps > 0 then
      local HEADER_ROW = "#,Status,Discovered by,Conquered by,Drops,Name,Lv,Min Turns,FQ,Rank,Seed,@,Type,Depth,Monster Ranks,Boss,Battlefield ID,Battlefield Description,Link"
      print(HEADER_ROW)

      for i = 1, maps do
         local base = tbl_offset.mapIndex * (i - 1) + tbl_addr.mapBase
         local statusMasked = maskCurrentMap(memory.readbyte(base))
         local status = lookup(statusMasked, tbl_contents.statusId, nil, tbl_contents.statusName, "exact")
         local disc = getAscii(base + tbl_offset.discover)
         local conq = getAscii(base + tbl_offset.conquer)
         local drops = lookup(memory.readbyte(base + tbl_offset.treasure), tbl_contents.dropId, nil, tbl_contents.dropName, "exact")
         local loc = getHex(memory.readbyte(base + tbl_offset.location), 2)
         local finalQualityOrLegacyId = memory.readbyte(base + tbl_offset.fqOrLegacyId)
         local seedTurns = memory.readword(base + tbl_offset.seedOrTurns)
         local LEGACY_NEW = 0x11

         local mapData = i..","..status.value..',"'..disc..'","'..conq..'",'.."'"..drops.value..","

         -- Normal
         if statusMasked < LEGACY_NEW then
            local tbl_output = {}
            for p = 1, 9 do
               tbl_output[p] = getOutput(seedTurns, tbl_param[p][1], tbl_param[p][2])
            end

            local rank = lookup(finalQualityOrLegacyId, tbl_contents.rankMin, tbl_contents.rankMax, tbl_contents.rankMin, "range")
            local environ = lookup(tbl_output[1] % 100, tbl_contents.envMin, tbl_contents.envMax, tbl_contents.envName, "range")
            local depth = tbl_output[2] % tbl_contents.depthMod[rank.index] + tbl_contents.depthInc[rank.index]
            local smr = tbl_output[3] % tbl_contents.smrMod[rank.index] + tbl_contents.smrInc[rank.index]
            local mr = getMR(smr, depth)
            local bossMath = tbl_output[4] % tbl_contents.bossMod[rank.index] + tbl_contents.bossInc[rank.index]
            local boss = lookup(bossMath, tbl_contents.bossMin, tbl_contents.bossMax, tbl_contents.bossName, "range")
            local prefix = tbl_contents.prefixName[tbl_output[5] % tbl_contents.prefixMod[smr] + tbl_contents.prefixInc[smr]]
            local locale = tbl_contents.localeName[(tbl_output[7] % tbl_contents.localeMod[depth - 1] + tbl_contents.localeInc[depth - 1]) * 5 - 5 + environ.index]
            local suffix = getSuffix(tbl_output[6], boss.index)
            local lv = getLv(tbl_output[8], depth, smr, boss.index)

            local rankHex = getHex(rank.value, 2)
            local seedHex = getHex(seedTurns, 4)
            local YAB_LINK = "https://www.yabd.org/apps/dq9/grottodetails.php?map=" -- Append rank and seed

            -- added for battlefield
            local bfIndex = getBfIndex(tbl_output[9])
            local bfId = getHex(tbl_assetBattle[bfIndex][1], 4)
            local bfDesc = tbl_assetBattle[bfIndex][2]
            
            mapData = mapData..prefix.." "..locale.." "..suffix..","..lv..",-,"..finalQualityOrLegacyId..",'"..rankHex..",'"..seedHex..",'"..loc..","..environ.value..",B"..depth..",'"..mr..","..boss.value..",'"..bfId..',"'..bfDesc..'",'..YAB_LINK..rankHex..seedHex

         -- Legacy
         elseif statusMasked >= LEGACY_NEW then
            local legacy = tbl_contents.legacyName[finalQualityOrLegacyId]
            local lv = memory.readbyte(base + tbl_offset.bossLv)
            mapData = mapData..legacy.."'s Map,"..lv..","..seedTurns..",-,-,-,'"..loc..",Legacy,-,-,"..legacy..",-,-,-"
         end
         print(mapData)
         mapData = nil
      end
   end
end

local function replaceBattlefield()
   local mapType = memory.readbyte(tbl_addr.currentType)

   -- 1 = inside a normal grotto
   if mapType == 1 then
      local inBattle = memory.readbyte(tbl_addr.battleFlag)
      local mapSeed = memory.readword(tbl_addr.currentSeed)

      if mapSeed ~= previousSeed then
         local current33rd = getOutput(mapSeed, tbl_param[9][1], tbl_param[9][2])
         local battlefieldIndex = getBfIndex(current33rd)
         id = tbl_assetBattle[battlefieldIndex][1]
         previousSeed = mapSeed
      end

      -- 1 = battle triggered
      if inBattle == 1 then
         memory.writeword(tbl_addr.battlefield, id)
      end
   end
end

memory.registerread(tbl_addr.mapBase, scrapeData) 

gui.register(replaceBattlefield)