Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

game: auto-save pc-settings to user's home directory as well as memcard files #1233

Merged
merged 13 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vs/launch.vs.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"project" : "CMakeLists.txt",
"projectTarget" : "gk.exe (bin\\gk.exe)",
"name" : "Run - Runtime (with kernel)",
"args" : [ "-fakeiso", "-debug", "-v", "-nodisplay" ]
"args" : [ "-fakeiso", "-debug", "-v" ]
},
{
"type" : "default",
Expand Down
24 changes: 2 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if(MSVC AND (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
-Xclang -std=c++17 \
-Xclang -D_CRT_SECURE_NO_WARNINGS \
-mavx \
-Wno-c++11-narrowing -W3")
-Wno-c++11-narrowing -Wno-c++98-compat -W3")

# additional c++ flags for release mode for our projects
if(CMAKE_BUILD_TYPE MATCHES "Release")
Expand Down Expand Up @@ -80,24 +80,6 @@ if(ASAN_BUILD)
message(STATUS "Doing ASAN build")
endif()

# if(WIN32)
# find_program(buildcache_program buildcache ${PROJECT_SOURCE_DIR}/bin/windows/)
# if(buildcache_program)
# message("Found Windows BuildCache, gonna use it!")
# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${buildcache_program}")
# else()
# message("Windows Buildcache not found!")
# endif()
# else()
# find_program(buildcache_program buildcache ${PROJECT_SOURCE_DIR}/bin/linux/)
# if(buildcache_program)
# message("Found Linux BuildCache, gonna use it!")
# set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${buildcache_program}")
# else()
# message("Linux Buildcache not found!")
# endif()
# endif()

option(CODE_COVERAGE "Enable Code Coverage Compiler Flags" OFF)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/third-party/cmake/modules/)

Expand Down Expand Up @@ -126,7 +108,6 @@ add_subdirectory(decompiler)

# build glfw library
add_subdirectory(third-party/glfw)

add_subdirectory(third-party/zstd)

# build imgui
Expand Down Expand Up @@ -158,7 +139,6 @@ add_subdirectory(third-party/lzokay EXCLUDE_FROM_ALL)

# build format library
add_subdirectory(third-party/fmt EXCLUDE_FROM_ALL)

# discord rich presence
include_directories(third-party/discord-rpc/include)
add_subdirectory(third-party/discord-rpc EXCLUDE_FROM_ALL)
Expand All @@ -170,8 +150,8 @@ option(ZYDIS_BUILD_EXAMPLES "Zydis: Build examples" OFF)
option(ZYDIS_BUILD_SHARED_LIB "Zydis: Build shared library" ON)
add_subdirectory(third-party/zydis EXCLUDE_FROM_ALL)


# windows memory management lib
if(WIN32)
add_subdirectory(third-party/mman)
endif()

6 changes: 6 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ tasks:
msg: "Couldn't locate runtime executable -- Have you compiled in release mode?"
cmds:
- "{{.GK_BIN_RELEASE_DIR}}/gk -fakeiso -debug -v"
run-game-quiet:
preconditions:
- sh: test -f {{.DECOMP_BIN_RELEASE_DIR}}/gk{{.EXE_FILE_EXTENSION}}
msg: "Couldn't locate runtime executable -- Have you compiled in release mode?"
cmds:
- "{{.GK_BIN_RELEASE_DIR}}/gk -fakeiso"
repl:
env:
OPENGOAL_DECOMP_DIR: "jak1/"
Expand Down
25 changes: 25 additions & 0 deletions common/util/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ std::filesystem::path get_user_home_dir() {
#endif
}

std::filesystem::path get_user_game_dir() {
// TODO - i anticipate UTF-8 problems on windows with our current FS api
return get_user_home_dir() / "OpenGOAL";
}

std::filesystem::path get_user_settings_dir() {
return get_user_game_dir() / "jak1" / "settings";
}

std::filesystem::path get_user_memcard_dir() {
return get_user_game_dir() / "jak1" / "saves";
}

std::string get_project_path() {
#ifdef _WIN32
char buffer[FILENAME_MAX];
Expand All @@ -66,6 +79,14 @@ std::string get_project_path() {
}

std::string get_file_path(const std::vector<std::string>& input) {
// TODO - clean this behaviour up, it causes unexpected behaviour when working with files
// the project path should be explicitly provided by whatever if needed
// TEMP HACK
// - if the provided path is absolute, don't add the project path
if (input.size() == 1 && std::filesystem::path(input.at(0)).is_absolute()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make this a different function, instead of having it do different things with absolute and relative paths?

I'm not opposed to this (it makes sense to let absolute paths be absolute paths), but I'm just wondering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the main reason I had to make this change is this method is used by the file-stream stuff:

s32 sceOpen(const char* filename, s32 flag) {
FILE* fp = nullptr;
auto name = file_util::get_file_path({filename});

I think long-term yeah we probably want a more explicit function like get_project_file_path and that function linked above should not be assuming everything is within the project directory. I think we can do a lot of cleanup / simplification, but im not sure how much we want to do immediately.

return input.at(0);
}

std::string currentPath = file_util::get_project_path();
char dirSeparator;

Expand All @@ -91,6 +112,10 @@ bool create_dir_if_needed(const std::string& path) {
return false;
}

bool create_dir_if_needed_for_file(const std::string& path) {
return std::filesystem::create_directories(std::filesystem::path(path).parent_path());
}

void write_binary_file(const std::string& name, const void* data, size_t size) {
FILE* fp = fopen(name.c_str(), "wb");
if (!fp) {
Expand Down
6 changes: 6 additions & 0 deletions common/util/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ namespace fs = std::filesystem;

namespace file_util {
std::filesystem::path get_user_home_dir();
std::filesystem::path get_user_game_dir();
std::filesystem::path get_user_settings_dir();
std::filesystem::path get_user_memcard_dir();
std::string get_project_path();
std::string get_file_path(const std::vector<std::string>& input);

bool create_dir_if_needed(const std::string& path);
bool create_dir_if_needed_for_file(const std::string& path);

void write_binary_file(const std::string& name, const void* data, size_t size);
void write_rgba_png(const std::string& name, void* data, int w, int h);
void write_text_file(const std::string& file_name, const std::string& text);
Expand Down
3 changes: 2 additions & 1 deletion decompiler/config/jak1_ntsc_black_label/new_strings.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"1018": ["AUTO"],
"1019": ["BORDERLESS"],
"1020": ["FULLSCREEN"],
"1021": ["WINDOWED"]
"1021": ["WINDOWED"],
"1049": ["USE ORIGINAL ASPECT"]
}
}
28 changes: 7 additions & 21 deletions decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5472,33 +5472,19 @@

"ocean-near-add-matrices": [[16, "vector"]],

"ocean-near-add-upload": [
[16, "vector"]
],
"ocean-near-add-upload": [[16, "vector"]],

"draw-ocean-mid": [
[16, "vector"]
],
"draw-ocean-mid": [[16, "vector"]],

"draw-ocean-mid-seams": [
[16, "sphere"]
],
"draw-ocean-mid-seams": [[16, "sphere"]],

"ocean-mid-add-upload-table": [
[16, "vector"]
],
"ocean-mid-add-upload-table": [[16, "vector"]],

"ocean-mid-add-upload": [
[16, "vector"]
],
"ocean-mid-add-upload": [[16, "vector"]],

"ocean-mid-check": [
[16, "vector"]
],
"ocean-mid-check": [[16, "vector"]],

"ocean-mid-add-matrices": [
[16, "vector"]
],
"ocean-mid-add-matrices": [[16, "vector"]],

"placeholder-do-not-add-below!": []
}
72 changes: 21 additions & 51 deletions decompiler/config/jak1_ntsc_black_label/type_casts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4023,9 +4023,7 @@
[251, "a0", "process-drawable"]
],

"(anon-function 46 racer-states)": [
[[4, 32], "v1", "target"]
],
"(anon-function 46 racer-states)": [[[4, 32], "v1", "target"]],

"(anon-function 45 racer-states)": [
[19, "a0", "target"],
Expand Down Expand Up @@ -7263,7 +7261,7 @@
[8, "a0", "dma-packet"],
[10, "a0", "dma-packet"]
],

"ocean-near-add-matrices": [
[7, "a0", "dma-packet"],
[12, "a0", "dma-packet"],
Expand All @@ -7276,9 +7274,7 @@
[[40, 46], "s3", "vector"]
],

"ocean-near-add-constants": [
[[8, 16], "a0", "dma-packet"]
],
"ocean-near-add-constants": [[[8, 16], "a0", "dma-packet"]],

"draw-ocean-near": [
[2, "a0", "dma-packet"],
Expand Down Expand Up @@ -7345,7 +7341,7 @@
[24, "a0", "dma-packet"]
],

"draw-bones-generic-merc":[
"draw-bones-generic-merc": [
[11, "v1", "generic-merc-ctrl"],
[198, "v1", "generic-merc-ctrl"],
[274, "a0", "generic-merc-ctrl"],
Expand All @@ -7359,7 +7355,7 @@
],

"generic-merc-execute-all": [
[[165,170], "v1", "terrain-context"],
[[165, 170], "v1", "terrain-context"],
[92, "a0", "terrain-context"],
[96, "v1", "terrain-context"],
[100, "v1", "terrain-context"],
Expand All @@ -7377,21 +7373,17 @@
[32, "a0", "terrain-context"]
],

"generic-work-init":[
"generic-work-init": [
[10, "a0", "terrain-context"],
[13, "a0", "terrain-context"],
[16, "a0", "terrain-context"],
[18, "a0", "terrain-context"],
[[21, 42], "gp", "adgif-shader"]
],

"render-ocean-far": [
[[23,588], "s5", "(inline-array ocean-vertex)"]
],
"render-ocean-far": [[[23, 588], "s5", "(inline-array ocean-vertex)"]],

"draw-ocean-far": [
[[65, 72], "gp", "dma-packet"]
],
"draw-ocean-far": [[[65, 72], "gp", "dma-packet"]],

"ocean-init-buffer": [
[[9, 14], "a2", "dma-packet"],
Expand Down Expand Up @@ -7428,34 +7420,22 @@
[[114, 117], "v1", "dma-packet"]
],

"ocean-texture-add-constants": [
[[8, 16], "a0", "dma-packet"]
],
"ocean-texture-add-constants": [[[8, 16], "a0", "dma-packet"]],

"ocean-texture-add-envmap": [
[[1, 8], "v1", "(pointer uint128)"]
],
"ocean-texture-add-envmap": [[[1, 8], "v1", "(pointer uint128)"]],

"ocean-texture-add-verts": [
[[6, 11], "a0", "dma-packet"]
],
"ocean-texture-add-verts": [[[6, 11], "a0", "dma-packet"]],

"ocean-texture-add-verts-last": [
[[6, 11], "a3", "dma-packet"],
[[19, 24], "a0", "dma-packet"]
],

"ocean-texture-add-call-start": [
[[3, 8], "a0", "dma-packet"]
],
"ocean-texture-add-call-start": [[[3, 8], "a0", "dma-packet"]],

"ocean-texture-add-call-rest": [
[[3, 8], "a0", "dma-packet"]
],
"ocean-texture-add-call-rest": [[[3, 8], "a0", "dma-packet"]],

"ocean-texture-add-call-done": [
[[3, 8], "a0", "dma-packet"]
],
"ocean-texture-add-call-done": [[[3, 8], "a0", "dma-packet"]],

"draw-ocean-texture": [
[[24, 29], "a0", "dma-packet"],
Expand Down Expand Up @@ -7532,7 +7512,7 @@
[57, "v1", "(inline-array vector)"]
],

"ocean-near-add-upload":[
"ocean-near-add-upload": [
[[40, 48], "a0", "dma-packet"],
[64, "a2", "(pointer int16)"],
[[81, 89], "a1", "vector4w"],
Expand Down Expand Up @@ -7569,39 +7549,29 @@
[49, "v1", "(pointer uint8)"]
],

"ocean-mid-mask-ptrs-bit?": [
[31, "a0", "(pointer uint8)"]
],
"ocean-mid-mask-ptrs-bit?": [[31, "a0", "(pointer uint8)"]],

"ocean-mid-camera-masks-bit?": [
[25, "a0", "(pointer uint8)"]
],
"ocean-mid-camera-masks-bit?": [[25, "a0", "(pointer uint8)"]],

"ocean-mid-add-upload": [
[[48, 62], "a2", "dma-packet"],
[[76, 81], "a0", "dma-packet"],
[95, "v1", "(pointer uint64)"]
],

"ocean-mid-add-call-flush": [
[[3, 11], "a0", "dma-packet"]
],
"ocean-mid-add-call-flush": [[[3, 11], "a0", "dma-packet"]],

"ocean-mid-add-call": [
[[3, 11], "a0", "dma-packet"]
],
"ocean-mid-add-call": [[[3, 11], "a0", "dma-packet"]],

"ocean-mid-add-matrices": [
[[12, 20], "a0", "dma-packet"],
[[30, 34], "v1", "matrix"],
[[41, 46], "s3", "vector"]
],

"ocean-mid-add-constants": [
[[8, 16], "a0", "dma-packet"]
],
"ocean-mid-add-constants": [[[8, 16], "a0", "dma-packet"]],

"ocean-near-add-heights" : [
"ocean-near-add-heights": [
[26, "a1", "int"],
[[11, 19], "a3", "dma-packet"],
[[30, 38], "a2", "dma-packet"]
Expand Down
4 changes: 2 additions & 2 deletions decompiler/config/jak1_ntsc_black_label/var_names.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -4028,9 +4028,9 @@
}
},

"render-ocean-far" : {
"render-ocean-far": {
"vars": {
"s5-0" : ["vertices", "(inline-array ocean-vertex)"]
"s5-0": ["vertices", "(inline-array ocean-vertex)"]
}
},

Expand Down
Loading