mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 17:36:05 -05:00
Add disable auto enable to Patch
This commit is contained in:
parent
23c3095263
commit
69821f3e2c
4 changed files with 35 additions and 6 deletions
|
@ -12,7 +12,7 @@ namespace geode {
|
|||
class Mod;
|
||||
class Loader;
|
||||
|
||||
class GEODE_DLL Hook {
|
||||
class GEODE_DLL Hook final {
|
||||
private:
|
||||
class Impl;
|
||||
std::shared_ptr<Impl> m_impl;
|
||||
|
@ -143,20 +143,21 @@ namespace geode {
|
|||
void setAutoEnable(bool autoEnable);
|
||||
};
|
||||
|
||||
class GEODE_DLL Patch {
|
||||
class GEODE_DLL Patch final {
|
||||
protected:
|
||||
Mod* m_owner;
|
||||
void* m_address;
|
||||
ByteVector m_original;
|
||||
ByteVector m_patch;
|
||||
bool m_applied;
|
||||
bool m_autoEnable;
|
||||
|
||||
// Only allow friend classes to create
|
||||
// patches. Whatever method created the
|
||||
// patches should take care of populating
|
||||
// m_owner, m_address, m_original and
|
||||
// m_patch.
|
||||
Patch() : m_applied(false) {}
|
||||
Patch();
|
||||
|
||||
// no copying
|
||||
Patch(Patch const&) = delete;
|
||||
|
@ -198,5 +199,17 @@ namespace geode {
|
|||
* @note For IPC
|
||||
*/
|
||||
json::Value getRuntimeInfo() const;
|
||||
|
||||
/**
|
||||
* Get whether the patch should be auto enabled or not.
|
||||
* @returns Auto enable
|
||||
*/
|
||||
bool getAutoEnable() const;
|
||||
|
||||
/**
|
||||
* Set whether the patch should be auto enabled or not.
|
||||
* @param autoEnable Auto enable
|
||||
*/
|
||||
void setAutoEnable(bool autoEnable);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -351,10 +351,16 @@ Result<> Mod::Impl::loadBinary() {
|
|||
}
|
||||
|
||||
for (auto const& patch : m_patches) {
|
||||
if (!patch->apply()) {
|
||||
log::warn("Unable to apply patch at {}", patch->getAddress());
|
||||
if (!patch) {
|
||||
log::warn("Patch is null in mod \"{}\"", m_metadata.getName());
|
||||
continue;
|
||||
}
|
||||
if (patch->getAutoEnable()) {
|
||||
if (!patch->apply()) {
|
||||
log::warn("Unable to apply patch at {}", patch->getAddress());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_enabled = true;
|
||||
|
|
|
@ -11,6 +11,16 @@ bool Patch::restore() {
|
|||
return bool(tulip::hook::writeMemory(m_address, m_original.data(), m_original.size()));
|
||||
}
|
||||
|
||||
Patch::Patch() : m_owner(nullptr), m_address(nullptr), m_applied(false), m_autoEnable(true) {}
|
||||
|
||||
void Patch::setAutoEnable(bool autoEnable) {
|
||||
m_autoEnable = autoEnable;
|
||||
}
|
||||
|
||||
bool Patch::getAutoEnable() const {
|
||||
return m_autoEnable;
|
||||
}
|
||||
|
||||
template <>
|
||||
struct json::Serialize<ByteVector> {
|
||||
static json::Value to_json(ByteVector const& bytes) {
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace gd {
|
|||
return std::string(*this) == std::string(other);
|
||||
}
|
||||
|
||||
// TODO: these need to stay for old mods linking against geode <1.2.0
|
||||
// TODO: these need to stay for old mods linking against geode <1.2.0, remove in 2.0.0
|
||||
template class map<int, int>;
|
||||
template class map<gd::string, gd::string>;
|
||||
template class map<gd::string, bool>;
|
||||
|
|
Loading…
Reference in a new issue