[manifest]
version = "1.0.0"
dump_lua = true
priority = 0

[[patches]]
[patches.copy]
target = "main.lua"
position = "append"
sources = [
	"talisman.lua"
]

# Show a Gold Seal to confirm Talisman is Active
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "replace_card.states.visible = false"
position = "before"
payload = "replace_card:set_seal('Gold', true, true)"
match_indent = true
overwrite = false

[[patches]]
[patches.module]
source = "nativefs.lua"
before = "main.lua"
name = "nativefs"

# Use formatted numbers for poker hand scores
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "{n=G.UIT.T, config={text = G.GAME.hands[handname].chips, scale = 0.45, colour = G.C.UI.TEXT_LIGHT}},"
position = "at"
payload = "{n=G.UIT.T, config={text = number_format(G.GAME.hands[handname].chips, 1000000), scale = 0.45, colour = G.C.UI.TEXT_LIGHT}},"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "{n=G.UIT.T, config={text = G.GAME.hands[handname].mult, scale = 0.45, colour = G.C.UI.TEXT_LIGHT}}"
position = "at"
payload = "{n=G.UIT.T, config={text = number_format(G.GAME.hands[handname].mult, 1000000), scale = 0.45, colour = G.C.UI.TEXT_LIGHT}}"
match_indent = true
overwrite = true

# Chip requirements for achievements/unlocks
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if args.chips >= 10000 then"
position = "at"
payload = "if to_big(args.chips) >= to_big(10000) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if args.chips >= 1000000 then"
position = "at"
payload = "if to_big(args.chips) >= to_big(1000000) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if args.chips >= 100000000 then"
position = "at"
payload = "if to_big(args.chips) >= to_big(100000000) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if card.unlock_condition.chips <= args.chips then"
position = "at"
payload = "if to_big(card.unlock_condition.chips) <= to_big(args.chips) then"
match_indent = true
overwrite = true

# More comparison issues
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "if hand_chips*mult > 0 then"
position = "at"
payload = "if to_big(hand_chips)*mult > to_big(0) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "if G.GAME.current_round.current_hand.chip_total < 1 then"
position = "at"
payload = "if to_big(G.GAME.current_round.current_hand.chip_total) < to_big(1) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "ease_chips(0)"
position = "at"
payload = "ease_chips(to_big(0))"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "chips = 0,"
position = "at"
payload = "chips = to_big(0),"
match_indent = true
overwrite = true

