dllLoader.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #pragma once
  2. #include <filesystem>
  3. #include <glad/glad.h> //used to not conflict with glfw
  4. #include <GLFW/glfw3.h>
  5. #include <pikaImgui/pikaImgui.h>
  6. #include <containerInformation.h>
  7. #include <vector>
  8. #include <baseContainer.h>
  9. #include <memoryArena/memoryArena.h>
  10. #include <runtimeContainer/runtimeContainer.h>
  11. #include <logs/log.h>
  12. #include <sstream>
  13. #include <unordered_map>
  14. #include <string>
  15. #define GAMEPLAYSTART(x) void x(pika::PikaContext &pikaContext, pika::LogManager &logs)
  16. typedef GAMEPLAYSTART(gameplayStart_t);
  17. #undef GAMEPLAYSTART
  18. #define GAMEPLAYRELOAD(x) void x(pika::PikaContext &pikaContext, pika::LogManager &logs)
  19. typedef GAMEPLAYRELOAD(gameplayReload_t);
  20. #undef GAMEPLAYRELOAD
  21. #define GETCONTAINERSINFO(x) void x(std::vector<pika::ContainerInformation> &info)
  22. typedef GETCONTAINERSINFO(getContainersInfo_t);
  23. #undef GETCONTAINERSINFO
  24. #define CONSTRUCTCONTAINER(x) bool x(Container **c, pika::memory::MemoryArena *arena, const char *name);
  25. typedef CONSTRUCTCONTAINER(constructContainer_t);
  26. #undef CONSTRUCTCONTAINER
  27. #define DESTRUCTCONTAINER(x) void x(Container **c, pika::memory::MemoryArena *arena);
  28. typedef DESTRUCTCONTAINER(destructContainer_t);
  29. #undef DESTRUCTCONTAINER
  30. #define BINDALLOCATOR(x) void x(pika::memory::FreeListAllocator *arena);
  31. typedef BINDALLOCATOR(bindAllocator_t);
  32. #undef BINDALLOCATOR
  33. #define RESETALLOCATOR(x) void x();
  34. typedef RESETALLOCATOR(resetAllocator_t)
  35. #undef RESETALLOCATOR
  36. #define DISSABLEALLOCATORS(x) void x();
  37. typedef DISSABLEALLOCATORS(dissableAllocators_t)
  38. #undef DISSABLEALLOCATORS
  39. #ifdef PIKA_WINDOWS
  40. #define NOMINMAX
  41. #include <Windows.h>
  42. #endif
  43. namespace pika
  44. {
  45. struct LoadedDll
  46. {
  47. gameplayStart_t *gameplayStart_ = {};
  48. gameplayReload_t *gameplayReload_ = {};
  49. getContainersInfo_t *getContainersInfo_ = {};
  50. constructContainer_t *constructContainer_ = {};
  51. destructContainer_t *destructContainer_ = {};
  52. bindAllocator_t *bindAllocator_ = {};
  53. resetAllocator_t *resetAllocator_ = {};
  54. dissableAllocators_t *dissableAllocators_ = {};
  55. #ifdef PIKA_WINDOWS
  56. FILETIME filetime = {};
  57. HMODULE dllHand = {};
  58. #endif
  59. int id = 0;
  60. bool loadDll(int id, pika::LogManager &logs);
  61. bool tryToloadDllUntillPossible(int id, pika::LogManager &logs, std::chrono::duration<long long> timeout =
  62. std::chrono::seconds(0));
  63. void unloadDll();
  64. //no need to call since it is called in load dll function
  65. void getContainerInfoAndCheck(pika::LogManager &logs);
  66. bool shouldReloadDll();
  67. void reloadContainerExtensionsSupport();
  68. std::vector<pika::ContainerInformation> containerInfo;
  69. std::unordered_map<std::string, std::vector<std::string>> containerExtensionsSupport;
  70. bool constructRuntimeContainer(pika::RuntimeContainer &c, const char *name);
  71. void bindAllocatorDllRealm(pika::memory::FreeListAllocator *allocator);
  72. void resetAllocatorDllRealm();
  73. bool checkIfDllIsOpenable();
  74. };
  75. };