forked from ReClassNET/ReClass.NET-SamplePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSamplePluginManagedExt.cs
More file actions
105 lines (86 loc) · 2.75 KB
/
SamplePluginManagedExt.cs
File metadata and controls
105 lines (86 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using ReClassNET.Forms;
using ReClassNET.Memory;
using ReClassNET.Nodes;
using ReClassNET.Plugins;
using ReClassNET.UI;
// The namespace name must equal the plugin name
namespace SamplePluginManaged
{
/// <summary>The class name must equal the namespace name + "Ext"</summary>
public class SamplePluginManagedExt : Plugin
{
private IPluginHost host;
private INodeInfoReader reader;
/// <summary>The icon to display in the plugin manager form.</summary>
public override Image Icon => null;
/// <summary>This method gets called when ReClass.NET loads the plugin.</summary>
public override bool Initialize(IPluginHost host)
{
this.host = host;
// Notfiy the plugin if a window is shown.
GlobalWindowManager.WindowAdded += OnWindowAdded;
// Register a node info reader to display custom data on nodes.
reader = new SampleNodeInfoReader();
host.RegisterNodeInfoReader(reader);
return true;
}
/// <summary>This method gets called when ReClass.NET unloads the plugin.</summary>
public override void Terminate()
{
// Clean up what you have registered.
host.DeregisterNodeInfoReader(reader);
GlobalWindowManager.WindowAdded -= OnWindowAdded;
host = null;
}
/// <summary>
/// This method gets called when a new windows is opened.
/// You can use this function to add a settings panel into the settings dialog for example.
/// </summary>
private void OnWindowAdded(object sender, GlobalWindowManagerEventArgs e)
{
if (e.Form is SettingsForm settingsForm)
{
settingsForm.Shown += delegate (object sender2, EventArgs e2)
{
try
{
var settingsTabControl = settingsForm.Controls.Find("settingsTabControl", true).FirstOrDefault() as TabControl;
if (settingsTabControl != null)
{
var newTab = new TabPage("SamplePlugin")
{
UseVisualStyleBackColor = true
};
// You can use a custom control here so you have designer support
//var myControl = new MyControl();
//myControl.Dock = DockStyle.Fill;
//newTab.Controls.Add(myControl);
// or add the controls manually.
var checkBox = new CheckBox
{
Text = "Use Sample Setting"
};
newTab.Controls.Add(checkBox);
settingsTabControl.TabPages.Add(newTab);
}
}
catch
{
}
};
}
}
}
public class SampleNodeInfoReader : INodeInfoReader
{
/// <summary>This method lets ReClass.NET print the name and the value of the node.</summary>
public string ReadNodeInfo(BaseNode node, IntPtr nodeAddress, IntPtr nodeValue, MemoryBuffer memory)
{
return $"{node.Name}@{nodeAddress.ToString("X")} => {nodeValue.ToString("X")}";
}
}
}