Skip to content

Commit

Permalink
将选取hook方法的剪贴板监视按钮外置到主界面,修改其为链接定向到子项目,修改Hook模块整体逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
hanmin0822 committed May 26, 2020
1 parent 9d740ee commit ac0608e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 deletions.
31 changes: 26 additions & 5 deletions MisakaTranslator-WPF/GameGuideWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public GameGuideWindow(int Mode)
FuncHint.Text = Application.Current.Resources["GameGuideWin_FuncHint_OCR"].ToString();
GuidePageFrame.Navigate(new Uri("GuidePages/OCR/ChooseOCRAreaPage.xaml", UriKind.Relative));
}
else if(Mode == 3)
else if (Mode == 3)
{
//重新选择Hook方法
List<string> lstStep = new List<string>() {
List<string> lstStep = new List<string>() {
Application.Current.Resources["GameGuideWin_ReHook_Step_1"].ToString(),
Application.Current.Resources["GameGuideWin_Step_5"].ToString()
};
Expand All @@ -70,6 +70,18 @@ public GameGuideWindow(int Mode)
FuncHint.Text = Application.Current.Resources["GameGuideWin_FuncHint_ReHook"].ToString();
GuidePageFrame.Navigate(new Uri("GuidePages/Hook/ReChooseHookFuncPage.xaml", UriKind.Relative));
}
else if (Mode == 4) {
//剪贴板监控
List<string> lstStep = new List<string>() {
Application.Current.Resources["GameGuideWin_Hook_Step_3"].ToString(),
Application.Current.Resources["GameGuideWin_Step_4"].ToString(),
Application.Current.Resources["GameGuideWin_Step_5"].ToString()
};

GuideStepBar.ItemsSource = lstStep;
FuncHint.Text = Application.Current.Resources["GameGuideWin_FuncHint_ClipBoard"].ToString();
GuidePageFrame.Navigate(new Uri("GuidePages/Hook/ChooseTextRepairFuncPage.xaml", UriKind.Relative));
}
}

/// <summary>
Expand All @@ -87,8 +99,8 @@ private void Next_Click(object sender, RoutedEventArgs e) {
//Hook方式设置 完成
Common.transMode = 1;
TranslateWindow translateWindow = new TranslateWindow();
translateWindow.Show();
translateWindow.Show();

this.Close();
}
else if (GuideMode == 2)
Expand All @@ -100,7 +112,7 @@ private void Next_Click(object sender, RoutedEventArgs e) {

this.Close();
}
else if(GuideMode == 3)
else if (GuideMode == 3)
{
//Hook方式设置 完成
Common.transMode = 1;
Expand All @@ -109,6 +121,15 @@ private void Next_Click(object sender, RoutedEventArgs e) {

this.Close();
}
else if (GuideMode == 4)
{
//剪贴板监控方式设置 完成
Common.transMode = 1;
TranslateWindow translateWindow = new TranslateWindow();
translateWindow.Show();

this.Close();
}
}
else {
//其他情况就跳转指定页面
Expand Down
6 changes: 5 additions & 1 deletion MisakaTranslator-WPF/GuidePages/Hook/ChooseHookFuncPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
<StackPanel Grid.Row="2" Orientation="Horizontal">
<Button HorizontalAlignment="Left" Margin="10" Content="{StaticResource ChooseHookFuncPage_BtnAddHook}" Click="AddHookBtn_Click"/>

<Button HorizontalAlignment="Left" Margin="10" Content="{StaticResource ChooseHookFuncPage_BtnAddClipboardFunc}" Click="AddClipBoardFuncBtn_Click"/>
<TextBlock Margin="10" VerticalAlignment="Center">
<Hyperlink Click="CannotfindHookBtn_Click">
<TextBlock Text="{StaticResource ChooseHookFuncPage_BtnCannotfindHook}"/>
</Hyperlink>
</TextBlock>
</StackPanel>

<Button Grid.Row="2" HorizontalAlignment="Right" Margin="10" Content="{StaticResource ChooseHookFuncPage_BtnConfirm}" Width="205" Click="ConfirmBtn_Click"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ private void Page_KeyDown(object sender, KeyEventArgs e)

}

private void AddClipBoardFuncBtn_Click(object sender, RoutedEventArgs e)
private void CannotfindHookBtn_Click(object sender, RoutedEventArgs e)
{
Common.textHooker.AddClipBoardThread(new System.Windows.Interop.WindowInteropHelper(Common.mainWin).Handle);
System.Diagnostics.Process.Start("https://github.com/hanmin0822/MisakaHookFinder");
}
}
}
3 changes: 2 additions & 1 deletion MisakaTranslator-WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
<hc:ButtonGroup Orientation="Horizontal">
<Button Background="{DynamicResource BoxBtnColor}" Content="{StaticResource BtnHookGuide}" Click="HookGuideBtn_Click" Height="50"></Button>
<Button Background="{DynamicResource BoxBtnColor}" Content="{StaticResource BtnOCRGuide}" Click="OCRGuideBtn_Click" Height="50"></Button>
</hc:ButtonGroup>
<Button Background="{DynamicResource BoxBtnColor}" Content="{StaticResource BtnClipboardGuide}" Click="ClipboardGuideBtn_Click" Height="50"></Button>
</hc:ButtonGroup>
</Border>
</StackPanel>

Expand Down
15 changes: 15 additions & 0 deletions MisakaTranslator-WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -460,5 +460,20 @@ private int GetGameListHasProcessGame_PID_ID()
}
return -1;
}

private void ClipboardGuideBtn_Click(object sender, RoutedEventArgs e)
{
Common.textHooker = new TextHookHandle();
Common.transMode = 1;
Common.textHooker.Init();
Common.textHooker.AddClipBoardThread(new System.Windows.Interop.WindowInteropHelper(Common.mainWin).Handle);

//剪贴板方式读取的特殊码和misakacode
Common.textHooker.HookCodeList.Add("HB0@0");
Common.textHooker.MisakaCodeList.Add("【0:-1:-1】");

var ggw = new GameGuideWindow(4);
ggw.Show();
}
}
}
6 changes: 4 additions & 2 deletions MisakaTranslator-WPF/lang/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<sys:String x:Key="BtnStart">Start translation</sys:String>
<sys:String x:Key="BtnHookGuide">Translate through hook Wizard</sys:String>
<sys:String x:Key="BtnOCRGuide">Translate through OCR Wizard</sys:String>
<sys:String x:Key="BtnClipboardGuide">Translate through ClipBoard</sys:String>

<sys:String x:Key="MainWindow_ScrollViewer_AddNewGame">New game</sys:String>

Expand Down Expand Up @@ -145,6 +146,7 @@
<sys:String x:Key="GameGuideWin_FuncHint_Hook">Extract Texts with TextHook</sys:String>
<sys:String x:Key="GameGuideWin_FuncHint_ReHook">Re-select the hook method to match the previous settings</sys:String>
<sys:String x:Key="GameGuideWin_FuncHint_OCR">Extract Texts with OCR</sys:String>
<sys:String x:Key="GameGuideWin_FuncHint_ClipBoard">Extract Texts with ClipBoard</sys:String>

<sys:String x:Key="ChooseGamePage_Introduce">Note: Run the game first, then come back and select the game process from the drop-down list. If the game has multiple processes, choose "Enable smart hook" in the Hook Settings.</sys:String>
<sys:String x:Key="ChooseGamePage_BtnChooseWin">Select a window</sys:String>
Expand Down Expand Up @@ -264,8 +266,8 @@

<sys:String x:Key="ChooseHookFuncPage_MBOX_hookcodeConfirm_left">MisakaTranslator has detected that you have input custom H-code behavior. The last H-code recorded is</sys:String>
<sys:String x:Key="ChooseHookFuncPage_MBOX_hookcodeConfirm_right">If you confirm that this H-code can get text, please select "Yes"; if it can't, select "No" to re-inject a custom H-code; if you do not need a custom H-code, please select "Cancel" to enter the next interface.</sys:String>
<sys:String x:Key="ChooseHookFuncPage_BtnAddClipboardFunc">Add clipboard monitoring method</sys:String>

<sys:String x:Key="ChooseHookFuncPage_BtnCannotfindHook">Can not find correct Hook?</sys:String>
<sys:String x:Key="App_Global_ErrorHint_left">MisakaTranslator encountered an exception that cannot be resolved. It is about to exit. Details about this exception have been stored in the "</sys:String>
<sys:String x:Key="App_Global_ErrorHint_right">" file in the "logs" Directory. To better the Translator, sending these files to the developer on GitHub to troubleshoot is appreciated.</sys:String>

Expand Down
6 changes: 5 additions & 1 deletion MisakaTranslator-WPF/lang/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<sys:String x:Key="BtnStart">开始翻译</sys:String>
<sys:String x:Key="BtnHookGuide">Hook方式游戏向导</sys:String>
<sys:String x:Key="BtnOCRGuide">OCR方式游戏向导</sys:String>
<sys:String x:Key="BtnClipboardGuide">剪贴板监控向导</sys:String>

<sys:String x:Key="MainWindow_ScrollViewer_AddNewGame">添加游戏</sys:String>

Expand Down Expand Up @@ -143,6 +144,7 @@
<sys:String x:Key="GameGuideWin_FuncHint_Hook">使用TextHook方式提取文本</sys:String>
<sys:String x:Key="GameGuideWin_FuncHint_ReHook">重新选择Hook方法以适配上次的设置</sys:String>
<sys:String x:Key="GameGuideWin_FuncHint_OCR">使用OCR方式提取文本</sys:String>
<sys:String x:Key="GameGuideWin_FuncHint_ClipBoard">使用剪贴板监控方式提取文本</sys:String>

<sys:String x:Key="ChooseGamePage_Introduce">说明:请先运行游戏,之后通过下拉列表选择游戏进程名。部分游戏可能存在多进程,请根据需要开启"智能注入"功能。</sys:String>
<sys:String x:Key="ChooseGamePage_BtnChooseWin">选择窗口</sys:String>
Expand Down Expand Up @@ -263,7 +265,9 @@

<sys:String x:Key="ChooseHookFuncPage_MBOX_hookcodeConfirm_left">MisakaTranslator检测到您有自定义特殊码行为,记录最后一个特殊码为</sys:String>
<sys:String x:Key="ChooseHookFuncPage_MBOX_hookcodeConfirm_right">如果您确认这个特殊码可以得到文本,请选择是;如果此特殊码不是您想要的结果,您可以选择否来重新注入一个自定义特殊码;如果您不需要自定义特殊码,请选择取消来进入下一个界面。</sys:String>
<sys:String x:Key="ChooseHookFuncPage_BtnAddClipboardFunc">添加剪贴板监视方法</sys:String>
<sys:String x:Key="ChooseHookFuncPage_BtnCannotfindHook">找不到正确的Hook方法?</sys:String>



<sys:String x:Key="App_Global_ErrorHint_left">MisakaTranslator发现了全局无法解决的异常,即将强制退出。关于本次异常的详细信息已经存储在logs目录下的</sys:String>
<sys:String x:Key="App_Global_ErrorHint_right">文件中,为了更好地维护本软件,我们希望您能将此文件发送给作者以修复这个问题。</sys:String>
Expand Down
19 changes: 18 additions & 1 deletion TextHookLibrary/TextHookHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class TextHookHandle


private Dictionary<Process, bool> PossibleGameProcessList;//与gamePID进程同名的进程列表
private int HandleMode;//处理的方式 1=已确定的单个进程 2=多个进程寻找能搜到文本的进程
private int HandleMode;//处理的方式 1=已确定的单个进程 2=多个进程寻找能搜到文本的进程 3=剪贴板监控
private Process MaxMemoryProcess;//最大内存进程,用于智能处理时单独注入这个进程而不是PossibleGameProcessList中的每个进程都注入

private int listIndex;//用于Hook功能选择界面的方法序号
Expand Down Expand Up @@ -137,6 +137,23 @@ public TextHookHandle(List<Process> GameProcessList)
ThreadID_RenewNum_List = new Dictionary<long, int>();
}

public TextHookHandle() {
//剪贴板方式读取专用
MisakaCodeList = new List<string>();
HookCodeList = new List<string>();
MaxMemoryProcess = null;
GamePID = -1;
PossibleGameProcessList = null;
TextractorOutPutHistory = new Queue<string>(2000);
HandleMode = 3;
listIndex = 0;
listIndex_Re = 0;
TextractorFun_Index_List = new Dictionary<long, int>();
TextractorFun_Re_Index_List = new Dictionary<long, int>();
ThreadID_HookDataInfo_List = new Dictionary<long, TextHookData>();
ThreadID_RenewNum_List = new Dictionary<long, int>();
}

/// <summary>
/// 结束时自动卸载所有Hook,调用方法即令此对象为null然后立即GC回收
/// </summary>
Expand Down

0 comments on commit ac0608e

Please sign in to comment.