Ryan-rsm-McKenzie / CommonLibSSE

A reverse engineered library for hacking Skyrim Special Edition

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Same functions works at SKSE64 library but not works at CommonLibSSE.

max-su-2019 opened this issue · comments

I tried to create a DisableCrosshair function and register it as a papyrus function into the game.

I did in "SKSE64 Library" and everythings worked propertly, the codes are as below:

void DisableCrosshair(StaticFunctionTag* base)
{
	auto menu = MenuManager::GetSingleton()->GetMenu(&UIStringHolder::GetSingleton()->hudMenu);

	if (menu && menu->view)
	{
		GFxValue result;
		GFxValue args[2];

		args[0].SetString("SetCrosshairEnabled");
		args[1].SetBool(false);

		menu->view->Invoke("call", &result, static_cast<GFxValue*>(args), 2);
	}

}

Then I tried to reproduce the function in CommonLib, but it seems didn't work at all:

void DisableCrosshair(RE::StaticFunctionTag*)
{
	auto menu = RE::UI::GetSingleton()->GetMenu(RE::InterfaceStrings::GetSingleton()->hudMenu);

	if (menu && menu->uiMovie)
	{
	        RE::GFxValue result;
		RE::GFxValue args[2];

		args[0].SetString("SetCrosshairEnabled");
		args[1].SetBoolean(false);

		menu->uiMovie->Invoke("call", &result, static_cast<RE::GFxValue*>(args), 2);

		//logger::debug("Start Disable Crosshair!");
	}

		//logger::debug("Disable Crosshair!")
}

I consider the functions I called were same in both case, but the result is different.

Is there anything wrong at the codes I writted? Would you give me some suggestion on that? Thanks!

Okay, finally figure that out. It really has so many difference :

	bool DisableCrosshair()
	{
		static const std::string FuncName = "SetCrosshairEnabled";

		logger::debug("Disable Crosshair Function!");

		auto hud = RE::UI::GetSingleton()->GetMenu<RE::HUDMenu>();

		if (!hud) 
		{
			logger::debug("Hud menu is not open!");
			return false;
		}

		auto view = hud ? hud->uiMovie : nullptr;
		auto delegate = hud ? hud->fxDelegate : nullptr;

		if (view && delegate)
		{
			logger::debug("Start Disable Crosshair!");

			RE::FxResponseArgsEx<1> arg;
			arg[0].SetBoolean(false);

			delegate->Invoke(view.get(), FuncName.c_str(), arg);

			logger::debug("Disable Crosshair Successfully!");
			return true;
		}

		logger::debug("Fail to Disable Crosshair!");
		return false;
	}