Last active
October 5, 2024 14:46
-
-
Save simplistik/81f5dc04df62ebfedc060892df902ea5 to your computer and use it in GitHub Desktop.
Remnant 2: Xbox GamePass (PC), RemnantSaveGuardian save file generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import shutil | |
| import getpass | |
| import time | |
| # Set debug variable | |
| debug = False | |
| # Searches for a folder containing 'containers.index' within the given root_folder. | |
| def find_save_folder(root_folder): | |
| for root, dirs, files in os.walk(root_folder): | |
| if 'containers.index' in files: | |
| if debug: | |
| print(f"Save folder found: {root}") | |
| return root | |
| if debug: | |
| print("Save folder with 'containers.index' not found.") | |
| return None | |
| # Function to get creation date of a folder | |
| def get_folder_creation_date(folder_path): | |
| return os.path.getctime(folder_path) | |
| # Retrieve the username of the user currently logged into the system | |
| user_name = getpass.getuser() | |
| #------- EDIT YOUR DETAILS HERE -------# | |
| # Destination folder path, this can be whatever folder you want | |
| destination_folder = rf"C:\Users\{user_name}\Documents\RSG_Temp" | |
| #------- STOP, DON'T EDIT BELOW THIS -------# | |
| # Dictionary to store file details (including the creation date of their parent folder) | |
| file_details = {} | |
| profile_file = "profile.sav" | |
| root_folder = rf"C:\Users\{user_name}\AppData\Local\Packages\PerfectWorldEntertainment.GFREMP2_jrajkyc4tsa6w\SystemAppData\wgs" | |
| # Source folder path | |
| source_folder = find_save_folder(root_folder) | |
| # Prefix to be excluded | |
| excluded_prefix = "container" | |
| # Create the destination folder if it doesn't exist | |
| if not os.path.exists(destination_folder): | |
| os.makedirs(destination_folder) | |
| if debug: | |
| print(f"Created destination folder: {destination_folder}") | |
| # Empty the entire destination folder | |
| for file_name in os.listdir(destination_folder): | |
| file_path = os.path.join(destination_folder, file_name) | |
| if os.path.isfile(file_path): | |
| os.remove(file_path) | |
| if debug: | |
| print(f"Removed existing file: {file_name}") | |
| # Iterate through the source folder and its subdirectories | |
| for root, dirs, files in os.walk(source_folder): | |
| for file_name in files: | |
| if not file_name.startswith(excluded_prefix): | |
| source_file_path = os.path.join(root, file_name) | |
| destination_file_path = os.path.join(destination_folder, file_name) | |
| try: | |
| # Store the creation date of the parent folder before moving | |
| file_details[file_name] = { | |
| 'source_path': source_file_path, | |
| 'creation_date': get_folder_creation_date(root) | |
| } | |
| shutil.copy2(source_file_path, destination_file_path) | |
| if debug: | |
| print(f"File '{file_name}' copied successfully.") | |
| except FileNotFoundError: | |
| print(f"File '{file_name}' not found in the source folder.") | |
| except Exception as e: | |
| print(f"Error copying '{file_name}': {e}") | |
| # Sort files by the creation date of their original parent folder, then by size | |
| sorted_files = sorted(file_details.keys(), key=lambda f: (file_details[f]['creation_date'], os.path.getsize(os.path.join(destination_folder, f)))) | |
| # Print sorted files with their original parent folder creation date and size | |
| if debug: | |
| for file in sorted_files: | |
| file_path = os.path.join(destination_folder, file) | |
| original_parent_folder_creation_date = time.ctime(file_details[file]['creation_date']) | |
| file_size = os.path.getsize(file_path) | |
| print(f"File: {file}, Original Parent Folder Creation Date: {original_parent_folder_creation_date}, Size: {file_size} bytes") | |
| # Rename files | |
| for index, file_name in enumerate(sorted_files): | |
| new_file_name = "profile.sav" if index == 0 else f"save_{index - 1}.sav" | |
| os.rename(os.path.join(destination_folder, file_name), os.path.join(destination_folder, new_file_name)) | |
| print(f"Renamed file ({file_name}) to '{new_file_name}'") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so the renaming file part broke for me after DLC 3 was released. I managed to get it working with the following changes: