mirror of
https://github.com/HIllya51/LunaHook.git
synced 2024-11-27 15:54:03 +08:00
refactor
This commit is contained in:
parent
05589b9ad4
commit
bf9a4f6320
@ -101,7 +101,11 @@ void LunaHost::on_proc_connect(DWORD pid)
|
||||
autoattachexes.insert(WideStringToString(pexe.value()));
|
||||
}
|
||||
}
|
||||
|
||||
TextThread* LunaHost::getcurrthread(){
|
||||
auto handle = g_hListBox_listtext->getdata(g_hListBox_listtext->currentidx());
|
||||
auto tt=Host::GetThread(handle);
|
||||
return tt;
|
||||
}
|
||||
LunaHost::LunaHost(){
|
||||
|
||||
configs=new confighelper;
|
||||
@ -170,63 +174,33 @@ LunaHost::LunaHost(){
|
||||
g_showtexts->settext(get);
|
||||
g_showtexts->scrolltoend();
|
||||
};
|
||||
g_hListBox_listtext->add_menu(MenuCopyHookCode,[&](){if(auto tt=getcurrthread())toclipboard(std::wstring(tt->hp.hookcode));});
|
||||
|
||||
#define IDM_REMOVE_HOOK 1001
|
||||
#define IDM_DETACH_PROCESS 1002
|
||||
#define IDM_COPY_HOOKCODE 1003
|
||||
#define IDM_REMEMBER_SELECTION 1004
|
||||
#define IDM_FORGET_SELECTION 1005
|
||||
g_hListBox_listtext->oncontextmenu=[](){
|
||||
HMENU hMenu = CreatePopupMenu();
|
||||
AppendMenu(hMenu, MF_STRING, IDM_COPY_HOOKCODE, MenuCopyHookCode);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_REMOVE_HOOK, MenuRemoveHook);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_DETACH_PROCESS, MenuDetachProcess);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_REMEMBER_SELECTION, MenuRemeberSelect);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_FORGET_SELECTION, MenuForgetSelect);
|
||||
return hMenu;
|
||||
};
|
||||
g_hListBox_listtext->oncontextmenucallback=[&](WPARAM wparam){
|
||||
g_hListBox_listtext->add_menu_sep();
|
||||
g_hListBox_listtext->add_menu(MenuRemoveHook,[&](){if(auto tt=getcurrthread())Host::RemoveHook(tt->tp.processId,tt->tp.addr);});
|
||||
|
||||
auto handle = g_hListBox_listtext->getdata(g_hListBox_listtext->currentidx());
|
||||
auto tt=Host::GetThread(handle);
|
||||
if(tt==0)return;
|
||||
switch (LOWORD(wparam)) {
|
||||
|
||||
case IDM_COPY_HOOKCODE:
|
||||
toclipboard(std::wstring(tt->hp.hookcode));
|
||||
break;
|
||||
case IDM_DETACH_PROCESS:
|
||||
g_hListBox_listtext->add_menu(MenuDetachProcess,[&](){
|
||||
if(auto tt=getcurrthread()){
|
||||
Host::DetachProcess(tt->tp.processId);
|
||||
userdetachedpids.insert(tt->tp.processId);
|
||||
break;
|
||||
case IDM_REMOVE_HOOK:
|
||||
Host::RemoveHook(tt->tp.processId,tt->tp.addr);
|
||||
break;
|
||||
case IDM_FORGET_SELECTION:
|
||||
case IDM_REMEMBER_SELECTION:
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
g_hListBox_listtext->add_menu_sep();
|
||||
g_hListBox_listtext->add_menu(MenuRemeberSelect,[&](){
|
||||
if(auto tt=getcurrthread())
|
||||
if(auto pexe=gmf(tt->tp.processId))
|
||||
{
|
||||
auto pexev=WideStringToString(pexe.value());
|
||||
if(LOWORD(wparam)==IDM_REMEMBER_SELECTION)
|
||||
{
|
||||
|
||||
savedhookcontext[pexev]={
|
||||
savedhookcontext[WideStringToString(pexe.value())]={
|
||||
{"hookcode",WideStringToString(tt->hp.hookcode)},
|
||||
{"ctx1",tt->tp.ctx},
|
||||
{"ctx2",tt->tp.ctx2},
|
||||
};
|
||||
}
|
||||
else if(LOWORD(wparam)==IDM_FORGET_SELECTION)
|
||||
{
|
||||
savedhookcontext.erase(pexev);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
});
|
||||
g_hListBox_listtext->add_menu(MenuForgetSelect,[&](){
|
||||
if(auto tt=getcurrthread())
|
||||
if(auto pexe=gmf(tt->tp.processId))
|
||||
savedhookcontext.erase(WideStringToString(pexe.value()));
|
||||
});
|
||||
|
||||
g_showtexts = new multilineedit(this);
|
||||
g_showtexts->setreadonly(true);
|
||||
|
||||
@ -425,6 +399,21 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
|
||||
void Pluginwindow::on_size(int w,int h){
|
||||
listplugins->setgeo(10,80,w-20,h-90);
|
||||
}
|
||||
void Pluginwindow::pluginrankmove(int moveoffset){
|
||||
auto idx=listplugins->currentidx();
|
||||
if(idx==-1)return;
|
||||
auto idx2=idx+moveoffset;
|
||||
auto a=min(idx,idx2),b=max(idx,idx2);
|
||||
if(a<0||b>=listplugins->count())return;
|
||||
pluginmanager->swaprank(a,b);
|
||||
|
||||
auto pa=((LPCWSTR)listplugins->getdata(a));
|
||||
auto pb=((LPCWSTR)listplugins->getdata(b));
|
||||
|
||||
listplugins->deleteitem(a);
|
||||
listplugins->insertitem(b,std::filesystem::path(pa).stem());
|
||||
listplugins->setdata(b,(LONG_PTR)pa);
|
||||
}
|
||||
Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p){
|
||||
pluginmanager=pl;
|
||||
(new label(this,LblPluginNotify))->setgeo(10,10,500,30);
|
||||
@ -435,64 +424,28 @@ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p){
|
||||
listplugins->setdata(idx,(LONG_PTR)_s);
|
||||
};
|
||||
listplugins = new listbox(this);
|
||||
#define IDM_ADD_PLUGIN 1004
|
||||
#define IDM_REMOVE_PLUGIN 1006
|
||||
#define IDM_RANK_UP 1007
|
||||
#define IDM_RANK_DOWN 1008
|
||||
listplugins->oncontextmenu=[](){
|
||||
HMENU hMenu = CreatePopupMenu();
|
||||
AppendMenu(hMenu, MF_STRING, IDM_ADD_PLUGIN, MenuAddPlugin);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_REMOVE_PLUGIN, MenuRemovePlugin);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_RANK_UP, MenuPluginRankUp);
|
||||
AppendMenu(hMenu, MF_STRING, IDM_RANK_DOWN, MenuPluginRankDown);
|
||||
return hMenu;
|
||||
};
|
||||
listplugins->oncontextmenucallback=[&](WPARAM wparam){
|
||||
|
||||
switch (LOWORD(wparam)) {
|
||||
case IDM_RANK_DOWN:
|
||||
case IDM_RANK_UP:
|
||||
{
|
||||
auto idx=listplugins->currentidx();
|
||||
if(idx==-1)break;
|
||||
auto idx2=idx+(
|
||||
(LOWORD(wparam)==IDM_RANK_UP)?-1:1
|
||||
);
|
||||
auto a=min(idx,idx2),b=max(idx,idx2);
|
||||
if(a<0||b>=listplugins->count())break;
|
||||
pluginmanager->swaprank(a,b);
|
||||
|
||||
auto pa=((LPCWSTR)listplugins->getdata(a));
|
||||
auto pb=((LPCWSTR)listplugins->getdata(b));
|
||||
|
||||
listplugins->deleteitem(a);
|
||||
listplugins->insertitem(b,std::filesystem::path(pa).stem());
|
||||
listplugins->setdata(b,(LONG_PTR)pa);
|
||||
break;
|
||||
}
|
||||
case IDM_ADD_PLUGIN:
|
||||
{
|
||||
auto f=pluginmanager->selectpluginfile();
|
||||
if(f.has_value()){
|
||||
listplugins->add_menu(MenuAddPlugin,[&](){
|
||||
if(auto f=pluginmanager->selectpluginfile())
|
||||
if(pluginmanager->addplugin(f.value())){
|
||||
listadd(f.value());
|
||||
}
|
||||
else{
|
||||
MessageBoxW(winId,InvalidPlugin,MsgError,0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IDM_REMOVE_PLUGIN:
|
||||
{
|
||||
});
|
||||
|
||||
listplugins->add_menu(MenuRemovePlugin,[&](){
|
||||
auto idx=listplugins->currentidx();
|
||||
if(idx==-1)break;
|
||||
if(idx==-1)return;
|
||||
pluginmanager->remove((LPCWSTR)listplugins->getdata(idx));
|
||||
listplugins->deleteitem(idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
listplugins->add_menu_sep();
|
||||
listplugins->add_menu(MenuPluginRankUp,std::bind(&Pluginwindow::pluginrankmove,this,-1));
|
||||
listplugins->add_menu(MenuPluginRankDown,std::bind(&Pluginwindow::pluginrankmove,this,1));
|
||||
|
||||
for(int i=0;i<pluginmanager->PluginRank.size();i++){
|
||||
listadd(pluginmanager->PluginRank[i]);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ class Pluginwindow:public mainwindow{
|
||||
public:
|
||||
Pluginwindow(mainwindow*,Pluginmanager*);
|
||||
void on_size(int w,int h);
|
||||
void pluginrankmove(int);
|
||||
};
|
||||
class Settingwindow:public mainwindow{
|
||||
checkbox* ckbfilterrepeat;
|
||||
@ -100,6 +101,7 @@ class LunaHost:public mainwindow{
|
||||
void on_thread_delete(TextThread& thread);
|
||||
void on_proc_connect(DWORD pid);
|
||||
public:
|
||||
TextThread* getcurrthread();
|
||||
confighelper* configs;
|
||||
int64_t currentselect=0;
|
||||
bool check_toclipboard;
|
||||
|
@ -314,3 +314,20 @@ gridlayout::gridlayout(int row,int col):control(0){
|
||||
void gridlayout::setmargin(int m){
|
||||
margin=m;
|
||||
}
|
||||
void control::menu_dispatch(WPARAM wparam){
|
||||
auto idx=LOWORD(wparam);
|
||||
menu_callbacks[idx].callback();
|
||||
}
|
||||
HMENU control::load_menu(){
|
||||
HMENU hMenu = CreatePopupMenu();
|
||||
for(int i=0;i<menu_callbacks.size();i++){
|
||||
AppendMenuW(hMenu,menu_callbacks[i].type,i,menu_callbacks[i].str.c_str());
|
||||
}
|
||||
return hMenu;
|
||||
}
|
||||
void control::add_menu(const std::wstring& str,std::function<void()> callback, UINT type){
|
||||
menu_callbacks.push_back({callback,type,str});
|
||||
}
|
||||
void control::add_menu_sep(){
|
||||
menu_callbacks.push_back({[](){},MF_SEPARATOR,L""});
|
||||
}
|
@ -8,8 +8,16 @@ class control:public basewindow{
|
||||
control(mainwindow*);
|
||||
virtual void dispatch(WPARAM);
|
||||
virtual void dispatch_2(WPARAM wParam, LPARAM lParam);
|
||||
std::function<HMENU()>oncontextmenu=[](){return (HMENU)nullptr;};
|
||||
std::function<void(WPARAM)>oncontextmenucallback=[](WPARAM){};
|
||||
void menu_dispatch(WPARAM);
|
||||
HMENU load_menu();
|
||||
struct menuinfos{
|
||||
std::function<void()> callback;
|
||||
UINT type;
|
||||
std::wstring str;
|
||||
};
|
||||
std::vector<menuinfos>menu_callbacks;
|
||||
void add_menu(const std::wstring&,std::function<void()> callback, UINT type=MF_STRING);
|
||||
void add_menu_sep();
|
||||
};
|
||||
|
||||
class button:public control{
|
||||
|
@ -315,12 +315,14 @@ bool Pluginmanager::addplugin(const std::wstring& p){
|
||||
auto importtable=getimporttable(p);
|
||||
if(importtable.empty())return false;
|
||||
auto isQt=qtchecker(importtable);
|
||||
LPVOID plugin;
|
||||
if(isQt){
|
||||
host->configs->pluginsadd({p,isQt});
|
||||
return true;
|
||||
plugin=0;
|
||||
}
|
||||
auto plugin=GetProcAddress(LoadLibraryW(p.c_str()),"OnNewSentence");
|
||||
else{
|
||||
plugin=GetProcAddress(LoadLibraryW(p.c_str()),"OnNewSentence");
|
||||
if(!plugin)return false;
|
||||
}
|
||||
|
||||
std::scoped_lock lock(OnNewSentenceSLock);
|
||||
if(!checkisdump(plugin)){
|
||||
|
@ -77,7 +77,7 @@ LRESULT mainwindow::wndproc(UINT message, WPARAM wParam, LPARAM lParam){
|
||||
if(lParam==0){
|
||||
for(auto ctl:controls){
|
||||
if(lastcontexthwnd==ctl->winId){
|
||||
ctl->oncontextmenucallback(wParam);break;
|
||||
ctl->menu_dispatch(wParam);break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,7 +94,7 @@ LRESULT mainwindow::wndproc(UINT message, WPARAM wParam, LPARAM lParam){
|
||||
bool succ=false;lastcontexthwnd=0;
|
||||
for(auto ctl:controls){
|
||||
if((HWND)wParam==ctl->winId){
|
||||
auto hm=ctl->oncontextmenu();
|
||||
auto hm=ctl->load_menu();
|
||||
if(hm){
|
||||
int xPos = LOWORD(lParam);
|
||||
int yPos = HIWORD(lParam);
|
||||
|
Loading…
Reference in New Issue
Block a user