Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../global.php(29) : eval()'d code(6) : eval()'d code on line 1

PHP Warning: Use of undefined constant misc - assumed 'misc' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant index - assumed 'index' (this will throw an Error in a future version of PHP) in ..../includes/class_bootstrap.php(1422) : eval()'d code(4) : eval()'d code on line 1

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6

PHP Warning: Use of undefined constant onlinestatusphrase - assumed 'onlinestatusphrase' (this will throw an Error in a future version of PHP) in ..../includes/class_core.php(4684) : eval()'d code on line 6
JAPI - Useful Tools for Tibia
Page 1 of 5 123 ... LastLast
Results 1 to 10 of 47

Thread: JAPI - Useful Tools for Tibia

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725

    JAPI - Useful Tools for Tibia

    So I've been working on a new project. I've named it JAPI (Josh's API).

    Current functions / features:

    ReaderClass:
    • Client Finder - getFirstClient(), getClientById(int ProcessID), getClients()
    • Read Memory - ReadInt32(UInt32 Address, uint length = 4), ReadString(UInt32 Address), ReadInt16(UInt32 Address), ReadInt64(UInt32 Address), ReadByte(UInt32 Address), ReadDouble(UInt32 Address), ReadBytes(UInt32 Address)
    • Read Individual Values: Hp(), MaxHp(), Mp(), MaxMp(), Soul(), X(), Y(), Z(), Cid(), Exp()
    • Read Group Values: GetPlayerInfo() returns Objects.Player() with .Hp, .MaxHp, .Mp, .MaxMp, .Soul, .X, .Y, .Z, .Cid, .Exp
    • Reads Name from Battle List: getMyName() returns string containing name.
    • Reads Battle List: BlGet() returns Battle list, for structures see Objects.BList.


    ControlWindow:
    • Send left/right click - LeftClick(int x, int y), RightClick(int x, int y)
    • Sends a string - SendKeys(string Message)
    • Finds a suitable hotkey from string - getHotKey(string Key) e.g getHotKey("F12") returns the keycode for F12 in UInt32 form.
    • Finds a suitable arrow key from string - getArrowKey(string Key) e.g getArrowKey("down") returns the keycode for down arrow in UInt32 form.
    • SendArrow(string Key) - Sends a keydown/keyup event to Tibia, for the entered key... E.g: SendArrow("down") will send down arrow key to Tibia.
    • SendHotkey(string Key) - Sends a hotkey event to Tibia, for the entered key... E.g: SendHotkey("F12") will send F12 hotkey to Tibia, works only for F1-F12, must be capital F.


    Objects:
    • World structure, incomplete, but contains a list of structures for BList, Player, Minimap, GUI - This will be used in UpdateWorld() once it's complete, to automatically update everything at once.
    • GUI Structure, incomplete, will contain all GUI shit, so you can store X, Y positions of GUI elements in Tibia.
    • Minimap structure, incomplete, will contain minimap shit, so you can store all minimap data.
    • BList structure, contains BList structure items, see Objects.cs for list of variables available at the minute.
    • Player structure, contains HP, HPMax, MP, MPMax, Soul, Cid, X, Y, Z, Exp.
    • HealRule structure, contains int MinHp, int MaxHp, int Mana, string Hotkey for heal rules, see example use in Form1.cs.


    Addresses:
    • Character info addresses, with an address for each element of the player data structure.
    • BListAddresses, with an address for each element of the BList structure.
    • MapAddresses, which is still empty since I haven't studied map reading for a while.


    I've been kinda busy putting all this together and grown a little tired of it, also hit a mental barrier, I can't seem to process much more at the minute due to lack of concentration. If anyone can find any use for it all of the code is available here, at googlecode. It is completely open source and anyone is free to use it as they wish.

    Also, I know I've called it an API when it has a GUI, and I realise the implications of this, but bare in mind that the plan is for it to be an API eventually, once I've finished it off and done with my testing. The current GUI contains a few tabs, each with a few controls in, I don't think the healer works, but everything else should (except the walker, obviously to anyone who bothers to look and see that there are no buttons for it). Some pictures are attached below, they are the 4 tab windows I've made, and they contain pretty much nothing of use. They do, however, demonstrate how you can use the API as intended.

    Use:
    I always got confused by TibiaAPI, and so I've made this work a little differently, you must declare a new instance of the Reader and ControlWindow classes, but not the Objects classes, e.g:
    ReaderClass Read = new ReaderClass();
    ControlWindow Ctrl = new ControlWindow();

    Then you can call my functions by doing:

    textBox1.Text = Read.Hp();

    or something like that. There are plenty of examples of how to extract the data with it, and if you know A* search algorithm and how to read the minimap, you may well be at the start of making your own bot.

    I will keep updating as I can, though it will be infrequent.

    Regards,
    Josh

    More pictures: http://tpforums.org/forum/threads/56...ll=1#post51337

    Updated images:



    Last edited by XtrmJash; 06-16-2013 at 09:50 PM.

  2. #2
    Super Moderator
    Join Date
    May 2007
    Posts
    1,191
    Sad to say, but the code is poorly structured. Also, this is not an API, it's an application.

  3. #3
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Quote Originally Posted by Blaster_89 View Post
    Sad to say, but the code is poorly structured. Also, this is not an API, it's an application.
    Would be helpful if you could explain what you mean by poorly structured...?

    Quote Originally Posted by ManInTheCave View Post
    Also, I know I've called it an API when it has a GUI, and I realise the implications of this, but bare in mind that the plan is for it to be an API eventually, once I've finished it off and done with my testing.
    It will be ported to another project at some point where it will become an API.

  4. #4
    Senior Member
    Join Date
    Jan 2012
    Posts
    417
    I noticed this is written everywhere:
    Code:
    Convert.ToUInt32(Tibia.MainModule.BaseAddress.ToInt32())
    Read it once and save in a field, property or whatever. Refresh it again only if you choose another tibia.

    Your ReadString function is a bit odd, because it reads up to 32 bytes and will return a string with strange length when you face bytes != 0 after your first byte = 0.

    you need get the first token, i.e, .Split('\0')[0]

  5. #5
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Quote Originally Posted by Blequi View Post
    I noticed this is written everywhere:
    Code:
    Convert.ToUInt32(Tibia.MainModule.BaseAddress.ToInt32())
    Read it once and save in a field, property or whatever. Refresh it again only if you choose another tibia.

    Your ReadString function is a bit odd, because it reads up to 32 bytes and will return a string with strange length when you face bytes != 0 after your first byte = 0.

    you need get the first token, i.e, .Split('\0')[0]
    Good points & well raised, I'll change the base address situation shortly, and will work on the string reading when I get chance... I'm assuming the string itself returns like this: "Player Name\0 XXXXXXXX", with those X's being either spaces, or the end of the name of the previous creature to be stored in that memory? I did have a function which first read the length of the memory used, then only read the bytes which it had to, but that's been lost in some old code and probably won't be recovered lol

    Edit: I've now fixed both of these issues, and it's working as I'd expect it to. Thanks again for your help!

    Edit 2: The healer is now working fully, as far as I can tell. I will do some testing on it tomorrow to make sure.
    Last edited by XtrmJash; 01-22-2013 at 07:31 PM.

  6. #6
    Super Moderator
    Join Date
    May 2007
    Posts
    1,191
    Quote Originally Posted by ManInTheCave View Post
    Would be helpful if you could explain what you mean by poorly structured...?
    You should split things up more, i.e. ReaderClass should imo be split into at least 4 classes.
    There should also be a collection class, that holds instances of everything you'd need (see the Client class of TibiaAPI).

    Also, you're not clearly dividing backend and frontend, you should not have to manually assign variables in a frontend that can easily be automated in the backend.

    Lastly, the thread you are creating to update your UI will use 100% of its resources (infinite while loop with no pauses), which is just a waste.
    You should also use try-catch in non-UI threads, because if an error happens in that thread, your whole application will crash.
    The code that is run inside that thread is also not thread-safe.

  7. #7
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Quote Originally Posted by Blaster_89 View Post
    You should split things up more, i.e. ReaderClass should imo be split into at least 4 classes.
    There should also be a collection class, that holds instances of everything you'd need (see the Client class of TibiaAPI).

    Also, you're not clearly dividing backend and frontend, you should not have to manually assign variables in a frontend that can easily be automated in the backend.

    Lastly, the thread you are creating to update your UI will use 100% of its resources (infinite while loop with no pauses), which is just a waste.
    You should also use try-catch in non-UI threads, because if an error happens in that thread, your whole application will crash.
    The code that is run inside that thread is also not thread-safe.
    Thanks, I think the collection class will be covered by my World struct, in Objects, though not sure if that's exactly what you mean, I feel it will allow easy enough access. I've only just learnt how to assign variables in a class file from data which is in an application, so I struggle with the idea of assigning variables in the backend. I'll take a look into this though I guess, there must be a better way.

    The UI thread does consume a lot of resources at the minute, yes, I only really implemented it as a method of testing the functions I've made at the backend. If I'm to keep it, I will make sure I sort the entire code there out, though that's 50/50, I will do my best to keep it a bit tidy for now, and will spend some time cleaning it up. Which code isn't thread safe, other than the while loops? I used them instead of timers as I was having issues with the default timer class, I read on StackOverflow that a while loop will do the same job, without any extra resource hogging...?

    Note that UpdateStats is run in a second thread, as is the healer, though as you mentioned they do consume a lot of CPU. I'll add a thread sleep ito the UpdateStats now, and will look at putting them into timers a in a more organised fashion tomorrow most likely.

    Massive thanks for your advice, it's really useful for me to learn this before I've already finished the project...

  8. #8
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    OK so I've made a few changes recently, including but probably not limited to:

    • Merged SendHotKey(), SendArrowKey() to one function, SendButton() - Now you can pass: F1-F12 (as before), or "left", "up", "right", "down", and it will try to find a value according to what you give it.
    • Added the Util class, which is basically a data store at the minute. You feed it a Process for Tibia, and it provides base addresses, window handles, and the process itself where required, using Util.Process etc.
    • Modified method of cycling through enumerations from switch to Enum.TryParse, it looks much neater and is now a lot easier on the eye.
    • Added the ClientChooser WinForm, which allows the user to change client at any time (Client selected by name in popout window - Extras -> Client).
    • Moved the BLStart, BLStep, BLMax addresses out of ReaderClass, now they are in Addresses.


    Probably some things I've missed. If anyone has any comments on shit I'm doing badly etc, let me know. I think progress is good so far though...? I've been going through C# 5.0 in a nutshell recently, hence my use of Enum.TryParse and a few other functions which I've not used before.

  9. #9
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    Currently porting this project over to a DLL file since so many people said "It's not an API", if anyone is interested. I see a clear lack of interest, however, in this idea!

    I don't think people get that the general plan is to make a new TibiaAPI, but with more up to date functions including controlling Tibia using new methods (including mouse clicks and key presses), but meh.

    I've got the library compiled and can use it properly, am just working on ironing out a few glitches, at the minute I've made all classes public and they are accessible, and I'm reading data fine. I've not tried the Control class yet, but will do so tomorrow and will post the results once I've gotten the new "UI" up to scratch, with all the features I want (primarily a healer, so I can actually test changes to the SendMessage function).

  10. #10
    Senior Member
    Join Date
    Jan 2008
    Location
    Cambridge, England
    Posts
    725
    OK so I've ported it over and it is now a dll file which can be used in any application. It comes with a sample application which is very incomplete. The healer probably doesn't work as I've not had time to test it. I'll add more functions over the weekend as I have some annual leave.

    Catch you all soon <3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •