2022-02-04 15:05:17 +01:00
|
|
|
#include "modpackSelector.h"
|
2022-09-18 00:29:12 +02:00
|
|
|
#include "main.h"
|
|
|
|
#include "version.h"
|
2021-04-06 16:58:19 +02:00
|
|
|
#include <cstdarg>
|
|
|
|
#include <cstdio>
|
2022-02-04 15:05:17 +01:00
|
|
|
#include <cstring>
|
2021-04-06 16:58:19 +02:00
|
|
|
#include <malloc.h>
|
2022-02-04 15:05:17 +01:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2021-04-06 16:58:19 +02:00
|
|
|
|
2022-04-22 17:37:16 +02:00
|
|
|
#include <content_redirection/redirection.h>
|
2021-04-06 16:58:19 +02:00
|
|
|
#include <coreinit/thread.h>
|
|
|
|
#include <memory/mappedmemory.h>
|
|
|
|
|
|
|
|
#include <coreinit/screen.h>
|
2022-02-04 15:05:17 +01:00
|
|
|
#include <fs/DirList.h>
|
|
|
|
#include <utils/logger.h>
|
|
|
|
#include <vpad/input.h>
|
2021-04-06 16:58:19 +02:00
|
|
|
|
2022-02-04 15:05:17 +01:00
|
|
|
#define TEXT_SEL(x, text1, text2) ((x) ? (text1) : (text2))
|
2021-04-06 16:58:19 +02:00
|
|
|
|
|
|
|
void ReplaceContent(const std::string &basePath);
|
|
|
|
|
|
|
|
void HandleMultiModPacks(uint64_t titleID) {
|
|
|
|
char TitleIDString[17];
|
|
|
|
snprintf(TitleIDString, 17, "%016llX", titleID);
|
|
|
|
|
|
|
|
std::map<std::string, std::string> modTitlePath;
|
|
|
|
|
|
|
|
std::map<std::string, std::string> mounting_points;
|
|
|
|
|
|
|
|
std::string modTitleIDPath = std::string("fs:/vol/external01/sdcafiine/") + TitleIDString;
|
2022-04-22 17:37:16 +02:00
|
|
|
DirList modTitleDirList(modTitleIDPath, nullptr, DirList::Dirs);
|
2021-04-06 16:58:19 +02:00
|
|
|
|
|
|
|
modTitleDirList.SortList();
|
|
|
|
|
|
|
|
for (int index = 0; index < modTitleDirList.GetFilecount(); index++) {
|
|
|
|
std::string curFile = modTitleDirList.GetFilename(index);
|
2022-04-22 17:37:16 +02:00
|
|
|
|
|
|
|
if (curFile == "." || curFile == "..") {
|
2021-04-06 16:58:19 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:37:16 +02:00
|
|
|
const std::string &packageName = curFile;
|
|
|
|
modTitlePath[packageName] = modTitleIDPath.append("/").append(curFile);
|
|
|
|
DEBUG_FUNCTION_LINE_VERBOSE("Found %s", packageName.c_str());
|
2021-04-06 16:58:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (modTitlePath.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-04 15:05:17 +01:00
|
|
|
int selected = 0;
|
2021-04-06 16:58:19 +02:00
|
|
|
int initScreen = 1;
|
2022-02-04 15:05:17 +01:00
|
|
|
int x_offset = -2;
|
2021-04-06 16:58:19 +02:00
|
|
|
|
|
|
|
// Init screen and screen buffers
|
|
|
|
OSScreenInit();
|
|
|
|
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
|
|
|
|
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
|
2022-04-22 17:37:16 +02:00
|
|
|
auto *screenBuffer = (uint8_t *) MEMAllocFromMappedMemoryForGX2Ex(screen_buf0_size + screen_buf1_size, 0x100);
|
2021-04-06 16:58:19 +02:00
|
|
|
if (screenBuffer == nullptr) {
|
2022-04-22 17:37:16 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to alloc screenBuffer");
|
2021-04-06 16:58:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
OSScreenSetBufferEx(SCREEN_TV, (void *) screenBuffer);
|
|
|
|
OSScreenSetBufferEx(SCREEN_DRC, (void *) (screenBuffer + screen_buf0_size));
|
|
|
|
|
|
|
|
OSScreenEnableEx(SCREEN_TV, 1);
|
|
|
|
OSScreenEnableEx(SCREEN_DRC, 1);
|
|
|
|
|
|
|
|
// Clear screens
|
|
|
|
OSScreenClearBufferEx(SCREEN_TV, 0);
|
|
|
|
OSScreenClearBufferEx(SCREEN_DRC, 0);
|
|
|
|
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_TV);
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_DRC);
|
|
|
|
|
|
|
|
VPADStatus vpad_data;
|
|
|
|
VPADReadError error;
|
|
|
|
|
|
|
|
int wantToExit = 0;
|
2022-02-04 15:05:17 +01:00
|
|
|
int page = 0;
|
|
|
|
int per_page = 13;
|
|
|
|
int max_pages = (modTitlePath.size() / per_page) + 1;
|
2021-04-06 16:58:19 +02:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
|
|
|
error = VPAD_READ_NO_SAMPLES;
|
|
|
|
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &error);
|
|
|
|
|
|
|
|
if (error == VPAD_READ_SUCCESS) {
|
|
|
|
if (vpad_data.trigger & VPAD_BUTTON_A) {
|
|
|
|
wantToExit = 1;
|
|
|
|
initScreen = 1;
|
|
|
|
} else if (vpad_data.trigger & VPAD_BUTTON_B) {
|
|
|
|
break;
|
|
|
|
} else if (vpad_data.trigger & VPAD_BUTTON_DOWN) {
|
|
|
|
selected++;
|
|
|
|
initScreen = 1;
|
|
|
|
} else if (vpad_data.trigger & VPAD_BUTTON_UP) {
|
|
|
|
selected--;
|
|
|
|
initScreen = 1;
|
|
|
|
} else if (vpad_data.trigger & VPAD_BUTTON_L) {
|
|
|
|
selected -= per_page;
|
|
|
|
initScreen = 1;
|
|
|
|
} else if (vpad_data.trigger & VPAD_BUTTON_R) {
|
|
|
|
selected += per_page;
|
|
|
|
initScreen = 1;
|
|
|
|
}
|
|
|
|
if (selected < 0) { selected = 0; }
|
|
|
|
if (selected >= modTitlePath.size()) { selected = modTitlePath.size() - 1; }
|
|
|
|
page = selected / per_page;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initScreen) {
|
|
|
|
OSScreenClearBufferEx(SCREEN_TV, 0);
|
|
|
|
OSScreenClearBufferEx(SCREEN_DRC, 0);
|
2022-09-18 00:29:12 +02:00
|
|
|
console_print_pos(x_offset, -1, "SDCafiine plugin " VERSION VERSION_EXTRA);
|
2021-04-06 16:58:19 +02:00
|
|
|
console_print_pos(x_offset, 1, "Select your options and press A to launch.");
|
|
|
|
console_print_pos(x_offset, 2, "Press B to launch without mods");
|
|
|
|
int y_offset = 4;
|
2022-02-04 15:05:17 +01:00
|
|
|
int cur_ = 0;
|
2021-04-06 16:58:19 +02:00
|
|
|
|
|
|
|
for (auto &it : modTitlePath) {
|
2022-02-04 15:05:17 +01:00
|
|
|
std::string key = it.first;
|
2021-04-06 16:58:19 +02:00
|
|
|
std::string value = it.second;
|
|
|
|
|
|
|
|
if (wantToExit && cur_ == selected) {
|
|
|
|
ReplaceContent(value.append("/content"));
|
|
|
|
//snprintf(gModFolder, FS_MAX_ENTNAME_SIZE, "%s", value.c_str());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cur_ >= (page * per_page) && cur_ < ((page + 1) * per_page)) {
|
|
|
|
console_print_pos(x_offset, y_offset++, "%s %s", TEXT_SEL((selected == cur_), "--->", " "), key.c_str());
|
|
|
|
}
|
|
|
|
cur_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wantToExit) { //just in case.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_pages > 0) {
|
|
|
|
console_print_pos(x_offset, 17, "Page %02d/%02d. Press L/R to change page.", page + 1, max_pages);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flip buffers
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_TV);
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_DRC);
|
|
|
|
|
|
|
|
initScreen = 0;
|
|
|
|
}
|
|
|
|
OSSleepTicks(OSMillisecondsToTicks(100));
|
|
|
|
}
|
|
|
|
|
|
|
|
OSScreenClearBufferEx(SCREEN_TV, 0);
|
|
|
|
OSScreenClearBufferEx(SCREEN_DRC, 0);
|
|
|
|
|
|
|
|
// Flip buffers
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_TV);
|
|
|
|
OSScreenFlipBuffersEx(SCREEN_DRC);
|
|
|
|
|
|
|
|
MEMFreeToMappedMemory(screenBuffer);
|
|
|
|
}
|
2022-04-22 17:37:16 +02:00
|
|
|
extern CRLayerHandle contentLayerHandle;
|
2021-04-06 16:58:19 +02:00
|
|
|
|
|
|
|
void ReplaceContent(const std::string &basePath) {
|
2022-04-22 17:37:16 +02:00
|
|
|
auto res = ContentRedirection_AddFSLayer(&contentLayerHandle,
|
|
|
|
"SDCafiine Content",
|
|
|
|
basePath.c_str(),
|
|
|
|
FS_LAYER_TYPE_CONTENT_MERGE);
|
|
|
|
if (res == CONTENT_REDIRECTION_RESULT_SUCCESS) {
|
|
|
|
DEBUG_FUNCTION_LINE("Redirect /vol/content to %s", basePath.c_str());
|
2021-04-06 16:58:19 +02:00
|
|
|
} else {
|
2022-04-22 17:37:16 +02:00
|
|
|
DEBUG_FUNCTION_LINE_ERR("Failed to redirect /vol/content to %s", basePath.c_str());
|
2021-04-06 16:58:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void console_print_pos(int x, int y, const char *format, ...) {
|
2022-04-22 17:37:16 +02:00
|
|
|
char *tmp = nullptr;
|
2021-04-06 16:58:19 +02:00
|
|
|
|
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
|
|
|
if ((vasprintf(&tmp, format, va) >= 0) && tmp) {
|
|
|
|
if (strlen(tmp) > 79) {
|
|
|
|
tmp[79] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OSScreenPutFontEx(SCREEN_TV, x, y, tmp);
|
|
|
|
OSScreenPutFontEx(SCREEN_DRC, x, y, tmp);
|
|
|
|
}
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
if (tmp) {
|
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
}
|