#pragma once
#include "Utils/MemoryUtils.h"
#include "Utils/FileUtils.h"
#include "SDK/ContainerScreenController.h"

namespace Hooks {
	class ContainerScreenControllers {
	private:
		typedef auto(__thiscall* containerscreencontroller__oncontainerslothovered_)(ContainerScreenController*, std::string32, int64_t) -> void;
		typedef auto(__thiscall* containerscreencontroller_tick_)(ContainerScreenController*) -> void;
		inline static containerscreencontroller_tick_ containerscreencontroller_tick;
		inline static containerscreencontroller__oncontainerslothovered_ containerscreencontroller__oncontainerslothovered;

		static auto callback__oncontainerslothovered(ContainerScreenController* _this, std::string32 collectionName, int64_t slot) -> void;
		static auto callback_tick(ContainerScreenController* _this) -> void;
	public:
		inline static int state = -1;
		static void Init() {
			std::thread([&] {
				void* pattern_oncintaerslothovered;
				if (Utils::File::getVersion() == _("1.21.80"))
					pattern_oncintaerslothovered = Utils::Memory::FindPattern(_("48 89 5C 24 18 48 89 7C 24 20 41 54 41 56 41 57 48 83 EC 20 45 33"));
				else if (Utils::File::getVersion() == _("1.21.73"))
					pattern_oncintaerslothovered = Utils::Memory::FindPattern(_("48 89 5C 24 18 48 89 7C 24 20 41 54 41 56 41 57 48 83 EC 20 45 33"));
				else if (Utils::File::getVersion() == _("1.21.72"))
					pattern_oncintaerslothovered = Utils::Memory::FindPattern(_("48 89 5C 24 18 48 89 7C 24 20 41 54 41 56 41 57 48 83 EC 20 45 33"));
				else if (Utils::File::getVersion() == _("1.21.71"))
					pattern_oncintaerslothovered = Utils::Memory::FindPattern(_("48 89 5C 24 18 48 89 7C 24 20 41 54 41 56 41 57 48 83 EC 20 45 33"));
				else if (Utils::File::getVersion() == _("1.21.70"))
					pattern_oncintaerslothovered = Utils::Memory::FindPattern(_("48 89 5C 24 18 48 89 7C 24 20 41 54 41 56 41 57 48 83 EC 20 45 33"));
				else
					pattern_oncintaerslothovered = Utils::Memory::FindPattern(_("48 89 5C 24 18 57 41 56 41 57 48 83 EC 20 45"));

				state = Utils::Memory::CreateHook(pattern_oncintaerslothovered, (void*)&callback__oncontainerslothovered, &containerscreencontroller__oncontainerslothovered);

				if (state != 0) {
					void* pattern_tick = nullptr;
					if (Utils::File::getVersion() == _("1.21.80")) {
						pattern_tick = Utils::Memory::FindPattern(_("E8 DE 0C EC"));
						pattern_tick = (void*)((uintptr_t)pattern_tick + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_tick + 1));
					}
					else if (Utils::File::getVersion() == _("1.21.73")) {
						pattern_tick = Utils::Memory::FindPattern(_("E8 AE 4B 8E"));
						pattern_tick = (void*)((uintptr_t)pattern_tick + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_tick + 1));
					}
					else if (Utils::File::getVersion() == _("1.21.72")) {
						pattern_tick = Utils::Memory::FindPattern(_("E8 BE 46 8E"));
						pattern_tick = (void*)((uintptr_t)pattern_tick + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_tick + 1));
					}
					else if (Utils::File::getVersion() == _("1.21.71")) {
						pattern_tick = Utils::Memory::FindPattern(_("E8 AE 26 8F"));
						pattern_tick = (void*)((uintptr_t)pattern_tick + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_tick + 1));
					}
					else if (Utils::File::getVersion() == _("1.21.70")) {
						pattern_tick = Utils::Memory::FindPattern(_("E8 DE 27 8F FA"));
						pattern_tick = (void*)((uintptr_t)pattern_tick + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_tick + 1));
					}
					else {
						pattern_tick = Utils::Memory::FindPattern(_("E8 FE C0 84"));
						pattern_tick = (void*)((uintptr_t)pattern_tick + 5 + *reinterpret_cast<int*>((uintptr_t)pattern_tick + 1));
					}
					state = Utils::Memory::CreateHook(pattern_tick, (void*)&callback_tick, &containerscreencontroller_tick);
				}

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