View previous topic :: View next topic |
Author |
Message |
isilweo
Joined: 29 Dec 2004 Posts: 22 Location: poland
|
Posted: Sun Feb 06, 2005 14:46 Post subject: Decoding NWN memory - Part 1 - Basics |
|
|
In last half year i've done some research on nwn scturctures in memory. I'll post my findings here cause they're useful and
if i get sucked by time hole (which happens sometimes) someone can make something out of them.
In the first part of my decoding memory series i'll focus on basics and describe most basic structures used by nwn. First of
all some most basic types that i'll used later
byte (or "b") - 1byte :) 1 cell of memory
int - 4b. integer. i'll asume it is unsigned
pointer - int (4b) - it holds address to something else (points for it)
and now simple structures. the structure notation i'll use is diffrent than in c++ but it's easier to imagine how data is
placed in memory.
SNWString - most (or all) strings in memory have this structure
//structure presented in my way
SNWString:
int ValuePointer;
int size;
struct SNWString //c-like
{
char * stringValue;
int stringSize;
};
this structure in memory looks like this:
36 08 00 07 05 00 00 00
it means that first int is pointer to string. It points to address 0x07000836. the second int is string size.
Note that the thing which is where valuePointer points is array of chars BUT it's is not said it's null-terminated string.
Sometimes it'll have \0 on the end and sometimes not (resrefs's don't have 0 and ie Names have). Note also that \0 is counted
in size if it's there and it's not counted if it's not there.
Arrays
Before all arrays there is always a simple structure
SArrayPointer:
int PointerToFirstElement
int NumberOfElements
you probably noticed that SNWString is exactly array of type char.
Array elements are placed one after another without any spacer bytes.
array of pointers - basicly array of ints. in memory it looks like this
Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
07808080: 90 80 80 07 05 00 00 00 //this is array pointer structure
07808090: A0 80 80 07 D0 90 30 07 20 34 32 08 48 0C 10 06
078080A0: Cc 84 40 07
in example above we have array of 5 pointers.
SArrayPointer's elements are:
pointer to first element - 07 80 80 90
number of array elements - 5
and then in 07808090 are 5 pointers.
Lists
List are a bit more complicated structures but are really simple (after you spend many hours looking at them in memory, where they're in complete disorder hehe)
List are used by nwn to store something that BW calls CExoLocString - that are names and descriptions in language sensitive string.
Before all lists we have simple structure with number of items and pointer to something i call PreList so:
SListPointer:
int pointerToSPreList
int NumberOfListElements
now if we follow our pointerToSPreList we'll have SPreList
SPreList:
int pointerToFirstElement
int pointerToLastElement
int NumberOfListElements
in above we have possibility to choose way we're going to loop through list (from begining or from end), and we have number of elements again. All elements of list have SListElement structure that is:
SListElement:
int pointerToPriorElement
int pointerToNextElement
int pointerToElementValue
Note that in first element pointerToPriorElement will be null (that is 00 00 00 00) and also in the last element pointerToNextElement will be null that's how you will know that you're at end (or begining). Before example just one more little structure
SLanguageString:
int LanguageId
sNWString LanguageString
i hope you remember (if not look at top of this post) that SNWString has to elements pointer and element count
To present example of list i'll use one more struct and it'll be important one
CExoLocString:
SListPointer PointerToList
int StrRef
if StrRef is FF FF FF FF it means that we'll have to look into PointerToList to search for string. If StrRef != FF FF FF FF we must lookup TLK files (dialog.tlk and user tlks if there are) to find string. And also if we look for string in TLK our SListPointer has 0 elements (but it always points somewhere).
Example of Lists on CExoLocString
Code: |
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
075D0DD0 E8 1E 57 07 13 00 00 00 č.W.....
here's SListPointer. in first int there's pointer to SPreList and in second list there's elements number. We have 19 elements (0x13) cause i've written strings in every language and gender
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
07571EE0 E0 16 67 07 C8 3D 58 07 ŕ.g.Č=X.
ptr to 1st element ptr to last element of list
07571EF0 13 00 00 00 ....
number of list elements
it's SPreList
Offset 0 1 2 3 4 5 6 7 8 9 A B
076716E0 00 00 00 00 58 81 53 07 20 1E 58 07 ....X�S. .X.
prior next ptr to SLanguageString
First element of list
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
07538150 E0 16 67 07 28 1D 58 07 ŕ.g.(.X.
prior next
07538160 B8 B4 57 07 ¸´W.
SLanguageString
Second Element of List
... (i've cut out that 16 elements)
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
07583DC0 C8 C6 59 07 00 00 00 00 ČĆY.....
prior next
07583DD0 78 DF 55 07 xßU.
ptr SLanguageString
there's none next element cause it's null. we're at end of list. maybe i'll also put how SLanguageString looks like
SLanguageString
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
0753A660 0B 00 00 00 40 EF 53 07 0B 00 00 00
languageID SNWString.ptr SNWString.size
Polish language, gender female:
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
0753EF40 6B 6F 62 69 65 74 61 68 65 68 00 kobietaheh.
|
have a good day
in next part i'll post ITEM structure decoded at 95% |
|
Back to top |
|
|
dragonsong
Joined: 08 Jan 2005 Posts: 19 Location: Salinas, CA
|
Posted: Mon Feb 07, 2005 5:00 Post subject: |
|
|
Great stuff, please keep it coming. _________________ - dragonsong |
|
Back to top |
|
|
|