Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Supported Unity Hub 3.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tylearymf committed Apr 22, 2023
1 parent 16cbd73 commit a6bbd64
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 44 deletions.
24 changes: 6 additions & 18 deletions Patcher/Hub/UnityHubPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -61,20 +51,18 @@ public async override Task<(bool success, string errorMsg)> ApplyPatch(Action<do
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());
Expand Down
97 changes: 97 additions & 0 deletions Patcher/Hub/UnityHubV3_4_2.cs
Original file line number Diff line number Diff line change
@@ -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<bool> 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;
}
}
}
7 changes: 6 additions & 1 deletion Patcher/Misc/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
40 changes: 25 additions & 15 deletions Patcher/Misc/PlatformUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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");
Expand All @@ -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:
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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<bool> MacOSRemoveQuarantine(string appPath)
Expand Down
16 changes: 7 additions & 9 deletions Patcher/Unity/UnityPatchInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion UniHacker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<Authors>tylearymf</Authors>
<Company>tylearymf</Company>
<Version>4.3</Version>
<Version>4.5</Version>
<PackageId>com.tylearymf.unihacker</PackageId>
<PackageProjectUrl>https:/www.github.com/tylearymf/unihacker</PackageProjectUrl>
<ApplicationIcon>Assets\avalonia-logo.ico</ApplicationIcon>
Expand Down

0 comments on commit a6bbd64

Please sign in to comment.