From 0d323563e4cc507e58ce1bb3ba632cf2310602c9 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 18 Aug 2013 13:26:37 +0200 Subject: Added cWindow property manipulation API. Now enchantment table and furnace properties can be set by a plugin --- source/Bindings.cpp | 71 +++++++++++++++++++++++++++++++++- source/Bindings.h | 2 +- source/BlockEntities/FurnaceEntity.cpp | 2 +- source/ClientHandle.cpp | 34 ++++++++-------- source/ClientHandle.h | 2 +- source/Protocol/Protocol.h | 2 +- source/Protocol/Protocol125.cpp | 30 +++++++------- source/Protocol/Protocol125.h | 2 +- source/Protocol/ProtocolRecognizer.cpp | 4 +- source/Protocol/ProtocolRecognizer.h | 2 +- source/UI/Window.cpp | 26 ++++++++++++- source/UI/Window.h | 10 ++++- 12 files changed, 142 insertions(+), 45 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 6a5ff3e32..d33be08ac 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 08/18/13 10:47:30. +** Generated automatically by tolua++-1.0.92 on 08/18/13 13:15:34. */ #ifndef __cplusplus @@ -26657,6 +26657,73 @@ static int tolua_AllToLua_cWindow_SetWindowTitle00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: SetProperty of class cWindow */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cWindow_SetProperty00 +static int tolua_AllToLua_cWindow_SetProperty00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cWindow",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cWindow* self = (cWindow*) tolua_tousertype(tolua_S,1,0); + int a_Property = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Value = ((int) tolua_tonumber(tolua_S,3,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetProperty'", NULL); +#endif + { + self->SetProperty(a_Property,a_Value); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetProperty'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetProperty of class cWindow */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cWindow_SetProperty01 +static int tolua_AllToLua_cWindow_SetProperty01(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cWindow",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,0,&tolua_err) || + (tolua_isvaluenil(tolua_S,4,&tolua_err) || !tolua_isusertype(tolua_S,4,"cPlayer",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + cWindow* self = (cWindow*) tolua_tousertype(tolua_S,1,0); + int a_Property = ((int) tolua_tonumber(tolua_S,2,0)); + int a_Value = ((int) tolua_tonumber(tolua_S,3,0)); + cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,4,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetProperty'", NULL); +#endif + { + self->SetProperty(a_Property,a_Value,*a_Player); + } + } + return 0; +tolua_lerror: + return tolua_AllToLua_cWindow_SetProperty00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + /* method: new of class cLuaWindow */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaWindow_new00 static int tolua_AllToLua_cLuaWindow_new00(lua_State* tolua_S) @@ -28610,6 +28677,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"IsSlotInPlayerInventory",tolua_AllToLua_cWindow_IsSlotInPlayerInventory00); tolua_function(tolua_S,"GetWindowTitle",tolua_AllToLua_cWindow_GetWindowTitle00); tolua_function(tolua_S,"SetWindowTitle",tolua_AllToLua_cWindow_SetWindowTitle00); + tolua_function(tolua_S,"SetProperty",tolua_AllToLua_cWindow_SetProperty00); + tolua_function(tolua_S,"SetProperty",tolua_AllToLua_cWindow_SetProperty01); tolua_endmodule(tolua_S); #ifdef __cplusplus tolua_cclass(tolua_S,"cLuaWindow","cLuaWindow","cWindow",tolua_collect_cLuaWindow); diff --git a/source/Bindings.h b/source/Bindings.h index 55baed803..a403294a9 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 08/18/13 10:47:31. +** Generated automatically by tolua++-1.0.92 on 08/18/13 13:15:34. */ /* Exported function */ diff --git a/source/BlockEntities/FurnaceEntity.cpp b/source/BlockEntities/FurnaceEntity.cpp index e1b6fc47b..6cac8573d 100644 --- a/source/BlockEntities/FurnaceEntity.cpp +++ b/source/BlockEntities/FurnaceEntity.cpp @@ -220,7 +220,7 @@ void cFurnaceEntity::BroadcastProgress(int a_ProgressbarID, short a_Value) cWindow * Window = GetWindow(); if (Window != NULL) { - Window->BroadcastInventoryProgress(a_ProgressbarID, a_Value); + Window->BroadcastProgress(a_ProgressbarID, a_Value); } } diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index dce2bbd25..4372d052c 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1718,15 +1718,6 @@ void cClientHandle::SendHealth(void) -void cClientHandle::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value) -{ - m_Protocol->SendInventoryProgress(a_WindowID, a_ProgressBar, a_Value); -} - - - - - void cClientHandle::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { m_Protocol->SendInventorySlot(a_WindowID, a_SlotNum, a_Item); @@ -1954,36 +1945,45 @@ void cClientHandle::SendWeather(eWeather a_Weather) -void cClientHandle::SendWindowClose(const cWindow & a_Window) +void cClientHandle::SendWholeInventory(const cInventory & a_Inventory) { - m_Protocol->SendWindowClose(a_Window); + m_Protocol->SendWholeInventory(a_Inventory); } -void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) +void cClientHandle::SendWholeInventory(const cWindow & a_Window) { - m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots); + m_Protocol->SendWholeInventory(a_Window); } -void cClientHandle::SendWholeInventory(const cInventory & a_Inventory) +void cClientHandle::SendWindowClose(const cWindow & a_Window) { - m_Protocol->SendWholeInventory(a_Inventory); + m_Protocol->SendWindowClose(a_Window); } -void cClientHandle::SendWholeInventory(const cWindow & a_Window) +void cClientHandle::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) { - m_Protocol->SendWholeInventory(a_Window); + m_Protocol->SendWindowOpen(a_WindowID, a_WindowType, a_WindowTitle, a_NumSlots); +} + + + + + +void cClientHandle::SendWindowProperty(const cWindow & a_Window, int a_Property, int a_Value) +{ + m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value); } diff --git a/source/ClientHandle.h b/source/ClientHandle.h index 9454b9b7a..c85257df1 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -111,7 +111,6 @@ public: void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion); void SendGameMode (eGameMode a_GameMode); void SendHealth (void); - void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value); void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item); void SendPickupSpawn (const cPickup & a_Pickup); void SendPlayerAnimation (const cPlayer & a_Player, char a_Animation); @@ -139,6 +138,7 @@ public: void SendWholeInventory (const cWindow & a_Window); void SendWindowClose (const cWindow & a_Window); void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots); + void SendWindowProperty (const cWindow & a_Window, int a_Property, int a_Value); const AString & GetUsername(void) const; // tolua_export void SetUsername( const AString & a_Username ); // tolua_export diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 5c46b2726..0953071b1 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -73,7 +73,6 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) = 0; virtual void SendGameMode (eGameMode a_GameMode) = 0; virtual void SendHealth (void) = 0; - virtual void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value) = 0; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) = 0; virtual void SendKeepAlive (int a_PingID) = 0; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) = 0; @@ -103,6 +102,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) = 0; virtual void SendWindowClose (const cWindow & a_Window) = 0; virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) = 0; + virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) = 0; /// Returns the ServerID used for authentication through session.minecraft.net virtual AString GetAuthServerID(void) = 0; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index e481bb9a7..6f79ed12c 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -82,7 +82,7 @@ enum PACKET_WINDOW_CLICK = 0x66, PACKET_INVENTORY_SLOT = 0x67, PACKET_INVENTORY_WHOLE = 0x68, - PACKET_INVENTORY_PROGRESS = 0x69, + PACKET_WINDOW_PROPERTY = 0x69, PACKET_CREATIVE_INVENTORY_ACTION = 0x6B, PACKET_UPDATE_SIGN = 0x82, PACKET_PLAYER_LIST_ITEM = 0xC9, @@ -491,20 +491,6 @@ void cProtocol125::SendHealth(void) -void cProtocol125::SendInventoryProgress(char a_WindowID, short a_ProgressBar, short a_Value) -{ - cCSLock Lock(m_CSPacket); - WriteByte (PACKET_INVENTORY_PROGRESS); - WriteByte (a_WindowID); - WriteShort(a_ProgressBar); - WriteShort(a_Value); - Flush(); -} - - - - - void cProtocol125::SendInventorySlot(char a_WindowID, short a_SlotNum, const cItem & a_Item) { cCSLock Lock(m_CSPacket); @@ -975,6 +961,20 @@ void cProtocol125::SendWindowOpen(char a_WindowID, char a_WindowType, const AStr +void cProtocol125::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) +{ + cCSLock Lock(m_CSPacket); + WriteByte (PACKET_WINDOW_PROPERTY); + WriteByte (a_Window.GetWindowID()); + WriteShort(a_Property); + WriteShort(a_Value); + Flush(); +} + + + + + AString cProtocol125::GetAuthServerID(void) { // http://wiki.vg/wiki/index.php?title=Session&oldid=2262 diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index ee8fd94eb..ec6e12a0d 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -50,7 +50,6 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; - virtual void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -80,6 +79,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; + virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; virtual AString GetAuthServerID(void) override; diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index 35c8fe993..ef2ed91f6 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -332,10 +332,10 @@ void cProtocolRecognizer::SendHealth(void) -void cProtocolRecognizer::SendInventoryProgress(char a_WindowID, short a_Progressbar, short a_Value) +void cProtocolRecognizer::SendWindowProperty(const cWindow & a_Window, short a_Property, short a_Value) { ASSERT(m_Protocol != NULL); - m_Protocol->SendInventoryProgress(a_WindowID, a_Progressbar, a_Value); + m_Protocol->SendWindowProperty(a_Window, a_Property, a_Value); } diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index 43d4a15e2..94bbb184f 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -80,7 +80,6 @@ public: virtual void SendExplosion (double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) override; virtual void SendGameMode (eGameMode a_GameMode) override; virtual void SendHealth (void) override; - virtual void SendInventoryProgress (char a_WindowID, short a_Progressbar, short a_Value) override; virtual void SendInventorySlot (char a_WindowID, short a_SlotNum, const cItem & a_Item) override; virtual void SendKeepAlive (int a_PingID) override; virtual void SendLogin (const cPlayer & a_Player, const cWorld & a_World) override; @@ -110,6 +109,7 @@ public: virtual void SendWholeInventory (const cWindow & a_Window) override; virtual void SendWindowClose (const cWindow & a_Window) override; virtual void SendWindowOpen (char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) override; + virtual void SendWindowProperty (const cWindow & a_Window, short a_Property, short a_Value) override; virtual AString GetAuthServerID(void) override; diff --git a/source/UI/Window.cpp b/source/UI/Window.cpp index 415ce08ff..786ae6ed1 100644 --- a/source/UI/Window.cpp +++ b/source/UI/Window.cpp @@ -664,12 +664,12 @@ void cWindow::BroadcastWholeWindow(void) -void cWindow::BroadcastInventoryProgress(short a_Progressbar, short a_Value) +void cWindow::BroadcastProgress(int a_Progressbar, int a_Value) { cCSLock Lock(m_CS); for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr) { - (*itr)->GetClientHandle()->SendInventoryProgress(m_WindowID, a_Progressbar, a_Value); + (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Progressbar, a_Value); } // for itr - m_OpenedBy[] } @@ -677,6 +677,28 @@ void cWindow::BroadcastInventoryProgress(short a_Progressbar, short a_Value) +void cWindow::SetProperty(int a_Property, int a_Value) +{ + cCSLock Lock(m_CS); + for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) + { + (*itr)->GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); + } // for itr - m_OpenedBy[] +} + + + + + +void cWindow::SetProperty(int a_Property, int a_Value, cPlayer & a_Player) +{ + a_Player.GetClientHandle()->SendWindowProperty(*this, a_Property, a_Value); +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cInventoryWindow: diff --git a/source/UI/Window.h b/source/UI/Window.h index 0be43e819..aa7e9d0d0 100644 --- a/source/UI/Window.h +++ b/source/UI/Window.h @@ -120,14 +120,20 @@ public: /// Sends the contents of the whole window to all clients of this window. void BroadcastWholeWindow(void); - /// Sends the progressbar to all clients of this window - void BroadcastInventoryProgress(short a_Progressbar, short a_Value); + /// Sends the progressbar to all clients of this window (same as SetProperty) + void BroadcastProgress(int a_Progressbar, int a_Value); // tolua_begin const AString & GetWindowTitle() const { return m_WindowTitle; } void SetWindowTitle(const AString & a_WindowTitle ) { m_WindowTitle = a_WindowTitle; } + /// Sends the UpdateWindowProperty (0x69) packet to all clients of the window + void SetProperty(int a_Property, int a_Value); + + /// Sends the UpdateWindowPropert(0x69) packet to the specified player + void SetProperty(int a_Property, int a_Value, cPlayer & a_Player); + // tolua_end void OwnerDestroyed(void); -- cgit v1.2.3