Skip to content
Joshua Scott edited this page Sep 16, 2015 · 4 revisions

Details

The SOE protocol uses a seeded CRC32 algorithm. The seed is a random number generated by the server and sent to new connections in the Session Response packet. The CRC key is also used in encryption.

Appending a CRC32

Some packets require that certain bytes of the CRC32 are appended to the end of the packet to ensure the data was received correctly. This is done automatically through SOEWriter when calling GetFinalSOEPacket. However, if you need to get the CRC32 of a piece of data for something other than the footer, it can be done using the GetAppendedCRC32 method from an instance of SOEClient which will return the byte array with the length of the client's CRC Length. If you need the entire CRC32, use GetCRC32Checksum.

Implementation

Found in SOEProtocol. Look in there for the static CRCTable.

public uint GetCRC32Checksum(uint crcSeed, byte[] packet)
{
    uint nCrc = CRCTable[(~crcSeed) & 0xFF];
    nCrc ^= 0x00FFFFFF;

    uint nIndex = (crcSeed >> 8) ^ nCrc;
    nCrc = (nCrc >> 8) & 0x00FFFFFF;
    nCrc ^= CRCTable[nIndex & 0xFF];

    nIndex = (crcSeed >> 16) ^ nCrc;
    nCrc = (nCrc >> 8) & 0x00FFFFFF;
    nCrc ^= CRCTable[nIndex & 0xFF];

    nIndex = (crcSeed >> 24) ^ nCrc;
    nCrc = (nCrc >> 8) & 0x00FFFFFF;
    nCrc ^= CRCTable[nIndex & 0xFF];

    for (int i = 0; i < packet.Length; i++)
    {
        nIndex = packet[i] ^ nCrc;
        nCrc = (nCrc >> 8) & 0x00FFFFFF;
        nCrc ^= CRCTable[nIndex & 0xFF];
    }

    return ~nCrc;
}

Clone this wiki locally