diff --git a/Enums/AssetTypes.cs b/Enums/AssetTypes.cs new file mode 100644 index 0000000..22f2af0 --- /dev/null +++ b/Enums/AssetTypes.cs @@ -0,0 +1,9 @@ +namespace USSR.Enums +{ + public enum AssetTypes + { + Asset, + Bundle, + Unknown + } +} diff --git a/Enums/WebCompressionTypes.cs b/Enums/WebCompressionTypes.cs new file mode 100644 index 0000000..33c95f1 --- /dev/null +++ b/Enums/WebCompressionTypes.cs @@ -0,0 +1,9 @@ +namespace USSR.Enums +{ + public enum WebCompressionTypes + { + None, + Brotli, + GZip + } +} diff --git a/README.md b/README.md index c235aa2..9573523 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The tool is an implementation of the guide available at () - .Title("What would you like to do? (Press ENTER go, UP/DOWN to select)") - .AddChoices(actionList) - ); - int choiceIndex = Array.FindIndex(actionList, item => item == actionPrompt); + string webDataFile = Path.Combine( + Path.GetDirectoryName(selectedFile) ?? string.Empty, + Path.GetFileNameWithoutExtension(selectedFile) + ); + string? unpackedWebDataDirectory = string.Empty; + bool isWebGL = false; - string? selectedFile = string.Empty, - webDataFile = string.Empty, - unpackedWebDataDirectory = string.Empty; - bool isWebGL = false; + AssetTypes assetType = GetAssetType(selectedFile, ref webDataFile, ref isWebGL); + if (assetType == AssetTypes.Unknown) + { + AnsiConsole.MarkupLine("[red]( ERR! )[/] Unknown/Unsupported file type!"); + Console.WriteLine(); + continue; // Prompt for action again + } - switch (choiceIndex) - { - case 0: - case 1: - AnsiConsole.MarkupLine("Opening File Picker..."); - // Unfortunately, this File Picker library currently only support one filter :( - // So we pass all file types and manually checking them if it's a valid file that we want. - DialogResult filePicker = Dialog.FileOpen( - null, - Path.GetDirectoryName(Utility.GetLastOpenedFile()) - ); + AssetsManager assetsManager = new(); + string? tpkFile = Path.Combine(ussrExec ?? string.Empty, ASSET_CLASS_DB); + if (!LoadClassPackage(assetsManager, tpkFile)) + { + continue; // Prompt for action again + } - if (filePicker.IsCancelled) - { - AnsiConsole.MarkupLine("Cancelled. Oh, it\'s okay ^_^"); - Console.WriteLine(); - goto ChooseAction; - } - else if (filePicker.IsError) - { - AnsiConsole.MarkupLine( - "[red]( RAWR )[/] Unable to open File Picker! Try using a different Terminal?" - ); - Console.WriteLine(); - goto ChooseAction; - } + List temporaryFiles = new(); + string inspectedFile = selectedFile; - selectedFile = filePicker.Path; - AnsiConsole.MarkupLineInterpolated( - $"( INFO ) Selected file: [green]{selectedFile}[/]" - ); - Utility.SaveLastOpenedFile(selectedFile); - break; - case 2: - AnsiConsole.MarkupLine("Have a nice day ;)"); - Console.ReadLine(); - return; - } + if (isWebGL) + { + unpackedWebDataDirectory = UnityWebTool.Unpack(webDataFile); + inspectedFile = Utility.FindRequiredAsset(unpackedWebDataDirectory); + assetType = GetAssetType(inspectedFile, ref webDataFile, ref isWebGL); + } - webDataFile = Path.Combine( - Path.GetDirectoryName(selectedFile) ?? string.Empty, - Path.GetFileNameWithoutExtension(selectedFile) // Without .br / .gz extension - ); - string selectedFileName = Path.GetFileName(selectedFile); + AssetsFileInstance? assetFileInstance = null; + BundleFileInstance? bundleFileInstance = null; + FileStream? bundleStream = null; - if (selectedFileName.Contains("globalgamemanagers")) - assetType = AssetTypes.Asset; - else if (selectedFileName.EndsWith(".unity3d")) - assetType = AssetTypes.Bundle; - else if (selectedFileName.EndsWith(".data")) - { - isWebGL = true; - webDataFile = selectedFile; - webGLCompressionType = WebGLCompressionType.None; - } - else if (selectedFileName.EndsWith("data.unityweb")) - { - string[] compressionList = { "Brotli", "GZip" }; - string compressionListPrompt = AnsiConsole.Prompt( - new SelectionPrompt() - .Title("What compression type did you use?") - .AddChoices(compressionList) - ); - int compressionChoiceIndex = Array.FindIndex( - compressionList, - item => item == compressionListPrompt - ); - isWebGL = true; + string tempFile = Utility.CloneFile(inspectedFile, $"{inspectedFile}.temp"); + temporaryFiles.Add(tempFile); + temporaryFiles.Add($"{tempFile}.unpacked"); - switch (compressionChoiceIndex) + switch (assetType) { - case 0: - webGLCompressionType = WebGLCompressionType.Brotli; - if ( - DecompressCompressedWebData( - webGLCompressionType, - selectedFile, - webDataFile - ) == 1 - ) - goto ChooseAction; + case AssetTypes.Asset: + assetFileInstance = LoadAssetFileInstance(tempFile, assetsManager); break; - case 1: - webGLCompressionType = WebGLCompressionType.GZip; - if ( - DecompressCompressedWebData( - webGLCompressionType, - selectedFile, - webDataFile - ) == 1 - ) - goto ChooseAction; + case AssetTypes.Bundle: + bundleStream = new FileStream(tempFile, FileMode.Open, FileAccess.Read); + bundleFileInstance = LoadBundleFileInstance( + tempFile, + assetsManager, + bundleStream + ); + assetFileInstance = LoadAssetFileInstance( + tempFile, + assetsManager, + bundleFileInstance + ); break; } - } - else if (selectedFileName.EndsWith("data.br")) - { - isWebGL = true; - webGLCompressionType = WebGLCompressionType.Brotli; - DecompressCompressedWebData(webGLCompressionType, selectedFile, webDataFile); - } - else if (selectedFileName.EndsWith("data.gz")) - { - isWebGL = true; - webGLCompressionType = WebGLCompressionType.GZip; - DecompressCompressedWebData(webGLCompressionType, selectedFile, webDataFile); - } - else - { - AnsiConsole.MarkupLine("[red]( RAWR )[/] Unknown/Unsupported file type!"); - Console.WriteLine(); - goto ChooseAction; - } - AssetsManager assetsManager = new(); - string? tpkFile = Path.Combine(ussrExec ??= string.Empty, ASSET_CLASS_DB); - LoadClassPackage(assetsManager, tpkFile); + if (assetFileInstance != null) + { + try + { + AnsiConsole.MarkupLine("( INFO ) Loading asset class types database..."); + assetsManager.LoadClassDatabaseFromPackage( + assetFileInstance.file.Metadata.UnityVersion + ); + AnsiConsole.MarkupLineInterpolated( + $"( INFO ) Unity Version: [bold green]{assetFileInstance.file.Metadata.UnityVersion}[/]" + ); - // List of files to be deleted later - List temporaryFiles = new(); - string inspectedFile = selectedFile; + switch (choiceIndex) + { + case 0: + assetFileInstance.file = RemoveSplashScreen( + assetsManager, + assetFileInstance + ); + break; + case 1: + assetFileInstance.file = RemoveWatermark( + assetsManager, + assetFileInstance + ); + break; + } - if (isWebGL) - { - // Unpack WebData asset + add to temporary files - unpackedWebDataDirectory = UnityWebTool.Unpack(webDataFile); + if (assetFileInstance.file != null) + { + Utility.BackupOnlyOnce(selectedFile); + WriteChanges( + inspectedFile, + assetType, + assetFileInstance, + bundleFileInstance + ); + } + } + catch (Exception ex) + { + AnsiConsole.MarkupLineInterpolated( + $"[red]( ERR! )[/] Error when loading asset class types database! {ex.Message}" + ); + continue; // Prompt for action again + } + } - // Find and select "data.unity3d" or "globalgamemanagers" - inspectedFile = Utility.FindRequiredAsset(unpackedWebDataDirectory); + Cleanup( + temporaryFiles, + bundleStream, + assetsManager, + unpackedWebDataDirectory, + webDataFile, + isWebGL + ); - // Determine the asset type - if (inspectedFile.Contains("globalgamemanagers")) - assetType = AssetTypes.Asset; - else if (inspectedFile.EndsWith(".unity3d")) - assetType = AssetTypes.Bundle; + AnsiConsole.WriteLine(); + AnsiConsole.MarkupLine("Press any key to continue..."); + Console.ReadKey(); + Console.Clear(); } + } - AssetsFileInstance? assetFileInstance = null; - BundleFileInstance? bundleFileInstance = null; - FileStream? bundleStream = null; - List? assetsReplacer = null; - - string tempFile = Utility.CloneFile(inspectedFile, $"{inspectedFile}.temp"); - temporaryFiles.Add(tempFile); - temporaryFiles.Add($"{tempFile}.unpacked"); // unpacked bundle file - - switch (assetType) + static AssetTypes GetAssetType( + string selectedFile, + ref string webDataFile, + ref bool isWebGL + ) + { + string selectedFileName = Path.GetFileName(selectedFile); + if (selectedFileName.Contains("globalgamemanagers")) + return AssetTypes.Asset; + if (selectedFileName.EndsWith(".unity3d")) + return AssetTypes.Bundle; + if (selectedFileName.EndsWith(".data")) { - case AssetTypes.Asset: - assetFileInstance = LoadAssetFileInstance(tempFile, assetsManager); - break; - case AssetTypes.Bundle: - bundleFileInstance = LoadBundleFileInstance( - tempFile, - assetsManager, - bundleStream - ); - assetFileInstance = LoadAssetFileInstance( - tempFile, - assetsManager, - bundleFileInstance - ); - break; + isWebGL = true; + webDataFile = selectedFile; + return AssetTypes.Asset; // Default to Asset type } - - try + if (selectedFileName.EndsWith("data.unityweb")) { - AnsiConsole.MarkupLine("( INFO ) Loading asset class types database..."); - assetsManager.LoadClassDatabaseFromPackage( - assetFileInstance?.file.Metadata.UnityVersion - ); + isWebGL = true; + WebCompressionTypes webCompressionType = GetCompression(); + if (!DecompressWebData(webCompressionType, selectedFile, webDataFile)) + return AssetTypes.Unknown; + return AssetTypes.Asset; } - catch (Exception ex) + if (selectedFileName.EndsWith("data.br")) { - AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when loading asset class types database! {ex.Message}" - ); - goto Cleanup; + isWebGL = true; + DecompressWebData(WebCompressionTypes.Brotli, selectedFile, webDataFile); + return AssetTypes.Asset; } - - if (assetFileInstance != null) + if (selectedFileName.EndsWith("data.gz")) { - AnsiConsole.MarkupLineInterpolated( - $"( INFO ) [bold]Unity Version[/]: [green]{assetFileInstance?.file.Metadata.UnityVersion.ToString()}[/]" - ); - - switch (choiceIndex) - { - case 0: - assetsReplacer = RemoveSplashScreen(assetsManager, assetFileInstance); - break; - case 1: - assetsReplacer = RemoveWatermark(assetsManager, assetFileInstance); - break; - } - - if (assetsReplacer != null) - { - Utility.BackupOnlyOnce(selectedFile); // Backup original file - // Write changes to the asset file - WriteChanges( - inspectedFile, - assetFileInstance, - bundleFileInstance, - assetsReplacer - ); - } + isWebGL = true; + DecompressWebData(WebCompressionTypes.GZip, selectedFile, webDataFile); + return AssetTypes.Asset; } + return AssetTypes.Unknown; + } - Cleanup: + static void Cleanup( + List temporaryFiles, + FileStream? bundleStream, + AssetsManager assetsManager, + string? unpackedWebDataDirectory, + string webDataFile, + bool isWebGL + ) + { bundleStream?.Close(); assetsManager?.UnloadAll(true); Utility.CleanUp(temporaryFiles); - // After writing the changes and cleaning the temporary files, - // it's time to pack the extracted WebData. - try + if (isWebGL) { - if (isWebGL && assetsReplacer != null) + try { - AnsiConsole.MarkupLineInterpolated( - $"( INFO ) Packing [green]{unpackedWebDataDirectory}[/]..." - ); - switch (webGLCompressionType) - { - case WebGLCompressionType.Brotli: - UnityWebTool.Pack(unpackedWebDataDirectory, webDataFile); - - AnsiConsole.MarkupLineInterpolated( - $"( INFO ) Compressing [green]{webDataFile}[/] using Brotli compression. Please be patient, it might take some time..." - ); - BrotliUtils.CompressFile(webDataFile, selectedFile); - break; - case WebGLCompressionType.GZip: - UnityWebTool.Pack(unpackedWebDataDirectory, webDataFile); - - AnsiConsole.MarkupLineInterpolated( - $"( INFO ) Compressing [green]{webDataFile}[/] using GZip compression. Please be patient, it might take some time..." - ); - GZipUtils.CompressFile(webDataFile, selectedFile); - break; - case WebGLCompressionType.None: - default: - UnityWebTool.Pack(unpackedWebDataDirectory, selectedFile); - break; - } + if (Directory.Exists(unpackedWebDataDirectory)) + Directory.Delete(unpackedWebDataDirectory, true); + if (File.Exists(webDataFile)) + File.Delete(webDataFile); } - } - catch (Exception ex) - { - AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when compressing Unity Web Data! {ex.Message}" - ); - } - finally - { - if (isWebGL) + catch (Exception ex) { - try - { - if (Directory.Exists(unpackedWebDataDirectory)) - Directory.Delete(unpackedWebDataDirectory, true); - if ( - !webGLCompressionType.Equals(WebGLCompressionType.None) - && File.Exists(webDataFile) - ) - File.Delete(webDataFile); - } - catch { } + AnsiConsole.MarkupLine("[red]( ERR! )[/] Error cleaning up temporary files!"); + AnsiConsole.WriteException(ex); } } - - Console.WriteLine(); - goto ChooseAction; } static void PrintHelp() { AnsiConsole.MarkupLineInterpolated( - $"[bold red]Unity Splash Screen Remover v{VERSION}[/]" + $"[bold red]Unity Splash Screen Remover v{appVersion}[/]" ); Console.WriteLine(); AnsiConsole.MarkupLine( - "USSR is a CLI tool to easily remove Unity splash screen logo (Made with Unity) from your game and keep your logo displayed. USSR didn't directly \"hack\" Unity Editor, but the generated build." + "USSR is a tool to easily remove Unity splash screen. USSR didn't directly \"hack\" the Unity Editor, but the generated build." ); Console.WriteLine(); AnsiConsole.MarkupLine( - "Before using USSR, make sure you have set the splash screen [bold green]\"Draw Mode\"[/] in [bold green]Player Settings[/] to [bold green]\"All Sequential\"[/] and don't forget to backup your game files!" + "Before using USSR, make sure you have set the splash screen [bold green]Draw Mode[/] in [bold green]Player Settings[/] to [bold green]All Sequential[/] and backup the target file below! For more information, visit USSR GitHub repo: [link]https://github.com/kiraio-moe/USSR[/]" ); Console.WriteLine(); + AnsiConsole.MarkupLine("[bold green]HOW TO USE[/]"); AnsiConsole.MarkupLine( - "For more information, visit USSR GitHub repo: [link]https://github.com/kiraio-moe/USSR[/]" + "Select the action below, find and select one of these files in your game data:" ); - Console.WriteLine(); - AnsiConsole.MarkupLine("[bold green]How to Use[/]:"); AnsiConsole.MarkupLine( - "Select the Action, find and choose one of these files in you game data:" + "[green]globalgamemanagers[/] | [green]data.unity3d[/] | [green]*.data[/] | [green]*.data.br[/] | [green]*.data.gz[/] | [green]*.data.unityweb[/]" ); - AnsiConsole.MarkupLine( - "[green]globalgamemanagers[/] | [green]data.unity3d[/] | [green].data[/] | [green].data.br[/] | [green].data.gz[/] | [green].data.unityweb[/]" + Console.WriteLine(); + } + + static int GetChoice() + { + string[] menuList = { "Remove Unity Splash Screen", "Remove Watermark", "Exit" }; + string actionPrompt = AnsiConsole.Prompt( + new SelectionPrompt() + .Title("What would you like to do? (Press ENTER to go, UP/DOWN to select)") + .AddChoices(menuList) ); + return Array.FindIndex(menuList, item => item == actionPrompt); } - static void LoadClassPackage(AssetsManager assetsManager, string tpkFile) + static WebCompressionTypes GetCompression() + { + string[] compressionList = { "Brotli", "GZip" }; + string compressionListPrompt = AnsiConsole.Prompt( + new SelectionPrompt() + .Title("What compression did you use?") + .AddChoices(compressionList) + ); + int choiceIndex = Array.FindIndex( + compressionList, + item => item == compressionListPrompt + ); + + return choiceIndex switch + { + 0 => WebCompressionTypes.Brotli, + 1 => WebCompressionTypes.GZip, + _ => WebCompressionTypes.None, + }; + } + + static string OpenFilePicker() + { + AnsiConsole.MarkupLine("Opening File Picker..."); + + DialogResult filePicker = Dialog.FileOpen( + null, + Path.GetDirectoryName(Utility.GetLastOpenedFile()) + ); + + if (filePicker.IsCancelled) + AnsiConsole.MarkupLine("( INFO ) Cancelled."); + else if (filePicker.IsError) + { + AnsiConsole.MarkupLine( + "[red]( ERR! )[/] Unable to open File Picker! Try using a different Terminal?" + ); + } + + Console.WriteLine(); + Console.Clear(); + + return filePicker.Path; + } + + static bool LoadClassPackage(AssetsManager assetsManager, string tpkFile) { if (File.Exists(tpkFile)) { @@ -364,18 +323,21 @@ static void LoadClassPackage(AssetsManager assetsManager, string tpkFile) $"( INFO ) Loading class types package: [green]{tpkFile}[/]..." ); assetsManager.LoadClassPackage(path: tpkFile); + return true; } catch (Exception ex) { AnsiConsole.MarkupLine( - $"[red]( RAWR )[/] Error when loading class types package! {ex.Message}" + $"[red]( ERR! )[/] Error when loading class types package! {ex.Message}" ); } } else AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] TPK file not found: [red]{tpkFile}[/]..." + $"[red]( ERR! )[/] TPK file not found: [red]{tpkFile}[/]..." ); + + return false; } /// @@ -402,14 +364,14 @@ AssetsManager assetsManager catch (Exception ex) { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when loading asset file! {ex.Message}" + $"[red]( ERR! )[/] Error when loading asset file! {ex.Message}" ); } } else { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Asset file not found: [red]{assetFile}[/]" + $"[red]( ERR! )[/] Asset file not found: [red]{assetFile}[/]" ); } @@ -419,7 +381,7 @@ AssetsManager assetsManager /// /// Load AssetFileInstance from . /// - /// + /// /// /// /// @@ -447,14 +409,14 @@ AssetsManager assetsManager catch (Exception ex) { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when loading asset file! {ex.Message}" + $"[red]( ERR! )[/] Error when loading asset file! {ex.Message}" ); } } else { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Asset file not found: [red]{assetFile}[/]" + $"[red]( ERR! )[/] Asset file not found: [red]{assetFile}[/]" ); } @@ -477,7 +439,7 @@ AssetsManager assetsManager $"( INFO ) Loading bundle file: [green]{bundleFile}[/]..." ); bundleFileInstance = assetsManager.LoadBundleFile(bundleFile, false); - // It will throw an error if we use 'using' + //! Don't auto dispose the stream unpackedBundleFileStream = File.Open($"{bundleFile}.unpacked", FileMode.Create); bundleFileInstance.file = BundleHelper.UnpackBundleToStream( bundleFileInstance.file, @@ -487,21 +449,21 @@ AssetsManager assetsManager catch (Exception ex) { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when loading bundle file! {ex.Message}" + $"[red]( ERR! )[/] Error when loading bundle file! {ex.Message}" ); } } else { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Bundle file not found: [red]{bundleFile}[/]" + $"[red]( ERR! )[/] Bundle file not found: [red]{bundleFile}[/]" ); } return bundleFileInstance; } - static List? RemoveSplashScreen( + static AssetsFile? RemoveSplashScreen( AssetsManager assetsManager, AssetsFileInstance? assetFileInstance ) @@ -523,23 +485,23 @@ AssetsManager assetsManager List? playerSettingsInfo = assetFile?.GetAssetsOfType( AssetClassID.PlayerSettings ); - AssetTypeValueField? playerSettingsBase = assetsManager.GetBaseField( - assetFileInstance, - playerSettingsInfo?[0] - ); - - if (playerSettingsBase == null) + AssetTypeValueField? playerSettingsBase = null; + try { - AnsiConsole.MarkupLine( - "[red]( RAWR )[/] Can\'t get Player Settings fields! It\'s possible that this current version of Unity are currently not supported yet." + playerSettingsBase = assetsManager.GetBaseField( + assetFileInstance, + playerSettingsInfo?[0] ); - AnsiConsole.MarkupLine( - "Try updating USSR [bold green]classdata.tpk[/] manually from there: [link green]https://nightly.link/AssetRipper/Tpk/workflows/type_tree_tpk/master/uncompressed_file.zip[/] and try again." + } + catch (Exception ex) + { + AnsiConsole.MarkupLineInterpolated( + $"[red]( ERR! )[/] Can\'t get Player Settings fields! {ex.Message} It\'s possible that the current Unity version isn\'t supported yet." ); AnsiConsole.MarkupLine( - "If the issue still persist, try switching to another Unity version." + "( INFO ) Try updating the [bold green]classdata.tpk[/] manually from there: [link green]https://nightly.link/AssetRipper/Tpk/workflows/type_tree_tpk/master/uncompressed_file.zip[/] and try again. If the issue still persist, try use another Unity version." ); - return null; + return assetFile; } // Required fields to remove splash screen @@ -550,9 +512,9 @@ AssetsManager assetsManager if (hasProVersion && !showUnityLogo) { AnsiConsole.MarkupLine( - "[yellow]( WARN ) Unity splash screen already removed![/]" + "[yellow]( WARN ) [bold]Unity splash screen already removed![/][/]" ); - return null; + return assetFile; } AssetTypeValueField splashScreenLogos = playerSettingsBase[ @@ -565,21 +527,20 @@ AssetsManager assetsManager $"( INFO ) There's [green]{totalSplashScreen}[/] splash screen detected." ); - switch (totalSplashScreen) + if (totalSplashScreen <= 0) { - case 0: - AnsiConsole.MarkupLine( - "[yellow]( WARN ) Nothing to do. Finally, taking a rest :)[/]" - ); - return null; - case 1: - AnsiConsole.MarkupLine("( INFO ) Auto remove the splash screen..."); - goto RemoveSplashScreen; // auto remove the splash screen + AnsiConsole.MarkupLine("[yellow]( WARN ) Nothing to do.[/]"); + return assetFile; } - AnsiConsole.MarkupLine( - "What order are Unity splash screen logo in your Player Settings? (Start from 0 [upmost])" - ); + for (int i = 0; i < totalSplashScreen; i++) + { + AnsiConsole.MarkupLineInterpolated( + $"[green]{i}[/] => [green]{splashScreenLogos.Children[i].FieldName}[/]" + ); + } + + AnsiConsole.MarkupLine("What order are Unity logo in your Player Settings?"); InputLogoIndex: int.TryParse( @@ -592,12 +553,12 @@ out splashScreenIndex if (splashScreenIndex < 0 && splashScreenIndex >= totalSplashScreen) { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] There's no splash screen at index [red]{splashScreenIndex}[/]! Try again." + $"[red]( ERR! )[/] There's no splash screen at index [red]{splashScreenIndex}[/]! Try again." ); goto InputLogoIndex; } - RemoveSplashScreen: + // RemoveSplashScreen: AnsiConsole.MarkupLineInterpolated( $"( INFO ) Set [green]hasProVersion[/] = [green]{!hasProVersion}[/] | [green]m_ShowUnitySplashLogo[/] = [green]{!showUnityLogo}[/]" ); @@ -611,40 +572,29 @@ out splashScreenIndex ); splashScreenLogos?.Children.RemoveAt(splashScreenIndex); + playerSettingsInfo?[0].SetNewData(playerSettingsBase); + buildSettingsInfo?[0].SetNewData(buildSettingsBase); - return new() - { - new AssetsReplacerFromMemory( - assetFile, - buildSettingsInfo?[0], - buildSettingsBase - ), - new AssetsReplacerFromMemory( - assetFile, - playerSettingsInfo?[0], - playerSettingsBase - ) - }; + return assetFile; } catch (Exception ex) { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when removing the splash screen! {ex.Message}" + $"[red]( ERR! )[/] Error when removing the splash screen! {ex.Message}" ); return null; } } - static List? RemoveWatermark( + static AssetsFile? RemoveWatermark( AssetsManager assetsManager, AssetsFileInstance? assetFileInstance ) { + AssetsFile? assetFile = assetFileInstance?.file; try { AnsiConsole.MarkupLine("( INFO ) Removing watermark..."); - - AssetsFile? assetFile = assetFileInstance?.file; List? buildSettingsInfo = assetFile?.GetAssetsOfType( AssetClassID.BuildSettings ); @@ -659,39 +609,34 @@ out splashScreenIndex if (noWatermark && !isTrial) { AnsiConsole.MarkupLine("[yellow]( WARN ) Watermark have been removed![/]"); - return null; + return assetFile; } AnsiConsole.MarkupLineInterpolated( - $"( INFO ) Set [green]isNoWatermarkBuild = {!noWatermark}[/] | [green]isTrial = {!isTrial}[/]" + $"( INFO ) Set [green]isNoWatermarkBuild[/] = [green]True[/] | [green]isTrial[/] = [green]False[/]" ); + buildSettingsBase["isNoWatermarkBuild"].AsBool = true; buildSettingsBase["isTrial"].AsBool = false; + buildSettingsInfo?[0].SetNewData(buildSettingsBase); - AnsiConsole.MarkupLine("( INFO ) [green]Watermark successfully removed.[/]"); - return new() - { - new AssetsReplacerFromMemory( - assetFile, - buildSettingsInfo?[0], - buildSettingsBase - ) - }; + AnsiConsole.MarkupLine("[green]( INFO ) Watermark successfully removed.[/]"); + return assetFile; } catch (Exception ex) { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when removing the watermark! {ex.Message}" + $"[red]( ERR! )[/] Error when removing the watermark! {ex.Message}" ); - return null; + return assetFile; } } static void WriteChanges( string modifiedFile, + AssetTypes assetType, AssetsFileInstance? assetFileInstance, - BundleFileInstance? bundleFileInstance, - List assetsReplacer + BundleFileInstance? bundleFileInstance ) { string uncompressedBundleFile = $"{modifiedFile}.uncompressed"; @@ -707,25 +652,17 @@ List assetsReplacer case AssetTypes.Asset: { using AssetsFileWriter writer = new(modifiedFile); - assetFileInstance?.file.Write(writer, 0, assetsReplacer); + assetFileInstance?.file.Write(writer); break; } case AssetTypes.Bundle: { - List bundleReplacer = - new() - { - new BundleReplacerFromAssets( - assetFileInstance?.name, - null, - assetFileInstance?.file, - assetsReplacer - ) - }; + List bundleReplacer = + new() { new ContentReplacerFromAssets(assetFileInstance?.file) }; // Write modified assets to uncompressed asset bundle using (AssetsFileWriter writer = new(uncompressedBundleFile)) - bundleFileInstance?.file.Write(writer, bundleReplacer); + bundleFileInstance?.file.Write(writer); AnsiConsole.MarkupLineInterpolated( $"( INFO ) Compressing [green]{modifiedFile}[/]..." @@ -741,7 +678,6 @@ List assetsReplacer using AssetsFileWriter uncompressedWriter = new(modifiedFile); uncompressedBundle.Pack( - uncompressedBundle.Reader, uncompressedWriter, AssetBundleCompressionType.LZ4 ); @@ -753,7 +689,7 @@ List assetsReplacer catch (Exception ex) { AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR )[/] Error when writing changes! {ex.Message}" + $"[red]( ERR! )[/] Error when writing changes! {ex.Message}" ); } finally @@ -763,55 +699,42 @@ List assetsReplacer } } - static int DecompressCompressedWebData( - WebGLCompressionType compressionType, + static bool DecompressWebData( + WebCompressionTypes compressionType, string inputPath, string outputPath ) { - switch (compressionType) + AnsiConsole.MarkupLineInterpolated( + $"( INFO ) Decompressing data as {compressionType.ToString()} compression: [green]{inputPath}[/]..." + ); + + try { - case WebGLCompressionType.Brotli: - try - { - AnsiConsole.MarkupLineInterpolated( - $"( INFO ) Decompressing Brotli [green]{inputPath}[/]..." - ); + switch (compressionType) + { + case WebCompressionTypes.Brotli: BrotliUtils.DecompressFile(inputPath, outputPath); - return 0; - } - catch (Exception ex) - { - AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR ) Failed to decompress {inputPath}![/] {ex.Message} Try choose different compression type." - ); - Console.WriteLine(); - if (File.Exists(outputPath)) - File.Delete(outputPath); - return 1; - } - case WebGLCompressionType.GZip: - try - { - AnsiConsole.MarkupLineInterpolated( - $"( INFO ) Decompressing GZip [green]{inputPath}[/]..." - ); + return true; + case WebCompressionTypes.GZip: GZipUtils.DecompressFile(inputPath, outputPath); - return 0; - } - catch (Exception ex) - { - AnsiConsole.MarkupLineInterpolated( - $"[red]( RAWR ) Failed to decompress {inputPath}![/] {ex.Message} Try choose different compression type." - ); - Console.WriteLine(); - if (File.Exists(outputPath)) - File.Delete(outputPath); - return 1; - } - case WebGLCompressionType.None: - default: - return 1; + return true; + case WebCompressionTypes.None: + default: + return false; + } + } + catch (Exception ex) + { + if (File.Exists(outputPath)) + File.Delete(outputPath); + + AnsiConsole.MarkupLineInterpolated( + $"[red]( ERR! ) Failed to decompress: {inputPath}![/] {ex.Message} Try different compression type." + ); + Console.WriteLine(); + + return false; } } } diff --git a/USSR.csproj b/USSR.csproj index 66c06bc..b0f86d1 100644 --- a/USSR.csproj +++ b/USSR.csproj @@ -3,17 +3,18 @@ Exe win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 - net6.0;net7.0;net8.0 + net6.0;net8.0 enable enable - + - + + diff --git a/Utils/Utility.cs b/Utils/Utility.cs index cc478cd..94186c4 100644 --- a/Utils/Utility.cs +++ b/Utils/Utility.cs @@ -5,6 +5,7 @@ namespace USSR.Utilities internal class Utility { const string LAST_OPEN_FILE = "last_open.txt"; + const string VERSION_FILE = "version.txt"; /// /// Check the file signature if it's a valid file. @@ -169,5 +170,14 @@ internal static string GetLastOpenedFile() return lastOpenedDirectory; } + + internal static string? GetVersion() + { + if (!File.Exists(VERSION_FILE)) + return "UNKNOWN"; + + using StreamReader reader = new(VERSION_FILE); + return reader.ReadLine(); + } } } diff --git a/build.sh b/build.sh index 6572b8f..ca51183 100644 --- a/build.sh +++ b/build.sh @@ -1,8 +1,8 @@ #!/bin/bash -VERSION="1.1.7" +VERSION=$(