Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent app suspension for MCBE. #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
56 changes: 53 additions & 3 deletions Flarial.Minimal/Injector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,70 @@

namespace Flarial.Minimal
{

public static class Minecraft
{
[DllImport("kernel32.dll")]
static extern long GetPackagesByPackageFamily(
[MarshalAs(UnmanagedType.LPWStr)] string packageFamilyName,
ref uint count,
IntPtr packageFullNames,
ref uint bufferLength,
IntPtr buffer);

[ComImport]
[Guid("f27c3930-8029-4ad1-94e3-3dba417810c1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IPackageDebugSettings
{
long EnableDebugging(
[MarshalAs(UnmanagedType.LPWStr)] string packageFullName,
[MarshalAs(UnmanagedType.LPWStr)] string debuggerCommandLine,
[MarshalAs(UnmanagedType.LPWStr)] string environment);
long DisableDebugging([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
long Suspend([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
long Resume([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
long TerminateAllProcesses([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
long SetTargetSessionId(ulong sessionId);
long StartServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
long StopServicing([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
long StartSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, ulong sessionId);
long StopSessionRedirection([MarshalAs(UnmanagedType.LPWStr)] string packageFullName);
long GetPackageExecutionState([MarshalAs(UnmanagedType.LPWStr)] string packageFullName, IntPtr packageExecutionState);
long RegisterForPackageStateChanges(
[MarshalAs(UnmanagedType.LPWStr)] string packageFullName,
IntPtr pPackageExecutionStateChangeNotification,
IntPtr pdwCookie);
long UnregisterForPackageStateChanges(ulong dwCookie);
}

private static Process Process;

public static void init()
{
var mcIndex = Process.GetProcessesByName("Minecraft.Windows");
IPackageDebugSettings pPackageDebugSettings = (IPackageDebugSettings)Activator.CreateInstance(
Type.GetTypeFromCLSID(new Guid(0xb1aec16f, 0x2383, 0x4852, 0xb0, 0xe9, 0x8f, 0x0b, 0x1d, 0xc6, 0x6b, 0x4d)));
uint count = 0, bufferLength = 0;
GetPackagesByPackageFamily("Microsoft.MinecraftUWP_8wekyb3d8bbwe", ref count, IntPtr.Zero, ref bufferLength, IntPtr.Zero);
IntPtr packageFullNames = Marshal.AllocHGlobal((int)(count * IntPtr.Size)),
buffer = Marshal.AllocHGlobal((int)(bufferLength * 2));
GetPackagesByPackageFamily("Microsoft.MinecraftUWP_8wekyb3d8bbwe", ref count, packageFullNames, ref bufferLength, buffer);
for (int i = 0; i < count; i++)
{
pPackageDebugSettings.EnableDebugging(Marshal.PtrToStringUni(Marshal.ReadIntPtr(packageFullNames)), null, null);
packageFullNames += IntPtr.Size;
}
Marshal.FreeHGlobal(packageFullNames);
Marshal.FreeHGlobal(buffer);

if (mcIndex.Length > 0)
{
Process = mcIndex[0];

}
}

public static async Task WaitForModules()
{
while (Process == null)
Expand All @@ -33,12 +83,12 @@ public static async Task WaitForModules()
Process.Refresh();
if (Process.Modules.Count > 155)
break;

await Task.Delay(100);
}
}
}

public enum DllReturns
{
SUCCESS = 0,
Expand Down