Skip to content

Commit

Permalink
up 修复自定义加载器问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Dec 23, 2024
1 parent 638c539 commit e58c251
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/ColorMC.Core/Game/GameLaunch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,8 +1336,8 @@ public static async Task<Dictionary<GameSettingObj, GameLaunchRes>>

//版本号检测
if (string.IsNullOrWhiteSpace(obj.Version)
|| (obj.Loader != Loaders.Normal && string.IsNullOrWhiteSpace(obj.LoaderVersion))
|| (obj.Loader == Loaders.Custom && !File.Exists(obj.GetGameLoaderFile())))
|| (obj.Loader is not (Loaders.Normal or Loaders.Custom) && string.IsNullOrWhiteSpace(obj.LoaderVersion))
|| (obj.Loader is Loaders.Custom && !File.Exists(obj.GetGameLoaderFile())))
{
throw new LaunchException(LaunchState.VersionError, LanguageHelper.Get("Core.Launch.Error7"));
}
Expand Down
62 changes: 60 additions & 2 deletions src/ColorMC.Core/Helpers/DownloadItemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ public static async Task<ConcurrentBag<DownloadItemObj>> BuildGameLibsAsync(Game
/// <returns>下载项目列表</returns>
public static async Task<MakeDownloadNameItemsRes?> DecodeLoaderJarAsync(GameSettingObj obj, string path, CancellationToken cancel)
{
using var zFile = new ZipFile(path);
using var zFile = new ZipFile(PathHelper.OpenRead(path));
using var stream1 = new MemoryStream();
using var stream2 = new MemoryStream();
var find1 = false;
Expand Down Expand Up @@ -1013,6 +1013,64 @@ async Task UnpackAsync(ForgeInstallObj obj1)
}
}

async Task Unpack1Async(ForgeLaunchObj obj1)
{
foreach (var item in obj1.Libraries)
{
if (cancel.IsCancellationRequested)
{
return;
}
if (!string.IsNullOrWhiteSpace(item.Downloads.Artifact.Url))
{
string local = Path.GetFullPath($"{LibrariesPath.BaseDir}/{item.Downloads.Artifact.Path}");
{
using var read = PathHelper.OpenRead(local);
if (read != null)
{
string sha1 = HashHelper.GenSha1(read);
if (sha1 == item.Downloads.Artifact.Sha1)
{
continue;
}
}
}

list.Add(new()
{
Name = item.Name,
Local = Path.GetFullPath($"{LibrariesPath.BaseDir}/{item.Downloads.Artifact.Path}"),
SHA1 = item.Downloads.Artifact.Sha1,
Url = item.Downloads.Artifact.Url
});
}
else
{
var item1 = zFile.GetEntry($"maven/{item.Downloads.Artifact.Path}");
if (item1 != null)
{
string local = Path.GetFullPath($"{LibrariesPath.BaseDir}/{item.Downloads.Artifact.Path}");
{
using var read = PathHelper.OpenRead(local);
if (read != null)
{
string sha1 = HashHelper.GenSha1(read);
if (sha1 == item.Downloads.Artifact.Sha1)
{
continue;
}
}
}

{
using var stream3 = zFile.GetInputStream(item1);
await PathHelper.WriteBytesAsync(local, stream3);
}
}
}
}
}

string name = "";

try
Expand All @@ -1032,7 +1090,7 @@ async Task UnpackAsync(ForgeInstallObj obj1)
data = Encoding.UTF8.GetString(array1);
var obj2 = JsonConvert.DeserializeObject<ForgeLaunchObj>(data)!;

await UnpackAsync(obj1);
await Unpack1Async(obj2);

