From 97cb8562121a743bafe402b5837de1b7f50be7d6 Mon Sep 17 00:00:00 2001 From: NikkeDoy Date: Thu, 12 Dec 2024 02:59:15 +0200 Subject: [PATCH] :sparkles: | Added username change feature. --- ProfileManager.py | 42 ++++++++++++++++++++++++++++++++++++++++++ main.py | 4 ++++ 2 files changed, 46 insertions(+) create mode 100644 ProfileManager.py diff --git a/ProfileManager.py b/ProfileManager.py new file mode 100644 index 0000000..4905957 --- /dev/null +++ b/ProfileManager.py @@ -0,0 +1,42 @@ +import os + +default_profile_location = "./Mods/bf1942/Settings/Profiles" +default_profile = "FinnWarsLauncher" + +def check_directory_exists(directory_path): + return os.path.isdir(directory_path) + +def change_username(username): + if not os.path.exists(default_profile_location): + print("Launcher is not installed correctly!") + print("Please, move finnwarslauncher.exe to the same folder as bf1942.exe!!!") + print("Thanks! :)") + return + + if not os.path.exists(default_profile_location + "/" + default_profile): + print("Profile not found... Creating \"FinnWarsLauncher\"-profile!") + os.makedirs("./Mods/bf1942/Settings/Profiles/FinnWarsLauncher") + + if not os.path.exists(default_profile_location + "/" + default_profile + "/GeneralOptions.con"): + print("GeneralOptions.con missing... Creating it!") + try: + with open(default_profile_location + "/" + default_profile + "/GeneralOptions.con") as file: + file.write(f"game.setPlayerName \"{username}\"") + except: + print("GeneralOptions.con could not be created... error, obviously.") + else: + print("GeneralOptions.con found! Changing the name.") + with open(default_profile_location + "/" + default_profile + "/GeneralOptions.con") as file: + lines = file.readlines() + if 0 < 2 <= len(lines): + lines[2] = "game.setPlayerName \"{username}\"" + file.writelines(lines) + + try: + with open(default_profile_location + "/GeneralOptions.con") as file: + lines = file.readlines() + if 0 < 1 <= len(lines): + lines[1] = f"run Profiles/{default_profile}/GeneralOptions.con" + file.writelines(lines) + except: + print(f"Couldn't set {default_profile} as default profile. Something is wrong.") diff --git a/main.py b/main.py index 1431a06..bf9a020 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,8 @@ import pyautogui import UserData import ResourceManager +import ProfileManager + def save_preferences(): UserData.save_preferences({"server": server_address_field.get(), "username": username_field.get(), "windowed": windowed.get()}) @@ -30,6 +32,8 @@ def launch_exe(): username_field.insert(0, UserData.default_username) return + ProfileManager.change_username(username_field.get()) + # If game needs to be windowed then we use BF42Plus provided "workaround." if windowed.get(): pyautogui.keyDown("shift")