Beispiel #1
0
        void launchButton_Click(object sender, EventArgs e)
        {
            var si   = new STARTUP_INFO();
            var args = " -w";

            if (sound.Checked)
            {
                args += " -ns";
            }
            var success    = CreateProcess(installDir.Text + "Game.exe", args, IntPtr.Zero, IntPtr.Zero, false, 4, IntPtr.Zero, installDir.Text, ref si, out PROCESS_INFORMATION pi);
            var d2         = Process.GetProcesses().ToList().FirstOrDefault(p => p.Id == pi.dwProcessId);
            var procHandle = pi.hProcess;      // OpenProcess(0x001F0FFF, false, startedProcess.Id);
            var moduleBase = (IntPtr)0x400000; // startedProcess.MainModule.BaseAddress doesn't work in suspended since crt/app isn't loaded yet?

            if (multi.Checked)
            {
                WriteProcessMemory(procHandle, moduleBase + 0xF562A, new Byte[] { 0xDB }, 1, 0);                // replace (test eax, eax) with (test ebx, ebx), same window check
            }
            if (sleepy.Checked)
            {
                WriteProcessMemory(procHandle, moduleBase + 0x51C31, new Byte[] { 0x90, 0x90 }, 2, 0);
            }
            WriteProcessMemory(procHandle, moduleBase + 0x11FE3B, new Byte[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }, 6, 0); // remove extrawork
            if (resolutionBox.Text != "800x600")
            {
                SetResolution(procHandle, moduleBase);
            }
            ResumeThread(pi.hThread);
            d2.WaitForInputIdle();
            if (fullscreen.Checked)
            {
                int style = GetWindowLong(d2.MainWindowHandle, -16);
                SetWindowLong(d2.MainWindowHandle, -16, (style & ~(0x00c00000)));
                SetWindowPos(d2.MainWindowHandle, 0, 0, 0, Resolution.Width, Resolution.Height, 0);
            }
            if (ClassicCdKey != classicCdKey.Text || XpakCdKey != xpakCdKey.Text)
            {
                UpdateCdKey(procHandle, moduleBase, classicCdKey.Text, xpakCdKey.Text);
            }
            EnableCustomCheckRevision(d2, procHandle);

            var dll = Resources.D2Mods;

            if (File.Exists("D2Mods.dll"))
            {
                dll = File.ReadAllBytes(@"D2Mods.dll");
            }
            if (mapHack.Checked)
            {
                var mm = new ManualMapInjection.Injection.ManualMapInjector(d2);
                mm.Inject(dll, procHandle);
            }
            CloseHandle(procHandle);
        }
Beispiel #2
0
        void launchButton_Click(object sender, EventArgs e)
        {
            var si   = new STARTUP_INFO();
            var args = " -w";

            if (sound.Checked)
            {
                args += " -ns";
            }
            var success    = CreateProcess(installDir.Text + "Game.exe", args, IntPtr.Zero, IntPtr.Zero, false, 4, IntPtr.Zero, installDir.Text, ref si, out PROCESS_INFORMATION pi);
            var d2         = Process.GetProcesses().ToList().FirstOrDefault(p => p.Id == pi.dwProcessId);
            var procHandle = pi.hProcess;      // OpenProcess(0x001F0FFF, false, startedProcess.Id);
            var moduleBase = (IntPtr)0x400000; // startedProcess.MainModule.BaseAddress doesn't work in suspended since crt/app isn't loaded yet?

            if (multi.Checked)
            {
                WriteProcessMemory(procHandle, moduleBase + 0xF562A, new Byte[] { 0xDB }, 1, 0);                // replace (test eax, eax) with (test ebx, ebx), same window check
            }
            if (sleepy.Checked)
            {
                WriteProcessMemory(procHandle, moduleBase + 0x51C31, new Byte[] { 0x90, 0x90 }, 2, 0);
            }
            WriteProcessMemory(procHandle, moduleBase + 0x11FE3B, new Byte[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }, 6, 0); // remove extrawork
            if (resolutionBox.Text != "800x600")
            {
                SetResolution(procHandle, moduleBase);
            }
            ResumeThread(pi.hThread);
            d2.WaitForInputIdle();
            if (fullscreen.Checked)
            {
                int style = GetWindowLong(d2.MainWindowHandle, -16);
                SetWindowLong(d2.MainWindowHandle, -16, (style & ~(0x00c00000)));
                SetWindowPos(d2.MainWindowHandle, 0, 0, 0, Resolution.Width, Resolution.Height, 0);
            }
            if (ClassicCdKey != classicCdKey.Text || XpakCdKey != xpakCdKey.Text)
            {
                UpdateCdKey(procHandle, moduleBase, classicCdKey.Text, xpakCdKey.Text);
            }
            EnableCustomCheckRevision(d2, procHandle);

            //if (File.Exists("D2Mods.dll")) HardcodedDll.Bytes = File.ReadAllBytes(@"D2Mods.dll");
            var createDllHardcode = false;

            if (createDllHardcode)
            {
                var sb = new StringBuilder();
                sb.Append(@"using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D2Launcher
{
    public static class HardcodedDll
    {
        public static Byte[] Bytes = new Byte[]{
");
                var q = 0; sb.Append(String.Join(", ", HardcodedDll.Bytes.Select(b => (((++q % 16) == 0) ? "\n" : "") + "0x" + b.ToString("X"))));
                sb.Append(@"};
    }
}
");
                File.WriteAllText(@"..\D2Launcher\HardcodedDll.cs", sb.ToString());
            }
            if (mapHack.Checked)
            {
                var mm = new ManualMapInjection.Injection.ManualMapInjector(d2);
                mm.Inject(HardcodedDll.Bytes, procHandle);
            }
            CloseHandle(procHandle);
        }