[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 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 |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 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 |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
| 21 | #ifndef WIN32 |
---|
| 22 | #include <dlfcn.h> |
---|
| 23 | #endif |
---|
| 24 | |
---|
| 25 | #include "Platform/Define.h" |
---|
| 26 | #include "ScriptCalls.h" |
---|
[149] | 27 | #include "World.h" |
---|
[2] | 28 | |
---|
| 29 | ScriptsSet Script=NULL; |
---|
| 30 | |
---|
| 31 | void UnloadScriptingModule() |
---|
| 32 | { |
---|
| 33 | if(Script) |
---|
| 34 | { |
---|
| 35 | //todo: some check if some func from script library is called right now |
---|
| 36 | Script->ScriptsFree(); |
---|
[44] | 37 | TRINITY_CLOSE_LIBRARY(Script->hScriptsLib); |
---|
[2] | 38 | delete Script; |
---|
| 39 | Script = NULL; |
---|
| 40 | } |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | bool LoadScriptingModule(char const* libName) |
---|
| 44 | { |
---|
| 45 | ScriptsSet testScript=new _ScriptSet; |
---|
| 46 | |
---|
[44] | 47 | std::string name = strlen(libName) ? libName : TRINITY_SCRIPT_NAME; |
---|
| 48 | name += TRINITY_SCRIPT_EXT; |
---|
[2] | 49 | |
---|
[44] | 50 | testScript->hScriptsLib=TRINITY_LOAD_LIBRARY(name.c_str()); |
---|
[2] | 51 | |
---|
| 52 | if(!testScript->hScriptsLib ) |
---|
| 53 | { |
---|
| 54 | printf("Error loading Scripts Library %s !\n",name.c_str()); |
---|
| 55 | delete testScript; |
---|
| 56 | return false; |
---|
| 57 | } |
---|
| 58 | |
---|
[44] | 59 | if( !(testScript->ScriptsInit =(scriptCallScriptsInit )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsInit" )) |
---|
| 60 | ||!(testScript->ScriptsFree =(scriptCallScriptsFree )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree" )) |
---|
[149] | 61 | ||!(testScript->ScriptsVersion =(scriptCallScriptsVersion )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsVersion" )) |
---|
[44] | 62 | ||!(testScript->GossipHello =(scriptCallGossipHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello" )) |
---|
| 63 | ||!(testScript->GOChooseReward =(scriptCallGOChooseReward )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOChooseReward" )) |
---|
| 64 | ||!(testScript->QuestAccept =(scriptCallQuestAccept )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"QuestAccept" )) |
---|
| 65 | ||!(testScript->GossipSelect =(scriptCallGossipSelect )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelect" )) |
---|
| 66 | ||!(testScript->GossipSelectWithCode=(scriptCallGossipSelectWithCode)TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipSelectWithCode")) |
---|
| 67 | ||!(testScript->QuestSelect =(scriptCallQuestSelect )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"QuestSelect" )) |
---|
| 68 | ||!(testScript->QuestComplete =(scriptCallQuestComplete )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"QuestComplete" )) |
---|
| 69 | ||!(testScript->NPCDialogStatus =(scriptCallNPCDialogStatus )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"NPCDialogStatus" )) |
---|
| 70 | ||!(testScript->GODialogStatus =(scriptCallGODialogStatus )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GODialogStatus" )) |
---|
| 71 | ||!(testScript->ChooseReward =(scriptCallChooseReward )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ChooseReward" )) |
---|
| 72 | ||!(testScript->ItemHello =(scriptCallItemHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ItemHello" )) |
---|
| 73 | ||!(testScript->GOHello =(scriptCallGOHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOHello" )) |
---|
| 74 | ||!(testScript->scriptAreaTrigger =(scriptCallAreaTrigger )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"AreaTrigger" )) |
---|
| 75 | ||!(testScript->ItemQuestAccept =(scriptCallItemQuestAccept )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ItemQuestAccept" )) |
---|
| 76 | ||!(testScript->GOQuestAccept =(scriptCallGOQuestAccept )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOQuestAccept" )) |
---|
| 77 | ||!(testScript->ReceiveEmote =(scriptCallReceiveEmote )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ReceiveEmote" )) |
---|
| 78 | ||!(testScript->ItemUse =(scriptCallItemUse )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ItemUse" )) |
---|
| 79 | ||!(testScript->GetAI =(scriptCallGetAI )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GetAI" )) |
---|
| 80 | ||!(testScript->CreateInstanceData =(scriptCallCreateInstanceData )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"CreateInstanceData" )) |
---|
[2] | 81 | ) |
---|
| 82 | { |
---|
| 83 | printf("Error loading Scripts Library %s !\n Library missing required functions.",name.c_str()); |
---|
[44] | 84 | TRINITY_CLOSE_LIBRARY(testScript->hScriptsLib); |
---|
[2] | 85 | delete testScript; |
---|
| 86 | return false; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | printf("Scripts Library %s was successfully loaded.\n",name.c_str()); |
---|
| 90 | |
---|
| 91 | //heh we are still there :P we have a valid library |
---|
| 92 | //we reload script |
---|
| 93 | UnloadScriptingModule(); |
---|
| 94 | |
---|
| 95 | Script=testScript; |
---|
| 96 | Script->ScriptsInit(); |
---|
| 97 | |
---|
[149] | 98 | sWorld.SetScriptsVersion(Script->ScriptsVersion()); |
---|
| 99 | |
---|
[2] | 100 | return true; |
---|
| 101 | } |
---|