Skip to content

Commit

Permalink
Merge branch 'save-slots'
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m3vilurr committed Oct 9, 2016
2 parents 1ef0118 + 3865d8a commit d68c438
Show file tree
Hide file tree
Showing 15 changed files with 469 additions and 228 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extern/inih"]
path = extern/inih
url = https://github.com/benhoyt/inih
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ set(CMAKE_C_FLAGS "-Wl,-q -Wall -O3 -std=c99")

include_directories(
sqlite3
extern/inih
)

add_executable(${PROJECT_NAME}.elf
src/console.c
src/appdb.c
src/file.c
src/font.c
src/button.c
src/config.c
src/main.c
src/vita_sqlite.c

sqlite3/sqlite3.c
extern/inih/ini.c
)

target_link_libraries(${PROJECT_NAME}.elf
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ Dump & restore decrypted savefile.
8. Repeat 3~7 steps or close savemgr
9. Play game.

## Configure
If you want to use another dump directory format, make simple `config.ini` file into `ux0:data/savemgr`

- use `ux0:data/savegames/PCSH00000_SLOT0`

```ini
base=/data/savegames
slot_format=%s_SLOT%d
```
- use `ux0:data/savegames/PCSH00000/SLOT_0`

```ini
base=/data/savegames
slot_format=%s/SLOT_%d
```

Default config like this

```ini
base=/data/rinCheat
slot_format=%s_SAVEDATA_SLOT%d
```

## Emergency guide
If you do something mess, please do these steps.

Expand Down
1 change: 1 addition & 0 deletions extern/inih
Submodule inih added at 60b5ad
34 changes: 34 additions & 0 deletions src/button.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <psp2/ctrl.h>

#include "common.h"
#include "button.h"

int read_btn() {
SceCtrlData pad = {0};
static int old;
static int hold_times;
int curr, btn;

sceCtrlPeekBufferPositive(0, &pad, 1);

if (pad.ly < 0x10) {
pad.buttons |= SCE_CTRL_UP;
} else if (pad.ly > 0xef) {
pad.buttons |= SCE_CTRL_DOWN;
}
curr = pad.buttons;
btn = pad.buttons & ~old;
if (curr && old == curr) {
hold_times += 1;
if (hold_times >= 10) {
btn = curr;
hold_times = 10;
btn |= SCE_CTRL_HOLD;
}
} else {
hold_times = 0;
old = curr;
}
return btn;
}

6 changes: 6 additions & 0 deletions src/button.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __BUTTON_H__
#define __BUTTON_H__

int read_btn();

#endif
32 changes: 32 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef __COMMON_H__
#define __COMMON_H__

#include <vita2d.h>

#define SAVE_MANAGER "SAVEMGR00"

#define ICON_CIRCLE "\xe2\x97\x8b"
#define ICON_CROSS "\xe2\x95\xb3"
#define ICON_SQUARE "\xe2\x96\xa1"
#define ICON_TRIANGLE "\xe2\x96\xb3"
#define ICON_UPDOWN "\xe2\x86\x95"

#define black RGBA8(0x00, 0x00, 0x00, 0xFF)
#define white RGBA8(0xFF, 0xFF, 0xFF, 0xFF)
#define green RGBA8(0x00, 0xFF, 0x00, 0xFF)
#define red RGBA8(0xFF, 0x00, 0x00, 0xFF)

#define TEMP_FILE "ux0:data/savemgr/tmp"
#define CONFIG_FILE "ux0:data/savemgr/config.ini"

#define DEFAULT_BASE_SAVEDIR "/data/rinCheat"
#define DEFAULT_SAVE_SLOT_FORMAT "%s_SAVEDATA_SLOT%d"

#define SCE_CTRL_HOLD 0x80000000

extern int SCE_CTRL_ENTER;
extern int SCE_CTRL_CANCEL;
extern char ICON_ENTER[4];
extern char ICON_CANCEL[4];

#endif
47 changes: 47 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <psp2/io/fcntl.h>
#include <psp2/appmgr.h>

#include "common.h"
#include "config.h"
#include "file.h"
#include "ini.h"

char app_titleid[16];
char app_title[256];

configure config = {0};

static int handler(void* out,
const char* section, const char* name, const char* value) {
configure *p = (configure*)out;

if (strcmp(name, "base") == 0) {
p->base = strdup(value);
} else if (strcmp(name, "slot_format") == 0) {
p->slot_format = strdup(value);
}
return 1;
}

void load_config() {
sceAppMgrAppParamGetString(0, 9, app_title , 256);
sceAppMgrAppParamGetString(0, 12, app_titleid , 16);

ini_parse(CONFIG_FILE, handler, &config);

if (!config.base) {
config.base = strdup(DEFAULT_BASE_SAVEDIR);
}
if (!config.slot_format) {
config.slot_format = strdup(DEFAULT_SAVE_SLOT_FORMAT);
}
int length = strlen(config.base) + strlen(config.slot_format) + 6;
char format[length];
memset(format, 0, length);
snprintf(format, length, "ux0:%s/%s", config.base, config.slot_format);
config.full_path_format = strdup(format);
}
17 changes: 17 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__

extern char app_titleid[16];
extern char app_title[256];

typedef struct configure {
const char *base;
const char *slot_format;
const char *full_path_format;
} configure;

extern configure config;

void load_config();

#endif
80 changes: 80 additions & 0 deletions src/console.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <string.h>

#include <psp2/types.h>
#include <psp2/system_param.h>
#include <psp2/apputil.h>
#include <psp2/ctrl.h>

#include <vita2d.h>

#include "common.h"
#include "button.h"
#include "font.h"

#define SCREEN_ROW 27
#define ROW_HEIGHT 20

static vita2d_pgf* debug_font;

int SCE_CTRL_ENTER;
int SCE_CTRL_CANCEL;
char ICON_ENTER[4];
char ICON_CANCEL[4];


void init_console() {
vita2d_set_clear_color(black);

debug_font = load_system_fonts();

SceAppUtilInitParam init_param = {0};
SceAppUtilBootParam boot_param = {0};
sceAppUtilInit(&init_param, &boot_param);

int enter_button;

sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_ENTER_BUTTON, &enter_button);
if (enter_button == SCE_SYSTEM_PARAM_ENTER_BUTTON_CIRCLE) {
SCE_CTRL_ENTER = SCE_CTRL_CIRCLE;
SCE_CTRL_CANCEL = SCE_CTRL_CROSS;
strcpy(ICON_ENTER, ICON_CIRCLE);
strcpy(ICON_CANCEL, ICON_CROSS);
} else {
SCE_CTRL_ENTER = SCE_CTRL_CROSS;
SCE_CTRL_CANCEL = SCE_CTRL_CIRCLE;
strcpy(ICON_ENTER, ICON_CROSS);
strcpy(ICON_CANCEL, ICON_CIRCLE);
}

sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE);
}

