forked from shiburizu/concerto-mbaacc
/
concerto.py
209 lines (192 loc) · 8.27 KB
/
concerto.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
207
208
209
import sys
from config import * # App config functions
# System
import requests
import time
import threading
import subprocess
import winreg
# Utility scripts
# Discord Rich Presence
import presence
# Melty Blood CCCaster
from mbaacc import Caster
# Kivy
from kivy.uix.screenmanager import ScreenManager, FadeTransition
from kivy.app import App
from kivy.lang import Builder
Builder.load_file('Concerto.kv')
# Internal UI objects
from ui import howtoscreen, lobbyscreen, lobbylist, offlinescreen, onlinescreen, mainscreen, resourcescreen, optionscreen, aboutscreen, sound, buttons
class Concerto(App):
def __init__(self, **kwargs):
super(Concerto, self).__init__(**kwargs)
self.mode = 'Menu' # current mode selection
self.offline_mode = None #secondary Offline activity, mostly for lobby
self.sm = ScreenManager(transition=FadeTransition(duration=0.10))
self.game = Caster(CApp=self) # expects Caster object
def build(self):
self.sound = sound.Sound()
self.MainScreen = mainscreen.MainScreen(CApp=self)
self.OnlineScreen = onlinescreen.OnlineScreen(CApp=self)
self.OfflineScreen = offlinescreen.OfflineScreen(CApp=self)
self.ResourceScreen = resourcescreen.ResourceScreen()
self.OptionScreen = optionscreen.OptionScreen(CApp=self)
self.LobbyList = lobbylist.LobbyList(CApp=self)
self.LobbyScreen = lobbyscreen.LobbyScreen(CApp=self)
self.HowtoScreen = howtoscreen.HowtoScreen()
self.AboutScreen = aboutscreen.AboutScreen()
self.sm.add_widget(self.MainScreen)
self.sm.add_widget(self.OnlineScreen)
self.sm.add_widget(self.OfflineScreen)
self.sm.add_widget(self.ResourceScreen)
self.sm.add_widget(self.OptionScreen)
self.sm.add_widget(self.LobbyList)
self.sm.add_widget(self.LobbyScreen)
self.sm.add_widget(self.HowtoScreen)
self.sm.add_widget(self.AboutScreen)
c = threading.Thread(target=self.checkPop,daemon=True)
c.start()
return self.sm
def on_start(self):
#necessary file sanity checks
e = []
# Register concerto:// url protocol handler
try:
key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, 'concerto')
winreg.SetValueEx(key, '', 0, winreg.REG_SZ, 'URL:Concerto Protocol')
winreg.SetValueEx(key, 'URL Protocol', 0, winreg.REG_SZ, '')
winreg.SetValueEx(winreg.CreateKey(key, 'DefaultIcon'), '', 0, winreg.REG_SZ, 'concerto.exe,0')
winreg.SetValueEx(winreg.CreateKey(key, 'shell\\open\\command'), '', 0, winreg.REG_SZ, '"' + sys.argv[0] + '" "%1"')
if key:
winreg.CloseKey(key)
except:
try:
winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, 'concerto')
except:
self.MainScreen.ids['welcome'].text = 'To join public lobbies via Discord run Concerto as admin once.'
logging.warning('Concerto: please start as admin once to add concerto protocol handler')
logging.warning('Concerto: argv is %s' % sys.argv[0])
s = PATH
logging.warning('Concerto: PATH is %s' % s)
if caster_config is None:
e.append('cccaster/config.ini not found.')
e.append('Please fix the above problems and restart Concerto.')
if e != []:
self.sound.muted = True
self.MainScreen.error_message(e)
else:
#if all is well, start loading in user options
if app_config['settings']['mute_bgm'] == '1':
self.sound.muted = True
else:
self.sound.cut_bgm()
# Connect discord rich presence
presence.connect()
presence.menu()
# Execute launch params
if len(sys.argv) > 1:
params = sys.argv[1].replace('concerto://', '').rstrip('/').split(':', 1)
if params[0] == 'lobby':
self.LobbyList.join(code=int(params[1]))
elif params[0] == 'connect':
self.OnlineScreen.join(ip=params[1])
elif params[0] == 'watch':
self.OnlineScreen.watch(ip=params[1])
def lobby_button(self, *args):
lst = [
self.MainScreen.ids['lobbyAnchor'],
self.OnlineScreen.ids['lobbyAnchor'],
self.OfflineScreen.ids['lobbyAnchor'],
self.ResourceScreen.ids['lobbyAnchor'],
self.OptionScreen.ids['lobbyAnchor'],
self.HowtoScreen.ids['lobbyAnchor'],
self.AboutScreen.ids['lobbyAnchor']
]
for i in lst:
b = buttons.LobbyBtn()
b.text += ' %s' % self.LobbyScreen.code
b.bind(on_release=self.switch_to_lobby)
i.clear_widgets()
i.add_widget(b)
def remove_lobby_button(self, *args):
lst = [
self.MainScreen.ids['lobbyAnchor'],
self.OnlineScreen.ids['lobbyAnchor'],
self.OfflineScreen.ids['lobbyAnchor'],
self.ResourceScreen.ids['lobbyAnchor'],
self.OptionScreen.ids['lobbyAnchor'],
self.HowtoScreen.ids['lobbyAnchor'],
self.AboutScreen.ids['lobbyAnchor']
]
for i in lst:
i.clear_widgets()
def update_lobby_button(self,text,*args):
lst = [
self.MainScreen.ids['lobbyAnchor'].children,
self.OnlineScreen.ids['lobbyAnchor'].children,
self.OfflineScreen.ids['lobbyAnchor'].children,
self.ResourceScreen.ids['lobbyAnchor'].children,
self.OptionScreen.ids['lobbyAnchor'].children,
self.HowtoScreen.ids['lobbyAnchor'].children,
self.AboutScreen.ids['lobbyAnchor'].children
]
for i in lst:
for n in i:
n.text = text
def switch_to_main(self, *args):
self.sm.current = 'Main'
def switch_to_lobby(self, *args):
self.sm.current = 'Lobby'
def checkPop(self, *args):
if self.game.aproc != None:
if self.game.aproc.isalive():
if self.game.offline is True:
cmd = f"""tasklist /FI "IMAGENAME eq mbaa.exe" /FO CSV /NH"""
task_data = subprocess.check_output(cmd, shell=True, creationflags=subprocess.CREATE_NO_WINDOW, stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL).decode("UTF8","ignore")
try:
task_data.replace("\"", "").split(",")[1]
except IndexError:
self.game.kill_caster()
else:
if self.OnlineScreen.active_pop != None:
self.OnlineScreen.active_pop.dismiss()
self.OnlineScreen.active_pop = None
if self.LobbyScreen.active_pop != None:
self.LobbyScreen.active_pop.dismiss()
self.LobbyScreen.active_pop = None
self.LobbyScreen.challenge_id = None
self.LobbyScreen.challenge_name = None
r = {
'action': 'end',
'p': self.LobbyScreen.player_id,
'id': self.LobbyScreen.code,
'secret': self.LobbyScreen.secret
}
requests.get(url=LOBBYURL, params=r).json()
self.game.kill_caster()
if hasattr(self,'sound'):
cmd = f"""tasklist /FI "IMAGENAME eq mbaa.exe" /FO CSV /NH"""
task_data = subprocess.check_output(cmd, shell=True, creationflags=subprocess.CREATE_NO_WINDOW, stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL).decode("UTF8","ignore")
try:
task_data.replace("\"", "").split(",")[1]
except IndexError:
if self.sound.bgm.state == 'stop':
self.sound.cut_bgm()
else:
if self.sound.bgm.state == 'play':
self.sound.cut_bgm()
time.sleep(2)
self.checkPop()
def run():
CApp = Concerto()
try:
CApp.run()
finally:
CApp.game.kill_caster()
# close rich presence connection
presence.close()
if CApp.LobbyScreen.code != None:
CApp.LobbyScreen.exit()
if __name__ == '__main__':
run()