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

lseek: let the host OS set lseek errors #2370

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mailwl
Copy link
Contributor

@mailwl mailwl commented Feb 7, 2025

In game Timespinner, the code:

    public AudioEngine(string settingsFile, TimeSpan lookAheadTime, string rendererId)
    {
        using (Stream input = TitleContainer.OpenStream(settingsFile))
        {
            using (BinaryReader reader = new BinaryReader(input))
            {
                // skip
                uint prcCurveOffset = reader.ReadUInt32(); // <-- here 0xFFFFFFFFu
                // skip
                reader.BaseStream.Seek((long)prcCurveOffset, SeekOrigin.Begin); <-- (long)prcCurveOffset == 4294967295 
                for (int index1 = 0; (long)index1 < (long)prcCurveCount; ++index1)  // <-- prcCurveCount = 0, never executes
                {
                       ///skip
                }
            }
        }
    }

bad C# u32>s64 conversion leads to huge offset, and in C-code it compares to (s32)(-1), too, which not equal (s64)(-1) and then crash.
But, as you may see, in C# code, result of Seek() to not checked at all, and even not used, so, we can pass needed result/error to C-code.
I did some other changes, which made the game playable, but i do not know, which helps, will make pr for it later

@mailwl
Copy link
Contributor Author

mailwl commented Feb 7, 2025

found where game is crashed - i occasionally set Log Filter to "*:Debug" - empty filter will game playable.
Looks like there is a place where "debug" log has malformed format string

@@ -321,6 +321,10 @@ s64 PS4_SYSV_ABI posix_lseek(int d, s64 offset, int whence) {
if (result < 0) {
LOG_ERROR(Kernel_Pthread, "posix_lseek: error = {}", result);
ErrSceToPosix(result);
// Workaround for XNA AudioEngine
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don’t know if this is just how you worded it, but there shouldn’t be any “workaround for (specific engine)”. If the engine code works on real hardware, we should figure out why and implement the behavior as the real lseek does it, not add custom workarounds like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i checked on usual .NET, the code
reader.BaseStream.Seek( (long)4294967295, SeekOrigin.Begin);
returns 4294967295 with no exception (the same with others offsets bigger than file itself)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like on ubuntu lseek doesn't even set the error

wl@DESKTOP-0004IRP:~$ cat ./file.txt
abcd
wl@DESKTOP-0004IRP:~$ cat main.cpp
#include <unistd.h>
#include <fcntl.h>
#include <iostream>
#include <string.h>

int main() {
    int fd = open("./file.txt", O_RDONLY);
    auto off = lseek(fd, 4555555555, SEEK_SET);
    std::cout << "fd:" << fd << ", off: " << off << ", err: " << strerror(errno) << std::endl;
    close(fd);
}
wl@DESKTOP-0004IRP:~$ g++ main.cpp
wl@DESKTOP-0004IRP:~$ ./a.out
fd:3, off: 4555555555, err: Success
wl@DESKTOP-0004IRP:~$

Copy link
Collaborator

Choose a reason for hiding this comment

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

My comment was less about the outward behavior of the function and more what is going on inside of it to make that happen.

@chronicer
Copy link

chronicer commented Feb 8, 2025

[Kernel.Fs] file_system.cpp:179 sceKernelClose: Closing /app0/VEHICLES/COMPETITORSOUNDS.BNDL
[Kernel.Fs] file_system.cpp:61 sceKernelOpen: path = /app0/GAMELOGIC/GAMEPLAY.BNDL flags = 0x0 mode = 0
[Common.Filesystem] io_file.cpp:386 Seek: Seeking past the end of the file
[Kernel.Fs] file_system.cpp:313 sceKernelLseek: sceKernelLseek: failed to seek

Yes, that's not C#, but also seek problem in NFS Hot Pursuit Remastered. May you know something about this?

@mailwl mailwl marked this pull request as draft February 8, 2025 17:12
@mailwl
Copy link
Contributor Author

mailwl commented Feb 8, 2025

with this PR NFS Hot Pursuit Remastered works, but i undestood, i made wrong implemetation. need to leave system seek function set errors by itself

@chronicer
Copy link

with this PR NFS Hot Pursuit Remastered works, but i undestood, i made wrong implemetation. need to leave system seek function set errors by itself

This error is displayed on all versions of the emulator, I just thought maybe you know something about this error)

@mailwl
Copy link
Contributor Author

mailwl commented Feb 9, 2025

i am not sure, i made some random changes on main branch, including this PR, works well (not exactly, 30 fps on my old notebook with 2060), i will update this PR in one-two days and tell, if it enough

2025-02-08 (2)

@chronicer
Copy link

i am not sure, i made some random changes on main branch, including this PR, works well (not exactly, 30 fps on my old notebook with 2060), i will update this PR in one-two days and tell, if it enough

2025-02-08 (2)

Bugs in NFS HP Remastered...

В общем у меня баги какие-то в ней, может это из-за 1050 ti, может быть из-за той ошибки. В гонке верхняя половина не рендерится. С твоим билдом всё ок, это на всех сборках так. Вот я и решил спросить, может быть знаешь хоть что-то о ней. Хотя у знакомого тоже такая же ошибка, но у него 2070 и всё ок.

{1D8A8349-D59F-4C62-BA60-D3FCE92084FD}
image

@mailwl
Copy link
Contributor Author

mailwl commented Feb 9, 2025

к сожалению, не смогу подсказать, в графике я полный ноль, но shadPS4 выставляет очень высокие требования к видеокарте - Vulkan 1.4, с большим количеством расширений

@mailwl mailwl changed the title Fix lseek(fd, -1, SEEK_SET) for XNA lseek: let the host OS set lseek errors Feb 17, 2025
@mailwl mailwl marked this pull request as ready for review February 17, 2025 07:19
@mailwl mailwl requested a review from squidbus February 20, 2025 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants