public virtual void UpdateSavedataHashes(PSF psf, sbyte[] data, int size, sbyte[] @params, sbyte[] key) { // Setup the params, hash and mode. sbyte[] hash = new sbyte[0x10]; // Determine the hashing mode. int mode = 0; int check_bit = 1; if (!isNullKey(key)) { if (Emulator.Instance.FirmwareVersion > 271) { mode = 4; } else { mode = 2; } } // Check for previous SAVEDATA_PARAMS. if (@params != null) { for (int i = 0; i < @params.Length; i++) { if (@params[i] != 0) { // Extract the mode setup from the already existing data. mode = ((@params[0] >> 4) & 0xF); check_bit = ((@params[0]) & 0xF); break; } } } // New mode (after firmware 2.7.1). if ((mode & 0x4) == 0x4) { // Generate a type 6 hash. hash = GenerateSavedataHash(data, size, 6); Array.Copy(hash, 0, data, 0x11B0 + 0x20, 0x10); // Set the SAVEDATA_PARAMS byte to 0x41. data[0x11B0] |= 0x01; data[0x11B0] |= 0x40; // Generate a type 5 hash. hash = GenerateSavedataHash(data, size, 5); Array.Copy(hash, 0, data, 0x11B0 + 0x70, 0x10); } else if ((mode & 0x2) == 0x2) { // Last old mode (firmware 2.0.0 to 2.7.1). // Generate a type 4 hash. hash = GenerateSavedataHash(data, size, 4); Array.Copy(hash, 0, data, 0x11B0 + 0x20, 0x10); // Set the SAVEDATA_PARAMS byte to 0x21. data[0x11B0] |= 0x01; data[0x11B0] |= 0x20; // Generate a type 3 hash. hash = GenerateSavedataHash(data, size, 3); Array.Copy(hash, 0, data, 0x11B0 + 0x70, 0x10); } else { // First old mode (before firmware 2.0.0). // Generate a type 2 hash. hash = GenerateSavedataHash(data, size, 2); Array.Copy(hash, 0, data, 0x11B0 + 0x20, 0x10); // Set the SAVEDATA_PARAMS byte to 0x01. data[0x11B0] |= 0x01; } if ((check_bit & 0x1) == 0x1) { // Generate a type 1 hash. hash = GenerateSavedataHash(data, size, 1); Array.Copy(hash, 0, data, 0x11B0 + 0x10, 0x10); } // Output the sealed override PSF file containing the SAVEDATA_PARAMS and file hashes. try { // Update the SAVEDATA_PARAMS. sbyte[] savedataParams = new sbyte[0x80]; for (int i = 0; i < 0x80; i++) { savedataParams[i] = data[0x11B0 + i]; } psf.put("SAVEDATA_PARAMS", savedataParams); } catch (Exception) { // Ignore... } }