# Patch for Steamodded Sound API
[[patches]]
[patches.pattern]
target = "main.lua"
pattern = "G.ARGS.score_intensity.organ = G.video_organ or G.ARGS.score_intensity.required_score > 0 and math.max(math.min(0.4, 0.1*math.log(G.ARGS.score_intensity.earned_score/(G.ARGS.score_intensity.required_score+1), 5)),0.) or 0"
position = "at"
payload = "G.ARGS.score_intensity.organ = G.video_organ or to_big(G.ARGS.score_intensity.required_score) > to_big(0) and math.max(math.min(0.4, 0.1*math.log(G.ARGS.score_intensity.earned_score/(G.ARGS.score_intensity.required_score+1), 5)),0.) or 0"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = "G.ARGS.score_intensity.organ = G.video_organ or G.ARGS.score_intensity.required_score > 0 and math.max(math.min(0.4, 0.1*math.log(G.ARGS.score_intensity.earned_score/(G.ARGS.score_intensity.required_score+1), 5)),0.) or 0"
position = "at"
payload = "G.ARGS.score_intensity.organ = G.video_organ or to_big(G.ARGS.score_intensity.required_score) > to_big(0) and math.max(math.min(0.4, 0.1*math.log(G.ARGS.score_intensity.earned_score/(G.ARGS.score_intensity.required_score+1), 5)),0.) or 0"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "if G.ARGS.score_intensity.earned_score >= G.ARGS.score_intensity.required_score and G.ARGS.score_intensity.required_score > 0 then"
position = "at"
payload = "if to_big(G.ARGS.score_intensity.earned_score) >= to_big(G.ARGS.score_intensity.required_score) and to_big(G.ARGS.score_intensity.required_score) > to_big(0) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "if G.GAME.chips - G.GAME.blind.chips >= 0 or G.GAME.current_round.hands_left < 1 then"
position = "at"
payload = '''if to_big(G.GAME.chips) >= to_big(G.GAME.blind.chips) or G.GAME.current_round.hands_left < 1 then'''
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "if G.GAME.chips - G.GAME.blind.chips >= 0 then"
position = "at"
payload = "if to_big(G.GAME.chips) >= to_big(G.GAME.blind.chips) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "blind.lua"
pattern = "if self.boss and G.GAME.chips - G.GAME.blind.chips >= 0 then"
position = "at"
payload = "if self.boss and to_big(G.GAME.chips) - G.GAME.blind.chips >= to_big(0) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "G.GAME.chips/G.GAME.blind.chips >= 0.25 then"
position = "at"
payload = "to_big(G.GAME.chips)/G.GAME.blind.chips >= to_big(0.25) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "if not G.TAROT_INTERRUPT_PULSE then G.FUNCS.text_super_juice(e, math.max(0,math.floor(math.log10(type(G.GAME.current_round.current_hand.mult) == 'number' and G.GAME.current_round.current_hand.mult or 1)))) end"
position = "at"
payload = "if not G.TAROT_INTERRUPT_PULSE then G.FUNCS.text_super_juice(e, math.min(2,math.max(0,math.floor(math.log10(is_number(G.GAME.current_round.current_hand.mult) and G.GAME.current_round.current_hand.mult or 1))))) end"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "if not G.TAROT_INTERRUPT_PULSE then G.FUNCS.text_super_juice(e, math.max(0,math.floor(math.log10(type(G.GAME.current_round.current_hand.chips) == 'number' and G.GAME.current_round.current_hand.chips or 1)))) end"
position = "at"
payload = "if not G.TAROT_INTERRUPT_PULSE then G.FUNCS.text_super_juice(e, math.min(2,math.max(0,math.floor(math.log10(is_number(G.GAME.current_round.current_hand.chips) and G.GAME.current_round.current_hand.chips or 1))))) end"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = "if type(G.GAME.current_round.current_hand.chips) ~= 'number' or type(G.GAME.current_round.current_hand.mult) ~= 'number' then"
position = "at"
payload = "if not is_number(G.GAME.current_round.current_hand.chips) or not is_number(G.GAME.current_round.current_hand.mult) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "main.lua"
pattern = "if type(G.GAME.current_round.current_hand.chips) ~= 'number' or type(G.GAME.current_round.current_hand.mult) ~= 'number' then"
position = "at"
payload = "if not is_number(G.GAME.current_round.current_hand.chips) or not is_number(G.GAME.current_round.current_hand.mult) then"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "local delta = (type(vals.chips) == 'number' and type(G.GAME.current_round.current_hand.chips) == 'number') and (vals.chips - G.GAME.current_round.current_hand.chips) or 0"
position = "at"
payload = "local delta = (is_number(vals.chips) and is_number(G.GAME.current_round.current_hand.chips)) and (vals.chips - G.GAME.current_round.current_hand.chips) or 0"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "local delta = (type(vals.mult) == 'number' and type(G.GAME.current_round.current_hand.mult) == 'number')and (vals.mult - G.GAME.current_round.current_hand.mult) or 0"
position = "at"
payload = "local delta = (is_number(vals.mult) and is_number(G.GAME.current_round.current_hand.mult))and (vals.mult - G.GAME.current_round.current_hand.mult) or 0"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if delta < 0 then delta = ''..delta; col = G.C.RED"
position = "at"
payload = "if to_big(delta) < to_big(0) then delta = number_format(delta); col = G.C.RED"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "elseif delta > 0 then delta = '+'..delta"
position = "at"
payload = "elseif to_big(delta) > to_big(0) then delta = '+'..number_format(delta)"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "else delta = ''..delta"
position = "at"
payload = "else delta = number_format(delta)"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "engine/string_packer.lua"
pattern = 'if type_v == "table" then'
position = "after"
payload = '''
if v.m and v.e then
v = "to_big("..v.m..","..v.e..")"
elseif v.array and v.sign then
	local v0 = "to_big({"
	for qi = 1,#v.array do
		v0 = v0 .. v.array[qi] .. ", "
	end
	v0 = v0 .. "},"..v.sign..")"
	v = v0
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "engine/string_packer.lua"
pattern = 'if v.is and v:is(Object) then'
position = "at"
payload = 'elseif v.is and v:is(Object) then'
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "{n=G.UIT.O, config={object = DynaText({string = {{ref_table = G.GAME.round_resets, ref_value = 'ante'}}, colours = {G.C.IMPORTANT},shadow = true, font = G.LANGUAGES['en-us'].font, scale = 2*scale}),id = 'ante_UI_count'}},"
position = "at"
payload = "{n=G.UIT.O, config={object = DynaText({string = {{ref_table = G.GAME.round_resets, ref_value = 'ante_disp'}}, colours = {G.C.IMPORTANT},shadow = true, font = G.LANGUAGES['en-us'].font, scale = scale_number(G.GAME.round_resets.ante, 2*scale, 100)}),id = 'ante_UI_count'}},--{n=G.UIT.T, config={text = number_format(G.GAME.round_resets.ante), lang = G.LANGUAGES['en-us'], scale = scale_number(G.GAME.round_resets.ante, 2*scale, 100), colour = G.C.IMPORTANT, shadow = true,id = 'ante_UI_count'}},"
match_indent = true
overwrite = true

[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "ante = 1,"
position = "after"
payload = "ante_disp = number_format(1),"
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "G.GAME.round_resets.ante = G.GAME.round_resets.ante + mod"
position = "after"
payload = "G.GAME.round_resets.ante_disp = number_format(G.GAME.round_resets.ante)"
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "if not G.ARGS.hand_chip_total_UI_set or G.ARGS.hand_chip_total_UI_set <  G.GAME.current_round.current_hand.chip_total then"
position = "at"
payload = "if not G.ARGS.hand_chip_total_UI_set or to_big(G.ARGS.hand_chip_total_UI_set) < to_big(G.GAME.current_round.current_hand.chip_total) then"
match_indent = true
overwrite = true


# For some reason Big leaks into the text engine, this mitigates it
[[patches]]
[patches.pattern]
target = "engine/text.lua"
pattern = "if self.strings[k].W > self.config.W then self.config.W = self.strings[k].W; self.strings[k].W_offset = 0 end"
position = "before"
payload = '''
if Big then
	if type(self.strings[k].W) == 'table' then
		self.strings[k].W = self.strings[k].W:to_number()
	end
	if type(self.strings[k].H) == 'table' then
		self.strings[k].H = self.strings[k].H:to_number()
	end
end
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "engine/text.lua"
pattern = "function DynaText:draw()"
position = "after"
payload = '''
if Big then
	self.scale = to_big(self.scale):to_number()
	if self.shadow_parallax then self.shadow_parallax.x = to_big(self.shadow_parallax.x):to_number() end
end
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "engine/text.lua"
pattern = "for k, letter in ipairs(self.strings[self.focused_string].letters) do"
position = "after"
payload = '''
if Big then
	letter.dims.x = to_big(letter.dims.x):to_number()
	letter.dims.y = to_big(letter.dims.y):to_number()
	letter.offset.x = to_big(letter.offset.x):to_number()
	letter.offset.y = to_big(letter.offset.y):to_number()
end
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "engine/ui.lua"
pattern = "if _th and _tw then"
position = "after"
payload = '''
if Big then
	_th = to_big(_th):to_number()
	_tw = to_big(_tw):to_number()
end
'''
match_indent = true
overwrite = false

#these last few are causing lag, so they'll only be applied in the main menu
[[patches]]
[patches.pattern]
target = "engine/ui.lua"
pattern = "local _cw, _ch = w:set_wh()"
position = "after"
payload = "if Big and G.STATE == G.STATES.MENU then _cw = to_big(_cw):to_number(); _ch = to_big(_ch):to_number() end"
match_indent = true

