Пример #1
0
 public void SendValues(float value, int ResX, int ResY)
 {
     desiredfov  = value;
     ResolutionX = ResX;
     ResolutionY = ResY;
     LogHandler.WriteLine("Thread received values: " + ResolutionX + "x" + ResolutionY + " @ " + desiredfov);
 }
Пример #2
0
 public void SendValues(float value, int ResX, int ResY, bool lithFixEnabled)
 {
     desiredfov     = value;
     ResolutionX    = ResX;
     ResolutionY    = ResY;
     LithFixEnabled = lithFixEnabled;
     LogHandler.WriteLine($"Thread received values: {ResolutionX}x{ResolutionY} @ {desiredfov}. LithFix: {LithFixEnabled}");
 }
Пример #3
0
 public void SendValues(float value, int ResX, int ResY, bool lithFixEnabled)
 {
     desiredfov     = value;
     ResolutionX    = ResX;
     ResolutionY    = ResY;
     LithFixEnabled = lithFixEnabled;
     LogHandler.WriteLine("GameHack thread received values: " + ResolutionX + "x" + ResolutionY + " @ " + desiredfov);
 }
Пример #4
0
 public mainform(string[] originalParams)
 {
     if (originalParams.Contains("-skiplauncher", StringComparer.InvariantCultureIgnoreCase))
     {
         originalParams = originalParams.Where(x => x.ToLower() != "-skiplauncher").ToArray();
         skipLauncher   = true;
     }
     this.originalParams = string.Join(" ", originalParams);
     LogHandler.WriteLine("LogFile created.");
     InitializeComponent();
 }
Пример #5
0
        private void startGame()
        {
            string cmdlineparamters = File.ReadLines("avp2cmds.txt").FirstOrDefault();

            cmdlineparamters = stripResolutionParameters(cmdlineparamters);

            if (_GraphicsSettings.windowed)
            {
                cmdlineparamters = cmdlineparamters + " +windowed 1";
            }
            else
            {
                cmdlineparamters = cmdlineparamters + " +windowed 0";
            }

            if (_GraphicsSettings.disablesound)
            {
                cmdlineparamters = cmdlineparamters + " +DisableSound 1";
            }
            else
            {
                cmdlineparamters = cmdlineparamters + " +DisableSound 0";
            }

            if (_GraphicsSettings.disablemusic)
            {
                cmdlineparamters = cmdlineparamters + " +DisableMusic 1";
            }
            else
            {
                cmdlineparamters = cmdlineparamters + " +DisableMusic 0";
            }

            if (_GraphicsSettings.disablelogos)
            {
                cmdlineparamters = cmdlineparamters + " +DisableMovies 1";
            }
            else
            {
                cmdlineparamters = cmdlineparamters + " +DisableMovies 0";
            }

            if (_GraphicsSettings.disablejoystick)
            {
                cmdlineparamters = cmdlineparamters + " +DisableJoystick 1";
            }
            else
            {
                cmdlineparamters = cmdlineparamters + " +DisableJoystick 0";
            }

            if (_GraphicsSettings.disabletripplebuffering)
            {
                cmdlineparamters = cmdlineparamters + " +EnableTripBuf 0";
            }
            else
            {
                cmdlineparamters = cmdlineparamters + " +EnableTripBuf 1";
            }

            if (_GraphicsSettings.disablehardwarecursor)
            {
                cmdlineparamters = cmdlineparamters + " +DisableHardwareCursor 1";
            }
            else
            {
                cmdlineparamters = cmdlineparamters + " +DisableHardwareCursor 0";
            }

            cmdlineparamters = cmdlineparamters + " " + originalParams + " " + _GraphicsSettings.T_CommandLine.Text;

            LogHandler.WriteLine("Launch parameters are: " + cmdlineparamters);

            Thread GameHackThread = new Thread(_gamehack.DoWork);

            if (_GraphicsSettings.aspectratiohack)
            {
                _gamehack.SendValues(_GraphicsSettings.fov, _GraphicsSettings.ResolutionX, _GraphicsSettings.ResolutionY);
                GameHackThread.Start();
            }


            try
            {
                Process gameProcess = new Process();
                gameProcess.StartInfo.FileName         = Path.Combine(Directory.GetCurrentDirectory(), "Lithtech.exe");
                gameProcess.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
                gameProcess.StartInfo.Arguments        = cmdlineparamters;
                this.WindowState = FormWindowState.Minimized;

                gameProcess.Start();
                gameProcess.WaitForExit();
                _gamehack.RequestStop();
                this.Close();
            }
            catch (Exception ex)
            {
                LogHandler.WriteLine("An error occurred when creating new process: " + ex.Message);
                return;
            }
        }
Пример #6
0
        public void DoWork()
        {
            fovY             = HorizontalFOVToVerticalRadians(desiredfov);
            fovX             = VerticalRadiansToHorizontalFor4By3Monitor(fovY);
            bgCorrectedValue = correntMenuBGWithAspect(1.308997035f);
            int variableBaseAddress = GetVariableAddressFromDll();

            LogHandler.WriteLine("Launcher directory is: " + path);
            LogHandler.WriteLine("Display FOV calculated to: " + fovX + " horizontal, " + fovY + " vertical");
            LogHandler.WriteLine("Variables address in DLL is: " + variableBaseAddress.ToString("X4"));
            System.Threading.Thread.Sleep(5000);

            while (!_shouldStop)
            {
                try
                {
                    myProcess = Process.GetProcessesByName(processName);

                    if (myProcess.Length > 0)
                    {
                        if (foundProcess == false)
                        {
                            System.Threading.Thread.Sleep(2000);
                        }
                        if (cshellBaseAdress == 0x0 || LithTechBaseAdress == 0x0 || d3dren == 0x0)
                        {
                            String    appToHookTo           = processName;
                            Process[] foundProcesses        = Process.GetProcessesByName(appToHookTo);
                            ProcessModuleCollection modules = foundProcesses[0].Modules;
                            foreach (ProcessModule i in modules)
                            {
                                var moduleName = i.ModuleName.ToLower();
                                if (!LithFixEnabled && moduleName == "cshell.dll")
                                {
                                    cshellBaseAdress = i.BaseAddress.ToInt32();
                                }
                                else if (LithFixEnabled && moduleName == "cshellreal.dll")
                                {
                                    cshellBaseAdress = i.BaseAddress.ToInt32();
                                }
                                else if (moduleName == "d3d.ren")
                                {
                                    d3dren = i.BaseAddress.ToInt32();
                                }
                            }
                        }

                        foundProcess = true;
                    }

                    if (foundProcess)
                    {
                        ReadFovX    = Trainer.ReadPointerFloat(myProcess, cshellBaseAdress + fovAddress, offsetFovX);
                        ReadFovY    = Trainer.ReadPointerFloat(myProcess, cshellBaseAdress + fovAddress, offsetFovY);
                        readBgValue = Trainer.ReadPointerFloat(myProcess, cshellBaseAdress + bgScalingAddress, bgScalingOffsetsY);

                        if (ReadFovX != fovX && ReadFovX != 0x0000000)
                        {
                            Trainer.WritePointerFloat(myProcess, cshellBaseAdress + fovAddress, offsetFovX, fovX);
                        }
                        if (ReadFovY != fovY && ReadFovY != 0x0000000)
                        {
                            Trainer.WritePointerFloat(myProcess, cshellBaseAdress + fovAddress, offsetFovY, fovY);
                        }
                        if (readBgValue != bgCorrectedValue && readBgValue != 0x0000000)
                        {
                            Trainer.WritePointerFloat(myProcess, cshellBaseAdress + bgScalingAddress, bgScalingOffsetsX, 1.570796f);
                            Trainer.WritePointerFloat(myProcess, cshellBaseAdress + bgScalingAddress, bgScalingOffsetsY, bgCorrectedValue);
                        }

                        if (!dllInjected && LithTechBaseAdress != 0x0 && cshellBaseAdress != 0x0 && d3dren != 0x0)
                        {
                            #region LogAssemblyBytes
                            {
                                string strByte = "";
                                for (int i = 0; i < 5; i++)
                                {
                                    strByte += (Trainer.ReadByte(myProcess, cshellBaseAdress + 0xE389 + i)).ToString("X2");
                                }

                                LogHandler.WriteLine("Bytes at injection point cshellBaseAdress + 0xE389 (resolution hack):" + strByte);
                            }

                            {
                                string strByte = "";
                                for (int i = 0; i < 6; i++)
                                {
                                    strByte += (Trainer.ReadByte(myProcess, LithTechBaseAdress + 0xB7F4 + i)).ToString("X2");
                                }

                                LogHandler.WriteLine("Bytes at injection point LithTechBaseAdress + 0xB7F4 (fov hack):" + strByte);
                            }

                            {
                                string strByte = "";
                                for (int i = 0; i < 9; i++)
                                {
                                    strByte += (Trainer.ReadByte(myProcess, d3dren + 0xFA52 + i)).ToString("X2");
                                }

                                LogHandler.WriteLine("Bytes at injection point d3dren + 0xFA52 (viewmodel hack):" + strByte);
                            }
                            #endregion

                            DllInjectionResult result = DllInjector.GetInstance.Inject(myProcess, Path.Combine(path, "widescreenfix.dll"));
                            LogHandler.WriteLine("DLL Injection: " + result);
                            if (result == DllInjectionResult.Success)
                            {
                                dllInjected = true;
                            }
                            else
                            {
                                LogHandler.WriteLine("Error when injecting DLL: " + result.ToString());
                                MessageBox.Show("Error when injecting DLL: " + result.ToString());
                            }

                            System.Threading.Thread.Sleep(500);

                            ProcessModuleCollection modules            = myProcess[0].Modules;
                            ProcessModule           dllBaseAdressIWant = null;
                            foreach (ProcessModule i in modules)
                            {
                                if (i.ModuleName == "widescreenfix.dll")
                                {
                                    dllBaseAdressIWant = i;
                                }
                            }
                            hookedDllAddress = dllBaseAdressIWant.BaseAddress.ToInt32();

                            LogHandler.WriteLine($"DLL Injected at: 0x{hookedDllAddress.ToString("X4")}");
                            LogHandler.WriteLine($"Writting to memory at: 0x{(hookedDllAddress + variableBaseAddress).ToString("X4")} and 0x{(hookedDllAddress + variableBaseAddress + 4).ToString("X4")}");
                            Trainer.WriteInteger(myProcess, hookedDllAddress + variableBaseAddress, ResolutionX);
                            Trainer.WriteInteger(myProcess, hookedDllAddress + variableBaseAddress + 4, ResolutionY);
                            LogHandler.WriteLine($"Written to dllHook: {ResolutionX}x{ResolutionY} at address {(hookedDllAddress + 0x19008).ToString("X4")}");
                        }
                    }
                    System.Threading.Thread.Sleep(threadDelay);
                }
                catch (Exception ex)
                {
                    LogHandler.WriteLine("Exception in GameHack.cs" + ex.ToString());
                }
            }
        }
Пример #7
0
        private void StartGame()
        {
            string cmdlineparamters = File.ReadLines("avp2cmds.txt").FirstOrDefault();

            cmdlineparamters = StripResolutionParameters(cmdlineparamters);

            cmdlineparamters += " ++RenderDll d3d.ren ++CardDesc display";

            if (customConfig.Windowed)
            {
                cmdlineparamters += " +windowed 1";
            }
            else
            {
                cmdlineparamters += " +windowed 0";
            }

            if (customConfig.DisableSound)
            {
                cmdlineparamters += " +DisableSound 1";
            }
            else
            {
                cmdlineparamters += " +DisableSound 0";
            }

            if (customConfig.DisableMusic)
            {
                cmdlineparamters += " +DisableMusic 1";
            }
            else
            {
                cmdlineparamters += " +DisableMusic 0";
            }

            if (customConfig.DisableLogos)
            {
                cmdlineparamters += " +DisableMovies 1";
            }
            else
            {
                cmdlineparamters += " +DisableMovies 0";
            }

            if (customConfig.DisableJoystick)
            {
                cmdlineparamters += " +DisableJoystick 1";
            }
            else
            {
                cmdlineparamters += " +DisableJoystick 0";
            }

            if (customConfig.DisableTrippleBuffering)
            {
                cmdlineparamters += " +EnableTripBuf 0";
            }
            else
            {
                cmdlineparamters += " +EnableTripBuf 1";
            }

            if (customConfig.DisableHardwareCursor)
            {
                cmdlineparamters += " +DisableHardwareCursor 1";
            }
            else
            {
                cmdlineparamters += " +DisableHardwareCursor 0";
            }

            if (customConfig.LithFixEnabled)
            {
                cmdlineparamters += $" -rez lithfix";
            }

            cmdlineparamters += $" {originalParams} {customConfig.CVARS}";


            Thread GameHackThread = new Thread(_gamehack.DoWork);

            if (customConfig.AspectRatioFix)
            {
                _gamehack.SendValues(customConfig.FOV, (int)lithTechConfig.GameScreenWidth, (int)lithTechConfig.GameScreenHeight, customConfig.LithFixEnabled);
                GameHackThread.Start();
            }

            try
            {
                Process gameProcess = new Process();
                gameProcess.StartInfo.FileName  = "Lithtech.exe";
                gameProcess.StartInfo.Arguments = cmdlineparamters;
                gameProcess.EnableRaisingEvents = true;
                this.WindowState = FormWindowState.Minimized;

                gameProcess.Start();
                gameProcess.WaitForExit();
                _gamehack.RequestStop();
                this.Close();
            }
            catch (Exception ex)
            {
                LogHandler.WriteLine("Exception in mainform (gameprocess):" + ex.ToString());
                return;
            }
        }
