Index: src/game/CharacterHandler.cpp =================================================================== --- src/game/CharacterHandler.cpp (revision 3477) +++ src/game/CharacterHandler.cpp (working copy) @@ -33,7 +33,8 @@ #include "ObjectAccessor.h" #include "Transports.h" #include "Group.h" -#include "../realmd/AuthCodes.h" +#include "../realmd/AuthCodes.h" +#include "ScriptCalls.h" void WorldSession::HandleCharEnumOpcode( WorldPacket & recv_data ) { @@ -547,6 +548,9 @@ SendNotification("GM mode is ON"); m_playerLoading = false; pCurrChar->SendAllowMove(); // may be add it to CMSG_SET_ACTIVE_MOVER handler? + + if (Script) + Script->OnPlayerJoin(pCurrChar); } void WorldSession::HandleSetFactionAtWar( WorldPacket & recv_data ) Index: src/game/ChatHandler.cpp =================================================================== --- src/game/ChatHandler.cpp (revision 3477) +++ src/game/ChatHandler.cpp (working copy) @@ -32,6 +32,15 @@ #include "ObjectAccessor.h" #include "ScriptCalls.h" +extern ScriptsSet Script; + + +bool ParseChatMessageToScript(Player* pl,const char* message ,uint32 type ) +{ + if(!Script) return false; + return Script->OnChatMessage(pl,message, type ); +} + void WorldSession::HandleMessagechatOpcode( WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data,4+4+1); @@ -57,6 +66,7 @@ if (sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHAT) || _player->isGameMaster()) lang = LANG_UNIVERSAL; + switch(type) { case CHAT_MSG_SAY: @@ -66,7 +76,9 @@ std::string msg = ""; recv_data >> msg; - if (sChatHandler.ParseCommands(msg.c_str(), this) > 0) + if( ParseChatMessageToScript( GetPlayer() , msg.c_str() ,type ) ) break; + + if (sChatHandler.ParseCommands(msg.c_str(), this) > 0) break; if(type == CHAT_MSG_SAY) @@ -84,7 +96,7 @@ CHECK_PACKET_SIZE(recv_data,4+4+(to.size()+1)+1); recv_data >> msg; - if(to.size() == 0) + if(to.size() == 0) { WorldPacket data(SMSG_CHAT_PLAYER_NOT_FOUND, (to.size()+1)); data<> msg; + if( ParseChatMessageToScript( GetPlayer() , msg.c_str() ,type ) ) break; + if (sChatHandler.ParseCommands(msg.c_str(), this) > 0) break; @@ -156,6 +170,8 @@ std::string msg = ""; recv_data >> msg; + if( ParseChatMessageToScript( GetPlayer() , msg.c_str() ,type ) ) break; + if (sChatHandler.ParseCommands(msg.c_str(), this) > 0) break; @@ -263,6 +279,7 @@ } } + void WorldSession::HandleTextEmoteOpcode( WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data,4+4+8); Index: src/game/Player.cpp =================================================================== --- src/game/Player.cpp (revision 3477) +++ src/game/Player.cpp (working copy) @@ -46,6 +46,7 @@ #include "Transports.h" #include "Weather.h" #include "BattleGround.h" +#include "ScriptCalls.h" #include @@ -11056,6 +11056,9 @@ // save pet (hunter pet level and experience and all type pets health/mana). if(Pet* pet = GetPet()) pet->SavePetToDB(PET_SAVE_AS_CURRENT); + + if (Script) + Script->OnPlayerSave(this, MS_PLAYERSAVE_FULL); } // fast save function for item/money cheating preventing - save only inventory and money state @@ -11063,6 +11066,9 @@ { _SaveInventory(); SetUInt32ValueInDB(PLAYER_FIELD_COINAGE,GetMoney(),GetGUID()); + + if (Script) + Script->OnPlayerSave(this, MS_PLAYERSAVE_ITEMS_AND_MONEY); } void Player::_SaveActions() Index: src/game/ScriptCalls.cpp =================================================================== --- src/game/ScriptCalls.cpp (revision 3477) +++ src/game/ScriptCalls.cpp (working copy) @@ -23,64 +23,75 @@ #include "Platform/Define.h" #include "ScriptCalls.h" +#include "Player.h" +#include "GameObject.h" +#include "SharedDefines.h" +#include "GossipDef.h" +#include "QuestDef.h" +#include "WorldSession.h" + ScriptsSet Script=NULL; -bool LoadScriptingModule(char const* libName) -{ - ScriptsSet testScript=new _ScriptSet; +extern void ScriptsInit(); +extern void ScriptsFree(); +extern bool GossipHello ( Player * player, Creature *_Creature ); +extern bool GossipSelect( Player *player, Creature *_Creature,uint32 sender, uint32 action ); +extern bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, uint32 action, char* sCode ); +extern bool QuestAccept( Player *player, Creature *_Creature, Quest *_Quest ); +extern bool QuestSelect( Player *player, Creature *_Creature, Quest *_Quest ); +extern bool QuestComplete( Player *player, Creature *_Creature, Quest *_Quest ); +extern bool ChooseReward( Player *player, Creature *_Creature, Quest *_Quest, uint32 opt ); +extern uint32 NPCDialogStatus( Player *player, Creature *_Creature ); +extern bool ItemHello( Player *player, Item *_Item, Quest *_Quest ); +extern bool ItemQuestAccept( Player *player, Item *_Item, Quest *_Quest ); +extern bool GOHello( Player *player, GameObject *_GO ); +extern bool GOQuestAccept( Player *player, GameObject *_GO, Quest *_Quest ); +extern bool GOChooseReward( Player *player, GameObject *_GO, Quest *_Quest, uint32 opt ); +extern bool AreaTrigger( Player *player, Quest *_Quest, uint32 triggerID ); +extern bool ReceiveEmote ( Player * player, Creature *_Creature, uint32 emote_id ); +extern bool OnChatMessage ( Player * player, const char* message, uint32 type ); +extern void OnDeath(Creature* victim , Unit* killer ); +extern void ScriptsUpdate(const time_t& diff); +extern bool OnPlayerSave ( Player *player, uint32 type); +extern bool OnPlayerJoin ( Player *player); - std::string name = strlen(libName) ? libName : MANGOS_SCRIPT_NAME; - name += MANGOS_SCRIPT_EXT; +extern CreatureAI* GetAI(Creature *_Creature ); - testScript->hScriptsLib=MANGOS_LOAD_LIBRARY(name.c_str()); - if(!testScript->hScriptsLib ) - { - printf("Error loading Scripts Library %s !\n",name.c_str()); - delete testScript; - return false; - } - else printf("Scripts Library %s was successfully loaded.\n",name.c_str()); - - if( !(testScript->ScriptsInit =(scriptCallScriptsInit )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsInit" )) - ||!(testScript->ScriptsFree =(scriptCallScriptsFree )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree" )) - ||!(testScript->GossipHello =(scriptCallGossipHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello" )) - ||!(testScript->GOChooseReward =(scriptCallGOChooseReward )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOChooseReward" )) - ||!(testScript->QuestAccept =(scriptCallQuestAccept )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestAccept" )) - ||!(testScript->GossipSelect =(scriptCallGossipSelect )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelect" )) - ||!(testScript->GossipSelectWithCode=(scriptCallGossipSelectWithCode)MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelectWithCode")) - ||!(testScript->QuestSelect =(scriptCallQuestSelect )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestSelect" )) - ||!(testScript->QuestComplete =(scriptCallQuestComplete )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"QuestComplete" )) - ||!(testScript->NPCDialogStatus =(scriptCallNPCDialogStatus )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"NPCDialogStatus" )) - ||!(testScript->ChooseReward =(scriptCallChooseReward )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ChooseReward" )) - ||!(testScript->ItemHello =(scriptCallItemHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ItemHello" )) - ||!(testScript->GOHello =(scriptCallGOHello )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOHello" )) - ||!(testScript->scriptAreaTrigger =(scriptCallAreaTrigger )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"AreaTrigger" )) - ||!(testScript->ItemQuestAccept =(scriptCallItemQuestAccept )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ItemQuestAccept" )) - ||!(testScript->GOQuestAccept =(scriptCallGOQuestAccept )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GOQuestAccept" )) - ||!(testScript->ReceiveEmote =(scriptCallReceiveEmote )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"ReceiveEmote" )) - ||!(testScript->GetAI =(scriptCallGetAI )MANGOS_GET_PROC_ADDR(testScript->hScriptsLib,"GetAI" )) - ) - { - MANGOS_CLOSE_LIBRARY(testScript->hScriptsLib); - delete testScript; - return false; - } - - //heh we are still there :P we have a valid library - //we reload script +bool LoadScriptingModule(char const* libName) +{ if(Script) { - ScriptsSet current =Script; - //todo: some check if some func from script library is called right now - Script=testScript; - current->ScriptsFree(); - MANGOS_CLOSE_LIBRARY(current->hScriptsLib); - delete current; - }else - Script=testScript; + Script->ScriptsFree(); + Script->ScriptsInit(); + return true; + } + + Script=new _ScriptSet; + Script->ScriptsInit =(scriptCallScriptsInit)&ScriptsInit; + Script->ScriptsFree =(scriptCallScriptsFree )&ScriptsFree; + Script->GossipHello =(scriptCallGossipHello)&GossipHello; + Script->GOChooseReward =(scriptCallGOChooseReward )&GOChooseReward; + Script->QuestAccept =(scriptCallQuestAccept )&QuestAccept; + Script->GossipSelect =(scriptCallGossipSelect)&GossipSelect; + Script->GossipSelectWithCode=(scriptCallGossipSelectWithCode)&GossipSelectWithCode; + Script->QuestSelect =(scriptCallQuestSelect)&QuestSelect; + Script->QuestComplete =(scriptCallQuestComplete)&QuestComplete; + Script->NPCDialogStatus =(scriptCallNPCDialogStatus)&NPCDialogStatus; + Script->ChooseReward =(scriptCallChooseReward)&ChooseReward; + Script->ItemHello =(scriptCallItemHello)&ItemHello; + Script->GOHello =(scriptCallGOHello)&GOHello; + Script->scriptAreaTrigger =(scriptCallAreaTrigger)&AreaTrigger; + Script->ItemQuestAccept =(scriptCallItemQuestAccept)&ItemQuestAccept; + Script->GOQuestAccept =(scriptCallGOQuestAccept)&GOQuestAccept; + Script->GetAI =(scriptCallGetAI)&GetAI; + Script->ReceiveEmote =(scriptCallReceiveEmote)&ReceiveEmote; + Script->OnChatMessage =(scriptCallOnChatMessage)&OnChatMessage; + Script->OnDeath =(scriptCallOnDeath)&OnDeath; + Script->ScriptsUpdate =(scriptCallScriptsUpdate)&ScriptsUpdate; + Script->OnPlayerSave =(scriptCallOnPlayerSave)&OnPlayerSave; + Script->OnPlayerJoin =(scriptCallOnPlayerJoin)&OnPlayerJoin; - Script->ScriptsInit(); - + Script->ScriptsInit(); return true; } Index: src/game/ScriptCalls.h =================================================================== --- src/game/ScriptCalls.h (revision 3477) +++ src/game/ScriptCalls.h (working copy) @@ -22,6 +22,19 @@ #include "GossipDef.h" #include "Player.h" +#define MANGOSCRIPT_PATCH_NPC_ON_EMOTE +#define MANGOSCRIPT_PATCH_CUSTOM_CHAT +#define MANGOSCRIPT_BUILD_PATCH_APPLYED + +// enums + +// For MangoScript OnPlayerSave +enum MS_PlayerSave +{ + MS_PLAYERSAVE_FULL = 0, + MS_PLAYERSAVE_ITEMS_AND_MONEY = 1 +}; + bool LoadScriptingModule(char const* libName = ""); typedef void(MANGOS_IMPORT * scriptCallScriptsInit) (); @@ -42,8 +55,16 @@ typedef bool(MANGOS_IMPORT * scriptCallGOQuestAccept)(Player *player, GameObject *, Quest *); typedef bool(MANGOS_IMPORT * scriptCallGOChooseReward)(Player *player, GameObject *, Quest *, uint32 opt ); typedef bool(MANGOS_IMPORT * scriptCallReceiveEmote) ( Player *player, Creature *_Creature, uint32 emote ); +typedef void(MANGOS_IMPORT * scriptCallScriptsUpdate) ( const time_t& diff ); +typedef bool(MANGOS_IMPORT * scriptCallOnPlayerSave) ( Player *player, uint32 type ); +typedef bool(MANGOS_IMPORT * scriptCallOnPlayerJoin) ( Player *player ); typedef CreatureAI* (MANGOS_IMPORT * scriptCallGetAI) ( Creature *_Creature ); +// Called on every CHAT_* chat message (see ChatHandler.cpp to see what types are triggered) +typedef bool(MANGOS_IMPORT * scriptCallOnChatMessage )(Player *player , const char* message ,uint32 type ); //return ttue to stop the message from being displayed +typedef void(MANGOS_IMPORT * scriptCallOnDeath )(Creature* victim , Unit* killer ); + + typedef struct { scriptCallScriptsInit ScriptsInit; @@ -65,6 +86,11 @@ scriptCallGOQuestAccept GOQuestAccept; scriptCallReceiveEmote ReceiveEmote; scriptCallGetAI GetAI; + scriptCallOnChatMessage OnChatMessage; + scriptCallOnDeath OnDeath; + scriptCallScriptsUpdate ScriptsUpdate; + scriptCallOnPlayerSave OnPlayerSave; + scriptCallOnPlayerJoin OnPlayerJoin; MANGOS_LIBRARY_HANDLE hScriptsLib; }_ScriptSet,*ScriptsSet; Index: src/game/Unit.cpp =================================================================== --- src/game/Unit.cpp (revision 3477) +++ src/game/Unit.cpp (working copy) @@ -38,6 +38,7 @@ #include "Util.h" #include "Totem.h" #include "TemporarySummon.h" +#include "ScriptCalls.h" #include @@ -492,6 +493,10 @@ he->DuelComplete(0); } + + if(pVictim->GetTypeId() == TYPEID_UNIT) + Script->OnDeath( (Creature*)pVictim, this); + } else // if (health <= damage) { Index: src/game/World.cpp =================================================================== --- src/game/World.cpp (revision 3477) +++ src/game/World.cpp (working copy) @@ -647,7 +647,7 @@ if (!scriptSchedule.empty()) ScriptsProcess(); - sBattleGroundMgr.Update(diff); + Script->ScriptsUpdate(diff); } ///