Format the code via clang-format (#1)

* Format the code via clang-format
This commit is contained in:
Maschell 2022-02-02 19:12:52 +01:00 committed by GitHub
parent e4b5d5920c
commit c82f178943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 326 additions and 236 deletions

66
.clang-format Normal file
View File

@ -0,0 +1,66 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: None
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 0
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -6,8 +6,16 @@ on:
- main
jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request]
jobs:
clang-format:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
build-binary:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary

View File

@ -42,6 +42,9 @@ docker run -it --rm -v ${PWD}:/project environmentloader-builder make
docker run -it --rm -v ${PWD}:/project environmentloader-builder make clean
```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`
## Credits
- maschell

View File

@ -1,15 +1,15 @@
#include <coreinit/debug.h>
#include "utils/logger.h"
#include <bits/shared_ptr.h>
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/memdefaultheap.h>
#include <whb/sdcard.h>
#include <whb/file.h>
#include <whb/log.h>
#include <bits/shared_ptr.h>
#include <coreinit/dynload.h>
#include "utils/logger.h"
#include <whb/sdcard.h>
#include "elfio/elfio.hpp"
#include "ElfUtils.h"
#include "elfio/elfio.hpp"
int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *sizeOut) {
char path[256];
@ -33,7 +33,7 @@ int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *si
goto exit;
}
exit:
exit:
WHBUnmountSdCard();
return result;
}
@ -111,13 +111,13 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
bool ElfUtils::doRelocation(std::vector<std::shared_ptr<RelocationData>> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) {
for (auto const &curReloc: relocData) {
for (auto const &curReloc : relocData) {
std::string functionName = curReloc->getName();
std::string rplName = curReloc->getImportRPLInformation()->getName();
int32_t isData = curReloc->getImportRPLInformation()->isData();
OSDynLoad_Module rplHandle = nullptr;
auto err = OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle);
if (err != OS_DYNLOAD_OK || rplHandle == 0) {
// only acquire if not already loaded.
@ -234,19 +234,19 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
}
if (freeSlot == nullptr) {
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full\n");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampolin[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampolin[0])));
return false;
}
if (target - (uint32_t) &(freeSlot->trampolin[0]) > 0x1FFFFFC) {
if (target - (uint32_t) & (freeSlot->trampolin[0]) > 0x1FFFFFC) {
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) &(freeSlot->trampolin[0])));
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, (target - (uint32_t) & (freeSlot->trampolin[0])));
return false;
}
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampolin[3] = 0x4E800420; // bctr
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF);// lis r11, real_addr@h
freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
freeSlot->trampolin[3] = 0x4E800420; // bctr
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
@ -256,7 +256,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
// Relocations for the imports may be overridden
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
}
auto symbolValue = (uint32_t) &(freeSlot->trampolin[0]);
auto symbolValue = (uint32_t) & (freeSlot->trampolin[0]);
value = symbolValue + addend;
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
}

View File

@ -1,11 +1,11 @@
#pragma once
#include "common/relocation_defines.h"
#include "module/RelocationData.h"
#include <cstdint>
#include <cstdio>
#include "common/relocation_defines.h"
#include <memory>
#include <vector>
#include "module/RelocationData.h"
#ifdef __cplusplus
@ -17,6 +17,7 @@ int32_t LoadFileToMem(const char *relativefilepath, char **fileOut, uint32_t *si
uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath);
uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fileSize);
// clang-format off
#define R_PPC_NONE 0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR16_LO 4
@ -44,6 +45,7 @@ uint32_t load_loader_elf(unsigned char *baseAddress, char *elf_data, uint32_t fi
#define PPC_LOW24 0x03FFFFFC
#define PPC_LOW14 0x0020FFFC
#define PPC_HALF16 0xFFFF
// clang-format on
#ifdef __cplusplus
}

View File

