#pragma once
#include "Utils/MemoryUtils.h"
#include "Client.h"

namespace Hooks {
	class RenderControllers {
	private:
		typedef auto(__thiscall* RenderController_GetOverlayColor_)(void*, ImColor*, void*) -> ImColor*;
		inline static RenderController_GetOverlayColor_ rendercontroller_getoverlaycolor;

		static auto callback_getoverlay(void* a1, ImColor* color, void* a3) -> ImColor*;
	public:
		inline static int state = -1;
		static void Init() {
			if (Utils::File::getVersion() == _("1.21.80")) return;

			std::thread([&] {
				void* pattern_getoverlaycolor;
				if (Utils::File::getVersion() == _("1.21.73")) {
					pattern_getoverlaycolor = Utils::Memory::FindPattern(_("E8 8F 3E 8D"));
					pattern_getoverlaycolor = (void*)((uintptr_t)pattern_getoverlaycolor + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_getoverlaycolor + 1));
				}
				else if (Utils::File::getVersion() == _("1.21.72")) {
					pattern_getoverlaycolor = Utils::Memory::FindPattern(_("E8 2F 3F 8D"));
					pattern_getoverlaycolor = (void*)((uintptr_t)pattern_getoverlaycolor + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_getoverlaycolor + 1));
				}
				else if (Utils::File::getVersion() == _("1.21.71")) {
					pattern_getoverlaycolor = Utils::Memory::FindPattern(_("E8 7F B1 8C"));
					pattern_getoverlaycolor = (void*)((uintptr_t)pattern_getoverlaycolor + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_getoverlaycolor + 1));
				}
				else if (Utils::File::getVersion() == _("1.21.70")) {
					pattern_getoverlaycolor = Utils::Memory::FindPattern(_("E8 7F B1 8C"));
					pattern_getoverlaycolor = (void*)((uintptr_t)pattern_getoverlaycolor + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_getoverlaycolor + 1));
				}
				else {
					pattern_getoverlaycolor = Utils::Memory::FindPattern(_("E8 CF 51 8F"));
					pattern_getoverlaycolor = (void*)((uintptr_t)pattern_getoverlaycolor + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_getoverlaycolor + 1));
				}


				state = Utils::Memory::CreateHook(pattern_getoverlaycolor, (void*)&callback_getoverlay, &rendercontroller_getoverlaycolor);

				if (state == 0)
					MessageBoxA(0, _("The program was terminated due to an error.\nError code: 1-13"), _("Valkyrie"), MB_ICONERROR);
				else
					std::cout << _("Test 1-13... OK\n");
				}).detach();
		}
	};
}

