Esempio n. 1
0
bool
LoadRAMAuto (bool silent)
{
	char filepath[MAXPATHLEN];
	char filepath2[MAXPATHLEN];

	// look for Auto save file
	if(!MakeFilePath(filepath, FILE_RAM, romFilename, 0))
		return false;

	if (LoadRAM(filepath, silent))
		return true;

	if (!GCSettings.AppendAuto)
		return false;

	// look for file with no number or Auto appended
	if(!MakeFilePath(filepath2, FILE_RAM, romFilename, -1))
		return false;

	if(LoadRAM(filepath2, silent))
	{
		// rename this file - append Auto
		rename(filepath2, filepath); // rename file (to avoid duplicates)
		return true;
	}
	return false;
}
Esempio n. 2
0
bool LoadBatteryOrStateAuto(int action, bool silent)
{
	char filepath[MAXPATHLEN];
	char filepath2[MAXPATHLEN];

	if(!MakeFilePath(filepath, action, ROMFilename, 0))
		return false;

	if (action==FILE_SRAM)
	{
		if (LoadBatteryOrState(filepath, action, SILENT))
			return true;

		if (!GCSettings.AppendAuto)
			return false;

		// look for file with no number or Auto appended
		if(!MakeFilePath(filepath2, action, ROMFilename, -1))
			return false;

		if(LoadBatteryOrState(filepath2, action, silent))
		{
			// rename this file - append Auto
			rename(filepath2, filepath); // rename file (to avoid duplicates)
			return true;
		}
		return false;
	}
	else
	{
		return LoadBatteryOrState(filepath, action, silent);
	}
}
Esempio n. 3
0
/****************************************************************************
 * 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 ();
}
Esempio n. 4
0
int WiiFileLoader()
{
	int size;
	char filepath[1024];

	memset(Memory.NSRTHeader, 0, sizeof(Memory.NSRTHeader));
	Memory.HeaderCount = 0;
	loadingFile = true;

	if(!inSz)
	{
		if(!MakeFilePath(filepath, FILE_ROM))
			return 0;

		size = LoadFile ((char *)Memory.ROM, filepath, browserList[browser.selIndex].length, NOTSILENT);
	}
	else
	{
		size = LoadSzFile(szpath, (unsigned char *)Memory.ROM);

		if(size <= 0)
		{
			browser.selIndex = 0;
			BrowserChangeFolder();
		}
	}
	loadingFile = false;

	if(size <= 0)
		return 0;

	SNESROMSize = Memory.HeaderRemove(size, Memory.HeaderCount, Memory.ROM);
	return SNESROMSize;
}
Esempio n. 5
0
char *
GetFirstZipFilename ()
{
	char * firstFilename = NULL;
	char tempbuffer[ZIPCHUNK];
	char filepath[1024];

	if(!MakeFilePath(filepath, FILE_ROM))
		return NULL;

	// read start of ZIP
	if(LoadFile (tempbuffer, filepath, ZIPCHUNK, NOTSILENT) < 35)
		return NULL;

	tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
	int namelength = tempbuffer[26]; // filename length starts 26 bytes in

	if(namelength < 0 || namelength > 200) // filename is not a reasonable length
	{
		ErrorPrompt("Error - Invalid ZIP file!");
		return NULL;
	}
	
	firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
	firstFilename[namelength] = 0; // truncate at filename length
	return strdup(firstFilename);
}
Esempio n. 6
0
char *
GetFirstZipFilename (int method)
{
	char * firstFilename = NULL;
	char tempbuffer[ZIPCHUNK];
	char filepath[1024];

	if(!MakeFilePath(filepath, FILE_ROM, method))
		return NULL;

	// read start of ZIP
	if(LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT))
	{
		tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
		int namelength = tempbuffer[26]; // filename length starts 26 bytes in

		if(namelength > 0 && namelength < 200) // the filename is a reasonable length
		{
			firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
			firstFilename[namelength] = 0; // truncate at filename length
		}
		else
		{
			WaitPrompt("Error - Invalid ZIP file!");
		}
	}

	return firstFilename;
}
Esempio n. 7
0
bool SaveBatteryOrStateAuto(int action, bool silent)
{
	char filepath[1024];

	if(!MakeFilePath(filepath, action, ROMFilename, 0))
		return false;

	return SaveBatteryOrState(filepath, action, silent);
}
Esempio n. 8
0
bool
SaveStateAuto (bool silent)
{
	char filepath[1024];

	if(!MakeFilePath(filepath, FILE_STATE, romFilename, 0))
		return false;

	return SaveState(filepath, silent);
}
Esempio n. 9
0
bool
SaveRAMAuto (bool silent)
{
	char filepath[1024];

	if(!MakeFilePath(filepath, FILE_RAM, romFilename, 0))
		return false;

	return SaveRAM(filepath, silent);
}
Esempio n. 10
0
int WiiFileLoader()
{
	size_t size;
	char filepath[1024];

	memset(Memory.NSRTHeader, 0, sizeof(Memory.NSRTHeader));
	Memory.HeaderCount = 0;
	loadingFile = true;

	if(!inSz)
	{
		if(!MakeFilePath(filepath, FILE_ROM))
			return 0;

		size = LoadFile ((char *)Memory.ROM, filepath, 0, Memory.MAX_ROM_SIZE, NOTSILENT);
	}
	else
	{
		size = LoadSzFile(szpath, (unsigned char *)Memory.ROM);

		if(size <= 0)
		{
			browser.selIndex = 0;
			BrowserChangeFolder();
		}
	}
	loadingFile = false;

	if(size <= 0)
		return 0;

	SNESROMSize = Memory.HeaderRemove(size, Memory.ROM);
	bsxBiosLoadFailed = false;

	if(isBSX()) {
		sprintf (filepath, "%s%s/BS-X.bin", pathPrefix[GCSettings.LoadMethod], APPFOLDER);
		if(LoadFile ((char *)Memory.BIOSROM, filepath, 0, 0x100000, SILENT) == 0) {
			bsxBiosLoadFailed = true;
		}
	}

	return SNESROMSize;
}
Esempio n. 11
0
/****************************************************************************
 * BrowserLoadSz
 *
 * Opens the selected 7z file, and parses a listing of the files within
 ***************************************************************************/
