-
Notifications
You must be signed in to change notification settings - Fork 9
/
Antiban.simba
679 lines (583 loc) · 18.8 KB
/
Antiban.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
{$include_once GameTab.simba}
{$include_once Login.simba}
{$include_once Mainscreen.simba}
{$include_once Mouse.simba}
{$include_once Player.simba}
{$include_once Skills.simba}
{$include_once Timing.simba}
{$include_once Worlds.simba}
(*
Antiban
=======
Experimental Antiban, Breaksystem, and fatigue/energy system.
Could contain some issues, and for that reason breaking changes may happen.
Other methods worth mentioning in this file:
.. code-block:: pascal
procedure TSRL.HoverRandomPlayer(OptionChance:Double=30; WaitMean:Double=3500);
procedure TSRL.MouseOffClient(Direction: Byte);
procedure TSRL.MouseOffClient(); overload;
function TSRL.DismissRandom(): Boolean;
Functions of RAntiban:
.. code-block:: pascal
function RAntiban.Init(Skills: TIntArray; LogSize:Int32=5): Boolean;
function RAntiban.Init(Skill: Int32; LogSize:Int32=5): Boolean; overload; //simple 1 skill
function RAntiban.Copy(): RAntiban; constref;
procedure RAntiban.SetupBiometrics();
function RAntiban.TimeRunning(): Int64; constref;
function RAntiban.TimeRunningAtClock(TimeOfDay: String; StVar: String='00:00'): Int64;
procedure RAntiban.DebugNote(s: String; AddToList:Boolean=True);
function RAntiban.AddTask(Task: RAntibanTask): Boolean;
function RAntiban.AddBreak(Task: TBreakTask): Boolean;
function RAntiban.RestarRAntiban(): Boolean;
function RAntiban.DoBreak(out BreakID: Int32): Boolean;
function RAntiban.DoBreak(): Boolean; overload;
function RAntiban.DoAntiban(CheckBreaks: Boolean = True): Boolean;
function RAntiban.HasSleep(): Boolean;
function RAntiban.GetSleepId(): Int32;
function RAntiban.TimeSinceBreak(LongerThan:Double=0): UInt64;
function RAntiban.BreaksPast(Timespan: Double): Int64;
function RAntiban.EnergyLevel(): Double;
procedure RAntiban.WaitFatigue(t: Double; Exp: Double=0.667);
Builtin antiban tasks that can be used directly with RAntiban:
.. code-block:: pascal
procedure RAntiban.LoseFocus();
procedure RAntiban.HoverPlayers();
procedure RAntiban.CheckSkill();
procedure RAntiban.RandomCompass();
procedure RAntiban.RandomCompassNESW();
procedure RAntiban.CheckStats();
procedure RAntiban.OpenRandomTab();
procedure RAntiban.VeryShortBreak();
procedure RAntiban.FiveMinBreak();
procedure RAntiban.DoMiscStuff();
You can easily create your own tasks like the above in your script that does
whatever. For a deeper look skip to the last lines of this file.
**Example of how such a method would look:**
.. pascal::
procedure RAntiban.HoverTotalLevel();
begin
Stats.HoverSkill(Random(SKILL_TOTAL), RandGauss(3000,300));
end;
** Example of usage in script **
.. pascal::
var
Antiban: RAntiban;
begin
Antiban.Init(SKILL_MINING);
//which method, how often, normal time variation
Antiban.AddTask([@Antiban.HoverTotalLevel, ONE_MINUTE*7, 0.33]);
Antiban.AddTask([@Antiban.HoverPlayers, ONE_MINUTE*9, 0.33]);
Antiban.AddTask([@Antiban.CheckSkill, ONE_MINUTE*13, 0.33]);
// and inside the script loop you do the following
// which will look for antibans that are ready to be executed, and then execute them.
Antiban.DoAntiban();
end;
*)
type
AAntibanTask = ^RAntibanTask;
RAntibanTask = record
Method: procedure of object;
Interval: Double;
StdVar: Double;
Condition: function: Boolean of object;
NextAtTime: Double;
end;
ABreakTask = ^RBreakTask;
RBreakTask = record
Interval: Double;
Length: Double;
LogoutChance: Double;
StdVar: Double;
NextAtTime, PrevAtTime: Double;
end;
RAntiban = record
ActiveSkills: Array of TSkillIndex;
Tasks: array of RAntibanTask;
Breaks: array of RBreakTask;
TotalBreakTime: UInt64;
HistorySize: Int32;
TasksDone: TStringArray;
Debug: Boolean;
ReturnToTab: Boolean;
BioHash, Endurance, Patience: Double;
end;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// RAntiban setup and such
{
Basic setup procedures
What skills do we care about, shoudl we return to the tab after we leave it,
and alterantively how long should the log be (mainly for debugging)
}
procedure RAntiban.Init(Skills: Array of TSkillIndex; ReturnToTab: Boolean = True; LogSize:Int32=5; Debug: Boolean = False);
begin
Self.ActiveSkills := Skills;
Self.HistorySize := LogSize;
Self.BioHash := Random();
Self.Endurance := Cos(Self.BioHash*PI/2);
Self.Patience := Sin(Self.BioHash*PI/1);
Self.SetupBiometrics();
Self.Debug := Debug;
Self.ReturnToTab := ReturnToTab;
end;
Procedure RAntiban.Init(Skill: TSkillIndex; ReturnToTab: Boolean = True; LogSize:Int32=5; Debug: Boolean = False); overload;
begin
Self.Init([Skill], ReturnToTab, LogSize, Debug);
end;
{
Deep copy of the antiban structure
}
function RAntiban.Copy(): RAntiban; constref;
begin
Result := Self;
Result.ActiveSkills := System.Copy(Self.ActiveSkills);
Result.Tasks := System.Copy(Self.Tasks);
Result.Breaks := System.Copy(Self.Breaks);
Result.TasksDone := System.Copy(Self.TasksDone);
end;
{
Sets up two variables Patience and an Endurance, based on your characters
nickname. These two factors are used within Energy calculation to make it
unique to you.
Patience (Energy gained from a break will..):
High: Drop of more slowly, but drops harder near the end (2-4 hours, see Endurance).
Low: Drop of faster, but gradually drop less of near the end.
Endurance:
- Energy from a break last 2-4 hours, depending on endurance (0..1).
High: You generally lasts longer before dropping off. Max endurance means
the bot can run for a full 24 hours before energy is depleted.
Low: You generally drop off faster. Min endurance means the bot can
only run for 16 hours before energy is depleted.
}
procedure RAntiban.SetupBiometrics();
var
h,i:UInt32;
k: string;
begin
k := RSPlayer.Me.Name;
h := $811C9DC5;
for i:=1 to Length(k) do
h := (h * $1000193) xor Ord(k[i]);
Self.BioHash := h / $FFFFFFFF;
Self.Endurance := Cos(Self.BioHash*PI/2);
Self.Patience := Sin(Self.BioHash*PI/1);
end;
{
A 64bit timer for runtime, so that we can do long proggies without hickups
}
function RAntiban.TimeRunning: Int64; constref;
begin
Result := GetTimeRunning;
end;
function RAntiban.TimeRunningWithoutBreaks: Int64; constref;
begin
Result := Self.TimeRunning() - Self.TotalBreakTime;
end;
{
Returns the time running at the given time of day.
}
function RAntiban.TimeRunningAtClock(TimeOfDay: String; StVar: String='00:00'): Int64;
var
res: TDateTime;
begin
res := (Date() + StrToTime(TimeOfDay)) - Now();
if (res < 0) then res += 1;
Result := Self.TimeRunning() + Trunc(res * 86400 * 1000);
Result += Trunc(srl.GaussRand(0, StrToTime(StVar) * 86400 * 1000));
Result := Max(0, Result);
end;
{
Debugs the latest antiban task done, and stores it in the logg.
}
procedure RAntiban.DebugNote(s: String; AddToList:Boolean=True);
var
text: String;
begin
text := '['+FormatDateTime('hh:mm:ss', Now())+']' + s;
if Self.Debug then
WriteLn(text);
if AddToList then
begin
Self.TasksDone += text;
if Length(Self.TasksDone) > Self.HistorySize then
Self.TasksDone.Del(0);
end;
end;
{
Used to add an antiban task.
The task How often Variation (0..1)
Example: Antiban.AddTask([@Antiban.LoseFocus, FIVE_MINUTES, 0.25]);
}
procedure RAntiban.AddTask(Task: RAntibanTask);
begin
with Task do
begin
if StdVar = 0 then StdVar := 0.25;
NextAtTime := Self.TimeRunning() + srl.GaussRand(Interval, Interval * StdVar);
end;
Self.Tasks += Task;
end;
{
Used to add an antiban break.
Example: Run every Lasts for? Logout chance Variation (0..1)
Antiban.AddBreak([ONE_HOUR, FIVE_MINUTES, 0.05, 0.25]);
Note:
Breaks should always be added in the order most often to least often, but
where a sleep kind of break is always the last addition.
}
procedure RAntiban.AddBreak(Task: RBreakTask);
begin
with Task do
begin
if StdVar = 0 then StdVar := 0.1;
NextAtTime := Self.TimeRunning() + Abs(srl.GaussRand(Interval, Interval * StdVar));
end;
Self.Breaks += Task;
end;
{
Internally used to reset all antiban timers to a random start
time after a break
}
procedure RAntiban.RestarRAntiban;
var i: Int32;
begin
for i:=0 to High(Self.Tasks) do
with Self.Tasks[i] do
NextAtTime := Self.TimeRunning() + Random() * Interval;
end;
{
Call this method to do a break. If one of those has pased it's time,
then it will be executed, and the method will return `True`.
Returns the id of the break executed.
}
function RAntiban.DoBreak(out BreakID: Int32): Boolean;
var
i, j, PauseStart: Int32;
procedure OffsetBreaks(UpTo, Length: Int32);
begin
for j:=0 to UpTo do
Self.Breaks[j].NextAtTime += Length;
end;
begin
BreakID := -1;
for i:=High(Self.Breaks) downto 0 do
if Self.TimeRunning() > Self.Breaks[i].NextAtTime then
with Self.Breaks[i] do
begin
writeln('Taking break...');
NextAtTime := Self.TimeRunning() + Abs(srl.GaussRand(Interval, Interval * StdVar));
PauseStart := Self.TimeRunning();
Self.TakeBreak(Self.Breaks[i]);
OffsetBreaks(i, Self.TimeRunning() - PauseStart);
PrevAtTime := Self.TimeRunning();
Self.RestarRAntiban();
BreakID := i;
Exit(True);
end;
end;
function RAntiban.DoBreak(): Boolean; overload;
var _: Int32;
begin
Result := Self.DoBreak(_);
end;
{
Call this method to do an antiban (or a break if `CheckBreaks` is set).
If one of those has pased it's time, then it will be executed, and the
method will return `True`
}
function RAntiban.DoAntiban(CheckBreaks: Boolean = True): Boolean;
var i: Int32;
begin
// check for antiban
for i:=0 to High(Self.Tasks) do
if Self.TimeRunning() > Self.Tasks[i].NextAtTime then
with Self.Tasks[i] do
begin
if (@Condition <> nil) and (not Condition()) then
Continue;
Method();
NextAtTime := Self.TimeRunning() + srl.GaussRand(Interval, Interval * StdVar);
Result := True;
i := -1;
end;
// check for breaks
if CheckBreaks then
Result := Self.DoBreak();
end;
{
Check if the antiban has a `sleep` break added.
Note: Sleep is defined by being 5+ hours, and is the the last added break.
}
function RAntiban.HasSleep(): Boolean;
var zZz: Int32;
begin
zZz := High(Self.Breaks);
Result := (zZz >= 0) and ((Self.Breaks[zZz].Length) > 5*ONE_HOUR);
end;
{
Returns the ID of the sleep break, if there is one, otherwise -1.
Note: Sleep is defined by being 5+ hours, and is the the last added break.
}
function RAntiban.GetSleepId(): Int32;
var zZz: Int32;
begin
Result := -1;
zZz := High(Self.Breaks);
if (zZz >= 0) and ((Self.Breaks[zZz].Length) > 5*ONE_HOUR) then
Result := zZz;
end;
{
Internally used to compute Energy
- It checks how long it was since last break, returns the value in milliseconds
}
function RAntiban.TimeSinceBreak(LongerThan:Double=0): UInt64;
var i: Int32;
begin
for i:=0 to High(Self.Breaks) do
if (Self.Breaks[i].Length >= LongerThan) and (Self.Breaks[i].PrevAtTime >= Result) then
Result := Trunc(Self.Breaks[i].PrevAtTime);
Result := Self.TimeRunning() - Result;
end;
{
Internally used to compute Energy
- The method gathers the sum/length of pauses the past `Timespan`.
It only counts one of each type of pauses, so if you have a 5 min break that
runs every 10 minutes, it will only count the last executed one no matter timespan.
}
function RAntiban.BreaksPast(Timespan: Double): Int64;
var
XHoursAgo: Double := Self.TimeRunning() - Timespan;
active, started: Double;
i: Int32;
begin
Active := Min(Timespan, Self.TimeRunning());
for i:=0 to High(Self.Breaks) do
if Self.Breaks[i].PrevAtTime >= XHoursAgo then
begin
if Self.Breaks[i].PrevAtTime = 0 then
Continue;
started := Max(XHoursAgo, Self.Breaks[i].PrevAtTime - Self.Breaks[i].Length);
Active -= Self.Breaks[i].PrevAtTime - started;
end;
Result := Round(Min(Timespan, Timespan - Active));
end;
{
Returns the current energy of your character, based on recent breaks, and runtime.
You should start with near 100% energy, can be a little less.
This method does expect your bot to have a sleep break (5+ hours), otherwise it
wont be worth a lot.
}
function RAntiban.EnergyLevel(): Double;
var
zz: Int32;
t,eLeftFromSleep, eLeftFromBreak, eBreakValue: Double;
PastX: Double;
begin
PastX := (2+(2*Self.Endurance)) * ONE_HOUR;
eLeftFromBreak := Max(0,Min(1,1-Power((Self.TimeSinceBreak() / (18*ONE_HOUR)), 1/3)));
eBreakValue := Power(Self.BreaksPast(PastX) / (PastX), 1/3);
Result := Max(0,Min(1,(eLeftFromBreak + eBreakValue) / (2.1 - (0.5*Self.Patience))));
if Self.HasSleep() then // if we have a sleep
begin
zz := High(Self.Breaks);
t := Self.TimeRunning() - Trunc(Self.Breaks[zz].PrevAtTime);
eLeftFromSleep := Max(0,Min(1,t / ((16*ONE_HOUR) + (8*ONE_HOUR*Self.Endurance))));
eLeftFromSleep := Power(1-eLeftFromSleep, 1/4);
Result := eLeftFromSleep * Result;
end;
Result := 100 * Result;
end;
// Energy based wait, if energy is 100% then wait length is 0.
// It scales exponentially by default (Exp = 0.667):
// 97% energy = 2% of the length
// 75% energy = 17% of the length
// 50% energy = 37% of the length
// 25% energy = 60% of the length
// 10% energy = 78% of the length
// 5% energy = 86% of the length
procedure RAntiban.WaitFatigue(t: Double; Exp: Double=0.667);
begin
Wait(Trunc(t * (1-Power(Max(0.0001, Self.EnergyLevel()/100), Exp))));
end;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Various predefined tasks you can use as antiban.
//
// You can also create your own tasks in your script and pass that to
// Antiban.AddTask, just follow the same structure as these methods bellow.
//
procedure RAntiban.LoseFocus();
begin
DebugNote('[RND] Losing focus');
if (EIOS_HasFocus(R_EIOS)) then
EIOS_LoseFocus(R_EIOS);
WaitEx(15000, 2000);
if (not EIOS_HasFocus(R_EIOS)) then
EIOS_GainFocus(R_EIOS);
//Login Player
end;
procedure RAntiban.HoverPlayers();
var
Players: Array of RSPlayer;
I, T, W, H: Integer;
Pnt: TPoint;
begin
DebugNote('[RND] Hovering players');
Players := RSPlayer.AllPlayers;
if (High(Players) <= 1) then
Exit;
I := Random(0, High(Players));
if (Players[I].Name = RSPlayer.Me.Name) then
begin
T := I;
repeat
I := Random(0, High(Players));
until (I <> T);
end;
Pnt := Players[I].Tile.ToLocal.TileToMS;
if (R_MainscreenBounds.Contains(Pnt)) then
begin
Mouse.Move(Pnt);
Wait(120, RandomRange(240, 2400));
case Random(100) of
0..79: Mouse.Click(MOUSE_RIGHT);
end;
Wait(560, Random(5130, 13015));
GetClientDimensions(W, H);
Mouse.Move(Random(0, W), Random(0, H));
end;
end;
Procedure RAntiban.HoverSkill;
var
Current: Integer;
begin
DebugNote('[RND] Hovering Skill');
Current := R_CurrentGameTab();
if (R_OpenGameTab(GAMETAB_STATS)) then
begin
Mouse.Move(R_GetSkillTabBounds(self.ActiveSkills[0]), False);
WaitEx(15000,1400);
if ReturnToTab then
if (Current = -1) then
R_OpenGameTab(GAMETAB_STATS) else R_OpenGameTab(Current);
end;
end;
Procedure RAntiban.CheckSkill;
var
Current: Integer;
begin
DebugNote('[RND] Checking Skill');
Current := R_CurrentGameTab();
if (R_OpenGameTab(GAMETAB_STATS)) then
begin
WaitEx(15000,1400);
if ReturnToTab then
if (Current = -1) then
R_OpenGameTab(GAMETAB_STATS) else R_OpenGameTab(Current);
end;
end;
Procedure RAntiban.CheckStats;
var
Current: Integer;
begin
DebugNote('[RND] Check Skill Stats');
Current := R_CurrentGameTab();
if (R_OpenGameTab(GAMETAB_STATS)) then
begin
WaitEx(RandomRange(1500, 3000),RandomRange(300, 600));
if ReturnToTab then
if (Current = -1) then
R_OpenGameTab(GAMETAB_STATS) else R_OpenGameTab(Current);
end;
end;
Procedure RAntiban.RandomCompass();
begin
DebugNote('[RND] Randomizing Compass');
R_SetCameraAngle(Random(0, 360));
end;
Procedure RAntiban.RandomHeight();
begin
DebugNote('[RND] Randomizing Camera Height');
R_SetCameraAngle(Random(0, 100));
end;
procedure RAntiban.OpenRandomTab();
begin
DebugNote('[RND] Open Random Tab');
R_OpenGameTab(Random(0, High(R_GameTabIDs)));
end;
procedure RAntiban.VeryShortBreak();
begin
DebugNote('[RND] Taking a breather');
if(Random(2)=0) then
if (EIOS_HasFocus(R_EIOS)) then
EIOS_LoseFocus(R_EIOS);
WaitEx(30000,5000);
if (not EIOS_HasFocus(R_EIOS)) then
EIOS_GainFocus(R_EIOS);
//Login Player;
Wait(60,600, wdLeft);
if Random(4) = 0 then self.CheckStats();
end;
procedure RAntiban.FiveMinBreak();
begin
Self.TakeBreak([0, FIVE_MINUTES, 0.50, 0.50]);
end;
procedure RAntiban.DoMiscStuff();
begin
DebugNote('[RND] Doing misc stuff');
for 0 to Random(2) do
begin
if Random(3) = 0 then
R_OpenGameTab(Random(0, High(R_GameTabIDs)));
WaitEx(1500,200);
if(Random(8) = 0) then
begin
if(Random(2) = 0) then
if (EIOS_HasFocus(R_EIOS)) then
EIOS_LoseFocus(R_EIOS);
WaitEx(40000,4500);
if (not EIOS_HasFocus(R_EIOS)) then
EIOS_GainFocus(R_EIOS);
end;
if(Random(3) = 0) then
begin
self.CheckStats();
WaitEx(2000,200);
end;
end;
end;
{
Internally used to take a break:
- It pauses for the time specified in the Task +/- Task.StdVar
- Can log out if LogoutChance is hit (0..1), and if rsclient is used an equal
test will be computed for it with the same chance as `LogoutChance` for losing focus.
}
procedure RAntiban.TakeBreak(Task: RBreakTask);
var
Time: Int64;
begin
Time := Abs(Round(srl.GaussRand(Task.Length, Task.Length * Task.StdVar)));
Self.TotalBreakTime := Self.TotalBreakTime + Time;
Self.DebugNote('[BREAK] Pausing for '+ srl.MsToTime(Time, Time_Formal_Long));
if(Random() < Task.LogoutChance) then R_Logout();
if(Random() < Task.LogoutChance) then self.LoseFocus();
while (Time > 0) do
begin
Wait(Trunc(Min(ONE_MINUTE*5, Time)));
Time -= Min(ONE_MINUTE*5, Time);
Self.DebugNote('[BREAK] '+ srl.MsToTime(Time, Time_Formal_Long)+' left', False);
end;
if (not EIOS_HasFocus(R_EIOS)) then
EIOS_GainFocus(R_EIOS);
//Player.Login;
Wait(60,600, wdLeft);
if Random(10)=0 then Self.CheckSkill();
end;
function RAntiban.TimeUntilBreak(Break: RBreakTask; Format: TTimeFormat = TIME_BARE): String;
begin
if (Break.NextAtTime - TimeRunning() <= 0) then
Result := 'Now'
else
Result := srl.MsToTime(Round(Break.NextAtTime - TimeRunning()), Format);
end;