From 42033b8c60fa72a224b6abf9de42fee0974db6db Mon Sep 17 00:00:00 2001 From: Fierelier Date: Sun, 9 Apr 2017 20:51:11 +0200 Subject: [PATCH] Initial Commit - --- .gitignore | 3 + launch.bat | 9 +++ mods/- | 0 py/modloader.py | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 .gitignore create mode 100644 launch.bat create mode 100644 mods/- create mode 100644 py/modloader.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec9f8f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/python/ +games/*/ +mods/*/ \ No newline at end of file diff --git a/launch.bat b/launch.bat new file mode 100644 index 0000000..089df8a --- /dev/null +++ b/launch.bat @@ -0,0 +1,9 @@ +@echo off +:start +cls +cd %~dp0 +::set tmp=%~dp0\bin\tmp +::set temp=%tmp% +bin\python\python.exe py\modloader.py +pause +goto start \ No newline at end of file diff --git a/mods/- b/mods/- new file mode 100644 index 0000000..e69de29 diff --git a/py/modloader.py b/py/modloader.py new file mode 100644 index 0000000..aa91ffa --- /dev/null +++ b/py/modloader.py @@ -0,0 +1,162 @@ +#Imports +import sys +import os +import shutil +import stat +import ctypes + +#Working variables +version = 0.1 +scriptPath = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..") +gamesPath = os.path.join(scriptPath,"games") +baseTitle = "Universal ModLoader " +str(version) + +def main(): + while True: + title(baseTitle) + clear() + print("Games:") + + index = 1 + for root,dirs,files in walklevel(gamesPath,0): + for dir in dirs: + print(str(index)+ ") " +dir) + index = index + 1 + + print("") + print("S) Search Games, A) Add Game") + choice = input("Choice: ") + if choice.lower() == "a": addGame(); continue + if choice.lower() == "s": searchGames(); continue + if isType(int,choice) == False: continue; + if int(choice) > index - 1 or int(choice) < 1: continue + + game = getFolderByIndex(gamesPath,int(choice)-1) + if game == "": continue + manageGame(game) + +def manageGame(game): + gamePath = os.path.join(gamesPath,game) + profilesPath = os.path.join(gamePath,"profiles") + + while True: + title(baseTitle+ " - " +game) + clear() + print("B) Back") + print("E) Edit Game, R) Reload Mods, U) Unload Mods") + print("") + print("Profiles:") + + index = 1 + for root,dirs,files in walklevel(profilesPath,0): + for dir in dirs: + print(str(index)+ ") " +dir) + index = index + 1 + + print("") + print("S) Search Profiles, A) Add Profile") + choice = input("Choice: ") + + +def getFolderByIndex(searchFolder,wanted): + index = 0 + for root,dirs,files in walklevel(searchFolder,0): + for dir in dirs: + if index == wanted: return dir + index = index + 1 + + return "" + +def walklevel(some_dir, level=1): + some_dir = some_dir.rstrip(os.path.sep) + assert os.path.isdir(some_dir) + num_sep = some_dir.count(os.path.sep) + for root, dirs, files in os.walk(some_dir): + yield root, dirs, files + num_sep_this = root.count(os.path.sep) + if num_sep + level <= num_sep_this: + del dirs[:] + +def clear(): + if os.name == "nt": + os.system("cls") + else: + os.system("clear") + +def title(titleText): + if os.name == "nt": + ctypes.windll.kernel32.SetConsoleTitleW(titleText) + else: + sys.stdout.write("\x1b]2;" +titleText+ "\x07") #needs testing + +def isType(type,value): + try: + type(value) + return True + except ValueError: + return False + +main() + +########################################OLD######################################## +def setupFolder(): + while True: + gameFolder = input("Drag + Drop GTA SA's folder in here and press enter:\n") + gameFolder = gameFolder.replace("\"","") + if os.path.isfile(os.path.join(gameFolder,"gta_sa.exe")): + file = open(os.path.join(scriptPath,"gtasafolder.txt"),"w") + file.write(gameFolder) + file.close() + return True + clear() + print("'gta_sa.exe' was not found in this path. Try again.") + +def loadMods(): + clear() + print("Please wait...") + originalFolder = gameFolder+ " - Original" + if not os.path.isdir(originalFolder): os.rename(gameFolder,originalFolder) + if os.path.isdir(gameFolder): shutil.rmtree(gameFolder) + for root,dirs,files in walklevel(os.path.join(scriptPath,"mods"),0): + for dir in dirs: + if dir[0] != "-": cloneFolder(os.path.join(root,dir),gameFolder,True) + + cloneFolder(originalFolder,gameFolder,False) + input("\nMods have been successfully loaded. Press any key to continue.") + return True + +def unloadMods(): + clear() + print("Please wait...") + originalFolder = gameFolder+ " - Original" + if not os.path.isdir(originalFolder): + clear() + input("Mods are already unloaded. Press any key to continue.") + return True + + shutil.rmtree(gameFolder) + os.rename(originalFolder,gameFolder) + input("\nMods have been successfully unloaded. Press any key to continue.") + return True + +def getGameFolder(): + file = open(os.path.join(scriptPath,"gtasafolder.txt")) + for line in file: + file.close() + return line.replace("\n","") + +def cloneFolder(src,dest,overwrite): + for root,dirs,files in os.walk(src): + for file in files: + srcFile = os.path.join(root,file) + newFile = srcFile.replace(src,dest) + newFolder = os.path.dirname(newFile) + if not os.path.isdir(newFolder): os.makedirs(newFolder) + + if overwrite == True: + if os.path.isfile(newFile): os.remove(newFile) + + if not os.path.isfile(newFile): + #os.system('mklink /H "' +newFile+ '" "' +srcFile+ '"') + os.link(srcFile,newFile) + print("Linking '" +srcFile+ "' to '" +newFile+ "'...") \ No newline at end of file