/
concerto.py
205 lines (191 loc) · 8.71 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
import sys
from config import * # App config functions
from gamedata import *
# System
import requests
import time
import threading
import subprocess
import winreg
import ui.lang
# 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.discord = False #Discord support flag
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
self.player_name = 'Concerto Player' #static player name to use for online lobbies
self.lang = ui.lang.current_lang
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(CApp=self)
self.OptionScreen = optionscreen.OptionScreen(CApp=self)
self.LobbyList = lobbylist.LobbyList(CApp=self)
self.LobbyScreen = lobbyscreen.LobbyScreen(CApp=self)
self.HowtoScreen = howtoscreen.HowtoScreen(CApp=self)
self.AboutScreen = aboutscreen.AboutScreen(CApp=self)
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):
logging.info('Concerto: Version %s' % CURRENT_VERSION)
if DEBUG_VERSION != "":
logging.info('Concerto: Debug Version %s' % DEBUG_VERSION)
logging.warning('Concerto: old CWD is %s' % os.getcwd())
os.chdir(PATH)
logging.warning('Concerto: new CWD is %s' % os.getcwd())
#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 = ui.lang.localize('TIP_CONCERTO_INVITES')
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)
#TODO integrity check all CCCaster essential assets
if caster_config is None:
e.append(ui.lang.localize('ERR_CCCASTER_MISSING'))
if game_config is None:
e.append(ui.lang.localize('ERR_SYSDATA_MISSING'))
if e != []:
self.sound.muted = True
e.append(ui.lang.localize('ERR_FIX_ISSUES'))
self.MainScreen.error_message(e,fatal=True)
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()
if app_config['settings']['discord'] == '1':
self.discord = True
# Connect discord rich presence
presence.connect()
presence.menu()
self.sound.mute_alerts = app_config['settings']['mute_alerts'] == '1'
self.player_name = caster_config['settings']['displayName']
# Execute launch params
if len(sys.argv) > 1:
params = sys.argv[1].replace('concerto://', '').rstrip('/').split(':', 1)
if params[0] == 'lobby':
check = self.OnlineScreen.online_login()
if check != []:
self.OnlineScreen.error_message(check)
else:
self.LobbyList.join(code=params[1])
elif params[0] == 'connect':
self.OnlineScreen.join(ip=params[1])
elif params[0] == 'watch':
self.OnlineScreen.watch(ip=params[1])
def on_stop(self,*args):
self.game.kill_caster()
if self.LobbyScreen.code != None:
self.LobbyScreen.exit()
if self.discord is True:
presence.close()
def lobby_button(self, *args):
for i in self.sm.screens:
if 'lobbyAnchor' in i.ids and i != self.LobbyScreen:
a = i.ids['lobbyAnchor']
b = buttons.LobbyBtn()
b.text += ' %s' % self.LobbyScreen.code
b.bind(on_release=self.switch_to_lobby)
a.clear_widgets()
a.add_widget(b)
def remove_lobby_button(self, *args):
for i in self.sm.screens:
if 'lobbyAnchor' in i.ids and i != self.LobbyScreen:
i.ids['lobbyAnchor'].clear_widgets()
def update_lobby_button(self,text,*args):
for i in self.sm.screens:
if 'lobbyAnchor' in i.ids and i != self.LobbyScreen:
a = i.ids['lobbyAnchor'].children
for n in a:
n.text = text
def switch_to_lobby(self, *args):
self.sm.current = 'Lobby'
def switch_to_main(self, *args):
self.sm.current = 'Main'
def checkPop(self, *args):
while True:
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)
def run():
CApp = Concerto()
CApp.run()
if __name__ == '__main__':
run()