mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-06-15 17:32:56 +00:00
Add F2 screenshot functionality and image writing support
- Updated `EControllerActions` to include `MINECRAFT_ACTION_SCREENSHOT`. - Added conditional compilation for `stb_image_write.h` in `Minecraft.cpp`. - Modified `run_middle()` to handle screenshot key press. - Updated `tick()` to capture and save screenshots as PNG files. - Introduced `KEY_SCREENSHOT` in `KeyboardMouseInput.h` mapped to F2. - Added `stb_image_write.h` for image writing capabilities.
This commit is contained in:
parent
ae006e03f4
commit
6aea7c4bb7
|
|
@ -879,7 +879,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
|
||||
|
|
|
|||
|
|
@ -73,6 +73,11 @@
|
|||
#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"
|
||||
#endif
|
||||
|
|
@ -1549,6 +1554,9 @@ void Minecraft::run_middle()
|
|||
localplayers[i]->ullButtonsPressed|=1LL<<MINECRAFT_ACTION_RENDER_DEBUG;
|
||||
}
|
||||
|
||||
if(g_KBMInput.IsKeyPressed(KeyboardMouseInput::KEY_SCREENSHOT))
|
||||
localplayers[i]->ullButtonsPressed|=1LL<<MINECRAFT_ACTION_SCREENSHOT;
|
||||
|
||||
// In flying mode, Shift held = sneak/descend
|
||||
if(g_KBMInput.IsKBMActive() && g_KBMInput.IsKeyDown(KeyboardMouseInput::KEY_SNEAK))
|
||||
{
|
||||
|
|
@ -3737,6 +3745,78 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures)
|
|||
//options->thirdPersonView = !options->thirdPersonView;
|
||||
}
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
if(player->ullButtonsPressed&(1LL<<MINECRAFT_ACTION_SCREENSHOT))
|
||||
{
|
||||
extern ID3D11Device* g_pd3dDevice;
|
||||
extern ID3D11DeviceContext* g_pImmediateContext;
|
||||
extern IDXGISwapChain* g_pSwapChain;
|
||||
|
||||
ID3D11Texture2D* pBackBuffer = nullptr;
|
||||
HRESULT hr = g_pSwapChain->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<<MINECRAFT_ACTION_GAME_INFO)) && gameMode->isInputAllowed(MINECRAFT_ACTION_GAME_INFO))
|
||||
{
|
||||
ui.NavigateToScene(iPad,eUIScene_InGameInfoMenu);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ public:
|
|||
static const int KEY_THIRD_PERSON = VK_F5;
|
||||
static const int KEY_DEBUG_INFO = VK_F3;
|
||||
static const int KEY_DEBUG_MENU = VK_F4;
|
||||
static const int KEY_SCREENSHOT = VK_F2;
|
||||
|
||||
void Init();
|
||||
void Tick();
|
||||
|
|
|
|||
1724
Minecraft.Client/Windows64/stb_image_write.h
Normal file
1724
Minecraft.Client/Windows64/stb_image_write.h
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue