From 7e82be42348035868c7524af39439ff180770b52 Mon Sep 17 00:00:00 2001 From: Pretzal Date: Sun, 2 Nov 2025 11:16:29 -0600 Subject: [PATCH 1/5] Fixing straight flush checking --- utilities/hooks.lua | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/utilities/hooks.lua b/utilities/hooks.lua index 7d269f6a..c68f917d 100644 --- a/utilities/hooks.lua +++ b/utilities/hooks.lua @@ -207,15 +207,44 @@ end -- Ace still can't wrap around straights even though it's no longer straight_edge -- accounts for Shortcut by checking for Q and 3 as well +-- Also now accounts for Four Fingers local get_straight_ref = get_straight function get_straight(hand, min_length, skip, wrap) - local has_king_queen = false - local has_2_3 = false - for i = 1, #hand do - if hand[i]:get_id() == 13 or hand[i]:get_id() == 12 then has_king_queen = true end - if hand[i]:get_id() == 2 or hand[i]:get_id() == 3 then has_2_3 = true end + if #hand < min_length then return {} end + if not wrap then + local has_king_queen = false + local has_2_3 = false + local check_cards = {} + for i = 1, #hand do + if hand[i]:get_id() == 13 or (skip and hand[i]:get_id() == 12) then + has_king_queen = true + check_cards[#check_cards + 1] = i + end + if hand[i]:get_id() == 2 or (skip and hand[i]:get_id() == 3) then + has_2_3 = true + check_cards[#check_cards + 1] = i + end + end + if has_king_queen and has_2_3 then + -- Check to see if we can reduce the number of cards. + -- Possibly gets pretty slow with a lot of selected cards? + if #hand > min_length then + for i = 1, #check_cards do + local temp_hand = {} + for j = 1, #hand do + if check_cards[i] ~= j then + temp_hand[#temp_hand + 1] = hand[j] + end + end + local straight = get_straight(temp_hand, min_length, skip, wrap) + if #straight > 0 then + return straight + end + end + end + return {} + end end - if has_king_queen and has_2_3 then return {} end return get_straight_ref(hand, min_length, skip, wrap) end From f3851f48a0b7151c402a2fee4243d6fe325c33df Mon Sep 17 00:00:00 2001 From: Pretzal Date: Mon, 3 Nov 2025 23:14:05 -0600 Subject: [PATCH 2/5] Rewriting get_straight check --- utilities/hooks.lua | 83 +++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/utilities/hooks.lua b/utilities/hooks.lua index c68f917d..02bd8ead 100644 --- a/utilities/hooks.lua +++ b/utilities/hooks.lua @@ -210,42 +210,73 @@ end -- Also now accounts for Four Fingers local get_straight_ref = get_straight function get_straight(hand, min_length, skip, wrap) + min_length = min_length or 5 + if min_length < 2 then min_length = 2 end if #hand < min_length then return {} end - if not wrap then - local has_king_queen = false - local has_2_3 = false - local check_cards = {} - for i = 1, #hand do - if hand[i]:get_id() == 13 or (skip and hand[i]:get_id() == 12) then - has_king_queen = true - check_cards[#check_cards + 1] = i + local ranks = {} + for k, _ in pairs(SMODS.Ranks) do ranks[k] = {} end + for _, card in ipairs(hand) do + local id = card:get_id() + if id > 0 then + for k, v in pairs(SMODS.Ranks) do + if v.id == id then + table.insert(ranks[k], card); break + end end - if hand[i]:get_id() == 2 or (skip and hand[i]:get_id() == 3) then - has_2_3 = true - check_cards[#check_cards + 1] = i + end + end + local function next_ranks(key, start) + local rank = SMODS.Ranks[key] + local ret = {} + if not start and not wrap and rank.straight_edge then + return ret + end + for _, v in ipairs(rank.next) do + ret[#ret + 1] = v + if skip and (wrap or not SMODS.Ranks[v].straight_edge) then + for _, w in ipairs(SMODS.Ranks[v].next) do + ret[#ret + 1] = w + end end end - if has_king_queen and has_2_3 then - -- Check to see if we can reduce the number of cards. - -- Possibly gets pretty slow with a lot of selected cards? - if #hand > min_length then - for i = 1, #check_cards do - local temp_hand = {} - for j = 1, #hand do - if check_cards[i] ~= j then - temp_hand[#temp_hand + 1] = hand[j] - end + return ret + end + local tuples = {} + local ret = {} + for _, k in ipairs(SMODS.Rank.obj_buffer) do + if next(ranks[k]) then + tuples[#tuples + 1] = { k } + end + end + for i = 2, #hand + 1 do + local new_tuples = {} + for _, tuple in ipairs(tuples) do + local any_tuple + if i ~= #hand + 1 then + for _, l in ipairs(next_ranks(tuple[i - 1], i == 2)) do + if next(ranks[l]) then + local new_tuple = {} + for _, v in ipairs(tuple) do new_tuple[#new_tuple + 1] = v end + new_tuple[#new_tuple + 1] = l + new_tuples[#new_tuples + 1] = new_tuple + any_tuple = true end - local straight = get_straight(temp_hand, min_length, skip, wrap) - if #straight > 0 then - return straight + end + end + if i > min_length and not any_tuple then + local straight = {} + for _, v in ipairs(tuple) do + for _, card in ipairs(ranks[v]) do + straight[#straight + 1] = card end end + ret[#ret + 1] = straight end - return {} end + tuples = new_tuples end - return get_straight_ref(hand, min_length, skip, wrap) + table.sort(ret, function(a, b) return #a > #b end) + return ret end -- Apostle-high straight flushes get renamed to "Rapture" From 646d7ba805d2b3f1e3e96836911cb46e491e584d Mon Sep 17 00:00:00 2001 From: Pretzal Date: Tue, 4 Nov 2025 20:29:19 -0600 Subject: [PATCH 3/5] Special exemptions for Apostle --- content/rank/apostle.lua | 2 -- utilities/hooks.lua | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/content/rank/apostle.lua b/content/rank/apostle.lua index 14831e3d..1c35afac 100644 --- a/content/rank/apostle.lua +++ b/content/rank/apostle.lua @@ -7,7 +7,6 @@ SMODS.Rank { hc_atlas = 'ranks_hc', pos = { x = 0 }, - straight_edge = true, next = { 'Ace' }, nominal = 12, face = true, @@ -38,6 +37,5 @@ SMODS.Rank { SMODS.Rank:take_ownership('Ace', { next = { '2', 'paperback_Apostle' }, - straight_edge = false } ) diff --git a/utilities/hooks.lua b/utilities/hooks.lua index 02bd8ead..a0fb41d6 100644 --- a/utilities/hooks.lua +++ b/utilities/hooks.lua @@ -208,7 +208,6 @@ end -- Ace still can't wrap around straights even though it's no longer straight_edge -- accounts for Shortcut by checking for Q and 3 as well -- Also now accounts for Four Fingers -local get_straight_ref = get_straight function get_straight(hand, min_length, skip, wrap) min_length = min_length or 5 if min_length < 2 then min_length = 2 end @@ -225,15 +224,23 @@ function get_straight(hand, min_length, skip, wrap) end end end - local function next_ranks(key, start) + local function next_ranks(key, start, from_apostle) local rank = SMODS.Ranks[key] local ret = {} - if not start and not wrap and rank.straight_edge then + if not start and not wrap and not from_apostle and rank.straight_edge then + for _, v in ipairs(rank.next) do + if v == 'paperback_Apostle' then + ret[#ret + 1] = v + end + end + return ret + end + if not start and not wrap and key == 'paperback_Apostle' then return ret end for _, v in ipairs(rank.next) do ret[#ret + 1] = v - if skip and (wrap or not SMODS.Ranks[v].straight_edge) then + if skip and (wrap or (not from_apostle and not SMODS.Ranks[v].straight_edge) or v ~= 'paperback_Apostle') then for _, w in ipairs(SMODS.Ranks[v].next) do ret[#ret + 1] = w end @@ -253,7 +260,7 @@ function get_straight(hand, min_length, skip, wrap) for _, tuple in ipairs(tuples) do local any_tuple if i ~= #hand + 1 then - for _, l in ipairs(next_ranks(tuple[i - 1], i == 2)) do + for _, l in ipairs(next_ranks(tuple[i - 1], i == 2, tuple[1] == 'paperback_Apostle')) do if next(ranks[l]) then local new_tuple = {} for _, v in ipairs(tuple) do new_tuple[#new_tuple + 1] = v end From 197d6fbfd040200cae5f71dce64b7350dc619f8b Mon Sep 17 00:00:00 2001 From: Pretzal Date: Thu, 6 Nov 2025 19:44:08 -0600 Subject: [PATCH 4/5] Converting to lovely patch --- lovely/apostle_fixes.toml | 52 +++++++++++++++++++++++++ utilities/hooks.lua | 81 --------------------------------------- 2 files changed, 52 insertions(+), 81 deletions(-) create mode 100644 lovely/apostle_fixes.toml diff --git a/lovely/apostle_fixes.toml b/lovely/apostle_fixes.toml new file mode 100644 index 00000000..9522041b --- /dev/null +++ b/lovely/apostle_fixes.toml @@ -0,0 +1,52 @@ +[manifest] +version = "1.0.0" +dump_lua = true +priority = 0 + +[[patches]] +[patches.pattern] +target = '=[SMODS _ "src/overrides.lua"]' +pattern = "local function next_ranks(key, start)" +position = "at" +match_indent = true +payload = ''' +local function next_ranks(key, start, from_apostle) +''' + +[[patches]] +[patches.pattern] +target = '=[SMODS _ "src/overrides.lua"]' +pattern = "if not start and not wrap and rank.straight_edge then return ret end" +position = "at" +match_indent = true +payload = ''' +if not start and not wrap and rank.straight_edge and not from_apostle then + for _, v in ipairs(rank.next) do + if v == 'paperback_Apostle' then + ret[#ret + 1] = v + end + end + return ret +end +if not start and not wrap and key == 'paperback_Apostle' then return ret end +''' + +[[patches]] +[patches.pattern] +target = '=[SMODS _ "src/overrides.lua"]' +pattern = "if skip and (wrap or not SMODS.Ranks[v].straight_edge) then" +position = "at" +match_indent = true +payload = ''' +if skip and (wrap or (not from_apostle and not SMODS.Ranks[v].straight_edge) or v ~= 'paperback_Apostle') then +''' + +[[patches]] +[patches.pattern] +target = '=[SMODS _ "src/overrides.lua"]' +pattern = "for _,l in ipairs(next_ranks(tuple[i-1], i == 2)) do" +position = "at" +match_indent = true +payload = ''' +for _,l in ipairs(next_ranks(tuple[i-1], i == 2, tuple[1] == 'paperback_Apostle')) do +''' diff --git a/utilities/hooks.lua b/utilities/hooks.lua index a0fb41d6..4f60fc51 100644 --- a/utilities/hooks.lua +++ b/utilities/hooks.lua @@ -205,87 +205,6 @@ function add_tag(tag) return add_tag_ref(tag) end --- Ace still can't wrap around straights even though it's no longer straight_edge --- accounts for Shortcut by checking for Q and 3 as well --- Also now accounts for Four Fingers -function get_straight(hand, min_length, skip, wrap) - min_length = min_length or 5 - if min_length < 2 then min_length = 2 end - if #hand < min_length then return {} end - local ranks = {} - for k, _ in pairs(SMODS.Ranks) do ranks[k] = {} end - for _, card in ipairs(hand) do - local id = card:get_id() - if id > 0 then - for k, v in pairs(SMODS.Ranks) do - if v.id == id then - table.insert(ranks[k], card); break - end - end - end - end - local function next_ranks(key, start, from_apostle) - local rank = SMODS.Ranks[key] - local ret = {} - if not start and not wrap and not from_apostle and rank.straight_edge then - for _, v in ipairs(rank.next) do - if v == 'paperback_Apostle' then - ret[#ret + 1] = v - end - end - return ret - end - if not start and not wrap and key == 'paperback_Apostle' then - return ret - end - for _, v in ipairs(rank.next) do - ret[#ret + 1] = v - if skip and (wrap or (not from_apostle and not SMODS.Ranks[v].straight_edge) or v ~= 'paperback_Apostle') then - for _, w in ipairs(SMODS.Ranks[v].next) do - ret[#ret + 1] = w - end - end - end - return ret - end - local tuples = {} - local ret = {} - for _, k in ipairs(SMODS.Rank.obj_buffer) do - if next(ranks[k]) then - tuples[#tuples + 1] = { k } - end - end - for i = 2, #hand + 1 do - local new_tuples = {} - for _, tuple in ipairs(tuples) do - local any_tuple - if i ~= #hand + 1 then - for _, l in ipairs(next_ranks(tuple[i - 1], i == 2, tuple[1] == 'paperback_Apostle')) do - if next(ranks[l]) then - local new_tuple = {} - for _, v in ipairs(tuple) do new_tuple[#new_tuple + 1] = v end - new_tuple[#new_tuple + 1] = l - new_tuples[#new_tuples + 1] = new_tuple - any_tuple = true - end - end - end - if i > min_length and not any_tuple then - local straight = {} - for _, v in ipairs(tuple) do - for _, card in ipairs(ranks[v]) do - straight[#straight + 1] = card - end - end - ret[#ret + 1] = straight - end - end - tuples = new_tuples - end - table.sort(ret, function(a, b) return #a > #b end) - return ret -end - -- Apostle-high straight flushes get renamed to "Rapture" local poker_hand_info_ref = G.FUNCS.get_poker_hand_info function G.FUNCS.get_poker_hand_info(_cards) From 1a79979e02c64514416105945bdcd2fed0172e92 Mon Sep 17 00:00:00 2001 From: Pretzal Date: Fri, 21 Nov 2025 08:36:40 -0600 Subject: [PATCH 5/5] Removing other fix --- lovely/ace_apostle_straights.toml | 74 ------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 lovely/ace_apostle_straights.toml diff --git a/lovely/ace_apostle_straights.toml b/lovely/ace_apostle_straights.toml deleted file mode 100644 index f4421047..00000000 --- a/lovely/ace_apostle_straights.toml +++ /dev/null @@ -1,74 +0,0 @@ -[manifest] -version = "1.0.0" -priority = 0 - -# Apostles ignore `wrap` in get_straight -[[patches]] -[patches.regex] -target = '=[SMODS _ "src/overrides.lua"]' -pattern = '(?wrap).*rank\.straight_edge.*then' -position = "at" -root_capture = "$wrap" -payload = '''(wrap and key ~= 'paperback_Apostle')''' -[[patches]] -[patches.regex] -target = '=[SMODS _ "src/overrides.lua"]' -pattern = '(?wrap).*SMODS\.Ranks\[v\]\.straight_edge.*then' -position = "at" -root_capture = "$wrap" -payload = '''(wrap and v ~= 'paperback_Apostle')''' - -# next_ranks() doesn't allow K-A-2 or Apostle-A-Apostle -# Paperback makes Ace have straight_edge = false, this fixes the side effects. -## Define helper to check -[[patches]] -[patches.pattern] -target = '=[SMODS _ "src/overrides.lua"]' -pattern = "function get_straight(*" -position = "after" -match_indent = true -payload = """ -local pb_prev_key -local function pb_is_illegal_seq(p_key, key, n_key, wrap) - return not wrap and key == 'Ace' and ( - (p_key == 'King' or p_key == 'Queen') and (n_key == '2' or n_key == '3') - or (p_key == 'paperback_Apostle') and (n_key == 'paperback_Apostle') - ) -end""" -## In next_ranks(), illegal next ranks are skipped -[[patches]] -[patches.pattern] -target = '=[SMODS _ "src/overrides.lua"]' -pattern = "ret[#ret+1] = v" -position = "before" -match_indent = true -payload = """ -if pb_is_illegal_seq(pb_prev_key, key, v, wrap) then - goto pb_continue_rank_next -end""" -[[patches]] -[patches.pattern] -target = '=[SMODS _ "src/overrides.lua"]' -pattern = """ - ret[#ret+1] = w - end -end""" -position = "at" -match_indent = false -payload = """ - if pb_is_illegal_seq(key, v, w, wrap) then - goto pb_continue_rank_next - end - ret[#ret+1] = w - end - end - ::pb_continue_rank_next::""" - -# Actually set pb_prev_key variable -[[patches]] -[patches.pattern] -target = '=[SMODS _ "src/overrides.lua"]' -pattern = "for _,l in ipairs(next_ranks(tuple[i-1], i == 2)) do" -position = "before" -match_indent = true -payload = "pb_prev_key = tuple[i-2]"