From aa0433228a9c791df27504eb1df6a392805193c7 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 21 Sep 2014 20:35:53 +0300 Subject: [PATCH] Fixed cheats - sendMesssage will also pass current object. Workaround-ish but should work. Branch should be fixed now. --- CCallback.cpp | 4 ++-- CCallback.h | 4 ++-- client/widgets/AdventureMapClasses.cpp | 2 +- lib/NetPacks.h | 7 ++++--- server/CGameHandler.cpp | 26 +++++++++++++------------- server/CGameHandler.h | 2 +- server/NetPacksServer.cpp | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) diff --git a/CCallback.cpp b/CCallback.cpp index 15fa6e869..825202162 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -258,10 +258,10 @@ void CCallback::save( const std::string &fname ) } -void CCallback::sendMessage(const std::string &mess) +void CCallback::sendMessage(const std::string &mess, const CGObjectInstance * currentObject) { ASSERT_IF_CALLED_WITH_PLAYER - PlayerMessage pm(*player, mess); + PlayerMessage pm(*player, mess, currentObject? currentObject->id : ObjectInstanceID(-1)); sendRequest(&(CPackForClient&)pm); } diff --git a/CCallback.h b/CCallback.h index dc866ffe6..0ac677be7 100644 --- a/CCallback.h +++ b/CCallback.h @@ -74,7 +74,7 @@ public: virtual void setFormation(const CGHeroInstance * hero, bool tight)=0; virtual void save(const std::string &fname) = 0; - virtual void sendMessage(const std::string &mess) = 0; + virtual void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) = 0; virtual void buildBoat(const IShipyard *obj) = 0; }; @@ -143,7 +143,7 @@ public: void setFormation(const CGHeroInstance * hero, bool tight); void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero); void save(const std::string &fname); - void sendMessage(const std::string &mess); + void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr); void buildBoat(const IShipyard *obj); void dig(const CGObjectInstance *hero); void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1)); diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index 053eedd54..42518788e 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -1168,7 +1168,7 @@ void CInGameConsole::endEnteringText(bool printEnteredText) if(printEnteredText) { std::string txt = enteredText.substr(0, enteredText.size()-1); - LOCPLINT->cb->sendMessage(txt); + LOCPLINT->cb->sendMessage(txt, LOCPLINT->getSelection()); previouslyEntered.push_back(txt); //print(txt); } diff --git a/lib/NetPacks.h b/lib/NetPacks.h index 3ed7ba79c..0dd65e06f 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -2035,8 +2035,8 @@ struct SaveGame : public CPackForClient, public CPackForServer struct PlayerMessage : public CPackForClient, public CPackForServer //513 { PlayerMessage(){CPackForClient::type = 513;}; - PlayerMessage(PlayerColor Player, const std::string &Text) - :player(Player),text(Text) + PlayerMessage(PlayerColor Player, const std::string &Text, ObjectInstanceID obj) + :player(Player),text(Text), currObj(obj) {CPackForClient::type = 513;}; void applyCl(CClient *cl); void applyGs(CGameState *gs){}; @@ -2044,10 +2044,11 @@ struct PlayerMessage : public CPackForClient, public CPackForServer //513 PlayerColor player; std::string text; + ObjectInstanceID currObj; // optional parameter that specifies current object. For cheats :) template void serialize(Handler &h, const int version) { - h & text & player; + h & text & player & currObj; } }; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 803ff033d..19280174e 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3778,18 +3778,18 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) return ok; } -void CGameHandler::playerMessage( PlayerColor player, const std::string &message ) +void CGameHandler::playerMessage( PlayerColor player, const std::string &message, ObjectInstanceID currObj ) { bool cheated=true; - PlayerMessage temp_message(player, message); + PlayerMessage temp_message(player, message, ObjectInstanceID(-1)); // don't inform other client on selected object sendAndApply(&temp_message); if(message == "vcmiistari") //give all spells and 999 mana - {/* + { SetMana sm; ChangeSpells cs; - CGHeroInstance *h = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *h = gs->getHero(currObj); if(!h && complain("Cannot realize cheat, no hero selected!")) return; sm.hid = cs.hid = h->id; @@ -3813,13 +3813,13 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message } else if (message == "vcmiarmenelos") //build all buildings in selected town { - CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *hero = gs->getHero(currObj); CGTownInstance *town; if (hero) town = hero->visitedTown; else - town = gs->getTown(gs->getPlayer(player)->currentSelection); + town = gs->getTown(currObj); if (town) { @@ -3836,7 +3836,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message } else if(message == "vcmiainur") //gives 5 archangels into each slot { - CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *hero = gs->getHero(currObj); const CCreature *archangel = VLC->creh->creatures.at(13); if(!hero) return; @@ -3846,7 +3846,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message } else if(message == "vcmiangband") //gives 10 black knight into each slot { - CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *hero = gs->getHero(currObj); const CCreature *blackKnight = VLC->creh->creatures.at(66); if(!hero) return; @@ -3856,7 +3856,7 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message } else if(message == "vcminoldor") //all war machines { - CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *hero = gs->getHero(currObj); if(!hero) return; if(!hero->getArt(ArtifactPosition::MACH1)) @@ -3868,24 +3868,24 @@ void CGameHandler::playerMessage( PlayerColor player, const std::string &message } else if (message == "vcmiforgeofnoldorking") //hero gets all artifacts except war machines, spell scrolls and spell book { - CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *hero = gs->getHero(currObj); if(!hero) return; for (int g = 7; g < VLC->arth->artifacts.size(); ++g) //including artifacts from mods giveHeroNewArtifact(hero, VLC->arth->artifacts.at(g), ArtifactPosition::PRE_FIRST); } else if(message == "vcmiglorfindel") //selected hero gains a new level { - CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *hero = gs->getHero(currObj); changePrimSkill(hero, PrimarySkill::EXPERIENCE, VLC->heroh->reqExp(hero->level+1) - VLC->heroh->reqExp(hero->level)); } else if(message == "vcminahar") //1000000 movement points { - CGHeroInstance *hero = gs->getHero(gs->getPlayer(player)->currentSelection); + CGHeroInstance *hero = gs->getHero(currObj); if(!hero) return; SetMovePoints smp; smp.hid = hero->id; smp.val = 1000000; - sendAndApply(&smp);*/ + sendAndApply(&smp); } else if(message == "vcmiformenos") //give resources { diff --git a/server/CGameHandler.h b/server/CGameHandler.h index f681dc14d..35c867784 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -198,7 +198,7 @@ public: void handleConnection(std::set players, CConnection &c); PlayerColor getPlayerAt(CConnection *c) const; - void playerMessage( PlayerColor player, const std::string &message); + void playerMessage( PlayerColor player, const std::string &message, ObjectInstanceID currObj); bool makeBattleAction(BattleAction &ba); bool makeAutomaticAction(const CStack *stack, BattleAction &ba); //used when action is taken by stack without volition of player (eg. unguided catapult attack) void handleSpellCasting(SpellID spellID, int spellLvl, BattleHex destination, ui8 casterSide, PlayerColor casterColor, const CGHeroInstance * caster, const CGHeroInstance * secHero, diff --git a/server/NetPacksServer.cpp b/server/NetPacksServer.cpp index 0391b17ac..fa4daf394 100644 --- a/server/NetPacksServer.cpp +++ b/server/NetPacksServer.cpp @@ -285,6 +285,6 @@ bool PlayerMessage::applyGh( CGameHandler *gh ) { ERROR_IF_NOT(player); if(gh->getPlayerAt(c) != player) ERROR_AND_RETURN; - gh->playerMessage(player,text); + gh->playerMessage(player,text, currObj); return true; }