Skip to content

Commit

Permalink
Update unity and hub patches for Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tylearymf committed Sep 4, 2022
1 parent ada9a44 commit 53b822f
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 47 deletions.
12 changes: 12 additions & 0 deletions Assets/Language_Chinese.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@

https://www.github.com/tylearymf/UniHacker</value>
</data>
<data name="Hub_copy_error1" xml:space="preserve">
<value>拷贝文件失败,请手动拷贝! '{0}' -&gt; '{1}'</value>
</data>
<data name="Hub_patch_error1" xml:space="preserve">
<value>找不到 'app.asar' 文件!</value>
</data>
<data name="Hub_patch_error2" xml:space="preserve">
<value>无法识别Unity Hub的版本号!</value>
</data>
<data name="Hub_Patch_Option" xml:space="preserve">
<value>是否需要登录你自己的账号?</value>
</data>
Expand Down Expand Up @@ -169,6 +178,9 @@ https://www.github.com/tylearymf/UniHacker</value>
<data name="Support" xml:space="preserve">
<value>支持破解</value>
</data>
<data name="Unity_patch_error1" xml:space="preserve">
<value>无法识别Unity的版本号!</value>
</data>
<data name="Unknown" xml:space="preserve">
<value>未知</value>
</data>
Expand Down
12 changes: 12 additions & 0 deletions Assets/Language_English.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ If patch fails, please submit Unity binary file or Unity Hub version number on G

https://www.github.com/tylearymf/UniHacker</value>
</data>
<data name="Hub_copy_error1" xml:space="preserve">
<value>Failed to copy files. Please manually copy files! '{0}' -&gt; '{1}'</value>
</data>
<data name="Hub_patch_error1" xml:space="preserve">
<value>The 'app.asar' file could not be found!</value>
</data>
<data name="Hub_patch_error2" xml:space="preserve">
<value>Unable to detect the version number of the Unity Hub!</value>
</data>
<data name="Hub_Patch_Option" xml:space="preserve">
<value>Do you need to log in to your own account?</value>
</data>
Expand Down Expand Up @@ -169,6 +178,9 @@ https://www.github.com/tylearymf/UniHacker</value>
<data name="Support" xml:space="preserve">
<value>Support Patch</value>
</data>
<data name="Unity_patch_error1" xml:space="preserve">
<value>Unable to detect the version number of the Unity!</value>
</data>
<data name="Unknown" xml:space="preserve">
<value>Unknown</value>
</data>
Expand Down
6 changes: 5 additions & 1 deletion Patcher/Hub/UnityHubPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public UnityHubPatcher(string filePath) : base(filePath)
if (patchResult)
{
if (Directory.Exists(asarUnpackPath))
CopyDirectory(asarUnpackPath, exportFolder, true);
{
var result = CopyDirectory(asarUnpackPath, exportFolder, true);
if (!result)
await MessageBox.Show(Language.GetString("Hub_copy_error1", asarUnpackPath, exportFolder));
}

if (File.Exists(asarPath) && !File.Exists(asarBackupPath))
File.Move(asarPath, asarBackupPath);
Expand Down
101 changes: 73 additions & 28 deletions Patcher/Misc/PlatformUtils.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Avalonia;
Expand Down Expand Up @@ -106,7 +108,7 @@ public static (string rootPath, string filePath) GetRealFilePath(string filePath
realFilePath = Path.Combine(rootPath, $"MacOS/{fileName}");
break;
case PlatformType.Linux:
if (fileName == "unityhub")
if (fileName.Contains("unityhub"))
realFilePath = Path.Combine(rootPath, "unityhub-bin");
break;
}
Expand Down Expand Up @@ -147,12 +149,18 @@ public static (string fileVersion, int majorVersion, int minorVersion) GetFileVe
case PlatformType.Linux:
if (fileName.Contains("unityhub", StringComparison.OrdinalIgnoreCase))
{
var hubPath = Path.GetDirectoryName(rootPath);
var infoPath = Path.Combine(hubPath!, "info");
if (File.Exists(infoPath))
var asarPath = Path.Combine(rootPath!, "resources/app.asar");
var asarBakPath = Path.Combine(rootPath!, "resources/app.asar.bak");
if (File.Exists(asarPath) || File.Exists(asarBakPath))
{
var infoContent = File.ReadAllText(infoPath);
var infoMatch = Regex.Match(infoContent, @"version\"":\s*\""(?<version>.*?)\""", RegexOptions.Singleline);
var asarContent = string.Empty;

if (File.Exists(asarPath))
asarContent = File.ReadAllText(asarPath);
else
asarContent = File.ReadAllText(asarBakPath);

var infoMatch = Regex.Match(asarContent, @"""name"":\s""unityhub"",.*?""version"":\s""(?<version>.*?)"",", RegexOptions.Singleline | RegexOptions.IgnoreCase);
if (infoMatch.Success)
{
fileVersion = infoMatch.Groups["version"].Value;
Expand All @@ -161,33 +169,29 @@ public static (string fileVersion, int majorVersion, int minorVersion) GetFileVe
_ = int.TryParse(versions[1], out minorVersion);
return (fileVersion, majorVersion, minorVersion);
}
else
{
MessageBox.Show(Language.GetString("Hub_patch_error2"));
}
}
else
{
MessageBox.Show(Language.GetString("Hub_patch_error1"));
}
}
else
{
#pragma warning disable CS8604
var cacheFolder = new DirectoryInfo(Path.Combine(rootPath, "Data/Resources/PackageManager/ProjectTemplates/libcache"));
#pragma warning restore CS8604
if (cacheFolder.Exists)
fileVersion = TryGetVersionOfUnity(filePath);
if (!string.IsNullOrEmpty(fileVersion))
{
var childFolders = cacheFolder.GetDirectories();
foreach (var child in childFolders)
{
var infoPath = Path.Combine(child.FullName, "Bee/bee_backend.info");
if (File.Exists(infoPath))
{
var infoContent = File.ReadAllText(infoPath);
var infoMatch = Regex.Match(infoContent, @"UnityVersion\"":\s*\""(?<version>.*?)\""", RegexOptions.Singleline);
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);
}
}
}
var versions = fileVersion.Split('.');
_ = int.TryParse(versions[0], out majorVersion);
_ = int.TryParse(versions[1], out minorVersion);
return (fileVersion, majorVersion, minorVersion);
}
else
{
MessageBox.Show(Language.GetString("Unity_patch_error1"));
}
}
break;
Expand All @@ -210,6 +214,47 @@ public static async Task<bool> MacOSRemoveQuarantine(string appPath)
return false;
}
}

public static string TryGetVersionOfUnity(string filePath)
{
var maxLength = 40;
var fileBytes = File.ReadAllBytes(filePath);

var regex1 = new Regex(@"\d+\.\d\.\d+[fb]\d_\w+", RegexOptions.Compiled | RegexOptions.Singleline);
var regex2 = new Regex(@"\d+\.\d\.\d+[fb]\d\.git\.\w+", RegexOptions.Compiled | RegexOptions.Singleline);

var counter = 0;
var stringBytes = new List<byte>(maxLength);

void Clear()
{
counter = 0;
stringBytes.Clear();
}

for (int i = 0; i < fileBytes.Length; i++)
{
if (++counter >= maxLength)
{
Clear();
continue;
}

stringBytes.Add(fileBytes[i]);
if (fileBytes[i] == 0 && stringBytes.Count > 1)
{
stringBytes.RemoveAt(stringBytes.Count - 1);
var versionName = Encoding.UTF8.GetString(stringBytes.ToArray());

if (regex1.IsMatch(versionName) || regex2.IsMatch(versionName))
return versionName;

Clear();
}
}

return string.Empty;
}
}

internal enum PlatformType
Expand Down
2 changes: 1 addition & 1 deletion Patcher/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class PatchManager
var fileName = Path.GetFileName(filePath);
if (fileName == "Unity" + PlatformUtils.GetExtension())
return new UnityPatcher(filePath);
else if (string.Compare(fileName.Replace(" ", ""), "UnityHub" + PlatformUtils.GetExtension(), true) == 0)
else if (fileName.Replace(" ", "").Contains("unityhub", StringComparison.OrdinalIgnoreCase))
return new UnityHubPatcher(filePath);
else
return new DefaultPatcher(filePath);
Expand Down
42 changes: 39 additions & 3 deletions Patcher/Unity/UnityPatchInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,45 @@ public static byte[] ToArray(params byte[] bytes)
{
new()
{
Version = "2021.3.0",
LightPattern = ToBytes(ToArray("74 67 48 8B 35 9C 82 23 01 48 8D 0D"), ToArray("84 36 01 00 00 48 8D B4 24 A8")),
DarkPattern = ToBytes(ToArray("EB 67 48 8B 35 9C 82 23 01 48 8D 0D"), ToArray("85 36 01 00 00 48 8D B4 24 A8")),
// 2017.4.40
Version = "2017",
LightPattern = ToBytes(ToArray("3C 7A 46 FF E9 78 FF FF FF 90 66 0F 1F 44 00 00 41 57 41 56 41 55")),
DarkPattern = ToBytes(ToArray("3C 7A 46 FF E9 78 FF FF FF 90 66 0F 1F 44 00 00 B8 01 00 00 00 C3")),
},
new()
{
// 2018.4.36
Version = "2018",
LightPattern = ToBytes(ToArray("24 4F E9 BA FE FF FF 90 0F 1F 84 00 00 00 00 00 41 57 41 56 41 55")),
DarkPattern = ToBytes(ToArray("24 4F E9 BA FE FF FF 90 0F 1F 84 00 00 00 00 00 B8 01 00 00 00 C3")),
},
new()
{
// 2019.4.40
Version = "2019",
LightPattern = ToBytes(ToArray("74 60 48 8D 35 ? ? ? 06 48 8D 0D"), ToArray("84 F6 01 00 00 48 8D 74 24 30")),
DarkPattern = ToBytes(ToArray("EB 60 48 8D 35 ? ? ? 06 48 8D 0D"), ToArray("85 F6 01 00 00 48 8D 74 24 30")),
},
new()
{
// 2020.3.38
Version = "2020",
LightPattern = ToBytes(ToArray("74 60 48 8B 35 ? ? ? 01 48 8D 0D"), ToArray("84 78 01 00 00 48 8D 74 24 78")),
DarkPattern = ToBytes(ToArray("EB 60 48 8D 35 ? ? ? 01 48 8D 0D"), ToArray("85 78 01 00 00 48 8D 74 24 78")),
},
new()
{
// 2021.3.7
Version = "2021",
LightPattern = ToBytes(ToArray("74 67 48 8B 35 ? ? ? 01 48 8D 0D"), ToArray("84 36 01 00 00 48 8D B4 24 A8")),
DarkPattern = ToBytes(ToArray("EB 67 48 8B 35 ? ? ? 01 48 8D 0D"), ToArray("85 36 01 00 00 48 8D B4 24 A8")),
},
new()
{
// 2022.1.15
Version = "2022",
LightPattern = ToBytes(ToArray("0F 84 A7 00 00 00 48 8B 35 D8 CE 27"), ToArray("84 36 01 00 00 48 8D B4 24 A8")),
DarkPattern = ToBytes(ToArray("E9 A8 00 00 00 00 48 8B 35 D8 CE 27"), ToArray("85 36 01 00 00 48 8D B4 24 A8")),
},
};

Expand Down
4 changes: 3 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public static AppBuilder BuildAvaloniaApp()
static void Test()
{
#if DEBUG
var versionName = PlatformUtils.TryGetVersionOfUnity("D:/Unity");

var stopwatch = new Stopwatch();
stopwatch.Start();
Console.WriteLine($"Start Search Pattern.");

var filePath = "D:/Unity";
var version = "2020.2.7";
var version = "2018.1.15";
var architecture = MachineArchitecture.GetArchitectureType(filePath);
var patchInfo = UnityPatchInfos.FindPatchInfo(version, architecture);
var fileBytes = File.ReadAllBytes(filePath);
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@

### 支持破解的Unity版本

| 2021.3.0 | | | | | |
| :----------------: | :--: | :--: | :--: | :--: | :--: |
| :white_check_mark: | | | | | |
| 2022.1 | 2021.x | 2020.x | 2019.x | 2018.x | 2017.x |
| :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |

### 支持破解的Unity Hub版本

| 3.x | 2.x | | | | |
| :--------: | :--------: | ---- | ---- | ---- | ---- |
| :question: | :question: | | | | |
| 3.x | 2.x | | | | |
| :----------------: | :----------------: | ---- | ---- | ---- | ---- |
| :white_check_mark: | :white_check_mark: | | | | |

## 免责声明

Expand Down
12 changes: 6 additions & 6 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ Usage

### Supported Unity Versions

| 2021.3.0 | | | | | |
| :----------------: | :--: | :--: | :--: | :--: | :--: |
| :white_check_mark: | | | | | |
| 2022.1 | 2021.x | 2020.x | 2019.x | 2018.x | 2017.x |
| :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |

### Supported UnityHub Versions

| 3.x | 2.x | | | | |
| :--------: | :--------: | ---- | ---- | ---- | ---- |
| :question: | :question: | | | | |
| 3.x | 2.x | | | | |
| :----------------: | :----------------: | ---- | ---- | ---- | ---- |
| :white_check_mark: | :white_check_mark: | | | | |

## Legal Disclaimer

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>3.4</Version>
<Version>3.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 53b822f

Please sign in to comment.