GearLoader 1.1.0
Mod loader for GGXXACPR
Loading...
Searching...
No Matches
gearLoader.hpp
1#ifndef GEARLOADER_HPP
2#define GEARLOADER_HPP
3
4#include "gearLoader_c.h"
5#include <string>
6
7
8inline bool operator==(const SemanticVersion& a, const SemanticVersion& b) {
9 return a.major == b.major &&
10 a.minor == b.minor &&
11 a.patchNum == b.patchNum;
12}
13inline bool operator>(const SemanticVersion& a, const SemanticVersion& b) {
14 return a.major > b.major ||
15 (a.major == b.major && a.minor > b.minor) ||
16 (a.major == b.major && a.minor == b.minor && a.patchNum > b.patchNum);
17}
18inline bool operator!=(const SemanticVersion& a, const SemanticVersion& b) { return !(a == b); }
19inline bool operator<(const SemanticVersion& a, const SemanticVersion& b) { return b > a; }
20inline bool operator>=(const SemanticVersion& a, const SemanticVersion& b) { return !(b > a); }
21inline bool operator<=(const SemanticVersion& a, const SemanticVersion& b) { return !(a > b); }
22
23namespace GearLoader {
24 enum class LogLevel {
25 DEBUG = GEARLOADER_LOG_LEVEL_DEBUG,
26 INFO = GEARLOADER_LOG_LEVEL_INFO,
27 WARN = GEARLOADER_LOG_LEVEL_WARN,
28 ERR = GEARLOADER_LOG_LEVEL_ERR,
29 VERBOSE = GEARLOADER_LOG_LEVEL_VERBOSE
30 };
31
37 class Api {
38 public:
39 Api(GearLoaderApi* c_api, GearLoaderContext* ctx) : base(c_api), _ctx(ctx) { }
44 bool VersionError() {
45 return (GEARLOADER_VERSION_NUM & 0xFF0000) != (base->version & 0xFF0000);
46 }
47
61 template<typename ApiType>
62 int RetrieveModApi(std::string name,
63 std::string versionConstraint,
64 const ApiType** pApi,
65 SemanticVersion* retrievedVersion) {
66 if (VersionError()) return 3;
67
68 const void* retApi;
69 int result = base->RetrieveModApi(
70 _ctx,
71 name.c_str(),
72 versionConstraint.c_str(),
73 &retApi,
74 retrievedVersion
75 );
76 *pApi = reinterpret_cast<const ApiType*>(retApi);
77 return result;
78 }
79
94 int RegisterApi (const void* api,
95 std::string name,
96 SemanticVersion version) {
97 if (VersionError()) return 3;
98 return base->RegisterApi(_ctx, api, name.c_str(), version);
99 }
100
109 int Log(LogLevel logLevel, std::string str) {
110 if (VersionError()) return 3;
111 return base->Log(_ctx, static_cast<uint32_t>(logLevel), str.c_str());
112 }
113 private:
114 GearLoaderApi* base;
115 GearLoaderContext* _ctx;
116 };
117}
118
119#endif
int RetrieveModApi(std::string name, std::string versionConstraint, const ApiType **pApi, SemanticVersion *retrievedVersion)
Retrieves an exported API of another loaded mod.
Definition gearLoader.hpp:62
bool VersionError()
Definition gearLoader.hpp:44
int RegisterApi(const void *api, std::string name, SemanticVersion version)
Registers an API with the mod loader.
Definition gearLoader.hpp:94
int Log(LogLevel logLevel, std::string str)
Logs the given string to the GearLoader.log file.
Definition gearLoader.hpp:109
Definition gearLoader_c.h:50
Definition gearLoader_c.h:21