int BrowserLoadSz()
{
	char filepath[MAXPATHLEN];
	memset(filepath, 0, MAXPATHLEN);

	// we'll store the 7z filepath for extraction later
	if(!MakeFilePath(szpath, FILE_ROM))
		return 0;

	int szfiles = SzParse(szpath);
	if(szfiles)
	{
		browser.numEntries = szfiles;
		inSz = true;
	}
	else
		ErrorPrompt("Error opening archive!");

	return szfiles;
}
Esempio n. 12
0
char *
GetFirstZipFilename (int method)
{
	char * firstFilename = NULL;
	char tempbuffer[ZIPCHUNK];
	char filepath[1024];

	if(!MakeFilePath(filepath, FILE_ROM, method))
		return NULL;

	// read start of ZIP
	LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT);

	tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
	int namelength = tempbuffer[26]; // filename length starts 26 bytes in

	firstFilename = &tempbuffer[30]; // first filename of a ZIP starts 31 bytes in
	firstFilename[namelength] = 0; // truncate at filename length

	return firstFilename;
}
Esempio n. 13
0
ListBox::ListBox()
{
	if (ListBoxStyle == NULL)
	{
		XmlData::Document* document = new XmlData::Document;

		StringW* filename = MakeFilePath(_Module, L"../../../ListBoxStyle.lxui");
		document->load(filename);

		Type* returnType;
		ListBoxStyle = dynamic_cast<Style*>(CreateObjectFromElement(NULL, NULL, document->get_documentElement(), &returnType));
	}

	set_Style(ListBoxStyle);

	/*
	ApplyStyle(get_Style(), this);

	InitScript();
	*/
}
Esempio n. 14
0
Thumb::Thumb()
{
	m_dragging = false;

	if (ThumbStyle == NULL)
	{
		XmlData::Document* document = new XmlData::Document;

		StringW* filename = MakeFilePath(_Module, L"../../../ThumbStyle.lxui");
		document->load(filename);

		Type* returnType;
		ThumbStyle = dynamic_cast<Style*>(CreateObjectFromElement(NULL, NULL, document->get_documentElement(), &returnType));
	}

	set_Style(ThumbStyle);
/*
	ApplyStyle(get_Style(), this);
	InitScript();
	*/
}
Esempio n. 15
0
/****************************************************************************
 * SetupCheats
 *
 * Erases any prexisting cheats, loads cheats from a cheat file
 * Called when a ROM is first loaded
 ***************************************************************************/
void
WiiSetupCheats()
{
    memset(Cheat.c, 0, sizeof(Cheat.c));
    Cheat.num_cheats = 0;

    char filepath[1024];
    int offset = 0;

    if(!MakeFilePath(filepath, FILE_CHEAT))
        return;

    AllocSaveBuffer();

    offset = LoadFile(filepath, SILENT);

    // load cheat file if present
    if(offset > 0)
        LoadCheatFile (offset);

    FreeSaveBuffer ();
}
Esempio n. 16
0
BOOL CMagneticView::OpenGame(LPCTSTR lpszPathName)
{
  CMagneticApp* pApp = (CMagneticApp*)AfxGetApp();
  CMagneticView* pView = CMagneticView::GetView();

  if (pApp->GetGameLoaded() && ms_is_running())
    pApp->SetRedrawStatus(CMagneticApp::Redraw::EndOpcode);

  if (pView)
    pView->ClearAll();

  CString strGfxName, strHntName, strSndName;
  MakeFilePath(strGfxName,lpszPathName,".gfx");
  MakeFilePath(strHntName,lpszPathName,".hnt");
  MakeFilePath(strSndName,lpszPathName,".snd");

  // Free previous game
  ms_freemem();

  // Initialize new game
  pApp->SetGameLoaded(ms_init((type8s*)lpszPathName,
    (type8s*)((LPCTSTR)strGfxName),
    (type8s*)((LPCTSTR)strHntName),
    (type8s*)((LPCTSTR)strSndName)));

  // If required, make the random number generator predictable
  if (pApp->GetPredictable())
    ms_seed(pApp->GetRandomSeed());

  // Check status of loaded game
  if (pApp->GetGameLoaded() == 0)
  {
    CString strMessage;

    strMessage.Format("Failed to load game \"%s\"",lpszPathName);
    AfxMessageBox(strMessage,MB_ICONEXCLAMATION);
  }
  else
  {
    if (pView)
    {
      pView->m_bStatusBar = false;
      pView->Invalidate();
    }

    // Show the title picture, if possible
    CMagneticTitleDlg Title;
    Title.ShowTitle(lpszPathName);

    if (pView)
    {
      // Set up default file names
      MakeFilePath(pView->m_strRecName,lpszPathName,".rec");
      MakeFilePath(pView->m_strScrName,lpszPathName,".scr");
      MakeFilePath(pView->m_strFileName,lpszPathName,".sav");

      pView->m_bStatusBar = ms_is_magwin() ? false : true;
    }
  }

  if (pView)
    pView->Invalidate();
  return (pApp->GetGameLoaded() != 0) ? TRUE : FALSE;
}
Esempio n. 17
0
/****************************************************************************
 * 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;
}
Esempio n. 18
0
/****************************************************************************
 * 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;
}