Skip to content
Snippets Groups Projects
Commit e1e8d47d authored by PoloNX's avatar PoloNX
Browse files

first commit

parents
No related branches found
No related tags found
No related merge requests found
romfs/gfx/lockpick.png

10.1 KiB

File added
File added
File added
File added
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include "Entity.hpp"
#include "Cursor.hpp"
#include "Input.hpp"
#include "RenderWindow.hpp"
#include "Reboot.hpp"
Cursor::Cursor()
{
posX = 105;
posY = 720 / 2 - 258 / 2 - 20;
}
void Cursor::moveCursorX(bool right)
{
if (right){
++column;
}
else{
--column;
}
}
bool Cursor::checkInputCursor(int value)
{
std::cout << "dans check input\n";
if (value == 14 or value == 18) //HidNpadButton_Right and HidNpadButton_StickLRight
{
moveCursorX(true);
std::cout << "dans move right\n";
}
else if (value == 12 or value == 16) //HidNpadButton_Left and HidNpadButton_StickLLeft
{
moveCursorX(false);
std::cout << "dans move left\n";
}
else if (value == 13 or value == 15 or value == 17 or value == 19) //HidNpadButton_Up and HidNpadButton_Down and HidNpadButton_StickLUp and HidNpadButton_StickLDown
{
if (line == 0){
posY = 537; //Cuz it's cool
if (column > -1 and column < 2){ //for ams and hekate
posX = 1280 / 2 - 75;
column = 0;
}
else{ //other
posX = 1280 / 2;
column = 1;
}
cursorWandH = 76;
line = 1;
}
else{
if (column == 0){ //for exit
column = 1;
}
else{ //for about
column = 2;
}
posY = 720 / 2 - 258 / 2 - 20;
cursorWandH = 258;
line = 0;
}
}
else if (value == 0) //HidNpadButton_A (reboot)
{
std::cout << "dans a\n";
if (line == 0){
Reboot reboot;
reboot.rebootNow(column);
}
else if (line == 1 and column == 1){
return true;
}
}
return false;
}
void Cursor::printCursor(RenderWindow render)
{
if (column > 3){
column = 0;
}
if (column < 0){
column = 3;
}
refreshPos();
rectCursor = {posX, posY, cursorWandH, cursorWandH};
render.renderRect(rectCursor);
}
void Cursor::refreshPos(){
if (line == 0){
posX = 105 + column * (258 + 14);
}
else{
posX = 552 + column * (100);
}
}
#include <SDL.h>
#include <SDL_image.h>
#include "Entity.hpp"
Entity::Entity(Vector2f p_pos, SDL_Texture* p_tex, int w, int h, int x, int y)
:pos(p_pos), tex(p_tex)
{
currentFrame.x = x;
currentFrame.y = y;
currentFrame.w = w;
currentFrame.h = h;
}
Entity::Entity(Vector2f p_pos, SDL_Texture* p_tex, int w, int h, int x, int y, int nFrames, int mSpeed)
:pos(p_pos), tex(p_tex)
{
frames = nFrames;
speed = mSpeed;
currentFrame.x = currentFrame.w * static_cast<int>((SDL_GetTicks() / speed) % frames);
currentFrame.y = y;
currentFrame.w = w;
currentFrame.h = h;
}
SDL_Texture* Entity::getTex()
{
return tex;
}
Vector2f& Entity::getPos()
{
return pos;
}
SDL_Rect Entity::getCurrentFrame()
{
return currentFrame;
}
Vector2f& Entity::addPos()
{
pos = Vector2f(10, 10);
return pos;
}
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <switch.h>
#include "Input.hpp"
#include "Cursor.hpp"
Input::Input(){
}
int Input::checkInput()
{
/*while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_JOYBUTTONDOWN:
return event.jbutton.button;
default:
inputValue = -1;
}
}*/
}
#include <iostream>
#include <switch.h>
#include "RenderWindow.hpp"
#include "Menu.hpp"
#include "Reboot.hpp"
#include "Cursor.hpp"
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <SDL2_gfxPrimitives.h>
void init();
int main(int argc, char *argv[])
{
init();
RenderWindow window("PayloadReboot", 1280, 720);
Menu menu (window);
Cursor cursor;
Input input;
SDL_Event event;
int inputValue = -1;
bool isOpen = true;
while (isOpen)
{
//input.checkInput();
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_JOYBUTTONDOWN:
inputValue = event.jbutton.button;
if(cursor.checkInputCursor(inputValue))
{
menu.printAbout();
}
default:
inputValue = -1;
}
}
window.clear();
menu.printMenu();
Reboot reboot;
//reboot.rebootNow(3);
cursor.printCursor(window);
window.display();
SDL_Delay(1000 / window.getRefreshRate());
}
}
void init()
{
socketInitializeDefault();
nxlinkStdio(); //redirect cout/cer to tcp
if (SDL_Init(SDL_INIT_VIDEO) > 0)
{
std::cout << "HEY... SDL_Init HAS FAILED. SDL_ERROR: " << SDL_GetError() << std::endl;
}
if (!(IMG_Init(IMG_INIT_PNG)))
{
std::cout << "HEY... IMG_Init HAS FAILED. SDL_ERROR: " << IMG_GetError() << std::endl;
}
if (!(TTF_Init()))
{
std::cout << "HEY... IMG_Init HAS FAILED. SDL_ERROR: " << TTF_GetError() << std::endl;
}
std::cout << "after ttf\n";
SDL_InitSubSystem(SDL_INIT_EVERYTHING); //Some init
SDL_JoystickEventState(SDL_ENABLE); //Joystick
SDL_JoystickOpen(0); //Open joystick
romfsInit(); //Init of romfs
}
#include <SDL.h>
#include <SDL_image.h>
#include <SDL2_gfxPrimitives.h>
#include <SDL_ttf.h>
#include <vector>
#include <iostream>
#include "Menu.hpp"
#include "Math.hpp"
#include "RenderWindow.hpp"
#include "Cursor.hpp"
#include "Input.hpp"
SDL_Point getsize(SDL_Texture* texture) {
SDL_Point size;
SDL_QueryTexture(texture, NULL, NULL, &size.x, &size.y);
return size;
}
Menu::Menu(RenderWindow pWindow)
{
window = pWindow;
//Create texture
tTitle = window.loadString("PayloadReboot");
chdir("romfs:/");
tExit = window.loadTexture("gfx/exit.png");
tInfo = window.loadTexture("gfx/info.png");
tHekate = window.loadTexture("gfx/hekate.png");
tAMS = window.loadTexture("gfx/fusee.png");
tLockpick = window.loadTexture("gfx/lockpick.png");
tLakka = window.loadTexture("gfx/lakka.png");
//Create rect
/*rectHekate = { 107, 0, 258, 258};
rectHekate.y = vertical / 2 - rectHekate.w / 2 - 20;
rectAms = { rectHekate.x + rectHekate.w + 14, 0, 258, 258};
rectAms.y = vertical / 2 - rectAms.w / 2 - 20;
rectLockpick = { rectAms.x + rectAms.w +14, 0, 258, 258};
rectLockpick.y = vertical / 2 - rectLockpick.w / 2 - 20;
rectLakka = { rectLakka.x + rectLakka.w + 14, 0, 258, 258};
rectLakka.y = vertical / 2 - rectLakka.w / 2 - 20;*/
rectTemplate = {105, vertical / 2 - 258 / 2 - 20, 258, 258};
}
void Menu::printMenu()
{
std::vector<Entity> vEntity {};
std::vector<Entity> vEntityCursor {};
SDL_Point size = getsize(tTitle);
vEntity.push_back(Entity (Vector2f(horizontal / 2 - size.x / 2, 0), tTitle, size.x, size.y, 0, 0));
/*REBOOT TEMPLATE*/
for (int i = 0; i < 4; ++i)
{
window.fillRect(rectTemplate, 80, 80, 80);
rectTemplate.x += rectTemplate.w + 14;
}
rectTemplate.x = 105;
/*ICONS HEKATE AMS...*/
vEntityCursor.push_back(Entity (Vector2f(rectTemplate.x, rectTemplate.y), tHekate, 258, 258, 0, 0));
vEntityCursor.push_back(Entity (Vector2f(rectTemplate.x + rectTemplate.w + 14, rectTemplate.y), tAMS, 258, 258, 0, 0));
vEntityCursor.push_back(Entity (Vector2f(rectTemplate.x + (rectTemplate.w + 14) * 2, rectTemplate.y), tLockpick, 258, 258, 0, 0));
vEntityCursor.push_back(Entity (Vector2f(rectTemplate.x + (rectTemplate.w + 14) * 3, rectTemplate.y), tLakka, 258, 258, 0, 0));
/*CIRCLE BEHIND SMALL ICONS*/
window.drawCircleBehindIcons();
/*BUTTON UNDER ICONS*/
size = getsize(tExit);
vEntity.push_back(Entity (Vector2f(horizontal / 2 - size.x * 1.5, 550), tExit, size.x, size.y, 0, 0));
size = getsize(tInfo);
vEntity.push_back(Entity (Vector2f(horizontal / 2 + size.x * 0.5, 550), tInfo, size.x, size.y, 0, 0));
for (auto i : vEntity)
{
window.render(i, 1);
}
for (auto i : vEntityCursor)
{
window.render(i, 1);
}
}
void Menu::printAbout(){
bool isOpen = true;
SDL_Event eventAbout;
std::vector<Entity> vEntity {};
SDL_Rect rect {320, 180, 640, 360};
window.fillRect(rect, 80, 80, 80);
//The code is disgusting but idk how to do better because \n doesn't work
SDL_Texture* tCredit = window.loadString("Thanks to :");
SDL_Texture* tSciresM = window.loadString("- SciresM for fusee");
SDL_Texture* tCTCaer = window.loadString("- CTCaer for hekate");
SDL_Texture* tshchmue = window.loadString("- shchmue for lockpick");
SDL_Texture* tpressA = window.loadString("- PRESS A TO EXIT !");
SDL_Point size = getsize(tCredit);
vEntity.push_back(Entity(Vector2f(340, 200), tCredit, size.x, size.y , 0, 0));
size = getsize(tSciresM);
vEntity.push_back(Entity(Vector2f(340, 230), tSciresM, size.x, size.y , 0, 0));
size = getsize(tCTCaer);
vEntity.push_back(Entity(Vector2f(340, 260), tCTCaer, size.x, size.y , 0, 0));
size = getsize(tshchmue);
vEntity.push_back(Entity(Vector2f(340, 290), tshchmue, size.x, size.y , 0, 0));
size = getsize(tpressA);
vEntity.push_back(Entity(Vector2f(340, 350), tpressA, size.x, size.y , 0, 0));
for (auto i : vEntity){
window.render(i, 1);
}
window.display();
while (isOpen){
while (SDL_PollEvent(&eventAbout)){
if (eventAbout.type == SDL_JOYBUTTONDOWN){
if (eventAbout.jbutton.button == 0) //button A
{
return;
}
}
}
}
}
\ No newline at end of file
// THE CODE IS NOT FROM ME !
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include "Reboot.hpp"
#define IRAM_PAYLOAD_MAX_SIZE 0x2F000
#define IRAM_PAYLOAD_BASE 0x40010000
alignas(0x1000) u8 g_reboot_payload[IRAM_PAYLOAD_MAX_SIZE];
alignas(0x1000) u8 g_ff_page[0x1000];
alignas(0x1000) u8 g_work_page[0x1000];
void do_iram_dram_copy(void *buf, uintptr_t iram_addr, size_t size, int option) {
memcpy(g_work_page, buf, size);
SecmonArgs args = {0};
args.X[0] = 0xF0000201; /* smcAmsIramCopy */
args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */
args.X[2] = iram_addr; /* IRAM Address */
args.X[3] = size; /* Copy size */
args.X[4] = option; /* 0 = Read, 1 = Write */
svcCallSecureMonitor(&args);
memcpy(buf, g_work_page, size);
}
void copy_to_iram(uintptr_t iram_addr, void *buf, size_t size) {
do_iram_dram_copy(buf, iram_addr, size, 1);
}
void copy_from_iram(void *buf, uintptr_t iram_addr, size_t size) {
do_iram_dram_copy(buf, iram_addr, size, 0);
}
static void clear_iram(void) {
memset(g_ff_page, 0xFF, sizeof(g_ff_page));
for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += sizeof(g_ff_page)) {
copy_to_iram(IRAM_PAYLOAD_BASE + i, g_ff_page, sizeof(g_ff_page));
}
}
static void reboot_to_payload(void) {
clear_iram();
for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += 0x1000) {
copy_to_iram(IRAM_PAYLOAD_BASE + i, &g_reboot_payload[i], 0x1000);
}
splSetConfig((SplConfigItem)65001, 2);
}
Reboot::Reboot(){
}
std::string whichPayload(int payload)
{
chdir("romfs:/");
if (payload == 0) //HEKATE
{
return "payload/hekate.bin";
}
else if (payload == 1) //AMS
{
return "payload/fusee.bin";
}
else if (payload == 2) //LOCKPICK
{
return "payload/lockpick.bin";
}
else if (payload == 3) //LAKKA
{
return "payload/lakka.rom";
}
}
void Reboot::rebootNow(int payload) //0 = hekate, 1 = ams, 2 = lockpick, 3 = lakka
{
Result rc = splInitialize();
FILE *f = fopen(whichPayload(payload).c_str(), "rb");
std::cout << "test\n";
if (f == NULL) {
std::cout << "Payload not found" << std::endl;
}
fread(g_reboot_payload, 1, sizeof(g_reboot_payload), f);
fclose(f);
reboot_to_payload();
spsmInitialize();
spsmShutdown(true);
}
\ No newline at end of file
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <iostream>
#include "Cursor.hpp"
#include "RenderWindow.hpp"
#include "Entity.hpp"
RenderWindow::RenderWindow(const char* p_title, int p_w, int p_h)
:window(NULL), renderer(NULL)
{
window = SDL_CreateWindow(p_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, p_w, p_h, SDL_WINDOW_SHOWN);
if (window == NULL)
{
std::cout << "HEY... Window failed to init. SDL_ERROR: " << SDL_GetError() << std::endl;
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
}
int RenderWindow::getRefreshRate()
{
int displayIndex = SDL_GetWindowDisplayIndex(window);
SDL_DisplayMode mode;
SDL_GetDisplayMode(displayIndex, 0, &mode);
return mode.refresh_rate;
}
SDL_Texture* RenderWindow::loadTexture(const char* p_filePath)
{
SDL_Texture* texture = NULL;
texture = IMG_LoadTexture(renderer, p_filePath);
if (texture == NULL)
std::cout << "HEY... Window failed to load texture. SDL_ERROR: " << SDL_GetError() << std::endl;
return texture;
}
SDL_Texture* RenderWindow::loadString(const char* text)
{
SDL_Texture* texture = NULL;
SDL_Surface* surface = NULL;
chdir("romfs:/");
TTF_Font* font = TTF_OpenFont("data/BerlinSansFB.ttf", 25);
surface = TTF_RenderText_Blended(font, text, SDL_Color{255, 255, 255, 255});
texture = SDL_CreateTextureFromSurface(renderer, surface);
if (texture == NULL)
std::cout << "HEY... Window failed to load texture. SDL_ERROR: " << SDL_GetError() << std::endl;
return texture;
}
void RenderWindow::cleanup()
{
SDL_DestroyWindow(window);
}
void RenderWindow::clear()
{
SDL_SetRenderDrawColor(renderer, 41, 41, 41, 255);
SDL_RenderClear(renderer);
}
void RenderWindow::render(Entity& p_entity, int multiply)
{
SDL_Rect src{};
src.x = p_entity.getCurrentFrame().x;
src.y = p_entity.getCurrentFrame().y;
src.w = p_entity.getCurrentFrame().w;
src.h = p_entity.getCurrentFrame().h;
SDL_Rect dst{};
dst.x = p_entity.getPos().x;
dst.y = p_entity.getPos().y;
dst.w = p_entity.getCurrentFrame().w * multiply;
dst.h = p_entity.getCurrentFrame().h * multiply;
SDL_RenderCopy(renderer, p_entity.getTex(), &src, &dst);
}
void RenderWindow::display()
{
SDL_RenderPresent(renderer);
}
void RenderWindow::renderRect(SDL_Rect rect)
{
//SDL_SetRenderDrawColor(renderer, 25, 145, 218, 255);
//SDL_RenderDrawRect(renderer, &rect);
/*Cursor cursor;
for (int i = 0; i < 5; ++i)
{
rectangleRGBA(renderer, cursor.getPosX() + 258 + i, cursor.getPosY() - i, cursor.getPosX() - i, cursor.getPosY() + 258 + i, 25, 145, 218, 255);
}*/
SDL_SetRenderDrawColor(renderer, 25, 145, 218, 255);
for (int i = 0; i < 5; ++i){
rect.w += 2;
rect.h += 2;
rect.x -= 1;
rect.y -= 1;
SDL_RenderDrawRect(renderer, &rect);
}
}
void RenderWindow::drawCircleBehindIcons()
{
filledCircleRGBA(renderer, 1280 / 2 + 50, 575, 38, 80, 80, 80, 255);
filledCircleRGBA(renderer, 1280 / 2 - 50, 575, 38, 80, 80, 80, 255);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment