FastColor/RemoveFPSCheat/LLVM-Style
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
110
source/Image.cpp
110
source/Image.cpp
@ -77,76 +77,82 @@ 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) {
|
||||
// RGBA -> ABGR
|
||||
for (u32 row = 0; row < width; row++) {
|
||||
for (u32 col = 0; col < height; col++) {
|
||||
u32 z = (row + col * width) * 4;
|
||||
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++) {
|
||||
u32 z = (row + col * width) * 4;
|
||||
|
||||
u8 r = *(u8 *)(buf + z);
|
||||
u8 g = *(u8 *)(buf + z + 1);
|
||||
u8 b = *(u8 *)(buf + z + 2);
|
||||
u8 a = *(u8 *)(buf + z + 3);
|
||||
u8 r = *(u8 *)(buf + z);
|
||||
u8 g = *(u8 *)(buf + z + 1);
|
||||
u8 b = *(u8 *)(buf + z + 2);
|
||||
u8 a = *(u8 *)(buf + z + 3);
|
||||
|
||||
*(buf + z) = a;
|
||||
*(buf + z + 1) = b;
|
||||
*(buf + z + 2) = g;
|
||||
*(buf + z + 3) = r;
|
||||
}
|
||||
}
|
||||
*(buf + z) = a;
|
||||
*(buf + z + 1) = b;
|
||||
*(buf + z + 2) = g;
|
||||
*(buf + z + 3) = r;
|
||||
}
|
||||
}
|
||||
|
||||
u32 w_pow2 = GetNextPowerOf2(width);
|
||||
u32 h_pow2 = GetNextPowerOf2(height);
|
||||
u32 w_pow2 = GetNextPowerOf2(width);
|
||||
u32 h_pow2 = GetNextPowerOf2(height);
|
||||
|
||||
subtex->width = (u16)width;
|
||||
subtex->height = (u16)height;
|
||||
subtex->left = 0.0f;
|
||||
subtex->top = 1.0f;
|
||||
subtex->right = (width / (float)w_pow2);
|
||||
subtex->bottom = 1.0 - (height / (float)h_pow2);
|
||||
subtex->width = (u16)width;
|
||||
subtex->height = (u16)height;
|
||||
subtex->left = 0.0f;
|
||||
subtex->top = 1.0f;
|
||||
subtex->right = (width / (float)w_pow2);
|
||||
subtex->bottom = 1.0 - (height / (float)h_pow2);
|
||||
|
||||
C3D_TexInit(tex, (u16)w_pow2, (u16)h_pow2, format);
|
||||
C3D_TexSetFilter(tex, GPU_NEAREST, GPU_NEAREST);
|
||||
C3D_TexInit(tex, (u16)w_pow2, (u16)h_pow2, format);
|
||||
C3D_TexSetFilter(tex, GPU_NEAREST, GPU_NEAREST);
|
||||
|
||||
u32 pixel_size = (size / width / height);
|
||||
u32 pixel_size = (size / width / height);
|
||||
|
||||
memset(tex->data, 0, tex->size);
|
||||
memset(tex->data, 0, tex->size);
|
||||
|
||||
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 src_pos = (y * width + x) * pixel_size;
|
||||
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 src_pos = (y * width + x) * pixel_size;
|
||||
|
||||
memcpy(&((u8*)tex->data)[dst_pos], &((u8*)buf)[src_pos], pixel_size);
|
||||
}
|
||||
}
|
||||
memcpy(&((u8 *)tex->data)[dst_pos], &((u8 *)buf)[src_pos], pixel_size);
|
||||
}
|
||||
}
|
||||
|
||||
C3D_TexFlush(tex);
|
||||
C3D_TexFlush(tex);
|
||||
|
||||
tex->border = 0x00000000;
|
||||
C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
|
||||
linearFree(buf);
|
||||
tex->border = 0x00000000;
|
||||
C3D_TexSetWrap(tex, GPU_CLAMP_TO_BORDER, GPU_CLAMP_TO_BORDER);
|
||||
linearFree(buf);
|
||||
}
|
||||
|
||||
bool IMG_LoadImageFile(C2D_Image *texture, const char *path) {
|
||||
stbi_uc *image = NULL;
|
||||
int width = 0, height = 0;
|
||||
stbi_uc *image = NULL;
|
||||
int width = 0, height = 0;
|
||||
int nc;
|
||||
|
||||
image = stbi_load(path, &width, &height, &nc, 4);
|
||||
image = stbi_load(path, &width, &height, &nc, 4);
|
||||
|
||||
if (width > 1024 || height > 1024) {
|
||||
stbi_image_free(image);
|
||||
return false;
|
||||
}
|
||||
if (width > 1024 || height > 1024) {
|
||||
stbi_image_free(image);
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
texture->tex = tex;
|
||||
texture->subtex = subtex;
|
||||
stbi_image_free(image);
|
||||
return true;
|
||||
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);
|
||||
texture->tex = tex;
|
||||
texture->subtex = subtex;
|
||||
stbi_image_free(image);
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
@ -162,7 +162,7 @@ static std::map<int, std::string> descos = {
|
||||
{47, "Invalid command header."},
|
||||
};
|
||||
|
||||
//Need to Fix The Range based Values
|
||||
// Need to Fix The Range based Values
|
||||
static std::map<int, std::string> descfs = {
|
||||
{101, "Archive not mounted or mount-point not found."},
|
||||
{120, "Title or object not found."},
|
||||
@ -262,9 +262,9 @@ static std::map<int, std::string> descmvd = {
|
||||
|
||||
static std::map<int, std::string> descqtm = {
|
||||
{8, "Camera is already in use or busy."},
|
||||
};
|
||||
};
|
||||
|
||||
//Need to Fix The Range based Values
|
||||
// Need to Fix The Range based Values
|
||||
static std::map<int, std::string> descapplication = {
|
||||
{0, "The application raised an error. Please consult the application's "
|
||||
"source code or ask the author for assistance with it."},
|
||||
|
@ -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,9 +1020,8 @@ 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");
|
||||
RenderD7::Draw::TextRight(400, 0, 0.7f, RenderD7::Color::Hex("#ffffff"),
|
||||
@ -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;
|
||||
|
Reference in New Issue
Block a user