#include "Level.h"

auto Level::getRuntimeActorList() -> std::vector<Actor*> {
	std::vector<Actor*> callback;
	static auto func = reinterpret_cast<void(__thiscall*)(void*, decltype(&callback))>((*reinterpret_cast<void***>(this))[310]);
	func(this, &callback);
	return callback;
}

auto Level::forEachPlayer(std::function<bool(Player&)> callback) -> void {
	if (Utils::File::getVersion() == _("1.21.80"))
		static auto func = reinterpret_cast<void(__thiscall*)(void*, std::function<bool(Player&)>)>((*reinterpret_cast<void***>(this))[213]);
	else if (Utils::File::getVersion() == _("1.21.73"))
		static auto func = reinterpret_cast<void(__thiscall*)(void*, std::function<bool(Player&)>)>((*reinterpret_cast<void***>(this))[214]);
	else if (Utils::File::getVersion() == _("1.21.72"))
		static auto func = reinterpret_cast<void(__thiscall*)(void*, std::function<bool(Player&)>)>((*reinterpret_cast<void***>(this))[214]);
	else if (Utils::File::getVersion() == _("1.21.71"))
		static auto func = reinterpret_cast<void(__thiscall*)(void*, std::function<bool(Player&)>)>((*reinterpret_cast<void***>(this))[214]);
	else if (Utils::File::getVersion() == _("1.21.70"))
		static auto func = reinterpret_cast<void(__thiscall*)(void*, std::function<bool(Player&)>)>((*reinterpret_cast<void***>(this))[214]);
	else
		static auto func = reinterpret_cast<void(__thiscall*)(void*, std::function<bool(Player&)>)>((*reinterpret_cast<void***>(this))[214]);
}

auto Level::getHitResult() -> HitResult& {
	if (Utils::File::getVersion() == _("1.21.80"))
		return **reinterpret_cast<std::shared_ptr<HitResult>*>((uintptr_t)this + 0x240);
	else if (Utils::File::getVersion() == _("1.21.73"))
		return **reinterpret_cast<std::shared_ptr<HitResult>*>((uintptr_t)this + 0x240);
	else if (Utils::File::getVersion() == _("1.21.72"))
		return **reinterpret_cast<std::shared_ptr<HitResult>*>((uintptr_t)this + 0x240);
	else if (Utils::File::getVersion() == _("1.21.71"))
		return **reinterpret_cast<std::shared_ptr<HitResult>*>((uintptr_t)this + 0x240);
	else if (Utils::File::getVersion() == _("1.21.70"))
		return **reinterpret_cast<std::shared_ptr<HitResult>*>((uintptr_t)this + 0x240);
	else
		return **reinterpret_cast<std::shared_ptr<HitResult>*>((uintptr_t)this + 0x248);
}
