Redone
- Everything has been redone.
This commit is contained in:
parent
42033b8c60
commit
6082478c63
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
bin/python/
|
|
||||||
games/*/
|
|
||||||
mods/*/
|
|
136
UniversalModloader.py
Normal file
136
UniversalModloader.py
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import ctypes
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import webbrowser
|
||||||
|
appPath = sys.argv[1]
|
||||||
|
appName = appPath.replace(os.path.dirname(appPath)+ "\\","")
|
||||||
|
originalAppPath = appPath + " - umlOriginal"
|
||||||
|
tmpAppPath = appPath + " - umlTemp"
|
||||||
|
modPath = os.path.join(appPath,"umlMods")
|
||||||
|
originalModPath = os.path.join(originalAppPath,"umlMods")
|
||||||
|
|
||||||
|
def loadMods(output = False):
|
||||||
|
if areModsLoaded():
|
||||||
|
if unloadMods() == False:
|
||||||
|
if output: print("Unloading mods failed!")
|
||||||
|
return False
|
||||||
|
|
||||||
|
cloneFolder(appPath,tmpAppPath,False)
|
||||||
|
for root,dirs,files in walklevel(modPath,0):
|
||||||
|
for dir in dirs:
|
||||||
|
cloneFolder(os.path.join(root,dir),tmpAppPath,True,False)
|
||||||
|
|
||||||
|
os.rename(appPath,originalAppPath)
|
||||||
|
os.rename(tmpAppPath,appPath)
|
||||||
|
ctypes.windll.kernel32.SetFileAttributesW(originalAppPath,2)
|
||||||
|
|
||||||
|
if output: print("Mods have been loaded!")
|
||||||
|
return True
|
||||||
|
|
||||||
|
def unloadMods(output = False):
|
||||||
|
if areModsLoaded() == False:
|
||||||
|
if output: print("Mods are already unloaded.")
|
||||||
|
return True
|
||||||
|
|
||||||
|
shutil.rmtree(appPath)
|
||||||
|
os.rename(originalAppPath,appPath)
|
||||||
|
ctypes.windll.kernel32.SetFileAttributesW(appPath,128)
|
||||||
|
|
||||||
|
if output: print("Unloading mods successful.")
|
||||||
|
return True
|
||||||
|
|
||||||
|
def openModsFolder():
|
||||||
|
if areModsLoaded():
|
||||||
|
webbrowser.open("file:///" +originalModPath)
|
||||||
|
else:
|
||||||
|
webbrowser.open("file:///" +modPath)
|
||||||
|
|
||||||
|
def areModsLoaded():
|
||||||
|
if os.path.isdir(originalAppPath):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def cloneFolder(src,dst,rpl,ignoreMods = True):
|
||||||
|
for root,dirs,files in os.walk(src):
|
||||||
|
newRoot = root.replace(src,dst)
|
||||||
|
if ignoreMods == True:
|
||||||
|
if root.replace(modPath,"") != root: continue
|
||||||
|
|
||||||
|
if os.path.isdir(newRoot) == False: os.makedirs(newRoot)
|
||||||
|
|
||||||
|
for file in files:
|
||||||
|
fullFile = os.path.join(root,file)
|
||||||
|
newFile = os.path.join(newRoot,file)
|
||||||
|
|
||||||
|
if os.path.isfile(newFile):
|
||||||
|
if rpl == True:
|
||||||
|
os.remove(newFile)
|
||||||
|
os.link(fullFile,newFile)
|
||||||
|
else:
|
||||||
|
os.link(fullFile,newFile)
|
||||||
|
|
||||||
|
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 title(string):
|
||||||
|
if os.name == "nt":
|
||||||
|
os.system("title " +string)
|
||||||
|
else:
|
||||||
|
sys.stdout.write("\x1b]2;" +string+ "\x07")
|
||||||
|
|
||||||
|
def clear():
|
||||||
|
os.system('cls' if os.name=='nt' else 'clear')
|
||||||
|
|
||||||
|
def cleanUp():
|
||||||
|
if os.path.isdir(tmpAppPath):
|
||||||
|
shutil.rmtree(tmpAppPath)
|
||||||
|
|
||||||
|
def checkUp():
|
||||||
|
if areModsLoaded() == False:
|
||||||
|
if os.path.isdir(modPath) == False:
|
||||||
|
os.makedirs(modPath)
|
||||||
|
|
||||||
|
def mainMenu():
|
||||||
|
clear()
|
||||||
|
|
||||||
|
if areModsLoaded() == False:
|
||||||
|
print("Welcome to Fier's Universal Modloader.")
|
||||||
|
print("Mods are not loaded.")
|
||||||
|
print("")
|
||||||
|
print("Please choose an action:")
|
||||||
|
print("1) Load Mods")
|
||||||
|
print("2) Open Mods-Folder")
|
||||||
|
choice = input("Choice: ")
|
||||||
|
|
||||||
|
clear()
|
||||||
|
if choice == "1": loadMods(True); input("Press ENTER to continue.")
|
||||||
|
if choice == "2": openModsFolder()
|
||||||
|
else:
|
||||||
|
print("Welcome to Fier's Universal Modloader.")
|
||||||
|
print("Mods are loaded.")
|
||||||
|
print("")
|
||||||
|
print("Please choose an action:")
|
||||||
|
print("1) Reload Mods")
|
||||||
|
print("2) Unload Mods")
|
||||||
|
print("3) Open Mods-Folder")
|
||||||
|
choice = input("Choice: ")
|
||||||
|
|
||||||
|
clear()
|
||||||
|
if choice == "1": loadMods(True); input("Press ENTER to continue.")
|
||||||
|
if choice == "2": unloadMods(True); input("Press ENTER to continue.")
|
||||||
|
if choice == "3": openModsFolder()
|
||||||
|
|
||||||
|
title("Fier's Universal Modloader: " +appName)
|
||||||
|
cleanUp()
|
||||||
|
checkUp()
|
||||||
|
while True:
|
||||||
|
mainMenu()
|
@ -1,9 +0,0 @@
|
|||||||
@echo off
|
|
||||||
:start
|
|
||||||
cls
|
|
||||||
cd %~dp0
|
|
||||||
::set tmp=%~dp0\bin\tmp
|
|
||||||
::set temp=%tmp%
|
|
||||||
bin\python\python.exe py\modloader.py
|
|
||||||
pause
|
|
||||||
goto start
|
|
162
py/modloader.py
162
py/modloader.py
@ -1,162 +0,0 @@
|
|||||||
#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+ "'...")
|
|
Loading…
Reference in New Issue
Block a user