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

namespace Hooks {
	class ClientInstances {
	private:
		typedef auto(__thiscall* clientinstance_)(ClientInstance* _this) -> void;
		inline static clientinstance_ clientinstance_ondimensionchanged;

		static auto callback_ondimensionchanged(ClientInstance* _this) -> void;

	public:
		inline static int state = -1;
		static auto Init() -> void {
			std::thread([&] {
				while (!Client::clientinstance) {
					if (!Client::running) break;
					Sleep(0);
				}
				if (!Client::clientinstance) return;

				auto ptr = *(uintptr_t**)(Client::clientinstance);

				if (Utils::File::getVersion() == _("1.21.73"))
					state = Utils::Memory::CreateHook(reinterpret_cast<void*>(ptr[152]), (void*)&callback_ondimensionchanged, &clientinstance_ondimensionchanged);
				else if (Utils::File::getVersion() == _("1.21.72"))
					state = Utils::Memory::CreateHook(reinterpret_cast<void*>(ptr[152]), (void*)&callback_ondimensionchanged, &clientinstance_ondimensionchanged);
				else if (Utils::File::getVersion() == _("1.21.71"))
					state = Utils::Memory::CreateHook(reinterpret_cast<void*>(ptr[152]), (void*)&callback_ondimensionchanged, &clientinstance_ondimensionchanged);
				else if (Utils::File::getVersion() == _("1.21.70"))
					state = Utils::Memory::CreateHook(reinterpret_cast<void*>(ptr[152]), (void*)&callback_ondimensionchanged, &clientinstance_ondimensionchanged);
				else
					state = Utils::Memory::CreateHook(reinterpret_cast<void*>(ptr[149]), (void*)&callback_ondimensionchanged, &clientinstance_ondimensionchanged);
				
				if (state == 0)
					MessageBoxA(0, _("The program was terminated due to an error.\nError code: 1-11"), _("Valkyrie"), MB_ICONERROR);
				else
					std::cout << _("Test 1-11... OK\n");
				}).detach();
		}
	};
}
