diff --git a/Patcher/Hub/UnityHubPatcher.cs b/Patcher/Hub/UnityHubPatcher.cs index 0d48eed..2594c5f 100644 --- a/Patcher/Hub/UnityHubPatcher.cs +++ b/Patcher/Hub/UnityHubPatcher.cs @@ -10,17 +10,7 @@ internal class UnityHubPatcher : Patcher { public UnityHubPatcher(string filePath) : base(filePath) { - PatchStatus = PatchStatus.NotSupport; - - var fileVersion = FileVersion; - if (fileVersion.StartsWith("2.")) - { - PatchStatus = PatchStatus.Support; - } - else if (fileVersion.StartsWith("3.")) - { - PatchStatus = PatchStatus.Support; - } + PatchStatus = MajorVersion >= 2 ? PatchStatus.Support : PatchStatus.NotSupport; var unityHubPath = RootPath; unityHubPath = Path.Combine(unityHubPath, "resources"); @@ -61,20 +51,18 @@ public UnityHubPatcher(string filePath) : base(filePath) File.Move(Path.Combine(exportFolder, "filespackage.json"), Path.Combine(exportFolder, "package.json")); } - var fileVersion = FileVersion; var patchResult = false; - - if (fileVersion.StartsWith("2.")) + if (Version >= new Version("3.4.2")) { - patchResult = UnityHubV2.Patch(exportFolder); + patchResult = await UnityHubV3_4_2.Patch(exportFolder); } - else if (fileVersion.StartsWith("3.")) + else if (MajorVersion == 3) { patchResult = await UnityHubV3.Patch(exportFolder); } - else + else if (MajorVersion == 2) { - patchResult = await UnityHubV3.Patch(exportFolder); + patchResult = UnityHubV2.Patch(exportFolder); } var licensingFilePath = Path.Combine(RootPath, "Frameworks/LicensingClient/Unity.Licensing.Client" + PlatformUtils.GetExtension()); diff --git a/Patcher/Hub/UnityHubV3_4_2.cs b/Patcher/Hub/UnityHubV3_4_2.cs new file mode 100644 index 0000000..2eda606 --- /dev/null +++ b/Patcher/Hub/UnityHubV3_4_2.cs @@ -0,0 +1,97 @@ +using System; +using System.IO; +using System.Threading.Tasks; +#if !DOCKER_ENV +using MessageBoxAvalonia = MessageBox.Avalonia; +#endif + +namespace UniHacker +{ + internal class UnityHubV3_4_2 + { + const string getValidEntitlementGroups = @" + return __awaiter(this, void 0, void 0, function* () { + return [{ + startDate: new Date('1993-01-01T08:00:00.000Z'), + expirationDate: new Date('9999-01-01T08:00:00.000Z'), + productName: __importDefault(require(""../../i18nHelper"")).default.i18n.translate('license-management:TYPE_EDUCATION'), + licenseType: 'ULF', + }]; + }); +"; + + const string isLicenseValid = @" + return __awaiter(this, void 0, void 0, function* () { + return true; + }); +"; + + const string licensingSdk_init = @" + return __awaiter(this, void 0, void 0, function* () { + return true; + }); +"; + const string licensingSdk_getInstance = @" + return null; + "; + + public static async Task Patch(string exportFolder) + { +#if DOCKER_ENV + Program.TryGetEnvironmentVariable(Program.NEED_LOGIN, out var needLogin); + if (string.Compare(needLogin, bool.TrueString, true) == 0) +#else + var result = await MessageBox.Show(Language.GetString("Hub_Patch_Option_Login"), MessageBoxAvalonia.Enums.ButtonEnum.YesNo); + if (result == MessageBoxAvalonia.Enums.ButtonResult.No) +#endif + { + var defaultLocalConfigPath = Path.Combine(exportFolder, "build/common/DefaultLocalConfig.js"); + var defaultLocalConfigContent = File.ReadAllText(defaultLocalConfigPath); + defaultLocalConfigContent = defaultLocalConfigContent.Replace("DisableSignIn]: false,", "DisableSignIn]: true,"); + File.WriteAllText(defaultLocalConfigPath, defaultLocalConfigContent); + } + +#if DOCKER_ENV + Program.TryGetEnvironmentVariable(Program.DISABLE_UPDATE, out var disableUpdate); + if (string.Compare(disableUpdate, bool.TrueString, true) == 0) +#else + result = await MessageBox.Show(Language.GetString("Hub_Patch_Option_DisableUpdate"), MessageBoxAvalonia.Enums.ButtonEnum.YesNo); + if (result == MessageBoxAvalonia.Enums.ButtonResult.Yes) +#endif + { + var defaultLocalConfigPath = Path.Combine(exportFolder, "build/common/DefaultLocalConfig.js"); + var defaultLocalConfigContent = File.ReadAllText(defaultLocalConfigPath); + defaultLocalConfigContent = defaultLocalConfigContent.Replace("DisableAutoUpdate]: false,", "DisableAutoUpdate]: true,"); + File.WriteAllText(defaultLocalConfigPath, defaultLocalConfigContent); + } + + var licenseServicePath = Path.Combine(exportFolder, "build/main/services/licenseService/licenseService.js"); + var licenseServiceContent = File.ReadAllText(licenseServicePath); + UnityHubPatcher.ReplaceMethodBody(ref licenseServiceContent, @"isLicenseValid", isLicenseValid); + File.WriteAllText(licenseServicePath, licenseServiceContent); + + var licenseServiceCorePath = Path.Combine(exportFolder, "build/main/services/licenseService/licenseServiceCore.js"); + var licenseServiceCoreContent = File.ReadAllText(licenseServiceCorePath); + UnityHubPatcher.ReplaceMethodBody(ref licenseServiceCoreContent, @"static getValidEntitlementGroups", getValidEntitlementGroups); + File.WriteAllText(licenseServiceCorePath, licenseServiceCoreContent); + + var licensingSdkPath = Path.Combine(exportFolder, "build/main/services/licenseService/licensingSdk.js"); + var licensingSdkContent = File.ReadAllText(licensingSdkPath); + UnityHubPatcher.ReplaceMethodBody(ref licensingSdkContent, @"init", licensingSdk_init); + UnityHubPatcher.ReplaceMethodBody(ref licensingSdkContent, @"getInstance", licensingSdk_getInstance); + File.WriteAllText(licensingSdkPath, licensingSdkContent); + + var editorappPath = Path.Combine(exportFolder, "build/main/services/editorApp/editorapp.js"); + var editorappContent = File.ReadAllText(editorappPath); + editorappContent = editorappContent.Replace("licensingSdk.getInstance().", "licensingSdk.getInstance()?."); + File.WriteAllText(editorappPath, editorappContent); + + var editorManagerPath = Path.Combine(exportFolder, "build/main/services/editorManager/editorManager.js"); + var editorManagerContent = File.ReadAllText(editorManagerPath); + editorManagerContent = editorManagerContent.Replace("return this.validateEditorFile(location, skipSignatureCheck)", "return this.validateEditorFile(location, true)"); + File.WriteAllText(editorManagerPath, editorManagerContent); + + return true; + } + } +} diff --git a/Patcher/Misc/Patcher.cs b/Patcher/Misc/Patcher.cs index fb87637..e3df81d 100644 --- a/Patcher/Misc/Patcher.cs +++ b/Patcher/Misc/Patcher.cs @@ -21,6 +21,10 @@ internal abstract class Patcher public int MinorVersion { protected set; get; } + public int BuildVersion { protected set; get; } + + public Version Version { protected set; get; } + public Patcher(string filePath) { @@ -30,7 +34,8 @@ public Patcher(string filePath) FilePath = realFilePath; RootPath = rootPath; ArchitectureType = MachineArchitecture.GetArchitectureType(realFilePath); - (FileVersion, MajorVersion, MinorVersion) = PlatformUtils.GetFileVersionInfo(filePath, ArchitectureType); + (FileVersion, MajorVersion, MinorVersion, BuildVersion) = PlatformUtils.GetFileVersionInfo(filePath, ArchitectureType); + Version = new Version(MajorVersion, MinorVersion, BuildVersion); PatchStatus = PatchStatus.Unknown; if (this is not DefaultPatcher) { diff --git a/Patcher/Misc/PlatformUtils.cs b/Patcher/Misc/PlatformUtils.cs index b73c5b4..eb3f517 100644 --- a/Patcher/Misc/PlatformUtils.cs +++ b/Patcher/Misc/PlatformUtils.cs @@ -121,13 +121,14 @@ public static (string rootPath, string filePath) GetRealFilePath(string filePath return (rootPath, realFilePath); } - public static (string fileVersion, int majorVersion, int minorVersion) GetFileVersionInfo(string filePath, ArchitectureType architectureType) + public static (string fileVersion, int majorVersion, int minorVersion, int buildVersion) GetFileVersionInfo(string filePath, ArchitectureType architectureType) { var fileName = Path.GetFileNameWithoutExtension(filePath); var rootPath = Path.GetDirectoryName(filePath); var fileVersion = string.Empty; var majorVersion = 0; var minorVersion = 0; + var buildVersion = 0; switch (GetPlatformTypeByArch(architectureType)) { @@ -136,7 +137,8 @@ public static (string fileVersion, int majorVersion, int minorVersion) GetFileVe fileVersion = !string.IsNullOrEmpty(info.ProductVersion) ? info.ProductVersion.Split('_')[0] : Language.GetString(PatchStatus.Unknown.ToString()); majorVersion = info.ProductMajorPart; minorVersion = info.ProductMinorPart; - return (fileVersion, majorVersion, minorVersion); + buildVersion = info.ProductBuildPart; + return (fileVersion, majorVersion, minorVersion, buildVersion); case PlatformType.MacOS: rootPath = Path.Combine(filePath, "Contents"); var plistFile = Path.Combine(rootPath, $"Info.plist"); @@ -145,10 +147,8 @@ public static (string fileVersion, int majorVersion, int minorVersion) GetFileVe if (match.Success) { fileVersion = match.Groups["version"].Value; - var versions = fileVersion.Split('.'); - _ = int.TryParse(versions[0], out majorVersion); - _ = int.TryParse(versions[1], out minorVersion); - return (fileVersion, majorVersion, minorVersion); + ParseVersionStr(fileVersion, ref majorVersion, ref minorVersion, ref buildVersion); + return (fileVersion, majorVersion, minorVersion, buildVersion); } break; case PlatformType.Linux: @@ -169,10 +169,8 @@ public static (string fileVersion, int majorVersion, int minorVersion) GetFileVe if (infoMatch.Success) { fileVersion = infoMatch.Groups["version"].Value; - var versions = fileVersion.Split('.'); - _ = int.TryParse(versions[0], out majorVersion); - _ = int.TryParse(versions[1], out minorVersion); - return (fileVersion, majorVersion, minorVersion); + ParseVersionStr(fileVersion, ref majorVersion, ref minorVersion, ref buildVersion); + return (fileVersion, majorVersion, minorVersion, buildVersion); } else { @@ -189,10 +187,8 @@ public static (string fileVersion, int majorVersion, int minorVersion) GetFileVe fileVersion = TryGetVersionOfUnity(filePath); if (!string.IsNullOrEmpty(fileVersion)) { - var versions = fileVersion.Split('.'); - _ = int.TryParse(versions[0], out majorVersion); - _ = int.TryParse(versions[1], out minorVersion); - return (fileVersion, majorVersion, minorVersion); + ParseVersionStr(fileVersion, ref majorVersion, ref minorVersion, ref buildVersion); + return (fileVersion, majorVersion, minorVersion, buildVersion); } else { @@ -202,7 +198,21 @@ public static (string fileVersion, int majorVersion, int minorVersion) GetFileVe break; } - return (fileVersion, majorVersion, minorVersion); + return (fileVersion, majorVersion, minorVersion, buildVersion); + } + + public static void ParseVersionStr(string version, ref int major, ref int minor, ref int build) + { + if (string.IsNullOrEmpty(version)) + return; + + var splits = version.Split('.'); + if (splits.Length > 0) + int.TryParse(splits[0], out major); + if (splits.Length > 1) + int.TryParse(splits[1], out minor); + if (splits.Length > 2) + int.TryParse(splits[2], out build); } public static async Task MacOSRemoveQuarantine(string appPath) diff --git a/Patcher/Unity/UnityPatchInfos.cs b/Patcher/Unity/UnityPatchInfos.cs index 75db007..c9f469b 100644 --- a/Patcher/Unity/UnityPatchInfos.cs +++ b/Patcher/Unity/UnityPatchInfos.cs @@ -239,15 +239,6 @@ public static byte[] ToArray(params byte[] bytes) }, new() { -// 2021.3.22(silicon) - Version = "2021.3.22", - Architecture = ArchitectureType.MacOS_ARM64, - LightPattern = ToBytes(ToArray("14 68 68 38 14 05 00 34"), ToArray("20 06 00 36 E1 E3 01 91 E0 03 13 AA 2F 0B")), - DarkPattern = ToBytes(ToArray("14 68 68 38 28 00 00 14"), ToArray("20 06 00 37 E1 E3 01 91 E0 03 13 AA 2F 0B")), - }, - - new() - { Version = "5.6.6 ; 5.6.7", LightPattern = ToBytes("84 CC 00 00 00 49 8B 37 E8 40 63 00 00 BB 0C"), DarkPattern = ToBytes("85 CC 00 00 00 49 8B 37 E8 40 63 00 00 BB 0C"), @@ -436,6 +427,13 @@ public static byte[] ToArray(params byte[] bytes) DarkPattern = ToBytes(ToArray("14 68 68 38 28 00 00 14 41 D3 00 90 21 60"), ToArray("20 06 00 37 E1 E3 01 91 E0 03 13 AA 2F 0B")), }, new() + { + Version = "2021.3.21", + Architecture = ArchitectureType.MacOS_ARM64, + LightPattern = ToBytes(ToArray("14 68 68 38 14 05 00 34"), ToArray("20 06 00 36 E1 E3 01 91 E0 03 13 AA 2F 0B")), + DarkPattern = ToBytes(ToArray("14 68 68 38 28 00 00 14"), ToArray("20 06 00 37 E1 E3 01 91 E0 03 13 AA 2F 0B")), + }, + new() { Version = "2022.1.2", Architecture = ArchitectureType.MacOS_ARM64, diff --git a/UniHacker.csproj b/UniHacker.csproj index cc4ae5c..3a99eb7 100644 --- a/UniHacker.csproj +++ b/UniHacker.csproj @@ -8,7 +8,7 @@ true tylearymf tylearymf - 4.3 + 4.5 com.tylearymf.unihacker https:/www.github.com/tylearymf/unihacker Assets\avalonia-logo.ico