1- (*
2- # Antiban
3- Methods to handle antiban.
4- *)
1+
52
63{$DEFINE WL_ANTIBAN_INCLUDED}
74{$IFNDEF WL_OSR}
4138 Next: Double;
4239 end;
4340
44- (*
45- ## TAntiban
46- Main record to handle the built-in WaspLib antiban.
47- *)
41+
4842 TAntiban = record
4943 DoingAntiban: Boolean;
5044 Debugging: Boolean;
@@ -122,28 +116,7 @@ begin
122116end;
123117
124118
125- (*
126- ## Antiban.AddTask
127- ```pascal
128- procedure TAntiban.AddTask(method: TAntibanMethod; interval: Double; randomness: Double = 0.2);
129- ```
130- Schedule a antiban task.
131- An antiban task can be any procedure but they should be short actions that won't
132- break your main script.
133-
134- `method` is a pointer to the task you want to perform. WaspLib includes a couple of them but you may make your own if you want.
135-
136- `interval` is the aproximate interval of time that has to pass for the antiban
137- task to occur and it will be repeated everytime that the interval has passed
138- and the antiban is checked with {ref}`Antiban.DoAntiban`.
139119
140- This task will only occur when **TAntiban.DoAntiban** is called.
141-
142- Example:
143- ```pascal
144- Antiban.AddTask(@Antiban.HoverSkills, 15 * ONE_MINUTE); //Every 15 minutes the script will run Antiban.HoverSkills().
145- ```
146- *)
147120procedure TAntiban.AddTask(method: TAntibanMethod; interval: Double; randomness: Double = 0.2);
148121var
149122 len: Integer;
@@ -153,26 +126,7 @@ begin
153126 Self._UpdateTask(len, @method, interval, randomness);
154127end;
155128
156- (*
157- ## Antiban.AddBreak
158- ```pascal
159- procedure TAntiban.AddBreak(interval, length: Double; randomness: Double = 0.2; logoutChance: Double = 0.33);
160- ```
161- Schedule a break. Breaks can be of short or medium length and should be shorter than any sleep breaks.
162-
163- `interval` is the aproximate interval of time that has to pass for the break to
164- occur and it will be repeated everytime that interval passes and the antiban is
165- checked either with {ref}`Antiban.DoBreak` or {ref}`Antiban.DoAntiban`.
166-
167- `length`, `randomness` and `logoutChance` are the same as {ref}`Antiban.AddSleep`.
168-
169- This break will only occur when {ref}`Antiban.DoAntiban` is called.
170129
171- Example:
172- ```pascal
173- Antiban.AddBreak(30 * ONE_MINUTE, 5 * ONE_MINUTE); //Every 30 minutes the script will take a 5 minute break, subject to variance from the randomness variable.
174- ```
175- *)
176130procedure TAntiban.AddBreak(interval, length: Double; randomness: Double = 0.2; logoutChance: Double = 0.33);
177131var
178132 len: Integer;
@@ -182,34 +136,7 @@ begin
182136 Self._UpdateBreak(len, interval, length, randomness, logoutChance);
183137end;
184138
185- (*
186- ## Antiban.AddSleep
187- ```pascal
188- procedure TAntiban.AddSleep(time: String; length: Double; randomness: Double = 0.1; logoutChance: Double = 0.5);
189- ```
190- Schedule a sleep break. A sleep break is a large break, it can be any length but
191- it's usually the several hours and also the largest one/ones.
192-
193- `time` is the aproximate time you want the break to occur and should be written
194- in a "bare" time format (00:00:00).
195-
196- `length` is how long we will sleep for in milliseconds.
197-
198- `randomness` is self explanatory, gives variance to the time our script will
199- sleep at and it's length too.
200- One thing to keep in mind is that randomness only affects time past `time`.
201- In other words, you will never sleep before `time`.
202-
203- `logoutChance` is the probability of logging out for the sleep break or to
204- simply afk and logout from inactivity.
205139
206- This sleep break will only occur when {ref}`Antiban.DoAntiban` is called and our sleep break is due.
207-
208- Example:
209- ```pascal
210- Antiban.AddSleep('01:30:45', 8 * ONE_HOUR, 0.1, 0.8); //At 01:30:45 on our computer time the script will take a break for 8 hours, subject to variance from the randomness variable.
211- ```
212- *)
213140procedure TAntiban.AddSleep(time: String; length: Double; randomness: Double = 0.1; logoutChance: Double = 0.5);
214141var
215142 len: Integer;
@@ -220,15 +147,7 @@ begin
220147end;
221148
222149
223- (*
224- ## Antiban.TakeBreak
225- ```pascal
226- procedure TAntiban.TakeBreak(var task: TBreakTask);
227- ```
228- Internal function used by {ref}`Antiban.DoAntiban` and is responsible for
229- performing the specified break `task`.
230- In other words, this is what makes the script take the break.
231- *)
150+
232151procedure TAntiban.TakeBreak(var task: TBreakTask);
233152var
234153 countdown: TCountDown;
@@ -281,15 +200,7 @@ begin
281200 task.Next := GetTimeRunning() + Abs(GaussRand(task.Interval, task.Interval * task.StdVar));
282201end;
283202
284- (*
285- ## Antiban.TakeSleep
286- ```pascal
287- procedure TAntiban.TakeSleep(var task: TSleepTask);
288- ```
289- Internal function used by {ref}`Antiban.DoAntiban` and is responsible for
290- performing the specified sleep `task`.
291- In other words, this is what makes the script take the sleep break.
292- *)
203+
293204procedure TAntiban.TakeSleep(var task: TSleepTask);
294205var
295206 countdown: TCountDown;
@@ -344,22 +255,7 @@ begin
344255end;
345256
346257
347- (*
348- ## Antiban.DoTask
349- ```pascal
350- function TAntiban.DoTask(): Boolean;
351- ```
352- Checks for scheduled antiban tasks, if any is due it will do it.
353-
354- You should only call this when taking doing an antiban task won't break your script.
355258
356- Returns true if a task was performed.
357-
358- Example:
359- ```pascal
360- Antiban.DoTask();
361- ```
362- *)
363259function TAntiban.DoTask(): Boolean;
364260var
365261 i: Int32;
@@ -394,22 +290,7 @@ begin
394290 activeTasks[i]^.Countdown.Resume();
395291end;
396292
397- (*
398- ## Antiban.DoBreak
399- ```pascal
400- function TAntiban.DoBreak(): Boolean;
401- ```
402- Checks for scheduled breaks, if any is due it will take it.
403-
404- You should only call this when taking a break won't break your script.
405-
406- Returns true if a break was taken.
407293
408- Example:
409- ```pascal
410- Antiban.DoBreak();
411- ```
412- *)
413294function TAntiban.DoBreak(): Boolean;
414295var
415296 i: Integer;
@@ -427,22 +308,7 @@ begin
427308 end;
428309end;
429310
430- (*
431- ## Antiban.DoSleep
432- ```pascal
433- function TAntiban.DoSleep(): Boolean;
434- ```
435- Checks for scheduled sleep breaks, if any is due it will take it.
436-
437- You should only call this when taking a sleep break won't break your script.
438-
439- Returns true if a sleep break was taken.
440311
441- Example:
442- ```pascal
443- Antiban.DoSleep();
444- ```
445- *)
446312function TAntiban.DoSleep(): Boolean;
447313var
448314 i: Integer;
@@ -461,27 +327,7 @@ begin
461327end;
462328
463329
464- (*
465- ## Antiban.DoAntiban
466- ```pascal
467- function TAntiban.DoAntiban(checkTasks, checkBreaks, checkSleeps: Boolean = True): Boolean;
468- ```
469- This should be called in your script when antiban sleeps, breaks or tasks won't
470- break your script.
471-
472- When this is called, the setup sleep breaks, breaks and tasks will be checked,
473- if enough time has passed to perform any of them
474- (subject to the parameters you pass in too), they will be performed, otherwise,
475- nothing will happen.
476-
477- Example:
478- ```pascal
479- Antiban.AddTask(15 * ONE_MINUTE, @Antiban.HoverSkills);
480-
481- while True do //Infinite loop
482- Antiban.DoAntiban(); //Antiban.HoverSkills will be called every time 15 minutes passed when this is called.
483- ```
484- *)
330+
485331function TAntiban.DoAntiban(checkTasks, checkBreaks, checkSleeps: Boolean = True): Boolean;
486332begin
487333 if Self.DoingAntiban then
@@ -512,44 +358,19 @@ begin
512358end;
513359
514360
515- (*
516- ## Antiban.TimeUntilBreak
517- ```pascal
518- function TAntiban.TimeUntilBreak(constref task: TBreakTask; fmt: String = TIME_FORMAL): String;
519- ```
520- Check how much time is left until the specified break `task` should be taken.
521- *)
361+
522362function TAntiban.TimeUntilBreak(constref task: TBreakTask; fmt: String = TIME_FORMAL): String;
523363begin
524364 Result := FormatMilliseconds(Max(0, Round(task.Next - GetTimeRunning())), fmt);
525365end;
526366
527- (*
528- ## Antiban.TimeUntilSleep
529- ```pascal
530- function TAntiban.TimeUntilSleep(constref task: TSleepTask; fmt: String = TIME_FORMAL): String;
531- ```
532- Check how much time is left until the specified sleep break `task` should be taken.
533- *)
367+
534368function TAntiban.TimeUntilSleep(constref task: TSleepTask; fmt: String = TIME_FORMAL): String;
535369begin
536370 Result := FormatMilliseconds(Max(0, Round(task.Next - GetTimeRunning())), fmt);
537371end;
538372
539- (*
540- ## Antiban.SimulateBreaks
541- ```pascal
542- procedure TAntiban.SimulateBreaks(bottingDays: UInt64 = 1000);
543- ```
544- Performs a simulation of `bottingDays` amount of days with the currently setup
545- breaks and prints the results.
546-
547- Example
548- ```pascal
549- Antiban.AddBreak(30 * ONE_MINUTE, 5 * ONE_MINUTE);
550- Antiban.SimulateBreaks();
551- ```
552- *)
373+
553374procedure TAntiban.SimulateBreaks(bottingDays: UInt64 = 1000);
554375var
555376 active, inactive, len, prev: Double;
@@ -586,8 +407,5 @@ begin
586407end;
587408
588409var
589- (*
590- ## Antiban variable
591- Global {ref}`TAntiban` variable.
592- *)
410+
593411 Antiban: TAntiban;
0 commit comments