Skip to content

Instantly share code, notes, and snippets.

@dextercd
Created April 24, 2026 16:25
Show Gist options
  • Select an option

  • Save dextercd/e039c7a8a47f1da54b8a980d3a2ee14d to your computer and use it in GitHub Desktop.

Select an option

Save dextercd/e039c7a8a47f1da54b8a980d3a2ee14d to your computer and use it in GitHub Desktop.
Noita New Game
dofile_once("data/scripts/lib/coroutines.lua")
local ffi = require("ffi")
local SDL = dofile("mods/PressRestart/sdl2_ffi.lua")
local imgui = load_imgui({mod="PressRestart", version="1.0.0"})
function send_inputs(inputs, delay)
SDL.SDL_EventState(SDL.SDL_MOUSEMOTION, SDL.SDL_IGNORE)
for _, input in ipairs(inputs) do
local ev = ffi.new("SDL_Event")
local kb = ffi.cast("SDL_KeyboardEvent*", ev)
kb.timestamp = SDL.SDL_GetTicks()
kb.keysym.sym = input
kb.keysym.scancode = SDL.SDL_GetScancodeFromKey(input)
kb.keysym.mod = 0
kb.type = SDL.SDL_KEYDOWN
SDL.SDL_PushEvent(ev)
kb.type = SDL.SDL_KEYUP
SDL.SDL_PushEvent(ev)
wait(delay)
end
SDL.SDL_EventState(SDL.SDL_MOUSEMOTION, SDL.SDL_ENABLE)
end
function OnWorldPreUpdate()
wake_up_waiting_threads(1)
if imgui.Begin("PressRestart") then
if imgui.Button("Restart") then
async(function()
send_inputs({
SDL.SDLK_ESCAPE,
SDL.SDLK_DOWN,
SDL.SDLK_DOWN,
SDL.SDLK_RETURN,
SDL.SDLK_RETURN,
SDL.SDLK_LEFT,
SDL.SDLK_RETURN,
}, 1)
end)
end
imgui.End()
end
end
function OnPausePreUpdate()
wake_up_waiting_threads(1)
end
dofile_once("mods/NoitaPatcher/load.lua")
local np = require("noitapatcher")
local ffi = require("ffi")
ffi.cdef([[
void* GetModuleHandleA(const char*);
]])
local base = ffi.cast("size_t", ffi.C.GetModuleHandleA(nil))
np.SetPauseState(4)
ffi.cast("int*", base + 0x00e0761c)[0] = 0 -- game mode nr
require("ffi").cast("void(__fastcall*)()", base + 0x005a2d70)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment