2022-12-14 06:11:19 -05:00
|
|
|
#include <Geode/loader/Loader.hpp>
|
2022-12-14 09:17:52 -05:00
|
|
|
#include <Geode/loader/Mod.hpp>
|
|
|
|
|
|
|
|
namespace geode {
|
|
|
|
/**
|
|
|
|
* To bypass the need for cyclic dependencies,
|
|
|
|
* this function does the exact same as Mod::get()
|
|
|
|
* However, it can be externed, unlike Mod::get()
|
|
|
|
* @returns Same thing Mod::get() returns
|
|
|
|
*/
|
|
|
|
Mod* getMod() {
|
|
|
|
return Mod::get();
|
|
|
|
}
|
|
|
|
}
|
2022-07-30 12:24:03 -04:00
|
|
|
|
2024-06-08 08:57:50 -04:00
|
|
|
GEODE_API void geodeImplicitEntry() {
|
2022-12-14 06:11:19 -05:00
|
|
|
// to make sure the instance is set into the sharedMod<> in load time
|
2024-06-08 08:57:50 -04:00
|
|
|
(void)geode::getMod();
|
2023-01-21 09:00:14 -05:00
|
|
|
}
|
2024-04-11 12:26:49 -04:00
|
|
|
|
|
|
|
#if defined(_DEBUG) && defined(GEODE_IS_WINDOWS)
|
|
|
|
|
|
|
|
// This bypasses any of the heap validation measures that are injected when compiling in Debug.
|
|
|
|
// Without these, the game will very likely crash when the mod tries to free memory allocated by the game (or another non-debug mod).
|
|
|
|
|
|
|
|
static inline void* relallocthrow(size_t size) {
|
2024-04-12 09:10:33 -04:00
|
|
|
void* p;
|
|
|
|
while ((p = HeapAlloc(GetProcessHeap(), 0, size)) == 0) {
|
|
|
|
if (_callnewh(size) == 0) {
|
|
|
|
static const std::bad_alloc exc;
|
|
|
|
throw exc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
2024-04-11 12:26:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void relfree(void* block) {
|
2024-04-12 09:10:33 -04:00
|
|
|
HeapFree(GetProcessHeap(), 0, block);
|
2024-04-11 12:26:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void* operator new(size_t size) {
|
|
|
|
return relallocthrow(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* operator new[](size_t size) {
|
|
|
|
return relallocthrow(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator delete(void* block) noexcept {
|
|
|
|
relfree(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|