From 0d4ff0ff9deff422e750e8148506fffc5a35a421 Mon Sep 17 00:00:00 2001 From: cidoku Date: Mon, 26 Jan 2026 21:42:51 -0300 Subject: [PATCH] improved evil xp https music download hack --- gameview.py | 93 +++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/gameview.py b/gameview.py index 943a825..2dbba1d 100644 --- a/gameview.py +++ b/gameview.py @@ -73,19 +73,20 @@ def downloadThread(link, savepath): return print "[client] Download missing: %s" % link - fp = urllib.urlopen(bucket + link) + print "[client] Trying to download from: %s" % (bucket + link) + fp = urlopen(bucket + link) if fp.getcode() == 200: - print savepath[:-1] + print "[client] Downloading to", savepath[:-1] if not os.path.exists(savepath[:-1]): os.makedirs(savepath[:-1]) with open(savepath, "wb") as f: f.write(fp.read()) - print "successfully downloaded:", link + print "[client] Successfully downloaded:", link return DOWNLOAD_BLACKLIST.append(link) - print "couldn't download '%s'" % link + print "[client] Couldn't download '%s'" % link def mockString(text): upper = random.choice([True, False]) @@ -110,7 +111,7 @@ def mockString(text): class XPMusicDownloadThread(QtCore.QThread): # Part of the evil HTTPS music download hack for XP systems - finished_signal = QtCore.pyqtSignal(int, str) + finishedSignal = QtCore.pyqtSignal(int, str) def __init__(self, caller, url): super(XPMusicDownloadThread, self).__init__() @@ -127,53 +128,53 @@ class XPMusicDownloadThread(QtCore.QThread): return headers = { - 'User-Agent': "AO2XP %s" % (GAME_VERSION), + 'User-Agent': "AO2XP %s" % GAME_VERSION, 'Accept': '*/*', 'Accept-Encoding': 'identity', 'Connection': 'Keep-Alive' } request = Request(url, headers=headers) - #request.get_method = lambda: 'HEAD' + try: response = urlopen(request, timeout=5) - # print request.headers - # print response.headers except Exception as e: - print "[audio] HTTP request failed, aborting... Details below:" + print "[audio] HTTP request failed, aborting..." print "[audio]", e, url self.quit() return - file_length = int(response.headers.get('Content-Length', 0)) + try: + fileLength = response.headers.get('Content-Length') + if fileLength is not None: + fileLength = int(fileLength) - if file_length > 0: - request = Request(url, headers=headers) - response = urlopen(request) - stream = "" + chunks = [] + bytesDownloaded = 0 + bufferSize = 8192 - bytes_downloaded = 0 - buffer_size = 8192 - - while bytes_downloaded < file_length: - if self.exiting: - self.quit() - break - - chunk = response.read(buffer_size) + while not self.exiting: + chunk = response.read(bufferSize) if not chunk: break - stream += chunk - bytes_downloaded += len(chunk) + chunks.append(chunk) + bytesDownloaded += len(chunk) - if not self.exiting: - self.caller.stream = create_string_buffer(stream) - self.finished_signal.emit(file_length, self.url) - else: - print "[audio] Stream is empty, aborting..." - self.quit() - return + if self.exiting: + self.quit() + return + + stream = ''.join(chunks) + + if fileLength is not None and bytesDownloaded != fileLength: + print "[audio] Warning: downloaded size mismatch" + + self.caller.XPStream = create_string_buffer(stream) + self.finishedSignal.emit(bytesDownloaded, url) + + finally: + response.close() def stop(self): self.exiting = True @@ -1775,9 +1776,9 @@ class GUI(QtGui.QWidget): self.guiltySfx = 0 self.notGuiltySfx = 0 - self.stream = 0 + self.XPStream = 0 self.specialStream = False - self.downloadThread = None + self.XPDownloadThread = None self.tcp = None self.demoPlayer = None @@ -4437,9 +4438,9 @@ class GUI(QtGui.QWidget): self.specialStream = True if (musl.startswith("https") and error == 2) or self.specialStream: print "[audio] Downloading music with urllib2" - self.downloadThread = XPMusicDownloadThread(self, mus.replace(" ", "%20")) - self.downloadThread.finished_signal.connect(self.playDownloadedMusic) - self.downloadThread.start() + self.XPDownloadThread = XPMusicDownloadThread(self, mus.replace(" ", "%20")) + self.XPDownloadThread.finishedSignal.connect(self.playDownloadedMusic) + self.XPDownloadThread.start() else: print "[audio] Couldn't play music. Error", error @@ -4452,19 +4453,19 @@ class GUI(QtGui.QWidget): self.specialStream = False else: audio.freeHandle(self.music) - if self.stream: - self.stream = None + if self.XPStream: + self.XPStream = None - if self.downloadThread: - self.downloadThread.stop() - self.downloadThread = None + if self.XPDownloadThread: + self.XPDownloadThread.stop() + self.XPDownloadThread = None - def playDownloadedMusic(self, file_length, url): + def playDownloadedMusic(self, fileLength, url): # Part of the evil HTTPS music download hack for XP systems if self.specialStream: - self.music = audio.loadMOD(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP) + self.music = audio.loadMOD(True, self.XPStream, 0, fileLength, BASS_SAMPLE_LOOP) else: - self.music = audio.loadHandle(True, self.stream, 0, file_length, BASS_SAMPLE_LOOP) + self.music = audio.loadHandle(True, self.XPStream, 0, fileLength, BASS_SAMPLE_LOOP) if self.music: print "[audio] Done downloading; playing stream" audio.setHandleAttr(self.music, BASS_ATTRIB_VOL, self.sliMusicVolume.value() / 100.0)