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

namespace Hooks {
	class UIControls {
	private:
		typedef auto(__thiscall* UIControl_getPosition_)(UIControl* _this) -> glm::vec2*;
		inline static UIControl_getPosition_ uicontrol_getposition;

		static auto callback_getposition(UIControl* _this) -> glm::vec2*;
	public:
		inline static int state = -1;
		static void Init() {
			std::thread([&] {
				void* pattern_getposition;
				if (Utils::File::getVersion() == _("1.21.80"))
					pattern_getposition = Utils::Memory::FindPattern(_("48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 60 0F 29 74 24 50 0F 29 7C 24 40 48 8B 05 60"));
				else if (Utils::File::getVersion() == _("1.21.73"))
					pattern_getposition = Utils::Memory::FindPattern(_("48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 60 0F 29 74 24 50 0F 29 7C 24 40 48 8B 05 C0"));
				else if (Utils::File::getVersion() == _("1.21.72"))
					pattern_getposition = Utils::Memory::FindPattern(_("48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 60 0F 29 74 24 50 0F 29 7C 24 40 48 8B 05 20"));
				else if (Utils::File::getVersion() == _("1.21.71"))
					pattern_getposition = Utils::Memory::FindPattern(_("48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 60 0F 29 74 24 50 0F 29 7C 24 40 48 8B 05 90"));
				else if (Utils::File::getVersion() == _("1.21.70"))
					pattern_getposition = Utils::Memory::FindPattern(_("48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 60 0F 29 74 24 50 0F 29 7C 24 40 48 8B 05 90"));
				else
					pattern_getposition = Utils::Memory::FindPattern(_("48 89 5C 24 10 48 89 74 24 18 57 48 83 EC 60 0F 29 74 24 50 0F 29 7C 24 40 48 8B 05 A0 0C"));

				state = Utils::Memory::CreateHook(pattern_getposition, (void*)&callback_getposition, &uicontrol_getposition);

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