Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- For use with SNES9X-RR (File => Lua Scripting) and FF6 T-Edition
- -- Creates <ff6_t_rage_order.ips> inside this .lua file's folder
- -- for player customization
- -- specify rages (by EXACT name) in the order you want it at the top
- -- if you don't want any then set this to {}
- -- if you want some set it like { "Thor", "Cheshire" }
- local priorityOrder = { }
- -- change these if necessary
- local offsetMonsterNames = 0xCFC400
- local nameLength = 8
- -- don't touch below unless necessary
- local offsetRageTable = 0xC26600
- local monsterCount = 0x1FF -- idk why this is here it doesn't matter
- local rageCount = 0xFE -- last one is FF, leave at 1 less than rage count (since 0 is a rage)
- local rageTable = memory.readbyterange(offsetRageTable,rageCount)
- -- don't touch below
- local monsterNames = {} -- stores only names for sorting
- local monsterNameIDs = {} -- matches names to id so we can re-write the id order
- local textMap = {
- [0x60] = "A", [0x61] = "B", [0x62] = "C", [0x63] = "D", [0x64] = "E", [0x65] = "F", [0x66] = "G", [0x67] = "H", [0x68] = "I", [0x69] = "J",
- [0x6A] = "K", [0x6B] = "L", [0x6C] = "M", [0x6D] = "N", [0x6E] = "O", [0x6F] = "P", [0x70] = "Q", [0x71] = "R", [0x72] = "S", [0x73] = "T",
- [0x74] = "U", [0x75] = "V", [0x76] = "W", [0x77] = "X", [0x78] = "Y", [0x79] = "Z",
- [0x7A] = "a", [0x7B] = "b", [0x7C] = "c", [0x7D] = "d", [0x7E] = "e", [0x7F] = "f", [0x80] = "g", [0x81] = "h", [0x82] = "i", [0x83] = "j",
- [0x84] = "k", [0x85] = "l", [0x86] = "m", [0x87] = "n", [0x88] = "o", [0x89] = "p", [0x8A] = "q", [0x8B] = "r", [0x8C] = "s", [0x8D] = "t",
- [0x8E] = "u", [0x8F] = "v", [0x90] = "w", [0x91] = "x", [0x92] = "y", [0x93] = "z",
- [0x53] = "0", [0x54] = "1", [0x55] = "2", [0x56] = "3", [0x57] = "4", [0x58] = "5", [0x59] = "6", [0x5A] = "7", [0x5B] = "8", [0x5C] = "9",
- [0x94] = "!", [0x95] = "?", [0x97] = "'", [0x98] = "-", [0x99] = ".", [0xFF] = " ",
- }
- function translateString(t)
- local s = ""
- for i=1,#t do
- s = s .. (textMap[t[i]] or "?")
- end
- s = trim(s)
- return s
- end
- function trim(out) return (out:gsub("^%s*(.-)%s*$", "%1")) end
- local priorityReverse = {}
- for i,v in pairs(priorityOrder) do
- priorityReverse[v] = i
- end
- for i=0,rageCount do
- local name = memory.readbyterange(offsetMonsterNames + (i*nameLength),nameLength)
- name = translateString(name)
- if (not priorityReverse[name]) then
- monsterNameIDs[name] = i
- monsterNames[#monsterNames + 1] = name
- else
- priorityOrder[priorityReverse[name]] = i
- end
- --print(string.format("%02x: %s",i,name)) -- uncomment to view each hex/name
- end
- table.sort(monsterNames)
- local hexMapOut = ""
- for i=1,#monsterNames do
- hexMapOut = hexMapOut .. string.format("%02x",monsterNameIDs[monsterNames[i]]) .. " "
- end
- if (#priorityOrder > 0) then print("If you get an error here, it means one of your monster names was invalid.") end
- for i=#priorityOrder,1,-1 do
- if (type(priorityOrder[i]) == "string") then print("Problematic custom monster: "..priorityOrder[i]) end
- hexMapOut = string.format("%02x",priorityOrder[i]) .. " " .. hexMapOut
- end
- hexMapOut = hexMapOut .. "FF " -- drop in the tonberries/nonexistent one last
- hexMapOut = hexMapOut:upper()
- hexMapOut = trim(hexMapOut)
- function string.split(input, sep)
- sep = sep or "%s"
- local t = {}
- for str in string.gmatch(input, "([^"..sep.."]+)") do table.insert(t, str) end
- return t
- end
- local t = hexMapOut:split(" ")
- t[256] = nil
- local s = ""
- for i,v in pairs(t) do t[i] = tonumber(t[i],16) end
- s = string.char(unpack(t))
- local offset = {}
- offsetRageTable = offsetRageTable - 0xC00000
- offset[1] = bit.band(offsetRageTable,0xFF0000) / 0x10000
- offset[2] = bit.band(offsetRageTable,0x00FF00) / 0x100
- offset[3] = bit.band(offsetRageTable,0x0000FF)
- local length = rageCount + 1
- length = { bit.band(length,0xFF00) / 0x100, bit.band(length,0x00FF) }
- s = "PATCH"..string.char(offset[1])..string.char(offset[2])..string.char(offset[3])..string.char(length[1])..string.char(length[2])..s.."EOF"
- file = io.open("ff6_t_rage_order.ips", "wb")
- file:write(s)
- file:close()
- print(hexMapOut)
- print("")
- print(string.format("DEBUG INFO: Hex table inside ips shown above, replace at 0x%0x~0x%0x (ends in FF, 0x%0x should be 20).",offsetRageTable,(offsetRageTable + rageCount + 1),(offsetRageTable + rageCount + 2)))
- print("")
- print("ff6_t_rage_order.ips saved to file, apply to rom to sort your rages (ignore above if you're not a dev)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement