Update .clang-format rules

This commit is contained in:
Maschell 2022-02-03 14:01:11 +01:00
parent 4512de73da
commit c56897cc75
8 changed files with 64 additions and 66 deletions

View File

@ -2,7 +2,7 @@
BasedOnStyle: LLVM BasedOnStyle: LLVM
AccessModifierOffset: -4 AccessModifierOffset: -4
AlignAfterOpenBracket: Align AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None AlignConsecutiveAssignments: Consecutive
AlignConsecutiveMacros: AcrossEmptyLinesAndComments AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align AlignOperands: Align
AllowAllArgumentsOnNextLine: false AllowAllArgumentsOnNextLine: false

View File

@ -28,7 +28,7 @@ void handleAccountSelection();
void bootWiiUMenu() { void bootWiiUMenu() {
nn::act::Initialize(); nn::act::Initialize();
nn::act::SlotNo slot = nn::act::GetSlotNo(); nn::act::SlotNo slot = nn::act::GetSlotNo();
nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount(); nn::act::SlotNo defaultSlot = nn::act::GetDefaultAccount();
nn::act::Finalize(); nn::act::Finalize();
@ -58,8 +58,8 @@ void handleAccountSelection() {
} }
char16_t nameOut[nn::act::MiiNameSize]; char16_t nameOut[nn::act::MiiNameSize];
std::shared_ptr<AccountInfo> accountInfo = std::make_shared<AccountInfo>(); std::shared_ptr<AccountInfo> accountInfo = std::make_shared<AccountInfo>();
accountInfo->slot = i; accountInfo->slot = i;
auto result = nn::act::GetMiiNameEx(reinterpret_cast<int16_t *>(nameOut), i); auto result = nn::act::GetMiiNameEx(reinterpret_cast<int16_t *>(nameOut), i);
if (result.IsSuccess()) { if (result.IsSuccess()) {
std::u16string source; std::u16string source;
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
@ -73,7 +73,7 @@ void handleAccountSelection() {
} }
uint32_t imageSize = 0; uint32_t imageSize = 0;
result = nn::act::GetMiiImageEx(&imageSize, accountInfo->miiImageBuffer, sizeof(accountInfo->miiImageBuffer), 0, i); result = nn::act::GetMiiImageEx(&imageSize, accountInfo->miiImageBuffer, sizeof(accountInfo->miiImageBuffer), 0, i);
if (result.IsSuccess()) { if (result.IsSuccess()) {
accountInfo->miiImageSize = imageSize; accountInfo->miiImageSize = imageSize;
} }

View File

@ -16,20 +16,20 @@
bool DrawUtils::isBackBuffer; bool DrawUtils::isBackBuffer;
uint8_t *DrawUtils::tvBuffer = nullptr; uint8_t *DrawUtils::tvBuffer = nullptr;
uint32_t DrawUtils::tvSize = 0; uint32_t DrawUtils::tvSize = 0;
uint8_t *DrawUtils::drcBuffer = nullptr; uint8_t *DrawUtils::drcBuffer = nullptr;
uint32_t DrawUtils::drcSize = 0; uint32_t DrawUtils::drcSize = 0;
// Don't put those into the class or we have to include ft everywhere // Don't put those into the class or we have to include ft everywhere
static FT_Library ft_lib = nullptr; static FT_Library ft_lib = nullptr;
static FT_Face ft_face = nullptr; static FT_Face ft_face = nullptr;
static Color font_col = {0xFFFFFFFF}; static Color font_col = {0xFFFFFFFF};
void *DrawUtils::InitOSScreen() { void *DrawUtils::InitOSScreen() {
OSScreenInit(); OSScreenInit();
uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV); uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV);
uint32_t drcBufferSize = OSScreenGetBufferSizeEx(SCREEN_DRC); uint32_t drcBufferSize = OSScreenGetBufferSizeEx(SCREEN_DRC);
auto *screenBuffer = (uint8_t *) memalign(0x100, tvBufferSize + drcBufferSize); auto *screenBuffer = (uint8_t *) memalign(0x100, tvBufferSize + drcBufferSize);
@ -46,10 +46,10 @@ void *DrawUtils::InitOSScreen() {
} }
void DrawUtils::initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize) { void DrawUtils::initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize) {
DrawUtils::tvBuffer = (uint8_t *) tvBuffer; DrawUtils::tvBuffer = (uint8_t *) tvBuffer;
DrawUtils::tvSize = tvSize; DrawUtils::tvSize = tvSize;
DrawUtils::drcBuffer = (uint8_t *) drcBuffer; DrawUtils::drcBuffer = (uint8_t *) drcBuffer;
DrawUtils::drcSize = drcSize; DrawUtils::drcSize = drcSize;
} }
void DrawUtils::beginDraw() { void DrawUtils::beginDraw() {
@ -91,11 +91,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
i += drcSize / 2; i += drcSize / 2;
} }
if (a == 0xFF) { if (a == 0xFF) {
drcBuffer[i] = r; drcBuffer[i] = r;
drcBuffer[i + 1] = g; drcBuffer[i + 1] = g;
drcBuffer[i + 2] = b; drcBuffer[i + 2] = b;
} else { } else {
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity); drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity); drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity);
drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity); drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity);
} }
@ -110,11 +110,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
i += tvSize / 2; i += tvSize / 2;
} }
if (a == 0xFF) { if (a == 0xFF) {
tvBuffer[i] = r; tvBuffer[i] = r;
tvBuffer[i + 1] = g; tvBuffer[i + 1] = g;
tvBuffer[i + 2] = b; tvBuffer[i + 2] = b;
} else { } else {
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity); tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity); tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity);
tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity); tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity);
} }
@ -145,8 +145,8 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32
} }
uint32_t dataPos = __builtin_bswap32(*(uint32_t *) &(data[0x0A])); uint32_t dataPos = __builtin_bswap32(*(uint32_t *) &(data[0x0A]));
uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12])); uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12]));
uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16])); uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16]));
if (dataPos == 0) { if (dataPos == 0) {
dataPos = 54; dataPos = 54;
@ -187,17 +187,17 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
png_read_info(png_ptr, info_ptr); png_read_info(png_ptr, info_ptr);
uint32_t width = 0; uint32_t width = 0;
uint32_t height = 0; uint32_t height = 0;
int bitDepth = 0; int bitDepth = 0;
int colorType = -1; int colorType = -1;
uint32_t retval = png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, NULL, NULL, NULL); uint32_t retval = png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, NULL, NULL, NULL);
if (retval != 1) { if (retval != 1) {
return; return;
} }
uint32_t bytesPerRow = png_get_rowbytes(png_ptr, info_ptr); uint32_t bytesPerRow = png_get_rowbytes(png_ptr, info_ptr);
uint8_t *rowData = new uint8_t[bytesPerRow]; uint8_t *rowData = new uint8_t[bytesPerRow];
for (uint32_t yy = y; yy < y + height; yy++) { for (uint32_t yy = y; yy < y + height; yy++) {
png_read_row(png_ptr, (png_bytep) rowData, NULL); png_read_row(png_ptr, (png_bytep) rowData, NULL);
@ -218,7 +218,7 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
} }
void DrawUtils::initFont() { void DrawUtils::initFont() {
void *font = NULL; void *font = NULL;
uint32_t size = 0; uint32_t size = 0;
OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size); OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size);
@ -276,7 +276,7 @@ void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRigh
void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight) { void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight) {
FT_GlyphSlot slot = ft_face->glyph; FT_GlyphSlot slot = ft_face->glyph;
FT_Vector pen = {(int) x, (int) y}; FT_Vector pen = {(int) x, (int) y};
if (alignRight) { if (alignRight) {
pen.x -= getTextWidth(string); pen.x -= getTextWidth(string);
@ -319,7 +319,7 @@ uint32_t DrawUtils::getTextWidth(const char *string) {
uint32_t DrawUtils::getTextWidth(const wchar_t *string) { uint32_t DrawUtils::getTextWidth(const wchar_t *string) {
FT_GlyphSlot slot = ft_face->glyph; FT_GlyphSlot slot = ft_face->glyph;
uint32_t width = 0; uint32_t width = 0;
for (; *string; string++) { for (; *string; string++) {
FT_Load_Glyph(ft_face, FT_Get_Char_Index(ft_face, *string), FT_LOAD_BITMAP_METRICS_ONLY); FT_Load_Glyph(ft_face, FT_Get_Char_Index(ft_face, *string), FT_LOAD_BITMAP_METRICS_ONLY);

View File

@ -34,8 +34,8 @@ const char *autoboot_config_strings[] = {
template<typename... Args> template<typename... Args>
std::string string_format(const std::string &format, Args... args) { std::string string_format(const std::string &format, Args... args) {
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0' int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
auto size = static_cast<size_t>(size_s); auto size = static_cast<size_t>(size_s);
auto buf = std::make_unique<char[]>(size); auto buf = std::make_unique<char[]>(size);
std::snprintf(buf.get(), size, format.c_str(), args...); std::snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
} }
@ -75,15 +75,15 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) {
OSFatal("Failed to alloc memory for screen"); OSFatal("Failed to alloc memory for screen");
} }
uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV); uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV);
uint32_t drcBufferSize = OSScreenGetBufferSizeEx(SCREEN_DRC); uint32_t drcBufferSize = OSScreenGetBufferSizeEx(SCREEN_DRC);
DrawUtils::initBuffers(screenBuffer, tvBufferSize, (void *) ((uint32_t) screenBuffer + tvBufferSize), drcBufferSize); DrawUtils::initBuffers(screenBuffer, tvBufferSize, (void *) ((uint32_t) screenBuffer + tvBufferSize), drcBufferSize);
DrawUtils::initFont(); DrawUtils::initFont();
uint32_t selected = autobootOptionInput > 0 ? autobootOptionInput : 0; uint32_t selected = autobootOptionInput > 0 ? autobootOptionInput : 0;
int autoboot = autobootOptionInput; int autoboot = autobootOptionInput;
bool redraw = true; bool redraw = true;
while (true) { while (true) {
VPADStatus vpad{}; VPADStatus vpad{};
VPADRead(VPAD_CHAN_0, &vpad, 1, nullptr); VPADRead(VPAD_CHAN_0, &vpad, 1, nullptr);
@ -102,10 +102,10 @@ int32_t handleMenuScreen(std::string &configPath, int32_t autobootOptionInput) {
break; break;
} else if (vpad.trigger & VPAD_BUTTON_X) { } else if (vpad.trigger & VPAD_BUTTON_X) {
autoboot = -1; autoboot = -1;
redraw = true; redraw = true;
} else if (vpad.trigger & VPAD_BUTTON_Y) { } else if (vpad.trigger & VPAD_BUTTON_Y) {
autoboot = selected; autoboot = selected;
redraw = true; redraw = true;
} }
if (redraw) { if (redraw) {
@ -174,14 +174,14 @@ nn::act::SlotNo handleAccountSelectScreen(const std::vector<std::shared_ptr<Acco
OSFatal("Failed to alloc memory for screen"); OSFatal("Failed to alloc memory for screen");
} }
uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV); uint32_t tvBufferSize = OSScreenGetBufferSizeEx(SCREEN_TV);
uint32_t drcBufferSize = OSScreenGetBufferSizeEx(SCREEN_DRC); uint32_t drcBufferSize = OSScreenGetBufferSizeEx(SCREEN_DRC);
DrawUtils::initBuffers(screenBuffer, tvBufferSize, (void *) ((uint32_t) screenBuffer + tvBufferSize), drcBufferSize); DrawUtils::initBuffers(screenBuffer, tvBufferSize, (void *) ((uint32_t) screenBuffer + tvBufferSize), drcBufferSize);
DrawUtils::initFont(); DrawUtils::initFont();
int32_t selected = 0; int32_t selected = 0;
bool redraw = true; bool redraw = true;
while (true) { while (true) {
VPADStatus vpad{}; VPADStatus vpad{};
VPADRead(VPAD_CHAN_0, &vpad, 1, nullptr); VPADRead(VPAD_CHAN_0, &vpad, 1, nullptr);
@ -206,21 +206,21 @@ nn::act::SlotNo handleAccountSelectScreen(const std::vector<std::shared_ptr<Acco
// draw buttons // draw buttons
uint32_t index = 8 + 24 + 8 + 4; uint32_t index = 8 + 24 + 8 + 4;
int32_t start = (selected / 5) * 5; int32_t start = (selected / 5) * 5;
int32_t end = (start + 5) < (int32_t) data.size() ? (start + 5) : data.size(); int32_t end = (start + 5) < (int32_t) data.size() ? (start + 5) : data.size();
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
auto &val = data[i]; auto &val = data[i];
if (val->miiImageSize > 0) { if (val->miiImageSize > 0) {
// Draw Mii // Draw Mii
auto width = 128; auto width = 128;
auto height = 128; auto height = 128;
auto target_height = 64u; auto target_height = 64u;
auto target_width = 64u; auto target_width = 64u;
auto xOffset = 20; auto xOffset = 20;
auto yOffset = index; auto yOffset = index;
for (uint32_t y = 0; y < target_height; y++) { for (uint32_t y = 0; y < target_height; y++) {
for (uint32_t x = 0; x < target_width; x++) { for (uint32_t x = 0; x < target_width; x++) {
uint32_t col = (((x) *width / target_width) + ((target_height - y - 1) * height / target_height) * width) * 4; uint32_t col = (((x) *width / target_width) + ((target_height - y - 1) * height / target_height) * width) * 4;
uint32_t colVal = ((uint32_t *) &val->miiImageBuffer[col + 1])[0]; uint32_t colVal = ((uint32_t *) &val->miiImageBuffer[col + 1])[0];
if (colVal == 0x00808080) { // Remove the green background. if (colVal == 0x00808080) { // Remove the green background.
DrawUtils::drawPixel(x + xOffset, y + yOffset, COLOR_BACKGROUND.r, COLOR_BACKGROUND.g, COLOR_BACKGROUND.b, COLOR_BACKGROUND.a); DrawUtils::drawPixel(x + xOffset, y + yOffset, COLOR_BACKGROUND.r, COLOR_BACKGROUND.g, COLOR_BACKGROUND.b, COLOR_BACKGROUND.a);
@ -249,7 +249,7 @@ nn::act::SlotNo handleAccountSelectScreen(const std::vector<std::shared_ptr<Acco
// draw top bar // draw top bar
DrawUtils::setFontSize(24); DrawUtils::setFontSize(24);
DrawUtils::print(16, 6 + 24, "Select your Account"); DrawUtils::print(16, 6 + 24, "Select your Account");
auto curPage = (selected / 5) + 1; auto curPage = (selected / 5) + 1;
auto totalPages = data.size() % 5 == 0 ? data.size() / 5 : data.size() / 5 + 1; auto totalPages = data.size() % 5 == 0 ? data.size() / 5 : data.size() / 5 + 1;
DrawUtils::print(SCREEN_WIDTH - 50, 6 + 24, string_format("%d/%d", curPage, totalPages).c_str()); DrawUtils::print(SCREEN_WIDTH - 50, 6 + 24, string_format("%d/%d", curPage, totalPages).c_str());
DrawUtils::drawRectFilled(8, 8 + 24 + 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_WHITE); DrawUtils::drawRectFilled(8, 8 + 24 + 4, SCREEN_WIDTH - 8 * 2, 3, COLOR_WHITE);
@ -287,7 +287,7 @@ nn::act::SlotNo handleAccountSelectScreen(const std::vector<std::shared_ptr<Acco
free(screenBuffer); free(screenBuffer);
auto i = 0; auto i = 0;
nn::act::SlotNo resultSlot = 0; nn::act::SlotNo resultSlot = 0;
for (auto const &val : data) { for (auto const &val : data) {
if (i == selected) { if (i == selected) {

View File

@ -7,16 +7,14 @@
#include <string> #include <string>
#include <vector> #include <vector>
// clang-format off #define COLOR_WHITE Color(0xffffffff)
#define COLOR_WHITE Color(0xffffffff) #define COLOR_BLACK Color(0, 0, 0, 255)
#define COLOR_BLACK Color(0, 0, 0, 255) #define COLOR_BACKGROUND COLOR_BLACK
#define COLOR_BACKGROUND COLOR_BLACK #define COLOR_TEXT COLOR_WHITE
#define COLOR_TEXT COLOR_WHITE #define COLOR_TEXT2 Color(0xB3ffffff)
#define COLOR_TEXT2 Color(0xB3ffffff) #define COLOR_AUTOBOOT Color(0xaeea00ff)
#define COLOR_AUTOBOOT Color(0xaeea00ff) #define COLOR_BORDER Color(204, 204, 204, 255)
#define COLOR_BORDER Color(204, 204, 204, 255) #define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff)
#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff)
// clang-format on
enum { enum {
BOOT_OPTION_WII_U_MENU, BOOT_OPTION_WII_U_MENU,

View File

@ -22,7 +22,7 @@ static void StartAppletAndExit() {
DEBUG_FUNCTION_LINE("Wait for applet"); DEBUG_FUNCTION_LINE("Wait for applet");
ProcUIInit(OSSavesDone_ReadyToRelease); ProcUIInit(OSSavesDone_ReadyToRelease);
bool doProcUi = true; bool doProcUi = true;
bool launchWiiUMenuOnNextForeground = false; bool launchWiiUMenuOnNextForeground = false;
while (true) { while (true) {
switch (ProcUIProcessMessages(true)) { switch (ProcUIProcessMessages(true)) {
@ -92,7 +92,7 @@ bool getQuickBoot() {
FSInitCmdBlock(&cmdBlock); FSInitCmdBlock(&cmdBlock);
auto fileStream = new nn::sl::FileStream; auto fileStream = new nn::sl::FileStream;
auto *fsClient = (FSClient *) memalign(0x40, sizeof(FSClient)); auto *fsClient = (FSClient *) memalign(0x40, sizeof(FSClient));
memset(fsClient, 0, sizeof(*fsClient)); memset(fsClient, 0, sizeof(*fsClient));
FSAddClient(fsClient, FS_ERROR_FLAG_NONE); FSAddClient(fsClient, FS_ERROR_FLAG_NONE);
@ -211,7 +211,7 @@ bool getQuickBoot() {
MCPTitleListType titleInfo; MCPTitleListType titleInfo;
int32_t handle = MCP_Open(); int32_t handle = MCP_Open();
auto err = MCP_GetTitleInfo(handle, info.titleId, &titleInfo); auto err = MCP_GetTitleInfo(handle, info.titleId, &titleInfo);
MCP_Close(handle); MCP_Close(handle);
if (err == 0) { if (err == 0) {
loadConsoleAccount(data.uuid); loadConsoleAccount(data.uuid);

View File

@ -35,15 +35,15 @@ static int numberUSBStorageDevicesConnected() {
memset(config, 0, sizeof(UhsConfig)); memset(config, 0, sizeof(UhsConfig));
config->controller_num = 0; config->controller_num = 0;
uint32_t size = 5120; uint32_t size = 5120;
void *buffer = memalign(0x40, size); void *buffer = memalign(0x40, size);
if (buffer == nullptr) { if (buffer == nullptr) {
free(handle); free(handle);
free(config); free(config);
} }
memset(buffer, 0, size); memset(buffer, 0, size);
config->buffer = buffer; config->buffer = buffer;
config->buffer_size = size; config->buffer_size = size;
if (UhsClientOpen(handle, config) != UHS_STATUS_OK) { if (UhsClientOpen(handle, config) != UHS_STATUS_OK) {
@ -102,7 +102,7 @@ void initExternalStorage() {
nn::spm::Initialize(); nn::spm::Initialize();
nn::spm::StorageListItem items[0x20]; nn::spm::StorageListItem items[0x20];
int tries = 0; int tries = 0;
bool found = false; bool found = false;
while (tries < 1200) { // Wait up to 20 seconds, like the Wii U Menu while (tries < 1200) { // Wait up to 20 seconds, like the Wii U Menu

View File

@ -7,15 +7,15 @@
#include <whb/log_udp.h> #include <whb/log_udp.h>
uint32_t moduleLogInit = false; uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false; uint32_t cafeLogInit = false;
uint32_t udpLogInit = false; uint32_t udpLogInit = false;
#endif #endif
void initLogging() { void initLogging() {
#ifdef DEBUG #ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) { if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit(); cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit(); udpLogInit = WHBLogUdpInit();
} }
#endif // DEBUG #endif // DEBUG
} }