name = obj1.Version;
if (!obj1.Version.StartsWith(obj1.Profile))
Expand Down
66 changes: 30 additions & 36 deletions src/ColorMC.Core/LaunchPath/LibrariesPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,39 +135,21 @@ public static string GetLoaderMainClass(this GameSettingObj obj)
public static async Task<List<string>> GetLibsAsync(this GameSettingObj obj)
{
var v2 = obj.IsGameVersionV2();
var list = new Dictionary<LibVersionObj, string>();
var loaderList = new Dictionary<LibVersionObj, string>();
var gameList = new Dictionary<LibVersionObj, string>();
var version = VersionPath.GetVersion(obj.Version)!;

if (obj.Loader == Loaders.Custom && obj.CustomLoader?.OffLib == true)
{
var list1 = await DownloadItemHelper.BuildGameLibsAsync(version);
foreach (var item in list1)
{
if (item.Later == null)
{
//不添加lwjgl
if (SystemInfo.Os == OsType.Android && item.Name.Contains("org.lwjgl"))
{
continue;
}
list.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name), Path.GetFullPath(item.Local));
}
}
}
else
var list4 = await DownloadItemHelper.BuildGameLibsAsync(version);
foreach (var item in list4)
{
var list1 = await DownloadItemHelper.BuildGameLibsAsync(version);
foreach (var item in list1)
if (item.Later == null)
{
if (item.Later == null)
//不添加lwjgl
if (SystemInfo.Os == OsType.Android && item.Name.Contains("org.lwjgl"))
{
//不添加lwjgl
if (SystemInfo.Os == OsType.Android && item.Name.Contains("org.lwjgl"))
{
continue;
}
list.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name), Path.GetFullPath(item.Local));
continue;
}
gameList.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name), Path.GetFullPath(item.Local));
}
}

Expand All @@ -182,12 +164,12 @@ public static async Task<List<string>> GetLibsAsync(this GameSettingObj obj)

foreach (var item in list2)
{
list.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name), item.Local);
loaderList.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name), item.Local);
}

if (v2)
{
list.AddOrUpdate(new(), GameHelper.ForgeWrapper);
loaderList.AddOrUpdate(new(), GameHelper.ForgeWrapper);
}
}
else if (obj.Loader == Loaders.Fabric)
Expand All @@ -196,7 +178,7 @@ public static async Task<List<string>> GetLibsAsync(this GameSettingObj obj)
foreach (var item in fabric.Libraries)
{
var name = PathHelper.NameToPath(item.Name);
list.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name),
loaderList.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name),
Path.GetFullPath($"{BaseDir}/{name}"));
}
}
Expand All @@ -206,31 +188,43 @@ public static async Task<List<string>> GetLibsAsync(this GameSettingObj obj)
foreach (var item in quilt.Libraries)
{
var name = PathHelper.NameToPath(item.Name);
list.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name),
loaderList.AddOrUpdate(FuntionUtils.MakeVersionObj(item.Name),
Path.GetFullPath($"{BaseDir}/{name}"));
}
}
else if (obj.Loader == Loaders.OptiFine)
{
GameHelper.ReadyOptifineWrapper();
list.AddOrUpdate(new(), GameHelper.OptifineWrapper);
loaderList.AddOrUpdate(new(), GameHelper.OptifineWrapper);
}
else if (obj.Loader == Loaders.Custom)
{
var list2 = obj.GetCustomLoaderLibs();
foreach (var (Name, Local) in list2)
{
list.AddOrUpdate(FuntionUtils.MakeVersionObj(Name), Local);
loaderList.AddOrUpdate(FuntionUtils.MakeVersionObj(Name), Local);
}
}

var output = new List<string>();

if (obj.Loader == Loaders.Custom && obj.CustomLoader?.OffLib == true)
{
output.AddRange(loaderList.Values);
output.AddRange(gameList.Values);
}
else
{
output.AddRange(gameList.Values);
output.AddRange(loaderList.Values);
}

//游戏核心
var list3 = new List<string>(list.Values);
if (obj.Loader != Loaders.NeoForge)
{
list3.Add(GetGameFile(obj.Version));
output.Add(GetGameFile(obj.Version));
}

return list3;
return output;
}
}
7 changes: 2 additions & 5 deletions src/ColorMC.Gui/UI/Model/GameEdit/GameEditTab1Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,8 @@ public async void GameLoad()
if (_obj.Loader == Loaders.Custom)
{
LoaderType = 1;
ReadCustomLoader();
CustomLoader = true;
}
else if (_obj.Loader != Loaders.Normal)
{
Expand Down Expand Up @@ -758,11 +760,6 @@ public async void GameLoad()
FID = _obj.FID;
PID = _obj.PID;

if (_obj.Loader == Loaders.Custom)
{
ReadCustomLoader();
}

OffLib = _obj.CustomLoader?.OffLib ?? false;

GameRun = GameManager.IsGameRun(_obj);
Expand Down

0 comments on commit e58c251

Please sign in to comment.