From 92604722c18528bb23022b56e29495c75404548a Mon Sep 17 00:00:00 2001 From: Andrew Burke Date: Tue, 14 May 2024 13:34:21 -0400 Subject: [PATCH] v1.1.9 --- CHANGELOG.md | 7 +++- Editor/AssetCatalogue.cs | 31 +-------------- Editor/AssetScrubber.cs | 32 ---------------- Editor/PatcherSteps.cs | 2 +- Editor/PatcherUtility.cs | 34 ++++++++++++++--- Editor/PatcherWindow.cs | 71 ++++++++++++++++++++++++++++++++++- Editor/Steps/StepsProgress.cs | 4 -- package.json | 2 +- 8 files changed, 107 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ca6845..3885888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -# 1.1.8 +# 1.1.9 + +- Fixed Project to Project migration not doing the full process +- Removed many warnings related to nullables + +# 1.1.8 - Fixed game wrapper version not being found diff --git a/Editor/AssetCatalogue.cs b/Editor/AssetCatalogue.cs index fa1c5f6..32c0518 100644 --- a/Editor/AssetCatalogue.cs +++ b/Editor/AssetCatalogue.cs @@ -324,8 +324,6 @@ public IEnumerable CompareProjectToProject(AssetCatalogue other) { EditorUtility.ClearProgressBar(); - return found; - // try to match shaders UnityEditor.EditorUtility.DisplayProgressBar("Comparing Catalogues", "Matching shaders - This will take a while", 0); stopWatch.Restart(); @@ -456,13 +454,8 @@ public string ToString(bool withTags) { } public bool TryGetEntry(string guid, out Entry entry) { -#if UNITY_2020_3_OR_NEWER - Entry? found = Entries.FirstOrDefault(x => x.Guid == guid); - entry = (found ?? default)!; -#else var found = Entries.FirstOrDefault(x => x.Guid == guid); entry = found ?? default; -#endif return found != null; } @@ -505,18 +498,14 @@ public bool ContainsFullTypeName(ScriptEntry otherEntry) { public class Entry { private const string FileIdColor = "#c0c0c07f"; - public string? AssetType; + public string AssetType; public string RelativePathToRoot; public string Guid; public long? FileId; public string[] AssociatedGuids; public string[] FileIds; -#if UNITY_2020_3_OR_NEWER - public Entry(string? assetType, string relativePathToRoot, string guid, long? fileId, string[]? associatedGuids, string[]? fileIds) { -#else public Entry(string assetType, string relativePathToRoot, string guid, long? fileId, string[] associatedGuids, string[] fileIds) { -#endif AssetType = assetType; if (relativePathToRoot.StartsWith("Assets")) { relativePathToRoot = relativePathToRoot.Substring("Assets".Length + 1); @@ -546,21 +535,11 @@ public virtual string ToString(bool withTags) { } public class ScriptEntry : Entry { -#if UNITY_2020_3_OR_NEWER - public string? FullTypeName; - public string? AssemblyName; -#else public string FullTypeName; public string AssemblyName; -#endif public ScriptEntry[] NestedTypes; - // public bool IsGeneric; -#if UNITY_2020_3_OR_NEWER - public ScriptEntry(string relativePathToRoot, string guid, long? fileId, string? fullTypeName, string? assemblyName, ScriptEntry[] nested, string[]? associatedGuids, string[]? fileIds) : base(typeof(MonoScript).FullName, relativePathToRoot, guid, fileId, associatedGuids, fileIds) { -#else public ScriptEntry(string relativePathToRoot, string guid, long? fileId, string fullTypeName, string assemblyName, ScriptEntry[] nested, string[] associatedGuids, string[] fileIds) : base(typeof(MonoScript).FullName, relativePathToRoot, guid, fileId, associatedGuids, fileIds) { -#endif FullTypeName = fullTypeName; AssemblyName = assemblyName; // IsGeneric = isGeneric; @@ -578,17 +557,9 @@ public override string ToString(bool withTags) { } public class ShaderEntry : Entry { -#if UNITY_2020_3_OR_NEWER - public string? FullShaderName; -#else public string FullShaderName; -#endif -#if UNITY_2020_3_OR_NEWER - public ShaderEntry(string relativePathToRoot, string guid, long? fileId, string? fullShaderName, string[]? associatedGuids, string[]? fileIds) : base(typeof(Shader).FullName, relativePathToRoot, guid, fileId, associatedGuids, fileIds) { -#else public ShaderEntry(string relativePathToRoot, string guid, long? fileId, string fullShaderName, string[] associatedGuids, string[] fileIds) : base(typeof(Shader).FullName, relativePathToRoot, guid, fileId, associatedGuids, fileIds) { -#endif FullShaderName = fullShaderName; } diff --git a/Editor/AssetScrubber.cs b/Editor/AssetScrubber.cs index d4f722a..ae9e7e7 100644 --- a/Editor/AssetScrubber.cs +++ b/Editor/AssetScrubber.cs @@ -534,11 +534,7 @@ public static AssetCatalogue ScrubProject(string searchQuery, string[] searchInF var properPath = path.ToOSPath(); -#if UNITY_2020_3_OR_NEWER - UnityEngine.Object? obj = null; -#else UnityEngine.Object obj = null; -#endif try { var fullPath = Path.GetFullPath(path); var assetPathNoAssets = PatcherUtility.GetPathWithoutRoot(path); @@ -725,11 +721,7 @@ private static Type[] GetAllTypes() { return allTypes; } -#if UNITY_2020_3_OR_NEWER - public static string? GetShaderName(string assetPath, string? contents) { -#else public static string GetShaderName(string assetPath, string contents) { -#endif if (!File.Exists(assetPath)) { return null; } @@ -772,11 +764,7 @@ public static string GetShaderName(string assetPath, string contents) { } } -#if UNITY_2020_3_OR_NEWER - private static string? GetNamespace(string text) { -#else private static string GetNamespace(string text) { -#endif var namespaceRegex = new Regex(@"namespace\s+(\w.*)"); var match = namespaceRegex.Match(text); @@ -1063,11 +1051,7 @@ private static bool IsGenericScript(string assetPath, string typeName) { return assetContents.Contains($" {typeName}<"); } -#if UNITY_2020_3_OR_NEWER - public static string? GetGuidFromDisk(string assetPath) { -#else public static string GetGuidFromDisk(string assetPath) { -#endif // scrub meta file directly (?) // var fullAssetPath = Path.GetFullPath(assetPath); var fullMetaPath = $"{assetPath}.meta"; @@ -1154,11 +1138,7 @@ public static IEnumerable GetFileIdsFromProjectAsset(string assetPath) { yield break; } -#if UNITY_2020_3_OR_NEWER - private static IEnumerable GetAssociatedGuids(string assetPath, string fullAssetPath, string? contents) { -#else private static IEnumerable GetAssociatedGuids(string assetPath, string fullAssetPath, string contents) { -#endif // var fullMetaPath = $"{fullAssetPath}.meta"; if (!File.Exists(fullAssetPath)) { yield break; @@ -1411,19 +1391,11 @@ public static void ReplaceAssetGuids(UPPatcherSettings settings, string rootPath // return projectGameAssetsPath; // } -#if UNITY_2020_3_OR_NEWER - public static string? GetProjectPathFromExportPath(AssetCatalogue.Entry entry, UPPatcherSettings settings, AssetRipperSettings arSettings, bool ignoreExclude) { -#else public static string GetProjectPathFromExportPath(AssetCatalogue.Entry entry, UPPatcherSettings settings, AssetRipperSettings arSettings, bool ignoreExclude) { -#endif return GetProjectPathFromExportPath(settings.ProjectGameAssetsPath, entry, settings, arSettings, ignoreExclude); } -#if UNITY_2020_3_OR_NEWER - public static string? GetProjectPathFromExportPath(string projectGameAssetsPath, AssetCatalogue.Entry entry, UPPatcherSettings settings, AssetRipperSettings arSettings, bool ignoreExclude) { -#else public static string GetProjectPathFromExportPath(string projectGameAssetsPath, AssetCatalogue.Entry entry, UPPatcherSettings settings, AssetRipperSettings arSettings, bool ignoreExclude) { -#endif var splitPath = entry.RelativePathToRoot.Split(Path.DirectorySeparatorChar); var sourceName = splitPath[0]; if (!arSettings.TryGetFolderMappingFromSource(sourceName, out var folder, out var exclude, Path.Combine("Unknown", sourceName))) { @@ -1442,11 +1414,7 @@ public static string GetProjectPathFromExportPath(string projectGameAssetsPath, return Path.Combine(projectGameAssetsPath, folder, restOfPath); } -#if UNITY_2020_3_OR_NEWER - public static string? GetExportPathFromProjectPath(string projectAssetPath, UPPatcherSettings settings, AssetRipperSettings arSettings) { -#else public static string GetExportPathFromProjectPath(string projectAssetPath, UPPatcherSettings settings, AssetRipperSettings arSettings) { -#endif var pathWithoutRoot = projectAssetPath.Substring(settings.ProjectGameAssetsPath.Length + 1); var withoutFile = Path.GetDirectoryName(pathWithoutRoot); if (!arSettings.TryGetFolderMappingFromOutput(withoutFile, out var folder, out var exclude)) { diff --git a/Editor/PatcherSteps.cs b/Editor/PatcherSteps.cs index 608b919..d9c9246 100644 --- a/Editor/PatcherSteps.cs +++ b/Editor/PatcherSteps.cs @@ -58,7 +58,7 @@ private static void RunFunction(MethodInfo func) { } var executor = new StepsExecutor(pipeline.Steps.ToArray()); - executor.Execute(); + executor.Execute().Forget(); } public static StepPipeline GetPipeline() { diff --git a/Editor/PatcherUtility.cs b/Editor/PatcherUtility.cs index bbd33f0..0ebf1dd 100644 --- a/Editor/PatcherUtility.cs +++ b/Editor/PatcherUtility.cs @@ -10,6 +10,8 @@ using System.Threading; using System.Threading.Tasks; using Lachee.Utilities.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Nomnom.UnityProjectPatcher.AssetRipper; using Nomnom.UnityProjectPatcher.Editor.Steps; using UnityEditor; @@ -17,6 +19,7 @@ using UnityEditor.SceneManagement; using UnityEditorInternal; using UnityEngine; +using UnityEngine.Networking; using UnityEngine.Profiling; using Debug = UnityEngine.Debug; using Object = UnityEngine.Object; @@ -145,6 +148,29 @@ public static (string version, string gameWrapperVersion) GetVersions(PackageCol } } + public static bool TryFetchGitVersion(string gitUrl, out string version) { + try { + // https://raw.githubusercontent.com/nomnomab/unity-lc-project-patcher/master/package.json + var packageUrl = $"{gitUrl.Replace("github.com", "raw.githubusercontent.com")}/master/package.json"; + var request = UnityWebRequest.Get(packageUrl); + request.SendWebRequest(); + while (!request.isDone) { } + if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError) { + version = null; + return false; + } + + var json = request.downloadHandler.text; + var packageContents = JObject.Parse(json); + version = packageContents["version"].Value(); + return true; + } catch (Exception e) { + Debug.LogWarning(e); + version = null; + return false; + } + } + public static bool IsProbablyPatched() { var settings = GetSettings(); if (!AssetDatabase.IsValidFolder(settings.ProjectGameAssetsPath)) { @@ -169,7 +195,7 @@ public static bool TryToCreatePath(string path) { return false; } - return false; + // return false; } public static Object GetGraphicsSettings() { @@ -261,12 +287,8 @@ public static IEnumerable GetParentTypes(this Type type) { currentBaseType = currentBaseType.BaseType; } } - -#if UNITY_2020_3_OR_NEWER - public static SerializedProperty? GetCustomRenderPipelineProperty() { -#else + public static SerializedProperty GetCustomRenderPipelineProperty() { -#endif var qualitySettings = PatcherUtility.GetQualitySettings(); var serializedObject = new SerializedObject(qualitySettings); diff --git a/Editor/PatcherWindow.cs b/Editor/PatcherWindow.cs index c23dc0f..28208bf 100644 --- a/Editor/PatcherWindow.cs +++ b/Editor/PatcherWindow.cs @@ -24,6 +24,76 @@ public class PatcherWindow: EditorWindow { // private bool _hasGameWrapperPackage; private UPPatcherAttribute _foundPackageAttribute; private PackageCollection _packageCollection; + + [InitializeOnLoadMethod] + private static void OnLoad() { + // check tool version + var packages = PatcherUtility.GetPackages(); + var toolGit = "https://github.com/nomnomab/unity-project-patcher"; + var bepinexGit = "https://github.com/nomnomab/unity-project-patcher-bepinex"; + var gameWrapper = PatcherUtility.GetGameWrapperAttribute(); + + var currentToolVersion = packages.FirstOrDefault(x => x.name == "com.nomnom.unity-project-patcher")?.version; + var currentBepInExVersion = packages.FirstOrDefault(x => x.name == "com.nomnom.unity-project-patcher-bepinex")?.version; + + try { + if (!string.IsNullOrEmpty(currentToolVersion) && PatcherUtility.TryFetchGitVersion(toolGit, out var toolVersion)) { + if (currentToolVersion != toolVersion) { + Debug.LogWarning($"[com.nomnom.unity-project-patcher] is outdated. Please update to {toolVersion} from \"{toolGit}\". Current version: {currentToolVersion}."); + } else { + Debug.Log($"[com.nomnom.unity-project-patcher] is up to date. Current version: {currentToolVersion}."); + } + } else { + Debug.LogWarning($"Failed to fetch [com.nomnom.unity-project-patcher] version from \"{toolGit}\"."); + } + } catch (Exception e) { + Debug.LogWarning($"Failed to fetch [com.nomnom.unity-project-patcher] version from \"{toolGit}\". Exception: {e}"); + } + + try { + if (!string.IsNullOrEmpty(currentBepInExVersion) && PatcherUtility.TryFetchGitVersion(bepinexGit, out var bepinexVersion)) { + if (currentBepInExVersion != bepinexVersion) { + Debug.LogWarning($"[com.nomnom.unity-project-patcher-bepinex] is outdated. Please update to {bepinexVersion} from \"{bepinexGit}\". Current version: {currentBepInExVersion}."); + } else { + Debug.Log($"[com.nomnom.unity-project-patcher-bepinex] is up to date. Current version: {currentBepInExVersion}."); + } + } else { + Debug.LogWarning($"Failed to fetch [com.nomnom.unity-project-patcher-bepinex] version from \"{bepinexGit}\"."); + } + } catch (Exception e) { + Debug.LogWarning($"Failed to fetch [com.nomnom.unity-project-patcher-bepinex] version from \"{bepinexGit}\". Exception: {e}"); + } + + if (gameWrapper != null) { + try { + var packageName = gameWrapper.PackageName; + var gamePackage = packages.FirstOrDefault(x => x.name == packageName); + var gameRepo = gamePackage.packageId; + if (string.IsNullOrEmpty(gameRepo) || !gameRepo.Contains('@')) { + Debug.LogWarning($"[com.nomnom.unity-project-patcher-bepinex] failed to get gamepackage or repository."); + } else if (gamePackage != null) { + var gameGit = gameRepo.Split('@')[1]; + if (gameGit.EndsWith(".git")) { + gameGit = gameGit.Substring(0, gameGit.Length - 4); + } + var currentGameVersion = gamePackage.version; + if (PatcherUtility.TryFetchGitVersion(gameGit, out var gameVersion)) { + if (currentGameVersion != gameVersion) { + Debug.LogWarning($"[{gamePackage.name}] is outdated. Please update to {gameVersion} from \"{gameGit}\". Current version: {currentGameVersion}."); + } else { + Debug.Log($"[{gamePackage.name}] is up to date. Current version: {currentGameVersion}."); + } + } else { + Debug.LogWarning($"Failed to fetch [{gamePackage.name}] version from \"{gameGit}\"."); + } + } else { + Debug.LogWarning($"[{gamePackage.name}] failed to get gamepackage or repository."); + } + } catch (Exception e) { + Debug.LogWarning($"Failed to fetch [{gameWrapper.PackageName}] version. Exception: {e}"); + } + } + } [MenuItem("Tools/Unity Project Patcher/Open Window")] private static void Open() { @@ -75,7 +145,6 @@ private void CheckPackages() { // check packages _hasBepInExPackage = _packageCollection.Any(x => x.name == "com.nomnom.unity-project-patcher-bepinex"); _hasBepInExFlag = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone).Contains("ENABLE_BEPINEX"); - _packageCollection = _packageCollection; _foundPackageAttribute = PatcherUtility.GetGameWrapperAttribute(); // _hasGameWrapperPackage = false; // if (!string.IsNullOrEmpty(_foundPackageAttribute?.PackageName)) { diff --git a/Editor/Steps/StepsProgress.cs b/Editor/Steps/StepsProgress.cs index bc2c90c..d4a9693 100644 --- a/Editor/Steps/StepsProgress.cs +++ b/Editor/Steps/StepsProgress.cs @@ -20,11 +20,7 @@ public string ToJson() { }); } -#if UNITY_2020_3_OR_NEWER - public static StepsProgress? FromPath(string path) { -#else public static StepsProgress FromPath(string path) { -#endif if (!File.Exists(path)) { return null; } diff --git a/package.json b/package.json index a080e2e..4633248 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.nomnom.unity-project-patcher", - "version": "1.1.8", + "version": "1.1.9", "displayName": "Unity Project Patcher", "description": "A tool that generates a Unity project from a game build that can be playable in-editor", "unity": "2022.3",