public SearchReadCodeDialog() { InitializeComponent(); PrimaryButtonClick += (_, _) => { // Condition here cause "Enter" key will cross this if (IsPrimaryButtonEnabled) { Textractor.SearchRCode(JapaneseText.Text); } }; Closing += (_, args) => { // If the PrimaryButton is disabled, block the "Enter" key if (args.Result == ContentDialogResult.Primary && !IsPrimaryButtonEnabled) { args.Cancel = true; } }; }
public HookConfigViewModel(IHookConfigDataService dataService) { _dataService = dataService; HookMapData = _dataService.GetHookMapData(); if (IsInDesignMode) { InputCode = "/HS-10@21967:NUKITASHI2.EXE"; Regexp = @"[\x00-\xFF]"; SelectedText = "悠真くんを攻略すれば210円か。なるほどなぁ…"; ConsoleOutput = "Textractor inject kirikiri\n" + "Textractor inject SiglusEngine\n" + "Textractor inject Cs2"; } else { // initialize InsertCodeCommand = new RelayCommand(() => Textractor.InsertHook(InputCode), CanInsertCode); SelectedHookChangeCommand = new RelayCommand(SelectedHookChangeHandle); SubmitCommand = new RelayCommand(SubmitMessage, CanSubmitMessage); if (File.Exists(SimpleIoc.Default.GetInstance <GameInfo>().ConfigPath)) { Regexp = EHConfig.GetValue(EHNode.Regexp); } Textractor.DataEvent += DataRecvEventHandler; Task.Run(async() => { SearchedCode = await QueryHCodeApi.QueryCode(SimpleIoc.Default.GetInstance <GameInfo>().MD5); if (SearchedCode != "") { log.Info($"Find code {SearchedCode} in Aniclan"); } }); } }
public async void Inject(object procItems) // Suger by CM { if (SelectedProcItem.proc.HasExited) { await new ContentDialog { Title = "Eroge Helper", Content = "Process has gone.", CloseButtonText = "OK" }.ShowAsync().ConfigureAwait(false); ProcItems.Remove(SelectedProcItem); } else { // 🧀 MatchProcess.Collect(SelectedProcItem.proc.ProcessName); // Cheak if there is eh.config file var configPath = SelectedProcItem.proc.MainModule !.FileName + ".eh.config"; if (File.Exists(configPath)) { GameConfig.Load(configPath); log.Info($"Get HCode {GameConfig.HookCode} from file {SelectedProcItem.proc.ProcessName}.exe.eh.config"); // Display text window await windowManager.ShowWindowAsync(IoC.Get <GameViewModel>()).ConfigureAwait(false); } else { log.Info("Not find xml config file, open hook panel."); await windowManager.ShowWindowAsync(IoC.Get <HookConfigViewModel>()).ConfigureAwait(false); } await TryCloseAsync().ConfigureAwait(false); Textractor.Init(); GameHooker.Init(); } }
/// <summary> /// Entry Point /// </summary> protected override async void OnStartup(object sender, System.Windows.StartupEventArgs e) { Log.Info("Started Logging"); if (e.Args.Length == 0) { // Display select processes window await DisplayRootViewFor <SelectProcessViewModel>(); } else { // Startup by shell menu var gamePath = e.Args[0]; var gameDir = gamePath.Substring(0, gamePath.LastIndexOf('\\')); Log.Info($"Game's path: {e.Args[0]}"); Log.Info($"Locate Emulator status: {e.Args.Contains("/le")}"); if (e.Args.Contains("/le")) { // Use Locate Emulator Process.Start(new ProcessStartInfo { FileName = Directory.GetCurrentDirectory() + @"\libs\x86\LEProc.exe", UseShellExecute = false, Arguments = File.Exists(gamePath + ".le.config") ? $"-run \"{gamePath}\"" : $"\"{gamePath}\"" }); // XXX: LE may throw AccessViolationException which can not be catched } else { // Direct start Process.Start(new ProcessStartInfo { FileName = gamePath, UseShellExecute = false, WorkingDirectory = gameDir }); } // 🧀 var findResult = MatchProcess.Collect(Path.GetFileNameWithoutExtension(gamePath)); if (findResult != true) { MessageBox.Show($"{Language.Strings.MessageBox_TimeoutInfo}", "Eroge Helper"); return; } // Cheak if there is eh.config file if (File.Exists(gamePath + ".eh.config")) { GameConfig.Load(gamePath + ".eh.config"); Log.Info($"Get HCode {GameConfig.HookCode} from file " + $"{Path.GetFileNameWithoutExtension(gamePath)}.exe.eh.config"); // Display text window await Container.Resolve <IWindowManager>().ShowWindowAsync(Container.Resolve <GameViewModel>(), "InsideView"); } else { Log.Info("Not find xml config file, open hook panel."); await DisplayRootViewFor <HookConfigViewModel>(); } Textractor.Init(); GameHooker.Init(); } }
public void InsertCode(object inputCode) => Textractor.InsertHook(InputCode);
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); var currentDirectory = Path.GetDirectoryName(GetType().Assembly.Location); Directory.SetCurrentDirectory(currentDirectory); Utils.AddEnvironmentPaths((currentDirectory + @"\libs").Split()); DispatcherHelper.Initialize(); SimpleIoc.Default.Register <GameInfo>(); SimpleIoc.Default.Register <AppSetting>(); //new TaskbarView(); notifyIcon = (TaskbarIcon)FindResource("NotifyIcon"); log4net.Config.XmlConfigurator.Configure(); // AppDomain.CurrentDomain.UnhandledException += GlobalErrorHandle 非ui线程 DispatcherUnhandledException += (s, eventArgs) => { log.Error(eventArgs.Exception); MessageBox.Show(eventArgs.Exception.ToString(), "Eroge Helper"); // TODO: 复制粘贴板转到github. Friendly error message }; log.Info("Started Logging"); log.Info($"Enviroment directory: {Directory.GetCurrentDirectory()}"); if (e.Args.Length == 0) { MessageBox.Show("请使用 EHInstaller 安装我> < \n\r" + "如果你已经安装了直接右键游戏选择Eroge Helper启动就好了~", "ErogeHelper"); Current.Shutdown(); return; } GameInfo gameInfo = SimpleIoc.Default.GetInstance(typeof(GameInfo)) as GameInfo; gameInfo.Path = e.Args[0]; gameInfo.ConfigPath = gameInfo.Path + ".eh.config"; gameInfo.Dir = gameInfo.Path.Substring(0, gameInfo.Path.LastIndexOf('\\')); gameInfo.ProcessName = Path.GetFileNameWithoutExtension(gameInfo.Path); gameInfo.MD5 = Utils.GetMD5(gameInfo.Path); log.Info($"Game's path: {e.Args[0]}"); log.Info($"Locate Emulator statu: {e.Args.Contains("/le")}"); if (e.Args.Contains("/le")) { // Use Locate Emulator try { Process.Start(new ProcessStartInfo { FileName = Directory.GetCurrentDirectory() + @"\libs\x86\LEProc.exe", UseShellExecute = false, Arguments = File.Exists(gameInfo.Path + ".le.config") ? $"-run \"{gameInfo.Path}\"" : $"\"{gameInfo.Path}\"" }); } // XXX: 捕获不到,7秒超时 catch (AccessViolationException) { throw new AccessViolationException("LE执行出现内存错误,这可能是游戏进程还未退出,问题不大请重新尝试用LE启动游戏~"); } } else { // Direct start Process.Start(new ProcessStartInfo { FileName = gameInfo.Path, UseShellExecute = false, WorkingDirectory = gameInfo.Dir }); } bool newProcFind; // Pid标记 List <int> procMark = new List <int>(); // tmpProcList 每次循环 Process.GetProcessesByName() 命中的进程 List <Process> tmpProcList = new List <Process>(); var totalTime = new Stopwatch(); totalTime.Start(); do { newProcFind = false; gameInfo.ProcList.Clear(); tmpProcList.Clear(); #region Collect Processes To tmpProcList foreach (Process p in Process.GetProcessesByName(gameInfo.ProcessName)) { tmpProcList.Add(p); } foreach (Process p in Process.GetProcessesByName(gameInfo.ProcessName + ".log")) { tmpProcList.Add(p); } #endregion foreach (Process p in tmpProcList) { gameInfo.ProcList.Add(p); if (!procMark.Contains(p.Id)) { procMark.Add(p.Id); try { if (p.WaitForInputIdle(500) == false) // 500 延迟随意写的,正常启动一般在100~200范围 { log.Info($"Procces {p.Id} maybe stuck"); } } catch (InvalidOperationException ex) { // skip no effect exception // This occurrent because process has no window event log.Warn(ex.Message); } newProcFind = true; } } // 进程找完却没有得到hWnd的可能也是存在的,所以以带hWnd的进程为主 gameInfo.HWndProc = Utils.FindHWndProc(gameInfo.ProcList); // timeout if (totalTime.Elapsed.TotalSeconds > 7 && gameInfo.HWndProc == null) { log.Info("Timeout! Find MainWindowHandle Faied"); MessageBox.Show("(超时)没能找到游戏窗口!", "ErogeHelper"); Current.Shutdown(); return; } } while (newProcFind || (gameInfo.HWndProc == null)); totalTime.Stop(); log.Info($"{gameInfo.ProcList.Count} Process(es) and window handle 0x{Convert.ToString(gameInfo.HWndProc.MainWindowHandle.ToInt64(), 16).ToUpper()} Found. Spend time {totalTime.Elapsed.TotalSeconds:0:00}s"); // Cheak if there is eh.config file if (File.Exists(gameInfo.ConfigPath)) { gameInfo.HookCode = EHConfig.GetValue(EHNode.HookCode); gameInfo.ThreadContext = long.Parse(EHConfig.GetValue(EHNode.ThreadContext)); gameInfo.SubThreadContext = long.Parse(EHConfig.GetValue(EHNode.SubThreadContext)); gameInfo.Regexp = EHConfig.GetValue(EHNode.Regexp); log.Info($"Get HCode {gameInfo.HookCode} from file {gameInfo.ProcessName}.exe.eh.config"); // Display text window new GameView().Show(); } else { log.Info("Not find xml config file, open hook panel."); new HookConfigView().Show(); } Textractor.Init(); }