[[patches]]
[patches.pattern]
target = "engine/moveable.lua"
pattern = "function Moveable:move_wh(dt)"
position = "after"
payload = '''
if Big and G.STATE == G.STATES.MENU then self.T.w = to_big(self.T.w):to_number()
self.T.h = to_big(self.T.h):to_number()
self.VT.w = to_big(self.VT.w):to_number()
self.VT.h = to_big(self.VT.h):to_number() end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/misc_functions.lua"
pattern = "function prep_draw(moveable, scale, rotate, offset)"
position = "after"
payload = '''
if Big and G.STATE == G.STATES.MENU then moveable.VT.x = to_big(moveable.VT.x):to_number()
moveable.VT.y = to_big(moveable.VT.y):to_number()
moveable.VT.w = to_big(moveable.VT.w):to_number()
moveable.VT.h = to_big(moveable.VT.h):to_number() end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "engine/ui.lua"
pattern = "if self.config.vert then love.graphics.translate(0,self.VT.h); love.graphics.rotate(-math.pi/2) end"
position = "before"
payload = '''
if Big and G.STATE == G.STATES.MENU then self.config.scale = to_big(self.config.scale):to_number() end
'''
match_indent = true

# poker hand level fixes
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "{n=G.UIT.T, config={text = localize('k_level_prefix')..G.GAME.hands[handname].level, scale = 0.5, colour = G.C.UI.TEXT_DARK}}"
position = "at"
payload = "{n=G.UIT.T, config={text = localize('k_level_prefix')..number_format(G.GAME.hands[handname].level), scale = 0.5, colour = G.C.UI.TEXT_DARK}}"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if args.level >= 10 then"
position = "at"
payload = "if to_big(args.level) >= to_big(10) then"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if type(vals.level) == 'number' then"
position = "at"
payload = "if is_number(vals.level) then"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "G.hand_text_area.hand_level.config.colour = G.C.HAND_LEVELS[math.min(vals.level, 7)]"
position = "at"
payload = "G.hand_text_area.hand_level.config.colour = G.C.HAND_LEVELS[to_number(to_big(math.min(vals.level, 7)))]"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "colours = {(G.GAME.hands[cfg.hand_type].level==1 and G.C.UI.TEXT_DARK or G.C.HAND_LEVELS[math.min(7, G.GAME.hands[cfg.hand_type].level)])}"
position = "at"
payload = "colours = {(to_big(G.GAME.hands[cfg.hand_type].level)==to_big(1) and G.C.UI.TEXT_DARK or G.C.HAND_LEVELS[to_number(to_big(math.min(7, G.GAME.hands[cfg.hand_type].level)))])}"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '{n=G.UIT.C, config={align = "cm", padding = 0.01, r = 0.1, colour = G.C.HAND_LEVELS[math.min(7, G.GAME.hands[handname].level)], minw = 1.5, outline = 0.8, outline_colour = G.C.WHITE}, nodes={'
position = "at"
payload = '{n=G.UIT.C, config={align = "cm", padding = 0.01, r = 0.1, colour = G.C.HAND_LEVELS[to_number(to_big(math.min(7, G.GAME.hands[handname].level)))], minw = 1.5, outline = 0.8, outline_colour = G.C.WHITE}, nodes={'
match_indent = true

# money fixes
[[patches]]
[patches.regex]
target = "functions/state_events.lua"
pattern = '''G\.GAME\.dollars >= 5'''
position = "at"
payload = "to_big(G.GAME.dollars) >= to_big(5)"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if G.GAME.dollars >= 400 then"
position = "at"
payload = '''if to_big(G.GAME.dollars) >= to_big(400) then'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "if ((G.GAME.dollars-G.GAME.bankrupt_at) - G.GAME.current_round.reroll_cost < 0) and G.GAME.current_round.reroll_cost ~= 0 then"
position = "at"
payload = '''if ((to_big(G.GAME.dollars)-to_big(G.GAME.bankrupt_at)) - to_big(G.GAME.current_round.reroll_cost) < to_big(0)) and G.GAME.current_round.reroll_cost ~= 0 then'''
match_indent = true

[[patches]]
[patches.regex]
target = "functions/button_callbacks.lua"
pattern = '''e\.config\.ref_table\.cost > G\.GAME\.dollars - G\.GAME\.bankrupt_at'''
position = "at"
payload = '''to_big(e.config.ref_table.cost) > to_big(G.GAME.dollars) - to_big(G.GAME.bankrupt_at)'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''if ((G.GAME.dollars-G.GAME.bankrupt_at) - 10 >= 0) and'''
position = "at"
payload = '''
if ((to_big(G.GAME.dollars)-to_big(G.GAME.bankrupt_at)) - to_big(10) >= to_big(0)) and
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = '''if card.unlock_condition.extra <= G.GAME.dollars then'''
position = "at"
payload = '''if to_big(card.unlock_condition.extra) <= to_big(G.GAME.dollars) then'''
match_indent = true

# Talisman compat for vanilla jokers 
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''if self.ability.name == 'Bull' and (G.GAME.dollars + (G.GAME.dollar_buffer or 0)) > 0 then'''
position = "at"
payload = '''if self.ability.name == 'Bull' and to_big(G.GAME.dollars + (G.GAME.dollar_buffer or 0)) > to_big(0) then'''
match_indent = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''if self.ability.name == 'Bootstraps' and math.floor((G.GAME.dollars + (G.GAME.dollar_buffer or 0))/self.ability.extra.dollars) >= 1 then'''
position = "at"
payload = '''if self.ability.name == 'Bootstraps' and to_big(math.floor((G.GAME.dollars + (G.GAME.dollar_buffer or 0))/self.ability.extra.dollars)) >= to_big(1) then'''
match_indent = true

# Vagabond
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''if G.GAME.dollars <= self.ability.extra then'''
position = "at"
payload = '''if to_big(G.GAME.dollars) <= to_big(self.ability.extra) then'''
match_indent = true

# Luxury Tax Challenge
[[patches]]
[patches.pattern]
target = "cardarea.lua"
pattern = '''self:change_size(self.config.last_poll_size - math.floor(G.GAME.dollars/G.GAME.modifiers.minus_hand_size_per_X_dollar))'''
position = "at"
payload = '''self:change_size(to_big(self.config.last_poll_size - math.floor(G.GAME.dollars/G.GAME.modifiers.minus_hand_size_per_X_dollar)):to_number())'''
match_indent = true

