-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.py
206 lines (173 loc) · 6.42 KB
/
base.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
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
from pypresence import Presence
import subprocess
import json
import tkinter as tk
from tkinter import filedialog
import psutil
import random
import json
import time
from flask import Flask, render_template, jsonify
from werkzeug.serving import make_server
import threading
import tkinter as tk
from tkinter import ttk
import webview
RPC = None
current_game = None
image_urls = [
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/1.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/2.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/3.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/4.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/5.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/6.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/7.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/8.jpg",
"https://raw.githubusercontent.com/mnelen12345/YolinaLauncher/main/large_image/9.jpg"
]
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def open_html_interface():
window = webview.create_window("YolinaLauncher", url="http://127.0.0.1:5000/", width=1410, height=720, resizable=False,)
drpidle()
webview.start()
def check_running_processes():
global current_game, RPC
running_processes = []
for p in psutil.process_iter(['name'], ad_value=''):
try:
running_processes.append(p.name())
except (psutil.NoSuchProcess, psutil.AccessDenied):
pass
if "GenshinImpact.exe" in running_processes:
current_game = "Genshin Impact"
print("1")
elif "StarRail.exe" in running_processes:
current_game = "Honkai: Star Rail"
print("2")
elif "BH3.exe" in running_processes:
current_game = "Honkai Impact 3rd"
print("3")
else:
current_game = None
if RPC: # Проверяем, что RPC инициализирован
RPC.update(state="Idle", details="In menu")
print("4")
time.sleep(5)
def create_rpc():
global RPC
RPC = Presence('1223969994824482879')
try:
RPC.connect()
print("Discord Rich Presence подключен успешно.")
except Exception as e:
print("Ошибка при подключении к Discord Rich Presence:", e)
def launch_game(exe_path):
subprocess.run([exe_path])
def select_game_path():
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename(initialdir="C:/", title="Выберите исполняемый файл игры")
return file_path
def save_game_path(choice, game_path):
try:
with open('games.json', 'r') as json_file:
data = json.load(json_file)
except FileNotFoundError:
data = {}
data[choice] = {"path": game_path}
with open('games.json', 'w') as json_file:
json.dump(data, json_file)
def load_game_path(choice):
try:
with open('games.json', 'r') as json_file:
data = json.load(json_file)
except FileNotFoundError:
data = {}
game_path = data.get(choice, {}).get("path", None)
return game_path
@app.route('/genshin_impact')
def genshin_impact():
game_path = load_game_path('1')
if game_path:
drpgi()
launch_game(game_path)
drpidle()
else:
print("Путь к игре Genshin Impact не найден в файле games.json.")
game_path = select_game_path()
if game_path:
save_game_path('1', game_path)
drpgi()
launch_game(game_path)
drpidle()
else:
print("Не выбран путь к игре Genshin Impact.")
result = {"message": "Genshin Impact function executed successfully!"}
return jsonify(result)
@app.route('/honkai_star_rail')
def honkai_star_rail():
game_path = load_game_path('2')
if game_path:
drphsr()
launch_game(game_path)
drpidle()
else:
print("Путь к игре Honkai: Star Rail не найден в файле games.json.")
game_path = select_game_path()
if game_path:
save_game_path('2', game_path)
drphsr()
launch_game(game_path)
drpidle()
else:
print("Не выбран путь к игре Honkai: Star Rail.")
result = {"message": "Genshin Impact function executed successfully!"}
return jsonify(result)
@app.route('/honkai_impact_3rd')
def honkai_impact():
game_path = load_game_path('3')
if game_path:
drphi3rd()
launch_game(game_path)
drpidle()
else:
print("Путь к игре Honkai Impact 3rd не найден в файле games.json.")
game_path = select_game_path()
if game_path:
save_game_path('3', game_path)
drphi3rd()
launch_game(game_path)
drpidle()
else:
print("Не выбран путь к игре Honkai Impact 3rd.")
result = {"message": "Genshin Impact function executed successfully!"}
return jsonify(result)
def drpidle():
RPC.update(state="idle", large_image=random.choice(image_urls), small_image="idle")
def drpgi():
RPC.update(state="Playing Genshin Impact", large_image=random.choice(image_urls), small_image="gi")
def drphsr():
RPC.update(state="Playing Honkai: Star Rail", large_image=random.choice(image_urls), small_image="hsr")
def drphi3rd():
RPC.update(state="Playing Honkai Impact 3rd", large_image=random.choice(image_urls), small_image="hi3rd")
def run_flask_app():
server = make_server('localhost', 5000, app)
server.serve_forever()
def update_rpc():
global RPC
while True:
time.sleep(5)
if __name__ == "__main__":
create_rpc()
flask_thread = threading.Thread(target=run_flask_app)
flask_thread.start()
rpc_thread = threading.Thread(target=update_rpc)
rpc_thread.start()
open_html_interface()
while True:
check_running_processes()
time.sleep(1)