Пример #1
0
static void disp_load_game_rec(int recNo, int x, int y, int refreshFlag) {
    if((recNo>0)&&(recNo<=game_file_array.size())) {
	GameFile* gfPtr = game_file_array[recNo];
	char* name = gfPtr->get_save_name();
	font_chartsm.put(x,y,name);
    }
};
Пример #2
0
//-------- Begin of function GameFileArray::load_all_game_header --------//
//
// Load all headers of all saved game files in current directory.
//
void GameFileArray::load_all_game_header(const char *path, const char *extStr)
{
	int       i;
	Directory gameDir;
	GameFile  gameFile;
	File      file;

	// ##### begin Gilbert 26/5 ######//
	String str;
	if( path && path[0] != '\0' )
	{
		str = path;
		str += "/";
		str += extStr;
	}
	else
	{
		str = extStr;
	}

	// gameDir.read( player_profile.save_game_path(extStr), 1 );  // 1-Sort file names
	gameDir.read( str, 1 );  // 1-Sort file names

	//-------- read in the headers of all game sets -------//

	zap();

	for( i=1 ; i<=gameDir.size() ; i++ )
	{
		// Directory store file name without path
		if( path && path[0] != '\0' )
		{
			str = path;
			str += "/";
			str += gameDir[i]->name;
		}
		else
		{
			str = gameDir[i]->name;
		}

		if( file.file_open( str, 1, 1 )      // last 1=allow varying read & write size
			&& file.file_read(&gameFile, sizeof(GameFile))
			&& gameFile.validate_header() )
		{
			strcpy( gameFile.file_name, file.file_name );  // in case that the name may be different
			gameFile.file_date = gameDir[i]->time;
	      linkin(&gameFile);
		}
		file.file_close();
	}
	// ##### end Gilbert 26/5 ######//
}
Пример #3
0
//-------- Begin of function GameFileArray::save_new_game -----//
//
// Save current game to a new saved game file immediately without
// prompting menu.
//
// Called by GameFileArray::process_action() and error handler.
//
// [char*] fileName - file name of the saved game
//
// return : <int> 1 - saved successfully.
//                0 - not saved.
//
int GameFileArray::save_new_game(const char* fileName)
{
	GameFile  gameFile;
	GameFile* gameFilePtr;
	int       addFlag=1;
	int       gameFileRecno;

	memset( &gameFile, 0, sizeof(GameFile) );

	if( fileName )
	{
		//----- check for overwriting an existing file ----//

		for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ )
		{
			gameFilePtr = game_file_array[gameFileRecno];

			if( strcmp(gameFilePtr->file_name, fileName)==0 )      // if this file name already exist
			{
				addFlag=0;
				break;
			}
		}

		strcpy( gameFile.file_name, fileName );
	}
	else
	{
		gameFile.set_file_name();        // give it a new game_file_name based on current group name
	}

	//----------- save game now ------------//

	if( gameFile.save_game(fileName) )
	{
		strcpy( last_file_name, gameFile.file_name );

		if( addFlag )
		{
			linkin(&gameFile);

			quick_sort( sort_game_file_function );
		}
		else
		{
			game_file_array.update(&gameFile, gameFileRecno);
		}

		return 1;
	}
	return 0;
}
Пример #4
0
GeckoCodeWidget::GeckoCodeWidget(const GameFile& game)
    : m_game(game), m_game_id(game.GetGameID().toStdString()), m_game_revision(game.GetRevision())
{
  CreateWidgets();
  ConnectWidgets();

  IniFile game_ini_local;

  // We don't use LoadLocalGameIni() here because user cheat codes that are installed via the UI
  // will always be stored in GS/${GAMEID}.ini
  game_ini_local.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + m_game_id + ".ini");

  IniFile game_ini_default = SConfig::GetInstance().LoadDefaultGameIni(m_game_id, m_game_revision);
  m_gecko_codes = Gecko::LoadCodes(game_ini_default, game_ini_local);

  UpdateList();
}
Пример #5
0
void WMOModelInstance::init(char *fname, GameFile &f)
{
  filename = QString::fromLatin1(fname);
  filename = filename.toLower();
  filename.replace(".mdx", ".m2");
  filename.replace(".mdl", ".m2");

  model = 0;

  float ff[3];
  f.read(ff, 12); // Position (X,Z,-Y)
  pos = fixCoordSystem(Vec3D(ff[0], ff[1], ff[2]));
  f.read(&w, 4); // W component of the orientation quaternion
  f.read(ff, 12); // X, Y, Z components of the orientaton quaternion
  dir = fixCoordSystem(Vec3D(ff[0], ff[1], ff[2]));
  f.read(&sc, 4); // Scale factor
  f.read(&d1, 4); // (B,G,R,A) Lightning-color. 
  lcol = Vec3D(((d1 & 0xff0000) >> 16) / 255.0f, ((d1 & 0x00ff00) >> 8) / 255.0f, (d1 & 0x0000ff) / 255.0f);
}
Пример #6
0
//------- Begin of function GameFileArray::process_action ------//
//
// [int] saveNew - save on a new game file
//                 (default : 0)
//
// return : <int> 1 - process ok
//                0 - process cancelled
//               -1 - save/load failed
//
int GameFileArray::process_action(int saveNew)
{
	//------------ save game --------------//

	if( action_mode == 1 )
	{
		if( saveNew || browse_recno==0 )   // save on empty slot
		{
			if ( !save_new_game())
				return -1;
		}
		else           // save on existing slot
		{
			if( !box.ask( _("It will overwrite the existing saved game, proceed ?") ) )
				return 0;

			GameFile* gameFile = game_file_array[browse_recno];

			if( !gameFile->save_game())
				return -1;

			strcpy( last_file_name, gameFile->file_name );
		}

		return 1;
	}

	//----------- load game -------------//

	else
	{
		GameFile* gameFile = game_file_array[browse_recno];

		int rc = gameFile->load_game((const char*)sys.dir_config, NULL);
		if( rc > 0 )
			strcpy( last_file_name, gameFile->file_name );
		return rc;
	}

	return 0;
}
Пример #7
0
//-------- Begin of function GameFileArray::load_all_game_header --------//
//
// Load all headers of all saved game files in current directory.
//
void GameFileArray::load_all_game_header(const char *extStr)
{
	char full_path[MAX_PATH+1];
	int       i;
	Directory gameDir;
	GameFile  gameFile;
	File      file;

	if (!misc.path_cat(full_path, sys.dir_config, extStr, MAX_PATH))
	{
		ERR("Path to the config directory too long.\n");
		return;
	}
	gameDir.read(full_path, 0);  // 0-Don't sort file names

	//-------- read in the headers of all game sets -------//

	zap();

	for( i=1 ; i<=gameDir.size() ; i++ )
	{
		if (!misc.path_cat(full_path, sys.dir_config, gameDir[i]->name, MAX_PATH))
		{
			ERR("Path to the saved game too long.\n");
			continue;
		}
		if( file.file_open(full_path, 1, 1)      // last 1=allow varying read & write size
			&& file.file_read(&gameFile, sizeof(GameFile))
			&& gameFile.validate_header() )
		{
			strcpy( gameFile.file_name, gameDir[i]->name );  // in case that the name may be different
			gameFile.file_date = gameDir[i]->time;
	      linkin(&gameFile);
		}
		file.file_close();
	}

	quick_sort( sort_game_file_function );
}
Пример #8
0
//-------- Begin of function GameFileArray::save_new_game -----//
//
// Save current game to a new saved game file immediately without
// prompting menu.
//
// Called by GameFileArray::process_action() and error handler.
//
// <char*> fileName - file name of the saved game
//
// return 1 - success
//        0 - cancel
//       -1 - fail
//
// ###### begin Gilbert 20/1 ########//
int GameFileArray::save_new_game(const char* fileName)
{
	GameFile  gameFile;
	GameFile* gameFilePtr;
	int       addFlag=1;
	int       gameFileRecno;

	memset( &gameFile, 0, sizeof(GameFile) );

	if( fileName )		// has a filename before extension
	{
		load_all_game_header( save_default_dir, save_default_ext );

		// ### begin Gilbert 26/5 #####//
		// fileName = player_profile.save_game_path(fileName);
		// ### end Gilbert 26/5 #####//

		if( save_default_dir[0] != '\0' )
		{
			strcpy( gameFile.file_name, save_default_dir );
			strcat( gameFile.file_name, "/" );
			strcat( gameFile.file_name, fileName );
		}
		else
		{
			strcpy( gameFile.file_name, fileName );
		}

		// if fileName without extension append

		if( !strchr(fileName, '.' ) )
		{
			strcat(gameFile.file_name, strchr( save_default_ext, '.') );		// remove '*' of "*.SAV"
		}

		//----- check for overwriting an existing file ----//

		for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ )
		{
			gameFilePtr = game_file_array[gameFileRecno];

			// ###### begin Gilbert 31/10 ######//
			if( strcasecmp(gameFilePtr->file_name, gameFile.file_name)==0 )      // if this file name already exist
			// ###### end Gilbert 31/10 ######//
			{
				addFlag=0;
				break;
			}
		}
		// strcpy( gameFile.file_name, fileName );		// now use gameFile.file_name instead
   }
	else
   {
		load_all_game_header( save_default_dir, save_default_ext );

		// find the extension begin with '.'
		err_when( !strchr(save_default_ext, '.') );
      gameFile.set_file_name(save_default_dir, strchr(save_default_ext, '.') );        // give it a new game_file_name based on current group name
   }

	// --------- ask description -------//

	if( !gameFile.ask_desc() )
		return 0;

	//----------- save game now ------------//

	if( gameFile.save_game(save_default_dir, NULL, NULL) )		// use gameFile.file_name
	{
		strcpy( last_file_name, gameFile.file_name );

		if( addFlag )
		{
         linkin(&gameFile);

			quick_sort( sort_game_file_function );
      }
		else
      {
			// #### begin Gilbert 31/10 ######//
         update(&gameFile, gameFileRecno);
			// #### end Gilbert 31/10 ######//
      }

		return 1;
   }

	return -1;

	// ###### end Gilbert 20/1 ########//
}
Пример #9
0
//------- Begin of function GameFileArray::process_action ------//
//
// [int] saveNew - save on a new game file
//                 (default : 0)
//
// return : <int> 1 - process ok
//                0 - process cancelled
//               -1 - save/load failed
//
int GameFileArray::process_action(int saveNew)
{
	//------------ save game --------------//

	if( action_mode == 1 )
	{
		if( saveNew || browse_recno==0 )   // save on empty slot
		{
			// #### begin Gilbert 20/1 ######//
			return save_new_game(NULL);
			// #### end Gilbert 20/1 ######//
		}
		else           // save on existing slot
		{
			if( !box.ask(text_game_menu.str_ask_overwrite()) )// "It will overwrite the existing saved game, proceed ?" ) )
				return 0;

			GameFile* gameFile = game_file_array[browse_recno];

			// ###### begin Gilbert 20/1 ########//
			if( !gameFile->ask_desc() )
				return 0;
			// ###### end Gilbert 20/1 ########//

			if( !gameFile->save_game(save_default_dir, NULL, NULL))
				return -1;

			strcpy( last_file_name, gameFile->file_name );
		}

		return 1;
	}

	//----------- load game -------------//

	else
	{
		GameFile* gameFile = game_file_array[browse_recno];

		// check gameFile->campaign_id. Campaign save game can be loaded
		// if and only if in campaign mode

		if( !sys.debug_session && gameFile->scenario_cheat_flag < sys.scenario_cheat_flag )
		{
			box.msg( text_game_menu.str_editor_cant_load() );// "Cannot load in scenario editor" );
			return 0;
		}

		// ###### begin Gilbert 9/4 ########//

		if( !pre_game && (game.is_campaign_mode() || gameFile->campaign_id) )
		{
			game.set_load_game_in_main_menu(gameFile->file_name);
			sys.signal_exit_flag = 2;		// quit to main menu and it will load game automatically
			return 1;
		}
		// ###### end Gilbert 9/4 ########//

		int rc = gameFile->load_game(save_default_dir, NULL);
		if( rc > 0 )
			strcpy( last_file_name, gameFile->file_name );
		return rc;
	}

	return 0;
}
Пример #10
0
bool Gui::LoadMenu(const GameFile & a_menuFile, const DataPack * a_dataPack)
{
	// Load the menu file
	Widget * createdMenu = NULL;
	if (a_menuFile.IsLoaded())
	{
		// Create a new widget and copy properties from file
		if (GameFile::Object * menuObject = a_menuFile.FindObject("menu"))
		{
			if (GameFile::Property * nameProp = menuObject->FindProperty("name"))
			{
				createdMenu = new Widget();
				createdMenu->SetName(a_menuFile.GetString("menu", "name"));
				if (a_dataPack == NULL || !a_dataPack->IsLoaded())
				{
					char menuFilePath[StringUtils::s_maxCharsPerLine];
					sprintf(menuFilePath, "%s%s.mnu", m_guiPath, createdMenu->GetName());
					createdMenu->SetFilePath(menuFilePath);
				}
				createdMenu->SetActive(false);

				// TODO Support for non fullscreen menus
				createdMenu->SetSize(Vector2(2.0f, 2.0f));
				createdMenu->SetDrawPos(Vector2(-1.0, 1.0));

				// Load child elements of the menu
				LinkedListNode<GameFile::Object> * childWidget = menuObject->GetChildren();
				while (childWidget != NULL)
				{
					GameFile::Object * curObject = childWidget->GetData();
					Widget * newChild = CreateWidget(curObject, createdMenu);
					// If not specified in the file, align child widgets to the parent menu
					if (!newChild->HasAlignTo())
					{
						newChild->SetAlignTo(createdMenu);
					}
					childWidget = childWidget->GetNext();
				}

				// Add to list of menus
				m_menus.InsertNew(createdMenu);
			}
			else // No properties present
			{
				Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Error loading menu file %s, menu does not have a name property.", a_menuFile);
			}

			// Set the active menu to the last menu with the begin loaded property
			if (createdMenu != NULL && menuObject->FindProperty("beginLoaded"))
			{
				if (menuObject->FindProperty("beginLoaded")->GetBool())
				{
					m_startupMenu = createdMenu;
				}
			}
		}
		else // Unexpected file format, no root element
		{
			Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Error loading menu file %s, no valid menu parent element.", a_menuFile);
		}

		return true;
	}
	return false;
}
Пример #11
0
void DGameTracker::ScanForGames()
{
    setDisabled(true);

    CFileSearch::XStringVector dirs(SConfig::GetInstance().m_ISOFolder);

    if (SConfig::GetInstance().m_RecursiveISOFolder)
    {
        for (u32 i = 0; i < dirs.size(); i++)
        {
            File::FSTEntry FST_Temp;
            File::ScanDirectoryTree(dirs[i], FST_Temp);
            for (auto& entry : FST_Temp.children)
            {
                if (entry.isDirectory)
                {
                    bool duplicate = false;
                    for (auto& dir : dirs)
                    {
                        if (dir == entry.physicalName)
                        {
                            duplicate = true;
                            break;
                        }
                    }
                    if (!duplicate)
                        dirs.push_back(entry.physicalName);
                }
            }
        }
    }

    for (std::string& dir : dirs)
        m_watcher.addPath(QString::fromStdString(dir));

    CFileSearch::XStringVector exts;
    if (SConfig::GetInstance().m_ListGC)
    {
        exts.push_back("*.gcm");
        exts.push_back("*.gcz");
    }
    if (SConfig::GetInstance().m_ListWii || SConfig::GetInstance().m_ListGC)
    {
        exts.push_back("*.iso");
        exts.push_back("*.ciso");
        exts.push_back("*.wbfs");
    }
    if (SConfig::GetInstance().m_ListWad)
        exts.push_back("*.wad");

    CFileSearch FileSearch(exts, dirs);
    const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
    QList<GameFile*> newItems;
    QStringList allItems;

    if (!rFilenames.empty())
    {
        for (u32 i = 0; i < rFilenames.size(); i++)
        {
            std::string FileName;
            SplitPath(rFilenames[i], nullptr, &FileName, nullptr);
            QString NameAndPath = QString::fromStdString(rFilenames[i]);
            allItems.append(NameAndPath);

            if (m_games.keys().contains(NameAndPath))
                continue;

            GameFile* obj = new GameFile(rFilenames[i]);
            if (obj->IsValid())
            {
                bool list = true;

                switch(obj->GetCountry())
                {
                case DiscIO::IVolume::COUNTRY_AUSTRALIA:
                    if (!SConfig::GetInstance().m_ListAustralia)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_EUROPE:
                    if (!SConfig::GetInstance().m_ListPal)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_FRANCE:
                    if (!SConfig::GetInstance().m_ListFrance)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_GERMANY:
                    if (!SConfig::GetInstance().m_ListGermany)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_INTERNATIONAL:
                    if (!SConfig::GetInstance().m_ListInternational)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_ITALY:
                    if (!SConfig::GetInstance().m_ListItaly)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_JAPAN:
                    if (!SConfig::GetInstance().m_ListJap)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_KOREA:
                    if (!SConfig::GetInstance().m_ListKorea)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_NETHERLANDS:
                    if (!SConfig::GetInstance().m_ListNetherlands)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_RUSSIA:
                    if (!SConfig::GetInstance().m_ListRussia)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_SPAIN:
                    if (!SConfig::GetInstance().m_ListSpain)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_TAIWAN:
                    if (!SConfig::GetInstance().m_ListTaiwan)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_USA:
                    if (!SConfig::GetInstance().m_ListUsa)
                        list = false;
                    break;
                case DiscIO::IVolume::COUNTRY_UNKNOWN:
                default:
                    if (!SConfig::GetInstance().m_ListUnknown)
                        list = false;
                    break;
                }

                if (list)
                    newItems.append(obj);
            }
        }
    }

    // Process all the new GameFiles
    for (GameFile* o : newItems)
        m_games.insert(o->GetFileName(), o);

    // Check for games that were removed
    QList<GameFile*> removedGames;
    for (QString& path : m_games.keys())
    {
        if (!allItems.contains(path))
        {
            removedGames.append(m_games.value(path));
            m_games.remove(path);
        }
    }

    m_tree_widget->AddGames(newItems);
    m_grid_widget->AddGames(newItems);

    m_tree_widget->RemoveGames(removedGames);
    m_grid_widget->RemoveGames(removedGames);

    for (GameFile* file : removedGames)
        delete file;

    setDisabled(false);
}
Пример #12
0
void DGameTracker::ScanForGames()
{
	setDisabled(true);

	delete m_watcher;
	m_watcher = new QFileSystemWatcher(this);
	for (std::string dir : SConfig::GetInstance().m_ISOFolder)
		m_watcher->addPath(QString::fromStdString(dir));
	if (SConfig::GetInstance().m_RecursiveISOFolder)
	{
		for (std::string dir : FindSubdirectories(SConfig::GetInstance().m_ISOFolder, /*recursive*/ true))
			m_watcher->addPath(QString::fromStdString(dir));
	}

	std::vector<std::string> exts;
	if (SConfig::GetInstance().m_ListGC)
	{
		exts.push_back("*.gcm");
		exts.push_back("*.gcz");
	}
	if (SConfig::GetInstance().m_ListWii || SConfig::GetInstance().m_ListGC)
	{
		exts.push_back("*.iso");
		exts.push_back("*.ciso");
		exts.push_back("*.wbfs");
	}
	if (SConfig::GetInstance().m_ListWad)
		exts.push_back("*.wad");
	if (SConfig::GetInstance().m_ListElfDol)
	{
		exts.push_back("*.dol");
		exts.push_back("*.elf");
	}

	auto rFilenames = DoFileSearch(exts, SConfig::GetInstance().m_ISOFolder, SConfig::GetInstance().m_RecursiveISOFolder);
	QList<GameFile*> newItems;
	QStringList allItems;

	if (!rFilenames.empty())
	{
		for (u32 i = 0; i < rFilenames.size(); i++)
		{
			std::string FileName;
			SplitPath(rFilenames[i], nullptr, &FileName, nullptr);
			QString NameAndPath = QString::fromStdString(rFilenames[i]);
			allItems.append(NameAndPath);

			if (m_games.keys().contains(NameAndPath))
				continue;

			GameFile* obj = new GameFile(rFilenames[i]);
			if (obj->IsValid())
			{
				bool list = true;

				switch (obj->GetCountry())
				{
					case DiscIO::IVolume::COUNTRY_AUSTRALIA:
						if (!SConfig::GetInstance().m_ListAustralia)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_EUROPE:
						if (!SConfig::GetInstance().m_ListPal)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_FRANCE:
						if (!SConfig::GetInstance().m_ListFrance)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_GERMANY:
						if (!SConfig::GetInstance().m_ListGermany)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_ITALY:
						if (!SConfig::GetInstance().m_ListItaly)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_JAPAN:
						if (!SConfig::GetInstance().m_ListJap)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_KOREA:
						if (!SConfig::GetInstance().m_ListKorea)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_NETHERLANDS:
						if (!SConfig::GetInstance().m_ListNetherlands)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_RUSSIA:
						if (!SConfig::GetInstance().m_ListRussia)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_SPAIN:
						if (!SConfig::GetInstance().m_ListSpain)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_TAIWAN:
						if (!SConfig::GetInstance().m_ListTaiwan)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_USA:
						if (!SConfig::GetInstance().m_ListUsa)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_WORLD:
						if (!SConfig::GetInstance().m_ListWorld)
							list = false;
						break;
					case DiscIO::IVolume::COUNTRY_UNKNOWN:
					default:
						if (!SConfig::GetInstance().m_ListUnknown)
							list = false;
						break;
				}

				if (list)
					newItems.append(obj);
			}
		}
	}

	// Process all the new GameFiles
	for (GameFile* o : newItems)
		m_games.insert(o->GetFileName(), o);

	// Check for games that were removed
	QList<GameFile*> removedGames;
	for (QString& path : m_games.keys())
	{
		if (!allItems.contains(path))
		{
			removedGames.append(m_games.value(path));
			m_games.remove(path);
		}
	}

	m_tree_widget->AddGames(newItems);
	m_grid_widget->AddGames(newItems);

	m_tree_widget->RemoveGames(removedGames);
	m_grid_widget->RemoveGames(removedGames);

	for (GameFile* file : removedGames)
		delete file;

	setDisabled(false);
}