Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Amount of frames to allow rewinding
- -- Higher == MORE MEMORY INTENSIVE.
- -- Don't set this too high or else
- rewindMax = 2000;
- keyBindings = {
- rewind = "W", -- rewind button (important)
- ramrnd = "E", -- FF0000-FFFFFF 100 times random words
- raminc = "R", -- FF0000-FFFFFF "" times +/- 1
- ramxrnd = "T", -- FF0000-FFFFFF 10000 times random bytes
- ramxinc = "Y", -- FF0000-FFFFFF "" times +/- 1
- ramnul = "U", -- FF0000-FFFFFF "" Null
- -- Note: There is no lua Game genie support on Gens-rr.
- ggadd = "G", -- Game genie code add (random)
- ggdel = "H", -- Game genie code del (random)
- ramswap = "U", -- Game genie code del (random)
- extswap = "I", -- Game genie code del (random)
- showHUD = "L", -- Toggle corruption HUD
- }
- -- -------------------------------- --
- -- Nonconfigurable stuff below here --
- -- -------------------------------- --
- function math.round(num, idp)
- local mult = 10^(idp or 0)
- if num >= 0 then return math.floor(num * mult + 0.5) / mult
- else return math.ceil(num * mult - 0.5) / mult end
- end
- function corruptWord(rangeLow, rangeHigh, inc, times)
- if times then
- local word = math.random(rangeLow, rangeHigh)
- local value = math.random(0x0000, 0xFFFF)
- if inc then
- value = memory.readword(word) - 1 + (math.random(0, 1) * 2)
- end
- memory.writeword(word, value)
- corruptWords = corruptWords + 1
- times = times - 1
- end
- end
- function corruptWordVal(rangeLow, rangeHigh, inc, times, val)
- if times then
- local word = math.random(rangeLow, rangeHigh)
- --while (word < 0xFF0200 or word > 0xFF0300) do
- while (word > 0xFF0100 and word < 0xFF3000) do
- word = math.random(rangeLow, rangeHigh)
- end
- local value = val
- if inc then
- value = val
- end
- memory.writeword(word, value)
- print (string.format("%06X -> %04X", word, value))
- corruptWords = corruptWords + 1
- times = times - 1
- end
- end
- function swapWords(rangeLow, rangeHigh)
- local word1 = math.random(rangeLow + 1, rangeHigh - 1)
- local word2 = word1 - 1 + (math.random(0, 1) * 2)
- local word1val = memory.readword(word1)
- local word2val = memory.readword(word2)
- memory.writeword(word1, word2val)
- memory.writeword(word2, word1val)
- corruptWords = corruptWords + 1
- end
- function statusLights(x, y, flags)
- x = x + 10;
- gui.box(x - 10, y, x + 28, y + 8, "#000000a0", "#000000a0")
- gui.text(x - 9, y + 1, "C", table.getn(gameGenieCodes) > 0 and "white" or "gray", "clear")
- gui.text(x - 1, y + 1, "R", flags['ramrnd'] and "white" or "gray", "clear")
- gui.text(x + 8, y + 1, "A", flags['raminc'] and "white" or "gray", "clear")
- gui.text(x + 15, y + 1, "B", flags['ramxrnd'] and "white" or "gray", "clear")
- gui.text(x + 23, y + 1, "S", flags['ramxinc'] and "white" or "gray", "clear")
- if ggtimer > -120 then
- if table.getn(gameGenieCodes) > 0 then
- gui.box(x - 10, y + 9, x + 28, y + 10 + 8 * table.getn(gameGenieCodes), "#000000a0", "#000000a0")
- end
- for i, v in ipairs(gameGenieCodes) do
- gui.text(x - 9, y + 3 + 8 * i, v, "white", "clear")
- end
- end
- end
- function randomGameGenieCode()
- -- local ggLetters = 'AEPOZXLUGKISTVYN'
- local ggLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
- local ret = ''
- for j = 1, 2 do
- for i = 1, 4 do
- local letter = math.random(1, 36)
- ret = ret .. ggLetters:sub(letter, letter)
- end
- if j == 1 then
- ret = ret .. '-'
- end
- end
- return ret
- end
- function rewindArrow(x, y, v, max, rewinding)
- local rwx = x;
- local rwy = y;
- local pct = math.min(math.max(0, v / max), 1)
- gui.box(x + 0, y + 2, x + 31, y + 6, "#000000b0", "black")
- local barsize = math.round(pct * 30);
- local color = "#9999ff"
- if pct < 0.25 then
- color = "red"
- end
- if barsize > 0 then
- gui.box(x + 1, y + 3, x + 0 + barsize, y + 5, color, color)
- end
- rwx = rwx + 7
- if rewinding and v == 0 then
- gui.box(rwx + 4, rwy - 4, rwx + 8, rwy + 4, "white", "black")
- gui.box(rwx + 10, rwy - 4, rwx + 14, rwy + 4, "white", "black")
- elseif rewinding then
- for rw = -1, 7 do
- gui.line(rwx + 0 + rw, rwy - 1 - math.floor(rw / 2), rwx + 0 + rw, rwy + 1 + math.floor(rw / 2), "black");
- gui.line(rwx + 1 + rw, rwy - 1 - math.floor(rw / 2), rwx + 1 + rw, rwy + 1 + math.floor(rw / 2), "black");
- gui.line(rwx + 9 + rw, rwy - 1 - math.floor(rw / 2), rwx + 9 + rw, rwy + 1 + math.floor(rw / 2), "black");
- gui.line(rwx + 10 + rw, rwy - 1 - math.floor(rw / 2), rwx + 10 + rw, rwy + 1 + math.floor(rw / 2), "black");
- if rw >= 0 then
- gui.line(rwx + 0 + rw, rwy - math.floor(rw / 2), rwx + 0 + rw, rwy + math.floor(rw / 2), "white");
- gui.line(rwx + 9 + rw, rwy - math.floor(rw / 2), rwx + 9 + rw, rwy + math.floor(rw / 2), "white");
- end
- end;
- else
- for rw = 0, 8 do
- gui.line(rwx + 5 + rw, rwy - 1 - math.floor((7 - rw) / 2), rwx + 5 + rw, rwy + 1 + math.floor((7 - rw) / 2), "black");
- gui.line(rwx + 6 + rw, rwy - 1 - math.floor((7 - rw) / 2), rwx + 6 + rw, rwy + 1 + math.floor((7 - rw) / 2), "black");
- if rw >= 1 then
- gui.line(rwx + 5 + rw, rwy - math.ceil((7 - rw) / 2), rwx + 5 + rw, rwy + math.ceil((7 - rw) / 2), "white");
- end
- end;
- end
- end
- corruptWords = 0
- timer = 0
- inpt = {}
- inpto = {}
- gameGenieCodes = {}
- saveStates = {}
- saveIndex = 0
- saveIndexMin = 0
- ggtimer = 0
- showHUD = true
- while true do
- inpto = inpt;
- inpt = input.get()
- local rewinding = false
- if inpt[keyBindings['rewind']] then
- rewinding = true
- end
- if inpt[keyBindings['rewind']] and saveStates[saveIndex] then
- savestate.load(saveStates[saveIndex])
- if saveStates[saveIndex - 1] then
- saveIndex = saveIndex - 1
- else
- saveIndexMin = saveIndex;
- end
- else
- local save = savestate.create()
- savestate.save(save)
- saveIndexMin = math.max(saveIndexMin, saveIndex - rewindMax)
- saveIndex = saveIndex + 1
- saveStates[saveIndex] = save
- saveStates[saveIndexMin] = nil
- end
- local corruptionFlag = {
- ramrnd = false,
- raminc = false,
- ramxrnd = false,
- ramxinc = false,
- }
- if inpt[keyBindings['ramrnd']] then
- corruptWord(0xFF0000, 0xFFFFFF, false, 100)
- corruptionFlag['ramrnd'] = true;
- end
- if inpt[keyBindings['raminc']] then
- corruptWord(0xFF0000, 0xFFFFFF, true, 100)
- corruptionFlag['raminc'] = true;
- end
- if inpt[keyBindings['ramxrnd']] then
- corruptWord(0xFF0000, 0xFF0FFF, false, 10000)
- corruptionFlag['ramxrnd'] = true;
- end
- if inpt[keyBindings['ramxinc']] then
- corruptWord(0xFF0000, 0xFFFFFF, true, 10000)
- corruptionFlag['ramxinc'] = true;
- end
- if inpt[keyBindings['ramnul']] then
- --corruptWordVal(0xFF3200, 0xFF32FF, false, 100, 0)
- corruptWordVal(0xFF0000, 0xFF5FFF, false, 100, 1)
- corruptionFlag['ramrnd'] = true;
- end
- if inpt[keyBindings['ramswap']] then
- swapWords(0xFF0000, 0xFFFFFF)
- corruptionFlag['ramrnd'] = true;
- end
- if inpt[keyBindings['extswap']] then
- swapWords(0xFF0000, 0xFFFFFF)
- corruptionFlag['raminc'] = true;
- end
- if inpt[keyBindings['ggadd']] and math.fmod(math.max(0, ggtimer), 6) == 0 then
- local code = randomGameGenieCode()
- -- emu.addgamegenie(code)
- table.insert(gameGenieCodes, code)
- end
- if inpt[keyBindings['ggdel']] and math.fmod(math.max(0, ggtimer), 6) == 0 then
- if table.getn(gameGenieCodes) > 0 then
- -- emu.delgamegenie(gameGenieCodes[table.getn(gameGenieCodes)])
- table.remove(gameGenieCodes)
- end
- end
- if inpt[keyBindings['ggadd']] or inpt[keyBindings['ggdel']] then
- ggtimer = math.max(1, ggtimer + 1)
- else
- ggtimer = math.min(0, ggtimer - 1)
- end
- if inpt[keyBindings['showHUD']] and not inpto[keyBindings['showHUD']] then
- showHUD = not showHUD
- end
- if showHUD then
- rewindArrow(280, 210, saveIndex - saveIndexMin, rewindMax, rewinding);
- statusLights( 0, 0, corruptionFlag)
- end
- timer = timer + 1
- emu.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement