-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
123 lines (105 loc) · 4.22 KB
/
main.py
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
from colorama import Fore, Style, Back
from tkinter import filedialog
from functools import partial
import os, keyboard, inject, json, time, platform, platformdirs, sys
version = 0.2
spotify_path = platformdirs.user_data_dir(roaming=True) + "\Spotify"
operating_system = platform.system()
def clear():
os.system("cls" if operating_system == "Windows" else "clear")
print(f"{Back.GREEN}{Fore.BLACK} SpotMod Patcher v{str(version)} {Style.RESET_ALL}{Fore.GREEN}\n")
def main():
global spotify_path
clear()
if not operating_system == "Windows":
print("At the moment, SpotMod only supports Windows.\nMac/Linux support is coming soon.")
input("\nPress enter to exit...")
quit()
data = json.load(open("data.json"))
if not data["path"] == "": spotify_path = data["path"]
if not os.path.exists(f"{spotify_path}/Spotify.exe"):
not_installed()
if not os.path.exists(f"{spotify_path}/SpotMod.txt"):
not_detected()
main_menu()
def main_menu():
while True:
clear()
option_list(["Add mod", "Manage mods", "Re-patch", "Uninstall SpotMod", "Quit"], [add_mod, manage_mods, patch, uninstall, quit])
def add_mod():
clear()
print("Please select your mod file...")
mod_file = filedialog.askopenfilename(filetypes=[("All Mod Files", "*.js")])
if mod_file:
clear()
inject.add_mod(mod_file, spotify_path)
def manage_mods():
while True:
clear()
mod_ids = []
data = json.load(open("SpotMod-dat/data.json", "r"))
for mod in data["mods"]:
mod_ids.append(mod["id"])
mod_ids.append("Cancel")
mod_id = option_list(mod_ids, None, "Select a mod:")
if mod_id == "Cancel": return
clear()
mod_enabled = data["mods"][mod_ids.index(mod_id)]["enabled"]
mod_option = option_list(["Disable mod" if mod_enabled else "Enable mod", "Remove mod", "Cancel"])
clear()
match mod_option:
case "Disable mod":
inject.enable_mod(mod_id, mod_ids, spotify_path, False)
case "Enable mod":
inject.enable_mod(mod_id, mod_ids, spotify_path, True)
case "Remove mod":
inject.remove_mod(mod_id, mod_ids, spotify_path)
case _:
pass
def not_detected():
print("SpotMod is not detected on this system.\n")
option_list(["Patch Spotify", "Quit"], [partial(patch, True), quit])
def not_installed():
global spotify_path
print(f"Spotify is not detected on this system at [{spotify_path}].\nMake sure you downloaded it from Spotify.com and not the Microsoft Store.\n")
option_list(["Spotify is installed somewhere else", "Quit"], [None, quit])
data = json.load(open("data.json"))
clear()
print("Please select your Spotify install folder...")
data["path"] = filedialog.askdirectory(initialdir=os.getenv("APPDATA"))
json.dump(data, open("data.json", "w"))
main()
def patch(delete_data = False):
clear()
inject.patch_spotify(spotify_path, delete_data)
main()
def uninstall():
clear()
option_list(["Yes. Remove all my mods.", "No! Take me back!"], [None, main_menu], "Are you sure you wish to un-patch Spotify and remove all mods?")
clear()
inject.unpatch_spotify(spotify_path)
def option_list(itemlist, calllist = None, prompt_text = "Please choose an option:"):
print(prompt_text)
for item in itemlist:
print(f"{itemlist.index(item) + 1}) {item}")
while True:
wait_for_no_keys()
key = keyboard.read_event().name
keyboard.send("Backspace")
keyboard.send("Backspace") # idk, it only works when you do it twice
if key.isdigit():
if int(key) <= len(itemlist) and not int(key) == 0:
if calllist is not None:
if calllist[int(key) - 1] is not None: calllist[int(key) - 1]()
break
else:
return itemlist[int(key) - 1]
def wait_for_no_keys():
while True:
if not any(keyboard.is_pressed(scan_code) for scan_code in range(1, 256)): # There has to be a better way to do this...
break
time.sleep(0.1)
def quit():
sys.exit()
if __name__ == "__main__":
main()