Compare commits

..

8 Commits

302 changed files with 5947 additions and 33750 deletions

View File

@ -19,12 +19,8 @@ chmod a+x linuxdeploy-x86_64.AppImage
chmod a+x linuxdeploy-plugin-qt-x86_64.AppImage
chmod a+x linuxdeploy-plugin-checkrt-x86_64.sh
# Build AppImage
./linuxdeploy-x86_64.AppImage --appdir AppDir
./linuxdeploy-plugin-checkrt-x86_64.sh --appdir AppDir
cp -a "$GITHUB_WORKSPACE/build/translations" AppDir/usr/bin
./linuxdeploy-x86_64.AppImage --appdir AppDir -d "$GITHUB_WORKSPACE"/.github/shadps4.desktop -e "$GITHUB_WORKSPACE"/build/shadps4 -i "$GITHUB_WORKSPACE"/.github/shadps4.png --plugin qt --output appimage
mv Shadps4-x86_64.AppImage Shadps4-qt.AppImage

View File

@ -23,7 +23,7 @@ jobs:
- name: Install misc packages
run: >
sudo apt-get update && sudo apt install libx11-dev libxext-dev libwayland-dev libfuse2 clang build-essential qt6-base-dev qt6-tools-dev
sudo apt-get update && sudo apt install libx11-dev libxext-dev libwayland-dev libfuse2 clang build-essential qt6-base-dev
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DENABLE_QT_GUI=ON

View File

@ -38,7 +38,7 @@ jobs:
host: mac
target: desktop
arch: clang_64
archives: qtbase qttools
archives: qtbase
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_OSX_ARCHITECTURES=x86_64 -DENABLE_QT_GUI=ON
@ -50,7 +50,6 @@ jobs:
run: |
mkdir upload
mv ${{github.workspace}}/build/shadps4.app upload
mv ${{github.workspace}}/build/translations upload
macdeployqt upload/shadps4.app
tar cf shadps4-macos-qt.tar.gz -C upload .

View File

@ -43,10 +43,10 @@ jobs:
mv ${{github.workspace}}/build/shadps4 upload
cp $(arch -x86_64 /usr/local/bin/brew --prefix)/opt/molten-vk/lib/libMoltenVK.dylib upload
install_name_tool -add_rpath "@loader_path" upload/shadps4
tar cf shadps4-macos-sdl.tar.gz -C upload .
tar cf shadps4-macos.tar.gz -C upload .
- name: Upload executable
uses: actions/upload-artifact@v4
with:
name: shadps4-macos-sdl
path: shadps4-macos-sdl.tar.gz
name: shadps4-macos
path: shadps4-macos.tar.gz

View File

@ -28,7 +28,7 @@ jobs:
host: windows
target: desktop
arch: win64_msvc2019_64
archives: qtbase qttools
archives: qtbase
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -T ClangCL -DENABLE_QT_GUI=ON
@ -40,7 +40,6 @@ jobs:
run: |
mkdir upload
move build/Release/shadPS4.exe upload
move build/translations upload
windeployqt --dir upload upload/shadPS4.exe
- name: Upload executable

View File

@ -29,6 +29,6 @@ jobs:
- name: Upload executable
uses: actions/upload-artifact@v4
with:
name: shadps4-win64-sdl
name: shadps4-win64
path: |
${{github.workspace}}/build/Release/shadPS4.exe

30
.gitmodules vendored
View File

@ -1,87 +1,63 @@
[submodule "externals/discord-rpc"]
path = externals/discord-rpc
url = https://github.com/shadps4-emu/ext-discord-rpc.git
[submodule "externals/cryptopp-cmake"]
path = externals/cryptopp-cmake
url = https://github.com/shadps4-emu/ext-cryptopp-cmake.git
shallow = true
[submodule "externals/cryptopp"]
path = externals/cryptopp
url = https://github.com/shadps4-emu/ext-cryptopp.git
shallow = true
[submodule "externals/cryptoppwin"]
path = externals/cryptoppwin
url = https://github.com/shadps4-emu/ext-cryptoppwin.git
shallow = true
[submodule "externals/zlib-ng"]
path = externals/zlib-ng
url = https://github.com/shadps4-emu/ext-zlib-ng.git
shallow = true
[submodule "externals/sdl3"]
path = externals/sdl3
url = https://github.com/shadps4-emu/ext-SDL.git
shallow = true
[submodule "externals/fmt"]
path = externals/fmt
url = https://github.com/shadps4-emu/ext-fmt.git
shallow = true
[submodule "externals/vulkan-headers"]
path = externals/vulkan-headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
shallow = true
[submodule "externals/vma"]
path = externals/vma
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
shallow = true
[submodule "externals/glslang"]
path = externals/glslang
url = https://github.com/KhronosGroup/glslang.git
shallow = true
[submodule "externals/robin-map"]
path = externals/robin-map
url = https://github.com/Tessil/robin-map.git
shallow = true
[submodule "externals/xbyak"]
path = externals/xbyak
url = https://github.com/herumi/xbyak.git
shallow = true
[submodule "externals/winpthreads"]
path = externals/winpthreads
url = https://github.com/shadps4-emu/winpthreads.git
shallow = true
[submodule "externals/magic_enum"]
path = externals/magic_enum
url = https://github.com/Neargye/magic_enum.git
shallow = true
[submodule "externals/toml11"]
path = externals/toml11
url = https://github.com/ToruNiina/toml11.git
shallow = true
[submodule "externals/zydis"]
path = externals/zydis
url = https://github.com/zyantific/zydis.git
shallow = true
[submodule "externals/sirit"]
path = externals/sirit
url = https://github.com/shadps4-emu/sirit.git
shallow = true
[submodule "externals/xxhash"]
path = externals/xxhash
url = https://github.com/Cyan4973/xxHash.git
shallow = true
[submodule "externals/tracy"]
path = externals/tracy
url = https://github.com/shadps4-emu/tracy.git
shallow = true
[submodule "externals/ext-boost"]
path = externals/ext-boost
url = https://github.com/shadps4-emu/ext-boost.git
shallow = true
[submodule "externals/date"]
path = externals/date
url = https://github.com/HowardHinnant/date.git
shallow = true
[submodule "externals/ffmpeg-core"]
path = externals/ffmpeg-core
url = https://github.com/shadps4-emu/ext-ffmpeg-core.git
shallow = true
[submodule "externals/half"]
path = externals/half
url = https://github.com/ROCm/half.git

View File

@ -15,7 +15,6 @@ Files: CMakeSettings.json
documents/Screenshots/Undertale.png
documents/Screenshots/We are DOOMED.png
scripts/ps4_names.txt
src/images/about_icon.png
src/images/controller_icon.png
src/images/exit_icon.png
src/images/file_icon.png

View File

