diff --git a/Data Files/Changelog.txt b/Data Files/Changelog.txt index df340509d..d998bc362 100644 --- a/Data Files/Changelog.txt +++ b/Data Files/Changelog.txt @@ -219,4 +219,5 @@ Revision Log Message 215 Apply change 213 to test configs 216 Convert tech 217 Tech investment -218 Add miaphysite religion mapping \ No newline at end of file +218 Add miaphysite religion mapping +219 No longer need the mod in place to avoid crashing \ No newline at end of file diff --git a/Source/Configuration.cpp b/Source/Configuration.cpp index 36e5e155c..434372d6f 100644 --- a/Source/Configuration.cpp +++ b/Source/Configuration.cpp @@ -14,7 +14,15 @@ Configuration::Configuration() printf("Reading configuration file.\n"); log("Reading configuration file.\n"); - vector obj = doParseFile("configuration.txt")->getValue("configuration"); + Object* oneObj = doParseFile("configuration.txt"); + if (oneObj == NULL) + { + log("Error: Could not open configuration.txt\n"); + printf("Error: Could not open configuration.txt\n"); + exit(-1); + } + + vector obj = oneObj->getValue("configuration"); if (obj.size() != 1) { printf("Configuration file must contain exactly one configuration section."); diff --git a/Source/Convert.cpp b/Source/Convert.cpp index a8845e16e..e7aa8c83e 100644 --- a/Source/Convert.cpp +++ b/Source/Convert.cpp @@ -66,6 +66,12 @@ int main(int argc, char * argv[]) log("\tGetting building types.\n"); printf("\tGetting building types.\n"); obj = doParseFile((Configuration::getCK2Path() + "/common/buildings.txt").c_str()); // for pre-1.06 installs + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/buildings.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/buildings.txt").c_str()); + exit(-1); + } srcWorld.addBuildingTypes(obj); struct _finddata_t buildingsData; intptr_t fileListing; @@ -82,6 +88,12 @@ int main(int argc, char * argv[]) continue; } obj = doParseFile((Configuration::getCK2Path() + "\\common\\buildings\\" + buildingsData.name).c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\buildings\\" + buildingsData.name).c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\buildings\\" + buildingsData.name).c_str()); + exit(-1); + } srcWorld.addBuildingTypes(obj); } while(_findnext(fileListing, &buildingsData) == 0); _findclose(fileListing); @@ -89,6 +101,12 @@ int main(int argc, char * argv[]) log("\tGetting CK2 religions\n"); printf("\tGetting CK2 religions\n"); obj = doParseFile((Configuration::getCK2Path() + "/common/religion.txt").c_str()); // for pre-1.06 installs + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/religion.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/religion.txt").c_str()); + exit(-1); + } religionGroupMapping CK2ReligionGroupMap; addReligionGroupMappings(obj, CK2ReligionGroupMap); struct _finddata_t religionsData; @@ -105,6 +123,12 @@ int main(int argc, char * argv[]) continue; } obj = doParseFile((Configuration::getCK2Path() + "\\common\\religions\\" + religionsData.name).c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\religions\\" + religionsData.name).c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\religions\\" + religionsData.name).c_str()); + exit(-1); + } addReligionGroupMappings(obj, CK2ReligionGroupMap); } while(_findnext(fileListing, &religionsData) == 0); _findclose(fileListing); @@ -112,6 +136,12 @@ int main(int argc, char * argv[]) log("\tGetting CK2 cultures\n"); printf("\tGetting CK2 cultures\n"); obj = doParseFile((Configuration::getCK2Path() + "/common/cultures.txt").c_str()); // for pre-1.06 installs + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/cultures.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/cultures.txt").c_str()); + exit(-1); + } cultureGroupMapping CK2CultureGroupMap; addCultureGroupMappings(obj, CK2CultureGroupMap); struct _finddata_t culturesData; @@ -128,6 +158,12 @@ int main(int argc, char * argv[]) continue; } obj = doParseFile((Configuration::getCK2Path() + "\\common\\cultures\\" + culturesData.name).c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\cultures\\" + culturesData.name).c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\cultures\\" + culturesData.name).c_str()); + exit(-1); + } addCultureGroupMappings(obj, CK2CultureGroupMap); } while(_findnext(fileListing, &culturesData) == 0); _findclose(fileListing); @@ -135,6 +171,12 @@ int main(int argc, char * argv[]) log("\tParsing landed titles.\n"); printf("\tParsing landed titles.\n"); obj = doParseFile((Configuration::getCK2Path() + "/common/landed_titles.txt").c_str()); // for pre-1.06 installs + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/landed_titles.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/landed_titles.txt").c_str()); + exit(-1); + } srcWorld.addPotentialTitles(obj); struct _finddata_t landedTitlesdata; if ( (fileListing = _findfirst( (CK2Loc + "\\common\\landed_titles\\*").c_str(), &landedTitlesdata)) == -1L) @@ -150,6 +192,12 @@ int main(int argc, char * argv[]) continue; } obj = doParseFile((Configuration::getCK2Path() + "\\common\\landed_titles\\" + landedTitlesdata.name).c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\landed_titles\\" + landedTitlesdata.name).c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\landed_titles\\" + landedTitlesdata.name).c_str()); + exit(-1); + } srcWorld.addPotentialTitles(obj); } while(_findnext(fileListing, &landedTitlesdata) == 0); _findclose(fileListing); @@ -157,6 +205,12 @@ int main(int argc, char * argv[]) log("\tGetting traits\n"); printf("\tGetting traits\n"); obj = doParseFile((Configuration::getCK2Path() + "/common/traits.txt").c_str()); // for pre-1.06 installs + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/traits.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/traits.txt").c_str()); + exit(-1); + } srcWorld.addTraits(obj); struct _finddata_t traitsData; if ( (fileListing = _findfirst( (CK2Loc + "\\common\\traits\\*").c_str(), &traitsData)) == -1L) @@ -172,6 +226,12 @@ int main(int argc, char * argv[]) continue; } obj = doParseFile((Configuration::getCK2Path() + "\\common\\traits\\" + traitsData.name).c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\traits\\" + traitsData.name).c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\traits\\" + traitsData.name).c_str()); + exit(-1); + } srcWorld.addTraits(obj); } while(_findnext(fileListing, &traitsData) == 0); _findclose(fileListing); @@ -179,6 +239,12 @@ int main(int argc, char * argv[]) log("\tAdding dynasties from CK2 Install\n"); printf("\tAdding dynasties from CK2 Install\n"); obj = doParseFile((Configuration::getCK2Path() + "/common/dynasties.txt").c_str()); // for pre-1.06 installs + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/dynasties.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "/common/dynasties.txt").c_str()); + exit(-1); + } srcWorld.addDynasties(obj); struct _finddata_t dynastiesData; if ( (fileListing = _findfirst( (CK2Loc + "\\common\\dynasties\\*").c_str(), &dynastiesData)) == -1L) @@ -194,6 +260,12 @@ int main(int argc, char * argv[]) continue; } obj = doParseFile((Configuration::getCK2Path() + "\\common\\dynasties\\" + dynastiesData.name).c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\dynasties\\" + dynastiesData.name).c_str()); + printf("Error: Could not open %s\n", (Configuration::getCK2Path() + "\\common\\dynasties\\" + dynastiesData.name).c_str()); + exit(-1); + } srcWorld.addDynasties(obj); } while(_findnext(fileListing, &dynastiesData) == 0); _findclose(fileListing); @@ -201,6 +273,12 @@ int main(int argc, char * argv[]) log("Parsing CK2 save.\n"); printf("Parsing CK2 save.\n"); obj = doParseFile(inputFilename.c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", inputFilename.c_str()); + printf("Error: Could not open %s\n", inputFilename.c_str()); + exit(-1); + } log("Importing parsed data.\n"); printf("Importing parsed data.\n"); @@ -216,6 +294,12 @@ int main(int argc, char * argv[]) printf("Parsing province mappings.\n"); const char* mappingFile = "province_mappings.txt"; obj = doParseFile(mappingFile); + if (obj == NULL) + { + log("Error: Could not open %s\n", mappingFile); + printf("Error: Could not open %s\n", mappingFile); + exit(-1); + } provinceMapping provinceMap = initProvinceMap(obj, srcWorld.getVersion()); inverseProvinceMapping inverseProvinceMap = invertProvinceMap(provinceMap); //map srcProvinces = srcWorld.getProvinces(); @@ -236,11 +320,47 @@ int main(int argc, char * argv[]) log("Setting up tech groups.\n"); printf("Setting up tech groups.\n"); obj = doParseFile( (Configuration::getEU3Path() + "/common/technology.txt").c_str() ); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technology.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technology.txt").c_str()); + exit(-1); + } Object* govObj = doParseFile( (Configuration::getEU3Path() + "/common/technologies/government.txt").c_str() ); + if (govObj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/government.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/government.txt").c_str()); + exit(-1); + } Object* prodObj = doParseFile( (Configuration::getEU3Path() + "/common/technologies/production.txt").c_str() ); + if (prodObj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/production.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/production.txt").c_str()); + exit(-1); + } Object* tradeObj = doParseFile( (Configuration::getEU3Path() + "/common/technologies/trade.txt").c_str() ); + if (tradeObj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/trade.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/trade.txt").c_str()); + exit(-1); + } Object* navalObj = doParseFile( (Configuration::getEU3Path() + "/common/technologies/naval.txt").c_str() ); + if (navalObj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/naval.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/naval.txt").c_str()); + exit(-1); + } Object* landObj = doParseFile( (Configuration::getEU3Path() + "/common/technologies/land.txt").c_str() ); + if (landObj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/land.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/technologies/land.txt").c_str()); + exit(-1); + } EU3Tech* techData = new EU3Tech(srcWorld.getEndDate(), obj, govObj, prodObj, tradeObj, navalObj, landObj); EU3World destWorld(&srcWorld, techData); @@ -254,12 +374,24 @@ int main(int argc, char * argv[]) log("Getting blocked EU3 nations.\n"); printf("Getting blocked EU3 nations.\n"); obj = doParseFile("blocked_nations.txt"); + if (obj == NULL) + { + log("Error: Could not open blocked_nations.txt\n"); + printf("Error: Could not open blocked_nations.txt\n"); + exit(-1); + } vector blockedNations = processBlockedNations(obj); // Get country mappings log("Parsing country mappings.\n"); printf("Parsing country mappings.\n"); - obj = doParseFile("country_mappings.txt"); + obj = doParseFile("country_mappings.txt"); + if (obj == NULL) + { + log("Error: Could not open country_mappings.txt\n"); + printf("Error: Could not open country_mappings.txt\n"); + exit(-1); + } // Map CK2 nations to EU3 nations log("Mapping CK2 nations to EU3 nations.\n"); @@ -281,6 +413,12 @@ int main(int argc, char * argv[]) log("Getting EU3 cultures\n"); printf("Getting EU3 cultures\n"); obj = doParseFile((Configuration::getEU3Path() + "/common/cultures.txt").c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/cultures.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/cultures.txt").c_str()); + exit(-1); + } cultureGroupMapping EU3CultureGroupMap; addCultureGroupMappings(obj, EU3CultureGroupMap); @@ -288,15 +426,35 @@ int main(int argc, char * argv[]) log("Getting EU3 religions\n"); printf("Getting EU3 religions\n"); obj = doParseFile((Configuration::getEU3Path() + "/common/religion.txt").c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/religion.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/common/religion.txt").c_str()); + exit(-1); + } religionGroupMapping EU3ReligionGroupMap; addReligionGroupMappings(obj, EU3ReligionGroupMap); - obj = doParseFile((Configuration::getEU3Path() + "/mod/Converter/common/religion.txt").c_str()); - addReligionGroupMappings(obj, EU3ReligionGroupMap); + obj = doParseFile((Configuration::getEU3Path() + "/mod/Converter/common/religion.txt").c_str()); // in case the mod is being used + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/mod/Converter/common/religion.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/mod/Converter/common/religion.txt").c_str()); + } + else + { + addReligionGroupMappings(obj, EU3ReligionGroupMap); + } // Get culture mappings log("Parsing culture mappings.\n"); printf("Parsing culture mappings.\n"); obj = doParseFile("culture_mappings.txt"); + if (obj == NULL) + { + log("Error: Could not open culture_mappings.txt\n"); + printf("Error: Could not open culture_mappings.txt\n"); + exit(-1); + } if (obj->getLeaves().size() < 1) { log("Error: Failed to parse culture_mappings.txt.\n"); @@ -310,6 +468,12 @@ int main(int argc, char * argv[]) log("Parsing religion mappings.\n"); printf("Parsing religion mappings.\n"); obj = doParseFile("religion_mappings.txt"); + if (obj == NULL) + { + log("Error: Could not open religion_mappings.txt\n"); + printf("Error: Could not open religion_mappings.txt\n"); + exit(-1); + } if (obj->getLeaves().size() < 1) { log("Error: Failed to parse religion_mappings.txt.\n"); @@ -323,6 +487,12 @@ int main(int argc, char * argv[]) log("Parsing continents.\n"); printf("Parsing continents.\n"); obj = doParseFile((Configuration::getEU3Path() + "\\map\\continent.txt").c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "\\map\\continent.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "\\map\\continent.txt").c_str()); + exit(-1); + } if (obj->getLeaves().size() < 1) { log("Error: Failed to parse continent.txt.\n"); @@ -338,9 +508,15 @@ int main(int argc, char * argv[]) adjacencyMapping adjacencyMap = initAdjacencyMap(); // Get trade good data - log("Inporting trade good data.\n"); - printf("Inporting trade good data.\n"); + log("Importing trade good data.\n"); + printf("Importing trade good data.\n"); obj = doParseFile((Configuration::getEU3Path() + "\\common\\Prices.txt").c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "\\common\\Prices.txt").c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "\\common\\Prices.txt").c_str()); + exit(-1); + } if (obj->getLeaves().size() < 1) { log("Error: Failed to parse Prices.txt.\n"); diff --git a/Source/EU3World/EU3Country.cpp b/Source/EU3World/EU3Country.cpp index cde5d9304..55f15566a 100644 --- a/Source/EU3World/EU3Country.cpp +++ b/Source/EU3World/EU3Country.cpp @@ -31,6 +31,12 @@ EU3Country::EU3Country(EU3World* world, string newTag, string newHistoryFile, da // Parse history file Object* obj; obj = doParseFile( (Configuration::getEU3Path() + "/history/countries/" + historyFile).c_str() ); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/history/countries/" + historyFile).c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/history/countries/" + historyFile).c_str()); + exit(-1); + } // Set objects from top of history file vector govLeaves = obj->getValue("government"); diff --git a/Source/EU3World/EU3Province.cpp b/Source/EU3World/EU3Province.cpp index b4fe6f830..93b70e66b 100644 --- a/Source/EU3World/EU3Province.cpp +++ b/Source/EU3World/EU3Province.cpp @@ -467,7 +467,7 @@ void EU3Province::determineCulture(const cultureMapping& cultureMap, const vecto culture = topCulture; } -#pragma optimize("", off) + void EU3Province::determineReligion(const religionMapping& religionMap, const vector& srcProvinces) { @@ -631,7 +631,7 @@ void EU3Province::determineReligion(const religionMapping& religionMap, const ve log("\tError: could not map religion %s to any EU3 religions (province %d: %s)\n", topReligion.c_str(), num, capital.c_str()); } } -#pragma optimize("", off) + void EU3Province::setManpower(double _manpower) { diff --git a/Source/EU3World/EU3World.cpp b/Source/EU3World/EU3World.cpp index 845caa966..80303db1e 100644 --- a/Source/EU3World/EU3World.cpp +++ b/Source/EU3World/EU3World.cpp @@ -351,6 +351,12 @@ void EU3World::setupProvinces(provinceMapping& provinceMap) if ( (fileListing = _findfirst(filename.c_str(), &fileData)) != -1L) { obj = doParseFile( (Configuration::getEU3Path() + "\\history\\provinces\\" + fileData.name).c_str() ); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "\\history\\provinces\\" + fileData.name).c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "\\history\\provinces\\" + fileData.name).c_str()); + exit(-1); + } _findclose(fileListing); } else @@ -740,6 +746,12 @@ void EU3World::convertAdvisors(inverseProvinceMapping& inverseProvinceMap, provi Object* obj; obj = doParseFile((Configuration::getEU3Path() + "/history/advisors/" + filename).c_str()); + if (obj == NULL) + { + log("Error: Could not open %s\n", (Configuration::getEU3Path() + "/history/advisors/" + filename).c_str()); + printf("Error: Could not open %s\n", (Configuration::getEU3Path() + "/history/advisors/" + filename).c_str()); + exit(-1); + } vector advisorsObj = obj->getLeaves(); for (unsigned int i = 0; i < advisorsObj.size(); i++) diff --git a/Source/Parsers/Parser.cpp b/Source/Parsers/Parser.cpp index ed375db81..c51849368 100644 --- a/Source/Parsers/Parser.cpp +++ b/Source/Parsers/Parser.cpp @@ -314,9 +314,7 @@ Object* doParseFile(const char* filename) read.open(filename); if (!read.is_open()) { - log("Error: Could not open %s\n", filename); - printf("Error: Could not open %s\n", filename); - exit(1); + return NULL; } readFile(read); read.close();