DLLmain.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * FILE
  21. *
  22. * DESCRIPTION
  23. *
  24. * PROGRAMMER
  25. * Denzil E. Long, Jr.
  26. *
  27. * VERSION INFO
  28. * $Author: Patrick $
  29. * $Revision: 10 $
  30. * $Modtime: 8/29/01 4:04p $
  31. * $Archive: /Commando/Code/Scripts/DLLmain.cpp $
  32. *
  33. ******************************************************************************/
  34. #include "Windows.H"
  35. #include "scripts.h"
  36. #include "scriptregistrar.h"
  37. //#include "missioncontrol.h"
  38. #include "dprint.h"
  39. /******************************************************************************
  40. *
  41. * NAME
  42. * DllMain
  43. *
  44. * DESCRIPTION
  45. * Main DLL entry point
  46. *
  47. * INPUTS
  48. * HINSTANCE hinst
  49. * DWORD reason
  50. * LPVOID
  51. *
  52. * RESULTS
  53. * BOOL APIENTRY
  54. *
  55. ******************************************************************************/
  56. __declspec(dllexport)
  57. BOOL APIENTRY DllMain(HINSTANCE hinst, DWORD reason, LPVOID)
  58. {
  59. if (reason == DLL_PROCESS_ATTACH) {
  60. // DebugPrint("\n========== Script.dll loaded ==========\n");
  61. DebugPrint("Total registered scripts: %d\n", ScriptRegistrar::Count());
  62. } else if (reason == DLL_PROCESS_DETACH) {
  63. // DebugPrint("\n========== Script.dll Unloaded ==========\n");
  64. }
  65. return TRUE;
  66. }
  67. /******************************************************************************
  68. *
  69. * NAME
  70. * Create_Script
  71. *
  72. * DESCRIPTION
  73. * DLL entry to create a script instance.
  74. *
  75. * INPUTS
  76. * const char* name
  77. *
  78. * RESULTS
  79. * ScriptClass*
  80. *
  81. ******************************************************************************/
  82. ScriptClass* Create_Script(const char* name)
  83. {
  84. return ScriptRegistrar::CreateScript(name);
  85. }
  86. /******************************************************************************
  87. *
  88. * NAME
  89. * Destroy_Script
  90. *
  91. * DESCRIPTION
  92. * DLL entry to destroy a script instance
  93. *
  94. * INPUTS
  95. * ScriptClass* script
  96. *
  97. * RESULTS
  98. * NONE
  99. *
  100. ******************************************************************************/
  101. void Destroy_Script(ScriptClass* script)
  102. {
  103. assert(script != NULL);
  104. delete script;
  105. }
  106. /******************************************************************************
  107. *
  108. * NAME
  109. * Get_Script_Count
  110. *
  111. * DESCRIPTION
  112. * DLL entry to count the number of registered scripts
  113. *
  114. * INPUTS
  115. * NONE
  116. *
  117. * RESULTS
  118. * Count
  119. *
  120. ******************************************************************************/
  121. int Get_Script_Count(void)
  122. {
  123. return ScriptRegistrar::Count();
  124. }
  125. /******************************************************************************
  126. *
  127. * NAME
  128. * Get_Script_Name
  129. *
  130. * DESCRIPTION
  131. * DLL entry to retrieve script name.
  132. *
  133. * INPUTS
  134. * int index
  135. *
  136. * RESULTS
  137. * const char*
  138. *
  139. ******************************************************************************/
  140. const char* Get_Script_Name(int index)
  141. {
  142. ScriptFactory* factory = ScriptRegistrar::GetScriptFactory(index);
  143. if (factory != NULL) {
  144. return factory->GetName();
  145. }
  146. return NULL;
  147. }
  148. /******************************************************************************
  149. *
  150. * NAME
  151. * Get_Script_Param_Description
  152. *
  153. * DESCRIPTION
  154. * DLL entry to retrieve Script parameter description.
  155. *
  156. * INPUTS
  157. * int index
  158. *
  159. * RESULTS
  160. * const char*
  161. *
  162. ******************************************************************************/
  163. const char* Get_Script_Param_Description(int index)
  164. {
  165. ScriptFactory* factory = ScriptRegistrar::GetScriptFactory(index);
  166. if (factory != NULL) {
  167. return factory->GetParamDescription();
  168. }
  169. return NULL;
  170. }
  171. /******************************************************************************
  172. *
  173. * NAME
  174. * Set_Script_Commands
  175. *
  176. * DESCRIPTION
  177. * DLL entry to initialize script commands hooks.
  178. *
  179. * INPUTS
  180. * ScriptCommandsClass* commands
  181. *
  182. * RESULTS
  183. * Success - True if successful; otherwise false.
  184. *
  185. ******************************************************************************/
  186. bool Set_Script_Commands(ScriptCommandsClass* commands)
  187. {
  188. assert(commands != NULL);
  189. // Save the commands list
  190. Commands = commands->Commands;
  191. DebugPrint("Setting script commands (Version %d, Size %d)\n",
  192. Commands->Version, Commands->Size);
  193. // Check the commands version number
  194. if ((Commands->Size != sizeof(ScriptCommands))
  195. || (Commands->Version != SCRIPT_COMMANDS_VERSION)) {
  196. DebugPrint("***** Invalid script commands (Expected Version %d, Size %d)\n",
  197. SCRIPT_COMMANDS_VERSION, sizeof(ScriptCommands));
  198. Commands->Debug_Message("******** Incorrect Script Commands Version\n");
  199. return false;
  200. }
  201. return true;
  202. }
  203. /******************************************************************************
  204. *
  205. * NAME
  206. * Set_Request_Destroy_Func
  207. *
  208. * DESCRIPTION
  209. *
  210. * INPUTS
  211. * Function
  212. *
  213. * RESULTS
  214. * NONE
  215. *
  216. ******************************************************************************/
  217. void Set_Request_Destroy_Func(void (*function)(ScriptClass*))
  218. {
  219. assert(function != NULL);
  220. ScriptImpClass::Set_Request_Destroy_Func(function);
  221. }