Forum Mod Bakery Docs

No Level Movies

Please sign in to reply to this topic.
Lets you disable vanilla mission/gag movies via mod settings. Does not affect the Level 3 Bonus Movie. Requires launcher version 1.18 or higher and any supported version of the game (including the demo).


Source code if interested:

CLICK TO VIEW
CustomFiles.ini
[code]
; CustomFiles.ini

[PathHandlers]
scripts\\missions\\*\\m?sdi.mfk=Resources\\lua\\MovieGate.lua ; Pre-mission
scripts\\missions\\*\\m?i.mfk=Resources\\lua\\MovieGate.lua ; Main-mission
scripts\\missions\\*\\level.mfk=Resources\\lua\\MovieGate.lua ; Level

; -----
[/code]
MovieGate.lua
[code]
-- MovieGate.lua
-- Gate MFK functions to play movies based on mod settings.
-- Feb-2025 @CelestialAddy

MissionMoviesOFF = GetSetting("MissionMoviesOFF")
GagMoviesOFF = GetSetting("GagMoviesOFF")
LoadingScript = ReadFile("/GameData/" .. GetPath())
CacheOldScript = LoadingScript

if MissionMoviesOFF then
LoadingScript = string.gsub(LoadingScript, "\"fmv\"", "\"timer\"")
LoadingScript = string.gsub(LoadingScript, "SetFMVInfo", "SetDurationTime(0); //")
end

if GagMoviesOFF then
LoadingScript = string.gsub(LoadingScript, "GagPlayFMV", "//")
end

if LoadingScript ~= CacheOldScript then print("Movie/s disabled in: " .. GetPath()) end

Output(LoadingScript)

-- End.
[/code]

Showcase (both disabled):



Download:

r1.0 (16KB LMLM via mega.nz)

Cool mod, though I have a few Lua suggestions:

  1. Don't use globals for anything that doesn't need to be retained out of scope.
    • In this mod, the examples would be things like LoadingScript and CacheOldScript. They are only relevant to the current executing script, so they should be local LoadingScript and local CacheOldScript.
    • This is both a performance enhancement, and also good coding practice as you can run into issues with anything bigger if you use similar variable names across files.
    • An example of a good global would be to put MissionMoviesOFF and GagMoviesOFF as globals in CustomFiles.lua, so you only call the GetSetting or GetSettings function once on game load, and then reference the global in future script calls.
  2. When editing mission scripts with gsub, there's a few performance and safety checks you can add.
    • If you read the initial file with local LoadingScript = ReadFile("/GameData/" .. GetPath()):gsub("//.-([\r\n])", "%1") you blank out all single-line comments, which improves performance on future gsub calls, and also adds safety to future calls that you're not matching into a comment.
    • When replacing the parameter of a specific function, it's best to include the function itself in your pattern in order to avoid vague pattern matching. The fmv check could, potentially, match something it shouldn't. Instead you could do LoadingScript = string.gsub(LoadingScript, "AddObjective%s*%(%s*\"fmv\"%s*%);", "AddObjective(\"timer\");") The %s* greedy matches any whitespace (as is allowed in the MFK/CON format), and %(/%) escapes the brackets to prevent a match group.
    • It's bad practice to blindly comment out the remainder of a line like your SetFMVInfo check. MFK/CON files support being minified into one line, as the token that splits commands is the semi-colon - Game.lua scripts are output to the game on one line for example. To counter this, you can do similar to the above to replace the entire command: LoadingScript = string.gsub(LoadingScript, "SetFMVInfo%s*%(.-%);", "SetDurationTime(0);"). As above it matches the whole command - .- being a lazy match for literally anything, so it gets as little as possible before the the closing bracket.
      • This could also be used for your GagPlayFMV match, but instead replace with an empty string: LoadingScript = string.gsub(LoadingScript, "GagPlayFMV%s*%(.-%);", "").
  3. Lastly, a bit of a self-plug, but my MFKLexer, whilst not currently fully released, provides a lot of helper functions for script manipulation. This script for example would be:
-- Assuming MissionMoviesOFF and GagMoviesOFF are in CustomFiles.lua
if not MissionMoviesOFF and not GagMoviesOFF then
    -- No modifications enabled, exit
    return
end

local Path = GetPath()
local GamePath = "/GameData/" .. Path
local MFK = MFKLexer.Lexer:Parse(ReadFile(GamePath))

local changed = false

if MissionMoviesOFF then
    changed = MFK:SetAll("addobjective", 1, "timer", "fmv") -- Replace the first argument in all `AddObjective` functions with `timer` if it currently `fmv`.
    if changed then -- If any functions are changed, replace all `SetFMVInfo` functions with `SetDurationTime` and set the first argument to `0`.
        for Function in MFK:GetFunctions("SetFMVInfo") do
            Function.Name = "SetDurationTime"
            Function.Arguments[1] = 0
        end
    end
end

if GagMoviesOFF then
    for Function, Index in MFK:GetFunctions("GagPlayFMV", true) do -- Loop through all `GagPlayFMV` functions backwards and remove them.
        MFK:RemoveFunction(Index)
        changed = true
    end
end

if changed then
    print("Movie/s disabled in: " .. GetPath())
    MFK:Output(true)
end

FMV removal copied from Randomiser v4.

Any questions - especially about Lua - always happy to lend a hand, just send a ping in the Discord.

Thanks,

Josh