Giter VIP home page Giter VIP logo

rare-n64-chksm's Introduction

Rare N64 Checksum Algorithm

This is the checksum algorithm used to detect corrupted save data in a number of Rare games. The mixing function also appears to be used as a random number generator in some games. This is mostly useful for those into ROM hacking or modifying save files. Code is provided in C but there is a online JS version you can just copy and paste hex bytes into.

This algorithm is known to be used in Goldeneye 007 (type A), Banjo-Kazooie (type B), Perfect Dark (type C) and, Banjo-Tooie (type A) .

Game Release date Final checksum formula
GoldenEye 007 Aug-25-1997 A, (u64) (S3 << 32) | S4
Banjo-Kazooie Jun-29-1998 B, (u32) S3 ^ S4
Perfect Dark May-22-2000 C, (u32) (S3 << 16) | (S4 & 0xFFFF)
Banjo-Tooie Nov-20-2000 A, (u64) (S3 << 32) | S4

Note: Perfect Dark has an EEPROM bug where empty space is overwritten with unused duplicate data. This means you need specific lengths to know when to stop reading data. The true lengths for these data sections are 96-5, 80-2 and 64-15. These are expressions; for example, the full allocated data size is 96 bytes but you must subtract 5, so the true length to stop at is 96-5 = 91. The other two lengths which don't contain empty space are 160 and 8. The other games are relatively straightforward for finding their offsets so I won't bother explaining the memory layout here...

rare-n64-chksm's People

Contributors

cxd4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rare-n64-chksm's Issues

Decomp CRC generation from 007 goldeneye

Hello, while working on decompiling 007 goldeneye we decomped the checksum generation function and thought you could maybe find it useful. The function is matching.

Its a tad shorter than the implementation you had but im not sure how much of that was accounting for the other games.

Ive also included the calling function and struct that we have been using for save_data.

Credits to trevor for this.

void gamefileGenerateCRC(u8 *addressA, u8 *addressB, save_data *retval)
{
    u8 *byte;
    s32 shift      = 0; // Shift value
    s64 polynormal = 0x8F809F473108B3C1;
    s32 checksum1  = 0; // Final checksum #1
    s32 checksum2  = 0; // Final checksum #2

    for(byte = addressA; byte < addressB; byte++,shift += 7)
    {
        polynormal += *byte << (shift & 0xF) ;
        checksum1 ^= randomGetNextFrom(&polynormal);
    }

    for(byte = addressB - 1; byte >= addressA; byte--,shift += 3)
    {
        polynormal += *byte << (shift & 0xF) ;
        checksum2 ^= randomGetNextFrom(&polynormal);
    }
    retval->chksum1 = checksum1;
    retval->chksum2 = checksum2;
}

Called by

void sub_GAME_7F01D7A0(save_data *save)
{
    if (save >= &saves[0] && save < &saves[5])
    {
        if (gamefileGamePakProbe() != 0)
        {
            gamefileGenerateCRC(&save->completion_bitflags, save + 1, save);
            joyGamePakLongWrite((((u32)((save - &saves[0]) * 0x60) >> 3) + 4), save, sizeof(save_data));
        }
    }
}

save_data struct

typedef struct save_data
{
  s32 chksum1;
  s32 chksum2;
  u8 completion_bitflags;
  u8 flag_007;
  u8 music_vol;
  u8 sfx_vol;
  u16 options;
  u8 unlocked_cheats_1;
  u8 unlocked_cheats_2;
  u8 unlocked_cheats_3;
  char padding;
  u8 times[(SP_LEVEL_MAX-1) * 4];
} save_data;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.