# for now, I'm letting dollar eval ignore bignum, I'll patch it later
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if num_dollars > 60 then"
position = "at"
payload = '''num_dollars = to_number(num_dollars); if math.abs(to_number(num_dollars)) > 60 then'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if num_dollars > 60 or num_dollars < -60 then"
position = "at"
payload = '''num_dollars = to_number(num_dollars); if math.abs(to_number(num_dollars)) > 60 then'''
match_indent = true

# This one also patches some extra stuff, but shouldn't cause any trouble
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if mod < 0 then"
position = "at"
payload = "if to_big(mod) < to_big(0) then"
match_indent = true

[[patches]]
[patches.pattern]
target = "blind.lua"
pattern = "if G.GAME.hands[handname].level > 1 then"
position = "at"
payload = "if to_big(G.GAME.hands[handname].level) > to_big(1) then"
match_indent = true

# call init game object appendum after init game object
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "if new_game_obj then self.GAME = self:init_game_object() end"
position = "after"
payload =  "if Talisman and Talisman.igo then self.GAME = Talisman.igo(self.GAME) end"
match_indent = true
overwrite = false

# call init game object appendum after init game object
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "self.GAME = saveTable and saveTable.GAME or self:init_game_object()"
position = "after"
payload =  "if Talisman and Talisman.igo then self.GAME = Talisman.igo(self.GAME) end"
match_indent = true
overwrite = false

# remove more animations from event queue
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "if effects[ii].card then"
position = "at"
payload = "if effects[ii].card and not Talisman.config_file.disable_anims then"
match_indent = true
overwrite = false

#enhancement animation removing
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "if self.edition and not silent then"
position = "at"
payload = "if self.edition and (not Talisman.config_file.disable_anims or (not Talisman.calculating_joker and not Talisman.calculating_score and not Talisman.calculating_card)) and not silent then"
match_indent = true
overwrite = false

# dollar buffer thingy
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "G.E_MANAGER:add_event(Event({func = (function() G.GAME.dollar_buffer = 0; return true end)}))"
position = "at"
payload = "if not Talisman.config_file.disable_anims then G.E_MANAGER:add_event(Event({func = (function() G.GAME.dollar_buffer = 0; return true end)})) else G.GAME.dollar_buffer = 0 end"
match_indent = true
overwrite = false

# add card
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "if G.GAME.blind then G.E_MANAGER:add_event(Event({ func = function() G.GAME.blind:set_blind(nil, true, nil); return true end })) end"
position = "at"
payload = "if G.GAME.blind and (not SMODS or G.GAME.blind.in_blind) and not (Talisman.config_file.disable_anims and (Talisman.calculating_joker or Talisman.calculating_score or Talisman.calculating_card)) then G.E_MANAGER:add_event(Event({ func = function() G.GAME.blind:set_blind(nil, true, nil); return true end })) end"
match_indent = true
overwrite = false

# hand level ups
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if not instant then"
position = "at"
payload = "if not instant and not Talisman.config_file.disable_anims then"
match_indent = true
overwrite = false

# Juice Issues
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "func = (function() card:juice_up(0.7);return true end)"
position = "at"
payload = "func = (function() if card and card.juice_up then card:juice_up(0.7) end;return true end)"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if card then card:juice_up(0.8, 0.5) end"
position = "at"
payload = "if card and card.juice_up then card:juice_up(0.8, 0.5) end"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "card:juice_up(0.6, 0.1)"
position = "at"
payload = "if card and card.juice_up then card:juice_up(0.6, 0.1) end"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "func = (function() if eval_func(card) then if not first or first then card:juice_up(0.1, 0.1) end;juice_card_until(card, eval_func, nil, 0.8) end return true end)"
position = "at"
payload = "func = (function() if eval_func(card) then if card and card.juice_up then card:juice_up(0.1, 0.1) end;juice_card_until(card, eval_func, nil, 0.8) end return true end)"
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "func = (function() if eval_func(card) then if not first or first then card:juice_up(0.1, 0.1) end;juice_card_until(card, eval_func, nil, 0.8) end return true end)"
position = "at"
payload = "func = (function() if eval_func(card) then if card and card.juice_up then card:juice_up(0.1, 0.1) end;juice_card_until(card, eval_func, nil, 0.8) end return true end)"
match_indent = true

# return eval_round value
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "add_round_eval_row({name = 'bottom', dollars = dollars})"
position = "after"
payload = "Talisman.dollars = dollars"
match_indent = true

# arbitrary operations on chips and mult
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "if effects.jokers.Xmult_mod then mult = mod_mult(mult*effects.jokers.Xmult_mod);extras.mult = true  end"
position = "after"
payload = '''
if effects.jokers.Emult_mod then mult = mod_mult(mult^effects.jokers.Emult_mod);extras.mult = true end
if effects.jokers.EEmult_mod then mult = mod_mult(mult:arrow(2, effects.jokers.EEmult_mod));extras.mult = true end
if effects.jokers.EEEmult_mod then mult = mod_mult(mult:arrow(3, effects.jokers.EEEmult_mod));extras.mult = true end
if effects.jokers.hypermult_mod and type(effects.jokers.hypermult_mod) == 'table' then mult = mod_mult(mult:arrow(effects.jokers.hypermult_mod[1], effects.jokers.hypermult_mod[2]));extras.mult = true end
if effects.jokers.Xchip_mod then hand_chips = mod_chips(hand_chips*effects.jokers.Xchip_mod);extras.hand_chips = true end
if effects.jokers.Echip_mod then hand_chips = mod_chips(hand_chips^effects.jokers.Echip_mod);extras.hand_chips = true end
if effects.jokers.EEchip_mod then hand_chips = mod_chips(hand_chips:arrow(2, effects.jokers.EEchip_mod));extras.hand_chips = true end
if effects.jokers.EEEchip_mod then hand_chips = mod_chips(hand_chips:arrow(3, effects.jokers.EEEchip_mod));extras.hand_chips = true end
if effects.jokers.hyperchip_mod and type(effects.jokers.hyperchip_mod) == 'table' then hand_chips = mod_chips(hand_chips:arrow(effects.jokers.hyperchip_mod[1], effects.jokers.hyperchip_mod[2]));extras.hand_chips = true end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "if effect.Xmult_mod then mult = mod_mult(mult*effect.Xmult_mod);extras.mult = true  end"
position = "after"
payload = '''
if effect.Emult_mod then mult = mod_mult(mult^effect.Emult_mod);extras.mult = true end
if effect.EEmult_mod then mult = mod_mult(mult:arrow(2, effect.EEmult_mod));extras.mult = true end
if effect.EEEmult_mod then mult = mod_mult(mult:arrow(3, effect.EEEmult_mod));extras.mult = true end
if effect.hypermult_mod and type(effect.hypermult_mod) == 'table' then mult = mod_mult(mult:arrow(effect.hypermult_mod[1], effect.hypermult_mod[2]));extras.mult = true end
if effect.Xchip_mod then hand_chips = mod_chips(hand_chips*effect.Xchip_mod);extras.hand_chips = true end
if effect.Echip_mod then hand_chips = mod_chips(hand_chips^effect.Echip_mod);extras.hand_chips = true end
if effect.EEchip_mod then hand_chips = mod_chips(hand_chips:arrow(2, effect.EEchip_mod));extras.hand_chips = true end
if effect.EEEchip_mod then hand_chips = mod_chips(hand_chips:arrow(3, effect.EEEchip_mod));extras.hand_chips = true end
if effect.hyperchip_mod and type(effect.hyperchip_mod) == 'table' then hand_chips = mod_chips(hand_chips:arrow(effect.hyperchip_mod[1], effect.hyperchip_mod[2]));extras.hand_chips = true end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "x_mult = center.config.Xmult or 1,"
position = "after"
payload = '''
e_mult = center.config.Emult or 0,
ee_mult = center.config.EEmult or 0,
eee_mult = center.config.EEEmult or 0,
hyper_mult = type(center.config.Hmult) == 'table' and center.config.Hmult or {0, 0},
x_chips = center.config.Xchips or 0,
e_chips = center.config.Echips or 0,
ee_chips = center.config.EEchips or 0,
eee_chips = center.config.EEEchips or 0,
hyper_chips = type(center.config.Hchips) == 'table' and center.config.Hchips or {0, 0},
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "local p_dollars = card:get_p_dollars()"
position = "before"
payload = '''
local x_chips = card:get_chip_x_bonus()
if x_chips > 0 then
	ret.x_chips = x_chips
end

local e_chips = card:get_chip_e_bonus()
if e_chips > 0 then
	ret.e_chips = e_chips
end

local ee_chips = card:get_chip_ee_bonus()
if ee_chips > 0 then
	ret.ee_chips = ee_chips
end

local eee_chips = card:get_chip_eee_bonus()
if eee_chips > 0 then
	ret.eee_chips = eee_chips
end

local hyper_chips = card:get_chip_hyper_bonus()
if type(hyper_chips) == 'table' and hyper_chips[1] > 0 and hyper_chips[2] > 0 then
	ret.hyper_chips = hyper_chips
end

local e_mult = card:get_chip_e_mult()
if e_mult > 0 then
	ret.e_mult = e_mult
end

local ee_mult = card:get_chip_ee_mult()
if ee_mult > 0 then
	ret.ee_mult = ee_mult
end

local eee_mult = card:get_chip_eee_mult()
if eee_mult > 0 then
	ret.eee_mult = eee_mult
end

local hyper_mult = card:get_chip_hyper_mult()
if type(hyper_mult) == 'table' and hyper_mult[1] > 0 and hyper_mult[2] > 0 then
	ret.hyper_mult = hyper_mult
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "elseif eval_type == 'dollars' then"
position = "before"
payload = '''
elseif eval_type == 'x_chips' then 
	sound = 'talisman_xchip'
	amt = amt
	text = 'X' .. amt
	colour = G.C.CHIPS
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'e_chips' then 
	sound = 'talisman_echip'
	amt = amt
	text = '^' .. amt
	colour = G.C.CHIPS
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'ee_chips' then 
	sound = 'talisman_eechip'
	amt = amt
	text = '^^' .. amt
	colour = G.C.CHIPS
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'eee_chips' then 
	sound = 'talisman_eeechip'
	amt = amt
	text = '^^^' .. amt
	colour = G.C.CHIPS
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'hyper_chips' then
	sound = 'talisman_eeechip'
	text = (amt[1] > 5 and ('{' .. tostring(amt[1]) .. '}') or string.rep('^', amt[1])) .. tostring(amt[2])
	amt = amt[2]
	colour = G.C.CHIPS
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'e_mult' then 
	sound = 'talisman_emult'
	amt = amt
	text = '^' .. amt .. ' Mult'
	colour = G.C.MULT
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'ee_mult' then 
	sound = 'talisman_eemult'
	amt = amt
	text = '^^' .. amt .. ' Mult'
	colour = G.C.MULT
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'eee_mult' then 
	sound = 'talisman_eeemult'
	amt = amt
	text = '^^^' .. amt .. ' Mult'
	colour = G.C.MULT
	config.type = 'fade'
	config.scale = 0.7
