Guest User

Untitled

a guest
Jan 24th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.21 KB | None | 0 0
  1. /***********************************************************
  2.  * AGSUtility                                              *
  3.  *                                                         *
  4.  * Author: Steven Poulton                                  *
  5.  *                                                         *
  6.  * Date: 09/01/2011                                        *
  7.  *                                                         *
  8.  * Description: An AGS Plugin to allow FMOD Integration    *
  9.  *                                                         *
  10.  ***********************************************************/
  11.  
  12. #pragma region Defines_and_Includes
  13.  
  14. #define MIN_EDITOR_VERSION 1
  15. #define MIN_ENGINE_VERSION 3
  16.  
  17. #define WIN32_LEAN_AND_MEAN
  18. #include <windows.h>
  19.  
  20.  
  21. #define REGISTER(x) engine->RegisterScriptFunction(#x, (void *) (x));
  22. #define STRINGIFY(s) STRINGIFY_X(s)
  23. #define STRINGIFY_X(s) #s
  24.  
  25. #define THIS_IS_THE_PLUGIN
  26. #include "agsplugin.h"
  27. #include "AGSDelegate.h"
  28.  
  29.  
  30. #pragma endregion
  31.  
  32.  
  33. // The standard Windows DLL entry point
  34.  
  35. BOOL APIENTRY DllMain( HANDLE hModule,
  36.                        DWORD  ul_reason_for_call,
  37.                        LPVOID lpReserved) {
  38.  
  39.   switch (ul_reason_for_call)   {
  40.         case DLL_PROCESS_ATTACH:
  41.         case DLL_THREAD_ATTACH:
  42.         case DLL_THREAD_DETACH:
  43.         case DLL_PROCESS_DETACH:
  44.             break;
  45.   }
  46.   return TRUE;
  47. }
  48.  
  49.  
  50.  
  51. //define engine
  52.  
  53. IAGSEngine      *engine = 0;
  54. ManagedAGSDelegateInterface *gAGSDelInterface;
  55. ManagedAGSDelegateReader *gAGSDelReader;
  56.  
  57. //==============================================================================
  58.  
  59. // ***** Design time *****
  60.  
  61. IAGSEditor *editor; // Editor interface
  62.  
  63. const char *ourScriptHeader =
  64.     "managed struct Delegate {\r\n"
  65.     "       import void Run();\r\n"
  66.     "       import static Delegate* Create(String name);\r\n"
  67.     "};\r\n";
  68.    
  69.    
  70.  
  71. #pragma region Editor Interop
  72.  
  73. LPCSTR AGS_GetPluginName()
  74. {
  75.     return ("AGSDelegates");
  76. }
  77.  
  78. int AGS_EditorStartup(IAGSEditor *lpEditor)
  79. {
  80.     // User has checked the plugin to use it in their game
  81.  
  82.     if (lpEditor->version < MIN_EDITOR_VERSION)
  83.         return (-1);
  84.    
  85.     editor = lpEditor;
  86.     editor->RegisterScriptHeader(ourScriptHeader);
  87.    
  88.     // Return 0 to indicate success
  89.     return (0);
  90. }
  91.  
  92. void AGS_EditorShutdown()
  93. {
  94.     editor->UnregisterScriptHeader(ourScriptHeader);
  95.    
  96.    
  97.        
  98. }
  99.  
  100. void AGS_EditorProperties(HWND parent)                        //*** optional ***
  101. {
  102.    
  103. }
  104.  
  105. int AGS_EditorSaveGame(char *buffer, int bufsize)             //*** optional ***
  106. {
  107.     return (0);
  108. }
  109.  
  110. void AGS_EditorLoadGame(char *buffer, int bufsize)            //*** optional ***
  111. {
  112.  
  113. }
  114.  
  115. #pragma endregion
  116.  
  117. AGSDelegate *CreateDelegate(const char *name)
  118. {
  119.     AGSDelegate *del = new AGSDelegate(engine, name);
  120.     engine->RegisterManagedObject(del, gAGSDelInterface);
  121.     return del;
  122. }
  123.  
  124. void RunDelegate(AGSDelegate *obj)
  125. {
  126.     obj->Run();
  127. }
  128.  
  129. #pragma region Engine
  130.  
  131. void InitInterfaces()
  132. {
  133.     gAGSDelInterface = new ManagedAGSDelegateInterface();
  134.     gAGSDelReader = new ManagedAGSDelegateReader(engine, gAGSDelInterface);
  135. }
  136.  
  137.  
  138. void AGS_EngineStartup(IAGSEngine *lpEngine)
  139. {
  140.     engine = lpEngine;
  141.    
  142.     // Make sure it's got the version with the features we need
  143.     if (engine->version < MIN_ENGINE_VERSION)
  144.         engine->AbortGame("Plugin needs engine version " STRINGIFY(MIN_ENGINE_VERSION) " or newer.");
  145.    
  146.     InitInterfaces();
  147.  
  148.     //engine->RequestEventHook(AGSE_SAVEGAME);
  149.    
  150.     //register functions
  151.    
  152.     engine->AddManagedObjectReader(ManagedAGSDelegateInterface::typeName, gAGSDelReader);
  153.     engine->RegisterScriptFunction("Delegate::Create^1", CreateDelegate);
  154.     engine->RegisterScriptFunction("Delegate::Run", RunDelegate);
  155.        
  156. }
  157.  
  158. void AGS_EngineShutdown()
  159. {
  160.  
  161. }
  162.  
  163. int AGS_EngineOnEvent(int event, int data)                    //*** optional ***
  164. {
  165.     // Return 1 to stop event from processing further (when needed)
  166.     return (0);
  167. }
  168.  
  169. //int AGS_EngineDebugHook(const char *scriptName,
  170. //                        int lineNum, int reserved)            //*** optional ***
  171. //{
  172. //  // Can be used to debug scripts, see documentation
  173. //}
  174. //
  175. //void AGS_EngineInitGfx(const char *driverID, void *data)      //*** optional ***
  176. //{
  177. //  // This allows you to make changes to how the graphics driver starts up.
  178. //  // See documentation
  179. //}
  180.  
  181. #pragma endregion
Add Comment
Please, Sign In to add comment