#include "NoSlow.h"

auto NoSlow::onWorldTick(Player* _this) -> void {
    if (!patched) {
        DWORD oldProtect;
        VirtualProtect((void*)tickentity_itemuseslowdownmodifiercomponent_, 5, PAGE_EXECUTE_READWRITE, &oldProtect);
        memcpy(ogBytes, (void*)tickentity_itemuseslowdownmodifiercomponent_, 5);
        VirtualProtect((void*)tickentity_itemuseslowdownmodifiercomponent_, 5, oldProtect, &oldProtect);

        VirtualProtect((LPVOID)tickentity_itemuseslowdownmodifiercomponent_, 5, PAGE_EXECUTE_READWRITE, &oldProtect);
        memcpy((LPVOID)tickentity_itemuseslowdownmodifiercomponent_, _("\xC3\x90\x90\x90\x90"), 5);
        VirtualProtect((LPVOID)tickentity_itemuseslowdownmodifiercomponent_, 5, oldProtect, &oldProtect);

        patched = true;
    }
}

auto NoSlow::onDisabled() -> void {
    if (patched) {
        DWORD oldProtect;
        VirtualProtect((LPVOID)tickentity_itemuseslowdownmodifiercomponent_, 5, PAGE_EXECUTE_READWRITE, &oldProtect);
        memcpy((LPVOID)tickentity_itemuseslowdownmodifiercomponent_, ogBytes, 5);
        VirtualProtect((LPVOID)tickentity_itemuseslowdownmodifiercomponent_, 5, oldProtect, &oldProtect);

        patched = false;
    }
}

auto NoSlow::getMode() -> std::string {
    switch (mode) {
    case 0:
        return _("Vanilla");
    }

    return _("Unknown");
}
