User File #638325093620916692

Upload All User Files

#638325093620916692 - [DQ9] A-Table Interface for DeSmuME (JP) v1

DQ9_ATI_JP_itemdrop.lua
76 downloads
Uploaded 10/10/2023 4:36 AM by TKG (see all 6)
How to Use:
  • Press L+R to toggle the visibility on/off
  • press Start to set the current AT value as the current position (0/33)
  • Press Start to clear the table
Seed:
  • shows current AT value in hex (32bit)
Pos:
  • "0/33": position 0 for general purpose and 33 for map methods
  • Follows position up to 999/1032
  • Turns yellow and orange as position reaches max (like HP)
  • "N/A": position is out of range
  • "RESET": the table for the previous seed is cleared
Drop:
buttonCount, togCount, shoulderCount = 0
startToggle, LRToggle = false
pos = 33
a = {}

DQdgry = "#313131"
DQgrn = "#52C618"
DQora = "#FF7331"
DQyel = "#FFC600"
DQred = "#FF0808"
ATgrn = "#00C000"
ATcya = "#00C0C0"
ATmag = "#C000C0"
nofill = "#00000000"
DQxmenu = "#000000B0"
DQtmenu = "#4A3921"

function getMainScreen()
   screen = false
	if bit.band(0x8000, memory.readword(0x4000304)) > 0 then
		screen = true
   end
   return screen
end

function mapmenu()
   isOpen = false
   if memory.readdword(0x020F9558) > 0 then
      isOpen = true
   end
   return isOpen
end

function tablecontains(table, value)
   found = false
   for k, v in pairs(table) do
      if v == value then found = true end
   end
   return found
end

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

function itemdrop(rand)
   rand = bit.band(bit.rshift(rand, 16), 32767)
   if rand <= 128 then return "1/256", "white", nofill
   elseif rand <= 256 then return "1/128", DQred, nofill
   elseif rand <= 512 then return "1/64", ATmag, nofill
   elseif rand <= 1024 then return "1/32", DQgrn, nofill
   elseif rand <= 2048 then return "1/16", ATcya, nofill
   elseif rand <= 4096 then return "1/8", DQyel, nofill
   else return ""
   end
end

function main()

   seed = memory.readdword(0x020EEE90)
   at = string.format("%08X", seed)
   --gui.text(2, -189, string.format("%.2f", 100*bit.band(bit.rshift(seed, 16), 0x7FFF)/32768) .. "%") --for percentage
   rand = dq9_rand(seed)

   buttonInput = bit.band(memory.readbyte(0x04000130), 0x8)

   if buttonInput == 0 then
      buttonCount = buttonCount + 1
      if buttonCount == 1 then startToggle = not startToggle end
   else
      buttonCount = 0
   end

   if startToggle then
      togCount = togCount + 1

      if togCount == 1 then

         a[pos] = at
         pos = pos + 1
         a[pos] = string.format("%08X", rand)

         for i = 35, 1032 do
            pos = pos + 1
            rand = dq9_rand(rand)
            string = string.format("%08X", rand)
            a[pos] = string
         end

      end

      if tablecontains(a, at) == true then
         for k, v in pairs(a) do
            if at == v then

               if k >= 952 then
                  colour = DQora
               elseif k >= 782 then
                  colour = DQyel
               else
                  colour = "white"
               end

               status = k - 33 .. "/" .. k
            end
         end
      else
         status = "N/A"
         colour = DQred
      end

   else
      pos = 33
      togCount = 0
      status = "RESET"
      colour = DQgrn

      for k in pairs(a) do
         a[k] = nil
      end

   end

   shoulderInput = memory.readbyte(0x04000131)

   if shoulderInput == 0 then
      shoulderCount = shoulderCount + 1
      if shoulderCount == 1 then LRToggle = not LRToggle end
   else
      shoulderCount = 0
   end

   if LRToggle then

      topscreen = getMainScreen()
      menuopen = mapmenu()

      x1, y1 = 8, 148
      fill = DQxmenu

      if menuopen == true then
         x1, y1 = 8, 7
         fill = DQtmenu
      elseif topscreen == true then
         x1, y1 = 163, -190
      end

      x2, y2 = x1 + 89, y1 + 34

      gui.box(x1, y1, x2, y2, fill, nofill)
      gui.line(x1, y1 + 2, x1, y2 - 2, "white") --L
      gui.line(x2, y1 + 2, x2, y2 - 2, "white") --R
      gui.line(x1 + 2, y1, x2 - 2, y1, "white") --T
      gui.line(x1 + 2, y2, x2 - 2, y2, "white") --B

      gui.pixel(x1 + 1, y1 + 1, "white") --TL
      gui.pixel(x2 - 1, y1 + 1, "white") --TR
      gui.pixel(x1 + 1, y2 - 1, "white") --BL
      gui.pixel(x2 - 1, y2 - 1, "white") --BR

      gui.line(x1 + 3, y2 + 1, x2 - 2, y2 + 1, DQdgry) --shadow B
      gui.line(x2 + 1, y1 + 3, x2 + 1, y2 - 2, DQdgry) --shadow R
      gui.pixel(x2 - 1, y2, DQdgry) --shadow BL
      gui.pixel(x2, y2 - 1, DQdgry) --shadow TR

      gui.text(x1 + 3, y1 + 4, "Seed: " .. at, "white", nofill)
      gui.text(x1 + 3, y1 + 14, " Pos: ", "white", nofill)
      gui.text(x1 + 39, y1 + 14, status, colour, nofill)
      gui.text(x1 + 3, y1 + 24, "Drop:", "white", nofill)
      gui.text(x1 + 39, y1 + 24, itemdrop(rand))

   end

end

gui.register(main)