Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 49 additions & 61 deletions Other/Citra_per_game_config/v2/CitraPerGame.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -9,65 +9,48 @@

;--- Helpers ---------------------------------------------------------------

SetRes(f) {
global CitraConfigFile
cfg := LoadConfig(CitraConfigFile)
SetRes(cfg, f) {
; Replace resolution_factor with value f (supports 1-10)
cfg := RegExReplace(cfg, "m)^resolution_factor=([2-9]|10|1)$", "resolution_factor=" f)
SaveConfig(cfg, CitraConfigFile)
return cfg
}

SetFilter(name, isDefaultTrue) {
global CitraConfigFile
cfg := LoadConfig(CitraConfigFile)

SetFilter(cfg, name, isDefaultTrue) {
if (name = "none")
cfg := StrReplace(cfg, "texture_filter_name=xBRZ freescale", "texture_filter_name=none")
else if (name = "xBRZ freescale")
cfg := StrReplace(cfg, "texture_filter_name=none", "texture_filter_name=xBRZ freescale")

cfg := StrReplace(cfg, "texture_filter_name\default=" (isDefaultTrue ? "false" : "true"), "texture_filter_name\default=" (isDefaultTrue ? "true" : "false"))
SaveConfig(cfg, CitraConfigFile)
return cfg
}

SetShader(name, wantDefaultFalse) {
global CitraConfigFile
cfg := LoadConfig(CitraConfigFile)

SetShader(cfg, name, wantDefaultFalse) {
if (name = "none (builtin)")
cfg := StrReplace(cfg, "pp_shader_name=Bump_Mapping_AA_optimize", "pp_shader_name=none (builtin)")
else if (name = "Bump_Mapping_AA_optimize")
cfg := StrReplace(cfg, "pp_shader_name=none (builtin)", "pp_shader_name=Bump_Mapping_AA_optimize")

cfg := StrReplace(cfg, "pp_shader_name\default=" (wantDefaultFalse ? "true" : "false"), "pp_shader_name\default=" (wantDefaultFalse ? "false" : "true"))
SaveConfig(cfg, CitraConfigFile)
return cfg
}

SetPreload(on) {
global CitraConfigFile
cfg := LoadConfig(CitraConfigFile)

SetPreload(cfg, on) {
cfg := StrReplace(cfg, "preload_textures\default=" (on ? "true" : "false"), "preload_textures\default=" (on ? "false" : "true"))
cfg := StrReplace(cfg, "preload_textures=" (on ? "false" : "false"), "preload_textures=" (on ? "true" : "false"))
Comment on lines 39 to 40
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetPreload() cannot reliably turn preloading off: the second StrReplace always searches for preload_textures=false (because (on ? "false" : "false") is always "false"), so when on is false and the config currently contains preload_textures=true, it will not be changed back to false. Update the replacement logic to handle both current states (e.g., replace the opposite of the desired value, or use a regex to set preload_textures= to the requested boolean).

Suggested change
cfg := StrReplace(cfg, "preload_textures\default=" (on ? "true" : "false"), "preload_textures\default=" (on ? "false" : "true"))
cfg := StrReplace(cfg, "preload_textures=" (on ? "false" : "false"), "preload_textures=" (on ? "true" : "false"))
desired := on ? "true" : "false"
; Ensure the default flag matches the desired state
cfg := StrReplace(cfg, "preload_textures\default=true", "preload_textures\default=" desired)
cfg := StrReplace(cfg, "preload_textures\default=false", "preload_textures\default=" desired)
; Ensure the actual setting matches the desired state
cfg := StrReplace(cfg, "preload_textures=true", "preload_textures=" desired)
cfg := StrReplace(cfg, "preload_textures=false", "preload_textures=" desired)

Copilot uses AI. Check for mistakes.
SaveConfig(cfg, CitraConfigFile)
return cfg
}

SetClock(pct) {
global CitraConfigFile
cfg := LoadConfig(CitraConfigFile)

SetClock(cfg, pct) {
cfg := StrReplace(cfg, "cpu_clock_percentage=125", "cpu_clock_percentage=" pct)
cfg := StrReplace(cfg, "cpu_clock_percentage=25", "cpu_clock_percentage=" pct)
SaveConfig(cfg, CitraConfigFile)
return cfg
}

SetLayout(opt) {
global CitraConfigFile
cfg := LoadConfig(CitraConfigFile)

SetLayout(cfg, opt) {
cfg := StrReplace(cfg, "layout_option=2", "layout_option=" opt)
cfg := StrReplace(cfg, "layout_option=0", "layout_option=" opt)
SaveConfig(cfg, CitraConfigFile)
return cfg
}

NormKey(k) {
Expand Down Expand Up @@ -114,51 +97,56 @@ else if (game = "mario_luigi_bis")
else if (game = "mario_luigi_bowsers_inside_story")
game := "mario_luigi_bowser_s_inside_story"

global CitraConfigFile
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global CitraConfigFile is redundant at the top-level scope (this file is already in global scope, and CitraConfigFile is initialized by CitraConfigBase.ahk). Removing this line would reduce confusion about whether the variable is being redefined here.

Suggested change
global CitraConfigFile

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cfg := LoadConfig(CitraConfigFile) happens before verifying that game matches a supported key (the invalid-key path calls ShowHelp() later). If an unsupported key is passed, this extra file read is unnecessary; consider moving the load/save work inside the recognized-game branches (or after validating the key).

Suggested change
global CitraConfigFile
global CitraConfigFile
; Validate game key before loading config to avoid unnecessary file I/O
if !(game = "default"
|| game = "3d_land"
|| game = "hd_texture_pack"
|| game = "luigi_s_mansion_2"
|| game = "mario_kart_7"
|| game = "mario_luigi_bowser_s_inside_story"
|| game = "mario_luigi"
|| game = "no_preloading"
|| game = "nsmb2") {
ShowHelp()
}

Copilot uses AI. Check for mistakes.
cfg := LoadConfig(CitraConfigFile)

; Apply configs
if (game = "default") {
SetRes(10)
SetFilter("xBRZ freescale", false)
SetShader("Bump_Mapping_AA_optimize", true)
SetPreload(true)
SetClock(125)
SetLayout(2)
cfg := SetRes(cfg, 10)
cfg := SetFilter(cfg, "xBRZ freescale", false)
cfg := SetShader(cfg, "Bump_Mapping_AA_optimize", true)
cfg := SetPreload(cfg, true)
cfg := SetClock(cfg, 125)
cfg := SetLayout(cfg, 2)
} else if (game = "3d_land") {
SetRes(8)
SetFilter("none", true)
SetShader("none (builtin)", false)
SetPreload(false)
cfg := SetRes(cfg, 8)
cfg := SetFilter(cfg, "none", true)
cfg := SetShader(cfg, "none (builtin)", false)
cfg := SetPreload(cfg, false)
} else if (game = "hd_texture_pack") {
SetRes(4)
SetFilter("none", true)
SetShader("none (builtin)", false)
SetPreload(false)
cfg := SetRes(cfg, 4)
cfg := SetFilter(cfg, "none", true)
cfg := SetShader(cfg, "none (builtin)", false)
cfg := SetPreload(cfg, false)
} else if (game = "luigi_s_mansion_2") {
SetRes(6)
SetClock(25)
cfg := SetRes(cfg, 6)
cfg := SetClock(cfg, 25)
} else if (game = "mario_kart_7") {
SetRes(5)
SetFilter("none", true)
SetPreload(false)
cfg := SetRes(cfg, 5)
cfg := SetFilter(cfg, "none", true)
cfg := SetPreload(cfg, false)
} else if (game = "mario_luigi_bowser_s_inside_story") {
SetLayout(0)
SetFilter("none", true)
SetShader("none (builtin)", false)
SetPreload(false)
cfg := SetLayout(cfg, 0)
cfg := SetFilter(cfg, "none", true)
cfg := SetShader(cfg, "none (builtin)", false)
cfg := SetPreload(cfg, false)
} else if (game = "mario_luigi") {
SetLayout(0)
cfg := SetLayout(cfg, 0)
} else if (game = "no_preloading") {
SetRes(10)
SetFilter("xBRZ freescale", false)
SetShader("Bump_Mapping_AA_optimize", true)
SetPreload(false)
cfg := SetRes(cfg, 10)
cfg := SetFilter(cfg, "xBRZ freescale", false)
cfg := SetShader(cfg, "Bump_Mapping_AA_optimize", true)
cfg := SetPreload(cfg, false)
} else if (game = "nsmb2") {
SetRes(10)
SetFilter("none", true)
SetShader("none (builtin)", false)
SetPreload(false)
cfg := SetRes(cfg, 10)
cfg := SetFilter(cfg, "none", true)
cfg := SetShader(cfg, "none (builtin)", false)
cfg := SetPreload(cfg, false)
} else {
ShowHelp()
}

SaveConfig(cfg, CitraConfigFile)
Copy link

Copilot AI Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return value of SaveConfig(cfg, CitraConfigFile) is ignored, but SaveConfig() can fail and returns false (and shows an error MsgBox). As written, the script will still show "Applied config" even if the save failed. Consider checking the return value and exiting with a non-zero code when saving fails.

Suggested change
SaveConfig(cfg, CitraConfigFile)
if !SaveConfig(cfg, CitraConfigFile) {
ExitApp 1
}

Copilot uses AI. Check for mistakes.

MsgBox("Applied config for '" game "'.", "CitraPerGame", 64)
ExitApp 0
Loading