Skip to content

Instantly share code, notes, and snippets.

@divinity76
Created July 30, 2015 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save divinity76/87d40683e04ec0898cca to your computer and use it in GitHub Desktop.
Save divinity76/87d40683e04ec0898cca to your computer and use it in GitHub Desktop.
how to fix mlvl 163 spell in YurOTS
In YurOTS, Magic Level will bug, and you'll get mlvl superfast, after:
Mages: mlvl 163
Paladin: mlvl 46
Knights: mlvl 16
this is due to several Integer Overflows through the code ( https://en.wikipedia.org/wiki/Integer_overflow )
for one, it cant save manaspent above std::numeric_limits<int32_t>::max() ,
to make it worse, the mana/mlvl is converted between int32_t, uint32_t, and 32-float, and 64-double through the code!
(if it overflows either int32_t or 32-float anywhere, mlvl will start to bug up)
- The easy fix: use int64_t and 64-double and 64-atoll (instead of 32-atoi/atol) - and some std::numeric_limits<size> checks in the protocol..
With this patch:
theoretically, you will need to use about 4.2 BILLION TIMES more mana to get magic level bug.
new bugs at:
Mages: mlvl 396 (confirmed)
Paladin: mlvl 114 (confirmed)
Knights: mlvl 35 (confirmed)
You can see the patch with colors here: https://github.com/divinity76/YurOTS/commit/db30a0addddf52cf86c5514481cbd93a8a056d03#diff-826ad1394d0a321a4c52406a9579f258L1
but without the formatting:
+CODE means "add this code"
-CODE means "remove this code"
@@BLABLA: means "near this code"
[code]
in account.h:
- unsigned long accnumber;
+ uint32_t accnumber;
in actions.cpp:
@@ -802,8 +802,8 @@ int ActionScript::internalGetPlayerInfo(lua_State *L, ePlayerInfo info)
- int value;
+ int64_t value;
@@ -1242,11 +1242,11 @@ int ActionScript::luaActionDoPlayerAddHealth(lua_State *L)
- int addmana = (int)internalGetNumber(L);
+ int64_t addmana = internalGetNumber(L);
in commands.cpp:
@@ -741,7 +741,7 @@ bool Commands::showManaForLvl(Creature* c, const std::string &cmd, const std::st
- std::string msg = std::string("You need to spent ") + str((int)player->getManaForNextMLevel()) +
+ std::string msg = std::string("You need to spent ") + str(player->getManaForNextMLevel()) +
in creature.cpp:
@@ -117,7 +117,7 @@ Creature::~Creature()
-void Creature::drainHealth(int damage, CreatureVector* arenaLosers)
+void Creature::drainHealth(int64_t damage, CreatureVector* arenaLosers)
@@ -134,7 +134,7 @@ void Creature::drainHealth(int damage)
-void Creature::drainMana(int damage)
+void Creature::drainMana(int64_t damage)
in creature.h:
@@ -35,7 +35,7 @@
extern LuaScript g_config;
#ifdef YUR_HIGH_LEVELS
-typedef __int64 exp_t;
+typedef int64_t exp_t;
@@ -123,16 +123,16 @@ class Creature : public AutoID, public Thing
- exp_t getExpForLv(const int& lv) const {
+ exp_t getExpForLv(const int& lv) const {
@@ -143,14 +143,14 @@ class Creature : public AutoID, public Thing
#ifdef YUR_PVP_ARENA
- virtual void drainHealth(int, CreatureVector* arenaLosers);
+ virtual void drainHealth(int64_t, CreatureVector* arenaLosers);
#else
virtual void drainHealth(int);
#endif //YUR_PVP_ARENA
- virtual void drainMana(int);
+ virtual void drainMana(int64_t);
- virtual int getWeaponDamage() const {
+ virtual int64_t getWeaponDamage() const {
- int mana, manamax, manaspent;
+ int64_t mana, manamax, manaspent;
- int health, healthmax;
+ int64_t health, healthmax;
- int maglevel; // magic level
+ int64_t maglevel; // magic level
in game.cpp:
@@ -181,8 +181,8 @@ void GameState::onAttack(Creature* attacker, const Position& pos, const MagicEff
- int damage = me->getDamage(targetCreature, attacker);
- int manaDamage = 0;
+ int64_t damage = me->getDamage(targetCreature, attacker);
+ int64_t manaDamage = 0;
//TODO: Decent formulas and such...
- int damage = attacker->getWeaponDamage();
+ int64_t damage = attacker->getWeaponDamage();
@@ -418,10 +418,10 @@ void GameState::onAttack(Creature* attacker, const Position& pos, Creature* atta
}
#endif //YUR_CVS_MODS
- int manaDamage = 0;
+ int64_t manaDamage = 0;
if(attackPlayer && attackedPlayer){
- damage -= (int) damage / 2;
+ damage -= damage / 2;
@@ -484,7 +484,7 @@ void GameState::onAttack(Creature* attacker, const Position& pos, Creature* atta
#endif //YUR_PVP_ARENA
}
-void GameState::addCreatureState(Tile* tile, Creature* attackedCreature, int damage, int manaDamage, bool drawBlood)
+void GameState::addCreatureState(Tile* tile, Creature* attackedCreature, int64_t damage, int64_t manaDamage, bool drawBlood)
@@ -494,7 +494,7 @@ void GameState::addCreatureState(Tile* tile, Creature* attackedCreature, int dam
creaturestates[tile].push_back( make_pair(attackedCreature, cs) );
}
-void GameState::onAttackedCreature(Tile* tile, Creature *attacker, Creature* attackedCreature, int damage, bool drawBlood)
+void GameState::onAttackedCreature(Tile* tile, Creature *attacker, Creature* attackedCreature, int64_t damage, bool drawBlood)
@@ -3390,7 +3390,7 @@ bool Game::creatureMakeMagic(Creature *creature, const Position& centerpos, cons
return bSuccess;
}
-void Game::creatureApplyDamage(Creature *creature, int damage, int &outDamage, int &outManaDamage
+void Game::creatureApplyDamage(Creature *creature, int64_t damage, int64_t &outDamage, int64_t &outManaDamage
@@ -3535,9 +3535,9 @@ bool Game::creatureOnPrepareMagicAttack(Creature *creature, Position pos, const
return false;
}
else
- player->mana -= me->manaCost;
+ player->mana -= (int64_t)me->manaCost;
//player->manaspent += me->manaCost;
- player->addManaSpent(me->manaCost);
+ player->addManaSpent((int64_t)me->manaCost);
}
@@ -4159,7 +4159,7 @@ void Game::checkSpawns(int t)
this->addEvent(makeTask(t, std::bind2nd(std::mem_fun(&Game::checkSpawns), t)));
}
-void Game::CreateDamageUpdate(Creature* creature, Creature* attackCreature, int damage)
+void Game::CreateDamageUpdate(Creature* creature, Creature* attackCreature, int64_t damage)
@@ -4194,7 +4194,7 @@ void Game::CreateDamageUpdate(Creature* creature, Creature* attackCreature, int
}
}
-void Game::CreateManaDamageUpdate(Creature* creature, Creature* attackCreature, int damage)
+void Game::CreateManaDamageUpdate(Creature* creature, Creature* attackCreature, int64_t damage)
@@ -5537,7 +5537,7 @@ void Game::checkSpell(Player* player, SpeakClasses& type, std::string text)
(g_config.SUMMONS_ALL_VOC && player->vocation != VOCATION_NONE))
{
std::string name = text.substr(11);
- int reqMana = Summons::getRequiredMana(name);
+ int64_t reqMana = Summons::getRequiredMana(name);
@@ -6158,7 +6183,7 @@ void Game::useWand(Creature *creature, Creature *attackedCreature, int wandid)
if(!player || !attackedCreature || player->pos.z != attackedCreature->pos.z)
return;
- int dist, mana = 0;
+ int64_t dist, mana = 0;
in game.h:
@@ -69,8 +69,8 @@ class CreatureState {
CreatureState() {};
~CreatureState() {};
- int damage;
- int manaDamage;
+ int64_t damage;
+ int64_t manaDamage;
@@ -95,8 +95,8 @@ class GameState {
const SpectatorVec& getSpectators() {return spectatorlist;}
protected:
- void addCreatureState(Tile* tile, Creature* attackedCreature, int damage, int manaDamage, bool drawBlood);
- void onAttackedCreature(Tile* tile, Creature* attacker, Creature* attackedCreature, int damage, bool drawBlood);
+ void addCreatureState(Tile* tile, Creature* attackedCreature, int64_t damage, int64_t manaDamage, bool drawBlood);
+ void onAttackedCreature(Tile* tile, Creature* attacker, Creature* attackedCreature, int64_t damage, bool drawBlood);
@@ -440,14 +440,14 @@ class Game {
* Change the players hitpoints
* Return: the mana damage and the actual hitpoint loss
*/
- void creatureApplyDamage(Creature *creature, int damage, int &outDamage, int &outManaDamage
+ void creatureApplyDamage(Creature *creature, int64_t damage, int64_t &outDamage, int64_t &outManaDamage
#ifdef YUR_PVP_ARENA
, CreatureVector*
#endif //YUR_PVP_ARENA
);
- void CreateDamageUpdate(Creature* player, Creature* attackCreature, int damage);
- void CreateManaDamageUpdate(Creature* player, Creature* attackCreature, int damage);
+ void CreateDamageUpdate(Creature* player, Creature* attackCreature, int64_t damage);
+ void CreateManaDamageUpdate(Creature* player, Creature* attackCreature, int64_t damage);
in ioplayerxml.cpp:
@@ -206,7 +206,7 @@ bool IOPlayerXML::loadPlayer(Player* player, std::string name){
- player->mana=atoi(nodeValue);
+ player->mana=atoll(nodeValue);
@@ -214,7 +214,7 @@ bool IOPlayerXML::loadPlayer(Player* player, std::string name){
nodeValue = (char*)xmlGetProp(p, (const xmlChar *) "max");
if(nodeValue) {
- player->manamax=atoi(nodeValue);
+ player->manamax=atoll(nodeValue);
@@ -222,7 +222,7 @@ bool IOPlayerXML::loadPlayer(Player* player, std::string name){
nodeValue = (char*)xmlGetProp(p, (const xmlChar *) "spent");
if(nodeValue) {
- player->manaspent=atoi(nodeValue);
+ player->manaspent=atoll(nodeValue);
in luascript.cpp:
@@ -57,17 +57,17 @@ int LuaScript::OpenFile(const char *filename)
CAP_GAIN[VOCATION_PALADIN] = atoi(getGlobalStringField("capgain", VOCATION_PALADIN + 1, "20").c_str());
CAP_GAIN[VOCATION_KNIGHT] = atoi(getGlobalStringField("capgain", VOCATION_KNIGHT + 1, "25").c_str());
- MANA_GAIN[VOCATION_NONE] = atoi(getGlobalStringField("managain", VOCATION_NONE + 1, "5").c_str());
- MANA_GAIN[VOCATION_SORCERER] = atoi(getGlobalStringField("managain", VOCATION_SORCERER + 1, "30").c_str());
- MANA_GAIN[VOCATION_DRUID] = atoi(getGlobalStringField("managain", VOCATION_DRUID + 1, "30").c_str());
- MANA_GAIN[VOCATION_PALADIN] = atoi(getGlobalStringField("managain", VOCATION_PALADIN + 1, "15").c_str());
- MANA_GAIN[VOCATION_KNIGHT] = atoi(getGlobalStringField("managain", VOCATION_KNIGHT + 1, "5").c_str());
-
- HP_GAIN[VOCATION_NONE] = atoi(getGlobalStringField("hpgain", VOCATION_NONE + 1, "5").c_str());
- HP_GAIN[VOCATION_SORCERER] = atoi(getGlobalStringField("hpgain", VOCATION_SORCERER + 1, "5").c_str());
- HP_GAIN[VOCATION_DRUID] = atoi(getGlobalStringField("hpgain", VOCATION_DRUID + 1, "5").c_str());
- HP_GAIN[VOCATION_PALADIN] = atoi(getGlobalStringField("hpgain", VOCATION_PALADIN + 1, "10").c_str());
- HP_GAIN[VOCATION_KNIGHT] = atoi(getGlobalStringField("hpgain", VOCATION_KNIGHT + 1, "15").c_str());
+ MANA_GAIN[VOCATION_NONE] = atoll(getGlobalStringField("managain", VOCATION_NONE + 1, "5").c_str());
+ MANA_GAIN[VOCATION_SORCERER] = atoll(getGlobalStringField("managain", VOCATION_SORCERER + 1, "30").c_str());
+ MANA_GAIN[VOCATION_DRUID] = atoll(getGlobalStringField("managain", VOCATION_DRUID + 1, "30").c_str());
+ MANA_GAIN[VOCATION_PALADIN] = atoll(getGlobalStringField("managain", VOCATION_PALADIN + 1, "15").c_str());
+ MANA_GAIN[VOCATION_KNIGHT] = atoll(getGlobalStringField("managain", VOCATION_KNIGHT + 1, "5").c_str());
+
+ HP_GAIN[VOCATION_NONE] = atoll(getGlobalStringField("hpgain", VOCATION_NONE + 1, "5").c_str());
+ HP_GAIN[VOCATION_SORCERER] = atoll(getGlobalStringField("hpgain", VOCATION_SORCERER + 1, "5").c_str());
+ HP_GAIN[VOCATION_DRUID] = atoll(getGlobalStringField("hpgain", VOCATION_DRUID + 1, "5").c_str());
+ HP_GAIN[VOCATION_PALADIN] = atoll(getGlobalStringField("hpgain", VOCATION_PALADIN + 1, "10").c_str());
+ HP_GAIN[VOCATION_KNIGHT] = atoll(getGlobalStringField("hpgain", VOCATION_KNIGHT + 1, "15").c_str());
@@ -87,11 +87,11 @@ int LuaScript::OpenFile(const char *filename)
SHIELD_MUL[VOCATION_PALADIN] = atoi(getGlobalStringField("shieldmul", VOCATION_PALADIN+1, "1").c_str());
SHIELD_MUL[VOCATION_KNIGHT] = atoi(getGlobalStringField("shieldmul", VOCATION_KNIGHT+1, "1").c_str());
- MANA_MUL[VOCATION_NONE] = atoi(getGlobalStringField("manamul", VOCATION_NONE+1, "1").c_str());
- MANA_MUL[VOCATION_SORCERER] = atoi(getGlobalStringField("manamul", VOCATION_SORCERER+1, "1").c_str());
- MANA_MUL[VOCATION_DRUID] = atoi(getGlobalStringField("manamul", VOCATION_DRUID+1, "1").c_str());
- MANA_MUL[VOCATION_PALADIN] = atoi(getGlobalStringField("manamul", VOCATION_PALADIN+1, "1").c_str());
- MANA_MUL[VOCATION_KNIGHT] = atoi(getGlobalStringField("manamul", VOCATION_KNIGHT+1, "1").c_str());
+ MANA_MUL[VOCATION_NONE] = atoll(getGlobalStringField("manamul", VOCATION_NONE+1, "1").c_str());
+ MANA_MUL[VOCATION_SORCERER] = atoll(getGlobalStringField("manamul", VOCATION_SORCERER+1, "1").c_str());
+ MANA_MUL[VOCATION_DRUID] = atoll(getGlobalStringField("manamul", VOCATION_DRUID+1, "1").c_str());
+ MANA_MUL[VOCATION_PALADIN] = atoll(getGlobalStringField("manamul", VOCATION_PALADIN+1, "1").c_str());
+ MANA_MUL[VOCATION_KNIGHT] = atoll(getGlobalStringField("manamul", VOCATION_KNIGHT+1, "1").c_str());
#endif //YUR_MULTIPLIERS
@@ -153,7 +153,7 @@ int LuaScript::OpenFile(const char *filename)
PROMOTED_VOCATIONS[VOCATION_DRUID] = getGlobalStringField("promoted_vocations",VOCATION_DRUID);
DIE_PERCENT_EXP = atoi(getGlobalStringField("diepercent",1,"7").c_str());
- DIE_PERCENT_MANA = atoi(getGlobalStringField("diepercent",2,"7").c_str());
+ DIE_PERCENT_MANA = atoll(getGlobalStringField("diepercent",2,"7").c_str());
@@ -178,17 +178,17 @@ int LuaScript::OpenFile(const char *filename)
#endif //JD_DEATH_LIST
#ifdef JD_WANDS
- MANA_SNAKEBITE = atoi(getGlobalStringField("rodmana", 1, "2").c_str());
- MANA_MOONLIGHT = atoi(getGlobalStringField("rodmana", 2, "3").c_str());
- MANA_VOLCANIC = atoi(getGlobalStringField("rodmana", 3, "5").c_str());
- MANA_QUAGMIRE = atoi(getGlobalStringField("rodmana", 4, "8").c_str());
- MANA_TEMPEST = atoi(getGlobalStringField("rodmana", 5, "13").c_str());
-
- MANA_VORTEX = atoi(getGlobalStringField("wandmana", 1, "2").c_str());
- MANA_DRAGONBREATH = atoi(getGlobalStringField("wandmana", 2, "3").c_str());
- MANA_PLAGUE = atoi(getGlobalStringField("wandmana", 3, "5").c_str());
- MANA_COSMIC = atoi(getGlobalStringField("wandmana", 4, "8").c_str());
- MANA_INFERNO = atoi(getGlobalStringField("wandmana", 5, "13").c_str());
+ MANA_SNAKEBITE = atoll(getGlobalStringField("rodmana", 1, "2").c_str());
+ MANA_MOONLIGHT = atoll(getGlobalStringField("rodmana", 2, "3").c_str());
+ MANA_VOLCANIC = atoll(getGlobalStringField("rodmana", 3, "5").c_str());
+ MANA_QUAGMIRE = atoll(getGlobalStringField("rodmana", 4, "8").c_str());
+ MANA_TEMPEST = atoll(getGlobalStringField("rodmana", 5, "13").c_str());
+
+ MANA_VORTEX = atoll(getGlobalStringField("wandmana", 1, "2").c_str());
+ MANA_DRAGONBREATH = atoll(getGlobalStringField("wandmana", 2, "3").c_str());
+ MANA_PLAGUE = atoll(getGlobalStringField("wandmana", 3, "5").c_str());
+ MANA_COSMIC = atoll(getGlobalStringField("wandmana", 4, "8").c_str());
+ MANA_INFERNO = atoll(getGlobalStringField("wandmana", 5, "13").c_str());
in luascript.h:
@@ -47,15 +47,15 @@ class LuaScript
#ifdef YUR_MULTIPLIERS
exp_t EXP_MUL;
exp_t EXP_MUL_PVP;
- int HEALTH_TICK_MUL;
- int MANA_TICK_MUL;
- int CAP_GAIN[5];
- int MANA_GAIN[5];
- int HP_GAIN[5];
+ int64_t HEALTH_TICK_MUL;
+ int64_t MANA_TICK_MUL;
+ int64_t CAP_GAIN[5];
+ int64_t MANA_GAIN[5];
+ int64_t HP_GAIN[5];
int WEAPON_MUL[5];
int SHIELD_MUL[5];
int DIST_MUL[5];
- int MANA_MUL[5];
+ int64_t MANA_MUL[5];
#endif //YUR_MULTIPLIERS
@@ -109,7 +109,7 @@ class LuaScript
std::string VOCATIONS[5];
std::string PROMOTED_VOCATIONS[5];
int DIE_PERCENT_EXP;
- int DIE_PERCENT_MANA;
+ int64_t DIE_PERCENT_MANA;
@@ -131,17 +131,17 @@ class LuaScript
#endif //JD_DEATH_LIST
#ifdef JD_WANDS
- int MANA_SNAKEBITE;
- int MANA_MOONLIGHT;
- int MANA_VOLCANIC;
- int MANA_QUAGMIRE;
- int MANA_TEMPEST;
-
- int MANA_VORTEX;
- int MANA_DRAGONBREATH;
- int MANA_PLAGUE;
- int MANA_COSMIC;
- int MANA_INFERNO;
+ int64_t MANA_SNAKEBITE;
+ int64_t MANA_MOONLIGHT;
+ int64_t MANA_VOLCANIC;
+ int64_t MANA_QUAGMIRE;
+ int64_t MANA_TEMPEST;
+
+ int64_t MANA_VORTEX;
+ int64_t MANA_DRAGONBREATH;
+ int64_t MANA_PLAGUE;
+ int64_t MANA_COSMIC;
+ int64_t MANA_INFERNO;
in magic.cpp:
@@ -52,13 +52,13 @@ bool MagicEffectClass::causeExhaustion(bool hasTarget) const
return hasTarget;
}
-int MagicEffectClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
+int64_t MagicEffectClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
{
if((attackType != ATTACK_NONE) && (target->getImmunities() & attackType) == attackType)
return 0;
if((!offensive || (target != attacker)) && target->access < g_config.ACCESS_PROTECT) {
- int damage = (int)random_range(minDamage, maxDamage);
+ int64_t damage = (int64_t)random_range(minDamage, maxDamage);
@@ -200,20 +200,20 @@ condition(dmglist)
}
-int MagicEffectTargetExClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
+int64_t MagicEffectTargetExClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
@@ -221,7 +221,7 @@ int MagicEffectTargetExClass::getDamage(Creature *target, const Creature *attack
}
}
- int damage = (int)random_range(minDamage, maxDamage);
+ int64_t damage = random_range(minDamage, maxDamage);
@@ -239,13 +239,13 @@ MagicEffectTargetCreatureCondition::MagicEffectTargetCreatureCondition(const uns
//
}
-int MagicEffectTargetCreatureCondition::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
+int64_t MagicEffectTargetCreatureCondition::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
{
if((attackType != ATTACK_NONE) && (target->getImmunities() & attackType) == attackType)
return 0;
if(target->access < g_config.ACCESS_PROTECT) {
- int damage = (int)random_range(minDamage, maxDamage);
+ int64_t damage = random_range(minDamage, maxDamage);
@@ -396,7 +396,7 @@ condition(dmglist)
//
}
-int MagicEffectAreaExClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
+int64_t MagicEffectAreaExClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
{
if((attackType != ATTACK_NONE) && (target->getImmunities() & attackType) == attackType)
return 0;
@@ -416,7 +416,7 @@ int MagicEffectAreaExClass::getDamage(Creature *target, const Creature *attacker
}
}
- int damage = (int)random_range(minDamage, maxDamage);
+ int64_t damage = random_range(minDamage, maxDamage);
@@ -441,7 +441,7 @@ MagicEffectAreaGroundClass::~MagicEffectAreaGroundClass()
}
}
-int MagicEffectAreaGroundClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
+int64_t MagicEffectAreaGroundClass::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
@@ -534,7 +534,7 @@ void MagicEffectItem::buildCondition()
}
}
-int MagicEffectItem::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
+int64_t MagicEffectItem::getDamage(Creature *target, const Creature *attacker /*= NULL*/) const
in magic.h:
@@ -83,11 +83,11 @@ class MagicEffectClass {
- virtual int getDamage(Creature* target, const Creature* attacker = NULL) const;
+ virtual int64_t getDamage(Creature* target, const Creature* attacker = NULL) const;
@@ -108,7 +108,7 @@ class MagicEffectClass {
int maxDamage;
bool offensive;
bool drawblood; //causes blood splashes
- long manaCost;
+ double manaCost;
@@ -154,7 +154,7 @@ class MagicEffectTargetCreatureCondition : public MagicEffectTargetClass
return false;
}
- virtual int getDamage(Creature *target, const Creature *attacker = NULL) const;
+ virtual int64_t getDamage(Creature *target, const Creature *attacker = NULL) const;
@@ -222,7 +222,7 @@ class MagicEffectTargetExClass : public MagicEffectTargetClass
MagicEffectTargetExClass(const ConditionVec& condition);
virtual ~MagicEffectTargetExClass() {};
- virtual int getDamage(Creature *target, const Creature *attacker = NULL) const;
+ virtual int64_t getDamage(Creature *target, const Creature *attacker = NULL) const;
@@ -254,12 +254,12 @@ class MagicEffectItem : public Item, public MagicEffectClass
return false;
}
- virtual int getDamage(Creature *target, const Creature *attacker = NULL) const;
+ virtual int64_t getDamage(Creature *target, const Creature *attacker = NULL) const;
@@ -278,7 +278,7 @@ class MagicEffectTargetGroundClass : public MagicEffectTargetClass {
return true;
}
- virtual int getDamage(Creature *target, const Creature *attacker = NULL) const
+ virtual int64_t getDamage(Creature *target, const Creature *attacker = NULL) const
@@ -329,7 +329,7 @@ class MagicEffectAreaExClass : public MagicEffectAreaClass
MagicEffectAreaExClass(const ConditionVec& dmglist);
virtual ~MagicEffectAreaExClass() {};
- virtual int getDamage(Creature *target, const Creature *attacker = NULL) const;
+ virtual int64_t getDamage(Creature *target, const Creature *attacker = NULL) const;
@@ -342,10 +342,10 @@ class MagicEffectAreaGroundClass : public MagicEffectAreaClass
MagicEffectAreaGroundClass(MagicEffectItem* fieldItem);
virtual ~MagicEffectAreaGroundClass();
- virtual int getDamage(Creature *target, const Creature *attacker = NULL) const;
+ virtual int64_t getDamage(Creature *target, const Creature *attacker = NULL) const;
in monster.cpp:
@@ -1126,7 +1126,7 @@ std::string Monster::getDescription(bool self) const
return str;
}
-int Monster::getWeaponDamage() const
+int64_t Monster::getWeaponDamage() const
in monster.h:
@@ -117,7 +117,7 @@ class Monster : public Creature
virtual fight_t getFightType() {return curPhysicalAttack->fighttype;};
virtual subfight_t getSubFightType() {return curPhysicalAttack->disttype;}
- virtual int getWeaponDamage() const;
+ virtual int64_t getWeaponDamage() const;
in npc.cpp:
@@ -104,20 +104,20 @@ Npc::Npc(const std::string& name, Game* game) :
while (p)
{
const char* str = (char*)p->name;
if(strcmp(str, "mana") == 0){
if(tmp = (char*)xmlGetProp(p, (const xmlChar *)"now")) {
- this->mana = atoi(tmp);
+ this->mana = atoll(tmp);
xmlFreeOTSERV(tmp);
}
else{
this->mana = 100;
}
if(tmp = (char*)xmlGetProp(p, (const xmlChar *)"max")) {
- this->manamax = atoi(tmp);
+ this->manamax = atoll(tmp);
in npc.h:
@@ -133,7 +133,7 @@ class Npc : public Creature
const std::string& getName() const {return name;};
fight_t getFightType(){return fighttype;};
- int mana, manamax;
+ int64_t mana, manamax;
in player.cpp:
@@ -48,17 +49,17 @@ extern Chat g_chat;
AutoList<Player> Player::listPlayer;
#ifdef YUR_PREMIUM_PROMOTION
-const int Player::promotedGainManaVector[5][2] = {{6,1},{2,1},{2,1},{3,1},{6,1}};
-const int Player::promotedGainHealthVector[5][2] = {{6,1},{6,1},{6,1},{3,1},{2,1}};
+const int64_t Player::promotedGainManaVector[5][2] = {{6,1},{2,1},{2,1},{3,1},{6,1}};
+const int64_t Player::promotedGainHealthVector[5][2] = {{6,1},{6,1},{6,1},{3,1},{2,1}};
#endif //YUR_PREMIUM_PROMOTION
-const int Player::gainManaVector[5][2] = {{6,1},{3,1},{3,1},{4,1},{6,1}};
-const int Player::gainHealthVector[5][2] = {{6,1},{6,1},{6,1},{4,1},{3,1}};
+const int64_t Player::gainManaVector[5][2] = {{6,1},{3,1},{3,1},{4,1},{6,1}};
+const int64_t Player::gainHealthVector[5][2] = {{6,1},{6,1},{6,1},{4,1},{3,1}};
#ifdef CVS_GAINS_MULS
int Player::CapGain[5] = {10, 10, 10, 20, 25};
-int Player::ManaGain[5] = {5, 30, 30, 15, 5};
-int Player::HPGain[5] = {5, 5, 5, 10, 15};
+int64_t Player::ManaGain[5] = {5, 30, 30, 15, 5};
+int64_t Player::HPGain[5] = {5, 5, 5, 10, 15};
#endif //CVS_GAINS_MULS
@@ -303,7 +304,7 @@ Item* Player::getItem(int pos) const
return NULL;
}
-int Player::getWeaponDamage() const
+int64_t Player::getWeaponDamage() const
{
double mul = 1.0;
#ifdef YUR_FIGHT_MODE
@@ -372,7 +373,7 @@ int Player::getWeaponDamage() const
damagemax = 2*mul*getSkill(SKILL_FIST,SKILL_LEVEL) + 5;
// return it
- return 1+(int)(damagemax*rand()/(RAND_MAX+1.0));
+ return 1+(int64_t)(damagemax*rand()/(RAND_MAX+1.0));
}
@@ -1033,7 +1034,7 @@ void Player::addSkillShieldTry(int skilltry){
}
}
-int Player::getPlayerInfo(playerinfo_t playerinfo) const
+int64_t Player::getPlayerInfo(playerinfo_t playerinfo) const
@@ -1053,7 +1054,7 @@ int Player::getPlayerInfo(playerinfo_t playerinfo) const
return 0;
}
-int Player::getSkill(skills_t skilltype, skillsid_t skillinfo) const
+int64_t Player::getSkill(skills_t skilltype, skillsid_t skillinfo) const
@@ -1134,13 +1135,12 @@ void Player::addSkillTryInternal(int skilltry,int skill){
}
-unsigned int Player::getReqMana(int maglevel, playervoc_t voc) {
+uint64_t Player::getReqMana(int64_t maglevel, playervoc_t voc) {
//ATTENTION: MAKE SURE THAT CHARS HAVE REASONABLE MAGIC LEVELS. ESPECIALY KNIGHTS!!!!!!!!!!!
- float ManaMultiplier[5] = { 1.0f, 1.1f, 1.1f, 1.4f, 3};
+ double ManaMultiplier[5] = { 1.0, 1.1, 1.1, 1.4, 3.0};
//will calculate required mana for a magic level
- unsigned int reqMana = (unsigned int) ( 400 * pow(ManaMultiplier[(int)voc], maglevel-1) );
-
+ uint64_t reqMana = (uint64_t)( 400 * std::pow(double(ManaMultiplier[voc]), double(maglevel-1)));
if (reqMana % 20 < 10) //CIP must have been bored when they invented this odd rounding
@@ -1807,7 +1807,7 @@ void Player::onTeleport(const Creature *creature, const Position *oldPos, unsign
client->sendThingMove(creature, creature,oldPos, oldstackpos, true, 1, 1);
}
-void Player::addManaSpent(unsigned long spent){
+void Player::addManaSpent(uint64_t spent){
if(spent == 0)
return;
@@ -1817,12 +1817,16 @@ void Player::addManaSpent(unsigned long spent){
this->manaspent += spent;
//Magic Level Advance
- int reqMana = this->getReqMana(this->maglevel+1, this->vocation);
+ int64_t reqMana = this->getReqMana(this->maglevel+1, this->vocation);
@@ -1860,15 +1864,15 @@ unsigned long Player::getIP() const
void Player::die()
{
//Magic Level downgrade
- unsigned long sumMana = 0;
- long lostMana = 0;
- for (int i = 1; i <= maglevel; i++) { //sum up all the mana
+ uint64_t sumMana = 0;
+ int64_t lostMana = 0;
+ for (int64_t i = 1; i <= maglevel; i++) { //sum up all the mana
sumMana += getReqMana(i, vocation);
}
sumMana += manaspent;
- lostMana = (long)(sumMana * g_config.DIE_PERCENT_MANA/100.0); //player loses 10% of all spent mana when he dies
+ lostMana = (int64_t)(sumMana * g_config.DIE_PERCENT_MANA/100.0); //player loses 10% of all spent mana when he dies
while(lostMana > manaspent){
@@ -1973,7 +1977,7 @@ void Player::kickPlayer()
bool Player::gainManaTick()
{
- int add;
+ int64_t add;
@@ -2647,7 +2651,7 @@ exp_t Player::getExpForNextLevel()
return getExpForLv(level + 1) - experience;
}
-unsigned long Player::getManaForNextMLevel()
+uint64_t Player::getManaForNextMLevel()
in player.h:
@@ -163,9 +163,9 @@ class Player : public Creature
inline StorageMap::const_iterator getStorageIteratorEnd() const {return storageMap.end();}
int getLevel() const {return level;}
- int getHealth() const {return health;}
- int getMana() const {return mana;}
- int getMagicLevel() const {return maglevel;}
+ int64_t getHealth() const {return health;}
+ int64_t getMana() const {return mana;}
+ int64_t getMagicLevel() const {return maglevel;}
playersex_t getSex() {return sex;}
@@ -175,8 +175,8 @@ class Player : public Creature
unsigned long getGuildId() const {return guildId;};
- int getPlayerInfo(playerinfo_t playerinfo) const;
- int getSkill(skills_t skilltype, skillsid_t skillinfo) const;
+ int64_t getPlayerInfo(playerinfo_t playerinfo) const;
+ int64_t getSkill(skills_t skilltype, skillsid_t skillinfo) const;
@@ -209,9 +209,9 @@ class Player : public Creature
Item* getItem(int pos) const;
Item* GetDistWeapon() const;
- void addManaSpent(unsigned long spent);
+ void addManaSpent(uint64_t spent);
void addExp(exp_t exp);
- virtual int getWeaponDamage() const;
+ virtual int64_t getWeaponDamage() const;
@@ -371,7 +371,7 @@ class Player : public Creature
#ifdef YUR_CMD_EXT
exp_t getExpForNextLevel();
- unsigned long getManaForNextMLevel();
+ uint64_t getManaForNextMLevel();
#endif //YUR_CMD_EXT
@@ -519,7 +519,7 @@ class Player : public Creature
static int WEAPON_MUL[5];
static int DIST_MUL[5];
static int SHIELD_MUL[5];
- static int MANA_MUL[5];
+ static int64_t MANA_MUL[5];
@@ -575,17 +575,17 @@ class Player : public Creature
//reminder: 0 = None, 1 = Sorcerer, 2 = Druid, 3 = Paladin, 4 = Knight
static int CapGain[5]; //for level advances
- static int ManaGain[5];
+ static int64_t ManaGain[5];
- static int HPGain[5];
+ static int64_t HPGain[5];
#endif //CVS_GAINS_MULS
- static const int gainManaVector[5][2];
- static const int gainHealthVector[5][2];
+ static const int64_t gainManaVector[5][2];
+ static const int64_t gainHealthVector[5][2];
unsigned short manaTick;
unsigned short healthTick;
#ifdef YUR_PREMIUM_PROMOTION
- static const int promotedGainManaVector[5][2];
- static const int promotedGainHealthVector[5][2];
+ static const int64_t promotedGainManaVector[5][2];
+ static const int64_t promotedGainHealthVector[5][2];
#endif //YUR_PREMIUM_PROMOTION
@@ -615,10 +615,10 @@ class Player : public Creature
int level;
double freeCapacity;
//int cap;
- int mana;
- int manamax;
- int manaspent;
- int maglevel;
+ int64_t mana;
+ int64_t manamax;
+ int64_t manaspent;
+ int64_t maglevel;
};
@@ -652,7 +652,7 @@ class Player : public Creature
unsigned int getReqSkillTries (int skill, int level, playervoc_t voc);
//for magic level advances
- unsigned int getReqMana(int maglevel, playervoc_t voc);
+ uint64_t getReqMana(int64_t maglevel, playervoc_t voc);
in protocol76.cpp:
@@ -26,7 +26,7 @@
#include <sstream>
#include <time.h>
#include <list>
-
+#include <limits>
#include "networkmessage.h"
#include "protocol76.h"
@@ -2712,11 +2712,11 @@ void Protocol76::AddCreature(NetworkMessage &msg,const Creature *creature, bool
msg.AddU32(creature->getID());
msg.AddString(creature->getName());
}
- msg.AddByte(std::max(1, creature->health*100/creature->healthmax));
+ msg.AddByte(std::max(1LL, creature->health*100/creature->healthmax));
@@ -2819,9 +2819,9 @@ void Protocol76::AddPlayerStats(NetworkMessage &msg,const Player *player)
#endif //YUR_HIGH_LEVELS
msg.AddByte(player->getPlayerInfo(PLAYERINFO_LEVELPERCENT));
- msg.AddU16(player->getMana());
- msg.AddU16(player->getPlayerInfo(PLAYERINFO_MAXMANA));
- msg.AddByte(player->getMagicLevel());
+ msg.AddU16(player->getMana() > std::numeric_limits<uint16_t>::max() ? 0:player->getMana());
+ msg.AddU16(player->getPlayerInfo(PLAYERINFO_MAXMANA) > std::numeric_limits<uint16_t>::max() ? 0:player->getPlayerInfo(PLAYERINFO_MAXMANA));
+ msg.AddByte(player->getMagicLevel() > std::numeric_limits<uint8_t>::max() ? 0:player->getMagicLevel());
msg.AddByte(player->getPlayerInfo(PLAYERINFO_MAGICLEVELPERCENT));
msg.AddByte(player->getPlayerInfo(PLAYERINFO_SOUL));
@@ -2889,7 +2889,7 @@ void Protocol76::AddCreatureHealth(NetworkMessage &msg,const Creature *creature)
{
msg.AddByte(0x8C);
msg.AddU32(creature->getID());
- msg.AddByte(std::max(1, creature->health*100/creature->healthmax));
+ msg.AddByte(std::max(1LL, creature->health*100/creature->healthmax));
then in spells.cpp:
@@ -35,14 +35,14 @@
bool Spells::loadFromXml(const std::string &datadir)
{
std::string name, words;
bool enabled = false;
- int vocId, maglv = 0, mana = 0, id = 0, charges = 0;
+ int64_t vocId, maglv = 0, mana = 0, id = 0, charges = 0;
@@ -54,36 +54,36 @@ bool Spells::loadFromXml(const std::string &datadir)
- maxVoc = atoi(nodeValue);
+ maxVoc = atoll(nodeValue);
@@ -100,18 +100,18 @@ bool Spells::loadFromXml(const std::string &datadir)
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"maglv");
if(nodeValue) {
- maglv = atoi(nodeValue);
+ maglv = atoll(nodeValue);
xmlFreeOTSERV(nodeValue);
}
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"mana");
if(nodeValue) {
- mana = atoi(nodeValue);
+ mana = atoll(nodeValue);
xmlFreeOTSERV(nodeValue);
}
@@ -161,18 +161,18 @@ bool Spells::loadFromXml(const std::string &datadir)
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"maglv");
if(nodeValue) {
- maglv = atoi(nodeValue);
+ maglv = atoll(nodeValue);
xmlFreeOTSERV(nodeValue);
}
nodeValue = (char*)xmlGetProp(p, (const xmlChar *)"mana");
if(nodeValue) {
- mana = atoi(nodeValue);
+ mana = atoll(nodeValue);
xmlFreeOTSERV(nodeValue);
}
@@ -212,7 +212,7 @@ Spells::~Spells(){
}
}
-Spell::Spell(std::string iname, int imagLv, int imana, Game* igame)
+Spell::Spell(std::string iname, int64_t imagLv, int64_t imana, Game* igame)
@@ -226,7 +226,7 @@ Spell::~Spell(){
}
}
-InstantSpell::InstantSpell(const std::string &datadir, std::string iname, std::string iwords, int magLv, int mana, Game* game)
+InstantSpell::InstantSpell(const std::string &datadir, std::string iname, std::string iwords, int64_t magLv, int64_t mana, Game* game)
@@ -235,7 +235,7 @@ InstantSpell::InstantSpell(const std::string &datadir, std::string iname, std::s
}
-RuneSpell::RuneSpell(const std::string &datadir, std::string iname, unsigned short id, unsigned short charges, int magLv, int mana, Game* game)
+RuneSpell::RuneSpell(const std::string &datadir, std::string iname, unsigned short id, unsigned short charges, int64_t magLv, int64_t mana, Game* game)
then in spells.h:
@@ -90,7 +90,7 @@ class Spells
class Spell
{
public:
- Spell(std::string name, int magLv, int mana, Game* game);
+ Spell(std::string name, int64_t magLv, int64_t mana, Game* game);
@@ -98,13 +98,13 @@ class Spell
bool isLoaded(){return loaded;}
SpellScript* getSpellScript(){return script;};
std::string getName() const {return name;};
- int getMana(){return mana;};
- int getMagLv(){
+ int64_t getMana(){return mana;};
+ int64_t getMagLv(){
return magLv;};
@@ -98,13 +98,13 @@ class Spell
bool isLoaded(){return loaded;}
SpellScript* getSpellScript(){return script;};
std::string getName() const {return name;};
- int getMana(){return mana;};
- int getMagLv(){
+ int64_t getMana(){return mana;};
+ int64_t getMagLv(){
return magLv;};
protected:
std::string name;
- int magLv, mana;
+ int64_t magLv, mana;
bool loaded;
SpellScript* script;
@@ -112,7 +112,7 @@ class Spell
class InstantSpell : public Spell
{
public:
- InstantSpell(const std::string &, std::string name, std::string words, int magLv, int mana, Game* game);
+ InstantSpell(const std::string &, std::string name, std::string words, int64_t magLv, int64_t mana, Game* game);
@@ -122,7 +122,7 @@ class InstantSpell : public Spell
class RuneSpell : public Spell
{
public:
- RuneSpell(const std::string& ,std::string name, unsigned short id, unsigned short charges, int magLv, int mana, Game* game);
+ RuneSpell(const std::string& ,std::string name, unsigned short id, unsigned short charges, int64_t magLv, int64_t mana, Game* game);
then in summons.cpp:
@@ -28,7 +28,7 @@ extern LuaScript g_config;
Summons::SummonMap Summons::summons;
-int Summons::getRequiredMana(std::string name)
+int64_t Summons::getRequiredMana(std::string name)
@@ -63,7 +63,7 @@ bool Summons::Load()
if (strcmp((char*) summonNode->name, "summon") == 0)
{
std::string name = (const char*)xmlGetProp(summonNode, (const xmlChar *) "name");
- int reqMana = atoi((const char*)xmlGetProp(summonNode, (const xmlChar *) "mana"));
+ int64_t reqMana = atoll((const char*)xmlGetProp(summonNode, (const xmlChar *) "mana"));
then in summons.h:
@@ -31,7 +31,7 @@ class Summons
static SummonMap summons;
public:
static bool Load();
- static int getRequiredMana(std::string name);
+ static int64_t getRequiredMana(std::string name);
};
then in tools.cpp:
@@ -43,16 +43,16 @@ bool fileExists(char* filename)
//////////////////////////////////////////////////
// get a random value between lowest_number and highest_number
-int random_range(int lowest_number, int highest_number)
+int64_t random_range(int64_t lowest_number, int64_t highest_number)
{
if(lowest_number > highest_number){
- int nTmp = highest_number;
+ int64_t nTmp = highest_number;
highest_number = lowest_number;
lowest_number = nTmp;
}
double range = highest_number - lowest_number + 1;
- return lowest_number + int(range * rand()/(RAND_MAX + 1.0));
+ return lowest_number + int64_t(range * rand()/(RAND_MAX + 1.0));
}
@@ -238,46 +238,46 @@ std::string tickstr(int ticks)
return info.str();
}
-std::string str(int value)
+
+std::string str(int32_t value)
{
char buf[64];
#ifdef USING_VISUAL_2005
- if (_itoa_s(value, buf, sizeof(buf), 10) == 0)
+ if (_ltoa_s(value, buf, sizeof(buf), 10) == 0)
return buf;
else
return "";
#else
- return itoa(value, buf, 10);
+ return ltoa(value, buf, 10);
#endif //USING_VISUAL_2005
}
-std::string str(long value)
+std::string str(uint32_t value)
{
char buf[64];
#ifdef USING_VISUAL_2005
- if (_ltoa_s(value, buf, sizeof(buf), 10) == 0)
+ if (_ultoa_s(value, buf, sizeof(buf), 10) == 0)
return buf;
else
return "";
#else
- return ltoa(value, buf, 10);
+ return _ultoa(value, buf, 10);
#endif //USING_VISUAL_2005
}
-std::string str(unsigned long value)
+std::string str(int64_t value)
{
- char buf[64];
+ char buf[128];
#ifdef USING_VISUAL_2005
- if (_ultoa_s(value, buf, sizeof(buf), 10) == 0)
+ if (_i64toa_s(value, buf, sizeof(buf), 10) == 0)
return buf;
else
return "";
#else
- return _ultoa(value, buf, 10);
+ return _i64toa(value, buf, 10);
#endif //USING_VISUAL_2005
}
-
-std::string str(__int64 value)
+std::string str(uint64_t value)
{
char buf[128];
#ifdef USING_VISUAL_2005
@@ -286,6 +286,6 @@ std::string str(__int64 value)
else
return "";
#else
- return _i64toa(value, buf, 10);
+ return _ui64toa(value, buf, 10);
#endif //USING_VISUAL_2005
}
then in tools.h:
@@ -24,7 +24,7 @@
bool fileExists(char* filename);
-int random_range(int lowest_number, int highest_number);
+int64_t random_range(int64_t lowest_number, int64_t highest_number);
@@ -33,9 +33,8 @@ int safe_atoi(const char* str);
double timer();
std::string article(const std::string& name);
std::string tickstr(int ticks);
-std::string str(int value);
-std::string str(long value);
-std::string str(unsigned long value);
-std::string str(__int64 value);
+std::string str(int32_t value);
+std::string str(uint32_t value);
+std::string str(int64_t value);
+std::string str(uint64_t value);
#endif
[/code]
---and finally you're done :D
now enjoy:
Mages: mlvl 396
Paladin: mlvl 114
Knights: mlvl 35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment