Post Pacific  

Go Back   Post Pacific > Lineage 2 > Lineage 2 Server Modifications ONLY!

Notices

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 17.10.2005, 16:36   #1
Livid
Архивный участник
 
Join Date: Apr 2005
Posts: 314
Default [Tutorial?][HEX] Adding new crystal_type to itemdata

First, I don't know how you can find that. It is just luck or skill or both. I will just explain what do you need to change and why do you need to change that.

Task: add new crystal_type property value. Just add. Nothing more. Hex is a bit incomplete, ex. if you crush item with new cryst. type you will either get crash or bunch of no-crystal thing.

A bit of theory: Server parses all script files and stores them in memory. It stores those in rather... complex format, but most of properties are being saved as word or dword (since c works with numbers faster). There is a function, actually, that converts string assigned to property into numeric value. And it is resided in here : 00567840. So, all we need is to read this function carefully and understand what actually does it do. Consider that as your hometask. I will stop only on moments needed for our task.

Practice?
First, if you read that one carefuly, you can understand how it works. It checks on appropriate string in table and substitutes it with appropriate numeric value.
Also, it makes 80h cycles, meaning that it's for-loop.
This:
Code:
00567849  |.  BE 4C566C00   MOV ESI,L2server.006C564C
gives us a clue where the array (or table if you wish) resides. For those who did not understand, it's in .6C564C.
Second, what's length of our table item and its structure?
Code:
00567850  |> /396E FC       /CMP DWORD PTR DS:[ESI-4],EBP  ;check if table item is referenced to proerty field we have. Notice [esi-4]!
00567853  |. /75 14         |JNE SHORT L2server.00567869  ;if it's not, jump
00567855  |. |8B06          |MOV EAX,DWORD PTR DS:[ESI]  ;Get first element of table item to eax
00567857  |. |85C0          |TEST EAX,EAX ; Check if it's NULL
00567859  |. |74 1A         |JE SHORT L2server.00567875 ; if it is, break; exit; return error.
0056785B  |. |53            |PUSH EBX ;in [EBX] you have string from .txt
0056785C  |. |50            |PUSH EAX ;in EAX you have first element of table item
0056785D  |. |E8 4E350300   |CALL <L2server.cmpstr> ; it is standart VC++ compare string routine. Every hexer should recognize it from first sight. Consider it as your hometask.
00567862  |. |83C4 08       |ADD ESP,8 ; Shift Stack by 8 (2 values we pushed earlier)
00567865  |. |85C0          |TEST EAX,EAX ; Check if function returned NULL*
00567867  |. |74 16         |JE SHORT L2server.0056787F ; If it did, then strings are equal. Exit cycle.
00567869  |> \47            |INC EDI ; increment for-loop variable by one
0056786A  |.  83C6 10       |ADD ESI,10 ; add 10h to table pointer**
0056786D      81FF 80000000 CMP EDI,80 ; check if we've got for-loop variable = 80h
00567873  |.^ 72 DB         \JB SHORT L2server.00567850 ; if not, continue on cycle.
*According to stdcall and Ccall, function stores return value in EAX.
**Which means we increment table item pointer by one. Which means that one table item is 10h = 16 bytes long.

Now, let's see to code which is being executed when we got strings matched.
Code:
0056787F  |> \C1E7 04       SHL EDI,4 ;this actually means "divide EDI by 2^4 and take whole part" = [EDI/16]
00567882  |.  8B87 50566C00 MOV EAX,DWORD PTR DS:[EDI+6C5650] ;EDI+006C564C+4. Obviously, second element of item we exited on.
00567888  |.  8B97 54566C00 MOV EDX,DWORD PTR DS:[EDI+6C5654] ;Obviously, third element of item we exited on.
Then exit function in normal way.
This means that function returns two values in EAX and EDX. First one is dword value of string. Second... I don't know, but in this context it doesn't matter (if you're curious, look what is that in near of .568CB5. That's where this function is being called and EDI is being used).

So, we need
1) add new element to table in format:
(int field, PWideChar StringValue, int DwordValue, int Unknown=0)
2) Increase loop count by one.

Second is easy. Change
Code:
0056786D      81FF 80000000 CMP EDI,80
to
Code:
0056786D      81FF 80000000 CMP EDI,81
First is a bit harder. Just a bit.
I just added it at the end of table, like that:
Code:
006C5E48:  26000000 585E6C00 06000000 00000000
Which means:
int field = 26h (which is crystal_type)
PWideChar StringValue = 6C5E58 = UNICODE 'e'
int DwordValue = 6
int Unknown = 0

It is also possible to move table somewhere else, where is more space if you need it. In this case, we did not.
Well... I think that's all. Any feedback is welcomed.

Software
I usually get asked what soft do I use. I always answer, but it gets annoying, so I want to make it clear.
I use ollydbg 1.10 for debugging, often hexing, usually to post my hexes here.
I use Hex workshop to search for strings and cross-section references.
I use hiew to hex fast fixes in different versions of exes.

Stop. Nothing more.
Livid is offline  
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 21:34.