From 1028ee2e6d021974424c18ae2fbb843f625a9735 Mon Sep 17 00:00:00 2001 From: neoapps-dev Date: Sun, 29 Mar 2026 18:29:04 +0300 Subject: [PATCH] fix: stb import --- Minecraft.Client/Common/App_enums.h | 3 +- Minecraft.Client/Minecraft.cpp | 79 +++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/Minecraft.Client/Common/App_enums.h b/Minecraft.Client/Common/App_enums.h index 73644ac5..1232a7c7 100644 --- a/Minecraft.Client/Common/App_enums.h +++ b/Minecraft.Client/Common/App_enums.h @@ -886,7 +886,8 @@ enum EControllerActions MINECRAFT_ACTION_SPAWN_CREEPER, MINECRAFT_ACTION_CHANGE_SKIN, MINECRAFT_ACTION_FLY_TOGGLE, - MINECRAFT_ACTION_RENDER_DEBUG + MINECRAFT_ACTION_RENDER_DEBUG, + MINECRAFT_ACTION_SCREENSHOT }; enum eMCLang diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index bf120b8b..2c483a8f 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -72,6 +72,10 @@ #include "Common/UI/IUIScene_CreativeMenu.h" #include "Common/UI/UIFontData.h" #include "DLCTexturePack.h" +#ifdef _WINDOWS64 +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "Windows64/stb_image_write.h" +#endif #ifdef __ORBIS__ #include "Orbis/Network/PsPlusUpsellWrapper_Orbis.h" @@ -1549,6 +1553,9 @@ void Minecraft::run_middle() localplayers[i]->ullButtonsPressed|=1LL<ullButtonsPressed|=1LL<thirdPersonView = !options->thirdPersonView; } +#ifdef _WINDOWS64 + if(player->ullButtonsPressed&(1LL<GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer); + if (SUCCEEDED(hr)) + { + D3D11_TEXTURE2D_DESC desc; + pBackBuffer->GetDesc(&desc); + desc.Usage = D3D11_USAGE_STAGING; + desc.BindFlags = 0; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + desc.MiscFlags = 0; + + ID3D11Texture2D* pStaging = nullptr; + hr = g_pd3dDevice->CreateTexture2D(&desc, nullptr, &pStaging); + if (SUCCEEDED(hr)) + { + g_pImmediateContext->CopyResource(pStaging, pBackBuffer); + + // Build path next to the executable + wchar_t exePath[MAX_PATH]; + GetModuleFileNameW(NULL, exePath, MAX_PATH); + wchar_t* lastSlash = wcsrchr(exePath, L'\\'); + if (lastSlash) *(lastSlash + 1) = L'\0'; + wstring screenshotDirPath = wstring(exePath) + L"screenshots"; + CreateDirectoryW(screenshotDirPath.c_str(), NULL); + + SYSTEMTIME st; + GetLocalTime(&st); + wchar_t filename[128]; + swprintf_s(filename, L"%04d-%02d-%02d_%02d.%02d.%02d.png", + st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); + wstring screenshotPath = screenshotDirPath + L"\\" + filename; + + D3D11_MAPPED_SUBRESOURCE mapped; + hr = g_pImmediateContext->Map(pStaging, 0, D3D11_MAP_READ, 0, &mapped); + if (SUCCEEDED(hr)) + { + // Copy RGBA rows (back buffer is R8G8B8A8_UNORM, already RGBA) + unsigned char* rgba = new unsigned char[desc.Width * desc.Height * 4]; + for (UINT row = 0; row < desc.Height; row++) + { + unsigned char* src = (unsigned char*)mapped.pData + row * mapped.RowPitch; + unsigned char* dst = rgba + row * desc.Width * 4; + memcpy(dst, src, desc.Width * 4); + } + g_pImmediateContext->Unmap(pStaging, 0); + + // Save PNG via stb_image_write + string narrowPath(screenshotPath.begin(), screenshotPath.end()); + int writeResult = stbi_write_png(narrowPath.c_str(), desc.Width, desc.Height, 4, rgba, desc.Width * 4); + delete[] rgba; + + // Local chat message — only on success + if (writeResult) + { + wstring msg = L"Saved screenshot to " + wstring(filename); + gui->addMessage(msg, iPad); + } + } + pStaging->Release(); + } + pBackBuffer->Release(); + } + } +#endif + if((player->ullButtonsPressed&(1LL<isInputAllowed(MINECRAFT_ACTION_GAME_INFO)) { ui.NavigateToScene(iPad,eUIScene_InGameInfoMenu);