diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 8de2f821e..3ac83ba65 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -222,22 +222,41 @@ string formatString(string str) { } string getGameCustomCoreDataPath(string originalBasePath, string uniqueFilePath) { + // original file path setup if(originalBasePath != "") { endPathWithSlash(originalBasePath); } + // - string result = originalBasePath + uniqueFilePath; - //string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); + // mydata user data override Config &config = Config::getInstance(); string data_path = config.getString("UserData_Root",""); if(data_path != "") { endPathWithSlash(data_path); } + // - if(data_path != "" && - (uniqueFilePath == "" || fileExists(data_path + uniqueFilePath) == true)) { + // if set this is the current active mod + string custom_mod_path = config.getCustomRuntimeProperty(Config::ACTIVE_MOD_PROPERTY_NAME); + if(custom_mod_path != "") { + endPathWithSlash(custom_mod_path); + } + // + + // decide which file to use + string result = ""; + + if(custom_mod_path != "" && + (uniqueFilePath == "" || fileExists(custom_mod_path + uniqueFilePath) == true)) { + result = custom_mod_path + uniqueFilePath; + } + else if(data_path != "" && + (uniqueFilePath == "" || fileExists(data_path + uniqueFilePath) == true)) { result = data_path + uniqueFilePath; } + else { + result = originalBasePath + uniqueFilePath; + } //printf("data_path [%s] result [%s]\n",data_path.c_str(),result.c_str()); return result; diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index 7a6927b31..074fc9051 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -67,6 +67,9 @@ const char *Config::glestuser_ini_filename = "glestuser.ini"; const char *Config::glestkeys_ini_filename = "glestkeys.ini"; const char *Config::glestuserkeys_ini_filename = "glestuserkeys.ini"; +const char *Config::ACTIVE_MOD_PROPERTY_NAME = "current_mod_name"; +map Config::customRuntimeProperties; + // ===================================================== // class Config // ===================================================== diff --git a/source/glest_game/global/config.h b/source/glest_game/global/config.h index 50a41a89b..33267f130 100644 --- a/source/glest_game/global/config.h +++ b/source/glest_game/global/config.h @@ -37,6 +37,7 @@ enum ConfigType { class Config { private: + std::pair properties; std::pair cfgType; std::pair fileNameParameter; @@ -48,11 +49,17 @@ private: static const char *glest_ini_filename; static const char *glestuser_ini_filename; + static map customRuntimeProperties; + public: + static const char *glestkeys_ini_filename; static const char *glestuserkeys_ini_filename; + static const char *ACTIVE_MOD_PROPERTY_NAME; + protected: + Config(); Config(std::pair type, std::pair file, std::pair fileMustExist); bool tryCustomPath(std::pair &type, std::pair &file, string custom_path); @@ -60,6 +67,7 @@ protected: vector > getPropertiesFromContainer(const Properties &propertiesObj) const; public: + static Config &getInstance(std::pair type = std::make_pair(cfgMainGame,cfgUserGame) , std::pair file = std::make_pair(glest_ini_filename,glestuser_ini_filename) , std::pair fileMustExist = std::make_pair(true,false) ); @@ -92,12 +100,12 @@ public: string getFileName(bool userFilename) const; - //char translateStringToCharKey(const string &value) const; - //SDLKey translateSpecialStringToSDLKey(char c) const; - SDLKey translateStringToSDLKey(const string &value) const; string toString(); + + static string getCustomRuntimeProperty(string key) { return customRuntimeProperties[key]; } + static void setCustomRuntimeProperty(string key, string value) { customRuntimeProperties[key] = value; } }; }}//end namespace diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index d5820db49..169ba10db 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2544,6 +2544,33 @@ int glestMain(int argc, char** argv) { return -1; } + if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MOD])) == true) { + + int foundParamIndIndex = -1; + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MOD]) + string("="),&foundParamIndIndex); + if(foundParamIndIndex < 0) { + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MOD]),&foundParamIndIndex); + } + string scenarioName = argv[foundParamIndIndex]; + vector paramPartTokens; + Tokenize(scenarioName,paramPartTokens,"="); + if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { + string autoloadModName = paramPartTokens[1]; + if(Properties::applyTagsToValue(autoloadModName) == true) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Property key [%s] now has value [%s]\n",Config::ACTIVE_MOD_PROPERTY_NAME,autoloadModName.c_str()); + } + + Config::setCustomRuntimeProperty(Config::ACTIVE_MOD_PROPERTY_NAME,autoloadModName); + + printf("Setting mod active [%s]\n",autoloadModName.c_str()); + } + else { + printf("\nInvalid mod pathname specified on commandline [%s] mod [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); + printParameterHelp(argv[0],foundInvalidArgs); + return -1; + } + } + SystemFlags::init(haveSpecialOutputCommandLineOption); //SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled = true; //SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = true; diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index 827b7ca3a..c9cd403e9 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -29,6 +29,7 @@ const char *GAME_ARGS[] = { "--starthost", "--headless-server-mode", "--load-scenario", + "--load-mod", "--preview-map", "--version", "--opengl-info", @@ -55,13 +56,11 @@ const char *GAME_ARGS[] = { "--disable-sound", "--enable-legacyfonts", "--force-ftglfonts", -// "--use-video-settings", "--resolution", "--colorbits", "--depthbits", "--fullscreen", - //"--windowed", "--use-font", "--font-basesize", @@ -76,6 +75,7 @@ enum GAME_ARG_TYPE { GAME_ARG_SERVER, GAME_ARG_MASTERSERVER_MODE, GAME_ARG_LOADSCENARIO, + GAME_ARG_MOD, GAME_ARG_PREVIEW_MAP, GAME_ARG_VERSION, GAME_ARG_OPENGL_INFO, @@ -104,7 +104,7 @@ enum GAME_ARG_TYPE { GAME_ARG_DISABLE_SOUND, GAME_ARG_ENABLE_LEGACYFONTS, GAME_ARG_FORCE_FTGLFONTS, - //GAME_ARG_USE_VIDEO_SETTINGS, + GAME_ARG_USE_RESOLUTION, GAME_ARG_USE_COLORBITS, GAME_ARG_USE_DEPTHBITS, @@ -133,6 +133,8 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\tvps - which does NOT read commands from the local console (required for some vps's)."); printf("\n%s=x\t\tAuto loads the specified scenario by scenario name.",GAME_ARGS[GAME_ARG_LOADSCENARIO]); + printf("\n%s=x\t\tAuto loads the specified mod by mod pathname.",GAME_ARGS[GAME_ARG_MOD]); + printf("\n%s=x\t\tAuto Preview the specified map by map name.",GAME_ARGS[GAME_ARG_PREVIEW_MAP]); printf("\n%s\t\t\tdisplays the version string of this program.",GAME_ARGS[GAME_ARG_VERSION]); printf("\n%s\t\t\tdisplays your video driver's OpenGL information.",GAME_ARGS[GAME_ARG_OPENGL_INFO]); diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 73f8b894d..a7f701f7c 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -28,10 +28,6 @@ #include "utf8.h" #include "font.h" -//#include -//#include -//#include -//#include #include "string_utils.h" #include "leak_dumper.h" @@ -50,216 +46,13 @@ string Properties::gameVersion = ""; // class Properties // ===================================================== -//wstring widen( const string& str ) -//{ -// wostringstream wstm ; -// wstm.imbue(std::locale("en_US.UTF-8")); -// const ctype& ctfacet = -// use_facet< ctype >( wstm.getloc() ) ; -// for( size_t i=0 ; i= 0xC0) -// { -// wchar_t c = ((byte)str[i++]) - 0xC0; -// while(((byte)str[i]) >= 0x80) -// c = (c << 6) | (((byte)str[i++]) - 0x80); -// --i; -// result[len++] = c; -// continue; -// } -// } -// result[len] = 0; -// return result; -//} - -//string conv_utf8_iso8859_7(string s) { -// int len = s.size(); -// string out = ""; -// string curr_char = ""; -// for(int i=0; i < len; i++) { -// curr_char = curr_char + s[i]; -// if( ( (s[i]) & (128+64) ) == 128) { -// //character end found -// if ( curr_char.size() == 2) { -// // 2-byte character check for it is greek one and convert -// if ((curr_char[0])==205) out = out + (char)(curr_char[1]+16); -// else if ((curr_char[0])==206) out = out + (char)(curr_char[1]+48); -// else if ((curr_char[0])==207) out = out + (char)(curr_char[1]+112); -// else ; // non greek 2-byte character, discard character -// } else ;// n-byte character, n>2, discard character -// curr_char = ""; -// } -// else if ((s[i]) < 128) { -// // character is one byte (ascii) -// out = out + curr_char; -// curr_char = ""; -// } -// } -// return out; -//} - -// Map from the most-significant 6 bits of the first byte to the total number of bytes in a -// UTF-8 character. -//static char UTF8_2_ISO_8859_1_len[] = -//{ -// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -// 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* erroneous */ -// 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6 -//}; -// -//static char UTF8_2_ISO_8859_1_mask[] = {0x3F, 0x7F, 0x1F, 0x0F, 0x07, -//0x03, 0x01}; - - -/*---------------------------------------------------------------------- -------- - Convert a UTF-8 string to a ISO-8859-1 MultiByte string. - No more than 'count' bytes will be written to the output buffer. - Return the size of the converted string in bytes, excl null -terminator. -*/ -//int ldap_x_utf8s_to_iso_8859_1s( char *mbstr, const char *utf8str, size_t count ) -//{ -// int res = 0; -// -// while (*utf8str != '\0') -// { -// int len = UTF8_2_ISO_8859_1_len[(*utf8str >> 2) & 0x3F]; -// unsigned long u = *utf8str & UTF8_2_ISO_8859_1_mask[len]; -// -// // erroneous -// if (len == 0) -// len = 5; -// -// for (++utf8str; --len > 0 && (*utf8str != '\0'); ++utf8str) -// { -// // be sure this is not an unexpected start of a new character -// if ((*utf8str & 0xC0) != 0x80) -// break; -// -// u = (u << 6) | (*utf8str & 0x3F); -// } -// -// if (mbstr != 0 && count != 0) -// { -// // be sure there is enough space left in the destination buffer -// if (res >= count) -// return res; -// -// // add the mapped character to the destination string or '?'(0x1A, SUB) if character -// // can't be represented in ISO-8859-1 -// *mbstr++ = (u <= 0xFF ? (char)u : '?'); -// } -// ++res; -// } -// -// // add the terminating null character -// if (mbstr != 0 && count != 0) -// { -// // be sure there is enough space left in the destination buffer -// if (res >= count) -// return res; -// *mbstr = 0; -// } -// -// return res; -//} // ldap_x_utf8s_to_iso_8859_1s -// -// -///*---------------------------------------------------------------------- -//------- -// Convert a ISO-8859-1 MultiByte string to a UTF-8 string. -// No more than 'count' bytes will be written to the output buffer. -// Return the size of the converted string in bytes, excl null -//terminator. -//*/ -//int ldap_x_iso_8859_1s_to_utf8s(char *utf8str, const char *mbstr, size_t count) -//{ -// int res = 0; -// -// // loop until we reach the end of the mb string -// for (; *mbstr != '\0'; ++mbstr) -// { -// // the character needs no mapping if the highest bit is not set -// if ((*mbstr & 0x80) == 0) -// { -// if (utf8str != 0 && count != 0) -// { -// // be sure there is enough space left in the destination buffer -// if (res >= count) -// return res; -// -// *utf8str++ = *mbstr; -// } -// ++res; -// } -// -// // otherwise mapping is necessary -// else -// { -// if (utf8str != 0 && count != 0) -// { -// // be sure there is enough space left in the destination buffer -// if (res+1 >= count) -// return res; -// -// *utf8str++ = (0xC0 | (0x03 & (*mbstr >> 6))); -// *utf8str++ = (0x80 | (0x3F & *mbstr)); -// } -// res += 2; -// } -// } -// -// // add the terminating null character -// if (utf8str != 0 && count != 0) -// { -// // be sure there is enough space left in the destination buffer -// if (res >= count) -// return res; -// *utf8str = 0; -// } -// -// return res; -//} // ldap_x_iso_8859_1s_to_utf8s - void Properties::load(const string &path, bool clearCurrentProperties) { - //wchar_t lineBuffer[maxLine]=L""; char lineBuffer[maxLine]=""; string line, key, value; size_t pos=0; this->path= path; - //std::locale::global(std::locale("")); bool is_utf8_language = valid_utf8_file(path.c_str()); #if defined(WIN32) && !defined(__MINGW32__) @@ -314,75 +107,6 @@ void Properties::load(const string &path, bool clearCurrentProperties) { } } -// bool isRLM = utf8::starts_with_rlm(&lineBuffer[0], &lineBuffer[0] + strlen(lineBuffer)); -// if(isRLM) { -// printf("\n\nORIGINAL TEXT [%s] isRLM = %d\n\n",&lineBuffer[0],isRLM); -// } - - //if(is_utf8_language == true && Font::forceLegacyFonts == true) { - //string line = lineBuffer; - //wstring wstr = fromUtf8(line.c_str(), line.size()); - - //vector utf16result; - //utf8::utf8to16(line.begin(), line.end(), back_inserter(utf16result)); - //vector utf16result; - //utf8::utf8to32(line.begin(), line.end(), back_inserter(utf16result)); - - //printf("\nConverted UTF-8 from [%s] to [%s]\n",line.c_str(),utf16result[0]); - - //char newBuf[4097]=""; - //int newSize = ldap_x_utf8s_to_iso_8859_1s( &newBuf[0], line.c_str(), 4096 ); - - //std::wstring wstr = widen(newBuf); - //String st(wstr.c_str()); - //String st(line.c_str()); - - //printf("\nConverted UTF-8 from [%s] to [%ls]\n",line.c_str(),wstr.c_str()); - - //const wchar_t *wBuf = &szPath[0]; - //setlocale(LC_ALL, "en_CA.ISO-8559-15"); - //std::locale::global(std::locale("en_CA.ISO-8559-15")); - //size_t size = 4096; - //char pMBBuffer[4096 + 1]=""; - //wcstombs(&pMBBuffer[0], &lineBuffer[0], (size_t)size);// Convert to char* from TCHAR[] - //string newStr=""; - //newStr.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :) - //printf("\nConverted UTF-8 from [%ls] to [%s]\n",&lineBuffer[0],newStr.c_str()); - //std::locale::global(std::locale("")); - - //char newBuf[4097]=""; - //int newSize = ldap_x_utf8s_to_iso_8859_1s( &newBuf[0], &pMBBuffer[0], 4096 ); - - //String st(&lineBuffer[0]); - //printf("\nConverted UTF-8 from [%ls] to [%s]\n",&lineBuffer[0],&newBuf[0]); - - //char newBuf[4097]=""; - //int newSize = ldap_x_utf8s_to_iso_8859_1s( &newBuf[0], line.c_str(), 4096 ); - - //string newStr = conv_utf8_iso8859_7(line); - //printf("\nConverted UTF-8 from [%s] to [%s]\n",line.c_str(),newBuf); -// for(int i = 0; i < line.size(); ++i) { -// printf("to [%c][%d]\n",line[i],line[i]); -// } - //for(int i = 0; i < newStr.size(); ++i) { - // printf("to [%c][%d]\n",newStr[i],newStr[i]); - //} - -// for(int i = 0; i < utf16result.size(); ++i) { -// printf("to [%c]\n",utf16result[i]); -// } -// - //memset(&lineBuffer[0],0,maxLine); - //memcpy(&lineBuffer[0],&newBuf[0],newSize); - //} - //else { - //string line = lineBuffer; - //printf("\nNON UTF-8 from [%s]\n",line.c_str()); - //for(int i = 0; i < line.size(); ++i) { - // printf("to [%c][%d]\n",line[i],line[i]); - //} - //} - //process line if it it not a comment if(lineBuffer[0] != ';') { //wstring wstr = lineBuffer;