diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 6904739c2..5c93c1a98 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -1142,6 +1142,10 @@ bool API::Resume() { return d->p->resume(); } +bool API::ForceResume() +{ + return d->p->forceresume(); +} bool API::isSuspended() { return d->p->isSuspended(); diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index 297025f17..adc7a1ba2 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -63,8 +63,14 @@ namespace DFHack bool Detach(); bool isAttached(); + // stop DF from executing bool Suspend(); + // resume DF bool Resume(); + /** + * be careful with this one + */ + bool ForceResume(); bool isSuspended(); /** * Matgloss. next four methods look very similar. I could use two and move the processing one level up... diff --git a/library/DFProcess-linux.cpp b/library/DFProcess-linux.cpp index 693105d92..9da19a8b3 100644 --- a/library/DFProcess-linux.cpp +++ b/library/DFProcess-linux.cpp @@ -252,6 +252,11 @@ bool Process::suspend() d->suspended = true; } +bool Process::forceresume() +{ + return resume(); +} + bool Process::resume() { int status; diff --git a/library/DFProcess-windows.cpp b/library/DFProcess-windows.cpp index b8abb5435..f2bdbc253 100644 --- a/library/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -186,6 +186,16 @@ bool Process::suspend() return true; } +bool Process::forceresume() +{ + if(!d->attached) + return false; + while (ResumeThread(d->my_main_thread) > 1); + d->suspended = false; + return true; +} + + bool Process::resume() { if(!d->attached) diff --git a/library/DFProcess.h b/library/DFProcess.h index 21f6a2960..f50caf1d4 100644 --- a/library/DFProcess.h +++ b/library/DFProcess.h @@ -72,6 +72,7 @@ namespace DFHack bool suspend(); bool resume(); + bool forceresume(); bool isSuspended(); bool isAttached(); diff --git a/tools/suspendtest.cpp b/tools/suspendtest.cpp index 07f5c680f..92a95a85c 100644 --- a/tools/suspendtest.cpp +++ b/tools/suspendtest.cpp @@ -24,15 +24,21 @@ int main (void) getline(cin, blah); DF.Resume(); - cout << "Resumed, DF should be running" << endl; getline(cin, blah); DF.Suspend(); - cout << "Suspended, DF should be suspended now" << endl; getline(cin, blah); + DF.Resume(); + cout << "Resumed, testing ForceResume. Suspend using SysInternals Process Explorer" << endl; + getline(cin, blah); + + DF.ForceResume(); + cout << "ForceResumed. DF should be running." << endl; + getline(cin, blah); + if(!DF.Detach()) { cerr << "Can't detach from DF" << endl;