![]() |
[Share] AI Function Table version x.x
The functions that are callable by AI.obj are stored in a function table in L2NPC. This share moves them to a text file in the script folder which is then loaded at server startup (with the aid of a dll that I wrote). Included is a patched L2NPC.exe in addition to the information required to patch it yourself in case yours is already heavily modified.
Installation instructions can be found in Readme.txt. Since I haven't created any new AI-callable functions yet, this share is currently useless to leechers. :mrgreen: There are now three ways you can create AI functions. I think option two is by far the simplest. :wink: In all cases, the function should use the __cdecl calling convention, and the first argument needs to be a pointer to a CNPC object (void* will also work). 1) Write the function in machine language and hex it into the server. (It's not impossible; I've done it myself. :wink: ) 2) Make a dll with the function (or edit mine) and import the function into L2NPC.exe using stud_pe. To get the address for the function table entry, convert the RVA (relative virtual address) of the thunk to the virtual address (or just add 0x400000 to the RVA). In the function table entry, make sure you use address_type = a_Thunk. 3) If you prefer dll injection to importing the function using stud_pe, reserve 4 bytes of memory in L2NPC.exe (such as in the .data2 section) to hold the address of the function. During dll initialization, inject the address of your function at that location. The function table entry is the same as in option 2, except that you will use the address of the memory holding the pointer to the function instead of the thunk. Like in option 2, you will need to set address_type to a_Thunk. When making a function, you will need to stick to the types defined in ai_func_table_pch; otherwise you won't know what to put when adding your function to the function table. It should be possible to add new types, but it may require a significant amount of hexing of L2NPC.exe. The next step is to add your function to ai_func_table.txt. The format is the same as other script files, so if you have worked with scripts before, it should seem familiar to you. ;) Sample entry in ai_func_table.txt: Code:
function_begin // beginning of entryCode for a sample function can be found in New Functions.cpp and New Functions.h. Enjoy. :) Вложения из исходного сообщения (сами файлы в копии отсутствуют): l2npc_with_ai_function_table_185.rar — 384393 байт |
great share.
where are you calling the function inside l2npc? |
Which function are you referring to?
|
this is definatly good stuff thanks!
|
It's great! Thank you!
|
Quote:
|
You can find that information in L2NPC Fixes.txt.
|
Thanks for this share. I have no use for it yet, but it will be interesting to use if I ever try adding new NPC functions. Great work!
|
Would there be a way to save to the MS SQL VIA Creating a function?
|
If you are asking if a function you create can access the SQL database, then of course it can. The NPC server probably has functions for sending queries (possibly imported from a dll), so just figure out what function to use and call it (with the appropriate parameters, of course).
|
Quote:
|
Since the dll's addresses are dinamic we cant set the addresses of new functions in the txt file, well not directly
you could create a map like this map<string, void (__cdecl *)(...)> mapName; and a new function void newfunction(...something); then in runtime set the map values mapName["newfunction"] = newfunction; so when reading the "newfunction" string from the txt we have a correct address for it this is just a sugestion ..anyone with a better idea, reply |
I'm working on a method for getting the function table to work with statically imported functions. My plans are for another field that determines the address type (absolute address or thunk). Absolute address is the default and is what all of the functions use right now. With the thunk type, when the function table is loaded, the program will go to the given address to find the address of the thunk, which will then be used in the in-memory copy of the function table.
Some information on statically importing functions: You can import a function into L2NPC.exe using stud_pe. Since the address can change, programs use thunks (which are essentially tiny functions) to call the imported function. The thunk address shown by stud_pe is actually the address of the memory that is filled in at program startup with the address of the thunk. So, to call an imported function, you would dereference the thunk address and call that. |
I uploaded the dll-friendly version 1.2. 8) The first post has been updated to reflect the changes.
Release notes: - Fixed a bug with multi-line comments in which **/ would not be recognized as the end of a comment. - Except for the sample function being imported into L2NPC.exe, it hasn't been changed at all from my original release. (This means that you don't have to redo any hex fixes in case you chose to go that route.) |
nice share.
|
thanks! very good share.
now have a time to take a cup of tea. |
mmmm very interesting ;)
I'll study it just when I have some free time. Thx |
Great work!
:D |
great work :D
|
| All times are GMT. The time now is 15:05. |