2017-06-05 02:02:04 +02:00
|
|
|
/*
|
|
|
|
|
* This file is part of Luma3DS
|
2020-04-25 13:26:21 +01:00
|
|
|
* Copyright (C) 2016-2020 Aurora Wright, TuxSH
|
2017-06-05 02:02:04 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
|
|
|
* * Requiring preservation of specified reasonable legal notices or
|
|
|
|
|
* author attributions in that material or in the Appropriate Legal
|
|
|
|
|
* Notices displayed by works containing it.
|
|
|
|
|
* * Prohibiting misrepresentation of the origin of that material,
|
|
|
|
|
* or requiring that modified versions of such material be marked in
|
|
|
|
|
* reasonable ways as different from the original version.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <3ds.h>
|
2017-11-18 16:37:35 +01:00
|
|
|
#include <3ds/os.h>
|
2017-06-05 02:02:04 +02:00
|
|
|
#include "menus.h"
|
|
|
|
|
#include "menu.h"
|
|
|
|
|
#include "draw.h"
|
|
|
|
|
#include "menus/process_list.h"
|
|
|
|
|
#include "menus/n3ds.h"
|
|
|
|
|
#include "menus/debugger.h"
|
|
|
|
|
#include "menus/miscellaneous.h"
|
2017-07-23 22:44:14 -04:00
|
|
|
#include "menus/sysconfig.h"
|
2018-04-15 04:51:47 +02:00
|
|
|
#include "menus/screen_filters.h"
|
2023-07-14 20:08:07 +02:00
|
|
|
#include "plugin.h"
|
2017-06-05 02:02:04 +02:00
|
|
|
#include "ifile.h"
|
|
|
|
|
#include "memory.h"
|
|
|
|
|
#include "fmt.h"
|
2020-05-16 02:37:47 +01:00
|
|
|
#include "process_patches.h"
|
2023-02-05 16:34:37 +00:00
|
|
|
#include "luma_config.h"
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
|
Menu rosalinaMenu = {
|
|
|
|
|
"Rosalina menu",
|
|
|
|
|
{
|
2020-05-15 02:29:17 +01:00
|
|
|
{ "Take screenshot", METHOD, .method = &RosalinaMenu_TakeScreenshot },
|
2024-09-09 00:44:48 +02:00
|
|
|
{ "Screen filters...", MENU, .menu = &screenFiltersMenu },
|
2018-04-05 23:40:18 +02:00
|
|
|
{ "Cheats...", METHOD, .method = &RosalinaMenu_Cheats },
|
2023-07-14 20:08:07 +02:00
|
|
|
{ "", METHOD, .method = PluginLoader__MenuCallback},
|
2024-09-09 00:44:48 +02:00
|
|
|
{ "New 3DS menu...", MENU, .menu = &N3DSMenu, .visibility = &menuCheckN3ds },
|
2017-06-05 02:02:04 +02:00
|
|
|
{ "Process list", METHOD, .method = &RosalinaMenu_ProcessList },
|
|
|
|
|
{ "Debugger options...", MENU, .menu = &debuggerMenu },
|
2017-07-23 22:44:14 -04:00
|
|
|
{ "System configuration...", MENU, .menu = &sysconfigMenu },
|
2017-06-05 02:02:04 +02:00
|
|
|
{ "Miscellaneous options...", MENU, .menu = &miscellaneousMenu },
|
2023-02-05 16:34:37 +00:00
|
|
|
{ "Save settings", METHOD, .method = &RosalinaMenu_SaveSettings },
|
2024-09-18 22:36:04 +02:00
|
|
|
{ "Power off / reboot", METHOD, .method = &RosalinaMenu_PowerOffOrReboot },
|
2024-08-14 22:48:33 +02:00
|
|
|
{ "System info", METHOD, .method = &RosalinaMenu_ShowSystemInfo },
|
2020-05-17 16:42:44 +01:00
|
|
|
{ "Credits", METHOD, .method = &RosalinaMenu_ShowCredits },
|
2020-05-17 22:48:26 +01:00
|
|
|
{ "Debug info", METHOD, .method = &RosalinaMenu_ShowDebugInfo, .visibility = &rosalinaMenuShouldShowDebugInfo },
|
2020-05-17 16:42:44 +01:00
|
|
|
{},
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-17 22:48:26 +01:00
|
|
|
bool rosalinaMenuShouldShowDebugInfo(void)
|
|
|
|
|
{
|
2020-07-15 22:24:08 +01:00
|
|
|
// Don't show on release builds
|
|
|
|
|
|
|
|
|
|
s64 out;
|
|
|
|
|
svcGetSystemInfo(&out, 0x10000, 0x200);
|
|
|
|
|
return out == 0;
|
2020-05-17 22:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-05 16:34:37 +00:00
|
|
|
void RosalinaMenu_SaveSettings(void)
|
|
|
|
|
{
|
|
|
|
|
Result res = LumaConfig_SaveSettings();
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, "Save settings");
|
|
|
|
|
if(R_SUCCEEDED(res))
|
|
|
|
|
Draw_DrawString(10, 30, COLOR_WHITE, "Operation succeeded.");
|
|
|
|
|
else
|
|
|
|
|
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08lx).", res);
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
}
|
|
|
|
|
while(!(waitInput() & KEY_B) && !menuShouldExit);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 22:36:04 +02:00
|
|
|
void RosalinaMenu_PowerOffOrReboot(void)
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, "Power Off / Reboot");
|
|
|
|
|
Draw_DrawString(10, 30, COLOR_WHITE, "Press A to power off.\nPress Y to reboot.\nPress B to go back.");
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
|
|
u32 pressed = waitInputWithTimeout(1000);
|
|
|
|
|
|
|
|
|
|
if(pressed & KEY_Y)
|
|
|
|
|
{
|
|
|
|
|
menuLeave();
|
|
|
|
|
APT_HardwareResetAsync();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if(pressed & KEY_A)
|
|
|
|
|
{
|
|
|
|
|
// Soft shutdown
|
|
|
|
|
menuLeave();
|
|
|
|
|
srvPublishToSubscriber(0x203, 0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if(pressed & KEY_B)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while(!menuShouldExit);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-14 22:48:33 +02:00
|
|
|
void RosalinaMenu_ShowSystemInfo(void)
|
|
|
|
|
{
|
|
|
|
|
u32 kver = osGetKernelVersion();
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, "Rosalina -- System info");
|
|
|
|
|
|
|
|
|
|
u32 posY = 30;
|
|
|
|
|
|
|
|
|
|
if (areScreenTypesInitialized)
|
|
|
|
|
{
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Top screen type: %s\n", topScreenType);
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Bottom screen type: %s\n\n", bottomScreenType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Kernel version: %lu.%lu-%lu\n\n", GET_VERSION_MAJOR(kver), GET_VERSION_MINOR(kver), GET_VERSION_REVISION(kver));
|
|
|
|
|
if (mcuFwVersion != 0 && mcuInfoTableRead)
|
|
|
|
|
{
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "MCU FW version: %lu.%lu\n", GET_VERSION_MAJOR(mcuFwVersion), GET_VERSION_MINOR(mcuFwVersion));
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "PMIC vendor: %hhu\n", mcuInfoTable[1]);
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Battery vendor: %hhu\n\n", mcuInfoTable[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
}
|
|
|
|
|
while(!(waitInput() & KEY_B) && !menuShouldExit);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-17 22:48:26 +01:00
|
|
|
void RosalinaMenu_ShowDebugInfo(void)
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
|
|
char memoryMap[512];
|
|
|
|
|
formatMemoryMapOfProcess(memoryMap, 511, CUR_PROCESS_HANDLE);
|
|
|
|
|
|
|
|
|
|
s64 kextAddrSize;
|
|
|
|
|
svcGetSystemInfo(&kextAddrSize, 0x10000, 0x300);
|
|
|
|
|
u32 kextPa = (u32)((u64)kextAddrSize >> 32);
|
|
|
|
|
u32 kextSize = (u32)kextAddrSize;
|
|
|
|
|
|
2021-02-01 02:51:14 +00:00
|
|
|
FS_SdMmcSpeedInfo speedInfo;
|
|
|
|
|
|
2020-05-17 22:48:26 +01:00
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, "Rosalina -- Debug info");
|
|
|
|
|
|
2024-08-14 22:48:33 +02:00
|
|
|
u32 posY = 30;
|
|
|
|
|
|
|
|
|
|
posY = Draw_DrawString(10, posY, COLOR_WHITE, memoryMap);
|
2021-01-07 01:37:46 +00:00
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Kernel ext PA: %08lx - %08lx\n\n", kextPa, kextPa + kextSize);
|
2021-02-01 02:51:14 +00:00
|
|
|
if (R_SUCCEEDED(FSUSER_GetSdmcSpeedInfo(&speedInfo)))
|
|
|
|
|
{
|
|
|
|
|
u32 clkDiv = 1 << (1 + (speedInfo.sdClkCtrl & 0xFF));
|
|
|
|
|
posY = Draw_DrawFormattedString(
|
|
|
|
|
10, posY, COLOR_WHITE, "SDMC speed: HS=%d %lukHz\n",
|
|
|
|
|
(int)speedInfo.highSpeedModeEnabled, SYSCLOCK_SDMMC / (1000 * clkDiv)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (R_SUCCEEDED(FSUSER_GetNandSpeedInfo(&speedInfo)))
|
|
|
|
|
{
|
|
|
|
|
u32 clkDiv = 1 << (1 + (speedInfo.sdClkCtrl & 0xFF));
|
|
|
|
|
posY = Draw_DrawFormattedString(
|
|
|
|
|
10, posY, COLOR_WHITE, "NAND speed: HS=%d %lukHz\n",
|
|
|
|
|
(int)speedInfo.highSpeedModeEnabled, SYSCLOCK_SDMMC / (1000 * clkDiv)
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-04-05 18:33:12 +01:00
|
|
|
{
|
|
|
|
|
posY = Draw_DrawFormattedString(
|
2023-01-03 15:30:07 +01:00
|
|
|
10, posY, COLOR_WHITE, "APPMEMTYPE: %lu\n",
|
|
|
|
|
OS_KernelConfig->app_memtype
|
2022-04-05 18:33:12 +01:00
|
|
|
);
|
|
|
|
|
}
|
2020-05-17 22:48:26 +01:00
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
}
|
|
|
|
|
while(!(waitInput() & KEY_B) && !menuShouldExit);
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
void RosalinaMenu_ShowCredits(void)
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, "Rosalina -- Luma3DS credits");
|
|
|
|
|
|
2024-05-01 23:49:33 +02:00
|
|
|
u32 posY = Draw_DrawString(10, 30, COLOR_WHITE, "Luma3DS (c) 2016-2024 AuroraWright, TuxSH") + SPACING_Y;
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
|
posY = Draw_DrawString(10, posY + SPACING_Y, COLOR_WHITE, "3DSX loading code by fincs");
|
|
|
|
|
posY = Draw_DrawString(10, posY + SPACING_Y, COLOR_WHITE, "Networking code & basic GDB functionality by Stary");
|
|
|
|
|
posY = Draw_DrawString(10, posY + SPACING_Y, COLOR_WHITE, "InputRedirection by Stary (PoC by ShinyQuagsire)");
|
|
|
|
|
|
|
|
|
|
posY += 2 * SPACING_Y;
|
|
|
|
|
|
|
|
|
|
Draw_DrawString(10, posY, COLOR_WHITE,
|
|
|
|
|
(
|
|
|
|
|
"Special thanks to:\n"
|
2020-07-15 22:24:08 +01:00
|
|
|
" fincs, WinterMute, mtheall, piepie62,\n"
|
|
|
|
|
" Luma3DS contributors, libctru contributors,\n"
|
2017-06-05 02:02:04 +02:00
|
|
|
" other people"
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
}
|
2020-05-15 20:00:13 +01:00
|
|
|
while(!(waitInput() & KEY_B) && !menuShouldExit);
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define TRY(expr) if(R_FAILED(res = (expr))) goto end;
|
|
|
|
|
|
2020-05-08 16:03:37 +01:00
|
|
|
static s64 timeSpentConvertingScreenshot = 0;
|
|
|
|
|
static s64 timeSpentWritingScreenshot = 0;
|
|
|
|
|
|
2020-07-05 18:44:22 +01:00
|
|
|
static Result RosalinaMenu_WriteScreenshot(IFile *file, u32 width, bool top, bool left)
|
2020-05-08 16:03:37 +01:00
|
|
|
{
|
2017-06-05 02:02:04 +02:00
|
|
|
u64 total;
|
2020-05-08 16:03:37 +01:00
|
|
|
Result res = 0;
|
2020-07-05 18:44:22 +01:00
|
|
|
u32 lineSize = 3 * width;
|
2024-06-22 01:22:22 +02:00
|
|
|
|
|
|
|
|
// When dealing with 800px mode (800x240 with half-width pixels), duplicate each line
|
|
|
|
|
// to restore aspect ratio and obtain faithful 800x480 screenshots
|
|
|
|
|
u32 scaleFactorY = width > 400 ? 2 : 1;
|
|
|
|
|
u32 numLinesScaled = 240 * scaleFactorY;
|
|
|
|
|
u32 remaining = lineSize * numLinesScaled;
|
2020-07-05 18:44:22 +01:00
|
|
|
|
|
|
|
|
TRY(Draw_AllocateFramebufferCacheForScreenshot(remaining));
|
|
|
|
|
|
2020-05-08 16:03:37 +01:00
|
|
|
u8 *framebufferCache = (u8 *)Draw_GetFramebufferCache();
|
|
|
|
|
u8 *framebufferCacheEnd = framebufferCache + Draw_GetFramebufferCacheSize();
|
|
|
|
|
|
|
|
|
|
u8 *buf = framebufferCache;
|
2024-06-22 01:22:22 +02:00
|
|
|
Draw_CreateBitmapHeader(framebufferCache, width, numLinesScaled);
|
2020-05-08 16:03:37 +01:00
|
|
|
buf += 54;
|
|
|
|
|
|
2020-05-08 18:19:17 +01:00
|
|
|
u32 y = 0;
|
2020-05-08 16:03:37 +01:00
|
|
|
// Our buffer might be smaller than the size of the screenshot...
|
|
|
|
|
while (remaining != 0)
|
|
|
|
|
{
|
|
|
|
|
s64 t0 = svcGetSystemTick();
|
|
|
|
|
u32 available = (u32)(framebufferCacheEnd - buf);
|
|
|
|
|
u32 size = available < remaining ? available : remaining;
|
2024-06-22 01:22:22 +02:00
|
|
|
u32 nlines = size / (lineSize * scaleFactorY);
|
|
|
|
|
Draw_ConvertFrameBufferLines(buf, width, y, nlines, scaleFactorY, top, left);
|
2020-05-08 16:03:37 +01:00
|
|
|
|
|
|
|
|
s64 t1 = svcGetSystemTick();
|
|
|
|
|
timeSpentConvertingScreenshot += t1 - t0;
|
2024-06-22 01:22:22 +02:00
|
|
|
TRY(IFile_Write(file, &total, framebufferCache, (y == 0 ? 54 : 0) + lineSize * nlines * scaleFactorY, 0)); // don't forget to write the header
|
2020-05-08 16:03:37 +01:00
|
|
|
timeSpentWritingScreenshot += svcGetSystemTick() - t1;
|
|
|
|
|
|
2020-05-08 18:19:17 +01:00
|
|
|
y += nlines;
|
2024-06-22 01:22:22 +02:00
|
|
|
remaining -= lineSize * nlines * scaleFactorY;
|
2020-05-08 16:03:37 +01:00
|
|
|
buf = framebufferCache;
|
|
|
|
|
}
|
2020-07-05 18:44:22 +01:00
|
|
|
end:
|
|
|
|
|
|
|
|
|
|
Draw_FreeFramebufferCache();
|
|
|
|
|
return res;
|
2020-05-08 16:03:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RosalinaMenu_TakeScreenshot(void)
|
|
|
|
|
{
|
2024-09-23 00:32:48 +02:00
|
|
|
IFile file = {0};
|
2020-05-08 16:03:37 +01:00
|
|
|
Result res = 0;
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
|
char filename[64];
|
2023-01-11 23:24:59 +00:00
|
|
|
char dateTimeStr[32];
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
|
FS_Archive archive;
|
|
|
|
|
FS_ArchiveID archiveId;
|
|
|
|
|
s64 out;
|
|
|
|
|
bool isSdMode;
|
2017-06-18 22:31:21 +02:00
|
|
|
|
2020-05-08 16:03:37 +01:00
|
|
|
timeSpentConvertingScreenshot = 0;
|
|
|
|
|
timeSpentWritingScreenshot = 0;
|
|
|
|
|
|
2017-06-18 22:31:21 +02:00
|
|
|
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x203))) svcBreak(USERBREAK_ASSERT);
|
2017-06-05 02:02:04 +02:00
|
|
|
isSdMode = (bool)out;
|
|
|
|
|
|
|
|
|
|
archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_RestoreFramebuffer();
|
2020-07-05 18:44:22 +01:00
|
|
|
Draw_FreeFramebufferCache();
|
2017-06-05 02:02:04 +02:00
|
|
|
|
2017-06-20 16:14:36 +02:00
|
|
|
svcFlushEntireDataCache();
|
|
|
|
|
|
2020-07-05 18:44:22 +01:00
|
|
|
bool is3d;
|
|
|
|
|
u32 topWidth, bottomWidth; // actually Y-dim
|
|
|
|
|
|
|
|
|
|
Draw_GetCurrentScreenInfo(&bottomWidth, &is3d, false);
|
|
|
|
|
Draw_GetCurrentScreenInfo(&topWidth, &is3d, true);
|
|
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
res = FSUSER_OpenArchive(&archive, archiveId, fsMakePath(PATH_EMPTY, ""));
|
|
|
|
|
if(R_SUCCEEDED(res))
|
|
|
|
|
{
|
|
|
|
|
res = FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, "/luma/screenshots"), 0);
|
|
|
|
|
if((u32)res == 0xC82044BE) // directory already exists
|
|
|
|
|
res = 0;
|
|
|
|
|
FSUSER_CloseArchive(archive);
|
|
|
|
|
}
|
2024-09-23 00:32:48 +02:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
archive = 0;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
2017-06-05 02:02:04 +02:00
|
|
|
|
2023-01-11 23:24:59 +00:00
|
|
|
dateTimeToString(dateTimeStr, osGetTime(), true);
|
2017-06-05 02:02:04 +02:00
|
|
|
|
2023-01-11 23:24:59 +00:00
|
|
|
sprintf(filename, "/luma/screenshots/%s_top.bmp", dateTimeStr);
|
2017-06-05 02:02:04 +02:00
|
|
|
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
|
2020-07-05 18:44:22 +01:00
|
|
|
TRY(RosalinaMenu_WriteScreenshot(&file, topWidth, true, true));
|
2017-06-05 02:02:04 +02:00
|
|
|
TRY(IFile_Close(&file));
|
|
|
|
|
|
2023-01-11 23:24:59 +00:00
|
|
|
sprintf(filename, "/luma/screenshots/%s_bot.bmp", dateTimeStr);
|
2017-06-05 02:02:04 +02:00
|
|
|
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
|
2020-07-05 18:44:22 +01:00
|
|
|
TRY(RosalinaMenu_WriteScreenshot(&file, bottomWidth, false, true));
|
2017-06-20 16:14:36 +02:00
|
|
|
TRY(IFile_Close(&file));
|
2017-06-05 02:02:04 +02:00
|
|
|
|
2020-07-05 18:44:22 +01:00
|
|
|
if(is3d && (Draw_GetCurrentFramebufferAddress(true, true) != Draw_GetCurrentFramebufferAddress(true, false)))
|
2017-06-05 02:02:04 +02:00
|
|
|
{
|
2023-01-11 23:24:59 +00:00
|
|
|
sprintf(filename, "/luma/screenshots/%s_top_right.bmp", dateTimeStr);
|
2017-06-05 02:02:04 +02:00
|
|
|
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
|
2020-07-05 18:44:22 +01:00
|
|
|
TRY(RosalinaMenu_WriteScreenshot(&file, topWidth, true, false));
|
2017-06-20 16:14:36 +02:00
|
|
|
TRY(IFile_Close(&file));
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
IFile_Close(&file);
|
2020-07-05 18:44:22 +01:00
|
|
|
|
2024-09-23 00:32:48 +02:00
|
|
|
if (archive != 0)
|
|
|
|
|
FSUSER_CloseArchive(archive);
|
|
|
|
|
|
2020-07-05 18:44:22 +01:00
|
|
|
if (R_FAILED(Draw_AllocateFramebufferCache(FB_BOTTOM_SIZE)))
|
|
|
|
|
__builtin_trap(); // We're f***ed if this happens
|
|
|
|
|
|
2017-06-20 16:14:36 +02:00
|
|
|
svcFlushEntireDataCache();
|
2017-06-05 02:02:04 +02:00
|
|
|
Draw_SetupFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, "Screenshot");
|
|
|
|
|
if(R_FAILED(res))
|
2018-05-24 00:55:38 +02:00
|
|
|
Draw_DrawFormattedString(10, 30, COLOR_WHITE, "Operation failed (0x%08lx).", (u32)res);
|
2017-06-05 02:02:04 +02:00
|
|
|
else
|
2020-05-08 16:03:37 +01:00
|
|
|
{
|
|
|
|
|
u32 t1 = (u32)(1000 * timeSpentConvertingScreenshot / SYSCLOCK_ARM11);
|
|
|
|
|
u32 t2 = (u32)(1000 * timeSpentWritingScreenshot / SYSCLOCK_ARM11);
|
|
|
|
|
u32 posY = 30;
|
|
|
|
|
posY = Draw_DrawString(10, posY, COLOR_WHITE, "Operation succeeded.\n\n");
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Time spent converting: %5lums\n", t1);
|
|
|
|
|
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Time spent writing files: %5lums\n", t2);
|
|
|
|
|
}
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
Draw_Unlock();
|
|
|
|
|
}
|
2020-05-15 20:00:13 +01:00
|
|
|
while(!(waitInput() & KEY_B) && !menuShouldExit);
|
2024-09-23 00:32:48 +02:00
|
|
|
}
|
2017-06-05 02:02:04 +02:00
|
|
|
|
2024-09-23 00:32:48 +02:00
|
|
|
static Result menuWriteSelfScreenshot(IFile *file)
|
|
|
|
|
{
|
|
|
|
|
u64 total;
|
|
|
|
|
Result res = 0;
|
|
|
|
|
|
|
|
|
|
u32 width = 320;
|
|
|
|
|
u32 lineSize = 3 * width;
|
|
|
|
|
|
|
|
|
|
u32 scaleFactorY = 1;
|
|
|
|
|
u32 numLinesScaled = 240 * scaleFactorY;
|
|
|
|
|
|
|
|
|
|
u32 addr = 0x0D800000; // keep this in check
|
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
|
|
u32 size = ((54 + lineSize * numLinesScaled * scaleFactorY) + 0xFFF) >> 12 << 12; // round-up
|
|
|
|
|
u8 *buffer = NULL;
|
|
|
|
|
|
|
|
|
|
TRY(svcControlMemoryEx(&tmp, addr, 0, size, MEMOP_ALLOC | MEMOP_REGION_SYSTEM, MEMPERM_READWRITE, true));
|
|
|
|
|
buffer = (u8 *)addr;
|
|
|
|
|
|
|
|
|
|
Draw_CreateBitmapHeader(buffer, width, numLinesScaled);
|
|
|
|
|
|
|
|
|
|
Draw_ConvertFrameBufferLines(buffer + 54, width, 0, numLinesScaled, scaleFactorY, false, false);
|
|
|
|
|
TRY(IFile_Write(file, &total, buffer, 54 + lineSize * numLinesScaled * scaleFactorY, 0)); // don't forget to write the header
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
if (buffer)
|
|
|
|
|
svcControlMemoryEx(&tmp, addr, 0, size, MEMOP_FREE, MEMPERM_DONTCARE, false);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void menuTakeSelfScreenshot(void)
|
|
|
|
|
{
|
|
|
|
|
// Optimized for N3DS. May fail due to OOM.
|
|
|
|
|
|
|
|
|
|
IFile file = {0};
|
|
|
|
|
Result res = 0;
|
|
|
|
|
|
|
|
|
|
char filename[100];
|
|
|
|
|
char dateTimeStr[64];
|
|
|
|
|
|
|
|
|
|
FS_Archive archive;
|
|
|
|
|
FS_ArchiveID archiveId;
|
|
|
|
|
s64 out;
|
|
|
|
|
bool isSdMode;
|
|
|
|
|
|
|
|
|
|
timeSpentConvertingScreenshot = 0;
|
|
|
|
|
timeSpentWritingScreenshot = 0;
|
|
|
|
|
|
|
|
|
|
if(R_FAILED(svcGetSystemInfo(&out, 0x10000, 0x203))) svcBreak(USERBREAK_ASSERT);
|
|
|
|
|
isSdMode = (bool)out;
|
|
|
|
|
|
|
|
|
|
archiveId = isSdMode ? ARCHIVE_SDMC : ARCHIVE_NAND_RW;
|
|
|
|
|
Draw_Lock();
|
|
|
|
|
svcFlushEntireDataCache();
|
|
|
|
|
|
|
|
|
|
res = FSUSER_OpenArchive(&archive, archiveId, fsMakePath(PATH_EMPTY, ""));
|
|
|
|
|
if(R_SUCCEEDED(res))
|
|
|
|
|
{
|
|
|
|
|
res = FSUSER_CreateDirectory(archive, fsMakePath(PATH_ASCII, "/luma/screenshots"), 0);
|
|
|
|
|
if((u32)res == 0xC82044BE) // directory already exists
|
|
|
|
|
res = 0;
|
|
|
|
|
FSUSER_CloseArchive(archive);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
archive = 0;
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dateTimeToString(dateTimeStr, osGetTime(), true);
|
|
|
|
|
|
|
|
|
|
sprintf(filename, "/luma/screenshots/rosalina_menu_%s.bmp", dateTimeStr);
|
|
|
|
|
|
|
|
|
|
TRY(IFile_Open(&file, archiveId, fsMakePath(PATH_EMPTY, ""), fsMakePath(PATH_ASCII, filename), FS_OPEN_CREATE | FS_OPEN_WRITE));
|
|
|
|
|
TRY(menuWriteSelfScreenshot(&file));
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
IFile_Close(&file);
|
|
|
|
|
|
|
|
|
|
if (archive != 0)
|
|
|
|
|
FSUSER_CloseArchive(archive);
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|
2024-09-23 00:32:48 +02:00
|
|
|
|
|
|
|
|
#undef TRY
|