elseif eval_type == 'hyper_mult' then 
	sound = 'talisman_eeemult'
	text = (amt[1] > 5 and ('{' .. tostring(amt[1]) .. '}') or string.rep('^', amt[1])) .. tostring(amt[2]) .. ' Mult'
	amt = amt[2]
	colour = G.C.MULT
	config.type = 'fade'
	config.scale = 0.7
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "if effects[ii].message then"
position = "before"
payload = '''
if effects[ii].x_chips then
	mod_percent = true
	hand_chips = mod_chips(hand_chips*effects[ii].x_chips)
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(G.hand.cards[i], 'x_chips', effects[ii].x_chips, percent)
end
if effects[ii].e_chips then
	mod_percent = true
	hand_chips = mod_chips(hand_chips^effects[ii].e_chips)
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(G.hand.cards[i], 'e_chips', effects[ii].e_chips, percent)
end
if effects[ii].ee_chips then
	mod_percent = true
	hand_chips = mod_chips(hand_chips:arrow(2, effects[ii].ee_chips))
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(G.hand.cards[i], 'ee_chips', effects[ii].ee_chips, percent)
end
if effects[ii].eee_chips then
	mod_percent = true
	hand_chips = mod_chips(hand_chips:arrow(3, effects[ii].eee_chips))
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(G.hand.cards[i], 'eee_chips', effects[ii].eee_chips, percent)
end
if effects[ii].hyper_chips and type(effects[ii].hyper_chips) == 'table' then
	mod_percent = true
	hand_chips = mod_chips(hand_chips:arrow(effects[ii].hyper_chips[1], effects[ii].hyper_chips[2]))
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(G.hand.cards[i], 'hyper_chips', effects[ii].hyper_chips, percent)
end
if effects[ii].e_mult then
	mod_percent = true
	mult = mod_mult(mult^effects[ii].e_mult)
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(G.hand.cards[i], 'e_mult', effects[ii].e_mult, percent)
end
if effects[ii].ee_mult then
	mod_percent = true
	mult = mod_mult(mult:arrow(2, effects[ii].ee_mult))
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(G.hand.cards[i], 'ee_mult', effects[ii].ee_mult, percent)
end
if effects[ii].eee_mult then
	mod_percent = true
	mult = mod_mult(mult:arrow(3, effects[ii].eee_mult))
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(G.hand.cards[i], 'eee_mult', effects[ii].eee_mult, percent)
end
if effects[ii].hyper_mult and type(effects[ii].hyper_mult) == 'table' then
	mod_percent = true
	mult = mod_mult(mult:arrow(effects[ii].hyper_mult[1], effects[ii].hyper_mult[2]))
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(G.hand.cards[i], 'hyper_mult', effects[ii].hyper_mult, percent)
end

'''
match_indent = true

