-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimmolate.py
More file actions
449 lines (395 loc) · 13.1 KB
/
immolate.py
File metadata and controls
449 lines (395 loc) · 13.1 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
from enum import Enum
import pyautogui
import keyboard
from include import winocr
import pyperclip
import numpy as np
from PIL import Image, ImageFilter, ImageEnhance
from difflib import SequenceMatcher
import time
from dataclasses import dataclass
# This is what stores all of the variables and info required by programs using Immolate.
version = "v0.03"
class options:
exitKeyCombination = "ctrl+c"
# Helper functions for basic actions
# Helper Functions
def checkForExit():
if keyboard.is_pressed("ctrl+c"):
exit(0)
def click(pos):
checkForExit()
pyautogui.moveTo(pos[0], pos[1])
time.sleep(0.05);
pyautogui.click()
def move(pos):
checkForExit()
pyautogui.moveTo(pos[0], pos[1])
def reset():
click(inGame.optionsButton);
click(quickOptions.newRunButton);
click(gameSelect.playButton);
time.sleep(2.25);
def resetSeeded(seed):
pyperclip.copy(seed)
click(inGame.optionsButton)
click(quickOptions.newRunButton)
click(gameSelect.seededRunButton)
click(gameSelect.pasteSeedButton)
click(gameSelect.playButton)
time.sleep(2.25)
def printSeed():
click(inGame.optionsButton)
click(quickOptions.copySeedButton)
print(pyperclip.paste())
def printSeedToFile(filename):
printSeed()
try:
# Check if the file exists
with open(filename, 'a') as file:
# Append the text to the file
file.write(pyperclip.paste() + '\n')
except FileNotFoundError:
# If the file doesn't exist, create it and write the text
with open(filename, 'w') as file:
file.write(pyperclip.paste() + '\n')
def readText(box):
# Takes screenshot, makes it larger, runs OCR
img = pyautogui.screenshot(region=(box[0],box[1],box[2]-box[0],box[3]-box[1]))
width, height = img.size
img = img.resize((width*3, height*3), resample=Image.NEAREST).filter(ImageFilter.SHARPEN);
img = ImageEnhance.Contrast(img).enhance(1.5)
return winocr.recognize_pil_sync(img, 'en')['text']
def readLine(box):
# Takes screenshot, makes it larger, runs OCR
# This one only returns the first line
img = pyautogui.screenshot(region=(box[0],box[1],box[2]-box[0],box[3]-box[1]))
width, height = img.size
img = img.resize((width*3, height*3), resample=Image.NEAREST).filter(ImageFilter.SHARPEN);
img = ImageEnhance.Contrast(img).enhance(1.5)
try:
result = winocr.recognize_pil_sync(img, 'en')['lines'][0]['text']
except:
result = ""
return result
def readLastLine(box):
# Takes screenshot, makes it larger, runs OCR
# This one only returns the last line
img = pyautogui.screenshot(region=(box[0],box[1],box[2]-box[0],box[3]-box[1]))
width, height = img.size
img = img.resize((width*3, height*3), resample=Image.NEAREST).filter(ImageFilter.SHARPEN);
img = ImageEnhance.Contrast(img).enhance(1.5)
try:
result = winocr.recognize_pil_sync(img, 'en')['lines'][-1]['text']
except:
result = ""
return result
def screenshot(box):
# Takes screenshot of a certain box
return pyautogui.screenshot(region=(box[0],box[1],box[2]-box[0],box[3]-box[1]))
def readTextNoEdits(box):
# Takes screenshot, makes it larger, runs OCR
# This one only returns the first line
img = pyautogui.screenshot(region=(box[0],box[1],box[2]-box[0],box[3]-box[1]))
try:
result = winocr.recognize_pil_sync(img, 'en')['text']
except:
result = ""
return result
def readLineNoEdits(box):
# Takes screenshot, makes it larger, runs OCR
# This one only returns the first line
img = pyautogui.screenshot(region=(box[0],box[1],box[2]-box[0],box[3]-box[1]))
try:
result = winocr.recognize_pil_sync(img, 'en')['lines'][0]['text']
except:
result = ""
return result
def readLastLineNoEdits(box):
# Takes screenshot, makes it larger, runs OCR
# This one only returns the last line
img = pyautogui.screenshot(region=(box[0],box[1],box[2]-box[0],box[3]-box[1]))
try:
result = winocr.recognize_pil_sync(img, 'en')['lines'][-1]['text']
except:
result = ""
return result
def readTextNoEditsFromScreenshot(img):
try:
result = winocr.recognize_pil_sync(img, 'en')['text']
except:
result = ""
return result
def readLineNoEditsFromScreenshot(img):
try:
result = winocr.recognize_pil_sync(img, 'en')['lines'][0]['text']
except:
result = ""
return result
def readLastLineNoEditsFromScreenshot(img):
try:
result = winocr.recognize_pil_sync(img, 'en')['lines'][-1]['text']
except:
result = ""
return result
# Finds the closest value in an Enum of things (jokers, spectral cards, etc.) to a string
# Can be used to overcome the inaccuracy of OCR
def closestValue(enum, string):
similarEnum = None
maxSimilarity = 0.0
for element in enum:
similarity = SequenceMatcher(None, string, element.value).ratio()
if similarity > maxSimilarity:
maxSimilarity = similarity
similarEnum = element
if maxSimilarity < 0.5:
return None #probably nothing
return similarEnum
# Finds the closest value out of all 52 playing cards
# Can be used to overcome the inaccuracy of OCR
def closestCard(string):
similarEnum = None
maxSimilarity = 0.0
for element in allCards:
similarity = SequenceMatcher(None, string, element.value()).ratio()
if similarity > maxSimilarity:
maxSimilarity = similarity
similarEnum = element
return similarEnum
# Coordinates of buttons and bounding boxes of text
class mainMenu:
playButton = (553, 911)
optionsButton = (845, 907)
quitButton = (1073, 907)
collectionButton = (1357, 904)
class quickOptions:
settingsButton = (965, 280)
copySeedButton = (1080, 364)
newRunButton = (963, 452)
mainMenuButton = (958, 558)
statsButton = (952, 632)
collectionButton = (959, 726)
backButton = (942, 824)
class settings:
class game:
increaseGameSpeedButton = (1076, 349)
decreaseGameSpeedButton = (849, 345)
class gameSelect:
newRunButton = (737, 135)
pasteSeedButton = (1064, 774)
seededRunButton = (722, 858)
playButton = (958, 855)
backButton = (951, 943)
class inGame: #General gameplay loop
runInfoButton = (154, 747)
optionsButton = (148, 918)
playHandButton = (831, 989)
discardButton = (1271, 946)
class blindMenu:
smallBlindPlayButton = (725, 394)
smallBlindSkipButton = (728, 781)
bigBlindPlayButton = (1054, 387)
bigBlindSkipButton = (1066, 800)
bossBlindPlayButton = (1392, 394)
tag1_selectedBox = (690, 835, 840, 911)
tag2_deselectedBox = (1021, 925, 1172, 1000)
tag2_selectedBox = (1024, 839, 1171, 911)
class boosterPackMenu:
packPosition = {
2: [(968, 842), (1146, 841)],
5: [(641, 841), (852, 837), (1061, 835), (1271, 839), (1471, 831)]
}
packDescription = {
2: [(867, 366, 1063, 500), (1056, 366, 1244, 500)],
5: [(558, 366, 732, 500), (765, 366, 935, 500), (966, 366, 1152, 500),
(1176, 366, 1352, 500), (1378, 366, 1563, 500)]
}
# Eventually these will probably just be the regular card positions shifted upwards
cardPosition = {
8: [(582, 459), (719, 460), (854, 441), (944, 430), (1110, 449),
(1217, 468), (1378, 472), (1504, 489)]
}
cardDescription = {
8: [(521, 144, 724, 350), (651, 144, 838, 370), (766, 144, 973, 350),
(902, 144, 1901, 350), (1020, 144, 1219, 350), (1149, 144, 1340, 350),
(1267, 144, 1469, 350), (1394, 144, 1583, 350)]
}
skipButton = (1057, 1006)
# Names or descriptions of things
class Joker(Enum):
JOKER = "Joker"
ZANY = "Zany Joker"
MAD = "Mad Joker"
CRAZY = "Crazy Joker"
DROLL = "Droll Joker"
HALF = "Half Joker"
ICE_CREAM = "Ice Cream"
JUGGLER = "Juggler"
RUNNER = "Runner"
GOLDEN = "Golden Joker"
STENCIL = "Joker Stencil"
FOUR_FINGERS = "Four Fingers"
CEREMONIAL_DAGGER = "Ceremonial Dagger"
BANNER = "Banner"
MARBLE = "Marble Joker"
LOYALTY_CARD = "Loyalty Card"
EIGHT_BALL = "8 Ball"
MISPRINT = "Misprint"
BLUEPRINT = "Blueprint"
RAISED_FIST = "Raised Fist"
FIBONACCI = "Fibonacci"
CARTOMANCER = "Cartomancer"
ASTRONOMER = "Astronomer"
ABSTRACT = "Abstract Joker"
DELAYED_GRATIFICATION = "Delayed Gratification"
GROS_MICHEL = "Gros Michel"
EVEN_STEVEN = "Even Steven"
ODD_TODD = "Odd Todd"
SCHOLAR = "Scholar"
BUSINESS_CARD = "Business Card"
SUPERNOVA = "Supernova"
RIDE_THE_BUS = "Ride the Bus"
BLACKBOARD = "Blackboard"
EGG = "Egg"
BURGLAR = "Burglar"
SCARY_FACE = "Scary Face"
MYSTIC_SUMMIT = "Mystic Summit"
DUSK = "Dusk"
DNA = "DNA"
SPLASH = "Splash"
SMEARED = "Smeared Joker"
CONSTELLATION = "Constellation"
HIKER = "Hiker"
SUPERPOSITION = "Superposition"
TO_DO_LIST = "To Do List"
class Tarot(Enum):
FOOL = "The Fool"
MAGICIAN = "The Magician"
HIGH_PRIESTESS = "The High Priestess"
EMPRESS = "The Empress"
EMPEROR = "The Emperor"
HIEROPHANT = "The Hierophant"
LOVERS = "The Lovers"
CHARIOT = "The Chariot"
JUSTICE = "Justice"
HERMIT = "The Hermit"
WHEEL_OF_FORTUNE = "The Wheel of Fortune"
STRENGTH = "Strength"
HANGED_MAN = "The Hanged Man"
DEATH = "Death"
TEMPERANCE = "Temperance"
DEVIL = "The Devil"
TOWER = "The Tower"
STAR = "The Star"
MOON = "The Moon"
SUN = "The Sun"
JUDGEMENT = "Judgement"
WORLD = "The World"
class Planet(Enum):
MERCURY = "Mercury"
VENUS = "Venus"
EARTH = "Earth"
MARS = "Mars"
JUPITER = "Jupiter"
SATURN = "Saturn"
URANUS = "Uranus"
NEPTUNE = "Neptune"
PLUTO = "Pluto"
PLANET_X = "Planet X"
CERES = "Ceres"
class Spectral(Enum):
FAMILIAR = "Familiar"
GRIM = "Grim"
INCANTATION = "Incantation"
TALISMAN = "Talisman"
AURA = "Aura"
WRAITH = "Wraith"
SIGIL = "Sigil"
OUIJA = "Ouija"
ECTOPLASM = "Ectoplasm"
IMMOLATE = "Immolate"
class BoosterPack(Enum):
ARCANA = "Arcana Pack", 3, Tarot
JUMBO_ARCANA = "Jumbo Arcana Pack", 4, Tarot
MEGA_ARCANA = "Mega Arcana Pack", 5, Tarot
CELESTIAL = "Celestial Pack", 3, Planet
JUMBO_CELESTIAL = "Jumbo Celestial Pack", 4, Planet
MEGA_CELESTIAL = "Mega Celestial Pack", 5, Planet
SPECTRAL = "Spectral Pack", 2, Spectral
JUMBO_SPECTRAL = "Jumbo Spectral Pack", 3, Spectral
MEGA_SPECTRAL = "Mega Spectral Pack", 4, Spectral
# Kudos to https://stackoverflow.com/questions/12680080/python-enums-with-attributes
def __new__(cls, *args, **kwds):
obj = object.__new__(cls)
obj._value_ = args[0]
return obj
def __init__(self, _: str, numCards: int = None, cardType: Enum = None):
self._numCards_ = numCards
self._cardType_ = cardType
@property
def numCards(self):
return self._numCards_
@property
def cardType(self):
return self._cardType_
class Tag(Enum):
UNCOMMON = "Shop has an Uncommon Joker"
RARE = "1 in 3 chance for shop to have a Rare Joker"
NEGATIVE = "1 in 5 chance for shop to have a Negative Joker"
FOIL = "1 in 2 chance for shop to have a Foil Joker"
HOLOGRAPHIC = "1 in 3 chance for shop to have a Holographic Joker"
POLYCHROME = "1 in 4 chance for shop to have a Polychrome Joker"
INVESTMENT = "After defeating the Boss Blind, gain $15"
VOUCHER = "Adds one Voucher to the next shop"
BOSS = "Rerolls the Boss Blind"
GOLD_SEAL = "Gold Seal card in the shop"
CHARM = "Gives a free Mega Arcana Pack", BoosterPack.MEGA_ARCANA
METEOR = "Gives a free Mega Celestial Pack", BoosterPack.MEGA_CELESTIAL
ENHANCED = "Enhanced card in the shop"
HANDY = "Start round with an extra 3 Hands"
GARBAGE = "Start round with an extra 3 Discards"
ETHEREAL = "Gives a free Spectral Pack", BoosterPack.SPECTRAL
# Kudos to https://stackoverflow.com/questions/12680080/python-enums-with-attributes
def __new__(cls, *args, **kwds):
obj = object.__new__(cls)
obj._value_ = args[0]
return obj
def __init__(self, _: str, associatedPack: BoosterPack = None):
self._associatedPack_ = associatedPack
@property
def associatedPack(self):
return self._associatedPack_
class Edition(Enum):
BASE = ""
FOIL = "Foil"
HOLOGRAPHIC = "Holographic"
POLYCHROME = "Polychrome"
NEGATIVE = "Negative"
class Suit(Enum):
CLUBS = "Clubs"
DIAMONDS = "Diamonds"
HEARTS = "Hearts"
SPADES = "Spades"
class Rank(Enum):
ACE = "Ace"
KING = "King"
QUEEN = "Queen"
JACK = "Jack"
TEN = "10"
# Why this weird ordering? If a single-digit rank isn't being recognized by OCR, it's usually 4
FOUR = "4"
NINE = "9"
EIGHT = "8"
SEVEN = "7"
SIX = "6"
FIVE = "5"
THREE = "3"
TWO = "2"
@dataclass
class Card:
rank: Rank
suit: Suit
def value(self):
return f"{self.rank.value} of {self.suit.value}"
# Precomputed variables
allCards = [Card(r, s) for r in Rank for s in Suit]