• Welcome to Valhalla Legends Archive.
 

Converting C++ structs

Started by Insolence, July 14, 2007, 08:38 PM

Previous topic - Next topic

Insolence

struct GAMEINFO
{
DWORD _1[6]; //0x00
WORD _1a; //0x18
CHAR szGameName[0x18]; //0x1A
CHAR szGameServerIp[0x56]; //0x32
CHAR szAccountName[0x30]; //0x88
CHAR szCharName[0x18]; //0xB8
CHAR szRealmName[0x18]; //0xD0
BYTE _2[0x157]; //0xE8
CHAR szGamePassword[0x18]; //0x23F
};


This is what I have so far:
    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
    public struct GameInfo
    {
        [FieldOffset(0x00)] [MarshalAs(UnmanagedType.ByValArray, SizeConst=6)]  public uint[] _1;
    [FieldOffset(0x18)] public UInt16  _1a;
        [FieldOffset(0x1A)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szGameName;
    [FieldOffset(0x32)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=86)] public string szGameServerIp;
    [FieldOffset(0x88)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=48)] public string szAccountName;
    [FieldOffset(0xB8)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szCharName;
    [FieldOffset(0xD0)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szRealmName;
    [FieldOffset(0xE8)] [MarshalAs(UnmanagedType.ByValArray, SizeConst=343)]  public uint[] _2;
    [FieldOffset(0x23F)] [MarshalAs(UnmanagedType.ByValTStr, SizeConst=24)] public string szGamePassword;
    }


EDIT:
Changing it to sequential did the trick.

MyndFyre

Why are you using ByValTStr?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Insolence

Should I not be?

It's working.