Skip to content

Commit

Permalink
fix vehdebug crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
cheat-engine committed Oct 4, 2022
1 parent 2bbef46 commit 7cfe3eb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Cheat Engine/VEHDebugger.pas
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function TVEHDebugInterface.SetThreadContext(hThread: THandle; const lpContext:
begin


if isFrozenThread then //use the VEHDebugView context
if (not wasInjectedEvent) and isFrozenThread then //use the VEHDebugView context
begin
result:=true;

Expand Down Expand Up @@ -245,9 +245,9 @@ function TVEHDebugInterface.GetThreadContext(hThread: THandle; var lpContext: TC
{$endif}

begin
if isFrozenThread then //use the VEHDebugView context
if (not wasInjectedEvent) and isFrozenThread then //use the VEHDebugView context
begin
OutputDebugString('VEH GetThreadContext. From frozen');
//OutputDebugString('VEH GetThreadContext. From frozen');
result:=true;
c:[email protected][0];
{$ifdef cpu64}
Expand Down Expand Up @@ -291,7 +291,7 @@ function TVEHDebugInterface.GetThreadContext(hThread: THandle; var lpContext: TC
end
else
begin
OutputDebugString('VEH GetThreadContext. not frozen');
// OutputDebugString('VEH GetThreadContext. not frozen');
result:=NewKernelHandler.GetThreadContext(hThread,lpContext);
end;
end;
Expand Down Expand Up @@ -341,7 +341,10 @@ function TVEHDebugInterface.WaitForDebugEvent(var lpDebugEvent: TDebugEvent; dwM
threads.Add(lpDebugEvent.dwThreadId, currentthread);
end;

suspendThread(CurrentThread);
if CurrentThread<>0 then
begin
suspendThread(CurrentThread);
end;
end
else
begin
Expand All @@ -351,7 +354,8 @@ function TVEHDebugInterface.WaitForDebugEvent(var lpDebugEvent: TDebugEvent; dwM

if threads.GetData(lpDebugEvent.dwThreadId,h) then
begin
closehandle(h);
if h<>0 then
closehandle(h);
threads.Delete(lpDebugEvent.dwThreadId);
end;
end;
Expand Down Expand Up @@ -386,10 +390,11 @@ function TVEHDebugInterface.WaitForDebugEvent(var lpDebugEvent: TDebugEvent; dwM
if threads.GetData(lpDebugEvent.dwThreadId,lpDebugEvent.CreateProcessInfo.hThread)=false then
begin
lpDebugEvent.CreateProcessInfo.hThread:=OpenThread(THREAD_ALL_ACCESS,false, lpDebugEvent.dwThreadId);
currentthread:=lpDebugEvent.CreateProcessInfo.hThread;
suspendthread(CurrentThread);
threads.Add(lpDebugEvent.dwThreadId,lpDebugEvent.CreateProcessInfo.hThread);
end;

currentthread:=lpDebugEvent.CreateProcessInfo.hThread;
suspendthread(CurrentThread);
end;

$ce000001: //create thread
Expand Down

0 comments on commit 7cfe3eb

Please sign in to comment.