Romhacking.net

Romhacking => Programming => Topic started by: MeganGrass on August 31, 2021, 04:33:47 pm

Title: Resident Evil 4 CRC [GameCube/PS2]
Post by: MeganGrass on August 31, 2021, 04:33:47 pm
Code: [Select]
UINT CRCTable[0x100]{ NULL };
VOID CRCInit(VOID) {

    // Variable
    UINT Bit = 0;
    UINT nBit;
    UINT pTable = 0;

    // Initialize
    do {
        nBit = 0;
        do {
            if ((Bit & 0x80000000) == 0) { Bit = Bit << 1; }
            else { Bit = Bit << 1 ^ 0x4C11DB7; }
            nBit++;
        } while (nBit < 8);
        (CRCTable)[pTable] = Bit;
        pTable++;
        Bit = pTable * 0x1000000;
    } while (pTable < 0x100);

    // Complete
    return;
}
UINT CalcCRC(UCHAR* Data, UINT len) {

    // Variable
    UINT Bit;
    UINT tmpCRC = NULL;
    UINT pData = 0;

    // Calculate
    if (len != 0) {
        Bit = 0;
        do {
            tmpCRC = tmpCRC << 8 ^ (CRCTable)[Bit ^ Data[pData]];
            pData++;
            Bit = tmpCRC >> 0x18;
        } while (pData < len);
    }

    // Complete
    return tmpCRC;
}


If the save data is "System Data,"
Code: [Select]
CRC = CalcCRC(&GCIFile[0x40], 0x1E78); and CRC is stored at 0x1EB8.

If the save data is regular progression saves,
Code: [Select]
CRC = CalcCRC(&GCIFile[0x40], 0xEAF8); and CRC is stored at 0xEB38.

This code likely works on the Wii/PC versions as well (untested).