Commit b1204d05 authored by Gerhard Stein's avatar Gerhard Stein

New way of reading exe offsets. This helps the level entry names in the MOMGalaxy mod

parent 76e7cd3b
......@@ -28,7 +28,7 @@ typedef void * memptr;
* @param ptr Pointer to data
* @return The value
*/
static inline auto GETWORD(byte *ptr) -> word
static inline auto GETWORD(const byte *ptr) -> word
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
return (ptr[0]<<8 | ptr[1]);
......@@ -56,7 +56,7 @@ static inline auto READWORD(byte *&ptr) -> word
* @param ptr Pointer to data
* @return The value
*/
static inline auto GETLONGWORD(byte *ptr) -> longword
static inline auto GETLONGWORD(const byte *ptr) -> longword
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
longword val = ptr[0]<<24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
......@@ -79,6 +79,19 @@ static inline auto READLONGWORD(byte *&ptr) -> longword
return val;
}
/**
* @brief MERGERLOFFSET Strange offset merger.
* For some offsets, it helps detecting the pointer correctly.
* It is used for level names basically
* @param levelLongWord word to work on
* @return tranformed value
*/
static inline auto MERGERLOFFSET(const unsigned long levelLongWord) -> unsigned long
{
const unsigned long part1 = levelLongWord >> 12;
const unsigned long part2 = levelLongWord & 0xFFF;
return part1 + part2;
};
#endif /* __TYPEDEFINITIONS_H__ */
......@@ -34,7 +34,7 @@ CMessages::extractNextString( const std::string matchingstring )
{
std::string Text;
for(unsigned long pos=mOffset ; ; pos++)
for(unsigned long pos = mOffset ; ; pos++)
{
if(mp_exe[pos] == 0x0)
{
......@@ -54,11 +54,14 @@ CMessages::extractNextString( const std::string matchingstring )
// This function reads the strings specified between the offsets,
// and creates a pair for for the map
std::pair<std::string, std::string>
CMessages::extractString( const std::string matchingstring, unsigned long start, unsigned long end, long offset )
CMessages::extractString( const std::string matchingstring,
const unsigned long start,
const unsigned long end,
const long offset )
{
std::string Text;
for(unsigned long pos=start+offset ; pos<end+offset ; pos++)
for(unsigned long pos = start+offset ; pos < end+offset ; pos++)
{
while(mp_exe[pos] == 0xA)
{
......@@ -189,33 +192,32 @@ bool CMessages::extractEp4Strings(std::map<std::string, std::string>& StringMap)
return false;
}
bool CMessages::extractEp5Strings(std::map<std::string, std::string>& StringMap)
bool CMessages::extractEp5Strings(std::map<std::string, std::string>& stringMap)
{
switch(m_version)
{
case 140:
{
// Level loading Texts (Base is usually at 0x2C00)
setDecodeOffset(0x201F0);
StringMap.insert( extractNextString( "LEVEL0_LOAD_TEXT" ) );
unsigned int levelOffset = 0x201F0;
for(unsigned int i=1 ; i<=18 ; i++)
int entryPtr = 0x31B18;
for(int i=0 ; i<=18 ; i++)
{
levelOffset += 0x30;
auto levelOffset = MERGERLOFFSET( GETLONGWORD(&(mp_exe[entryPtr])) );
setDecodeOffset(levelOffset);
const std::string levelKey = "LEVEL" + to_string(i) + "_LOAD_TEXT";
StringMap.insert( extractNextString( levelKey ) );
stringMap.insert( extractNextString( levelKey ) );
entryPtr += 4;
}
// Fuse text. This text is loaded when you break one of the fuses
setDecodeOffset(0x31BFB);
StringMap.insert( extractNextString( "FUSE_WONDER" ) );
StringMap.insert( extractNextString( "FUSE_CASUAL" ) );
stringMap.insert( extractNextString( "FUSE_WONDER" ) );
stringMap.insert( extractNextString( "FUSE_CASUAL" ) );
setDecodeOffset(0x1FDE0);
StringMap.insert( extractNextString( "STORY_TEXT" ) );
stringMap.insert( extractNextString( "STORY_TEXT" ) );
return true;
......
......@@ -24,13 +24,16 @@ private:
extractNextString( const std::string matchingstring );
std::pair<std::string, std::string>
extractString( const std::string matchingstring, unsigned long start, unsigned long end, long offset=0 );
extractString(const std::string matchingstring,
const unsigned long start,
const unsigned long end,
const long offset=0 );
std::pair<std::string, std::string>
extractStringOff( const std::string matchingstring, unsigned long start );
bool extractEp4Strings(std::map<std::string, std::string>& StringMap);
bool extractEp5Strings(std::map<std::string, std::string>& StringMap);
bool extractEp5Strings(std::map<std::string, std::string>& stringMap);
bool extractEp6Strings(std::map<std::string, std::string>& StringMap);
unsigned char *mp_exe;
......
......@@ -273,10 +273,10 @@ void CSettings::setOption( const GameOption opt, const std::string &menuname, co
void CSettings::loadDefaultGameCfg()
{
setOption( GameOption::ALLOWPKING, "Friendly Fire ", "pking", 1 );
setOption( GameOption::KEYSTACK, "Keystacking ", "keystack", 0 );
setOption( GameOption::LVLREPLAYABILITY, "Replay Levels ", "level_replayability", 0 );
setOption( GameOption::KEYSTACK, "Keystacking ", "keystack", 0 );
setOption( GameOption::LVLREPLAYABILITY,"Replay Levels ", "level_replayability", 0 );
setOption( GameOption::RISEBONUS, "Rising Bonus ", "rise_bonus", 1 );
setOption( GameOption::MODERN, "Modern Style ", "modern_style", 1 );
setOption( GameOption::MODERN, "Modern Style ", "modern_style", 1 );
setOption( GameOption::HUD, "HUD Display ", "hud", 1 );
setOption( GameOption::SHOWFPS, "Show FPS ", "showfps", 0 );
setOption( GameOption::FLASHEFFECT, "Flash Effects ", "flashfx", 1 );
......@@ -332,4 +332,3 @@ bool CSettings::saveGameOptions()
const std::string CSettings::getConfigFileName() const
{ return CONFIGFILENAME; }
CSettings::~CSettings() {}
......@@ -35,7 +35,6 @@ public:
char value);
const std::string getConfigFileName() const;
virtual ~CSettings();
};
#endif /* CSETTINGS_H_ */
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