ScriptMgr.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/ScriptMgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 4/27/00 8:53a $*
  29. * *
  30. * $Revision:: 5 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "stdafx.h"
  36. #include "scriptmgr.h"
  37. #include "..\..\scripts\ScriptEvents.H"
  38. #include "EditScript.h"
  39. #include "Utils.h"
  40. #include "FileMgr.h"
  41. #include "FileLocations.h"
  42. //////////////////////////////////////////////////////////////////////////
  43. // Static member initialization
  44. //////////////////////////////////////////////////////////////////////////
  45. SCRIPT_LIST ScriptMgrClass::_ScriptList;
  46. //////////////////////////////////////////////////////////////////////////
  47. //
  48. // ~ScriptMgrClass
  49. //
  50. //////////////////////////////////////////////////////////////////////////
  51. ScriptMgrClass::~ScriptMgrClass (void)
  52. {
  53. Shutdown ();
  54. return ;
  55. }
  56. //////////////////////////////////////////////////////////////////////////
  57. //
  58. // Initialize
  59. //
  60. //////////////////////////////////////////////////////////////////////////
  61. void
  62. ScriptMgrClass::Initialize (void)
  63. {
  64. CString scripts_path = ::Get_File_Mgr ()->Make_Full_Path (SCRIPTS_PATH);
  65. //CString search_path = ::Make_Path (scripts_path, "*.dll");
  66. CString filename;
  67. // Denzil 4/3/00 - Use scripts.dll for all builds
  68. #if(0)
  69. #ifdef WWDEBUG
  70. #ifndef NDEBUG
  71. filename = "SCRIPTSD.DLL";
  72. #else
  73. filename = "SCRIPTSP.DLL";
  74. #endif
  75. #else
  76. filename = "SCRIPTS.DLL";
  77. #endif
  78. #else // Denzil
  79. filename = "SCRIPTS.DLL";
  80. #endif // Denzil
  81. //
  82. // Find all files that match this wildcard
  83. //
  84. /*WIN32_FIND_DATA find_info = { 0 };
  85. BOOL keep_going = TRUE;
  86. for (HANDLE file_find = ::FindFirstFile (search_path, &find_info);
  87. (file_find != INVALID_HANDLE_VALUE) && keep_going;
  88. keep_going = ::FindNextFile (file_find, &find_info))
  89. {*/
  90. //
  91. // Build a path to the DLL
  92. //
  93. //CString dll_name = ::Make_Path (scripts_path, Get_Filename_From_Path (find_info.cFileName));
  94. CString dll_name = ::Make_Path (scripts_path, filename);
  95. if (::GetFileAttributes (dll_name) != 0xFFFFFFFF) {
  96. HMODULE module_handle = ::LoadLibrary (dll_name);
  97. if (module_handle != NULL) {
  98. // Lookup the function pointer we need to call to determine
  99. // a filename list
  100. LPFN_GET_SCRIPT_COUNT pfn_get_script_count = (LPFN_GET_SCRIPT_COUNT)::GetProcAddress (module_handle, LPSTR_GET_SCRIPT_COUNT);
  101. LPFN_GET_SCRIPT_NAME pfn_get_script_name = (LPFN_GET_SCRIPT_NAME)::GetProcAddress (module_handle, LPSTR_GET_SCRIPT_NAME);
  102. LPFN_GET_SCRIPT_PARAM_DESCRIPTION pfn_get_param_desc = (LPFN_GET_SCRIPT_PARAM_DESCRIPTION)::GetProcAddress (module_handle, LPSTR_GET_SCRIPT_PARAM_DESCRIPTION);
  103. ASSERT (pfn_get_script_count != NULL);
  104. ASSERT (pfn_get_script_name != NULL);
  105. ASSERT (pfn_get_param_desc != NULL);
  106. if ((pfn_get_script_count != NULL) &&
  107. (pfn_get_script_name != NULL) &&
  108. (pfn_get_param_desc != NULL))
  109. {
  110. int count = (*pfn_get_script_count) ();
  111. //
  112. // Loop through all the scripts in the list and add their names
  113. // to our list
  114. //
  115. for (int index = 0; index < count; index ++) {
  116. EditScriptClass *script = new EditScriptClass;
  117. //
  118. // Pass the script name, and the script params onto our object
  119. //
  120. script->Set_Name ((*pfn_get_script_name) (index));
  121. script->Set_Param_Desc ((*pfn_get_param_desc) (index));
  122. // Add this script to the list
  123. _ScriptList.Add (script);
  124. }
  125. }
  126. // Unload the DLL from memory
  127. ::FreeLibrary (module_handle);
  128. module_handle = NULL;
  129. }
  130. }
  131. /*}
  132. if (file_find != INVALID_HANDLE_VALUE) {
  133. ::FindClose (file_find);
  134. }*/
  135. return ;
  136. }
  137. //////////////////////////////////////////////////////////////////////////
  138. //
  139. // Shutdown
  140. //
  141. //////////////////////////////////////////////////////////////////////////
  142. void
  143. ScriptMgrClass::Shutdown (void)
  144. {
  145. for (int index = 0; index < _ScriptList.Count (); index++) {
  146. EditScriptClass *script = _ScriptList[index];
  147. SAFE_DELETE (script);
  148. }
  149. _ScriptList.Delete_All ();
  150. return ;
  151. }
  152. //////////////////////////////////////////////////////////////////////////
  153. //
  154. // Find_Script
  155. //
  156. //////////////////////////////////////////////////////////////////////////
  157. EditScriptClass *
  158. ScriptMgrClass::Find_Script (LPCTSTR name)
  159. {
  160. EditScriptClass *script = NULL;
  161. for (int index = 0; (index < _ScriptList.Count ()) && (script == NULL); index++) {
  162. EditScriptClass *curr_script = _ScriptList[index];
  163. //
  164. // Is this the script we are looking for?
  165. //
  166. if (::lstrcmpi (curr_script->Get_Name (), name) == 0) {
  167. script = curr_script;
  168. }
  169. }
  170. return script;
  171. }