dllLoader.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #define GAMEPLAYSTART(x) void x(pika::PikaContext &pikaContext)
  14. typedef GAMEPLAYSTART(gameplayStart_t);
  15. #undef GAMEPLAYSTART
  16. #define GAMEPLAYRELOAD(x) void x(pika::PikaContext &pikaContext)
  17. typedef GAMEPLAYRELOAD(gameplayReload_t);
  18. #undef GAMEPLAYRELOAD
  19. #define GETCONTAINERSINFO(x) void x(std::vector<pika::ContainerInformation> &info)
  20. typedef GETCONTAINERSINFO(getContainersInfo_t);
  21. #undef GETCONTAINERSINFO
  22. #define CONSTRUCTCONTAINER(x) bool x(Container **c, pika::memory::MemoryArena *arena, const char *name);
  23. typedef CONSTRUCTCONTAINER(constructContainer_t);
  24. #undef CONSTRUCTCONTAINER
  25. #define DESTRUCTCONTAINER(x) void x(Container **c, pika::memory::MemoryArena *arena);
  26. typedef DESTRUCTCONTAINER(destructContainer_t);
  27. #undef DESTRUCTCONTAINER
  28. #define BINDALLOCATOR(x) void x(pika::memory::FreeListAllocator *arena);
  29. typedef BINDALLOCATOR(bindAllocator_t);
  30. #undef BINDALLOCATOR
  31. #define RESETALLOCATOR(x) void x();
  32. typedef RESETALLOCATOR(resetAllocator_t)
  33. #undef RESETALLOCATOR
  34. #define DISSABLEALLOCATORS(x) void x();
  35. typedef DISSABLEALLOCATORS(dissableAllocators_t)
  36. #undef DISSABLEALLOCATORS
  37. #ifdef PIKA_WINDOWS
  38. #define NOMINMAX
  39. #define WIN32_LEAN_AND_MEAN
  40. #include <Windows.h>
  41. #endif
  42. namespace pika
  43. {
  44. struct LoadedDll
  45. {
  46. gameplayStart_t *gameplayStart_ = {};
  47. gameplayReload_t *gameplayReload_ = {};
  48. getContainersInfo_t *getContainersInfo_ = {};
  49. constructContainer_t *constructContainer_ = {};
  50. destructContainer_t *destructContainer_ = {};
  51. bindAllocator_t *bindAllocator_ = {};
  52. resetAllocator_t *resetAllocator_ = {};
  53. dissableAllocators_t *dissableAllocators_ = {};
  54. #ifdef PIKA_WINDOWS
  55. FILETIME filetime = {};
  56. HMODULE dllHand = {};
  57. #endif
  58. int id = 0;
  59. bool loadDll(int id, pika::LogManager &logs);
  60. bool tryToloadDllUntillPossible(int id, pika::LogManager &logs, std::chrono::duration<long long> timeout =
  61. std::chrono::seconds(0));
  62. void unloadDll();
  63. //no need to call since it is called in load dll function
  64. void getContainerInfoAndCheck(pika::LogManager &logs);
  65. bool shouldReloadDll();
  66. std::vector<pika::ContainerInformation> containerInfo;
  67. bool constructRuntimeContainer(pika::RuntimeContainer &c, const char *name);
  68. void bindAllocatorDllRealm(pika::memory::FreeListAllocator *allocator);
  69. void resetAllocatorDllRealm();
  70. bool checkIfDllIsOpenable();
  71. };
  72. };