2
2
using System . Drawing ;
3
3
using System . Linq ;
4
4
using System . Windows . Forms ;
5
+ using IronPython . Hosting ;
6
+ using Microsoft . Scripting . Hosting ;
7
+ using ReClassNET ;
5
8
using ReClassNET . Plugins ;
6
9
7
10
namespace PythonScriptingPlugin
8
11
{
9
12
public class PythonScriptingPluginExt : Plugin
10
13
{
11
14
private IPluginHost host ;
15
+ private ScriptEngine engine ;
12
16
13
17
public override Image Icon => Properties . Resources . B16x16_Logo ;
14
18
@@ -28,19 +32,84 @@ public override bool Initialize(IPluginHost pluginHost)
28
32
29
33
host = pluginHost ;
30
34
35
+ engine = Python . CreateEngine ( ) ;
36
+ engine . Runtime . LoadAssembly ( typeof ( IntPtr ) . Assembly ) ;
37
+ engine . Runtime . LoadAssembly ( typeof ( Program ) . Assembly ) ;
38
+
31
39
var scriptingMenuItem = new ToolStripMenuItem ( "Scripts" ) ;
32
40
33
41
var editorMenuItem = new ToolStripMenuItem ( "Editor" ) ;
34
42
scriptingMenuItem . DropDownItems . Add ( editorMenuItem ) ;
35
43
44
+ var testMenuItem = new ToolStripMenuItem ( "Test" ) ;
45
+ testMenuItem . Click += ( sender , args ) =>
46
+ {
47
+ /*var expression = @"data = process.ReadRemoteMemory(IntPtr(0xFFD20000), 4)
48
+
49
+ logger.Log(LogLevel.Error, str(data[0]))
50
+ logger.Log(LogLevel.Error, str(data[1]))";*/
51
+
52
+ var expression = @"for m in process.Modules:
53
+ logger.Log(LogLevel.Error, m.Name)" ;
54
+
55
+ try
56
+ {
57
+ ExecuteScript ( expression ) ;
58
+ }
59
+ catch ( Exception e )
60
+ {
61
+ Program . ShowException ( e ) ;
62
+ }
63
+ } ;
64
+ scriptingMenuItem . DropDownItems . Add ( testMenuItem ) ;
65
+
36
66
host . MainWindow . MainMenu . Items . Insert ( 3 , scriptingMenuItem ) ;
37
67
38
68
return true ;
39
69
}
40
70
41
71
public override void Terminate ( )
42
72
{
73
+ engine = null ;
74
+
43
75
host = null ;
44
76
}
77
+
78
+ private ScriptScope CreateReClassScope ( )
79
+ {
80
+ var scope = engine . CreateScope ( ) ;
81
+
82
+ dynamic s = scope ;
83
+
84
+ s . Is64Bit = false ;
85
+
86
+ s . ReClassName = Constants . ApplicationName ;
87
+ s . ReClassVersion = Constants . ApplicationVersion ;
88
+
89
+ s . logger = host . Logger ;
90
+ s . process = host . Process ;
91
+
92
+ return scope ;
93
+ }
94
+
95
+ private static string CreateExpressionPreamble ( )
96
+ {
97
+ return "from System import *\n "
98
+ + "from ReClassNET import *\n "
99
+ + "from ReClassNET.Logger import *\n "
100
+ + "from ReClassNET.Memory import *\n "
101
+ + "from ReClassNET.MemoryScanner import *\n "
102
+ + "from ReClassNET.Nodes import *\n "
103
+ + "from ReClassNET.Util import *\n " ;
104
+ }
105
+
106
+ private object ExecuteScript ( string code )
107
+ {
108
+ var scope = CreateReClassScope ( ) ;
109
+
110
+ code = CreateExpressionPreamble ( ) + code ;
111
+
112
+ return engine . Execute ( code , scope ) ;
113
+ }
45
114
}
46
115
}
0 commit comments