/src/game/ScriptCalls.cpp

https://github.com/xiaofeng2009/TC2 · C++ · 127 lines · 90 code · 15 blank · 22 comment · 3 complexity · 14e63f228225503bfc9dc553a7e82dac MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  3. *
  4. * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef WIN32
  21. #include <dlfcn.h>
  22. #endif
  23. #include "Common.h"
  24. #include "Platform/Define.h"
  25. #include "ScriptCalls.h"
  26. #include "World.h"
  27. #include "Config/ConfigEnv.h"
  28. ScriptsSet Script=NULL;
  29. void UnloadScriptingModule()
  30. {
  31. if(Script)
  32. {
  33. //todo: some check if some func from script library is called right now
  34. Script->ScriptsFree();
  35. TRINITY_CLOSE_LIBRARY(Script->hScriptsLib);
  36. delete Script;
  37. Script = NULL;
  38. }
  39. }
  40. bool LoadScriptingModule(char const* libName)
  41. {
  42. ScriptsSet testScript=new _ScriptSet;
  43. std::string name = strlen(libName) ? libName : TRINITY_SCRIPT_NAME;
  44. name += TRINITY_SCRIPT_EXT;
  45. testScript->hScriptsLib=TRINITY_LOAD_LIBRARY(name.c_str());
  46. if(!testScript->hScriptsLib )
  47. {
  48. printf("Error loading Scripts Library %s !\n",name.c_str());
  49. delete testScript;
  50. return false;
  51. }
  52. if( !(testScript->ScriptsInit =(scriptCallScriptsInit )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsInit" ))
  53. ||!(testScript->OnLogin =(scriptCallOnLogin )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnLogin" ))
  54. ||!(testScript->OnLogout =(scriptCallOnLogout )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnLogout" ))
  55. ||!(testScript->OnPVPKill =(scriptCallOnPVPKill )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnPVPKill" ))
  56. ||!(testScript->OnLogin =(scriptCallOnLogin )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnLogin" ))
  57. ||!(testScript->OnLogout =(scriptCallOnLogout )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnLogout" ))
  58. ||!(testScript->OnPVPKill =(scriptCallOnPVPKill )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnPVPKill" ))
  59. ||!(testScript->OnSpellCast =(scriptCallOnSpellCast )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnSpellCast" ))
  60. ||!(testScript->OnGetXP =(scriptCallOnGetXP )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnGetXP" ))
  61. ||!(testScript->OnGetMoney =(scriptCallOnGetMoney )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnGetMoney" ))
  62. ||!(testScript->OnPlayerChat =(scriptCallOnPlayerChat )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnPlayerChat" ))
  63. ||!(testScript->OnServerStartup =(scriptCallOnServerStartup )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnServerStartup" ))
  64. ||!(testScript->OnServerShutdown =(scriptCallOnServerShutdown )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnServerShutdown" ))
  65. ||!(testScript->OnAreaChange =(scriptCallOnAreaChange )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnAreaChange" ))
  66. ||!(testScript->OnItemClick =(scriptCallOnItemClick )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnItemClick" ))
  67. ||!(testScript->OnItemOpen =(scriptCallOnItemOpen )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnItemOpen" ))
  68. ||!(testScript->OnGoClick =(scriptCallOnGoClick )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnGoClick" ))
  69. ||!(testScript->OnCreatureKill =(scriptCallOnCreatureKill )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnCreatureKill" ))
  70. ||!(testScript->ScriptsFree =(scriptCallScriptsFree )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree" ))
  71. ||!(testScript->ScriptsVersion =(scriptCallScriptsVersion )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsVersion" ))
  72. ||!(testScript->GossipHello =(scriptCallGossipHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello" ))
  73. ||!(testScript->GOChooseReward =(scriptCallGOChooseReward )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOChooseReward" ))
  74. ||!(testScript->QuestAccept =(scriptCallQuestAccept )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"QuestAccept" ))
  75. ||!(testScript->GossipSelect =(scriptCallGossipSelect )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelect" ))
  76. ||!(testScript->GossipSelectWithCode=(scriptCallGossipSelectWithCode)TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelectWithCode"))
  77. ||!(testScript->GOSelect =(scriptCallGOSelect )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOSelect" ))
  78. ||!(testScript->GOSelectWithCode =(scriptCallGOSelectWithCode )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOSelectWithCode" ))
  79. ||!(testScript->QuestSelect =(scriptCallQuestSelect )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"QuestSelect" ))
  80. ||!(testScript->QuestComplete =(scriptCallQuestComplete )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"QuestComplete" ))
  81. ||!(testScript->NPCDialogStatus =(scriptCallNPCDialogStatus )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"NPCDialogStatus" ))
  82. ||!(testScript->GODialogStatus =(scriptCallGODialogStatus )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GODialogStatus" ))
  83. ||!(testScript->ChooseReward =(scriptCallChooseReward )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ChooseReward" ))
  84. ||!(testScript->ItemHello =(scriptCallItemHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ItemHello" ))
  85. ||!(testScript->GOHello =(scriptCallGOHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOHello" ))
  86. ||!(testScript->scriptAreaTrigger =(scriptCallAreaTrigger )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"AreaTrigger" ))
  87. ||!(testScript->ItemQuestAccept =(scriptCallItemQuestAccept )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ItemQuestAccept" ))
  88. ||!(testScript->GOQuestAccept =(scriptCallGOQuestAccept )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOQuestAccept" ))
  89. ||!(testScript->ItemUse =(scriptCallItemUse )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ItemUse" ))
  90. ||!(testScript->ItemExpire =(scriptCallItemExpire )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ItemExpire" ))
  91. ||!(testScript->EffectDummyGameObj =(scriptCallEffectDummyGameObj )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"EffectDummyGameObj" ))
  92. ||!(testScript->EffectDummyCreature =(scriptCallEffectDummyCreature )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"EffectDummyCreature" ))
  93. ||!(testScript->EffectDummyItem =(scriptCallEffectDummyItem )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"EffectDummyItem" ))
  94. ||!(testScript->GetAI =(scriptCallGetAI )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GetAI" ))
  95. ||!(testScript->CreateInstanceData =(scriptCallCreateInstanceData )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"CreateInstanceData" ))
  96. )
  97. {
  98. printf("Error loading Scripts Library %s !\n Library missing required functions.",name.c_str());
  99. TRINITY_CLOSE_LIBRARY(testScript->hScriptsLib);
  100. delete testScript;
  101. return false;
  102. }
  103. sLog.outString();
  104. sLog.outString( ">>> Scripts Library %s was successfully loaded.\n", name.c_str() );
  105. //heh we are still there :P we have a valid library
  106. //we reload script
  107. UnloadScriptingModule();
  108. Script=testScript;
  109. Script->ScriptsInit(sConfig.GetFilename().c_str());
  110. sWorld.SetScriptsVersion(Script->ScriptsVersion());
  111. return true;
  112. }