From 05436e135af2765e7044899ab0a731fe68ac7519 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Mon, 30 Jul 2012 05:51:03 -0300 Subject: [PATCH] Fix some bugs --- modules/game_interface/gameinterface.lua | 2 +- modules/game_interface/widgets/uiitem.lua | 3 +++ src/framework/graphics/texture.cpp | 1 - src/framework/graphics/texturemanager.cpp | 7 +++++-- src/otclient/game.cpp | 6 ++++++ src/otclient/game.h | 6 ++---- src/otclient/item.cpp | 14 ++++++++++++++ src/otclient/item.h | 4 ++-- src/otclient/uiitem.cpp | 2 +- 9 files changed, 34 insertions(+), 11 deletions(-) diff --git a/modules/game_interface/gameinterface.lua b/modules/game_interface/gameinterface.lua index 7a243ada..755217ec 100644 --- a/modules/game_interface/gameinterface.lua +++ b/modules/game_interface/gameinterface.lua @@ -395,7 +395,7 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton and not g_mouse.isPressed(MouseLeftButton) then local player = g_game.getLocalPlayer() if multiUseThing:isCreature() and multiUseThing:isCreature() ~= player then - g_game.attack(multiUseThing:isCreature()) + g_game.attack(multiUseThing) return true elseif multiUseThing:isContainer() then if multiUseThing:getParentContainer() then diff --git a/modules/game_interface/widgets/uiitem.lua b/modules/game_interface/widgets/uiitem.lua index a8a66e38..410ad832 100644 --- a/modules/game_interface/widgets/uiitem.lua +++ b/modules/game_interface/widgets/uiitem.lua @@ -24,12 +24,15 @@ function UIItem:onDrop(widget, mousePos) if not widget or not widget.currentDragThing then return false end local item = widget.currentDragThing + if not item:isItem() then return false end + local toPos = self.position local itemPos = item:getPosition() if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end if item:getCount() > 1 then + g_game.look(item) modules.game_interface.moveStackableItem(item, toPos) else g_game.move(item, toPos, 1) diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index edfe711f..2c3f774e 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -79,7 +79,6 @@ Texture::Texture(const ImagePtr& image, bool buildMipmaps) Texture::~Texture() { - assert(!g_app.isTerminated()); // free texture from gl memory if(g_graphics.ok() && m_id != 0) glDeleteTextures(1, &m_id); diff --git a/src/framework/graphics/texturemanager.cpp b/src/framework/graphics/texturemanager.cpp index 6f35be54..7d5545be 100644 --- a/src/framework/graphics/texturemanager.cpp +++ b/src/framework/graphics/texturemanager.cpp @@ -40,9 +40,12 @@ void TextureManager::terminate() #ifndef NDEBUG // check for leaks int refs = 0; - for(const auto& it : m_textures) - if(it.second->ref_count() > 1) + for(const auto& it : m_textures) { + if(it.second->ref_count() > 1) { refs++; + g_logger.debug(stdext::format("texture reference released: %s", it.first)); + } + } if(refs > 0) g_logger.debug(stdext::format("%d textures references left", refs)); #endif diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index 9e54d9a8..bc9123d3 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -42,6 +42,12 @@ Game::Game() m_protocolVersion = 0; } +void Game::terminate() +{ + resetGameStates(); + m_protocolGame = nullptr; +} + void Game::resetGameStates() { m_online = false; diff --git a/src/otclient/game.h b/src/otclient/game.h index 7b143c67..71490093 100644 --- a/src/otclient/game.h +++ b/src/otclient/game.h @@ -42,6 +42,8 @@ class Game public: Game(); + void terminate(); + private: void resetGameStates(); @@ -241,9 +243,6 @@ public: void setClientVersion(int version); int getClientVersion() { return m_protocolVersion; } - void setRSA(const std::string& rsa); - std::string getRSA() { return m_rsa; } - bool canPerformGameAction(); bool checkBotProtection(); @@ -298,7 +297,6 @@ private: std::string m_worldName; std::bitset m_features; int m_protocolVersion; - std::string m_rsa; }; extern Game g_game; diff --git a/src/otclient/item.cpp b/src/otclient/item.cpp index 2f2dae6f..b8cf4c60 100644 --- a/src/otclient/item.cpp +++ b/src/otclient/item.cpp @@ -298,6 +298,20 @@ void Item::serializeItem(const BinaryTreePtr& out) } } +int Item::getSubType() +{ + if(isSplash() || isFluidContainer()) + return m_countOrSubType; + return 1; +} + +int Item::getCount() +{ + if(isStackable()) + return m_countOrSubType; + return 1; +} + bool Item::isMoveable() { return !rawGetThingType()->isNotMoveable(); diff --git a/src/otclient/item.h b/src/otclient/item.h index cf879a0f..991a7fa2 100644 --- a/src/otclient/item.h +++ b/src/otclient/item.h @@ -90,8 +90,8 @@ public: void setSubType(int subType) { m_countOrSubType = subType; } int getCountOrSubType() { return m_countOrSubType; } - int getSubType() { return m_countOrSubType; } - int getCount() { return m_countOrSubType; } + int getSubType(); + int getCount(); uint32 getId() { return m_id; } bool isValid(); diff --git a/src/otclient/uiitem.cpp b/src/otclient/uiitem.cpp index 8bffc38a..4abdb97c 100644 --- a/src/otclient/uiitem.cpp +++ b/src/otclient/uiitem.cpp @@ -58,7 +58,7 @@ void UIItem::drawSelf(Fw::DrawPane drawPane) g_painter->setColor(Color::white); m_item->draw(dest, scaleFactor, true); - if(m_font && (m_item->isStackable() || m_item->isChargeable()) && m_item->getCount() > 1) { + if(m_font && (m_item->isStackable() || m_item->isChargeable()) && m_item->getCountOrSubType() > 1) { std::string count = stdext::to_string(m_item->getCount()); g_painter->setColor(Color(231, 231, 231)); m_font->drawText(count, Rect(m_rect.topLeft(), m_rect.bottomRight() - Point(3, 0)), Fw::AlignBottomRight);