Пример #8
0
        private void StartGame()
        {
            string cmdlineparamters = File.ReadLines("avp2cmds.txt").FirstOrDefault();

            cmdlineparamters = stripResolutionParameters(cmdlineparamters);

            if (customConfig.Windowed)
            {
                cmdlineparamters += " +windowed 1";
            }
            else
            {
                cmdlineparamters += " +windowed 0";
            }

            if (customConfig.DisableSound)
            {
                cmdlineparamters += " +DisableSound 1";
            }
            else
            {
                cmdlineparamters += " +DisableSound 0";
            }

            if (customConfig.DisableMusic)
            {
                cmdlineparamters += " +DisableMusic 1";
            }
            else
            {
                cmdlineparamters += " +DisableMusic 0";
            }

            if (customConfig.DisableLogos)
            {
                cmdlineparamters += " +DisableMovies 1";
            }
            else
            {
                cmdlineparamters += " +DisableMovies 0";
            }

            if (customConfig.DisableJoystick)
            {
                cmdlineparamters += " +DisableJoystick 1";
            }
            else
            {
                cmdlineparamters += " +DisableJoystick 0";
            }

            if (customConfig.DisableTrippleBuffering)
            {
                cmdlineparamters += " +EnableTripBuf 0";
            }
            else
            {
                cmdlineparamters += " +EnableTripBuf 1";
            }

            if (customConfig.DisableHardwareCursor)
            {
                cmdlineparamters += " +DisableHardwareCursor 1";
            }
            else
            {
                cmdlineparamters += " +DisableHardwareCursor 0";
            }

            if (customConfig.LithFixEnabled)
            {
                cmdlineparamters += " -rez lithfix";
            }

            cmdlineparamters += $" {originalParams} {customConfig.CVARS}";

            LogHandler.WriteLine("Launch parameters are: " + cmdlineparamters);

            Thread GameHackThread = new Thread(_gamehack.DoWork);

            if (customConfig.AspectRatioFix)
            {
                _gamehack.SendValues(customConfig.FOV, (int)lithTechConfig.GameScreenWidth, (int)lithTechConfig.GameScreenHeight, customConfig.LithFixEnabled);
                GameHackThread.Start();
            }

            try
            {
                Process gameProcess = new Process();
                gameProcess.StartInfo.FileName         = Path.Combine(Directory.GetCurrentDirectory(), "Lithtech.exe");
                gameProcess.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
                gameProcess.StartInfo.Arguments        = cmdlineparamters;
                this.WindowState = FormWindowState.Minimized;

                gameProcess.Start();
                gameProcess.WaitForExit();
                _gamehack.RequestStop();
                this.Close();
            }
            catch (Exception ex)
            {
                LogHandler.WriteLine("An error occurred when creating new process: " + ex.Message);
                return;
            }
        }