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

#include "SDK/TextureGroup.h"
#include "SDK/TexturePtr.h"
#include "SDK/ResourceLocation.h"

namespace Hooks {
	class TextureGroups {
	private:
		typedef auto(__thiscall* TextureGroup_getTexture_)(mce::TextureGroup*, mce::TexturePtr*, ResourceLocation*, bool, void*, int, void*) -> mce::TexturePtr*;
		inline static TextureGroup_getTexture_ texturegroup_gettexture;

		static auto callback_gettexture(mce::TextureGroup* _this, mce::TexturePtr* result, ResourceLocation* location, bool forceReload, void* a5, int a6, void* a7) -> mce::TexturePtr*;
	public:
		inline static int state = -1;
		static void Init() {
			std::thread([&] {
				void* pattern_gettexture;
				if (Utils::File::getVersion() == _("1.21.80"))
					pattern_gettexture = Utils::Memory::FindPattern(_("40 53 55 56 57 41 54 41 55 41 56 41 57 48 81 EC F8 00 00 00 48 8B 05 C5 9F"));
				else if (Utils::File::getVersion() == _("1.21.73"))
					pattern_gettexture = Utils::Memory::FindPattern(_("48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57 48 81 EC F0 00 00 00 48 8B 05 E2"));
				else if (Utils::File::getVersion() == _("1.21.72"))
					pattern_gettexture = Utils::Memory::FindPattern(_("48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57 48 81 EC F0 00 00 00 48 8B 05 92"));
				else if (Utils::File::getVersion() == _("1.21.71"))
					pattern_gettexture = Utils::Memory::FindPattern(_("48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57 48 81 EC F0 00 00 00 48 8B 05 B2"));
				else if (Utils::File::getVersion() == _("1.21.70"))
					pattern_gettexture = Utils::Memory::FindPattern(_("48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57 48 81 EC F0 00 00 00 48 8B 05 C2"));
				else
					pattern_gettexture = Utils::Memory::FindPattern(_("48 89 5C 24 20 55 56 57 41 54 41 55 41 56 41 57 48 81 EC F0 00 00 00 48 8B 05 C2"));

				state = Utils::Memory::CreateHook(pattern_gettexture, (void*)&callback_gettexture, &texturegroup_gettexture);

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