User File #638546307652060831

Upload All User Files

#638546307652060831 - [DQ9] A-Table Interface V2

DQ9_ATI_v2.lua
4 downloads
Uploaded 5 days ago by TKG (see all 6)
Written by TKG
How to Use:
- Hit L + R to toggle the view on/off
- Hit Start to restart tracking
Display:
- AT: current 32bit AT address in hexadecimal (NA: 0x020EEF30, JP: 0x020EEE90)
- OUT: current 15bit output in decimal
- POS: current position (up to 999)
- MAP: current position for map methods (up to 1032)
- PRE: deftness required for preemptive on the next position (+1)
- AMB: Y/N for ambush on the next position (+2)
- COM: common drop (+2)
- RAR: rare drop (+1)
-- Written by TKG

-- How to Use:
-- Hit L + R to toggle the view on/off
-- Hit Start to restart tracking

-- Display:
-- AT: current 32bit AT address in hexadecimal (NA: 0x020EEF30, JP: 0x020EEE90)
-- OUT: current 15bit output in decimal
-- POS: current position (up to 999)
-- MAP: current position for map methods (up to 1032)
-- PRE: deftness required for preemptive on the next position (+1)
-- AMB: Y/N for ambush on the next position (+2)
-- COM: common drop (+2)
-- RAR: rare drop (+1)

local startCount = 0
local triggerCount = 0
local LRToggle = true
local ATable = {}
local inputs = {}

local function getHex(decimal, digits)
   if digits == 4 then return string.format("%04X", decimal)
   elseif digits == 8 then return string.format("%08X", decimal)
   end
end

local function ATRand(currentSeed)
   local hi = bit.rshift(currentSeed, 16)
   local lo = (bit.band(currentSeed, 65535)) * 1103515245 + 12345
   local cr = bit.rshift(lo, 16)
   lo = bit.band(lo, 65535)
   hi = bit.band(hi * 1103515245 + cr, 65535)
   return bit.bor(bit.lshift(hi, 16), lo)
end

local function getOutput(ATValue)
   return bit.band(bit.rshift(ATValue, 16), 32767)
end

local function getDeftness(output)
   local deftness = math.ceil(output / 32768 * 100 - 2) * 20
   if deftness % 20 ~= 0 then
      deftness = math.ceil(deftness / 20) * 20
   end
   if deftness > 999 then
      return "-"
   elseif deftness < 1 then
      return 0
   else
      return deftness
   end
end

local function getDropChance(output)
   local itemRange = {4096, 2048, 1024, 512, 256, 128, 0}
   local itemChance = {"-", "1/8", "1/16", "1/32", "1/64", "1/128", "1/256"}
   for i = 1, 7 do
      if output >= itemRange[i] then
         return itemChance[i]
      end
   end
end

local function renderGUI(at, out, pos, map, pre, amb, commonDrop, rareDrop)
   local guiElements = {
      {5, -188, " AT " .. at, "white", "clear"},
      {5, -178, "0UT " .. out, "white", "clear"},
      {87, -188, "P0S " .. pos, "cyan", "clear"},
      {87, -178, "MAP " .. map, "cyan", "clear"},
      {145, -188, "PRE " .. pre, "magenta", "clear"},
      {145, -178, "AMB " .. amb, "magenta", "clear"},
      {196, -188, "C0M " .. commonDrop, "yellow", "clear"},
      {196, -178, "RAR " .. rareDrop, "yellow", "clear"}
   }

   gui.box(0, -192, 256, -168, "#000000C0", "#000000C0")
   for k, element in ipairs(guiElements) do
      gui.text(element[1], element[2], element[3], element[4], element[5])
   end
end

local function main()

   local seed = memory.readdword(0x020EEF30)
   local at = getHex(seed, 8)
   local out = getOutput(seed)

   inputs = joypad.get(1)
   startCount = inputs.start and startCount + 1 or 0

   if startCount == 1 then
      ATable[0] = seed
      for i = 1, 999 do
         ATable[i] = ATRand(ATable[i-1])
      end
   end

   local pos = "-"
   local map = "-"
   for p, v in pairs(ATable) do
      if getHex(v, 8) == at then
         pos = p
         map = p + 33
         break
      end
   end

   local amb = "N"
   local pos1 = ATRand(seed)
   local pos2 = ATRand(pos1)
   local pos1out = getOutput(pos1)
   local pos2out = getOutput(pos2)
   local rareDrop = getDropChance(pos1out)
   local commonDrop = getDropChance(pos2out)
   local pre = getDeftness(pos1out)
   if pos2out <= 655 then amb = "Y" end

   if inputs.L and inputs.R then
      triggerCount = triggerCount + 1
      if triggerCount == 1 then
         LRToggle = not LRToggle
      end
   else
      triggerCount = 0
   end

   if LRToggle then
      renderGUI(at, out, pos, map, pre, amb, commonDrop, rareDrop)
   end

end

gui.register(main)