Skip to content

Commit 41dcf03

Browse files
committed
Added process events.
1 parent 2e3d7ec commit 41dcf03

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

Forms/MainForm.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,17 @@ public MainForm(CoreFunctionsManager coreFunctions)
5353
toolStrip.Renderer = new CustomToolStripProfessionalRenderer(false);
5454

5555
remoteProcess = new RemoteProcess(coreFunctions);
56-
remoteProcess.ProcessChanged += delegate (RemoteProcess sender)
56+
remoteProcess.ProcessAttached += (sender) =>
5757
{
58-
if (!sender.IsValid)
59-
{
60-
Text = Constants.ApplicationName;
61-
processInfoToolStripStatusLabel.Text = "No process selected";
62-
}
63-
else
64-
{
65-
var text = $"{sender.UnderlayingProcess.Name} (PID: {sender.UnderlayingProcess.Id.ToString()})";
58+
var text = $"{sender.UnderlayingProcess.Name} (PID: {sender.UnderlayingProcess.Id.ToString()})";
6659

67-
Text = $"{Constants.ApplicationName} - {text}";
68-
processInfoToolStripStatusLabel.Text = text;
69-
}
60+
Text = $"{Constants.ApplicationName} - {text}";
61+
processInfoToolStripStatusLabel.Text = text;
62+
};
63+
remoteProcess.ProcessClosed += (sender) =>
64+
{
65+
Text = Constants.ApplicationName;
66+
processInfoToolStripStatusLabel.Text = "No process selected";
7067
};
7168

7269
memory = new MemoryBuffer

Memory/RemoteProcess.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace ReClassNET.Memory
1717
{
18-
public delegate void UnderlayingProcessChangedEvent(RemoteProcess sender);
18+
public delegate void RemoteProcessEvent(RemoteProcess sender);
1919

2020
public class RemoteProcess : IDisposable
2121
{
@@ -36,7 +36,14 @@ public class RemoteProcess : IDisposable
3636
private ProcessInfo process;
3737
private IntPtr handle;
3838

39-
public event UnderlayingProcessChangedEvent ProcessChanged;
39+
/// <summary>Event which gets invoked when a process was opened.</summary>
40+
public event RemoteProcessEvent ProcessAttached;
41+
42+
/// <summary>Event which gets invoked before a process gets closed.</summary>
43+
public event RemoteProcessEvent ProcessClosing;
44+
45+
/// <summary>Event which gets invoked after a process was closed.</summary>
46+
public event RemoteProcessEvent ProcessClosed;
4047

4148
public CoreFunctionsManager CoreFunctions => coreFunctions;
4249

@@ -81,7 +88,7 @@ public void Open(ProcessInfo info)
8188
handle = coreFunctions.OpenRemoteProcess(process.Id, ProcessAccess.Full);
8289
}
8390

84-
ProcessChanged?.Invoke(this);
91+
ProcessAttached?.Invoke(this);
8592
}
8693
}
8794

@@ -90,6 +97,8 @@ public void Close()
9097
{
9198
if (process != null)
9299
{
100+
ProcessClosing?.Invoke(this);
101+
93102
lock (processSync)
94103
{
95104
debugger.Terminate();
@@ -101,7 +110,7 @@ public void Close()
101110
process = null;
102111
}
103112

104-
ProcessChanged?.Invoke(this);
113+
ProcessClosed?.Invoke(this);
105114
}
106115
}
107116

0 commit comments

Comments
 (0)