# sfx
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "sound = extra.edition and 'foil2' or extra.mult_mod and 'multhit1' or extra.Xmult_mod and 'multhit2' or 'generic1'"
position = "at"
payload = '''sound = extra.edition and 'foil2' or extra.mult_mod and 'multhit1' or extra.Xmult_mod and 'multhit2' or extra.Xchip_mod and 'talisman_xchip' or extra.Echip_mod and 'talisman_echip' or extra.Emult_mod and 'talisman_emult' or extra.EEchip_mod and 'talisman_eechip' or extra.EEmult_mod and 'talisman_eemult' or (extra.EEEchip_mod or extra.hyperchip_mod) and 'talisman_eeechip' or (extra.EEEmult_mod or extra.hypermult_mod) and 'talisman_eeemult' or 'generic1'
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "--calculate the card edition effects"
position = "before"
payload = '''
if effects[ii].x_chips then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	hand_chips = mod_chips(hand_chips*effects[ii].x_chips)
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(scoring_hand[i], 'x_chips', effects[ii].x_chips, percent)
end
if effects[ii].e_chips then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	hand_chips = mod_chips(hand_chips^effects[ii].e_chips)
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(scoring_hand[i], 'e_chips', effects[ii].e_chips, percent)
end
if effects[ii].ee_chips then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	hand_chips = mod_chips(hand_chips:arrow(2, effects[ii].ee_chips))
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(scoring_hand[i], 'ee_chips', effects[ii].ee_chips, percent)
end
if effects[ii].eee_chips then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	hand_chips = mod_chips(hand_chips:arrow(3, effects[ii].eee_chips))
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(scoring_hand[i], 'eee_chips', effects[ii].eee_chips, percent)
end
if effects[ii].hyper_chips and type(effects[ii].hyper_chips) == 'table' then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	hand_chips = mod_chips(hand_chips:arrow(effects[ii].hyper_chips[1], effects[ii].hyper_chips[2]))
	update_hand_text({delay = 0}, {chips = hand_chips})
	card_eval_status_text(scoring_hand[i], 'hyper_chips', effects[ii].hyper_chips, percent)
end
if effects[ii].e_mult then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	mult = mod_mult(mult^effects[ii].e_mult)
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(scoring_hand[i], 'e_mult', effects[ii].e_mult, percent)
end
if effects[ii].ee_mult then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	mult = mod_mult(mult:arrow(2, effects[ii].ee_mult))
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(scoring_hand[i], 'ee_mult', effects[ii].ee_mult, percent)
end
if effects[ii].eee_mult then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	mult = mod_mult(mult:arrow(3, effects[ii].eee_mult))
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(scoring_hand[i], 'eee_mult', effects[ii].eee_mult, percent)
end
if effects[ii].hyper_mult and type(effects[ii].hyper_mult) == 'table' then
	mod_percent = true
	if effects[ii].card then juice_card(effects[ii].card) end
	mult = mod_mult(mult:arrow(effects[ii].hyper_mult[1], effects[ii].hyper_mult[2]))
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(scoring_hand[i], 'hyper_mult', effects[ii].hyper_mult, percent)
end

'''
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = 'if effects[ii].edition.p_dollars_mod then'
position = 'before'
match_indent = true
payload = '''
if scoring_hand and scoring_hand[i] and scoring_hand[i].edition then
	local trg = scoring_hand[i]
	local edi = trg.edition
	if edi.x_chips then
		hand_chips = mod_chips(hand_chips * edi.x_chips)
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = 'X'.. edi.x_chips ,
		edition = true,
		x_chips = true})
	end
	if edi.e_chips then
		hand_chips = mod_chips(hand_chips ^ edi.e_chips)
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^'.. edi.e_chips ,
		edition = true,
		e_chips = true})
	end
	if edi.ee_chips then
		hand_chips = mod_chips(hand_chips:arrow(2, edi.ee_chips))
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^'.. edi.ee_chips ,
		edition = true,
		ee_chips = true})
	end
	if edi.eee_chips then
		hand_chips = mod_chips(hand_chips:arrow(3, edi.eee_chips))
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^^'.. edi.eee_chips ,
		edition = true,
		eee_chips = true})
	end
	if edi.hyper_chips and type(edi.hyper_chips) == 'table' then
		hand_chips = mod_chips(hand_chips:arrow(edi.hyper_chips[1], edi.hyper_chips[2]))
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = (edi.hyper_chips[1] > 5 and ('{' .. edi.hyper_chips[1] .. '}') or string.rep('^', edi.hyper_chips[1])) .. edi.hyper_chips[2] ,
		edition = true,
		eee_chips = true})
	end
	if edi.e_mult then
		mult = mod_mult(mult ^ edi.e_mult)
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^'.. edi.e_mult ..' Mult',
		edition = true,
		e_mult = true})
	end
	if edi.ee_mult then
		mult = mod_mult(mult:arrow(2, edi.ee_mult))
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^'.. edi.ee_mult ..' Mult',
		edition = true,
		ee_mult = true})
	end
	if edi.eee_mult then
		mult = mod_mult(mult:arrow(3, edi.eee_mult))
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^^'.. edi.eee_mult ..' Mult',
		edition = true,
		eee_mult = true})
	end
	if edi.hyper_mult and type(edi.hyper_mult) == 'table' then
		mult = mod_mult(mult:arrow(edi.hyper_mult[1], edi.hyper_mult[2]))
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = (edi.hyper_mult[1] > 5 and ('{' .. edi.hyper_mult[1] .. '}') or string.rep('^', edi.hyper_mult[1])) .. edi.hyper_mult[2] ..' Mult',
		edition = true,
		hyper_mult = true})
	end
