bool ResourceUI::Create() { // get the metadata component fwRefContainer<fx::ResourceMetaDataComponent> metaData = m_resource->GetComponent<fx::ResourceMetaDataComponent>(); // get the UI page list and a number of pages auto uiPageData = metaData->GetEntries("ui_page"); int pageCount = std::distance(uiPageData.begin(), uiPageData.end()); // if no page exists, return if (pageCount == 0) { return false; } // if more than one, warn if (pageCount > 1) { trace(__FUNCTION__ ": more than one ui_page in resource %s\n", m_resource->GetName().c_str()); return false; } // mark us as having a frame m_hasFrame = true; // get the page name from the iterator std::string pageName = uiPageData.begin()->second; // initialize the page auto resourceName = m_resource->GetName(); std::transform(resourceName.begin(), resourceName.end(), resourceName.begin(), ::ToLower); CefRegisterSchemeHandlerFactory("http", resourceName, Instance<NUISchemeHandlerFactory>::Get()); // create the NUI frame std::string path = "nui://" + m_resource->GetName() + "/" + pageName; nui::CreateFrame(m_resource->GetName(), path); // add a cross-origin entry to allow fetching the callback handler CefAddCrossOriginWhitelistEntry(va("nui://%s", m_resource->GetName().c_str()), "http", m_resource->GetName(), true); return true; }
bool ResourceUI::Create() { auto& metaData = m_resource->GetMetaData(); auto it = metaData.find("uiPage"); CefRegisterSchemeHandlerFactory("http", m_resource->GetName(), nui::GetSchemeHandlerFactory()); if (it == metaData.end()) { return false; } std::string path = "nui://" + m_resource->GetName() + "/" + it->second; nui::CreateFrame(m_resource->GetName(), path); CefAddCrossOriginWhitelistEntry(va("nui://%s", m_resource->GetName().c_str()), "http", m_resource->GetName(), true); return true; }
void FinalizeInitNUI() { if (getenv("CitizenFX_ToolMode")) { return; } std::wstring cachePath = MakeRelativeCitPath(L"cache\\browser\\"); CreateDirectory(cachePath.c_str(), nullptr); // delete any old CEF logs DeleteFile(MakeRelativeCitPath(L"debug.log").c_str()); auto selfApp = Instance<NUIApp>::Get(); CefMainArgs args(GetModuleHandle(NULL)); CefRefPtr<CefApp> app(selfApp); CefSettings cSettings; cSettings.multi_threaded_message_loop = true; cSettings.remote_debugging_port = 13172; cSettings.pack_loading_disabled = false; // true; cSettings.windowless_rendering_enabled = false; // true; cSettings.log_severity = LOGSEVERITY_DISABLE; CefString(&cSettings.browser_subprocess_path).FromWString(MakeCfxSubProcess(L"ChromeBrowser")); CefString(&cSettings.locale).FromASCII("en-US"); std::wstring resPath = MakeRelativeCitPath(L"bin/cef/"); CefString(&cSettings.resources_dir_path).FromWString(resPath); CefString(&cSettings.locales_dir_path).FromWString(resPath); CefString(&cSettings.cache_path).FromWString(cachePath); // 2014-06-30: sandbox disabled as it breaks scheme handler factories (results in blank page being loaded) CefInitialize(args, cSettings, app.get(), /*cefSandbox*/ nullptr); CefRegisterSchemeHandlerFactory("nui", "", Instance<NUISchemeHandlerFactory>::Get()); CefAddCrossOriginWhitelistEntry("nui://game", "http", "", true); CefAddCrossOriginWhitelistEntry("nui://game", "nui", "", true); HookFunctionBase::RunAll(); #if defined(GTA_NY) OnGrcBeginScene.Connect([] () { Instance<NUIWindowManager>::Get()->ForAllWindows([] (fwRefContainer<NUIWindow> window) { window->UpdateFrame(); }); }); #else #endif //g_hooksDLL->SetHookCallback(StringHash("d3dCreate"), [] (void*) OnGrcCreateDevice.Connect([]() { //int resX = *(int*)0xFDCEAC; //int resY = *(int*)0xFDCEB0; int resX, resY; GetGameResolution(resX, resY); auto rootWindow = NUIWindow::Create(true, resX, resY, "nui://game/ui/root.html"); rootWindow->SetPaintType(NUIPaintTypePostRender); Instance<NUIWindowManager>::Get()->SetRootWindow(rootWindow); }); }