This commit is contained in:
恍兮惚兮 2024-03-29 15:07:43 +08:00
parent 05589b9ad4
commit bf9a4f6320
6 changed files with 100 additions and 118 deletions

View File

@ -101,7 +101,11 @@ void LunaHost::on_proc_connect(DWORD pid)
autoattachexes.insert(WideStringToString(pexe.value())); 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(){ LunaHost::LunaHost(){
configs=new confighelper; configs=new confighelper;
@ -170,63 +174,33 @@ LunaHost::LunaHost(){
g_showtexts->settext(get); g_showtexts->settext(get);
g_showtexts->scrolltoend(); g_showtexts->scrolltoend();
}; };
g_hListBox_listtext->add_menu(MenuCopyHookCode,[&](){if(auto tt=getcurrthread())toclipboard(std::wstring(tt->hp.hookcode));});
#define IDM_REMOVE_HOOK 1001 g_hListBox_listtext->add_menu_sep();
#define IDM_DETACH_PROCESS 1002 g_hListBox_listtext->add_menu(MenuRemoveHook,[&](){if(auto tt=getcurrthread())Host::RemoveHook(tt->tp.processId,tt->tp.addr);});
#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){
auto handle = g_hListBox_listtext->getdata(g_hListBox_listtext->currentidx()); g_hListBox_listtext->add_menu(MenuDetachProcess,[&](){
auto tt=Host::GetThread(handle); if(auto tt=getcurrthread()){
if(tt==0)return; Host::DetachProcess(tt->tp.processId);
switch (LOWORD(wparam)) { userdetachedpids.insert(tt->tp.processId);
case IDM_COPY_HOOKCODE:
toclipboard(std::wstring(tt->hp.hookcode));
break;
case IDM_DETACH_PROCESS:
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:
{
if(auto pexe=gmf(tt->tp.processId))
{
auto pexev=WideStringToString(pexe.value());
if(LOWORD(wparam)==IDM_REMEMBER_SELECTION)
{
savedhookcontext[pexev]={
{"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_sep();
g_hListBox_listtext->add_menu(MenuRemeberSelect,[&](){
if(auto tt=getcurrthread())
if(auto pexe=gmf(tt->tp.processId))
savedhookcontext[WideStringToString(pexe.value())]={
{"hookcode",WideStringToString(tt->hp.hookcode)},
{"ctx1",tt->tp.ctx},
{"ctx2",tt->tp.ctx2},
};
});
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 = new multilineedit(this);
g_showtexts->setreadonly(true); g_showtexts->setreadonly(true);
@ -425,6 +399,21 @@ Settingwindow::Settingwindow(LunaHost* host):mainwindow(host){
void Pluginwindow::on_size(int w,int h){ void Pluginwindow::on_size(int w,int h){
listplugins->setgeo(10,80,w-20,h-90); 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){ Pluginwindow::Pluginwindow(mainwindow*p,Pluginmanager* pl):mainwindow(p){
pluginmanager=pl; pluginmanager=pl;
(new label(this,LblPluginNotify))->setgeo(10,10,500,30); (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->setdata(idx,(LONG_PTR)_s);
}; };
listplugins = new listbox(this); 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)) { listplugins->add_menu(MenuAddPlugin,[&](){
case IDM_RANK_DOWN: if(auto f=pluginmanager->selectpluginfile())
case IDM_RANK_UP: if(pluginmanager->addplugin(f.value())){
{ listadd(f.value());
auto idx=listplugins->currentidx(); }
if(idx==-1)break; else{
auto idx2=idx+( MessageBoxW(winId,InvalidPlugin,MsgError,0);
(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)); listplugins->add_menu(MenuRemovePlugin,[&](){
auto pb=((LPCWSTR)listplugins->getdata(b)); auto idx=listplugins->currentidx();
if(idx==-1)return;
pluginmanager->remove((LPCWSTR)listplugins->getdata(idx));
listplugins->deleteitem(idx);
});
listplugins->add_menu_sep();
listplugins->add_menu(MenuPluginRankUp,std::bind(&Pluginwindow::pluginrankmove,this,-1));
listplugins->add_menu(MenuPluginRankDown,std::bind(&Pluginwindow::pluginrankmove,this,1));
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()){
if(pluginmanager->addplugin(f.value())){
listadd(f.value());
}
else{
MessageBoxW(winId,InvalidPlugin,MsgError,0);
}
}
break;
}
case IDM_REMOVE_PLUGIN:
{
auto idx=listplugins->currentidx();
if(idx==-1)break;
pluginmanager->remove((LPCWSTR)listplugins->getdata(idx));
listplugins->deleteitem(idx);
break;
}
}
};
for(int i=0;i<pluginmanager->PluginRank.size();i++){ for(int i=0;i<pluginmanager->PluginRank.size();i++){
listadd(pluginmanager->PluginRank[i]); listadd(pluginmanager->PluginRank[i]);
} }

View File

@ -10,6 +10,7 @@ class Pluginwindow:public mainwindow{
public: public:
Pluginwindow(mainwindow*,Pluginmanager*); Pluginwindow(mainwindow*,Pluginmanager*);
void on_size(int w,int h); void on_size(int w,int h);
void pluginrankmove(int);
}; };
class Settingwindow:public mainwindow{ class Settingwindow:public mainwindow{
checkbox* ckbfilterrepeat; checkbox* ckbfilterrepeat;
@ -100,6 +101,7 @@ class LunaHost:public mainwindow{
void on_thread_delete(TextThread& thread); void on_thread_delete(TextThread& thread);
void on_proc_connect(DWORD pid); void on_proc_connect(DWORD pid);
public: public:
TextThread* getcurrthread();
confighelper* configs; confighelper* configs;
int64_t currentselect=0; int64_t currentselect=0;
bool check_toclipboard; bool check_toclipboard;

View File

@ -314,3 +314,20 @@ gridlayout::gridlayout(int row,int col):control(0){
void gridlayout::setmargin(int m){ void gridlayout::setmargin(int m){
margin=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""});
}

View File

@ -8,8 +8,16 @@ class control:public basewindow{
control(mainwindow*); control(mainwindow*);
virtual void dispatch(WPARAM); virtual void dispatch(WPARAM);
virtual void dispatch_2(WPARAM wParam, LPARAM lParam); virtual void dispatch_2(WPARAM wParam, LPARAM lParam);
std::function<HMENU()>oncontextmenu=[](){return (HMENU)nullptr;}; void menu_dispatch(WPARAM);
std::function<void(WPARAM)>oncontextmenucallback=[](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{ class button:public control{

View File

@ -315,12 +315,14 @@ bool Pluginmanager::addplugin(const std::wstring& p){
auto importtable=getimporttable(p); auto importtable=getimporttable(p);
if(importtable.empty())return false; if(importtable.empty())return false;
auto isQt=qtchecker(importtable); auto isQt=qtchecker(importtable);
LPVOID plugin;
if(isQt){ if(isQt){
host->configs->pluginsadd({p,isQt}); plugin=0;
return true; }
else{
plugin=GetProcAddress(LoadLibraryW(p.c_str()),"OnNewSentence");
if(!plugin)return false;
} }
auto plugin=GetProcAddress(LoadLibraryW(p.c_str()),"OnNewSentence");
if(!plugin)return false;
std::scoped_lock lock(OnNewSentenceSLock); std::scoped_lock lock(OnNewSentenceSLock);
if(!checkisdump(plugin)){ if(!checkisdump(plugin)){

View File

@ -77,7 +77,7 @@ LRESULT mainwindow::wndproc(UINT message, WPARAM wParam, LPARAM lParam){
if(lParam==0){ if(lParam==0){
for(auto ctl:controls){ for(auto ctl:controls){
if(lastcontexthwnd==ctl->winId){ 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; bool succ=false;lastcontexthwnd=0;
for(auto ctl:controls){ for(auto ctl:controls){
if((HWND)wParam==ctl->winId){ if((HWND)wParam==ctl->winId){
auto hm=ctl->oncontextmenu(); auto hm=ctl->load_menu();
if(hm){ if(hm){
int xPos = LOWORD(lParam); int xPos = LOWORD(lParam);
int yPos = HIWORD(lParam); int yPos = HIWORD(lParam);