end
'''

# my fix for this one is really scuffed
[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = 'if edition_effects.jokers.x_mult_mod then'
position = 'before'
match_indent = true
payload = '''
if edition_effects.jokers.x_mult_mod then
	mult = mod_mult(mult*edition_effects.jokers.x_mult_mod)
	update_hand_text({delay = 0}, {mult = mult})
	card_eval_status_text(_card, 'jokers', nil, percent, nil, {
		message = localize{type='variable',key='a_xmult',vars={edition_effects.jokers.x_mult_mod}},
		x_mult_mod =  edition_effects.jokers.x_mult_mod,
		colour =  G.C.EDITION,
		edition = true})
end
if G.jokers.cards and G.jokers.cards[i] and G.jokers.cards[i].edition then
	local trg = G.jokers.cards[i]
	local edi = trg.edition
	if edi.x_chips then
		hand_chips = mod_chips(hand_chips * edi.x_chips)
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = 'X'.. edi.x_chips ,
		edition = true,
		x_chips = true})
	end
	if edi.e_chips then
		hand_chips = mod_chips(hand_chips ^ edi.e_chips)
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^'.. edi.e_chips ,
		edition = true,
		e_chips = true})
	end
	if edi.ee_chips then
		hand_chips = mod_chips(hand_chips:arrow(2, edi.ee_chips))
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^'.. edi.ee_chips ,
		edition = true,
		ee_chips = true})
	end
	if edi.eee_chips then
		hand_chips = mod_chips(hand_chips:arrow(3, edi.eee_chips))
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^^'.. edi.eee_chips ,
		edition = true,
		eee_chips = true})
	end
	if edi.hyper_chips and type(edi.hyper_chips) == 'table' then
		hand_chips = mod_chips(hand_chips:arrow(edi.hyper_chips[1], edi.hyper_chips[2]))
		update_hand_text({delay = 0}, {chips = hand_chips})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = (edi.hyper_chips[1] > 5 and ('{' .. edi.hyper_chips[1] .. '}') or string.rep('^', edi.hyper_chips[1])) .. edi.hyper_chips[2] ,
		edition = true,
		eee_chips = true})
	end
	if edi.e_mult then
		mult = mod_mult(mult ^ edi.e_mult)
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^'.. edi.e_mult ..' Mult',
		edition = true,
		e_mult = true})
	end
	if edi.ee_mult then
		mult = mod_mult(mult:arrow(2, edi.ee_mult))
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^'.. edi.ee_mult ..' Mult',
		edition = true,
		ee_mult = true})
	end
	if edi.eee_mult then
		mult = mod_mult(mult:arrow(3, edi.eee_mult))
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = '^^^'.. edi.eee_mult ..' Mult',
		edition = true,
		eee_mult = true})
	end
	if edi.hyper_mult and type(edi.hyper_mult) == 'table' then
		mult = mod_mult(mult:arrow(edi.hyper_mult[1], edi.hyper_mult[2]))
		update_hand_text({delay = 0}, {mult = mult})
		card_eval_status_text(trg, 'extra', nil, percent, nil,
		{message = (edi.hyper_mult[1] > 5 and ('{' .. edi.hyper_mult[1] .. '}') or string.rep('^', edi.hyper_mult[1])) .. edi.hyper_mult[2] ..' Mult',
		edition = true,
		hyper_mult = true})
	end
end
edition_effects.jokers.x_mult_mod = nil
'''

# naneinf crash fixes
[[patches]]
[patches.pattern]
target = 'functions/misc_functions.lua'
pattern = "if G.GAME.round_scores[score] and math.floor(amt) > G.GAME.round_scores[score].amt then"
position = "at"
payload = '''
if G.GAME.round_scores[score] and math.floor(amt) > (G.GAME.round_scores[score].amt or 0) then'''
match_indent = true

[[patches]]
[patches.pattern]
target = 'game.lua'
pattern = "function Game:update_hand_played(dt)"
position = "after"
payload = '''
G.GAME.chips = (G.GAME.chips or 0)
G.GAME.blind.chips = (G.GAME.blind.chips or math.huge)'''
match_indent = true
# Naneinf crash fixes end

# Scoring coroutine
[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = "check_for_unlock({type = 'play_all_hearts'})"
position = 'before'
payload = 'if G.SCORING_COROUTINE then return false end '
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = '''                       G.STATE_COMPLETE = false
                        return true
'''
position = 'before'
payload = 'if G.SCORING_COROUTINE then return false end '
match_indent = false

# Don't crash in vanilla with big numbers in UI
[[patches]]
[patches.pattern]
target = 'functions/misc_functions.lua'
pattern = "assembled_string = assembled_string..(type(subpart) == 'string' and subpart or args.vars[tonumber(subpart[1])] or 'ERROR')"
position = 'before'
payload = '''
if not SMODS and type(subpart) ~= 'string' then 
	if type(args.vars[tonumber(subpart[ 1 ])]) ~= 'number' then
		args.vars[tonumber(subpart[ 1 ])] = tostring(args.vars[tonumber(subpart[ 1 ])])
	else
		args.vars[tonumber(subpart[ 1 ])] = number_format(args.vars[tonumber(subpart[ 1 ])], 1000000)
	end
