Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 16.06.2006, 11:11   #1
Bruenor
Архивный участник
 
Join Date: Jun 2006
Posts: 14
Default [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 entry
name = [AddMoveAroundDesire]  // function name
id = 0                        // function id (the number you use in AI.obj)
address = 0x0042E670          // address of the function
address_type = a_Absolute     // address type (a_Absolute or a_Thunk; the default type is a_Absolute)
return_type = t_void          // return type (defined in ai_func_table_pch.txt)
arg_count = 2                 // number of arguments
arg_type = {t_int;t_float}    // list of the argument types
function_end                  // end of entry
The final step is to call your function from an AI script. Several tutorials for this exist on PostPacific, such as [SHARE][TUTORIAL]AI.OBJ.

Code for a sample function can be found in New Functions.cpp and New Functions.h.


Enjoy.

Вложения из исходного сообщения (сами файлы в копии отсутствуют):
l2npc_with_ai_function_table_185.rar — 384393 байт
Bruenor is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 15:54.