- added some basic protection against memory hacking tools
This commit is contained in:
parent
ccaaf5ab35
commit
2ab82c9271
|
@ -23,40 +23,6 @@ using namespace Shared::Util;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
void ValueCheckerVault::addItemToVault(const void *ptr,int value) {
|
|
||||||
Checksum checksum;
|
|
||||||
checksum.addString(intToStr(value));
|
|
||||||
vaultList[ptr] = intToStr(checksum.getSum());
|
|
||||||
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] add vault key [%p] value [%s] [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,intToStr(checksum.getSum()).c_str(),value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ValueCheckerVault::checkItemInVault(const void *ptr,int value) const {
|
|
||||||
map<const void *,string>::const_iterator iterFind = vaultList.find(ptr);
|
|
||||||
if(iterFind == vaultList.end()) {
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) {
|
|
||||||
printf("In [%s::%s Line: %d] check vault key [%p] value [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,value);
|
|
||||||
for(map<const void *,string>::const_iterator iterFind = vaultList.begin();
|
|
||||||
iterFind != vaultList.end(); iterFind++) {
|
|
||||||
printf("In [%s::%s Line: %d] LIST-- check vault key [%p] value [%s]\n",__FILE__,__FUNCTION__,__LINE__,iterFind->first,iterFind->second.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw std::runtime_error("memory value has been unexpectedly modified (not found)!");
|
|
||||||
}
|
|
||||||
Checksum checksum;
|
|
||||||
checksum.addString(intToStr(value));
|
|
||||||
if(iterFind->second != intToStr(checksum.getSum())) {
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) {
|
|
||||||
printf("In [%s::%s Line: %d] check vault key [%p] value [%s] [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,intToStr(checksum.getSum()).c_str(),value);
|
|
||||||
for(map<const void *,string>::const_iterator iterFind = vaultList.begin();
|
|
||||||
iterFind != vaultList.end(); iterFind++) {
|
|
||||||
printf("In [%s::%s Line: %d] LIST-- check vault key [%p] value [%s]\n",__FILE__,__FUNCTION__,__LINE__,iterFind->first,iterFind->second.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw std::runtime_error("memory value has been unexpectedly modified (changed)!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Resource
|
// class Resource
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "vec.h"
|
#include "vec.h"
|
||||||
#include <map>
|
#include "platform_common.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -22,6 +22,7 @@ using std::map;
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
using Shared::Graphics::Vec2i;
|
using Shared::Graphics::Vec2i;
|
||||||
|
using Shared::PlatformCommon::ValueCheckerVault;
|
||||||
|
|
||||||
class ResourceType;
|
class ResourceType;
|
||||||
|
|
||||||
|
@ -31,21 +32,6 @@ class ResourceType;
|
||||||
/// Amount of a given ResourceType
|
/// Amount of a given ResourceType
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class ValueCheckerVault {
|
|
||||||
|
|
||||||
protected:
|
|
||||||
map<const void *,string> vaultList;
|
|
||||||
|
|
||||||
void addItemToVault(const void *ptr,int value);
|
|
||||||
void checkItemInVault(const void *ptr,int value) const;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ValueCheckerVault() {
|
|
||||||
vaultList.clear();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Resource : public ValueCheckerVault {
|
class Resource : public ValueCheckerVault {
|
||||||
private:
|
private:
|
||||||
int amount;
|
int amount;
|
||||||
|
|
|
@ -163,7 +163,6 @@ set<Unit*> Unit::livingUnitsp;
|
||||||
Game *Unit::game = NULL;
|
Game *Unit::game = NULL;
|
||||||
|
|
||||||
Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing):id(id) {
|
Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing):id(id) {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
modelFacing = CardinalDir::NORTH;
|
modelFacing = CardinalDir::NORTH;
|
||||||
|
@ -242,6 +241,9 @@ Unit::Unit(int id, UnitPathInterface *unitpath, const Vec2i &pos, const UnitType
|
||||||
livingUnits.insert(id);
|
livingUnits.insert(id);
|
||||||
livingUnitsp.insert(this);
|
livingUnitsp.insert(this);
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
addItemToVault(&this->ep,this->ep);
|
||||||
|
|
||||||
logSynchData(__FILE__,__LINE__);
|
logSynchData(__FILE__,__LINE__);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
@ -909,7 +911,11 @@ void Unit::born() {
|
||||||
faction->applyStaticProduction(type);
|
faction->applyStaticProduction(type);
|
||||||
setCurrSkill(scStop);
|
setCurrSkill(scStop);
|
||||||
|
|
||||||
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
hp= type->getMaxHp();
|
hp= type->getMaxHp();
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::kill() {
|
void Unit::kill() {
|
||||||
|
@ -1115,10 +1121,15 @@ void Unit::tick() {
|
||||||
|
|
||||||
//regenerate hp
|
//regenerate hp
|
||||||
if(type->getHpRegeneration() >= 0) {
|
if(type->getHpRegeneration() >= 0) {
|
||||||
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
hp+= type->getHpRegeneration();
|
hp+= type->getHpRegeneration();
|
||||||
if(hp>type->getTotalMaxHp(&totalUpgrade)){
|
|
||||||
hp= type->getTotalMaxHp(&totalUpgrade);
|
if(hp > type->getTotalMaxHp(&totalUpgrade)) {
|
||||||
|
hp = type->getTotalMaxHp(&totalUpgrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
}
|
}
|
||||||
// If we have negative regeneration then check if the unit should die
|
// If we have negative regeneration then check if the unit should die
|
||||||
else {
|
else {
|
||||||
|
@ -1138,11 +1149,16 @@ void Unit::tick() {
|
||||||
stopDamageParticles();
|
stopDamageParticles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkItemInVault(&this->ep,this->ep);
|
||||||
|
|
||||||
//regenerate ep
|
//regenerate ep
|
||||||
ep += type->getEpRegeneration();
|
ep += type->getEpRegeneration();
|
||||||
|
|
||||||
if(ep>type->getTotalMaxEp(&totalUpgrade)){
|
if(ep>type->getTotalMaxEp(&totalUpgrade)){
|
||||||
ep= type->getTotalMaxEp(&totalUpgrade);
|
ep= type->getTotalMaxEp(&totalUpgrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addItemToVault(&this->ep,this->ep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1160,12 +1176,16 @@ bool Unit::computeEp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
//if not enough ep
|
//if not enough ep
|
||||||
if(ep-currSkill->getEpCost() < 0) {
|
if(ep - currSkill->getEpCost() < 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkItemInVault(&this->ep,this->ep);
|
||||||
|
|
||||||
//decrease ep
|
//decrease ep
|
||||||
ep-= currSkill->getEpCost();
|
ep -= currSkill->getEpCost();
|
||||||
|
|
||||||
|
addItemToVault(&this->ep,this->ep);
|
||||||
|
|
||||||
if(getType() == NULL) {
|
if(getType() == NULL) {
|
||||||
char szBuf[4096]="";
|
char szBuf[4096]="";
|
||||||
|
@ -1173,10 +1193,12 @@ bool Unit::computeEp() {
|
||||||
throw runtime_error(szBuf);
|
throw runtime_error(szBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ep>getType()->getTotalMaxEp(&totalUpgrade)){
|
if(ep > getType()->getTotalMaxEp(&totalUpgrade)){
|
||||||
ep= getType()->getTotalMaxEp(&totalUpgrade);
|
ep = getType()->getTotalMaxEp(&totalUpgrade);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addItemToVault(&this->ep,this->ep);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1189,14 +1211,20 @@ bool Unit::repair(){
|
||||||
}
|
}
|
||||||
|
|
||||||
//increase hp
|
//increase hp
|
||||||
hp+= getType()->getMaxHp()/type->getProductionTime() + 1;
|
checkItemInVault(&this->hp,this->hp);
|
||||||
if(hp>(getType()->getTotalMaxHp(&totalUpgrade))){
|
|
||||||
hp= getType()->getTotalMaxHp(&totalUpgrade);
|
hp += getType()->getMaxHp()/type->getProductionTime() + 1;
|
||||||
|
if(hp > (getType()->getTotalMaxHp(&totalUpgrade))) {
|
||||||
|
hp = getType()->getTotalMaxHp(&totalUpgrade);
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
//stop DamageParticles
|
//stop DamageParticles
|
||||||
if(hp>type->getTotalMaxHp(&totalUpgrade)/2 ){
|
if(hp > type->getTotalMaxHp(&totalUpgrade)/2 ) {
|
||||||
stopDamageParticles();
|
stopDamageParticles();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1208,8 +1236,12 @@ bool Unit::decHp(int i) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
hp -= i;
|
hp -= i;
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
if(type == NULL) {
|
if(type == NULL) {
|
||||||
char szBuf[4096]="";
|
char szBuf[4096]="";
|
||||||
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
sprintf(szBuf,"In [%s::%s Line: %d] ERROR: type == NULL, Unit = [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->toString().c_str());
|
||||||
|
@ -1225,6 +1257,9 @@ bool Unit::decHp(int i) {
|
||||||
if(hp <= 0) {
|
if(hp <= 0) {
|
||||||
alive= false;
|
alive= false;
|
||||||
hp=0;
|
hp=0;
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
stopDamageParticles();
|
stopDamageParticles();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1328,7 +1363,12 @@ void Unit::applyUpgrade(const UpgradeType *upgradeType){
|
||||||
|
|
||||||
if(upgradeType->isAffected(type)){
|
if(upgradeType->isAffected(type)){
|
||||||
totalUpgrade.sum(upgradeType);
|
totalUpgrade.sum(upgradeType);
|
||||||
hp+= upgradeType->getMaxHp();
|
|
||||||
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
|
hp += upgradeType->getMaxHp();
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1344,7 +1384,12 @@ void Unit::incKills(){
|
||||||
level= nextLevel;
|
level= nextLevel;
|
||||||
int maxHp= totalUpgrade.getMaxHp();
|
int maxHp= totalUpgrade.getMaxHp();
|
||||||
totalUpgrade.incLevel(type);
|
totalUpgrade.incLevel(type);
|
||||||
hp+= totalUpgrade.getMaxHp()-maxHp;
|
|
||||||
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
|
hp += totalUpgrade.getMaxHp()-maxHp;
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1370,7 +1415,13 @@ bool Unit::morph(const MorphCommandType *mct){
|
||||||
if(map->isFreeCellsOrHasUnit(pos, morphUnitType->getSize(), morphUnitField, this)){
|
if(map->isFreeCellsOrHasUnit(pos, morphUnitType->getSize(), morphUnitField, this)){
|
||||||
map->clearUnitCells(this, pos);
|
map->clearUnitCells(this, pos);
|
||||||
faction->deApplyStaticCosts(type);
|
faction->deApplyStaticCosts(type);
|
||||||
hp+= morphUnitType->getMaxHp() - type->getMaxHp();
|
|
||||||
|
checkItemInVault(&this->hp,this->hp);
|
||||||
|
|
||||||
|
hp += morphUnitType->getMaxHp() - type->getMaxHp();
|
||||||
|
|
||||||
|
addItemToVault(&this->hp,this->hp);
|
||||||
|
|
||||||
type= morphUnitType;
|
type= morphUnitType;
|
||||||
level= NULL;
|
level= NULL;
|
||||||
currField=morphUnitField;
|
currField=morphUnitField;
|
||||||
|
|
|
@ -31,6 +31,7 @@ using Shared::Graphics::Vec3f;
|
||||||
using Shared::Graphics::Vec2i;
|
using Shared::Graphics::Vec2i;
|
||||||
using Shared::Graphics::Model;
|
using Shared::Graphics::Model;
|
||||||
using Shared::PlatformCommon::Chrono;
|
using Shared::PlatformCommon::Chrono;
|
||||||
|
using Shared::PlatformCommon::ValueCheckerVault;
|
||||||
|
|
||||||
using std::set;
|
using std::set;
|
||||||
|
|
||||||
|
@ -216,7 +217,7 @@ public:
|
||||||
/// A game unit or building
|
/// A game unit or building
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
||||||
class Unit {
|
class Unit : public ValueCheckerVault {
|
||||||
private:
|
private:
|
||||||
typedef list<Command*> Commands;
|
typedef list<Command*> Commands;
|
||||||
typedef list<UnitObserver*> Observers;
|
typedef list<UnitObserver*> Observers;
|
||||||
|
|
|
@ -52,7 +52,7 @@ const char *UnitType::propertyNames[]= {"burnable", "rotated_climb"};
|
||||||
|
|
||||||
// ==================== creation and loading ====================
|
// ==================== creation and loading ====================
|
||||||
|
|
||||||
UnitType::UnitType(){
|
UnitType::UnitType() : ProducibleType() {
|
||||||
|
|
||||||
meetingPointImage = NULL;
|
meetingPointImage = NULL;
|
||||||
lightColor= Vec3f(0.f);
|
lightColor= Vec3f(0.f);
|
||||||
|
@ -82,6 +82,22 @@ UnitType::UnitType(){
|
||||||
hpRegeneration= 0;
|
hpRegeneration= 0;
|
||||||
epRegeneration= 0;
|
epRegeneration= 0;
|
||||||
maxUnitCount= 0;
|
maxUnitCount= 0;
|
||||||
|
maxHp=0;
|
||||||
|
maxEp=0;
|
||||||
|
armor=0;
|
||||||
|
sight=0;
|
||||||
|
size=0;
|
||||||
|
height=0;
|
||||||
|
|
||||||
|
addItemToVault(&(this->maxHp),this->maxHp);
|
||||||
|
addItemToVault(&(this->hpRegeneration),this->hpRegeneration);
|
||||||
|
addItemToVault(&(this->maxEp),this->maxEp);
|
||||||
|
addItemToVault(&(this->epRegeneration),this->epRegeneration);
|
||||||
|
addItemToVault(&(this->maxUnitCount),this->maxUnitCount);
|
||||||
|
addItemToVault(&(this->armor),this->armor);
|
||||||
|
addItemToVault(&(this->sight),this->sight);
|
||||||
|
addItemToVault(&(this->size),this->size);
|
||||||
|
addItemToVault(&(this->height),this->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnitType::~UnitType(){
|
UnitType::~UnitType(){
|
||||||
|
@ -124,39 +140,69 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
|
||||||
const XmlNode *parametersNode= unitNode->getChild("parameters");
|
const XmlNode *parametersNode= unitNode->getChild("parameters");
|
||||||
|
|
||||||
//size
|
//size
|
||||||
|
//checkItemInVault(&(this->size),this->size);
|
||||||
|
|
||||||
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
|
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
|
||||||
|
|
||||||
|
addItemToVault(&(this->size),this->size);
|
||||||
|
|
||||||
//height
|
//height
|
||||||
|
//checkItemInVault(&(this->height),this->height);
|
||||||
|
|
||||||
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
|
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
|
||||||
|
|
||||||
|
addItemToVault(&(this->height),this->height);
|
||||||
|
|
||||||
//maxHp
|
//maxHp
|
||||||
maxHp= parametersNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
//checkItemInVault(&(this->maxHp),this->maxHp);
|
||||||
|
|
||||||
|
maxHp = parametersNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
||||||
|
|
||||||
|
addItemToVault(&(this->maxHp),this->maxHp);
|
||||||
|
|
||||||
//hpRegeneration
|
//hpRegeneration
|
||||||
|
//checkItemInVault(&(this->hpRegeneration),this->hpRegeneration);
|
||||||
|
|
||||||
hpRegeneration= parametersNode->getChild("max-hp")->getAttribute("regeneration")->getIntValue();
|
hpRegeneration= parametersNode->getChild("max-hp")->getAttribute("regeneration")->getIntValue();
|
||||||
|
|
||||||
|
addItemToVault(&(this->hpRegeneration),this->hpRegeneration);
|
||||||
|
|
||||||
//maxEp
|
//maxEp
|
||||||
|
//checkItemInVault(&(this->maxEp),this->maxEp);
|
||||||
|
|
||||||
maxEp= parametersNode->getChild("max-ep")->getAttribute("value")->getIntValue();
|
maxEp= parametersNode->getChild("max-ep")->getAttribute("value")->getIntValue();
|
||||||
|
|
||||||
if(maxEp!=0){
|
addItemToVault(&(this->maxEp),this->maxEp);
|
||||||
//wpRegeneration
|
|
||||||
|
if(maxEp != 0) {
|
||||||
|
//epRegeneration
|
||||||
|
//checkItemInVault(&(this->epRegeneration),this->epRegeneration);
|
||||||
|
|
||||||
epRegeneration= parametersNode->getChild("max-ep")->getAttribute("regeneration")->getIntValue();
|
epRegeneration= parametersNode->getChild("max-ep")->getAttribute("regeneration")->getIntValue();
|
||||||
}
|
}
|
||||||
|
addItemToVault(&(this->epRegeneration),this->epRegeneration);
|
||||||
|
|
||||||
//maxUnitCount
|
//maxUnitCount
|
||||||
if(parametersNode->hasChild("max-unit-count")){
|
if(parametersNode->hasChild("max-unit-count")) {
|
||||||
|
//checkItemInVault(&(this->maxUnitCount),this->maxUnitCount);
|
||||||
|
|
||||||
maxUnitCount= parametersNode->getChild("max-unit-count")->getAttribute("value")->getIntValue();
|
maxUnitCount= parametersNode->getChild("max-unit-count")->getAttribute("value")->getIntValue();
|
||||||
}
|
}
|
||||||
|
addItemToVault(&(this->maxUnitCount),this->maxUnitCount);
|
||||||
|
|
||||||
//armor
|
//armor
|
||||||
|
//checkItemInVault(&(this->armor),this->armor);
|
||||||
armor= parametersNode->getChild("armor")->getAttribute("value")->getIntValue();
|
armor= parametersNode->getChild("armor")->getAttribute("value")->getIntValue();
|
||||||
|
addItemToVault(&(this->armor),this->armor);
|
||||||
|
|
||||||
//armor type string
|
//armor type string
|
||||||
string armorTypeName= parametersNode->getChild("armor-type")->getAttribute("value")->getRestrictedValue();
|
string armorTypeName= parametersNode->getChild("armor-type")->getAttribute("value")->getRestrictedValue();
|
||||||
armorType= techTree->getArmorType(armorTypeName);
|
armorType= techTree->getArmorType(armorTypeName);
|
||||||
|
|
||||||
//sight
|
//sight
|
||||||
|
//checkItemInVault(&(this->sight),this->sight);
|
||||||
sight= parametersNode->getChild("sight")->getAttribute("value")->getIntValue();
|
sight= parametersNode->getChild("sight")->getAttribute("value")->getIntValue();
|
||||||
|
addItemToVault(&(this->sight),this->sight);
|
||||||
|
|
||||||
//prod time
|
//prod time
|
||||||
productionTime= parametersNode->getChild("time")->getAttribute("value")->getIntValue();
|
productionTime= parametersNode->getChild("time")->getAttribute("value")->getIntValue();
|
||||||
|
@ -486,6 +532,8 @@ const RepairCommandType *UnitType::getFirstRepairCommand(const UnitType *repaire
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnitType::hasEmptyCellMap() const {
|
bool UnitType::hasEmptyCellMap() const {
|
||||||
|
checkItemInVault(&(this->size),this->size);
|
||||||
|
|
||||||
bool result = (size > 0);
|
bool result = (size > 0);
|
||||||
|
|
||||||
for(int i = 0; result == true && i < size; ++i) {
|
for(int i = 0; result == true && i < size; ++i) {
|
||||||
|
@ -505,6 +553,9 @@ bool UnitType::getCellMapCell(int x, int y, CardinalDir facing) const {
|
||||||
if(cellMap == NULL) {
|
if(cellMap == NULL) {
|
||||||
throw runtime_error("cellMap == NULL");
|
throw runtime_error("cellMap == NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkItemInVault(&(this->size),this->size);
|
||||||
|
|
||||||
int tmp=0;
|
int tmp=0;
|
||||||
switch (facing) {
|
switch (facing) {
|
||||||
case CardinalDir::EAST:
|
case CardinalDir::EAST:
|
||||||
|
@ -553,45 +604,53 @@ const SkillType *UnitType::getSkillType(const string &skillName, SkillClass skil
|
||||||
// ==================== totals ====================
|
// ==================== totals ====================
|
||||||
|
|
||||||
int UnitType::getTotalMaxHp(const TotalUpgrade *totalUpgrade) const{
|
int UnitType::getTotalMaxHp(const TotalUpgrade *totalUpgrade) const{
|
||||||
|
checkItemInVault(&(this->maxHp),this->maxHp);
|
||||||
|
|
||||||
return maxHp + totalUpgrade->getMaxHp();
|
return maxHp + totalUpgrade->getMaxHp();
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnitType::getTotalMaxEp(const TotalUpgrade *totalUpgrade) const{
|
int UnitType::getTotalMaxEp(const TotalUpgrade *totalUpgrade) const{
|
||||||
|
checkItemInVault(&(this->maxEp),this->maxEp);
|
||||||
|
|
||||||
return maxEp + totalUpgrade->getMaxEp();
|
return maxEp + totalUpgrade->getMaxEp();
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnitType::getTotalArmor(const TotalUpgrade *totalUpgrade) const{
|
int UnitType::getTotalArmor(const TotalUpgrade *totalUpgrade) const {
|
||||||
|
checkItemInVault(&(this->armor),this->armor);
|
||||||
|
|
||||||
return armor + totalUpgrade->getArmor();
|
return armor + totalUpgrade->getArmor();
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnitType::getTotalSight(const TotalUpgrade *totalUpgrade) const{
|
int UnitType::getTotalSight(const TotalUpgrade *totalUpgrade) const{
|
||||||
|
checkItemInVault(&(this->sight),this->sight);
|
||||||
|
|
||||||
return sight + totalUpgrade->getSight();
|
return sight + totalUpgrade->getSight();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== has ====================
|
// ==================== has ====================
|
||||||
|
|
||||||
bool UnitType::hasSkillClass(SkillClass skillClass) const{
|
bool UnitType::hasSkillClass(SkillClass skillClass) const {
|
||||||
return firstSkillTypeOfClass[skillClass]!=NULL;
|
return firstSkillTypeOfClass[skillClass]!=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnitType::hasCommandType(const CommandType *commandType) const{
|
bool UnitType::hasCommandType(const CommandType *commandType) const {
|
||||||
assert(commandType!=NULL);
|
assert(commandType!=NULL);
|
||||||
for(int i=0; i<commandTypes.size(); ++i){
|
for(int i=0; i<commandTypes.size(); ++i) {
|
||||||
if(commandTypes[i]==commandType){
|
if(commandTypes[i]==commandType) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnitType::hasCommandClass(CommandClass commandClass) const{
|
bool UnitType::hasCommandClass(CommandClass commandClass) const {
|
||||||
return firstCommandTypeOfClass[commandClass]!=NULL;
|
return firstCommandTypeOfClass[commandClass]!=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UnitType::hasSkillType(const SkillType *skillType) const{
|
bool UnitType::hasSkillType(const SkillType *skillType) const {
|
||||||
assert(skillType!=NULL);
|
assert(skillType!=NULL);
|
||||||
for(int i=0; i<skillTypes.size(); ++i){
|
for(int i=0; i<skillTypes.size(); ++i) {
|
||||||
if(skillTypes[i]==skillType){
|
if(skillTypes[i]==skillType) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -614,11 +673,11 @@ bool UnitType::isOfClass(UnitClass uc) const{
|
||||||
|
|
||||||
// ==================== PRIVATE ====================
|
// ==================== PRIVATE ====================
|
||||||
|
|
||||||
void UnitType::computeFirstStOfClass(){
|
void UnitType::computeFirstStOfClass() {
|
||||||
for(int j= 0; j<scCount; ++j){
|
for(int j= 0; j < scCount; ++j) {
|
||||||
firstSkillTypeOfClass[j]= NULL;
|
firstSkillTypeOfClass[j]= NULL;
|
||||||
for(int i= 0; i<skillTypes.size(); ++i){
|
for(int i= 0; i < skillTypes.size(); ++i) {
|
||||||
if(skillTypes[i]->getClass()== SkillClass(j)){
|
if(skillTypes[i]->getClass()== SkillClass(j)) {
|
||||||
firstSkillTypeOfClass[j]= skillTypes[i];
|
firstSkillTypeOfClass[j]= skillTypes[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -629,10 +688,10 @@ void UnitType::computeFirstStOfClass(){
|
||||||
void UnitType::computeFirstCtOfClass(){
|
void UnitType::computeFirstCtOfClass(){
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] \n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] \n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
for(int j=0; j<ccCount; ++j){
|
for(int j=0; j<ccCount; ++j) {
|
||||||
firstCommandTypeOfClass[j]= NULL;
|
firstCommandTypeOfClass[j]= NULL;
|
||||||
for(int i=0; i<commandTypes.size(); ++i){
|
for(int i=0; i < commandTypes.size(); ++i) {
|
||||||
if(commandTypes[i]->getClass()== CommandClass(j)){
|
if(commandTypes[i]->getClass()== CommandClass(j)) {
|
||||||
firstCommandTypeOfClass[j]= commandTypes[i];
|
firstCommandTypeOfClass[j]= commandTypes[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -673,7 +732,10 @@ string UnitType::getReqDesc() const{
|
||||||
Lang &lang= Lang::getInstance();
|
Lang &lang= Lang::getInstance();
|
||||||
string desc = "Limits: ";
|
string desc = "Limits: ";
|
||||||
string resultTxt="";
|
string resultTxt="";
|
||||||
if(getMaxUnitCount()>0){
|
|
||||||
|
checkItemInVault(&(this->maxUnitCount),this->maxUnitCount);
|
||||||
|
|
||||||
|
if(getMaxUnitCount() > 0) {
|
||||||
resultTxt+="\n"+lang.get("MaxUnitCount")+" "+intToStr(getMaxUnitCount());
|
resultTxt+="\n"+lang.get("MaxUnitCount")+" "+intToStr(getMaxUnitCount());
|
||||||
}
|
}
|
||||||
if(resultTxt=="")
|
if(resultTxt=="")
|
||||||
|
|
|
@ -18,12 +18,14 @@
|
||||||
#include "sound_container.h"
|
#include "sound_container.h"
|
||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
#include "game_constants.h"
|
#include "game_constants.h"
|
||||||
|
#include "platform_common.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
using Shared::Sound::StaticSound;
|
using Shared::Sound::StaticSound;
|
||||||
using Shared::Util::Checksum;
|
using Shared::Util::Checksum;
|
||||||
|
using Shared::PlatformCommon::ValueCheckerVault;
|
||||||
|
|
||||||
class UpgradeType;
|
class UpgradeType;
|
||||||
class UnitType;
|
class UnitType;
|
||||||
|
@ -38,7 +40,7 @@ class Faction;
|
||||||
// class Level
|
// class Level
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
||||||
class Level{
|
class Level {
|
||||||
private:
|
private:
|
||||||
string name;
|
string name;
|
||||||
int kills;
|
int kills;
|
||||||
|
@ -56,7 +58,7 @@ public:
|
||||||
/// A unit or building type
|
/// A unit or building type
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
||||||
enum UnitClass{
|
enum UnitClass {
|
||||||
ucWarrior,
|
ucWarrior,
|
||||||
ucWorker,
|
ucWorker,
|
||||||
ucBuilding
|
ucBuilding
|
||||||
|
@ -64,9 +66,9 @@ enum UnitClass{
|
||||||
|
|
||||||
typedef list<UnitParticleSystemType*> DamageParticleSystemTypes;
|
typedef list<UnitParticleSystemType*> DamageParticleSystemTypes;
|
||||||
|
|
||||||
class UnitType: public ProducibleType{
|
class UnitType: public ProducibleType, public ValueCheckerVault {
|
||||||
public:
|
public:
|
||||||
enum Property{
|
enum Property {
|
||||||
pBurnable,
|
pBurnable,
|
||||||
pRotatedClimb,
|
pRotatedClimb,
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "checksum.h"
|
#include "checksum.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
#include <map>
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -164,6 +165,23 @@ inline string trim (const string & s, const string & t = SPACES) {
|
||||||
return trim_left (trim_right (d, t), t) ;
|
return trim_left (trim_right (d, t), t) ;
|
||||||
} // end of trim
|
} // end of trim
|
||||||
|
|
||||||
|
|
||||||
|
class ValueCheckerVault {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::map<const void *,string> vaultList;
|
||||||
|
|
||||||
|
void addItemToVault(const void *ptr,int value);
|
||||||
|
void checkItemInVault(const void *ptr,int value) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ValueCheckerVault() {
|
||||||
|
vaultList.clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -990,4 +990,39 @@ string ModeInfo::getString() const{
|
||||||
return intToStr(width)+"x"+intToStr(height)+"-"+intToStr(depth);
|
return intToStr(width)+"x"+intToStr(height)+"-"+intToStr(depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ValueCheckerVault::addItemToVault(const void *ptr,int value) {
|
||||||
|
Checksum checksum;
|
||||||
|
checksum.addString(intToStr(value));
|
||||||
|
vaultList[ptr] = intToStr(checksum.getSum());
|
||||||
|
|
||||||
|
// if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] add vault key [%p] value [%s] [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,intToStr(checksum.getSum()).c_str(),value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ValueCheckerVault::checkItemInVault(const void *ptr,int value) const {
|
||||||
|
map<const void *,string>::const_iterator iterFind = vaultList.find(ptr);
|
||||||
|
if(iterFind == vaultList.end()) {
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) {
|
||||||
|
// printf("In [%s::%s Line: %d] check vault key [%p] value [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,value);
|
||||||
|
// for(map<const void *,string>::const_iterator iterFind = vaultList.begin();
|
||||||
|
// iterFind != vaultList.end(); iterFind++) {
|
||||||
|
// printf("In [%s::%s Line: %d] LIST-- check vault key [%p] value [%s]\n",__FILE__,__FUNCTION__,__LINE__,iterFind->first,iterFind->second.c_str());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
throw std::runtime_error("memory value has been unexpectedly modified (not found)!");
|
||||||
|
}
|
||||||
|
Checksum checksum;
|
||||||
|
checksum.addString(intToStr(value));
|
||||||
|
if(iterFind->second != intToStr(checksum.getSum())) {
|
||||||
|
// if(SystemFlags::VERBOSE_MODE_ENABLED) {
|
||||||
|
// printf("In [%s::%s Line: %d] check vault key [%p] value [%s] [%d]\n",__FILE__,__FUNCTION__,__LINE__,ptr,intToStr(checksum.getSum()).c_str(),value);
|
||||||
|
// for(map<const void *,string>::const_iterator iterFind = vaultList.begin();
|
||||||
|
// iterFind != vaultList.end(); iterFind++) {
|
||||||
|
// printf("In [%s::%s Line: %d] LIST-- check vault key [%p] value [%s]\n",__FILE__,__FUNCTION__,__LINE__,iterFind->first,iterFind->second.c_str());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
throw std::runtime_error("memory value has been unexpectedly modified (changed)!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
Loading…
Reference in New Issue