FastColor/RemoveFPSCheat/LLVM-Style

This commit is contained in:
tobid7 2023-03-07 18:09:48 +01:00
parent 2f7a266dc5
commit 66a35f28e6
22 changed files with 18350 additions and 15235 deletions

11
.vscode/settings.json vendored
View File

@ -88,6 +88,15 @@
"xtree": "cpp",
"xutility": "cpp",
"queue": "cpp",
"semaphore": "cpp"
"semaphore": "cpp",
"hash_map": "cpp",
"set": "cpp",
"unordered_set": "cpp",
"source_location": "cpp",
"future": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"variant": "cpp"
}
}

7
cformat.sh Executable file
View File

@ -0,0 +1,7 @@
find . -type f \( -name '*.h' -o -name '*.hpp' -o -name '*.hh' -o -name '*.ino' -o -name '*.cpp' -o -name '*.c' -o -name '*.cxx' -o -name '*.inl' \) -and -not -path './build/*' -not -path './base/external/*' -not -path './DPP/*' | while read file; do
if [[ "$file" != *"json.hpp" ]]; then
echo "Formatting $file..."
clang-format -i --style=LLVM $file
fi
done

View File

@ -25,10 +25,10 @@
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <renderd7/external/libnsbmp/libnsbmp.h>
@ -64,25 +64,21 @@ static inline uint16_t read_uint16(uint8_t *data, unsigned int o) {
}
static inline int32_t read_int32(uint8_t *data, unsigned int o) {
return (int32_t) ((unsigned)data[o] |
((unsigned)data[o+1] << 8) |
return (int32_t)((unsigned)data[o] | ((unsigned)data[o + 1] << 8) |
((unsigned)data[o + 2] << 16) |
((unsigned)data[o + 3] << 24));
}
static inline uint32_t read_uint32(uint8_t *data, unsigned int o) {
return (uint32_t) ((unsigned)data[o] |
((unsigned)data[o+1] << 8) |
return (uint32_t)((unsigned)data[o] | ((unsigned)data[o + 1] << 8) |
((unsigned)data[o + 2] << 16) |
((unsigned)data[o + 3] << 24));
}
/**
* Parse the bitmap info header
*/
static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
{
static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data) {
uint32_t header_size;
uint32_t i;
uint8_t j;
@ -147,11 +143,8 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
* values considered legal are:
* RGB ENCODING: 1, 4, 8, 16, 24 and 32
*/
if ((bmp->bpp != 1) && (bmp->bpp != 4) &&
(bmp->bpp != 8) &&
(bmp->bpp != 16) &&
(bmp->bpp != 24) &&
(bmp->bpp != 32))
if ((bmp->bpp != 1) && (bmp->bpp != 4) && (bmp->bpp != 8) &&
(bmp->bpp != 16) && (bmp->bpp != 24) && (bmp->bpp != 32))
return BMP_DATA_ERROR;
if (bmp->bpp < 16)
bmp->colours = (1 << bmp->bpp);
@ -236,11 +229,8 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
*/
switch (bmp->encoding) {
case BMP_ENCODING_RGB:
if ((bmp->bpp != 1) && (bmp->bpp != 4) &&
(bmp->bpp != 8) &&
(bmp->bpp != 16) &&
(bmp->bpp != 24) &&
(bmp->bpp != 32))
if ((bmp->bpp != 1) && (bmp->bpp != 4) && (bmp->bpp != 8) &&
(bmp->bpp != 16) && (bmp->bpp != 24) && (bmp->bpp != 32))
return BMP_DATA_ERROR;
break;
case BMP_ENCODING_RLE8:
@ -345,7 +335,8 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
/* create our bitmap */
flags |= BMP_NEW | BMP_CLEAR_MEMORY;
bmp->bitmap = bmp->bitmap_callbacks.bitmap_create(bmp->width, bmp->height, flags);
bmp->bitmap =
bmp->bitmap_callbacks.bitmap_create(bmp->width, bmp->height, flags);
if (!bmp->bitmap) {
if (bmp->colour_table)
free(bmp->colour_table);
@ -360,7 +351,6 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
return BMP_OK;
}
/**
* Parse the bitmap file header
*
@ -368,8 +358,7 @@ static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)
* \param data The data for the file header
* \return BMP_OK on success or error code on faliure
*/
static bmp_result bmp_file_header_parse(bmp_image *bmp, uint8_t *data)
{
static bmp_result bmp_file_header_parse(bmp_image *bmp, uint8_t *data) {
/* standard 14-byte BMP file header is:
*
* +0 UINT16 File Type ('BM')
@ -394,7 +383,6 @@ static bmp_result bmp_file_header_parse(bmp_image *bmp, uint8_t *data)
return BMP_OK;
}
/**
* Allocates memory for the next BMP in an ICO collection
*
@ -410,7 +398,6 @@ static bmp_result next_ico_image(ico_collection *ico, ico_image *image) {
return BMP_OK;
}
/**
* Parse the icon file header
*
@ -418,8 +405,7 @@ static bmp_result next_ico_image(ico_collection *ico, ico_image *image) {
* \param data The header data to parse.
* \return BMP_OK on successful parse else error code
*/
static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
{
static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data) {
uint16_t count, i;
bmp_result result;
int area, max_area = 0;
@ -442,7 +428,8 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
data += ICO_FILE_HEADER_SIZE;
/* check if we have enough data for the directory */
if (ico->buffer_size < (uint32_t)(ICO_FILE_HEADER_SIZE + (ICO_DIR_ENTRY_SIZE * count)))
if (ico->buffer_size <
(uint32_t)(ICO_FILE_HEADER_SIZE + (ICO_DIR_ENTRY_SIZE * count)))
return BMP_INSUFFICIENT_DATA;
/* Decode the BMP files.
@ -456,7 +443,8 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
* +4 UINT16 Colour Planes (should be 0 or 1)
* +6 UINT16 Bits Per Pixel
* +8 UINT32 Size of BMP info header + bitmap data in bytes
* +12 UINT32 Offset (points to the BMP info header, not the bitmap data)
* +12 UINT32 Offset (points to the BMP info header, not the bitmap
*data)
*/
for (i = 0; i < count; i++) {
ico_image *image;
@ -482,8 +470,7 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
/* Ensure that the bitmap data resides in the buffer */
if (image->bmp.bmp_data - ico->ico_data >= 0 &&
(uint32_t)(image->bmp.bmp_data -
ico->ico_data) >= ico->buffer_size)
(uint32_t)(image->bmp.bmp_data - ico->ico_data) >= ico->buffer_size)
return BMP_DATA_ERROR;
/* Ensure that we have sufficient data to read the bitmap */
@ -491,8 +478,7 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
ico->buffer_size - (ico->ico_data - data))
return BMP_INSUFFICIENT_DATA;
result = bmp_info_header_parse(&image->bmp,
image->bmp.bmp_data);
result = bmp_info_header_parse(&image->bmp, image->bmp.bmp_data);
if (result != BMP_OK)
return result;
@ -507,7 +493,6 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
return BMP_OK;
}
/**
* Decode BMP data stored in 32bpp colour.
*
@ -518,8 +503,7 @@ static bmp_result ico_header_parse(ico_collection *ico, uint8_t *data)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable
*/
static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
{
static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes) {
uint8_t *top, *bottom, *end, *data;
uint32_t *scanline;
uint32_t x, y;
@ -589,7 +573,6 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK;
}
/**
* Decode BMP data stored in 24bpp colour.
*
@ -600,8 +583,7 @@ static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable
*/
static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
{
static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes) {
uint8_t *top, *bottom, *end, *data;
uint32_t *scanline;
uint32_t x, y;
@ -662,7 +644,6 @@ static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK;
}
/**
* Decode BMP data stored in 16bpp colour.
*
@ -673,8 +654,7 @@ static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable
*/
static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
{
static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes) {
uint8_t *top, *bottom, *end, *data;
uint32_t *scanline;
uint32_t x, y, swidth;
@ -731,8 +711,7 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
scanline[x] = bmp->trans_colour;
else {
/* 16-bit RGB defaults to RGB555 */
scanline[x] = ((word & (31 << 0)) << 19) |
((word & (31 << 5)) << 6) |
scanline[x] = ((word & (31 << 0)) << 19) | ((word & (31 << 5)) << 6) |
((word & (31 << 10)) >> 7);
}
if (bmp->opaque)
@ -748,7 +727,6 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK;
}
/**
* Decode BMP data stored with a palette and in 8bpp colour or less.
*
@ -759,8 +737,7 @@ static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable
*/
static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
{
static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes) {
uint8_t *top, *bottom, *end, *data;
uint32_t *scanline;
intptr_t addr;
@ -812,8 +789,7 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
if (idx < bmp->colours) {
/* ensure colour table index is in bounds */
scanline[x] = bmp->colour_table[idx];
if ((bmp->limited_trans) &&
(scanline[x] == bmp->transparent_index)) {
if ((bmp->limited_trans) && (scanline[x] == bmp->transparent_index)) {
scanline[x] = bmp->trans_colour;
}
}
@ -825,7 +801,6 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
return BMP_OK;
}
/**
* Decode a 1bpp mask for an ICO
*
@ -834,8 +809,7 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes)
* \param bytes the number of bytes of data available
* \return BMP_OK on success
*/
static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes)
{
static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes) {
uint8_t *top, *bottom, *end;
uint32_t *scanline;
intptr_t addr;
@ -873,7 +847,6 @@ static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes)
return BMP_OK;
}
/**
* Decode BMP data stored encoded in RLE8.
*
@ -884,9 +857,7 @@ static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable
*/
static bmp_result
bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
{
static bmp_result bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes) {
uint8_t *top, *bottom, *end;
uint32_t *scanline;
uint32_t swidth;
@ -1027,7 +998,6 @@ bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
return BMP_OK;
}
/**
* Decode BMP data stored encoded in RLE4.
*
@ -1038,9 +1008,7 @@ bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes)
* BMP_INSUFFICIENT_DATA if the bitmap data ends unexpectedly;
* in this case, the image may be partially viewable
*/
static bmp_result
bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
{
static bmp_result bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes) {
uint8_t *top, *bottom, *end;
uint32_t *scanline;
uint32_t swidth;
@ -1123,19 +1091,16 @@ bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
} else {
scanline -= bmp->width;
}
}
if ((i & 1) == 0) {
pixel = *data++;
if ((pixel >> 4) >= bmp->colours)
return BMP_DATA_ERROR;
scanline[x++] = bmp->colour_table
[pixel >> 4];
scanline[x++] = bmp->colour_table[pixel >> 4];
} else {
if ((pixel & 0xf) >= bmp->colours)
return BMP_DATA_ERROR;
scanline[x++] = bmp->colour_table
[pixel & 0xf];
scanline[x++] = bmp->colour_table[pixel & 0xf];
}
}
length = (length + 1) >> 1;
@ -1167,8 +1132,7 @@ bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
*/
pixel2 = *data++;
if ((pixel2 >> 4) >= bmp->colours ||
(pixel2 & 0xf) >= bmp->colours)
if ((pixel2 >> 4) >= bmp->colours || (pixel2 & 0xf) >= bmp->colours)
return BMP_DATA_ERROR;
pixel = bmp->colour_table[pixel2 >> 4];
pixel2 = bmp->colour_table[pixel2 & 0xf];
@ -1189,31 +1153,24 @@ bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes)
else
scanline[x++] = pixel2;
}
}
} while (data < end);
return BMP_OK;
}
/* exported interface documented in libnsbmp.h */
bmp_result
bmp_create(bmp_image *bmp,
bmp_bitmap_callback_vt *bitmap_callbacks)
{
bmp_result bmp_create(bmp_image *bmp,
bmp_bitmap_callback_vt *bitmap_callbacks) {
memset(bmp, 0, sizeof(bmp_image));
bmp->bitmap_callbacks = *bitmap_callbacks;
return BMP_OK;
}
/* exported interface documented in libnsbmp.h */
bmp_result
ico_collection_create(ico_collection *ico,
bmp_bitmap_callback_vt *bitmap_callbacks)
{
bmp_result ico_collection_create(ico_collection *ico,
bmp_bitmap_callback_vt *bitmap_callbacks) {
memset(ico, 0, sizeof(ico_collection));
ico->bitmap_callbacks = *bitmap_callbacks;
@ -1221,10 +1178,8 @@ ico_collection_create(ico_collection *ico,
return BMP_OK;
}
/* exported interface documented in libnsbmp.h */
bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data)
{
bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data) {
bmp_result res;
/* ensure we aren't already initialised */
@ -1243,10 +1198,8 @@ bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data)
return res;
}
/* exported interface documented in libnsbmp.h */
bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data)
{
bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data) {
/* ensure we aren't already initialised */
if (ico->first)
return BMP_OK;
@ -1258,10 +1211,8 @@ bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data)
return ico_header_parse(ico, data);
}
/* exported interface documented in libnsbmp.h */
bmp_result bmp_decode(bmp_image *bmp)
{
bmp_result bmp_decode(bmp_image *bmp) {
uint8_t *data;
uint32_t bytes;
bmp_result result = BMP_OK;
@ -1325,19 +1276,15 @@ bmp_result bmp_decode(bmp_image *bmp)
return result;
}
/* exported interface documented in libnsbmp.h */
bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t colour)
{
bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t colour) {
bmp->limited_trans = true;
bmp->trans_colour = colour;
return bmp_decode(bmp);
}
/* exported interface documented in libnsbmp.h */
bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height)
{
bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height) {
bmp_image *bmp = NULL;
ico_image *image;
int x, y, cur, distance = (1 << 24);
@ -1360,10 +1307,8 @@ bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height)
return bmp;
}
/* exported interface documented in libnsbmp.h */
void bmp_finalise(bmp_image *bmp)
{
void bmp_finalise(bmp_image *bmp) {
if (bmp->bitmap)
bmp->bitmap_callbacks.bitmap_destroy(bmp->bitmap);
bmp->bitmap = NULL;
@ -1372,10 +1317,8 @@ void bmp_finalise(bmp_image *bmp)
bmp->colour_table = NULL;
}
/* exported interface documented in libnsbmp.h */
void ico_finalise(ico_collection *ico)
{
void ico_finalise(ico_collection *ico) {
ico_image *image;
for (image = ico->first; image; image = image->next)

105
external/source/fs.c vendored
View File

@ -3,9 +3,9 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <stdlib.h>
#define WORKING_DIR "/"
@ -23,7 +23,8 @@ FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID archiveID) {
Result ret = 0;
if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID, fsMakePath(PATH_EMPTY, ""))))
if (R_FAILED(ret = FSUSER_OpenArchive(archive, archiveID,
fsMakePath(PATH_EMPTY, ""))))
return ret;
return 0;
@ -44,19 +45,23 @@ Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenDirectory(handle, archive, fsMakePath(PATH_UTF16, path_u16))))
if (R_FAILED(ret = FSUSER_OpenDirectory(handle, archive,
fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes) {
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path,
u32 flags, u32 attributes) {
Result ret = 0;
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(handle, archive, fsMakePath(PATH_UTF16, path_u16), flags, attributes)))
if (R_FAILED(ret = FSUSER_OpenFile(handle, archive,
fsMakePath(PATH_UTF16, path_u16), flags,
attributes)))
return ret;
return 0;
@ -68,7 +73,8 @@ Result FS_MakeDir(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateDirectory(archive, fsMakePath(PATH_UTF16, path_u16), 0)))
if (R_FAILED(ret = FSUSER_CreateDirectory(
archive, fsMakePath(PATH_UTF16, path_u16), 0)))
return ret;
return 0;
@ -80,7 +86,8 @@ Result FS_CreateFile(FS_Archive archive, const char *path, u64 size) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
if (R_FAILED(ret = FSUSER_CreateFile(
archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret;
return 0;
@ -121,7 +128,8 @@ bool FS_FileExists(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
if (R_FAILED(FSUSER_OpenFile(
&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
return false;
if (R_FAILED(FSFILE_Close(handle)))
@ -136,7 +144,8 @@ bool FS_DirExists(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path_u16))))
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive,
fsMakePath(PATH_UTF16, path_u16))))
return false;
if (R_FAILED(FSDIR_Close(handle)))
@ -152,7 +161,9 @@ Result FS_GetFileSize(FS_Archive archive, const char *path, u64 *size) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_READ, 0)))
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive,
fsMakePath(PATH_UTF16, path_u16),
FS_OPEN_READ, 0)))
return ret;
if (R_FAILED(ret = FSFILE_GetSize(handle, size))) {
@ -194,7 +205,8 @@ Result FS_RemoveFile(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteFile(archive, fsMakePath(PATH_UTF16, path_u16))))
if (R_FAILED(
ret = FSUSER_DeleteFile(archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
@ -206,7 +218,8 @@ Result FS_RemoveDir(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectory(archive, fsMakePath(PATH_UTF16, path_u16))))
if (R_FAILED(ret = FSUSER_DeleteDirectory(archive,
fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
@ -218,37 +231,48 @@ Result FS_RemoveDirRecursive(FS_Archive archive, const char *path) {
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_UTF16, path_u16))))
if (R_FAILED(ret = FSUSER_DeleteDirectoryRecursively(
archive, fsMakePath(PATH_UTF16, path_u16))))
return ret;
return 0;
}
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename) {
Result FS_RenameFile(FS_Archive archive, const char *old_filename,
const char *new_filename) {
Result ret = 0;
u16 old_filename_u16[strlen(old_filename) + 1];
Utils_U8_To_U16(old_filename_u16, (const u8 *)old_filename, strlen(old_filename) + 1);
Utils_U8_To_U16(old_filename_u16, (const u8 *)old_filename,
strlen(old_filename) + 1);
u16 new_filename_u16[strlen(new_filename) + 1];
Utils_U8_To_U16(new_filename_u16, (const u8 *)new_filename, strlen(new_filename) + 1);
Utils_U8_To_U16(new_filename_u16, (const u8 *)new_filename,
strlen(new_filename) + 1);
if (R_FAILED(ret = FSUSER_RenameFile(archive, fsMakePath(PATH_UTF16, old_filename_u16), archive, fsMakePath(PATH_UTF16, new_filename_u16))))
if (R_FAILED(ret = FSUSER_RenameFile(
archive, fsMakePath(PATH_UTF16, old_filename_u16), archive,
fsMakePath(PATH_UTF16, new_filename_u16))))
return ret;
return 0;
}
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname) {
Result FS_RenameDir(FS_Archive archive, const char *old_dirname,
const char *new_dirname) {
Result ret = 0;
u16 old_dirname_u16[strlen(old_dirname) + 1];
Utils_U8_To_U16(old_dirname_u16, (const u8 *)old_dirname, strlen(old_dirname) + 1);
Utils_U8_To_U16(old_dirname_u16, (const u8 *)old_dirname,
strlen(old_dirname) + 1);
u16 new_dirname_u16[strlen(new_dirname) + 1];
Utils_U8_To_U16(new_dirname_u16, (const u8 *)new_dirname, strlen(new_dirname) + 1);
Utils_U8_To_U16(new_dirname_u16, (const u8 *)new_dirname,
strlen(new_dirname) + 1);
if (R_FAILED(ret = FSUSER_RenameDirectory(archive, fsMakePath(PATH_UTF16, old_dirname_u16), archive, fsMakePath(PATH_UTF16, new_dirname_u16))))
if (R_FAILED(ret = FSUSER_RenameDirectory(
archive, fsMakePath(PATH_UTF16, old_dirname_u16), archive,
fsMakePath(PATH_UTF16, new_dirname_u16))))
return ret;
return 0;
@ -274,7 +298,8 @@ Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf) {
return 0;
}
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size) {
Result FS_Write(FS_Archive archive, const char *path, const void *buf,
u32 size) {
Result ret = 0;
Handle handle;
u32 bytes_written = 0;
@ -285,13 +310,17 @@ Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size)
u16 path_u16[strlen(path) + 1];
Utils_U8_To_U16(path_u16, (const u8 *)path, strlen(path) + 1);
if (R_FAILED(ret = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
if (R_FAILED(ret = FSUSER_CreateFile(
archive, fsMakePath(PATH_UTF16, path_u16), 0, size)))
return ret;
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive, fsMakePath(PATH_UTF16, path_u16), FS_OPEN_WRITE, 0)))
if (R_FAILED(ret = FSUSER_OpenFile(&handle, archive,
fsMakePath(PATH_UTF16, path_u16),
FS_OPEN_WRITE, 0)))
return ret;
if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size, FS_WRITE_FLUSH))) {
if (R_FAILED(ret = FSFILE_Write(handle, &bytes_written, 0, buf, size,
FS_WRITE_FLUSH))) {
FSFILE_Close(handle);
return ret;
}
@ -317,9 +346,9 @@ char *FS_GetFileTimestamp(const char *path) {
int month = timeStruct->tm_mon + 1; // January being 0
int year = timeStruct->tm_year + 1900;
snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours, minutes);
}
else
snprintf(timeStr, 60, "%d/%d/%d %2i:%02i", year, month, day, hours,
minutes);
} else
return NULL;
return timeStr;
@ -333,7 +362,8 @@ FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) {
if (!strncmp(path, "sdmc:/", 6)) {
prefixlen = 5;
} else if (*path != '/') {
//if the path is local (doesnt start with a slash), it needs to be appended to the working dir to be valid
// if the path is local (doesnt start with a slash), it needs to be appended
// to the working dir to be valid
char *actualPath = NULL;
asprintf(&actualPath, "%s%s", WORKING_DIR, path);
filePath = fsMakePath(PATH_ASCII, actualPath);
@ -355,14 +385,17 @@ Result makeDirs(const char * path) {
ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, ""));
for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) {
for (char *slashpos = strchr(path + 1, '/'); slashpos != NULL;
slashpos = strchr(slashpos + 1, '/')) {
char bak = *(slashpos);
*(slashpos) = '\0';
Handle dirHandle;
ret = FSUSER_OpenDirectory(&dirHandle, archive, filePath);
if (R_SUCCEEDED(ret)) FSDIR_Close(dirHandle);
else ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
if (R_SUCCEEDED(ret))
FSDIR_Close(dirHandle);
else
ret = FSUSER_CreateDirectory(archive, filePath, FS_ATTRIBUTE_DIRECTORY);
*(slashpos) = bak;
}
@ -379,8 +412,12 @@ Result openFile(Handle* fileHandle, const char * path, bool write) {
Result ret = 0;
ret = makeDirs(strdup(path));
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0);
if (write) ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing
ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""),
filePath, flags, 0);
if (write)
ret = FSFILE_SetSize(
*fileHandle,
0); // truncate the file to remove previous contents before writing
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
#pragma once
#include <renderd7/StealConsole.hpp>
#include <renderd7/bmp.hpp>
#include <renderd7/renderd7.hpp>
#include <renderd7/StealConsole.hpp>

