// // Public members: // // Internal members: internal MainForm() { InitializeComponent(); this.Icon = Program.Icon; this.pictureBoxHelp.Image = SystemIcons.Information.ToBitmap(); this.Text = L10n._p("Window title, args: {0} - version", "Half-Life Advanced Effects {0}", System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion); this.fileToolStripMenuItem.Text = L10n._p("Main window | menu", "File"); this.menuLaunchCSGO.Text = L10n._p("Main window | menu | File", "Launch CS:GO"); this.launchGoldSrcToolStripMenuItem.Text = L10n._p("Main window | menu | File", "Launch GoldSrc"); this.menuExit.Text = L10n._p("Main window | menu | File", "Exit"); this.viewToolStripMenuItem.Text = L10n._p("Main Window | menu", "View"); this.menuStatusBar.Text = L10n._p("Main window | menu | View", "Status Bar"); this.toolsToolStripMenuItem.Text = L10n._p("Main window | menu", "Tools"); this.calculatorsToolStripMenuItem.Text = L10n._p("Main window | menu | Tools", "Calculators"); this.menuFileSize.Text = L10n._p("Main window | menu | Tools | Calculators", "File Size"); this.menuAfxRgbaLut.Text = L10n._p("Main window | menu | Tools", "Color Lookup Tables"); this.menuVoronoi.Text = L10n._p("Main window | menu | Tools | Color Lookup Tables", "Voronoi"); this.goldSrcToolStripMenuItem.Text = L10n._p("Main window | menu | Tools", "GoldSrc"); this.demoToolsToolStripMenuItem.Text = L10n._p("Main window | menu | Tools | GoldSrc", "Demo Tools"); this.skyManagerToolStripMenuItem.Text = L10n._p("Main window | menu | Tools | GoldSrc", "Sky Manager"); this.developerToolStripMenuItem.Text = L10n._p("Main window | menu | Tools", "Developer"); this.menuCustomLoader.Text = L10n._p("Main window | menu | Tools | Developer", "Custom Loader"); this.menuGuidToClipBoard.Text = L10n._p("Main window | menu | Tools | Developer", "Own GUID to ClipBoard"); this.menuNewGuidToClipBoard.Text = L10n._p("Main window | menu | Tools | Developer", "New GUID to ClipBoard"); this.helpToolStripMenuItem.Text = L10n._p("Main window | menu", "Help"); this.checkForUpdatesToolStripMenuItem.Text = L10n._p("Main window | menu | Help", "Check for Updates"); this.menuAutoUpdateCheck.Text = L10n._p("Main window | menu | Help | Check for Updates", "Auto Check"); this.checkNowToolStripMenuItem.Text = L10n._p("Main window | menu | Help | Check for Updates", "Check Now"); this.menuAdvancedFxOrg.Text = L10n._p("Main window | menu | Help", "Official Website"); this.donateToolStripMenuItem.Text = L10n._p("Main window | menu", "Donate"); this.checkUpdatesLabel.Text = L10n._p("Main window | check updates strip", "Check for updates automatically?"); this.statusLabelAutoYes.Text = L10n._p("Main window | check updates strip", "Yes"); this.statusLabelAutoNo.Text = L10n._p("Main window | check updates strip", "No"); this.statusLabelIgnore.Text = L10n._p("Main window | update status strip", "Ignore"); this.statusLabelHide.Text = L10n._p("Main window | update status strip", "OK"); this.statusLabelUpdate.Text = L10n._p("Main window | update status strip | label", "Update status unknown"); this.menuContact.Text = L10n._("Contact / Privacy Policy / Imprint (advancedfx.org)"); this.groupBoxHelp.Text = L10n._("Help"); this.labelHelpLanguage.Text = L10n._("Language:"); this.labelHelpSelection.Text = L10n._("Selection:"); { HelpEntry officialEnglishSupportPage = new HelpEntry(L10n._("Official support page (English)"), "https://www.advancedfx.org/support/"); HelpEntry chinesePage = new HelpEntry(L10n._("HLAE Chinese Station"), "https://hlae.site/"); helpLanguages = new HelpLanguage[] { new HelpLanguage("en", L10n._p("Language", "English (en)"), new HelpEntry[] { officialEnglishSupportPage }), new HelpLanguage("zh-CN", L10n._p("Language", "Chinese (zh-CN)"), new HelpEntry[] { chinesePage }) }; this.comboBoxHelpLanguage.Items.AddRange(helpLanguages); string ietfLanguageTag = System.Globalization.CultureInfo.CurrentUICulture.IetfLanguageTag; string twoLetterIsoLanguageName = System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName; // Select a default language: int selectIndex = -1; int curIndex = 0; foreach (HelpLanguage helpLanguage in helpLanguages) { if (helpLanguage.Code.Equals(ietfLanguageTag)) { selectIndex = curIndex; break; } ++curIndex; } if (selectIndex == -1) { curIndex = 0; foreach (HelpLanguage helpLanguage in helpLanguages) { if (helpLanguage.Code.Equals(twoLetterIsoLanguageName)) { selectIndex = curIndex; break; } ++curIndex; } } if (selectIndex == -1 && 0 < helpLanguages.Length) { selectIndex = 0; } if (selectIndex != -1) { comboBoxHelpLanguage.SelectedIndex = selectIndex; } } m_UpdateCheckNotification = new UpdateCheckNotificationTarget(this, new UpdateCheckedDelegate(OnUpdateChecked)); }
// // Public members: // // Internal members: internal MainForm() { InitializeComponent(); this.Icon = Program.Icon; this.pictureBoxHelp.Image = SystemIcons.Information.ToBitmap(); this.Text = L10n._p("Main window", "Half-Life Advanced Effects"); this.fileToolStripMenuItem.Text = L10n._p("Main window | menu", "File"); this.menuLaunchCSGO.Text = L10n._p("Main window | menu | File", "Launch CS:GO"); this.launchGoldSrcToolStripMenuItem.Text = L10n._p("Main window | menu | File", "Launch GoldSrc"); this.menuExit.Text = L10n._p("Main window | menu | File", "Exit"); this.viewToolStripMenuItem.Text = L10n._p("Main Window | menu", "View"); this.menuStatusBar.Text = L10n._p("Main window | menu | View", "Status Bar"); this.toolsToolStripMenuItem.Text = L10n._p("Main window | menu", "Tools"); this.calculatorsToolStripMenuItem.Text = L10n._p("Main window | menu | Tools", "Calculators"); this.menuFileSize.Text = L10n._p("Main window | menu | Tools | Calculators", "File Size"); this.goldSrcToolStripMenuItem.Text = L10n._p("Main window | menu | Tools", "GoldSrc"); this.demoToolsToolStripMenuItem.Text = L10n._p("Main window | menu | Tools | GoldSrc", "Demo Tools"); this.skyManagerToolStripMenuItem.Text = L10n._p("Main window | menu | Tools | GoldSrc", "Sky Manager"); this.developerToolStripMenuItem.Text = L10n._p("Main window | menu | Tools", "Developer"); this.menuCustomLoader.Text = L10n._p("Main window | menu | Tools | Developer", "Custom Loader"); this.menuGuidToClipBoard.Text = L10n._p("Main window | menu | Tools | Developer", "Own GUID to ClipBoard"); this.menuNewGuidToClipBoard.Text = L10n._p("Main window | menu | Tools | Developer", "New GUID to ClipBoard"); this.helpToolStripMenuItem.Text = L10n._p("Main window | menu", "Help"); this.checkForUpdatesToolStripMenuItem.Text = L10n._p("Main window | menu | Help", "Check for Updates"); this.menuAutoUpdateCheck.Text = L10n._p("Main window | menu | Help | Check for Updates", "Auto Check"); this.checkNowToolStripMenuItem.Text = L10n._p("Main window | menu | Help | Check for Updates", "Check Now"); this.menuAdvancedFxOrg.Text = L10n._p("Main window | menu | Help", "Official Website"); this.donateToolStripMenuItem.Text = L10n._p("Main window | menu", "Donate"); this.checkUpdatesLabel.Text = L10n._p("Main window | check updates strip", "Check for updates automatically?"); this.statusLabelAutoYes.Text = L10n._p("Main window | check updates strip", "Yes"); this.statusLabelAutoNo.Text = L10n._p("Main window | check updates strip", "No"); this.statusLabelIgnore.Text = L10n._p("Main window | update status strip", "Ignore"); this.statusLabelHide.Text = L10n._p("Main window | update status strip", "OK"); this.statusLabelUpdate.Text = L10n._p("Main window | update status strip | label", "Update status unknown"); this.groupBoxHelp.Text = L10n._("Help"); this.labelHelpLanguage.Text = L10n._("Language:"); this.labelHelpSelection.Text = L10n._("Selection:"); { HelpEntry officialEnglishSupportPage = new HelpEntry(L10n._("Official support page (English)"), "https://www.advancedfx.org/support/"); helpLanguages = new HelpLanguage[] { new HelpLanguage("en", L10n._p("Language", "English"), new HelpEntry[] { officialEnglishSupportPage }) }; this.comboBoxHelpLanguage.Items.AddRange(helpLanguages); string ietfLanguageTagPath = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "locales", System.Globalization.CultureInfo.CurrentUICulture.IetfLanguageTag, "hlae", "messages.mo"); string twoLetterIsoLanguageNamPath = System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "locales", System.Globalization.CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, "hlae", "messages.mo"); // Select a default language: int selectIndex = -1; int curIndex = 0; foreach (HelpLanguage helpLanguage in helpLanguages) { if (helpLanguage.Code.Equals(ietfLanguageTagPath)) { selectIndex = curIndex; break; } ++curIndex; } if (selectIndex == -1) { foreach (HelpLanguage helpLanguage in helpLanguages) { if (helpLanguage.Code.Equals(twoLetterIsoLanguageNamPath)) { selectIndex = curIndex; break; } ++curIndex; } } if (selectIndex == -1 && 0 < helpLanguages.Length) { selectIndex = 0; } if (selectIndex != -1) { comboBoxHelpLanguage.SelectedIndex = selectIndex; } } m_UpdateCheckNotification = new UpdateCheckNotificationTarget(this, new UpdateCheckedDelegate(OnUpdateChecked)); }
public static bool Load(IEnumerable <GetHookPathDelegate> getHookPathCollection, string programPath, string cmdLine, string environment = null, bool showErrorMessage = true) { try { string programOptions = "\"" + programPath + "\" " + cmdLine; string programDirectory = System.IO.Path.GetDirectoryName(programPath); PROCESS_INFORMATION processInfo = new PROCESS_INFORMATION(); STARTUPINFOW startupInfo = new STARTUPINFOW(); startupInfo.cb = (UInt32)Marshal.SizeOf(startupInfo); if (!CreateProcessW( programPath , programOptions , null , null , true // inherit handles , //CREATE_DEFAULT_ERROR_MODE| CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS | CREATE_SUSPENDED //DEBUG_ONLY_THIS_PROCESS| //DEBUG_PROCESS // we want to catch debug event's (sadly also of childs) | CREATE_UNICODE_ENVIRONMENT , environment , programDirectory , ref startupInfo , out processInfo) ) { throw HlaeErrors.LoaderCreateProcessException(Marshal.GetLastWin32Error()); } try { bool isProcess64Bit = IsProcess64Bit(processInfo.hProcess); foreach (GetHookPathDelegate getHookPath in getHookPathCollection) { string hookPath = getHookPath(isProcess64Bit); using (System.Diagnostics.Process injector = new System.Diagnostics.Process()) { injector.StartInfo.UseShellExecute = false; injector.StartInfo.FileName = System.AppDomain.CurrentDomain.BaseDirectory + (isProcess64Bit ? "\\x64" : "") + "\\injector.exe"; injector.StartInfo.CreateNoWindow = true; injector.StartInfo.RedirectStandardInput = true; injector.StartInfo.RedirectStandardOutput = true; try { injector.Start(); } catch (Exception e) { throw HlaeErrors.InjectorStartException( injector.StartInfo.FileName, e ); } AfxError error = null; IFormatter formatter = new advancedfx.injector.interop.Formatter(); using (Stream injectorIn = injector.StandardInput.BaseStream) { using (Stream injectorOut = injector.StandardOutput.BaseStream) { advancedfx.injector.interop.InjectMessage injectMessage = new advancedfx.injector.interop.InjectMessage(); injectMessage.ProcessId = processInfo.dwProcessId; injectMessage.DllPath = hookPath; formatter.Serialize(injectorIn, injectMessage); injectorIn.Flush(); bool injectorExit = false; while (!injectorExit) { advancedfx.injector.interop.ProcessMessage m = (advancedfx.injector.interop.ProcessMessage)formatter.Deserialize(injectorOut); switch (m) { case advancedfx.injector.interop.ExceptionError exceptionError: if (null == error) { error = HlaeErrors.Unknown; } break; case advancedfx.injector.interop.OpenProcessError openProcessError: if (null == error) { error = HlaeErrors.OpenProcessFailed; } break; case advancedfx.injector.interop.VirtualAllocExArgDllDirError virtualAllocExArgDllDirError: if (null == error) { error = HlaeErrors.VirtualAllocExReadWriteFailed; } break; case advancedfx.injector.interop.VirtualAllocExArgDllFilePathError virtualAllocExArgDllFilePathError: if (null == error) { error = HlaeErrors.VirtualAllocExReadWriteFailed; } break; case advancedfx.injector.interop.GetImageError getImageError: if (null == error) { error = HlaeErrors.GetImageFailed; } break; case advancedfx.injector.interop.VirtualAllocExImageError virtualAllocExImageError: if (null == error) { error = HlaeErrors.VirtualAllocExReadWriteExecuteFailed; } break; case advancedfx.injector.interop.WriteProcessMemoryArgDllDirError writeProcessMemoryArgDllDirError: if (null == error) { error = HlaeErrors.WriteProcessMemoryFailed; } break; case advancedfx.injector.interop.WriteProcessMemoryArgDllFilePathError writeProcessMemoryArgDllFilePathError: if (null == error) { error = HlaeErrors.WriteProcessMemoryFailed; } break; case advancedfx.injector.interop.WriteProcessMemoryImageError writeProcessMemoryImageError: if (null == error) { error = HlaeErrors.WriteProcessMemoryFailed; } break; case advancedfx.injector.interop.FlushInstructionCacheError flushInstructionCacheError: if (null == error) { error = HlaeErrors.FlushInstructionCacheFailed; } break; case advancedfx.injector.interop.CreateRemoteThreadError createRemoteThreadError: if (null == error) { error = HlaeErrors.CreateRemoteThreadFailed; } break; case advancedfx.injector.interop.ContinueWaitingQuestion contineWaitingQuestion: { advancedfx.injector.interop.ContinueWaiting r = new advancedfx.injector.interop.ContinueWaiting(); r.Response = DialogResult.Yes == MessageBox.Show(L10n._("Image injection problem.\nContinue waiting?"), L10n._("injector Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning); formatter.Serialize(injectorIn, r); injectorIn.Flush(); } break; case advancedfx.injector.interop.TerminateThreadError terminateThreadError: // ignore for now break; case advancedfx.injector.interop.GetExitCodeThreadError getExitCodeThreadError: // ignore for now break; case advancedfx.injector.interop.InvalidExitCodeError invalidExitCodeError: if (null == error) { error = InjectorErrors.AfxHookUnknown; } break; case advancedfx.injector.interop.KnownExitCodeError knownExitCodeError: if (null == error) { error = InjectorErrors.Instance.GetById((int)knownExitCodeError.ThreadExitCode); } break; case advancedfx.injector.interop.CloseHandleThreadError closeHandleError: // ignore for now break; case advancedfx.injector.interop.VirtualFreeExImageError virtualFreeExImageError: // ignore for now break; case advancedfx.injector.interop.VirtualFreeExArgFilePathError virtualFreeExArgFilePathError: // ignore for now break; case advancedfx.injector.interop.VirtualFreeExArgDllDirError virtualFreeExArgDllDirError: // ignore for now break; case advancedfx.injector.interop.CloseHandleProcessError closeHandleProcessError: // ignore for now break; case advancedfx.injector.interop.InjectResponse injectResponse: bool injectorOk = injectResponse.Response; injector.WaitForExit(); if (!injectorOk) { throw null == error ? HlaeErrors.Unknown : error; } injectorExit = true; break; default: throw HlaeErrors.Unknown; } } } } } } } finally { System.Threading.Thread.Sleep(2000); ResumeThread(processInfo.hThread); CloseHandle(processInfo.hThread); CloseHandle(processInfo.hProcess); } } catch (AfxError e) { if (showErrorMessage) { using (ErrorDialogue frm = new ErrorDialogue()) { frm.Error = e; frm.ShowDialog(); } } return(false); } catch (Exception e) { if (showErrorMessage) { using (ErrorDialogue frm = new ErrorDialogue()) { frm.Error = HlaeErrors.LoaderException(e); frm.ShowDialog(); } } return(false); } return(true); }