@ -17,13 +17,14 @@
#pragma once
#include <cstdint>
#include <cstddef>
#include <cstdint>
#ifdef __cplusplus
extern "C" {
#endif
// clang-format off
#define DYN_LINK_FUNCTION_NAME_LENGTH 351
#define DYN_LINK_IMPORT_NAME_LENGTH 50
@ -31,6 +32,7 @@ extern "C" {
#define DYN_LINK_IMPORT_LIST_LENGTH 50
#define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
// clang-format on
typedef struct _dyn_linking_function_t {
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];

View File

@ -17,10 +17,10 @@
#pragma once
#include <cstdint>
#include <cstddef>
#include "dynamic_linking_defines.h"
#include "relocation_defines.h"
#include <cstddef>
#include <cstdint>
#ifdef __cplusplus
extern "C" {

View File

@ -19,14 +19,15 @@
#include <cstdint>
typedef enum RelocationTrampolinStatus{
// clang-format off
typedef enum RelocationTrampolinStatus {
RELOC_TRAMP_FREE = 0,
RELOC_TRAMP_FIXED = 1,
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
RELOC_TRAMP_IMPORT_DONE = 3,
} RelocationTrampolinStatus;
typedef enum RelocationType{
typedef enum RelocationType {
RELOC_TYPE_FIXED = 0,
RELOC_TYPE_IMPORT = 1
} RelocationType;
@ -35,3 +36,4 @@ typedef struct relocation_trampolin_entry_t {
uint32_t trampolin[4];
RelocationTrampolinStatus status;
} relocation_trampolin_entry_t;
// clang-format on

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,3 +1,4 @@
// clang-format off
/*
Copyright (C) 2001-2015 by Serge Lamikhov-Center

View File

@ -1,9 +1,9 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <strings.h>
#include <fs/CFile.hpp>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
CFile::CFile() {
iFd = -1;
@ -35,16 +35,16 @@ int32_t CFile::open(const std::string &filepath, eOpenTypes mode) {
switch (mode) {
default:
case ReadOnly: // file must exist
case ReadOnly:// file must exist
openMode = O_RDONLY;
break;
case WriteOnly: // file will be created / zerod
case WriteOnly:// file will be created / zerod
openMode = O_TRUNC | O_CREAT | O_WRONLY;
break;
case ReadWrite: // file must exist
case ReadWrite:// file must exist
openMode = O_RDWR;
break;
case Append: // append to file, file will be created if missing. write only
case Append:// append to file, file will be created if missing. write only
openMode = O_CREAT | O_APPEND | O_WRONLY;
break;
}
@ -171,5 +171,3 @@ int32_t CFile::fwrite(const char *format, ...) {
return result;
}

View File

@ -1,10 +1,10 @@
#ifndef CFILE_HPP_
#define CFILE_HPP_
#include <stdio.h>
#include <string>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unistd.h>
#include <wut_types.h>

View File

@ -24,14 +24,14 @@
* DirList Class
* for WiiXplorer 2010
***************************************************************************/
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <strings.h>
#include <algorithm>
#include <sys/stat.h>
#include <sys/dirent.h>
#include <sys/stat.h>
#include <fs/DirList.h>
#include <utils/StringTools.h>

View File

@ -27,8 +27,8 @@
#ifndef ___DIRLIST_H_
#define ___DIRLIST_H_
#include <vector>
#include <string>
#include <vector>
#include <wut_types.h>
typedef struct {
@ -97,6 +97,7 @@ public:
Dirs = 0x02,
CheckSubfolders = 0x08,
};
protected:
// Internal parser
BOOL InternalLoadPath(std::string &path);

View File

@ -33,23 +33,22 @@ void KernelWriteU32(uint32_t addr, uint32_t value) {
}
/* Write a 32-bit word with kernel permissions */
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) {
asm volatile (
"li 3,1\n"
"li 4,0\n"
"mr 5,%1\n"
"li 6,0\n"
"li 7,0\n"
"lis 8,1\n"
"mr 9,%0\n"
"mr %1,1\n"
"li 0,0x3500\n"
"sc\n"
"nop\n"
"mr 1,%1\n"
:
: "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12"
);
void __attribute__((noinline)) kern_write(void *addr, uint32_t value) {
asm volatile(
"li 3,1\n"
"li 4,0\n"
"mr 5,%1\n"
"li 6,0\n"
"li 7,0\n"
"lis 8,1\n"
"mr 9,%0\n"
"mr %1,1\n"
"li 0,0x3500\n"
"sc\n"
"nop\n"
"mr 1,%1\n"
:
: "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12");
}

View File

@ -2,6 +2,7 @@
#include <cstdint>
// clang-format off
#define ADDRESS_main_entry_hook 0x0101C56C
#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
@ -9,9 +10,10 @@
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu
#define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL)
// clang-format on
void RevertMainHook();
void KernelWriteU32(uint32_t addr, uint32_t value);
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value);
void __attribute__((noinline)) kern_write(void *addr, uint32_t value);

View File

@ -1,41 +1,42 @@
#include <cstring>
#include <gx2/state.h>
#include "utils/StringTools.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/foreground.h>
#include <coreinit/ios.h>
#include <coreinit/screen.h>
#include <coreinit/title.h>
#include <elfio/elfio.hpp>
#include <fcntl.h>
#include <gx2/state.h>
#include <malloc.h>
#include <memory>
#include <nn/act/client_cpp.h>
#include <proc_ui/procui.h>
#include <sysapp/launch.h>
#include <sysapp/title.h>
#include <coreinit/foreground.h>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <nn/act/client_cpp.h>
#include <coreinit/dynload.h>
#include <whb/log_udp.h>
#include <vector>
#include <vpad/input.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <vector>
#include <coreinit/dynload.h>
#include <coreinit/title.h>
#include <coreinit/screen.h>
#include <memory>
#include <malloc.h>
#include <vpad/input.h>
#include <coreinit/debug.h>
#include <fcntl.h>
#include "utils/StringTools.h"
#include <whb/log_udp.h>
#include "fs/DirList.h"
#include "module/ModuleDataFactory.h"
#include "ElfUtils.h"
#include "kernel.h"
#include "common/module_defines.h"
#include "fs/DirList.h"
#include "kernel.h"
#include "module/ModuleDataFactory.h"
#include "utils/DrawUtils.h"
// clang-format off
#define MEMORY_REGION_START 0x00A00000
#define MEMORY_REGION_SIZE 0x00600000
#define MEMORY_REGION_END (MEMORY_REGION_START + MEMORY_REGION_SIZE)
#define AUTOBOOT_CONFIG_PATH "fs:/vol/external01/wiiu/environments/default.cfg"
// clang-format on
bool CheckRunning() {
switch (ProcUIProcessMessages(true)) {
@ -109,7 +110,7 @@ int main(int argc, char **argv) {
auto handle = IOS_Open("/dev/mcp", IOS_OPEN_READ);
if (handle >= 0) {
int in = 0xF9; // IPC_CUSTOM_COPY_ENVIRONMENT_PATH
int in = 0xF9;// IPC_CUSTOM_COPY_ENVIRONMENT_PATH
if (IOS_Ioctl(handle, 100, &in, sizeof(in), environmentPath, sizeof(environmentPath)) == IOS_ERROR_OK) {
DEBUG_FUNCTION_LINE("Boot into %s", environmentPath);
}
@ -200,7 +201,9 @@ int main(int argc, char **argv) {
DEBUG_FUNCTION_LINE("Calling entrypoint @%08X", moduleData.value()->getEntrypoint());
char *arr[1];
arr[0] = (char *) environment_path.c_str();
((int (*)(int, char **)) moduleData.value()->getEntrypoint())(1, arr);
// clang-format off
((int(*)(int, char **)) moduleData.value()->getEntrypoint())(1, arr);
// clang-format on
DEBUG_FUNCTION_LINE("Back from module");
}
} else {
@ -211,7 +214,9 @@ int main(int argc, char **argv) {
if ((i + 1) < argc) {
i++;
DEBUG_FUNCTION_LINE("call forceDefaultTitleIDToWiiUMenu");
auto forceDefaultTitleIDToWiiUMenu = (void (*)()) argv[i];
// clang-format off
auto forceDefaultTitleIDToWiiUMenu = (void(*)()) argv[i];
// clang-format on
forceDefaultTitleIDToWiiUMenu();
}
}
@ -233,6 +238,7 @@ int main(int argc, char **argv) {
return 0;
}
// clang-format off
#define COLOR_WHITE Color(0xffffffff)
#define COLOR_BLACK Color(0, 0, 0, 255)
#define COLOR_RED Color(237, 28, 36, 255)
@ -242,7 +248,7 @@ int main(int argc, char **argv) {
#define COLOR_AUTOBOOT Color(0xaeea00ff)
#define COLOR_BORDER Color(204, 204, 204, 255)
#define COLOR_BORDER_HIGHLIGHTED Color(0x3478e4ff)
// clang-format on
std::string EnvironmentSelectionScreen(const std::map<std::string, std::string> &payloads, int32_t autobootIndex) {
OSScreenInit();
@ -301,7 +307,7 @@ std::string EnvironmentSelectionScreen(const std::map<std::string, std::string>
uint32_t index = 8 + 24 + 8 + 4;
uint32_t i = 0;
if (!payloads.empty()) {
for (auto const&[key, val]: payloads) {
for (auto const &[key, val] : payloads) {
if (i == selected) {
DrawUtils::drawRect(16, index, SCREEN_WIDTH - 16 * 2, 44, 4, COLOR_BORDER_HIGHLIGHTED);
} else {
@ -362,7 +368,7 @@ std::string EnvironmentSelectionScreen(const std::map<std::string, std::string>
writeFileContent(AUTOBOOT_CONFIG_PATH, "-1");
} else {
int i = 0;
for (auto const&[key, val]: payloads) {
for (auto const &[key, val] : payloads) {
if (i == autoBoot) {
DEBUG_FUNCTION_LINE("Save config");
writeFileContent(AUTOBOOT_CONFIG_PATH, key);
@ -374,7 +380,7 @@ std::string EnvironmentSelectionScreen(const std::map<std::string, std::string>
}
int i = 0;
for (auto const&[key, val]: payloads) {
for (auto const &[key, val] : payloads) {
if (i == selected) {
return val;
}

View File

@ -17,10 +17,11 @@
#pragma once
#include <string>
#include <optional>
#include <utility>
#include "utils/logger.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
class ImportRPLInformation {

View File

@ -17,11 +17,11 @@
#pragma once
#include <string>
#include <vector>
#include "RelocationData.h"
#include <map>
#include <set>
#include "RelocationData.h"
#include <string>
#include <vector>
class ModuleData {
public:

View File

@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <string>
#include <vector>
#include <map>
#include <coreinit/cache.h>
#include "ModuleDataFactory.h"
#include "ElfUtils.h"
#include <coreinit/cache.h>
#include <map>
#include <string>
#include <vector>
using namespace ELFIO;
@ -144,7 +144,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t destination_address_en
}
auto relocationData = getImportRelocationData(reader, destinations);
for (auto const &reloc: relocationData) {
for (auto const &reloc : relocationData) {
moduleData->addRelocationData(reloc);
}

View File

@ -17,12 +17,12 @@
#pragma once
#include <string>
#include <vector>
#include <map>
#include "../common/relocation_defines.h"
#include "ModuleData.h"
#include "elfio/elfio.hpp"
#include "../common/relocation_defines.h"
#include <map>
#include <string>
#include <vector>
class ModuleDataFactory {
public:

View File

@ -17,10 +17,10 @@
#pragma once
#include <string>
#include <memory>
#include <utility>
#include "ImportRPLInformation.h"
#include <memory>
#include <string>
#include <utility>
class RelocationData {

View File

@ -1,11 +1,11 @@
#include "DrawUtils.h"
#include <cmath>
#include <coreinit/cache.h>
#include <coreinit/memory.h>
#include <coreinit/screen.h>
#include <coreinit/cache.h>
#include <png.h>
#include <ft2build.h>
#include <png.h>
#include FT_FREETYPE_H
// buffer width
@ -14,9 +14,9 @@
bool DrawUtils::isBackBuffer;
uint8_t* DrawUtils::tvBuffer = nullptr;
uint8_t *DrawUtils::tvBuffer = nullptr;
uint32_t DrawUtils::tvSize = 0;
uint8_t* DrawUtils::drcBuffer = nullptr;
uint8_t *DrawUtils::drcBuffer = nullptr;
uint32_t DrawUtils::drcSize = 0;
// Don't put those into the class or we have to include ft everywhere
@ -24,32 +24,29 @@ static FT_Library ft_lib = nullptr;
static FT_Face ft_face = nullptr;
static Color font_col = {0xFFFFFFFF};
void DrawUtils::initBuffers(void* tvBuffer, uint32_t tvSize, void* drcBuffer, uint32_t drcSize)
{
DrawUtils::tvBuffer = (uint8_t*) tvBuffer;
void DrawUtils::initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize) {
DrawUtils::tvBuffer = (uint8_t *) tvBuffer;
DrawUtils::tvSize = tvSize;
DrawUtils::drcBuffer = (uint8_t*) drcBuffer;
DrawUtils::drcBuffer = (uint8_t *) drcBuffer;
DrawUtils::drcSize = drcSize;
}
void DrawUtils::beginDraw()
{
uint32_t pixel = *(uint32_t*) tvBuffer;
void DrawUtils::beginDraw() {
uint32_t pixel = *(uint32_t *) tvBuffer;
// check which buffer is currently used
OSScreenPutPixelEx(SCREEN_TV, 0, 0, 0xABCDEF90);
if (*(uint32_t*) tvBuffer == 0xABCDEF90) {
if (*(uint32_t *) tvBuffer == 0xABCDEF90) {
isBackBuffer = false;
} else {
isBackBuffer = true;
}
// restore the pixel we used for checking
*(uint32_t*) tvBuffer = pixel;
*(uint32_t *) tvBuffer = pixel;
}
void DrawUtils::endDraw()
{
void DrawUtils::endDraw() {
// OSScreenFlipBuffersEx already flushes the cache?
// DCFlushRange(tvBuffer, tvSize);
// DCFlushRange(drcBuffer, drcSize);
@ -58,14 +55,12 @@ void DrawUtils::endDraw()
OSScreenFlipBuffersEx(SCREEN_TV);
}
void DrawUtils::clear(Color col)
{
void DrawUtils::clear(Color col) {
OSScreenClearBufferEx(SCREEN_TV, col.color);
OSScreenClearBufferEx(SCREEN_DRC, col.color);
}
void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
float opacity = a / 255.0f;
// put pixel in the drc buffer
@ -75,12 +70,11 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
i += drcSize / 2;
}
if (a == 0xFF) {
drcBuffer[i ] = r;
drcBuffer[i] = r;
drcBuffer[i + 1] = g;
drcBuffer[i + 2] = b;
}
else {
drcBuffer[i ] = r * opacity + drcBuffer[i ] * (1 - opacity);
} else {
drcBuffer[i] = r * opacity + drcBuffer[i] * (1 - opacity);
drcBuffer[i + 1] = g * opacity + drcBuffer[i + 1] * (1 - opacity);
drcBuffer[i + 2] = b * opacity + drcBuffer[i + 2] * (1 - opacity);
}
@ -88,29 +82,27 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
// scale and put pixel in the tv buffer
for (uint32_t yy = (y * 1.5); yy < ((y * 1.5) + 1); yy++) {
for (uint32_t xx = (x * 1.5); xx < ((x * 1.5) + 1); xx++) {
for (uint32_t xx = (x * 1.5); xx < ((x * 1.5) + 1); xx++) {
uint32_t i = (xx + yy * TV_WIDTH) * 4;
if (i + 3 < tvSize / 2) {
if (isBackBuffer) {
i += tvSize / 2;
}
if (a == 0xFF) {
tvBuffer[i ] = r;
tvBuffer[i] = r;
tvBuffer[i + 1] = g;
tvBuffer[i + 2] = b;
}
else {
tvBuffer[i ] = r * opacity + tvBuffer[i ] * (1 - opacity);
} else {
tvBuffer[i] = r * opacity + tvBuffer[i] * (1 - opacity);
tvBuffer[i + 1] = g * opacity + tvBuffer[i + 1] * (1 - opacity);
tvBuffer[i + 2] = b * opacity + tvBuffer[i + 2] * (1 - opacity);
}
}
}
}
}
}
}
void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col)
{
void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col) {
for (uint32_t yy = y; yy < y + h; yy++) {
for (uint32_t xx = x; xx < x + w; xx++) {
drawPixel(xx, yy, col);
@ -118,30 +110,28 @@ void DrawUtils::drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, C
}
}
void DrawUtils::drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col)
{
void DrawUtils::drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col) {
drawRectFilled(x, y, w, borderSize, col);
drawRectFilled(x, y + h - borderSize, w, borderSize, col);
drawRectFilled(x, y, borderSize, h, col);
drawRectFilled(x + w - borderSize, y, borderSize, h, col);
}
void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t* data)
{
if ( data[0] != 'B' || data[1] != 'M' ) {
// invalid header
return;
}
void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data) {
if (data[0] != 'B' || data[1] != 'M') {
// invalid header
return;
}
uint32_t dataPos = __builtin_bswap32(*(uint32_t*)&(data[0x0A]));
uint32_t width = __builtin_bswap32(*(uint32_t*)&(data[0x12]));
uint32_t height = __builtin_bswap32(*(uint32_t*)&(data[0x16]));
uint32_t dataPos = __builtin_bswap32(*(uint32_t *) &(data[0x0A]));
uint32_t width = __builtin_bswap32(*(uint32_t *) &(data[0x12]));
uint32_t height = __builtin_bswap32(*(uint32_t *) &(data[0x16]));
if (dataPos == 0) {
dataPos = 54;
}
if (dataPos == 0) {
dataPos = 54;
}
data += dataPos;
data += dataPos;
// TODO flip image since bitmaps are stored upside down
@ -153,28 +143,26 @@ void DrawUtils::drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32
}
}
static void png_read_data(png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead)
{
void** data = (void**) png_get_io_ptr(png_ptr);
static void png_read_data(png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead) {
void **data = (void **) png_get_io_ptr(png_ptr);
memcpy(outBytes, *data, byteCountToRead);
*((uint8_t**) data) += byteCountToRead;
*((uint8_t **) data) += byteCountToRead;
}
void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
{
void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t *data) {
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(png_ptr == NULL) {
if (png_ptr == NULL) {
return;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if(info_ptr == NULL) {
if (info_ptr == NULL) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
return;
}
png_set_read_fn(png_ptr, (void*) &data, png_read_data);
png_set_read_fn(png_ptr, (void *) &data, png_read_data);
png_read_info(png_ptr, info_ptr);
@ -183,22 +171,21 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
int bitDepth = 0;
int colorType = -1;
uint32_t retval = png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, &colorType, NULL, NULL, NULL);
if(retval != 1) {
if (retval != 1) {
return;
}
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++) {
png_read_row(png_ptr, (png_bytep)rowData, NULL);
for (uint32_t yy = y; yy < y + height; yy++) {
png_read_row(png_ptr, (png_bytep) rowData, NULL);
for (uint32_t xx = x; xx < x + width; xx++) {
if (colorType == PNG_COLOR_TYPE_RGB_ALPHA) {
uint32_t i = (xx - x) * 4;
drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], rowData[i + 3]);
}
else if (colorType == PNG_COLOR_TYPE_RGB) {
} else if (colorType == PNG_COLOR_TYPE_RGB) {
uint32_t i = (xx - x) * 3;
drawPixel(xx, yy, rowData[i], rowData[i + 1], rowData[i + 2], 0xFF);
}
@ -209,39 +196,34 @@ void DrawUtils::drawPNG(uint32_t x, uint32_t y, const uint8_t* data)
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
}
void DrawUtils::initFont()
{
void* font = NULL;
void DrawUtils::initFont() {
void *font = NULL;
uint32_t size = 0;
OSGetSharedData(OS_SHAREDDATATYPE_FONT_STANDARD, 0, &font, &size);
if (font && size) {
FT_Init_FreeType(&ft_lib);
FT_New_Memory_Face(ft_lib, (FT_Byte*) font, size, 0, &ft_face);
FT_New_Memory_Face(ft_lib, (FT_Byte *) font, size, 0, &ft_face);
}
}
void DrawUtils::deinitFont()
{
void DrawUtils::deinitFont() {
FT_Done_Face(ft_face);
FT_Done_FreeType(ft_lib);
}
void DrawUtils::setFontSize(uint32_t size)
{
void DrawUtils::setFontSize(uint32_t size) {
FT_Set_Pixel_Sizes(ft_face, 0, size);
}
void DrawUtils::setFontColor(Color col)
{
void DrawUtils::setFontColor(Color col) {
font_col = col;
}
static void draw_freetype_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y)
{
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
static void draw_freetype_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y) {
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
for (i = x, p = 0; i < x_max; i++, p++) {
for (j = y, q = 0; j < y_max; j++, q++) {
@ -255,25 +237,23 @@ static void draw_freetype_bitmap(FT_Bitmap* bitmap, FT_Int x, FT_Int y)
}
}
void DrawUtils::print(uint32_t x, uint32_t y, const char* string, bool alignRight)
{
wchar_t* buffer = new wchar_t[strlen(string) + 1];
void DrawUtils::print(uint32_t x, uint32_t y, const char *string, bool alignRight) {
wchar_t *buffer = new wchar_t[strlen(string) + 1];
size_t num = mbstowcs(buffer, string, strlen(string));
if (num > 0) {
buffer[num] = 0;
}
else {
wchar_t* tmp = buffer;
while ((*tmp++ = *string++));
} else {
wchar_t *tmp = buffer;
while ((*tmp++ = *string++))
;
}
print(x, y, buffer, alignRight);
delete[] buffer;
}
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_Vector pen = {(int) x, (int) y};
@ -298,17 +278,16 @@ void DrawUtils::print(uint32_t x, uint32_t y, const wchar_t* string, bool alignR
}
}
uint32_t DrawUtils::getTextWidth(const char* string)
{
wchar_t* buffer = new wchar_t[strlen(string) + 1];
uint32_t DrawUtils::getTextWidth(const char *string) {
wchar_t *buffer = new wchar_t[strlen(string) + 1];
size_t num = mbstowcs(buffer, string, strlen(string));
if (num > 0) {
buffer[num] = 0;
}
else {
wchar_t* tmp = buffer;
while ((*tmp++ = *string++));
} else {
wchar_t *tmp = buffer;
while ((*tmp++ = *string++))
;
}
uint32_t width = getTextWidth(buffer);
@ -317,8 +296,7 @@ uint32_t DrawUtils::getTextWidth(const char* string)
return width;
}
uint32_t DrawUtils::getTextWidth(const wchar_t* string)
{
uint32_t DrawUtils::getTextWidth(const wchar_t *string) {
FT_GlyphSlot slot = ft_face->glyph;
uint32_t width = 0;

View File

@ -7,11 +7,14 @@
#define SCREEN_HEIGHT 480
union Color {
Color(uint32_t color) {
this->color = color;
Color(uint32_t color) {
this->color = color;
}
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
this->r = r; this->g = g; this->b = b; this->a = a;
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
this->r = r;
this->g = g;
this->b = b;
this->a = a;
}
uint32_t color;
@ -25,7 +28,7 @@ union Color {
class DrawUtils {
public:
static void initBuffers(void* tvBuffer, uint32_t tvSize, void* drcBuffer, uint32_t drcSize);
static void initBuffers(void *tvBuffer, uint32_t tvSize, void *drcBuffer, uint32_t drcSize);
static void beginDraw();
static void endDraw();
static void clear(Color col);
@ -35,23 +38,23 @@ public:
static void drawRectFilled(uint32_t x, uint32_t y, uint32_t w, uint32_t h, Color col);
static void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t borderSize, Color col);
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t* data);
static void drawPNG(uint32_t x, uint32_t y, const uint8_t* data);
static void drawBitmap(uint32_t x, uint32_t y, uint32_t target_width, uint32_t target_height, const uint8_t *data);
static void drawPNG(uint32_t x, uint32_t y, const uint8_t *data);
static void initFont();
static void deinitFont();
static void setFontSize(uint32_t size);
static void setFontColor(Color col);
static void print(uint32_t x, uint32_t y, const char* string, bool alignRight = false);
static void print(uint32_t x, uint32_t y, const wchar_t* string, bool alignRight = false);
static uint32_t getTextWidth(const char* string);
static uint32_t getTextWidth(const wchar_t* string);
static void print(uint32_t x, uint32_t y, const char *string, bool alignRight = false);
static void print(uint32_t x, uint32_t y, const wchar_t *string, bool alignRight = false);
static uint32_t getTextWidth(const char *string);
static uint32_t getTextWidth(const wchar_t *string);
private:
static bool isBackBuffer;
static uint8_t* tvBuffer;
static uint8_t *tvBuffer;
static uint32_t tvSize;
static uint8_t* drcBuffer;
static uint8_t *drcBuffer;
static uint32_t drcSize;
};

View File

@ -23,17 +23,16 @@
*
* for WiiXplorer 2010
***************************************************************************/
#include <vector>
#include <string>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <string>
#include <strings.h>
#include <wut_types.h>
#include <stdio.h>
#include <utils/StringTools.h>
#include <vector>
#include <wchar.h>
#include <wut_types.h>
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
@ -249,7 +248,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
char *tmp; // varies
int len_rep; // length of rep (the string to remove)
int len_with; // length of with (the string to replace rep with)
int len_front; // distance between rep and end of last rep
int len_front;// distance between rep and end of last rep
int count; // number of replacements
// sanity checks and initialization
@ -257,7 +256,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
return NULL;
len_rep = strlen(rep);
if (len_rep == 0)
return NULL; // empty rep causes infinite loop during count
return NULL;// empty rep causes infinite loop during count
if (!with)
with = (char *) "";
len_with = strlen(with);
@ -283,7 +282,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
len_front = ins - orig;
tmp = strncpy(tmp, orig, len_front) + len_front;
tmp = strcpy(tmp, with) + len_with;
orig += len_front + len_rep; // move to next "end of rep"
orig += len_front + len_rep;// move to next "end of rep"
}
strcpy(tmp, orig);
return result;

View File

@ -26,8 +26,8 @@
#ifndef __STRING_TOOLS_H
#define __STRING_TOOLS_H
#include <vector>
#include <string>
#include <vector>
#include <wut_types.h>
class StringTools {
@ -62,4 +62,3 @@ public:
};
#endif /* __STRING_TOOLS_H */

View File

@ -1,13 +1,13 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif // DEBUG
#endif// DEBUG
void initLogging() {
#ifdef DEBUG
@ -15,7 +15,7 @@ void initLogging() {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
#endif// DEBUG
}
void deinitLogging() {
@ -32,5 +32,5 @@ void deinitLogging() {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
#endif// DEBUG
}

View File

@ -1,7 +1,7 @@
#pragma once
#include <whb/log.h>
#include <string.h>
#include <whb/log.h>
#ifdef __cplusplus
extern "C" {
@ -14,12 +14,14 @@ extern "C" {
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#else
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus
}
#endif