@ -66,24 +66,20 @@ git_branch_name(GIT_BRANCH)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/common/scm_rev.cpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/common/scm_rev.cpp" @ONLY)
find_package(Boost 1.84.0 CONFIG)
find_package(FFmpeg 5.1.2 MODULE)
find_package(fmt 10.2.0 CONFIG)
find_package(cryptopp 8.9.0 MODULE)
find_package(fmt 10.2.1 CONFIG)
find_package(glslang 14.2.0 CONFIG)
find_package(magic_enum 0.9.6 CONFIG)
find_package(RenderDoc 1.6.0 MODULE)
find_package(SDL3 3.1.2 CONFIG)
find_package(toml11 4.2.0 CONFIG)
find_package(toml11 3.8.1 CONFIG)
find_package(tsl-robin-map 1.3.0 CONFIG)
find_package(VulkanHeaders 1.3.289 CONFIG)
find_package(VulkanMemoryAllocator 3.1.0 CONFIG)
find_package(xbyak 7.07 CONFIG)
find_package(xxHash 0.8.2 MODULE)
find_package(zlib-ng 2.1.7 MODULE)
find_package(Zydis 5.0.0 CONFIG)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR NOT MSVC)
find_package(cryptopp 8.9.0 MODULE)
endif()
find_package(zlib-ng 2.2.0 MODULE)
find_package(Zydis 4.1.0 CONFIG)
find_package(RenderDoc MODULE)
if (APPLE)
find_package(date 3.0.1 CONFIG)
@ -95,41 +91,20 @@ check_symbol_exists(pthread_mutex_timedlock "pthread.h" HAVE_PTHREAD_MUTEX_TIMED
if(HAVE_PTHREAD_MUTEX_TIMEDLOCK OR WIN32)
add_compile_options(-DHAVE_PTHREAD_MUTEX_TIMEDLOCK)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# libc++ requires -fexperimental-library to enable std::jthread and std::stop_token support.
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(_LIBCPP_VERSION version LIBCPP)
if(LIBCPP)
add_compile_options(-fexperimental-library)
endif()
check_symbol_exists(sem_timedwait "semaphore.h" HAVE_SEM_TIMEDWAIT)
if(HAVE_SEM_TIMEDWAIT OR WIN32)
add_compile_options(-DHAVE_SEM_TIMEDWAIT)
endif()
add_subdirectory(externals)
include_directories(src)
if(ENABLE_QT_GUI)
find_package(Qt6 REQUIRED COMPONENTS Widgets Concurrent LinguistTools Network)
find_package(Qt6 REQUIRED COMPONENTS Widgets Concurrent)
qt_standard_project_setup()
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(QT_TRANSLATIONS "${PROJECT_SOURCE_DIR}/src/qt_gui/translations")
file(GLOB_RECURSE TRANSLATIONS_TS ${QT_TRANSLATIONS}/*.ts)
set_source_files_properties(${TRANSLATIONS_TS} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/translations")
qt_add_translation(TRANSLATIONS_QM ${TRANSLATIONS_TS})
set(TRANSLATIONS_QRC ${CMAKE_CURRENT_BINARY_DIR}/translations/translations.qrc)
file(WRITE ${TRANSLATIONS_QRC} "<RCC><qresource prefix=\"translations\">\n")
foreach (QM ${TRANSLATIONS_QM})
get_filename_component(QM_FILE ${QM} NAME)
file(APPEND ${TRANSLATIONS_QRC} "<file>${QM_FILE}</file>\n")
endforeach (QM)
file(APPEND ${TRANSLATIONS_QRC} "</qresource></RCC>")
qt_add_resources(TRANSLATIONS ${TRANSLATIONS_QRC})
endif()
set(AUDIO_CORE src/audio_core/sdl_audio.cpp
@ -142,13 +117,10 @@ set(AUDIO_LIB src/core/libraries/audio/audioin.cpp
src/core/libraries/audio/audioout.h
src/core/libraries/ajm/ajm.cpp
src/core/libraries/ajm/ajm.h
src/core/libraries/ngs2/ngs2.cpp
src/core/libraries/ngs2/ngs2.h
)
set(GNM_LIB src/core/libraries/gnmdriver/gnmdriver.cpp
src/core/libraries/gnmdriver/gnmdriver.h
src/core/libraries/gnmdriver/gnm_error.h
)
set(KERNEL_LIB
@ -209,28 +181,11 @@ set(SYSTEM_LIBS src/core/libraries/system/commondialog.cpp
src/core/libraries/app_content/app_content.h
src/core/libraries/rtc/rtc.cpp
src/core/libraries/rtc/rtc.h
src/core/libraries/rtc/rtc_error.h
src/core/libraries/disc_map/disc_map.cpp
src/core/libraries/disc_map/disc_map.h
src/core/libraries/disc_map/disc_map_codes.h
src/core/libraries/avplayer/avplayer_common.cpp
src/core/libraries/avplayer/avplayer_common.h
src/core/libraries/avplayer/avplayer_file_streamer.cpp
src/core/libraries/avplayer/avplayer_file_streamer.h
src/core/libraries/avplayer/avplayer_impl.cpp
src/core/libraries/avplayer/avplayer_impl.h
src/core/libraries/avplayer/avplayer_source.cpp
src/core/libraries/avplayer/avplayer_source.h
src/core/libraries/avplayer/avplayer_state.cpp
src/core/libraries/avplayer/avplayer_state.h
src/core/libraries/avplayer/avplayer.cpp
src/core/libraries/avplayer/avplayer.h
src/core/libraries/ngs2/ngs2.cpp
src/core/libraries/ngs2/ngs2.h
src/core/libraries/ngs2/ngs2_error.h
src/core/libraries/ngs2/ngs2_impl.cpp
src/core/libraries/ngs2/ngs2_impl.h
src/core/libraries/ajm/ajm_error.h
)
set(VIDEOOUT_LIB src/core/libraries/videoout/buffer.h
@ -240,7 +195,21 @@ set(VIDEOOUT_LIB src/core/libraries/videoout/buffer.h
src/core/libraries/videoout/video_out.h
)
set(LIBC_SOURCES src/core/libraries/libc_internal/libc_internal.cpp
set(LIBC_SOURCES src/core/libraries/libc/libc.cpp
src/core/libraries/libc/libc.h
src/core/libraries/libc/printf.h
src/core/libraries/libc/va_ctx.h
src/core/libraries/libc/libc_cxa.cpp
src/core/libraries/libc/libc_cxa.h
src/core/libraries/libc/libc_stdio.cpp
src/core/libraries/libc/libc_stdio.h
src/core/libraries/libc/libc_math.cpp
src/core/libraries/libc/libc_math.h
src/core/libraries/libc/libc_string.cpp
src/core/libraries/libc/libc_string.h
src/core/libraries/libc/libc_stdlib.cpp
src/core/libraries/libc/libc_stdlib.h
src/core/libraries/libc_internal/libc_internal.cpp
src/core/libraries/libc_internal/libc_internal.h
)
@ -266,7 +235,6 @@ set(PLAYGO_LIB src/core/libraries/playgo/playgo.cpp
set(RANDOM_LIB src/core/libraries/random/random.cpp
src/core/libraries/random/random.h
src/core/libraries/random/random_error.h
)
set(USBD_LIB src/core/libraries/usbd/usbd.cpp
@ -280,7 +248,6 @@ set(NP_LIBS src/core/libraries/np_manager/np_manager.cpp
src/core/libraries/np_trophy/np_trophy.cpp
src/core/libraries/np_trophy/np_trophy.h
)
set(MISC_LIBS src/core/libraries/screenshot/screenshot.cpp
src/core/libraries/screenshot/screenshot.h
)
@ -430,6 +397,7 @@ set(SHADER_RECOMPILER src/shader_recompiler/exception.h
src/shader_recompiler/backend/spirv/spirv_emit_context.h
src/shader_recompiler/frontend/translate/data_share.cpp
src/shader_recompiler/frontend/translate/export.cpp
src/shader_recompiler/frontend/translate/flat_memory.cpp
src/shader_recompiler/frontend/translate/scalar_alu.cpp
src/shader_recompiler/frontend/translate/scalar_memory.cpp
src/shader_recompiler/frontend/translate/translate.cpp
@ -449,11 +417,10 @@ set(SHADER_RECOMPILER src/shader_recompiler/exception.h
src/shader_recompiler/frontend/opcodes.h
src/shader_recompiler/frontend/structured_control_flow.cpp
src/shader_recompiler/frontend/structured_control_flow.h
src/shader_recompiler/ir/passes/constant_propagation_pass.cpp
src/shader_recompiler/ir/passes/constant_propogation_pass.cpp
src/shader_recompiler/ir/passes/dead_code_elimination_pass.cpp
src/shader_recompiler/ir/passes/identity_removal_pass.cpp
src/shader_recompiler/ir/passes/ir_passes.h
src/shader_recompiler/ir/passes/lower_shared_mem_to_registers.cpp
src/shader_recompiler/ir/passes/resource_tracking_pass.cpp
src/shader_recompiler/ir/passes/shader_info_collection_pass.cpp
src/shader_recompiler/ir/passes/ssa_rewrite_pass.cpp
@ -487,7 +454,6 @@ set(VIDEO_CORE src/video_core/amdgpu/liverpool.cpp
src/video_core/amdgpu/pm4_cmds.h
src/video_core/amdgpu/pm4_opcodes.h
src/video_core/amdgpu/resource.h
src/video_core/amdgpu/default_context.cpp
src/video_core/buffer_cache/buffer.cpp
src/video_core/buffer_cache/buffer.h
src/video_core/buffer_cache/buffer_cache.cpp
@ -521,8 +487,6 @@ set(VIDEO_CORE src/video_core/amdgpu/liverpool.cpp
src/video_core/renderer_vulkan/vk_resource_pool.h
src/video_core/renderer_vulkan/vk_scheduler.cpp
src/video_core/renderer_vulkan/vk_scheduler.h
src/video_core/renderer_vulkan/vk_shader_cache.cpp
src/video_core/renderer_vulkan/vk_shader_cache.h
src/video_core/renderer_vulkan/vk_shader_util.cpp
src/video_core/renderer_vulkan/vk_shader_util.h
src/video_core/renderer_vulkan/vk_swapchain.cpp
@ -562,13 +526,7 @@ set(EMULATOR src/emulator.cpp
if(ENABLE_QT_GUI)
qt_add_resources(RESOURCE_FILES src/shadps4.qrc)
set(QT_GUI src/qt_gui/about_dialog.cpp
src/qt_gui/about_dialog.h
src/qt_gui/about_dialog.ui
src/qt_gui/cheats_patches.cpp
src/qt_gui/cheats_patches.h
src/qt_gui/memory_patcher.cpp
src/qt_gui/memory_patcher.h
set(QT_GUI
src/qt_gui/main_window_ui.h
src/qt_gui/main_window.cpp
src/qt_gui/main_window.h
@ -596,7 +554,6 @@ set(QT_GUI src/qt_gui/about_dialog.cpp
src/qt_gui/main.cpp
${EMULATOR}
${RESOURCE_FILES}
${TRANSLATIONS}
)
endif()
@ -631,7 +588,7 @@ endif()
create_target_directory_groups(shadps4)
target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API FFmpeg::ffmpeg)
target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::toml11 tsl::robin_map xbyak::xbyak Tracy::TracyClient RenderDoc::API)
target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::SPIRV glslang::glslang SDL3::SDL3)
if (APPLE)
@ -644,9 +601,6 @@ if (APPLE)
# Replacement for std::chrono::time_zone
target_link_libraries(shadps4 PRIVATE date::date-tz)
# Half float conversions for F16C patches
target_link_libraries(shadps4 PRIVATE half)
endif()
if (NOT ENABLE_QT_GUI)
@ -660,45 +614,27 @@ else()
endif()
if (ENABLE_QT_GUI)
target_link_libraries(shadps4 PRIVATE Qt6::Widgets Qt6::Concurrent Qt6::Network)
add_definitions(-DENABLE_QT_GUI)
target_link_libraries(shadps4 PRIVATE Qt6::Widgets Qt6::Concurrent)
endif()
if (WIN32)
target_link_libraries(shadps4 PRIVATE mincore winpthreads)
if (MSVC)
# MSVC likes putting opinions on what people can use, disable:
target_link_libraries(shadps4 PRIVATE mincore winpthreads clang_rt.builtins-x86_64.lib)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
endif()
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN)
if (MSVC)
# Needed for conflicts with time.h of windows.h
add_definitions(-D_TIMESPEC_DEFINED)
endif()
# Target Windows 10 RS5
add_definitions(-DNTDDI_VERSION=0x0A000006 -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00)
if (MSVC)
target_link_libraries(shadps4 PRIVATE clang_rt.builtins-x86_64.lib)
endif()
# Increase stack commit area
target_link_options(shadps4 PRIVATE /STACK:0x200000,0x200000)
# Disable ASLR so we can reserve the user area
if (MSVC)
target_link_options(shadps4 PRIVATE /DYNAMICBASE:NO)
else()
target_link_options(shadps4 PRIVATE -Wl,--disable-dynamicbase)
endif()
# Increase stack commit area (Needed, otherwise there are crashes)
if (MSVC)
target_link_options(shadps4 PRIVATE /STACK:0x200000,0x200000)
else()
target_link_options(shadps4 PRIVATE -Wl,--stack,2097152)
endif()
endif()
if (WIN32)

View File

@ -69,7 +69,7 @@ enum class SomeEnum {
* Note that the asterisks are indented by one space to align to the first line.
*/
struct Position {
// Always initialize member variables!
// Always intitialize member variables!
int x{};
int y{};
};

View File

@ -32,30 +32,27 @@ SPDX-License-Identifier: GPL-2.0-or-later
<img src="https://github.com/shadps4-emu/shadPS4/blob/main/documents/Screenshots/We are DOOMED.png" width="400">
</p>
# General information
# shadPS4
shadPS4 is an early **PlayStation 4** emulator for **Windows**, **Linux** and **macOS** written in C++.
shadPS4 is an early **PlayStation 4** emulator for **Windows**, **Linux** and **macOS** written in C++
If you encounter problems or have doubts, do not hesitate to look at the [**Quickstart**](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Quickstart/Quickstart.md).
To verify that a game works, you can look at [**shadPS4 Game Compatibility**](https://github.com/shadps4-emu/shadps4-game-compatibility).
To discuss shadPS4 development, suggest ideas or to ask for help, join our [**Discord server**](https://discord.gg/MyZRaBngxA).
To discuss shadPS4 development or suggest ideas, join the [**Discord server**](https://discord.gg/MyZRaBngxA).
To get the latest news, go to our [**X (Twitter)**](https://x.com/shadps4) or our [**website**](https://shadps4.net/).
To get the latest news, go to our [**X (twitter)**](https://x.com/shadps4) or our [**website**](https://shadps4.net/).
# Status
> [!IMPORTANT]
> shadPS4 is early in developement, don't expect a flawless experience.
Currently, the emulator successfully runs small games like [**Sonic Mania**](https://www.youtube.com/watch?v=AAHoNzhHyCU), [**Undertale**](https://youtu.be/5zIvdy65Ro4) and it can even *somewhat* run [**Bloodborne**](https://www.youtube.com/watch?v=wC6s0avpQRE).
In development, small games are working like [**Sonic Mania**](https://www.youtube.com/watch?v=AAHoNzhHyCU), [**Undertale**](https://youtu.be/5zIvdy65Ro4), [**Dysmantle**](https://youtu.be/b9xzhLBdESE) and others...
# Why
This project began as a fun project. Given our limited free time, it may take some time before shadPS4 can run more complex games, but we're committed to making small, regular updates.
The project started as a fun project. Due to limited free time, it will probably take a while before shadPS4 is able to run anything decent, but we're trying to make small, regular commits.
# Building
# Build
## Windows
@ -65,7 +62,7 @@ Check the build instructions for [**Windows**](https://github.com/shadps4-emu/sh
Check the build instructions for [**Linux**](https://github.com/shadps4-emu/shadPS4/blob/main/documents/building-linux.md).
## Building status
## Build status
<details>
<summary><b>Windows</b></summary>
@ -94,16 +91,9 @@ Check the build instructions for [**Linux**](https://github.com/shadps4-emu/shad
|macOS Qt Build|[![macOS-qt](https://github.com/shadps4-emu/shadPS4/actions/workflows/macos-qt.yml/badge.svg)](https://github.com/shadps4-emu/shadPS4/actions/workflows/macos-qt.yml)
</details>
# Debugging and reporting issues
# Keyboard Mapping
For more information on how to test, debug and report issues with the emulator or games, read the [Debugging documentation](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Debugging/Debugging.md).
# Keyboard mapping
> [!NOTE]
> Xbox and DualShock controllers work out of the box.
| Controller button | Keyboard equivelant |
| Controller button | Keyboard |
|-------------|-------------|
LEFT AXIS UP | W |
LEFT AXIS DOWN | S |

View File

@ -1,23 +0,0 @@
# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_package(PkgConfig QUIET)
pkg_check_modules(FFMPEG QUIET IMPORTED_TARGET libavcodec libavfilter libavformat libavutil libswresample libswscale)
find_file(FFMPEG_VERSION_FILE libavutil/ffversion.h HINTS "${FFMPEG_libavutil_INCLUDEDIR}")
if (FFMPEG_VERSION_FILE)
file(STRINGS "${FFMPEG_VERSION_FILE}" FFMPEG_VERSION_LINE REGEX "FFMPEG_VERSION")
string(REGEX MATCH "[0-9.]+" FFMPEG_VERSION "${FFMPEG_VERSION_LINE}")
unset(FFMPEG_VERSION_LINE)
unset(FFMPEG_VERSION_FILE)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFmpeg
REQUIRED_VARS FFMPEG_LINK_LIBRARIES
VERSION_VAR FFMPEG_VERSION
)
if (FFmpeg_FOUND AND NOT TARGET FFmpeg::ffmpeg)
add_library(FFmpeg::ffmpeg ALIAS PkgConfig::FFMPEG)
endif()

View File

@ -1,25 +0,0 @@
# SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
# SPDX-License-Identifier: GPL-2.0-or-later
find_path(RENDERDOC_INCLUDE_DIR renderdoc_app.h)
if (RENDERDOC_INCLUDE_DIR AND EXISTS "${RENDERDOC_INCLUDE_DIR}/renderdoc_app.h")
file(STRINGS "${RENDERDOC_INCLUDE_DIR}/renderdoc_app.h" RENDERDOC_VERSION_LINE REGEX "typedef struct RENDERDOC_API")
string(REGEX REPLACE ".*typedef struct RENDERDOC_API_([0-9]+)_([0-9]+)_([0-9]+).*" "\\1.\\2.\\3" RENDERDOC_VERSION "${RENDERDOC_VERSION_LINE}")
unset(RENDERDOC_VERSION_LINE)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(RenderDoc
REQUIRED_VARS RENDERDOC_INCLUDE_DIR
VERSION_VAR RENDERDOC_VERSION
)
if (RenderDoc_FOUND AND NOT TARGET RenderDoc::API)
add_library(RenderDoc::API INTERFACE IMPORTED)
set_target_properties(RenderDoc::API PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${RENDERDOC_INCLUDE_DIR}"
)
endif()
mark_as_advanced(RENDERDOC_INCLUDE_DIR)

View File

@ -1,156 +0,0 @@
<!--
SPDX-FileCopyrightText: 2024 shadPS4 Emulator Project
SPDX-License-Identifier: GPL-2.0-or-later
-->
# Debugging and reporting issues about shadPS4 and games
This document covers information about debugging, troubleshooting and reporting developer-side issues related to shadPS4 and games.
## Setup
This section will guide you through setting up tools for debugging the emulator. This list will likely expand as more tools and platforms receive consistent setups.
<details>
<summary>Windows and Visual Studio</summary>
Make sure you have the project set up for building on Windows with Visual Studio and CMake: [Build shadPS4 for Windows
](https://github.com/shadps4-emu/shadPS4/blob/main/documents/building-windows.md)
1. Open the project folder in Visual Studio **as a folder**. _Do not run `cmake ..` or other commands that set up the project._
2. In the Solution Explorer, click the **Switch between solutions and available views** button.\
![image](https://github.com/user-attachments/assets/4e2be2b1-ba5a-4451-9ab2-f4ecf246213d)
3. Double-click on **CMake Targets View**.\
![image](https://github.com/user-attachments/assets/5ce7cf90-cd61-4cfa-bef5-645909827290)
4. Under **shadPS4 Project**, right-click on the **shadps4 (executable)** solution and click **Set as Startup Item**. This will let you start and debug shadPS4 using the VS debug buttons, as well as the default F5 shortcut.\
![image](https://github.com/user-attachments/assets/34c7c047-28a3-499f-be8f-df781134d104)
5. Right-click the **shadps4 (executable)** solution once more and click **Add debug configuration**.
6. Add an `"args: []"` section into the first `configurations` entry.\
List your game path as an argument, as if you were launching the non-GUI emulator from the command line.
![image](https://github.com/user-attachments/assets/8c7c3e69-f38f-4d6b-bdfd-4f1c41c50be7)
7. Set the appropriate CMake configuration for debugging or testing.
- For debugging the emulator and games within it, select `x64-Clang-Debug`.
- For testing the emulator with compiler optimizations as a release build, it is recommended to select `x64-Clang-RelWithDebInfo`,
as debug symbols will still be generated in case you encounter release configuration-exclusive bugs/errors.
![image](https://github.com/user-attachments/assets/0d975f7a-7bea-4f89-87ef-5d685bea4381)
Launch and debug the emulator through **Debug > Start Debugging** (F5 by default), or **Debug > Start Without Debugging** (Ctrl+F5 by default) when testing games for performance.
</details>
## Configuration
You can configure the emulator by editing the `config.toml` file found in the `user` folder created after starting the application.
<details>
<summary>Some configuration entries worth changing</summary>
- `[General]`
- `logType`: Configures logging synchronization (`sync`/`async`)
- By default, the emulator logs messages asynchronously for better performance. Some log messages may end up being received out-of-order.
- It can be beneficial to set this to `sync` in order for the log to accurately maintain message order, at the cost of performance.
- When communicating about issues with games and the log messages aren't clear due to potentially confusing order, set this to `sync` and send that log as well.
- `logFilter`: Sets the logging category for various logging classes.
- Format: `<class>:<level> ...`
- Multiple classes can be set by separating them with a space. (example: `Render:Warning Debug:Critical Lib.Pad:Error`)
- Sub-classes can be specified in the same format as seen in the console/log (such as `Core.Linker`).
- All classes and sub-classes can be set by specifying a `*` symbol. (example: `Kernel.*:Critical`)
- Valid log levels: `Trace, Debug, Info, Warning, Error, Critical` - in this order, setting a level silences all levels preceding it and logs every level after it.
- Examples:
- If the log is being spammed with messages coming from Lib.Pad, you can use `Lib.Pad:Critical` to only log critical-level messages.
- If you'd like to mute everything, but still want to receive messages from Vulkan rendering: `*:Critical Render.Vulkan:Info`
- `Fullscreen`: Display the game in a full screen borderless window.
- `[GPU]`
- `dumpShaders`: Dump shaders that are loaded by the emulator. Dump path: `../user/shader/dumps`
- `nullGpu`: Disables rendering.
- `screenWidth` and `screenHeight`: Configures the game window width and height.
- `[Vulkan]`
- `validation`-related settings: Use when debugging Vulkan.
- `rdocEnable`: Automatically hook RenderDoc when installed. Useful for debugging shaders and game rendering.
- `rdocMarkersEnable`: Enable automatic RenderDoc event annotation
- `[LLE]`
- `libc`: Use LLE with `libc`.
</details>
## Quick analysis
This section will provide some preliminary steps to take and tips on what to do when you encounter scenarios that require debugging.
<details open>
<summary>When a game crashes and breaks in the debugger</summary>
1. Analyze the log
- A console will open by default when you launch the emulator. It shows the same log messages that go into the log file found at `<emulator executable>/user/log/shad_log.txt`.
- It is recommended that you start analyzing the log bottom-up first:
- Are there any critical or error-level messages at the end of the log that would point to a reason for the game crashing?
- Do any of the last few messages contain information about the game loading files?
- Did the game window draw anything on-screen?
- Continue analyzing the log from the start to see other errors (such as with initialization, memory mapping, linker errors etc.)
2. Analyze the stack trace
- When the emulator is launched through a debugger, it will **break** when an exception or violation is encountered.\
_(**breaking** in this context means pausing execution of the program before it continues or stops altogether.
Breaks can be intentional as well - these are set with various kinds of **breakpoints**.)_
- Default setups of most debuggers include a **Stack trace** window/panel that lists the functions the program has called before breaking.
- The stack trace entries can be navigated to and will show the relevant function, as well as switch to the state that the program was in at the time of execution.\
Use the **Locals** and **Watch** windows to investigate variables and other code in these contexts.
3. Identify the reason for the crash
- **Logs aren't always accurate in determining the reason for a crash.**\
Some log entries are reported as errors but may not be fatal for the execution to stop. `Critical` entries are most likely to be the cause for crashes.
- Pinpoint the area of the emulator where the crash occured\
If the stack trace ends with functions that are relevant to rendering, it is safe to assume that the issue is with **rendering**.\
Similarly, if a crash is in a library responsible for playing videos, your issue can be narrowed down to the scope of video playback in the emulator.
- **⚠ Some crashes are intentional**
- If you identify **Access violations for writing operations** where the function is (or in cases of game libraries, _looks like_ it is) copying memory,
it most likely is an **intentional exception** meant to catch game data being written by the game.
This is used by the emulator developers to identify procedures that have to do with game data changing.
- Debugging tools usually include an option to not break on certain types of exceptions. **Exclude access violations and other intentional exceptions when debugging to skip these exceptions.**
- You can also identify such cases if the game works in Release builds of the emulator. These intentional exceptions are development-time only.
- Attempt to **Continue** and observe whether the stack trace and/or variables and registers change when you encounter exceptions.
</details>
## Reporting and communicating about issues
When communicating with the project about game-specific issues, specify an **uniquely identifable game name** along with its `CUSA-xxxxx` code that is specific to the region/variant of the game you're testing.\
The version number is also important to add at least in the description, especially if you can verify that the game behaves differently across versions.\
Accurately identifying games will help other developers that own that game recognize your issue by its title and jump in to help test and debug it.
- Examples of good naming schemes:
- Amplitude (2016) `CUSA02480`
- Rock Band 4 (`CUSA02084`) v1.0
- inFamous: Second Son \[`CUSA-00004`\]
- Examples of unideal naming schemes:
- _The Witness_
- _GTA 5_
- _Watch Dogs_
- If your issue is small or you aren't sure whether you have properly identified something, [join the Discord server](https://discord.gg/MyZRaBngxA) and use the #development channel
to concisely explain the issue, as well as any findings you currently have.
- It is recommended that you check the [game compatibility issue tracker](https://github.com/shadps4-emu/shadps4-game-compatibility/issues) and post very short summaries of progress changes there,
(such as the game now booting into the menu or getting in-game) for organizational and status update purposes.
- ⚠ **Do not post theoretical, unproven game-specific issues in the emulator issue tracker that you cannot verify and locate in the emulator source code as being a bug.**\
Do, however, add information about the game you experienced the issue in, so that it can be tested in a reproducible environment.
- Good example: "_Crash in `Shader::Gcn::CFG::EmitBlocks()`, out of bounds list access_" -> _issue description shares stack trace, points to code in the repository and provides relevant information_
- Bad example: "_Amplitude crashes on boot, access violation_" -> _issue description reiterates title, focuses on the game instead of the emulator and refuses to elaborate_

BIN
documents/Quickstart/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -58,24 +58,4 @@ To install PKG files (game and updates), you will need the Qt application (with
## Configure the emulator
You can configure the emulator by editing the `config.toml` file found in the `user` folder created after starting the application.\
Some settings may be related to more technical development and debugging. For more information on those, see [Debugging](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Debugging/Debugging.md#configuration).
Here's a list of configuration entries that are worth changing:
- `[General]`
- `Fullscreen`: Display the game in a full screen borderless window.
- `logType`: Configures logging synchronization (`sync`/`async`)
- It can be beneficial to set this to `sync` in order for the log to accurately maintain message order, at the cost of performance.
- Use when sending logs to developers. See more about [reporting issues](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Debugging/Debugging.md#reporting-and-communicating-about-issues).
- `logFilter`: Sets the logging category for various logging classes.
- Format: `<class>:<level> ...`, `<class.*>:<level> <*:level> ...`
- Valid log levels: `Trace, Debug, Info, Warning, Error, Critical` - in this order, setting a level silences all levels preceding it and logs every level after it.
- Examples:
- If the log is being spammed with messages coming from Lib.Pad, you can use `Lib.Pad:Critical` to only log critical-level messages.
- If you'd like to mute everything, but still want to receive messages from Vulkan rendering: `*:Error Render.Vulkan:Info`
- `[GPU]`
- `screenWidth` and `screenHeight`: Configures the game window width and height.
You can configure the emulator in the "user" folder (created after the first start of the application) then in the "config.toml" file. Here you can find lots of parameters to set with True or False.

View File

@ -5,96 +5,21 @@ SPDX-License-Identifier: GPL-2.0-or-later
# Build shadPS4 for Windows
This tutorial reads as if you have none of the prerequisites already installed. If you do, just ignore the steps regarding installation.
If you are building to contribute to the project, please omit `--depth 1` from the git invokations.
## Download Visual Studio Community 2022
Note: **ARM64 is not supported!** As of writing, it will not build nor run. The instructions with respect to ARM64 are for developers only.
Download link: [**Visual Studio 2022**](https://visualstudio.microsoft.com/vs/)
## Option 1: Visual Studio 2022
## Requirements
### (Prerequisite) Download the Community edition from [**Visual Studio 2022**](https://visualstudio.microsoft.com/vs/)
### From Visual Studio Community
Once you are within the installer:
1. Select `Desktop development with C++`
2. Go to "Individual Components" tab
3. Search and select `C++ Clang Compiler for Windows` and `MSBuild support for LLVM`
4. Continue the installation
- Desktop development with C++
### (Prerequisite) Download [**Qt**](https://doc.qt.io/qt-6/get-and-install-qt.html)
### From individual components tab install
Beware, this requires you to create a Qt account. If you do not want to do this, please follow the MSYS2/MinGW compilation method instead.
- C++ Clang Compiler for Windows (17.0.3)
- MSBuild support for LLVM (Clang-cl) toolset
1. Under the current, non beta version of Qt (at the time of writing 6.7.2), select the option `MSVC 2019 64-bit` or similar.
If you are on Windows on ARM / Qualcomm Snapdragon Elite X, select `MSVC 2019 ARM64` instead.
- ## Compiling
Go through the installation normally. If you know what you are doing, you may unselect individual components that eat up too much disk space.
2. Download and install [Qt Visual Studio Tools](https://marketplace.visualstudio.com/items?itemName=TheQtCompany.QtVisualStudioTools2022)
Once you are finished, you will have to configure Qt within Visual Studio:
1. Tools -> Options -> Qt -> Versions
2. Add a new Qt version and navigate it to the correct folder. Should look like so: `C:\Qt\6.7.2\msvc2019_64`
3. Enable the default checkmark on the new version you just created.
### (Prerequisite) Download [**Git for Windows**](https://git-scm.com/download/win)
Go through the Git for Windows installation as normal
### Cloning the source code
1. Open Git for Windows, navigate to a place where you want to store the shadPS4 source code folder
2. Clone the repository by running
`git clone --depth 1 --recursive https://github.com/shadps4-emu/shadPS4`
### Compiling with Visual Studio GUI
1. Open up Visual Studio, select `Open a local folder` and select the folder with the shadPS4 source code. The folder should contain `CMakeLists.txt`
2. Change x64-Clang-Debug to x64-Clang-Release if you want a regular, non-debug build.
3. If you want to build shadPS4 with the Qt Gui:
1. Click x64-Clang-Release and select "Manage Configurations"
2. Look for "CMake command arguments" and add to the text field
`-DENABLE_QT_GUI=ON -DCMAKE_PREFIX_PATH=C:\Qt\6.7.2\msvc2019_64`
(Change Qt path if you've installed it to non-default path)
3. Press CTRL+S to save and wait a moment for CMake generation
4. Change the project to build to shadps4.exe
5. Build -> Build All
Your shadps4.exe will be in `c:\path\to\source\Build\x64-Clang-Release\`
To automatically populate the necessary files to run shadPS4.exe, run in a command prompt or terminal:
`C:\Qt\6.7.2\msvc2019_64\bin\windeployqt.exe c:\path\to\shadps4.exe`
(Change Qt path if you've installed it to non-default path)
## Option 2: MSYS2/MinGW
### (Prerequisite) Download [**MSYS2**](https://www.msys2.org/)
Go through the MSYS2 installation as normal
If you are building to distribute, please omit `-DCMAKE_CXX_FLAGS="-O2 -march=native"` within the build configuration step.
Normal x86-based computers, follow:
1. Open "MSYS2 MINGW64" from your new applications
2. Run `pacman -Syu`, let it complete;
3. Run `pacman -S --needed git mingw-w64-x86_64-binutils mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja mingw-w64-x86_64-qt6-base`
4. Run `git clone --depth 1 --recursive https://github.com/shadps4-emu/shadPS4`
5. Run `cd shadPS4`
6. Run `cmake -S . -B build -DCMAKE_CXX_COMPILER="clang++.exe" -DCMAKE_C_COMPILER="clang.exe" -DCMAKE_CXX_FLAGS="-O2 -march=native"`
7. Run `cmake --build build`
8. To run the finished product, run `./build/shadPS4.exe`
ARM64-based computers, follow:
1. Open "MSYS2 CLANGARM64" from your new applications
2. Run `pacman -Syu`, let it complete;
3. Run `pacman -S --needed git mingw-w64-clang-aarch64-binutils mingw-w64-clang-aarch64-clang mingw-w64-clang-aarch64-cmake mingw-w64-clang-aarch64-ninja mingw-w64-clang-aarch64-qt6-base`
4. Run `git clone --depth 1 --recursive https://github.com/shadps4-emu/shadPS4`
5. Run `cd shadPS4`
6. Run `cmake -S . -B build -DCMAKE_CXX_COMPILER="clang++.exe" -DCMAKE_C_COMPILER="clang.exe" -DCMAKE_CXX_FLAGS="-O2 -march=native"`
7. Run `cmake --build build`
8. To run the finished product, run `./build/shadPS4.exe`
## Note on MSYS2 builds
These builds may not be easily copyable to people who do not also have a MSYS2 installation.
If you want to distribute these builds, you need to copy over the correct DLLs into a distribution folder.
In order to run them, you must be within the MSYS2 shell environment.
- Open Visual Studio Community and select the **x64-Clang-Release**, **x64-Clang-Debug** or **x64-Clang-RelWithDebInfo**. It should compile just fine.

View File

@ -1,44 +1,32 @@
v0.2.0 15/08/2024 - codename validptr
=================
- Adding macOS support
- Big shader recompiler improvements
- Core improvements
- GUI improvements
v0.1.0 01/07/2024 - codename madturtle
=================
- Added a shader recompiler, with this we have a lot of games that starts to work
- Rewrote a big part of core
v0.0.3 23/03/2024 - codename salad
=================
- Switching to std::thread
- Use unique_ptr where possible
- Replace printf/scanf with type safe fmt
- Implemented sceKernelGetProcessTime
- Implemented sceKernelGetProcessTimeCounter, sceKernelGetProcessTimeCounterFrequency
- Pause emu with P button
- Timers rewrote with std::chrono
- Added sceSystemServiceGetStatus
- Initial FileSystem implementation
- Initial TLS work
- New logging implementation
- Some functions implemented for userService, systemService
- Added sceAudioOut module and output using SDL audio
-Switching to std::thread
-Use unique_ptr where possible
-Replace printf/scanf with type safe fmt
-Implemented sceKernelGetProcessTime
-Implemented sceKernelGetProcessTimeCounter , sceKernelGetProcessTimeCounterFrequency
-Pause emu with P button
-Timers rewrote with std::chrono
-Added sceSystemServiceGetStatus
-Initial FileSystem implementation
-Initial TLS work
-New logging implementation
-Some functions implemented for userService,systemService
-Added sceAudioOut module and output using sdl audio
v0.0.2 21/10/2023
=================
- Using cstdint header in variable types
- run_main_entry: Rewrite in asm for stack setup
- Printf libc implementation for work with sysv_abi
- Initial pad emulation (only digital pad atm)
- Implemented sceVideoOutIsFlipPending
- Added auto stubs, now unsupported hle function will resolve as empty stubs
- Rewrote libc_cxa functions
- Libc implementations ( _ZdlPv,_Znwm,rand,_Fsin,qsort,free,strncpy,memmove,atan2f,pow,_Sin)
- ET_SCE_DYNAMIC behaves as valid for execution now
- Initial FileSystem work (not yet usable)
-using cstdint header in variable types
-run_main_entry: Rewrite in asm for stack setup
-printf libc implementation for work with sysv_abi
-initial pad emulation (only digital pad atm)
-Implemented sceVideoOutIsFlipPending
-Added auto stubs , now unsupported hle function will resolve as empty stubs
-Rewrote libc_cxa functions
-Libc implementations ( _ZdlPv,_Znwm,rand,_Fsin,qsort,free,strncpy,memmove,atan2f,pow,_Sin)
-ET_SCE_DYNAMIC behaves as valid for execution now.
-Initial FileSystem work (not yet usable).
v0.0.1 29/09/2023
=================
First public release. Everything is new.
First public release . Everything is new

35
documents/readme.txt Normal file
View File

@ -0,0 +1,35 @@
shadPS4 - A PS4 emulator
=========================
1. Intro
2. Current status
3. Contributors
4. Greetings
1.Intro
=======
shadPS4 is a Play Station 4 emulator for Windows and Linux. Although atm it can't run a lot of stuff, we are working torwards to make it more compatible.
2.Current status
================
shadPS4 is a HLE emulator. Currently on a small amount of functions is emulated, which is one of the reasons compatibility is low.
3.Contributors
==============
- georgemoralis
- raphaelthegreat
- skmp
- wheremyfoodat
4.Greetings
===========
I would like to thank the following people for helping me so far, with coding or moral support.
- wheremyfoodat - or @rodakinos for believed me
- paris - or OFFTKP for not believing me and that made me a better coder :D
- skmp - or kornilios for being good old friend
- PandaBad - our beloved stalker
- emufan4568 - for advices
- velocity - for talking 1-2 times per year on discord server. We miss you velocity
- probably more, will include in the next readme :D

View File

@ -25,6 +25,11 @@ if (NOT TARGET fmt::fmt)
add_subdirectory(fmt)
endif()
# Discord-RPC
set(BUILD_EXAMPLES OFF CACHE BOOL "")
add_subdirectory(discord-rpc)
target_include_directories(discord-rpc INTERFACE ./discord-rpc/include)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND MSVC)
# If it is clang and MSVC we will add a static lib
# CryptoPP
@ -42,12 +47,6 @@ else()
endif()
endif()
if (NOT TARGET FFmpeg::ffmpeg)
set(ARCHITECTURE "x86_64")
add_subdirectory(ffmpeg-core)
add_library(FFmpeg::ffmpeg ALIAS ffmpeg)
endif()
# Zlib-Ng
if (NOT TARGET zlib-ng::zlib)
set(ZLIB_ENABLE_TESTS OFF)
@ -142,17 +141,11 @@ if (WIN32)
target_compile_options(sirit PUBLIC "-Wno-error=unused-command-line-argument")
endif()
if (APPLE)
# half
add_library(half INTERFACE)
target_include_directories(half INTERFACE half/include)
# date
if (NOT TARGET date::date-tz)
# date
if (APPLE AND NOT TARGET date::date-tz)
option(BUILD_TZ_LIB "" ON)
option(USE_SYSTEM_TZ_DB "" ON)
add_subdirectory(date)
endif()
endif()
# Tracy

1
externals/discord-rpc vendored Submodule

@ -0,0 +1 @@
Subproject commit 4ec218155d73bcb8022f8f7ca72305d801f84beb

2
externals/ext-boost vendored

@ -1 +1 @@
Subproject commit a04136add1e469f46d8ae8d3e8307779240a5c53
Subproject commit 147b2de7734f5dc3b9aeb1f4135ae15fcd44b9d7

@ -1 +0,0 @@
Subproject commit e30b7d7fe228bfb3f6e41ce1040b44a15eb7d5e0

2
externals/glslang vendored

@ -1 +1 @@
Subproject commit 12cbda959b6df2af119a76a73ff906c2bed36884
Subproject commit 7c4d91e7819a1d27213aa3499953d54ae1a00e8f

1
externals/half vendored

@ -1 +0,0 @@
Subproject commit 1ddada225144cac0de8f6b5c0dd9acffd99a2e68

2
externals/robin-map vendored

@ -1 +1 @@
Subproject commit 2c48a1a50203bbaf1e3d0d64c5d726d56f8d3bb3
Subproject commit 1115dad3ffa0994e3f43b693d9b9cc99944c64c1

2
externals/sirit vendored

@ -1 +1 @@
Subproject commit 37090c74cc6e680f2bc334cac8fd182f7634a1f6
Subproject commit 8db09231c448b913ae905d5237ce2eca46e3fe87

2
externals/toml11 vendored

@ -1 +1 @@
Subproject commit 4b740127230472779c4a4d71e1a75aaa3a367a2d
Subproject commit fcb1d3d7e5885edfadbbe9572991dc4b3248af58

2
externals/vma vendored

@ -1 +1 @@
Subproject commit e1bdbca9baf4d682fb6066b380f4aa4a7bdbb58a
Subproject commit 871913da6a4b132b567d7b65c509600363c0041e

@ -1 +1 @@
Subproject commit d205aff40b4e15d4c568523ee6a26f85138126d9
Subproject commit 595c8d4794410a4e64b98dc58d27c0310d7ea2fd

2
externals/xbyak vendored

@ -1 +1 @@
Subproject commit ccdf68421bc8eb85693f573080fc0a5faad862db
Subproject commit aabb091ae37068498751fd58202a9854408ecb0e

2
externals/xxhash vendored

@ -1 +1 @@
Subproject commit dbea33e47e7c0fe0b7c8592cd931c7430c1f130d
Subproject commit ee65ff988bab34a184c700e2fbe1e1c5bc27485d

2
externals/zydis vendored

@ -1 +1 @@
Subproject commit bd73bc03b0aacaa89c9c203b9b43cd08f1b1843b
Subproject commit 16c6a369c193981e9cf314126589eaa8763f92c3

View File

@ -114108,7 +114108,7 @@ STUB(
_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_7Matches2V124RequestCompetitiveResultEE7add_refEv)
STUB("efPahl2FufA",
_ZN3sce2Np9CppWebApi30CommunicationRestrictionStatus2V35Error8fromJsonERKNS_4Json5ValueE)
STUB("efX3lrPwdKA", sceAppContentAddcontMountByEntitlementId)
STUB("efX3lrPwdKA", sceAppContentAddcontMountByEntitlemetId)
STUB("efXnxYFN5oE", _ZNSt11range_errorD0Ev)
STUB("efcwuDLsAM0", _ZThn120_NK7WebCore16HTMLMediaElement5mutedEv)
STUB("efhGArzWdxE", _ZN7bmalloc6IsoTLS15s_didInitializeE)
@ -129493,7 +129493,7 @@ STUB(
STUB("kJlYH5uMAWI", sceNetResolverDestroy)
STUB("kJmdxo4uM+8",
_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE5_InitERKSt8_Locinfo)
STUB("kJmjt81mXKQ", sceAppContentAddcontEnqueueDownloadByEntitlementId)
STUB("kJmjt81mXKQ", sceAppContentAddcontEnqueueDownloadByEntitlemetId)
STUB(
"kJoY9lMIFzY",
_ZN3sce2Np9CppWebApi6Common8IteratorINS2_12IntrusivePtrINS1_21AdvancedPlayerProfile2V138MatchCompletionRateDisconnectedMetricsEEEEmmEi)

View File

@ -80897,10 +80897,10 @@ sceAppCheckerExecute
sceAppCheckerExecuteEx
sceAppContentAddcontDelete
sceAppContentAddcontEnqueueDownload
sceAppContentAddcontEnqueueDownloadByEntitlementId
sceAppContentAddcontEnqueueDownloadByEntitlemetId
sceAppContentAddcontEnqueueDownloadSp
sceAppContentAddcontMount
sceAppContentAddcontMountByEntitlementId
sceAppContentAddcontMountByEntitlemetId
sceAppContentAddcontShrink
sceAppContentAddcontUnmount
sceAppContentAppParamGetInt

View File

@ -1,23 +1,19 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "sdl_audio.h"
#include "common/assert.h"
#include "core/libraries/error_codes.h"
#include <SDL3/SDL_audio.h>
#include <SDL3/SDL_init.h>
#include <SDL3/SDL_timer.h>
#include <mutex> // std::unique_lock
#include "common/assert.h"
#include "core/libraries/error_codes.h"
#include "sdl_audio.h"
namespace Audio {
int SDLAudio::AudioOutOpen(int type, u32 samples_num, u32 freq,
Libraries::AudioOut::OrbisAudioOutParamFormat format) {
using Libraries::AudioOut::OrbisAudioOutParamFormat;
std::unique_lock lock{m_mutex};
std::scoped_lock lock{m_mutex};
for (int id = 0; id < portsOut.size(); id++) {
auto& port = portsOut[id];
if (!port.isOpen) {
@ -92,7 +88,7 @@ int SDLAudio::AudioOutOpen(int type, u32 samples_num, u32 freq,
}
s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) {
std::shared_lock lock{m_mutex};
std::scoped_lock lock{m_mutex};
auto& port = portsOut[handle - 1];
if (!port.isOpen) {
return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT;
@ -104,7 +100,7 @@ s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) {
int result = SDL_PutAudioStreamData(port.stream, ptr,
port.samples_num * port.sample_size * port.channels_num);
// TODO find a correct value 8192 is estimated
while (SDL_GetAudioStreamAvailable(port.stream) > 65536) {
while (SDL_GetAudioStreamAvailable(port.stream) > 8192) {
SDL_Delay(0);
}
@ -113,7 +109,7 @@ s32 SDLAudio::AudioOutOutput(s32 handle, const void* ptr) {
bool SDLAudio::AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume) {
using Libraries::AudioOut::OrbisAudioOutParamFormat;
std::shared_lock lock{m_mutex};
std::scoped_lock lock{m_mutex};
auto& port = portsOut[handle - 1];
if (!port.isOpen) {
return ORBIS_AUDIO_OUT_ERROR_INVALID_PORT;
@ -151,7 +147,7 @@ bool SDLAudio::AudioOutSetVolume(s32 handle, s32 bitflag, s32* volume) {
}
bool SDLAudio::AudioOutGetStatus(s32 handle, int* type, int* channels_num) {
std::shared_lock lock{m_mutex};
std::scoped_lock lock{m_mutex};
auto& port = portsOut[handle - 1];
*type = port.type;
*channels_num = port.channels_num;

View File

@ -3,7 +3,7 @@
#pragma once
#include <shared_mutex>
#include <mutex>
#include <SDL3/SDL_audio.h>
#include "core/libraries/audio/audioout.h"
@ -22,17 +22,17 @@ public:
private:
struct PortOut {
SDL_AudioStream* stream = nullptr;
bool isOpen = false;
int type = 0;
u32 samples_num = 0;
u8 sample_size = 0;
u32 freq = 0;
u32 format = -1;
int type = 0;
int channels_num = 0;
int volume[8] = {};
u8 sample_size = 0;
bool isOpen = false;
SDL_AudioStream* stream = nullptr;
};
std::shared_mutex m_mutex;
std::mutex m_mutex;
std::array<PortOut, 22> portsOut; // main up to 8 ports , BGM 1 port , voice up to 4 ports ,
// personal up to 4 ports , padspk up to 5 ports , aux 1 port
};

View File

@ -16,13 +16,10 @@ static u32 screenHeight = 720;
static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
static std::string logFilter;
static std::string logType = "async";
static std::string userName = "shadPS4";
static bool useSpecialPad = false;
static int specialPadClass = 1;
static bool isDebugDump = false;
static bool isLibc = true;
static bool isShowSplash = false;
static bool isNullGpu = false;
static bool shouldCopyGPUBuffers = false;
static bool shouldDumpShaders = false;
static bool shouldDumpPM4 = false;
static u32 vblankDivider = 1;
@ -48,10 +45,13 @@ u32 m_window_size_H = 720;
std::vector<std::string> m_pkg_viewer;
std::vector<std::string> m_elf_viewer;
std::vector<std::string> m_recent_files;
std::string emulator_language = "en";
// Settings
u32 m_language = 1; // english
bool isLleLibc() {
return isLibc;
}
bool isNeoMode() {
return isNeo;
}
@ -80,18 +80,6 @@ std::string getLogType() {
return logType;
}
std::string getUserName() {
return userName;
}
bool getUseSpecialPad() {
return useSpecialPad;
}
int getSpecialPadClass() {
return specialPadClass;
}
bool debugDump() {
return isDebugDump;
}
@ -104,10 +92,6 @@ bool nullGpu() {
return isNullGpu;
}
bool copyGPUCmdBuffers() {
return shouldCopyGPUBuffers;
}
bool dumpShaders() {
return shouldDumpShaders;
}
@ -140,10 +124,6 @@ bool vkValidationGpuEnabled() {
return vkValidationGpu;
}
void setGpuId(s32 selectedGpuId) {
gpuId = selectedGpuId;
}
void setScreenWidth(u32 width) {
screenWidth = width;
}
@ -164,10 +144,6 @@ void setNullGpu(bool enable) {
isNullGpu = enable;
}
void setCopyGPUCmdBuffers(bool enable) {
shouldCopyGPUBuffers = enable;
}
void setDumpShaders(bool enable) {
shouldDumpShaders = enable;
}
@ -204,26 +180,14 @@ void setNeoMode(bool enable) {
isNeo = enable;
}
void setLogType(const std::string& type) {
void setLogType(std::string type) {
logType = type;
}
void setLogFilter(const std::string& type) {
void setLogFilter(std::string type) {
logFilter = type;
}
void setUserName(const std::string& type) {
userName = type;
}
void setUseSpecialPad(bool use) {
useSpecialPad = use;
}
void setSpecialPadClass(int type) {
specialPadClass = type;
}
void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) {
main_window_geometry_x = x;
main_window_geometry_y = y;
@ -242,10 +206,10 @@ void setIconSize(u32 size) {
void setIconSizeGrid(u32 size) {
m_icon_size_grid = size;
}
void setSliderPosition(u32 pos) {
void setSliderPositon(u32 pos) {
m_slider_pos = pos;
}
void setSliderPositionGrid(u32 pos) {
void setSliderPositonGrid(u32 pos) {
m_slider_pos_grid = pos;
}
void setTableMode(u32 mode) {
@ -257,23 +221,19 @@ void setMainWindowWidth(u32 width) {
void setMainWindowHeight(u32 height) {
m_window_size_H = height;
}
void setPkgViewer(const std::vector<std::string>& pkgList) {
void setPkgViewer(std::vector<std::string> pkgList) {
m_pkg_viewer.resize(pkgList.size());
m_pkg_viewer = pkgList;
}
void setElfViewer(const std::vector<std::string>& elfList) {
void setElfViewer(std::vector<std::string> elfList) {
m_elf_viewer.resize(elfList.size());
m_elf_viewer = elfList;
}
void setRecentFiles(const std::vector<std::string>& recentFiles) {
void setRecentFiles(std::vector<std::string> recentFiles) {
m_recent_files.resize(recentFiles.size());
m_recent_files = recentFiles;
}
void setEmulatorLanguage(std::string language) {
emulator_language = language;
}
u32 getMainWindowGeometryX() {
return main_window_geometry_x;
}
@ -298,10 +258,10 @@ u32 getIconSize() {
u32 getIconSizeGrid() {
return m_icon_size_grid;
}
u32 getSliderPosition() {
u32 getSliderPositon() {
return m_slider_pos;
}
u32 getSliderPositionGrid() {
u32 getSliderPositonGrid() {
return m_slider_pos_grid;
}
u32 getTableMode() {
@ -323,10 +283,6 @@ std::vector<std::string> getRecentFiles() {
return m_recent_files;
}
std::string getEmulatorLanguage() {
return emulator_language;
}
u32 GetLanguage() {
return m_language;
}
@ -353,24 +309,15 @@ void load(const std::filesystem::path& path) {
isFullscreen = toml::find_or<bool>(general, "Fullscreen", false);
logFilter = toml::find_or<std::string>(general, "logFilter", "");
logType = toml::find_or<std::string>(general, "logType", "sync");
userName = toml::find_or<std::string>(general, "userName", "shadPS4");
isShowSplash = toml::find_or<bool>(general, "showSplash", true);
}
if (data.contains("Input")) {
const toml::value& input = data.at("Input");
useSpecialPad = toml::find_or<bool>(input, "useSpecialPad", false);
specialPadClass = toml::find_or<int>(input, "specialPadClass", 1);
}
if (data.contains("GPU")) {
const toml::value& gpu = data.at("GPU");
screenWidth = toml::find_or<int>(gpu, "screenWidth", screenWidth);
screenHeight = toml::find_or<int>(gpu, "screenHeight", screenHeight);
isNullGpu = toml::find_or<bool>(gpu, "nullGpu", false);
shouldCopyGPUBuffers = toml::find_or<bool>(gpu, "copyGPUBuffers", false);
shouldDumpShaders = toml::find_or<bool>(gpu, "dumpShaders", false);
shouldDumpPM4 = toml::find_or<bool>(gpu, "dumpPM4", false);
vblankDivider = toml::find_or<int>(gpu, "vblankDivider", 1);
@ -393,6 +340,12 @@ void load(const std::filesystem::path& path) {
isDebugDump = toml::find_or<bool>(debug, "DebugDump", false);
}
if (data.contains("LLE")) {
const toml::value& lle = data.at("LLE");
isLibc = toml::find_or<bool>(lle, "libc", true);
}
if (data.contains("GUI")) {
const toml::value& gui = data.at("GUI");
@ -412,7 +365,6 @@ void load(const std::filesystem::path& path) {
m_elf_viewer = toml::find_or<std::vector<std::string>>(gui, "elfDirs", {});
m_recent_files = toml::find_or<std::vector<std::string>>(gui, "recentFiles", {});
m_table_mode = toml::find_or<int>(gui, "gameTableMode", 0);
emulator_language = toml::find_or<std::string>(gui, "emulatorLanguage", "en");
}
if (data.contains("Settings")) {
@ -444,14 +396,10 @@ void save(const std::filesystem::path& path) {
data["General"]["Fullscreen"] = isFullscreen;
data["General"]["logFilter"] = logFilter;
data["General"]["logType"] = logType;
data["General"]["userName"] = userName;
data["General"]["showSplash"] = isShowSplash;
data["Input"]["useSpecialPad"] = useSpecialPad;
data["Input"]["specialPadClass"] = specialPadClass;
data["GPU"]["screenWidth"] = screenWidth;
data["GPU"]["screenHeight"] = screenHeight;
data["GPU"]["nullGpu"] = isNullGpu;
data["GPU"]["copyGPUBuffers"] = shouldCopyGPUBuffers;
data["GPU"]["dumpShaders"] = shouldDumpShaders;
data["GPU"]["dumpPM4"] = shouldDumpPM4;
data["GPU"]["vblankDivider"] = vblankDivider;
@ -462,6 +410,7 @@ void save(const std::filesystem::path& path) {
data["Vulkan"]["rdocEnable"] = rdocEnable;
data["Vulkan"]["rdocMarkersEnable"] = rdocMarkersEnable;
data["Debug"]["DebugDump"] = isDebugDump;
data["LLE"]["libc"] = isLibc;
data["GUI"]["theme"] = mw_themes;
data["GUI"]["iconSize"] = m_icon_size;
data["GUI"]["sliderPos"] = m_slider_pos;
@ -478,7 +427,6 @@ void save(const std::filesystem::path& path) {
data["GUI"]["pkgDirs"] = m_pkg_viewer;
data["GUI"]["elfDirs"] = m_elf_viewer;
data["GUI"]["recentFiles"] = m_recent_files;
data["GUI"]["emulatorLanguage"] = emulator_language;
data["Settings"]["consoleLanguage"] = m_language;
@ -494,9 +442,6 @@ void setDefaultValues() {
screenHeight = 720;
logFilter = "";
logType = "async";
userName = "shadPS4";
useSpecialPad = false;
specialPadClass = 1;
isDebugDump = false;
isShowSplash = false;
isNullGpu = false;
@ -505,9 +450,7 @@ void setDefaultValues() {
vblankDivider = 1;
vkValidation = false;
rdocEnable = false;
emulator_language = "en";
m_language = 1;
gpuId = -1;
}
} // namespace Config

View File

@ -15,19 +15,15 @@ bool isNeoMode();
bool isFullscreenMode();
std::string getLogFilter();
std::string getLogType();
std::string getUserName();
bool getUseSpecialPad();
int getSpecialPadClass();
u32 getScreenWidth();
u32 getScreenHeight();
s32 getGpuId();
bool debugDump();
bool isLleLibc();
bool showSplash();
bool nullGpu();
bool copyGPUCmdBuffers();
bool dumpShaders();
bool dumpPM4();
bool isRdocEnabled();
@ -37,23 +33,17 @@ u32 vblankDiv();
void setDebugDump(bool enable);
void setShowSplash(bool enable);
void setNullGpu(bool enable);
void setCopyGPUCmdBuffers(bool enable);
void setDumpShaders(bool enable);
void setDumpPM4(bool enable);
void setVblankDiv(u32 value);
void setGpuId(s32 selectedGpuId);
void setScreenWidth(u32 width);
void setScreenHeight(u32 height);
void setFullscreenMode(bool enable);
void setLanguage(u32 language);
void setNeoMode(bool enable);
void setUserName(const std::string& type);
void setUseSpecialPad(bool use);
void setSpecialPadClass(int type);
void setLogType(const std::string& type);
void setLogFilter(const std::string& type);
void setLogType(std::string type);
void setLogFilter(std::string type);
void setVkValidation(bool enable);
void setVkSyncValidation(bool enable);
@ -69,15 +59,14 @@ void setGameInstallDir(const std::string& dir);
void setMainWindowTheme(u32 theme);
void setIconSize(u32 size);
void setIconSizeGrid(u32 size);
void setSliderPosition(u32 pos);
void setSliderPositionGrid(u32 pos);
void setSliderPositon(u32 pos);
void setSliderPositonGrid(u32 pos);
void setTableMode(u32 mode);
void setMainWindowWidth(u32 width);
void setMainWindowHeight(u32 height);
void setPkgViewer(const std::vector<std::string>& pkgList);
void setElfViewer(const std::vector<std::string>& elfList);
void setRecentFiles(const std::vector<std::string>& recentFiles);
void setEmulatorLanguage(std::string language);
void setPkgViewer(std::vector<std::string> pkgList);
void setElfViewer(std::vector<std::string> elfList);
void setRecentFiles(std::vector<std::string> recentFiles);
u32 getMainWindowGeometryX();
u32 getMainWindowGeometryY();
@ -87,15 +76,14 @@ std::string getGameInstallDir();
u32 getMainWindowTheme();
u32 getIconSize();
u32 getIconSizeGrid();
u32 getSliderPosition();
u32 getSliderPositionGrid();
u32 getSliderPositon();
u32 getSliderPositonGrid();
u32 getTableMode();
u32 getMainWindowWidth();
u32 getMainWindowHeight();
std::vector<std::string> getPkgViewer();
std::vector<std::string> getElfViewer();
std::vector<std::string> getRecentFiles();
std::string getEmulatorLanguage();
void setDefaultValues();

View File

@ -29,7 +29,7 @@ static inline bool IsProfilerConnected() {
#define TRACK_ALLOC(ptr, size, pool) TracyAllocN(std::bit_cast<void*>(ptr), (size), (pool))
#define TRACK_FREE(ptr, pool) TracyFreeN(std::bit_cast<void*>(ptr), (pool))
enum MarkersPalette : int {
enum MarkersPallete : int {
EmulatorMarkerColor = 0x264653,
RendererMarkerColor = 0x2a9d8f,
HleMarkerColor = 0xe9c46a,

View File

@ -217,7 +217,7 @@ void IOFile::Close() {
file = nullptr;
#ifdef _WIN64
if (file_mapping && file_access_mode == FileAccessMode::ReadWrite) {
if (file_mapping) {
CloseHandle(std::bit_cast<HANDLE>(file_mapping));
}
#endif
@ -259,7 +259,8 @@ uintptr_t IOFile::GetFileMapping() {
mapping = CreateFileMapping2(hfile, NULL, FILE_MAP_WRITE, PAGE_READWRITE, SEC_COMMIT, 0,
NULL, NULL, 0);
} else {
mapping = hfile;
mapping = CreateFileMapping2(hfile, NULL, FILE_MAP_READ, PAGE_READONLY, SEC_COMMIT, 0, NULL,
NULL, 0);
}
file_mapping = std::bit_cast<uintptr_t>(mapping);

View File

@ -106,13 +106,12 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
SUB(Lib, DiscMap) \
SUB(Lib, Png) \
SUB(Lib, PlayGo) \
SUB(Lib, Random) \
SUB(Lib, Usbd) \
SUB(Lib, Ajm) \
SUB(Lib, ErrorDialog) \
SUB(Lib, ImeDialog) \
SUB(Lib, AvPlayer) \
SUB(Lib, Ngs2) \
SUB(Lib, Random) \
CLS(Frontend) \
CLS(Render) \
SUB(Render, Vulkan) \

View File

@ -79,7 +79,6 @@ enum class Class : u8 {
Lib_ErrorDialog, ///< The LibSceErrorDialog implementation.
Lib_ImeDialog, ///< The LibSceImeDialog implementation.
Lib_AvPlayer, ///< The LibSceAvPlayer implementation.
Lib_Ngs2, ///< The LibSceNgs2 implementation.
Frontend, ///< Emulator UI
Render, ///< Video Core
Render_Vulkan, ///< Vulkan backend

View File

@ -18,16 +18,16 @@ NativeClock::NativeClock()
us_rdtsc_factor{GetFixedPoint64Factor(std::micro::den, rdtsc_frequency)},
ms_rdtsc_factor{GetFixedPoint64Factor(std::milli::den, rdtsc_frequency)} {}
u64 NativeClock::GetTimeNS(u64 base_ptc /*= 0*/) const {
return MultiplyHigh(GetUptime() - base_ptc, ns_rdtsc_factor);
u64 NativeClock::GetTimeNS() const {
return MultiplyHigh(GetUptime(), ns_rdtsc_factor);
}
u64 NativeClock::GetTimeUS(u64 base_ptc /*= 0*/) const {
return MultiplyHigh(GetUptime() - base_ptc, us_rdtsc_factor);
u64 NativeClock::GetTimeUS() const {
return MultiplyHigh(GetUptime(), us_rdtsc_factor);
}
u64 NativeClock::GetTimeMS(u64 base_ptc /*= 0*/) const {
return MultiplyHigh(GetUptime() - base_ptc, ms_rdtsc_factor);
u64 NativeClock::GetTimeMS() const {
return MultiplyHigh(GetUptime(), ms_rdtsc_factor);
}
u64 NativeClock::GetUptime() const {

View File

@ -16,9 +16,9 @@ public:
return rdtsc_frequency;
}
u64 GetTimeNS(u64 base_ptc = 0) const;
u64 GetTimeUS(u64 base_ptc = 0) const;
u64 GetTimeMS(u64 base_ptc = 0) const;
u64 GetTimeNS() const;
u64 GetTimeUS() const;
u64 GetTimeMS() const;
u64 GetUptime() const;
u64 GetProcessTimeUS() const;

View File

@ -8,7 +8,6 @@
#ifdef __APPLE__
#include <CoreFoundation/CFBundle.h>
#include <dlfcn.h>
#include <sys/param.h>
#endif
@ -27,55 +26,26 @@ namespace Common::FS {
namespace fs = std::filesystem;
#ifdef __APPLE__
using IsTranslocatedURLFunc = Boolean (*)(CFURLRef path, bool* isTranslocated,
CFErrorRef* __nullable error);
using CreateOriginalPathForURLFunc = CFURLRef __nullable (*)(CFURLRef translocatedPath,
CFErrorRef* __nullable error);
static CFURLRef UntranslocateBundlePath(const CFURLRef bundle_path) {
if (void* security_handle =
dlopen("/System/Library/Frameworks/Security.framework/Security", RTLD_LAZY)) {
SCOPE_EXIT {
dlclose(security_handle);
};
const auto IsTranslocatedURL = reinterpret_cast<IsTranslocatedURLFunc>(
dlsym(security_handle, "SecTranslocateIsTranslocatedURL"));
const auto CreateOriginalPathForURL = reinterpret_cast<CreateOriginalPathForURLFunc>(
dlsym(security_handle, "SecTranslocateCreateOriginalPathForURL"));
bool is_translocated = false;
if (IsTranslocatedURL && CreateOriginalPathForURL &&
IsTranslocatedURL(bundle_path, &is_translocated, nullptr) && is_translocated) {
return CreateOriginalPathForURL(bundle_path, nullptr);
}
}
return nullptr;
}
static std::filesystem::path GetBundleParentDirectory() {
if (CFBundleRef bundle_ref = CFBundleGetMainBundle()) {
if (CFURLRef bundle_url_ref = CFBundleCopyBundleURL(bundle_ref)) {
SCOPE_EXIT {
CFRelease(bundle_url_ref);
};
CFURLRef untranslocated_url_ref = UntranslocateBundlePath(bundle_url_ref);
if (CFStringRef bundle_path_ref =
CFURLCopyFileSystemPath(bundle_url_ref, kCFURLPOSIXPathStyle)) {
SCOPE_EXIT {
if (untranslocated_url_ref) {
CFRelease(untranslocated_url_ref);
}
CFRelease(bundle_path_ref);
};
char app_bundle_path[MAXPATHLEN];
if (CFURLGetFileSystemRepresentation(
untranslocated_url_ref ? untranslocated_url_ref : bundle_url_ref, true,
reinterpret_cast<u8*>(app_bundle_path), sizeof(app_bundle_path))) {
if (CFStringGetFileSystemRepresentation(bundle_path_ref, app_bundle_path,
sizeof(app_bundle_path))) {
std::filesystem::path bundle_path{app_bundle_path};
return bundle_path.parent_path();
}
}
}
}
return std::filesystem::current_path();
}
#endif
@ -104,9 +74,6 @@ static auto UserPaths = [] {
create_path(PathType::SysModuleDir, user_dir / SYSMODULES_DIR);
create_path(PathType::DownloadDir, user_dir / DOWNLOAD_DIR);
create_path(PathType::CapturesDir, user_dir / CAPTURES_DIR);
create_path(PathType::CheatsDir, user_dir / CHEATS_DIR);
create_path(PathType::PatchesDir, user_dir / PATCHES_DIR);
create_path(PathType::AddonsDir, user_dir / ADDONS_DIR);
return paths;
}();

View File

@ -20,9 +20,6 @@ enum class PathType {
SysModuleDir, // Where system modules are stored.
DownloadDir, // Where downloads/temp files are stored.
CapturesDir, // Where rdoc captures are stored.
CheatsDir, // Where cheats are stored.
PatchesDir, // Where patches are stored.
AddonsDir, // Where additional content is stored.
};
constexpr auto PORTABLE_DIR = "user";
@ -38,9 +35,6 @@ constexpr auto TEMPDATA_DIR = "temp";
constexpr auto SYSMODULES_DIR = "sys_modules";
constexpr auto DOWNLOAD_DIR = "download";
constexpr auto CAPTURES_DIR = "captures";
constexpr auto CHEATS_DIR = "cheats";
constexpr auto PATCHES_DIR = "patches";
constexpr auto ADDONS_DIR = "addcont";
// Filenames
constexpr auto LOG_FILE = "shad_log.txt";

View File

@ -28,13 +28,9 @@ struct SlotId {
template <class T>
class SlotVector {
constexpr static std::size_t InitialCapacity = 2048;
constexpr static std::size_t InitialCapacity = 1024;
public:
SlotVector() {
Reserve(InitialCapacity);
}
~SlotVector() noexcept {
std::size_t index = 0;
for (u64 bits : stored_bitset) {
@ -71,6 +67,19 @@ public:
return SlotId{index};
}
template <typename... Args>
[[nodiscard]] SlotId swap_and_insert(SlotId existing_id, Args&&... args) noexcept {
const u32 index = FreeValueIndex();
T& existing_value = values[existing_id.index].object;
new (&values[index].object) T(std::move(existing_value));
existing_value.~T();
new (&values[existing_id.index].object) T(std::forward<Args>(args)...);
SetStorageBit(index);
return SlotId{index};
}
void erase(SlotId id) noexcept {
values[id.index].object.~T();
free_list.push_back(id.index);
@ -142,8 +151,7 @@ private:
const std::size_t old_free_size = free_list.size();
free_list.resize(old_free_size + (new_capacity - values_capacity));
const std::size_t new_free_size = free_list.size();
std::iota(free_list.rbegin(), free_list.rbegin() + new_free_size - old_free_size,
std::iota(free_list.begin() + old_free_size, free_list.end(),
static_cast<u32>(values_capacity));
delete[] values;

View File

@ -94,7 +94,7 @@ namespace Common {
// This function divides a u128 by a u32 value and produces two u64 values:
// the result of division and the remainder
[[nodiscard]] static inline std::pair<u64, u64> Divide128On32(const u128& dividend, u32 divisor) {
[[nodiscard]] static inline std::pair<u64, u64> Divide128On32(u128 dividend, u32 divisor) {
u64 remainder = dividend[0] % divisor;
u64 accum = dividend[0] / divisor;
if (dividend[1] == 0)

View File

@ -8,7 +8,7 @@
namespace Common {
constexpr char VERSION[] = "0.2.1 WIP";
constexpr char VERSION[] = "0.1.1 WIP";
constexpr bool isRelease = false;
} // namespace Common

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <boost/icl/separate_interval_set.hpp>
#include "common/alignment.h"
#include "common/assert.h"
#include "common/error.h"
#include "core/address_space.h"
@ -99,7 +98,7 @@ struct AddressSpace::Impl {
backing_handle =
CreateFileMapping2(INVALID_HANDLE_VALUE, nullptr, FILE_MAP_WRITE | FILE_MAP_READ,
PAGE_READWRITE, SEC_COMMIT, BackingSize, nullptr, nullptr, 0);
ASSERT_MSG(backing_handle, "{}", Common::GetLastErrorMsg());
ASSERT(backing_handle);
// Allocate a virtual memory for the backing file map as placeholder
backing_base = static_cast<u8*>(VirtualAlloc2(process, nullptr, BackingSize,
MEM_RESERVE | MEM_RESERVE_PLACEHOLDER,
@ -107,7 +106,7 @@ struct AddressSpace::Impl {
// Map backing placeholder. This will commit the pages
void* const ret = MapViewOfFile3(backing_handle, process, backing_base, 0, BackingSize,
MEM_REPLACE_PLACEHOLDER, PAGE_READWRITE, nullptr, 0);
ASSERT_MSG(ret == backing_base, "{}", Common::GetLastErrorMsg());
ASSERT(ret == backing_base);
}
~Impl() {
@ -130,10 +129,9 @@ struct AddressSpace::Impl {
}
void* Map(VAddr virtual_addr, PAddr phys_addr, size_t size, ULONG prot, uintptr_t fd = 0) {
const size_t aligned_size = Common::AlignUp(size, 16_KB);
const auto it = placeholders.find(virtual_addr);
ASSERT_MSG(it != placeholders.end(), "Cannot map already mapped region");
ASSERT_MSG(virtual_addr >= it->lower() && virtual_addr + aligned_size <= it->upper(),
ASSERT_MSG(virtual_addr >= it->lower() && virtual_addr + size <= it->upper(),
"Map range must be fully contained in a placeholder");
// Windows only allows splitting a placeholder into two.
@ -142,7 +140,7 @@ struct AddressSpace::Impl {
// one at the start and at the end.
const VAddr placeholder_start = it->lower();
const VAddr placeholder_end = it->upper();
const VAddr virtual_end = virtual_addr + aligned_size;
const VAddr virtual_end = virtual_addr + size;
// If the placeholder doesn't exactly start at virtual_addr, split it at the start.
if (placeholder_start != virtual_addr) {
@ -163,23 +161,11 @@ struct AddressSpace::Impl {
void* ptr = nullptr;
if (phys_addr != -1) {
HANDLE backing = fd ? reinterpret_cast<HANDLE>(fd) : backing_handle;
if (fd && prot == PAGE_READONLY) {
DWORD resultvar;
ptr = VirtualAlloc2(process, reinterpret_cast<PVOID>(virtual_addr), aligned_size,
MEM_RESERVE | MEM_COMMIT | MEM_REPLACE_PLACEHOLDER,
PAGE_READWRITE, nullptr, 0);
bool ret = ReadFile(backing, ptr, size, &resultvar, NULL);
ASSERT_MSG(ret, "ReadFile failed. {}", Common::GetLastErrorMsg());
ret = VirtualProtect(ptr, size, prot, &resultvar);
ASSERT_MSG(ret, "VirtualProtect failed. {}", Common::GetLastErrorMsg());
} else {
ptr = MapViewOfFile3(backing, process, reinterpret_cast<PVOID>(virtual_addr),
phys_addr, aligned_size, MEM_REPLACE_PLACEHOLDER, prot,
nullptr, 0);
}
ptr = MapViewOfFile3(backing, process, reinterpret_cast<PVOID>(virtual_addr), phys_addr,
size, MEM_REPLACE_PLACEHOLDER, prot, nullptr, 0);
} else {
ptr =
VirtualAlloc2(process, reinterpret_cast<PVOID>(virtual_addr), aligned_size,
VirtualAlloc2(process, reinterpret_cast<PVOID>(virtual_addr), size,
MEM_RESERVE | MEM_COMMIT | MEM_REPLACE_PLACEHOLDER, prot, nullptr, 0);
}
ASSERT_MSG(ptr, "{}", Common::GetLastErrorMsg());
@ -468,28 +454,8 @@ void* AddressSpace::MapFile(VAddr virtual_addr, size_t size, size_t offset, u32
#endif
}
void AddressSpace::Unmap(VAddr virtual_addr, size_t size, VAddr start_in_vma, VAddr end_in_vma,
PAddr phys_base, bool is_exec, bool has_backing, bool readonly_file) {
#ifdef _WIN32
// There does not appear to be comparable support for partial unmapping on Windows.
// Unfortunately, a least one title was found to require this. The workaround is to unmap
// the entire allocation and remap the portions outside of the requested unmapping range.
impl->Unmap(virtual_addr, size, has_backing && !readonly_file);
// TODO: Determine if any titles require partial unmapping support for flexible allocations.
ASSERT_MSG(has_backing || (start_in_vma == 0 && end_in_vma == size),
"Partial unmapping of flexible allocations is not supported");
if (start_in_vma != 0) {
Map(virtual_addr, start_in_vma, 0, phys_base, is_exec);
}
if (end_in_vma != size) {
Map(virtual_addr + end_in_vma, size - end_in_vma, 0, phys_base + end_in_vma, is_exec);
}
#else
impl->Unmap(virtual_addr + start_in_vma, end_in_vma - start_in_vma, has_backing);
#endif
void AddressSpace::Unmap(VAddr virtual_addr, size_t size, bool has_backing) {
return impl->Unmap(virtual_addr, size, has_backing);
}
void AddressSpace::Protect(VAddr virtual_addr, size_t size, MemoryPermission perms) {

View File

@ -91,8 +91,7 @@ public:
void* MapFile(VAddr virtual_addr, size_t size, size_t offset, u32 prot, uintptr_t fd);
/// Unmaps specified virtual memory area.
void Unmap(VAddr virtual_addr, size_t size, VAddr start_in_vma, VAddr end_in_vma,
PAddr phys_base, bool is_exec, bool has_backing, bool readonly_file);
void Unmap(VAddr virtual_addr, size_t size, bool has_backing);
void Protect(VAddr virtual_addr, size_t size, MemoryPermission perms);

View File

@ -114108,7 +114108,7 @@ STUB(
_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_7Matches2V124RequestCompetitiveResultEE7add_refEv)
STUB("efPahl2FufA",
_ZN3sce2Np9CppWebApi30CommunicationRestrictionStatus2V35Error8fromJsonERKNS_4Json5ValueE)
STUB("efX3lrPwdKA", sceAppContentAddcontMountByEntitlementId)
STUB("efX3lrPwdKA", sceAppContentAddcontMountByEntitlemetId)
STUB("efXnxYFN5oE", _ZNSt11range_errorD0Ev)
STUB("efcwuDLsAM0", _ZThn120_NK7WebCore16HTMLMediaElement5mutedEv)
STUB("efhGArzWdxE", _ZN7bmalloc6IsoTLS15s_didInitializeE)
@ -129493,7 +129493,7 @@ STUB(
STUB("kJlYH5uMAWI", sceNetResolverDestroy)
STUB("kJmdxo4uM+8",
_ZNSt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEE5_InitERKSt8_Locinfo)
STUB("kJmjt81mXKQ", sceAppContentAddcontEnqueueDownloadByEntitlementId)
STUB("kJmjt81mXKQ", sceAppContentAddcontEnqueueDownloadByEntitlemetId)
STUB(
"kJoY9lMIFzY",
_ZN3sce2Np9CppWebApi6Common8IteratorINS2_12IntrusivePtrINS1_21AdvancedPlayerProfile2V138MatchCompletionRateDisconnectedMetricsEEEEmmEi)

View File

@ -13,7 +13,7 @@ namespace Core::AeroLib {
// on lookup, setting up the nid_entry they are matched with
//
// If it runs out of stubs with name information, it will return
// a default implementation without function name details
// a default implemetnation without function name details
// Up to 512, larger values lead to more resolve stub slots
// and to longer compile / CI times

View File

@ -15,7 +15,6 @@
#else
#include <pthread.h>
#ifdef __APPLE__
#include <half.hpp>
#include <sys/sysctl.h>
#endif
#endif
@ -31,12 +30,6 @@ static Xbyak::Reg ZydisToXbyakRegister(const ZydisRegister reg) {
if (reg >= ZYDIS_REGISTER_RAX && reg <= ZYDIS_REGISTER_R15) {
return Xbyak::Reg64(reg - ZYDIS_REGISTER_RAX + Xbyak::Operand::RAX);
}
if (reg >= ZYDIS_REGISTER_XMM0 && reg <= ZYDIS_REGISTER_XMM31) {
return Xbyak::Xmm(reg - ZYDIS_REGISTER_XMM0 + xmm0.getIdx());
}
if (reg >= ZYDIS_REGISTER_YMM0 && reg <= ZYDIS_REGISTER_YMM31) {
return Xbyak::Ymm(reg - ZYDIS_REGISTER_YMM0 + ymm0.getIdx());
}
UNREACHABLE_MSG("Unsupported register: {}", static_cast<u32>(reg));
}
@ -73,12 +66,6 @@ static Xbyak::Address ZydisToXbyakMemoryOperand(const ZydisDecodedOperand& opera
return ptr[expression];
}
static u64 ZydisToXbyakImmediateOperand(const ZydisDecodedOperand& operand) {
ASSERT_MSG(operand.type == ZYDIS_OPERAND_TYPE_IMMEDIATE,
"Expected immediate operand, got type: {}", static_cast<u32>(operand.type));
return operand.imm.value.u;
}
static std::unique_ptr<Xbyak::Operand> ZydisToXbyakOperand(const ZydisDecodedOperand& operand) {
switch (operand.type) {
case ZYDIS_OPERAND_TYPE_REGISTER: {
@ -123,135 +110,51 @@ static Xbyak::Reg AllocateScratchRegister(
#ifdef __APPLE__
static pthread_key_t stack_pointer_slot;
static pthread_key_t patch_stack_slot;
static std::once_flag patch_context_slots_init_flag;
static constexpr u32 MaxSavedRegisters = 3;
static pthread_key_t register_save_slots[MaxSavedRegisters];
static std::once_flag register_save_init_flag;
static_assert(sizeof(void*) == sizeof(u64),
"Cannot fit a register inside a thread local storage slot.");
static void InitializePatchContextSlots() {
ASSERT_MSG(pthread_key_create(&stack_pointer_slot, nullptr) == 0,
"Unable to allocate thread-local register for stack pointer.");
ASSERT_MSG(pthread_key_create(&patch_stack_slot, nullptr) == 0,
"Unable to allocate thread-local register for patch stack.");
}
void InitializeThreadPatchStack() {
std::call_once(patch_context_slots_init_flag, InitializePatchContextSlots);
const auto* patch_stack = std::malloc(0x1000);
pthread_setspecific(patch_stack_slot, patch_stack);
}
void CleanupThreadPatchStack() {
std::call_once(patch_context_slots_init_flag, InitializePatchContextSlots);
auto* patch_stack = pthread_getspecific(patch_stack_slot);
if (patch_stack != nullptr) {
std::free(patch_stack);
pthread_setspecific(patch_stack_slot, nullptr);
static void InitializeRegisterSaveSlots() {
for (u32 i = 0; i < MaxSavedRegisters; i++) {
ASSERT_MSG(pthread_key_create(&register_save_slots[i], nullptr) == 0,
"Unable to allocate thread-local register save slot {}", i);
}
}
/// Saves the stack pointer to thread local storage and loads the patch stack.
static void SaveStack(Xbyak::CodeGenerator& c) {
std::call_once(patch_context_slots_init_flag, InitializePatchContextSlots);
// Save stack pointer and load patch stack.
c.putSeg(gs);
c.mov(qword[reinterpret_cast<void*>(stack_pointer_slot * sizeof(void*))], rsp);
c.putSeg(gs);
c.mov(rsp, qword[reinterpret_cast<void*>(patch_stack_slot * sizeof(void*))]);
}
/// Restores the stack pointer from thread local storage.
static void RestoreStack(Xbyak::CodeGenerator& c) {
std::call_once(patch_context_slots_init_flag, InitializePatchContextSlots);
// Save patch stack pointer and load original stack.
c.putSeg(gs);
c.mov(qword[reinterpret_cast<void*>(patch_stack_slot * sizeof(void*))], rsp);
c.putSeg(gs);
c.mov(rsp, qword[reinterpret_cast<void*>(stack_pointer_slot * sizeof(void*))]);
}
#else
// These utilities are not implemented as we can't save anything to thread local storage without
// temporary registers.
void InitializeThreadPatchStack() {
// No-op
}
void CleanupThreadPatchStack() {
// No-op
}
/// Saves the stack pointer to thread local storage and loads the patch stack.
static void SaveStack(Xbyak::CodeGenerator& c) {
UNIMPLEMENTED();
}
/// Restores the stack pointer from thread local storage.
static void RestoreStack(Xbyak::CodeGenerator& c) {
UNIMPLEMENTED();
}
#endif
/// Switches to the patch stack, saves registers, and restores the original stack.
static void SaveRegisters(Xbyak::CodeGenerator& c, const std::initializer_list<Xbyak::Reg> regs) {
SaveStack(c);
ASSERT_MSG(regs.size() <= MaxSavedRegisters, "Not enough space to save {} registers.",
regs.size());
std::call_once(register_save_init_flag, &InitializeRegisterSaveSlots);
u32 index = 0;
for (const auto& reg : regs) {
c.push(reg.cvt64());
const auto offset = reinterpret_cast<void*>(register_save_slots[index++] * sizeof(void*));
c.putSeg(gs);
c.mov(qword[offset], reg.cvt64());
}
RestoreStack(c);
}
/// Switches to the patch stack, restores registers, and restores the original stack.
static void RestoreRegisters(Xbyak::CodeGenerator& c,
const std::initializer_list<Xbyak::Reg> regs) {
SaveStack(c);
ASSERT_MSG(regs.size() <= MaxSavedRegisters, "Not enough space to restore {} registers.",
regs.size());
std::call_once(register_save_init_flag, &InitializeRegisterSaveSlots);
u32 index = 0;
for (const auto& reg : regs) {
c.pop(reg.cvt64());
}
RestoreStack(c);
}
const auto offset = reinterpret_cast<void*>(register_save_slots[index++] * sizeof(void*));
/// Switches to the patch stack and stores all registers.
static void SaveContext(Xbyak::CodeGenerator& c) {
SaveStack(c);
for (int reg = Xbyak::Operand::RAX; reg <= Xbyak::Operand::R15; reg++) {
c.push(Xbyak::Reg64(reg));
}
for (int reg = 0; reg <= 7; reg++) {
c.sub(rsp, 32);
c.vmovdqu(ptr[rsp], Xbyak::Ymm(reg));
c.putSeg(gs);
c.mov(reg.cvt64(), qword[offset]);
}
}
/// Restores all registers and restores the original stack.
/// If the destination is a register, it is not restored to preserve the output.
static void RestoreContext(Xbyak::CodeGenerator& c, const Xbyak::Operand& dst) {
for (int reg = 7; reg >= 0; reg--) {
if ((!dst.isXMM() && !dst.isYMM()) || dst.getIdx() != reg) {
c.vmovdqu(Xbyak::Ymm(reg), ptr[rsp]);
}
c.add(rsp, 32);
}
for (int reg = Xbyak::Operand::R15; reg >= Xbyak::Operand::RAX; reg--) {
if (!dst.isREG() || dst.getIdx() != reg) {
c.pop(Xbyak::Reg64(reg));
} else {
c.add(rsp, 4);
}
}
RestoreStack(c);
}
#ifdef __APPLE__
static void GenerateANDN(const ZydisDecodedOperand* operands, Xbyak::CodeGenerator& c) {
const auto dst = ZydisToXbyakRegisterOperand(operands[0]);
const auto src1 = ZydisToXbyakRegisterOperand(operands[1]);
@ -301,9 +204,9 @@ static void GenerateBEXTR(const ZydisDecodedOperand* operands, Xbyak::CodeGenera
c.and_(dst, scratch2);
if (dst.getIdx() == shift.getIdx()) {
RestoreRegisters(c, {scratch2, scratch1});
RestoreRegisters(c, {scratch1, scratch2});
} else {
RestoreRegisters(c, {shift, scratch2, scratch1});
RestoreRegisters(c, {scratch1, scratch2, shift});
}
}
@ -355,138 +258,10 @@ static void GenerateBLSR(const ZydisDecodedOperand* operands, Xbyak::CodeGenerat
RestoreRegisters(c, {scratch});
}
static __attribute__((sysv_abi)) void PerformVCVTPH2PS(float* out, const half_float::half* in,
const u32 count) {
for (u32 i = 0; i < count; i++) {
out[i] = half_float::half_cast<float>(in[i]);
}
}
static void GenerateVCVTPH2PS(const ZydisDecodedOperand* operands, Xbyak::CodeGenerator& c) {
const auto dst = ZydisToXbyakRegisterOperand(operands[0]);
const auto src = ZydisToXbyakOperand(operands[1]);
const auto float_count = dst.getBit() / 32;
const auto byte_count = float_count * 4;
SaveContext(c);
// Allocate stack space for outputs and load into first parameter.
c.sub(rsp, byte_count);
c.mov(rdi, rsp);
if (src->isXMM()) {
// Allocate stack space for inputs and load into second parameter.
c.sub(rsp, byte_count);
c.mov(rsi, rsp);
// Move input to the allocated space.
c.movdqu(ptr[rsp], *reinterpret_cast<Xbyak::Xmm*>(src.get()));
} else {
c.lea(rsi, src->getAddress());
}
// Load float count into third parameter.
c.mov(rdx, float_count);
c.mov(rax, reinterpret_cast<u64>(PerformVCVTPH2PS));
c.call(rax);
if (src->isXMM()) {
// Clean up after inputs space.
c.add(rsp, byte_count);
}
// Load outputs into destination register and clean up space.
if (dst.isYMM()) {
c.vmovdqu(*reinterpret_cast<const Xbyak::Ymm*>(&dst), ptr[rsp]);
} else {
c.movdqu(*reinterpret_cast<const Xbyak::Xmm*>(&dst), ptr[rsp]);
}
c.add(rsp, byte_count);
RestoreContext(c, dst);
}
using SingleToHalfFloatConverter = half_float::half (*)(float);
static const SingleToHalfFloatConverter SingleToHalfFloatConverters[4] = {
half_float::half_cast<half_float::half, std::round_to_nearest, float>,
half_float::half_cast<half_float::half, std::round_toward_neg_infinity, float>,
half_float::half_cast<half_float::half, std::round_toward_infinity, float>,
half_float::half_cast<half_float::half, std::round_toward_zero, float>,
};
static __attribute__((sysv_abi)) void PerformVCVTPS2PH(half_float::half* out, const float* in,
const u32 count, const u8 rounding_mode) {
const auto conversion_func = SingleToHalfFloatConverters[rounding_mode];
for (u32 i = 0; i < count; i++) {
out[i] = conversion_func(in[i]);
}
}
static void GenerateVCVTPS2PH(const ZydisDecodedOperand* operands, Xbyak::CodeGenerator& c) {
const auto dst = ZydisToXbyakOperand(operands[0]);
const auto src = ZydisToXbyakRegisterOperand(operands[1]);
const auto ctrl = ZydisToXbyakImmediateOperand(operands[2]);
const auto float_count = src.getBit() / 32;
const auto byte_count = float_count * 4;
SaveContext(c);
if (dst->isXMM()) {
// Allocate stack space for outputs and load into first parameter.
c.sub(rsp, byte_count);
c.mov(rdi, rsp);
} else {
c.lea(rdi, dst->getAddress());
}
// Allocate stack space for inputs and load into second parameter.
c.sub(rsp, byte_count);
c.mov(rsi, rsp);
// Move input to the allocated space.
if (src.isYMM()) {
c.vmovdqu(ptr[rsp], *reinterpret_cast<const Xbyak::Ymm*>(&src));
} else {
c.movdqu(ptr[rsp], *reinterpret_cast<const Xbyak::Xmm*>(&src));
}
// Load float count into third parameter.
c.mov(rdx, float_count);
// Load rounding mode into fourth parameter.
if (ctrl & 4) {
// Load from MXCSR.RC.
c.stmxcsr(ptr[rsp - 4]);
c.mov(rcx, ptr[rsp - 4]);
c.shr(rcx, 13);
c.and_(rcx, 3);
} else {
c.mov(rcx, ctrl & 3);
}
c.mov(rax, reinterpret_cast<u64>(PerformVCVTPS2PH));
c.call(rax);
// Clean up after inputs space.
c.add(rsp, byte_count);
if (dst->isXMM()) {
// Load outputs into destination register and clean up space.
c.movdqu(*reinterpret_cast<Xbyak::Xmm*>(dst.get()), ptr[rsp]);
c.add(rsp, byte_count);
}
RestoreContext(c, *dst);
}
static bool FilterRosetta2Only(const ZydisDecodedOperand*) {
bool FilterRosetta2Only(const ZydisDecodedOperand*) {
int ret = 0;
size_t size = sizeof(ret);
if (sysctlbyname("sysctl.proc_translated", &ret, &size, nullptr, 0) != 0) {
if (sysctlbyname("sysctl.proc_translated", &ret, &size, NULL, 0) != 0) {
return false;
}
return ret;
@ -564,16 +339,12 @@ static const std::unordered_map<ZydisMnemonic, PatchInfo> Patches = {
#endif
#ifdef __APPLE__
// Patches for instruction sets not supported by Rosetta 2.
// BMI1
// BMI1 instructions that are not supported by Rosetta 2 on Apple Silicon.
{ZYDIS_MNEMONIC_ANDN, {FilterRosetta2Only, GenerateANDN, true}},
{ZYDIS_MNEMONIC_BEXTR, {FilterRosetta2Only, GenerateBEXTR, true}},
{ZYDIS_MNEMONIC_BLSI, {FilterRosetta2Only, GenerateBLSI, true}},
{ZYDIS_MNEMONIC_BLSMSK, {FilterRosetta2Only, GenerateBLSMSK, true}},
{ZYDIS_MNEMONIC_BLSR, {FilterRosetta2Only, GenerateBLSR, true}},
// F16C
{ZYDIS_MNEMONIC_VCVTPH2PS, {FilterRosetta2Only, GenerateVCVTPH2PS, true}},
{ZYDIS_MNEMONIC_VCVTPS2PH, {FilterRosetta2Only, GenerateVCVTPS2PH, true}},
#endif
};

View File

@ -9,12 +9,6 @@ class CodeGenerator;
namespace Core {
/// Initializes a stack for the current thread for use by patch implementations.
void InitializeThreadPatchStack();
/// Cleans up the patch stack for the current thread.
void CleanupThreadPatchStack();
/// Patches CPU instructions that cannot run as-is on the host.
void PatchInstructions(u64 segment_addr, u64 segment_size, Xbyak::CodeGenerator& c);

View File

@ -6,18 +6,18 @@
CryptoPP::RSA::PrivateKey Crypto::key_pkg_derived_key3_keyset_init() {
CryptoPP::InvertibleRSAFunction params;
params.SetPrime1(CryptoPP::Integer(PkgDerivedKey3Keyset::Prime1, 0x80));
params.SetPrime2(CryptoPP::Integer(PkgDerivedKey3Keyset::Prime2, 0x80));
params.SetPrime1(CryptoPP::Integer(pkg_derived_key3_keyset.Prime1, 0x80));
params.SetPrime2(CryptoPP::Integer(pkg_derived_key3_keyset.Prime2, 0x80));
params.SetPublicExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::PublicExponent, 4));
params.SetPrivateExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::PrivateExponent, 0x100));
params.SetPublicExponent(CryptoPP::Integer(pkg_derived_key3_keyset.PublicExponent, 4));
params.SetPrivateExponent(CryptoPP::Integer(pkg_derived_key3_keyset.PrivateExponent, 0x100));
params.SetModPrime1PrivateExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::Exponent1, 0x80));
params.SetModPrime2PrivateExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::Exponent2, 0x80));
params.SetModPrime1PrivateExponent(CryptoPP::Integer(pkg_derived_key3_keyset.Exponent1, 0x80));
params.SetModPrime2PrivateExponent(CryptoPP::Integer(pkg_derived_key3_keyset.Exponent2, 0x80));
params.SetModulus(CryptoPP::Integer(PkgDerivedKey3Keyset::Modulus, 0x100));
params.SetModulus(CryptoPP::Integer(pkg_derived_key3_keyset.Modulus, 0x100));
params.SetMultiplicativeInverseOfPrime2ModPrime1(
CryptoPP::Integer(PkgDerivedKey3Keyset::Coefficient, 0x80));
CryptoPP::Integer(pkg_derived_key3_keyset.Coefficient, 0x80));
CryptoPP::RSA::PrivateKey privateKey(params);
@ -26,18 +26,18 @@ CryptoPP::RSA::PrivateKey Crypto::key_pkg_derived_key3_keyset_init() {
CryptoPP::RSA::PrivateKey Crypto::FakeKeyset_keyset_init() {
CryptoPP::InvertibleRSAFunction params;
params.SetPrime1(CryptoPP::Integer(FakeKeyset::Prime1, 0x80));
params.SetPrime2(CryptoPP::Integer(FakeKeyset::Prime2, 0x80));
params.SetPrime1(CryptoPP::Integer(FakeKeyset_keyset.Prime1, 0x80));
params.SetPrime2(CryptoPP::Integer(FakeKeyset_keyset.Prime2, 0x80));
params.SetPublicExponent(CryptoPP::Integer(FakeKeyset::PublicExponent, 4));
params.SetPrivateExponent(CryptoPP::Integer(FakeKeyset::PrivateExponent, 0x100));
params.SetPublicExponent(CryptoPP::Integer(FakeKeyset_keyset.PublicExponent, 4));
params.SetPrivateExponent(CryptoPP::Integer(FakeKeyset_keyset.PrivateExponent, 0x100));
params.SetModPrime1PrivateExponent(CryptoPP::Integer(FakeKeyset::Exponent1, 0x80));
params.SetModPrime2PrivateExponent(CryptoPP::Integer(FakeKeyset::Exponent2, 0x80));
params.SetModPrime1PrivateExponent(CryptoPP::Integer(FakeKeyset_keyset.Exponent1, 0x80));
params.SetModPrime2PrivateExponent(CryptoPP::Integer(FakeKeyset_keyset.Exponent2, 0x80));
params.SetModulus(CryptoPP::Integer(FakeKeyset::Modulus, 0x100));
params.SetModulus(CryptoPP::Integer(FakeKeyset_keyset.Modulus, 0x100));
params.SetMultiplicativeInverseOfPrime2ModPrime1(
CryptoPP::Integer(FakeKeyset::Coefficient, 0x80));
CryptoPP::Integer(FakeKeyset_keyset.Coefficient, 0x80));
CryptoPP::RSA::PrivateKey privateKey(params);
@ -46,22 +46,25 @@ CryptoPP::RSA::PrivateKey Crypto::FakeKeyset_keyset_init() {
CryptoPP::RSA::PrivateKey Crypto::DebugRifKeyset_init() {
CryptoPP::InvertibleRSAFunction params;
params.SetPrime1(CryptoPP::Integer(DebugRifKeyset::Prime1, sizeof(DebugRifKeyset::Prime1)));
params.SetPrime2(CryptoPP::Integer(DebugRifKeyset::Prime2, sizeof(DebugRifKeyset::Prime2)));
params.SetPrime1(
CryptoPP::Integer(DebugRifKeyset_keyset.Prime1, sizeof(DebugRifKeyset_keyset.Prime1)));
params.SetPrime2(
CryptoPP::Integer(DebugRifKeyset_keyset.Prime2, sizeof(DebugRifKeyset_keyset.Prime2)));
params.SetPublicExponent(
CryptoPP::Integer(DebugRifKeyset::PublicExponent, sizeof(DebugRifKeyset::PublicExponent)));
params.SetPrivateExponent(CryptoPP::Integer(DebugRifKeyset::PrivateExponent,
sizeof(DebugRifKeyset::PrivateExponent)));
params.SetPublicExponent(CryptoPP::Integer(DebugRifKeyset_keyset.PrivateExponent,
sizeof(DebugRifKeyset_keyset.PrivateExponent)));
params.SetPrivateExponent(CryptoPP::Integer(DebugRifKeyset_keyset.PrivateExponent,
sizeof(DebugRifKeyset_keyset.PrivateExponent)));
params.SetModPrime1PrivateExponent(
CryptoPP::Integer(DebugRifKeyset::Exponent1, sizeof(DebugRifKeyset::Exponent1)));
params.SetModPrime2PrivateExponent(
CryptoPP::Integer(DebugRifKeyset::Exponent2, sizeof(DebugRifKeyset::Exponent2)));
params.SetModPrime1PrivateExponent(CryptoPP::Integer(DebugRifKeyset_keyset.Exponent1,
sizeof(DebugRifKeyset_keyset.Exponent1)));
params.SetModPrime2PrivateExponent(CryptoPP::Integer(DebugRifKeyset_keyset.Exponent2,
sizeof(DebugRifKeyset_keyset.Exponent2)));
params.SetModulus(CryptoPP::Integer(DebugRifKeyset::Modulus, sizeof(DebugRifKeyset::Modulus)));
params.SetMultiplicativeInverseOfPrime2ModPrime1(
CryptoPP::Integer(DebugRifKeyset::Coefficient, sizeof(DebugRifKeyset::Coefficient)));
params.SetModulus(
CryptoPP::Integer(DebugRifKeyset_keyset.Modulus, sizeof(DebugRifKeyset_keyset.Modulus)));
params.SetMultiplicativeInverseOfPrime2ModPrime1(CryptoPP::Integer(
DebugRifKeyset_keyset.Coefficient, sizeof(DebugRifKeyset_keyset.Coefficient)));
CryptoPP::RSA::PrivateKey privateKey(params);

View File

@ -17,6 +17,10 @@
class Crypto {
public:
PkgDerivedKey3Keyset pkg_derived_key3_keyset;
FakeKeyset FakeKeyset_keyset;
DebugRifKeyset DebugRifKeyset_keyset;
CryptoPP::RSA::PrivateKey key_pkg_derived_key3_keyset_init();
CryptoPP::RSA::PrivateKey FakeKeyset_keyset_init();
CryptoPP::RSA::PrivateKey DebugRifKeyset_init();

View File

@ -7,299 +7,384 @@
class FakeKeyset {
public:
// Constructor
static constexpr CryptoPP::byte Exponent1[] = {
0x6D, 0x48, 0xE0, 0x54, 0x40, 0x25, 0xC8, 0x41, 0x29, 0x52, 0x42, 0x27, 0xEB, 0xD2, 0xC7,
0xAB, 0x6B, 0x9C, 0x27, 0x0A, 0xB4, 0x1F, 0x94, 0x4E, 0xFA, 0x42, 0x1D, 0xB7, 0xBC, 0xB9,
0xAE, 0xBC, 0x04, 0x6F, 0x75, 0x8F, 0x10, 0x5F, 0x89, 0xAC, 0xAB, 0x9C, 0xD2, 0xFA, 0xE6,
0xA4, 0x13, 0x83, 0x68, 0xD4, 0x56, 0x38, 0xFE, 0xE5, 0x2B, 0x78, 0x44, 0x9C, 0x34, 0xE6,
0x5A, 0xA0, 0xBE, 0x05, 0x70, 0xAD, 0x15, 0xC3, 0x2D, 0x31, 0xAC, 0x97, 0x5D, 0x88, 0xFC,
0xC1, 0x62, 0x3D, 0xE2, 0xED, 0x11, 0xDB, 0xB6, 0x9E, 0xFC, 0x5A, 0x5A, 0x03, 0xF6, 0xCF,
0x08, 0xD4, 0x5D, 0x90, 0xC9, 0x2A, 0xB9, 0x9B, 0xCF, 0xC8, 0x1A, 0x65, 0xF3, 0x5B, 0xE8,
0x7F, 0xCF, 0xA5, 0xA6, 0x4C, 0x5C, 0x2A, 0x12, 0x0F, 0x92, 0xA5, 0xE3, 0xF0, 0x17, 0x1E,
0x9A, 0x97, 0x45, 0x86, 0xFD, 0xDB, 0x54, 0x25};
const CryptoPP::byte* Exponent1;
// exponent2 = d mod (q - 1)
static constexpr CryptoPP::byte Exponent2[] = {
0x2A, 0x51, 0xCE, 0x02, 0x44, 0x28, 0x50, 0xE8, 0x30, 0x20, 0x7C, 0x9C, 0x55, 0xBF, 0x60,
0x39, 0xBC, 0xD1, 0xF0, 0xE7, 0x68, 0xF8, 0x08, 0x5B, 0x61, 0x1F, 0xA7, 0xBF, 0xD0, 0xE8,
0x8B, 0xB5, 0xB1, 0xD5, 0xD9, 0x16, 0xAC, 0x75, 0x0C, 0x6D, 0xF2, 0xE0, 0xB5, 0x97, 0x75,
0xD2, 0x68, 0x16, 0x1F, 0x00, 0x7D, 0x8B, 0x17, 0xE8, 0x78, 0x48, 0x41, 0x71, 0x2B, 0x18,
0x96, 0x80, 0x11, 0xDB, 0x68, 0x39, 0x9C, 0xD6, 0xE0, 0x72, 0x42, 0x86, 0xF0, 0x1B, 0x16,
0x0D, 0x3E, 0x12, 0x94, 0x3D, 0x25, 0xA8, 0xA9, 0x30, 0x9E, 0x54, 0x5A, 0xD6, 0x36, 0x6C,
0xD6, 0x8C, 0x20, 0x62, 0x8F, 0xA1, 0x6B, 0x1F, 0x7C, 0x6D, 0xB2, 0xB1, 0xC1, 0x2E, 0xAD,
0x36, 0x02, 0x9C, 0x3A, 0xCA, 0x2F, 0x09, 0xD2, 0x45, 0x9E, 0xEB, 0xF2, 0xBC, 0x6C, 0xAA,
0x3B, 0x3E, 0x90, 0xBC, 0x38, 0x67, 0x35, 0x4D};
const CryptoPP::byte* Exponent2;
// e
static constexpr CryptoPP::byte PublicExponent[] = {0, 1, 0, 1};
const CryptoPP::byte* PublicExponent;
// (InverseQ)(q) = 1 mod p
static constexpr CryptoPP::byte Coefficient[] = {
0x0B, 0x67, 0x1C, 0x0D, 0x6C, 0x57, 0xD3, 0xE7, 0x05, 0x65, 0x94, 0x31, 0x56, 0x55, 0xFD,
0x28, 0x08, 0xFA, 0x05, 0x8A, 0xCC, 0x55, 0x39, 0x61, 0x97, 0x63, 0xA0, 0x16, 0x27, 0x3D,
0xED, 0xC1, 0x16, 0x40, 0x2A, 0x12, 0xEA, 0x6F, 0xD9, 0xD8, 0x58, 0x56, 0xA8, 0x56, 0x8B,
0x0D, 0x38, 0x5E, 0x1E, 0x80, 0x3B, 0x5F, 0x40, 0x80, 0x6F, 0x62, 0x4F, 0x28, 0xA2, 0x69,
0xF3, 0xD3, 0xF7, 0xFD, 0xB2, 0xC3, 0x52, 0x43, 0x20, 0x92, 0x9D, 0x97, 0x8D, 0xA0, 0x15,
0x07, 0x15, 0x6E, 0xA4, 0x0D, 0x56, 0xD3, 0x37, 0x1A, 0xC4, 0x9E, 0xDF, 0x02, 0x49, 0xB8,
0x0A, 0x84, 0x62, 0xF5, 0xFA, 0xB9, 0x3F, 0xA4, 0x09, 0x76, 0xCC, 0xAA, 0xB9, 0x9B, 0xA6,
0x4F, 0xC1, 0x6A, 0x64, 0xCE, 0xD8, 0x77, 0xAB, 0x4B, 0xF9, 0xA0, 0xAE, 0xDA, 0xF1, 0x67,
0x87, 0x7C, 0x98, 0x5C, 0x7E, 0xB8, 0x73, 0xF5};
const CryptoPP::byte* Coefficient;
// n = p * q
static constexpr CryptoPP::byte Modulus[] = {
0xC6, 0xCF, 0x71, 0xE7, 0xE5, 0x9A, 0xF0, 0xD1, 0x2A, 0x2C, 0x45, 0x8B, 0xF9, 0x2A, 0x0E,
0xC1, 0x43, 0x05, 0x8B, 0xC3, 0x71, 0x17, 0x80, 0x1D, 0xCD, 0x49, 0x7D, 0xDE, 0x35, 0x9D,
0x25, 0x9B, 0xA0, 0xD7, 0xA0, 0xF2, 0x7D, 0x6C, 0x08, 0x7E, 0xAA, 0x55, 0x02, 0x68, 0x2B,
0x23, 0xC6, 0x44, 0xB8, 0x44, 0x18, 0xEB, 0x56, 0xCF, 0x16, 0xA2, 0x48, 0x03, 0xC9, 0xE7,
0x4F, 0x87, 0xEB, 0x3D, 0x30, 0xC3, 0x15, 0x88, 0xBF, 0x20, 0xE7, 0x9D, 0xFF, 0x77, 0x0C,
0xDE, 0x1D, 0x24, 0x1E, 0x63, 0xA9, 0x4F, 0x8A, 0xBF, 0x5B, 0xBE, 0x60, 0x19, 0x68, 0x33,
0x3B, 0xFC, 0xED, 0x9F, 0x47, 0x4E, 0x5F, 0xF8, 0xEA, 0xCB, 0x3D, 0x00, 0xBD, 0x67, 0x01,
0xF9, 0x2C, 0x6D, 0xC6, 0xAC, 0x13, 0x64, 0xE7, 0x67, 0x14, 0xF3, 0xDC, 0x52, 0x69, 0x6A,
0xB9, 0x83, 0x2C, 0x42, 0x30, 0x13, 0x1B, 0xB2, 0xD8, 0xA5, 0x02, 0x0D, 0x79, 0xED, 0x96,
0xB1, 0x0D, 0xF8, 0xCC, 0x0C, 0xDF, 0x81, 0x95, 0x4F, 0x03, 0x58, 0x09, 0x57, 0x0E, 0x80,
0x69, 0x2E, 0xFE, 0xFF, 0x52, 0x77, 0xEA, 0x75, 0x28, 0xA8, 0xFB, 0xC9, 0xBE, 0xBF, 0x9F,
0xBB, 0xB7, 0x79, 0x8E, 0x18, 0x05, 0xE1, 0x80, 0xBD, 0x50, 0x34, 0x94, 0x81, 0xD3, 0x53,
0xC2, 0x69, 0xA2, 0xD2, 0x4C, 0xCF, 0x6C, 0xF4, 0x57, 0x2C, 0x10, 0x4A, 0x3F, 0xFB, 0x22,
0xFD, 0x8B, 0x97, 0xE2, 0xC9, 0x5B, 0xA6, 0x2B, 0xCD, 0xD6, 0x1B, 0x6B, 0xDB, 0x68, 0x7F,
0x4B, 0xC2, 0xA0, 0x50, 0x34, 0xC0, 0x05, 0xE5, 0x8D, 0xEF, 0x24, 0x67, 0xFF, 0x93, 0x40,
0xCF, 0x2D, 0x62, 0xA2, 0xA0, 0x50, 0xB1, 0xF1, 0x3A, 0xA8, 0x3D, 0xFD, 0x80, 0xD1, 0xF9,
0xB8, 0x05, 0x22, 0xAF, 0xC8, 0x35, 0x45, 0x90, 0x58, 0x8E, 0xE3, 0x3A, 0x7C, 0xBD, 0x3E,
0x27};
const CryptoPP::byte* Modulus;
// p
static constexpr CryptoPP::byte Prime1[] = {
0xFE, 0xF6, 0xBF, 0x1D, 0x69, 0xAB, 0x16, 0x25, 0x08, 0x47, 0x55, 0x6B, 0x86, 0xE4, 0x35,
0x88, 0x72, 0x2A, 0xB1, 0x3D, 0xF8, 0xB6, 0x44, 0xCA, 0xB3, 0xAB, 0x19, 0xD1, 0x04, 0x24,
0x28, 0x0A, 0x74, 0x55, 0xB8, 0x15, 0x45, 0x09, 0xCC, 0x13, 0x1C, 0xF2, 0xBA, 0x37, 0xA9,
0x03, 0x90, 0x8F, 0x02, 0x10, 0xFF, 0x25, 0x79, 0x86, 0xCC, 0x18, 0x50, 0x9A, 0x10, 0x5F,
0x5B, 0x4C, 0x1C, 0x4E, 0xB0, 0xA7, 0xE3, 0x59, 0xB1, 0x2D, 0xA0, 0xC6, 0xB0, 0x20, 0x2C,
0x21, 0x33, 0x12, 0xB3, 0xAF, 0x72, 0x34, 0x83, 0xCD, 0x52, 0x2F, 0xAF, 0x0F, 0x20, 0x5A,
0x1B, 0xC0, 0xE2, 0xA3, 0x76, 0x34, 0x0F, 0xD7, 0xFC, 0xC1, 0x41, 0xC9, 0xF9, 0x79, 0x40,
0x17, 0x42, 0x21, 0x3E, 0x9D, 0xFD, 0xC7, 0xC1, 0x50, 0xDE, 0x44, 0x5A, 0xC9, 0x31, 0x89,
0x6A, 0x78, 0x05, 0xBE, 0x65, 0xB4, 0xE8, 0x2D};
const CryptoPP::byte* Prime1;
// q
static constexpr CryptoPP::byte Prime2[] = {
0xC7, 0x9E, 0x47, 0x58, 0x00, 0x7D, 0x62, 0x82, 0xB0, 0xD2, 0x22, 0x81, 0xD4, 0xA8, 0x97,
0x1B, 0x79, 0x0C, 0x3A, 0xB0, 0xD7, 0xC9, 0x30, 0xE3, 0xC3, 0x53, 0x8E, 0x57, 0xEF, 0xF0,
0x9B, 0x9F, 0xB3, 0x90, 0x52, 0xC6, 0x94, 0x22, 0x36, 0xAA, 0xE6, 0x4A, 0x5F, 0x72, 0x1D,
0x70, 0xE8, 0x76, 0x58, 0xC8, 0xB2, 0x91, 0xCE, 0x9C, 0xC3, 0xE9, 0x09, 0x7F, 0x2E, 0x47,
0x97, 0xCC, 0x90, 0x39, 0x15, 0x35, 0x31, 0xDE, 0x1F, 0x0C, 0x8C, 0x0D, 0xC1, 0xC2, 0x92,
0xBE, 0x97, 0xBF, 0x2F, 0x91, 0xA1, 0x8C, 0x7D, 0x50, 0xA8, 0x21, 0x2F, 0xD7, 0xA2,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D5, 0x43, 0x82, 0x49, 0xDA, 0x6E, 0x7C, 0xA1, 0xC5, 0x8C, 0xA5, 0xB0, 0x09, 0xE0,
0xCE, 0x3D, 0xDF, 0xF4, 0x9D, 0x3C, 0x97, 0x15, 0xE2, 0x6A, 0xC7, 0x2B, 0x3C, 0x50, 0x93,
0x23, 0xDB, 0xBA, 0x4A, 0x22, 0x66, 0x44, 0xAC, 0x78, 0xBB, 0x0E, 0x1A, 0x27, 0x43, 0xB5,
0x71, 0x67, 0xAF, 0xF4, 0xAB, 0x48, 0x46, 0x93, 0x73, 0xD0, 0x42, 0xAB, 0x93, 0x63, 0xE5,
0x6C, 0x9A, 0xDE, 0x50, 0x24, 0xC0, 0x23, 0x7D, 0x99, 0x79, 0x3F, 0x22, 0x07, 0xE0, 0xC1,
0x48, 0x56, 0x1B, 0xDF, 0x83, 0x09, 0x12, 0xB4, 0x2D, 0x45, 0x6B, 0xC9, 0xC0, 0x68, 0x85,
0x99, 0x90, 0x79, 0x96, 0x1A, 0xD7, 0xF5, 0x4D, 0x1F, 0x37, 0x83, 0x40, 0x4A, 0xEC, 0x39,
0x37, 0xA6, 0x80, 0x92, 0x7D, 0xC5, 0x80, 0xC7, 0xD6, 0x6F, 0xFE, 0x8A, 0x79, 0x89, 0xC6,
0xB1};
const CryptoPP::byte* Prime2;
const CryptoPP::byte* PrivateExponent;
// Constructor
FakeKeyset() {
// Initialize PrivateExponent
PrivateExponent = new CryptoPP::byte[0x100]{
0x7F, 0x76, 0xCD, 0x0E, 0xE2, 0xD4, 0xDE, 0x05, 0x1C, 0xC6, 0xD9, 0xA8, 0x0E, 0x8D,
0xFA, 0x7B, 0xCA, 0x1E, 0xAA, 0x27, 0x1A, 0x40, 0xF8, 0xF1, 0x22, 0x87, 0x35, 0xDD,
0xDB, 0xFD, 0xEE, 0xF8, 0xC2, 0xBC, 0xBD, 0x01, 0xFB, 0x8B, 0xE2, 0x3E, 0x63, 0xB2,
0xB1, 0x22, 0x5C, 0x56, 0x49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, 0xD7, 0xF5, 0x4D, 0x1F, 0x37, 0x83, 0x40, 0x4A,
0xEC, 0x39, 0x37, 0xA6, 0x80, 0x92, 0x7D, 0xC5, 0x80, 0xC7, 0xD6, 0x6F, 0xFE, 0x8A,
0x79, 0x89, 0xC6, 0xB1};
// Initialize Exponent1
Exponent1 = new CryptoPP::byte[0x80]{
0x6D, 0x48, 0xE0, 0x54, 0x40, 0x25, 0xC8, 0x41, 0x29, 0x52, 0x42, 0x27, 0xEB,
0xD2, 0xC7, 0xAB, 0x6B, 0x9C, 0x27, 0x0A, 0xB4, 0x1F, 0x94, 0x4E, 0xFA, 0x42,
0x1D, 0xB7, 0xBC, 0xB9, 0xAE, 0xBC, 0x04, 0x6F, 0x75, 0x8F, 0x10, 0x5F, 0x89,
0xAC, 0xAB, 0x9C, 0xD2, 0xFA, 0xE6, 0xA4, 0x13, 0x83, 0x68, 0xD4, 0x56, 0x38,
0xFE, 0xE5, 0x2B, 0x78, 0x44, 0x9C, 0x34, 0xE6, 0x5A, 0xA0, 0xBE, 0x05, 0x70,
0xAD, 0x15, 0xC3, 0x2D, 0x31, 0xAC, 0x97, 0x5D, 0x88, 0xFC, 0xC1, 0x62, 0x3D,
0xE2, 0xED, 0x11, 0xDB, 0xB6, 0x9E, 0xFC, 0x5A, 0x5A, 0x03, 0xF6, 0xCF, 0x08,
0xD4, 0x5D, 0x90, 0xC9, 0x2A, 0xB9, 0x9B, 0xCF, 0xC8, 0x1A, 0x65, 0xF3, 0x5B,
0xE8, 0x7F, 0xCF, 0xA5, 0xA6, 0x4C, 0x5C, 0x2A, 0x12, 0x0F, 0x92, 0xA5, 0xE3,
0xF0, 0x17, 0x1E, 0x9A, 0x97, 0x45, 0x86, 0xFD, 0xDB, 0x54, 0x25
};
Exponent2 = new CryptoPP::byte[0x80]{
0x2A, 0x51, 0xCE, 0x02, 0x44, 0x28, 0x50, 0xE8, 0x30, 0x20, 0x7C, 0x9C, 0x55,
0xBF, 0x60, 0x39, 0xBC, 0xD1, 0xF0, 0xE7, 0x68, 0xF8, 0x08, 0x5B, 0x61, 0x1F,
0xA7, 0xBF, 0xD0, 0xE8, 0x8B, 0xB5, 0xB1, 0xD5, 0xD9, 0x16, 0xAC, 0x75, 0x0C,
0x6D, 0xF2, 0xE0, 0xB5, 0x97, 0x75, 0xD2, 0x68, 0x16, 0x1F, 0x00, 0x7D, 0x8B,
0x17, 0xE8, 0x78, 0x48, 0x41, 0x71, 0x2B, 0x18, 0x96, 0x80, 0x11, 0xDB, 0x68,
0x39, 0x9C, 0xD6, 0xE0, 0x72, 0x42, 0x86, 0xF0, 0x1B, 0x16, 0x0D, 0x3E, 0x12,
0x94, 0x3D, 0x25, 0xA8, 0xA9, 0x30, 0x9E, 0x54, 0x5A, 0xD6, 0x36, 0x6C, 0xD6,
0x8C, 0x20, 0x62, 0x8F, 0xA1, 0x6B, 0x1F, 0x7C, 0x6D, 0xB2, 0xB1, 0xC1, 0x2E,
0xAD, 0x36, 0x02, 0x9C, 0x3A, 0xCA, 0x2F, 0x09, 0xD2, 0x45, 0x9E, 0xEB, 0xF2,
0xBC, 0x6C, 0xAA, 0x3B, 0x3E, 0x90, 0xBC, 0x38, 0x67, 0x35, 0x4D};
PublicExponent = new CryptoPP::byte[4]{0, 1, 0, 1};
Coefficient = new CryptoPP::byte[0x80]{
0x0B, 0x67, 0x1C, 0x0D, 0x6C, 0x57, 0xD3, 0xE7, 0x05, 0x65, 0x94, 0x31, 0x56,
0x55, 0xFD, 0x28, 0x08, 0xFA, 0x05, 0x8A, 0xCC, 0x55, 0x39, 0x61, 0x97, 0x63,
0xA0, 0x16, 0x27, 0x3D, 0xED, 0xC1, 0x16, 0x40, 0x2A, 0x12, 0xEA, 0x6F, 0xD9,
0xD8, 0x58, 0x56, 0xA8, 0x56, 0x8B, 0x0D, 0x38, 0x5E, 0x1E, 0x80, 0x3B, 0x5F,
0x40, 0x80, 0x6F, 0x62, 0x4F, 0x28, 0xA2, 0x69, 0xF3, 0xD3, 0xF7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F, 0xD7, 0xA2, 0x9A, 0x7E,
0xB5, 0xA7, 0x2A, 0x90, 0x02, 0xD9, 0xF3, 0x3D, 0xD1, 0xEB, 0xB8, 0xE0, 0x5A,
0x79, 0x9E, 0x7D, 0x8D, 0xCA, 0x18, 0x6D, 0xBD, 0x9E, 0xA1, 0x80, 0x28, 0x6B,
0x2A, 0xFE, 0x51, 0x24, 0x9B, 0x6F, 0x4D, 0x84, 0x77, 0x80, 0x23};
};
};
class DebugRifKeyset {
public:
// Constructor
// std::uint8_t* PrivateExponent;
static constexpr CryptoPP::byte Exponent1[] = {
0xCD, 0x9A, 0x61, 0xB0, 0xB8, 0xD5, 0xB4, 0xE4, 0xE4, 0xF6, 0xAB, 0xF7, 0x27, 0xB7, 0x56,
0x59, 0x6B, 0xB9, 0x11, 0xE7, 0xF4, 0x83, 0xAF, 0xB9, 0x73, 0x99, 0x7F, 0x49, 0xA2, 0x9C,
0xF0, 0xB5, 0x6D, 0x37, 0x82, 0x14, 0x15, 0xF1, 0x04, 0x8A, 0xD4, 0x8E, 0xEB, 0x2E, 0x1F,
0xE2, 0x81, 0xA9, 0x62, 0x6E, 0xB1, 0x68, 0x75, 0x62, 0xF3, 0x0F, 0xFE, 0xD4, 0x91, 0x87,
0x98, 0x78, 0xBF, 0x26, 0xB5, 0x07, 0x58, 0xD0, 0xEE, 0x3F, 0x21, 0xE8, 0xC8, 0x0F, 0x5F,
0xFA, 0x1C, 0x64, 0x74, 0x49, 0x52, 0xEB, 0xE7, 0xEE, 0xDE, 0xBA, 0x23, 0x26, 0x4A, 0xF6,
0x9C, 0x1A, 0x09, 0x3F, 0xB9, 0x0B, 0x36, 0x26, 0x1A, 0xBE, 0xA9, 0x76, 0xE6, 0xF2, 0x69,
0xDE, 0xFF, 0xAF, 0xCC, 0x0C, 0x9A, 0x66, 0x03, 0x86, 0x0A, 0x1F, 0x49, 0xA4, 0x10, 0xB6,
0xBC, 0xC3, 0x7C, 0x88, 0xE8, 0xCE, 0x4B, 0xD9};
const CryptoPP::byte* Exponent1;
// exponent2 = d mod (q - 1)
static constexpr CryptoPP::byte Exponent2[] = {
0xB3, 0x73, 0xA3, 0x59, 0xE6, 0x97, 0xC0, 0xAB, 0x3B, 0x68, 0xFC, 0x39, 0xAC, 0xDB, 0x44,
0xB1, 0xB4, 0x9E, 0x35, 0x4D, 0xBE, 0xC5, 0x36, 0x69, 0x6C, 0x3D, 0xC5, 0xFC, 0xFE, 0x4B,
0x2F, 0xDC, 0x86, 0x80, 0x46, 0x96, 0x40, 0x1A, 0x0D, 0x6E, 0xFA, 0x8C, 0xE0, 0x47, 0x91,
0xAC, 0xAD, 0x95, 0x2B, 0x8E, 0x1F, 0xF2, 0x0A, 0x45, 0xF8, 0x29, 0x95, 0x70, 0xC6, 0x88,
0x5F, 0x71, 0x03, 0x99, 0x79, 0xBC, 0x84, 0x71, 0xBD, 0xE8, 0x84, 0x8C, 0x0E, 0xD4, 0x7B,
0x30, 0x74, 0x57, 0x1A, 0x95, 0xE7, 0x90, 0x19, 0x8D, 0xAD, 0x8B, 0x4C, 0x4E, 0xC3, 0xE7,
0x6B, 0x23, 0x86, 0x01, 0xEE, 0x9B, 0xE0, 0x2F, 0x15, 0xA2, 0x2C, 0x4C, 0x39, 0xD3, 0xDF,
0x9C, 0x39, 0x01, 0xF1, 0x8C, 0x44, 0x4A, 0x15, 0x44, 0xDC, 0x51, 0xF7, 0x22, 0xD7, 0x7F,
0x41, 0x7F, 0x68, 0xFA, 0xEE, 0x56, 0xE8, 0x05};
const CryptoPP::byte* Exponent2;
// e
static constexpr CryptoPP::byte PublicExponent[] = {0x00, 0x01, 0x00, 0x01};
const CryptoPP::byte* PublicExponent;
// (InverseQ)(q) = 1 mod p
static constexpr CryptoPP::byte Coefficient[] = {
0xC0, 0x32, 0x43, 0xD3, 0x8C, 0x3D, 0xB4, 0xD2, 0x48, 0x8C, 0x42, 0x41, 0x24, 0x94, 0x6C,
0x80, 0xC9, 0xC1, 0x79, 0x36, 0x7F, 0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x2E, 0xB5, 0x6B, 0x70, 0xA4, 0x42, 0x9F, 0x64,
0xC1};
const CryptoPP::byte* Modulus;
// p
static constexpr CryptoPP::byte Prime1[] = {
0xE5, 0x62, 0xE1, 0x7F, 0x9F, 0x86, 0x08, 0xE2, 0x61, 0xD3, 0xD0, 0x42, 0xE2, 0xC4, 0xB6,
0xA8, 0x51, 0x09, 0x19, 0x14, 0xA4, 0x3A, 0x11, 0x4C, 0x33, 0xA5, 0x9C, 0x01, 0x5E, 0x34,
0xB6, 0x3F, 0x02, 0x1A, 0xCA, 0x47, 0xF1, 0x4F, 0x3B, 0x35, 0x2A, 0x07, 0x20, 0xEC, 0xD8,
0xC1, 0x15, 0xD9, 0xCA, 0x03, 0x4F, 0xB8, 0xE8, 0x09, 0x73, 0x3F, 0x85, 0xB7, 0x41, 0xD5,
0x51, 0x3E, 0x7B, 0xE3, 0x53, 0x2B, 0x48, 0x8B, 0x8E, 0xCB, 0xBA, 0xF7, 0xE0, 0x60, 0xF5,
0x35, 0x0E, 0x6F, 0xB0, 0xD9, 0x2A, 0x99, 0xD0, 0xFF, 0x60, 0x14, 0xED, 0x40, 0xEA, 0xF8,
0xD7, 0x0B, 0xC3, 0x8D, 0x8C, 0xE8, 0x81, 0xB3, 0x75, 0x93, 0x15, 0xB3, 0x7D, 0xF6, 0x39,
0x60, 0x1A, 0x00, 0xE7, 0xC3, 0x27, 0xAD, 0xA4, 0x33, 0xD5, 0x3E, 0xA4, 0x35, 0x48, 0x6F,
0x22, 0xEF, 0x5D, 0xDD, 0x7D, 0x7B, 0x61, 0x05};
const CryptoPP::byte* Prime1;
// q
static constexpr CryptoPP::byte Prime2[] = {
0xD9, 0x6C, 0xC2, 0x0C, 0xF7, 0xAE, 0xD1, 0xF3, 0x3B, 0x3B, 0x49, 0x1E, 0x9F, 0x12, 0x9C,
0xA1, 0x78, 0x1F, 0x35, 0x1D, 0x98, 0x26, 0x13, 0x71, 0xF9, 0x09, 0xFD, 0xF0, 0xAD, 0x38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xBA, 0xE0, 0x2F, 0x3F, 0xB1, 0xEF, 0xA5, 0x05, 0x5D, 0x28,
0x8B, 0xAB, 0xB5, 0xD0, 0x23, 0x2F, 0x8A, 0xCF, 0x48, 0x7C, 0xAA, 0xBB, 0xC8, 0x5B, 0x36,
0x27, 0xC5, 0x16, 0xA4, 0xB6, 0x61, 0xAC, 0x0C, 0x28, 0x47, 0x79, 0x3F, 0x38, 0xAE, 0x5E,
0x25, 0xC6, 0xAF, 0x35, 0xAE, 0xBC, 0xB0, 0xF3, 0xBC, 0xBD, 0xFD, 0xA4, 0x87, 0x0D, 0x14,
0x3D, 0x90, 0xE4, 0xDE, 0x5D, 0x1D, 0x46, 0x81, 0xF1, 0x28, 0x6D, 0x2F, 0x2C, 0x5E, 0x97,
0x2D, 0x89, 0x2A, 0x51, 0x72, 0x3C, 0x20, 0x02, 0x59, 0xB1, 0x98, 0x93, 0x05, 0x1E, 0x3F,
0xA1, 0x8A, 0x69, 0x30, 0x0E, 0x70, 0x84, 0x8B, 0xAE, 0x97, 0xA1, 0x08, 0x95, 0x63, 0x4C,
0xC7, 0xE8, 0x5D, 0x59, 0xCA, 0x78, 0x2A, 0x23, 0x87, 0xAC, 0x6F, 0x04, 0x33, 0xB1, 0x61,
0xB9, 0xF0, 0x95, 0xDA, 0x33, 0xCC, 0xE0, 0x4C, 0x82, 0x68, 0x82, 0x14, 0x51, 0xBE, 0x49,
0x1C, 0x58, 0xA2, 0x8B, 0x05, 0x4E, 0x98, 0x37, 0xEB, 0x94, 0x0B, 0x01, 0x22, 0xDC, 0xB3,
0x19, 0xCA, 0x77, 0xA6, 0x6E, 0x97, 0xFF, 0x8A, 0x53, 0x5A, 0xC5, 0x24, 0xE4, 0xAF, 0x6E,
0xA8, 0x2B, 0x53, 0xA4, 0xBE, 0x96, 0xA5, 0x7B, 0xCE, 0x22, 0x56, 0xA3, 0xF1, 0xCF, 0x14,
0xA5};
const CryptoPP::byte* Prime2;
const CryptoPP::byte* PrivateExponent;
// Constructor
DebugRifKeyset() {
// Initialize PrivateExponent
PrivateExponent = new CryptoPP::byte[0x100]{
0x01, 0x61, 0xAD, 0xD8, 0x9C, 0x06, 0x89, 0xD0, 0x60, 0xC8, 0x41, 0xF0, 0xB3, 0x83,
0x01, 0x5D, 0xE3, 0xA2, 0x6B, 0xA2, 0xBA, 0x9A, 0x0A, 0x58, 0xCD, 0x1A, 0xA0, 0x97,
0x64, 0xEC, 0xD0, 0x31, 0x1F, 0xCA, 0x36, 0x0E, 0x69, 0xDD, 0x40, 0xF7, 0x4E, 0xC0,
0xC6, 0xA3, 0x73, 0xF0, 0x69, 0x84, 0xB2, 0xF4, 0x4B, 0x29, 0x14, 0x2A, 0x6D, 0xB8,
0x23, 0xD8, 0x1B, 0x61, 0xD4, 0x9E, 0x87, 0xB3, 0xBB, 0xA9, 0xC4, 0x85, 0x4A, 0xF8,
0x03, 0x4A, 0xBF, 0xFE, 0xF9, 0xFE, 0x8B, 0xDD, 0x54, 0x83, 0xBA, 0xE0, 0x2F, 0x3F,
0xB1, 0xEF, 0xA5, 0x05, 0x5D, 0x28, 0x8B, 0xAB, 0xB5, 0xD0, 0x23, 0x2F, 0x8A, 0xCF,
0x48, 0x7C, 0xAA, 0xBB, 0xC8, 0x5B, 0x36, 0x27, 0xC5, 0x16, 0xA4, 0xB6, 0x61, 0xAC,
0x0C, 0x28, 0x47, 0x79, 0x3F, 0x38, 0xAE, 0x5E, 0x25, 0xC6, 0xAF, 0x35, 0xAE, 0xBC,
0xB0, 0xF3, 0xBC, 0xBD, 0xFD, 0xA4, 0x87, 0x0D, 0x14, 0x3D, 0x90, 0xE4, 0xDE, 0x5D,
0x1D, 0x46, 0x81, 0xF1, 0x28, 0x6D, 0x2F, 0x2C, 0x5E, 0x97, 0x2D, 0x89, 0x2A, 0x51,
0x72, 0x3C, 0x20, 0x02, 0x59, 0xB1, 0x98, 0x93, 0x05, 0x1E, 0x3F, 0xA1, 0x8A, 0x69,
0x30, 0x0E, 0x70, 0x84,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x09, 0x3F, 0xB9, 0x0B, 0x36, 0x26, 0x1A, 0xBE, 0xA9, 0x76, 0xE6, 0xF2,
0x69, 0xDE, 0xFF, 0xAF, 0xCC, 0x0C, 0x9A, 0x66, 0x03, 0x86, 0x0A, 0x1F, 0x49,
0xA4, 0x10, 0xB6, 0xBC, 0xC3, 0x7C, 0x88, 0xE8, 0xCE, 0x4B, 0xD9
};
Exponent2 = new CryptoPP::byte[0x80]{
0xB3, 0x73, 0xA3, 0x59, 0xE6, 0x97, 0xC0, 0xAB, 0x3B, 0x68, 0xFC, 0x39, 0xAC,
0xDB, 0x44, 0xB1, 0xB4, 0x9E, 0x35, 0x4D, 0xBE, 0xC5, 0x36, 0x69, 0x6C, 0x3D,
0xC5, 0xFC, 0xFE, 0x4B, 0x2F, 0xDC, 0x86, 0x80, 0x46, 0x96, 0x40, 0x1A, 0x0D,
0x6E, 0xFA, 0x8C, 0xE0, 0x47, 0x91, 0xAC, 0xAD, 0x95, 0x2B, 0x8E, 0x1F, 0xF2,
0x0A, 0x45, 0xF8, 0x29, 0x95, 0x70, 0xC6, 0x88, 0x5F, 0x71, 0x03, 0x99, 0x79,
0xBC, 0x84, 0x71, 0xBD, 0xE8, 0x84, 0x8C, 0x0E, 0xD4, 0x7B, 0x30, 0x74, 0x57,
0x1A, 0x95, 0xE7, 0x90, 0x19, 0x8D, 0xAD, 0x8B, 0x4C, 0x4E, 0xC3, 0xE7, 0x6B,
0x23, 0x86, 0x01, 0xEE, 0x9B, 0xE0, 0x2F, 0x15, 0xA2, 0x2C, 0x4C, 0x39, 0xD3,
0xDF, 0x9C, 0x39, 0x01, 0xF1, 0x8C, 0x44, 0x4A, 0x15, 0x44, 0xDC, 0x51, 0xF7,
0x22, 0xD7, 0x7F, 0x41, 0x7F, 0x68, 0xFA, 0xEE, 0x56, 0xE8, 0x05};
PublicExponent = new CryptoPP::byte[4]{0x00, 0x01, 0x00, 0x01};
Coefficient = new CryptoPP::byte[0x80]{
0xC0, 0x32, 0x43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0x71, 0xF9, 0x09,
0xFD, 0xF0, 0xAD, 0x38, 0x55, 0xB7, 0xEE, 0x61, 0x04, 0x72, 0x51, 0x87, 0x2E,
0x05, 0x84, 0xB1, 0x1D, 0x0C, 0x0D, 0xDB, 0xD4, 0x25, 0x3E, 0x26, 0xED, 0xEA,
0xB8, 0xF7, 0x49, 0xFE, 0xA2, 0x94, 0xE6, 0xF2, 0x08, 0x92, 0xA7, 0x85, 0xF5,
0x30, 0xB9, 0x84, 0x22, 0xBF, 0xCA, 0xF0, 0x5F, 0xCB, 0x31, 0x20, 0x34, 0x49,
0x16, 0x76, 0x34, 0xCC, 0x7A, 0xCB, 0x96, 0xFE, 0x78, 0x7A, 0x41, 0xFE, 0x9A,
0xA2, 0x23, 0xF7, 0x68, 0x80, 0xD6, 0xCE, 0x4A, 0x78, 0xA5, 0xB7, 0x05, 0x77,
0x81, 0x1F, 0xDE, 0x5E, 0xA8, 0x6E, 0x3E, 0x87, 0xEC, 0x44, 0xD2, 0x69, 0xC6,
0x54, 0x91, 0x6B, 0x5E, 0x13, 0x8A, 0x03, 0x87, 0x05, 0x31, 0x8D};
};
};
class PkgDerivedKey3Keyset {
public:
// PkgDerivedKey3Keyset();
//~PkgDerivedKey3Keyset();
// Constructor
// std::uint8_t* PrivateExponent;
static constexpr CryptoPP::byte Exponent1[] = {
0x52, 0xCC, 0x2D, 0xA0, 0x9C, 0x9E, 0x75, 0xE7, 0x28, 0xEE, 0x3D, 0xDE, 0xE3, 0x45, 0xD1,
0x4F, 0x94, 0x1C, 0xCC, 0xC8, 0x87, 0x29, 0x45, 0x3B, 0x8D, 0x6E, 0xAB, 0x6E, 0x2A, 0xA7,
0xC7, 0x15, 0x43, 0xA3, 0x04, 0x8F, 0x90, 0x5F, 0xEB, 0xF3, 0x38, 0x4A, 0x77, 0xFA, 0x36,
0xB7, 0x15, 0x76, 0xB6, 0x01, 0x1A, 0x8E, 0x25, 0x87, 0x82, 0xF1, 0x55, 0xD8, 0xC6, 0x43,
0x2A, 0xC0, 0xE5, 0x98, 0xC9, 0x32, 0xD1, 0x94, 0x6F, 0xD9, 0x01, 0xBA, 0x06, 0x81, 0xE0,
0x6D, 0x88, 0xF2, 0x24, 0x2A, 0x25, 0x01, 0x64, 0x5C, 0xBF, 0xF2, 0xD9, 0x99, 0x67, 0x3E,
0xF6, 0x72, 0xEE, 0xE4, 0xE2, 0x33, 0x5C, 0xF8, 0x00, 0x40, 0xE3, 0x2A, 0x9A, 0xF4, 0x3D,
0x22, 0x86, 0x44, 0x3C, 0xFB, 0x0A, 0xA5, 0x7C, 0x3F, 0xCC, 0xF5, 0xF1, 0x16, 0xC4, 0xAC,
0x88, 0xB4, 0xDE, 0x62, 0x94, 0x92, 0x6A, 0x13};
const CryptoPP::byte* Exponent1;
// exponent2 = d mod (q - 1)
static constexpr CryptoPP::byte Exponent2[] = {
0x7C, 0x9D, 0xAD, 0x39, 0xE0, 0xD5, 0x60, 0x14, 0x94, 0x48, 0x19, 0x7F, 0x88, 0x95, 0xD5,
0x8B, 0x80, 0xAD, 0x85, 0x8A, 0x4B, 0x77, 0x37, 0x85, 0xD0, 0x77, 0xBB, 0xBF, 0x89, 0x71,
0x4A, 0x72, 0xCB, 0x72, 0x68, 0x38, 0xEC, 0x02, 0xC6, 0x7D, 0xC6, 0x44, 0x06, 0x33, 0x51,
0x1C, 0xC0, 0xFF, 0x95, 0x8F, 0x0D, 0x75, 0xDC, 0x25, 0xBB, 0x0B, 0x73, 0x91, 0xA9, 0x6D,
0x42, 0xD8, 0x03, 0xB7, 0x68, 0xD4, 0x1E, 0x75, 0x62, 0xA3, 0x70, 0x35, 0x79, 0x78, 0x00,
0xC8, 0xF5, 0xEF, 0x15, 0xB9, 0xFC, 0x4E, 0x47, 0x5A, 0xC8, 0x70, 0x70, 0x5B, 0x52, 0x98,
0xC0, 0xC2, 0x58, 0x4A, 0x70, 0x96, 0xCC, 0xB8, 0x10, 0xE1, 0x2F, 0x78, 0x8B, 0x2B, 0xA1,
0x7F, 0xF9, 0xAC, 0xDE, 0xF0, 0xBB, 0x2B, 0xE2, 0x66, 0xE3, 0x22, 0x92, 0x31, 0x21, 0x57,
0x92, 0xC4, 0xB8, 0xF2, 0x3E, 0x76, 0x20, 0x37};
const CryptoPP::byte* Exponent2;
// e
static constexpr CryptoPP::byte PublicExponent[] = {0, 1, 0, 1};
const CryptoPP::byte* PublicExponent;
// (InverseQ)(q) = 1 mod p
static constexpr CryptoPP::byte Coefficient[] = {
0x45, 0x97, 0x55, 0xD4, 0x22, 0x08, 0x5E, 0xF3, 0x5C, 0xB4, 0x05, 0x7A, 0xFD, 0xAA, 0x42,
0x42, 0xAD, 0x9A, 0x8C, 0xA0, 0x6C, 0xBB, 0x1D, 0x68, 0x54, 0x54, 0x6E, 0x3E, 0x32, 0xE3,
0x53, 0x73, 0x76, 0xF1, 0x3E, 0x01, 0xEA, 0xD3, 0xCF, 0xEB, 0xEB, 0x23, 0x3E, 0xC0, 0xBE,
0xCE, 0xEC, 0x2C, 0x89, 0x5F, 0xA8, 0x27, 0x3A, 0x4C, 0xB7, 0xE6, 0x74, 0xBC, 0x45, 0x4C,
0x26, 0xC8, 0x25, 0xFF, 0x34, 0x63, 0x25, 0x37, 0xE1, 0x48, 0x10, 0xC1, 0x93, 0xA6, 0xAF,
0xEB, 0xBA, 0xE3, 0xA2, 0xF1, 0x3D, 0xEF, 0x63, 0xD8, 0xF4, 0xFD, 0xD3, 0xEE, 0xE2, 0x5D,
0xE9, 0x33, 0xCC, 0xAD, 0xBA, 0x75, 0x5C, 0x85, 0xAF, 0xCE, 0xA9, 0x3D, 0xD1, 0xA2, 0x17,
0xF3, 0xF6, 0x98, 0xB3, 0x50, 0x8E, 0x5E, 0xF6, 0xEB, 0x02, 0x8E, 0xA1, 0x62, 0xA7, 0xD6,
0x2C, 0xEC, 0x91, 0xFF, 0x15, 0x40, 0xD2, 0xE3};
const CryptoPP::byte* Coefficient;
// n = p * q
static constexpr CryptoPP::byte Modulus[] = {
0xd2, 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, 0x5f, 0x54, 0xa1, 0xf6, 0x7e, 0xe5, 0xe0, 0x5f,
0x61, 0xc1, 0x20, 0xb4, 0xb9, 0xb4, 0x33, 0x08, 0x70, 0xe4, 0xdf, 0x89, 0x56, 0xed, 0x01,
0x29, 0x46, 0x77, 0x5f, 0x8c, 0xb8, 0xa9, 0xf5, 0x1e, 0x2e, 0xb3, 0xb9, 0xbf, 0xe0, 0x09,
0xb7, 0x8d, 0x28, 0xd4, 0xa6, 0xc3, 0xb8, 0x1e, 0x1f, 0x07, 0xeb, 0xb4, 0x12, 0x0b, 0x95,
0xb8, 0x85, 0x30, 0xfd, 0xdc, 0x39, 0x13, 0xd0, 0x7c, 0xdc, 0x8f, 0xed, 0xf9, 0xc9, 0xa3,
0xc1};
const CryptoPP::byte* Modulus;
// p
static constexpr CryptoPP::byte Prime1[] = {
0xF9, 0x67, 0xAD, 0x99, 0x12, 0x31, 0x0C, 0x56, 0xA2, 0x2E, 0x16, 0x1C, 0x46, 0xB3, 0x4D,
0x5B, 0x43, 0xBE, 0x42, 0xA2, 0xF6, 0x86, 0x96, 0x80, 0x42, 0xC3, 0xC7, 0x3F, 0xC3, 0x42,
0xF5, 0x87, 0x49, 0x33, 0x9F, 0x07, 0x5D, 0x6E, 0x2C, 0x04, 0xFD, 0xE3, 0xE1, 0xB2, 0xAE,
0x0A, 0x0C, 0xF0, 0xC7, 0xA6, 0x1C, 0xA1, 0x63, 0x50, 0xC8, 0x09, 0x9C, 0x51, 0x24, 0x52,
0x6C, 0x5E, 0x5E, 0xBD, 0x1E, 0x27, 0x06, 0xBB, 0xBC, 0x9E, 0x94, 0xE1, 0x35, 0xD4, 0x6D,
0xB3, 0xCB, 0x3C, 0x68, 0xDD, 0x68, 0xB3, 0xFE, 0x6C, 0xCB, 0x8D, 0x82, 0x20, 0x76, 0x23,
0x63, 0xB7, 0xE9, 0x68, 0x10, 0x01, 0x4E, 0xDC, 0xBA, 0x27, 0x5D, 0x01, 0xC1, 0x2D, 0x80,
0x5E, 0x2B, 0xAF, 0x82, 0x6B, 0xD8, 0x84, 0xB6, 0x10, 0x52, 0x86, 0xA7, 0x89, 0x8E, 0xAE,
0x9A, 0xE2, 0x89, 0xC6, 0xF7, 0xD5, 0x87, 0xFB};
const CryptoPP::byte* Prime1;
// q
static constexpr CryptoPP::byte Prime2[] = {
0xD7, 0xA1, 0x0F, 0x9A, 0x8B, 0xF2, 0xC9, 0x11, 0x95, 0x32, 0x9A, 0x8C, 0xF0, 0xD9, 0x40,
0x47, 0xF5, 0x68, 0xA0, 0x0D, 0xBD, 0xC1, 0xFC, 0x43, 0x2F, 0x65, 0xF9, 0xC3, 0x61, 0x0F,
0x25, 0x77, 0x54, 0xAD, 0xD7, 0x58, 0xAC, 0x84, 0x40, 0x60, 0x8D, 0x3F, 0xF3, 0x65, 0x89,
0x75, 0xB5, 0xC6, 0x2C, 0x51, 0x1A, 0x2F, 0x1F, 0x22, 0xE4, 0x43, 0x11, 0x54, 0xBE, 0xC9,
0xB4, 0xC7, 0xB5, 0x1B, 0x05, 0x0B, 0xBC, 0x56, 0x9A, 0xCD, 0x4A, 0xD9, 0x73, 0x68, 0x5E,
0x5C, 0xFB, 0x92, 0xB7, 0x8B, 0x0D, 0xFF, 0xF5, 0x07, 0xCA, 0xB4, 0xC8, 0x9B, 0x96, 0x3C,
0x07, 0x9E, 0x3E, 0x6B, 0x2A, 0x11, 0xF2, 0x8A, 0xB1, 0x8A, 0xD7, 0x2E, 0x1B, 0xA5, 0x53,
0x24, 0x06, 0xED, 0x50, 0xB8, 0x90, 0x67, 0xB1, 0xE2, 0x41, 0xC6, 0x92, 0x01, 0xEE, 0x10,
0xF0, 0x61, 0xBB, 0xFB, 0xB2, 0x7D, 0x4A, 0x73};
static constexpr CryptoPP::byte PrivateExponent[] = {
0x32, 0xD9, 0x03, 0x90, 0x8F, 0xBD, 0xB0, 0x8F, 0x57, 0x2B, 0x28, 0x5E, 0x0B, 0x8D, 0xB3,
0xEA, 0x5C, 0xD1, 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0xA9, 0x8B, 0x06, 0xB4, 0xF0, 0x72, 0xF6, 0x77, 0xDF, 0x98, 0x64,
0xF1, 0xEC, 0xFE, 0x37, 0x2D, 0xBC, 0xAE, 0x8C, 0x08, 0x81, 0x1F, 0xC3, 0xC9, 0x89, 0x1A,
0xC7, 0x42, 0x82, 0x4B, 0x2E, 0xDC, 0x8E, 0x8D, 0x73, 0xCE, 0xB1, 0xCC, 0x01, 0xD9, 0x08,
0x70, 0x87, 0x3C, 0x44, 0x08, 0xEC, 0x49, 0x8F, 0x81, 0x5A, 0xE2, 0x40, 0xFF, 0x77, 0xFC,
0x0D};
const CryptoPP::byte* Prime2;
const CryptoPP::byte* PrivateExponent;
PkgDerivedKey3Keyset() {
Prime1 = new CryptoPP::byte[0x80]{
0xF9, 0x67, 0xAD, 0x99, 0x12, 0x31, 0x0C, 0x56, 0xA2, 0x2E, 0x16, 0x1C, 0x46,
0xB3, 0x4D, 0x5B, 0x43, 0xBE, 0x42, 0xA2, 0xF6, 0x86, 0x96, 0x80, 0x42, 0xC3,
0xC7, 0x3F, 0xC3, 0x42, 0xF5, 0x87, 0x49, 0x33, 0x9F, 0x07, 0x5D, 0x6E, 0x2C,
0x04, 0xFD, 0xE3, 0xE1, 0xB2, 0xAE, 0x0A, 0x0C, 0xF0, 0xC7, 0xA6, 0x1C, 0xA1,
0x63, 0x50, 0xC8, 0x09, 0x9C, 0x51, 0x24, 0x52, 0x6C, 0x5E, 0x5E, 0xBD, 0x1E,
0x27, 0x06, 0xBB, 0xBC, 0x9E, 0x94, 0xE1, 0x35, 0xD4, 0x6D, 0xB3, 0xCB, 0x3C,
0x68, 0xDD, 0x68, 0xB3, 0xFE, 0x6C, 0xCB, 0x8D, 0x82, 0x20, 0x76, 0x23, 0x63,
0xB7, 0xE9, 0x68, 0x10, 0x01, 0x4E, 0xDC, 0xBA, 0x27, 0x5D, 0x01, 0xC1, 0x2D,
0x80, 0x5E, 0x2B, 0xAF, 0x82, 0x6B, 0xD8, 0x84,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, 0x1f, 0x2d, 0x2f, 0x7e, 0xd9, 0x08, 0xba, 0x06, 0xb3,
0xbf, 0x2e, 0x20, 0x3f, 0x4e, 0x3f, 0xfe, 0x44, 0xff, 0xaa, 0x50, 0x43, 0x57, 0x91,
0x69, 0x94, 0x49, 0x15, 0x82, 0x82, 0xe4, 0x0f, 0x4c, 0x8d, 0x9d, 0x2c, 0xc9, 0x5b,
0x1d, 0x64, 0xbf, 0x88, 0x8b, 0xd4, 0xc5, 0x94, 0xe7, 0x65, 0x47, 0x84, 0x1e, 0xe5,
0x79, 0x10, 0xfb, 0x98, 0x93, 0x47, 0xb9, 0x7d, 0x85, 0x12, 0xa6, 0x40, 0x98, 0x2c,
0xf7, 0x92, 0xbc, 0x95, 0x19, 0x32, 0xed, 0xe8, 0x90, 0x56, 0x0d, 0x65, 0xc1, 0xaa,
0x78, 0xc6, 0x2e, 0x54, 0xfd, 0x5f, 0x54, 0xa1, 0xf6, 0x7e, 0xe5, 0xe0, 0x5f, 0x61,
0xc1, 0x20, 0xb4, 0xb9, 0xb4, 0x33, 0x08, 0x70, 0xe4, 0xdf, 0x89, 0x56, 0xed, 0x01,
0x29, 0x46, 0x77, 0x5f, 0x8c, 0xb8, 0xa9, 0xf5, 0x1e, 0x2e, 0xb3, 0xb9, 0xbf, 0xe0,
0x09, 0xb7, 0x8d, 0x28, 0xd4, 0xa6, 0xc3, 0xb8, 0x1e, 0x1f, 0x07, 0xeb, 0xb4, 0x12,
0x0b, 0x95, 0xb8, 0x85, 0x30, 0xfd, 0xdc, 0x39, 0x13, 0xd0, 0x7c, 0xdc, 0x8f, 0xed,
0xf9, 0xc9, 0xa3, 0xc1};
PublicExponent = new CryptoPP::byte[4]{0, 1, 0, 1};
};
};

View File

@ -67,19 +67,15 @@ bool PKG::Open(const std::filesystem::path& filepath) {
file.Seek(0x47); // skip first 7 characters of content_id
file.Read(pkgTitleID);
file.Seek(0);
pkg.resize(pkgheader.pkg_promote_size);
file.Read(pkg);
u32 offset = pkgheader.pkg_table_entry_offset;
u32 n_files = pkgheader.pkg_table_entry_count;
file.Seek(offset);
for (int i = 0; i < n_files; i++) {
PKGEntry entry{};
file.Read(entry.id);
file.Read(entry.filename_offset);
file.Read(entry.flags1);
file.Read(entry.flags2);
file.Read(entry.offset);
file.Read(entry.size);
file.Seek(8, Common::FS::SeekOrigin::CurrentPosition);
PKGEntry entry;
std::memcpy(&entry, &pkg[offset + i * 0x20], sizeof(entry));
// Try to figure out the name
const auto name = GetEntryNameByType(entry.id);
@ -117,6 +113,9 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
failreason = "Content size is bigger than pkg size";
return false;
}
file.Seek(0);
pkg.resize(pkgheader.pkg_promote_size);
file.Read(pkg);
u32 offset = pkgheader.pkg_table_entry_offset;
u32 n_files = pkgheader.pkg_table_entry_count;
@ -127,18 +126,9 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
std::array<std::array<u8, 256>, 7> key1;
std::array<u8, 256> imgkeydata;
file.Seek(offset);
for (int i = 0; i < n_files; i++) {
PKGEntry entry{};
file.Read(entry.id);
file.Read(entry.filename_offset);
file.Read(entry.flags1);
file.Read(entry.flags2);
file.Read(entry.offset);
file.Read(entry.size);
file.Seek(8, Common::FS::SeekOrigin::CurrentPosition);
auto currentPos = file.Tell();
PKGEntry entry;
std::memcpy(&entry, &pkg[offset + i * 0x20], sizeof(entry));
// Try to figure out the name
const auto name = GetEntryNameByType(entry.id);
@ -149,15 +139,8 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
// Just print with id
Common::FS::IOFile out(extract_path / "sce_sys" / std::to_string(entry.id),
Common::FS::FileAccessMode::Write);
file.Seek(entry.offset);
std::vector<u8> data;
data.resize(entry.size);
file.ReadRaw<u8>(data.data(), entry.size);
out.WriteRaw<u8>(data.data(), entry.size);
out.WriteRaw<u8>(pkg.data() + entry.offset, entry.size);
out.Close();
file.Seek(currentPos);
continue;
}
@ -195,25 +178,14 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
}
Common::FS::IOFile out(extract_path / "sce_sys" / name, Common::FS::FileAccessMode::Write);
file.Seek(entry.offset);
std::vector<u8> data;
data.resize(entry.size);
file.ReadRaw<u8>(data.data(), entry.size);
out.WriteRaw<u8>(data.data(), entry.size);
out.WriteRaw<u8>(pkg.data() + entry.offset, entry.size);
out.Close();
// Decrypt Np stuff and overwrite.
if (entry.id == 0x400 || entry.id == 0x401 || entry.id == 0x402 ||
entry.id == 0x403) { // somehow 0x401 is not decrypting
decNp.resize(entry.size);
file.Seek(entry.offset);
std::vector<u8> data;
data.resize(entry.size);
file.ReadRaw<u8>(data.data(), entry.size);
std::span<u8> cipherNp(data.data(), entry.size);
std::span<u8> cipherNp(pkg.data() + entry.offset, entry.size);
std::array<u8, 64> concatenated_ivkey_dk3_;
std::memcpy(concatenated_ivkey_dk3_.data(), &entry, sizeof(entry));
std::memcpy(concatenated_ivkey_dk3_.data() + sizeof(entry), dk3_.data(), sizeof(dk3_));
@ -225,8 +197,6 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
out.Write(decNp);
out.Close();
}
file.Seek(currentPos);
}
// Extract trophy files
@ -244,9 +214,6 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
PKG::crypto.PfsGenCryptoKey(ekpfsKey, seed, dataKey, tweakKey);
const u32 length = pkgheader.pfs_cache_size * 0x2; // Seems to be ok.
int num_blocks = 0;
std::vector<u8> pfsc(length);
if (length != 0) {
// Read encrypted pfs_image
std::vector<u8> pfs_encrypted(length);
file.Seek(pkgheader.pfs_image_offset);
@ -258,18 +225,18 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
// Retrieve PFSC from decrypted pfs_image.
pfsc_offset = GetPFSCOffset(pfs_decrypted);
std::vector<u8> pfsc(length);
std::memcpy(pfsc.data(), pfs_decrypted.data() + pfsc_offset, length - pfsc_offset);
PFSCHdr pfsChdr;
std::memcpy(&pfsChdr, pfsc.data(), sizeof(pfsChdr));
num_blocks = (int)(pfsChdr.data_length / pfsChdr.block_sz2);
const int num_blocks = (int)(pfsChdr.data_length / pfsChdr.block_sz2);
sectorMap.resize(num_blocks + 1); // 8 bytes, need extra 1 to get the last offset.
for (int i = 0; i < num_blocks + 1; i++) {
std::memcpy(&sectorMap[i], pfsc.data() + pfsChdr.block_offsets + i * 8, 8);
}
}
u32 ent_size = 0;
u32 ndinode = 0;
@ -312,8 +279,8 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
}
}
// let's deal with the root/uroot entries here.
// Sometimes it's more than 2 entries (Tomb Raider Remastered)
// let's deal with the root/uroot enteries here.
// Sometimes it's more than 2 enteries (Tomb Raider Remastered)
const std::string_view flat_path_table(&decompressedData[0x10], 15);
if (flat_path_table == "flat_path_table") {
uroot_reached = true;
@ -329,15 +296,7 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
} else {
// Set the the folder according to the current inode.
// Can be 2 or more (rarely)
auto parent_path = extract_path.parent_path();
auto title_id = GetTitleID();
if (parent_path.filename() != title_id) {
extractPaths[ndinode_counter] = parent_path / title_id;
} else {
// DLCs path has different structure
extractPaths[ndinode_counter] = extract_path;
}
extractPaths[ndinode_counter] = extract_path.parent_path() / GetTitleID();
uroot_reached = false;
break;
}
@ -391,7 +350,7 @@ bool PKG::Extract(const std::filesystem::path& filepath, const std::filesystem::
return true;
}
void PKG::ExtractFiles(const int index) {
void PKG::ExtractFiles(const int& index) {
int inode_number = fsTable[index].inode;
int inode_type = fsTable[index].type;
std::string inode_name = fsTable[index].name;

View File

@ -104,7 +104,7 @@ public:
~PKG();
bool Open(const std::filesystem::path& filepath);
void ExtractFiles(const int index);
void ExtractFiles(const int& index);
bool Extract(const std::filesystem::path& filepath, const std::filesystem::path& extract,
std::string& failreason);
@ -149,6 +149,7 @@ public:
private:
Crypto crypto;
TRP trp;
std::vector<u8> pkg;
u64 pkgSize = 0;
char pkgTitleID[9];
PKGHeader pkgheader;

View File

@ -1,75 +1,16 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/io_file.h"
#include "playgo_chunk.h"
bool PlaygoFile::Open(const std::filesystem::path& filepath) {
bool PlaygoChunk::Open(const std::filesystem::path& filepath) {
Common::FS::IOFile file(filepath, Common::FS::FileAccessMode::Read);
if (file.IsOpen()) {
if (!file.IsOpen()) {
return false;
}
file.Read(playgoHeader);
if (LoadChunks(file)) {
return true;
}
}
return false;
}
bool PlaygoFile::LoadChunks(const Common::FS::IOFile& file) {
if (file.IsOpen()) {
if (playgoHeader.magic == PLAYGO_MAGIC) {
bool ret = true;
std::string chunk_attrs_data, chunk_mchunks_data, chunk_labels_data, mchunk_attrs_data;
ret = ret && load_chunk_data(file, playgoHeader.chunk_attrs, chunk_attrs_data);
ret = ret && load_chunk_data(file, playgoHeader.chunk_mchunks, chunk_mchunks_data);
ret = ret && load_chunk_data(file, playgoHeader.chunk_labels, chunk_labels_data);
ret = ret && load_chunk_data(file, playgoHeader.mchunk_attrs, mchunk_attrs_data);
if (ret) {
chunks.resize(playgoHeader.chunk_count);
auto chunk_attrs =
reinterpret_cast<playgo_chunk_attr_entry_t*>(&chunk_attrs_data[0]);
auto chunk_mchunks = reinterpret_cast<u16*>(&chunk_mchunks_data[0]);
auto chunk_labels = reinterpret_cast<char*>(&chunk_labels_data[0]);
auto mchunk_attrs =
reinterpret_cast<playgo_mchunk_attr_entry_t*>(&mchunk_attrs_data[0]);
for (u16 i = 0; i < playgoHeader.chunk_count; i++) {
chunks[i].req_locus = chunk_attrs[i].req_locus;
chunks[i].language_mask = chunk_attrs[i].language_mask;
chunks[i].label_name = std::string(chunk_labels + chunk_attrs[i].label_offset);
u64 total_size = 0;
u16 mchunk_count = chunk_attrs[i].mchunk_count;
if (mchunk_count != 0) {
auto mchunks = reinterpret_cast<u16*>(
((u8*)chunk_mchunks + chunk_attrs[i].mchunks_offset));
for (u16 j = 0; j < mchunk_count; j++) {
u16 mchunk_id = mchunks[j];
total_size += mchunk_attrs[mchunk_id].size.size;
}
}
chunks[i].total_size = total_size;
}
}
return ret;
}
}
return false;
}
bool PlaygoFile::load_chunk_data(const Common::FS::IOFile& file, const chunk_t chunk,
std::string& data) {
if (file.IsOpen()) {
if (file.Seek(chunk.offset)) {
data.resize(chunk.length);
if (data.size() == chunk.length) {
file.ReadRaw<char>(&data[0], chunk.length);
return true;
}
}
}
return false;
}

View File

@ -3,129 +3,29 @@
#pragma once
#include <filesystem>
#include <mutex>
#include <vector>
#include "common/io_file.h"
#include "core/libraries/playgo/playgo_types.h"
constexpr u32 PLAYGO_MAGIC = 0x6F676C70;
struct chunk_t {
u32 offset;
u32 length;
} __attribute__((packed));
#include "common/types.h"
struct PlaygoHeader {
u32 magic;
u16 version_major;
u16 version_minor;
u16 image_count; // [0;1]
u16 chunk_count; // [0;1000]
u16 mchunk_count; // [0;8000]
u16 scenario_count; // [0;32]
u32 file_size;
u16 default_scenario_id;
u16 attrib;
u32 sdk_version;
u16 disc_count; // [0;2] (if equals to 0 then disc count = 1)
u16 layer_bmp;
u8 reserved[32];
char content_id[128];
chunk_t chunk_attrs; // [0;32000]
chunk_t chunk_mchunks;
chunk_t chunk_labels; // [0;16000]
chunk_t mchunk_attrs; // [0;12800]
chunk_t scenario_attrs; // [0;1024]
chunk_t scenario_chunks;
chunk_t scenario_labels;
chunk_t inner_mchunk_attrs; // [0;12800]
} __attribute__((packed));
struct playgo_scenario_attr_entry_t {
u8 _type;
u8 _unk[19];
u16 initial_chunk_count;
u16 image_count;
u16 chunk_count;
u32 chunks_offset; //<-scenario_chunks
u32 label_offset; //<-scenario_labels
} __attribute__((packed));
struct image_disc_layer_no_t {
u8 layer_no : 2;
u8 disc_no : 2;
u8 image_no : 4;
} __attribute__((packed));
struct playgo_chunk_attr_entry_t {
u8 flag;
image_disc_layer_no_t image_disc_layer_no;
u8 req_locus;
u8 unk[11];
u16 mchunk_count;
u64 language_mask;
u32 mchunks_offset; //<-chunk_mchunks
u32 label_offset; //<-chunk_labels
} __attribute__((packed));
struct playgo_chunk_loc_t {
u64 offset : 48;
u64 _align1 : 8;
u64 image_no : 4;
u64 _align2 : 4;
} __attribute__((packed));
struct playgo_chunk_size_t {
u64 size : 48;
u64 _align : 16;
} __attribute__((packed));
struct playgo_mchunk_attr_entry_t {
playgo_chunk_loc_t loc;
playgo_chunk_size_t size;
} __attribute__((packed));
struct PlaygoChunk {
u64 req_locus;
u64 language_mask;
u64 total_size;
std::string label_name;
u16 scenario_count;
// TODO fill the rest
};
class PlaygoFile {
class PlaygoChunk {
public:
bool initialized;
OrbisPlayGoHandle handle;
OrbisPlayGoChunkId id;
OrbisPlayGoLocus locus;
OrbisPlayGoInstallSpeed speed;
s64 speed_tick;
OrbisPlayGoEta eta;
OrbisPlayGoLanguageMask langMask;
std::vector<PlaygoChunk> chunks;
public:
PlaygoFile()
: initialized(false), handle(0), id(0), locus(0), speed(ORBIS_PLAYGO_INSTALL_SPEED_TRICKLE),
speed_tick(0), eta(0), langMask(0), playgoHeader{0} {}
~PlaygoFile() = default;
PlaygoChunk() = default;
~PlaygoChunk() = default;
bool Open(const std::filesystem::path& filepath);
bool LoadChunks(const Common::FS::IOFile& file);
PlaygoHeader& GetPlaygoHeader() {
PlaygoHeader GetPlaygoHeader() {
return playgoHeader;
}
std::mutex& GetSpeedMutex() {
return speed_mutex;
}
private:
bool load_chunk_data(const Common::FS::IOFile& file, const chunk_t chunk, std::string& data);
private:
PlaygoHeader playgoHeader;
std::mutex speed_mutex;
};

View File

@ -9,7 +9,7 @@ PSF::PSF() = default;
PSF::~PSF() = default;
bool PSF::open(const std::string& filepath, const std::vector<u8>& psfBuffer) {
bool PSF::open(const std::string& filepath, std::vector<u8> psfBuffer) {
if (!psfBuffer.empty()) {
psf.resize(psfBuffer.size());
psf = psfBuffer;

View File

@ -35,7 +35,7 @@ public:
PSF();
~PSF();
bool open(const std::string& filepath, const std::vector<u8>& psfBuffer);
bool open(const std::string& filepath, std::vector<u8> psfBuffer);
std::string GetString(const std::string& key);
u32 GetInteger(const std::string& key);

View File

@ -6,7 +6,7 @@
TRP::TRP() = default;
TRP::~TRP() = default;
void TRP::GetNPcommID(const std::filesystem::path& trophyPath, int index) {
void TRP::GetNPcommID(std::filesystem::path trophyPath, int index) {
std::filesystem::path trpPath = trophyPath / "sce_sys/npbind.dat";
Common::FS::IOFile npbindFile(trpPath, Common::FS::FileAccessMode::Read);
if (!npbindFile.IsOpen()) {
@ -27,7 +27,7 @@ static void removePadding(std::vector<u8>& vec) {
}
}
bool TRP::Extract(const std::filesystem::path& trophyPath) {
bool TRP::Extract(std::filesystem::path trophyPath) {
std::string title = trophyPath.filename().string();
std::filesystem::path gameSysDir = trophyPath / "sce_sys/trophy/";
if (!std::filesystem::exists(gameSysDir)) {

View File

@ -33,8 +33,8 @@ class TRP {
public:
TRP();
~TRP();
bool Extract(const std::filesystem::path& trophyPath);
void GetNPcommID(const std::filesystem::path& trophyPath, int index);
bool Extract(std::filesystem::path trophyPath);
void GetNPcommID(std::filesystem::path trophyPath, int index);
private:
Crypto crypto;

View File

@ -25,9 +25,9 @@ void MntPoints::UnmountAll() {
m_mnt_pairs.clear();
}
std::filesystem::path MntPoints::GetHostPath(std::string_view guest_directory) {
std::filesystem::path MntPoints::GetHostPath(const std::string& guest_directory) {
// Evil games like Turok2 pass double slashes e.g /app0//game.kpf
std::string corrected_path(guest_directory);
auto corrected_path = guest_directory;
size_t pos = corrected_path.find("//");
while (pos != std::string::npos) {
corrected_path.replace(pos, 2, "/");
@ -48,13 +48,12 @@ std::filesystem::path MntPoints::GetHostPath(std::string_view guest_directory) {
pos = mount->mount.size() + 1;
const auto rel_path = std::string_view(corrected_path).substr(pos);
const auto host_path = mount->host_path / rel_path;
if (!NeedsCaseInsensitiveSearch) {
if (!NeedsCaseInsensiveSearch) {
return host_path;
}
// If the path does not exist attempt to verify this.
// Retrieve parent path until we find one that exists.
std::scoped_lock lk{m_mutex};
path_parts.clear();
auto current_path = host_path;
while (!std::filesystem::exists(current_path)) {

View File

@ -14,9 +14,9 @@ namespace Core::FileSys {
class MntPoints {
#ifdef _WIN64
static constexpr bool NeedsCaseInsensitiveSearch = false;
static constexpr bool NeedsCaseInsensiveSearch = false;
#else
static constexpr bool NeedsCaseInsensitiveSearch = true;
static constexpr bool NeedsCaseInsensiveSearch = true;
#endif
public:
struct MntPair {
@ -31,7 +31,7 @@ public:
void Unmount(const std::filesystem::path& host_folder, const std::string& guest_folder);
void UnmountAll();
std::filesystem::path GetHostPath(std::string_view guest_directory);
std::filesystem::path GetHostPath(const std::string& guest_directory);
const MntPair* GetMount(const std::string& guest_path) {
const auto it = std::ranges::find_if(

View File

@ -1,10 +1,9 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "ajm.h"
#include "ajm_error.h"
// Generated By moduleGenerator
#include "common/logging/log.h"
#include "core/libraries/ajm/ajm.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"

View File

@ -1,28 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
constexpr int ORBIS_AJM_ERROR_UNKNOWN = 0x80930001;
constexpr int ORBIS_AJM_ERROR_INVALID_CONTEXT = 0x80930002;
constexpr int ORBIS_AJM_ERROR_INVALID_INSTANCE = 0x80930003;
constexpr int ORBIS_AJM_ERROR_INVALID_BATCH = 0x80930004;
constexpr int ORBIS_AJM_ERROR_INVALID_PARAMETER = 0x80930005;
constexpr int ORBIS_AJM_ERROR_OUT_OF_MEMORY = 0x80930006;
constexpr int ORBIS_AJM_ERROR_OUT_OF_RESOURCES = 0x80930007;
constexpr int ORBIS_AJM_ERROR_CODEC_NOT_SUPPORTED = 0x80930008;
constexpr int ORBIS_AJM_ERROR_CODEC_ALREADY_REGISTERED = 0x80930009;
constexpr int ORBIS_AJM_ERROR_CODEC_NOT_REGISTERED = 0x8093000A;
constexpr int ORBIS_AJM_ERROR_WRONG_REVISION_FLAG = 0x8093000B;
constexpr int ORBIS_AJM_ERROR_FLAG_NOT_SUPPORTED = 0x8093000C;
constexpr int ORBIS_AJM_ERROR_BUSY = 0x8093000D;
constexpr int ORBIS_AJM_ERROR_BAD_PRIORITY = 0x8093000E;
constexpr int ORBIS_AJM_ERROR_IN_PROGRESS = 0x8093000F;
constexpr int ORBIS_AJM_ERROR_RETRY = 0x80930010;
constexpr int ORBIS_AJM_ERROR_MALFORMED_BATCH = 0x80930011;
constexpr int ORBIS_AJM_ERROR_JOB_CREATION = 0x80930012;
constexpr int ORBIS_AJM_ERROR_INVALID_OPCODE = 0x80930013;
constexpr int ORBIS_AJM_ERROR_PRIORITY_VIOLATION = 0x80930014;
constexpr int ORBIS_AJM_ERROR_BUFFER_TOO_BIG = 0x80930015;
constexpr int ORBIS_AJM_ERROR_INVALID_ADDRESS = 0x80930016;
constexpr int ORBIS_AJM_ERROR_CANCELLED = 0x80930017;

View File

@ -1,38 +1,20 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Generated By moduleGenerator
#include <cmath>
#include <common/path_util.h>
#include <common/singleton.h>
#include <core/file_format/psf.h>
#include <core/file_sys/fs.h>
#include "app_content.h"
#include "common/io_file.h"
#include "common/logging/log.h"
#include "common/path_util.h"
#include "common/singleton.h"
#include "common/string_util.h"
#include "core/file_format/psf.h"
#include "core/file_sys/fs.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"
namespace Libraries::AppContent {
int32_t addcont_count = 0;
struct AddContInfo {
char entitlementLabel[ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE];
OrbisAppContentAddcontDownloadStatus status;
OrbisAppContentGetEntitlementKey key;
};
std::array<AddContInfo, ORBIS_APP_CONTENT_INFO_LIST_MAX_SIZE> addcont_info = {{
{"0000000000000000",
ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00}},
}};
std::string title_id;
int PS4_SYSV_ABI _Z5dummyv() {
LOG_ERROR(Lib_AppContent, "(STUBBED) called");
return ORBIS_OK;
@ -53,31 +35,9 @@ int PS4_SYSV_ABI sceAppContentAddcontEnqueueDownloadSp() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAppContentAddcontMount(u32 service_label,
const OrbisNpUnifiedEntitlementLabel* entitlement_label,
OrbisAppContentMountPoint* mount_point) {
LOG_INFO(Lib_AppContent, "called");
const auto& mount_dir = Common::FS::GetUserPath(Common::FS::PathType::AddonsDir) / title_id /
entitlement_label->data;
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
for (int i = 0; i < addcont_count; i++) {
if (strncmp(entitlement_label->data, addcont_info[i].entitlementLabel,
ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE - 1) != 0) {
continue;
}
if (addcont_info[i].status != ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED) {
return ORBIS_APP_CONTENT_ERROR_NOT_FOUND;
}
snprintf(mount_point->data, ORBIS_APP_CONTENT_MOUNTPOINT_DATA_MAXSIZE, "/addcont%d", i);
mnt->Mount(mount_dir, mount_point->data);
int PS4_SYSV_ABI sceAppContentAddcontMount() {
LOG_ERROR(Lib_AppContent, "(STUBBED) called");
return ORBIS_OK;
}
return ORBIS_APP_CONTENT_ERROR_NOT_FOUND;
}
int PS4_SYSV_ABI sceAppContentAddcontShrink() {
@ -164,80 +124,22 @@ int PS4_SYSV_ABI sceAppContentGetAddcontDownloadProgress() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAppContentGetAddcontInfo(u32 service_label,
const OrbisNpUnifiedEntitlementLabel* entitlementLabel,
OrbisAppContentAddcontInfo* info) {
LOG_INFO(Lib_AppContent, "called");
if (entitlementLabel == nullptr || info == nullptr) {
return ORBIS_APP_CONTENT_ERROR_PARAMETER;
}
for (auto i = 0; i < addcont_count; i++) {
if (strncmp(entitlementLabel->data, addcont_info[i].entitlementLabel,
ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE - 1) != 0) {
continue;
}
LOG_INFO(Lib_AppContent, "found DLC {}", entitlementLabel->data);
strncpy(info->entitlement_label.data, addcont_info[i].entitlementLabel,
ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE);
info->status = addcont_info[i].status;
int PS4_SYSV_ABI sceAppContentGetAddcontInfo() {
LOG_ERROR(Lib_AppContent, "(STUBBED) called");
return ORBIS_OK;
}
return ORBIS_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT;
}
int PS4_SYSV_ABI sceAppContentGetAddcontInfoList(u32 service_label,
OrbisAppContentAddcontInfo* list, u32 list_num,
u32* hit_num) {
LOG_INFO(Lib_AppContent, "called");
if (list_num == 0 || list == nullptr) {
if (hit_num == nullptr) {
return ORBIS_APP_CONTENT_ERROR_PARAMETER;
}
*hit_num = addcont_count;
return ORBIS_OK;
}
int dlcs_to_list = addcont_count < list_num ? addcont_count : list_num;
for (int i = 0; i < dlcs_to_list; i++) {
strncpy(list[i].entitlement_label.data, addcont_info[i].entitlementLabel,
ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE);
list[i].status = addcont_info[i].status;
}
if (hit_num != nullptr) {
*hit_num = dlcs_to_list;
}
*hit_num = 0;
LOG_ERROR(Lib_AppContent, "(DUMMY) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAppContentGetEntitlementKey(
u32 service_label, const OrbisNpUnifiedEntitlementLabel* entitlement_label,
OrbisAppContentGetEntitlementKey* key) {
LOG_ERROR(Lib_AppContent, "called");
if (entitlement_label == nullptr || key == nullptr) {
return ORBIS_APP_CONTENT_ERROR_PARAMETER;
}
for (int i = 0; i < addcont_count; i++) {
if (strncmp(entitlement_label->data, addcont_info[i].entitlementLabel,
ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE - 1) != 0) {
continue;
}
memcpy(key->data, addcont_info[i].key.data, ORBIS_APP_CONTENT_ENTITLEMENT_KEY_SIZE);
int PS4_SYSV_ABI sceAppContentGetEntitlementKey() {
LOG_ERROR(Lib_AppContent, "(STUBBED) called");
return ORBIS_OK;
}
return ORBIS_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT;
}
int PS4_SYSV_ABI sceAppContentGetRegion() {
@ -248,25 +150,7 @@ int PS4_SYSV_ABI sceAppContentGetRegion() {
int PS4_SYSV_ABI sceAppContentInitialize(const OrbisAppContentInitParam* initParam,
OrbisAppContentBootParam* bootParam) {
LOG_ERROR(Lib_AppContent, "(DUMMY) called");
auto* param_sfo = Common::Singleton<PSF>::Instance();
const auto addons_dir = Common::FS::GetUserPath(Common::FS::PathType::AddonsDir);
title_id = param_sfo->GetString("TITLE_ID");
auto addon_path = addons_dir / title_id;
if (std::filesystem::exists(addon_path)) {
for (const auto& entry : std::filesystem::directory_iterator(addon_path)) {
if (entry.is_directory()) {
auto entitlement_label = entry.path().filename().string();
AddContInfo info{};
info.status = ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED;
strcpy(info.entitlementLabel, entitlement_label.c_str());
addcont_info[addcont_count++] = info;
}
}
}
bootParam->attr = 0; // always 0
return ORBIS_OK;
}
@ -337,12 +221,12 @@ int PS4_SYSV_ABI Func_C59A36FF8D7C59DA() {
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAppContentAddcontEnqueueDownloadByEntitlementId() {
int PS4_SYSV_ABI sceAppContentAddcontEnqueueDownloadByEntitlemetId() {
LOG_ERROR(Lib_AppContent, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAppContentAddcontMountByEntitlementId() {
int PS4_SYSV_ABI sceAppContentAddcontMountByEntitlemetId() {
LOG_ERROR(Lib_AppContent, "(STUBBED) called");
return ORBIS_OK;
}
@ -429,9 +313,9 @@ void RegisterlibSceAppContent(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("xZo2-418Wdo", "libSceAppContentBundle", 1, "libSceAppContent", 1, 1,
Func_C59A36FF8D7C59DA);
LIB_FUNCTION("kJmjt81mXKQ", "libSceAppContentIro", 1, "libSceAppContent", 1, 1,
sceAppContentAddcontEnqueueDownloadByEntitlementId);
sceAppContentAddcontEnqueueDownloadByEntitlemetId);
LIB_FUNCTION("efX3lrPwdKA", "libSceAppContentIro", 1, "libSceAppContent", 1, 1,
sceAppContentAddcontMountByEntitlementId);
sceAppContentAddcontMountByEntitlemetId);
LIB_FUNCTION("z9hgjLd1SGA", "libSceAppContentIro", 1, "libSceAppContent", 1, 1,
sceAppContentGetAddcontInfoByEntitlementId);
LIB_FUNCTION("3wUaDTGmjcQ", "libSceAppContentIro", 1, "libSceAppContent", 1, 1,

View File

@ -41,16 +41,6 @@ struct OrbisAppContentMountPoint {
constexpr int ORBIS_APP_CONTENT_TEMPORARY_DATA_OPTION_NONE = 0;
constexpr int ORBIS_APP_CONTENT_TEMPORARY_DATA_OPTION_FORMAT = (1 << 0);
constexpr int ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE = 17;
constexpr int ORBIS_APP_CONTENT_ENTITLEMENT_KEY_SIZE = 16;
constexpr int ORBIS_APP_CONTENT_INFO_LIST_MAX_SIZE = 2500;
enum OrbisAppContentAddcontDownloadStatus : u32 {
ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_NO_EXTRA_DATA = 0,
ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_NO_IN_QUEUE = 1,
ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_DOWNLOADING = 2,
ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_DOWNLOAD_SUSPENDED = 3,
ORBIS_APP_CONTENT_ADDCONT_DOWNLOAD_STATUS_INSTALLED = 4
};
struct OrbisNpUnifiedEntitlementLabel {
char data[ORBIS_NP_UNIFIED_ENTITLEMENT_LABEL_SIZE];
@ -64,17 +54,11 @@ struct OrbisAppContentAddcontInfo {
u32 status;
};
struct OrbisAppContentGetEntitlementKey {
char data[ORBIS_APP_CONTENT_ENTITLEMENT_KEY_SIZE];
};
int PS4_SYSV_ABI _Z5dummyv();
int PS4_SYSV_ABI sceAppContentAddcontDelete();
int PS4_SYSV_ABI sceAppContentAddcontEnqueueDownload();
int PS4_SYSV_ABI sceAppContentAddcontEnqueueDownloadSp();
int PS4_SYSV_ABI sceAppContentAddcontMount(u32 service_label,
const OrbisNpUnifiedEntitlementLabel* entitlement_label,
OrbisAppContentMountPoint* mount_point);
int PS4_SYSV_ABI sceAppContentAddcontMount();
int PS4_SYSV_ABI sceAppContentAddcontShrink();
int PS4_SYSV_ABI sceAppContentAddcontUnmount();
int PS4_SYSV_ABI sceAppContentAppParamGetInt(OrbisAppContentAppParamId paramId, s32* value);
@ -86,15 +70,11 @@ int PS4_SYSV_ABI sceAppContentDownload1Shrink();
int PS4_SYSV_ABI sceAppContentDownloadDataFormat();
int PS4_SYSV_ABI sceAppContentDownloadDataGetAvailableSpaceKb();
int PS4_SYSV_ABI sceAppContentGetAddcontDownloadProgress();
int PS4_SYSV_ABI sceAppContentGetAddcontInfo(u32 service_label,
const OrbisNpUnifiedEntitlementLabel* entitlementLabel,
OrbisAppContentAddcontInfo* info);
int PS4_SYSV_ABI sceAppContentGetAddcontInfo();
int PS4_SYSV_ABI sceAppContentGetAddcontInfoList(u32 service_label,
OrbisAppContentAddcontInfo* list, u32 list_num,
u32* hit_num);
int PS4_SYSV_ABI sceAppContentGetEntitlementKey(
u32 service_label, const OrbisNpUnifiedEntitlementLabel* entitlement_label,
OrbisAppContentGetEntitlementKey* key);
int PS4_SYSV_ABI sceAppContentGetEntitlementKey();
int PS4_SYSV_ABI sceAppContentGetRegion();
int PS4_SYSV_ABI sceAppContentInitialize(const OrbisAppContentInitParam* initParam,
OrbisAppContentBootParam* bootParam);
@ -112,8 +92,8 @@ int PS4_SYSV_ABI sceAppContentTemporaryDataMount2(OrbisAppContentTemporaryDataOp
int PS4_SYSV_ABI sceAppContentTemporaryDataUnmount();
int PS4_SYSV_ABI sceAppContentGetPftFlag();
int PS4_SYSV_ABI Func_C59A36FF8D7C59DA();
int PS4_SYSV_ABI sceAppContentAddcontEnqueueDownloadByEntitlementId();
int PS4_SYSV_ABI sceAppContentAddcontMountByEntitlementId();
int PS4_SYSV_ABI sceAppContentAddcontEnqueueDownloadByEntitlemetId();
int PS4_SYSV_ABI sceAppContentAddcontMountByEntitlemetId();
int PS4_SYSV_ABI sceAppContentGetAddcontInfoByEntitlementId();
int PS4_SYSV_ABI sceAppContentGetAddcontInfoListByIroTag();
int PS4_SYSV_ABI sceAppContentGetDownloadedStoreCountry();

View File

@ -2,10 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <memory>
#include <common/assert.h>
#include <magic_enum.hpp>
#include "audio_core/sdl_audio.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/libraries/audio/audioout.h"
#include "core/libraries/error_codes.h"
@ -176,6 +175,7 @@ int PS4_SYSV_ABI sceAudioOutGetLastOutputTime() {
}
int PS4_SYSV_ABI sceAudioOutGetPortState(s32 handle, OrbisAudioOutPortState* state) {
int type = 0;
int channels_num = 0;
@ -235,11 +235,11 @@ int PS4_SYSV_ABI sceAudioOutGetSystemState() {
}
int PS4_SYSV_ABI sceAudioOutInit() {
LOG_TRACE(Lib_AudioOut, "called");
if (audio != nullptr) {
return ORBIS_AUDIO_OUT_ERROR_ALREADY_INIT;
}
audio = std::make_unique<Audio::SDLAudio>();
LOG_INFO(Lib_AudioOut, "called");
return ORBIS_OK;
}

View File

@ -1,34 +1,21 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Generated By moduleGenerator
#include "avplayer.h"
#include "avplayer_impl.h"
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/thread_management.h"
#include "core/libraries/libs.h"
namespace Libraries::AvPlayer {
using namespace Kernel;
s32 PS4_SYSV_ABI sceAvPlayerAddSource(SceAvPlayerHandle handle, const char* filename) {
LOG_TRACE(Lib_AvPlayer, "filename = {}", filename);
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->AddSource(filename);
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
int PS4_SYSV_ABI sceAvPlayerAddSource() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerAddSourceEx(SceAvPlayerHandle handle, SceAvPlayerUriType uriType,
SceAvPlayerSourceDetails* sourceDetails) {
int PS4_SYSV_ABI sceAvPlayerAddSourceEx() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
return ORBIS_OK;
}
@ -37,247 +24,122 @@ int PS4_SYSV_ABI sceAvPlayerChangeStream() {
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerClose(SceAvPlayerHandle handle) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr) {
LOG_TRACE(Lib_AvPlayer, "returning ORBIS_AVPLAYER_ERROR_INVALID_PARAMS");
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
delete handle;
LOG_TRACE(Lib_AvPlayer, "returning ORBIS_OK");
return ORBIS_OK;
}
u64 PS4_SYSV_ABI sceAvPlayerCurrentTime(SceAvPlayerHandle handle) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->CurrentTime();
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
s32 PS4_SYSV_ABI sceAvPlayerDisableStream(SceAvPlayerHandle handle, u32 stream_id) {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerEnableStream(SceAvPlayerHandle handle, u32 stream_id) {
LOG_TRACE(Lib_AvPlayer, "stream_id = {}", stream_id);
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->EnableStream(stream_id);
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
bool PS4_SYSV_ABI sceAvPlayerGetAudioData(SceAvPlayerHandle handle, SceAvPlayerFrameInfo* p_info) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr || p_info == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->GetAudioData(*p_info);
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
s32 PS4_SYSV_ABI sceAvPlayerGetStreamInfo(SceAvPlayerHandle handle, u32 stream_id,
SceAvPlayerStreamInfo* p_info) {
LOG_TRACE(Lib_AvPlayer, "stream_id = {}", stream_id);
if (handle == nullptr || p_info == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->GetStreamInfo(stream_id, *p_info);
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
bool PS4_SYSV_ABI sceAvPlayerGetVideoData(SceAvPlayerHandle handle,
SceAvPlayerFrameInfo* video_info) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr || video_info == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->GetVideoData(*video_info);
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
bool PS4_SYSV_ABI sceAvPlayerGetVideoDataEx(SceAvPlayerHandle handle,
SceAvPlayerFrameInfoEx* video_info) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr || video_info == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->GetVideoData(*video_info);
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
SceAvPlayerHandle PS4_SYSV_ABI sceAvPlayerInit(SceAvPlayerInitData* data) {
LOG_TRACE(Lib_AvPlayer, "called");
if (data == nullptr) {
return nullptr;
}
if (data->memory_replacement.allocate == nullptr ||
data->memory_replacement.allocate_texture == nullptr ||
data->memory_replacement.deallocate == nullptr ||
data->memory_replacement.deallocate_texture == nullptr) {
LOG_ERROR(Lib_AvPlayer, "All allocators are required for AVPlayer Initialisation.");
return nullptr;
}
return new AvPlayer(*data);
}
s32 PS4_SYSV_ABI sceAvPlayerInitEx(const SceAvPlayerInitDataEx* p_data,
SceAvPlayerHandle* p_player) {
LOG_TRACE(Lib_AvPlayer, "called");
if (p_data == nullptr || p_player == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
if (p_data->memory_replacement.allocate == nullptr ||
p_data->memory_replacement.allocate_texture == nullptr ||
p_data->memory_replacement.deallocate == nullptr ||
p_data->memory_replacement.deallocate_texture == nullptr) {
LOG_ERROR(Lib_AvPlayer, "All allocators are required for AVPlayer Initialisation.");
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
SceAvPlayerInitData data = {};
data.memory_replacement = p_data->memory_replacement;
data.file_replacement = p_data->file_replacement;
data.event_replacement = p_data->event_replacement;
data.default_language = p_data->default_language;
data.num_output_video_framebuffers = p_data->num_output_video_framebuffers;
data.auto_start = p_data->auto_start;
*p_player = new AvPlayer(data);
return ORBIS_OK;
}
bool PS4_SYSV_ABI sceAvPlayerIsActive(SceAvPlayerHandle handle) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr) {
LOG_TRACE(Lib_AvPlayer, "returning ORBIS_AVPLAYER_ERROR_INVALID_PARAMS");
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->IsActive();
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
s32 PS4_SYSV_ABI sceAvPlayerJumpToTime(SceAvPlayerHandle handle, uint64_t time) {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called, time (msec) = {}", time);
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerPause(SceAvPlayerHandle handle) {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerPostInit(SceAvPlayerHandle handle, SceAvPlayerPostInitData* data) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr || data == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->PostInit(*data);
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
}
s32 PS4_SYSV_ABI sceAvPlayerPrintf(const char* format, ...) {
int PS4_SYSV_ABI sceAvPlayerClose() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerResume(SceAvPlayerHandle handle) {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerSetAvSyncMode(SceAvPlayerHandle handle,
SceAvPlayerAvSyncMode sync_mode) {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerSetLogCallback(SceAvPlayerLogCallback log_cb, void* user_data) {
int PS4_SYSV_ABI sceAvPlayerCurrentTime() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerSetLooping(SceAvPlayerHandle handle, bool loop_flag) {
LOG_TRACE(Lib_AvPlayer, "called, looping = {}", loop_flag);
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
if (!handle->SetLooping(loop_flag)) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerSetTrickSpeed(SceAvPlayerHandle handle, s32 trick_speed) {
int PS4_SYSV_ABI sceAvPlayerDisableStream() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerStart(SceAvPlayerHandle handle) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->Start();
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
int PS4_SYSV_ABI sceAvPlayerEnableStream() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerStop(SceAvPlayerHandle handle) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr) {
LOG_TRACE(Lib_AvPlayer, "returning ORBIS_AVPLAYER_ERROR_INVALID_PARAMS");
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->Stop();
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
int PS4_SYSV_ABI sceAvPlayerGetAudioData() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerStreamCount(SceAvPlayerHandle handle) {
LOG_TRACE(Lib_AvPlayer, "called");
if (handle == nullptr) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
const auto res = handle->GetStreamCount();
LOG_TRACE(Lib_AvPlayer, "returning {}", res);
return res;
int PS4_SYSV_ABI sceAvPlayerGetStreamInfo() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
s32 PS4_SYSV_ABI sceAvPlayerVprintf(const char* format, va_list args) {
int PS4_SYSV_ABI sceAvPlayerGetVideoData() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerGetVideoDataEx() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerInit() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerInitEx() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerIsActive() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerJumpToTime() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerPause() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerPostInit() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerPrintf() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerResume() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerSetAvSyncMode() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerSetLogCallback() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerSetLooping() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerSetTrickSpeed() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerStart() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerStop() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerStreamCount() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}
int PS4_SYSV_ABI sceAvPlayerVprintf() {
LOG_ERROR(Lib_AvPlayer, "(STUBBED) called");
return ORBIS_OK;
}

View File

@ -5,288 +5,39 @@
#include "common/types.h"
#include <stdarg.h> // va_list
#include <stddef.h> // size_t
namespace Core::Loader {
class SymbolsResolver;
}
namespace Libraries::AvPlayer {
class AvPlayer;
using SceAvPlayerHandle = AvPlayer*;
enum SceAvPlayerUriType { SCE_AVPLAYER_URI_TYPE_SOURCE = 0 };
struct SceAvPlayerUri {
const char* name;
u32 length;
};
enum SceAvPlayerSourceType {
SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN = 0,
SCE_AVPLAYER_SOURCE_TYPE_FILE_MP4 = 1,
SCE_AVPLAYER_SOURCE_TYPE_HLS = 8
};
struct SceAvPlayerSourceDetails {
SceAvPlayerUri uri;
u8 reserved1[64];
SceAvPlayerSourceType source_type;
u8 reserved2[44];
};
struct SceAvPlayerAudio {
u16 channel_count;
u8 reserved1[2];
u32 sample_rate;
u32 size;
u8 language_code[4];
};
struct SceAvPlayerVideo {
u32 width;
u32 height;
f32 aspect_ratio;
u8 language_code[4];
};
struct SceAvPlayerTextPosition {
u16 top;
u16 left;
u16 bottom;
u16 right;
};
struct SceAvPlayerTimedText {
u8 language_code[4];
u16 text_size;
u16 font_size;
SceAvPlayerTextPosition position;
};
union SceAvPlayerStreamDetails {
u8 reserved[16];
SceAvPlayerAudio audio;
SceAvPlayerVideo video;
SceAvPlayerTimedText subs;
};
struct SceAvPlayerFrameInfo {
u8* pData;
u8 reserved[4];
u64 timestamp;
SceAvPlayerStreamDetails details;
};
struct SceAvPlayerStreamInfo {
u32 type;
u8 reserved[4];
SceAvPlayerStreamDetails details;
u64 duration;
u64 start_time;
};
struct SceAvPlayerAudioEx {
u16 channel_count;
u8 reserved[2];
u32 sample_rate;
u32 size;
u8 language_code[4];
u8 reserved1[64];
};
struct SceAvPlayerVideoEx {
u32 width;
u32 height;
f32 aspect_ratio;
u8 language_code[4];
u32 framerate;
u32 crop_left_offset;
u32 crop_right_offset;
u32 crop_top_offset;
u32 crop_bottom_offset;
u32 pitch;
u8 luma_bit_depth;
u8 chroma_bit_depth;
bool video_full_range_flag;
u8 reserved1[37];
};
struct SceAvPlayerTimedTextEx {
u8 language_code[4];
u8 reserved[12];
u8 reserved1[64];
};
union SceAvPlayerStreamDetailsEx {
SceAvPlayerAudioEx audio;
SceAvPlayerVideoEx video;
SceAvPlayerTimedTextEx subs;
u8 reserved1[80];
};
struct SceAvPlayerFrameInfoEx {
void* pData;
u8 reserved[4];
u64 timestamp;
SceAvPlayerStreamDetailsEx details;
};
typedef void* PS4_SYSV_ABI (*SceAvPlayerAllocate)(void* p, u32 align, u32 size);
typedef void PS4_SYSV_ABI (*SceAvPlayerDeallocate)(void* p, void* mem);
typedef void* PS4_SYSV_ABI (*SceAvPlayerAllocateTexture)(void* p, u32 align, u32 size);
typedef void PS4_SYSV_ABI (*SceAvPlayerDeallocateTexture)(void* p, void* mem);
struct SceAvPlayerMemAllocator {
void* object_ptr;
SceAvPlayerAllocate allocate;
SceAvPlayerDeallocate deallocate;
SceAvPlayerAllocateTexture allocate_texture;
SceAvPlayerDeallocateTexture deallocate_texture;
};
typedef s32 PS4_SYSV_ABI (*SceAvPlayerOpenFile)(void* p, const char* name);
typedef s32 PS4_SYSV_ABI (*SceAvPlayerCloseFile)(void* p);
typedef s32 PS4_SYSV_ABI (*SceAvPlayerReadOffsetFile)(void* p, u8* buf, u64 pos, u32 len);
typedef u64 PS4_SYSV_ABI (*SceAvPlayerSizeFile)(void* p);
struct SceAvPlayerFileReplacement {
void* object_ptr;
SceAvPlayerOpenFile open;
SceAvPlayerCloseFile close;
SceAvPlayerReadOffsetFile readOffset;
SceAvPlayerSizeFile size;
};
typedef void PS4_SYSV_ABI (*SceAvPlayerEventCallback)(void* p, s32 event, s32 src_id, void* data);
struct SceAvPlayerEventReplacement {
void* object_ptr;
SceAvPlayerEventCallback event_callback;
};
enum SceAvPlayerDebuglevels {
SCE_AVPLAYER_DBG_NONE,
SCE_AVPLAYER_DBG_INFO,
SCE_AVPLAYER_DBG_WARNINGS,
SCE_AVPLAYER_DBG_ALL
};
struct SceAvPlayerInitData {
SceAvPlayerMemAllocator memory_replacement;
SceAvPlayerFileReplacement file_replacement;
SceAvPlayerEventReplacement event_replacement;
SceAvPlayerDebuglevels debug_level;
u32 base_priority;
s32 num_output_video_framebuffers;
bool auto_start;
u8 reserved[3];
const char* default_language;
};
struct SceAvPlayerInitDataEx {
size_t this_size;
SceAvPlayerMemAllocator memory_replacement;
SceAvPlayerFileReplacement file_replacement;
SceAvPlayerEventReplacement event_replacement;
const char* default_language;
SceAvPlayerDebuglevels debug_level;
u32 audio_decoder_priority;
u32 audio_decoder_affinity;
u32 video_decoder_priority;
u32 video_decoder_affinity;
u32 demuxer_priority;
u32 demuxer_affinity;
u32 controller_priority;
u32 controller_affinity;
u32 http_streaming_priority;
u32 http_streaming_affinity;
u32 file_streaming_priority;
u32 file_streaming_affinity;
s32 num_output_video_framebuffers;
bool auto_start;
u8 reserved[3];
};
enum SceAvPlayerStreamType {
SCE_AVPLAYER_VIDEO,
SCE_AVPLAYER_AUDIO,
SCE_AVPLAYER_TIMEDTEXT,
SCE_AVPLAYER_UNKNOWN
};
enum SceAvPlayerVideoDecoderType {
SCE_AVPLAYER_VIDEO_DECODER_TYPE_DEFAULT = 0,
SCE_AVPLAYER_VIDEO_DECODER_TYPE_RESERVED1,
SCE_AVPLAYER_VIDEO_DECODER_TYPE_SOFTWARE,
SCE_AVPLAYER_VIDEO_DECODER_TYPE_SOFTWARE2
};
enum SceAvPlayerAudioDecoderType {
SCE_AVPLAYER_AUDIO_DECODER_TYPE_DEFAULT = 0,
SCE_AVPLAYER_AUDIO_DECODER_TYPE_RESERVED1,
SCE_AVPLAYER_AUDIO_DECODER_TYPE_RESERVED2
};
struct SceAvPlayerDecoderInit {
union {
SceAvPlayerVideoDecoderType video_type;
SceAvPlayerAudioDecoderType audio_type;
u8 reserved[4];
} decoderType;
union {
struct {
s32 cpu_affinity_mask;
s32 cpu_thread_priority;
u8 decode_pipeline_depth;
u8 compute_pipe_id;
u8 compute_queue_id;
u8 enable_interlaced;
u8 reserved[16];
} avcSw2;
struct {
u8 audio_channel_order;
u8 reserved[27];
} aac;
u8 reserved[28];
} decoderParams;
};
struct SceAvPlayerHTTPCtx {
u32 http_context_id;
u32 ssl_context_id;
};
struct SceAvPlayerPostInitData {
u32 demux_video_buffer_size;
SceAvPlayerDecoderInit video_decoder_init;
SceAvPlayerDecoderInit audio_decoder_init;
SceAvPlayerHTTPCtx http_context;
u8 reserved[56];
};
enum SceAvPlayerAvSyncMode {
SCE_AVPLAYER_AV_SYNC_MODE_DEFAULT = 0,
SCE_AVPLAYER_AV_SYNC_MODE_NONE
};
typedef int PS4_SYSV_ABI (*SceAvPlayerLogCallback)(void* p, const char* format, va_list args);
enum SceAvPlayerEvents {
SCE_AVPLAYER_STATE_STOP = 0x01,
SCE_AVPLAYER_STATE_READY = 0x02,
SCE_AVPLAYER_STATE_PLAY = 0x03,
SCE_AVPLAYER_STATE_PAUSE = 0x04,
SCE_AVPLAYER_STATE_BUFFERING = 0x05,
SCE_AVPLAYER_TIMED_TEXT_DELIVERY = 0x10,
SCE_AVPLAYER_WARNING_ID = 0x20,
SCE_AVPLAYER_ENCRYPTION = 0x30,
SCE_AVPLAYER_DRM_ERROR = 0x40
};
int PS4_SYSV_ABI sceAvPlayerAddSource();
int PS4_SYSV_ABI sceAvPlayerAddSourceEx();
int PS4_SYSV_ABI sceAvPlayerChangeStream();
int PS4_SYSV_ABI sceAvPlayerClose();
int PS4_SYSV_ABI sceAvPlayerCurrentTime();
int PS4_SYSV_ABI sceAvPlayerDisableStream();
int PS4_SYSV_ABI sceAvPlayerEnableStream();
int PS4_SYSV_ABI sceAvPlayerGetAudioData();
int PS4_SYSV_ABI sceAvPlayerGetStreamInfo();
int PS4_SYSV_ABI sceAvPlayerGetVideoData();
int PS4_SYSV_ABI sceAvPlayerGetVideoDataEx();
int PS4_SYSV_ABI sceAvPlayerInit();
int PS4_SYSV_ABI sceAvPlayerInitEx();
int PS4_SYSV_ABI sceAvPlayerIsActive();
int PS4_SYSV_ABI sceAvPlayerJumpToTime();
int PS4_SYSV_ABI sceAvPlayerPause();
int PS4_SYSV_ABI sceAvPlayerPostInit();
int PS4_SYSV_ABI sceAvPlayerPrintf();
int PS4_SYSV_ABI sceAvPlayerResume();
int PS4_SYSV_ABI sceAvPlayerSetAvSyncMode();
int PS4_SYSV_ABI sceAvPlayerSetLogCallback();
int PS4_SYSV_ABI sceAvPlayerSetLooping();
int PS4_SYSV_ABI sceAvPlayerSetTrickSpeed();
int PS4_SYSV_ABI sceAvPlayerStart();
int PS4_SYSV_ABI sceAvPlayerStop();
int PS4_SYSV_ABI sceAvPlayerStreamCount();
int PS4_SYSV_ABI sceAvPlayerVprintf();
void RegisterlibSceAvPlayer(Core::Loader::SymbolsResolver* sym);
} // namespace Libraries::AvPlayer

View File

@ -1,61 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "avplayer.h"
#include "avplayer_common.h"
#include <algorithm> // std::equal
#include <cctype> // std::tolower
#include <string_view> // std::string_view
namespace Libraries::AvPlayer {
using namespace Kernel;
static bool ichar_equals(char a, char b) {
return std::tolower(static_cast<unsigned char>(a)) ==
std::tolower(static_cast<unsigned char>(b));
}
static bool iequals(std::string_view l, std::string_view r) {
return std::ranges::equal(l, r, ichar_equals);
}
SceAvPlayerSourceType GetSourceType(std::string_view path) {
if (path.empty()) {
return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN;
}
std::string_view name = path;
if (path.find("://") != std::string_view::npos) {
// This path is a URI. Strip HTTP parameters from it.
// schema://server.domain/path/file.ext/and/beyond?param=value#paragraph ->
// -> schema://server.domain/path/to/file.ext/and/beyond
name = path.substr(0, path.find_first_of("?#"));
if (name.empty()) {
return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN;
}
}
// schema://server.domain/path/to/file.ext/and/beyond -> .ext/and/beyond
auto ext = name.substr(name.rfind('.'));
if (ext.empty()) {
return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN;
}
// .ext/and/beyond -> .ext
ext = ext.substr(0, ext.find('/'));
if (iequals(ext, ".mp4") || iequals(ext, ".m4v") || iequals(ext, ".m3d") ||
iequals(ext, ".m4a") || iequals(ext, ".mov")) {
return SCE_AVPLAYER_SOURCE_TYPE_FILE_MP4;
}
if (iequals(ext, ".m3u8")) {
return SCE_AVPLAYER_SOURCE_TYPE_HLS;
}
return SCE_AVPLAYER_SOURCE_TYPE_UNKNOWN;
}
} // namespace Libraries::AvPlayer

View File

@ -1,91 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "avplayer.h"
#include "common/assert.h"
#include "common/logging/log.h"
#include "core/libraries/kernel/thread_management.h"
#include <optional>
#include <utility>
#include <queue>
#define AVPLAYER_IS_ERROR(x) ((x) < 0)
namespace Libraries::AvPlayer {
enum class AvState {
Initial,
AddingSource,
Ready,
Play,
Stop,
EndOfFile,
Pause,
C0x08,
Jump,
TrickMode,
C0x0B,
Buffering,
Starting,
Error,
};
enum class AvEventType {
ChangeFlowState = 21,
WarningId = 22,
RevertState = 30,
AddSource = 40,
Error = 255,
};
union AvPlayerEventData {
u32 num_frames; // 20
AvState state; // AvEventType::ChangeFlowState
s32 error; // AvEventType::WarningId
u32 attempt; // AvEventType::AddSource
};
struct AvPlayerEvent {
AvEventType event;
AvPlayerEventData payload;
};
template <class T>
class AvPlayerQueue {
public:
size_t Size() {
return m_queue.size();
}
void Push(T&& value) {
std::lock_guard guard(m_mutex);
m_queue.emplace(std::forward<T>(value));
}
std::optional<T> Pop() {
if (Size() == 0) {
return std::nullopt;
}
std::lock_guard guard(m_mutex);
auto result = std::move(m_queue.front());
m_queue.pop();
return result;
}
void Clear() {
std::lock_guard guard(m_mutex);
m_queue = {};
}
private:
std::mutex m_mutex{};
std::queue<T> m_queue{};
};
SceAvPlayerSourceType GetSourceType(std::string_view path);
} // namespace Libraries::AvPlayer

View File

@ -1,23 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "avplayer.h"
#include "common/types.h"
#include <string_view>
struct AVIOContext;
namespace Libraries::AvPlayer {
class IDataStreamer {
public:
virtual ~IDataStreamer() = default;
virtual bool Init(std::string_view path) = 0;
virtual AVIOContext* GetContext() = 0;
};
} // namespace Libraries::AvPlayer

View File

@ -1,90 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "avplayer_file_streamer.h"
#include "avplayer_common.h"
#include <magic_enum.hpp>
extern "C" {
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
}
#include <algorithm> // std::max, std::min
#define AVPLAYER_AVIO_BUFFER_SIZE 4096
namespace Libraries::AvPlayer {
AvPlayerFileStreamer::AvPlayerFileStreamer(const SceAvPlayerFileReplacement& file_replacement)
: m_file_replacement(file_replacement) {}
AvPlayerFileStreamer::~AvPlayerFileStreamer() {
if (m_avio_context != nullptr) {
avio_context_free(&m_avio_context);
}
if (m_file_replacement.close != nullptr && m_fd >= 0) {
const auto close = m_file_replacement.close;
const auto ptr = m_file_replacement.object_ptr;
close(ptr);
}
}
bool AvPlayerFileStreamer::Init(std::string_view path) {
const auto ptr = m_file_replacement.object_ptr;
m_fd = m_file_replacement.open(ptr, path.data());
if (m_fd < 0) {
return false;
}
m_file_size = m_file_replacement.size(ptr);
// avio_buffer is deallocated in `avio_context_free`
const auto avio_buffer = reinterpret_cast<u8*>(av_malloc(AVPLAYER_AVIO_BUFFER_SIZE));
m_avio_context =
avio_alloc_context(avio_buffer, AVPLAYER_AVIO_BUFFER_SIZE, 0, this,
&AvPlayerFileStreamer::ReadPacket, nullptr, &AvPlayerFileStreamer::Seek);
return true;
}
s32 AvPlayerFileStreamer::ReadPacket(void* opaque, u8* buffer, s32 size) {
const auto self = reinterpret_cast<AvPlayerFileStreamer*>(opaque);
if (self->m_position >= self->m_file_size) {
return AVERROR_EOF;
}
if (self->m_position + size > self->m_file_size) {
size = self->m_file_size - self->m_position;
}
const auto read_offset = self->m_file_replacement.readOffset;
const auto ptr = self->m_file_replacement.object_ptr;
const auto bytes_read = read_offset(ptr, buffer, self->m_position, size);
if (bytes_read == 0 && size != 0) {
return AVERROR_EOF;
}
self->m_position += bytes_read;
return bytes_read;
}
s64 AvPlayerFileStreamer::Seek(void* opaque, s64 offset, int whence) {
const auto self = reinterpret_cast<AvPlayerFileStreamer*>(opaque);
if (whence & AVSEEK_SIZE) {
return self->m_file_size;
}
if (whence == SEEK_CUR) {
self->m_position =
std::min(u64(std::max(s64(0), s64(self->m_position) + offset)), self->m_file_size);
return self->m_position;
} else if (whence == SEEK_SET) {
self->m_position = std::min(u64(std::max(s64(0), offset)), self->m_file_size);
return self->m_position;
} else if (whence == SEEK_END) {
self->m_position =
std::min(u64(std::max(s64(0), s64(self->m_file_size) + offset)), self->m_file_size);
return self->m_position;
}
return -1;
}
} // namespace Libraries::AvPlayer

View File

@ -1,39 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "avplayer.h"
#include "avplayer_data_streamer.h"
#include <string_view>
#include <vector>
struct AVIOContext;
namespace Libraries::AvPlayer {
class AvPlayerFileStreamer : public IDataStreamer {
public:
AvPlayerFileStreamer(const SceAvPlayerFileReplacement& file_replacement);
~AvPlayerFileStreamer();
bool Init(std::string_view path) override;
AVIOContext* GetContext() override {
return m_avio_context;
}
private:
static s32 ReadPacket(void* opaque, u8* buffer, s32 size);
static s64 Seek(void* opaque, s64 buffer, int whence);
SceAvPlayerFileReplacement m_file_replacement;
int m_fd = -1;
u64 m_position{};
u64 m_file_size{};
AVIOContext* m_avio_context{};
};
} // namespace Libraries::AvPlayer

View File

@ -1,203 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "avplayer_common.h"
#include "avplayer_file_streamer.h"
#include "avplayer_impl.h"
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/libkernel.h"
using namespace Libraries::Kernel;
namespace Libraries::AvPlayer {
void* PS4_SYSV_ABI AvPlayer::Allocate(void* handle, u32 alignment, u32 size) {
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
const auto allocate = self->m_init_data_original.memory_replacement.allocate;
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
return allocate(ptr, alignment, size);
}
void PS4_SYSV_ABI AvPlayer::Deallocate(void* handle, void* memory) {
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
const auto deallocate = self->m_init_data_original.memory_replacement.deallocate;
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
return deallocate(ptr, memory);
}
void* PS4_SYSV_ABI AvPlayer::AllocateTexture(void* handle, u32 alignment, u32 size) {
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
const auto allocate = self->m_init_data_original.memory_replacement.allocate_texture;
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
return allocate(ptr, alignment, size);
}
void PS4_SYSV_ABI AvPlayer::DeallocateTexture(void* handle, void* memory) {
const auto* const self = reinterpret_cast<AvPlayer*>(handle);
const auto deallocate = self->m_init_data_original.memory_replacement.deallocate_texture;
const auto ptr = self->m_init_data_original.memory_replacement.object_ptr;
return deallocate(ptr, memory);
}
int PS4_SYSV_ABI AvPlayer::OpenFile(void* handle, const char* filename) {
auto const self = reinterpret_cast<AvPlayer*>(handle);
std::lock_guard guard(self->m_file_io_mutex);
const auto open = self->m_init_data_original.file_replacement.open;
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
return open(ptr, filename);
}
int PS4_SYSV_ABI AvPlayer::CloseFile(void* handle) {
auto const self = reinterpret_cast<AvPlayer*>(handle);
std::lock_guard guard(self->m_file_io_mutex);
const auto close = self->m_init_data_original.file_replacement.close;
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
return close(ptr);
}
int PS4_SYSV_ABI AvPlayer::ReadOffsetFile(void* handle, u8* buffer, u64 position, u32 length) {
auto const self = reinterpret_cast<AvPlayer*>(handle);
std::lock_guard guard(self->m_file_io_mutex);
const auto read_offset = self->m_init_data_original.file_replacement.readOffset;
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
return read_offset(ptr, buffer, position, length);
}
u64 PS4_SYSV_ABI AvPlayer::SizeFile(void* handle) {
auto const self = reinterpret_cast<AvPlayer*>(handle);
std::lock_guard guard(self->m_file_io_mutex);
const auto size = self->m_init_data_original.file_replacement.size;
const auto ptr = self->m_init_data_original.file_replacement.object_ptr;
return size(ptr);
}
SceAvPlayerInitData AvPlayer::StubInitData(const SceAvPlayerInitData& data) {
SceAvPlayerInitData result = data;
result.memory_replacement.object_ptr = this;
result.memory_replacement.allocate = &AvPlayer::Allocate;
result.memory_replacement.deallocate = &AvPlayer::Deallocate;
result.memory_replacement.allocate_texture = &AvPlayer::AllocateTexture;
result.memory_replacement.deallocate_texture = &AvPlayer::DeallocateTexture;
if (data.file_replacement.open == nullptr || data.file_replacement.close == nullptr ||
data.file_replacement.readOffset == nullptr || data.file_replacement.size == nullptr) {
result.file_replacement = {};
} else {
result.file_replacement.object_ptr = this;
result.file_replacement.open = &AvPlayer::OpenFile;
result.file_replacement.close = &AvPlayer::CloseFile;
result.file_replacement.readOffset = &AvPlayer::ReadOffsetFile;
result.file_replacement.size = &AvPlayer::SizeFile;
}
return result;
}
AvPlayer::AvPlayer(const SceAvPlayerInitData& data)
: m_init_data(StubInitData(data)), m_init_data_original(data),
m_state(std::make_unique<AvPlayerState>(m_init_data)) {}
s32 AvPlayer::PostInit(const SceAvPlayerPostInitData& data) {
m_post_init_data = data;
return ORBIS_OK;
}
s32 AvPlayer::AddSource(std::string_view path) {
if (path.empty()) {
return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS;
}
if (!m_state->AddSource(path, GetSourceType(path))) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
return ORBIS_OK;
}
s32 AvPlayer::GetStreamCount() {
if (m_state == nullptr) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
const auto res = m_state->GetStreamCount();
if (AVPLAYER_IS_ERROR(res)) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
return res;
}
s32 AvPlayer::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) {
if (!m_state->GetStreamInfo(stream_index, info)) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
return ORBIS_OK;
}
s32 AvPlayer::EnableStream(u32 stream_index) {
if (m_state == nullptr) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
if (!m_state->EnableStream(stream_index)) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
return ORBIS_OK;
}
s32 AvPlayer::Start() {
if (!m_state->Start()) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
return ORBIS_OK;
}
bool AvPlayer::GetVideoData(SceAvPlayerFrameInfo& video_info) {
if (m_state == nullptr) {
return false;
}
return m_state->GetVideoData(video_info);
}
bool AvPlayer::GetVideoData(SceAvPlayerFrameInfoEx& video_info) {
if (m_state == nullptr) {
return false;
}
return m_state->GetVideoData(video_info);
}
bool AvPlayer::GetAudioData(SceAvPlayerFrameInfo& audio_info) {
if (m_state == nullptr) {
return false;
}
return m_state->GetAudioData(audio_info);
}
bool AvPlayer::IsActive() {
if (m_state == nullptr) {
return false;
}
return m_state->IsActive();
}
u64 AvPlayer::CurrentTime() {
if (m_state == nullptr) {
return 0;
}
return m_state->CurrentTime();
}
s32 AvPlayer::Stop() {
if (m_state == nullptr || !m_state->Stop()) {
return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED;
}
return ORBIS_OK;
}
bool AvPlayer::SetLooping(bool is_looping) {
if (m_state == nullptr) {
return false;
}
return m_state->SetLooping(is_looping);
}
} // namespace Libraries::AvPlayer

View File

@ -1,68 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "avplayer.h"
#include "avplayer_data_streamer.h"
#include "avplayer_state.h"
#include "core/libraries/kernel/thread_management.h"
#include <mutex>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
#include <memory>
#include <vector>
namespace Libraries::AvPlayer {
class AvPlayer {
public:
AvPlayer(const SceAvPlayerInitData& data);
s32 PostInit(const SceAvPlayerPostInitData& data);
s32 AddSource(std::string_view filename);
s32 GetStreamCount();
s32 GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info);
s32 EnableStream(u32 stream_index);
s32 Start();
bool GetAudioData(SceAvPlayerFrameInfo& audio_info);
bool GetVideoData(SceAvPlayerFrameInfo& video_info);
bool GetVideoData(SceAvPlayerFrameInfoEx& video_info);
bool IsActive();
u64 CurrentTime();
s32 Stop();
bool SetLooping(bool is_looping);
private:
using ScePthreadMutex = Kernel::ScePthreadMutex;
// Memory Replacement
static void* PS4_SYSV_ABI Allocate(void* handle, u32 alignment, u32 size);
static void PS4_SYSV_ABI Deallocate(void* handle, void* memory);
static void* PS4_SYSV_ABI AllocateTexture(void* handle, u32 alignment, u32 size);
static void PS4_SYSV_ABI DeallocateTexture(void* handle, void* memory);
// File Replacement
static int PS4_SYSV_ABI OpenFile(void* handle, const char* filename);
static int PS4_SYSV_ABI CloseFile(void* handle);
static int PS4_SYSV_ABI ReadOffsetFile(void* handle, u8* buffer, u64 position, u32 length);
static u64 PS4_SYSV_ABI SizeFile(void* handle);
SceAvPlayerInitData StubInitData(const SceAvPlayerInitData& data);
SceAvPlayerInitData m_init_data{};
SceAvPlayerInitData m_init_data_original{};
SceAvPlayerPostInitData m_post_init_data{};
std::mutex m_file_io_mutex{};
std::atomic_bool m_has_source{};
std::unique_ptr<AvPlayerState> m_state{};
};
} // namespace Libraries::AvPlayer

View File

@ -1,772 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "avplayer_source.h"
#include "avplayer_file_streamer.h"
#include "common/alignment.h"
#include "common/singleton.h"
#include "core/file_sys/fs.h"
#include "core/libraries/kernel/time_management.h"
#include <magic_enum.hpp>
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libswresample/swresample.h>
#include <libswscale/swscale.h>
}
namespace Libraries::AvPlayer {
using namespace Kernel;
AvPlayerSource::AvPlayerSource(AvPlayerStateCallback& state) : m_state(state) {}
AvPlayerSource::~AvPlayerSource() {
Stop();
}
bool AvPlayerSource::Init(const SceAvPlayerInitData& init_data, std::string_view path) {
m_memory_replacement = init_data.memory_replacement,
m_num_output_video_framebuffers =
std::min(std::max(2, init_data.num_output_video_framebuffers), 16);
AVFormatContext* context = avformat_alloc_context();
if (init_data.file_replacement.open != nullptr) {
m_up_data_streamer = std::make_unique<AvPlayerFileStreamer>(init_data.file_replacement);
if (!m_up_data_streamer->Init(path)) {
return false;
}
context->pb = m_up_data_streamer->GetContext();
if (AVPLAYER_IS_ERROR(avformat_open_input(&context, nullptr, nullptr, nullptr))) {
return false;
}
} else {
const auto mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
const auto filepath = mnt->GetHostPath(path);
if (AVPLAYER_IS_ERROR(
avformat_open_input(&context, filepath.string().c_str(), nullptr, nullptr))) {
return false;
}
}
m_avformat_context = AVFormatContextPtr(context, &ReleaseAVFormatContext);
return true;
}
bool AvPlayerSource::FindStreamInfo() {
if (m_avformat_context == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not find stream info. NULL context.");
return false;
}
if (m_avformat_context->nb_streams > 0) {
return true;
}
return avformat_find_stream_info(m_avformat_context.get(), nullptr) == 0;
}
s32 AvPlayerSource::GetStreamCount() {
if (m_avformat_context == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not get stream count. NULL context.");
return -1;
}
LOG_INFO(Lib_AvPlayer, "Stream Count: {}", m_avformat_context->nb_streams);
return m_avformat_context->nb_streams;
}
static s32 CodecTypeToStreamType(AVMediaType codec_type) {
switch (codec_type) {
case AVMediaType::AVMEDIA_TYPE_VIDEO:
return SCE_AVPLAYER_VIDEO;
case AVMediaType::AVMEDIA_TYPE_AUDIO:
return SCE_AVPLAYER_AUDIO;
case AVMediaType::AVMEDIA_TYPE_SUBTITLE:
return SCE_AVPLAYER_TIMEDTEXT;
default:
LOG_ERROR(Lib_AvPlayer, "Unexpected AVMediaType {}", magic_enum::enum_name(codec_type));
return -1;
}
}
static f32 AVRationalToF32(const AVRational rational) {
return f32(rational.num) / rational.den;
}
bool AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) {
info = {};
if (m_avformat_context == nullptr || stream_index >= m_avformat_context->nb_streams) {
LOG_ERROR(Lib_AvPlayer, "Could not get stream {} info.", stream_index);
return false;
}
const auto p_stream = m_avformat_context->streams[stream_index];
if (p_stream == nullptr || p_stream->codecpar == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not get stream {} info. NULL stream.", stream_index);
return false;
}
info.type = CodecTypeToStreamType(p_stream->codecpar->codec_type);
info.start_time = p_stream->start_time;
info.duration = p_stream->duration;
const auto p_lang_node = av_dict_get(p_stream->metadata, "language", nullptr, 0);
if (p_lang_node != nullptr) {
LOG_INFO(Lib_AvPlayer, "Stream {} language = {}", stream_index, p_lang_node->value);
} else {
LOG_WARNING(Lib_AvPlayer, "Stream {} language is unknown", stream_index);
}
switch (info.type) {
case SCE_AVPLAYER_VIDEO:
LOG_INFO(Lib_AvPlayer, "Stream {} is a video stream.", stream_index);
info.details.video.aspect_ratio =
f32(p_stream->codecpar->width) / p_stream->codecpar->height;
info.details.video.width = Common::AlignUp(u32(p_stream->codecpar->width), 16);
info.details.video.height = Common::AlignUp(u32(p_stream->codecpar->height), 16);
if (p_lang_node != nullptr) {
std::memcpy(info.details.video.language_code, p_lang_node->value,
std::min(strlen(p_lang_node->value), size_t(3)));
}
break;
case SCE_AVPLAYER_AUDIO:
LOG_INFO(Lib_AvPlayer, "Stream {} is an audio stream.", stream_index);
info.details.audio.channel_count = p_stream->codecpar->ch_layout.nb_channels;
info.details.audio.sample_rate = p_stream->codecpar->sample_rate;
info.details.audio.size = 0; // sceAvPlayerGetStreamInfo() is expected to set this to 0
if (p_lang_node != nullptr) {
std::memcpy(info.details.audio.language_code, p_lang_node->value,
std::min(strlen(p_lang_node->value), size_t(3)));
}
break;
case SCE_AVPLAYER_TIMEDTEXT:
LOG_WARNING(Lib_AvPlayer, "Stream {} is a timedtext stream.", stream_index);
info.details.subs.font_size = 12;
info.details.subs.text_size = 12;
if (p_lang_node != nullptr) {
std::memcpy(info.details.subs.language_code, p_lang_node->value,
std::min(strlen(p_lang_node->value), size_t(3)));
}
break;
default:
LOG_ERROR(Lib_AvPlayer, "Stream {} type is unknown: {}.", stream_index, info.type);
return false;
}
return true;
}
bool AvPlayerSource::EnableStream(u32 stream_index) {
if (m_avformat_context == nullptr || stream_index >= m_avformat_context->nb_streams) {
return false;
}
const auto stream = m_avformat_context->streams[stream_index];
const auto decoder = avcodec_find_decoder(stream->codecpar->codec_id);
if (decoder == nullptr) {
return false;
}
switch (stream->codecpar->codec_type) {
case AVMediaType::AVMEDIA_TYPE_VIDEO: {
m_video_stream_index = stream_index;
m_video_codec_context =
AVCodecContextPtr(avcodec_alloc_context3(decoder), &ReleaseAVCodecContext);
if (avcodec_parameters_to_context(m_video_codec_context.get(), stream->codecpar) < 0) {
LOG_ERROR(Lib_AvPlayer, "Could not copy stream {} avcodec parameters to context.",
stream_index);
return false;
}
if (avcodec_open2(m_video_codec_context.get(), decoder, nullptr) < 0) {
LOG_ERROR(Lib_AvPlayer, "Could not open avcodec for video stream {}.", stream_index);
return false;
}
const auto width = Common::AlignUp(u32(m_video_codec_context->width), 16);
const auto height = Common::AlignUp(u32(m_video_codec_context->height), 16);
const auto size = (width * height * 3) / 2;
for (u64 index = 0; index < m_num_output_video_framebuffers; ++index) {
m_video_buffers.Push(FrameBuffer(m_memory_replacement, 0x100, size));
}
LOG_INFO(Lib_AvPlayer, "Video stream {} enabled", stream_index);
break;
}
case AVMediaType::AVMEDIA_TYPE_AUDIO: {
m_audio_stream_index = stream_index;
m_audio_codec_context =
AVCodecContextPtr(avcodec_alloc_context3(decoder), &ReleaseAVCodecContext);
if (avcodec_parameters_to_context(m_audio_codec_context.get(), stream->codecpar) < 0) {
LOG_ERROR(Lib_AvPlayer, "Could not copy stream {} avcodec parameters to context.",
stream_index);
return false;
}
if (avcodec_open2(m_audio_codec_context.get(), decoder, nullptr) < 0) {
LOG_ERROR(Lib_AvPlayer, "Could not open avcodec for audio stream {}.", stream_index);
return false;
}
const auto num_channels = m_audio_codec_context->ch_layout.nb_channels;
const auto align = num_channels * sizeof(u16);
const auto size = num_channels * sizeof(u16) * 1024;
for (u64 index = 0; index < 4; ++index) {
m_audio_buffers.Push(FrameBuffer(m_memory_replacement, 0x100, size));
}
LOG_INFO(Lib_AvPlayer, "Audio stream {} enabled", stream_index);
break;
}
default:
LOG_WARNING(Lib_AvPlayer, "Unknown stream type {} for stream {}",
magic_enum::enum_name(stream->codecpar->codec_type), stream_index);
break;
}
return true;
}
void AvPlayerSource::SetLooping(bool is_looping) {
m_is_looping = is_looping;
}
std::optional<bool> AvPlayerSource::HasFrames(u32 num_frames) {
return m_video_packets.Size() > num_frames || m_is_eof;
}
bool AvPlayerSource::Start() {
std::unique_lock lock(m_state_mutex);
if (m_audio_codec_context == nullptr && m_video_codec_context == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not start playback. NULL context.");
return false;
}
m_demuxer_thread = std::jthread([this](std::stop_token stop) { this->DemuxerThread(stop); });
m_video_decoder_thread =
std::jthread([this](std::stop_token stop) { this->VideoDecoderThread(stop); });
m_audio_decoder_thread =
std::jthread([this](std::stop_token stop) { this->AudioDecoderThread(stop); });
m_start_time = std::chrono::high_resolution_clock::now();
return true;
}
bool AvPlayerSource::Stop() {
std::unique_lock lock(m_state_mutex);
if (!HasRunningThreads()) {
LOG_WARNING(Lib_AvPlayer, "Could not stop playback: already stopped.");
return false;
}
m_video_decoder_thread.request_stop();
m_audio_decoder_thread.request_stop();
m_demuxer_thread.request_stop();
if (m_demuxer_thread.joinable()) {
m_demuxer_thread.join();
}
if (m_video_decoder_thread.joinable()) {
m_video_decoder_thread.join();
}
if (m_audio_decoder_thread.joinable()) {
m_audio_decoder_thread.join();
}
if (m_current_audio_frame.has_value()) {
m_audio_buffers.Push(std::move(m_current_audio_frame.value()));
m_current_audio_frame.reset();
}
if (m_current_video_frame.has_value()) {
m_video_buffers.Push(std::move(m_current_video_frame.value()));
m_current_video_frame.reset();
}
m_stop_cv.Notify();
m_audio_packets.Clear();
m_video_packets.Clear();
m_audio_frames.Clear();
m_video_frames.Clear();
return true;
}
bool AvPlayerSource::GetVideoData(SceAvPlayerFrameInfo& video_info) {
if (!IsActive()) {
return false;
}
SceAvPlayerFrameInfoEx info{};
if (!GetVideoData(info)) {
return false;
}
video_info = {};
video_info.timestamp = u64(info.timestamp);
video_info.pData = reinterpret_cast<u8*>(info.pData);
video_info.details.video.aspect_ratio = info.details.video.aspect_ratio;
video_info.details.video.width = info.details.video.width;
video_info.details.video.height = info.details.video.height;
return true;
}
bool AvPlayerSource::GetVideoData(SceAvPlayerFrameInfoEx& video_info) {
if (!IsActive()) {
return false;
}
m_video_frames_cv.Wait([this] { return m_video_frames.Size() != 0 || m_is_eof; });
auto frame = m_video_frames.Pop();
if (!frame.has_value()) {
LOG_WARNING(Lib_AvPlayer, "Could get video frame. EOF reached.");
return false;
}
{
using namespace std::chrono;
auto elapsed_time =
duration_cast<milliseconds>(high_resolution_clock::now() - m_start_time).count();
if (elapsed_time < frame->info.timestamp) {
if (m_stop_cv.WaitFor(milliseconds(frame->info.timestamp - elapsed_time),
[&] { return elapsed_time >= frame->info.timestamp; })) {
return false;
}
}
}
// return the buffer to the queue
if (m_current_video_frame.has_value()) {
m_video_buffers.Push(std::move(m_current_video_frame.value()));
m_video_buffers_cv.Notify();
}
m_current_video_frame = std::move(frame->buffer);
video_info = frame->info;
return true;
}
bool AvPlayerSource::GetAudioData(SceAvPlayerFrameInfo& audio_info) {
if (!IsActive()) {
return false;
}
m_audio_frames_cv.Wait([this] { return m_audio_frames.Size() != 0 || m_is_eof; });
auto frame = m_audio_frames.Pop();
if (!frame.has_value()) {
LOG_WARNING(Lib_AvPlayer, "Could get audio frame. EOF reached.");
return false;
}
{
using namespace std::chrono;
auto elapsed_time =
duration_cast<milliseconds>(high_resolution_clock::now() - m_start_time).count();
if (elapsed_time < frame->info.timestamp) {
if (m_stop_cv.WaitFor(milliseconds(frame->info.timestamp - elapsed_time),
[&] { return elapsed_time >= frame->info.timestamp; })) {
return false;
}
}
}
// return the buffer to the queue
if (m_current_audio_frame.has_value()) {
m_audio_buffers.Push(std::move(m_current_audio_frame.value()));
m_audio_buffers_cv.Notify();
}
m_current_audio_frame = std::move(frame->buffer);
audio_info = {};
audio_info.timestamp = frame->info.timestamp;
audio_info.pData = reinterpret_cast<u8*>(frame->info.pData);
audio_info.details.audio.sample_rate = frame->info.details.audio.sample_rate;
audio_info.details.audio.size = frame->info.details.audio.size;
audio_info.details.audio.channel_count = frame->info.details.audio.channel_count;
return true;
}
u64 AvPlayerSource::CurrentTime() {
if (!IsActive()) {
return 0;
}
using namespace std::chrono;
return duration_cast<milliseconds>(high_resolution_clock::now() - m_start_time).count();
}
bool AvPlayerSource::IsActive() {
return !m_is_eof || m_audio_packets.Size() != 0 || m_video_packets.Size() != 0 ||
m_video_frames.Size() != 0 || m_audio_frames.Size() != 0;
}
void AvPlayerSource::ReleaseAVPacket(AVPacket* packet) {
if (packet != nullptr) {
av_packet_free(&packet);
}
}
void AvPlayerSource::ReleaseAVFrame(AVFrame* frame) {
if (frame != nullptr) {
av_frame_free(&frame);
}
}
void AvPlayerSource::ReleaseAVCodecContext(AVCodecContext* context) {
if (context != nullptr) {
avcodec_free_context(&context);
}
}
void AvPlayerSource::ReleaseSWRContext(SwrContext* context) {
if (context != nullptr) {
swr_free(&context);
}
}
void AvPlayerSource::ReleaseSWSContext(SwsContext* context) {
if (context != nullptr) {
sws_freeContext(context);
}
}
void AvPlayerSource::ReleaseAVFormatContext(AVFormatContext* context) {
if (context != nullptr) {
avformat_close_input(&context);
}
}
void AvPlayerSource::DemuxerThread(std::stop_token stop) {
using namespace std::chrono;
if (!m_audio_stream_index.has_value() && !m_video_stream_index.has_value()) {
LOG_WARNING(Lib_AvPlayer, "Could not start DEMUXER thread. No streams enabled.");
return;
}
LOG_INFO(Lib_AvPlayer, "Demuxer Thread started");
while (!stop.stop_requested()) {
if (m_video_packets.Size() > 30 && m_audio_packets.Size() > 8) {
std::this_thread::sleep_for(milliseconds(5));
continue;
}
AVPacketPtr up_packet(av_packet_alloc(), &ReleaseAVPacket);
const auto res = av_read_frame(m_avformat_context.get(), up_packet.get());
if (res < 0) {
if (res == AVERROR_EOF) {
if (m_is_looping) {
LOG_INFO(Lib_AvPlayer, "EOF reached in demuxer. Looping the source...");
avio_seek(m_avformat_context->pb, 0, SEEK_SET);
if (m_video_stream_index.has_value()) {
const auto index = m_video_stream_index.value();
const auto stream = m_avformat_context->streams[index];
avformat_seek_file(m_avformat_context.get(), index, 0, 0, stream->duration,
0);
}
if (m_audio_stream_index.has_value()) {
const auto index = m_audio_stream_index.value();
const auto stream = m_avformat_context->streams[index];
avformat_seek_file(m_avformat_context.get(), index, 0, 0, stream->duration,
0);
}
continue;
} else {
LOG_INFO(Lib_AvPlayer, "EOF reached in demuxer. Exiting.");
break;
}
} else {
LOG_ERROR(Lib_AvPlayer, "Could not read AV frame: error = {}", res);
m_state.OnError();
return;
}
break;
}
if (up_packet->stream_index == m_video_stream_index) {
m_video_packets.Push(std::move(up_packet));
m_video_packets_cv.Notify();
} else if (up_packet->stream_index == m_audio_stream_index) {
m_audio_packets.Push(std::move(up_packet));
m_audio_packets_cv.Notify();
}
}
m_is_eof = true;
m_video_packets_cv.Notify();
m_audio_packets_cv.Notify();
m_video_frames_cv.Notify();
m_audio_frames_cv.Notify();
if (m_video_decoder_thread.joinable()) {
m_video_decoder_thread.join();
}
if (m_audio_decoder_thread.joinable()) {
m_audio_decoder_thread.join();
}
m_state.OnEOF();
LOG_INFO(Lib_AvPlayer, "Demuxer Thread exited normaly");
}
AvPlayerSource::AVFramePtr AvPlayerSource::ConvertVideoFrame(const AVFrame& frame) {
auto nv12_frame = AVFramePtr{av_frame_alloc(), &ReleaseAVFrame};
nv12_frame->pts = frame.pts;
nv12_frame->pkt_dts = frame.pkt_dts < 0 ? 0 : frame.pkt_dts;
nv12_frame->format = AV_PIX_FMT_NV12;
nv12_frame->width = frame.width;
nv12_frame->height = frame.height;
nv12_frame->sample_aspect_ratio = frame.sample_aspect_ratio;
nv12_frame->crop_top = frame.crop_top;
nv12_frame->crop_bottom = frame.crop_bottom;
nv12_frame->crop_left = frame.crop_left;
nv12_frame->crop_right = frame.crop_right;
av_frame_get_buffer(nv12_frame.get(), 0);
if (m_sws_context == nullptr) {
m_sws_context =
SWSContextPtr(sws_getContext(frame.width, frame.height, AVPixelFormat(frame.format),
nv12_frame->width, nv12_frame->height, AV_PIX_FMT_NV12,
SWS_FAST_BILINEAR, nullptr, nullptr, nullptr),
&ReleaseSWSContext);
}
const auto res = sws_scale(m_sws_context.get(), frame.data, frame.linesize, 0, frame.height,
nv12_frame->data, nv12_frame->linesize);
if (res < 0) {
LOG_ERROR(Lib_AvPlayer, "Could not convert to NV12: {}", av_err2str(res));
return AVFramePtr{nullptr, &ReleaseAVFrame};
}
return nv12_frame;
}
static void CopyNV12Data(u8* dst, const AVFrame& src) {
const auto width = Common::AlignUp(u32(src.width), 16);
const auto height = Common::AlignUp(u32(src.height), 16);
if (src.width == width) {
std::memcpy(dst, src.data[0], src.width * src.height);
std::memcpy(dst + src.width * height, src.data[1], (src.width * src.height) / 2);
} else {
const auto luma_dst = dst;
for (u32 y = 0; y < src.height; ++y) {
std::memcpy(luma_dst + y * width, src.data[0] + y * src.width, src.width);
}
const auto chroma_dst = dst + width * height;
for (u32 y = 0; y < src.height / 2; ++y) {
std::memcpy(chroma_dst + y * (width / 2), src.data[0] + y * (src.width / 2),
src.width / 2);
}
}
}
Frame AvPlayerSource::PrepareVideoFrame(FrameBuffer buffer, const AVFrame& frame) {
ASSERT(frame.format == AV_PIX_FMT_NV12);
auto p_buffer = buffer.GetBuffer();
CopyNV12Data(p_buffer, frame);
const auto pkt_dts = u64(frame.pkt_dts) * 1000;
const auto stream = m_avformat_context->streams[m_video_stream_index.value()];
const auto time_base = stream->time_base;
const auto den = time_base.den;
const auto num = time_base.num;
const auto timestamp = (num != 0 && den > 1) ? (pkt_dts * num) / den : pkt_dts;
const auto width = Common::AlignUp(u32(frame.width), 16);
const auto height = Common::AlignUp(u32(frame.height), 16);
return Frame{
.buffer = std::move(buffer),
.info =
{
.pData = p_buffer,
.timestamp = timestamp,
.details =
{
.video =
{
.width = u32(width),
.height = u32(height),
.aspect_ratio = AVRationalToF32(frame.sample_aspect_ratio),
.crop_left_offset = u32(frame.crop_left),
.crop_right_offset = u32(frame.crop_right + (width - frame.width)),
.crop_top_offset = u32(frame.crop_top),
.crop_bottom_offset =
u32(frame.crop_bottom + (height - frame.height)),
.pitch = u32(frame.linesize[0]),
.luma_bit_depth = 8,
.chroma_bit_depth = 8,
},
},
},
};
}
void AvPlayerSource::VideoDecoderThread(std::stop_token stop) {
using namespace std::chrono;
LOG_INFO(Lib_AvPlayer, "Video Decoder Thread started");
while ((!m_is_eof || m_video_packets.Size() != 0) && !stop.stop_requested()) {
if (!m_video_packets_cv.Wait(stop,
[this] { return m_video_packets.Size() != 0 || m_is_eof; })) {
continue;
}
const auto packet = m_video_packets.Pop();
if (!packet.has_value()) {
continue;
}
auto res = avcodec_send_packet(m_video_codec_context.get(), packet->get());
if (res < 0 && res != AVERROR(EAGAIN)) {
m_state.OnError();
LOG_ERROR(Lib_AvPlayer, "Could not send packet to the video codec. Error = {}",
av_err2str(res));
return;
}
while (res >= 0) {
if (!m_video_buffers_cv.Wait(stop, [this] { return m_video_buffers.Size() != 0; })) {
break;
}
if (m_video_buffers.Size() == 0) {
continue;
}
auto up_frame = AVFramePtr(av_frame_alloc(), &ReleaseAVFrame);
res = avcodec_receive_frame(m_video_codec_context.get(), up_frame.get());
if (res < 0) {
if (res == AVERROR_EOF) {
LOG_INFO(Lib_AvPlayer, "EOF reached in video decoder");
return;
} else if (res != AVERROR(EAGAIN)) {
LOG_ERROR(Lib_AvPlayer,
"Could not receive frame from the video codec. Error = {}",
av_err2str(res));
m_state.OnError();
return;
}
} else {
auto buffer = m_video_buffers.Pop();
if (!buffer.has_value()) {
// Video buffers queue was cleared. This means that player was stopped.
break;
}
if (up_frame->format != AV_PIX_FMT_NV12) {
const auto nv12_frame = ConvertVideoFrame(*up_frame);
m_video_frames.Push(PrepareVideoFrame(std::move(buffer.value()), *nv12_frame));
} else {
m_video_frames.Push(PrepareVideoFrame(std::move(buffer.value()), *up_frame));
}
m_video_frames_cv.Notify();
}
}
}
LOG_INFO(Lib_AvPlayer, "Video Decoder Thread exited normaly");
}
AvPlayerSource::AVFramePtr AvPlayerSource::ConvertAudioFrame(const AVFrame& frame) {
auto pcm16_frame = AVFramePtr{av_frame_alloc(), &ReleaseAVFrame};
pcm16_frame->pts = frame.pts;
pcm16_frame->pkt_dts = frame.pkt_dts < 0 ? 0 : frame.pkt_dts;
pcm16_frame->format = AV_SAMPLE_FMT_S16;
pcm16_frame->ch_layout = frame.ch_layout;
pcm16_frame->sample_rate = frame.sample_rate;
if (m_swr_context == nullptr) {
SwrContext* swr_context = nullptr;
AVChannelLayout in_ch_layout = frame.ch_layout;
AVChannelLayout out_ch_layout = frame.ch_layout;
swr_alloc_set_opts2(&swr_context, &out_ch_layout, AV_SAMPLE_FMT_S16, frame.sample_rate,
&in_ch_layout, AVSampleFormat(frame.format), frame.sample_rate, 0,
nullptr);
m_swr_context = SWRContextPtr(swr_context, &ReleaseSWRContext);
swr_init(m_swr_context.get());
}
const auto res = swr_convert_frame(m_swr_context.get(), pcm16_frame.get(), &frame);
if (res < 0) {
LOG_ERROR(Lib_AvPlayer, "Could not convert to NV12: {}", av_err2str(res));
return AVFramePtr{nullptr, &ReleaseAVFrame};
}
return pcm16_frame;
}
Frame AvPlayerSource::PrepareAudioFrame(FrameBuffer buffer, const AVFrame& frame) {
ASSERT(frame.format == AV_SAMPLE_FMT_S16);
ASSERT(frame.nb_samples <= 1024);
auto p_buffer = buffer.GetBuffer();
const auto size = frame.ch_layout.nb_channels * frame.nb_samples * sizeof(u16);
std::memcpy(p_buffer, frame.data[0], size);
const auto pkt_dts = u64(frame.pkt_dts) * 1000;
const auto stream = m_avformat_context->streams[m_audio_stream_index.value()];
const auto time_base = stream->time_base;
const auto den = time_base.den;
const auto num = time_base.num;
const auto timestamp = (num != 0 && den > 1) ? (pkt_dts * num) / den : pkt_dts;
return Frame{
.buffer = std::move(buffer),
.info =
{
.pData = p_buffer,
.timestamp = timestamp,
.details =
{
.audio =
{
.channel_count = u16(frame.ch_layout.nb_channels),
.sample_rate = u32(frame.sample_rate),
.size = u32(size),
},
},
},
};
}
void AvPlayerSource::AudioDecoderThread(std::stop_token stop) {
using namespace std::chrono;
LOG_INFO(Lib_AvPlayer, "Audio Decoder Thread started");
while ((!m_is_eof || m_audio_packets.Size() != 0) && !stop.stop_requested()) {
if (!m_audio_packets_cv.Wait(stop,
[this] { return m_audio_packets.Size() != 0 || m_is_eof; })) {
continue;
}
const auto packet = m_audio_packets.Pop();
if (!packet.has_value()) {
continue;
}
auto res = avcodec_send_packet(m_audio_codec_context.get(), packet->get());
if (res < 0 && res != AVERROR(EAGAIN)) {
m_state.OnError();
LOG_ERROR(Lib_AvPlayer, "Could not send packet to the audio codec. Error = {}",
av_err2str(res));
return;
}
while (res >= 0) {
if (!m_audio_buffers_cv.Wait(stop, [this] { return m_audio_buffers.Size() != 0; })) {
break;
}
if (m_audio_buffers.Size() == 0) {
continue;
}
auto up_frame = AVFramePtr(av_frame_alloc(), &ReleaseAVFrame);
res = avcodec_receive_frame(m_audio_codec_context.get(), up_frame.get());
if (res < 0) {
if (res == AVERROR_EOF) {
LOG_INFO(Lib_AvPlayer, "EOF reached in audio decoder");
return;
} else if (res != AVERROR(EAGAIN)) {
m_state.OnError();
LOG_ERROR(Lib_AvPlayer,
"Could not receive frame from the audio codec. Error = {}",
av_err2str(res));
return;
}
} else {
auto buffer = m_audio_buffers.Pop();
if (!buffer.has_value()) {
// Audio buffers queue was cleared. This means that player was stopped.
break;
}
if (up_frame->format != AV_SAMPLE_FMT_S16) {
const auto pcm16_frame = ConvertAudioFrame(*up_frame);
m_audio_frames.Push(PrepareAudioFrame(std::move(buffer.value()), *pcm16_frame));
} else {
m_audio_frames.Push(PrepareAudioFrame(std::move(buffer.value()), *up_frame));
}
m_audio_frames_cv.Notify();
}
}
}
LOG_INFO(Lib_AvPlayer, "Audio Decoder Thread exited normaly");
}
bool AvPlayerSource::HasRunningThreads() const {
return m_demuxer_thread.joinable() || m_video_decoder_thread.joinable() ||
m_audio_decoder_thread.joinable();
}
} // namespace Libraries::AvPlayer

View File

@ -1,219 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "avplayer.h"
#include "avplayer_common.h"
#include "avplayer_data_streamer.h"
#include "common/polyfill_thread.h"
#include "common/types.h"
#include "core/libraries/kernel/thread_management.h"
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <optional>
#include <string>
struct AVCodecContext;
struct AVFormatContext;
struct AVFrame;
struct AVIOContext;
struct AVPacket;
struct SwrContext;
struct SwsContext;
namespace Libraries::AvPlayer {
class AvPlayerStateCallback {
public:
virtual ~AvPlayerStateCallback() = default;
virtual void OnWarning(u32 id) = 0;
virtual void OnError() = 0;
virtual void OnEOF() = 0;
};
class FrameBuffer {
public:
FrameBuffer(const SceAvPlayerMemAllocator& memory_replacement, u32 align, u32 size) noexcept
: m_memory_replacement(memory_replacement),
m_data(Allocate(memory_replacement, align, size)) {
ASSERT_MSG(m_data, "Could not allocated frame buffer.");
}
~FrameBuffer() {
if (m_data != nullptr) {
Deallocate(m_memory_replacement, m_data);
m_data = {};
}
}
FrameBuffer(const FrameBuffer&) noexcept = delete;
FrameBuffer& operator=(const FrameBuffer&) noexcept = delete;
FrameBuffer(FrameBuffer&& r) noexcept
: m_memory_replacement(r.m_memory_replacement), m_data(r.m_data) {
r.m_data = nullptr;
};
FrameBuffer& operator=(FrameBuffer&& r) noexcept {
std::swap(m_data, r.m_data);
return *this;
}
u8* GetBuffer() const noexcept {
return m_data;
}
private:
static u8* Allocate(const SceAvPlayerMemAllocator& memory_replacement, u32 align, u32 size) {
return reinterpret_cast<u8*>(
memory_replacement.allocate(memory_replacement.object_ptr, align, size));
}
static void Deallocate(const SceAvPlayerMemAllocator& memory_replacement, void* ptr) {
memory_replacement.deallocate(memory_replacement.object_ptr, ptr);
}
const SceAvPlayerMemAllocator& m_memory_replacement;
u8* m_data = nullptr;
};
struct Frame {
FrameBuffer buffer;
SceAvPlayerFrameInfoEx info;
};
class EventCV {
public:
template <class Pred>
void Wait(Pred pred) {
std::unique_lock lock(m_mutex);
m_cv.wait(lock, std::move(pred));
}
template <class Pred>
bool Wait(std::stop_token stop, Pred pred) {
std::unique_lock lock(m_mutex);
return m_cv.wait(lock, std::move(stop), std::move(pred));
}
template <class Pred, class Rep, class Period>
bool WaitFor(std::chrono::duration<Rep, Period> timeout, Pred pred) {
std::unique_lock lock(m_mutex);
return m_cv.wait_for(lock, timeout, std::move(pred));
}
void Notify() {
std::unique_lock lock(m_mutex);
m_cv.notify_all();
}
private:
std::mutex m_mutex{};
std::condition_variable_any m_cv{};
};
class AvPlayerSource {
public:
AvPlayerSource(AvPlayerStateCallback& state);
~AvPlayerSource();
bool Init(const SceAvPlayerInitData& init_data, std::string_view path);
bool FindStreamInfo();
s32 GetStreamCount();
bool GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info);
bool EnableStream(u32 stream_index);
void SetLooping(bool is_looping);
std::optional<bool> HasFrames(u32 num_frames);
bool Start();
bool Stop();
bool GetAudioData(SceAvPlayerFrameInfo& audio_info);
bool GetVideoData(SceAvPlayerFrameInfo& video_info);
bool GetVideoData(SceAvPlayerFrameInfoEx& video_info);
u64 CurrentTime();
bool IsActive();
private:
using ScePthread = Kernel::ScePthread;
static void ReleaseAVPacket(AVPacket* packet);
static void ReleaseAVFrame(AVFrame* frame);
static void ReleaseAVCodecContext(AVCodecContext* context);
static void ReleaseSWRContext(SwrContext* context);
static void ReleaseSWSContext(SwsContext* context);
static void ReleaseAVFormatContext(AVFormatContext* context);
using AVPacketPtr = std::unique_ptr<AVPacket, decltype(&ReleaseAVPacket)>;
using AVFramePtr = std::unique_ptr<AVFrame, decltype(&ReleaseAVFrame)>;
using AVCodecContextPtr = std::unique_ptr<AVCodecContext, decltype(&ReleaseAVCodecContext)>;
using SWRContextPtr = std::unique_ptr<SwrContext, decltype(&ReleaseSWRContext)>;
using SWSContextPtr = std::unique_ptr<SwsContext, decltype(&ReleaseSWSContext)>;
using AVFormatContextPtr = std::unique_ptr<AVFormatContext, decltype(&ReleaseAVFormatContext)>;
void DemuxerThread(std::stop_token stop);
void VideoDecoderThread(std::stop_token stop);
void AudioDecoderThread(std::stop_token stop);
bool HasRunningThreads() const;
AVFramePtr ConvertAudioFrame(const AVFrame& frame);
AVFramePtr ConvertVideoFrame(const AVFrame& frame);
Frame PrepareAudioFrame(FrameBuffer buffer, const AVFrame& frame);
Frame PrepareVideoFrame(FrameBuffer buffer, const AVFrame& frame);
AvPlayerStateCallback& m_state;
SceAvPlayerMemAllocator m_memory_replacement{};
u32 m_num_output_video_framebuffers{};
std::atomic_bool m_is_looping = false;
std::atomic_bool m_is_eof = false;
std::unique_ptr<IDataStreamer> m_up_data_streamer;
AvPlayerQueue<FrameBuffer> m_audio_buffers;
AvPlayerQueue<FrameBuffer> m_video_buffers;
AvPlayerQueue<AVPacketPtr> m_audio_packets;
AvPlayerQueue<AVPacketPtr> m_video_packets;
AvPlayerQueue<Frame> m_audio_frames;
AvPlayerQueue<Frame> m_video_frames;
std::optional<FrameBuffer> m_current_video_frame;
std::optional<FrameBuffer> m_current_audio_frame;
std::optional<s32> m_video_stream_index{};
std::optional<s32> m_audio_stream_index{};
EventCV m_audio_packets_cv{};
EventCV m_audio_frames_cv{};
EventCV m_audio_buffers_cv{};
EventCV m_video_packets_cv{};
EventCV m_video_frames_cv{};
EventCV m_video_buffers_cv{};
EventCV m_stop_cv{};
std::mutex m_state_mutex{};
std::jthread m_demuxer_thread{};
std::jthread m_video_decoder_thread{};
std::jthread m_audio_decoder_thread{};
AVFormatContextPtr m_avformat_context{nullptr, &ReleaseAVFormatContext};
AVCodecContextPtr m_video_codec_context{nullptr, &ReleaseAVCodecContext};
AVCodecContextPtr m_audio_codec_context{nullptr, &ReleaseAVCodecContext};
SWRContextPtr m_swr_context{nullptr, &ReleaseSWRContext};
SWSContextPtr m_sws_context{nullptr, &ReleaseSWSContext};
std::chrono::high_resolution_clock::time_point m_start_time{};
};
} // namespace Libraries::AvPlayer

View File

@ -1,505 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "avplayer_file_streamer.h"
#include "avplayer_source.h"
#include "avplayer_state.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/kernel/time_management.h"
#include <magic_enum.hpp>
namespace Libraries::AvPlayer {
using namespace Kernel;
void PS4_SYSV_ABI AvPlayerState::AutoPlayEventCallback(void* opaque, s32 event_id, s32 source_id,
void* event_data) {
auto const self = reinterpret_cast<AvPlayerState*>(opaque);
if (event_id == SCE_AVPLAYER_STATE_READY) {
s32 video_stream_index = -1;
s32 audio_stream_index = -1;
s32 timedtext_stream_index = -1;
const s32 stream_count = self->GetStreamCount();
if (AVPLAYER_IS_ERROR(stream_count)) {
self->Stop();
return;
}
if (stream_count == 0) {
self->Stop();
return;
}
for (u32 stream_index = 0; stream_index < stream_count; ++stream_index) {
SceAvPlayerStreamInfo info{};
if (!self->GetStreamInfo(stream_index, info)) {
self->Stop();
return;
}
const std::string_view default_language(
reinterpret_cast<char*>(self->m_default_language));
switch (info.type) {
case SCE_AVPLAYER_VIDEO:
if (video_stream_index == -1) {
video_stream_index = stream_index;
}
if (!default_language.empty() &&
default_language == reinterpret_cast<char*>(info.details.video.language_code)) {
video_stream_index = stream_index;
}
break;
case SCE_AVPLAYER_AUDIO:
if (audio_stream_index == -1) {
audio_stream_index = stream_index;
}
if (!default_language.empty() &&
default_language == reinterpret_cast<char*>(info.details.video.language_code)) {
audio_stream_index = stream_index;
}
break;
case SCE_AVPLAYER_TIMEDTEXT:
if (default_language.empty()) {
timedtext_stream_index = stream_index;
break;
}
if (default_language == reinterpret_cast<char*>(info.details.video.language_code)) {
timedtext_stream_index = stream_index;
}
break;
}
}
if (video_stream_index != -1) {
self->EnableStream(video_stream_index);
}
if (audio_stream_index != -1) {
self->EnableStream(audio_stream_index);
}
if (timedtext_stream_index != -1) {
self->EnableStream(timedtext_stream_index);
}
self->Start();
return;
}
// Pass other events to the game
const auto callback = self->m_event_replacement.event_callback;
const auto ptr = self->m_event_replacement.object_ptr;
if (callback != nullptr) {
callback(ptr, event_id, 0, event_data);
}
}
// Called inside GAME thread
AvPlayerState::AvPlayerState(const SceAvPlayerInitData& init_data)
: m_init_data(init_data), m_event_replacement(init_data.event_replacement) {
if (m_event_replacement.event_callback == nullptr || init_data.auto_start) {
m_auto_start = true;
m_init_data.event_replacement.event_callback = &AvPlayerState::AutoPlayEventCallback;
m_init_data.event_replacement.object_ptr = this;
}
if (init_data.default_language != nullptr) {
std::memcpy(m_default_language, init_data.default_language, sizeof(m_default_language));
}
SetState(AvState::Initial);
StartControllerThread();
}
AvPlayerState::~AvPlayerState() {
{
std::unique_lock lock(m_source_mutex);
m_up_source.reset();
}
if (m_controller_thread.joinable()) {
m_controller_thread.request_stop();
m_controller_thread.join();
}
m_event_queue.Clear();
}
// Called inside GAME thread
bool AvPlayerState::AddSource(std::string_view path, SceAvPlayerSourceType source_type) {
if (path.empty()) {
LOG_ERROR(Lib_AvPlayer, "File path is empty.");
return false;
}
{
std::unique_lock lock(m_source_mutex);
if (m_up_source != nullptr) {
LOG_ERROR(Lib_AvPlayer, "Only one source is supported.");
return false;
}
m_up_source = std::make_unique<AvPlayerSource>(*this);
if (!m_up_source->Init(m_init_data, path)) {
SetState(AvState::Error);
m_up_source.reset();
return false;
}
}
AddSourceEvent();
return true;
}
// Called inside GAME thread
s32 AvPlayerState::GetStreamCount() {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not get stream count. No source.");
return -1;
}
return m_up_source->GetStreamCount();
}
// Called inside GAME thread
bool AvPlayerState::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not get stream {} info. No source.", stream_index);
return false;
}
return m_up_source->GetStreamInfo(stream_index, info);
}
// Called inside GAME thread
bool AvPlayerState::Start() {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr || !m_up_source->Start()) {
LOG_ERROR(Lib_AvPlayer, "Could not start playback.");
return false;
}
SetState(AvState::Play);
OnPlaybackStateChanged(AvState::Play);
return true;
}
void AvPlayerState::AvControllerThread(std::stop_token stop) {
using std::chrono::milliseconds;
while (!stop.stop_requested()) {
if (m_event_queue.Size() != 0) {
ProcessEvent();
continue;
}
std::this_thread::sleep_for(milliseconds(5));
UpdateBufferingState();
}
}
// Called inside GAME thread
void AvPlayerState::AddSourceEvent() {
SetState(AvState::AddingSource);
m_event_queue.Push(AvPlayerEvent{
.event = AvEventType::AddSource,
});
}
void AvPlayerState::WarningEvent(s32 id) {
m_event_queue.Push(AvPlayerEvent{
.event = AvEventType::WarningId,
.payload =
{
.error = id,
},
});
}
// Called inside GAME thread
void AvPlayerState::StartControllerThread() {
m_controller_thread =
std::jthread([this](std::stop_token stop) { this->AvControllerThread(stop); });
}
// Called inside GAME thread
bool AvPlayerState::EnableStream(u32 stream_index) {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
return false;
}
return m_up_source->EnableStream(stream_index);
}
// Called inside GAME thread
bool AvPlayerState::Stop() {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr || m_current_state == AvState::Stop) {
return false;
}
if (!m_up_source->Stop()) {
return false;
}
if (!SetState(AvState::Stop)) {
return false;
}
OnPlaybackStateChanged(AvState::Stop);
return true;
}
bool AvPlayerState::GetVideoData(SceAvPlayerFrameInfo& video_info) {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
return false;
}
return m_up_source->GetVideoData(video_info);
}
bool AvPlayerState::GetVideoData(SceAvPlayerFrameInfoEx& video_info) {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
return false;
}
return m_up_source->GetVideoData(video_info);
}
bool AvPlayerState::GetAudioData(SceAvPlayerFrameInfo& audio_info) {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
return false;
}
return m_up_source->GetAudioData(audio_info);
}
bool AvPlayerState::IsActive() {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
return false;
}
return m_current_state != AvState::Stop && m_current_state != AvState::Error &&
m_current_state != AvState::EndOfFile && m_up_source->IsActive();
}
u64 AvPlayerState::CurrentTime() {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not get current time. No source.");
return 0;
}
return m_up_source->CurrentTime();
}
bool AvPlayerState::SetLooping(bool is_looping) {
std::shared_lock lock(m_source_mutex);
if (m_up_source == nullptr) {
LOG_ERROR(Lib_AvPlayer, "Could not set loop flag. No source.");
return false;
}
m_up_source->SetLooping(is_looping);
return true;
}
// May be called from different threads
void AvPlayerState::OnWarning(u32 id) {
// Forward to CONTROLLER thread
WarningEvent(id);
}
void AvPlayerState::OnError() {
SetState(AvState::Error);
OnPlaybackStateChanged(AvState::Error);
}
void AvPlayerState::OnEOF() {
SetState(AvState::EndOfFile);
}
// Called inside CONTROLLER thread
void AvPlayerState::OnPlaybackStateChanged(AvState state) {
switch (state) {
case AvState::Ready: {
EmitEvent(SCE_AVPLAYER_STATE_READY);
break;
}
case AvState::Play: {
EmitEvent(SCE_AVPLAYER_STATE_PLAY);
break;
}
case AvState::Stop: {
EmitEvent(SCE_AVPLAYER_STATE_STOP);
break;
}
case AvState::Pause: {
EmitEvent(SCE_AVPLAYER_STATE_PAUSE);
break;
}
case AvState::Buffering: {
EmitEvent(SCE_AVPLAYER_STATE_BUFFERING);
break;
}
default:
break;
}
}
// Called inside CONTROLLER and GAME threads
bool AvPlayerState::SetState(AvState state) {
std::lock_guard guard(m_state_machine_mutex);
if (!IsStateTransitionValid(state)) {
LOG_ERROR(Lib_AvPlayer, "Invalid state transition: {} -> {}",
magic_enum::enum_name(m_current_state.load()), magic_enum::enum_name(state));
return false;
}
m_previous_state.store(m_current_state);
m_current_state.store(state);
return true;
}
// Called inside CONTROLLER thread
std::optional<bool> AvPlayerState::OnBufferingCheckEvent(u32 num_frames) {
std::shared_lock lock(m_source_mutex);
if (!m_up_source) {
return std::nullopt;
}
return m_up_source->HasFrames(num_frames);
}
// Called inside CONTROLLER thread
void AvPlayerState::EmitEvent(SceAvPlayerEvents event_id, void* event_data) {
LOG_INFO(Lib_AvPlayer, "Sending event to the game: id = {}", magic_enum::enum_name(event_id));
const auto callback = m_init_data.event_replacement.event_callback;
if (callback) {
const auto ptr = m_init_data.event_replacement.object_ptr;
callback(ptr, event_id, 0, event_data);
}
}
// Called inside CONTROLLER thread
void AvPlayerState::ProcessEvent() {
if (m_current_state == AvState::Jump) {
return;
}
std::lock_guard guard(m_event_handler_mutex);
auto event = m_event_queue.Pop();
if (!event.has_value()) {
return;
}
switch (event->event) {
case AvEventType::WarningId: {
OnWarning(event->payload.error);
break;
}
case AvEventType::RevertState: {
SetState(m_previous_state.load());
break;
}
case AvEventType::AddSource: {
std::shared_lock lock(m_source_mutex);
if (m_up_source->FindStreamInfo()) {
SetState(AvState::Ready);
OnPlaybackStateChanged(AvState::Ready);
} else {
OnWarning(ORBIS_AVPLAYER_ERROR_NOT_SUPPORTED);
SetState(AvState::Error);
}
break;
}
case AvEventType::Error: {
OnWarning(event->payload.error);
SetState(AvState::Error);
break;
}
default:
break;
}
}
// Called inside CONTROLLER thread
void AvPlayerState::UpdateBufferingState() {
if (m_current_state == AvState::Buffering) {
const auto has_frames = OnBufferingCheckEvent(10);
if (!has_frames.has_value()) {
return;
}
if (has_frames.value()) {
const auto state =
m_previous_state >= AvState::C0x0B ? m_previous_state.load() : AvState::Play;
SetState(state);
OnPlaybackStateChanged(state);
}
} else if (m_current_state == AvState::Play) {
const auto has_frames = OnBufferingCheckEvent(0);
if (!has_frames.has_value()) {
return;
}
if (!has_frames.value()) {
SetState(AvState::Buffering);
OnPlaybackStateChanged(AvState::Buffering);
}
}
}
bool AvPlayerState::IsStateTransitionValid(AvState state) {
switch (state) {
case AvState::Play: {
switch (m_current_state.load()) {
case AvState::Stop:
case AvState::EndOfFile:
// case AvState::C0x08:
case AvState::Error:
return false;
default:
return true;
}
}
case AvState::Pause: {
switch (m_current_state.load()) {
case AvState::Stop:
case AvState::EndOfFile:
// case AvState::C0x08:
case AvState::Starting:
case AvState::Error:
return false;
default:
return true;
}
}
case AvState::Jump: {
switch (m_current_state.load()) {
case AvState::Stop:
case AvState::EndOfFile:
// case AvState::C0x08:
case AvState::TrickMode:
case AvState::Starting:
case AvState::Error:
return false;
default:
return true;
}
}
case AvState::TrickMode: {
switch (m_current_state.load()) {
case AvState::Stop:
case AvState::EndOfFile:
// case AvState::C0x08:
case AvState::Jump:
case AvState::Starting:
case AvState::Error:
return false;
default:
return true;
}
}
case AvState::Buffering: {
switch (m_current_state.load()) {
case AvState::Stop:
case AvState::EndOfFile:
case AvState::Pause:
// case AvState::C0x08:
case AvState::Starting:
case AvState::Error:
return false;
default:
return true;
}
}
default:
return true;
}
}
} // namespace Libraries::AvPlayer

View File

@ -1,88 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "avplayer.h"
#include "avplayer_data_streamer.h"
#include "avplayer_source.h"
#include "common/polyfill_thread.h"
#include "core/libraries/kernel/thread_management.h"
#include <memory>
#include <mutex>
#include <shared_mutex>
namespace Libraries::AvPlayer {
class Stream;
class AvDecoder;
class AvPlayerState : public AvPlayerStateCallback {
public:
AvPlayerState(const SceAvPlayerInitData& init_data);
~AvPlayerState();
bool AddSource(std::string_view filename, SceAvPlayerSourceType source_type);
s32 GetStreamCount();
bool GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info);
bool EnableStream(u32 stream_index);
bool Start();
bool Stop();
bool GetAudioData(SceAvPlayerFrameInfo& audio_info);
bool GetVideoData(SceAvPlayerFrameInfo& video_info);
bool GetVideoData(SceAvPlayerFrameInfoEx& video_info);
bool IsActive();
u64 CurrentTime();
bool SetLooping(bool is_looping);
private:
using ScePthreadMutex = Kernel::ScePthreadMutex;
using ScePthread = Kernel::ScePthread;
// Event Replacement
static void PS4_SYSV_ABI AutoPlayEventCallback(void* handle, s32 event_id, s32 source_id,
void* event_data);
void OnWarning(u32 id) override;
void OnError() override;
void OnEOF() override;
void OnPlaybackStateChanged(AvState state);
std::optional<bool> OnBufferingCheckEvent(u32 num_frames);
void EmitEvent(SceAvPlayerEvents event_id, void* event_data = nullptr);
bool SetState(AvState state);
void AvControllerThread(std::stop_token stop);
void AddSourceEvent();
void WarningEvent(s32 id);
void StartControllerThread();
void ProcessEvent();
void UpdateBufferingState();
bool IsStateTransitionValid(AvState state);
std::unique_ptr<AvPlayerSource> m_up_source;
SceAvPlayerInitData m_init_data{};
SceAvPlayerEventReplacement m_event_replacement{};
bool m_auto_start{};
u8 m_default_language[4]{};
std::atomic<AvState> m_current_state;
std::atomic<AvState> m_previous_state;
u32 m_thread_priority;
u32 m_thread_affinity;
std::atomic_uint32_t m_some_event_result{};
std::shared_mutex m_source_mutex{};
std::mutex m_state_machine_mutex{};
std::mutex m_event_handler_mutex{};
std::jthread m_controller_thread{};
AvPlayerQueue<AvPlayerEvent> m_event_queue{};
};
} // namespace Libraries::AvPlayer

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Generated By moduleGenerator
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Generated By moduleGenerator
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"

View File

@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// Generated By moduleGenerator
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"

View File

@ -233,6 +233,9 @@ constexpr int SCE_KERNEL_ERROR_ESDKVERSION = 0x80020063;
constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064;
constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065;
// libSceRandom error codes
constexpr int SCE_RANDOM_ERROR_INVALID = 0x817C0016;
// videoOut
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; // invalid addresses
@ -246,6 +249,14 @@ constexpr int SCE_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; // slot alr
constexpr int SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; // flip queue is full
constexpr int SCE_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; // Invalid buffer attribute option
// GnmDriver
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_PIPE_ID = 0x80D17000;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_QUEUE_ID = 0x80D17001;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_BASE_ADDR = 0x80D17003;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_SIZE = 0x80D17002;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_READ_PTR_ADDR = 0x80D17004;
constexpr int ORBIS_GNM_ERROR_FAILURE = 0x8EEE00FF;
// Generic
constexpr int ORBIS_OK = 0x00000000;
constexpr int ORBIS_FAIL = 0xFFFFFFFF;
@ -446,20 +457,5 @@ constexpr int ORBIS_NP_TROPHY_ERROR_HANDLE_EXCEEDS_MAX = 0x80551624;
constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_ALREADY_EXISTS = 0x80551613;
constexpr int ORBIS_NP_TROPHY_ERROR_CONTEXT_EXCEEDS_MAX = 0x80551622;
// AvPlayer library
constexpr int ORBIS_AVPLAYER_ERROR_INVALID_PARAMS = 0x806A0001;
constexpr int ORBIS_AVPLAYER_ERROR_OPERATION_FAILED = 0x806A0002;
constexpr int ORBIS_AVPLAYER_ERROR_NO_MEMORY = 0x806A0003;
constexpr int ORBIS_AVPLAYER_ERROR_NOT_SUPPORTED = 0x806A0004;
constexpr int ORBIS_AVPLAYER_ERROR_WAR_FILE_NONINTERLEAVED = 0x806A00A0;
constexpr int ORBIS_AVPLAYER_ERROR_WAR_LOOPING_BACK = 0x806A00A1;
constexpr int ORBIS_AVPLAYER_ERROR_WAR_JUMP_COMPLETE = 0x806A00A3;
constexpr int ORBIS_AVPLAYER_ERROR_INFO_MARLIN_ENCRY = 0x806A00B0;
constexpr int ORBIS_AVPLAYER_ERROR_INFO_PLAYREADY_ENCRY = 0x806A00B4;
constexpr int ORBIS_AVPLAYER_ERROR_INFO_AES_ENCRY = 0x806A00B5;
constexpr int ORBIS_AVPLAYER_ERROR_INFO_OTHER_ENCRY = 0x806A00BF;
// AppContent library
constexpr int ORBIS_APP_CONTENT_ERROR_PARAMETER = 0x80D90002;
constexpr int ORBIS_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT = 0x80D90007;
constexpr int ORBIS_APP_CONTENT_ERROR_NOT_FOUND = 0x80D90005;

View File

@ -1,85 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
constexpr int ORBIS_GNM_ERROR_SUBMISSION_FAILED_INVALID_ARGUMENT = 0x80D11000;
constexpr int ORBIS_GNM_ERROR_SUBMISSION_NOT_ENOUGH_RESOURCES = 0x80D11001;
constexpr int ORBIS_GNM_ERROR_SUBMISSION_AND_FLIP_FAILED_INVALID_COMMAND_BUFFER = 0x80D11080;
constexpr int ORBIS_GNM_ERROR_SUBMISSION_AND_FLIP_FAILED_INVALID_QUEUE_FULL = 0x80D11081;
constexpr int ORBIS_GNM_ERROR_SUBMISSION_AND_FLIP_FAILED_REQUEST_FAILED = 0x80D11082;
constexpr int ORBIS_GNM_ERROR_SUBMISSION_FAILED_INTERNAL_ERROR = 0x80D110FF;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING = 0x80D12000;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_RWBUFFER_ROTYPE = 0x80D12001;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_BLENDING = 0x80D12002;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_DRAW_CU_MASK = 0x80D12003;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_MRT_SETUP = 0x80D12004;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_DEPTH_RT_SETUP = 0x80D12005;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_PS_AND_MRT_FORMAT = 0x80D1200F;
constexpr int ORBIS_GNM_ERROR_VALIDATION_ERROR = 0x80D13000;
constexpr int ORBIS_GNM_ERROR_VALIDATION_VSHARP = 0x80D13001;
constexpr int ORBIS_GNM_ERROR_VALIDATION_TSHARP = 0x80D13002;
constexpr int ORBIS_GNM_ERROR_VALIDATION_RESOURCE = 0x80D13003;
constexpr int ORBIS_GNM_ERROR_VALIDATION_TABLE_MEMORY = 0x80D13004;
constexpr int ORBIS_GNM_ERROR_VALIDATION_WRITE_EVENT_OP = 0x80D13005;
constexpr int ORBIS_GNM_ERROR_VALIDATION_INDEX_BUFFER = 0x80D13006;
constexpr int ORBIS_GNM_ERROR_VALIDATION_TESS_FACTOR_BUFFER = 0x80D13007;
constexpr int ORBIS_GNM_ERROR_VALIDATION_SCRATCH_RING = 0x80D13008;
constexpr int ORBIS_GNM_ERROR_VALIDATION_PRIMITIVE_TYPE = 0x80D13009;
constexpr int ORBIS_GNM_ERROR_VALIDATION_INDEX_SIZE = 0x80D1300A;
constexpr int ORBIS_GNM_ERROR_VALIDATION_INLINE_DRAW_SIZE = 0x80D1300B;
constexpr int ORBIS_GNM_ERROR_VALIDATION_NUM_INPUT_PATCHES = 0x80D1300C;
constexpr int ORBIS_GNM_ERROR_VALIDATION_GS_MODE = 0x80D1300D;
constexpr int ORBIS_GNM_ERROR_VALIDATION_SHADER_ADDRESS = 0x80D1300E;
constexpr int ORBIS_GNM_ERROR_VALIDATION_BORDER_COLOR_TABLE = 0x80D1300F;
constexpr int ORBIS_GNM_ERROR_VALIDATION_SSHARP = 0x80D13010;
constexpr int ORBIS_GNM_ERROR_VALIDATION_DISPATCH_DRAW = 0x80D13011;
constexpr int ORBIS_GNM_ERROR_VALIDATION_ACTIVE_SHADER_STAGE = 0x80D13012;
constexpr int ORBIS_GNM_ERROR_VALIDATION_DCB = 0x80D13013;
constexpr int ORBIS_GNM_ERROR_VALIDATION_MISMATCH_SHADER_STAGE = 0x80D13014;
constexpr int ORBIS_GNM_ERROR_VALIDATION_MRT_SETUP = 0x80D13015;
constexpr int ORBIS_GNM_ERROR_VALIDATION_BAD_OP_CODE = 0x80D13016;
constexpr int ORBIS_GNM_ERROR_VALIDATION_DEPTH_RT_SETUP = 0x80D13017;
constexpr int ORBIS_GNM_ERROR_VALIDATION_NUM_INSTANCES = 0x80D13018;
constexpr int ORBIS_GNM_ERROR_VALIDATION_SRT = 0x80D13019;
constexpr int ORBIS_GNM_ERROR_VALIDATION_INVALID_ARGUMENT = 0x80D13FFD;
constexpr int ORBIS_GNM_ERROR_VALIDATION_FAILED_INTERNAL_ERROR = 0x80D13FFE;
constexpr int ORBIS_GNM_ERROR_VALIDATION_NOT_ENABLED = 0x80D13FFF;
constexpr int ORBIS_GNM_ERROR_CAPTURE_FILE_IO = 0x80D15000;
constexpr int ORBIS_GNM_ERROR_CAPTURE_RAZOR_NOT_LOADED = 0x80D15001;
constexpr int ORBIS_GNM_ERROR_CAPTURE_NOTHING_TO_CAPTURE = 0x80D15002;
constexpr int ORBIS_GNM_ERROR_CAPTURE_FAILED_INTERNAL = 0x80D1500F;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_PIPE_ID = 0x80D17000;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_QUEUE_ID = 0x80D17001;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_SIZE = 0x80D17002;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_BASE_ADDR = 0x80D17003;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_READ_PTR_ADDR = 0x80D17004;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_PIPE_PRIORITY = 0x80D17005;
constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INTERNAL = 0x80D170FF;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_ARGUMENT = 0x80D19000;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_SHADER = 0x80D19001;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_STALE_HANDLE = 0x80D19002;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_FULL = 0x80D19003;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_NOT_PERMITTED = 0x80D19004;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_OUTPUT_ARGUMENT_IS_NULL = 0x80D19005;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_OWNER_HANDLE_INVALID = 0x80D19006;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_HANDLE_INVALID = 0x80D19007;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_TYPE_INVALID = 0x80D19008;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_GDS_RESOURCE_TYPE_INVALID = 0x80D19009;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_SIZE_INVALID = 0x80D1900A;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_ADDRESS_IS_NULL = 0x80D1900B;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_GDS_OFFSET_INVALID = 0x80D1900C;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_NAME_IS_NULL = 0x80D1900D;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_OWNER_NAME_IS_NULL = 0x80D1900E;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_FIND_CALLBACK_IS_NULL = 0x80D1900F;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_IS_NOT_SHADER = 0x80D19010;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_USER_MEMORY_PARAM_IS_NULL = 0x80D19011;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_USER_MEMORY_PARAM_NOT_ALIGNED = 0x80D19012;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_NAME_LENGTH_PARAM = 0x80D19013;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_SIZE_PARAM = 0x80D19014;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_NUM_RESOURCES_PARAM = 0x80D19015;
constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INTERNAL = 0x80D19FFF;
constexpr int ORBIS_GNM_ERROR_GET_GPU_INFO_PARAMETER_NULL = 0x80D1B000;
constexpr int ORBIS_GNM_ERROR_GET_GPU_INFO_FAILED = 0x80D1B001;
constexpr int ORBIS_GNM_ERROR_GET_GPU_INFO_PARAMETER_INVALID = 0x80D1B002;
constexpr int ORBIS_GNM_ERROR_FAILURE = 0x8EEE00FF;

View File

@ -1,9 +1,6 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "gnm_error.h"
#include "gnmdriver.h"
#include "common/assert.h"
#include "common/config.h"
#include "common/debug.h"
@ -12,6 +9,7 @@
#include "common/slot_vector.h"
#include "core/address_space.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/gnmdriver/gnmdriver.h"
#include "core/libraries/kernel/libkernel.h"
#include "core/libraries/libs.h"
#include "core/libraries/videoout/video_out.h"
@ -57,10 +55,6 @@ static constexpr auto HwInitPacketSize = 0x100u;
// clang-format off
static constexpr std::array InitSequence{
// A fake preamble to mimic context reset sent by FW
0xc0001200u, 0u, // IT_CLEAR_STATE
// Actual init state sequence
0xc0017600u, 0x216u, 0xffffffffu,
0xc0017600u, 0x217u, 0xffffffffu,
0xc0017600u, 0x215u, 0u,
@ -100,13 +94,9 @@ static constexpr std::array InitSequence{
0xc0036900u, 0x295u, 0x100u, 0x100u, 4u,
0xc0017900u, 0x200u, 0xe0000000u,
};
static_assert(InitSequence.size() == 0x73 + 2);
static_assert(InitSequence.size() == 0x73);
static constexpr std::array InitSequence175{
// A fake preamble to mimic context reset sent by FW
0xc0001200u, 0u, // IT_CLEAR_STATE
// Actual init state sequence
0xc0017600u, 0x216u, 0xffffffffu,
0xc0017600u, 0x217u, 0xffffffffu,
0xc0017600u, 0x215u, 0u,
@ -146,13 +136,9 @@ static constexpr std::array InitSequence175{
0xc0036900u, 0x295u, 0x100u, 0x100u, 4u,
0xc0017900u, 0x200u, 0xe0000000u,
};
static_assert(InitSequence175.size() == 0x73 + 2);
static_assert(InitSequence175.size() == 0x73);
static constexpr std::array InitSequence200{
// A fake preamble to mimic context reset sent by FW
0xc0001200u, 0u, // IT_CLEAR_STATE
// Actual init state sequence
0xc0017600u, 0x216u, 0xffffffffu,
0xc0017600u, 0x217u, 0xffffffffu,
0xc0017600u, 0x215u, 0u,
@ -193,13 +179,9 @@ static constexpr std::array InitSequence200{
0xc0036900u, 0x295u, 0x100u, 0x100u, 4u,
0xc0017900u, 0x200u, 0xe0000000u,
};
static_assert(InitSequence200.size() == 0x76 + 2);
static_assert(InitSequence200.size() == 0x76);
static constexpr std::array InitSequence350{
// A fake preamble to mimic context reset sent by FW
0xc0001200u, 0u, // IT_CLEAR_STATE
// Actual init state sequence
0xc0017600u, 0x216u, 0xffffffffu,
0xc0017600u, 0x217u, 0xffffffffu,
0xc0017600u, 0x215u, 0u,
@ -242,7 +224,7 @@ static constexpr std::array InitSequence350{
0xc0017900u, 0x200u, 0xe0000000u,
0xc0016900u, 0x2aau, 0xffu,
};
static_assert(InitSequence350.size() == 0x7c + 2);
static_assert(InitSequence350.size() == 0x7c);
static constexpr std::array CtxInitSequence{
0xc0012800u, 0x80000000u, 0x80000000u,
@ -650,12 +632,12 @@ s32 PS4_SYSV_ABI sceGnmDrawIndexAuto(u32* cmdbuf, u32 size, u32 index_count, u32
}
s32 PS4_SYSV_ABI sceGnmDrawIndexIndirect(u32* cmdbuf, u32 size, u32 data_offset, u32 shader_stage,
u32 vertex_sgpr_offset, u32 instance_sgpr_offset,
u32 vertex_sgpr_offset, u32 instance_vgpr_offset,
u32 flags) {
LOG_TRACE(Lib_GnmDriver, "called");
if (cmdbuf && (size == 9) && (shader_stage < ShaderStages::Max) &&
(vertex_sgpr_offset < 0x10u) && (instance_sgpr_offset < 0x10u)) {
(vertex_sgpr_offset < 0x10u) && (instance_vgpr_offset < 0x10u)) {
const auto predicate = flags & 1 ? PM4Predicate::PredEnable : PM4Predicate::PredDisable;
cmdbuf = WriteHeader<PM4ItOpcode::DrawIndexIndirect>(
@ -665,7 +647,7 @@ s32 PS4_SYSV_ABI sceGnmDrawIndexIndirect(u32* cmdbuf, u32 size, u32 data_offset,
cmdbuf[0] = data_offset;
cmdbuf[1] = vertex_sgpr_offset == 0 ? 0 : (vertex_sgpr_offset & 0xffffu) + sgpr_offset;
cmdbuf[2] = instance_sgpr_offset == 0 ? 0 : (instance_sgpr_offset & 0xffffu) + sgpr_offset;
cmdbuf[2] = instance_vgpr_offset == 0 ? 0 : (instance_vgpr_offset & 0xffffu) + sgpr_offset;
cmdbuf[3] = 0;
cmdbuf += 4;
@ -707,11 +689,11 @@ s32 PS4_SYSV_ABI sceGnmDrawIndexOffset(u32* cmdbuf, u32 size, u32 index_offset,
}
s32 PS4_SYSV_ABI sceGnmDrawIndirect(u32* cmdbuf, u32 size, u32 data_offset, u32 shader_stage,
u32 vertex_sgpr_offset, u32 instance_sgpr_offset, u32 flags) {
u32 vertex_sgpr_offset, u32 instance_vgpr_offset, u32 flags) {
LOG_TRACE(Lib_GnmDriver, "called");
if (cmdbuf && (size == 9) && (shader_stage < ShaderStages::Max) &&
(vertex_sgpr_offset < 0x10u) && (instance_sgpr_offset < 0x10u)) {
(vertex_sgpr_offset < 0x10u) && (instance_vgpr_offset < 0x10u)) {
const auto predicate = flags & 1 ? PM4Predicate::PredEnable : PM4Predicate::PredDisable;
cmdbuf = WriteHeader<PM4ItOpcode::DrawIndirect>(cmdbuf, 4, PM4ShaderType::ShaderGraphics,
@ -721,7 +703,7 @@ s32 PS4_SYSV_ABI sceGnmDrawIndirect(u32* cmdbuf, u32 size, u32 data_offset, u32
cmdbuf[0] = data_offset;
cmdbuf[1] = vertex_sgpr_offset == 0 ? 0 : (vertex_sgpr_offset & 0xffffu) + sgpr_offset;
cmdbuf[2] = instance_sgpr_offset == 0 ? 0 : (instance_sgpr_offset & 0xffffu) + sgpr_offset;
cmdbuf[2] = instance_vgpr_offset == 0 ? 0 : (instance_vgpr_offset & 0xffffu) + sgpr_offset;
cmdbuf[3] = 2; // auto index
cmdbuf += 4;
@ -753,11 +735,11 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState(u32* cmdbuf, u32 size) {
cmdbuf = ClearContextState(cmdbuf);
}
std::memcpy(cmdbuf, &InitSequence[2], (InitSequence.size() - 2) * 4);
cmdbuf += InitSequence.size() - 2;
std::memcpy(cmdbuf, InitSequence.data(), InitSequence.size() * 4);
cmdbuf += InitSequence.size();
const auto cmdbuf_left =
HwInitPacketSize - (InitSequence.size() - 2) - (clear_state ? 0xc : 0) - 1;
HwInitPacketSize - InitSequence.size() - (clear_state ? 0xc : 0) - 1;
cmdbuf = WriteHeader<PM4ItOpcode::Nop>(cmdbuf, cmdbuf_left);
cmdbuf = WriteBody(cmdbuf, 0u);
@ -775,10 +757,10 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState175(u32* cmdbuf, u32 size) {
}
cmdbuf = ClearContextState(cmdbuf);
std::memcpy(cmdbuf, &InitSequence175[2], (InitSequence175.size() - 2) * 4);
cmdbuf += InitSequence175.size() - 2;
std::memcpy(cmdbuf, InitSequence175.data(), InitSequence175.size() * 4);
cmdbuf += InitSequence175.size();
constexpr auto cmdbuf_left = HwInitPacketSize - (InitSequence175.size() - 2) - 0xc - 1;
constexpr auto cmdbuf_left = HwInitPacketSize - InitSequence175.size() - 0xc - 1;
WriteTrailingNop<cmdbuf_left>(cmdbuf);
return HwInitPacketSize;
@ -796,11 +778,11 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState200(u32* cmdbuf, u32 size) {
cmdbuf = ClearContextState(cmdbuf);
}
std::memcpy(cmdbuf, &InitSequence200[2], (InitSequence200.size() - 2) * 4);
cmdbuf += InitSequence200.size() - 2;
std::memcpy(cmdbuf, InitSequence200.data(), InitSequence200.size() * 4);
cmdbuf += InitSequence200.size();
const auto cmdbuf_left =
HwInitPacketSize - (InitSequence200.size() - 2) - (clear_state ? 0xc : 0) - 1;
HwInitPacketSize - InitSequence200.size() - (clear_state ? 0xc : 0) - 1;
cmdbuf = WriteHeader<PM4ItOpcode::Nop>(cmdbuf, cmdbuf_left);
cmdbuf = WriteBody(cmdbuf, 0u);
@ -822,11 +804,11 @@ u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState350(u32* cmdbuf, u32 size) {
cmdbuf = ClearContextState(cmdbuf);
}
std::memcpy(cmdbuf, &InitSequence350[2], (InitSequence350.size() - 2) * 4);
cmdbuf += InitSequence350.size() - 2;
std::memcpy(cmdbuf, InitSequence350.data(), InitSequence350.size() * 4);
cmdbuf += InitSequence350.size();
const auto cmdbuf_left =
HwInitPacketSize - (InitSequence350.size() - 2) - (clear_state ? 0xc : 0) - 1;
HwInitPacketSize - InitSequence350.size() - (clear_state ? 0xc : 0) - 1;
cmdbuf = WriteHeader<PM4ItOpcode::Nop>(cmdbuf, cmdbuf_left);
cmdbuf = WriteBody(cmdbuf, 0u);
@ -1761,7 +1743,7 @@ s32 PS4_SYSV_ABI sceGnmSetVsShader(u32* cmdbuf, u32 size, const u32* vs_regs, u3
return -1;
}
const u32 var = shader_modifier == 0 ? vs_regs[2] : (vs_regs[2] & 0xfcfffc3f) | shader_modifier;
const u32 var = shader_modifier == 0 ? vs_regs[2] : (vs_regs[2] & 0xfcfffc3f | shader_modifier);
cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x48u, vs_regs[0], 0u); // SPI_SHADER_PGM_LO_VS
cmdbuf = PM4CmdSetData::SetShReg(cmdbuf, 0x4au, var, vs_regs[3]); // SPI_SHADER_PGM_RSRC1_VS
cmdbuf = PM4CmdSetData::SetContextReg(cmdbuf, 0x207u, vs_regs[6]); // PA_CL_VS_OUT_CNTL

View File

@ -45,7 +45,7 @@ s32 PS4_SYSV_ABI sceGnmDrawIndex(u32* cmdbuf, u32 size, u32 index_count, uintptr
u32 flags, u32 type);
s32 PS4_SYSV_ABI sceGnmDrawIndexAuto(u32* cmdbuf, u32 size, u32 index_count, u32 flags);
s32 PS4_SYSV_ABI sceGnmDrawIndexIndirect(u32* cmdbuf, u32 size, u32 data_offset, u32 shader_stage,
u32 vertex_sgpr_offset, u32 instance_sgpr_offset,
u32 vertex_sgpr_offset, u32 instance_vgpr_offset,
u32 flags);
int PS4_SYSV_ABI sceGnmDrawIndexIndirectCountMulti();
int PS4_SYSV_ABI sceGnmDrawIndexIndirectMulti();
@ -53,7 +53,7 @@ int PS4_SYSV_ABI sceGnmDrawIndexMultiInstanced();
s32 PS4_SYSV_ABI sceGnmDrawIndexOffset(u32* cmdbuf, u32 size, u32 index_offset, u32 index_count,
u32 flags);
s32 PS4_SYSV_ABI sceGnmDrawIndirect(u32* cmdbuf, u32 size, u32 data_offset, u32 shader_stage,
u32 vertex_sgpr_offset, u32 instance_sgpr_offset, u32 flags);
u32 vertex_sgpr_offset, u32 instance_vgpr_offset, u32 flags);
int PS4_SYSV_ABI sceGnmDrawIndirectCountMulti();
int PS4_SYSV_ABI sceGnmDrawIndirectMulti();
u32 PS4_SYSV_ABI sceGnmDrawInitDefaultHardwareState(u32* cmdbuf, u32 size);

View File

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "common/assert.h"
#include <common/assert.h>
#include "common/logging/log.h"
#include "core/libraries/error_codes.h"
#include "core/libraries/libs.h"

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <thread>
#include "core/libraries/error_codes.h"
#include "event_flag_obj.h"

View File

@ -2,10 +2,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <condition_variable>
#include <mutex>
#include "common/types.h"
namespace Libraries::Kernel {

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <thread>
#include "common/assert.h"
#include "core/libraries/kernel/event_queue.h"

View File

@ -208,7 +208,4 @@ int PS4_SYSV_ABI sceKernelDeleteUserEvent(SceKernelEqueue eq, int id) {
return ORBIS_OK;
}
s16 PS4_SYSV_ABI sceKernelGetEventFilter(const SceKernelEvent* ev) {
return ev->filter;
}
} // namespace Libraries::Kernel

View File

@ -21,6 +21,5 @@ int PS4_SYSV_ABI sceKernelDeleteUserEvent(SceKernelEqueue eq, int id);
int PS4_SYSV_ABI sceKernelAddUserEvent(SceKernelEqueue eq, int id);
int PS4_SYSV_ABI sceKernelAddUserEventEdge(SceKernelEqueue eq, int id);
s32 PS4_SYSV_ABI sceKernelAddHRTimerEvent(SceKernelEqueue eq, int id, timespec* ts, void* udata);
s16 PS4_SYSV_ABI sceKernelGetEventFilter(const SceKernelEvent* ev);
} // namespace Libraries::Kernel

Some files were not shown because too many files have changed in this diff Show More