2018/12/3的最新ImGui做內部DLL嵌入式UI時,CSGO進遊戲不繪圖

2018/12/3的最新ImGui做內部DLL嵌入式UI時,CSGO進遊戲不繪圖,解決方法:

繪圖框架:

      	static HRESULT __stdcall hookedPresent(IDirect3DDevice9* device, 
   const RECT* src, const RECT* dest, HWND windowOverride, const   
   RGNDATA* dirtyRegion) noexcept { 	static bool isInitialised{
   false };
   if (!isInitialised) { 		ImGui::CreateContext();
      		ImGui_ImplWin32_Init(FindWindowA("Valve001", NULL));
      		ImGui_ImplDX9_Init(device);
      
      		ImGui::StyleColorsDark(); 		ImGuiStyle& style = ImGui::GetStyle();
      		style.WindowRounding = 0.0f; 		style.WindowBorderSize = 0.0f;
      		style.ChildBorderSize = 0.0f; 		ImGuiIO& io = ImGui::GetIO();
      		io.IniFilename = nullptr; 		io.LogFilename = nullptr; 		char    buffer[MAX_PATH]; 		GetWindowsDirectoryA(buffer, MAX_PATH);
      		io.Fonts->AddFontFromFileTTF(std::string{ buffer + std::string{    "\\Fonts\\Tahoma.ttf" } }.c_str(), 16.0f);
      
      		HookMessage(); 		isInitialised = true; 	} 	else if (open) { 		DWORD    d3rsColorWrite;
   		device->GetRenderState(D3DRS_COLORWRITEENABLE,   
   &d3rsColorWrite); 		IDirect3DVertexDeclaration9*
   vertexDeclaration;
      		device->GetVertexDeclaration(&vertexDeclaration);
      		IDirect3DVertexShader9* vertexShader;
      		device->GetVertexShader(&vertexShader);
      		device->SetRenderState(D3DRS_COLORWRITEENABLE, 0xffffffff);
      		device->SetRenderState(D3DRS_SRGBWRITEENABLE, false);
      		device->SetSamplerState(NULL, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
      		device->SetSamplerState(NULL, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
      		device->SetSamplerState(NULL, D3DSAMP_ADDRESSW, D3DTADDRESS_WRAP);
      		device->SetSamplerState(NULL, D3DSAMP_SRGBTEXTURE, NULL);
      
      		ImGui_ImplDX9_NewFrame(); 		ImGui_ImplWin32_NewFrame();
      		ImGui::NewFrame();
      
      		ImGui::GetIO().MouseDrawCursor = false; 		{ 			static float f =
      0.0f; 			static int counter = 0;
      
      			ImGui::Begin("Hello, world!");                          // Create    a window called "Hello, world!" and append into it.
      
      			ImGui::Text("This is some useful text.");               // Display    some text (you can use a format strings too)
      
      			ImGui::SliderFloat("float", &f, 0.0f, 1.0f);            // Edit 1    float using a slider from 0.0f to 1.0f    
      
      			if (ImGui::Button("Button"))                            // Buttons    return true when clicked (most widgets return true
   when   edited/activated)
      				counter++; 			ImGui::SameLine(); 			ImGui::Text("counter = %d", counter);
      
      			ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
      1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); 			ImGui::End(); 		}
      
      		ImGui::EndFrame(); 		ImGui::Render();
      		ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
      
      		device->SetRenderState(D3DRS_COLORWRITEENABLE, d3rsColorWrite);
      		device->SetRenderState(D3DRS_SRGBWRITEENABLE, true);
      		device->SetVertexDeclaration(vertexDeclaration);
      		device->SetVertexShader(vertexShader); 	} 	return    originalPresent(device, src, dest, windowOverride, dirtyRegion);
   }

不接收鼠標消息:

VS2017直接搜源文件,格式:

if (::GetActiveWindow() == g_hWnd && ::GetCursorPos(&pos))

改成

if (/*::GetActiveWindow() == g_hWnd &&*/ ::GetCursorPos(&pos))

OK了。內部就可以正常使用ImGui UI了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章