Auto login after critical

Does anyone have disconnections or critical errors? Well, it’s time to get rid of this annoying issue. You can use the following script to control ‘all’ your bot accounts (which must be specified), and it will automatically log them in in case of a disconnection. Note these lines in the txt file:

SetLength(Accounts, 2);
addListener(0, 'Pinokio', 'test', 'test');
addListener(1, 'Astron', 'admin', 'admin');

I have specified two of my accounts. If you have for example, 5 bot accounts, you will need to SetLength to 5 and then add the listener for each of your accounts. The structure of the addListener function is as follows: addListener(INDEX_OF_ARRAY, CHAR_NAME, ACCOUNT_USERNAME, ACCOUNT_PASSWORD). You can put the code into any account and run it. It will loop all the user names you have specified as a listener.

uses
  SysUtils;

const
  GamePath = '"C:\Program Files (x86)\Lineage II\system\L2.exe"';

type
  TAccountInfo = record
    CharName: string;
    UserName: string;
    Password: string;
  end;

var
  Accounts: array of TAccountInfo;

function ShellExecuteW(hwnd: integer; lpOperation, lpFile, lpParameters, lpDirectory: PChar; nShowCmd: integer): integer; stdcall;
  external 'Shell32.dll';

procedure GameClose(charName: string);
begin
  if Assigned(GetControl(charName)) then
    GetControl(charName).GameClose;
  Delay(1000);
end;

procedure StartL2;
begin
  ShellExecuteW(0, 'open', PChar(GamePath), nil, nil, 0);
  Delay(10000);
end;

procedure UseKey(charName, key: string; ms: integer = 2000);
begin
  GetControl(charName).UseKey(key);
  Delay(ms);
end;

procedure ReconnectGame(charName, username, password: string);
begin
  GameClose(charName);
  StartL2;
  GetControl(charName).EnterText(username);
  UseKey(charName, 'Tab', 300);
  GetControl(charName).EnterText(password);
  UseKey(charName, 'Enter');
  UseKey(charName, 'Enter');
  UseKey(charName, 'Enter');
  UseKey(charName, 'Enter');
  GetControl(charName).FaceControl(0, true);
end;

procedure Monitor;
var
  i: Integer;
begin
  Print('Monitor has started...');
  while True do
  begin
    Delay(3000);
    for i := Low(Accounts) to High(Accounts) do
    begin
      if (not Assigned(GetControl(Accounts[i].CharName))) or (GetControl(Accounts[i].CharName).Status = lsOff) or (GetControl(Accounts[i].CharName).Status = lsOffline) then
      begin
        Print(Accounts[i].CharName + ' disconnected. Trying auto-login...');
        if Assigned(GetControl(Accounts[i].CharName)) then
          GetControl(Accounts[i].CharName).FaceControl(0, False);
        ReconnectGame(Accounts[i].CharName, Accounts[i].UserName, Accounts[i].Password);
      end;
    end;
  end;
end;

procedure addListener(arrIndex:integer; charName,username,password:string);
begin
  Accounts[arrIndex].CharName := charName;
  Accounts[arrIndex].UserName := username;
  Accounts[arrIndex].Password := password;
end;
begin
  SetLength(Accounts, 2);
  addListener(0,'Pinokio','test','test'); // index of array , char name, account usernmame, account password
  addListener(1,'Astron','admin','admin');  // index of array , char name, account usernmame, account password
  

  Script.NewThread(@Monitor);
  Delay(-1);
end.

I made it using the free version of adrenaline. Once the bot succeeds in logging in a character, it will automatically ‘start’ the bot (as if we were pressing the ‘End’ key).

Dont forget to set your own path to the l2.exe: GamePath = '"C:\Program Files (x86)\Lineage II\system\L2.exe"';

Author: Velmsun