Dadido3 / noita-mapcap

A tool to capture a Noita world as a huge image
MIT License
65 stars 8 forks source link

Disable shaders, GUI and AI #14

Open danielniccoli opened 2 years ago

danielniccoli commented 2 years ago

This does disable shaders, GUI and AI. Because it writes to the processes memory, it works only on builds where we know the exact memory address. It also only works on the dev build, because the release build is missing the code that disables the AI.

This effectively replaces pressing F5, F8 and F12. It also helps with getting a better screen cap, because it stops entities from moving, if the motion is caused by AI.

function OnWorldInitialized() -- This is called once the game world is initialized. Doesn't ensure any world chunks actually exist. Use OnPlayerSpawned to ensure the chunks around player have been loaded or created.
    --[[
        The following code disables shaders, GUI and AI.

        While shaders and GUI can be disabled in the release build as well, only the dev build has the debugging feature to disable the AI.

        Due to direct memory address write operations, only known builds on known operating systems are supported.
        Adding new builds or operating systems is easy, if someone supports us with the research.
    ]] --
    local ffi = require("ffi")
    if DebugGetIsDevBuild() == false then
        GamePrint("This mod cannot be run in the release build. You must run the dev build (noita_dev.exe) to capture a map!")
        GamePrint("If you like to capture the world of your current run, read the README for instructions on how to copy the savegame to the dev build.")
        -- exit mod init somehow?
    else
        if ffi.os == "Windows" then
            if ffi.string(ffi.cast("char*", 0x00F77B0C)) == "Build Apr 23 2021 18:36:55" then -- GOG build
                ffi.cast("char*", 0x010E3B6C)[0] = 1 -- disable shaders (Debug: mPostFxDisabled)
                ffi.cast("char*", 0x010E3B6D)[0] = 1 -- disable GUI     (Debug: mGuiDisabled)
                ffi.cast("char*", 0x010E3B73)[0] = 1 -- freeze AI       (Debug: mFreezeAI)
            elseif ffi.string(ffi.cast("char*", 0x00F80384)) == "Build Apr 23 2021 18:40:40" then -- Steam build
                ffi.cast("char*", 0x010EDEBC)[0] = 1 -- disable shaders (Debug: mPostFxDisabled)
                ffi.cast("char*", 0x010EDEBD)[0] = 1 -- disable GUI     (Debug: mGuiDisabled)
                ffi.cast("char*", 0x010EDEC3)[0] = 1 -- freeze AI       (Debug: mFreezeAI)
            else
                GamePrint("You are running a currently unsupported Noita build.")
                GamePrint("We would appreciate your help to add support for this build. Please open a ticket at https://github.com/Dadido3/noita-mapcap.")
            end
        else
            GamePrint("You are running a currently unsupported OS.")
            GamePrint("We would appreciate your help to add support for this OS. Please open a ticket at https://github.com/Dadido3/noita-mapcap.")
        end
    end
end
Dadido3 commented 2 years ago

This is awesome. Did you use cheat engine to find these addresses?

I'm currently adding a settings menu, once that is done i will look into adding this. There will be advanced options to enable/disable a lot of stuff, and this will be a nice addition to the options.

danielniccoli commented 2 years ago

Yes, I used Cheat Engine. Amazing tool.

danielniccoli commented 2 years ago

Thanks for the shoutout in the README of v2❣️