Skip to content
Permalink
Browse files

clean THEN sanitize

refactor MCDPatch application directly into the loadData() function,
so patches can be applied before data is validated.
add validation for armor values on MCD objects
add an exception for any game-breaking MCD errors
  • Loading branch information
Warboy1982 committed Oct 18, 2019
1 parent d4e1b5b commit f9853b2cb8c8f741ac58707487ef493416d890a3
@@ -9,6 +9,10 @@ MCDPatches: #will never be done
# bigWall 7 = acts as south wall
# bigWall 8 = acts as east and south wall
# bigWall 9 = acts as west and north wall
- type: ENTRY
data:
- MCDIndex: 6
deathTile: 7
- type: ATLANTIS
data:
- MCDIndex: 47
@@ -2027,11 +2027,7 @@ void BattlescapeGenerator::generateMap(const std::vector<MapScript*> *script)

for (std::vector<MapDataSet*>::iterator i = _terrain->getMapDataSets()->begin(); i != _terrain->getMapDataSets()->end(); ++i)
{
(*i)->loadData();
if (_game->getMod()->getMCDPatch((*i)->getName()))
{
_game->getMod()->getMCDPatch((*i)->getName())->modifyData(*i);
}
(*i)->loadData(_game->getMod()->getMCDPatch((*i)->getName()));
_save->getMapDataSets()->push_back(*i);
mapDataSetIDOffset++;
}
@@ -2274,11 +2270,7 @@ void BattlescapeGenerator::generateMap(const std::vector<MapScript*> *script)
{
for (std::vector<MapDataSet*>::iterator i = ufoTerrain->getMapDataSets()->begin(); i != ufoTerrain->getMapDataSets()->end(); ++i)
{
(*i)->loadData();
if (_game->getMod()->getMCDPatch((*i)->getName()))
{
_game->getMod()->getMCDPatch((*i)->getName())->modifyData(*i);
}
(*i)->loadData(_game->getMod()->getMCDPatch((*i)->getName()));
_save->getMapDataSets()->push_back(*i);
craftDataSetIDOffset++;
}
@@ -2301,11 +2293,7 @@ void BattlescapeGenerator::generateMap(const std::vector<MapScript*> *script)
{
for (std::vector<MapDataSet*>::iterator i = _craft->getRules()->getBattlescapeTerrainData()->getMapDataSets()->begin(); i != _craft->getRules()->getBattlescapeTerrainData()->getMapDataSets()->end(); ++i)
{
(*i)->loadData();
if (_game->getMod()->getMCDPatch((*i)->getName()))
{
_game->getMod()->getMCDPatch((*i)->getName())->modifyData(*i);
}
(*i)->loadData(_game->getMod()->getMCDPatch((*i)->getName()));
_save->getMapDataSets()->push_back(*i);
}
loadMAP(craftMap, _craftPos.x * 10, _craftPos.y * 10, _craft->getRules()->getBattlescapeTerrainData(), mapDataSetIDOffset + craftDataSetIDOffset, true, true);
@@ -94,7 +94,7 @@ SurfaceSet *MapDataSet::getSurfaceset() const
* Loads terrain data in XCom format (MCD & PCK files).
* @sa http://www.ufopaedia.org/index.php?title=MCD
*/
void MapDataSet::loadData()
void MapDataSet::loadData(MCDPatch *patch)
{
// prevents loading twice
if (_loaded) return;
@@ -215,17 +215,37 @@ void MapDataSet::loadData()

mapFile.close();

// apply any ruleset patches before validation
if (patch)
{
patch->modifyData(this);
}

// Validate MCD references
bool validData = true;

for (size_t i = 0; i < _objects.size(); ++i)
{
if (_objects[i]->getDieMCD() >= _objects.size())
{
Log(LOG_INFO) << "MCD " << _name << " object " << i << " has invalid DieMCD: " << _objects[i]->getDieMCD();
validData = false;
}
if (_objects[i]->getAltMCD() >= _objects.size())
{
Log(LOG_INFO) << "MCD " << _name << " object " << i << " has invalid AltMCD: " << _objects[i]->getAltMCD();
validData = false;
}
if (_objects[i]->getArmor() == 0)
{
Log(LOG_INFO) << "MCD " << _name << " object " << i << " has 0 armor";
validData = false;
}
}

if (!validData)
{
throw Exception("invalid MCD file: " + fname + ", check log file for more details.");
}

// Load terrain sprites/surfaces/PCK files into a surfaceset
@@ -21,6 +21,7 @@
#include <vector>
#include <SDL.h>
#include <yaml-cpp/yaml.h>
#include "../Mod/MCDPatch.h"

namespace OpenXcom
{
@@ -57,7 +58,7 @@ class MapDataSet
/// Gets the surfaces in this dataset.
SurfaceSet *getSurfaceset() const;
/// Loads the objects from an MCD file.
void loadData();
void loadData(MCDPatch *patch);
/// Unloads to free memory.
void unloadData();
/// Gets a blank floor tile.
@@ -344,11 +344,7 @@ void SavedBattleGame::loadMapResources(Mod *mod)
{
for (std::vector<MapDataSet*>::const_iterator i = _mapDataSets.begin(); i != _mapDataSets.end(); ++i)
{
(*i)->loadData();
if (mod->getMCDPatch((*i)->getName()))
{
mod->getMCDPatch((*i)->getName())->modifyData(*i);
}
(*i)->loadData(mod->getMCDPatch((*i)->getName()));
}

int mdsID, mdID;

0 comments on commit f9853b2

Please sign in to comment.
You can’t perform that action at this time.