end
'''
match_indent = false

# Patch save manager to do Talisman things
[[patches]]
[patches.pattern]
target = 'engine/save_manager.lua'
pattern = 'CHANNEL = love.thread.getChannel("save_request")'
position = 'after'
payload = '''
function tal_compress_and_save(_file, _data, talisman)
  local save_string = type(_data) == 'table' and STR_PACK(_data) or _data
  local fallback_save = STR_PACK({GAME = {won = true}}) --just bare minimum to not crash, maybe eventually display some info?
  if talisman == 'bignumber' then
    fallback_save = "if not BigMeta then " .. fallback_save
  elseif talisman == 'omeganum' then
    fallback_save = "if not OmegaMeta then " .. fallback_save
  else
    fallback_save = "if BigMeta or OmegaMeta then " .. fallback_save
  end
  fallback_save = fallback_save .. " end"
  save_string = fallback_save .. " " .. save_string
  save_string = love.data.compress('string', 'deflate', save_string, 1)
  love.filesystem.write(_file,save_string)
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = 'engine/save_manager.lua'
pattern = "compress_and_save(prefix_profile..'save.jkr', request.save_table)"
position = 'at'
payload = "tal_compress_and_save(prefix_profile..'save.jkr', request.save_table, request.talisman)"
match_indent = true

[[patches]]
[patches.pattern]
target = 'game.lua'
pattern = "type = 'save_run',"
position = 'after'
payload = 'talisman = Talisman.config_file.break_infinity,'
match_indent = true

# Fix some card_eval_status_text crashes
[[patches]]
[patches.pattern]
target = 'functions/common_events.lua'
pattern = "text = localize{type='variable',key='a_chips'..(amt<0 and '_minus' or ''),vars={math.abs(amt)}}"
position = 'at'
payload = "text = localize{type='variable',key='a_chips'..(to_big(amt)<to_big(0) and '_minus' or ''),vars={math.abs(amt)}}"
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/common_events.lua'
pattern = "text = localize{type='variable',key='a_mult'..(amt<0 and '_minus' or ''),vars={math.abs(amt)}}"
position = 'at'
payload = "text = localize{type='variable',key='a_mult'..(to_big(amt)<to_big(0) and '_minus' or ''),vars={math.abs(amt)}}"
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/common_events.lua'
pattern = "text = localize{type='variable',key='a_xmult'..(amt<0 and '_minus' or ''),vars={math.abs(amt)}}"
position = 'at'
payload = "text = localize{type='variable',key='a_xmult'..(to_big(amt)<to_big(0) and '_minus' or ''),vars={math.abs(amt)}}"
match_indent = true

# Fully split up evaluate_play
# This allows mods' lovely patches to still work fine while also letting Talisman's abort feature work
[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = "G.FUNCS.evaluate_play = function(e)"
position = 'at'
payload = "function evaluate_play_intro()"
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = "if not G.GAME.blind:debuff_hand(G.play.cards, poker_hands, text) then"
position = 'at'
payload = '''return text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta
end
function evaluate_play_main(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
'''
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = '''
else
    mult = mod_mult(0)
'''
position = 'at'
payload = '''
return text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta
end
function evaluate_play_debuff(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
	mult = mod_mult(0)
'''
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = '''
end
G.E_MANAGER:add_event(Event({
	trigger = 'after',delay = 0.4,
'''
position = 'at'
payload = '''
return text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta
end
function evaluate_play_final_scoring(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
G.E_MANAGER:add_event(Event({
	trigger = 'after',delay = 0.4,
'''
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = '''
	func = (function() G.GAME.current_round.current_hand.handname = '';return true end)
}))
delay(0.3)
'''
position = 'at'
payload = '''
	func = (function() G.GAME.current_round.current_hand.handname = '';return true end)
}))
delay(0.3)
return text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta
end
function evaluate_play_after(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
'''
match_indent = true

# Let shaders not use bignums
[[patches]]
[patches.pattern]
target = 'engine/sprite.lua'
pattern = "G.SHADERS[_shader]:send(v.name, v.val or (v.func and v.func()) or v.ref_table[v.ref_value])"
position = 'at'
payload = '''local val = v.val or (v.func and v.func()) or v.ref_table[v.ref_value]
if type(val) == "table" and is_number(val) then
	if val > to_big(1e300) then
		val = 1e300
	else
		val = val:tonumber()
	end
end
G.SHADERS[_shader]:send(v.name, val)'''
match_indent = true

# Let ambient sounds not use bignums
[[patches]]
[patches.pattern]
target = 'functions/misc_functions.lua'
pattern = "AC[k].vol = (not G.video_organ and G.STATE == G.STATES.SPLASH) and 0 or AC[k].vol and v.volfunc(AC[k].vol) or 0"
position = 'after'
payload = '''
if type(AC[k].vol) == "table" then
	if AC[k].vol > to_big(1e300) then
		AC[k].vol = 1e300
	else
		AC[k].vol = AC[k].vol:to_number()
	end
end
if type(AC[k].per) == "table" then
	if AC[k].per > to_big(1e300) then
		AC[k].per = 1e300
	else
		AC[k].per = AC[k].per:to_number()
	end
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = 'functions/button_callbacks.lua'
pattern = "_F.intensity = ((G.pack_cards and not G.pack_cards.REMOVED) or (G.TAROT_INTERRUPT)) and 0 or math.max(0., math.log(G.ARGS.score_intensity.earned_score, 5)-2)"
position = 'after'
payload = '''if type(_F.intensity) == "table" then
	if _F.intensity > to_big(1e300) then
		_F.intensity = 1e300
	else
		_F.intensity = _F.intensity:to_number()
	end
end
'''
match_indent = true

# G.funcs.evaluate_play()
[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
position = 'at'
match_indent = true
pattern = '''
G.E_MANAGER:add_event(Event({
    trigger = 'immediate',
    func = function()
        G.FUNCS.evaluate_play()
        return true
    end
}))
'''
payload = '''
G.E_MANAGER:add_event(Event({
    trigger = 'immediate',
    func = function()
        G.FUNCS.evaluate_play(e)
        return true
    end
}))
'''