News: 11 March 2016 - Forum Rules

Author Topic: Resident Evil 4 CRC [GameCube/PS2]  (Read 1028 times)

MeganGrass

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
    • GitHub
Resident Evil 4 CRC [GameCube/PS2]
« 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).