From abd3c321f63a39da8c02fcc5a1818bfbbd2aa2b0 Mon Sep 17 00:00:00 2001 From: bgkillas Date: Tue, 4 Mar 2025 17:24:15 -0500 Subject: [PATCH] add option to disable global perks and disable spells --- noita-proxy/src/lib.rs | 52 ++++++++++++++++--- noita-proxy/src/net.rs | 10 ++++ quant.ew/files/core/perk_fns.lua | 14 +++++ .../perk_patches/append/perks_common.lua | 2 +- .../system/spell_patches/banned_spells.lua | 27 ++++++++++ .../system/spell_patches/spell_patches.lua | 14 +++++ 6 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 quant.ew/files/system/spell_patches/banned_spells.lua diff --git a/noita-proxy/src/lib.rs b/noita-proxy/src/lib.rs index d46a5024..b0877b2a 100644 --- a/noita-proxy/src/lib.rs +++ b/noita-proxy/src/lib.rs @@ -135,6 +135,8 @@ pub struct GameSettings { no_material_damage: Option, global_hp_loss: Option, perk_ban_list: Option, + disabled_globals: Option, + spell_ban_list: Option, physics_damage: Option, share_gold: Option, nice_terraforming: Option, @@ -420,6 +422,35 @@ impl GameSettings { game_settings.give_host_sampo = Some(temp) } } + { + let mut temp = game_settings.enemy_hp_mult.unwrap_or(def.enemy_hp_mult); + if ui + .add( + Slider::new(&mut temp, 1.0..=1000.0) + .logarithmic(true) + .text(tr("connect_settings_enemy_hp_scale")), + ) + .changed() + { + game_settings.enemy_hp_mult = Some(temp) + } + } + { + let mut temp = game_settings + .spell_ban_list + .clone() + .unwrap_or(def.spell_ban_list); + ui.label("spell ban list, by internal names, comma seperated"); + if ui + .add_sized( + [ui.available_width() - 30.0, 20.0], + egui::TextEdit::singleline(&mut temp), + ) + .changed() + { + game_settings.spell_ban_list = Some(temp) + } + } ui.add_space(10.0); ui.label("Player settings"); ui.horizontal(|ui| { @@ -478,7 +509,7 @@ impl GameSettings { .perk_ban_list .clone() .unwrap_or(def.perk_ban_list); - ui.label("perk ban list, comma seperated"); + ui.label("perk ban list, by internal names, comma seperated"); if ui .add_sized( [ui.available_width() - 30.0, 20.0], @@ -490,16 +521,19 @@ impl GameSettings { } } { - let mut temp = game_settings.enemy_hp_mult.unwrap_or(def.enemy_hp_mult); + let mut temp = game_settings + .disabled_globals + .clone() + .unwrap_or(def.disabled_globals); + ui.label("global perks to ignore, by internal names, comma seperated, will cause undefined behaviour do not report issues, find list in perk_fns.lua"); if ui - .add( - Slider::new(&mut temp, 1.0..=1000.0) - .logarithmic(true) - .text(tr("connect_settings_enemy_hp_scale")), + .add_sized( + [ui.available_width() - 30.0, 20.0], + egui::TextEdit::singleline(&mut temp), ) .changed() { - game_settings.enemy_hp_mult = Some(temp) + game_settings.disabled_globals = Some(temp) } } if ui.button(tr("apply_default_settings")).clicked() { @@ -521,6 +555,8 @@ pub struct DefaultSettings { no_material_damage: bool, global_hp_loss: bool, perk_ban_list: String, + disabled_globals: String, + spell_ban_list: String, physics_damage: bool, share_gold: bool, nice_terraforming: bool, @@ -554,6 +590,8 @@ impl Default for DefaultSettings { no_material_damage: false, global_hp_loss: false, perk_ban_list: String::new(), + disabled_globals: String::new(), + spell_ban_list: String::new(), physics_damage: true, share_gold: false, nice_terraforming: true, diff --git a/noita-proxy/src/net.rs b/noita-proxy/src/net.rs index 7900c437..0728b1b4 100644 --- a/noita-proxy/src/net.rs +++ b/noita-proxy/src/net.rs @@ -969,6 +969,16 @@ impl NetManager { "perk_ban_list", lst.perk_ban_list.unwrap_or(def.perk_ban_list).as_str(), ); + state.try_ws_write_option( + "spell_ban_list", + lst.spell_ban_list.unwrap_or(def.spell_ban_list).as_str(), + ); + state.try_ws_write_option( + "disabled_globals", + lst.disabled_globals + .unwrap_or(def.disabled_globals) + .as_str(), + ); state.try_ws_write_option( "disable_kummitus", settings.disable_kummitus.unwrap_or(def.disable_kummitus), diff --git a/quant.ew/files/core/perk_fns.lua b/quant.ew/files/core/perk_fns.lua index 615f692f..49afdcd0 100644 --- a/quant.ew/files/core/perk_fns.lua +++ b/quant.ew/files/core/perk_fns.lua @@ -247,6 +247,17 @@ function perk_fns.update_perks_for_entity(perk_data, entity, allow_perk) -- util.set_ent_variable(entity, "ew_current_perks", perk_data) end +local function string_split(s, splitter) + local words = {} + if s == nil or splitter == nil or s == "" then + return {} + end + for word in string.gmatch(s, "([^" .. splitter .. "]+)") do + table.insert(words, word) + end + return words +end + local first = true function perk_fns.on_world_update() @@ -268,6 +279,9 @@ function perk_fns.on_world_update() end end end + for _, perk in ipairs(string_split(ctx.proxy_opt.disabled_globals, ",")) do + global_perks[perk] = nil + end first = false end if diff --git a/quant.ew/files/system/perk_patches/append/perks_common.lua b/quant.ew/files/system/perk_patches/append/perks_common.lua index e4e2a860..2222018b 100644 --- a/quant.ew/files/system/perk_patches/append/perks_common.lua +++ b/quant.ew/files/system/perk_patches/append/perks_common.lua @@ -81,7 +81,7 @@ end) local function string_split(s, splitter) local words = {} - if s == nil or splitter == nil then + if s == nil or splitter == nil or s == "" then return {} end for word in string.gmatch(s, "([^" .. splitter .. "]+)") do diff --git a/quant.ew/files/system/spell_patches/banned_spells.lua b/quant.ew/files/system/spell_patches/banned_spells.lua new file mode 100644 index 00000000..d6556c68 --- /dev/null +++ b/quant.ew/files/system/spell_patches/banned_spells.lua @@ -0,0 +1,27 @@ +local function string_split(s, splitter) + local words = {} + if s == nil or splitter == nil or s == "" then + return {} + end + for word in string.gmatch(s, "([^" .. splitter .. "]+)") do + table.insert(words, word) + end + return words +end +local t = string_split(CrossCall("ew_banned_spells"), ",") +local old = GetRandomActionWithType +function GetRandomActionWithType(...) + local n = old + while table.contains(t, n) do + n = old + end + return n +end +old = GetRandomAction +function GetRandomAction(...) + local n = old + while table.contains(t, n) do + n = old + end + return n +end diff --git a/quant.ew/files/system/spell_patches/spell_patches.lua b/quant.ew/files/system/spell_patches/spell_patches.lua index c0477172..6fde11dc 100644 --- a/quant.ew/files/system/spell_patches/spell_patches.lua +++ b/quant.ew/files/system/spell_patches/spell_patches.lua @@ -16,4 +16,18 @@ util.copy_file_content( "data/scripts/projectiles/essence_to_power.lua" ) +if ctx.proxy_opt.spell_ban_list ~= nil and ctx.proxy_opt.spell_ban_list ~= "" then + util.add_cross_call("ew_banned_spells", function() + return ctx.proxy_opt.spell_ban_list + end) + for _, file in ipairs({ + "data/scripts/perks/perk_list.lua", + "data/scripts/items/generate_shop_item.lua", + "data/scripts/gun/procedural/gun_procedural_better.lua", + "data/scripts/gun/procedural/gun_procedural.lua", + }) do + ModLuaFileAppend(file, "mods/quant.ew/files/system/spell_patches/banned_spells.lua") + end +end + return {}