/
smart.simba
217 lines (201 loc) · 8.56 KB
/
smart.simba
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
{$DEFINE SMART}
{$loadlib libsmartremote}
type tSmart=record
graphics:tGraphics;
pid:int32;
target:int32;
end;
var
smart:tSmart;
smartPointers:array of pointer;
function tSmart.getAvailablePID():int32;
var
funcLength,
funcIndex:int32;
begin
if smartGetClients(true) then
result:=smartGetAvailablePID(0);
exit(result);
end;
procedure tSmart.create();
begin self.create(800,600);end;
procedure tSmart.create(funcWidth,funcHeight:int32);overload;
var
funcParams:tStringArray;
begin
if not self.setPair() then
begin
if length(funcParams:=self.getParams())<2 then
begin
ogl.debug('tSmart.getParameters() failed');
terminateScript();
end;
self.target:=smartSpawnClient(self.getJavaPath(),replace(pluginPath,'\','/',[0]),funcParams[0],','+funcParams[1],funcWidth,funcHeight,'',self.getUserAgent(),'-XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=30','OpenGL32.dll');
if self.target then
begin
try
self.pid:=smartGetClientPID(self.target);
setEIOSTarget('libsmartremote',toStr(self.pid));
self.graphics.create(funcWidth,funcHeight,smartDebugArray(self.target));
insert(@self,smartPointers);
except
ogl.debug('tSmart.create() failed');
smartFreeClient(self.target);
terminateScript();
end;
end else
begin
ogl.debug('tSmart.create() failed');
smartFreeClient(self.target);
terminateScript();
end;
end;
addOnTerminate('tSmartSetFree');
end;
procedure tSmart.destroy();
begin
smartFreeClient(self.target);
smartKillClient(self.pid);
self.graphics.free();
self.pid:=0;
self.target:=0;
delete(pointer(@self),smartPointers);
end;
function tSmart.getDriveLetter():string;
begin exit(replaceRegExpr('^(\w):\\.*',pluginPath,'$1',true));end;
function tSmart.getJavaPath():ansiString;
var
funcJRE,
funcProgramFiles:tStringArray;
funcJREIndex,
funcProgramFilesIndex:int32;
begin
for funcProgramFilesIndex to high(funcProgramFiles:=getDirectories(self.getDriveLetter()+':\Program Files')) do
for funcJREIndex:=high(funcJRE:=getDirectories(self.getDriveLetter()+':\'+funcProgramFiles[funcProgramFilesIndex]+'\Java\jre')) downTo 0 do
if fileExists(self.getDriveLetter()+':\'+funcProgramFiles[funcProgramFilesIndex]+'\Java\'+funcJRE[funcJREIndex]+'\bin\java.exe') then
begin
result:=self.getDriveLetter()+':\'+funcProgramFiles[funcProgramFilesIndex]+'\Java\'+funcJRE[funcJREIndex]+'\bin\java.exe';
break;
end;
exit(result);
end;
function tSmart.getHeight():int32;
begin
if (result:=oglClientHeight)=0 then
begin
getClientPosition(oglClientWidth,oglClientHeight);
result:=oglClientHeight;
end;
exit(result);
end;
function tSmart.getParams():tStringArray;
var
funcAttempts,
funcIndex,
funcResultIndex:int32;
funcPage:string;
funcPageExplode:tStringArray;
begin
for 0 to 10 do
begin
funcPage:=getPage('http://world'+toStr(random({$IFNDEF DARKSCAPE}1,150{$ELSE}200,207{$ENDIF}))+'.runescape.com/jav_config_beta.ws');
if pos('404 - Page not found',funcPage)=0 then
begin
setLength(result,length(funcPageExplode:=explode(#10,funcPage)));
for funcIndex to high(funcPageExplode) do
if execRegExpr('^(codebase|param)=(.+)',funcPageExplode[funcIndex]) then
begin
result[funcResultIndex]:=replaceRegExpr('^(codebase|param)=(.+)',funcPageExplode[funcIndex],'$2',true);
funcResultIndex+=1;
end;
break;
end;
end;
setLength(result,funcResultIndex);
exit(result);
end;
function tSmart.getUserAgent():string;
const
funcUserAgentArray:tStringArray=[
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240',
'Mozilla/5.0 (Windows NT 6.1; rv:41.0) Gecko/20100101 Firefox/41.0',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0',
'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36',
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1; rv:41.0) Gecko/20100101 Firefox/41.0',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0; Trident/5.0)',
'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0',
'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Trident/5.0)',
'Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101 Firefox/38.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; rv:40.0) Gecko/20100101 Firefox/40.0',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36 OPR/32.0.1948.69',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
];
begin
exit(funcUserAgentArray[random(length(funcUserAgentArray))]);
end;
function tSmart.getWidth():int32;
begin
if (result:=oglClientWidth)=0 then
begin
getClientPosition(oglClientWidth,oglClientHeight);
result:=oglClientWidth;
end;
exit(result);
end;
function tSmart.setPair():boolean;
begin
if (self.pid:=self.getAvailablePID()) then
if (self.target:=smartPairClient(self.pid)) then
begin
setEIOSTarget('libsmartremote',toStr(self.pid));
self.graphics.create(self.getWidth(),self.getHeight(),smartDebugArray(self.target));
insert(@self,smartPointers);
result:=true;
end;
if result then
ogl.debug('tSmart.setPair() successful');
exit(result);
end;
procedure tSmart.setFree();overload;
begin
smartFreeClient(self.target);
self.graphics.free();
self.pid:=0;
self.target:=0;
delete(pointer(@self),smartPointers);
end;
procedure tSmartSetFree;
var
funcIndex:int32;
begin
for funcIndex to high(smartPointers) do
tSmart(smartPointers[funcIndex]^).setFree();
end;