/**************************************************************************** * SetupCheats * * Erases any prexisting cheats, loads cheats from a cheat file * Called when a ROM is first loaded ***************************************************************************/ void SetupCheats() { char filepath[1024]; int offset = 0; S9xInitCheatData (); S9xDeleteCheats (); int method = GCSettings.SaveMethod; if(method == METHOD_AUTO) method = autoSaveMethod(SILENT); if(!MakeFilePath(filepath, FILE_CHEAT, method)) return; AllocSaveBuffer(); offset = LoadFile(filepath, method, SILENT); // load cheat file if present if(offset > 0) { if(NGCLoadCheatFile (offset)) { // disable all cheats loaded from the file for (uint16 i = 0; i < Cheat.num_cheats; i++) S9xDisableCheat(i); } } FreeSaveBuffer (); }
bool SaveRAM (int method, bool silent) { ShowAction ((char*) "Saving..."); if(method == METHOD_AUTO) method = autoSaveMethod(); bool retval = false; char filepath[1024]; int datasize = 0; int offset = 0; // save game save to savebuffer if(nesGameType == 1) datasize = NGCFCEU_GameSave(&iNESCart, 0); else if(nesGameType == 2) datasize = NGCFCEU_GameSave(&UNIFCart, 0); if ( datasize ) { if(method == METHOD_SD || method == METHOD_USB) { if(ChangeFATInterface(method, NOTSILENT)) { sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename); offset = SaveBufferToFAT (filepath, datasize, silent); } } else if(method == METHOD_SMB) { sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename); offset = SaveBufferToSMB (filepath, datasize, silent); } else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { sprintf (filepath, "%08x.sav", iNESGameCRC32); if(method == METHOD_MC_SLOTA) offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent); else offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent); } if (offset > 0) { if ( !silent ) WaitPrompt((char *)"Save successful"); retval = true; } } else { if ( !silent ) WaitPrompt((char *)"No data to save!"); } return retval; }
bool LoadState (int method, bool silent) { ShowAction ((char*) "Loading..."); if(method == METHOD_AUTO) method = autoSaveMethod(); // we use 'Save' because we need R/W char filepath[1024]; int offset = 0; if(method == METHOD_SD || method == METHOD_USB) { ChangeFATInterface(method, NOTSILENT); sprintf (filepath, "%s/%s/%s.fcs", ROOTFATDIR, GCSettings.SaveFolder, romFilename); offset = LoadSaveBufferFromFAT (filepath, silent); if(offset == 0) // file not found { // look for CRC save sprintf (filepath, "%08x.fcs", iNESGameCRC32); offset = LoadSaveBufferFromFAT (filepath, silent); } } else if(method == METHOD_SMB) { sprintf (filepath, "%s/%s.fcs", GCSettings.SaveFolder, romFilename); offset = LoadSaveBufferFromSMB (filepath, silent); } else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { sprintf (filepath, "%08x.fcs", iNESGameCRC32); if(method == METHOD_MC_SLOTA) offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent); else offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent); } if (offset > 0) { GCFCEUSS_Load(); return 1; } // if we reached here, nothing was done! if(!silent) WaitPrompt ((char*) "State file not found"); return 0; }
bool LoadRAM (int method, bool silent) { ShowAction ((char*) "Loading..."); if(method == METHOD_AUTO) method = autoSaveMethod(); // we use 'Save' because we need R/W char filepath[1024]; int offset = 0; if(method == METHOD_SD || method == METHOD_USB) { if(ChangeFATInterface(method, NOTSILENT)) { sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename); offset = LoadSaveBufferFromFAT (filepath, silent); } } else if(method == METHOD_SMB) { sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename); offset = LoadSaveBufferFromSMB (filepath, silent); } else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { sprintf (filepath, "%08x.sav", iNESGameCRC32); if(method == METHOD_MC_SLOTA) offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent); else offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent); } if (offset > 0) { if(nesGameType == 1) NGCFCEU_GameSave(&iNESCart, 1); else if(nesGameType == 2) NGCFCEU_GameSave(&UNIFCart, 1); ResetNES(); return 1; } // if we reached here, nothing was done! if(!silent) WaitPrompt ((char*) "Save file not found"); return 0; }
bool SaveState (int method, bool silent) { ShowAction ((char*) "Saving..."); if(method == METHOD_AUTO) method = autoSaveMethod(); bool retval = false; char filepath[1024]; int datasize; int offset = 0; datasize = GCFCEUSS_Save(); if ( datasize ) { if(method == METHOD_SD || method == METHOD_USB) { if(ChangeFATInterface(method, NOTSILENT)) { sprintf (filepath, "%s/%s/%s.fcs", ROOTFATDIR, GCSettings.SaveFolder, romFilename); offset = SaveBufferToFAT (filepath, datasize, silent); } } else if(method == METHOD_SMB) { sprintf (filepath, "%s/%s.fcs", GCSettings.SaveFolder, romFilename); offset = SaveBufferToSMB (filepath, datasize, silent); } else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { sprintf (filepath, "%08x.fcs", iNESGameCRC32); if(method == METHOD_MC_SLOTA) offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent); else offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent); } if (offset > 0) { if ( !silent ) WaitPrompt((char *)"Save successful"); retval = true; } } return retval; }
bool MakeFilePath(char filepath[], int type, char * filename, int filenum) { char file[512]; char folder[1024]; char ext[4]; char temppath[MAXPATHLEN]; if(type == FILE_ROM) { // Check path length if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN) { ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } else { sprintf(temppath, "%s%s",browser.dir,browserList[browser.selIndex].filename); } } else { if(GCSettings.SaveMethod == DEVICE_AUTO) GCSettings.SaveMethod = autoSaveMethod(SILENT); if(GCSettings.SaveMethod == DEVICE_AUTO) return false; switch(type) { case FILE_SRAM: case FILE_SNAPSHOT: sprintf(folder, GCSettings.SaveFolder); if(type == FILE_SRAM) sprintf(ext, "srm"); else sprintf(ext, "frz"); if(filenum >= -1) { if(filenum == -1) sprintf(file, "%s.%s", filename, ext); else if(filenum == 0) if (GCSettings.AppendAuto <= 0) sprintf(file, "%s.%s", filename, ext); else sprintf(file, "%s Auto.%s", filename, ext); else sprintf(file, "%s %i.%s", filename, filenum, ext); } else { sprintf(file, "%s", filename); } break; case FILE_CHEAT: sprintf(folder, GCSettings.CheatFolder); sprintf(file, "%s.cht", Memory.ROMFilename); break; } sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file); } CleanupPath(temppath); // cleanup path snprintf(filepath, MAXPATHLEN, "%s", temppath); return true; }
bool SavePrefs (bool silent) { char filepath[MAXPATHLEN]; int datasize; int offset = 0; int device = 0; if(prefpath[0] != 0) { sprintf(filepath, "%s/%s", prefpath, PREF_FILE_NAME); FindDevice(filepath, &device); } else if(appPath[0] != 0) { sprintf(filepath, "%s/%s", appPath, PREF_FILE_NAME); strcpy(prefpath, appPath); FindDevice(filepath, &device); } else { device = autoSaveMethod(silent); if(device == 0) return false; sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER); DIR *dir = opendir(filepath); if (!dir) { if(mkdir(filepath, 0777) != 0) return false; sprintf(filepath, "%s%s/roms", pathPrefix[device], APPFOLDER); if(mkdir(filepath, 0777) != 0) return false; sprintf(filepath, "%s%s/saves", pathPrefix[device], APPFOLDER); if(mkdir(filepath, 0777) != 0) return false; } else { closedir(dir); } sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME); sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER); } if(device == 0) return false; if (!silent) ShowAction ("Saving preferences..."); FixInvalidSettings(); AllocSaveBuffer (); datasize = preparePrefsData (); offset = SaveFile(filepath, datasize, silent); FreeSaveBuffer (); CancelAction(); if (offset > 0) { if (!silent) InfoPrompt("Preferences saved"); return true; } return false; }
bool MakeFilePath(char filepath[], int type, char * filename, int filenum) { char file[512]; char folder[1024]; char ext[4]; char temppath[MAXPATHLEN]; if(type == FILE_ROM) { // Check path length if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN) { ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } else { sprintf(temppath, "%s%s",browser.dir,browserList[browser.selIndex].filename); } } else if (type == FILE_BORDER_PNG) { const char* loadedpath = filename; if (loadedpath == NULL) loadedpath = "default"; // Ensure that loadedname contains only the filename, not the path const char* loadedname = strrchr(loadedpath, '/'); if (loadedname == NULL) loadedname = loadedpath; // Check path length if ((strlen(pathPrefix[GCSettings.LoadMethod]) + strlen(GCSettings.BorderFolder) + strlen(loadedname)) >= MAXPATHLEN) { ErrorPrompt("Maximum filepath length reached!"); filepath[0] = 0; return false; } StripExt(file, loadedname); sprintf(temppath, "%s%s/%s.png", pathPrefix[GCSettings.LoadMethod], GCSettings.BorderFolder, file); } else { if(GCSettings.SaveMethod == DEVICE_AUTO) GCSettings.SaveMethod = autoSaveMethod(SILENT); if(GCSettings.SaveMethod == DEVICE_AUTO) return false; switch(type) { case FILE_SRAM: case FILE_SNAPSHOT: sprintf(folder, GCSettings.SaveFolder); if(type == FILE_SRAM) sprintf(ext, "sav"); else sprintf(ext, "sgm"); if(filenum >= -1) { if(filenum == -1) sprintf(file, "%s.%s", filename, ext); else if(filenum == 0) if (GCSettings.AppendAuto <= 0) { sprintf(file, "%s.%s", filename, ext); } else { sprintf(file, "%s Auto.%s", filename, ext); } else sprintf(file, "%s %i.%s", filename, filenum, ext); } else { sprintf(file, "%s", filename); } break; } sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file); } CleanupPath(temppath); // cleanup path snprintf(filepath, MAXPATHLEN, "%s", temppath); return true; }
/**************************************************************************** * NGCUnfreezeGame ***************************************************************************/ int NGCUnfreezeGame (int method, bool8 silent) { char filepath[1024]; int offset = 0; int result = 0; char msg[80]; bufoffset = 0; ShowAction ((char*) "Loading..."); if(method == METHOD_AUTO) method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W if(!MakeFilePath(filepath, FILE_SNAPSHOT, method)) return 0; AllocSaveBuffer (); offset = LoadFile(filepath, method, silent); if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B { if (offset) { char * zipbuffer = (char *)malloc(SAVEBUFFERSIZE); memset (zipbuffer, 0, SAVEBUFFERSIZE); // skip the saveicon and comment offset = (sizeof(saveicon) + 64); uLongf zipsize = 0; uLongf decompressedsize = 0; memcpy (&zipsize, savebuffer+offset, 4); offset += 4; memcpy (&decompressedsize, savebuffer+offset, 4); offset += 4; uLongf DestBuffSize = SAVEBUFFERSIZE; int err= uncompress((Bytef*)zipbuffer, (uLongf*)&DestBuffSize, (const Bytef*)(savebuffer + offset), zipsize); if ( err!=Z_OK ) { sprintf (msg, "Unzip error %s ",zError(err)); WaitPrompt (msg); } else if ( DestBuffSize != decompressedsize ) { WaitPrompt((char*) "Unzipped size doesn't match expected size!"); } else { offset = SAVEBUFFERSIZE; memcpy (savebuffer, zipbuffer, SAVEBUFFERSIZE); } free(zipbuffer); } } if(offset > 0) { if (S9xUnfreezeGame ("AGAME") == SUCCESS) result = 1; else WaitPrompt((char*) "Error thawing"); } else { if(!silent) WaitPrompt((char*) "Freeze file not found"); } FreeSaveBuffer (); return result; }
/**************************************************************************** * NGCFreezeGame * * Do freeze game for Nintendo Gamecube ***************************************************************************/ int NGCFreezeGame (int method, bool8 silent) { char filepath[1024]; int offset = 0; // bytes written (actual) int woffset = 0; // bytes written (expected) char msg[100]; ShowAction ((char*) "Saving..."); if(method == METHOD_AUTO) method = autoSaveMethod(); if(!MakeFilePath(filepath, FILE_SNAPSHOT, method)) return 0; S9xSetSoundMute (TRUE); S9xPrepareSoundForSnapshotSave (FALSE); AllocSaveBuffer (); NGCFreezeMemBuffer (); // copy freeze mem into savebuffer woffset = bufoffset; S9xPrepareSoundForSnapshotSave (TRUE); S9xSetSoundMute (FALSE); if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B { // Copy in save icon woffset = sizeof (saveicon); memcpy (savebuffer, saveicon, woffset); // And the freezecomment sprintf (freezecomment[0], "%s Freeze", VERSIONSTR); sprintf (freezecomment[1], Memory.ROMName); memcpy (savebuffer + woffset, freezecomment, 64); woffset += 64; // Zip and copy in the freeze uLongf DestBuffSize = (uLongf) SAVEBUFFERSIZE; int err= compress2((Bytef*)(savebuffer+woffset+8), (uLongf*)&DestBuffSize, (const Bytef*)savebuffer, (uLongf)bufoffset, Z_BEST_COMPRESSION); if(err!=Z_OK) { sprintf (msg, "zip error %s ",zError(err)); WaitPrompt (msg); return 0; } int zippedsize = (int)DestBuffSize; memcpy (savebuffer + woffset, &zippedsize, 4); woffset += 4; int decompressedsize = (int)bufoffset; memcpy (savebuffer + woffset, &decompressedsize, 4); woffset += 4; woffset += zippedsize; } offset = SaveFile(filepath, woffset, method, silent); FreeSaveBuffer (); if(offset > 0) // save successful! { if(!silent) WaitPrompt((char*) "Save successful"); return 1; } return 0; }