18 de nov. de 2012

Criando um Mini-Bot de Tibia

Inicialmente vou dar logo os créditos de onde tirei o conteúdo:
Kimoszin - www.tibiaking.com
Quando eu comecei a utilizar o delphi esse foi o primeiro aplicativo que criei exatamente com esse tutorial, espero que ajude alguém!

Agora vamos ao que interessa:
Nesse mini-bot você terá um mana trainer, um anti-kick e um eat food!



Componentes, vamos precisar de:

1 TGroupBox
1 TButton
2 TLabeledEdit
2 TCheckBox
1 TCombobox
2 TLabel
4 TTimer

Renomeando componentes, para renomear você deve ir ate a propriedade name:

Button -> StartButton
Timer1 -> CastSpell
Timer2 -> EndereçoTimer3 -> Kick
Timer4 -> Food
LabeledEdit1 -> Spell
LabeledEdit2 -> Mana

Arrumando Componentes, quando já estiverem renomeados:

CastSpell.Enabled.False CastSpell.Interval.700
Kick.Enabled.False
Kick.Interval.60000
Food.Enabled.False
Food.Interval.30000
Combobox1.Style.csDropDownListForm1.Caption 'Escolha um Nome para o Bot'

Variáveis Globais, declare embaixo do Form1 : TForm1
PH : THandle;
PID, ThID: DWORD;
H : THandle;

Variaveis Globais, declare embaixo do Form1 : TForm1
PH : THandle;
PID, ThID: DWORD;
H : THandle;

Funções usadas, declare elas embaixo do {$R *.dfm},

//Função para escrever na janela do Tibia
function say(mensagem: string):string;
 var
  h: HWND;
  letra: Integer;
  B: Byte;
 begin
  h := FindWindow(nil, 'tibia');
  for letra := 1 to Length(mensagem) do
  begin
        B := Byte(mensagem[letra]);
        SendMessage(h, WM_CHAR, B, 0);
  end;
        SendMessage(h, WM_CHAR, 13, 0);
  end;

//Função para ler endereço de memoria do Tibia
  function LerInt(Address: Integer): Integer;
var
  value:integer;
  ler :dword;
begin
H := FindWindow(nil, 'Tibia');
ThID := GetWindowThreadProcessId(H, @PID);
PH := OpenProcess(PROCESS_ALL_ACCESS,FALSE,PID);
ReadProcessMemory(PH, Ptr(Address), @Value, 4, Ler);
Result:=value;
end;

//Função para aperta uma determinada tecla na janela do Tibia
function hotkey(x :string): string;
         var
  h: HWND;
  i : integer;
begin
 if x ='F1' then
  i := 112
  else if x ='F2' then
  i := 113
  else if x ='F3' then
  i := 114
  else if x ='F4' then
  i := 115
  else if x ='F5' then
  i := 116
  else if x ='F6' then
  i := 117
  else if x ='F7' then
  i := 118
  else if x ='F8' then
  i := 119
  else if x ='F9' then
  i := 120
  else if x ='F10' then
  i := 121
  else if x ='F11' then
  i := 122
  else if x ='F12' then
  i := 123;

  h := FindWindow(nil, 'Tibia');  // acha a janela do tibia
  SendMessage(h, WM_KEYdown, i, 0);   //pressiona a tecla
  SendMessage(h, WM_KEYUP, i, 0);  //solta tecla
  end;

Depois de botar os componentes, renomeá-los e declarar as funções,
Vamos botar os devidos códigos nos respectivos componentes
Lembrando que é tudo dentro do begin e end, se tiver Var você deve excluir o begin, e adiciona-lo depois

CastSpell
if StrToInt(Label2.Caption) > (StrToInt(Mana.Text)) then
say(Spell.text)
// Se a mana do player for maior que a mana que foi digitada no component mana, entao vai falar a magia

Endereço
Label2.caption := IntToStr(Lerint($0081CE5C));
// Vai ler o endereço da mana do personagem e transforma em numero para o label2

Kick
Var
TibiaHandle : THandle;
begin
TibiaHandle:=FindWindow(nil,'Tibia'); // Pega a janela do Tibia
SendMessage(TibiaHandle,WM_KEYDOWN,VK_CONTROL,1); // Pressiona o Ctrl
SendMessage(TibiaHandle,WM_KEYDOWN,VK_UP,1); // Pressiona a tecla para cima
SendMessage(TibiaHandle,WM_KEYUP,VK_UP,1); // Libera a tecla
SendMessage(TibiaHandle,WM_KEYDOWN,VK_DOWN,1); // Pressiona a tecla para baixo
SendMessage(TibiaHandle,WM_KEYUP,VK_DOWN,1); // Libera a tecla
SendMessage(TibiaHandle,WM_KEYUP,VK_CONTROL,1); // Libera o Ctrl
end;

Food
hotkey(Combobox1.Text)
// Pressiona oque tiver no Texto do Combobox

StartButton
CastSpell.Enabled := not(CastSpell.Enabled);
Food.Enabled := not(Food.Enabled);
Kick.Enabled := not(Kick.Enabled);
if Checkbox1.checked then
Kick.Enabled := true
else
Kick.Enabled := false;
if Checkbox2.checked then
Food.Enabled := true
else
Food.Enabled := false;
if (Spell.Text <> '') and (Mana.Text <> '') then
CastSpell.Enabled := true
else
CastSpell.Enabled := false;
if (Kick.Enabled) or (Food.Enabled) or (CastSpell.Enabled) then
StartButton.Caption := 'Stop'
else
StartButton.Caption := 'Start';

Qualquer dúvida que tiverem estou aqui para esclarecer!
Novamente, Créditos: Kimoszin!

Atenciosamente,
Bruno Adriano

2 comentários:

  1. como voce pega as variaveis do cliente?
    Tipo a mana e tals? Quero por exemplo pegar o HP
    como faria?

    ResponderExcluir