|
CodeSamples
Snippets of code to get you started with TibiaAPI.
Table of Contents
NoteMost of these samples assume you have imported Tibia and Tibia.Objects: C# using Tibia; using Tibia.Objects; VB.Net Imports Tibia Imports Tibia.Objects Get a client object to work withC# Client client = Util.ClientChooser.ShowBox();
if (client == null)
{
MessageBox.Show("No active client.");
Application.Exit();
}VB.Net Dim client as Client = ClientChooser.ShowBox()
If client Is Nothing Then
MsgBox("No active client.")
Application.[Exit]()
End IfUsing the hook proxyVB.Net Imports Tibia.Objects
Imports Tibia.Packets
Imports Tibia.Util
Public Class MainForm
Private client As Client
Private proxy As HookProxy
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
client = ClientChooser.ShowBox()
proxy = New HookProxy(client)
AddHandler proxy.ReceivedCreatureSpeechIncomingPacket, AddressOf ReceivedCreatureSpeechIncomingPacket
End Sub
Private Function ReceivedCreatureSpeechIncomingPacket(ByVal p As IncomingPacket)
Dim packet As Incoming.CreatureSpeechPacket = p
MessageBox.Show(packet.SenderName & ": " & packet.Message)
Return True
End Function
End ClassGetting player information from the Tibia websiteC# // Set the textbox uxText to equal the profession of the player Bubble
// This method is asynchronous, that is why we have to supply a
// callback to get the data. It does not block your GUI if the
// request take a while.
private void uxButton_Click(object sender, EventArgs e)
{
Website.LookupPlayer("Bubble", delegate(Website.CharInfo i)
{
uxText.Invoke(new EventHandler(delegate
{
uxText.Text = i.Profession;
}));
});
}Parsing commands from the playerC# // Put this after you start the proxy client.Proxy.ReceivedPlayerSpeechOutgoingPacket += new Tibia.Util.Proxy.OutgoingPacketListener(Proxy_ReceivedPlayerSpeechOutgoingPacket); // This simple example assumes you have a textbox named uxText,
// to which it will append the command your client sent
private bool Proxy_ReceivedPlayerSpeechOutgoingPacket(Tibia.Packets.OutgoingPacket packet)
{
Tibia.Packets.Outgoing.PlayerSpeechPacket p = (Tibia.Packets.Outgoing.PlayerSpeechPacket)packet;
if (p.Message.StartsWith("/"))
{
uxText.Invoke(new EventHandler(delegate
{
uxText.AppendText("Command: " + p.Message.Substring(1));
uxText.AppendText(Environment.NewLine);
// Scroll to the bottom of the text box
uxText.SelectionStart = uxText.Text.Length;
uxText.ScrollToCaret();
}));
// Don't send the command to the server
return false;
}
return true;
}Using the proxyC# // Start the proxy and attach event handlers
// Put this in Form_Load
client.StartProxy();
client.Proxy.SplitPacketFromServer += Proxy_SplitPacketFromServer;
client.Proxy.SplitPacketFromClient += Proxy_SplitPacketFromClient;
// These sample event handlers are other methods, outside Form_Load
// LogPacket assumes you have a textbox called uxLog
void Proxy_SplitPacketFromClient(byte type, byte[] data)
{
LogPacket(data, "CLIENT");
}
void Proxy_SplitPacketFromServer(byte type, byte[] data)
{
LogPacket(data, "SERVER");
}
private void LogPacket(byte[] packet, string from)
{
uxPackets.Invoke(new EventHandler(delegate
{
string s = "from " + from + Environment.NewLine;
s += Packet.ByteArrayToHexString(packet) + Environment.NewLine + Environment.NewLine;
uxLog.Text += s;
}));
}Perform name spy or level spyC# // Show names on other floors client.Map.ShowNames(true); // Move the screen to the floor below client.Map.ShowFloor(-1, true); VB.Net ' Show names on other floors client.Map.ShowNames(true) ' Move the screen to the floor below client.Map.ShowFloor(-1, true) Setup a global mouse hookThe following code will show you how to set up a global mouse hook and capture when the ButtonDown event is raised C# // Enable mouse hook and set the button down event to a function
if (!MouseHook.Enabled) {
MouseHook.Enable();
MouseHook.ButtonDown = GlobalMouseDown;
}
// The function to handle the button down event
public bool GlobalMouseDown(System.Windows.Forms.MouseButtons button)
{
if (button == Windows.Forms.MouseButtons.Left) {
MessageBox.Show("Left mouse button was clicked down.");
}
return true;
}VB.Net ' Enable mouse hook and set the button down event to a function
If Not MouseHook.Enabled Then
MouseHook.Enable()
MouseHook.ButtonDown = AddressOf GlobalMouseDown
End If
' The function to handle the button down event
Public Function GlobalMouseDown(ByVal button As System.Windows.Forms.MouseButtons)
If button = Windows.Forms.MouseButtons.Left Then
MessageBox.Show("Left mouse button was clicked down.")
End If
Return True
End FunctionSetup a global keyboard hookPut the following in a button's click event. This example captures the hotkey Ctrl + Alt + A in the Tibia client only (doesn't let it go to the client). All other keypresses, client or otherwise, are ignored. C# if (!KeyboardHook.Enabled)
{
KeyboardHook.Enable();
KeyboardHook.Add(Keys.A, new KeyboardHook.KeyPressed(delegate()
{
if (client.IsActive)
{
if (KeyboardHook.Control && KeyboardHook.Alt)
{
string text = "You want to capture the hotkey " +
Tibia.KeyboardHook.KeyToString(Keys.A) + " in Tibia!";
MessageBox.Show(text);
return false;
}
}
return true;
}));
}
else
{
KeyboardHook.Disable();
}Connect to an OT ServerC# client.Login.SetOT("radonia.net", 7171);VB.Net client.Login.SetOT("radonia.net", 7171)Eat a mushroom in your inventoryC# client.Inventory.UseItem(Tibia.Constants.Items.Food.WhiteMushroom.Id); VB.Net client.Inventory.UseItem(Tibia.Constants.Items.Food.WhiteMushroom.Id) Attack the first rat found in the battelistC# client.BattleList.GetCreatures().Where(
creature => creature.Name.Equals("rat", StringComparison.CurrentCultureIgnoreCase).Attack();VB.Net client.BattleList.GetCreatures().Where(Function(creature) creature.Name.Equals("rat", StringComparison.CurrentCultureIgnoreCase).Attack()Change your players outfit type and addonC# Player player = client.getPlayer(); player.OutfitType = Tibia.Constants.OutfitType.BeggarMale; player.Addon = Tibia.Constants.OutfitAddon.Both; VB.Net Dim player As Player = client.getPlayer() player.OutfitType = Tibia.Constants.OutfitType.BeggarMale player.Addon = Tibia.Constants.OutfitAddon.Both Replace all the trees with small fir treesC# client.Map.replaceTrees(); VB.Net client.Map.replaceTrees() Make a simple lighthackC# Player player=client.GetPlayer(); player.Light = Tibia.Constants.LightSize.Full; player.LightColor = Tibia.Constants.LightColor.White; Draw players hitpoints in percents above his nameC# Player player = client.GetPlayer(); client.Screen.DrawCreatureText(player.Id, new Location(0, -10, 0), Color.Green, Tibia.Constants.ClientFont.NormalBorder, player.HPBar.ToString() + "%"); |
Sign in to add a comment
Good good. !!!
Good work.. ^^
How to do lighthack, keep updating diffrent kind of small cheat. Realy like this projekt, best ever! Love u man!
I cant get the dll imported into C#.net, the example projects dont open properly :/
Any help?
im a terrible noob, but can someone also show how to do this in C++?
you can rewrite the entire api to the native C++ =)
i'm tring to do this .. but .. it's hard :( .. i have emulated all of C# functions used in the library but now .. i need to correct 1198 errors :(
ihul ;D
Please update the examples!