Advertisement
Guest User

Untitled

a guest
Feb 8th, 2020
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.46 KB | None | 0 0
  1. -- For use with SNES9X-RR (File => Lua Scripting) and FF6 T-Edition
  2. -- Creates <ff6_t_rage_order.ips> inside this .lua file's folder
  3.  
  4. -- for player customization
  5. -- specify rages (by EXACT name) in the order you want it at the top
  6. -- if you don't want any then set this to {}
  7. -- if you want some set it like { "Thor", "Cheshire" }
  8. local priorityOrder = { }
  9.  
  10. -- change these if necessary
  11. local offsetMonsterNames = 0xCFC400
  12. local nameLength = 8
  13.  
  14.  
  15. -- don't touch below unless necessary
  16. local offsetRageTable = 0xC26600
  17. local monsterCount = 0x1FF -- idk why this is here it doesn't matter
  18. local rageCount = 0xFE -- last one is FF, leave at 1 less than rage count (since 0 is a rage)
  19. local rageTable = memory.readbyterange(offsetRageTable,rageCount)
  20.  
  21.  
  22. -- don't touch below
  23. local monsterNames = {} -- stores only names for sorting
  24. local monsterNameIDs = {} -- matches names to id so we can re-write the id order
  25.  
  26. local textMap = {
  27.     [0x60] = "A", [0x61] = "B", [0x62] = "C", [0x63] = "D", [0x64] = "E", [0x65] = "F", [0x66] = "G", [0x67] = "H", [0x68] = "I", [0x69] = "J",
  28.     [0x6A] = "K", [0x6B] = "L", [0x6C] = "M", [0x6D] = "N", [0x6E] = "O", [0x6F] = "P", [0x70] = "Q", [0x71] = "R", [0x72] = "S", [0x73] = "T",
  29.     [0x74] = "U", [0x75] = "V", [0x76] = "W", [0x77] = "X", [0x78] = "Y", [0x79] = "Z",
  30.     [0x7A] = "a", [0x7B] = "b", [0x7C] = "c", [0x7D] = "d", [0x7E] = "e", [0x7F] = "f", [0x80] = "g", [0x81] = "h", [0x82] = "i", [0x83] = "j",
  31.     [0x84] = "k", [0x85] = "l", [0x86] = "m", [0x87] = "n", [0x88] = "o", [0x89] = "p", [0x8A] = "q", [0x8B] = "r", [0x8C] = "s", [0x8D] = "t",
  32.     [0x8E] = "u", [0x8F] = "v", [0x90] = "w", [0x91] = "x", [0x92] = "y", [0x93] = "z",
  33.     [0x53] = "0", [0x54] = "1", [0x55] = "2", [0x56] = "3", [0x57] = "4", [0x58] = "5", [0x59] = "6", [0x5A] = "7", [0x5B] = "8", [0x5C] = "9",
  34.     [0x94] = "!", [0x95] = "?", [0x97] = "'", [0x98] = "-", [0x99] = ".", [0xFF] = " ",
  35. }
  36. function translateString(t)
  37.     local s = ""
  38.     for i=1,#t do
  39.         s = s .. (textMap[t[i]] or "?")
  40.     end
  41.     s = trim(s)
  42.     return s
  43. end
  44. function trim(out) return (out:gsub("^%s*(.-)%s*$", "%1")) end
  45.  
  46. local priorityReverse = {}
  47. for i,v in pairs(priorityOrder) do
  48.     priorityReverse[v] = i
  49.    
  50. end
  51. for i=0,rageCount do
  52.     local name = memory.readbyterange(offsetMonsterNames + (i*nameLength),nameLength)
  53.     name = translateString(name)
  54.     if (not priorityReverse[name]) then
  55.         monsterNameIDs[name] = i
  56.         monsterNames[#monsterNames + 1] = name
  57.     else
  58.         priorityOrder[priorityReverse[name]] = i
  59.     end
  60.     --print(string.format("%02x: %s",i,name)) -- uncomment to view each hex/name
  61. end
  62.  
  63. table.sort(monsterNames)
  64. local hexMapOut = ""
  65. for i=1,#monsterNames do
  66.     hexMapOut = hexMapOut .. string.format("%02x",monsterNameIDs[monsterNames[i]]) .. " "
  67. end
  68. if (#priorityOrder > 0) then print("If you get an error here, it means one of your monster names was invalid.") end
  69. for i=#priorityOrder,1,-1 do
  70.     if (type(priorityOrder[i]) == "string") then print("Problematic custom monster: "..priorityOrder[i]) end
  71.     hexMapOut = string.format("%02x",priorityOrder[i]) .. " " .. hexMapOut
  72. end
  73. hexMapOut = hexMapOut .. "FF " -- drop in the tonberries/nonexistent one last
  74. hexMapOut = hexMapOut:upper()
  75. hexMapOut = trim(hexMapOut)
  76.  
  77. function string.split(input, sep)
  78.     sep = sep or "%s"
  79.     local t = {}
  80.     for str in string.gmatch(input, "([^"..sep.."]+)") do table.insert(t, str) end
  81.     return t
  82. end
  83. local t = hexMapOut:split(" ")
  84. t[256] = nil
  85. local s = ""
  86. for i,v in pairs(t) do t[i] = tonumber(t[i],16) end
  87. s = string.char(unpack(t))
  88. local offset = {}
  89. offsetRageTable = offsetRageTable - 0xC00000
  90. offset[1] = bit.band(offsetRageTable,0xFF0000) / 0x10000
  91. offset[2] = bit.band(offsetRageTable,0x00FF00) / 0x100
  92. offset[3] = bit.band(offsetRageTable,0x0000FF)
  93. local length = rageCount + 1
  94. length = { bit.band(length,0xFF00) / 0x100, bit.band(length,0x00FF) }
  95. s = "PATCH"..string.char(offset[1])..string.char(offset[2])..string.char(offset[3])..string.char(length[1])..string.char(length[2])..s.."EOF"
  96.  
  97. file = io.open("ff6_t_rage_order.ips", "wb")
  98. file:write(s)
  99. file:close()
  100.  
  101. print(hexMapOut)
  102. print("")
  103. 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)))
  104. print("")
  105. 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