Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 55 additions & 5 deletions BedrockLauncher.Core/BedrockCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ private static async Task<Process> WaitForProcessAsync(string processName, DateT

if (processes.Length > 0)
{

return processes
.Where(p => p.StartTime > startTime)
.OrderBy(p => (p.StartTime - startTime).TotalMilliseconds)
Expand All @@ -265,6 +264,17 @@ private static async Task<Process> WaitForProcessAsync(string processName, DateT

return null;
}
private static DateTime GetStartTimeSafe(Process proc)
{
try
{
return proc.StartTime;
}
catch
{
return DateTime.MinValue;
}
}
/// <summary>
/// Launch the Minecraft game process based on the specified launch options
/// </summary>
Expand All @@ -276,15 +286,55 @@ public async Task<Process> LaunchGameAsync(LaunchOptions options)
if (options.MinecraftBuildType == MinecraftBuildTypeVersion.GDK)
{
options.Progress?.Report(LaunchState.Launching);
DateTime startTimestamp = DateTime.Now;
string targetExe = "Minecraft.Windows.exe";
string fullPath = Path.Combine(options.GameFolder, targetExe);
string processName = Path.GetFileNameWithoutExtension(targetExe);


var beforeSnapshot = Process.GetProcessesByName(processName)
.ToDictionary(p => p.Id, p => GetStartTimeSafe(p));

Process.Start(new ProcessStartInfo()

DateTime launchTime = DateTime.Now;
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = Path.Combine(options.GameFolder, "Minecraft.Windows.exe")
Arguments = fullPath,
UseShellExecute = true
});

process = await WaitForProcessAsync("Minecraft.Windows", startTimestamp, TimeSpan.FromSeconds(10));
Process minecraftProcess = null;


for (int i = 0; i < 10; i++)
{
var currentProcesses = Process.GetProcessesByName(processName);
foreach (var proc in currentProcesses)
{

if (beforeSnapshot.ContainsKey(proc.Id))
continue;


DateTime startTime = GetStartTimeSafe(proc);
if (startTime == DateTime.MinValue)
continue;

if (startTime >= launchTime.AddMilliseconds(-200))
{
minecraftProcess = proc;
break;
}
}

if (minecraftProcess != null)
break;

Thread.Sleep(500);

}
process = minecraftProcess;

options.Progress?.Report(LaunchState.Launched);
}

Expand Down
4 changes: 2 additions & 2 deletions BedrockLauncher.Core/BedrockLauncher.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<Version>2.0.4-dev</Version>
<Version>2.0.4.1-dev</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<Version>2.0.4</Version>
<Version>2.0.4.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
6 changes: 4 additions & 2 deletions CoreTest/LaunchTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using BedrockLauncher.Core;
using BedrockLauncher.Core.CoreOption;
using BedrockLauncher.Core.DependsComplete;
Expand All @@ -15,13 +16,14 @@ public void Test()
bedrockCore.InitAsync().Wait();
var launchOptions = new LaunchOptions()
{
GameFolder = Path.GetFullPath(""),
GameFolder = Path.GetFullPath(@"E:\test2\plugins\Glacie\bedrock_versions\1.26.2"),
MinecraftBuildType = MinecraftBuildTypeVersion.GDK,
GameType = MinecraftGameTypeVersion.Release,
LaunchArgs = null
};
var process = bedrockCore.LaunchGameAsync(launchOptions).Result;
// ExeLauncher.LaunchWithLowPrivilege(@"E:\GlacieCrack\plugins\Glacie\bedrock_versions\1234\Minecraft.Windows.exe", "");
Debug.WriteLine(process.Id);
// ExeLauncher.LaunchWithLowPrivilege(@"E:\GlacieCrack\plugins\Glacie\bedrock_versions\1234\Minecraft.Windows.exe", "");
}
[TestMethod]
public void MsiTest()
Expand Down
3 changes: 2 additions & 1 deletion CoreTest/VersionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using BedrockLauncher.Core.Utils;
using BedrockLauncher.Core.VersionJsons;

namespace CoreTest
{
Expand All @@ -18,7 +19,7 @@ public void Test()
for (long i = 0; i < 1000; i++)
{

Console.WriteLine(VersionHelper.GetNextVersion(new Version("1.21.10006.0")));
Console.WriteLine(VersionsHelper.GetNextVersion(new Version("1.21.11236.0")));
}
}
}
Expand Down
Loading