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