#include "STDInc.hpp"

namespace Components
{
	void Branding::DrawClientVersion()
	{
		if (Dvars::Functions::Dvar_FindVar("cg_drawBrandingInfo")->current.enabled)
		{
			const char* text = "IW3SP-MOD " VERSION;

			float alpha = 0.65f + 0.075f * std::sin(0.001f * Game::Sys_MilliSeconds());
			const float color[4] = { 0.83f, 0.92f, 0.81f, alpha };
			const float glowColor[4] = { 0.37f, 0.72f, 0.4f, alpha };

			const float fontScale = 0.2f;

			auto* const placement = Game::ScrPlace_GetUnsafeFullPlacement();
			const char* fontname = Game::UI_GetFontHandle(placement, fontScale);
			Game::Font_s* fontHandle = Game::R_RegisterFont("fonts/objectiveFont", sizeof("fonts/objectiveFont"));

			const auto width = Game::UI_TextWidth(text, 0, fontHandle, fontScale);
			const auto height = Game::UI_TextHeight(fontHandle, fontScale);

			float offs_x = 2.5f;
			float offs_y = 13.5f;

			Game::UI_DrawTextWithGlow(1, 1, placement, text, fontHandle, offs_x, offs_y, fontScale, color, 3, glowColor, 0, 0);
		}
	}

	void Branding::VersionOfTheGameStub()
	{
		Branding::DrawClientVersion();
		Utils::Hook::Call<void()>(0x438B20)();
	}

	Branding::Branding()
	{
		//Branding stuffs
		// Game window name
		Utils::Hook::Set<const char*>(0x5D9680, "IW3SP-MOD");
		// Game console name (external console)
		Utils::Hook::Set<const char*>(0x5963F7, "IW3SP Modification");

		// Game console name (~)
		Utils::Hook::Set<const char*>(0x43B9E1, "IW3SP-MOD: > ");
		// Short version
		Utils::Hook::Set<const char*>(0x534FE3, "1.5");

		Utils::Hook::Set<const char*>(0x53535E, "// generated by IW3SP-MOD\n");
		Utils::Hook::Set<const char*>(0x5353F0, "// generated by IW3SP-MOD\n");

		// SCR_UpdateFrame hooking
		Utils::Hook(0x447888, VersionOfTheGameStub, HOOK_CALL).install()->quick();
	}

	Branding::~Branding()
	{
	}
}