Beispiel #1
0
void L1_GetSaveGameImage() {
	int width = 250, height = 188;
	Bitmap *screenshot;
	int dataSize;

	lua_Object param = lua_getparam(1);
	if (!lua_isstring(param)) {
		lua_pushnil();
		return;
	}
	const char *filename = lua_getstring(param);
	SaveGame *savedState = SaveGame::openForLoading(filename);
	if (!savedState || savedState->saveVersion() != SaveGame::SAVEGAME_VERSION) {
		lua_pushnil();
		return;
	}
	dataSize = savedState->beginSection('SIMG');
	uint16 *data = new uint16[dataSize / 2];
	for (int l = 0; l < dataSize / 2; l++) {
		data[l] = savedState->readLEUint16();
	}
	screenshot = new Bitmap((char *)data, width, height, 16, "screenshot");
	if (screenshot) {
		lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
	} else {
		lua_pushnil();
		warning("Could not restore screenshot from file");
		delete savedState;
		return;
	}
	savedState->endSection();
	delete savedState;
}
Beispiel #2
0
void L1_SubmitSaveGameData() {
	lua_Object table, table2;
	SaveGame *savedState;
	const char *str;
	table = lua_getparam(1);

	savedState = g_grim->savedState();
	if (!savedState)
		error("Cannot obtain saved game");
	savedState->beginSection('SUBS');
	int count = 0;
	for (;;) {
		lua_pushobject(table);
		lua_pushnumber(count);
		count++;
		table2 = lua_gettable();
		if (lua_isnil(table2))
			break;
		str = lua_getstring(table2);
		int32 len = strlen(str) + 1;
		savedState->writeLESint32(len);
		savedState->write(str, len);
	}
	savedState->endSection();
}
const vector< string >& getStringList( int playernum, const string &mykey )
{
    if ( playernum < 0 || (unsigned int) playernum >= _Universe->numPlayers() ) {
        static const vector<string> empty;
        return empty;
    }
    
    SaveGame *savegame = _Universe->AccessCockpit( playernum )->savegame;

    /* Should check old-style string lists, but it would defeat the purpose
       of this fast getter. Besides, any functionality that uses this one is
       using the new-style string lists, so we're cool (or ought to be) */
    return savegame->readMissionStringData( mykey );
}
Beispiel #4
0
void Lua_V2::ThumbnailFromFile() {
	lua_Object texIdObj = lua_getparam(1);
	lua_Object filenameObj = lua_getparam(2);

	if (!lua_isnumber(texIdObj) || !lua_isstring(filenameObj)) {
		warning("Lua_V2::ThumbnailFromFile: wrong parameters");
		return;
	}
	int index = (int)lua_getnumber(texIdObj);
	const char *filename = lua_getstring(filenameObj);

	int width = 256, height = 128;
	Bitmap *screenshot;

	SaveGame *savedState = SaveGame::openForLoading(filename);
	if (!savedState || !savedState->isCompatible()) {
		delete savedState;
		warning("Lua_V2::ThumbnailFromFile: savegame %s not compatible", filename);
		lua_pushnil();
		return;
	}
	int dataSize = savedState->beginSection('SIMG');
	if (dataSize != width * height * 2) {
		warning("Lua_V2::ThumbnailFromFile: savegame uses unexpected thumbnail size, ignore it");
		lua_pushnil();
		delete savedState;
		return;
	}
	uint16 *data = new uint16[dataSize / 2];
	for (int l = 0; l < dataSize / 2; l++) {
		data[l] = savedState->readLEUint16();
	}
	Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data);
	screenshot = new Bitmap(buf, width, height, "screenshot");
	if (!screenshot) {
		lua_pushnil();
		warning("Lua_V2::ThumbnailFromFile: Could not restore screenshot from file %s", filename);
		delete[] data;
		delete savedState;
		return;
	}

	screenshot->_data->convertToColorFormat(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
	g_driver->createSpecialtyTexture(index, screenshot->getData(0).getRawBuffer(), width, height);
	delete[] data;
	savedState->endSection();
	delete savedState;

	pushbool(true);
}
void saveStringList( int playernum, const string &mykey, const vector< string > &names )
{
    if ( playernum < 0 || (unsigned int) playernum >= _Universe->numPlayers() )
        return;

    SaveGame *savegame = _Universe->AccessCockpit( playernum )->savegame;
    
    // Erase old-style string lists
    if (savegame->getMissionDataLength(mykey) != 0)
        clearSaveData(playernum, mykey);
    
    vector< string > &ans = savegame->getMissionStringData( mykey );
    clearSaveString(playernum, mykey);
    for (vector<string>::const_iterator i = names.begin(); i != names.end(); ++i) {
        if (SERVER)
            VSServer->sendSaveData( playernum, Subcmd::StringValue|Subcmd::SetValue,
                                    ans.size(), &mykey, NULL, &*i, NULL );
        ans.push_back( *i );
    }
}
Beispiel #6
0
SaveStateList GrimMetaEngine::listSaves(const char *target) const {
	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
	Common::StringArray filenames;
	Common::String pattern = "grim*.gsv";

	filenames = saveFileMan->listSavefiles(pattern);

	SaveStateList saveList;
	char str[256];
	int32 strSize;
	for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
		// Obtain the last digits of the filename, since they correspond to the save slot
		int slotNum = atoi(file->c_str() + 4);

		if (slotNum >= 0) {
			SaveGame *savedState = SaveGame::openForLoading(*file);
			if (savedState && savedState->isCompatible()) {
				savedState->beginSection('SUBS');
				strSize = savedState->readLESint32();
				savedState->read(str, strSize);
				savedState->endSection();
				saveList.push_back(SaveStateDescriptor(slotNum, str));
			}
			delete savedState;
		}
	}

	Common::sort(saveList.begin(), saveList.end(), cmpSave);
	return saveList;
}
Beispiel #7
0
void Lua_V1::GetSaveGameData() {
	lua_Object param = lua_getparam(1);
	if (!lua_isstring(param))
		return;
	const char *filename = lua_getstring(param);
	SaveGame *savedState = SaveGame::openForLoading(filename);
	lua_Object result = lua_createtable();

	if (!savedState || !savedState->isCompatible()) {
		lua_pushobject(result);
		lua_pushnumber(2);
		lua_pushstring("mo.set"); // Just a placeholder to not make it throw a lua error
		lua_settable();
		lua_pushobject(result);

		if (!savedState) {
			warning("Savegame %s is invalid", filename);
		} else {
			warning("Savegame %s is incompatible with this ResidualVM build. Save version: %d.%d; current version: %d.%d",
					filename, savedState->saveMajorVersion(), savedState->saveMinorVersion(),
					SaveGame::SAVEGAME_MAJOR_VERSION, SaveGame::SAVEGAME_MINOR_VERSION);
		}
		delete savedState;
		return;
	}
	int32 dataSize = savedState->beginSection('SUBS');

	char str[200];
	int32 strSize;
	int count = 0;

	for (;;) {
		if (dataSize <= 0)
			break;
		strSize = savedState->readLESint32();
		savedState->read(str, strSize);
		lua_pushobject(result);
		lua_pushnumber(count);
		lua_pushstring(str);
		lua_settable();
		dataSize -= strSize;
		dataSize -= 4;
		count++;
	}
	lua_pushobject(result);

	savedState->endSection();
	delete savedState;
}
vector< string > loadStringList( int playernum, const string &mykey )
{
    if ( playernum < 0 || (unsigned int) playernum >= _Universe->numPlayers() )
        return vector< string > ();
    
    SaveGame *savegame = _Universe->AccessCockpit( playernum )->savegame;
    vector< string >rez;
        
    const vector< string > &ans = savegame->readMissionStringData( mykey );
    if (ans.size() > 0) {
        /* This is the modern way to store string data: as strings */
        rez.reserve(ans.size());
        rez.insert(rez.end(), ans.begin(), ans.end());
    } else {
        /* This variant loads it from float data, converting to character data.
           It's a legacy variant, highly and unpleasantly convoluted and sub-performant,
           but we must support it to be compatible with old savegames */
        const vector< float > &ans = savegame->readMissionData( mykey );
        int lengt = ans.size();
        rez.reserve(ans.size());
        if (lengt >= 1) {
            string curstr;
            int    length = (int)ans[0];
            for (int j = 0; j < length && j < lengt; j++) {
                char myint = (char)ans[j+1];
                if (myint != '\0') {
                    curstr += myint;
                } else {
                    rez.push_back( curstr );
                    curstr = "";
                }
            }
        }
    }
    return rez;
}
Beispiel #9
0
void Lua_V1::GetSaveGameImage() {
	int width = 250, height = 188;
	Bitmap *screenshot;
	int dataSize;

	lua_Object param = lua_getparam(1);
	if (!lua_isstring(param)) {
		lua_pushnil();
		return;
	}
	const char *filename = lua_getstring(param);
	SaveGame *savedState = SaveGame::openForLoading(filename);
	if (!savedState || !savedState->isCompatible()) {
		delete savedState;
		lua_pushnil();
		return;
	}
	dataSize = savedState->beginSection('SIMG');
	uint16 *data = new uint16[dataSize / 2];
	for (int l = 0; l < dataSize / 2; l++) {
		data[l] = savedState->readLEUint16();
	}
	Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data);
	screenshot = new Bitmap(buf, width, height, "screenshot");
	delete[] data;
	if (screenshot) {
		lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
	} else {
		lua_pushnil();
		warning("Could not restore screenshot from file");
		delete savedState;
		return;
	}
	savedState->endSection();
	delete savedState;
}
Beispiel #10
0
SaveStateList GrimMetaEngine::listSaves(const char *target) const {
	Common::String gameId = ConfMan.get("gameid", target);
	Common::Platform platform = Common::parsePlatform(ConfMan.get("platform", target));
	Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
	Common::StringArray filenames;
	Common::String pattern = gameId == "monkey4" ? "efmi###.gsv" : "grim##.gsv";
	
	if (platform == Common::kPlatformPS2)
		pattern = "efmi###.ps2";

	filenames = saveFileMan->listSavefiles(pattern);

	SaveStateList saveList;
	char str[256];
	int32 strSize;
	for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
		// Obtain the last digits of the filename, since they correspond to the save slot
		int slotNum = atoi(file->c_str() + 4);

		if (slotNum >= 0) {
			SaveGame *savedState = SaveGame::openForLoading(*file);
			if (savedState && savedState->isCompatible()) {
				if (platform == Common::kPlatformPS2)
					savedState->beginSection('PS2S');
				else
					savedState->beginSection('SUBS');
				strSize = savedState->readLESint32();
				savedState->read(str, strSize);
				savedState->endSection();
				saveList.push_back(SaveStateDescriptor(slotNum, str));
			}
			delete savedState;
		}
	}

	Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
	return saveList;
}
int main()
{
	SaveGame SaveFileData = { 0, false, 0, 0 };
	char favLetter;
	string input;														//A char variable for processing a users input.
	string text;														//A string variable for when the user wishes to have the contents of the text file printed to the command console.
	ifstream file1;														//An ifstream for reading text files.
	ofstream file2;														//An ofstream for writing in text files.
	string fileinput;													//A string for when the user wishes to add something to the text file.
	file1.open("MyLog.txt");											//Opens the text file MyLog.
	file1.close();														//Closes the text file MyLog.
	for (int i = 0; i < 2; i++)											//A for loop is created so that the choices and following orange text are repeated until the user exits the program.
	{
		system("cls");													//Clears the text on the command console's screen.
		cout << "Welcome user to MyLog text file manipulator.\n"		//Prints to the command console's screen the text in orange.
			<< "Please choose what to do from the following list.\n"	//The numbered words are to tell the user what choices he has to choose from.
			<< "1 Display\n2 Write\n3 Clear\n4 Save\n0 Exit\n";
		getline(cin, input);											//Prompts the user for input.
		if (input == "1")
		{
			system("cls");												//Clears the text on the command console's screen.
			file1.open("MyLog.txt",
				ios_base::in);											//Sets the text file to be open for input statements and not overwrite the text file's content.
			while (!file1.eof())										//A while loop is created to output every line of the text file until there is nothing else in the file.
			{
				getline(file1, text);									//Gives the text string the same content as the text file.
				cout << text << endl;									//"Displays", or prints out, the information that the text string holds.
			}
			system("pause");											//Pauses the program so the user can take their time to read the printed text.
			i = 0;														//Resets i so the for loop continues allowing for further actions.
			file1.close();												//Closes the text file.
		}
		else if (input == "2")
		{
			system("cls");												//Clears the text on the command console's screen.
			file2.open("MyLog.txt",										//Opens the text file for adding new text to the end of the previous content.
				ios_base::app);											
			getline(cin, fileinput);									//Prompts the user to write text that will be inputted into the text file.
			file2 << fileinput << "\n";									//Adds the content of fileinput to the content of the text file.
			system("pause");											//Pauses the program so the user can take their time to read the printed text.
			i = 0;														//Resets i so the for loop continues allowing for further actions.
			file2.close();												//Closes the text file.
		}
		else if (input == "3")
		{
			system("cls");												//Clears the text on the command console's screen.
			file1.open("MyLog.txt",
				ios_base::out
				| ios_base::trunc);										//Clears the content in the text file.
			system("pause");											//Pauses the program so the user can take their time to read the printed text.
			i = 0;														//Resets i so the for loop continues allowing for further actions.
			file1.close();												//Closes the text file.
		}
		else if (input == "4")
		{
				system("cls");											//Clears the text on the command console's screen.
				cout << "Do you want to input data and save it or "		//Prints the orange text to the command console and tells the user to choose either 1 or 2.
					<< "look at the saved data?\n"
					<< "1 Save\n2 Display Save\n";
				cin >> input;											//Prompts the user for input.
				if (input == "1")
				{
					system("cls");										//Clears the text on the command console's screen.
					cout << "What's your Favorite Number?	";			//Prints the orange text to the command console and tells the user to enter their favorite number.
					cin >> SaveFileData.favnum;							//Prompts the user to input their favorite number.
					cout << "How would you rate your Favorite Number "	
						<< "on a scale of 0 to 1000000?\n";				
					cin >> SaveFileData.rating;							
					cout << "What is your Favorite Letter?	";
					cin >> favLetter;
					SaveFileData.Saved = true;
					*SaveFileData.Pointer = &favLetter;
					SaveFileData = { SaveFileData.favnum,				
						SaveFileData.Saved,
						SaveFileData.rating,
						*SaveFileData.Pointer };
					SaveFileData.Save();
					
				}
				else if (input == "2")