-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
582 lines (581 loc) · 28.2 KB
/
Copy pathcore.lua
File metadata and controls
582 lines (581 loc) · 28.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
local compiler=require('ghostloop.compiler')
local L = {version='0.1.0', route=require('ghostloop.route'), visible=true,
running=false, paused=false, mode='idle', status='Ready', detail='F8 opens Ghost Loop',
speed='Turbo', budget_ms=25, target=10000, cycles=0, money_cycles=0, actions=0,
judgements=0, negatives=0, colas=0, histogram={}, step=0, buttons={}}
function L.center_candidates(center)
if not L.fast or not center or not L.center_index then return G.P_CENTERS end
return L.center_index[center.name] or G.P_CENTERS
end
local function index_centers()
L.center_index={}
local identities={}
for key,center in pairs(G.P_CENTERS) do
if identities[center] then L.center_index=nil;return end
identities[center]=true
if center.name then
local list=L.center_index[center.name] or {}
list[key]=center;L.center_index[center.name]=list
end
end
end
local phase_names = {BLIND_SELECT='blind_select', SELECTING_HAND='selecting_hand',
SHOP='shop', ROUND_EVAL='round_eval', TAROT_PACK='tarot_pack', PLANET_PACK='planet_pack',
SPECTRAL_PACK='spectral_pack', STANDARD_PACK='standard_pack', BUFFOON_PACK='buffoon_pack',
PLAY_TAROT='play_tarot', GAME_OVER='game_over'}
function L.phase()
if not G or not G.STATES then return 'loading' end
for k,v in pairs(phase_names) do if G.STATE==G.STATES[k] then return v end end
return 'menu'
end
local function blocking()
if not G.E_MANAGER then return true end
for _,q in pairs(G.E_MANAGER.queues) do
for _,e in ipairs(q) do if e.blocking and not e.complete then return true end end
end
return false
end
function L.ready()
if not G or not G.GAME or G.OVERLAY_MENU or G.SETTINGS.paused then return false end
if G.CONTROLLER.lock_input or G.CONTROLLER.locked or (G.GAME.STOP_USE or 0)>0 then return false end
for k,v in pairs(G.CONTROLLER.locks or {}) do if v and k~='load' then return false end end
if blocking() then return false end
local p=L.phase()
if p=='shop' then return G.STATE_COMPLETE and G.shop and G.shop_jokers and G.shop_booster end
if p=='blind_select' then return G.STATE_COMPLETE and G.blind_select and G.blind_select_opts end
if p=='selecting_hand' then return G.STATE_COMPLETE and G.hand and #G.hand.cards>0 and (G.GAME.STOP_USE or 0)<=0 end
if p=='round_eval' then return G.STATE_COMPLETE and G.round_eval end
if p:find('_pack$') then return G.pack_cards and G.GAME.pack_choices end
return false
end
local function card_key(c) return c.config.center.key end
local function find(zone,selector)
assert(G[zone] and G[zone].cards,'Missing card area: '..zone)
local found
for _,c in ipairs(G[zone].cards) do
local yes=selector.key and card_key(c)==selector.key or
(selector.rank and c.base.value==selector.rank and c.base.suit==selector.suit)
if yes then assert(not found,'Ambiguous card selection'); found=c end
end
assert(found,'Route differs: missing '..(selector.key or (selector.rank..' '..selector.suit)))
return found
end
local function keys(zone)
local out={}
for _,c in ipairs(G[zone] and G[zone].cards or {}) do out[#out+1]=card_key(c) end
return out
end
local function same(a,b)
if #a~=#b then return false end
for i,v in ipairs(a) do if v~=b[i] then return false end end
return true
end
function L.verify(expect)
if not expect then return end
local actual={phase=L.phase(),ante=G.GAME.round_resets.ante,round=G.GAME.round,
money=G.GAME.dollars,score=G.GAME.chips,reroll_cost=G.GAME.current_round.reroll_cost,
jokers=keys('jokers'),consumables=keys('consumeables'),shop=keys('shop_jokers')}
for k,v in pairs(expect) do
local ok=type(v)=='table' and same(actual[k],v) or actual[k]==v
assert(ok,'Route differs after step '..L.step..': '..k..' (expected '..
(type(v)=='table' and table.concat(v,',') or tostring(v))..', got '..
(type(actual[k])=='table' and table.concat(actual[k],',') or tostring(actual[k]))..')')
end
end
local function wait_ready()
local stable=0
for i=1,12000 do
coroutine.yield('wait')
if L.phase()=='game_over' then error('The run ended; automation stopped') end
if L.ready() then stable=stable+1 else stable=0 end
if stable>=3 then return end
end
error('Game did not settle; automation stopped')
end
local function select_cards(selectors)
G.hand:unhighlight_all()
for i,s in ipairs(selectors) do
local c=find('hand',s)
c.T.x=i;if c.VT then c.VT.x=i end
G.hand:add_to_highlighted(c,true)
end
end
local fast_use_no_effect={c_fool=true,c_emperor=true,c_hermit=true,c_temperance=true,c_judgement=true}
local function fast_use(card)
local area=card.area
assert(area==G.consumeables and card.ability.set=='Tarot','Fast use only accepts owned Tarots')
assert(not card:check_use(),'Card use was rejected')
G.TAROT_INTERRUPT=G.STATES.SHOP;G.STATE=G.STATES.PLAY_TAROT
G.CONTROLLER.locks.use=true
area:remove_card(card);G.play:emplace(card)
card:use_consumeable(area)
-- These five shop Tarots have no vanilla using-consumable Joker effect
-- beyond Fortune Teller's popup. Its value uses the native usage counter.
if SMODS or G.VERSION~='1.0.1o-FULL' or not fast_use_no_effect[card.config.center.key] then
for _,joker in ipairs(G.jokers.cards) do joker:calculate_joker({using_consumeable=true,consumeable=card}) end
end
G.E_MANAGER:add_event(Event({trigger='after',delay=0.2,func=function()
card:start_dissolve()
G.E_MANAGER:add_event(Event({trigger='after',delay=0.1,func=function()
G.STATE=G.STATES.SHOP;G.TAROT_INTERRUPT=nil;G.CONTROLLER.locks.use=false
return true
end}))
return true
end}))
end
function L.perform(a)
assert(L.ready(),'Game is busy')
local p,t=L.phase(),a.type
local e={config={}}
if t=='select_blind' then
assert(p=='blind_select' and G.GAME.blind_on_deck==a.blind,'Wrong blind')
e.config.ref_table=G.P_BLINDS[G.GAME.round_resets.blind_choices[a.blind]]
G.FUNCS.select_blind(e)
elseif t=='play' or t=='discard' then
assert(p=='selecting_hand','No playable hand')
assert(#a.cards>0 and #a.cards<=G.hand.config.highlighted_limit,'Invalid hand size')
if t=='discard' then assert(G.GAME.current_round.discards_left>0,'No discards left') end
select_cards(a.cards)
if t=='play' then G.FUNCS.play_cards_from_highlighted(e)
else G.FUNCS.discard_cards_from_highlighted(e) end
elseif t=='cash_out' then
assert(p=='round_eval','Round is not over');G.FUNCS.cash_out(e)
elseif t=='end_shop' then
assert(p=='shop','Not in a shop');G.FUNCS.toggle_shop(e)
elseif t=='reroll_shop' then
assert(p=='shop','Not in a shop')
assert(G.GAME.dollars-(G.GAME.bankrupt_at or 0)>=G.GAME.current_round.reroll_cost,'Insufficient reroll money')
G.FUNCS.reroll_shop(e)
elseif t=='buy' then
assert(p=='shop','Not in a shop');local c=find(a.area,a.card)
assert(c.cost<=G.GAME.dollars-(G.GAME.bankrupt_at or 0),'Insufficient purchase money')
if c.ability.set=='Joker' then assert(#G.jokers.cards<G.jokers.config.card_limit+(c.edition and c.edition.negative and 1 or 0),'No Joker slot') end
if c.ability.consumeable then assert(#G.consumeables.cards<G.consumeables.config.card_limit,'No consumable slot') end
e.config.ref_table=c
if a.area=='shop_jokers' then G.FUNCS.buy_from_shop(e) else G.FUNCS.use_card(e) end
elseif t=='choose_pack_card' then
assert(p:find('_pack$'),'No pack open');local c=find('pack_cards',a.card)
e.config.ref_table=c;G.FUNCS.use_card(e)
elseif t=='sell' then
local c=a.exact_card or find(a.area or 'consumeables',a.card)
if L.fast then c:update(1/60*512) end
assert(c:can_sell_card(),'Card cannot be sold');e.config.ref_table=c
if L.fast and not SMODS and G.VERSION=='1.0.1o-FULL' then
c:sell_card()
for _,j in ipairs(G.jokers.cards) do
if j~=c and j.ability.name=='Campfire' then j:calculate_joker({selling_card=true,card=c}) end
end
else G.FUNCS.sell_card(e) end
elseif t=='use_consumable' then
local c=find('consumeables',a.card)
if G.hand then G.hand:unhighlight_all() end
if L.fast and card_key(c)=='c_temperance' then
for _,j in ipairs(G.jokers.cards) do j:update(1/60*512) end
end
if L.fast then c:update(1/60*512) end
assert(c:can_use_consumeable(),'Consumable cannot be used')
e.config.ref_table=c
if L.fast and p=='shop' and c.ability.set=='Tarot' then fast_use(c) else G.FUNCS.use_card(e) end
else error('Unsupported route action: '..t) end
L.actions=L.actions+1
wait_ready()
end
local function use(key) L.perform({type='use_consumable',card={key=key}}) end
local function sell(key,zone,exact) L.perform({type='sell',card={key=key},area=zone or 'consumeables',exact_card=exact}) end
local function loop_guard(mode)
assert(L.phase()=='shop','Cycles require a settled shop')
assert(#G.consumeables.cards==2,'Cycles require Fool and one other Tarot')
assert(G.GAME.last_tarot_planet=='c_emperor','Fool must currently copy Emperor')
assert(G.consumeables.config.card_limit>=2,'Emperor needs two consumable slots')
for _,c in ipairs(G.jokers.cards) do assert(card_key(c)~='j_ring_master','Sell Showman before cycling: it disables duplicate blocking') end
find('consumeables',{key='c_fool'})
if mode=='money' then find('consumeables',{key='c_devil'})
else find('shop_jokers',{key='c_devil'}) end
end
function L.cycle(mode)
loop_guard(mode)
local other
for _,c in ipairs(G.consumeables.cards) do if card_key(c)~='c_fool' then other=card_key(c) end end
local money_before=G.GAME.dollars
if mode=='money' then
sell('c_devil');use('c_fool');use('c_emperor')
assert(G.GAME.dollars==money_before+1,'Money loop changed: expected exactly +$1')
L.money_cycles=L.money_cycles+1
else
L.histogram[other]=(L.histogram[other] or 0)+1
use('c_fool')
if other=='c_judgement' and #G.jokers.cards<G.jokers.config.card_limit then
local before={};for _,c in ipairs(G.jokers.cards) do before[c]=true end
use(other);L.judgements=L.judgements+1
local added
for _,c in ipairs(G.jokers.cards) do if not before[c] then assert(not added,'Multiple Jokers appeared');added=c end end
assert(added,'Judgement did not create a Joker')
local key=card_key(added)
if added.edition and added.edition.negative and key~='j_ring_master' and key~='j_diet_cola' then
L.negatives=L.negatives+1
else
sell(key,'jokers',added)
if key=='j_diet_cola' then L.colas=L.colas+1 end
end
elseif other=='c_hermit' or other=='c_temperance' then use(other)
else sell(other) end
use('c_emperor');L.cycles=L.cycles+1
end
loop_guard(mode)
L.last_tarot=other
L.persist()
-- Keep collection advancing as fast as allocation, rather than letting
-- stock Balatro reach its 300 MB emergency full-collection threshold.
local started=love.timer.getTime()
collectgarbage('step',collectgarbage('count')>65536 and 32 or 8)
L.max_gc_ms=math.max(L.max_gc_ms or 0,(love.timer.getTime()-started)*1000)
end
function L.persist(exact)
if G and G.GAME then
local meta=G.GAME.ghost_loop or {}
local exact_rng=meta.exact_rng or {}
if exact then
exact_rng={}
for k,v in pairs(G.GAME.pseudorandom or {}) do
if type(v)=='number' then
exact_rng[k]=v~=v and 'nan' or v==math.huge and 'inf' or v==-math.huge and '-inf' or string.format('%.17g',v)
end
end
end
meta.version=L.version;meta.step=L.step;meta.cycles=L.cycles;meta.money_cycles=L.money_cycles
meta.judgements=L.judgements;meta.negatives=L.negatives;meta.colas=L.colas
meta.route_complete=L.route_complete or false;meta.route_next=L.route_next;meta.exact_rng=exact_rng
meta.histogram=L.histogram
G.GAME.ghost_loop=meta
end
end
local function restore_speed()
compiler.stop()
if L.prior_speed and G and G.SETTINGS then G.SETTINGS.GAMESPEED=L.prior_speed end
L.prior_speed=nil;L.fast=false
end
function L.flush_save()
local started=love.timer.getTime()
L.persist(true)
if L.native_save and G and G.STAGE==G.STAGES.RUN and L.ready() then L.native_save();L.save_pending=false end
L.max_save_ms=math.max(L.max_save_ms or 0,(love.timer.getTime()-started)*1000)
end
local function stop(error_text)
L.elapsed=L.started and love.timer.getTime()-L.started or 0
L.running=false;L.paused=false;L.co=nil;L.fast=false
restore_speed()
if error_text then L.status='Stopped';L.detail=tostring(error_text);L.error=L.detail
elseif L.stop_requested then L.status='Stopped';L.detail='Stopped at a safe boundary. Resume the guide or run another cycle batch.'
else L.status='Done';L.detail=L.route_complete and 'Ghost route verified. Run Tarot cycles or play normally.' or 'Cycle batch finished.' end
L.flush_save()
end
function L.cancel()
if L.running then L.stop_requested=true;L.paused=false;L.status='Stopping after the current cycle' end
end
function L.pause()
if not L.running then return end
L.paused=not L.paused;L.status=L.paused and 'Paused' or 'Running'
end
local function begin(mode,fn)
assert(not L.running,'Automation is already running')
index_centers()
L.error=nil;L.running=true;L.paused=false;L.stop_requested=false;L.mode=mode
L.started=love.timer.getTime();L.started_cycles=L.cycles+L.money_cycles
L.elapsed=nil
L.max_gc_ms=0;L.max_save_ms=0;L.max_update_ms=0;L.max_frame_ms=0;L.slow_frames=0
L.prior_speed=G.SETTINGS.GAMESPEED;L.status='Running';L.next_at=0
if mode=='cycles' and L.speed=='Turbo' and G.VERSION=='1.0.1o-FULL' then compiler.start(L.visual_native) end
L.co=coroutine.create(fn)
end
function L.start_cycles(count,speed)
local mode='tarot'
for _,c in ipairs(G.consumeables and G.consumeables.cards or {}) do if card_key(c)=='c_devil' then mode='money' end end
loop_guard(mode)
L.speed=speed or 'Turbo'
count=math.floor(count or L.target);assert(count>=1 and count<=10000000,'Choose 1 to 10,000,000 cycles')
L.batch_count=count;L.batch_done=0
begin('cycles',function()
for i=1,count do
L.fast=L.speed=='Turbo'
L.cycle(mode);L.batch_done=i
if L.stop_requested then return end
coroutine.yield('boundary')
end
end)
end
function L.start_route(resume)
assert(L.ready(),'Wait for the game to settle')
assert(G.GAME.selected_back.name=='Ghost Deck' and G.GAME.stake==1,'Select Ghost Deck, White Stake')
assert(G.GAME.pseudorandom.seed==L.route.seed,'Use seed '..L.route.seed)
assert(G.VERSION=='1.0.1o-FULL','This route was verified on Balatro 1.0.1o-FULL')
assert(G.SETTINGS.tutorial_complete,'Finish the tutorial before using this guide')
local start_at=1
if resume then
local m=G.GAME.ghost_loop
assert(m and m.version==L.version and m.route_next and not m.route_complete,'No unfinished guide in this save')
start_at=m.route_next
assert(start_at>=1 and start_at<=#L.route.steps+1,'Invalid saved guide step')
if start_at==50 then
loop_guard('money');assert(G.GAME.dollars==13+L.money_cycles,'Saved money stage no longer matches')
elseif start_at>1 then L.verify(L.route.steps[start_at-1].expect) end
else
assert(L.phase()=='blind_select' and G.GAME.round==0 and G.GAME.dollars==4 and #G.jokers.cards==0,'The guide needs an untouched fresh run')
find('consumeables',{key='c_hex'})
L.step=0;L.cycles=0;L.money_cycles=0;L.actions=0;L.judgements=0;L.negatives=0;L.colas=0
L.histogram={};L.route_complete=false
end
begin('route',function()
for i=start_at,#L.route.steps do
local a=L.route.steps[i]
L.route_next=i
L.step=i;L.detail=a.label;L.fast=false
L.route_speed=math.min(64,4*2^math.floor((i-1)/8))
L.route_ticks=math.min(24,2+math.floor((i-1)/3))
if a.type=='farm' then
L.batch_count=a.count;L.batch_done=0
for j=L.money_cycles+1,a.count do
L.fast=true;L.cycle('money');L.batch_done=j
if L.stop_requested then return end
coroutine.yield('boundary')
end
L.fast=false
else L.perform(a) end
L.verify(a.expect);L.route_next=i+1;L.persist()
if L.stop_requested then return end
coroutine.yield('route_step')
end
L.route_complete=true
end)
end
function L.new_run()
assert(not L.running,'Stop automation first')
assert(G.P_CENTERS.b_ghost and G.P_CENTERS.b_ghost.unlocked,'Unlock Ghost Deck first')
assert(G.SETTINGS.tutorial_complete,'Finish the tutorial first')
if G.OVERLAY_MENU then G.FUNCS.exit_overlay_menu() end
G.GAME.viewed_back=Back(G.P_CENTERS.b_ghost)
G.FUNCS.start_run(nil,{seed=L.route.seed,stake=1})
L.pending_route=true;L.status='Starting fresh Ghost Deck';L.detail='Seed '..L.route.seed
end
function L.shop_tick()
local dt=1/15
G.SETTINGS.GAMESPEED=512;G.SPEEDFACTOR=512;G.real_dt=dt
G.TIMERS.REAL=G.TIMERS.REAL+dt;G.TIMERS.UPTIME=G.TIMERS.UPTIME+dt
G.TIMERS.TOTAL=G.TIMERS.TOTAL+dt*512
G.E_MANAGER:update(dt)
if G.STATE==G.STATES.PLAY_TAROT then G:update_play_tarot(dt) end
-- Refresh the same native lock cache without repeating mouse polling,
-- hit testing and focus navigation hundreds of times per rendered frame.
-- Ordinary love.update still runs the complete controller every frame.
local controller=G.CONTROLLER
controller.locks.wipe=G.screenwipe and true or false
controller.locked=false
for _,v in pairs(controller.locks) do if v then controller.locked=true end end
end
function L.update(dt)
if not G or not G.GAME then return end
if not L.gc_hook and nuGC then
local native_gc=nuGC
nuGC=function(budget,ceiling,disable)
local started=love.timer.getTime()
local result=native_gc(L.fast and math.max(budget or 0,collectgarbage('count')>65536 and 0.0015 or 0.0005) or budget,ceiling,disable)
if L.fast then L.max_gc_ms=math.max(L.max_gc_ms or 0,(love.timer.getTime()-started)*1000) end
return result
end
L.gc_hook=true
end
if not L.visual_hooks and attention_text and play_sound and UIBox then
local native_attention,native_sound,native_recalculate=attention_text,play_sound,UIBox.recalculate
attention_text=function(...) if not L.fast then return native_attention(...) end end
play_sound=function(...) if not L.fast then return native_sound(...) end end
UIBox.recalculate=function(self,...)
if L.fast and self==G.HUD then L.hud_dirty=true;return end
return native_recalculate(self,...)
end
L.refresh_hud=function()
if L.hud_dirty and G.HUD then native_recalculate(G.HUD);L.hud_dirty=false end
end
for _,class in ipairs({Moveable,Sprite}) do
local remove=class.remove
class.remove=function(object,...)
if L.fast and object.REMOVED then return end
return remove(object,...)
end
end
local native_sell=Card.sell_card
Card.sell_card=function(card)
if not L.fast or L.phase()~='shop' then return native_sell(card) end
G.CONTROLLER.locks.selling_card=true;stop_use()
card:calculate_joker({selling_self=true})
G.E_MANAGER:add_event(Event({trigger='immediate',func=function()
ease_dollars(card.sell_cost)
inc_career_stat('c_cards_sold',1)
if card.ability.set=='Joker' then
inc_career_stat('c_jokers_sold',1)
if G.GAME.blind and G.GAME.blind.name=='Verdant Leaf' then G.GAME.blind:disable() end
end
card:start_dissolve({G.C.GOLD})
G.E_MANAGER:add_event(Event({trigger='after',delay=0.3,blocking=false,func=function()
G.CONTROLLER.locks.selling_card=nil;return true
end}))
return true
end}))
end
local native_dissolve,native_materialize=Card.start_dissolve,Card.start_materialize
Card.start_dissolve=function(card,colours,silent,timefac,no_juice)
if not L.fast then return native_dissolve(card,colours,silent,timefac,no_juice) end
-- Keep the native removal callback and its timing; omit only the
-- particles, dissolve interpolation and sound events around it.
card.dissolve=1;card.states.visible=false
local duration=0.7*(timefac or 1)
G.E_MANAGER:add_event(Event({trigger='after',blockable=false,delay=1.05*duration,
func=function() card:remove();return true end}))
G.E_MANAGER:add_event(Event({trigger='after',blockable=false,delay=1.051*duration}))
end
Card.start_materialize=function(card,colours,silent,timefac)
if not L.fast then return native_materialize(card,colours,silent,timefac) end
card.states.visible=true;card.states.hover.can=true;card.dissolve=0
end
local native_card_init,native_move_init=Card.init,Moveable.init
Card.init=function(card,x,y,w,h,base,center,params)
local prior=L.building_tarot
if L.fast and center and center.set=='Tarot' then L.building_tarot=card end
native_card_init(card,x,y,w,h,base,center,params)
L.building_tarot=prior
end
Moveable.init=function(object,x,y,w,h)
if L.building_tarot and object==L.building_tarot then
local interrupted=G.STAGE_OBJECT_INTERRUPT
G.STAGE_OBJECT_INTERRUPT=true
Node.init(object,{T={x,y,w,h}})
G.STAGE_OBJECT_INTERRUPT=interrupted
object.VT={x=x,y=y,w=w,h=h,r=0,scale=1};object.CT=object.VT
object.pinch={x=false,y=false}
object.shadow_parrallax={x=0,y=-1.5};object.shadow_height=0.2
object.ghost_deferred_move=true
return
end
if L.building_tarot and getmetatable(object)==Moveable and w==0 and h==0 then
object.ghost_deferred_shadow=true
return
end
return native_move_init(object,x,y,w,h)
end
local move_remove=Moveable.remove
Moveable.remove=function(object,...)
if object.ghost_deferred_shadow or object.ghost_deferred_move then object.REMOVED=true;return end
return move_remove(object,...)
end
local function realize_move(card)
if not card.ghost_deferred_move then return end
local states,id,transform,visible,serial=card.states,card.ID,card.T,card.VT,G.ID
native_move_init(card,transform.x,transform.y,transform.w,transform.h)
card.states=states;card.ID=id;card.T=transform;card.VT=visible;card.CT=visible;G.ID=serial
card.children.shadow=Moveable(0,0,0,0)
card.ghost_deferred_move=nil
end
local native_move=Card.move
Card.move=function(card,...)
if card.REMOVED then return end
realize_move(card)
return native_move(card,...)
end
local native_sprites,native_draw=Card.set_sprites,Card.draw
local function deferred_sprite()
return {VT={w=0,h=0},remove=function() end}
end
Card.set_sprites=function(card,center,front)
if L.fast and not card.playing_card and card.config.center.consumeable then
-- Most intermediate Tarots are used before the next draw.
-- Allocate their image objects only if they actually render.
if not card.children.center then
card.children.center=deferred_sprite();card.children.back=deferred_sprite()
card.ghost_deferred_visual=true
end
if card.ghost_deferred_visual then return end
end
return native_sprites(card,center,front)
end
Card.draw=function(card,...)
if L.fast and card.area==G.play and card.ability.consumeable then return end
if card.ghost_deferred_move and not card.states.visible then return end
if card.states.visible then realize_move(card) end
if card.ghost_deferred_visual and card.states.visible then
card.children.center=nil;card.children.back=nil
local front=card.config.card
native_sprites(card,card.config.center,front and next(front) and front or nil)
card.children.center.parent=card;card.children.back.parent=card
card.ghost_deferred_visual=nil
end
return native_draw(card,...)
end
L.visual_native={native_draw,native_move,native_move_init,native_sprites,native_materialize,native_dissolve,native_recalculate,native_attention,native_sound}
L.visual_hooks=true
end
if L.refresh_hud then L.refresh_hud() end
if not L.hooked_load and Game and Game.start_run then
local native_start=Game.start_run
Game.start_run=function(self,args)
local saved=args and args.savetext
local meta=saved and saved.GAME and saved.GAME.ghost_loop
if meta and meta.version==L.version and type(meta.exact_rng)=='table' then
-- Native saves round doubles and do not represent NaN as a Lua
-- number. Restore only this run's own lossless numeric mirror.
for k,s in pairs(meta.exact_rng) do
local n=s=='nan' and 0/0 or s=='inf' and math.huge or s=='-inf' and -math.huge or tonumber(s)
if n then saved.GAME.pseudorandom[k]=n end
end
end
return native_start(self,args)
end
L.hooked_load=true
end
if L.seen_game~=G.GAME and not L.running then
L.seen_game=G.GAME
local meta=G.GAME.ghost_loop
if meta and meta.version==L.version then
for _,k in ipairs({'step','cycles','money_cycles','judgements','negatives','colas','route_complete','route_next'}) do L[k]=meta[k] end
L.histogram=meta.histogram or {}
end
end
if not L.native_save and type(save_run)=='function' then
L.native_save=save_run
save_run=function(...)
if L.running then L.save_pending=true;return end
if G and G.GAME and G.GAME.ghost_loop then L.persist(true) end
return L.native_save(...)
end
end
if L.pending_route and L.ready() then
L.pending_route=false
local ok,err=pcall(L.start_route);if not ok then stop(err) end
end
if not L.running or L.paused or G.OVERLAY_MENU or G.SETTINGS.paused then return end
if love.timer.getTime()<(L.next_at or 0) then return end
local deadline=love.timer.getTime()+L.budget_ms/1000
local ticks=0
repeat
ticks=ticks+1
if L.fast then L.shop_tick()
elseif ticks>1 and L.mode=='route' then G:update(1/60) end
G.SETTINGS.GAMESPEED=L.fast and 512 or (L.mode=='route' and (L.route_speed or 4) or 16)
local ok,why=coroutine.resume(L.co)
if not ok then stop(why);return end
if coroutine.status(L.co)=='dead' then stop();return end
if why=='route_step' then
L.next_at=0
L.fast=false;L.flush_save();return
end
if why=='boundary' and love.timer.getTime()-(L.saved_at or 0)>2 then
L.flush_save();L.saved_at=love.timer.getTime()
end
if not L.fast and (L.mode~='route' or ticks>=(L.route_ticks or 2)) then return end
until love.timer.getTime()>=deadline
end
function L.safe(fn)
local ok,err=pcall(fn)
if not ok then
if L.running then stop(err)
else L.status='Cannot start';L.detail=tostring(err);L.error=L.detail end
end
end
return L