character dat structure

its all ok now, except for this:

Code:
union {
            long unknowInt8[34];
            float unknowFloat8[34];
            short unknowShort8[68];
        };
        long sessionID;
        long x;
        long y;
        long z;
        union {
            long unknowInt9[4];
            float unknowFloat9[4];
            short unknowShort9[8];
        };
cant reproduce that in C# :(

I know a union allows that offset to be read as a int,float or a short in the 1st case, I just make it as an int, then I try to retrieve the next fields, like: sessionID, X,Y,Z, but they are with the incorrect values :(
 
its all ok now, except for this:

Code:
union {
            long unknowInt8[34];
            float unknowFloat8[34];
            short unknowShort8[68];
        };
        long sessionID;
        long x;
        long y;
        long z;
        union {
            long unknowInt9[4];
            float unknowFloat9[4];
            short unknowShort9[8];
        };
cant reproduce that in C# :(

I know a union allows that offset to be read as a int,float or a short in the 1st case, I just make it as an int, then I try to retrieve the next fields, like: sessionID, X,Y,Z, but they are with the incorrect values :(
I think you are slightly mistaken. A union allows a single memory location to be accessed implicitly as one of a number of different datatypes, without explicitly specifying the typecast in each access.

So, in the first case the array of 34 long integers "unknowInt8" occupies the same memory as the "unknownFloat8" and the 68 short integers "unknownShort8".

So, lets examine the following code using that union
Code:
unknownInt8[0] = 0x00FFFF00;
printf("Short[0] = %n, Short[1] = %n\n", unknownShort8[0], unknownShort8[1]);
This code will display:-
Code:
Short[0] = 255, Short[1] = 65280
i.e. unknownShort8[0] = 0xff, unknownShort8[1] = 0xff00. Get it?

Maybe that's what you meant.

I'll give another simple example, if you make a union of a single element of type ubyte and of type char, then you can assign "a" to the char element, then add (+=) 32 to the ubyte element and the char element will then contain "A". ;)

If nothing else, I'm sure C# can contain the data in it's most basic form as an object defining access and modification properties and methods for the data which match the required datatypes, and perform internal typecasting in the operation overloads for those methods and properties. (however you work a property get & set and operator overloads in C#) unions are much simpler to write, and much simpler for the compiler to turn into machine code.

In most CPUs there is 0 logic to performing these typecasts, so why "invent" source code for the programmer to write in order to achieve something that is naturally understood without any CPU cycles or instruction execution in the processor?

From x86 assembly point of view, this method of managing information in memory is implicit in the fact that there is only one data type known to the CPU; Binary. XD How the assembler source code chooses to "pretty" it's entry for the coder is irrelevant to the CPU. :D:
 
Last edited:
This is how I made:

Code:
        [StructLayout(LayoutKind.Explicit)]
        struct P_Union
        {
            [FieldOffset(0), MarshalAs(UnmanagedType.ByValArray, SizeConst = 34)]
            int[] p_int;
            [FieldOffset(0), MarshalAs(UnmanagedType.ByValArray, SizeConst = 34)]
            float[] p_float;
            [FieldOffset(0), MarshalAs(UnmanagedType.ByValArray, SizeConst = 34*2)]
            short[] p_short;
        }
        // remove padding
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct CharDat 
        {
            public int size;
            public int opcode;
            [MarshalAs(UnmanagedType.ByValTStr,SizeConst = 8)]
            public string header;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string charName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
            public string charModel1;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
            public string charModel2;
            public long charID;
            long unknow;
            int mobs;
            public CharacterClass Class;
            public int Level;
            public int Strength;
            public int spirit;
            public int talent;
            public int agility;
            public int health;
            public int freeStat;
            public int attackRatting;
            public int attackPowerMin;
            public int attackPowerMax;
            public int attackSpeed;
            public int attackLengh;
            public int criticalAttack;
            public int defense;
            public int block;
            public int absorbtion;
            public int speed;
            int nulls;
            public short currentpot;
            public short maxpot;
            public short elementalPoison;
            public short elementalNone;
            public short elementalFire;
            public short elementalIce;
            public short elementalLight;
            public short elementalOrganic;
            [MarshalAs(UnmanagedType.ByValArray,SizeConst = 5)]
            int[] zeros;
            public short currentHP;
            public short maxHP;
            public short currentMP;
            public short maxMP;
            public short currentSTM;
            public short maxSTM;
            public float HP_Regen;
            public float MP_Regen;
            public float STM_Regen;
            public int currentExp;
            public int nextLevelExp;
            public int gold;
            P_Union union1;
            public int SessionID;
            public Stages currentMap;
            int unknow2;
        }
but I cant get the X Y Z... dunno how they are saved in the .dat file

I guess the P_Union struct is correct, isnt it?

@edit

I managed to get the correct X and Z values:

Code:
public Stages currentMap; // 0x1E4
int unknow2;
byte not;
public short X;
short not2;
public short Z;

seems that the Y value isnt saved in the .dat file, am I right? when I spawn in ric my Y is 203 (0xCB) but there isnt any 0xCB in my .dat
 
Last edited:
Camera mode have only 3 values 0, 1, 2.

I think it is possible to calculate Y, but you need to know how PT use hight data in .smd files.
Well, PT calculating Y all the time if you look at admin HUD so it might be good place to look at.

PS. Are you sure that X, Z are not int?
 
I know it's very close to how an .itm file is saved. Altering it tends to "invalidate" and I never managed to get the item validator program to work properly. (I could do with someone who has writing a guide)

It stores X and Y co-ordinates within the inventory, and I did manage to put more in my inventory by having each item only a couple of pixels away from each other... but it introduces many bugs, and my character ended up with inventory I could not pick up and move. :(:
 
I'd like to know how to read all the items I have in my dat char. but not using anything like a string.contains(item name) method, you know?

I am making the game formulas inside my emulator and some of them require the additional which is given by the item :huh:

Dunno if it helps but in the very first line where the item table on the dat beings, the second integer value I guess its the item count you have in your character. dunno if it helps to unveil the mistery of the item table! lol
 
Last edited:
Here is .war file example:
http://forum.ragezone.com/f286/war-structure-670143/#post5724387

Good start but its not completed. Items are complicated, usually when I change one thing whole item disappear :/ So there must be many checks in server that are not allowing for spawning bugged/edited items. Probably I have to update checksums every time I change something.

One items have huge structure.
 
Back