plugins.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _PLUGINS_H_
  4. #define _PLUGINS_H_
  5. #ifndef _CBASETYPES_H_
  6. #include "../common/cbasetypes.h"
  7. #endif
  8. #include "../common/plugin.h"
  9. ////// Dynamic Link Library functions ///////////////
  10. #ifdef WIN32
  11. #define WIN32_LEAN_AND_MEAN
  12. #include <windows.h>
  13. #define DLL_OPEN(x) LoadLibrary(x)
  14. #define DLL_SYM(x,y,z) (FARPROC)(x) = GetProcAddress(y,z)
  15. #define DLL_CLOSE(x) FreeLibrary(x)
  16. char *DLL_ERROR(void);
  17. #define DLL_EXT ".dll"
  18. #define DLL HINSTANCE
  19. #else
  20. #include <dlfcn.h>
  21. #define DLL_OPEN(x) dlopen(x,RTLD_NOW)
  22. #define DLL_SYM(x,y,z) (x) = (void *)dlsym(y,z)
  23. #define DLL_CLOSE(x) dlclose(x)
  24. #define DLL_ERROR dlerror
  25. #ifdef CYGWIN
  26. #define DLL_EXT ".dll"
  27. #else
  28. #define DLL_EXT ".so"
  29. #endif
  30. #define DLL void *
  31. #include <string.h> // size_t
  32. #endif
  33. ////// Plugin Definitions ///////////////////
  34. typedef struct _Plugin {
  35. DLL dll;
  36. char state;
  37. char* filename;
  38. struct _Plugin_Info* info;
  39. struct _Plugin* next;
  40. } Plugin;
  41. /////////////////////////////////////////////
  42. int register_plugin_func(char* name);
  43. int register_plugin_event(Plugin_Event_Func* func, char* name);
  44. int plugin_event_trigger(char* name);
  45. int export_symbol(void* var, size_t offset);
  46. #define EXPORT_SYMBOL(s) export_symbol((s), -1);
  47. Plugin* plugin_open(const char* filename);
  48. void plugin_load(const char* filename);
  49. void plugin_unload(Plugin* plugin);
  50. void plugins_init(void);
  51. void plugins_final(void);
  52. #endif /* _PLUGINS_H_ */