mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 01:49:39 -06:00
Compare commits
77 Commits
1.2.49
...
Canary-1.2
Author | SHA1 | Date | |
---|---|---|---|
1ed2aea029 | |||
34caa03385 | |||
104701e80d | |||
cef88febb2 | |||
5fccfb76b9 | |||
4cb5946be4 | |||
e1dfb48e23 | |||
6d8738c048 | |||
abfcfcaf0f | |||
d404a8b05b | |||
42cbe24bb1 | |||
79ba9d1258 | |||
826ffd4a04 | |||
7369079459 | |||
a506d81989 | |||
15c20920b3 | |||
285ee276b6 | |||
617b81e209 | |||
eb6ce7bcb3 | |||
69f75f2df1 | |||
10c8d73b60 | |||
e01a30016e | |||
e26625dfd5 | |||
9c82d98ec4 | |||
4aae82bad1 | |||
299be822c4 | |||
b17e4f79fb | |||
a7b58df3fe | |||
8c2d6192ba | |||
2a23000fed | |||
ab7d0a2e6d | |||
bd2681b2f9 | |||
640d7f9e77 | |||
02e8278438 | |||
6acd86c890 | |||
708256ce96 | |||
5bf50836e1 | |||
730ba44043 | |||
36c374cc7a | |||
75f714488e | |||
4831965404 | |||
47b8145809 | |||
20cc21add6 | |||
683baec1af | |||
f4957d2a09 | |||
3e1182af22 | |||
6664ed1b11 | |||
0c88b9eff7 | |||
8a064bcd7e | |||
5ff962be37 | |||
d9c8b7d937 | |||
feeeafe8fe | |||
04f014c777 | |||
4a677deb50 | |||
1c07bf3dd0 | |||
4c83794254 | |||
6911e288bc | |||
67ab54e2bb | |||
139c195eb7 | |||
9305d171e7 | |||
fb4ab5ea08 | |||
d7e17abade | |||
bdb92224f9 | |||
b21740c931 | |||
4f06c343a4 | |||
6c6f18509b | |||
70b7c4c1c3 | |||
7764a74a6d | |||
5de2c4f292 | |||
5845787325 | |||
9c94db1130 | |||
1c3347c95a | |||
b70580bc9f | |||
4926df42a4 | |||
7038a902c3 | |||
6be8838043 | |||
033ea86c1b |
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -61,11 +61,11 @@ jobs:
|
||||
if: matrix.platform.name != 'linux-arm64'
|
||||
|
||||
- name: Publish Ryujinx
|
||||
run: dotnet publish -c "${{ matrix.configuration }}" -r "${{ matrix.platform.name }}" -o ./publish -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:DebugType=embedded -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER src/Ryujinx --self-contained true
|
||||
run: dotnet publish -c "${{ matrix.configuration }}" -r "${{ matrix.platform.name }}" -o ./publish -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:DebugType=embedded -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER src/Ryujinx --self-contained
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Publish Ryujinx.Headless.SDL2
|
||||
run: dotnet publish -c "${{ matrix.configuration }}" -r "${{ matrix.platform.name }}" -o ./publish_sdl2_headless -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:DebugType=embedded -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER src/Ryujinx.Headless.SDL2 --self-contained true
|
||||
run: dotnet publish -c "${{ matrix.configuration }}" -r "${{ matrix.platform.name }}" -o ./publish_sdl2_headless -p:Version="${{ env.RYUJINX_BASE_VERSION }}" -p:DebugType=embedded -p:SourceRevisionId="${{ steps.git_short_hash.outputs.result }}" -p:ExtraDefineConstants=DISABLE_UPDATER src/Ryujinx.Headless.SDL2 --self-contained
|
||||
if: github.event_name == 'pull_request' && matrix.platform.os != 'macos-13'
|
||||
|
||||
- name: Set executable bit
|
||||
|
257
.github/workflows/canary.yml
vendored
Normal file
257
.github/workflows/canary.yml
vendored
Normal file
@ -0,0 +1,257 @@
|
||||
name: Canary release job
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs: {}
|
||||
push:
|
||||
branches: [ master ]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'docs/**'
|
||||
- 'assets/**'
|
||||
- '*.yml'
|
||||
- '*.json'
|
||||
- '*.config'
|
||||
- '*.md'
|
||||
|
||||
concurrency: release
|
||||
|
||||
env:
|
||||
POWERSHELL_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
RYUJINX_BASE_VERSION: "1.2"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_NAME: "canary"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_OWNER: "GreemDev"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO: "Ryujinx"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_REPO: "Ryujinx-Canary"
|
||||
RELEASE: 1
|
||||
|
||||
jobs:
|
||||
tag:
|
||||
name: Create tag
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Get version info
|
||||
id: version_info
|
||||
run: |
|
||||
echo "build_version=${{ env.RYUJINX_BASE_VERSION }}.${{ github.run_number }}" >> $GITHUB_OUTPUT
|
||||
echo "prev_build_version=${{ env.RYUJINX_BASE_VERSION }}.$((${{ github.run_number }} - 1))" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
- name: Create tag
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
github.rest.git.createRef({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
ref: 'refs/tags/Canary-${{ steps.version_info.outputs.build_version }}',
|
||||
sha: context.sha
|
||||
})
|
||||
|
||||
- name: Create release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: "Canary ${{ steps.version_info.outputs.build_version }}"
|
||||
tag: ${{ steps.version_info.outputs.build_version }}
|
||||
body: "**Full Changelog**: https://github.com/${{ github.repository }}/compare/Canary-${{ steps.version_info.outputs.prev_build_version }}...Canary-${{ steps.version_info.outputs.build_version }}"
|
||||
omitBodyDuringUpdate: true
|
||||
owner: ${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_OWNER }}
|
||||
repo: ${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}
|
||||
token: ${{ secrets.RELEASE_TOKEN }}
|
||||
|
||||
release:
|
||||
name: Release for ${{ matrix.platform.name }}
|
||||
runs-on: ${{ matrix.platform.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
platform:
|
||||
- { name: win-x64, os: windows-latest, zip_os_name: win_x64 }
|
||||
- { name: linux-x64, os: ubuntu-latest, zip_os_name: linux_x64 }
|
||||
- { name: linux-arm64, os: ubuntu-latest, zip_os_name: linux_arm64 }
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
global-json-file: global.json
|
||||
|
||||
- name: Overwrite csc problem matcher
|
||||
run: echo "::add-matcher::.github/csc.json"
|
||||
|
||||
- name: Get version info
|
||||
id: version_info
|
||||
run: |
|
||||
echo "build_version=${{ env.RYUJINX_BASE_VERSION }}.${{ github.run_number }}" >> $GITHUB_OUTPUT
|
||||
echo "prev_build_version=${{ env.RYUJINX_BASE_VERSION }}.$((${{ github.run_number }} - 1))" >> $GITHUB_OUTPUT
|
||||
echo "git_short_hash=$(git rev-parse --short "${{ github.sha }}")" >> $GITHUB_OUTPUT
|
||||
shell: bash
|
||||
|
||||
- name: Configure for release
|
||||
run: |
|
||||
sed -r --in-place 's/\%\%RYUJINX_BUILD_VERSION\%\%/${{ steps.version_info.outputs.build_version }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_BUILD_GIT_HASH\%\%/${{ steps.version_info.outputs.git_short_hash }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_NAME\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_NAME }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_OWNER\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_OWNER }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_CONFIG_FILE_NAME\%\%/Config\.json/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
shell: bash
|
||||
|
||||
- name: Create output dir
|
||||
run: "mkdir release_output"
|
||||
|
||||
- name: Publish
|
||||
run: |
|
||||
dotnet publish -c Release -r "${{ matrix.platform.name }}" -o ./publish_ava/publish -p:Version="${{ steps.version_info.outputs.build_version }}" -p:SourceRevisionId="${{ steps.version_info.outputs.git_short_hash }}" -p:DebugType=embedded src/Ryujinx --self-contained -p:IncludeNativeLibrariesForSelfExtract=true
|
||||
dotnet publish -c Release -r "${{ matrix.platform.name }}" -o ./publish_sdl2_headless/publish -p:Version="${{ steps.version_info.outputs.build_version }}" -p:SourceRevisionId="${{ steps.version_info.outputs.git_short_hash }}" -p:DebugType=embedded src/Ryujinx.Headless.SDL2 --self-contained -p:IncludeNativeLibrariesForSelfExtract=true
|
||||
|
||||
- name: Packing Windows builds
|
||||
if: matrix.platform.os == 'windows-latest'
|
||||
run: |
|
||||
pushd publish_ava
|
||||
rm publish/libarmeilleure-jitsupport.dylib
|
||||
7z a ../release_output/ryujinx-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.zip publish
|
||||
popd
|
||||
|
||||
pushd publish_sdl2_headless
|
||||
rm publish/libarmeilleure-jitsupport.dylib
|
||||
7z a ../release_output/sdl2-ryujinx-headless-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.zip publish
|
||||
popd
|
||||
shell: bash
|
||||
|
||||
- name: Packing Linux builds
|
||||
if: matrix.platform.os == 'ubuntu-latest'
|
||||
run: |
|
||||
pushd publish_ava
|
||||
rm publish/libarmeilleure-jitsupport.dylib
|
||||
chmod +x publish/Ryujinx.sh publish/Ryujinx
|
||||
tar -czvf ../release_output/ryujinx-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.tar.gz publish
|
||||
popd
|
||||
|
||||
pushd publish_sdl2_headless
|
||||
rm publish/libarmeilleure-jitsupport.dylib
|
||||
chmod +x publish/Ryujinx.sh publish/Ryujinx.Headless.SDL2
|
||||
tar -czvf ../release_output/sdl2-ryujinx-headless-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.tar.gz publish
|
||||
popd
|
||||
shell: bash
|
||||
|
||||
#- name: Build AppImage (Linux)
|
||||
# if: matrix.platform.os == 'ubuntu-latest'
|
||||
# run: |
|
||||
# BUILD_VERSION="${{ steps.version_info.outputs.build_version }}"
|
||||
# PLATFORM_NAME="${{ matrix.platform.name }}"
|
||||
|
||||
# sudo apt install -y zsync desktop-file-utils appstream
|
||||
|
||||
# mkdir -p tools
|
||||
# export PATH="$PATH:$(readlink -f tools)"
|
||||
|
||||
# Setup appimagetool
|
||||
# wget -q -O tools/appimagetool "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage"
|
||||
# chmod +x tools/appimagetool
|
||||
# chmod +x distribution/linux/appimage/build-appimage.sh
|
||||
|
||||
# Explicitly set $ARCH for appimagetool ($ARCH_NAME is for the file name)
|
||||
# if [ "$PLATFORM_NAME" = "linux-x64" ]; then
|
||||
# ARCH_NAME=x64
|
||||
# export ARCH=x86_64
|
||||
# elif [ "$PLATFORM_NAME" = "linux-arm64" ]; then
|
||||
# ARCH_NAME=arm64
|
||||
# export ARCH=aarch64
|
||||
# else
|
||||
# echo "Unexpected PLATFORM_NAME "$PLATFORM_NAME""
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
# export UFLAG="gh-releases-zsync|${{ github.repository_owner }}|${{ github.event.repository.name }}|latest|*-$ARCH_NAME.AppImage.zsync"
|
||||
# BUILDDIR=publish_ava OUTDIR=publish_ava_appimage distribution/linux/appimage/build-appimage.sh
|
||||
|
||||
# Add to release output
|
||||
# pushd publish_ava_appimage
|
||||
# mv Ryujinx.AppImage ../release_output/ryujinx-$BUILD_VERSION-$ARCH_NAME.AppImage
|
||||
# mv Ryujinx.AppImage.zsync ../release_output/ryujinx-$BUILD_VERSION-$ARCH_NAME.AppImage.zsync
|
||||
# popd
|
||||
# shell: bash
|
||||
|
||||
- name: Pushing new release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: ${{ steps.version_info.outputs.build_version }}
|
||||
artifacts: "release_output/*.tar.gz,release_output/*.zip"
|
||||
#artifacts: "release_output/*.tar.gz,release_output/*.zip/*AppImage*"
|
||||
tag: ${{ steps.version_info.outputs.build_version }}
|
||||
body: "**Full Changelog**: https://github.com/${{ github.repository }}/compare/Canary-${{ steps.version_info.outputs.prev_build_version }}...Canary-${{ steps.version_info.outputs.build_version }}"
|
||||
omitBodyDuringUpdate: true
|
||||
allowUpdates: true
|
||||
replacesArtifacts: true
|
||||
owner: ${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_OWNER }}
|
||||
repo: ${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}
|
||||
token: ${{ secrets.RELEASE_TOKEN }}
|
||||
|
||||
macos_release:
|
||||
name: Release MacOS universal
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
global-json-file: global.json
|
||||
|
||||
- name: Setup LLVM 15
|
||||
run: |
|
||||
wget https://apt.llvm.org/llvm.sh
|
||||
chmod +x llvm.sh
|
||||
sudo ./llvm.sh 15
|
||||
|
||||
- name: Install rcodesign
|
||||
run: |
|
||||
mkdir -p $HOME/.bin
|
||||
gh release download -R indygreg/apple-platform-rs -O apple-codesign.tar.gz -p 'apple-codesign-*-x86_64-unknown-linux-musl.tar.gz'
|
||||
tar -xzvf apple-codesign.tar.gz --wildcards '*/rcodesign' --strip-components=1
|
||||
rm apple-codesign.tar.gz
|
||||
mv rcodesign $HOME/.bin/
|
||||
echo "$HOME/.bin" >> $GITHUB_PATH
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Get version info
|
||||
id: version_info
|
||||
run: |
|
||||
echo "build_version=${{ env.RYUJINX_BASE_VERSION }}.${{ github.run_number }}" >> $GITHUB_OUTPUT
|
||||
echo "prev_build_version=${{ env.RYUJINX_BASE_VERSION }}.$((${{ github.run_number }} - 1))" >> $GITHUB_OUTPUT
|
||||
echo "git_short_hash=$(git rev-parse --short "${{ github.sha }}")" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Configure for release
|
||||
run: |
|
||||
sed -r --in-place 's/\%\%RYUJINX_BUILD_VERSION\%\%/${{ steps.version_info.outputs.build_version }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_BUILD_GIT_HASH\%\%/${{ steps.version_info.outputs.git_short_hash }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_NAME\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_NAME }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_OWNER\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_OWNER }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_CONFIG_FILE_NAME\%\%/Config\.json/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
shell: bash
|
||||
|
||||
- name: Publish macOS Ryujinx
|
||||
run: |
|
||||
./distribution/macos/create_macos_build_ava.sh . publish_tmp_ava publish_ava ./distribution/macos/entitlements.xml "${{ steps.version_info.outputs.build_version }}" "${{ steps.version_info.outputs.git_short_hash }}" Release
|
||||
|
||||
- name: Publish macOS Ryujinx.Headless.SDL2
|
||||
run: |
|
||||
./distribution/macos/create_macos_build_headless.sh . publish_tmp_headless publish_headless ./distribution/macos/entitlements.xml "${{ steps.version_info.outputs.build_version }}" "${{ steps.version_info.outputs.git_short_hash }}" Release
|
||||
|
||||
- name: Pushing new release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: "Canary ${{ steps.version_info.outputs.build_version }}"
|
||||
artifacts: "publish_ava/*.tar.gz, publish_headless/*.tar.gz"
|
||||
tag: ${{ steps.version_info.outputs.build_version }}
|
||||
body: "**Full Changelog**: https://github.com/${{ github.repository }}/compare/Canary-${{ steps.version_info.outputs.prev_build_version }}...Canary-${{ steps.version_info.outputs.build_version }}"
|
||||
omitBodyDuringUpdate: true
|
||||
allowUpdates: true
|
||||
replacesArtifacts: true
|
||||
owner: ${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_OWNER }}
|
||||
repo: ${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}
|
||||
token: ${{ secrets.RELEASE_TOKEN }}
|
55
.github/workflows/release.yml
vendored
55
.github/workflows/release.yml
vendored
@ -4,7 +4,7 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs: {}
|
||||
push:
|
||||
branches: [ master ]
|
||||
branches: [ release ]
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- 'docs/**'
|
||||
@ -20,7 +20,7 @@ env:
|
||||
POWERSHELL_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
RYUJINX_BASE_VERSION: "1.2"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_NAME: "master"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_NAME: "release"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_OWNER: "GreemDev"
|
||||
RYUJINX_TARGET_RELEASE_CHANNEL_REPO: "Ryujinx"
|
||||
RELEASE: 1
|
||||
@ -93,6 +93,7 @@ jobs:
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_NAME\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_NAME }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_OWNER\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_OWNER }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_CONFIG_FILE_NAME\%\%/Config\.json/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
shell: bash
|
||||
|
||||
@ -101,32 +102,20 @@ jobs:
|
||||
|
||||
- name: Publish
|
||||
run: |
|
||||
dotnet publish -c Release -r "${{ matrix.platform.name }}" -o ./publish_ava/publish -p:Version="${{ steps.version_info.outputs.build_version }}" -p:SourceRevisionId="${{ steps.version_info.outputs.git_short_hash }}" -p:DebugType=embedded src/Ryujinx --self-contained true
|
||||
dotnet publish -c Release -r "${{ matrix.platform.name }}" -o ./publish_sdl2_headless/publish -p:Version="${{ steps.version_info.outputs.build_version }}" -p:SourceRevisionId="${{ steps.version_info.outputs.git_short_hash }}" -p:DebugType=embedded src/Ryujinx.Headless.SDL2 --self-contained true
|
||||
dotnet publish -c Release -r "${{ matrix.platform.name }}" -o ./publish -p:Version="${{ steps.version_info.outputs.build_version }}" -p:SourceRevisionId="${{ steps.version_info.outputs.git_short_hash }}" -p:DebugType=embedded src/Ryujinx --self-contained -p:IncludeNativeLibrariesForSelfExtract=true
|
||||
dotnet publish -c Release -r "${{ matrix.platform.name }}" -o ./publish_sdl2_headless -p:Version="${{ steps.version_info.outputs.build_version }}" -p:SourceRevisionId="${{ steps.version_info.outputs.git_short_hash }}" -p:DebugType=embedded src/Ryujinx.Headless.SDL2 --self-contained -p:IncludeNativeLibrariesForSelfExtract=true
|
||||
|
||||
- name: Packing Windows builds
|
||||
if: matrix.platform.os == 'windows-latest'
|
||||
run: |
|
||||
pushd publish_ava
|
||||
7z a ../release_output/ryujinx-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.zip publish
|
||||
pushd publish
|
||||
rm libarmeilleure-jitsupport.dylib
|
||||
7z a ../release_output/ryujinx-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.zip ../publish
|
||||
popd
|
||||
|
||||
pushd publish_sdl2_headless
|
||||
7z a ../release_output/sdl2-ryujinx-headless-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.zip publish
|
||||
popd
|
||||
shell: bash
|
||||
|
||||
- name: Packing Linux builds
|
||||
if: matrix.platform.os == 'ubuntu-latest'
|
||||
run: |
|
||||
pushd publish_ava
|
||||
chmod +x publish/Ryujinx.sh publish/Ryujinx
|
||||
tar -czvf ../release_output/ryujinx-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.tar.gz publish
|
||||
popd
|
||||
|
||||
pushd publish_sdl2_headless
|
||||
chmod +x publish/Ryujinx.sh publish/Ryujinx.Headless.SDL2
|
||||
tar -czvf ../release_output/sdl2-ryujinx-headless-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.tar.gz publish
|
||||
rm libarmeilleure-jitsupport.dylib
|
||||
7z a ../release_output/sdl2-ryujinx-headless-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.zip ../publish
|
||||
popd
|
||||
shell: bash
|
||||
|
||||
@ -159,13 +148,26 @@ jobs:
|
||||
fi
|
||||
|
||||
export UFLAG="gh-releases-zsync|${{ github.repository_owner }}|${{ github.event.repository.name }}|latest|*-$ARCH_NAME.AppImage.zsync"
|
||||
BUILDDIR=publish_ava OUTDIR=publish_ava_appimage distribution/linux/appimage/build-appimage.sh
|
||||
BUILDDIR=publish OUTDIR=publish_appimage distribution/linux/appimage/build-appimage.sh
|
||||
|
||||
# Add to release output
|
||||
pushd publish_ava_appimage
|
||||
pushd publish_appimage
|
||||
mv Ryujinx.AppImage ../release_output/ryujinx-$BUILD_VERSION-$ARCH_NAME.AppImage
|
||||
mv Ryujinx.AppImage.zsync ../release_output/ryujinx-$BUILD_VERSION-$ARCH_NAME.AppImage.zsync
|
||||
popd
|
||||
shell: bash
|
||||
|
||||
- name: Packing Linux builds
|
||||
if: matrix.platform.os == 'ubuntu-latest'
|
||||
run: |
|
||||
pushd publish
|
||||
chmod +x Ryujinx.sh Ryujinx
|
||||
tar -czvf ../release_output/ryujinx-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.tar.gz ../publish
|
||||
popd
|
||||
|
||||
pushd publish_sdl2_headless
|
||||
chmod +x Ryujinx.sh Ryujinx.Headless.SDL2
|
||||
tar -czvf ../release_output/sdl2-ryujinx-headless-${{ steps.version_info.outputs.build_version }}-${{ matrix.platform.zip_os_name }}.tar.gz ../publish
|
||||
popd
|
||||
shell: bash
|
||||
|
||||
- name: Pushing new release
|
||||
@ -223,12 +225,13 @@ jobs:
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_NAME\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_NAME }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_OWNER\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_OWNER }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO\%\%/${{ env.RYUJINX_TARGET_RELEASE_CHANNEL_REPO }}/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
sed -r --in-place 's/\%\%RYUJINX_CONFIG_FILE_NAME\%\%/Config\.json/g;' src/Ryujinx.Common/ReleaseInformation.cs
|
||||
shell: bash
|
||||
|
||||
- name: Publish macOS Ryujinx
|
||||
run: |
|
||||
./distribution/macos/create_macos_build_ava.sh . publish_tmp_ava publish_ava ./distribution/macos/entitlements.xml "${{ steps.version_info.outputs.build_version }}" "${{ steps.version_info.outputs.git_short_hash }}" Release
|
||||
./distribution/macos/create_macos_build_ava.sh . publish_tmp_ava publish ./distribution/macos/entitlements.xml "${{ steps.version_info.outputs.build_version }}" "${{ steps.version_info.outputs.git_short_hash }}" Release
|
||||
|
||||
- name: Publish macOS Ryujinx.Headless.SDL2
|
||||
run: |
|
||||
@ -238,7 +241,7 @@ jobs:
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
name: ${{ steps.version_info.outputs.build_version }}
|
||||
artifacts: "publish_ava/*.tar.gz, publish_headless/*.tar.gz"
|
||||
artifacts: "publish/*.tar.gz, publish_headless/*.tar.gz"
|
||||
tag: ${{ steps.version_info.outputs.build_version }}
|
||||
body: "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ steps.version_info.outputs.prev_build_version }}...${{ steps.version_info.outputs.build_version }}"
|
||||
omitBodyDuringUpdate: true
|
||||
|
@ -12,24 +12,15 @@ Please read the entire document before continuing as it can potentially save eve
|
||||
|
||||
We always welcome bug reports, feature proposals and overall feedback. Here are a few tips on how you can make reporting your issue as effective as possible.
|
||||
|
||||
### Identify Where to Report
|
||||
|
||||
The Ryujinx codebase is distributed across multiple repositories in the [Ryujinx organization](https://github.com/Ryujinx). Depending on the feedback you might want to file the issue on a different repo. Here are a few common repos:
|
||||
|
||||
* [Ryujinx/Ryujinx](https://github.com/Ryujinx/Ryujinx) Ryujinx core project files.
|
||||
* [Ryujinx/Ryujinx-Games-List](https://github.com/Ryujinx/Ryujinx-Games-List) Ryujinx game compatibility list.
|
||||
* [Ryujinx/Ryujinx-Website](https://github.com/Ryujinx/Ryujinx-Website) Ryujinx website source code.
|
||||
* [Ryujinx/Ryujinx-Ldn-Website](https://github.com/Ryujinx/Ryujinx-Ldn-Website) Ryujinx LDN website source code.
|
||||
|
||||
### Finding Existing Issues
|
||||
|
||||
Before filing a new issue, please search our [open issues](https://github.com/Ryujinx/Ryujinx/issues) to check if it already exists.
|
||||
Before filing a new issue, please search our [open issues](https://github.com/GreemDev/Ryujinx/issues) to check if it already exists.
|
||||
|
||||
If you do find an existing issue, please include your own feedback in the discussion. Do consider upvoting (👍 reaction) the original post, as this helps us prioritize popular issues in our backlog.
|
||||
|
||||
### Writing a Good Feature Request
|
||||
|
||||
Please review any feature requests already opened to both check it has not already been suggested, and to familiarize yourself with the format. When ready to submit a proposal, please use the [Feature Request issue template](https://github.com/Ryujinx/Ryujinx/issues/new?assignees=&labels=&projects=&template=feature_request.yml&title=%5BFeature+Request%5D).
|
||||
Please review any feature requests already opened to both check it has not already been suggested, and to familiarize yourself with the format. When ready to submit a proposal, please use the [Feature Request issue template](https://github.com/GreemDev/Ryujinx/issues/new?assignees=&labels=&projects=&template=feature_request.yml&title=%5BFeature+Request%5D).
|
||||
|
||||
### Writing a Good Bug Report
|
||||
|
||||
@ -43,13 +34,13 @@ Ideally, a bug report should contain the following information:
|
||||
* A Ryujinx log file of the run instance where the issue occurred. Log files can be found in `[Executable Folder]/Logs` and are named chronologically.
|
||||
* Additional information, e.g. is it a regression from previous versions? Are there any known workarounds?
|
||||
|
||||
When ready to submit a bug report, please use the [Bug Report issue template](https://github.com/Ryujinx/Ryujinx/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml&title=%5BBug%5D).
|
||||
When ready to submit a bug report, please use the [Bug Report issue template](https://github.com/GreemDev/Ryujinx/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml&title=%5BBug%5D).
|
||||
|
||||
## Contributing Changes
|
||||
|
||||
Project maintainers will merge changes that both improve the project and meet our standards for code quality.
|
||||
|
||||
The [Pull Request Guide](docs/workflow/pr-guide.md) and [License](https://github.com/Ryujinx/Ryujinx/blob/master/LICENSE.txt) docs define additional guidance.
|
||||
The [Pull Request Guide](docs/workflow/pr-guide.md) and [License](https://github.com/GreemDev/Ryujinx/blob/master/LICENSE.txt) docs define additional guidance.
|
||||
|
||||
### DOs and DON'Ts
|
||||
|
||||
@ -83,15 +74,15 @@ We use and recommend the following workflow:
|
||||
3. In your fork, create a branch off of main (`git checkout -b mybranch`).
|
||||
- Branches are useful since they isolate your changes from incoming changes from upstream. They also enable you to create multiple PRs from the same fork.
|
||||
4. Make and commit your changes to your branch.
|
||||
- [Build Instructions](https://github.com/Ryujinx/Ryujinx#building) explains how to build and test.
|
||||
- [Build Instructions](https://github.com/GreemDev/Ryujinx#building) explains how to build and test.
|
||||
- Commit messages should be clear statements of action and intent.
|
||||
6. Build the repository with your changes.
|
||||
- Make sure that the builds are clean.
|
||||
- Make sure that `dotnet format` has been run and any corrections tested and committed.
|
||||
7. Create a pull request (PR) against the Ryujinx/Ryujinx repository's **main** branch.
|
||||
- State in the description what issue or improvement your change is addressing.
|
||||
- Check if all the Continuous Integration checks are passing. Refer to [Actions](https://github.com/Ryujinx/Ryujinx/actions) to check for outstanding errors.
|
||||
8. Wait for feedback or approval of your changes from the [core development team](https://github.com/orgs/Ryujinx/teams/developers)
|
||||
- Check if all the Continuous Integration checks are passing. Refer to [Actions](https://github.com/GreemDev/Ryujinx/actions) to check for outstanding errors.
|
||||
8. Wait for feedback or approval of your changes from the core development team
|
||||
- Details about the pull request [review procedure](docs/workflow/ci/pr-guide.md).
|
||||
9. When the team members have signed off, and all checks are green, your PR will be merged.
|
||||
- The next official build will automatically include your change.
|
||||
@ -99,7 +90,7 @@ We use and recommend the following workflow:
|
||||
|
||||
### Good First Issues
|
||||
|
||||
The team marks the most straightforward issues as [good first issues](https://github.com/Ryujinx/Ryujinx/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22). This set of issues is the place to start if you are interested in contributing but new to the codebase.
|
||||
The team marks the most straightforward issues as [good first issues](https://github.com/GreemDev/Ryujinx/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22). This set of issues is the place to start if you are interested in contributing but new to the codebase.
|
||||
|
||||
### Commit Messages
|
||||
|
||||
@ -122,7 +113,7 @@ Also do your best to factor commits appropriately, not too large with unrelated
|
||||
|
||||
### PR - CI Process
|
||||
|
||||
The [Ryujinx continuous integration](https://github.com/Ryujinx/Ryujinx/actions) (CI) system will automatically perform the required builds and run tests (including the ones you are expected to run) for PRs. Builds and test runs must be clean or have bugs properly filed against flaky/unexpected failures that are unrelated to your change.
|
||||
The [Ryujinx continuous integration](https://github.com/GreemDev/Ryujinx/actions) (CI) system will automatically perform the required builds and run tests (including the ones you are expected to run) for PRs. Builds and test runs must be clean or have bugs properly filed against flaky/unexpected failures that are unrelated to your change.
|
||||
|
||||
If the CI build fails for any reason, the PR actions tab should be consulted for further information on the failure. There are a few usual suspects for such a failure:
|
||||
* `dotnet format` has not been run on the PR and has outstanding stylistic issues.
|
||||
@ -143,5 +134,5 @@ Ryujinx uses some implementations and frameworks from other projects. The follow
|
||||
|
||||
- The license of the file is [permissive](https://en.wikipedia.org/wiki/Permissive_free_software_licence).
|
||||
- The license of the file is left in-tact.
|
||||
- The contribution is correctly attributed in the [3rd party notices](https://github.com/Ryujinx/Ryujinx/blob/master/distribution/legal/THIRDPARTY.md) file in the repository, as needed.
|
||||
- The contribution is correctly attributed in the [3rd party notices](https://github.com/GreemDev/Ryujinx/blob/master/distribution/legal/THIRDPARTY.md) file in the repository, as needed.
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
<PackageVersion Include="LibHac" Version="0.19.0" />
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
|
||||
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.0.1" />
|
||||
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.1.2" />
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
|
||||
<PackageVersion Include="MsgPack.Cli" Version="1.0.1" />
|
||||
@ -33,6 +33,7 @@
|
||||
<PackageVersion Include="OpenTK.Graphics" Version="4.8.2" />
|
||||
<PackageVersion Include="OpenTK.Audio.OpenAL" Version="4.8.2" />
|
||||
<PackageVersion Include="OpenTK.Windowing.GraphicsLibraryFramework" Version="4.8.2" />
|
||||
<PackageVersion Include="Open.NAT.Core" Version="2.1.0.5" />
|
||||
<PackageVersion Include="Ryujinx.Audio.OpenAL.Dependencies" Version="1.21.0.1" />
|
||||
<PackageVersion Include="Ryujinx.Graphics.Nvdec.Dependencies" Version="5.0.3-build14" />
|
||||
<PackageVersion Include="Ryujinx.Graphics.Vulkan.Dependencies.MoltenVK" Version="1.2.0" />
|
||||
|
47
README.md
47
README.md
@ -6,6 +6,23 @@
|
||||
<br>
|
||||
<sub><sup><b>(REE-YOU-JINX)</b></sup></sub>
|
||||
<br>
|
||||
<a href="https://github.com/GreemDev/Ryujinx/actions/workflows/release.yml">
|
||||
<img src="https://github.com/GreemDev/Ryujinx/actions/workflows/release.yml/badge.svg"
|
||||
alt="">
|
||||
</a>
|
||||
<a href="https://github.com/GreemDev/Ryujinx/releases/latest">
|
||||
<img src="https://img.shields.io/github/v/release/GreemDev/Ryujinx"
|
||||
alt="Latest Release">
|
||||
</a>
|
||||
<br>
|
||||
<a href="https://github.com/GreemDev/Ryujinx/actions/workflows/canary.yml">
|
||||
<img src="https://github.com/GreemDev/Ryujinx/actions/workflows/canary.yml/badge.svg"
|
||||
alt="">
|
||||
</a>
|
||||
<a href="https://github.com/GreemDev/Ryujinx-Canary/releases/latest">
|
||||
<img src="https://img.shields.io/github/v/release/GreemDev/Ryujinx-Canary?label=canary"
|
||||
alt="Latest Canary Release">
|
||||
</a>
|
||||
</h1>
|
||||
|
||||
<p align="center">
|
||||
@ -17,25 +34,22 @@
|
||||
</p>
|
||||
<p align="center">
|
||||
On October 1st 2024, Ryujinx was discontinued as the creator was forced to abandon the project.
|
||||
This fork is intended to be a direct continuation for existing Ryujinx users.
|
||||
Guides and documentation will not be provided at this time, though you can find the old ones on the Internet Archive.
|
||||
<br>
|
||||
This fork is intended to be a QoL uplift for existing Ryujinx users.
|
||||
<br>
|
||||
This is not a Ryujinx revival project. This is not a Phoenix project.
|
||||
<br>
|
||||
Guides and documentation can be found on the <a href="https://github.com/GreemDev/Ryujinx/wiki">Wiki tab</a>.
|
||||
</p>
|
||||
<p align="center">
|
||||
If you would like a version more true to original Ryujinx, check out <a href="https://github.com/ryujinx-mirror/ryujinx">ryujinx-mirror</a>.
|
||||
If you would like a version more preservative fork of Ryujinx, check out <a href="https://github.com/ryujinx-mirror/ryujinx">ryujinx-mirror</a>.
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/GreemDev/Ryujinx/actions/workflows/release.yml">
|
||||
<img src="https://github.com/GreemDev/Ryujinx/actions/workflows/release.yml/badge.svg"
|
||||
alt="">
|
||||
</a>
|
||||
<a href="https://crwd.in/ryujinx">
|
||||
<img src="https://badges.crowdin.net/ryujinx/localized.svg"
|
||||
alt="">
|
||||
</a>
|
||||
Click below to join the Discord:
|
||||
<br>
|
||||
<a href="https://discord.gg/dHPrkBkkyA">
|
||||
<img src="https://img.shields.io/discord/1294443224030511104?color=5865F2&label=Ryujinx&logo=discord&logoColor=white"
|
||||
alt="Discord">
|
||||
<img src="https://img.shields.io/discord/1294443224030511104?color=5865F2&label=Ryubing&logo=discord&logoColor=white" alt="Discord">
|
||||
</a>
|
||||
<br>
|
||||
<br>
|
||||
@ -56,17 +70,20 @@ Use the search function to see if a game has been tested already!
|
||||
To run this emulator, your PC must be equipped with at least 8GiB of RAM;
|
||||
failing to meet this requirement may result in a poor gameplay experience or unexpected crashes.
|
||||
|
||||
## Latest build
|
||||
## Latest release
|
||||
|
||||
These builds are compiled automatically for each commit on the master branch.
|
||||
Releases are compiled automatically for each commit on the master branch.
|
||||
While we strive to ensure optimal stability and performance prior to pushing an update, our automated builds **may be unstable or completely broken**.
|
||||
|
||||
You can find the latest release [here](https://github.com/GreemDev/Ryujinx/releases/latest).
|
||||
|
||||
## Documentation
|
||||
|
||||
If you are planning to contribute or just want to learn more about this project please read through our [documentation](docs/README.md).
|
||||
|
||||
## Building
|
||||
|
||||
Building the project is for advanced users.
|
||||
If you wish to build the emulator yourself, follow these steps:
|
||||
|
||||
### Step 1
|
||||
|
15
Ryujinx.sln
15
Ryujinx.sln
@ -29,12 +29,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Graphics.Nvdec", "s
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Audio", "src\Ryujinx.Audio\Ryujinx.Audio.csproj", "{806ACF6D-90B0-45D0-A1AC-5F220F3B3985}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{36F870C1-3E5F-485F-B426-F0645AF78751}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
Directory.Packages.props = Directory.Packages.props
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Memory", "src\Ryujinx.Memory\Ryujinx.Memory.csproj", "{A5E6C691-9E22-4263-8F40-42F002CE66BE}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Tests.Memory", "src\Ryujinx.Tests.Memory\Ryujinx.Tests.Memory.csproj", "{D1CC5322-7325-4F6B-9625-194B30BE1296}"
|
||||
@ -87,6 +81,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.Horizon.Kernel.Gene
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ryujinx.HLE.Generators", "src\Ryujinx.HLE.Generators\Ryujinx.HLE.Generators.csproj", "{B575BCDE-2FD8-4A5D-8756-31CDD7FE81F0}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{36F870C1-3E5F-485F-B426-F0645AF78751}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.editorconfig = .editorconfig
|
||||
Directory.Packages.props = Directory.Packages.props
|
||||
.github/workflows/release.yml = .github/workflows/release.yml
|
||||
.github/workflows/canary.yml = .github/workflows/canary.yml
|
||||
.github/workflows/build.yml = .github/workflows/build.yml
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
Binary file not shown.
@ -46,5 +46,5 @@ then
|
||||
rcodesign sign --entitlements-xml-path "$ENTITLEMENTS_FILE_PATH" "$APP_BUNDLE_DIRECTORY"
|
||||
else
|
||||
echo "Usign codesign for ad-hoc signing"
|
||||
codesign --entitlements "$ENTITLEMENTS_FILE_PATH" -f --deep -s - "$APP_BUNDLE_DIRECTORY"
|
||||
fi
|
||||
codesign --entitlements "$ENTITLEMENTS_FILE_PATH" -f -s - "$APP_BUNDLE_DIRECTORY"
|
||||
fi
|
||||
|
@ -99,7 +99,7 @@ then
|
||||
rcodesign sign --entitlements-xml-path "$ENTITLEMENTS_FILE_PATH" "$UNIVERSAL_APP_BUNDLE"
|
||||
else
|
||||
echo "Using codesign for ad-hoc signing"
|
||||
codesign --entitlements "$ENTITLEMENTS_FILE_PATH" -f --deep -s - "$UNIVERSAL_APP_BUNDLE"
|
||||
codesign --entitlements "$ENTITLEMENTS_FILE_PATH" -f -s - "$UNIVERSAL_APP_BUNDLE"
|
||||
fi
|
||||
|
||||
echo "Creating archive"
|
||||
@ -111,4 +111,4 @@ rm "$RELEASE_TAR_FILE_NAME"
|
||||
|
||||
popd
|
||||
|
||||
echo "Done"
|
||||
echo "Done"
|
||||
|
@ -95,7 +95,7 @@ else
|
||||
echo "Using codesign for ad-hoc signing"
|
||||
for FILE in "$UNIVERSAL_OUTPUT"/*; do
|
||||
if [[ $(file "$FILE") == *"Mach-O"* ]]; then
|
||||
codesign --entitlements "$ENTITLEMENTS_FILE_PATH" -f --deep -s - "$FILE"
|
||||
codesign --entitlements "$ENTITLEMENTS_FILE_PATH" -f -s - "$FILE"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@ -108,4 +108,4 @@ gzip -9 < "$RELEASE_TAR_FILE_NAME" > "$RELEASE_TAR_FILE_NAME.gz"
|
||||
rm "$RELEASE_TAR_FILE_NAME"
|
||||
popd
|
||||
|
||||
echo "Done"
|
||||
echo "Done"
|
||||
|
@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 255.76 255.76"><defs><style>.cls-1{fill:#02c5e5;}.cls-2{fill:#ff5f55;}.cls-3{fill:none;}</style></defs><g id="Ebene_2" data-name="Ebene 2"><g id="Ebene_1-2" data-name="Ebene 1"><g id="Ebene_2-2" data-name="Ebene 2"><g id="Ebene_1-2-2" data-name="Ebene 1-2"><path class="cls-1" d="M80.63,0V220.39H44.37c-14,0-35.74-20.74-35.74-39.13V40.13C8.63,19.19,31.36,0,49.06,0Z"/><path class="cls-2" d="M175.13,35.37V255.76h36.26c14,0,35.74-20.74,35.74-39.13V75.5c0-20.94-22.73-40.13-40.43-40.13Z"/><polygon class="cls-1" points="124.34 137.96 122.58 145.57 90.64 145.57 92.89 137.96 124.34 137.96"/><polygon class="cls-2" points="160.29 137.96 157.84 145.57 122.58 145.57 124.34 137.96 160.29 137.96"/><polygon class="cls-1" points="130.39 111.86 128.62 119.47 95.14 119.47 97.39 111.86 130.39 111.86"/><polygon class="cls-2" points="164.79 111.86 162.34 119.47 128.62 119.47 130.39 111.86 164.79 111.86"/><polygon class="cls-1" points="104.24 167.99 122.83 87.77 129.78 87.77 111.19 167.99 104.24 167.99"/><polygon class="cls-2" points="128.18 167.99 146.77 87.77 153.89 87.77 135.3 167.99 128.18 167.99"/></g><rect class="cls-3" width="255.76" height="255.76"/></g></g></g></svg>
|
||||
<svg viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"><path d="M80.63 0V220.39H44.37C30.37 220.39 8.63 199.65 8.63 181.26V40.13C8.63 19.19 31.36 0 49.06 0H80.63Z" fill="url(#g)"/><path d="M175.13 35.37V255.76H211.39C225.39 255.76 247.13 235.02 247.13 216.63V75.5C247.13 54.56 224.4 35.37 206.7 35.37H175.13Z" fill="url(#g)"/><path fill-rule="evenodd" clip-rule="evenodd" d="M109.436 145.57L104.24 167.99H111.19L116.386 145.57H133.376L128.18 167.99H135.3L140.496 145.57H157.84L160.29 137.96H142.259L146.544 119.47H162.34L164.79 111.86H148.307L153.89 87.77H146.77L141.187 111.86H124.197L129.78 87.77H122.83L117.247 111.86H97.39L95.14 119.47H115.484L111.199 137.96H92.89L90.64 145.57H109.436ZM139.424 119.47L135.139 137.96H118.149L122.434 119.47H139.424Z" fill="url(#g)"/><defs><linearGradient id="g" x1="223.76" y1="32" x2="27" y2="228.76" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#686868"/><stop offset="0.14" stop-color="#686868"/><stop offset="0.14" stop-color="#AE9675"/><stop offset="0.28" stop-color="#AE9675"/><stop offset="0.28" stop-color="#FF635E"/><stop offset="0.42" stop-color="#FF635E"/><stop offset="0.42" stop-color="#FE8F63"/><stop offset="0.56" stop-color="#FE8F63"/><stop offset="0.56" stop-color="#FDEF68"/><stop offset="0.7" stop-color="#FDEF68"/><stop offset="0.7" stop-color="#71C56D"/><stop offset="0.84" stop-color="#71C56D"/><stop offset="0.84" stop-color="#32ADDD"/><stop offset="1" stop-color="#32ADDD"/></linearGradient></defs></svg>
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.5 KiB |
BIN
docs/shell.png
BIN
docs/shell.png
Binary file not shown.
Before Width: | Height: | Size: 905 KiB After Width: | Height: | Size: 1.4 MiB |
@ -2,7 +2,7 @@
|
||||
|
||||
## Contributing Rules
|
||||
|
||||
All contributions to Ryujinx/Ryujinx repository are made via pull requests (PRs) rather than through direct commits. The pull requests are reviewed and merged by the maintainers after a review and at least two approvals from the core development team.
|
||||
All contributions to GreemDev/Ryujinx repository are made via pull requests (PRs) rather than through direct commits. The pull requests are reviewed and merged by the maintainers after a review and at least two approvals from the core development team.
|
||||
|
||||
To merge pull requests, you must have write permissions in the repository.
|
||||
|
||||
@ -24,7 +24,7 @@ If during the code review process a merge conflict occurs, the PR author is resp
|
||||
|
||||
## Pull Request Builds
|
||||
|
||||
When submitting a PR to the `Ryujinx/Ryujinx` repository, various builds will run validating many areas to ensure we keep developer productivity and product quality high. These various workflows can be tracked in the [Actions](https://github.com/Ryujinx/Ryujinx/actions) tab of the repository. If the job continues to completion, the build artifacts will be uploaded and posted as a comment in the PR discussion.
|
||||
When submitting a PR to the `GreemDev/Ryujinx` repository, various builds will run validating many areas to ensure we keep developer productivity and product quality high. These various workflows can be tracked in the [Actions](https://github.com/GreemDev/Ryujinx/actions) tab of the repository. If the job continues to completion, the build artifacts will be uploaded and posted as a comment in the PR discussion.
|
||||
|
||||
## Review Turnaround Times
|
||||
|
||||
@ -42,7 +42,7 @@ Anyone with write access can merge a pull request manually when the following co
|
||||
|
||||
* The PR has been approved by two reviewers and any other objections are addressed.
|
||||
* You can request follow up reviews from the original reviewers if they requested changes.
|
||||
* The PR successfully builds and passes all tests in the Continuous Integration (CI) system. In case of failures, refer to the [Actions](https://github.com/Ryujinx/Ryujinx/actions) tab of your PR.
|
||||
* The PR successfully builds and passes all tests in the Continuous Integration (CI) system. In case of failures, refer to the [Actions](https://github.com/GreemDev/Ryujinx/actions) tab of your PR.
|
||||
|
||||
Typically, PRs are merged as one commit (squash merges). It creates a simpler history than a Merge Commit. "Special circumstances" are rare, and typically mean that there are a series of cleanly separated changes that will be too hard to understand if squashed together, or for some reason we want to preserve the ability to dissect them.
|
||||
|
||||
|
@ -77,7 +77,7 @@ namespace ARMeilleure.Translation
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (int pBlkIndex = 0; pBlkIndex < block.Predecessors.Count; pBlkIndex++)
|
||||
{
|
||||
BasicBlock current = block.Predecessors[pBlkIndex];
|
||||
|
@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -848,17 +849,15 @@ namespace ARMeilleure.Translation.PTC
|
||||
}
|
||||
}
|
||||
|
||||
List<Thread> threads = new();
|
||||
|
||||
for (int i = 0; i < degreeOfParallelism; i++)
|
||||
{
|
||||
Thread thread = new(TranslateFuncs)
|
||||
{
|
||||
IsBackground = true,
|
||||
};
|
||||
|
||||
threads.Add(thread);
|
||||
}
|
||||
List<Thread> threads = Enumerable.Range(0, degreeOfParallelism)
|
||||
.Select(idx =>
|
||||
new Thread(TranslateFuncs)
|
||||
{
|
||||
IsBackground = true,
|
||||
Name = "Ptc.TranslateThread." + idx
|
||||
}
|
||||
).ToList();
|
||||
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
@ -885,6 +884,7 @@ namespace ARMeilleure.Translation.PTC
|
||||
Thread preSaveThread = new(PreSave)
|
||||
{
|
||||
IsBackground = true,
|
||||
Name = "Ptc.DiskWriter"
|
||||
};
|
||||
preSaveThread.Start();
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
|
||||
|
||||
public OpenALHardwareDeviceDriver()
|
||||
{
|
||||
_device = ALC.OpenDevice("");
|
||||
_device = ALC.OpenDevice(string.Empty);
|
||||
_context = ALC.CreateContext(_device, new ALContextAttributes());
|
||||
_updateRequiredEvent = new ManualResetEvent(false);
|
||||
_pauseEvent = new ManualResetEvent(true);
|
||||
|
@ -81,7 +81,7 @@ namespace Ryujinx.Audio.Renderer.Dsp
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static short GetCoefficientAtIndex(ReadOnlySpan<short> coefficients, int index)
|
||||
{
|
||||
if ((uint)index > (uint)coefficients.Length)
|
||||
if ((uint)index >= (uint)coefficients.Length)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.AudioRenderer, $"Out of bound read for coefficient at index {index}");
|
||||
|
||||
|
@ -119,7 +119,7 @@ namespace Ryujinx.Common.Configuration
|
||||
|
||||
private static string SetUpLogsDir()
|
||||
{
|
||||
string logDir = "";
|
||||
string logDir = string.Empty;
|
||||
|
||||
if (Mode == LaunchMode.Portable)
|
||||
{
|
||||
@ -148,7 +148,7 @@ namespace Ryujinx.Common.Configuration
|
||||
catch
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Application, $"Logging directory could not be created '{logDir}'");
|
||||
logDir = "";
|
||||
logDir = string.Empty;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(logDir))
|
||||
@ -179,7 +179,7 @@ namespace Ryujinx.Common.Configuration
|
||||
catch
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Application, $"Logging directory could not be created '{logDir}'");
|
||||
logDir = "";
|
||||
logDir = string.Empty;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(logDir))
|
||||
|
@ -3,6 +3,7 @@ namespace Ryujinx.Common.Configuration.Multiplayer
|
||||
public enum MultiplayerMode
|
||||
{
|
||||
Disabled,
|
||||
LdnRyu,
|
||||
LdnMitm,
|
||||
}
|
||||
}
|
||||
|
@ -121,8 +121,8 @@ namespace Ryujinx.Common.GraphicsDriver
|
||||
};
|
||||
application.AppName.Set("Ryujinx.exe");
|
||||
application.UserFriendlyName.Set("Ryujinx");
|
||||
application.Launcher.Set("");
|
||||
application.FileInFolder.Set("");
|
||||
application.Launcher.Set(string.Empty);
|
||||
application.FileInFolder.Set(string.Empty);
|
||||
|
||||
Check(NvAPI_DRS_CreateApplication(handle, profileHandle, ref application));
|
||||
}
|
||||
|
@ -72,5 +72,6 @@ namespace Ryujinx.Common.Logging
|
||||
TamperMachine,
|
||||
UI,
|
||||
Vic,
|
||||
XCIFileTrimmer
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace Ryujinx.Common.Logging
|
||||
{
|
||||
if (_enabledClasses[(int)logClass])
|
||||
{
|
||||
Updated?.Invoke(null, new LogEventArgs(Level, _time.Elapsed, Thread.CurrentThread.Name, FormatMessage(logClass, "", message)));
|
||||
Updated?.Invoke(null, new LogEventArgs(Level, _time.Elapsed, Thread.CurrentThread.Name, FormatMessage(logClass, string.Empty, message)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,10 @@ namespace Ryujinx.Common.Logging.Targets
|
||||
string ILogTarget.Name { get => _target.Name; }
|
||||
|
||||
public AsyncLogTargetWrapper(ILogTarget target)
|
||||
: this(target, -1, AsyncLogTargetOverflowAction.Block)
|
||||
: this(target, -1)
|
||||
{ }
|
||||
|
||||
public AsyncLogTargetWrapper(ILogTarget target, int queueLimit, AsyncLogTargetOverflowAction overflowAction)
|
||||
public AsyncLogTargetWrapper(ILogTarget target, int queueLimit = -1, AsyncLogTargetOverflowAction overflowAction = AsyncLogTargetOverflowAction.Block)
|
||||
{
|
||||
_target = target;
|
||||
_messageQueue = new BlockingCollection<LogEventArgs>(queueLimit);
|
||||
|
@ -47,7 +47,7 @@ namespace Ryujinx.Common.Logging.Targets
|
||||
}
|
||||
|
||||
// Clean up old logs, should only keep 3
|
||||
FileInfo[] files = logDir.GetFiles("*.log").OrderBy((info => info.CreationTime)).ToArray();
|
||||
FileInfo[] files = logDir.GetFiles("*.log").OrderBy(info => info.CreationTime).ToArray();
|
||||
for (int i = 0; i < files.Length - 2; i++)
|
||||
{
|
||||
try
|
||||
|
30
src/Ryujinx.Common/Logging/XCIFileTrimmerLog.cs
Normal file
30
src/Ryujinx.Common/Logging/XCIFileTrimmerLog.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Ryujinx.Common.Utilities;
|
||||
|
||||
namespace Ryujinx.Common.Logging
|
||||
{
|
||||
public class XCIFileTrimmerLog : XCIFileTrimmer.ILog
|
||||
{
|
||||
public virtual void Progress(long current, long total, string text, bool complete)
|
||||
{
|
||||
}
|
||||
|
||||
public void Write(XCIFileTrimmer.LogType logType, string text)
|
||||
{
|
||||
switch (logType)
|
||||
{
|
||||
case XCIFileTrimmer.LogType.Info:
|
||||
Logger.Notice.Print(LogClass.XCIFileTrimmer, text);
|
||||
break;
|
||||
case XCIFileTrimmer.LogType.Warn:
|
||||
Logger.Warning?.Print(LogClass.XCIFileTrimmer, text);
|
||||
break;
|
||||
case XCIFileTrimmer.LogType.Error:
|
||||
Logger.Error?.Print(LogClass.XCIFileTrimmer, text);
|
||||
break;
|
||||
case XCIFileTrimmer.LogType.Progress:
|
||||
Logger.Info?.Print(LogClass.XCIFileTrimmer, text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -803,18 +803,6 @@ namespace Ryujinx.Common.Memory
|
||||
public Span<T> AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length);
|
||||
}
|
||||
|
||||
public struct Array256<T> : IArray<T> where T : unmanaged
|
||||
{
|
||||
T _e0;
|
||||
Array128<T> _other;
|
||||
Array127<T> _other2;
|
||||
public readonly int Length => 256;
|
||||
public ref T this[int index] => ref AsSpan()[index];
|
||||
|
||||
[Pure]
|
||||
public Span<T> AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length);
|
||||
}
|
||||
|
||||
public struct Array140<T> : IArray<T> where T : unmanaged
|
||||
{
|
||||
T _e0;
|
||||
@ -828,6 +816,18 @@ namespace Ryujinx.Common.Memory
|
||||
public Span<T> AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length);
|
||||
}
|
||||
|
||||
public struct Array256<T> : IArray<T> where T : unmanaged
|
||||
{
|
||||
T _e0;
|
||||
Array128<T> _other;
|
||||
Array127<T> _other2;
|
||||
public readonly int Length => 256;
|
||||
public ref T this[int index] => ref AsSpan()[index];
|
||||
|
||||
[Pure]
|
||||
public Span<T> AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length);
|
||||
}
|
||||
|
||||
public struct Array384<T> : IArray<T> where T : unmanaged
|
||||
{
|
||||
T _e0;
|
||||
|
@ -1,11 +1,13 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Common
|
||||
{
|
||||
public class ReactiveObject<T>
|
||||
{
|
||||
private readonly ReaderWriterLockSlim _readerWriterLock = new();
|
||||
private readonly ReaderWriterLockSlim _rwLock = new();
|
||||
private bool _isInitialized;
|
||||
private T _value;
|
||||
|
||||
@ -15,15 +17,15 @@ namespace Ryujinx.Common
|
||||
{
|
||||
get
|
||||
{
|
||||
_readerWriterLock.EnterReadLock();
|
||||
_rwLock.EnterReadLock();
|
||||
T value = _value;
|
||||
_readerWriterLock.ExitReadLock();
|
||||
_rwLock.ExitReadLock();
|
||||
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
_readerWriterLock.EnterWriteLock();
|
||||
_rwLock.EnterWriteLock();
|
||||
|
||||
T oldValue = _value;
|
||||
|
||||
@ -32,7 +34,7 @@ namespace Ryujinx.Common
|
||||
_isInitialized = true;
|
||||
_value = value;
|
||||
|
||||
_readerWriterLock.ExitWriteLock();
|
||||
_rwLock.ExitWriteLock();
|
||||
|
||||
if (!oldIsInitialized || oldValue == null || !oldValue.Equals(_value))
|
||||
{
|
||||
@ -40,12 +42,22 @@ namespace Ryujinx.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LogChangesToValue(string valueName, LogClass logClass = LogClass.Configuration)
|
||||
=> Event += (_, e) => ReactiveObjectHelper.LogValueChange(logClass, e, valueName);
|
||||
|
||||
public static implicit operator T(ReactiveObject<T> obj) => obj.Value;
|
||||
}
|
||||
|
||||
public static class ReactiveObjectHelper
|
||||
{
|
||||
public static void LogValueChange<T>(LogClass logClass, ReactiveEventArgs<T> eventArgs, string valueName)
|
||||
{
|
||||
string message = string.Create(CultureInfo.InvariantCulture, $"{valueName} set to: {eventArgs.NewValue}");
|
||||
|
||||
Logger.Info?.Print(logClass, message);
|
||||
}
|
||||
|
||||
public static void Toggle(this ReactiveObject<bool> rBoolean) => rBoolean.Value = !rBoolean.Value;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,9 @@ namespace Ryujinx.Common
|
||||
// DO NOT EDIT, filled by CI
|
||||
public static class ReleaseInformation
|
||||
{
|
||||
private const string FlatHubChannelOwner = "flathub";
|
||||
private const string FlatHubChannel = "flathub";
|
||||
private const string CanaryChannel = "canary";
|
||||
private const string ReleaseChannel = "release";
|
||||
|
||||
private const string BuildVersion = "%%RYUJINX_BUILD_VERSION%%";
|
||||
public const string BuildGitHash = "%%RYUJINX_BUILD_GIT_HASH%%";
|
||||
@ -13,6 +15,7 @@ namespace Ryujinx.Common
|
||||
private const string ConfigFileName = "%%RYUJINX_CONFIG_FILE_NAME%%";
|
||||
|
||||
public const string ReleaseChannelOwner = "%%RYUJINX_TARGET_RELEASE_CHANNEL_OWNER%%";
|
||||
public const string ReleaseChannelSourceRepo = "%%RYUJINX_TARGET_RELEASE_CHANNEL_SOURCE_REPO%%";
|
||||
public const string ReleaseChannelRepo = "%%RYUJINX_TARGET_RELEASE_CHANNEL_REPO%%";
|
||||
|
||||
public static string ConfigName => !ConfigFileName.StartsWith("%%") ? ConfigFileName : "Config.json";
|
||||
@ -21,10 +24,15 @@ namespace Ryujinx.Common
|
||||
!BuildGitHash.StartsWith("%%") &&
|
||||
!ReleaseChannelName.StartsWith("%%") &&
|
||||
!ReleaseChannelOwner.StartsWith("%%") &&
|
||||
!ReleaseChannelSourceRepo.StartsWith("%%") &&
|
||||
!ReleaseChannelRepo.StartsWith("%%") &&
|
||||
!ConfigFileName.StartsWith("%%");
|
||||
|
||||
public static bool IsFlatHubBuild => IsValid && ReleaseChannelOwner.Equals(FlatHubChannelOwner);
|
||||
public static bool IsFlatHubBuild => IsValid && ReleaseChannelOwner.Equals(FlatHubChannel);
|
||||
|
||||
public static bool IsCanaryBuild => IsValid && ReleaseChannelName.Equals(CanaryChannel);
|
||||
|
||||
public static bool IsReleaseBuild => IsValid && ReleaseChannelName.Equals(ReleaseChannel);
|
||||
|
||||
public static string Version => IsValid ? BuildVersion : Assembly.GetEntryAssembly()!.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" />
|
||||
<PackageReference Include="MsgPack.Cli" />
|
||||
<PackageReference Include="System.Management" />
|
||||
<PackageReference Include="Humanizer" />
|
||||
<PackageReference Include="Gommon" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -17,29 +17,19 @@ namespace Ryujinx.Common.Utilities
|
||||
/// It is REQUIRED for you to save returned options statically or as a part of static serializer context
|
||||
/// in order to avoid performance issues. You can safely modify returned options for your case before storing.
|
||||
/// </remarks>
|
||||
public static JsonSerializerOptions GetDefaultSerializerOptions(bool indented = true)
|
||||
{
|
||||
JsonSerializerOptions options = new()
|
||||
public static JsonSerializerOptions GetDefaultSerializerOptions(bool indented = true) =>
|
||||
new()
|
||||
{
|
||||
DictionaryKeyPolicy = _snakeCasePolicy,
|
||||
PropertyNamingPolicy = _snakeCasePolicy,
|
||||
WriteIndented = indented,
|
||||
AllowTrailingCommas = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
public static string Serialize<T>(T value, JsonTypeInfo<T> typeInfo) => JsonSerializer.Serialize(value, typeInfo);
|
||||
|
||||
public static string Serialize<T>(T value, JsonTypeInfo<T> typeInfo)
|
||||
{
|
||||
return JsonSerializer.Serialize(value, typeInfo);
|
||||
}
|
||||
|
||||
public static T Deserialize<T>(string value, JsonTypeInfo<T> typeInfo)
|
||||
{
|
||||
return JsonSerializer.Deserialize(value, typeInfo);
|
||||
}
|
||||
public static T Deserialize<T>(string value, JsonTypeInfo<T> typeInfo) => JsonSerializer.Deserialize(value, typeInfo);
|
||||
|
||||
public static void SerializeToFile<T>(string filePath, T value, JsonTypeInfo<T> typeInfo)
|
||||
{
|
||||
@ -53,10 +43,7 @@ namespace Ryujinx.Common.Utilities
|
||||
return JsonSerializer.Deserialize(file, typeInfo);
|
||||
}
|
||||
|
||||
public static void SerializeToStream<T>(Stream stream, T value, JsonTypeInfo<T> typeInfo)
|
||||
{
|
||||
JsonSerializer.Serialize(stream, value, typeInfo);
|
||||
}
|
||||
public static void SerializeToStream<T>(Stream stream, T value, JsonTypeInfo<T> typeInfo) => JsonSerializer.Serialize(stream, value, typeInfo);
|
||||
|
||||
private class SnakeCaseNamingPolicy : JsonNamingPolicy
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
@ -65,6 +66,11 @@ namespace Ryujinx.Common.Utilities
|
||||
return (targetProperties, targetAddressInfo);
|
||||
}
|
||||
|
||||
public static bool SupportsDynamicDns()
|
||||
{
|
||||
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
}
|
||||
|
||||
public static uint ConvertIpv4Address(IPAddress ipAddress)
|
||||
{
|
||||
return BinaryPrimitives.ReadUInt32BigEndian(ipAddress.GetAddressBytes());
|
||||
|
524
src/Ryujinx.Common/Utilities/XCIFileTrimmer.cs
Normal file
524
src/Ryujinx.Common/Utilities/XCIFileTrimmer.cs
Normal file
@ -0,0 +1,524 @@
|
||||
// Uncomment the line below to ensure XCIFileTrimmer does not modify files
|
||||
//#define XCI_TRIMMER_READ_ONLY_MODE
|
||||
|
||||
using Gommon;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Common.Utilities
|
||||
{
|
||||
public sealed class XCIFileTrimmer
|
||||
{
|
||||
private const long BytesInAMegabyte = 1024 * 1024;
|
||||
private const int BufferSize = 8 * (int)BytesInAMegabyte;
|
||||
|
||||
private const long CartSizeMBinFormattedGB = 952;
|
||||
private const int CartKeyAreaSize = 0x1000;
|
||||
private const byte PaddingByte = 0xFF;
|
||||
private const int HeaderFilePos = 0x100;
|
||||
private const int CartSizeFilePos = 0x10D;
|
||||
private const int DataSizeFilePos = 0x118;
|
||||
private const string HeaderMagicValue = "HEAD";
|
||||
|
||||
/// <summary>
|
||||
/// Cartridge Sizes (ByteIdentifier, SizeInGB)
|
||||
/// </summary>
|
||||
private static readonly Dictionary<byte, long> _cartSizesGB = new()
|
||||
{
|
||||
{ 0xFA, 1 },
|
||||
{ 0xF8, 2 },
|
||||
{ 0xF0, 4 },
|
||||
{ 0xE0, 8 },
|
||||
{ 0xE1, 16 },
|
||||
{ 0xE2, 32 }
|
||||
};
|
||||
|
||||
private static long RecordsToByte(long records)
|
||||
{
|
||||
return 512 + (records * 512);
|
||||
}
|
||||
|
||||
public static bool CanTrim(string filename, ILog log = null)
|
||||
{
|
||||
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var trimmer = new XCIFileTrimmer(filename, log);
|
||||
return trimmer.CanBeTrimmed;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool CanUntrim(string filename, ILog log = null)
|
||||
{
|
||||
if (Path.GetExtension(filename).Equals(".XCI", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var trimmer = new XCIFileTrimmer(filename, log);
|
||||
return trimmer.CanBeUntrimmed;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private ILog _log;
|
||||
private string _filename;
|
||||
private FileStream _fileStream;
|
||||
private BinaryReader _binaryReader;
|
||||
private long _offsetB, _dataSizeB, _cartSizeB, _fileSizeB;
|
||||
private bool _fileOK = true;
|
||||
private bool _freeSpaceChecked = false;
|
||||
private bool _freeSpaceValid = false;
|
||||
|
||||
public enum OperationOutcome
|
||||
{
|
||||
Undetermined,
|
||||
InvalidXCIFile,
|
||||
NoTrimNecessary,
|
||||
NoUntrimPossible,
|
||||
FreeSpaceCheckFailed,
|
||||
FileIOWriteError,
|
||||
ReadOnlyFileCannotFix,
|
||||
FileSizeChanged,
|
||||
Successful,
|
||||
Cancelled
|
||||
}
|
||||
|
||||
public enum LogType
|
||||
{
|
||||
Info,
|
||||
Warn,
|
||||
Error,
|
||||
Progress
|
||||
}
|
||||
|
||||
public interface ILog
|
||||
{
|
||||
public void Write(LogType logType, string text);
|
||||
public void Progress(long current, long total, string text, bool complete);
|
||||
}
|
||||
|
||||
public bool FileOK => _fileOK;
|
||||
public bool Trimmed => _fileOK && FileSizeB < UntrimmedFileSizeB;
|
||||
public bool ContainsKeyArea => _offsetB != 0;
|
||||
public bool CanBeTrimmed => _fileOK && FileSizeB > TrimmedFileSizeB;
|
||||
public bool CanBeUntrimmed => _fileOK && FileSizeB < UntrimmedFileSizeB;
|
||||
public bool FreeSpaceChecked => _fileOK && _freeSpaceChecked;
|
||||
public bool FreeSpaceValid => _fileOK && _freeSpaceValid;
|
||||
public long DataSizeB => _dataSizeB;
|
||||
public long CartSizeB => _cartSizeB;
|
||||
public long FileSizeB => _fileSizeB;
|
||||
public long DiskSpaceSavedB => CartSizeB - FileSizeB;
|
||||
public long DiskSpaceSavingsB => CartSizeB - DataSizeB;
|
||||
public long TrimmedFileSizeB => _offsetB + _dataSizeB;
|
||||
public long UntrimmedFileSizeB => _offsetB + _cartSizeB;
|
||||
|
||||
public ILog Log
|
||||
{
|
||||
get => _log;
|
||||
set => _log = value;
|
||||
}
|
||||
|
||||
public String Filename
|
||||
{
|
||||
get => _filename;
|
||||
set
|
||||
{
|
||||
_filename = value;
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
public long Pos
|
||||
{
|
||||
get => _fileStream.Position;
|
||||
set => _fileStream.Position = value;
|
||||
}
|
||||
|
||||
public XCIFileTrimmer(string path, ILog log = null)
|
||||
{
|
||||
Log = log;
|
||||
Filename = path;
|
||||
ReadHeader();
|
||||
}
|
||||
|
||||
public void CheckFreeSpace(CancellationToken? cancelToken = null)
|
||||
{
|
||||
if (FreeSpaceChecked)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (CanBeTrimmed)
|
||||
{
|
||||
_freeSpaceValid = false;
|
||||
|
||||
OpenReaders();
|
||||
|
||||
try
|
||||
{
|
||||
Pos = TrimmedFileSizeB;
|
||||
bool freeSpaceValid = true;
|
||||
long readSizeB = FileSizeB - TrimmedFileSizeB;
|
||||
|
||||
Stopwatch timedSw = Lambda.Timed(() =>
|
||||
{
|
||||
freeSpaceValid = CheckPadding(readSizeB, cancelToken);
|
||||
});
|
||||
|
||||
if (timedSw.Elapsed.TotalSeconds > 0)
|
||||
{
|
||||
Log?.Write(LogType.Info, $"Checked at {readSizeB / (double)XCIFileTrimmer.BytesInAMegabyte / timedSw.Elapsed.TotalSeconds:N} Mb/sec");
|
||||
}
|
||||
|
||||
if (freeSpaceValid)
|
||||
Log?.Write(LogType.Info, "Free space is valid");
|
||||
|
||||
_freeSpaceValid = freeSpaceValid;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseReaders();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Log?.Write(LogType.Warn, "There is no free space to check.");
|
||||
_freeSpaceValid = false;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_freeSpaceChecked = true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckPadding(long readSizeB, CancellationToken? cancelToken = null)
|
||||
{
|
||||
long maxReads = readSizeB / XCIFileTrimmer.BufferSize;
|
||||
long read = 0;
|
||||
var buffer = new byte[BufferSize];
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int bytes = _fileStream.Read(buffer, 0, XCIFileTrimmer.BufferSize);
|
||||
if (bytes == 0)
|
||||
break;
|
||||
|
||||
Log?.Progress(read, maxReads, "Verifying file can be trimmed", false);
|
||||
if (buffer.Take(bytes).AsParallel().Any(b => b != XCIFileTrimmer.PaddingByte))
|
||||
{
|
||||
Log?.Write(LogType.Warn, "Free space is NOT valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
read++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
_freeSpaceChecked = false;
|
||||
_freeSpaceValid = false;
|
||||
ReadHeader();
|
||||
}
|
||||
|
||||
public OperationOutcome Trim(CancellationToken? cancelToken = null)
|
||||
{
|
||||
if (!FileOK)
|
||||
{
|
||||
return OperationOutcome.InvalidXCIFile;
|
||||
}
|
||||
|
||||
if (!CanBeTrimmed)
|
||||
{
|
||||
return OperationOutcome.NoTrimNecessary;
|
||||
}
|
||||
|
||||
if (!FreeSpaceChecked)
|
||||
{
|
||||
CheckFreeSpace(cancelToken);
|
||||
}
|
||||
|
||||
if (!FreeSpaceValid)
|
||||
{
|
||||
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
|
||||
{
|
||||
return OperationOutcome.Cancelled;
|
||||
}
|
||||
else
|
||||
{
|
||||
return OperationOutcome.FreeSpaceCheckFailed;
|
||||
}
|
||||
}
|
||||
|
||||
Log?.Write(LogType.Info, "Trimming...");
|
||||
|
||||
try
|
||||
{
|
||||
var info = new FileInfo(Filename);
|
||||
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log?.Write(LogType.Info, "Attempting to remove ReadOnly attribute");
|
||||
File.SetAttributes(Filename, info.Attributes & ~FileAttributes.ReadOnly);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log?.Write(LogType.Error, e.ToString());
|
||||
return OperationOutcome.ReadOnlyFileCannotFix;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.Length != FileSizeB)
|
||||
{
|
||||
Log?.Write(LogType.Error, "File size has changed, cannot safely trim.");
|
||||
return OperationOutcome.FileSizeChanged;
|
||||
}
|
||||
|
||||
var outfileStream = new FileStream(_filename, FileMode.Open, FileAccess.Write, FileShare.Write);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
#if !XCI_TRIMMER_READ_ONLY_MODE
|
||||
outfileStream.SetLength(TrimmedFileSizeB);
|
||||
#endif
|
||||
return OperationOutcome.Successful;
|
||||
}
|
||||
finally
|
||||
{
|
||||
outfileStream.Close();
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log?.Write(LogType.Error, e.ToString());
|
||||
return OperationOutcome.FileIOWriteError;
|
||||
}
|
||||
}
|
||||
|
||||
public OperationOutcome Untrim(CancellationToken? cancelToken = null)
|
||||
{
|
||||
if (!FileOK)
|
||||
{
|
||||
return OperationOutcome.InvalidXCIFile;
|
||||
}
|
||||
|
||||
if (!CanBeUntrimmed)
|
||||
{
|
||||
return OperationOutcome.NoUntrimPossible;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Log?.Write(LogType.Info, "Untrimming...");
|
||||
|
||||
var info = new FileInfo(Filename);
|
||||
if ((info.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log?.Write(LogType.Info, "Attempting to remove ReadOnly attribute");
|
||||
File.SetAttributes(Filename, info.Attributes & ~FileAttributes.ReadOnly);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log?.Write(LogType.Error, e.ToString());
|
||||
return OperationOutcome.ReadOnlyFileCannotFix;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.Length != FileSizeB)
|
||||
{
|
||||
Log?.Write(LogType.Error, "File size has changed, cannot safely untrim.");
|
||||
return OperationOutcome.FileSizeChanged;
|
||||
}
|
||||
|
||||
var outfileStream = new FileStream(_filename, FileMode.Append, FileAccess.Write, FileShare.Write);
|
||||
long bytesToWriteB = UntrimmedFileSizeB - FileSizeB;
|
||||
|
||||
try
|
||||
{
|
||||
Stopwatch timedSw = Lambda.Timed(() =>
|
||||
{
|
||||
WritePadding(outfileStream, bytesToWriteB, cancelToken);
|
||||
});
|
||||
|
||||
if (timedSw.Elapsed.TotalSeconds > 0)
|
||||
{
|
||||
Log?.Write(LogType.Info, $"Wrote at {bytesToWriteB / (double)XCIFileTrimmer.BytesInAMegabyte / timedSw.Elapsed.TotalSeconds:N} Mb/sec");
|
||||
}
|
||||
|
||||
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
|
||||
{
|
||||
return OperationOutcome.Cancelled;
|
||||
}
|
||||
else
|
||||
{
|
||||
return OperationOutcome.Successful;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
outfileStream.Close();
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log?.Write(LogType.Error, e.ToString());
|
||||
return OperationOutcome.FileIOWriteError;
|
||||
}
|
||||
}
|
||||
|
||||
private void WritePadding(FileStream outfileStream, long bytesToWriteB, CancellationToken? cancelToken = null)
|
||||
{
|
||||
long bytesLeftToWriteB = bytesToWriteB;
|
||||
long writes = bytesLeftToWriteB / XCIFileTrimmer.BufferSize;
|
||||
int write = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var buffer = new byte[BufferSize];
|
||||
Array.Fill<byte>(buffer, XCIFileTrimmer.PaddingByte);
|
||||
|
||||
while (bytesLeftToWriteB > 0)
|
||||
{
|
||||
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
long bytesToWrite = Math.Min(XCIFileTrimmer.BufferSize, bytesLeftToWriteB);
|
||||
|
||||
#if !XCI_TRIMMER_READ_ONLY_MODE
|
||||
outfileStream.Write(buffer, 0, (int)bytesToWrite);
|
||||
#endif
|
||||
|
||||
bytesLeftToWriteB -= bytesToWrite;
|
||||
Log?.Progress(write, writes, "Writing padding data...", false);
|
||||
write++;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log?.Progress(write, writes, "Writing padding data...", true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenReaders()
|
||||
{
|
||||
if (_binaryReader == null)
|
||||
{
|
||||
_fileStream = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
_binaryReader = new BinaryReader(_fileStream);
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseReaders()
|
||||
{
|
||||
if (_binaryReader != null && _binaryReader.BaseStream != null)
|
||||
_binaryReader.Close();
|
||||
_binaryReader = null;
|
||||
_fileStream = null;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void ReadHeader()
|
||||
{
|
||||
try
|
||||
{
|
||||
OpenReaders();
|
||||
|
||||
try
|
||||
{
|
||||
// Attempt without key area
|
||||
bool success = CheckAndReadHeader(false);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
// Attempt with key area
|
||||
success = CheckAndReadHeader(true);
|
||||
}
|
||||
|
||||
_fileOK = success;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseReaders();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log?.Write(LogType.Error, ex.Message);
|
||||
_fileOK = false;
|
||||
_dataSizeB = 0;
|
||||
_cartSizeB = 0;
|
||||
_fileSizeB = 0;
|
||||
_offsetB = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckAndReadHeader(bool assumeKeyArea)
|
||||
{
|
||||
// Read file size
|
||||
_fileSizeB = _fileStream.Length;
|
||||
if (_fileSizeB < 32 * 1024)
|
||||
{
|
||||
Log?.Write(LogType.Error, "The source file doesn't look like an XCI file as the data size is too small");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Setup offset
|
||||
_offsetB = (long)(assumeKeyArea ? XCIFileTrimmer.CartKeyAreaSize : 0);
|
||||
|
||||
// Check header
|
||||
Pos = _offsetB + XCIFileTrimmer.HeaderFilePos;
|
||||
string head = System.Text.Encoding.ASCII.GetString(_binaryReader.ReadBytes(4));
|
||||
if (head != XCIFileTrimmer.HeaderMagicValue)
|
||||
{
|
||||
if (!assumeKeyArea)
|
||||
{
|
||||
Log?.Write(LogType.Warn, $"Incorrect header found, file mat contain a key area...");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log?.Write(LogType.Error, "The source file doesn't look like an XCI file as the header is corrupted");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read Cart Size
|
||||
Pos = _offsetB + XCIFileTrimmer.CartSizeFilePos;
|
||||
byte cartSizeId = _binaryReader.ReadByte();
|
||||
if (!_cartSizesGB.TryGetValue(cartSizeId, out long cartSizeNGB))
|
||||
{
|
||||
Log?.Write(LogType.Error, $"The source file doesn't look like an XCI file as the Cartridge Size is incorrect (0x{cartSizeId:X2})");
|
||||
return false;
|
||||
}
|
||||
_cartSizeB = cartSizeNGB * XCIFileTrimmer.CartSizeMBinFormattedGB * XCIFileTrimmer.BytesInAMegabyte;
|
||||
|
||||
// Read data size
|
||||
Pos = _offsetB + XCIFileTrimmer.DataSizeFilePos;
|
||||
long records = (long)BitConverter.ToUInt32(_binaryReader.ReadBytes(4), 0);
|
||||
_dataSizeB = RecordsToByte(records);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.GAL
|
||||
IPipeline Pipeline { get; }
|
||||
|
||||
IWindow Window { get; }
|
||||
|
||||
|
||||
uint ProgramCount { get; }
|
||||
|
||||
void BackgroundContextAction(Action action, bool alwaysBackground = false);
|
||||
|
@ -152,16 +152,17 @@ namespace Ryujinx.Graphics.Gpu
|
||||
/// Creates a new GPU memory manager.
|
||||
/// </summary>
|
||||
/// <param name="pid">ID of the process that owns the memory manager</param>
|
||||
/// <param name="cpuMemorySize">The amount of physical CPU Memory Avaiable on the device.</param>
|
||||
/// <returns>The memory manager</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception>
|
||||
public MemoryManager CreateMemoryManager(ulong pid)
|
||||
public MemoryManager CreateMemoryManager(ulong pid, ulong cpuMemorySize)
|
||||
{
|
||||
if (!PhysicalMemoryRegistry.TryGetValue(pid, out var physicalMemory))
|
||||
{
|
||||
throw new ArgumentException("The PID is invalid or the process was not registered", nameof(pid));
|
||||
}
|
||||
|
||||
return new MemoryManager(physicalMemory);
|
||||
return new MemoryManager(physicalMemory, cpuMemorySize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@ -47,11 +48,17 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
{
|
||||
private const int MinCountForDeletion = 32;
|
||||
private const int MaxCapacity = 2048;
|
||||
private const ulong GiB = 1024 * 1024 * 1024;
|
||||
private ulong MaxTextureSizeCapacity = 4UL * GiB;
|
||||
private const ulong MinTextureSizeCapacity = 512 * 1024 * 1024;
|
||||
private const ulong MaxTextureSizeCapacity = 4UL * 1024 * 1024 * 1024;
|
||||
private const ulong DefaultTextureSizeCapacity = 1UL * 1024 * 1024 * 1024;
|
||||
private const ulong DefaultTextureSizeCapacity = 1 * GiB;
|
||||
private const ulong TextureSizeCapacity6GiB = 4 * GiB;
|
||||
private const ulong TextureSizeCapacity8GiB = 6 * GiB;
|
||||
private const ulong TextureSizeCapacity12GiB = 12 * GiB;
|
||||
|
||||
|
||||
private const float MemoryScaleFactor = 0.50f;
|
||||
private ulong _maxCacheMemoryUsage = 0;
|
||||
private ulong _maxCacheMemoryUsage = DefaultTextureSizeCapacity;
|
||||
|
||||
private readonly LinkedList<Texture> _textures;
|
||||
private ulong _totalSize;
|
||||
@ -66,18 +73,38 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the backend GPU has 0 memory capacity, the cache size defaults to `DefaultTextureSizeCapacity`.
|
||||
///
|
||||
/// Reads the current Device total CPU Memory, to determine the maximum amount of Vram available. Capped to 50% of Current GPU Memory.
|
||||
/// </remarks>
|
||||
/// <param name="context">The GPU context that the cache belongs to</param>
|
||||
public void Initialize(GpuContext context)
|
||||
/// <param name="cpuMemorySize">The amount of physical CPU Memory Avaiable on the device.</param>
|
||||
public void Initialize(GpuContext context, ulong cpuMemorySize)
|
||||
{
|
||||
var cpuMemorySizeGiB = cpuMemorySize / GiB;
|
||||
|
||||
if (cpuMemorySizeGiB < 6 || context.Capabilities.MaximumGpuMemory == 0)
|
||||
{
|
||||
_maxCacheMemoryUsage = DefaultTextureSizeCapacity;
|
||||
return;
|
||||
}
|
||||
else if (cpuMemorySizeGiB == 6)
|
||||
{
|
||||
MaxTextureSizeCapacity = TextureSizeCapacity6GiB;
|
||||
}
|
||||
else if (cpuMemorySizeGiB == 8)
|
||||
{
|
||||
MaxTextureSizeCapacity = TextureSizeCapacity8GiB;
|
||||
}
|
||||
else
|
||||
{
|
||||
MaxTextureSizeCapacity = TextureSizeCapacity12GiB;
|
||||
}
|
||||
|
||||
var cacheMemory = (ulong)(context.Capabilities.MaximumGpuMemory * MemoryScaleFactor);
|
||||
|
||||
_maxCacheMemoryUsage = Math.Clamp(cacheMemory, MinTextureSizeCapacity, MaxTextureSizeCapacity);
|
||||
|
||||
if (context.Capabilities.MaximumGpuMemory == 0)
|
||||
{
|
||||
_maxCacheMemoryUsage = DefaultTextureSizeCapacity;
|
||||
}
|
||||
Logger.Info?.Print(LogClass.Gpu, $"AutoDelete Cache Allocated VRAM : {_maxCacheMemoryUsage / GiB} GiB");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -71,9 +71,10 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
/// <summary>
|
||||
/// Initializes the cache, setting the maximum texture capacity for the specified GPU context.
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
/// <param name="cpuMemorySize">The amount of physical CPU Memory Avaiable on the device.</param>
|
||||
public void Initialize(ulong cpuMemorySize)
|
||||
{
|
||||
_cache.Initialize(_context);
|
||||
_cache.Initialize(_context, cpuMemorySize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -55,7 +55,8 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
/// Creates a new instance of the GPU memory manager.
|
||||
/// </summary>
|
||||
/// <param name="physicalMemory">Physical memory that this memory manager will map into</param>
|
||||
internal MemoryManager(PhysicalMemory physicalMemory)
|
||||
/// <param name="cpuMemorySize">The amount of physical CPU Memory Avaiable on the device.</param>
|
||||
internal MemoryManager(PhysicalMemory physicalMemory, ulong cpuMemorySize)
|
||||
{
|
||||
Physical = physicalMemory;
|
||||
VirtualRangeCache = new VirtualRangeCache(this);
|
||||
@ -65,7 +66,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
MemoryUnmapped += Physical.BufferCache.MemoryUnmappedHandler;
|
||||
MemoryUnmapped += VirtualRangeCache.MemoryUnmappedHandler;
|
||||
MemoryUnmapped += CounterCache.MemoryUnmappedHandler;
|
||||
Physical.TextureCache.Initialize();
|
||||
Physical.TextureCache.Initialize(cpuMemorySize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -97,7 +97,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info)
|
||||
{
|
||||
ProgramCount++;
|
||||
|
||||
|
||||
return new Program(shaders, info.FragmentOutputMap);
|
||||
}
|
||||
|
||||
|
@ -432,7 +432,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
||||
|
||||
bool colorIsVector = isGather || !isShadow;
|
||||
|
||||
texCall += ")" + (colorIsVector ? GetMaskMultiDest(texOp.Index) : "");
|
||||
texCall += ")" + (colorIsVector ? GetMaskMultiDest(texOp.Index) : string.Empty);
|
||||
|
||||
return texCall;
|
||||
}
|
||||
|
@ -830,12 +830,12 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
if (use.Node != null)
|
||||
{
|
||||
Console.Write($"{indentation} {separator}- ({(use.Inverted ? "INV " : "")}{use.Index})");
|
||||
Console.Write($"{indentation} {separator}- ({(use.Inverted ? "INV " : string.Empty)}{use.Index})");
|
||||
PrintTreeNode(use.Node, indentation + (last ? " " : " | "));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{indentation} {separator}- ({(use.Inverted ? "INV " : "")}{use.Index}) NULL");
|
||||
Console.WriteLine($"{indentation} {separator}- ({(use.Inverted ? "INV " : string.Empty)}{use.Index}) NULL");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -852,12 +852,12 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
if (use.Node != null)
|
||||
{
|
||||
Console.Write($"{indentation} {separator}- ({(use.Inverted ? "INV " : "")}{use.Index})");
|
||||
Console.Write($"{indentation} {separator}- ({(use.Inverted ? "INV " : string.Empty)}{use.Index})");
|
||||
PrintTreeNode(use.Node, indentation + (last ? " " : " | "));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"{indentation} {separator}- ({(use.Inverted ? "INV " : "")}{use.Index}) NULL");
|
||||
Console.WriteLine($"{indentation} {separator}- ({(use.Inverted ? "INV " : string.Empty)}{use.Index}) NULL");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,8 +55,10 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
if (_handle != BufferHandle.Null)
|
||||
{
|
||||
// May need to restride the vertex buffer.
|
||||
|
||||
if (gd.NeedsVertexBufferAlignment(AttributeScalarAlignment, out int alignment) && (_stride % alignment) != 0)
|
||||
//
|
||||
// Fix divide by zero when recovering from missed draw (Oct. 16 2024)
|
||||
// (fixes crash in 'Baldo: The Guardian Owls' opening cutscene)
|
||||
if (gd.NeedsVertexBufferAlignment(AttributeScalarAlignment, out int alignment) && alignment != 0 && (_stride % alignment) != 0)
|
||||
{
|
||||
autoBuffer = gd.BufferManager.GetAlignedVertexBuffer(cbs, _handle, _offset, _size, _stride, alignment);
|
||||
|
||||
|
@ -104,25 +104,27 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
|
||||
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;
|
||||
|
||||
public VulkanRenderer(Vk api, Func<Instance, Vk, SurfaceKHR> surfaceFunc, Func<string[]> requiredExtensionsFunc, string preferredGpuId)
|
||||
public VulkanRenderer(Vk api, Func<Instance, Vk, SurfaceKHR> getSurface, Func<string[]> requiredExtensionsFunc, string preferredGpuId)
|
||||
{
|
||||
_getSurface = surfaceFunc;
|
||||
_getSurface = getSurface;
|
||||
_getRequiredExtensions = requiredExtensionsFunc;
|
||||
_preferredGpuId = preferredGpuId;
|
||||
Api = api;
|
||||
Shaders = new HashSet<ShaderCollection>();
|
||||
Textures = new HashSet<ITexture>();
|
||||
Samplers = new HashSet<SamplerHolder>();
|
||||
Shaders = [];
|
||||
Textures = [];
|
||||
Samplers = [];
|
||||
|
||||
if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
// Any device running on MacOS is using MoltenVK, even Intel and AMD vendors.
|
||||
if (IsMoltenVk = OperatingSystem.IsMacOS())
|
||||
MVKInitialization.Initialize();
|
||||
|
||||
// Any device running on MacOS is using MoltenVK, even Intel and AMD vendors.
|
||||
IsMoltenVk = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static VulkanRenderer Create(
|
||||
string preferredGpuId,
|
||||
Func<Instance, Vk, SurfaceKHR> getSurface,
|
||||
Func<string[]> getRequiredExtensions
|
||||
) => new(Vk.GetApi(), getSurface, getRequiredExtensions, preferredGpuId);
|
||||
|
||||
private unsafe void LoadFeatures(uint maxQueueCount, uint queueFamilyIndex)
|
||||
{
|
||||
FormatCapabilities = new FormatCapabilities(Api, _physicalDevice.PhysicalDevice);
|
||||
@ -547,7 +549,7 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
public IProgram CreateProgram(ShaderSource[] sources, ShaderInfo info)
|
||||
{
|
||||
ProgramCount++;
|
||||
|
||||
|
||||
bool isCompute = sources.Length == 1 && sources[0].Stage == ShaderStage.Compute;
|
||||
|
||||
if (info.State.HasValue || isCompute)
|
||||
|
@ -13,6 +13,7 @@ namespace Ryujinx.HLE.Generators
|
||||
var syntaxReceiver = (ServiceSyntaxReceiver)context.SyntaxReceiver;
|
||||
CodeGenerator generator = new CodeGenerator();
|
||||
|
||||
generator.AppendLine("#nullable enable");
|
||||
generator.AppendLine("using System;");
|
||||
generator.EnterScope($"namespace Ryujinx.HLE.HOS.Services.Sm");
|
||||
generator.EnterScope($"partial class IUserInterface");
|
||||
@ -22,7 +23,7 @@ namespace Ryujinx.HLE.Generators
|
||||
{
|
||||
if (className.Modifiers.Any(SyntaxKind.AbstractKeyword) || className.Modifiers.Any(SyntaxKind.PrivateKeyword) || !className.AttributeLists.Any(x => x.Attributes.Any(y => y.ToString().StartsWith("Service"))))
|
||||
continue;
|
||||
var name = GetFullName(className, context).Replace("global::", "");
|
||||
var name = GetFullName(className, context).Replace("global::", string.Empty);
|
||||
if (!name.StartsWith("Ryujinx.HLE.HOS.Services"))
|
||||
continue;
|
||||
var constructors = className.ChildNodes().Where(x => x.IsKind(SyntaxKind.ConstructorDeclaration)).Select(y => y as ConstructorDeclarationSyntax).ToArray();
|
||||
@ -58,6 +59,7 @@ namespace Ryujinx.HLE.Generators
|
||||
|
||||
generator.LeaveScope();
|
||||
generator.LeaveScope();
|
||||
generator.AppendLine("#nullable disable");
|
||||
context.AddSource($"IUserInterface.g.cs", generator.ToString());
|
||||
}
|
||||
|
||||
|
@ -523,7 +523,7 @@ namespace Ryujinx.HLE.FileSystem
|
||||
{
|
||||
// Clean up the name and get the NcaId
|
||||
|
||||
string[] pathComponents = entry.FullName.Replace(".cnmt", "").Split('/');
|
||||
string[] pathComponents = entry.FullName.Replace(".cnmt", string.Empty).Split('/');
|
||||
|
||||
string ncaId = pathComponents[^1];
|
||||
|
||||
|
@ -132,7 +132,7 @@ namespace Ryujinx.HLE.FileSystem
|
||||
|
||||
if (systemPath.StartsWith(baseSystemPath))
|
||||
{
|
||||
string rawPath = systemPath.Replace(baseSystemPath, "");
|
||||
string rawPath = systemPath.Replace(baseSystemPath, string.Empty);
|
||||
int firstSeparatorOffset = rawPath.IndexOf(Path.DirectorySeparatorChar);
|
||||
|
||||
if (firstSeparatorOffset == -1)
|
||||
|
@ -164,6 +164,21 @@ namespace Ryujinx.HLE
|
||||
/// </summary>
|
||||
public MultiplayerMode MultiplayerMode { internal get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Disable P2P mode
|
||||
/// </summary>
|
||||
public bool MultiplayerDisableP2p { internal get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Multiplayer Passphrase
|
||||
/// </summary>
|
||||
public string MultiplayerLdnPassphrase { internal get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// LDN Server
|
||||
/// </summary>
|
||||
public string MultiplayerLdnServer { internal get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An action called when HLE force a refresh of output after docked mode changed.
|
||||
/// </summary>
|
||||
@ -194,7 +209,10 @@ namespace Ryujinx.HLE
|
||||
float audioVolume,
|
||||
bool useHypervisor,
|
||||
string multiplayerLanInterfaceId,
|
||||
MultiplayerMode multiplayerMode)
|
||||
MultiplayerMode multiplayerMode,
|
||||
bool multiplayerDisableP2p,
|
||||
string multiplayerLdnPassphrase,
|
||||
string multiplayerLdnServer)
|
||||
{
|
||||
VirtualFileSystem = virtualFileSystem;
|
||||
LibHacHorizonManager = libHacHorizonManager;
|
||||
@ -222,6 +240,9 @@ namespace Ryujinx.HLE
|
||||
UseHypervisor = useHypervisor;
|
||||
MultiplayerLanInterfaceId = multiplayerLanInterfaceId;
|
||||
MultiplayerMode = multiplayerMode;
|
||||
MultiplayerDisableP2p = multiplayerDisableP2p;
|
||||
MultiplayerLdnPassphrase = multiplayerLdnPassphrase;
|
||||
MultiplayerLdnServer = multiplayerLdnServer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Applets.Browser;
|
||||
using Ryujinx.HLE.HOS.Applets.Dummy;
|
||||
using Ryujinx.HLE.HOS.Applets.Error;
|
||||
using Ryujinx.HLE.HOS.Services.Am.AppletAE;
|
||||
using System;
|
||||
@ -26,9 +28,13 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
return new BrowserApplet(system);
|
||||
case AppletId.LibAppletOff:
|
||||
return new BrowserApplet(system);
|
||||
case AppletId.MiiEdit:
|
||||
Logger.Warning?.Print(LogClass.Application, $"Please use the MiiEdit inside File/Open Applet");
|
||||
return new DummyApplet(system);
|
||||
}
|
||||
|
||||
throw new NotImplementedException($"{applet} applet is not implemented.");
|
||||
Logger.Warning?.Print(LogClass.Application, $"Applet {applet} not implemented!");
|
||||
return new DummyApplet(system);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
43
src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs
Normal file
43
src/Ryujinx.HLE/HOS/Applets/Dummy/DummyApplet.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.HLE.HOS.Applets;
|
||||
using Ryujinx.HLE.HOS.Services.Am.AppletAE;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
namespace Ryujinx.HLE.HOS.Applets.Dummy
|
||||
{
|
||||
internal class DummyApplet : IApplet
|
||||
{
|
||||
private readonly Horizon _system;
|
||||
private AppletSession _normalSession;
|
||||
public event EventHandler AppletStateChanged;
|
||||
public DummyApplet(Horizon system)
|
||||
{
|
||||
_system = system;
|
||||
}
|
||||
public ResultCode Start(AppletSession normalSession, AppletSession interactiveSession)
|
||||
{
|
||||
_normalSession = normalSession;
|
||||
_normalSession.Push(BuildResponse());
|
||||
AppletStateChanged?.Invoke(this, null);
|
||||
_system.ReturnFocus();
|
||||
return ResultCode.Success;
|
||||
}
|
||||
private static T ReadStruct<T>(byte[] data) where T : struct
|
||||
{
|
||||
return MemoryMarshal.Read<T>(data.AsSpan());
|
||||
}
|
||||
private static byte[] BuildResponse()
|
||||
{
|
||||
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
|
||||
using BinaryWriter writer = new(stream);
|
||||
writer.Write((ulong)ResultCode.Success);
|
||||
return stream.ToArray();
|
||||
}
|
||||
public ResultCode GetResult()
|
||||
{
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
@ -107,7 +107,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error
|
||||
|
||||
private static string CleanText(string value)
|
||||
{
|
||||
return CleanTextRegex().Replace(value, "").Replace("\0", "");
|
||||
return CleanTextRegex().Replace(value, string.Empty).Replace("\0", string.Empty);
|
||||
}
|
||||
|
||||
private string GetMessageText(uint module, uint description, string key)
|
||||
@ -129,17 +129,15 @@ namespace Ryujinx.HLE.HOS.Applets.Error
|
||||
|
||||
return CleanText(reader.ReadToEnd());
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private string[] GetButtonsText(uint module, uint description, string key)
|
||||
{
|
||||
string buttonsText = GetMessageText(module, description, key);
|
||||
|
||||
return (buttonsText == "") ? null : buttonsText.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
|
||||
return (buttonsText == string.Empty) ? null : buttonsText.Split(["\r\n", "\r", "\n"], StringSplitOptions.None);
|
||||
}
|
||||
|
||||
private void ParseErrorCommonArg()
|
||||
@ -156,7 +154,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error
|
||||
|
||||
string message = GetMessageText(module, description, "DlgMsg");
|
||||
|
||||
if (message == "")
|
||||
if (message == string.Empty)
|
||||
{
|
||||
message = "An error has occured.\n\nPlease try again later.";
|
||||
}
|
||||
@ -190,7 +188,7 @@ namespace Ryujinx.HLE.HOS.Applets.Error
|
||||
|
||||
// TODO: Handle the LanguageCode to return the translated "OK" and "Details".
|
||||
|
||||
if (detailsText.Trim() != "")
|
||||
if (detailsText.Trim() != string.Empty)
|
||||
{
|
||||
buttons.Add("Details");
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
|
||||
private byte[] _transferMemory;
|
||||
|
||||
private string _textValue = "";
|
||||
private string _textValue = string.Empty;
|
||||
private int _cursorBegin = 0;
|
||||
private Encoding _encoding = Encoding.Unicode;
|
||||
private KeyboardResult _lastResult = KeyboardResult.NotSet;
|
||||
|
@ -305,7 +305,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
||||
{
|
||||
SKRect bounds = SKRect.Empty;
|
||||
|
||||
if (text == "")
|
||||
if (text == string.Empty)
|
||||
{
|
||||
paint.MeasureText(" ", ref bounds);
|
||||
}
|
||||
@ -321,7 +321,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
||||
{
|
||||
SKRect bounds = SKRect.Empty;
|
||||
|
||||
if (text == "")
|
||||
if (text == string.Empty)
|
||||
{
|
||||
paint.MeasureText(" ", ref bounds);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
||||
/// </summary>
|
||||
internal class SoftwareKeyboardUIState
|
||||
{
|
||||
public string InputText = "";
|
||||
public string InputText = string.Empty;
|
||||
public int CursorBegin = 0;
|
||||
public int CursorEnd = 0;
|
||||
public bool AcceptPressed = false;
|
||||
|
@ -2463,7 +2463,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler
|
||||
return ParseIntegerLiteral("unsigned short");
|
||||
case 'i':
|
||||
_position++;
|
||||
return ParseIntegerLiteral("");
|
||||
return ParseIntegerLiteral(string.Empty);
|
||||
case 'j':
|
||||
_position++;
|
||||
return ParseIntegerLiteral("u");
|
||||
|
@ -238,7 +238,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||
}
|
||||
else
|
||||
{
|
||||
info.SubName = "";
|
||||
info.SubName = string.Empty;
|
||||
}
|
||||
|
||||
info.ImageName = GetGuessedNsoNameFromIndex(imageIndex);
|
||||
|
@ -116,18 +116,13 @@ namespace Ryujinx.HLE.HOS
|
||||
private readonly Dictionary<ulong, ModCache> _appMods; // key is ApplicationId
|
||||
private PatchCache _patches;
|
||||
|
||||
private static readonly EnumerationOptions _dirEnumOptions;
|
||||
|
||||
static ModLoader()
|
||||
private static readonly EnumerationOptions _dirEnumOptions = new()
|
||||
{
|
||||
_dirEnumOptions = new EnumerationOptions
|
||||
{
|
||||
MatchCasing = MatchCasing.CaseInsensitive,
|
||||
MatchType = MatchType.Simple,
|
||||
RecurseSubdirectories = false,
|
||||
ReturnSpecialDirectories = false,
|
||||
};
|
||||
}
|
||||
MatchCasing = MatchCasing.CaseInsensitive,
|
||||
MatchType = MatchType.Simple,
|
||||
RecurseSubdirectories = false,
|
||||
ReturnSpecialDirectories = false,
|
||||
};
|
||||
|
||||
public ModLoader()
|
||||
{
|
||||
@ -169,7 +164,7 @@ namespace Ryujinx.HLE.HOS
|
||||
foreach (var modDir in dir.EnumerateDirectories())
|
||||
{
|
||||
types.Clear();
|
||||
Mod<DirectoryInfo> mod = new("", null, true);
|
||||
Mod<DirectoryInfo> mod = new(string.Empty, null, true);
|
||||
|
||||
if (StrEquals(RomfsDir, modDir.Name))
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
||||
{
|
||||
if (userId.IsNull)
|
||||
{
|
||||
userId = new UserId(Guid.NewGuid().ToString().Replace("-", ""));
|
||||
userId = new UserId(Guid.NewGuid().ToString().Replace("-", string.Empty));
|
||||
}
|
||||
|
||||
UserProfile profile = new(userId, name, image);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Ryujinx.HLE.HOS.Services.Am.AppletAE.AllSystemAppletProxiesService;
|
||||
using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Am.AppletAE
|
||||
{
|
||||
@ -25,5 +26,14 @@ namespace Ryujinx.HLE.HOS.Services.Am.AppletAE
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(350)]
|
||||
// OpenSystemApplicationProxy(u64, pid, handle<copy>) -> object<nn::am::service::IApplicationProxy>
|
||||
public ResultCode OpenSystemApplicationProxy(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new IApplicationProxy(context.Request.HandleDesc.PId));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using Ryujinx.HLE.Exceptions;
|
||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugMouse;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugPad;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse;
|
||||
@ -28,6 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
public DebugPadDevice DebugPad;
|
||||
public TouchDevice Touchscreen;
|
||||
public MouseDevice Mouse;
|
||||
public DebugMouseDevice DebugMouse;
|
||||
public KeyboardDevice Keyboard;
|
||||
public NpadDevices Npads;
|
||||
|
||||
@ -44,6 +46,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
CheckTypeSizeOrThrow<RingLifo<DebugPadState>>(0x2c8);
|
||||
CheckTypeSizeOrThrow<RingLifo<TouchScreenState>>(0x2C38);
|
||||
CheckTypeSizeOrThrow<RingLifo<MouseState>>(0x350);
|
||||
CheckTypeSizeOrThrow<RingLifo<DebugMouseState>>(0x350);
|
||||
CheckTypeSizeOrThrow<RingLifo<KeyboardState>>(0x3D8);
|
||||
CheckTypeSizeOrThrow<Array10<NpadState>>(0x32000);
|
||||
CheckTypeSizeOrThrow<SharedMemory>(Horizon.HidSize);
|
||||
@ -64,6 +67,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
DebugPad = new DebugPadDevice(_device, true);
|
||||
Touchscreen = new TouchDevice(_device, true);
|
||||
Mouse = new MouseDevice(_device, false);
|
||||
DebugMouse = new DebugMouseDevice(_device, false);
|
||||
Keyboard = new KeyboardDevice(_device, false);
|
||||
Npads = new NpadDevices(_device, true);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugMouse;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
{
|
||||
public class DebugMouseDevice : BaseDevice
|
||||
{
|
||||
public DebugMouseDevice(Switch device, bool active) : base(device, active) { }
|
||||
|
||||
public void Update()
|
||||
{
|
||||
ref RingLifo<DebugMouseState> lifo = ref _device.Hid.SharedMemory.DebugMouse;
|
||||
|
||||
ref DebugMouseState previousEntry = ref lifo.GetCurrentEntryRef();
|
||||
|
||||
DebugMouseState newState = new()
|
||||
{
|
||||
SamplingNumber = previousEntry.SamplingNumber + 1,
|
||||
};
|
||||
|
||||
if (Active)
|
||||
{
|
||||
// TODO: This is a debug device only present in dev environment, do we want to support it?
|
||||
}
|
||||
|
||||
lifo.Write(ref newState);
|
||||
}
|
||||
}
|
||||
}
|
@ -130,6 +130,26 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(26)]
|
||||
// ActivateDebugMouse(nn::applet::AppletResourceUserId)
|
||||
public ResultCode ActivateDebugMouse(ServiceCtx context)
|
||||
{
|
||||
long appletResourceUserId = context.RequestData.ReadInt64();
|
||||
|
||||
context.Device.Hid.DebugMouse.Active = true;
|
||||
|
||||
// Initialize entries to avoid issues with some games.
|
||||
|
||||
for (int entry = 0; entry < Hid.SharedMemEntryCount; entry++)
|
||||
{
|
||||
context.Device.Hid.DebugMouse.Update();
|
||||
}
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(31)]
|
||||
// ActivateKeyboard(nn::applet::AppletResourceUserId)
|
||||
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugMouse
|
||||
{
|
||||
[Flags]
|
||||
enum DebugMouseAttribute : uint
|
||||
{
|
||||
None = 0,
|
||||
Transferable = 1 << 0,
|
||||
IsConnected = 1 << 1,
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugMouse
|
||||
{
|
||||
[Flags]
|
||||
enum DebugMouseButton : uint
|
||||
{
|
||||
None = 0,
|
||||
Left = 1 << 0,
|
||||
Right = 1 << 1,
|
||||
Middle = 1 << 2,
|
||||
Forward = 1 << 3,
|
||||
Back = 1 << 4,
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugMouse
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
struct DebugMouseState : ISampledDataStruct
|
||||
{
|
||||
public ulong SamplingNumber;
|
||||
public int X;
|
||||
public int Y;
|
||||
public int DeltaX;
|
||||
public int DeltaY;
|
||||
public int WheelDeltaX;
|
||||
public int WheelDeltaY;
|
||||
public DebugMouseButton Buttons;
|
||||
public DebugMouseAttribute Attributes;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugMouse;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.DebugPad;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Keyboard;
|
||||
using Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory.Mouse;
|
||||
@ -44,6 +45,12 @@ namespace Ryujinx.HLE.HOS.Services.Hid.Types.SharedMemory
|
||||
/// </summary>
|
||||
[FieldOffset(0x9A00)]
|
||||
public Array10<NpadState> Npads;
|
||||
|
||||
/// <summary>
|
||||
/// Debug mouse.
|
||||
/// </summary>
|
||||
[FieldOffset(0x3DC00)]
|
||||
public RingLifo<DebugMouseState> DebugMouse;
|
||||
|
||||
public static SharedMemory Create()
|
||||
{
|
||||
|
@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x20)]
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x20, Pack = 8)]
|
||||
struct NetworkConfig
|
||||
{
|
||||
public IntentId IntentId;
|
||||
|
@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x60)]
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x60, Pack = 8)]
|
||||
struct ScanFilter
|
||||
{
|
||||
public NetworkId NetworkId;
|
||||
|
@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x44)]
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x44, Pack = 2)]
|
||||
struct SecurityConfig
|
||||
{
|
||||
public SecurityMode SecurityMode;
|
||||
|
@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x20)]
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x20, Pack = 1)]
|
||||
struct SecurityParameter
|
||||
{
|
||||
public Array16<byte> Data;
|
||||
|
@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x30)]
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x30, Pack = 1)]
|
||||
struct UserConfig
|
||||
{
|
||||
public Array33<byte> UserName;
|
||||
|
@ -15,6 +15,8 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
public Array8<NodeLatestUpdate> LatestUpdates = new();
|
||||
public bool Connected { get; private set; }
|
||||
|
||||
public ProxyConfig Config => _parent.NetworkClient.Config;
|
||||
|
||||
public AccessPoint(IUserLocalCommunicationService parent)
|
||||
{
|
||||
_parent = parent;
|
||||
@ -24,9 +26,12 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_parent.NetworkClient.DisconnectNetwork();
|
||||
if (_parent?.NetworkClient != null)
|
||||
{
|
||||
_parent.NetworkClient.DisconnectNetwork();
|
||||
|
||||
_parent.NetworkClient.NetworkChange -= NetworkChanged;
|
||||
_parent.NetworkClient.NetworkChange -= NetworkChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void NetworkChanged(object sender, NetworkChangeEventArgs e)
|
||||
|
@ -6,6 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
{
|
||||
interface INetworkClient : IDisposable
|
||||
{
|
||||
ProxyConfig Config { get; }
|
||||
bool NeedsRealId { get; }
|
||||
|
||||
event EventHandler<NetworkChangeEventArgs> NetworkChange;
|
||||
|
@ -9,6 +9,8 @@ using Ryujinx.HLE.HOS.Ipc;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.Types;
|
||||
using Ryujinx.Horizon.Common;
|
||||
using Ryujinx.Memory;
|
||||
using System;
|
||||
@ -21,6 +23,9 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
{
|
||||
class IUserLocalCommunicationService : IpcService, IDisposable
|
||||
{
|
||||
public static string DefaultLanPlayHost = "ryuldn.vudjun.com";
|
||||
public static short LanPlayPort = 30456;
|
||||
|
||||
public INetworkClient NetworkClient { get; private set; }
|
||||
|
||||
private const int NifmRequestID = 90;
|
||||
@ -175,19 +180,37 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
|
||||
if (_state == NetworkState.AccessPointCreated || _state == NetworkState.StationConnected)
|
||||
{
|
||||
(_, UnicastIPAddressInformation unicastAddress) = NetworkHelpers.GetLocalInterface(context.Device.Configuration.MultiplayerLanInterfaceId);
|
||||
|
||||
if (unicastAddress == null)
|
||||
ProxyConfig config = _state switch
|
||||
{
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(DefaultIPAddress));
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(DefaultSubnetMask));
|
||||
NetworkState.AccessPointCreated => _accessPoint.Config,
|
||||
NetworkState.StationConnected => _station.Config,
|
||||
|
||||
_ => default
|
||||
};
|
||||
|
||||
if (config.ProxyIp == 0)
|
||||
{
|
||||
(_, UnicastIPAddressInformation unicastAddress) = NetworkHelpers.GetLocalInterface(context.Device.Configuration.MultiplayerLanInterfaceId);
|
||||
|
||||
if (unicastAddress == null)
|
||||
{
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(DefaultIPAddress));
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(DefaultSubnetMask));
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Info?.Print(LogClass.ServiceLdn, $"Console's LDN IP is \"{unicastAddress.Address}\".");
|
||||
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(unicastAddress.Address));
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(unicastAddress.IPv4Mask));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Info?.Print(LogClass.ServiceLdn, $"Console's LDN IP is \"{unicastAddress.Address}\".");
|
||||
Logger.Info?.Print(LogClass.ServiceLdn, $"LDN obtained proxy IP.");
|
||||
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(unicastAddress.Address));
|
||||
context.ResponseData.Write(NetworkHelpers.ConvertIpv4Address(unicastAddress.IPv4Mask));
|
||||
context.ResponseData.Write(config.ProxyIp);
|
||||
context.ResponseData.Write(config.ProxySubnetMask);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1066,6 +1089,27 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case MultiplayerMode.LdnRyu:
|
||||
try
|
||||
{
|
||||
string ldnServer = context.Device.Configuration.MultiplayerLdnServer;
|
||||
if (string.IsNullOrEmpty(ldnServer))
|
||||
{
|
||||
ldnServer = DefaultLanPlayHost;
|
||||
}
|
||||
if (!IPAddress.TryParse(ldnServer, out IPAddress ipAddress))
|
||||
{
|
||||
ipAddress = Dns.GetHostEntry(ldnServer).AddressList[0];
|
||||
}
|
||||
NetworkClient = new LdnMasterProxyClient(ipAddress.ToString(), LanPlayPort, context.Device.Configuration);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceLdn, "Could not locate LdnRyu server. Defaulting to stubbed wireless.");
|
||||
Logger.Error?.Print(LogClass.ServiceLdn, ex.Message);
|
||||
NetworkClient = new LdnDisabledClient();
|
||||
}
|
||||
break;
|
||||
case MultiplayerMode.LdnMitm:
|
||||
NetworkClient = new LdnMitmClient(context.Device.Configuration);
|
||||
break;
|
||||
@ -1103,7 +1147,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
_accessPoint?.Dispose();
|
||||
_accessPoint = null;
|
||||
|
||||
NetworkClient?.Dispose();
|
||||
NetworkClient?.DisconnectAndStop();
|
||||
NetworkClient = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.Types;
|
||||
using System;
|
||||
@ -6,12 +7,14 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
{
|
||||
class LdnDisabledClient : INetworkClient
|
||||
{
|
||||
public ProxyConfig Config { get; }
|
||||
public bool NeedsRealId => true;
|
||||
|
||||
public event EventHandler<NetworkChangeEventArgs> NetworkChange;
|
||||
|
||||
public NetworkError Connect(ConnectRequest request)
|
||||
{
|
||||
Logger.Warning?.PrintMsg(LogClass.ServiceLdn, "Attempted to connect to a network, but Multiplayer is disabled!");
|
||||
NetworkChange?.Invoke(this, new NetworkChangeEventArgs(new NetworkInfo(), false));
|
||||
|
||||
return NetworkError.None;
|
||||
@ -19,6 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
|
||||
public NetworkError ConnectPrivate(ConnectPrivateRequest request)
|
||||
{
|
||||
Logger.Warning?.PrintMsg(LogClass.ServiceLdn, "Attempted to connect to a network, but Multiplayer is disabled!");
|
||||
NetworkChange?.Invoke(this, new NetworkChangeEventArgs(new NetworkInfo(), false));
|
||||
|
||||
return NetworkError.None;
|
||||
@ -26,6 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
|
||||
public bool CreateNetwork(CreateAccessPointRequest request, byte[] advertiseData)
|
||||
{
|
||||
Logger.Warning?.PrintMsg(LogClass.ServiceLdn, "Attempted to create a network, but Multiplayer is disabled!");
|
||||
NetworkChange?.Invoke(this, new NetworkChangeEventArgs(new NetworkInfo(), false));
|
||||
|
||||
return true;
|
||||
@ -33,6 +38,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
|
||||
public bool CreateNetworkPrivate(CreateAccessPointPrivateRequest request, byte[] advertiseData)
|
||||
{
|
||||
Logger.Warning?.PrintMsg(LogClass.ServiceLdn, "Attempted to create a network, but Multiplayer is disabled!");
|
||||
NetworkChange?.Invoke(this, new NetworkChangeEventArgs(new NetworkInfo(), false));
|
||||
|
||||
return true;
|
||||
@ -49,6 +55,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
|
||||
|
||||
public NetworkInfo[] Scan(ushort channel, ScanFilter scanFilter)
|
||||
{
|
||||
Logger.Warning?.PrintMsg(LogClass.ServiceLdn, "Attempted to scan for networks, but Multiplayer is disabled!");
|
||||
return Array.Empty<NetworkInfo>();
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Gommon;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
@ -143,7 +144,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm
|
||||
if (decompressedLdnData.Length != header.DecompressLength)
|
||||
{
|
||||
Logger.Error?.PrintMsg(LogClass.ServiceLdn, $"Decompress error: length does not match. ({decompressedLdnData.Length} != {header.DecompressLength})");
|
||||
Logger.Error?.PrintMsg(LogClass.ServiceLdn, $"Decompress error data: '{string.Join("", decompressedLdnData.Select(x => (int)x).ToArray())}'");
|
||||
Logger.Error?.PrintMsg(LogClass.ServiceLdn, $"Decompress error data: '{decompressedLdnData.Select(x => (int)x).JoinToString(string.Empty)}'");
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnMitm
|
||||
/// </summary>
|
||||
internal class LdnMitmClient : INetworkClient
|
||||
{
|
||||
public ProxyConfig Config { get; }
|
||||
public bool NeedsRealId => false;
|
||||
|
||||
public event EventHandler<NetworkChangeEventArgs> NetworkChange;
|
||||
|
@ -0,0 +1,7 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
|
||||
{
|
||||
interface IProxyClient
|
||||
{
|
||||
bool SendAsync(byte[] buffer);
|
||||
}
|
||||
}
|
@ -0,0 +1,645 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy;
|
||||
using Ryujinx.HLE.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TcpClient = NetCoreServer.TcpClient;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
|
||||
{
|
||||
class LdnMasterProxyClient : TcpClient, INetworkClient, IProxyClient
|
||||
{
|
||||
public bool NeedsRealId => true;
|
||||
|
||||
private static InitializeMessage InitializeMemory = new InitializeMessage();
|
||||
|
||||
private const int InactiveTimeout = 6000;
|
||||
private const int FailureTimeout = 4000;
|
||||
private const int ScanTimeout = 1000;
|
||||
|
||||
private bool _useP2pProxy;
|
||||
private NetworkError _lastError;
|
||||
|
||||
private readonly ManualResetEvent _connected = new ManualResetEvent(false);
|
||||
private readonly ManualResetEvent _error = new ManualResetEvent(false);
|
||||
private readonly ManualResetEvent _scan = new ManualResetEvent(false);
|
||||
private readonly ManualResetEvent _reject = new ManualResetEvent(false);
|
||||
private readonly AutoResetEvent _apConnected = new AutoResetEvent(false);
|
||||
|
||||
private readonly RyuLdnProtocol _protocol;
|
||||
private readonly NetworkTimeout _timeout;
|
||||
|
||||
private readonly List<NetworkInfo> _availableGames = new List<NetworkInfo>();
|
||||
private DisconnectReason _disconnectReason;
|
||||
|
||||
private P2pProxyServer _hostedProxy;
|
||||
private P2pProxyClient _connectedProxy;
|
||||
|
||||
private bool _networkConnected;
|
||||
|
||||
private string _passphrase;
|
||||
private byte[] _gameVersion = new byte[0x10];
|
||||
|
||||
private readonly HLEConfiguration _config;
|
||||
|
||||
public event EventHandler<NetworkChangeEventArgs> NetworkChange;
|
||||
|
||||
public ProxyConfig Config { get; private set; }
|
||||
|
||||
public LdnMasterProxyClient(string address, int port, HLEConfiguration config) : base(address, port)
|
||||
{
|
||||
if (ProxyHelpers.SupportsNoDelay())
|
||||
{
|
||||
OptionNoDelay = true;
|
||||
}
|
||||
|
||||
_protocol = new RyuLdnProtocol();
|
||||
_timeout = new NetworkTimeout(InactiveTimeout, TimeoutConnection);
|
||||
|
||||
_protocol.Initialize += HandleInitialize;
|
||||
_protocol.Connected += HandleConnected;
|
||||
_protocol.Reject += HandleReject;
|
||||
_protocol.RejectReply += HandleRejectReply;
|
||||
_protocol.SyncNetwork += HandleSyncNetwork;
|
||||
_protocol.ProxyConfig += HandleProxyConfig;
|
||||
_protocol.Disconnected += HandleDisconnected;
|
||||
|
||||
_protocol.ScanReply += HandleScanReply;
|
||||
_protocol.ScanReplyEnd += HandleScanReplyEnd;
|
||||
_protocol.ExternalProxy += HandleExternalProxy;
|
||||
|
||||
_protocol.Ping += HandlePing;
|
||||
_protocol.NetworkError += HandleNetworkError;
|
||||
|
||||
_config = config;
|
||||
_useP2pProxy = !config.MultiplayerDisableP2p;
|
||||
}
|
||||
|
||||
private void TimeoutConnection()
|
||||
{
|
||||
_connected.Reset();
|
||||
|
||||
DisconnectAsync();
|
||||
|
||||
while (IsConnected)
|
||||
{
|
||||
Thread.Yield();
|
||||
}
|
||||
}
|
||||
|
||||
private bool EnsureConnected()
|
||||
{
|
||||
if (IsConnected)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
_error.Reset();
|
||||
|
||||
ConnectAsync();
|
||||
|
||||
int index = WaitHandle.WaitAny(new WaitHandle[] { _connected, _error }, FailureTimeout);
|
||||
|
||||
if (IsConnected)
|
||||
{
|
||||
SendAsync(_protocol.Encode(PacketId.Initialize, InitializeMemory));
|
||||
}
|
||||
|
||||
return index == 0 && IsConnected;
|
||||
}
|
||||
|
||||
private void UpdatePassphraseIfNeeded()
|
||||
{
|
||||
string passphrase = _config.MultiplayerLdnPassphrase ?? "";
|
||||
if (passphrase != _passphrase)
|
||||
{
|
||||
_passphrase = passphrase;
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.Passphrase, StringUtils.GetFixedLengthBytes(passphrase, 0x80, Encoding.UTF8)));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnConnected()
|
||||
{
|
||||
Logger.Info?.PrintMsg(LogClass.ServiceLdn, $"LDN TCP client connected a new session with Id {Id}");
|
||||
|
||||
UpdatePassphraseIfNeeded();
|
||||
|
||||
_connected.Set();
|
||||
}
|
||||
|
||||
protected override void OnDisconnected()
|
||||
{
|
||||
Logger.Info?.PrintMsg(LogClass.ServiceLdn, $"LDN TCP client disconnected a session with Id {Id}");
|
||||
|
||||
_passphrase = null;
|
||||
|
||||
_connected.Reset();
|
||||
|
||||
if (_networkConnected)
|
||||
{
|
||||
DisconnectInternal();
|
||||
}
|
||||
}
|
||||
|
||||
public void DisconnectAndStop()
|
||||
{
|
||||
_timeout.Dispose();
|
||||
|
||||
DisconnectAsync();
|
||||
|
||||
while (IsConnected)
|
||||
{
|
||||
Thread.Yield();
|
||||
}
|
||||
|
||||
Dispose();
|
||||
}
|
||||
|
||||
protected override void OnReceived(byte[] buffer, long offset, long size)
|
||||
{
|
||||
_protocol.Read(buffer, (int)offset, (int)size);
|
||||
}
|
||||
|
||||
protected override void OnError(SocketError error)
|
||||
{
|
||||
Logger.Info?.PrintMsg(LogClass.ServiceLdn, $"LDN TCP client caught an error with code {error}");
|
||||
|
||||
_error.Set();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void HandleInitialize(LdnHeader header, InitializeMessage initialize)
|
||||
{
|
||||
InitializeMemory = initialize;
|
||||
}
|
||||
|
||||
private void HandleExternalProxy(LdnHeader header, ExternalProxyConfig config)
|
||||
{
|
||||
int length = config.AddressFamily switch
|
||||
{
|
||||
AddressFamily.InterNetwork => 4,
|
||||
AddressFamily.InterNetworkV6 => 16,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
return; // Invalid external proxy.
|
||||
}
|
||||
|
||||
IPAddress address = new(config.ProxyIp.AsSpan()[..length].ToArray());
|
||||
P2pProxyClient proxy = new(address.ToString(), config.ProxyPort);
|
||||
|
||||
_connectedProxy = proxy;
|
||||
|
||||
bool success = proxy.PerformAuth(config);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
DisconnectInternal();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandlePing(LdnHeader header, PingMessage ping)
|
||||
{
|
||||
if (ping.Requester == 0) // Server requested.
|
||||
{
|
||||
// Send the ping message back.
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.Ping, ping));
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleNetworkError(LdnHeader header, NetworkErrorMessage error)
|
||||
{
|
||||
if (error.Error == NetworkError.PortUnreachable)
|
||||
{
|
||||
_useP2pProxy = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastError = error.Error;
|
||||
}
|
||||
}
|
||||
|
||||
private NetworkError ConsumeNetworkError()
|
||||
{
|
||||
NetworkError result = _lastError;
|
||||
|
||||
_lastError = NetworkError.None;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void HandleSyncNetwork(LdnHeader header, NetworkInfo info)
|
||||
{
|
||||
NetworkChange?.Invoke(this, new NetworkChangeEventArgs(info, true));
|
||||
}
|
||||
|
||||
private void HandleConnected(LdnHeader header, NetworkInfo info)
|
||||
{
|
||||
_networkConnected = true;
|
||||
_disconnectReason = DisconnectReason.None;
|
||||
|
||||
_apConnected.Set();
|
||||
|
||||
NetworkChange?.Invoke(this, new NetworkChangeEventArgs(info, true));
|
||||
}
|
||||
|
||||
private void HandleDisconnected(LdnHeader header, DisconnectMessage message)
|
||||
{
|
||||
DisconnectInternal();
|
||||
}
|
||||
|
||||
private void HandleReject(LdnHeader header, RejectRequest reject)
|
||||
{
|
||||
// When the client receives a Reject request, we have been rejected and will be disconnected shortly.
|
||||
_disconnectReason = reject.DisconnectReason;
|
||||
}
|
||||
|
||||
private void HandleRejectReply(LdnHeader header)
|
||||
{
|
||||
_reject.Set();
|
||||
}
|
||||
|
||||
private void HandleScanReply(LdnHeader header, NetworkInfo info)
|
||||
{
|
||||
_availableGames.Add(info);
|
||||
}
|
||||
|
||||
private void HandleScanReplyEnd(LdnHeader obj)
|
||||
{
|
||||
_scan.Set();
|
||||
}
|
||||
|
||||
private void DisconnectInternal()
|
||||
{
|
||||
if (_networkConnected)
|
||||
{
|
||||
_networkConnected = false;
|
||||
|
||||
_hostedProxy?.Dispose();
|
||||
_hostedProxy = null;
|
||||
|
||||
_connectedProxy?.Dispose();
|
||||
_connectedProxy = null;
|
||||
|
||||
_apConnected.Reset();
|
||||
|
||||
NetworkChange?.Invoke(this, new NetworkChangeEventArgs(new NetworkInfo(), false, _disconnectReason));
|
||||
|
||||
if (IsConnected)
|
||||
{
|
||||
_timeout.RefreshTimeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DisconnectNetwork()
|
||||
{
|
||||
if (_networkConnected)
|
||||
{
|
||||
SendAsync(_protocol.Encode(PacketId.Disconnect, new DisconnectMessage()));
|
||||
|
||||
DisconnectInternal();
|
||||
}
|
||||
}
|
||||
|
||||
public ResultCode Reject(DisconnectReason disconnectReason, uint nodeId)
|
||||
{
|
||||
if (_networkConnected)
|
||||
{
|
||||
_reject.Reset();
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.Reject, new RejectRequest(disconnectReason, nodeId)));
|
||||
|
||||
int index = WaitHandle.WaitAny(new WaitHandle[] { _reject, _error }, InactiveTimeout);
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
return (ConsumeNetworkError() != NetworkError.None) ? ResultCode.InvalidState : ResultCode.Success;
|
||||
}
|
||||
}
|
||||
|
||||
return ResultCode.InvalidState;
|
||||
}
|
||||
|
||||
public void SetAdvertiseData(byte[] data)
|
||||
{
|
||||
// TODO: validate we're the owner (the server will do this anyways tho)
|
||||
if (_networkConnected)
|
||||
{
|
||||
SendAsync(_protocol.Encode(PacketId.SetAdvertiseData, data));
|
||||
}
|
||||
}
|
||||
|
||||
public void SetGameVersion(byte[] versionString)
|
||||
{
|
||||
_gameVersion = versionString;
|
||||
|
||||
if (_gameVersion.Length < 0x10)
|
||||
{
|
||||
Array.Resize(ref _gameVersion, 0x10);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetStationAcceptPolicy(AcceptPolicy acceptPolicy)
|
||||
{
|
||||
// TODO: validate we're the owner (the server will do this anyways tho)
|
||||
if (_networkConnected)
|
||||
{
|
||||
SendAsync(_protocol.Encode(PacketId.SetAcceptPolicy, new SetAcceptPolicyRequest
|
||||
{
|
||||
StationAcceptPolicy = acceptPolicy
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void DisposeProxy()
|
||||
{
|
||||
_hostedProxy?.Dispose();
|
||||
_hostedProxy = null;
|
||||
}
|
||||
|
||||
private void ConfigureAccessPoint(ref RyuNetworkConfig request)
|
||||
{
|
||||
_gameVersion.AsSpan().CopyTo(request.GameVersion.AsSpan());
|
||||
|
||||
if (_useP2pProxy)
|
||||
{
|
||||
// Before sending the request, attempt to set up a proxy server.
|
||||
// This can be on a range of private ports, which can be exposed on a range of public
|
||||
// ports via UPnP. If any of this fails, we just fall back to using the master server.
|
||||
|
||||
int i = 0;
|
||||
for (; i < P2pProxyServer.PrivatePortRange; i++)
|
||||
{
|
||||
_hostedProxy = new P2pProxyServer(this, (ushort)(P2pProxyServer.PrivatePortBase + i), _protocol);
|
||||
|
||||
try
|
||||
{
|
||||
_hostedProxy.Start();
|
||||
|
||||
break;
|
||||
}
|
||||
catch (SocketException e)
|
||||
{
|
||||
_hostedProxy.Dispose();
|
||||
_hostedProxy = null;
|
||||
|
||||
if (e.SocketErrorCode != SocketError.AddressAlreadyInUse)
|
||||
{
|
||||
i = P2pProxyServer.PrivatePortRange; // Immediately fail.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool openSuccess = i < P2pProxyServer.PrivatePortRange;
|
||||
|
||||
if (openSuccess)
|
||||
{
|
||||
Task<ushort> natPunchResult = _hostedProxy.NatPunch();
|
||||
|
||||
try
|
||||
{
|
||||
if (natPunchResult.Result != 0)
|
||||
{
|
||||
// Tell the server that we are hosting the proxy.
|
||||
request.ExternalProxyPort = natPunchResult.Result;
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
|
||||
if (request.ExternalProxyPort == 0)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ServiceLdn, "Failed to open a port with UPnP for P2P connection. Proxying through the master server instead. Expect higher latency.");
|
||||
_hostedProxy.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Info?.Print(LogClass.ServiceLdn, $"Created a wireless P2P network on port {request.ExternalProxyPort}.");
|
||||
_hostedProxy.Start();
|
||||
|
||||
(_, UnicastIPAddressInformation unicastAddress) = NetworkHelpers.GetLocalInterface();
|
||||
|
||||
unicastAddress.Address.GetAddressBytes().AsSpan().CopyTo(request.PrivateIp.AsSpan());
|
||||
request.InternalProxyPort = _hostedProxy.PrivatePort;
|
||||
request.AddressFamily = unicastAddress.Address.AddressFamily;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ServiceLdn, "Cannot create a P2P server. Proxying through the master server instead. Expect higher latency.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CreateNetworkCommon()
|
||||
{
|
||||
bool signalled = _apConnected.WaitOne(FailureTimeout);
|
||||
|
||||
if (!_useP2pProxy && _hostedProxy != null)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.ServiceLdn, "Locally hosted proxy server was not externally reachable. Proxying through the master server instead. Expect higher latency.");
|
||||
|
||||
DisposeProxy();
|
||||
}
|
||||
|
||||
if (signalled && _connectedProxy != null)
|
||||
{
|
||||
_connectedProxy.EnsureProxyReady();
|
||||
|
||||
Config = _connectedProxy.ProxyConfig;
|
||||
}
|
||||
else
|
||||
{
|
||||
DisposeProxy();
|
||||
}
|
||||
|
||||
return signalled;
|
||||
}
|
||||
|
||||
public bool CreateNetwork(CreateAccessPointRequest request, byte[] advertiseData)
|
||||
{
|
||||
_timeout.DisableTimeout();
|
||||
|
||||
ConfigureAccessPoint(ref request.RyuNetworkConfig);
|
||||
|
||||
if (!EnsureConnected())
|
||||
{
|
||||
DisposeProxy();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdatePassphraseIfNeeded();
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.CreateAccessPoint, request, advertiseData));
|
||||
|
||||
// Send a network change event with dummy data immediately. Necessary to avoid crashes in some games
|
||||
var networkChangeEvent = new NetworkChangeEventArgs(new NetworkInfo()
|
||||
{
|
||||
Common = new CommonNetworkInfo()
|
||||
{
|
||||
MacAddress = InitializeMemory.MacAddress,
|
||||
Channel = request.NetworkConfig.Channel,
|
||||
LinkLevel = 3,
|
||||
NetworkType = 2,
|
||||
Ssid = new Ssid()
|
||||
{
|
||||
Length = 32
|
||||
}
|
||||
},
|
||||
Ldn = new LdnNetworkInfo()
|
||||
{
|
||||
AdvertiseDataSize = (ushort)advertiseData.Length,
|
||||
AuthenticationId = 0,
|
||||
NodeCount = 1,
|
||||
NodeCountMax = request.NetworkConfig.NodeCountMax,
|
||||
SecurityMode = (ushort)request.SecurityConfig.SecurityMode
|
||||
}
|
||||
}, true);
|
||||
networkChangeEvent.Info.Ldn.Nodes[0] = new NodeInfo()
|
||||
{
|
||||
Ipv4Address = 175243265,
|
||||
IsConnected = 1,
|
||||
LocalCommunicationVersion = request.NetworkConfig.LocalCommunicationVersion,
|
||||
MacAddress = InitializeMemory.MacAddress,
|
||||
NodeId = 0,
|
||||
UserName = request.UserConfig.UserName
|
||||
};
|
||||
"12345678123456781234567812345678"u8.ToArray().CopyTo(networkChangeEvent.Info.Common.Ssid.Name.AsSpan());
|
||||
NetworkChange?.Invoke(this, networkChangeEvent);
|
||||
|
||||
return CreateNetworkCommon();
|
||||
}
|
||||
|
||||
public bool CreateNetworkPrivate(CreateAccessPointPrivateRequest request, byte[] advertiseData)
|
||||
{
|
||||
_timeout.DisableTimeout();
|
||||
|
||||
ConfigureAccessPoint(ref request.RyuNetworkConfig);
|
||||
|
||||
if (!EnsureConnected())
|
||||
{
|
||||
DisposeProxy();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdatePassphraseIfNeeded();
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.CreateAccessPointPrivate, request, advertiseData));
|
||||
|
||||
return CreateNetworkCommon();
|
||||
}
|
||||
|
||||
public NetworkInfo[] Scan(ushort channel, ScanFilter scanFilter)
|
||||
{
|
||||
if (!_networkConnected)
|
||||
{
|
||||
_timeout.RefreshTimeout();
|
||||
}
|
||||
|
||||
_availableGames.Clear();
|
||||
|
||||
int index = -1;
|
||||
|
||||
if (EnsureConnected())
|
||||
{
|
||||
UpdatePassphraseIfNeeded();
|
||||
|
||||
_scan.Reset();
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.Scan, scanFilter));
|
||||
|
||||
index = WaitHandle.WaitAny(new WaitHandle[] { _scan, _error }, ScanTimeout);
|
||||
}
|
||||
|
||||
if (index != 0)
|
||||
{
|
||||
// An error occurred or timeout. Write 0 games.
|
||||
return Array.Empty<NetworkInfo>();
|
||||
}
|
||||
|
||||
return _availableGames.ToArray();
|
||||
}
|
||||
|
||||
private NetworkError ConnectCommon()
|
||||
{
|
||||
bool signalled = _apConnected.WaitOne(FailureTimeout);
|
||||
|
||||
NetworkError error = ConsumeNetworkError();
|
||||
|
||||
if (error != NetworkError.None)
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
if (signalled && _connectedProxy != null)
|
||||
{
|
||||
_connectedProxy.EnsureProxyReady();
|
||||
|
||||
Config = _connectedProxy.ProxyConfig;
|
||||
}
|
||||
|
||||
return signalled ? NetworkError.None : NetworkError.ConnectTimeout;
|
||||
}
|
||||
|
||||
public NetworkError Connect(ConnectRequest request)
|
||||
{
|
||||
_timeout.DisableTimeout();
|
||||
|
||||
if (!EnsureConnected())
|
||||
{
|
||||
return NetworkError.Unknown;
|
||||
}
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.Connect, request));
|
||||
|
||||
var networkChangeEvent = new NetworkChangeEventArgs(new NetworkInfo()
|
||||
{
|
||||
Common = request.NetworkInfo.Common,
|
||||
Ldn = request.NetworkInfo.Ldn
|
||||
}, true);
|
||||
|
||||
NetworkChange?.Invoke(this, networkChangeEvent);
|
||||
|
||||
return ConnectCommon();
|
||||
}
|
||||
|
||||
public NetworkError ConnectPrivate(ConnectPrivateRequest request)
|
||||
{
|
||||
_timeout.DisableTimeout();
|
||||
|
||||
if (!EnsureConnected())
|
||||
{
|
||||
return NetworkError.Unknown;
|
||||
}
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.ConnectPrivate, request));
|
||||
|
||||
return ConnectCommon();
|
||||
}
|
||||
|
||||
private void HandleProxyConfig(LdnHeader header, ProxyConfig config)
|
||||
{
|
||||
Config = config;
|
||||
|
||||
SocketHelpers.RegisterProxy(new LdnProxy(config, this, _protocol));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
|
||||
{
|
||||
class NetworkTimeout : IDisposable
|
||||
{
|
||||
private readonly int _idleTimeout;
|
||||
private readonly Action _timeoutCallback;
|
||||
private CancellationTokenSource _cancel;
|
||||
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public NetworkTimeout(int idleTimeout, Action timeoutCallback)
|
||||
{
|
||||
_idleTimeout = idleTimeout;
|
||||
_timeoutCallback = timeoutCallback;
|
||||
}
|
||||
|
||||
private async Task TimeoutTask()
|
||||
{
|
||||
CancellationTokenSource cts;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
cts = _cancel;
|
||||
}
|
||||
|
||||
if (cts == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(_idleTimeout, cts.Token);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
return; // Timeout cancelled.
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
// Run the timeout callback. If the cancel token source has been replaced, we have _just_ been cancelled.
|
||||
if (cts == _cancel)
|
||||
{
|
||||
_timeoutCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool RefreshTimeout()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_cancel?.Cancel();
|
||||
|
||||
_cancel = new CancellationTokenSource();
|
||||
|
||||
Task.Run(TimeoutTask);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void DisableTimeout()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_cancel?.Cancel();
|
||||
|
||||
_cancel = new CancellationTokenSource();
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisableTimeout();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
|
||||
{
|
||||
public class EphemeralPortPool
|
||||
{
|
||||
private const ushort EphemeralBase = 49152;
|
||||
|
||||
private readonly List<ushort> _ephemeralPorts = new List<ushort>();
|
||||
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public ushort Get()
|
||||
{
|
||||
ushort port = EphemeralBase;
|
||||
lock (_lock)
|
||||
{
|
||||
// Starting at the ephemeral port base, return an ephemeral port that is not in use.
|
||||
// Returns 0 if the range is exhausted.
|
||||
|
||||
for (int i = 0; i < _ephemeralPorts.Count; i++)
|
||||
{
|
||||
ushort existingPort = _ephemeralPorts[i];
|
||||
|
||||
if (existingPort > port)
|
||||
{
|
||||
// The port was free - take it.
|
||||
_ephemeralPorts.Insert(i, port);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
port++;
|
||||
}
|
||||
|
||||
if (port != 0)
|
||||
{
|
||||
_ephemeralPorts.Add(port);
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
public void Return(ushort port)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_ephemeralPorts.Remove(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,254 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
|
||||
{
|
||||
class LdnProxy : IDisposable
|
||||
{
|
||||
public EndPoint LocalEndpoint { get; }
|
||||
public IPAddress LocalAddress { get; }
|
||||
|
||||
private readonly List<LdnProxySocket> _sockets = new List<LdnProxySocket>();
|
||||
private readonly Dictionary<ProtocolType, EphemeralPortPool> _ephemeralPorts = new Dictionary<ProtocolType, EphemeralPortPool>();
|
||||
|
||||
private readonly IProxyClient _parent;
|
||||
private RyuLdnProtocol _protocol;
|
||||
private readonly uint _subnetMask;
|
||||
private readonly uint _localIp;
|
||||
private readonly uint _broadcast;
|
||||
|
||||
public LdnProxy(ProxyConfig config, IProxyClient client, RyuLdnProtocol protocol)
|
||||
{
|
||||
_parent = client;
|
||||
_protocol = protocol;
|
||||
|
||||
_ephemeralPorts[ProtocolType.Udp] = new EphemeralPortPool();
|
||||
_ephemeralPorts[ProtocolType.Tcp] = new EphemeralPortPool();
|
||||
|
||||
byte[] address = BitConverter.GetBytes(config.ProxyIp);
|
||||
Array.Reverse(address);
|
||||
LocalAddress = new IPAddress(address);
|
||||
|
||||
_subnetMask = config.ProxySubnetMask;
|
||||
_localIp = config.ProxyIp;
|
||||
_broadcast = _localIp | (~_subnetMask);
|
||||
|
||||
RegisterHandlers(protocol);
|
||||
}
|
||||
|
||||
public bool Supported(AddressFamily domain, SocketType type, ProtocolType protocol)
|
||||
{
|
||||
if (protocol == ProtocolType.Tcp)
|
||||
{
|
||||
Logger.Error?.PrintMsg(LogClass.ServiceLdn, "Tcp proxy networking is untested. Please report this game so that it can be tested.");
|
||||
}
|
||||
return domain == AddressFamily.InterNetwork && (protocol == ProtocolType.Tcp || protocol == ProtocolType.Udp);
|
||||
}
|
||||
|
||||
private void RegisterHandlers(RyuLdnProtocol protocol)
|
||||
{
|
||||
protocol.ProxyConnect += HandleConnectionRequest;
|
||||
protocol.ProxyConnectReply += HandleConnectionResponse;
|
||||
protocol.ProxyData += HandleData;
|
||||
protocol.ProxyDisconnect += HandleDisconnect;
|
||||
|
||||
_protocol = protocol;
|
||||
}
|
||||
|
||||
public void UnregisterHandlers(RyuLdnProtocol protocol)
|
||||
{
|
||||
protocol.ProxyConnect -= HandleConnectionRequest;
|
||||
protocol.ProxyConnectReply -= HandleConnectionResponse;
|
||||
protocol.ProxyData -= HandleData;
|
||||
protocol.ProxyDisconnect -= HandleDisconnect;
|
||||
}
|
||||
|
||||
public ushort GetEphemeralPort(ProtocolType type)
|
||||
{
|
||||
return _ephemeralPorts[type].Get();
|
||||
}
|
||||
|
||||
public void ReturnEphemeralPort(ProtocolType type, ushort port)
|
||||
{
|
||||
_ephemeralPorts[type].Return(port);
|
||||
}
|
||||
|
||||
public void RegisterSocket(LdnProxySocket socket)
|
||||
{
|
||||
lock (_sockets)
|
||||
{
|
||||
_sockets.Add(socket);
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterSocket(LdnProxySocket socket)
|
||||
{
|
||||
lock (_sockets)
|
||||
{
|
||||
_sockets.Remove(socket);
|
||||
}
|
||||
}
|
||||
|
||||
private void ForRoutedSockets(ProxyInfo info, Action<LdnProxySocket> action)
|
||||
{
|
||||
lock (_sockets)
|
||||
{
|
||||
foreach (LdnProxySocket socket in _sockets)
|
||||
{
|
||||
// Must match protocol and destination port.
|
||||
if (socket.ProtocolType != info.Protocol || socket.LocalEndPoint is not IPEndPoint endpoint || endpoint.Port != info.DestPort)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// We can assume packets routed to us have been sent to our destination.
|
||||
// They will either be sent to us, or broadcast packets.
|
||||
|
||||
action(socket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleConnectionRequest(LdnHeader header, ProxyConnectRequest request)
|
||||
{
|
||||
ForRoutedSockets(request.Info, (socket) =>
|
||||
{
|
||||
socket.HandleConnectRequest(request);
|
||||
});
|
||||
}
|
||||
|
||||
public void HandleConnectionResponse(LdnHeader header, ProxyConnectResponse response)
|
||||
{
|
||||
ForRoutedSockets(response.Info, (socket) =>
|
||||
{
|
||||
socket.HandleConnectResponse(response);
|
||||
});
|
||||
}
|
||||
|
||||
public void HandleData(LdnHeader header, ProxyDataHeader proxyHeader, byte[] data)
|
||||
{
|
||||
ProxyDataPacket packet = new ProxyDataPacket() { Header = proxyHeader, Data = data };
|
||||
|
||||
ForRoutedSockets(proxyHeader.Info, (socket) =>
|
||||
{
|
||||
socket.IncomingData(packet);
|
||||
});
|
||||
}
|
||||
|
||||
public void HandleDisconnect(LdnHeader header, ProxyDisconnectMessage disconnect)
|
||||
{
|
||||
ForRoutedSockets(disconnect.Info, (socket) =>
|
||||
{
|
||||
socket.HandleDisconnect(disconnect);
|
||||
});
|
||||
}
|
||||
|
||||
private uint GetIpV4(IPEndPoint endpoint)
|
||||
{
|
||||
if (endpoint.AddressFamily != AddressFamily.InterNetwork)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
byte[] address = endpoint.Address.GetAddressBytes();
|
||||
Array.Reverse(address);
|
||||
|
||||
return BitConverter.ToUInt32(address);
|
||||
}
|
||||
|
||||
private ProxyInfo MakeInfo(IPEndPoint localEp, IPEndPoint remoteEP, ProtocolType type)
|
||||
{
|
||||
return new ProxyInfo
|
||||
{
|
||||
SourceIpV4 = GetIpV4(localEp),
|
||||
SourcePort = (ushort)localEp.Port,
|
||||
|
||||
DestIpV4 = GetIpV4(remoteEP),
|
||||
DestPort = (ushort)remoteEP.Port,
|
||||
|
||||
Protocol = type
|
||||
};
|
||||
}
|
||||
|
||||
public void RequestConnection(IPEndPoint localEp, IPEndPoint remoteEp, ProtocolType type)
|
||||
{
|
||||
// We must ask the other side to initialize a connection, so they can accept a socket for us.
|
||||
|
||||
ProxyConnectRequest request = new ProxyConnectRequest
|
||||
{
|
||||
Info = MakeInfo(localEp, remoteEp, type)
|
||||
};
|
||||
|
||||
_parent.SendAsync(_protocol.Encode(PacketId.ProxyConnect, request));
|
||||
}
|
||||
|
||||
public void SignalConnected(IPEndPoint localEp, IPEndPoint remoteEp, ProtocolType type)
|
||||
{
|
||||
// We must tell the other side that we have accepted their request for connection.
|
||||
|
||||
ProxyConnectResponse request = new ProxyConnectResponse
|
||||
{
|
||||
Info = MakeInfo(localEp, remoteEp, type)
|
||||
};
|
||||
|
||||
_parent.SendAsync(_protocol.Encode(PacketId.ProxyConnectReply, request));
|
||||
}
|
||||
|
||||
public void EndConnection(IPEndPoint localEp, IPEndPoint remoteEp, ProtocolType type)
|
||||
{
|
||||
// We must tell the other side that our connection is dropped.
|
||||
|
||||
ProxyDisconnectMessage request = new ProxyDisconnectMessage
|
||||
{
|
||||
Info = MakeInfo(localEp, remoteEp, type),
|
||||
DisconnectReason = 0 // TODO
|
||||
};
|
||||
|
||||
_parent.SendAsync(_protocol.Encode(PacketId.ProxyDisconnect, request));
|
||||
}
|
||||
|
||||
public int SendTo(ReadOnlySpan<byte> buffer, SocketFlags flags, IPEndPoint localEp, IPEndPoint remoteEp, ProtocolType type)
|
||||
{
|
||||
// We send exactly as much as the user wants us to, currently instantly.
|
||||
// TODO: handle over "virtual mtu" (we have a max packet size to worry about anyways). fragment if tcp? throw if udp?
|
||||
|
||||
ProxyDataHeader request = new ProxyDataHeader
|
||||
{
|
||||
Info = MakeInfo(localEp, remoteEp, type),
|
||||
DataLength = (uint)buffer.Length
|
||||
};
|
||||
|
||||
_parent.SendAsync(_protocol.Encode(PacketId.ProxyData, request, buffer.ToArray()));
|
||||
|
||||
return buffer.Length;
|
||||
}
|
||||
|
||||
public bool IsBroadcast(uint ip)
|
||||
{
|
||||
return ip == _broadcast;
|
||||
}
|
||||
|
||||
public bool IsMyself(uint ip)
|
||||
{
|
||||
return ip == _localIp;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnregisterHandlers(_protocol);
|
||||
|
||||
lock (_sockets)
|
||||
{
|
||||
foreach (LdnProxySocket socket in _sockets)
|
||||
{
|
||||
socket.ProxyDestroyed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,797 @@
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl;
|
||||
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
|
||||
{
|
||||
/// <summary>
|
||||
/// This socket is forwarded through a TCP stream that goes through the Ldn server.
|
||||
/// The Ldn server will then route the packets we send (or need to receive) within the virtual adhoc network.
|
||||
/// </summary>
|
||||
class LdnProxySocket : ISocketImpl
|
||||
{
|
||||
private readonly LdnProxy _proxy;
|
||||
|
||||
private bool _isListening;
|
||||
private readonly List<LdnProxySocket> _listenSockets = new List<LdnProxySocket>();
|
||||
|
||||
private readonly Queue<ProxyConnectRequest> _connectRequests = new Queue<ProxyConnectRequest>();
|
||||
|
||||
private readonly AutoResetEvent _acceptEvent = new AutoResetEvent(false);
|
||||
private readonly int _acceptTimeout = -1;
|
||||
|
||||
private readonly Queue<int> _errors = new Queue<int>();
|
||||
|
||||
private readonly AutoResetEvent _connectEvent = new AutoResetEvent(false);
|
||||
private ProxyConnectResponse _connectResponse;
|
||||
|
||||
private int _receiveTimeout = -1;
|
||||
private readonly AutoResetEvent _receiveEvent = new AutoResetEvent(false);
|
||||
private readonly Queue<ProxyDataPacket> _receiveQueue = new Queue<ProxyDataPacket>();
|
||||
|
||||
// private int _sendTimeout = -1; // Sends are techically instant right now, so not _really_ used.
|
||||
|
||||
private bool _connecting;
|
||||
private bool _broadcast;
|
||||
private bool _readShutdown;
|
||||
// private bool _writeShutdown;
|
||||
private bool _closed;
|
||||
|
||||
private readonly Dictionary<SocketOptionName, int> _socketOptions = new Dictionary<SocketOptionName, int>()
|
||||
{
|
||||
{ SocketOptionName.Broadcast, 0 }, //TODO: honor this value
|
||||
{ SocketOptionName.DontLinger, 0 },
|
||||
{ SocketOptionName.Debug, 0 },
|
||||
{ SocketOptionName.Error, 0 },
|
||||
{ SocketOptionName.KeepAlive, 0 },
|
||||
{ SocketOptionName.OutOfBandInline, 0 },
|
||||
{ SocketOptionName.ReceiveBuffer, 131072 },
|
||||
{ SocketOptionName.ReceiveTimeout, -1 },
|
||||
{ SocketOptionName.SendBuffer, 131072 },
|
||||
{ SocketOptionName.SendTimeout, -1 },
|
||||
{ SocketOptionName.Type, 0 },
|
||||
{ SocketOptionName.ReuseAddress, 0 } //TODO: honor this value
|
||||
};
|
||||
|
||||
public EndPoint RemoteEndPoint { get; private set; }
|
||||
|
||||
public EndPoint LocalEndPoint { get; private set; }
|
||||
|
||||
public bool Connected { get; private set; }
|
||||
|
||||
public bool IsBound { get; private set; }
|
||||
|
||||
public AddressFamily AddressFamily { get; }
|
||||
|
||||
public SocketType SocketType { get; }
|
||||
|
||||
public ProtocolType ProtocolType { get; }
|
||||
|
||||
public bool Blocking { get; set; }
|
||||
|
||||
public int Available
|
||||
{
|
||||
get
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
lock (_receiveQueue)
|
||||
{
|
||||
foreach (ProxyDataPacket data in _receiveQueue)
|
||||
{
|
||||
result += data.Data.Length;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Readable
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_isListening)
|
||||
{
|
||||
lock (_connectRequests)
|
||||
{
|
||||
return _connectRequests.Count > 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_readShutdown)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
lock (_receiveQueue)
|
||||
{
|
||||
return _receiveQueue.Count > 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public bool Writable => Connected || ProtocolType == ProtocolType.Udp;
|
||||
public bool Error => false;
|
||||
|
||||
public LdnProxySocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, LdnProxy proxy)
|
||||
{
|
||||
AddressFamily = addressFamily;
|
||||
SocketType = socketType;
|
||||
ProtocolType = protocolType;
|
||||
|
||||
_proxy = proxy;
|
||||
_socketOptions[SocketOptionName.Type] = (int)socketType;
|
||||
|
||||
proxy.RegisterSocket(this);
|
||||
}
|
||||
|
||||
private IPEndPoint EnsureLocalEndpoint(bool replace)
|
||||
{
|
||||
if (LocalEndPoint != null)
|
||||
{
|
||||
if (replace)
|
||||
{
|
||||
_proxy.ReturnEphemeralPort(ProtocolType, (ushort)((IPEndPoint)LocalEndPoint).Port);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (IPEndPoint)LocalEndPoint;
|
||||
}
|
||||
}
|
||||
|
||||
IPEndPoint localEp = new IPEndPoint(_proxy.LocalAddress, _proxy.GetEphemeralPort(ProtocolType));
|
||||
LocalEndPoint = localEp;
|
||||
|
||||
return localEp;
|
||||
}
|
||||
|
||||
public LdnProxySocket AsAccepted(IPEndPoint remoteEp)
|
||||
{
|
||||
Connected = true;
|
||||
RemoteEndPoint = remoteEp;
|
||||
|
||||
IPEndPoint localEp = EnsureLocalEndpoint(true);
|
||||
|
||||
_proxy.SignalConnected(localEp, remoteEp, ProtocolType);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void SignalError(WsaError error)
|
||||
{
|
||||
lock (_errors)
|
||||
{
|
||||
_errors.Enqueue((int)error);
|
||||
}
|
||||
}
|
||||
|
||||
private IPEndPoint GetEndpoint(uint ipv4, ushort port)
|
||||
{
|
||||
byte[] address = BitConverter.GetBytes(ipv4);
|
||||
Array.Reverse(address);
|
||||
|
||||
return new IPEndPoint(new IPAddress(address), port);
|
||||
}
|
||||
|
||||
public void IncomingData(ProxyDataPacket packet)
|
||||
{
|
||||
bool isBroadcast = _proxy.IsBroadcast(packet.Header.Info.DestIpV4);
|
||||
|
||||
if (!_closed && (_broadcast || !isBroadcast))
|
||||
{
|
||||
lock (_receiveQueue)
|
||||
{
|
||||
_receiveQueue.Enqueue(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ISocketImpl Accept()
|
||||
{
|
||||
if (!_isListening)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
// Accept a pending request to this socket.
|
||||
|
||||
lock (_connectRequests)
|
||||
{
|
||||
if (!Blocking && _connectRequests.Count == 0)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAEWOULDBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
_acceptEvent.WaitOne(_acceptTimeout);
|
||||
|
||||
lock (_connectRequests)
|
||||
{
|
||||
while (_connectRequests.Count > 0)
|
||||
{
|
||||
ProxyConnectRequest request = _connectRequests.Dequeue();
|
||||
|
||||
if (_connectRequests.Count > 0)
|
||||
{
|
||||
_acceptEvent.Set(); // Still more accepts to do.
|
||||
}
|
||||
|
||||
// Is this request made for us?
|
||||
IPEndPoint endpoint = GetEndpoint(request.Info.DestIpV4, request.Info.DestPort);
|
||||
|
||||
if (Equals(endpoint, LocalEndPoint))
|
||||
{
|
||||
// Yes - let's accept.
|
||||
IPEndPoint remoteEndpoint = GetEndpoint(request.Info.SourceIpV4, request.Info.SourcePort);
|
||||
|
||||
LdnProxySocket socket = new LdnProxySocket(AddressFamily, SocketType, ProtocolType, _proxy).AsAccepted(remoteEndpoint);
|
||||
|
||||
lock (_listenSockets)
|
||||
{
|
||||
_listenSockets.Add(socket);
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(EndPoint localEP)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(localEP);
|
||||
|
||||
if (LocalEndPoint != null)
|
||||
{
|
||||
_proxy.ReturnEphemeralPort(ProtocolType, (ushort)((IPEndPoint)LocalEndPoint).Port);
|
||||
}
|
||||
var asIPEndpoint = (IPEndPoint)localEP;
|
||||
if (asIPEndpoint.Port == 0)
|
||||
{
|
||||
asIPEndpoint.Port = (ushort)_proxy.GetEphemeralPort(ProtocolType);
|
||||
}
|
||||
|
||||
LocalEndPoint = (IPEndPoint)localEP;
|
||||
|
||||
IsBound = true;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_closed = true;
|
||||
|
||||
_proxy.UnregisterSocket(this);
|
||||
|
||||
if (Connected)
|
||||
{
|
||||
Disconnect(false);
|
||||
}
|
||||
|
||||
lock (_listenSockets)
|
||||
{
|
||||
foreach (LdnProxySocket socket in _listenSockets)
|
||||
{
|
||||
socket.Close();
|
||||
}
|
||||
}
|
||||
|
||||
_isListening = false;
|
||||
}
|
||||
|
||||
public void Connect(EndPoint remoteEP)
|
||||
{
|
||||
if (_isListening || !IsBound)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
if (remoteEP is not IPEndPoint)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
IPEndPoint localEp = EnsureLocalEndpoint(true);
|
||||
|
||||
_connecting = true;
|
||||
|
||||
_proxy.RequestConnection(localEp, (IPEndPoint)remoteEP, ProtocolType);
|
||||
|
||||
if (!Blocking && ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAEWOULDBLOCK);
|
||||
}
|
||||
|
||||
_connectEvent.WaitOne(); //timeout?
|
||||
|
||||
if (_connectResponse.Info.SourceIpV4 == 0)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAECONNREFUSED);
|
||||
}
|
||||
|
||||
_connectResponse = default;
|
||||
}
|
||||
|
||||
public void HandleConnectResponse(ProxyConnectResponse obj)
|
||||
{
|
||||
if (!_connecting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_connecting = false;
|
||||
|
||||
if (_connectResponse.Info.SourceIpV4 != 0)
|
||||
{
|
||||
IPEndPoint remoteEp = GetEndpoint(obj.Info.SourceIpV4, obj.Info.SourcePort);
|
||||
RemoteEndPoint = remoteEp;
|
||||
|
||||
Connected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Connection failed
|
||||
|
||||
SignalError(WsaError.WSAECONNREFUSED);
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect(bool reuseSocket)
|
||||
{
|
||||
if (Connected)
|
||||
{
|
||||
ConnectionEnded();
|
||||
|
||||
// The other side needs to be notified that connection ended.
|
||||
_proxy.EndConnection(LocalEndPoint as IPEndPoint, RemoteEndPoint as IPEndPoint, ProtocolType);
|
||||
}
|
||||
}
|
||||
|
||||
private void ConnectionEnded()
|
||||
{
|
||||
if (Connected)
|
||||
{
|
||||
RemoteEndPoint = null;
|
||||
Connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue)
|
||||
{
|
||||
if (optionLevel != SocketOptionLevel.Socket)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (_socketOptions.TryGetValue(optionName, out int result))
|
||||
{
|
||||
byte[] data = BitConverter.GetBytes(result);
|
||||
Array.Copy(data, 0, optionValue, 0, Math.Min(data.Length, optionValue.Length));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public void Listen(int backlog)
|
||||
{
|
||||
if (!IsBound)
|
||||
{
|
||||
throw new SocketException();
|
||||
}
|
||||
|
||||
_isListening = true;
|
||||
}
|
||||
|
||||
public void HandleConnectRequest(ProxyConnectRequest obj)
|
||||
{
|
||||
lock (_connectRequests)
|
||||
{
|
||||
_connectRequests.Enqueue(obj);
|
||||
}
|
||||
|
||||
_connectEvent.Set();
|
||||
}
|
||||
|
||||
public void HandleDisconnect(ProxyDisconnectMessage message)
|
||||
{
|
||||
Disconnect(false);
|
||||
}
|
||||
|
||||
public int Receive(Span<byte> buffer)
|
||||
{
|
||||
EndPoint dummy = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
return ReceiveFrom(buffer, SocketFlags.None, ref dummy);
|
||||
}
|
||||
|
||||
public int Receive(Span<byte> buffer, SocketFlags flags)
|
||||
{
|
||||
EndPoint dummy = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
return ReceiveFrom(buffer, flags, ref dummy);
|
||||
}
|
||||
|
||||
public int Receive(Span<byte> buffer, SocketFlags flags, out SocketError socketError)
|
||||
{
|
||||
EndPoint dummy = new IPEndPoint(IPAddress.Any, 0);
|
||||
|
||||
return ReceiveFrom(buffer, flags, out socketError, ref dummy);
|
||||
}
|
||||
|
||||
public int ReceiveFrom(Span<byte> buffer, SocketFlags flags, ref EndPoint remoteEp)
|
||||
{
|
||||
// We just receive all packets meant for us anyways regardless of EP in the actual implementation.
|
||||
// The point is mostly to return the endpoint that we got the data from.
|
||||
|
||||
if (!Connected && ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAECONNRESET);
|
||||
}
|
||||
|
||||
lock (_receiveQueue)
|
||||
{
|
||||
if (_receiveQueue.Count > 0)
|
||||
{
|
||||
return ReceiveFromQueue(buffer, flags, ref remoteEp);
|
||||
}
|
||||
else if (_readShutdown)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (!Blocking)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAEWOULDBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
int timeout = _receiveTimeout;
|
||||
|
||||
_receiveEvent.WaitOne(timeout == 0 ? -1 : timeout);
|
||||
|
||||
if (!Connected && ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAECONNRESET);
|
||||
}
|
||||
|
||||
lock (_receiveQueue)
|
||||
{
|
||||
if (_receiveQueue.Count > 0)
|
||||
{
|
||||
return ReceiveFromQueue(buffer, flags, ref remoteEp);
|
||||
}
|
||||
else if (_readShutdown)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAETIMEDOUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ReceiveFrom(Span<byte> buffer, SocketFlags flags, out SocketError socketError, ref EndPoint remoteEp)
|
||||
{
|
||||
// We just receive all packets meant for us anyways regardless of EP in the actual implementation.
|
||||
// The point is mostly to return the endpoint that we got the data from.
|
||||
|
||||
if (!Connected && ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
socketError = SocketError.ConnectionReset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
lock (_receiveQueue)
|
||||
{
|
||||
if (_receiveQueue.Count > 0)
|
||||
{
|
||||
return ReceiveFromQueue(buffer, flags, out socketError, ref remoteEp);
|
||||
}
|
||||
else if (_readShutdown)
|
||||
{
|
||||
socketError = SocketError.Success;
|
||||
return 0;
|
||||
}
|
||||
else if (!Blocking)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAEWOULDBLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
int timeout = _receiveTimeout;
|
||||
|
||||
_receiveEvent.WaitOne(timeout == 0 ? -1 : timeout);
|
||||
|
||||
if (!Connected && ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAECONNRESET);
|
||||
}
|
||||
|
||||
lock (_receiveQueue)
|
||||
{
|
||||
if (_receiveQueue.Count > 0)
|
||||
{
|
||||
return ReceiveFromQueue(buffer, flags, out socketError, ref remoteEp);
|
||||
}
|
||||
else if (_readShutdown)
|
||||
{
|
||||
socketError = SocketError.Success;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
socketError = SocketError.TimedOut;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int ReceiveFromQueue(Span<byte> buffer, SocketFlags flags, ref EndPoint remoteEp)
|
||||
{
|
||||
int size = buffer.Length;
|
||||
|
||||
// Assumes we have the receive queue lock, and at least one item in the queue.
|
||||
ProxyDataPacket packet = _receiveQueue.Peek();
|
||||
|
||||
remoteEp = GetEndpoint(packet.Header.Info.SourceIpV4, packet.Header.Info.SourcePort);
|
||||
|
||||
bool peek = (flags & SocketFlags.Peek) != 0;
|
||||
|
||||
int read;
|
||||
|
||||
if (packet.Data.Length > size)
|
||||
{
|
||||
read = size;
|
||||
|
||||
// Cannot fit in the output buffer. Copy up to what we've got.
|
||||
packet.Data.AsSpan(0, size).CopyTo(buffer);
|
||||
|
||||
if (ProtocolType == ProtocolType.Udp)
|
||||
{
|
||||
// Udp overflows, loses the data, then throws an exception.
|
||||
|
||||
if (!peek)
|
||||
{
|
||||
_receiveQueue.Dequeue();
|
||||
}
|
||||
|
||||
throw new SocketException((int)WsaError.WSAEMSGSIZE);
|
||||
}
|
||||
else if (ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
// Split the data at the buffer boundary. It will stay on the recieve queue.
|
||||
|
||||
byte[] newData = new byte[packet.Data.Length - size];
|
||||
Array.Copy(packet.Data, size, newData, 0, newData.Length);
|
||||
|
||||
packet.Data = newData;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
read = packet.Data.Length;
|
||||
|
||||
packet.Data.AsSpan(0, packet.Data.Length).CopyTo(buffer);
|
||||
|
||||
if (!peek)
|
||||
{
|
||||
_receiveQueue.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
private int ReceiveFromQueue(Span<byte> buffer, SocketFlags flags, out SocketError socketError, ref EndPoint remoteEp)
|
||||
{
|
||||
int size = buffer.Length;
|
||||
|
||||
// Assumes we have the receive queue lock, and at least one item in the queue.
|
||||
ProxyDataPacket packet = _receiveQueue.Peek();
|
||||
|
||||
remoteEp = GetEndpoint(packet.Header.Info.SourceIpV4, packet.Header.Info.SourcePort);
|
||||
|
||||
bool peek = (flags & SocketFlags.Peek) != 0;
|
||||
|
||||
int read;
|
||||
|
||||
if (packet.Data.Length > size)
|
||||
{
|
||||
read = size;
|
||||
|
||||
// Cannot fit in the output buffer. Copy up to what we've got.
|
||||
packet.Data.AsSpan(0, size).CopyTo(buffer);
|
||||
|
||||
if (ProtocolType == ProtocolType.Udp)
|
||||
{
|
||||
// Udp overflows, loses the data, then throws an exception.
|
||||
|
||||
if (!peek)
|
||||
{
|
||||
_receiveQueue.Dequeue();
|
||||
}
|
||||
|
||||
socketError = SocketError.MessageSize;
|
||||
return -1;
|
||||
}
|
||||
else if (ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
// Split the data at the buffer boundary. It will stay on the recieve queue.
|
||||
|
||||
byte[] newData = new byte[packet.Data.Length - size];
|
||||
Array.Copy(packet.Data, size, newData, 0, newData.Length);
|
||||
|
||||
packet.Data = newData;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
read = packet.Data.Length;
|
||||
|
||||
packet.Data.AsSpan(0, packet.Data.Length).CopyTo(buffer);
|
||||
|
||||
if (!peek)
|
||||
{
|
||||
_receiveQueue.Dequeue();
|
||||
}
|
||||
}
|
||||
|
||||
socketError = SocketError.Success;
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
public int Send(ReadOnlySpan<byte> buffer)
|
||||
{
|
||||
// Send to the remote host chosen when we "connect" or "accept".
|
||||
if (!Connected)
|
||||
{
|
||||
throw new SocketException();
|
||||
}
|
||||
|
||||
return SendTo(buffer, SocketFlags.None, RemoteEndPoint);
|
||||
}
|
||||
|
||||
public int Send(ReadOnlySpan<byte> buffer, SocketFlags flags)
|
||||
{
|
||||
// Send to the remote host chosen when we "connect" or "accept".
|
||||
if (!Connected)
|
||||
{
|
||||
throw new SocketException();
|
||||
}
|
||||
|
||||
return SendTo(buffer, flags, RemoteEndPoint);
|
||||
}
|
||||
|
||||
public int Send(ReadOnlySpan<byte> buffer, SocketFlags flags, out SocketError socketError)
|
||||
{
|
||||
// Send to the remote host chosen when we "connect" or "accept".
|
||||
if (!Connected)
|
||||
{
|
||||
throw new SocketException();
|
||||
}
|
||||
|
||||
return SendTo(buffer, flags, out socketError, RemoteEndPoint);
|
||||
}
|
||||
|
||||
public int SendTo(ReadOnlySpan<byte> buffer, SocketFlags flags, EndPoint remoteEP)
|
||||
{
|
||||
if (!Connected && ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
throw new SocketException((int)WsaError.WSAECONNRESET);
|
||||
}
|
||||
|
||||
IPEndPoint localEp = EnsureLocalEndpoint(false);
|
||||
|
||||
if (remoteEP is not IPEndPoint)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
return _proxy.SendTo(buffer, flags, localEp, (IPEndPoint)remoteEP, ProtocolType);
|
||||
}
|
||||
|
||||
public int SendTo(ReadOnlySpan<byte> buffer, SocketFlags flags, out SocketError socketError, EndPoint remoteEP)
|
||||
{
|
||||
if (!Connected && ProtocolType == ProtocolType.Tcp)
|
||||
{
|
||||
socketError = SocketError.ConnectionReset;
|
||||
return -1;
|
||||
}
|
||||
|
||||
IPEndPoint localEp = EnsureLocalEndpoint(false);
|
||||
|
||||
if (remoteEP is not IPEndPoint)
|
||||
{
|
||||
// throw new NotSupportedException();
|
||||
socketError = SocketError.OperationNotSupported;
|
||||
return -1;
|
||||
}
|
||||
|
||||
socketError = SocketError.Success;
|
||||
|
||||
return _proxy.SendTo(buffer, flags, localEp, (IPEndPoint)remoteEP, ProtocolType);
|
||||
}
|
||||
|
||||
public bool Poll(int microSeconds, SelectMode mode)
|
||||
{
|
||||
return mode switch
|
||||
{
|
||||
SelectMode.SelectRead => Readable,
|
||||
SelectMode.SelectWrite => Writable,
|
||||
SelectMode.SelectError => Error,
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue)
|
||||
{
|
||||
if (optionLevel != SocketOptionLevel.Socket)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
switch (optionName)
|
||||
{
|
||||
case SocketOptionName.SendTimeout:
|
||||
//_sendTimeout = optionValue;
|
||||
break;
|
||||
case SocketOptionName.ReceiveTimeout:
|
||||
_receiveTimeout = optionValue;
|
||||
break;
|
||||
case SocketOptionName.Broadcast:
|
||||
_broadcast = optionValue != 0;
|
||||
break;
|
||||
}
|
||||
|
||||
lock (_socketOptions)
|
||||
{
|
||||
_socketOptions[optionName] = optionValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, object optionValue)
|
||||
{
|
||||
// Just linger uses this for now in BSD, which we ignore.
|
||||
}
|
||||
|
||||
public void Shutdown(SocketShutdown how)
|
||||
{
|
||||
switch (how)
|
||||
{
|
||||
case SocketShutdown.Both:
|
||||
_readShutdown = true;
|
||||
// _writeShutdown = true;
|
||||
break;
|
||||
case SocketShutdown.Receive:
|
||||
_readShutdown = true;
|
||||
break;
|
||||
case SocketShutdown.Send:
|
||||
// _writeShutdown = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ProxyDestroyed()
|
||||
{
|
||||
// Do nothing, for now. Will likely be more useful with TCP.
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using TcpClient = NetCoreServer.TcpClient;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
|
||||
{
|
||||
class P2pProxyClient : TcpClient, IProxyClient
|
||||
{
|
||||
private const int FailureTimeout = 4000;
|
||||
|
||||
public ProxyConfig ProxyConfig { get; private set; }
|
||||
|
||||
private readonly RyuLdnProtocol _protocol;
|
||||
|
||||
private readonly ManualResetEvent _connected = new ManualResetEvent(false);
|
||||
private readonly ManualResetEvent _ready = new ManualResetEvent(false);
|
||||
private readonly AutoResetEvent _error = new AutoResetEvent(false);
|
||||
|
||||
public P2pProxyClient(string address, int port) : base(address, port)
|
||||
{
|
||||
if (ProxyHelpers.SupportsNoDelay())
|
||||
{
|
||||
OptionNoDelay = true;
|
||||
}
|
||||
|
||||
_protocol = new RyuLdnProtocol();
|
||||
|
||||
_protocol.ProxyConfig += HandleProxyConfig;
|
||||
|
||||
ConnectAsync();
|
||||
}
|
||||
|
||||
protected override void OnConnected()
|
||||
{
|
||||
Logger.Info?.PrintMsg(LogClass.ServiceLdn, $"Proxy TCP client connected a new session with Id {Id}");
|
||||
|
||||
_connected.Set();
|
||||
}
|
||||
|
||||
protected override void OnDisconnected()
|
||||
{
|
||||
Logger.Info?.PrintMsg(LogClass.ServiceLdn, $"Proxy TCP client disconnected a session with Id {Id}");
|
||||
|
||||
SocketHelpers.UnregisterProxy();
|
||||
|
||||
_connected.Reset();
|
||||
}
|
||||
|
||||
protected override void OnReceived(byte[] buffer, long offset, long size)
|
||||
{
|
||||
_protocol.Read(buffer, (int)offset, (int)size);
|
||||
}
|
||||
|
||||
protected override void OnError(SocketError error)
|
||||
{
|
||||
Logger.Info?.PrintMsg(LogClass.ServiceLdn, $"Proxy TCP client caught an error with code {error}");
|
||||
|
||||
_error.Set();
|
||||
}
|
||||
|
||||
private void HandleProxyConfig(LdnHeader header, ProxyConfig config)
|
||||
{
|
||||
ProxyConfig = config;
|
||||
|
||||
SocketHelpers.RegisterProxy(new LdnProxy(config, this, _protocol));
|
||||
|
||||
_ready.Set();
|
||||
}
|
||||
|
||||
public bool EnsureProxyReady()
|
||||
{
|
||||
return _ready.WaitOne(FailureTimeout);
|
||||
}
|
||||
|
||||
public bool PerformAuth(ExternalProxyConfig config)
|
||||
{
|
||||
bool signalled = _connected.WaitOne(FailureTimeout);
|
||||
|
||||
if (!signalled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
SendAsync(_protocol.Encode(PacketId.ExternalProxy, config));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,388 @@
|
||||
using NetCoreServer;
|
||||
using Open.Nat;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
|
||||
{
|
||||
class P2pProxyServer : TcpServer, IDisposable
|
||||
{
|
||||
public const ushort PrivatePortBase = 39990;
|
||||
public const int PrivatePortRange = 10;
|
||||
|
||||
private const ushort PublicPortBase = 39990;
|
||||
private const int PublicPortRange = 10;
|
||||
|
||||
private const ushort PortLeaseLength = 60;
|
||||
private const ushort PortLeaseRenew = 50;
|
||||
|
||||
private const ushort AuthWaitSeconds = 1;
|
||||
|
||||
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
|
||||
|
||||
public ushort PrivatePort { get; }
|
||||
|
||||
private ushort _publicPort;
|
||||
|
||||
private bool _disposed;
|
||||
private readonly CancellationTokenSource _disposedCancellation = new CancellationTokenSource();
|
||||
|
||||
private NatDevice _natDevice;
|
||||
private Mapping _portMapping;
|
||||
|
||||
private readonly List<P2pProxySession> _players = new List<P2pProxySession>();
|
||||
|
||||
private readonly List<ExternalProxyToken> _waitingTokens = new List<ExternalProxyToken>();
|
||||
private readonly AutoResetEvent _tokenEvent = new AutoResetEvent(false);
|
||||
|
||||
private uint _broadcastAddress;
|
||||
|
||||
private readonly LdnMasterProxyClient _master;
|
||||
private readonly RyuLdnProtocol _masterProtocol;
|
||||
private readonly RyuLdnProtocol _protocol;
|
||||
|
||||
public P2pProxyServer(LdnMasterProxyClient master, ushort port, RyuLdnProtocol masterProtocol) : base(IPAddress.Any, port)
|
||||
{
|
||||
if (ProxyHelpers.SupportsNoDelay())
|
||||
{
|
||||
OptionNoDelay = true;
|
||||
}
|
||||
|
||||
PrivatePort = port;
|
||||
|
||||
_master = master;
|
||||
_masterProtocol = masterProtocol;
|
||||
|
||||
_masterProtocol.ExternalProxyState += HandleStateChange;
|
||||
_masterProtocol.ExternalProxyToken += HandleToken;
|
||||
|
||||
_protocol = new RyuLdnProtocol();
|
||||
}
|
||||
|
||||
private void HandleToken(LdnHeader header, ExternalProxyToken token)
|
||||
{
|
||||
_lock.EnterWriteLock();
|
||||
|
||||
_waitingTokens.Add(token);
|
||||
|
||||
_lock.ExitWriteLock();
|
||||
|
||||
_tokenEvent.Set();
|
||||
}
|
||||
|
||||
private void HandleStateChange(LdnHeader header, ExternalProxyConnectionState state)
|
||||
{
|
||||
if (!state.Connected)
|
||||
{
|
||||
_lock.EnterWriteLock();
|
||||
|
||||
_waitingTokens.RemoveAll(token => token.VirtualIp == state.IpAddress);
|
||||
|
||||
_players.RemoveAll(player =>
|
||||
{
|
||||
if (player.VirtualIpAddress == state.IpAddress)
|
||||
{
|
||||
player.DisconnectAndStop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
_lock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
|
||||
public void Configure(ProxyConfig config)
|
||||
{
|
||||
_broadcastAddress = config.ProxyIp | (~config.ProxySubnetMask);
|
||||
}
|
||||
|
||||
public async Task<ushort> NatPunch()
|
||||
{
|
||||
NatDiscoverer discoverer = new NatDiscoverer();
|
||||
CancellationTokenSource cts = new CancellationTokenSource(1000);
|
||||
|
||||
NatDevice device;
|
||||
|
||||
try
|
||||
{
|
||||
device = await discoverer.DiscoverDeviceAsync(PortMapper.Upnp, cts);
|
||||
}
|
||||
catch (NatDeviceNotFoundException)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
_publicPort = PublicPortBase;
|
||||
|
||||
for (int i = 0; i < PublicPortRange; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
_portMapping = new Mapping(Protocol.Tcp, PrivatePort, _publicPort, PortLeaseLength, "Ryujinx Local Multiplayer");
|
||||
|
||||
await device.CreatePortMapAsync(_portMapping);
|
||||
|
||||
break;
|
||||
}
|
||||
catch (MappingException)
|
||||
{
|
||||
_publicPort++;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (i == PublicPortRange - 1)
|
||||
{
|
||||
_publicPort = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (_publicPort != 0)
|
||||
{
|
||||
_ = Task.Delay(PortLeaseRenew * 1000, _disposedCancellation.Token).ContinueWith((task) => Task.Run(RefreshLease));
|
||||
}
|
||||
|
||||
_natDevice = device;
|
||||
|
||||
return _publicPort;
|
||||
}
|
||||
|
||||
// Proxy handlers
|
||||
|
||||
private void RouteMessage(P2pProxySession sender, ref ProxyInfo info, Action<P2pProxySession> action)
|
||||
{
|
||||
if (info.SourceIpV4 == 0)
|
||||
{
|
||||
// If they sent from a connection bound on 0.0.0.0, make others see it as them.
|
||||
info.SourceIpV4 = sender.VirtualIpAddress;
|
||||
}
|
||||
else if (info.SourceIpV4 != sender.VirtualIpAddress)
|
||||
{
|
||||
// Can't pretend to be somebody else.
|
||||
return;
|
||||
}
|
||||
|
||||
uint destIp = info.DestIpV4;
|
||||
|
||||
if (destIp == 0xc0a800ff)
|
||||
{
|
||||
destIp = _broadcastAddress;
|
||||
}
|
||||
|
||||
bool isBroadcast = destIp == _broadcastAddress;
|
||||
|
||||
_lock.EnterReadLock();
|
||||
|
||||
if (isBroadcast)
|
||||
{
|
||||
_players.ForEach(player =>
|
||||
{
|
||||
action(player);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
P2pProxySession target = _players.FirstOrDefault(player => player.VirtualIpAddress == destIp);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
action(target);
|
||||
}
|
||||
}
|
||||
|
||||
_lock.ExitReadLock();
|
||||
}
|
||||
|
||||
public void HandleProxyDisconnect(P2pProxySession sender, LdnHeader header, ProxyDisconnectMessage message)
|
||||
{
|
||||
RouteMessage(sender, ref message.Info, (target) =>
|
||||
{
|
||||
target.SendAsync(sender.Protocol.Encode(PacketId.ProxyDisconnect, message));
|
||||
});
|
||||
}
|
||||
|
||||
public void HandleProxyData(P2pProxySession sender, LdnHeader header, ProxyDataHeader message, byte[] data)
|
||||
{
|
||||
RouteMessage(sender, ref message.Info, (target) =>
|
||||
{
|
||||
target.SendAsync(sender.Protocol.Encode(PacketId.ProxyData, message, data));
|
||||
});
|
||||
}
|
||||
|
||||
public void HandleProxyConnectReply(P2pProxySession sender, LdnHeader header, ProxyConnectResponse message)
|
||||
{
|
||||
RouteMessage(sender, ref message.Info, (target) =>
|
||||
{
|
||||
target.SendAsync(sender.Protocol.Encode(PacketId.ProxyConnectReply, message));
|
||||
});
|
||||
}
|
||||
|
||||
public void HandleProxyConnect(P2pProxySession sender, LdnHeader header, ProxyConnectRequest message)
|
||||
{
|
||||
RouteMessage(sender, ref message.Info, (target) =>
|
||||
{
|
||||
target.SendAsync(sender.Protocol.Encode(PacketId.ProxyConnect, message));
|
||||
});
|
||||
}
|
||||
|
||||
// End proxy handlers
|
||||
|
||||
private async Task RefreshLease()
|
||||
{
|
||||
if (_disposed || _natDevice == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _natDevice.CreatePortMapAsync(_portMapping);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
_ = Task.Delay(PortLeaseRenew, _disposedCancellation.Token).ContinueWith((task) => Task.Run(RefreshLease));
|
||||
}
|
||||
|
||||
public bool TryRegisterUser(P2pProxySession session, ExternalProxyConfig config)
|
||||
{
|
||||
_lock.EnterWriteLock();
|
||||
|
||||
// Attempt to find matching configuration. If we don't find one, wait for a bit and try again.
|
||||
// Woken by new tokens coming in from the master server.
|
||||
|
||||
IPAddress address = (session.Socket.RemoteEndPoint as IPEndPoint).Address;
|
||||
byte[] addressBytes = ProxyHelpers.AddressTo16Byte(address);
|
||||
|
||||
long time;
|
||||
long endTime = Stopwatch.GetTimestamp() + Stopwatch.Frequency * AuthWaitSeconds;
|
||||
|
||||
do
|
||||
{
|
||||
for (int i = 0; i < _waitingTokens.Count; i++)
|
||||
{
|
||||
ExternalProxyToken waitToken = _waitingTokens[i];
|
||||
|
||||
// Allow any client that has a private IP to connect. (indicated by the server as all 0 in the token)
|
||||
|
||||
bool isPrivate = waitToken.PhysicalIp.AsSpan().SequenceEqual(new byte[16]);
|
||||
bool ipEqual = isPrivate || waitToken.AddressFamily == address.AddressFamily && waitToken.PhysicalIp.AsSpan().SequenceEqual(addressBytes);
|
||||
|
||||
if (ipEqual && waitToken.Token.AsSpan().SequenceEqual(config.Token.AsSpan()))
|
||||
{
|
||||
// This is a match.
|
||||
|
||||
_waitingTokens.RemoveAt(i);
|
||||
|
||||
session.SetIpv4(waitToken.VirtualIp);
|
||||
|
||||
ProxyConfig pconfig = new ProxyConfig
|
||||
{
|
||||
ProxyIp = session.VirtualIpAddress,
|
||||
ProxySubnetMask = 0xFFFF0000 // TODO: Use from server.
|
||||
};
|
||||
|
||||
if (_players.Count == 0)
|
||||
{
|
||||
Configure(pconfig);
|
||||
}
|
||||
|
||||
_players.Add(session);
|
||||
|
||||
session.SendAsync(_protocol.Encode(PacketId.ProxyConfig, pconfig));
|
||||
|
||||
_lock.ExitWriteLock();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Couldn't find the token.
|
||||
// It may not have arrived yet, so wait for one to arrive.
|
||||
|
||||
_lock.ExitWriteLock();
|
||||
|
||||
time = Stopwatch.GetTimestamp();
|
||||
int remainingMs = (int)((endTime - time) / (Stopwatch.Frequency / 1000));
|
||||
|
||||
if (remainingMs < 0)
|
||||
{
|
||||
remainingMs = 0;
|
||||
}
|
||||
|
||||
_tokenEvent.WaitOne(remainingMs);
|
||||
|
||||
_lock.EnterWriteLock();
|
||||
|
||||
} while (time < endTime);
|
||||
|
||||
_lock.ExitWriteLock();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void DisconnectProxyClient(P2pProxySession session)
|
||||
{
|
||||
_lock.EnterWriteLock();
|
||||
|
||||
bool removed = _players.Remove(session);
|
||||
|
||||
if (removed)
|
||||
{
|
||||
_master.SendAsync(_masterProtocol.Encode(PacketId.ExternalProxyState, new ExternalProxyConnectionState
|
||||
{
|
||||
IpAddress = session.VirtualIpAddress,
|
||||
Connected = false
|
||||
}));
|
||||
}
|
||||
|
||||
_lock.ExitWriteLock();
|
||||
}
|
||||
|
||||
public new void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
|
||||
_disposed = true;
|
||||
_disposedCancellation.Cancel();
|
||||
|
||||
try
|
||||
{
|
||||
Task delete = _natDevice?.DeletePortMapAsync(new Mapping(Protocol.Tcp, PrivatePort, _publicPort, 60, "Ryujinx Local Multiplayer"));
|
||||
|
||||
// Just absorb any exceptions.
|
||||
delete?.ContinueWith((task) => { });
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Fail silently.
|
||||
}
|
||||
}
|
||||
|
||||
protected override TcpSession CreateSession()
|
||||
{
|
||||
return new P2pProxySession(this);
|
||||
}
|
||||
|
||||
protected override void OnError(SocketError error)
|
||||
{
|
||||
Logger.Info?.PrintMsg(LogClass.ServiceLdn, $"Proxy TCP server caught an error with code {error}");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
using NetCoreServer;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types;
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
|
||||
{
|
||||
class P2pProxySession : TcpSession
|
||||
{
|
||||
public uint VirtualIpAddress { get; private set; }
|
||||
public RyuLdnProtocol Protocol { get; }
|
||||
|
||||
private readonly P2pProxyServer _parent;
|
||||
|
||||
private bool _masterClosed;
|
||||
|
||||
public P2pProxySession(P2pProxyServer server) : base(server)
|
||||
{
|
||||
_parent = server;
|
||||
|
||||
Protocol = new RyuLdnProtocol();
|
||||
|
||||
Protocol.ProxyDisconnect += HandleProxyDisconnect;
|
||||
Protocol.ProxyData += HandleProxyData;
|
||||
Protocol.ProxyConnectReply += HandleProxyConnectReply;
|
||||
Protocol.ProxyConnect += HandleProxyConnect;
|
||||
|
||||
Protocol.ExternalProxy += HandleAuthentication;
|
||||
}
|
||||
|
||||
private void HandleAuthentication(LdnHeader header, ExternalProxyConfig token)
|
||||
{
|
||||
if (!_parent.TryRegisterUser(this, token))
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIpv4(uint ip)
|
||||
{
|
||||
VirtualIpAddress = ip;
|
||||
}
|
||||
|
||||
public void DisconnectAndStop()
|
||||
{
|
||||
_masterClosed = true;
|
||||
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
protected override void OnDisconnected()
|
||||
{
|
||||
if (!_masterClosed)
|
||||
{
|
||||
_parent.DisconnectProxyClient(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnReceived(byte[] buffer, long offset, long size)
|
||||
{
|
||||
try
|
||||
{
|
||||
Protocol.Read(buffer, (int)offset, (int)size);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleProxyDisconnect(LdnHeader header, ProxyDisconnectMessage message)
|
||||
{
|
||||
_parent.HandleProxyDisconnect(this, header, message);
|
||||
}
|
||||
|
||||
private void HandleProxyData(LdnHeader header, ProxyDataHeader message, byte[] data)
|
||||
{
|
||||
_parent.HandleProxyData(this, header, message, data);
|
||||
}
|
||||
|
||||
private void HandleProxyConnectReply(LdnHeader header, ProxyConnectResponse data)
|
||||
{
|
||||
_parent.HandleProxyConnectReply(this, header, data);
|
||||
}
|
||||
|
||||
private void HandleProxyConnect(LdnHeader header, ProxyConnectRequest message)
|
||||
{
|
||||
_parent.HandleProxyConnect(this, header, message);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
|
||||
{
|
||||
static class ProxyHelpers
|
||||
{
|
||||
public static byte[] AddressTo16Byte(IPAddress address)
|
||||
{
|
||||
byte[] ipBytes = new byte[16];
|
||||
byte[] srcBytes = address.GetAddressBytes();
|
||||
|
||||
Array.Copy(srcBytes, 0, ipBytes, 0, srcBytes.Length);
|
||||
|
||||
return ipBytes;
|
||||
}
|
||||
|
||||
public static bool SupportsNoDelay()
|
||||
{
|
||||
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,380 @@
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.Types;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu
|
||||
{
|
||||
class RyuLdnProtocol
|
||||
{
|
||||
private const byte CurrentProtocolVersion = 1;
|
||||
private const int Magic = ('R' << 0) | ('L' << 8) | ('D' << 16) | ('N' << 24);
|
||||
private const int MaxPacketSize = 131072;
|
||||
|
||||
private readonly int _headerSize = Marshal.SizeOf<LdnHeader>();
|
||||
|
||||
private readonly byte[] _buffer = new byte[MaxPacketSize];
|
||||
private int _bufferEnd = 0;
|
||||
|
||||
// Client Packets.
|
||||
public event Action<LdnHeader, InitializeMessage> Initialize;
|
||||
public event Action<LdnHeader, PassphraseMessage> Passphrase;
|
||||
public event Action<LdnHeader, NetworkInfo> Connected;
|
||||
public event Action<LdnHeader, NetworkInfo> SyncNetwork;
|
||||
public event Action<LdnHeader, NetworkInfo> ScanReply;
|
||||
public event Action<LdnHeader> ScanReplyEnd;
|
||||
public event Action<LdnHeader, DisconnectMessage> Disconnected;
|
||||
|
||||
// External Proxy Packets.
|
||||
public event Action<LdnHeader, ExternalProxyConfig> ExternalProxy;
|
||||
public event Action<LdnHeader, ExternalProxyConnectionState> ExternalProxyState;
|
||||
public event Action<LdnHeader, ExternalProxyToken> ExternalProxyToken;
|
||||
|
||||
// Server Packets.
|
||||
public event Action<LdnHeader, CreateAccessPointRequest, byte[]> CreateAccessPoint;
|
||||
public event Action<LdnHeader, CreateAccessPointPrivateRequest, byte[]> CreateAccessPointPrivate;
|
||||
public event Action<LdnHeader, RejectRequest> Reject;
|
||||
public event Action<LdnHeader> RejectReply;
|
||||
public event Action<LdnHeader, SetAcceptPolicyRequest> SetAcceptPolicy;
|
||||
public event Action<LdnHeader, byte[]> SetAdvertiseData;
|
||||
public event Action<LdnHeader, ConnectRequest> Connect;
|
||||
public event Action<LdnHeader, ConnectPrivateRequest> ConnectPrivate;
|
||||
public event Action<LdnHeader, ScanFilter> Scan;
|
||||
|
||||
// Proxy Packets.
|
||||
public event Action<LdnHeader, ProxyConfig> ProxyConfig;
|
||||
public event Action<LdnHeader, ProxyConnectRequest> ProxyConnect;
|
||||
public event Action<LdnHeader, ProxyConnectResponse> ProxyConnectReply;
|
||||
public event Action<LdnHeader, ProxyDataHeader, byte[]> ProxyData;
|
||||
public event Action<LdnHeader, ProxyDisconnectMessage> ProxyDisconnect;
|
||||
|
||||
// Lifecycle Packets.
|
||||
public event Action<LdnHeader, NetworkErrorMessage> NetworkError;
|
||||
public event Action<LdnHeader, PingMessage> Ping;
|
||||
|
||||
public RyuLdnProtocol() { }
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_bufferEnd = 0;
|
||||
}
|
||||
|
||||
public void Read(byte[] data, int offset, int size)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
while (index < size)
|
||||
{
|
||||
if (_bufferEnd < _headerSize)
|
||||
{
|
||||
// Assemble the header first.
|
||||
|
||||
int copyable = Math.Min(size - index, Math.Min(size, _headerSize - _bufferEnd));
|
||||
|
||||
Array.Copy(data, index + offset, _buffer, _bufferEnd, copyable);
|
||||
|
||||
index += copyable;
|
||||
_bufferEnd += copyable;
|
||||
}
|
||||
|
||||
if (_bufferEnd >= _headerSize)
|
||||
{
|
||||
// The header is available. Make sure we received all the data (size specified in the header)
|
||||
|
||||
LdnHeader ldnHeader = MemoryMarshal.Cast<byte, LdnHeader>(_buffer)[0];
|
||||
|
||||
if (ldnHeader.Magic != Magic)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid magic number in received packet.");
|
||||
}
|
||||
|
||||
if (ldnHeader.Version != CurrentProtocolVersion)
|
||||
{
|
||||
throw new InvalidOperationException($"Protocol version mismatch. Expected ${CurrentProtocolVersion}, was ${ldnHeader.Version}.");
|
||||
}
|
||||
|
||||
int finalSize = _headerSize + ldnHeader.DataSize;
|
||||
|
||||
if (finalSize >= MaxPacketSize)
|
||||
{
|
||||
throw new InvalidOperationException($"Max packet size {MaxPacketSize} exceeded.");
|
||||
}
|
||||
|
||||
int copyable = Math.Min(size - index, Math.Min(size, finalSize - _bufferEnd));
|
||||
|
||||
Array.Copy(data, index + offset, _buffer, _bufferEnd, copyable);
|
||||
|
||||
index += copyable;
|
||||
_bufferEnd += copyable;
|
||||
|
||||
if (finalSize == _bufferEnd)
|
||||
{
|
||||
// The full packet has been retrieved. Send it to be decoded.
|
||||
|
||||
byte[] ldnData = new byte[ldnHeader.DataSize];
|
||||
|
||||
Array.Copy(_buffer, _headerSize, ldnData, 0, ldnData.Length);
|
||||
|
||||
DecodeAndHandle(ldnHeader, ldnData);
|
||||
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private (T, byte[]) ParseWithData<T>(byte[] data) where T : struct
|
||||
{
|
||||
T str = default;
|
||||
int size = Marshal.SizeOf(str);
|
||||
|
||||
byte[] remainder = new byte[data.Length - size];
|
||||
|
||||
if (remainder.Length > 0)
|
||||
{
|
||||
Array.Copy(data, size, remainder, 0, remainder.Length);
|
||||
}
|
||||
|
||||
return (MemoryMarshal.Read<T>(data), remainder);
|
||||
}
|
||||
|
||||
private void DecodeAndHandle(LdnHeader header, byte[] data)
|
||||
{
|
||||
switch ((PacketId)header.Type)
|
||||
{
|
||||
// Client Packets.
|
||||
case PacketId.Initialize:
|
||||
{
|
||||
Initialize?.Invoke(header, MemoryMarshal.Read<InitializeMessage>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.Passphrase:
|
||||
{
|
||||
Passphrase?.Invoke(header, MemoryMarshal.Read<PassphraseMessage>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.Connected:
|
||||
{
|
||||
Connected?.Invoke(header, MemoryMarshal.Read<NetworkInfo>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.SyncNetwork:
|
||||
{
|
||||
SyncNetwork?.Invoke(header, MemoryMarshal.Read<NetworkInfo>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ScanReply:
|
||||
{
|
||||
ScanReply?.Invoke(header, MemoryMarshal.Read<NetworkInfo>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PacketId.ScanReplyEnd:
|
||||
{
|
||||
ScanReplyEnd?.Invoke(header);
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.Disconnect:
|
||||
{
|
||||
Disconnected?.Invoke(header, MemoryMarshal.Read<DisconnectMessage>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// External Proxy Packets.
|
||||
case PacketId.ExternalProxy:
|
||||
{
|
||||
ExternalProxy?.Invoke(header, MemoryMarshal.Read<ExternalProxyConfig>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ExternalProxyState:
|
||||
{
|
||||
ExternalProxyState?.Invoke(header, MemoryMarshal.Read<ExternalProxyConnectionState>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ExternalProxyToken:
|
||||
{
|
||||
ExternalProxyToken?.Invoke(header, MemoryMarshal.Read<ExternalProxyToken>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Server Packets.
|
||||
case PacketId.CreateAccessPoint:
|
||||
{
|
||||
(CreateAccessPointRequest packet, byte[] extraData) = ParseWithData<CreateAccessPointRequest>(data);
|
||||
CreateAccessPoint?.Invoke(header, packet, extraData);
|
||||
break;
|
||||
}
|
||||
case PacketId.CreateAccessPointPrivate:
|
||||
{
|
||||
(CreateAccessPointPrivateRequest packet, byte[] extraData) = ParseWithData<CreateAccessPointPrivateRequest>(data);
|
||||
CreateAccessPointPrivate?.Invoke(header, packet, extraData);
|
||||
break;
|
||||
}
|
||||
case PacketId.Reject:
|
||||
{
|
||||
Reject?.Invoke(header, MemoryMarshal.Read<RejectRequest>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.RejectReply:
|
||||
{
|
||||
RejectReply?.Invoke(header);
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.SetAcceptPolicy:
|
||||
{
|
||||
SetAcceptPolicy?.Invoke(header, MemoryMarshal.Read<SetAcceptPolicyRequest>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.SetAdvertiseData:
|
||||
{
|
||||
SetAdvertiseData?.Invoke(header, data);
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.Connect:
|
||||
{
|
||||
Connect?.Invoke(header, MemoryMarshal.Read<ConnectRequest>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ConnectPrivate:
|
||||
{
|
||||
ConnectPrivate?.Invoke(header, MemoryMarshal.Read<ConnectPrivateRequest>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.Scan:
|
||||
{
|
||||
Scan?.Invoke(header, MemoryMarshal.Read<ScanFilter>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Proxy Packets
|
||||
case PacketId.ProxyConfig:
|
||||
{
|
||||
ProxyConfig?.Invoke(header, MemoryMarshal.Read<ProxyConfig>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ProxyConnect:
|
||||
{
|
||||
ProxyConnect?.Invoke(header, MemoryMarshal.Read<ProxyConnectRequest>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ProxyConnectReply:
|
||||
{
|
||||
ProxyConnectReply?.Invoke(header, MemoryMarshal.Read<ProxyConnectResponse>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ProxyData:
|
||||
{
|
||||
(ProxyDataHeader packet, byte[] extraData) = ParseWithData<ProxyDataHeader>(data);
|
||||
|
||||
ProxyData?.Invoke(header, packet, extraData);
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.ProxyDisconnect:
|
||||
{
|
||||
ProxyDisconnect?.Invoke(header, MemoryMarshal.Read<ProxyDisconnectMessage>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Lifecycle Packets.
|
||||
case PacketId.Ping:
|
||||
{
|
||||
Ping?.Invoke(header, MemoryMarshal.Read<PingMessage>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
case PacketId.NetworkError:
|
||||
{
|
||||
NetworkError?.Invoke(header, MemoryMarshal.Read<NetworkErrorMessage>(data));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static LdnHeader GetHeader(PacketId type, int dataSize)
|
||||
{
|
||||
return new LdnHeader()
|
||||
{
|
||||
Magic = Magic,
|
||||
Version = CurrentProtocolVersion,
|
||||
Type = (byte)type,
|
||||
DataSize = dataSize
|
||||
};
|
||||
}
|
||||
|
||||
public byte[] Encode(PacketId type)
|
||||
{
|
||||
LdnHeader header = GetHeader(type, 0);
|
||||
|
||||
return SpanHelpers.AsSpan<LdnHeader, byte>(ref header).ToArray();
|
||||
}
|
||||
|
||||
public byte[] Encode(PacketId type, byte[] data)
|
||||
{
|
||||
LdnHeader header = GetHeader(type, data.Length);
|
||||
|
||||
byte[] result = SpanHelpers.AsSpan<LdnHeader, byte>(ref header).ToArray();
|
||||
|
||||
Array.Resize(ref result, result.Length + data.Length);
|
||||
Array.Copy(data, 0, result, Marshal.SizeOf<LdnHeader>(), data.Length);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] Encode<T>(PacketId type, T packet) where T : unmanaged
|
||||
{
|
||||
byte[] packetData = SpanHelpers.AsSpan<T, byte>(ref packet).ToArray();
|
||||
|
||||
LdnHeader header = GetHeader(type, packetData.Length);
|
||||
|
||||
byte[] result = SpanHelpers.AsSpan<LdnHeader, byte>(ref header).ToArray();
|
||||
|
||||
Array.Resize(ref result, result.Length + packetData.Length);
|
||||
Array.Copy(packetData, 0, result, Marshal.SizeOf<LdnHeader>(), packetData.Length);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] Encode<T>(PacketId type, T packet, byte[] data) where T : unmanaged
|
||||
{
|
||||
byte[] packetData = SpanHelpers.AsSpan<T, byte>(ref packet).ToArray();
|
||||
|
||||
LdnHeader header = GetHeader(type, packetData.Length + data.Length);
|
||||
|
||||
byte[] result = SpanHelpers.AsSpan<LdnHeader, byte>(ref header).ToArray();
|
||||
|
||||
Array.Resize(ref result, result.Length + packetData.Length + data.Length);
|
||||
Array.Copy(packetData, 0, result, Marshal.SizeOf<LdnHeader>(), packetData.Length);
|
||||
Array.Copy(data, 0, result, Marshal.SizeOf<LdnHeader>() + packetData.Length, data.Length);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x4)]
|
||||
struct DisconnectMessage
|
||||
{
|
||||
public uint DisconnectIP;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Sent by the server to point a client towards an external server being used as a proxy.
|
||||
/// The client then forwards this to the external proxy after connecting, to verify the connection worked.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x26, Pack = 1)]
|
||||
struct ExternalProxyConfig
|
||||
{
|
||||
public Array16<byte> ProxyIp;
|
||||
public AddressFamily AddressFamily;
|
||||
public ushort ProxyPort;
|
||||
public Array16<byte> Token;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates a change in connection state for the given client.
|
||||
/// Is sent to notify the master server when connection is first established.
|
||||
/// Can be sent by the external proxy to the master server to notify it of a proxy disconnect.
|
||||
/// Can be sent by the master server to notify the external proxy of a user leaving a room.
|
||||
/// Both will result in a force kick.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x8, Pack = 4)]
|
||||
struct ExternalProxyConnectionState
|
||||
{
|
||||
public uint IpAddress;
|
||||
public bool Connected;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Sent by the master server to an external proxy to tell them someone is going to connect.
|
||||
/// This drives authentication, and lets the proxy know what virtual IP to give to each joiner,
|
||||
/// as these are managed by the master server.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x28)]
|
||||
struct ExternalProxyToken
|
||||
{
|
||||
public uint VirtualIp;
|
||||
public Array16<byte> Token;
|
||||
public Array16<byte> PhysicalIp;
|
||||
public AddressFamily AddressFamily;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// This message is first sent by the client to identify themselves.
|
||||
/// If the server has a token+mac combo that matches the submission, then they are returned their new ID and mac address. (the mac is also reassigned to the new id)
|
||||
/// Otherwise, they are returned a random mac address.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x16)]
|
||||
struct InitializeMessage
|
||||
{
|
||||
// All 0 if we don't have an ID yet.
|
||||
public Array16<byte> Id;
|
||||
|
||||
// All 0 if we don't have a mac yet.
|
||||
public Array6<byte> MacAddress;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0xA)]
|
||||
struct LdnHeader
|
||||
{
|
||||
public uint Magic;
|
||||
public byte Type;
|
||||
public byte Version;
|
||||
public int DataSize;
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
enum PacketId
|
||||
{
|
||||
Initialize,
|
||||
Passphrase,
|
||||
|
||||
CreateAccessPoint,
|
||||
CreateAccessPointPrivate,
|
||||
ExternalProxy,
|
||||
ExternalProxyToken,
|
||||
ExternalProxyState,
|
||||
SyncNetwork,
|
||||
Reject,
|
||||
RejectReply,
|
||||
Scan,
|
||||
ScanReply,
|
||||
ScanReplyEnd,
|
||||
Connect,
|
||||
ConnectPrivate,
|
||||
Connected,
|
||||
Disconnect,
|
||||
|
||||
ProxyConfig,
|
||||
ProxyConnect,
|
||||
ProxyConnectReply,
|
||||
ProxyData,
|
||||
ProxyDisconnect,
|
||||
|
||||
SetAcceptPolicy,
|
||||
SetAdvertiseData,
|
||||
|
||||
Ping = 254,
|
||||
NetworkError = 255
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x80)]
|
||||
struct PassphraseMessage
|
||||
{
|
||||
public Array128<byte> Passphrase;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x2)]
|
||||
struct PingMessage
|
||||
{
|
||||
public byte Requester;
|
||||
public byte Id;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
|
||||
struct ProxyConnectRequest
|
||||
{
|
||||
public ProxyInfo Info;
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
|
||||
struct ProxyConnectResponse
|
||||
{
|
||||
public ProxyInfo Info;
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents data sent over a transport layer.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x14)]
|
||||
struct ProxyDataHeader
|
||||
{
|
||||
public ProxyInfo Info;
|
||||
public uint DataLength; // Followed by the data with the specified byte length.
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Types
|
||||
{
|
||||
class ProxyDataPacket
|
||||
{
|
||||
public ProxyDataHeader Header;
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user