void draw_start() {
vita2d_start_drawing();
vita2d_clear_screen();
}

void draw_end() {
vita2d_end_drawing();
vita2d_wait_rendering_done();
vita2d_swap_buffers();
}

void draw_text(uint32_t y, const char* text, uint32_t color) {
for (int i = 0; i < 3; i++){
vita2d_start_drawing();
vita2d_pgf_draw_text(debug_font, 2, (y + 1) * ROW_HEIGHT, color, 1.0, text);
draw_end();
}
}

void draw_loop_text(uint32_t y, const char *text, uint32_t color) {
vita2d_pgf_draw_text(debug_font, 2, (y + 1) * ROW_HEIGHT, color, 1.0, text);
}

void clear_screen() {
for (int i = 0; i < 3; i++){
draw_start();
draw_end();
}
}
11 changes: 11 additions & 0 deletions src/console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __CONSOLE_H__
#define __CONSOLE_H__

void init_console();
void draw_start();
void draw_end();
void draw_text(uint32_t y, const char* text, uint32_t color);
void draw_loop_text(uint32_t y, const char *text, uint32_t color);
void clear_screen();

#endif
33 changes: 33 additions & 0 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
#include <psp2/io/fcntl.h>
#include <psp2/io/dirent.h>

#include "common.h"
#include "file.h"

#define printf psvDebugScreenPrintf

#define SCE_ERROR_ERRNO_ENOENT 0x80010002
#define SCE_ERROR_ERRNO_EEXIST 0x80010011
#define SCE_ERROR_ERRNO_ENODEV 0x80010013
#define SCE_ERROR_ERRNO_EINVAL 0x80010016

int exists(const char *path) {
SceIoStat stat = {0};
Expand All @@ -28,6 +30,37 @@ int is_dir(const char *path) {
return SCE_S_ISDIR(stat.st_mode);
}

int mkdir(const char *path, int mode) {
if (exists(path)) {
if (is_dir(path)) {
return 0;
}
return SCE_ERROR_ERRNO_EEXIST;
}
int len = strlen(path);
char p[len];
memset(p, 0, len);
for (int i = 0; i < len; i++) {
if (path[i] == '/') {
if (strcmp(p, "ux0:/") == 0) {
p[i] = path[i];
continue;

}
if (!exists(p)) {
sceIoMkdir(p, mode);
} else {
if (!is_dir(p)) {
return SCE_ERROR_ERRNO_EINVAL;
}
}
}
p[i] = path[i];
}
sceIoMkdir(path, mode);
return 0;
}

int rmdir(const char *path) {
SceUID dfd = sceIoDopen(path);
if (dfd < 0) {
Expand Down
1 change: 1 addition & 0 deletions src/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
int exists(const char *path);
int is_dir(const char *path);

int mkdir(const char *path, int mode);
int rmdir(const char *path);
int mvdir(const char *src, const char *dest);
int copydir(const char *src, const char *dest);
Expand Down
1 change: 1 addition & 0 deletions src/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#include <vita2d.h>

vita2d_pgf* load_system_fonts();

#endif

0 comments on commit d68c438

Please sign in to comment.