Просмотр исходного кода

Fixed cheats - sendMesssage will also pass current object.

Workaround-ish but should work. Branch should be fixed now.
Ivan Savenko 11 лет назад
Родитель
Сommit
aa0433228a

+ 2 - 2
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);
 }
 

+ 2 - 2
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));

+ 1 - 1
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);
 	}

+ 4 - 3
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 <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & text & player;
+		h & text & player & currObj;
 	}
 };
 

+ 13 - 13
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
 	{

+ 1 - 1
server/CGameHandler.h

@@ -198,7 +198,7 @@ public:
 	void handleConnection(std::set<PlayerColor> 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,

+ 1 - 1
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;
 }