forked from gamegrd/imitating
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRun_script.pas
More file actions
167 lines (141 loc) · 4.35 KB
/
Copy pathRun_script.pas
File metadata and controls
167 lines (141 loc) · 4.35 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
unit Run_script;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Dialogs,MY_API, lua, lualib,lauxlib, LuaUtils;
type //定义线程类
TScriptThread=class(TThread)
ExpressionCleck:Boolean;
protected
procedure Execute; override;
procedure Ready;
procedure OnDead(Sender: TObject);
function RelaceMSG(s:string):string;
public
constructor create(const EXPCleck:boolean=True);
end;
var
L:Plua_State;
Running:boolean;
MI_WINIO:string ='WinIo.dll';
_kernel,_U32,_gdi32,_WINIO: THandle;
Hardwork:Boolean;
function luaopen_vcl(L: Plua_State): Integer; cdecl; external 'vcl.dll';
//function luaopen_afx(L: Plua_State): Integer; cdecl; external 'afx.dll';
function luaopen_winreg(L: Plua_State): Integer; cdecl; external 'winreg.dll';
implementation
uses Unit1;
constructor TScriptThread.create(const EXPCleck:boolean=True);
begin
inherited create(false);
ExpressionCleck:= EXPCleck;
Ready;
OnTerminate:=OnDead;
freeonterminate:=true;//线程终止时自动删除对象
end;
procedure TScriptThread.OnDead(Sender: TObject);
begin
Running:=False;
RunScript:=nil;
FrmMain.ToolButton16.Enabled:=True;
FrmMain.ToolButton17.Enabled:=False;
end;
function TScriptThread.RelaceMSG(s:string):string;
begin
if CompareText('unexpected symbol',s) = 0 then
result :='未知的关键字,正确的关键字应该是黑体的,请您检查是不否有写错字'
else if CompareText(s,'to close `while') = 0 then
result := '应该有一个 end 去关闭 while'
else if CompareText(s,'then'' expected') = 0 then
result := '缺少 那么 关键字'
else if CompareText(s,'to close `function') = 0 then
result := '应该有一个 返回 去关闭一个过程'
else if CompareText(s,'<eof> expected near `end') = 0 then
result := '多写了一个 返回 语句? 请您仔细检查'
else result :='';
end;
procedure TScriptThread.Execute;
begin
if ExpressionCleck then
begin
try
log('开始语法检查...',clWhite);
LuaLoadBuffer(L,User_Scr.Text, 'User_Scr');
except
on E: ELuaException do
begin
if (E.Msg <> 'STOP') then
begin
log(Format('[错误]:%s Line:%d',[E.Msg,E.Line]),CLRed);
// log(Format('第 %d 行发现错误,提示消息[%s]',[E.Line,E.Msg]),CLRed);
ErrorLine:=e.Line-1;
FrmMain.SynEditor1.SetLineColor(ErrorLine,clBlack,clRed);
exit;
end;
end;
end;
log('语法检查通过...',clLime);
lua_dobuffer(L,pchar(User_Scr.Text),length(User_Scr.Text),'User_Scr');
end
else
begin
lua_dobuffer(L,pchar(User_Scr.Text),length(User_Scr.Text),'User_Scr');
end;
end;
procedure TScriptThread.Ready;
begin
if L<>nil then
begin
lua_close(L);
L:=nil;
end;
L := lua_open();
luaopen_base(L);
luaopen_table(L);
luaopen_string(L);
luaopen_os(L);
luaopen_math(L);
luaopen_vcl(L);
//luaopen_afx(L);
luaopen_winreg(L);
luaopen_debug(L);
lua_settop(L, 0);
//注册函数
lua_register(L,'print',API_print) ;
lua_register(L,'stoprun',API_stoprun) ;
//==键盘==
lua_register(L,'keypress',API_KeyPress) ;
lua_register(L,'keydown',API_KeyDown) ;
lua_register(L,'keyup',API_KeyUp) ;
//==鼠标==
lua_register(L,'leftclick',API_LeftClick) ;
lua_register(L,'rightclick',API_RightClick) ;
lua_register(L,'middleclick',API_MiddleClick) ;
lua_register(L,'leftdblick',API_LeftDoubleClick) ;
lua_register(L,'leftdown',API_LeftDown);
lua_register(L,'leftup',API_LeftUp);
lua_register(L,'rightdown',API_RightDown) ;
lua_register(L,'rightup',API_RightUp);
lua_register(L,'moveto',API_MoveTo);
lua_register(L,'mover',API_MoveR);
//==其它===
lua_register(L,'sleep',API_Sleep);
lua_register(L,'beep',API_Beep);
lua_register(L,'messagebox',API_messagebox) ;
lua_register(L,'saystring',API_saystring) ;
lua_register(L,'findpic',API_findpic) ;
lua_register(L,'getpixelcolor',API_getpixelcolor) ;
lua_register(L,'findcolor',API_findcolor) ;
lua_register(L,'findcolorex',API_findcolorex) ;
lua_register(L,'comparecolore',API_comparecolore) ;
lua_register(L,'readmemory',API_readmemory) ;
//===========系统API================
lua_register(L,'findwindow',API_FindWindow) ;
lua_register(L,'setwindowpos',API_SetWindowPos) ;
lua_register(L,'playsound',API_PlaySound) ;
lua_register(L,'gettickcount',API_GetTickCount) ;
lua_register(L,'postmessage',API_PostMessage) ;
lua_register(L,'sendmessage',API_SendMessage) ;
lua_register(L,'execute',API_Execute) ;
end;
end.