View File

@ -26,6 +26,6 @@ public:
uint8_t m_r, m_g, m_b, m_a;
};
std::string RGB2Hex(int r, int g, int b);
uint32_t Hex(const std::string color, uint8_t a = 255);
uint32_t Hex(const std::string &color, uint8_t a = 255);
} // namespace Color
} // namespace RenderD7

View File

@ -1,11 +1,9 @@
#pragma once
#include <string>
#include <3ds.h>
#include <string>
namespace RenderD7
{
class ResultDecoder
{
namespace RenderD7 {
class ResultDecoder {
public:
ResultDecoder() {}
~ResultDecoder() {}
@ -24,4 +22,4 @@ namespace RenderD7
private:
Result m_rescode;
};
}
} // namespace RenderD7

View File

@ -2,7 +2,6 @@
#include <sstream>
#include <string>
namespace RenderD7 {
class StealConsole {
public:

View File

@ -7,7 +7,8 @@ extern FS_Archive archive, sdmc_archive, nand_archive;
Result FS_OpenArchive(FS_Archive *archive, FS_ArchiveID id);
Result FS_CloseArchive(FS_Archive archive);
Result FS_OpenDir(Handle *handle, FS_Archive archive, const char *path);
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path, u32 flags, u32 attributes);
Result FS_OpenFile(Handle *handle, FS_Archive archive, const char *path,
u32 flags, u32 attributes);
Result FS_MakeDir(FS_Archive archive, const char *path);
Result FS_CreateFile(FS_Archive archive, const char *path, u64 size);
Result FS_RecursiveMakeDir(FS_Archive archive, const char *path);
@ -20,10 +21,13 @@ u64 FS_GetUsedStorage(FS_SystemMediaType media_type);
Result FS_RemoveFile(FS_Archive archive, const char *path);
Result FS_RemoveDir(FS_Archive archive, const char *path);
Result FS_RemoveDirRecursive(FS_Archive archive, const char *path);
Result FS_RenameFile(FS_Archive archive, const char *old_filename, const char *new_filename);
Result FS_RenameDir(FS_Archive archive, const char *old_dirname, const char *new_dirname);
Result FS_RenameFile(FS_Archive archive, const char *old_filename,
const char *new_filename);
Result FS_RenameDir(FS_Archive archive, const char *old_dirname,
const char *new_dirname);
Result FS_Read(FS_Archive archive, const char *path, u64 size, void *buf);
Result FS_Write(FS_Archive archive, const char *path, const void *buf, u32 size);
Result FS_Write(FS_Archive archive, const char *path, const void *buf,
u32 size);
char *FS_GetFileTimestamp(const char *path);
Result makeDirs(const char *path);
Result openFile(Handle *fileHandle, const char *path, bool write);

View File

@ -16,8 +16,8 @@
#define libnsbmp_h_
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#include <stdint.h>
/* bmp flags */
#define BMP_NEW 0
@ -47,7 +47,8 @@ typedef enum {
} bmp_encoding;
/* API for Bitmap callbacks */
typedef void* (*bmp_bitmap_cb_create)(int width, int height, unsigned int state);
typedef void *(*bmp_bitmap_cb_create)(int width, int height,
unsigned int state);
typedef void (*bmp_bitmap_cb_destroy)(void *bitmap);
typedef unsigned char *(*bmp_bitmap_cb_get_buffer)(void *bitmap);
typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap);

View File

@ -16,11 +16,17 @@
#define LOG(x) ((void)0)
#else
#ifdef __GNUC__
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
#define LOG(x) \
do { printf x, fputc('\n', stdout)); \
} while (0)
#elif defined(__CC_NORCROFT)
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
#define LOG(x) \
do { printf x, fputc('\n', stdout)); \
} while (0)
#else
# define LOG(x) do { printf x, fputc('\n', stdout)); } while (0)
#define LOG(x) \
do { printf x, fputc('\n', stdout)); \
} while (0)
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,18 +1,40 @@
#include <renderd7/Color.hpp>
#include <map>
#define RGBA8(r, g, b, a) \
((((r)&0xFF) << 0) | (((g)&0xFF) << 8) | (((b)&0xFF) << 16) | \
(((a)&0xFF) << 24))
uint32_t RenderD7::Color::Hex(const std::string color, uint8_t a) {
// uint32_t RenderD7::Color::Hex(const std::string &color, uint8_t a) {
// if (color.length() < 7 ||
// std::regex_search(color.substr(1),
// std::regex("[^0-9A-Fa-f]"))) { // invalid color.
// return RenderD7::Color::Hex("#000000", 0);
// }
// int r = std::stoi(color.substr(1, 2), nullptr, 16);
// int g = std::stoi(color.substr(3, 2), nullptr, 16);
// int b = std::stoi(color.substr(5, 2), nullptr, 16);
// return RGBA8(r, g, b, a);
// }
// Lookup-Table für Hex-to-Dez-Konvertierung
static const std::map<char, int> HEX_TO_DEC = {
{'0', 0}, {'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5},
{'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'a', 10}, {'b', 11},
{'c', 12}, {'d', 13}, {'e', 14}, {'f', 15}, {'A', 10}, {'B', 11},
{'C', 12}, {'D', 13}, {'E', 14}, {'F', 15}};
uint32_t RenderD7::Color::Hex(const std::string &color, uint8_t a) {
if (color.length() < 7 ||
std::regex_search(color.substr(1),
std::regex("[^0-9A-Fa-f]"))) { // invalid color.
std::find_if(color.begin() + 1, color.end(),
[](char c) { return !std::isxdigit(c); }) != color.end()) {
return RenderD7::Color::Hex("#000000", 0);
}
int r = std::stoi(color.substr(1, 2), nullptr, 16);
int g = std::stoi(color.substr(3, 2), nullptr, 16);
int b = std::stoi(color.substr(5, 2), nullptr, 16);
int r = HEX_TO_DEC.at(color[1]) * 16 + HEX_TO_DEC.at(color[2]);
int g = HEX_TO_DEC.at(color[3]) * 16 + HEX_TO_DEC.at(color[4]);
int b = HEX_TO_DEC.at(color[5]) * 16 + HEX_TO_DEC.at(color[6]);
return RGBA8(r, g, b, a);
}

View File

@ -9,12 +9,13 @@
#include <filesystem>
std::vector<RenderD7::FileSystem::Entry> RenderD7::FileSystem::GetDirContent(std::string path)
{
std::vector<RenderD7::FileSystem::Entry>
RenderD7::FileSystem::GetDirContent(std::string path) {
std::vector<RenderD7::FileSystem::Entry> res;
for(const auto& entry : std::filesystem::directory_iterator(std::filesystem::path(path)))
{
res.push_back({entry.path().string(), GetFileName(entry.path().string()), entry.is_directory()});
for (const auto &entry :
std::filesystem::directory_iterator(std::filesystem::path(path))) {
res.push_back({entry.path().string(), GetFileName(entry.path().string()),
entry.is_directory()});
}
return res;
}

View File

@ -77,7 +77,9 @@ static bool C3DTexToC2DImage(C2D_Image *texture, u32 width, u32 height,
return false;
}
static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex, u8 *buf, u32 size, u32 width, u32 height, GPU_TEXCOLOR format) {
static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex,
u8 *buf, u32 size, u32 width, u32 height,
GPU_TEXCOLOR format) {
// RGBA -> ABGR
for (u32 row = 0; row < width; row++) {
for (u32 col = 0; col < height; col++) {
@ -114,7 +116,10 @@ static void OLD_C3DTexToC2DImage(C3D_Tex *tex, Tex3DS_SubTexture *subtex, u8 *bu
for (u32 x = 0; x < width; x++) {
for (u32 y = 0; y < height; y++) {
u32 dst_pos = ((((y >> 3) * (w_pow2 >> 3) + (x >> 3)) << 6) + ((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) | ((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) * pixel_size;
u32 dst_pos = ((((y >> 3) * (w_pow2 >> 3) + (x >> 3)) << 6) +
((x & 1) | ((y & 1) << 1) | ((x & 2) << 1) |
((y & 2) << 2) | ((x & 4) << 2) | ((y & 4) << 3))) *
pixel_size;
u32 src_pos = (y * width + x) * pixel_size;
memcpy(&((u8 *)tex->data)[dst_pos], &((u8 *)buf)[src_pos], pixel_size);
@ -142,7 +147,8 @@ bool IMG_LoadImageFile(C2D_Image *texture, const char *path) {
C3D_Tex *tex = new C3D_Tex;
Tex3DS_SubTexture *subtex = new Tex3DS_SubTexture;
OLD_C3DTexToC2DImage(tex, subtex, image, (u32)(width * height * 4), (u32)width, (u32)height, GPU_RGBA8);
OLD_C3DTexToC2DImage(tex, subtex, image, (u32)(width * height * 4),
(u32)width, (u32)height, GPU_RGBA8);
texture->tex = tex;
texture->subtex = subtex;
stbi_image_free(image);

View File

@ -432,7 +432,7 @@ Result RenderD7::Init::Main(std::string app_name) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct);
std::string Fps = cfgstruct["settings"]["forceFrameRate"];
C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
////C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["enableoverlay"]));
mt_txtcolor =
@ -547,7 +547,7 @@ Result RenderD7::Init::Minimal(std::string app_name) {
cfgfile = std::make_unique<INI::INIFile>(cfgpath + "/config.ini");
cfgfile->read(cfgstruct);
std::string Fps = cfgstruct["settings"]["forceFrameRate"];
C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
//C3D_FrameRate(RenderD7::Convert::StringtoFloat(Fps));
metrikd = RenderD7::Convert::FloatToBool(RenderD7::Convert::StringtoFloat(
cfgstruct["metrik-settings"]["enableoverlay"]));
mt_txtcolor =
@ -1020,8 +1020,7 @@ void RenderD7::RSettings::Draw(void) const {
RenderD7::OnScreen(Top);
RenderD7::Draw::Rect(0, 21, 400, 220, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(5, 30, 0.7f, DSEVENBLACK,
std::string(CHANGELOG));
RenderD7::Draw::Text(5, 30, 0.7f, DSEVENBLACK, std::string(CHANGELOG));
RenderD7::Draw::Rect(0, 0, 400, 21, RenderD7::Color::Hex("#111111"));
RenderD7::Draw::Text(0, 0, 0.7f, DSEVENWHITE, "RenderD7->Changelog");
@ -1030,7 +1029,8 @@ void RenderD7::RSettings::Draw(void) const {
RenderD7::OnScreen(Bottom);
RenderD7::Draw::Rect(0, 0, 320, 240, RenderD7::Color::Hex("#eeeeee"));
RenderD7::Draw::Text(0, 0, 0.7f, RenderD7::Color::Hex("#111111"),
"Press B to Get back!\ntxty: " + std::to_string(txtposy));
"Press B to Get back!\ntxty: " +
std::to_string(txtposy));
} else if (m_state == RINFO) {
std::string rd7ver = RENDERD7VSTRING;
@ -1103,8 +1103,8 @@ void RenderD7::RSettings::Logic(u32 hDown, u32 hHeld, u32 hUp,
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[3]) &&
!metrikd) {
cfgstruct["settings"]["forceFrameRate"] = Kbd(2, SWKBD_TYPE_NUMPAD);
C3D_FrameRate(RenderD7::Convert::StringtoFloat(
cfgstruct["settings"]["forceFrameRate"]));
//C3D_FrameRate(RenderD7::Convert::StringtoFloat(
//cfgstruct["settings"]["forceFrameRate"]));
}
if (d7_hDown & KEY_TOUCH && RenderD7::touchTObj(d7_touch, buttons[4])) {
mt_screen = mt_screen ? 0 : 1;

View File

@ -1,8 +1,7 @@
// rd7cc
#include <iostream>
#include <fstream>
int main(int argc, char* argv[])
{
#include <iostream>
int main(int argc, char *argv[]) {
std::ofstream result("result.hpp");
result << "//Result" << std::endl;