initial linux support (check for lowercase dirs)

This commit is contained in:
cidoku 2025-02-17 16:45:06 -03:00
parent 448dbeb63e
commit a524e0d3ca
4 changed files with 61 additions and 46 deletions

View File

@ -95,6 +95,11 @@ if not debugmode:
import gameview, mainmenu, options import gameview, mainmenu, options
# This hides stupid useless QT warnings
def handler(msg_type, msg_string):
pass
QtCore.qInstallMsgHandler(handler)
audio.init() audio.init()
shit = gamewindow() shit = gamewindow()
shit.show() shit.show()

View File

@ -34,9 +34,11 @@ Returns string with dll name if it's missing, empty if all DLLs are in place
one = os.path.exists(os.path.abspath(dllf)) one = os.path.exists(os.path.abspath(dllf))
two = os.path.exists(os.path.abspath(opus)) two = os.path.exists(os.path.abspath(opus))
three = os.path.exists(os.path.abspath(flac)) three = os.path.exists(os.path.abspath(flac))
four = os.path.exists(os.path.abspath(midi))
if not one: return dllf if not one: return dllf
if not two: return two if not two: return two
if not three: return three if not three: return three
if not four: return four
return "" return ""
@ -53,13 +55,20 @@ Initialize BASS and the opus plugin
else: else:
import pybass as dll import pybass as dll
import pybass.pybassmidi as bassmidi import pybass.pybassmidi as bassmidi
dll.BASS_Init(ini.read_ini_int("AO2XP.ini", "Audio", "device", -1), freq, 0, 0, 0) if not dll.BASS_Init(ini.read_ini_int("AO2XP.ini", "Audio", "device", -1), freq, 0, 0, 0):
dll.BASS_PluginLoad(os.path.abspath(opus), 0) print "[audio] Audio library could not be initialized. Error", self.getbasserror()
dll.BASS_PluginLoad(os.path.abspath(flac), 0) if not dll.BASS_PluginLoad(os.path.abspath(opus), 0):
dll.BASS_PluginLoad(os.path.abspath(midi), 0) print "[audio] Opus plugin failed to load. Error", self.getbasserror()
if not dll.BASS_PluginLoad(os.path.abspath(flac), 0):
dll.BASS_SetConfigPtr(bassmidi.BASS_CONFIG_MIDI_DEFFONT, "gm.sf2"); print "[audio] FLAC plugin failed to load. Error", self.getbasserror()
if not dll.BASS_PluginLoad(os.path.abspath(midi), 0):
print "[audio] MIDI plugin failed to load. Error", self.getbasserror()
if os.path.exists(os.path.abspath("gm.sf2")):
dll.BASS_SetConfigPtr(bassmidi.BASS_CONFIG_MIDI_DEFFONT, "gm.sf2");
else:
print "[audio] Soundfont not fount. MIDI files will not play."
def free(): def free():
""" """

View File

@ -9,7 +9,7 @@ AO2XPpath = "AO2XPbase/"
def get_option(section, value, default=""): def get_option(section, value, default=""):
tempini = ConfigParser() tempini = ConfigParser()
tempini.read("ao2xp.ini") tempini.read("AO2XP.ini")
return ini.read_ini(tempini, section, value, default) return ini.read_ini(tempini, section, value, default)
class CharIcon(QtGui.QLabel): class CharIcon(QtGui.QLabel):
@ -111,10 +111,11 @@ class charselect(QtGui.QWidget):
else: else:
self.prevpage.hide() self.prevpage.hide()
if exists(AOpath+"characters/"+self.charlist[ind][0]+"/char_icon.png"): # AO2 char = self.charlist[ind][0].lower()
self.setBtnImage.emit(AOpath+"characters/"+self.charlist[ind][0]+"/char_icon.png", i) if exists(AOpath+"characters/"+ char +"/char_icon.png"): # AO2
elif exists(AOpath+"misc/demothings/"+self.charlist[ind][0]+"_char_icon.png"): # AO 1.7.5/1.8 self.setBtnImage.emit(AOpath+"characters/"+ char +"/char_icon.png", i)
self.setBtnImage.emit(AOpath+"misc/demothings/"+self.charlist[ind][0]+"_char_icon.png", i) elif exists(AOpath+"misc/demothings/"+ char +"_char_icon.png"): # AO 1.7.5/1.8
self.setBtnImage.emit(AOpath+"misc/demothings/"+ char +"_char_icon.png", i)
else: else:
self.setBtnImage.emit("placeholder.png", i) self.setBtnImage.emit("placeholder.png", i)

View File

@ -80,7 +80,7 @@ def encode_ao_str(text):
def get_char_ini(char, section, value, default=""): def get_char_ini(char, section, value, default=""):
tempini = ConfigParser() tempini = ConfigParser()
with open(AOpath + 'characters/' + char + '/char.ini', 'r') as file: with open(AOpath + 'characters/' + char.lower() + '/char.ini', 'r') as file:
for line in file: for line in file:
try: try:
tempini.readfp(file) tempini.readfp(file)
@ -261,7 +261,7 @@ class AOCharMovie(QtGui.QLabel):
self.pillow_frames = [] self.pillow_frames = []
self.pillow_frame = 0 self.pillow_frame = 0
p_char = p_char.decode('utf-8') p_char = p_char.lower().decode('utf-8')
original_path = AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".gif" original_path = AOpath+"characters/"+p_char+"/"+emote_prefix+p_emote+".gif"
alt_path = AOpath+"characters/"+p_char+"/"+p_emote+".png" alt_path = AOpath+"characters/"+p_char+"/"+p_emote+".png"
@ -335,6 +335,7 @@ class AOCharMovie(QtGui.QLabel):
self.show() self.show()
def play_pre(self, p_char, p_emote, duration): def play_pre(self, p_char, p_emote, duration):
p_char = p_char.lower()
gif_path = AOpath+"characters/"+p_char+"/"+p_emote+".gif" gif_path = AOpath+"characters/"+p_char+"/"+p_emote+".gif"
apng_path = AOpath+"characters/"+p_char+"/"+p_emote+".apng" apng_path = AOpath+"characters/"+p_char+"/"+p_emote+".apng"
webp_path = AOpath+"characters/"+p_char+"/"+p_emote+".webp" webp_path = AOpath+"characters/"+p_char+"/"+p_emote+".webp"
@ -381,6 +382,7 @@ class AOCharMovie(QtGui.QLabel):
self.play(p_char, p_emote, "") self.play(p_char, p_emote, "")
def play_talking(self, p_char, p_emote): def play_talking(self, p_char, p_emote):
p_char = p_char.lower()
gif_path = AOpath + 'characters/' + p_char + '/(b)' + p_emote + '.gif' gif_path = AOpath + 'characters/' + p_char + '/(b)' + p_emote + '.gif'
self.m_movie.stop() self.m_movie.stop()
@ -394,6 +396,7 @@ class AOCharMovie(QtGui.QLabel):
self.play(p_char, p_emote, '(b)') self.play(p_char, p_emote, '(b)')
def play_idle(self, p_char, p_emote): def play_idle(self, p_char, p_emote):
p_char = p_char.lower()
gif_path = AOpath + 'characters/' + p_char + '/(a)' + p_emote + '.gif' gif_path = AOpath + 'characters/' + p_char + '/(a)' + p_emote + '.gif'
self.m_movie.stop() self.m_movie.stop()
@ -1349,9 +1352,9 @@ class gui(QtGui.QWidget):
effectslist.insert(0, "No effect") effectslist.insert(0, "No effect")
self.effectdropdown.addItems(effectslist) self.effectdropdown.addItems(effectslist)
charname = unicode(charname) charname = unicode(charname.toLower())
self.charname = unicode(ini.read_ini(AOpath + 'characters/' + charname + '/char.ini', "options", "name", charname), "utf-8") self.charname = ini.read_ini(AOpath + 'characters/' + charname + '/char.ini', "options", "name", charname).decode('utf-8').lower()
self.charside = ini.read_ini(AOpath + 'characters/' + charname + '/char.ini', "options", "side", "def") self.charside = ini.read_ini(AOpath + 'characters/' + charname + '/char.ini', "options", "side", "def")
self.posdropdown.setCurrentIndex(self.posdropdown.findText(self.charside)) self.posdropdown.setCurrentIndex(self.posdropdown.findText(self.charside))
@ -1683,7 +1686,7 @@ class gui(QtGui.QWidget):
msg += "chat#" msg += "chat#"
msg += emote[1]+"#" #pre-anim msg += emote[1]+"#" #pre-anim
msg += self.charname+"#" msg += self.charname.title()+"#"
msg += emote[2]+"#" #anim msg += emote[2]+"#" #anim
msg += text.decode('utf-8')+"#" msg += text.decode('utf-8')+"#"
msg += self.charside+"#" msg += self.charside+"#"
@ -1884,8 +1887,8 @@ class gui(QtGui.QWidget):
if objection_mod <= 4 and objection_mod >= 1: if objection_mod <= 4 and objection_mod >= 1:
objections = ["holdit", "objection", "takethat", "custom_objections/"+custom_objection if custom_objection != "custom" else "custom"] objections = ["holdit", "objection", "takethat", "custom_objections/"+custom_objection if custom_objection != "custom" else "custom"]
self.objectionview.play(objections[objection_mod-1], f_char) self.objectionview.play(objections[objection_mod-1], f_char.lower())
self.playObjectionSnd(f_char, objection_mod) self.playObjectionSnd(f_char.lower(), objection_mod)
emote_mod = int(self.m_chatmessage[EMOTE_MOD]) emote_mod = int(self.m_chatmessage[EMOTE_MOD])
if emote_mod == 0: if emote_mod == 0:
@ -2484,8 +2487,8 @@ class gui(QtGui.QWidget):
else: else:
self.objectsnd = None self.objectsnd = None
if ini.read_ini_bool("AO2XP.ini", "General", "download sounds", True): if ini.read_ini_bool("AO2XP.ini", "General", "download sounds", True):
thread.start_new_thread(download_thread, ("base/characters/"+charname.lower()+"/"+objecting.lower()+".wav", AOpath+"characters/"+charname.lower()+"/"+objecting.lower()+".wav")) thread.start_new_thread(download_thread, ("base/characters/"+charname+"/"+objecting+".wav", AOpath+"characters/"+charname+"/"+objecting.lower()+".wav"))
thread.start_new_thread(download_thread, ("base/characters/"+charname.lower()+"/"+objecting.lower()+".opus", AOpath+"characters/"+charname.lower()+"/"+objecting.lower()+".wav")) thread.start_new_thread(download_thread, ("base/characters/"+charname+"/"+objecting+".opus", AOpath+"characters/"+charname+"/"+objecting.lower()+".wav"))
if exists(AOpath + 'sounds/general/sfx-objection.opus'): if exists(AOpath + 'sounds/general/sfx-objection.opus'):
self.objectsnd = audio.loadhandle(False, AOpath + 'sounds/general/sfx-objection.opus', 0, 0, 0) self.objectsnd = audio.loadhandle(False, AOpath + 'sounds/general/sfx-objection.opus', 0, 0, 0)
@ -2524,24 +2527,18 @@ class gui(QtGui.QWidget):
audio.playhandle(self.sound, True) audio.playhandle(self.sound, True)
def playMusic(self, mus): def playMusic(self, mus):
if mus == "~stop.mp3":
self.stopMusic()
return
if not mus.endswith(".mp3") and "===MUSIC START===.mp3" in self.musiclist: #vidya workaround if not mus.endswith(".mp3") and "===MUSIC START===.mp3" in self.musiclist: #vidya workaround
mus += ".mp3" mus += ".mp3"
musl = mus.lower()
# if self.music:
# if audio.handleisactive(self.music):
# audio.stophandle(self.music)
# audio.freehandle(self.music)
# if self.stream:
# self.stream = None
# if self.download_thread:
# self.download_thread.terminate() # Live dangerously
# self.download_thread = None
self.stopMusic() self.stopMusic()
if exists(AOpath + 'sounds/music/' + mus): if exists(AOpath + 'sounds/music/' + musl):
self.music = audio.loadhandle(False, AOpath + 'sounds/music/' + mus, 0, 0, BASS_SAMPLE_LOOP) self.music = audio.loadhandle(False, AOpath + 'sounds/music/' + musl, 0, 0, BASS_SAMPLE_LOOP)
audio.sethandleattr(self.music, BASS_ATTRIB_VOL, self.musicslider.value() / 100.0) audio.sethandleattr(self.music, BASS_ATTRIB_VOL, self.musicslider.value() / 100.0)
audio.playhandle(self.music, True) audio.playhandle(self.music, True)
@ -2549,12 +2546,12 @@ class gui(QtGui.QWidget):
if mus.lower().startswith("http"): if mus.lower().startswith("http"):
#self.music = audio.loadURLhandle(mus, 0, BASS_STREAM_BLOCK | BASS_SAMPLE_LOOP) #self.music = audio.loadURLhandle(mus, 0, BASS_STREAM_BLOCK | BASS_SAMPLE_LOOP)
self.music = audio.loadURLhandle(mus, 0, BASS_SAMPLE_LOOP) self.music = audio.loadURLhandle(mus, 0, BASS_SAMPLE_LOOP)
print "[audio] Trying to play", mus.lower() print "[audio] Trying to play", mus
else: else:
for bucket in buckets: for bucket in buckets:
if not bucket: continue if not bucket: continue
print "[audio] Music stream:", bucket+'base/sounds/music/' + mus.lower() print "[audio] Music stream:", bucket+'base/sounds/music/' + mus
self.music = audio.loadURLhandle(bucket+'base/sounds/music/' + mus.lower(), 0, BASS_STREAM_BLOCK | BASS_SAMPLE_LOOP) self.music = audio.loadURLhandle(bucket+'base/sounds/music/' + musl, 0, BASS_STREAM_BLOCK | BASS_SAMPLE_LOOP)
if self.music: break if self.music: break
if self.music: if self.music:
@ -2563,7 +2560,6 @@ class gui(QtGui.QWidget):
else: else:
print "[audio] Couldn't play music. Error", audio.getbasserror() print "[audio] Couldn't play music. Error", audio.getbasserror()
# Here comes the evil HTTPS hack for XP systems, but it also allows us to download and play modules and midis, because, why not? # Here comes the evil HTTPS hack for XP systems, but it also allows us to download and play modules and midis, because, why not?
musl = mus.lower()
musext = os.path.splitext(basename(musl))[-1] musext = os.path.splitext(basename(musl))[-1]
if musext in ['.mid', '.midi']: if musext in ['.mid', '.midi']:
self.specialstream = 1 self.specialstream = 1
@ -2657,7 +2653,7 @@ class gui(QtGui.QWidget):
self.healthbars.emit(hp[0], hp[1]) self.healthbars.emit(hp[0], hp[1])
for char in self.charlist: for char in self.charlist:
if not exists(AOpath + 'characters/' + char[0] + '/char.ini'): if not exists(AOpath + 'characters/' + char[0].lower() + '/char.ini'):
continue continue
char[2] = get_char_ini(char[0], "options", "gender", "male") char[2] = get_char_ini(char[0], "options", "gender", "male")
@ -2691,10 +2687,15 @@ class gui(QtGui.QWidget):
song = song.replace("<and>","&").decode('utf-8') song = song.replace("<and>","&").decode('utf-8')
songitem = QtGui.QListWidgetItem() songitem = QtGui.QListWidgetItem()
songitem.setText(song) songitem.setText(song)
if exists(AOpath + 'sounds/music/' + song): try:
if not song.endswith("mp3") and not song.endswith("opus") :
print song
except:
pass
if exists(AOpath + 'sounds/music/' + song.lower()):
songitem.setBackgroundColor(QtGui.QColor(128, 255, 128)) songitem.setBackgroundColor(QtGui.QColor(128, 255, 128))
else: #else:
songitem.setBackgroundColor(QtGui.QColor(255, 128, 128)) #songitem.setBackgroundColor(QtGui.QColor(255, 128, 128))
self.musicitems.addItem(songitem) self.musicitems.addItem(songitem)
for pid in playerlist: for pid in playerlist:
@ -3039,7 +3040,7 @@ class TCP_Thread(QtCore.QThread):
self.send_attempts += 1 self.send_attempts += 1
if self.send_attempts >= self.max_attempts: if self.send_attempts >= self.max_attempts:
self.send_attempts = 0 self.send_attempts = 0
print "[warning] message discarded" #print "[warning] message discarded"
del self.parent.msgqueue[0] del self.parent.msgqueue[0]
self.parent.msgqueueList.takeItem(0) self.parent.msgqueueList.takeItem(0)
continue continue
@ -3074,14 +3075,13 @@ class TCP_Thread(QtCore.QThread):
if len(network) > 3 and network[3]: if len(network) > 3 and network[3]:
name += " ("+network[3].decode("utf-8")+")" name += " ("+network[3].decode("utf-8")+")"
#self.parent.icLog.append('[%d:%.2d] %s changed the music to %s' % (t[3], t[4], name, music))
self.IC_Log.emit('[%d:%.2d] %s changed the music to %s' % (t[3], t[4], name, music)) self.IC_Log.emit('[%d:%.2d] %s changed the music to %s' % (t[3], t[4], name, music))
else: else:
self.IC_Log.emit('[%d:%.2d] the music was changed to %s' % (t[3], t[4], music)) self.IC_Log.emit('[%d:%.2d] The music was changed to %s' % (t[3], t[4], music))
self.parent.playMusic(music) self.parent.playMusic(music)
elif header == 'BN': elif header == 'BN':
self.newBackground.emit(network[1]) self.newBackground.emit(network[1].lower())
elif header == 'CT': elif header == 'CT':
name = decode_ao_str(network[1].decode('utf-8')) name = decode_ao_str(network[1].decode('utf-8'))