#include "Mouse.h"
#include "Client.h"
#include "Mod/Mod.h"

#include "Datas/UserDatas.h"

void Hooks::Mouse::callback(void* _this, char button, char action, short x, short y, short movex, short movey, char a8) {
	if (ImGui::GetCurrentContext()) {
		if (button == 1)
			ImGui::GetIO().MouseDown[0] = static_cast<int>(action) == 1;
		else if (button == 2)
			ImGui::GetIO().MouseDown[1] = static_cast<int>(action) == 1;

		ImGui::GetIO().MousePos = ImVec2(x, y);
	}

    bool cancel = false;
    for (Mod* mod : Client::modlist) {
        if (!mod->enabled && mod->onlyenabled)continue;
        
        mod->onMouse(button, action, &cancel);
    }

	if (button == 4) {
		Client::mousescrolling = true;

		Client::mousedirection = static_cast<int>(action) == 120;
	}
	else {
		Client::mousescrolling = false;
	}

	Client::mousecontroller = _this;
	Client::mousex = x;
	Client::mousey = y;
	Client::mousemovx = movex;
	Client::mousemovy = movey;

	if (Client::cancelInputs) return;
	if (Client::forceCancelinputs) return;

	if (!cancel)
		mouse(_this, button, action, x, y, movex, movey, a8);
}
