Commit b4301098 authored by Gerhard Stein's avatar Gerhard Stein

More secure checks, added basic python script for replacing the DOS Exes

of the Keen games.
parent c328f6e3
Subproject commit 9fbb1c44b9d39ac10bd1d07f9937eec6c92b8f9b
Subproject commit ddb78481b822c0d8f4eab47fa0b197a24643573b
......@@ -334,9 +334,14 @@ bool CGameLauncher::scanExecutables(const std::string& path)
for(int i = 1; i <= 7; ++i)
{
CExeFile executable;
// Load the exe into memory
// Load the exe into memory or a python script
if(!executable.readData(i, path))
continue;
{
if(!executable.readMainPythonScript(i, path))
{
continue;
}
}
// Process the exe for type
GameEntry newentry;
......@@ -392,7 +397,7 @@ bool CGameLauncher::scanExecutables(const std::string& path)
}
void CGameLauncher::start()
bool CGameLauncher::start()
{
// Here it always makes sense to have the mouse cursor active
SDL_ShowCursor(SDL_ENABLE);
......@@ -447,6 +452,8 @@ void CGameLauncher::start()
mGameScanner.setStyle(PROGRESS_STYLE_TEXT);
mGameScanner.RunLoadActionBackground(new GamesScan(*this));
mGameScanner.start();
return true;
}
......@@ -693,7 +700,18 @@ void CGameLauncher::ponderPatchDialog()
if( episode > 0 ) // The game has to have a valid episode!
{
// Get the EXE-Data of the game and load it into the memory.
if(!gKeenFiles.exeFile.readData(episode, DataDirectory))
bool ok = false;
if(gKeenFiles.exeFile.readData(episode, DataDirectory))
{
ok = true;
}
else if(gKeenFiles.exeFile.readMainPythonScript(episode, DataDirectory))
{
ok = true;
}
if(!ok)
{
letchooseagain();
}
......
......@@ -76,7 +76,7 @@ public:
*/
bool setupMenu();
void start();
bool start() override;
void showMessageBox(const std::string &text);
......
......@@ -23,7 +23,7 @@ public:
mDataPath(datapath)
{}
virtual void start() = 0;
virtual bool start() = 0;
void ponder(const float deltaT);
......
......@@ -4,8 +4,10 @@
/**
* @brief start Usually this is started before anything else but still after construction.
*/
void Textmode::start()
{}
bool Textmode::start()
{
return true;
}
/**
* @brief pumpEvent Events like user closes windows or mouse presses are processed here.
......
......@@ -10,7 +10,7 @@ public:
/**
* @brief start Usually this is started before anything else but still after construction.
*/
void start();
bool start() override;
/**
* @brief pumpEvent Events like user closes windows or mouse presses are processed here.
......
......@@ -30,7 +30,7 @@ void KeenEngine::switchToGamePlayMode(const int startLevel)
void KeenEngine::start()
bool KeenEngine::start()
{
int version;
......@@ -44,7 +44,7 @@ void KeenEngine::start()
{
gLogging.textOut(FONTCOLORS::RED, "KeenEngine::loadResources: Could not load data from the EXE File<br>");
gEventManager.add(new GMSwitchToGameLauncher() );
return;
return false;
}
gKeenFiles.setupFilenames(mEp);
......@@ -55,6 +55,8 @@ void KeenEngine::start()
// Load the Resources
loadResources( LOADALL );
return true;
}
void KeenEngine::pumpEvent(const CEvent *evPtr)
......
......@@ -19,7 +19,7 @@ public:
virtual void openMainMenu() = 0;
void start();
bool start() override;
virtual void pumpEvent(const CEvent *evPtr);
......
......@@ -74,9 +74,10 @@ DreamsControlPanel::~DreamsControlPanel()
void DreamsControlPanel::start()
bool DreamsControlPanel::start()
{
US_ControlPanel_Init();
return true;
}
......
......@@ -126,7 +126,7 @@ public:
/**
* @brief start called the first time usually when the instance was created
*/
void start();
bool start() override;
/**
* @brief pumpEvent Events like user closes windows or mouse presses are processed here.
......
......@@ -154,9 +154,10 @@ void InitGame()
}
void DreamsDosIntro::start()
bool DreamsDosIntro::start()
{
InitGame();
return true;
}
void DreamsDosIntro::pumpEvent(const CEvent *evPtr)
......
......@@ -17,7 +17,7 @@ class DreamsDosIntro : public GsEngine
/**
* @brief start Usually this is started before anything else but still after the construction.
*/
void start();
bool start() override;
/**
* @brief pumpEvent Events like user closes windows or mouse presses are processed here.
......
......@@ -398,7 +398,7 @@ void DreamsEngine::applyScreenMode()
}
void DreamsEngine::start()
bool DreamsEngine::start()
{
CExeFile &ExeFile = gKeenFiles.exeFile;
......@@ -436,6 +436,8 @@ void DreamsEngine::start()
gGameStateChange = GSS_INTRO_TEXT;
mpScene->start();
return true;
}
bool mResourcesLoaded = false;
......
......@@ -78,7 +78,7 @@ public:
/**
* @brief start Starts the Dreams engine which refers to accessing RefKeen code
*/
void start();
bool start() override;
/**
* @brief ponder Everything logic related here
......
......@@ -34,13 +34,15 @@ void startLevel();
void DreamsGamePlay::start()
bool DreamsGamePlay::start()
{
if(!ResumeGame)
{
GamePlayStart();
GamePlayStartLevel();
}
return true;
}
......
......@@ -25,7 +25,7 @@ public:
/**
* @brief start called the first time usually when the instance was created
*/
void start();
bool start() override;
/**
* @brief pumpEvent Events like user closes windows or mouse presses are processed here.
......
......@@ -58,9 +58,10 @@ DreamsIntro::DreamsIntro()
}
void DreamsIntro::start()
bool DreamsIntro::start()
{
ingame = false;
return true;
}
void DreamsIntro::pumpEvent(const CEvent *evPtr)
......
......@@ -23,7 +23,7 @@ public:
/**
* @brief start Usually this is started before anything else but still after the construction.
*/
void start();
bool start() override;
/**
* @brief pumpEvent Events like user closes windows or mouse presses are processed here.
......
......@@ -80,7 +80,8 @@ void CExeFile::dumpDataFile(const std::string& filename)
ofile.write( reinterpret_cast<char*>(m_rawdata), m_datasize - m_headersize);
}
bool CExeFile::readData(const unsigned int episode, const std::string& datadirectory)
bool CExeFile::readData(const unsigned int episode,
const std::string& datadirectory)
{
// TODO: It would be nice to gather a list of executables and by scanning it decide which episode will be played.
......@@ -199,8 +200,44 @@ bool CExeFile::readData(const unsigned int episode, const std::string& datadirec
return true;
}
bool CExeFile::readMainPythonScript(const unsigned int episode,
const std::string& datadirectory)
{
std::string filename = datadirectory + "/keen" + itoa(episode) + ".py";
std::ifstream File;
OpenGameFileR(File, filename, std::ios::binary);
// If we still have no file found, the directory with the game cannot be used at all.
if(!File)
return false;
m_filename = filename;
m_episode = episode;
std::string localDataDir = datadirectory;
if( localDataDir != "")
{
if(*(localDataDir.end()-1) != '/')
localDataDir += "/";
}
auto &keenFiles = gKeenFiles;
keenFiles.gameDir = localDataDir;
gLogging << "Python script \"" << filename << "\" detected!";
mIsPythonScript = true;
return true;
}
bool CExeFile::Supported()
{
if(mIsPythonScript)
return true;
if( m_supportmap.find(m_datasize) == m_supportmap.end())
return false;
......
......@@ -50,6 +50,15 @@ class CExeFile {
*/
bool readData(const unsigned int episode, const std::string& datadirectory);
/**
* @brief readMainPythonScript Try to get a main python script load
* @param episode Episode for which to read for
* @param datadirectory path where the data is located
* @return if everything went well true, otherwise false
*/
bool readMainPythonScript(const unsigned int episode,
const std::string& datadirectory);
/**
* @brief Tells whether The Exe-File is supported by CG or not.
* This Information is hard-coded in the CExefile constructor
......@@ -115,6 +124,7 @@ private:
size_t m_datasize;
size_t m_headersize;
int m_episode;
bool mIsPythonScript = false;
bool m_demo;
unsigned int m_crc;
std::vector<byte> mData;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment