Skip to content

Commit

Permalink
Remove 128 character buffer causing long filenames to crash gk (#3771)
Browse files Browse the repository at this point in the history
Several users have reported that ArchipelaGOAL is not launching
properly, even when using the OpenGOAL Launcher. The window pops up with
a black screen, and then quits. The only way they can run it is if they
double click gk.exe.

This comes down to the Launcher providing gk.exe with the `config_path`
parameter, which leads the program to find `archipelagoal-settings.gc`.
Here is an example from me:

```
D:\Applications\Games\OpenGOAL\features\jak1\mods\JakMods\_settings\archipelagoal\OpenGOAL\jak1\settings/Mods/archipelagoal-settings.gc
```

If a user's base OpenGOAL install directory is long enough, this path
becomes longer than 128 characters. This overflows the character buffer
in `kopen` which is used to open file streams. If you're only slightly
over the limit like myself, at 135 characters, you may not have noticed
a problem. But some users have paths a little longer, like 168
characters, and they report the issue is consistent.

Water111 suggested we remove the 128 character buffer and use the
filename data directly. This fix requires no changes to the Launcher,
just to the kernel, and every mod could stand to benefit from this fix.
  • Loading branch information
massimilianodelliubaldini authored Nov 28, 2024
1 parent ef719d2 commit 4c2e1a8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
6 changes: 2 additions & 4 deletions game/kernel/jak1/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,12 @@ u64 kopen(u64 fs, u64 name, u64 mode) {
file_stream->name = name;
file_stream->flags = 0;
lg::print("****** CALL TO kopen() ******\n");
char buffer[128];
// sprintf(buffer, "host:%s", Ptr<String>(name)->data());
sprintf(buffer, "%s", Ptr<String>(name)->data());
if (!strcmp(info(Ptr<Symbol>(mode))->str->data(), "read")) {
file_stream->file = sceOpen(buffer, SCE_RDONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_RDONLY);
} else {
// 0x602
file_stream->file = sceOpen(buffer, SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
}

return fs;
Expand Down
8 changes: 3 additions & 5 deletions game/kernel/jak2/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,19 +505,17 @@ u64 kopen(u64 fs, u64 name, u64 mode) {
file_stream->name = name;
file_stream->flags = 0;
lg::print("****** CALL TO kopen() ******\n");
char buffer[128];
// sprintf(buffer, "host:%s", Ptr<String>(name)->data());
sprintf(buffer, "%s", Ptr<String>(name)->data());
if (!strcmp(symbol_name_cstr(*Ptr<Symbol4<u8>>(mode)), "read")) {
// 0x1
file_stream->file = sceOpen(buffer, SCE_RDONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_RDONLY);
} else if (!strcmp(symbol_name_cstr(*Ptr<Symbol4<u8>>(mode)), "append")) {
// new in jak 2!
// 0x202
file_stream->file = sceOpen(buffer, SCE_CREAT | SCE_WRONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_CREAT | SCE_WRONLY);
} else {
// 0x602
file_stream->file = sceOpen(buffer, SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
file_stream->file = sceOpen(Ptr<String>(name)->data(), SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
}

return fs;
Expand Down
8 changes: 3 additions & 5 deletions game/kernel/jak3/kmachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,17 @@ u64 kopen(u64 fs, u64 name, u64 mode) {
file_stream->name = name;
file_stream->flags = 0;
lg::print("****** CALL TO kopen() ******\n");
char buffer[128];
// sprintf(buffer, "host:%s", Ptr<String>(name)->data());
sprintf(buffer, "%s", Ptr<String>(name)->data());
if (!strcmp(sym_to_cstring(Ptr<Symbol4<u8>>(mode)), "read")) {
// 0x1
file_stream->file = ee::sceOpen(buffer, SCE_RDONLY);
file_stream->file = ee::sceOpen(Ptr<String>(name)->data(), SCE_RDONLY);
} else if (!strcmp(sym_to_cstring(Ptr<Symbol4<u8>>(mode)), "append")) {
// new in jak 2!
// 0x202
file_stream->file = ee::sceOpen(buffer, SCE_CREAT | SCE_WRONLY);
file_stream->file = ee::sceOpen(Ptr<String>(name)->data(), SCE_CREAT | SCE_WRONLY);
} else {
// 0x602
file_stream->file = ee::sceOpen(buffer, SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
file_stream->file = ee::sceOpen(Ptr<String>(name)->data(), SCE_TRUNC | SCE_CREAT | SCE_WRONLY);
}

return fs;
Expand Down

0 comments on commit 4c2e1a8

Please sign in to comment.