shadps4-emu / shadPS4

PS4 emulator for Windows,Linux,MacOS
https://shadps4.net/
GNU General Public License v2.0
9.09k stars 484 forks source link

The Last Of Us Part II (CUSA07820) sceKernelGetDirectMemorySize Halt #789

Open StevenMiller123 opened 1 week ago

StevenMiller123 commented 1 week ago

The Last Of Us Part II verifies the value of sceKernelGetDirectMemorySize, and halts if the returned value differs from what it expects. A log of this behavior can be found at https://github.com/shadps4-emu/shadps4-game-compatibility/issues/66. This behavior is probably because the game sets a flexible memory size, a behavior that appears to be emulated fine.

Through decompiling the game's eboot, I found that the game uses the constant value 0x15f200000 to verify the direct memory size. For reference, the game sets the flexible memory size to 0xce00000, assuming the current emulated behavior is accurate. This would put the expected total memory size at 0x16c000000. For whatever reason, the expected sizes do not change when isPS4Pro is enabled in the config. I'm not sure if I can share any relevant assembly, but if this would be liked and is considered fine, then I will. I cannot provide any decompilation, as my Ghidra couldn't decomp the function this is all contained in.

dark147x commented 1 week ago

Cool, I don't know much about development, I just hope to play the game (I played the first part before the PC port on an RPCS3). I wish you good luck!!!

raphaelthegreat commented 1 week ago

Does the game progress further with this adjustment?

StevenMiller123 commented 1 week ago

Yes, the game gets past this halt, but then immediately crashes from what appears to be an issue with sceKernelAvailableFlexibleMemorySize. These are the printed errors.

[Kernel.Vmm] <Info> memory_management.cpp:sceKernelAvailableFlexibleMemorySize:246: called size = 0xcaac000  
[Tty] <Info> libkernel.cpp:ps4__write:210: Code and Data section is too large. It is 17592186044416.016 and should be 73.000
[Tty] <Info> libkernel.cpp:ps4__write:210: Warning - RAM Cache is being disabled.

Here is a log with my fix applied, I modified sceKernelGetDirectMemorySize to print the returned size for debugging purposes. Log: TLOU2 log.txt

I've also confirmed that the game requires the direct memory size to be the exact value I listed, and changing the size to slightly above or below the variable I listed causes that halt to come back.

StevenMiller123 commented 1 day ago

Looking at logs from running the game on a base PS4, I think the issue is likely with how we handle flexible memory size assignments instead. I think the game might be trying to reduce the flexible memory size to increase dmem size, though I don't know how I would verify this, and I won't have access to my PS4s for another month or so.