Advertisement
Guest User

boom-plus-dx.lua

a guest
Jul 21st, 2017
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.82 KB | None | 0 0
  1.  
  2.  
  3. -- Amount of frames to allow rewinding
  4. -- Higher == MORE MEMORY INTENSIVE.
  5. -- Don't set this too high or else
  6. rewindMax   = 2000;
  7.  
  8.  
  9. keyBindings = {
  10.     rewind  = "W",  -- rewind button (important)
  11.  
  12.     ramrnd  = "E",  -- FF0000-FFFFFF 100 times random words
  13.     raminc  = "R",  -- FF0000-FFFFFF "" times +/- 1
  14.     ramxrnd = "T",  -- FF0000-FFFFFF 10000 times random bytes
  15.     ramxinc = "Y",  -- FF0000-FFFFFF "" times +/- 1
  16.     ramnul  = "U",  -- FF0000-FFFFFF "" Null
  17. -- Note: There is no lua Game genie support on Gens-rr.
  18.     ggadd   = "G",  -- Game genie code add (random)
  19.     ggdel   = "H",  -- Game genie code del (random)
  20.     ramswap = "U",  -- Game genie code del (random)
  21.     extswap = "I",  -- Game genie code del (random)
  22.     showHUD = "L",  -- Toggle corruption HUD
  23. }
  24.  
  25.  
  26. -- -------------------------------- --
  27. -- Nonconfigurable stuff below here --
  28. -- -------------------------------- --
  29.  
  30.  
  31.  
  32.  
  33. function math.round(num, idp)
  34.     local mult = 10^(idp or 0)
  35.     if num >= 0 then return math.floor(num * mult + 0.5) / mult
  36.     else return math.ceil(num * mult - 0.5) / mult end
  37. end
  38.  
  39.  
  40.  
  41. function corruptWord(rangeLow, rangeHigh, inc, times)
  42.     if times then
  43.         local word  = math.random(rangeLow, rangeHigh)
  44.         local value = math.random(0x0000, 0xFFFF)
  45.         if inc then
  46.             value   = memory.readword(word) - 1 + (math.random(0, 1) * 2)
  47.         end
  48.  
  49.         memory.writeword(word, value)
  50.  
  51.         corruptWords    = corruptWords + 1
  52.         times = times - 1
  53.     end
  54. end
  55.  
  56. function corruptWordVal(rangeLow, rangeHigh, inc, times, val)
  57.     if times then
  58.         local word = math.random(rangeLow, rangeHigh)
  59.         --while (word < 0xFF0200 or word > 0xFF0300) do
  60.         while (word > 0xFF0100 and word < 0xFF3000) do
  61.             word = math.random(rangeLow, rangeHigh)
  62.         end
  63.        
  64.         local value = val
  65.         if inc then
  66.             value   = val
  67.         end
  68.  
  69.         memory.writeword(word, value)
  70.         print (string.format("%06X -> %04X", word, value))
  71.  
  72.         corruptWords    = corruptWords + 1
  73.         times = times - 1
  74.     end
  75. end
  76.  
  77.  
  78.  
  79.  
  80. function swapWords(rangeLow, rangeHigh)
  81.  
  82.     local word1 = math.random(rangeLow + 1, rangeHigh - 1)
  83.     local word2 = word1 - 1 + (math.random(0, 1) * 2)
  84.  
  85.     local   word1val    = memory.readword(word1)
  86.     local   word2val    = memory.readword(word2)
  87.     memory.writeword(word1, word2val)
  88.     memory.writeword(word2, word1val)
  89.  
  90.     corruptWords    = corruptWords + 1
  91. end
  92.  
  93.  
  94.  
  95. function statusLights(x, y, flags)
  96.  
  97.     x   = x + 10;
  98.  
  99.     gui.box(x - 10, y, x + 28, y + 8, "#000000a0", "#000000a0")
  100.     gui.text(x -  9, y + 1, "C", table.getn(gameGenieCodes) > 0 and "white" or "gray", "clear")
  101.     gui.text(x -  1, y + 1, "R", flags['ramrnd'] and "white" or "gray", "clear")
  102.     gui.text(x +  8, y + 1, "A", flags['raminc'] and "white" or "gray", "clear")
  103.     gui.text(x + 15, y + 1, "B", flags['ramxrnd'] and "white" or "gray", "clear")
  104.     gui.text(x + 23, y + 1, "S", flags['ramxinc'] and "white" or "gray", "clear")
  105.  
  106.     if ggtimer > -120 then
  107.         if table.getn(gameGenieCodes) > 0 then
  108.             gui.box(x - 10, y + 9, x + 28, y + 10 + 8 * table.getn(gameGenieCodes), "#000000a0", "#000000a0")
  109.         end
  110.         for i, v in ipairs(gameGenieCodes) do
  111.             gui.text(x - 9, y + 3 + 8 * i, v, "white", "clear")
  112.         end
  113.     end
  114.  
  115. end
  116.  
  117.  
  118. function randomGameGenieCode()
  119.    
  120. --  local ggLetters = 'AEPOZXLUGKISTVYN'
  121.     local ggLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
  122.     local ret       = ''
  123.     for j = 1, 2 do
  124.         for i = 1, 4 do
  125.             local letter    = math.random(1, 36)
  126.             ret         = ret .. ggLetters:sub(letter, letter)
  127.         end
  128.         if j == 1 then
  129.             ret = ret .. '-'
  130.         end
  131.     end
  132.     return ret
  133.  
  134. end
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. function rewindArrow(x, y, v, max, rewinding)
  142.  
  143.     local rwx   = x;
  144.     local rwy   = y;
  145.  
  146.     local pct   = math.min(math.max(0, v / max), 1)
  147.  
  148.     gui.box(x + 0, y + 2, x + 31, y + 6, "#000000b0", "black")
  149.  
  150.     local barsize   = math.round(pct * 30);
  151.     local color     = "#9999ff"
  152.     if pct < 0.25 then
  153.         color   = "red"
  154.     end
  155.     if barsize > 0 then
  156.         gui.box(x + 1, y + 3, x + 0 + barsize, y + 5, color, color)
  157.     end
  158.  
  159.     rwx = rwx + 7
  160.  
  161.     if rewinding and v == 0 then
  162.         gui.box(rwx + 4, rwy - 4, rwx + 8, rwy + 4, "white", "black")
  163.         gui.box(rwx + 10, rwy - 4, rwx + 14, rwy + 4, "white", "black")
  164.     elseif rewinding then
  165.         for rw = -1, 7 do
  166.             gui.line(rwx +  0 + rw, rwy - 1 - math.floor(rw / 2), rwx +  0 + rw, rwy + 1 + math.floor(rw / 2), "black");
  167.             gui.line(rwx +  1 + rw, rwy - 1 - math.floor(rw / 2), rwx +  1 + rw, rwy + 1 + math.floor(rw / 2), "black");
  168.             gui.line(rwx +  9 + rw, rwy - 1 - math.floor(rw / 2), rwx +  9 + rw, rwy + 1 + math.floor(rw / 2), "black");
  169.             gui.line(rwx + 10 + rw, rwy - 1 - math.floor(rw / 2), rwx + 10 + rw, rwy + 1 + math.floor(rw / 2), "black");
  170.  
  171.             if rw >= 0 then
  172.                 gui.line(rwx + 0 + rw, rwy - math.floor(rw / 2), rwx + 0 + rw, rwy + math.floor(rw / 2), "white");
  173.                 gui.line(rwx + 9 + rw, rwy - math.floor(rw / 2), rwx + 9 + rw, rwy + math.floor(rw / 2), "white");
  174.             end
  175.         end;
  176.     else
  177.         for rw = 0, 8 do
  178.             gui.line(rwx +  5 + rw, rwy - 1 - math.floor((7 - rw) / 2), rwx +  5 + rw, rwy + 1 + math.floor((7 - rw) / 2), "black");
  179.             gui.line(rwx +  6 + rw, rwy - 1 - math.floor((7 - rw) / 2), rwx +  6 + rw, rwy + 1 + math.floor((7 - rw) / 2), "black");
  180.  
  181.             if rw >= 1 then
  182.                 gui.line(rwx + 5 + rw, rwy - math.ceil((7 - rw) / 2), rwx + 5 + rw, rwy + math.ceil((7 - rw) / 2), "white");
  183.             end
  184.         end;
  185.  
  186.  
  187.     end
  188.  
  189.  
  190. end
  191.  
  192.  
  193. corruptWords    = 0
  194. timer           = 0
  195. inpt            = {}
  196. inpto           = {}
  197. gameGenieCodes  = {}
  198. saveStates      = {}
  199. saveIndex       = 0
  200. saveIndexMin    = 0
  201. ggtimer         = 0
  202. showHUD         = true
  203.  
  204. while true do
  205.  
  206.     inpto   = inpt;
  207.     inpt    = input.get()
  208.  
  209.     local rewinding = false
  210.     if inpt[keyBindings['rewind']] then
  211.         rewinding   = true
  212.     end
  213.  
  214.     if inpt[keyBindings['rewind']] and saveStates[saveIndex] then
  215.         savestate.load(saveStates[saveIndex])
  216.         if saveStates[saveIndex - 1] then
  217.             saveIndex   = saveIndex - 1
  218.         else
  219.             saveIndexMin    = saveIndex;
  220.         end
  221.     else
  222.  
  223.         local save = savestate.create()
  224.         savestate.save(save)
  225.         saveIndexMin        = math.max(saveIndexMin, saveIndex - rewindMax)
  226.         saveIndex           = saveIndex + 1
  227.         saveStates[saveIndex] = save
  228.         saveStates[saveIndexMin]    = nil
  229.     end
  230.  
  231.  
  232.  
  233.  
  234.  
  235.     local corruptionFlag    = {
  236.         ramrnd  = false,
  237.         raminc  = false,
  238.         ramxrnd = false,
  239.         ramxinc = false,
  240.     }
  241.  
  242.  
  243.  
  244.     if inpt[keyBindings['ramrnd']] then
  245.         corruptWord(0xFF0000, 0xFFFFFF, false, 100)
  246.         corruptionFlag['ramrnd']    = true;
  247.     end
  248.     if inpt[keyBindings['raminc']] then
  249.         corruptWord(0xFF0000, 0xFFFFFF, true, 100)
  250.         corruptionFlag['raminc']    = true;
  251.     end
  252.     if inpt[keyBindings['ramxrnd']] then
  253.         corruptWord(0xFF0000, 0xFF0FFF, false, 10000)
  254.         corruptionFlag['ramxrnd']   = true;
  255.     end
  256.     if inpt[keyBindings['ramxinc']] then
  257.         corruptWord(0xFF0000, 0xFFFFFF, true, 10000)
  258.         corruptionFlag['ramxinc']   = true;
  259.     end
  260.     if inpt[keyBindings['ramnul']] then
  261.         --corruptWordVal(0xFF3200, 0xFF32FF, false, 100, 0)
  262.         corruptWordVal(0xFF0000, 0xFF5FFF, false, 100, 1)
  263.         corruptionFlag['ramrnd']    = true;
  264.     end
  265.  
  266.     if inpt[keyBindings['ramswap']] then
  267.         swapWords(0xFF0000, 0xFFFFFF)
  268.         corruptionFlag['ramrnd']    = true;
  269.     end
  270.     if inpt[keyBindings['extswap']] then
  271.         swapWords(0xFF0000, 0xFFFFFF)
  272.         corruptionFlag['raminc']    = true;
  273.     end
  274.  
  275.  
  276.     if inpt[keyBindings['ggadd']] and math.fmod(math.max(0, ggtimer), 6) == 0 then
  277.         local code  = randomGameGenieCode()
  278. --      emu.addgamegenie(code)
  279.         table.insert(gameGenieCodes, code)
  280.     end
  281.  
  282.     if inpt[keyBindings['ggdel']] and math.fmod(math.max(0, ggtimer), 6) == 0 then
  283.         if table.getn(gameGenieCodes) > 0 then
  284. --          emu.delgamegenie(gameGenieCodes[table.getn(gameGenieCodes)])
  285.             table.remove(gameGenieCodes)
  286.         end
  287.     end
  288.  
  289.  
  290.     if inpt[keyBindings['ggadd']] or inpt[keyBindings['ggdel']] then
  291.         ggtimer = math.max(1, ggtimer + 1)
  292.     else
  293.         ggtimer = math.min(0, ggtimer - 1)
  294.     end
  295.  
  296.  
  297.     if inpt[keyBindings['showHUD']] and not inpto[keyBindings['showHUD']] then
  298.         showHUD = not showHUD
  299.     end
  300.  
  301.  
  302.  
  303.     if showHUD then
  304.         rewindArrow(280, 210, saveIndex - saveIndexMin, rewindMax, rewinding);
  305.         statusLights( 0, 0, corruptionFlag)
  306.     end
  307.  
  308.  
  309.     timer   = timer + 1
  310.     emu.frameadvance()
  311.  
  312. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement