forked from MeloNX/MeloNX
Compare commits
44 Commits
melo-lates
...
XC-ios-ht
Author | SHA1 | Date | |
---|---|---|---|
c5c79c26ea | |||
61fca7892f | |||
6b045f3e6f | |||
f33e8ed879 | |||
c32873a734 | |||
c6415d7e32 | |||
5c18cb1bbb | |||
|
fc68e3d413 | ||
|
e382a35387 | ||
|
15171a703a | ||
|
4530a8839b | ||
|
4671ec67a2 | ||
|
a5fe1a34c5 | ||
|
b9282a25e8 | ||
|
0bb5389370 | ||
|
8b81cb39d7 | ||
|
ccdb8b76a8 | ||
37020a5026 | |||
259f6c6872 | |||
|
2b7e29fa21 | ||
8917ebf708 | |||
d326f5a00b | |||
3721a77cc4 | |||
667d54ed2d | |||
1b70bfea8b | |||
33b8571414 | |||
33af004d85 | |||
|
54cb7eb953 | ||
ceab2f0ac8 | |||
7986859398 | |||
c4506da8a1 | |||
9f72c9da10 | |||
ba0c49f545 | |||
80148ac69a | |||
|
7417ddfeef | ||
|
f66590203a | ||
|
f091e6c5ea | ||
|
75a66586b2 | ||
|
3207e1e739 | ||
|
a6b4f2d91f | ||
|
93af19e200 | ||
|
172f364f62 | ||
|
05666c918d | ||
b45af91523 |
49
.gitea/workflows/updateApp.yml
Normal file
49
.gitea/workflows/updateApp.yml
Normal file
@ -0,0 +1,49 @@
|
||||
name: Update apps.json on new release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
update:
|
||||
runs-on: debian-trixie
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get install -y jq
|
||||
|
||||
- name: Extract release data
|
||||
id: release
|
||||
run: |
|
||||
echo "VERSION=${GITEA_REF_NAME}" >> $GITHUB_OUTPUT
|
||||
echo "DESCRIPTION=$(echo '${GITEA_EVENT_RELEASE_BODY}' | jq -Rs .)" >> $GITHUB_OUTPUT
|
||||
echo "DATE=$(date '+%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
IPA_URL=$(echo '${GITEA_EVENT_RELEASE_ASSETS}' | jq -r '.[0].browser_download_url')
|
||||
echo "DOWNLOAD_URL=$IPA_URL" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update apps.json
|
||||
run: |
|
||||
jq --arg version "${{ steps.release.outputs.VERSION }}" \
|
||||
--arg buildVersion "1" \
|
||||
--arg date "${{ steps.release.outputs.DATE }}" \
|
||||
--arg localizedDescription "${{ steps.release.outputs.DESCRIPTION }}" \
|
||||
--arg downloadURL "${{ steps.release.outputs.DOWNLOAD_URL }}" \
|
||||
'.apps[0].versions |= [{"version": $version, "buildVersion": $buildVersion, "date": $date, "localizedDescription": $localizedDescription, "downloadURL": $downloadURL, "minOSVersion": "15.0"}]' \
|
||||
apps.json > tmp.json && mv tmp.json apps.json
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
git config user.name "gitea-actions"
|
||||
git config user.email "gitea-actions@localhost"
|
||||
git add apps.json
|
||||
git commit -m "Update apps.json for release ${{ steps.release.outputs.VERSION }}"
|
||||
git push
|
||||
env:
|
||||
GIT_AUTHOR_NAME: gitea-actions
|
||||
GIT_AUTHOR_EMAIL: gitea-actions@localhost
|
||||
GIT_COMMITTER_NAME: gitea-actions
|
||||
GIT_COMMITTER_EMAIL: gitea-actions@localhost
|
@ -1,3 +1,12 @@
|
||||
Currently licensed under the GNU AFFERO GENERAL PUBLIC LICENSE version 3, or any later version, at your choice.
|
||||
You may obtain a copy of the license at <https://gnu.org/>
|
||||
|
||||
Copyright (c) Rhajune Park and contributors, 2025
|
||||
|
||||
For copyright infringement claims, please contact abuse@pythonplayer123.dev for expedited processing
|
||||
|
||||
Previously licensed under the MeloNX License.
|
||||
|
||||
MeloNX License
|
||||
|
||||
Copyright (c) MeloNX Team and Contributors
|
||||
|
78
README.md
78
README.md
@ -6,11 +6,6 @@
|
||||
|
||||
<h1 align="center">MeloNX</h1>
|
||||
|
||||
## Documentation
|
||||
|
||||
If you are planning to contribute or just want to learn more about this project please read through our [documentation](docs/README.md).
|
||||
|
||||
|
||||
<p align="center">
|
||||
MeloNX enables Nintendo Switch game emulation on iOS using the Ryujinx iOS code base.
|
||||
</p>
|
||||
@ -28,11 +23,10 @@ MeloNX works on iPhone XS/XR and later and iPad 8th Gen and later. Check out the
|
||||
|
||||
## FAQ
|
||||
- MeloNX is made for iOS 17+, on iOS 15 - 16 MeloNX can be installed but may have issues or not work at all.
|
||||
- MeloNX needs Xcode or a Paid Apple Developer Account. SideStore support may come soon (SideStore Side Issue)
|
||||
- MeloNX needs JIT
|
||||
- MeloNX cannot be Sideloaded normally and requires the use of the following Installation Guide(s).
|
||||
- MeloNX requires JIT
|
||||
- Recommended Device: iPhone 15 Pro or newer.
|
||||
- Low-End Recommended Device**: iPhone 13 Pro.
|
||||
- Lowest Supported Device: iPhone XR
|
||||
- Low-End Recommended Device: iPhone 13 Pro.
|
||||
|
||||
|
||||
## How to install
|
||||
@ -54,14 +48,67 @@ MeloNX works on iPhone XS/XR and later and iPad 8th Gen and later. Check out the
|
||||
|
||||
4. **Enable JIT**
|
||||
- Use your preferred method to enable Just-In-Time (JIT) compilation.
|
||||
- We reccomend using [JitStreamer](https://jkcoxson.com/jitstreamer)
|
||||
|
||||
5. **Add Necessary Files**
|
||||
|
||||
If having Issues installing firmware (Make sure your Keys are installed first)
|
||||
- If needed, install firmware and keys from **Ryujinx Desktop**.
|
||||
- If needed, install firmware and keys from **Ryujinx Desktop** (or forks).
|
||||
- Copy the **bis** and **system** folders
|
||||
|
||||
### Free Developer Account (Experimental)
|
||||
|
||||
### Xcode
|
||||
1. **Sideload MeloNX**
|
||||
- Use [SideStore](https://sidestore.io/) or [AltStore](https://altstore.io/) (**NOT** AltStore PAL).
|
||||
|
||||
2. **Sideload the Entitlement App**
|
||||
- Install [this app](https://github.com/hugeBlack/GetMoreRam/releases/download/nightly/Entitlement.ipa) using [SideStore](https://sidestore.io/) or [AltStore](https://altstore.io/) (**NOT** AltStore PAL).
|
||||
|
||||
3. **Sign In to Your Account**
|
||||
- Open **Settings** in the entitlement app and sign in with your Apple ID.
|
||||
|
||||
4. **Refresh App IDs**
|
||||
- Navigate to the **App IDs** page.
|
||||
- Tap **Refresh** to update the list.
|
||||
|
||||
5. **Enable Increased Memory Limit**
|
||||
- Select **MeloNX** (should be like "com.stossy11.MeloNX" or some variation) from the list.
|
||||
- Tap **Add Increased Memory Limit**.
|
||||
|
||||
6. **Reinstall MeloNX**
|
||||
- Delete the existing installation.
|
||||
- Sideload the app again using SideStore or AltStore.
|
||||
|
||||
7. **Verify Increased Memory Limit**
|
||||
- Open MeloNX and check if the **Increased Memory Limit** is enabled.
|
||||
|
||||
8. **Add Necessary Files**
|
||||
|
||||
If having Issues installing firmware (Make sure your keys are installed first)
|
||||
- If needed, install firmware and keys from **Ryujinx Desktop** (or forks).
|
||||
- Copy the **bis** and **system** folders
|
||||
|
||||
9. **Enable JIT**
|
||||
- Use your preferred method to enable Just-In-Time (JIT) compilation.
|
||||
- We recommend using [JitStreamer](https://jkcoxson.com/jitstreamer)
|
||||
|
||||
|
||||
### TrollStore
|
||||
As Said in FAQ:
|
||||
> MeloNX is made for iOS 17+, on iOS 15 - 16 MeloNX can be installed but may have issues or not work at all.
|
||||
|
||||
1. **Install MeloNX with TrollStore**
|
||||
|
||||
2. **Add Necessary Files**
|
||||
|
||||
3. **Enable TrollStore JIT**
|
||||
- MeloNX includes automatic JIT using the TrollStore URL Scheme
|
||||
- Open MeloNX Settings
|
||||
- Scroll down and enable the "TrollStore JIT" toggle
|
||||
- Profit
|
||||
|
||||
|
||||
### Free Developer Account (Xcode)
|
||||
|
||||
**NOTE: These Xcode builds are nightly and may have unfinished features.**
|
||||
|
||||
@ -70,8 +117,8 @@ If having Issues installing firmware (Make sure your Keys are installed first)
|
||||
|
||||
2. **Add Necessary Files**
|
||||
|
||||
If having Issues installing firmware (Make sure your Keys are installed first)
|
||||
- If needed, install firmware and keys from **Ryujinx Desktop**.
|
||||
If having Issues installing firmware (Make sure your keys are installed first)
|
||||
- If needed, install firmware and keys from **Ryujinx Desktop** (or forks).
|
||||
- Copy the **bis** and **system** folders
|
||||
|
||||
## Features
|
||||
@ -99,9 +146,8 @@ If having Issues installing firmware (Make sure your Keys are installed first)
|
||||
- **Input**
|
||||
|
||||
We currently have support for keyboard, touch input, JoyCon input support, and nearly all controllers.
|
||||
Motion controls are natively supported in most cases; for dual-JoyCon motion support, DS4Windows or BetterJoy are currently required.
|
||||
In all scenarios, you can set up everything inside the input configuration menu.
|
||||
|
||||
Motion controls are natively supported in most cases.
|
||||
|
||||
- **DLC & Modifications**
|
||||
|
||||
MeloNX supports DLC + Game Update Add-ons.
|
||||
|
@ -41,4 +41,6 @@ ESCAPED_PATH=$(echo "$DOTNET_PATH" | sed 's/\//\\\//g')
|
||||
# Update the xcconfig file
|
||||
sed -i '' "s/^DOTNET = .*/DOTNET = $ESCAPED_PATH/g" "$XCCONFIG_FILE"
|
||||
|
||||
$DOTNET_PATH clean
|
||||
|
||||
echo "Updated MeloNX.xcconfig with DOTNET path: $DOTNET_PATH"
|
||||
|
49
source.json
Normal file
49
source.json
Normal file
@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "MeloNX",
|
||||
"subtitle": "A source for the MeloNX Application",
|
||||
"description": "Welcome to the MeloNX source! The latest download for MeloNX.",
|
||||
"iconURL": "https://git.743378673.xyz/CycloKid/assets/media/branch/main/Melo/AppIcons/MeloNX.png",
|
||||
"headerURL": "https://cdn.discordapp.com/attachments/1320760161836466257/1331670540447912090/melon-x-not-melo-nx-amiright-guys.png?ex=67f556d6&is=67f40556&hm=71be8f109a14f1c47d8f4965aa017bccb5617962b7a9f5cdfb936a5a8135dad7&",
|
||||
"website": "https://MeloNX.org",
|
||||
"tintColor": "#AE34EB",
|
||||
"featuredApps": [
|
||||
"com.stossy11.MeloNX"
|
||||
],
|
||||
"apps": [
|
||||
{
|
||||
"name": "MeloNX",
|
||||
"bundleIdentifier": "com.stossy11.MeloNX",
|
||||
"developerName": "Stossy11",
|
||||
"subtitle": "An NX Emulator.",
|
||||
"localizedDescription": "MeloNX is an iOS Nintendo Switch emulator based on Ryujinx, written primarily in C#. Designed to bring accurate performance and a user-friendly interface to iOS, MeloNX makes Switch games accessible on Apple devices. Developed from the ground up, MeloNX is open-source and available on a custom Gitea server under the MeloNX license (Based on MIT) (requires increased memory limit)",
|
||||
"iconURL": "https://git.743378673.xyz/CycloKid/assets/media/branch/main/Melo/AppIcons/MeloNX.png",
|
||||
"tintColor": "#AE34EB",
|
||||
"category": "games",
|
||||
"screenshots": [
|
||||
"https://git.743378673.xyz/stossy11/screenshots/raw/branch/main/IMG_0380.PNG",
|
||||
"https://git.743378673.xyz/stossy11/screenshots/raw/branch/main/IMG_0381.PNG"
|
||||
],
|
||||
"versions": [
|
||||
{
|
||||
"version": "1.7.0",
|
||||
"buildVersion": "1",
|
||||
"date": "2025-04-08",
|
||||
"localizedDescription": "First AltStore release!",
|
||||
"downloadURL": "https://git.743378673.xyz/MeloNX/MeloNX/releases/download/1.7.0/MeloNX.ipa",
|
||||
"size": 79821,
|
||||
"minOSVersion": "15.0"
|
||||
}
|
||||
],
|
||||
"appPermissions": {
|
||||
"entitlements": [
|
||||
"get-task-allow",
|
||||
"com.apple.developer.kernel.increased-memory-limit"
|
||||
],
|
||||
"privacy": {
|
||||
"NSPhotoLibraryAddUsageDescription": "MeloNX needs access to your Photo Library in order to save screenshots."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"news": []
|
||||
}
|
@ -3,7 +3,6 @@ using ARMeilleure.CodeGen.Unwinding;
|
||||
using ARMeilleure.Memory;
|
||||
using ARMeilleure.Native;
|
||||
using Ryujinx.Memory;
|
||||
using Ryujinx.Common.Logging;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
@ -16,73 +15,52 @@ namespace ARMeilleure.Translation.Cache
|
||||
static partial class JitCache
|
||||
{
|
||||
private static readonly int _pageSize = (int)MemoryBlock.GetPageSize();
|
||||
private static readonly int _pageMask = _pageSize - 4;
|
||||
private static readonly int _pageMask = _pageSize - 1;
|
||||
|
||||
private const int CodeAlignment = 4; // Bytes.
|
||||
private const int CacheSize = 128 * 1024 * 1024;
|
||||
private const int CacheSizeIOS = 128 * 1024 * 1024;
|
||||
private const int CacheSize = 2047 * 1024 * 1024;
|
||||
private const int CacheSizeIOS = 1024 * 1024 * 1024;
|
||||
|
||||
private static ReservedRegion _jitRegion;
|
||||
private static JitCacheInvalidation _jitCacheInvalidator;
|
||||
|
||||
private static List<CacheMemoryAllocator> _cacheAllocators = [];
|
||||
private static CacheMemoryAllocator _cacheAllocator;
|
||||
|
||||
private static readonly List<CacheEntry> _cacheEntries = new();
|
||||
|
||||
private static readonly object _lock = new();
|
||||
private static bool _initialized;
|
||||
|
||||
private static readonly List<ReservedRegion> _jitRegions = new();
|
||||
|
||||
private static int _activeRegionIndex = 0;
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
[LibraryImport("kernel32.dll", SetLastError = true)]
|
||||
public static partial IntPtr FlushInstructionCache(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize);
|
||||
|
||||
public static void Initialize(IJitMemoryAllocator allocator)
|
||||
{
|
||||
if (_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (_initialized)
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
// JitUnwindWindows.RemoveFunctionTableHandler(
|
||||
// _jitRegions[0].Pointer);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _jitRegions.Count; i++)
|
||||
{
|
||||
_jitRegions[i].Dispose();
|
||||
}
|
||||
|
||||
_jitRegions.Clear();
|
||||
_cacheAllocators.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
_initialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_activeRegionIndex = 0;
|
||||
|
||||
var firstRegion = new ReservedRegion(allocator, CacheSize);
|
||||
_jitRegions.Add(firstRegion);
|
||||
|
||||
CacheMemoryAllocator firstCacheAllocator = new(CacheSize);
|
||||
_cacheAllocators.Add(firstCacheAllocator);
|
||||
_jitRegion = new ReservedRegion(allocator, (ulong)(OperatingSystem.IsIOS() ? CacheSizeIOS : CacheSize));
|
||||
|
||||
if (!OperatingSystem.IsWindows() && !OperatingSystem.IsMacOS() && !OperatingSystem.IsIOS())
|
||||
{
|
||||
_jitCacheInvalidator = new JitCacheInvalidation(allocator);
|
||||
}
|
||||
|
||||
_cacheAllocator = new CacheMemoryAllocator(CacheSize);
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
JitUnwindWindows.InstallFunctionTableHandler(
|
||||
firstRegion.Pointer, CacheSize, firstRegion.Pointer + Allocate(_pageSize)
|
||||
);
|
||||
JitUnwindWindows.InstallFunctionTableHandler(_jitRegion.Pointer, CacheSize, _jitRegion.Pointer + Allocate(_pageSize));
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
@ -95,9 +73,7 @@ namespace ARMeilleure.Translation.Cache
|
||||
{
|
||||
while (_deferredRxProtect.TryDequeue(out var result))
|
||||
{
|
||||
ReservedRegion targetRegion = _jitRegions[_activeRegionIndex];
|
||||
|
||||
ReprotectAsExecutable(targetRegion, result.funcOffset, result.length);
|
||||
ReprotectAsExecutable(result.funcOffset, result.length);
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,8 +87,7 @@ namespace ARMeilleure.Translation.Cache
|
||||
|
||||
int funcOffset = Allocate(code.Length, deferProtect);
|
||||
|
||||
ReservedRegion targetRegion = _jitRegions[_activeRegionIndex];
|
||||
IntPtr funcPtr = targetRegion.Pointer + funcOffset;
|
||||
IntPtr funcPtr = _jitRegion.Pointer + funcOffset;
|
||||
|
||||
if (OperatingSystem.IsIOS())
|
||||
{
|
||||
@ -123,7 +98,8 @@ namespace ARMeilleure.Translation.Cache
|
||||
}
|
||||
else
|
||||
{
|
||||
ReprotectAsExecutable(targetRegion, funcOffset, code.Length);
|
||||
ReprotectAsExecutable(funcOffset, code.Length);
|
||||
|
||||
JitSupportDarwinAot.Invalidate(funcPtr, (ulong)code.Length);
|
||||
}
|
||||
}
|
||||
@ -139,9 +115,9 @@ namespace ARMeilleure.Translation.Cache
|
||||
}
|
||||
else
|
||||
{
|
||||
ReprotectAsWritable(targetRegion, funcOffset, code.Length);
|
||||
ReprotectAsWritable(funcOffset, code.Length);
|
||||
Marshal.Copy(code, 0, funcPtr, code.Length);
|
||||
ReprotectAsExecutable(targetRegion, funcOffset, code.Length);
|
||||
ReprotectAsExecutable(funcOffset, code.Length);
|
||||
|
||||
if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
||||
{
|
||||
@ -163,50 +139,41 @@ namespace ARMeilleure.Translation.Cache
|
||||
{
|
||||
if (OperatingSystem.IsIOS())
|
||||
{
|
||||
// return;
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
foreach (var region in _jitRegions)
|
||||
Debug.Assert(_initialized);
|
||||
|
||||
int funcOffset = (int)(pointer.ToInt64() - _jitRegion.Pointer.ToInt64());
|
||||
|
||||
if (TryFind(funcOffset, out CacheEntry entry, out int entryIndex) && entry.Offset == funcOffset)
|
||||
{
|
||||
if (pointer.ToInt64() < region.Pointer.ToInt64() ||
|
||||
pointer.ToInt64() >= (region.Pointer + CacheSize).ToInt64())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int funcOffset = (int)(pointer.ToInt64() - region.Pointer.ToInt64());
|
||||
|
||||
if (TryFind(funcOffset, out CacheEntry entry, out int entryIndex) && entry.Offset == funcOffset)
|
||||
{
|
||||
_cacheAllocators[_activeRegionIndex].Free(funcOffset, AlignCodeSize(entry.Size));
|
||||
_cacheEntries.RemoveAt(entryIndex);
|
||||
}
|
||||
|
||||
return;
|
||||
_cacheAllocator.Free(funcOffset, AlignCodeSize(entry.Size));
|
||||
_cacheEntries.RemoveAt(entryIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReprotectAsWritable(ReservedRegion region, int offset, int size)
|
||||
private static void ReprotectAsWritable(int offset, int size)
|
||||
{
|
||||
int endOffs = offset + size;
|
||||
|
||||
int regionStart = offset & ~_pageMask;
|
||||
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
||||
|
||||
region.Block.MapAsRwx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||
_jitRegion.Block.MapAsRwx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||
}
|
||||
|
||||
private static void ReprotectAsExecutable(ReservedRegion region, int offset, int size)
|
||||
private static void ReprotectAsExecutable(int offset, int size)
|
||||
{
|
||||
int endOffs = offset + size;
|
||||
|
||||
int regionStart = offset & ~_pageMask;
|
||||
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
||||
|
||||
region.Block.MapAsRx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||
_jitRegion.Block.MapAsRx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||
}
|
||||
|
||||
private static int Allocate(int codeSize, bool deferProtect = false)
|
||||
@ -220,33 +187,18 @@ namespace ARMeilleure.Translation.Cache
|
||||
alignment = 0x4000;
|
||||
}
|
||||
|
||||
int allocOffset = _cacheAllocators[_activeRegionIndex].Allocate(ref codeSize, alignment);
|
||||
int allocOffset = _cacheAllocator.Allocate(ref codeSize, alignment);
|
||||
|
||||
if (allocOffset >= 0)
|
||||
Console.WriteLine($"{allocOffset:x8}: {codeSize:x8} {alignment:x8}");
|
||||
|
||||
if (allocOffset < 0)
|
||||
{
|
||||
_jitRegions[_activeRegionIndex].ExpandIfNeeded((ulong)allocOffset + (ulong)codeSize);
|
||||
return allocOffset;
|
||||
throw new OutOfMemoryException("JIT Cache exhausted.");
|
||||
}
|
||||
|
||||
int exhaustedRegion = _activeRegionIndex;
|
||||
var newRegion = new ReservedRegion(_jitRegions[0].Allocator, CacheSize);
|
||||
_jitRegions.Add(newRegion);
|
||||
_activeRegionIndex = _jitRegions.Count - 1;
|
||||
_jitRegion.ExpandIfNeeded((ulong)allocOffset + (ulong)codeSize);
|
||||
|
||||
int newRegionNumber = _activeRegionIndex;
|
||||
|
||||
Logger.Info?.Print(LogClass.Cpu, $"JIT Cache Region {exhaustedRegion} exhausted, creating new Cache Region {_activeRegionIndex} ({((long)(_activeRegionIndex + 1) * CacheSize)} Total Allocation).");
|
||||
|
||||
_cacheAllocators.Add(new CacheMemoryAllocator(CacheSize));
|
||||
|
||||
int allocOffsetNew = _cacheAllocators[_activeRegionIndex].Allocate(ref codeSize, alignment);
|
||||
if (allocOffsetNew < 0)
|
||||
{
|
||||
throw new OutOfMemoryException("Failed to allocate in new Cache Region!");
|
||||
}
|
||||
|
||||
newRegion.ExpandIfNeeded((ulong)allocOffsetNew + (ulong)codeSize);
|
||||
return allocOffsetNew;
|
||||
return allocOffset;
|
||||
}
|
||||
|
||||
private static int AlignCodeSize(int codeSize, bool deferProtect = false)
|
||||
@ -299,4 +251,4 @@ namespace ARMeilleure.Translation.Cache
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,6 @@
|
||||
// Configuration settings file format documentation can be found at:
|
||||
// https://help.apple.com/xcode/#/dev745c5c974
|
||||
|
||||
VERSION = 1.5.0
|
||||
VERSION = 1.7.0
|
||||
|
||||
DOTNET = /usr/local/share/dotnet/dotnet
|
||||
|
@ -24,7 +24,6 @@
|
||||
/* End PBXAggregateTarget section */
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
4E0DED342D05695D00FEF007 /* SwiftUIJoystick in Frameworks */ = {isa = PBXBuildFile; productRef = 4E0DED332D05695D00FEF007 /* SwiftUIJoystick */; };
|
||||
4E12B23C2D797CFA00FB2271 /* MeloNX.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 4E12B23B2D797CFA00FB2271 /* MeloNX.xcconfig */; };
|
||||
4E8A80772D5FDD2D0041B48F /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E80AA622CD7122800029585 /* GameController.framework */; };
|
||||
4EA5AE822D16807500AD0B9F /* SwiftSVG in Frameworks */ = {isa = PBXBuildFile; productRef = 4EA5AE812D16807500AD0B9F /* SwiftSVG */; };
|
||||
@ -32,6 +31,13 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
4E2953AB2D803BC9000497CD /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 4E80A9852CD6F54500029585 /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = BD43C6212D1B248D003BBC42;
|
||||
remoteInfo = com.Stossy11.MeloNX.RyujinxAg;
|
||||
};
|
||||
4E80A99E2CD6F54700029585 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 4E80A9852CD6F54500029585 /* Project object */;
|
||||
@ -109,7 +115,7 @@
|
||||
"Dependencies/Dynamic Libraries/Ryujinx.Headless.SDL2.dylib" = (
|
||||
CodeSignOnCopy,
|
||||
);
|
||||
"Dependencies/Dynamic Libraries/RyujinxKeyboard.framework" = (
|
||||
"Dependencies/Dynamic Libraries/RyujinxHelper.framework" = (
|
||||
CodeSignOnCopy,
|
||||
RemoveHeadersOnCopy,
|
||||
);
|
||||
@ -122,10 +128,6 @@
|
||||
"Dependencies/Dynamic Libraries/libavutil.dylib" = (
|
||||
CodeSignOnCopy,
|
||||
);
|
||||
Dependencies/XCFrameworks/MoltenVK.xcframework = (
|
||||
CodeSignOnCopy,
|
||||
RemoveHeadersOnCopy,
|
||||
);
|
||||
Dependencies/XCFrameworks/SDL2.xcframework = (
|
||||
CodeSignOnCopy,
|
||||
RemoveHeadersOnCopy,
|
||||
@ -170,7 +172,7 @@
|
||||
"Dependencies/Dynamic Libraries/libavutil.dylib",
|
||||
"Dependencies/Dynamic Libraries/libMoltenVK.dylib",
|
||||
"Dependencies/Dynamic Libraries/Ryujinx.Headless.SDL2.dylib",
|
||||
"Dependencies/Dynamic Libraries/RyujinxKeyboard.framework",
|
||||
"Dependencies/Dynamic Libraries/RyujinxHelper.framework",
|
||||
Dependencies/XCFrameworks/libavcodec.xcframework,
|
||||
Dependencies/XCFrameworks/libavfilter.xcframework,
|
||||
Dependencies/XCFrameworks/libavformat.xcframework,
|
||||
@ -179,7 +181,6 @@
|
||||
Dependencies/XCFrameworks/libswresample.xcframework,
|
||||
Dependencies/XCFrameworks/libswscale.xcframework,
|
||||
Dependencies/XCFrameworks/libteakra.xcframework,
|
||||
Dependencies/XCFrameworks/MoltenVK.xcframework,
|
||||
Dependencies/XCFrameworks/SDL2.xcframework,
|
||||
);
|
||||
};
|
||||
@ -196,7 +197,6 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
4E0DED342D05695D00FEF007 /* SwiftUIJoystick in Frameworks */,
|
||||
CA8F9C322D3F5AB200D7E586 /* GameController.framework in Frameworks */,
|
||||
4EA5AE822D16807500AD0B9F /* SwiftSVG in Frameworks */,
|
||||
4E8A80772D5FDD2D0041B48F /* GameController.framework in Frameworks */,
|
||||
@ -287,13 +287,13 @@
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
4E2953AC2D803BC9000497CD /* PBXTargetDependency */,
|
||||
);
|
||||
fileSystemSynchronizedGroups = (
|
||||
4E80A98F2CD6F54500029585 /* MeloNX */,
|
||||
);
|
||||
name = MeloNX;
|
||||
packageProductDependencies = (
|
||||
4E0DED332D05695D00FEF007 /* SwiftUIJoystick */,
|
||||
4EA5AE812D16807500AD0B9F /* SwiftSVG */,
|
||||
);
|
||||
productName = MeloNX;
|
||||
@ -354,7 +354,7 @@
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1620;
|
||||
LastUpgradeCheck = 1610;
|
||||
LastUpgradeCheck = 1620;
|
||||
TargetAttributes = {
|
||||
4E80A98C2CD6F54500029585 = {
|
||||
CreatedOnToolsVersion = 16.1;
|
||||
@ -385,7 +385,6 @@
|
||||
mainGroup = 4E80A9842CD6F54500029585;
|
||||
minimizedProjectReferenceProxies = 1;
|
||||
packageReferences = (
|
||||
4E0DED322D05695D00FEF007 /* XCRemoteSwiftPackageReference "SwiftUIJoystick" */,
|
||||
4EA5AE802D16807500AD0B9F /* XCRemoteSwiftPackageReference "SwiftSVG" */,
|
||||
);
|
||||
preferredProjectObjectVersion = 56;
|
||||
@ -445,7 +444,7 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "cd ../..\nmv src/Ryujinx.Headless.SDL2/bin/Release/net8.0/ios-arm64/native/Ryujinx.Headless.SDL2.dylib src/MeloNX/MeloNX/Dependencies/Dynamic\\ Libraries/Ryujinx.Headless.SDL2.dylib\n";
|
||||
shellScript = "cd ../..\nmv src/Ryujinx.Headless.SDL2/bin/Release/net8.0/ios-arm64/publish/Ryujinx.Headless.SDL2.dylib src/MeloNX/MeloNX/Dependencies/Dynamic\\ Libraries/Ryujinx.Headless.SDL2.dylib\n";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
@ -474,6 +473,12 @@
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
4E2953AC2D803BC9000497CD /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
platformFilter = ios;
|
||||
target = BD43C6212D1B248D003BBC42 /* com.Stossy11.MeloNX.RyujinxAg */;
|
||||
targetProxy = 4E2953AB2D803BC9000497CD /* PBXContainerItemProxy */;
|
||||
};
|
||||
4E80A99F2CD6F54700029585 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 4E80A98C2CD6F54500029585 /* MeloNX */;
|
||||
@ -638,7 +643,7 @@
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_ASSET_PATHS = "";
|
||||
DEVELOPMENT_TEAM = 95J8WZ4TN8;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
ENABLE_PREVIEWS = YES;
|
||||
ENABLE_TESTABILITY = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
@ -693,8 +698,40 @@
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
);
|
||||
GCC_OPTIMIZATION_LEVEL = fast;
|
||||
GCC_OPTIMIZATION_LEVEL = z;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = MeloNX/Info.plist;
|
||||
INFOPLIST_KEY_GCSupportsControllerUserInteraction = YES;
|
||||
@ -708,7 +745,7 @@
|
||||
INFOPLIST_KEY_UIRequiresFullScreen = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
|
||||
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
@ -808,10 +845,83 @@
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
);
|
||||
MARKETING_VERSION = "$(VERSION)";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.stossy11.MeloNX;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MeloNX/App/Core/Headers/Ryujinx-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@ -884,8 +994,40 @@
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
);
|
||||
GCC_OPTIMIZATION_LEVEL = fast;
|
||||
GCC_OPTIMIZATION_LEVEL = z;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_FILE = MeloNX/Info.plist;
|
||||
INFOPLIST_KEY_GCSupportsControllerUserInteraction = YES;
|
||||
@ -899,7 +1041,7 @@
|
||||
INFOPLIST_KEY_UIRequiresFullScreen = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
|
||||
INFOPLIST_KEY_UISupportsDocumentBrowser = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
@ -999,10 +1141,83 @@
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
|
||||
);
|
||||
MARKETING_VERSION = "$(VERSION)";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.stossy11.MeloNX;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
|
||||
SUPPORTS_MACCATALYST = NO;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "MeloNX/App/Core/Headers/Ryujinx-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@ -1198,14 +1413,6 @@
|
||||
/* End XCConfigurationList section */
|
||||
|
||||
/* Begin XCRemoteSwiftPackageReference section */
|
||||
4E0DED322D05695D00FEF007 /* XCRemoteSwiftPackageReference "SwiftUIJoystick" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/michael94ellis/SwiftUIJoystick";
|
||||
requirement = {
|
||||
kind = upToNextMajorVersion;
|
||||
minimumVersion = 1.5.0;
|
||||
};
|
||||
};
|
||||
4EA5AE802D16807500AD0B9F /* XCRemoteSwiftPackageReference "SwiftSVG" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/mchoe/SwiftSVG";
|
||||
@ -1217,11 +1424,6 @@
|
||||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
4E0DED332D05695D00FEF007 /* SwiftUIJoystick */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 4E0DED322D05695D00FEF007 /* XCRemoteSwiftPackageReference "SwiftUIJoystick" */;
|
||||
productName = SwiftUIJoystick;
|
||||
};
|
||||
4EA5AE812D16807500AD0B9F /* SwiftSVG */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 4EA5AE802D16807500AD0B9F /* XCRemoteSwiftPackageReference "SwiftSVG" */;
|
||||
|
@ -1,24 +0,0 @@
|
||||
{
|
||||
"originHash" : "d611b071fbe94fdc9900a07a218340eab4ce2c3c7168bf6542f2830c0400a72b",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "swiftsvg",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/mchoe/SwiftSVG",
|
||||
"state" : {
|
||||
"branch" : "master",
|
||||
"revision" : "88b9ee086b29019e35f6f49c8e30e5552eb8fa9d"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swiftuijoystick",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/michael94ellis/SwiftUIJoystick",
|
||||
"state" : {
|
||||
"revision" : "5bd303cdafb369a70a45c902538b42dd3c5f4d65",
|
||||
"version" : "1.5.0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
}
|
Binary file not shown.
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<array/>
|
||||
</plist>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1610"
|
||||
version = "1.7">
|
||||
LastUpgradeVersion = "1620"
|
||||
version = "2.0">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES"
|
||||
@ -62,10 +62,13 @@
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugXPCServices = "NO"
|
||||
debugServiceExtension = "internal"
|
||||
enableGPUValidationMode = "1"
|
||||
showGraphicsOverview = "Yes"
|
||||
allowLocationSimulation = "YES">
|
||||
allowLocationSimulation = "YES"
|
||||
queueDebuggingEnabled = "No"
|
||||
consoleMode = "0"
|
||||
structuredConsoleMode = "2">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
@ -105,8 +108,17 @@
|
||||
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
|
||||
<ActionContent
|
||||
title = "Run Script"
|
||||
scriptText = "REPO_DIR="$(cd "${SRCROOT}/../../" && pwd)" SCRIPT_PATH="$REPO_DIR/distribution/ios/set_current_version.sh" sh "${SCRIPT_PATH}" "
|
||||
scriptText = "REPO_DIR="$(cd "${SRCROOT}/../../" && pwd)" SCRIPT_PATH="$REPO_DIR/distribution/ios/set_current_version.sh" echo "hi" sh "${SCRIPT_PATH}" "
|
||||
shellToInvoke = "/bin/bash">
|
||||
<EnvironmentBuildable>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "4E80A98C2CD6F54500029585"
|
||||
BuildableName = "MeloNX.app"
|
||||
BlueprintName = "MeloNX"
|
||||
ReferencedContainer = "container:MeloNX.xcodeproj">
|
||||
</BuildableReference>
|
||||
</EnvironmentBuildable>
|
||||
</ActionContent>
|
||||
</ExecutionAction>
|
||||
</PreActions>
|
||||
|
@ -11,7 +11,7 @@
|
||||
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
|
||||
<ActionContent
|
||||
title = "Run Script"
|
||||
scriptText = "REPO_DIR="$(cd "${SRCROOT}/../../" && pwd)" SCRIPT_PATH="$REPO_DIR/distribution/ios/get_dotnet.sh" sh "${SCRIPT_PATH}" "
|
||||
scriptText = "REPO_DIR="$(cd "${SRCROOT}/../../" && pwd)" SCRIPT_PATH="$REPO_DIR/distribution/ios/get_dotnet.sh" echo "Xcode is located at: $DEVELOPER_DIR" sh "${SCRIPT_PATH}" "
|
||||
shellToInvoke = "/bin/bash">
|
||||
<EnvironmentBuildable>
|
||||
<BuildableReference
|
||||
|
@ -31,12 +31,12 @@ func SecTaskCopyValuesForEntitlements(
|
||||
|
||||
func checkAppEntitlements(_ ents: [String]) -> [String: Any] {
|
||||
guard let task = SecTaskCreateFromSelf(nil) else {
|
||||
print("Failed to create SecTask")
|
||||
// print("Failed to create SecTask")
|
||||
return [:]
|
||||
}
|
||||
|
||||
guard let entitlements = SecTaskCopyValuesForEntitlements(task, ents as CFArray, nil) else {
|
||||
print("Failed to get entitlements")
|
||||
// print("Failed to get entitlements")
|
||||
return [:]
|
||||
}
|
||||
|
||||
@ -45,12 +45,12 @@ func checkAppEntitlements(_ ents: [String]) -> [String: Any] {
|
||||
|
||||
func checkAppEntitlement(_ ent: String) -> Bool {
|
||||
guard let task = SecTaskCreateFromSelf(nil) else {
|
||||
print("Failed to create SecTask")
|
||||
// print("Failed to create SecTask")
|
||||
return false
|
||||
}
|
||||
|
||||
guard let entitlements = SecTaskCopyValueForEntitlement(task, ent as NSString, nil) else {
|
||||
print("Failed to get entitlements")
|
||||
// print("Failed to get entitlements")
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ char* installed_firmware_version();
|
||||
|
||||
void set_native_window(void *layerPtr);
|
||||
|
||||
void stop_emulation();
|
||||
void stop_emulation(bool shouldPause);
|
||||
|
||||
void initialize();
|
||||
|
||||
|
@ -34,7 +34,7 @@ func checkMemoryPermissions(at address: UnsafeRawPointer) -> Bool {
|
||||
}
|
||||
|
||||
if result != KERN_SUCCESS {
|
||||
print("Failed to reach \(address)")
|
||||
// print("Failed to reach \(address)")
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -6,39 +6,121 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Network
|
||||
import UIKit
|
||||
|
||||
func enableJITEB() {
|
||||
guard let bundleID = Bundle.main.bundleIdentifier else {
|
||||
return
|
||||
func enableJITEB() {
|
||||
if UserDefaults.standard.bool(forKey: "waitForVPN") {
|
||||
waitForVPNConnection { connected in
|
||||
if connected {
|
||||
enableJITEBRequest()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
enableJITEBRequest()
|
||||
}
|
||||
}
|
||||
|
||||
func enableJITEBRequest() {
|
||||
let pid = Int(getpid())
|
||||
// print(pid)
|
||||
|
||||
let address = URL(string: "http://[fd00::]:9172/launch_app/\(bundleID)")!
|
||||
let address = URL(string: "http://[fd00::]:9172/attach/\(pid)")!
|
||||
var request = URLRequest(url: address)
|
||||
request.httpMethod = "POST"
|
||||
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let task = URLSession.shared.dataTask(with: address) { data, response, error in
|
||||
if error != nil {
|
||||
let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
||||
if let error = error {
|
||||
presentAlert(title: "Request Error", message: error.localizedDescription)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
guard let httpResponse = response as? HTTPURLResponse else {
|
||||
return
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
showLaunchAppAlert(jsonData: data!, in: UIApplication.shared.windows.last!.rootViewController!)
|
||||
if let data = data, let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
|
||||
showLaunchAppAlert(jsonData: data, in: windowScene.windows.last!.rootViewController!)
|
||||
} else {
|
||||
fatalError("Unable to get Window")
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
|
||||
func waitForVPNConnection(timeout: TimeInterval = 30, interval: TimeInterval = 1, _ completion: @escaping (Bool) -> Void) {
|
||||
let startTime = Date()
|
||||
let timer = DispatchSource.makeTimerSource(queue: DispatchQueue.global(qos: .background))
|
||||
|
||||
timer.schedule(deadline: .now(), repeating: interval)
|
||||
|
||||
timer.setEventHandler {
|
||||
pingSite { connected in
|
||||
if connected {
|
||||
timer.cancel()
|
||||
DispatchQueue.main.async {
|
||||
completion(true)
|
||||
}
|
||||
} else if Date().timeIntervalSince(startTime) > timeout {
|
||||
timer.cancel()
|
||||
DispatchQueue.main.async {
|
||||
completion(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timer.resume()
|
||||
}
|
||||
|
||||
func pingSite(host: String = "http://[fd00::]:9172/hello", completion: @escaping (Bool) -> Void) {
|
||||
guard let url = URL(string: host) else {
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
|
||||
let config = URLSessionConfiguration.default
|
||||
config.timeoutIntervalForRequest = 2.0
|
||||
config.timeoutIntervalForResource = 2.0
|
||||
|
||||
let session = URLSession(configuration: config)
|
||||
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "GET"
|
||||
|
||||
let task = session.dataTask(with: request) { _, response, error in
|
||||
if let error = error {
|
||||
// print("Ping failed: \(error.localizedDescription)")
|
||||
completion(false)
|
||||
} else if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 {
|
||||
completion(true)
|
||||
} else {
|
||||
let httpResponse = response as? HTTPURLResponse
|
||||
completion(false)
|
||||
}
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
|
||||
|
||||
func presentAlert(title: String, message: String, completion: (() -> Void)? = nil) {
|
||||
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
||||
let lastWindow = windowScene.windows.last {
|
||||
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .default) { _ in
|
||||
completion?()
|
||||
})
|
||||
|
||||
DispatchQueue.main.async {
|
||||
lastWindow.rootViewController?.present(alert, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LaunchApp: Codable {
|
||||
let ok: Bool
|
||||
let error: String?
|
||||
let launching: Bool
|
||||
let position: Int?
|
||||
let mounting: Bool
|
||||
let success: Bool
|
||||
let message: String
|
||||
}
|
||||
|
||||
func showLaunchAppAlert(jsonData: Data, in viewController: UIViewController) {
|
||||
@ -47,28 +129,23 @@ func showLaunchAppAlert(jsonData: Data, in viewController: UIViewController) {
|
||||
|
||||
var message = ""
|
||||
|
||||
if let error = result.error {
|
||||
message = "Error: \(error)"
|
||||
} else if result.mounting {
|
||||
message = "App is mounting..."
|
||||
} else if result.launching {
|
||||
message = "App is launching..."
|
||||
if !result.success {
|
||||
message += "\n\(result.message)"
|
||||
|
||||
|
||||
let alert = UIAlertController(title: "JIT Error", message: message, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .default))
|
||||
|
||||
DispatchQueue.main.async {
|
||||
viewController.present(alert, animated: true)
|
||||
}
|
||||
} else {
|
||||
message = "App launch status unknown."
|
||||
}
|
||||
|
||||
if let position = result.position {
|
||||
message += "\nPosition: \(position)"
|
||||
}
|
||||
|
||||
let alert = UIAlertController(title: "Launch Status", message: message, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .default))
|
||||
|
||||
DispatchQueue.main.async {
|
||||
viewController.present(alert, animated: true)
|
||||
// print("Hopefully JIT is enabled now...")
|
||||
Ryujinx.shared.ryuIsJITEnabled()
|
||||
}
|
||||
|
||||
} catch {
|
||||
// print(String(data: jsonData, encoding: .utf8))
|
||||
let alert = UIAlertController(title: "Decoding Error", message: error.localizedDescription, preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .default))
|
||||
|
||||
|
19
src/MeloNX/MeloNX/App/Core/JIT/StikJIT/StikEnableJIT.swift
Normal file
19
src/MeloNX/MeloNX/App/Core/JIT/StikJIT/StikEnableJIT.swift
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// EnableJIT.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by Stossy11 on 10/02/2025.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Network
|
||||
import UIKit
|
||||
|
||||
func enableJITStik() {
|
||||
let bundleid = Bundle.main.bundleIdentifier ?? "Unknown"
|
||||
|
||||
let address = URL(string: "stikjit://enable-jit?bundle-id=\(bundleid)")!
|
||||
if UIApplication.shared.canOpenURL(address) {
|
||||
UIApplication.shared.open(address)
|
||||
}
|
||||
}
|
@ -49,52 +49,50 @@ class NativeController: Hashable {
|
||||
// Update joystick state here
|
||||
},
|
||||
SetPlayerIndex: { userdata, playerIndex in
|
||||
print("Player index set to \(playerIndex)")
|
||||
// print("Player index set to \(playerIndex)")
|
||||
},
|
||||
Rumble: { userdata, lowFreq, highFreq in
|
||||
print("Rumble with \(lowFreq), \(highFreq)")
|
||||
// print("Rumble with \(lowFreq), \(highFreq)")
|
||||
guard let userdata else { return 0 }
|
||||
let _self = Unmanaged<NativeController>.fromOpaque(userdata).takeUnretainedValue()
|
||||
VirtualController.rumble(lowFreq: Float(lowFreq), highFreq: Float(highFreq), engine: _self.controllerHaptics)
|
||||
return 0
|
||||
},
|
||||
RumbleTriggers: { userdata, leftRumble, rightRumble in
|
||||
print("Trigger rumble with \(leftRumble), \(rightRumble)")
|
||||
// print("Trigger rumble with \(leftRumble), \(rightRumble)")
|
||||
return 0
|
||||
},
|
||||
SetLED: { userdata, red, green, blue in
|
||||
print("Set LED to RGB(\(red), \(green), \(blue))")
|
||||
// print("Set LED to RGB(\(red), \(green), \(blue))")
|
||||
return 0
|
||||
},
|
||||
SendEffect: { userdata, data, size in
|
||||
print("Effect sent with size \(size)")
|
||||
// print("Effect sent with size \(size)")
|
||||
return 0
|
||||
}
|
||||
)
|
||||
|
||||
instanceID = SDL_JoystickAttachVirtualEx(&joystickDesc)// SDL_JoystickAttachVirtual(SDL_JoystickType(SDL_JOYSTICK_TYPE_GAMECONTROLLER.rawValue), 6, 15, 1)
|
||||
if instanceID < 0 {
|
||||
print("Failed to create virtual joystick: \(String(cString: SDL_GetError()))")
|
||||
// print("Failed to create virtual joystick: \(String(cString: SDL_GetError()))")
|
||||
return
|
||||
}
|
||||
|
||||
// Open a game controller for the virtual joystick
|
||||
let joystick = SDL_JoystickFromInstanceID(instanceID)
|
||||
controller = SDL_GameControllerOpen(Int32(instanceID))
|
||||
|
||||
if controller == nil {
|
||||
print("Failed to create virtual controller: \(String(cString: SDL_GetError()))")
|
||||
// print("Failed to create virtual controller: \(String(cString: SDL_GetError()))")
|
||||
return
|
||||
}
|
||||
|
||||
if #available(iOS 16, *) {
|
||||
guard let gamepad = nativeController.extendedGamepad
|
||||
else { return }
|
||||
|
||||
setupButtonChangeListener(gamepad.buttonA, for: .A)
|
||||
setupButtonChangeListener(gamepad.buttonB, for: .B)
|
||||
setupButtonChangeListener(gamepad.buttonX, for: .X)
|
||||
setupButtonChangeListener(gamepad.buttonY, for: .Y)
|
||||
|
||||
setupButtonChangeListener(gamepad.buttonA, for: UserDefaults.standard.bool(forKey: "swapBandA") ? .B : .A)
|
||||
setupButtonChangeListener(gamepad.buttonB, for: UserDefaults.standard.bool(forKey: "swapBandA") ? .A : .B)
|
||||
setupButtonChangeListener(gamepad.buttonX, for: UserDefaults.standard.bool(forKey: "swapBandA") ? .Y : .X)
|
||||
setupButtonChangeListener(gamepad.buttonY, for: UserDefaults.standard.bool(forKey: "swapBandA") ? .X : .Y)
|
||||
|
||||
setupButtonChangeListener(gamepad.dpad.up, for: .dPadUp)
|
||||
setupButtonChangeListener(gamepad.dpad.down, for: .dPadDown)
|
||||
@ -141,7 +139,7 @@ class NativeController: Hashable {
|
||||
|
||||
func setupTriggerChangeListener(_ button: GCControllerButtonInput, for key: ThumbstickType) {
|
||||
button.valueChangedHandler = { [unowned self] _, value, pressed in
|
||||
// print("Value: \(value), Is pressed: \(pressed)")
|
||||
// // print("Value: \(value), Is pressed: \(pressed)")
|
||||
let axis: SDL_GameControllerAxis = (key == .left) ? SDL_CONTROLLER_AXIS_TRIGGERLEFT : SDL_CONTROLLER_AXIS_TRIGGERRIGHT
|
||||
let scaledValue = Sint16(value * 32767.0)
|
||||
updateAxisValue(value: scaledValue, forAxis: axis)
|
||||
@ -179,7 +177,7 @@ class NativeController: Hashable {
|
||||
try highFreqPlayer.start(atTime: 0.2)
|
||||
|
||||
} catch {
|
||||
print("Error creating haptic patterns: \(error)")
|
||||
// print("Error creating haptic patterns: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,7 +206,7 @@ class NativeController: Hashable {
|
||||
func setButtonState(_ state: Uint8, for button: VirtualControllerButton) {
|
||||
guard controller != nil else { return }
|
||||
|
||||
// print("Button: \(button.rawValue) {state: \(state)}")
|
||||
// // print("Button: \(button.rawValue) {state: \(state)}")
|
||||
if (button == .leftTrigger || button == .rightTrigger) && (state == 1 || state == 0) {
|
||||
let axis: SDL_GameControllerAxis = (button == .leftTrigger) ? SDL_CONTROLLER_AXIS_TRIGGERLEFT : SDL_CONTROLLER_AXIS_TRIGGERRIGHT
|
||||
let value: Int = (state == 1) ? 32767 : 0
|
||||
|
@ -41,41 +41,39 @@ class VirtualController {
|
||||
// Update joystick state here
|
||||
},
|
||||
SetPlayerIndex: { userdata, playerIndex in
|
||||
print("Player index set to \(playerIndex)")
|
||||
// print("Player index set to \(playerIndex)")
|
||||
},
|
||||
Rumble: { userdata, lowFreq, highFreq in
|
||||
print("Rumble with \(lowFreq), \(highFreq)")
|
||||
// print("Rumble with \(lowFreq), \(highFreq)")
|
||||
if UIDevice.current.userInterfaceIdiom == .phone {
|
||||
VirtualController.rumble(lowFreq: Float(lowFreq), highFreq: Float(highFreq))
|
||||
}
|
||||
return 0
|
||||
},
|
||||
RumbleTriggers: { userdata, leftRumble, rightRumble in
|
||||
print("Trigger rumble with \(leftRumble), \(rightRumble)")
|
||||
// print("Trigger rumble with \(leftRumble), \(rightRumble)")
|
||||
return 0
|
||||
},
|
||||
SetLED: { userdata, red, green, blue in
|
||||
print("Set LED to RGB(\(red), \(green), \(blue))")
|
||||
// print("Set LED to RGB(\(red), \(green), \(blue))")
|
||||
return 0
|
||||
},
|
||||
SendEffect: { userdata, data, size in
|
||||
print("Effect sent with size \(size)")
|
||||
// print("Effect sent with size \(size)")
|
||||
return 0
|
||||
}
|
||||
)
|
||||
|
||||
instanceID = SDL_JoystickAttachVirtualEx(&joystickDesc)// SDL_JoystickAttachVirtual(SDL_JoystickType(SDL_JOYSTICK_TYPE_GAMECONTROLLER.rawValue), 6, 15, 1)
|
||||
if instanceID < 0 {
|
||||
print("Failed to create virtual joystick: \(String(cString: SDL_GetError()))")
|
||||
// print("Failed to create virtual joystick: \(String(cString: SDL_GetError()))")
|
||||
return
|
||||
}
|
||||
|
||||
// Open a game controller for the virtual joystick
|
||||
let joystick = SDL_JoystickFromInstanceID(instanceID)
|
||||
controller = SDL_GameControllerOpen(Int32(instanceID))
|
||||
|
||||
if controller == nil {
|
||||
print("Failed to create virtual controller: \(String(cString: SDL_GetError()))")
|
||||
// print("Failed to create virtual controller: \(String(cString: SDL_GetError()))")
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -109,7 +107,7 @@ class VirtualController {
|
||||
}
|
||||
|
||||
guard let engine else {
|
||||
return print("Error creating haptic patterns: hapticEngine is nil")
|
||||
return // print("Error creating haptic patterns: hapticEngine is nil")
|
||||
}
|
||||
|
||||
let lowFreqPlayer = try engine.makePlayer(with: lowFreqPattern)
|
||||
@ -119,7 +117,7 @@ class VirtualController {
|
||||
try highFreqPlayer.start(atTime: 0)
|
||||
|
||||
} catch {
|
||||
print("Error creating haptic patterns: \(error)")
|
||||
// print("Error creating haptic patterns: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,10 +131,8 @@ class VirtualController {
|
||||
}
|
||||
|
||||
func thumbstickMoved(_ stick: ThumbstickType, x: Double, y: Double) {
|
||||
let scaleFactor = 32767.0 / 160
|
||||
|
||||
let scaledX = Int16(min(32767.0, max(-32768.0, x * scaleFactor)))
|
||||
let scaledY = Int16(min(32767.0, max(-32768.0, y * scaleFactor)))
|
||||
let scaledX = Int16(min(32767.0, max(-32768.0, x * 32767.0)))
|
||||
let scaledY = Int16(min(32767.0, max(-32768.0, y * 32767.0)))
|
||||
|
||||
if stick == .right {
|
||||
updateAxisValue(value: scaledX, forAxis: SDL_GameControllerAxis(SDL_CONTROLLER_AXIS_RIGHTX.rawValue))
|
||||
@ -150,7 +146,7 @@ class VirtualController {
|
||||
func setButtonState(_ state: Uint8, for button: VirtualControllerButton) {
|
||||
guard controller != nil else { return }
|
||||
|
||||
print("Button: \(button.rawValue) {state: \(state)}")
|
||||
// // print("Button: \(button.rawValue) {state: \(state)}")
|
||||
if (button == .leftTrigger || button == .rightTrigger) && (state == 1 || state == 0) {
|
||||
let axis: SDL_GameControllerAxis = (button == .leftTrigger) ? SDL_CONTROLLER_AXIS_TRIGGERLEFT : SDL_CONTROLLER_AXIS_TRIGGERRIGHT
|
||||
let value: Int = (state == 1) ? 32767 : 0
|
||||
@ -174,10 +170,10 @@ class VirtualController {
|
||||
}
|
||||
|
||||
enum VirtualControllerButton: Int {
|
||||
case B
|
||||
case A
|
||||
case Y
|
||||
case B
|
||||
case X
|
||||
case Y
|
||||
case back
|
||||
case guide
|
||||
case start
|
||||
@ -191,6 +187,24 @@ enum VirtualControllerButton: Int {
|
||||
case dPadRight
|
||||
case leftTrigger
|
||||
case rightTrigger
|
||||
|
||||
var isTrigger: Bool {
|
||||
switch self {
|
||||
case .leftTrigger, .rightTrigger, .leftShoulder, .rightShoulder:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var isSmall: Bool {
|
||||
switch self {
|
||||
case .back, .start, .guide:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum ThumbstickType: Int {
|
||||
|
@ -35,8 +35,8 @@ class MemoryUsageMonitor: ObservableObject {
|
||||
memoryUsage = taskInfo.phys_footprint
|
||||
}
|
||||
else {
|
||||
print("Error with task_info(): " +
|
||||
(String(cString: mach_error_string(result), encoding: String.Encoding.ascii) ?? "unknown error"))
|
||||
// print("Error with task_info(): " +
|
||||
// (String(cString: mach_error_string(result), encoding: String.Encoding.ascii) ?? "unknown error"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,7 @@ import Foundation
|
||||
|
||||
class MTLHud {
|
||||
|
||||
var canMetalHud: Bool {
|
||||
return openMetalDylib()
|
||||
}
|
||||
@Published var canMetalHud: Bool = false
|
||||
|
||||
var isEnabled: Bool {
|
||||
if let getenv = getenv("MTL_HUD_ENABLED") {
|
||||
@ -24,7 +22,17 @@ class MTLHud {
|
||||
static let shared = MTLHud()
|
||||
|
||||
private init() {
|
||||
openMetalDylib()
|
||||
let _ = openMetalDylib() // i'm fixing the warnings just because you said i suck at coding Autumn (propenchiefer,
|
||||
https://youtu.be/tc65SNOTMz4 7:23)
|
||||
if UserDefaults.standard.bool(forKey: "MTL_HUD_ENABLED") {
|
||||
enable()
|
||||
} else {
|
||||
disable()
|
||||
}
|
||||
}
|
||||
|
||||
func toggle() {
|
||||
// print(UserDefaults.standard.bool(forKey: "MTL_HUD_ENABLED"))
|
||||
if UserDefaults.standard.bool(forKey: "MTL_HUD_ENABLED") {
|
||||
enable()
|
||||
} else {
|
||||
@ -35,16 +43,15 @@ class MTLHud {
|
||||
func openMetalDylib() -> Bool {
|
||||
let path = "/usr/lib/libMTLHud.dylib"
|
||||
|
||||
// Load the dynamic library
|
||||
if dlopen(path, RTLD_NOW) != nil {
|
||||
// Library loaded successfully
|
||||
print("Library loaded from \(path)")
|
||||
// print("Library loaded from \(path)")
|
||||
canMetalHud = true
|
||||
return true
|
||||
} else {
|
||||
// Handle error
|
||||
if let error = String(validatingUTF8: dlerror()) {
|
||||
print("Error loading library: \(error)")
|
||||
// print("Error loading library: \(error)")
|
||||
}
|
||||
canMetalHud = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,93 @@ import GameController
|
||||
import MetalKit
|
||||
import Metal
|
||||
|
||||
class LogCapture {
|
||||
static let shared = LogCapture()
|
||||
|
||||
private var stdoutPipe: Pipe?
|
||||
private var stderrPipe: Pipe?
|
||||
private let originalStdout: Int32
|
||||
private let originalStderr: Int32
|
||||
|
||||
var capturedLogs: [String] = [] {
|
||||
didSet {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(name: .newLogCaptured, object: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private init() {
|
||||
originalStdout = dup(STDOUT_FILENO)
|
||||
originalStderr = dup(STDERR_FILENO)
|
||||
startCapturing()
|
||||
}
|
||||
|
||||
func startCapturing() {
|
||||
stdoutPipe = Pipe()
|
||||
stderrPipe = Pipe()
|
||||
|
||||
redirectOutput(to: stdoutPipe!, fileDescriptor: STDOUT_FILENO)
|
||||
redirectOutput(to: stderrPipe!, fileDescriptor: STDERR_FILENO)
|
||||
|
||||
setupReadabilityHandler(for: stdoutPipe!, isStdout: true)
|
||||
setupReadabilityHandler(for: stderrPipe!, isStdout: false)
|
||||
}
|
||||
|
||||
func stopCapturing() {
|
||||
dup2(originalStdout, STDOUT_FILENO)
|
||||
dup2(originalStderr, STDERR_FILENO)
|
||||
|
||||
stdoutPipe?.fileHandleForReading.readabilityHandler = nil
|
||||
stderrPipe?.fileHandleForReading.readabilityHandler = nil
|
||||
}
|
||||
|
||||
private func redirectOutput(to pipe: Pipe, fileDescriptor: Int32) {
|
||||
dup2(pipe.fileHandleForWriting.fileDescriptor, fileDescriptor)
|
||||
}
|
||||
|
||||
private func setupReadabilityHandler(for pipe: Pipe, isStdout: Bool) {
|
||||
pipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in
|
||||
let data = fileHandle.availableData
|
||||
let originalFD = isStdout ? self?.originalStdout : self?.originalStderr
|
||||
write(originalFD ?? STDOUT_FILENO, (data as NSData).bytes, data.count)
|
||||
|
||||
if let logString = String(data: data, encoding: .utf8),
|
||||
let cleanedLog = self?.cleanLog(logString), !cleanedLog.isEmpty {
|
||||
self?.capturedLogs.append(cleanedLog)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func cleanLog(_ raw: String) -> String? {
|
||||
let lines = raw.split(separator: "\n")
|
||||
let filteredLines = lines.filter { line in
|
||||
!line.contains("SwiftUI") &&
|
||||
!line.contains("ForEach") &&
|
||||
!line.contains("VStack") &&
|
||||
!line.contains("Invalid frame dimension (negative or non-finite).")
|
||||
}
|
||||
|
||||
let cleaned = filteredLines.map { line -> String in
|
||||
if let tabRange = line.range(of: "\t") {
|
||||
return line[tabRange.upperBound...].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
return line.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}.joined(separator: "\n")
|
||||
|
||||
return cleaned.isEmpty ? nil : cleaned.replacingOccurrences(of: "\n\n", with: "\n")
|
||||
}
|
||||
|
||||
deinit {
|
||||
stopCapturing()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Notification.Name {
|
||||
static let newLogCaptured = Notification.Name("newLogCaptured")
|
||||
}
|
||||
|
||||
struct Controller: Identifiable, Hashable {
|
||||
var id: String
|
||||
var name: String
|
||||
@ -31,13 +118,14 @@ struct iOSNav<Content: View>: View {
|
||||
}
|
||||
|
||||
|
||||
class Ryujinx {
|
||||
class Ryujinx : ObservableObject {
|
||||
private var isRunning = false
|
||||
|
||||
let virtualController = VirtualController()
|
||||
|
||||
@Published var controllerMap: [Controller] = []
|
||||
@Published var metalLayer: CAMetalLayer? = nil
|
||||
@Published var isPortrait = false
|
||||
@Published var firmwareversion = "0"
|
||||
@Published var emulationUIView: MeloMTKView? = nil
|
||||
@Published var config: Ryujinx.Configuration? = nil
|
||||
@ -45,6 +133,10 @@ class Ryujinx {
|
||||
|
||||
@Published var defMLContentSize: CGFloat?
|
||||
|
||||
var thread: Thread = Thread { }
|
||||
|
||||
@Published var jitenabled = false
|
||||
|
||||
var shouldMetal: Bool {
|
||||
metalLayer == nil
|
||||
}
|
||||
@ -145,7 +237,8 @@ class Ryujinx {
|
||||
|
||||
self.config = config
|
||||
|
||||
RunLoop.current.perform { [self] in
|
||||
|
||||
thread = Thread { [self] in
|
||||
|
||||
isRunning = true
|
||||
|
||||
@ -175,12 +268,99 @@ class Ryujinx {
|
||||
}
|
||||
} catch {
|
||||
self.isRunning = false
|
||||
Self.log("Emulation failed to start: \(error)")
|
||||
Thread.sleep(forTimeInterval: 0.3)
|
||||
let logs = LogCapture.shared.capturedLogs
|
||||
let parsedLogs = extractExceptionInfo(logs)
|
||||
if let parsedLogs {
|
||||
DispatchQueue.main.async {
|
||||
let result = Array(logs.suffix(from: parsedLogs.lineIndex))
|
||||
|
||||
LogCapture.shared.capturedLogs = Array(LogCapture.shared.capturedLogs.prefix(upTo: parsedLogs.lineIndex))
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd_HH-mm-ss"
|
||||
let currentDate = Date()
|
||||
let dateString = dateFormatter.string(from: currentDate)
|
||||
let path = URL.documentsDirectory.appendingPathComponent("StackTrace").appendingPathComponent("StackTrace-\(dateString).txt").path
|
||||
|
||||
self.saveArrayAsTextFile(strings: result, filePath: path)
|
||||
|
||||
|
||||
presentAlert(title: "MeloNX Crashed!", message: parsedLogs.exceptionType + ": " + parsedLogs.message) {
|
||||
|
||||
assert(true, parsedLogs.exceptionType)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
presentAlert(title: "MeloNX Crashed!", message: "Unknown Error") {
|
||||
assert(true, "Exception was not detected")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thread.qualityOfService = .userInteractive
|
||||
thread.name = "MeloNX"
|
||||
thread.start()
|
||||
}
|
||||
|
||||
func saveArrayAsTextFile(strings: [String], filePath: String) {
|
||||
let text = strings.joined(separator: "\n")
|
||||
|
||||
let path = URL.documentsDirectory.appendingPathComponent("StackTrace").path
|
||||
|
||||
do {
|
||||
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: false)
|
||||
} catch {
|
||||
|
||||
}
|
||||
|
||||
do {
|
||||
try text.write(to: URL(fileURLWithPath: filePath), atomically: true, encoding: .utf8)
|
||||
print("File saved successfully.")
|
||||
} catch {
|
||||
print("Error saving file: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
struct ExceptionInfo {
|
||||
let exceptionType: String
|
||||
let message: String
|
||||
let lineIndex: Int
|
||||
}
|
||||
|
||||
func extractExceptionInfo(_ logs: [String]) -> ExceptionInfo? {
|
||||
for i in (0..<logs.count).reversed() {
|
||||
let line = logs[i]
|
||||
let pattern = "([\\w\\.]+Exception): ([^\\s]+(?:\\s+[^\\s]+)*)"
|
||||
|
||||
guard let regex = try? NSRegularExpression(pattern: pattern, options: []),
|
||||
let match = regex.firstMatch(in: line, options: [], range: NSRange(location: 0, length: line.count)) else {
|
||||
continue
|
||||
}
|
||||
|
||||
// Extract exception type and message if pattern matches
|
||||
if let exceptionTypeRange = Range(match.range(at: 1), in: line),
|
||||
let messageRange = Range(match.range(at: 2), in: line) {
|
||||
|
||||
let exceptionType = String(line[exceptionTypeRange])
|
||||
|
||||
var message = String(line[messageRange])
|
||||
if let atIndex = message.range(of: "\\s+at\\s+", options: .regularExpression) {
|
||||
message = String(message[..<atIndex.lowerBound])
|
||||
}
|
||||
|
||||
message = message.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
return ExceptionInfo(exceptionType: exceptionType, message: message, lineIndex: i)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func stop() throws {
|
||||
guard isRunning else {
|
||||
throw RyujinxError.notRunning
|
||||
@ -191,7 +371,7 @@ class Ryujinx {
|
||||
self.emulationUIView = nil
|
||||
self.metalLayer = nil
|
||||
|
||||
stop_emulation()
|
||||
thread.cancel()
|
||||
}
|
||||
|
||||
var running: Bool {
|
||||
@ -209,7 +389,7 @@ class Ryujinx {
|
||||
do {
|
||||
try fileManager.createDirectory(at: romsDirectory, withIntermediateDirectories: true, attributes: nil)
|
||||
} catch {
|
||||
print("Failed to create roms directory: \(error)")
|
||||
// print("Failed to create roms directory: \(error)")
|
||||
}
|
||||
}
|
||||
var games: [Game] = []
|
||||
@ -234,13 +414,13 @@ class Ryujinx {
|
||||
|
||||
games.append(game)
|
||||
} catch {
|
||||
print(error)
|
||||
// print(error)
|
||||
}
|
||||
}
|
||||
|
||||
return games
|
||||
} catch {
|
||||
print("Error loading games from roms folder: \(error)")
|
||||
// print("Error loading games from roms folder: \(error)")
|
||||
return games
|
||||
}
|
||||
|
||||
@ -264,6 +444,24 @@ class Ryujinx {
|
||||
// We don't need this. Ryujinx should handle it fine :3
|
||||
// this also causes crashes in some games :3
|
||||
|
||||
var model = ""
|
||||
|
||||
var systemInfo = utsname()
|
||||
uname(&systemInfo)
|
||||
let machineMirror = Mirror(reflecting: systemInfo.machine)
|
||||
model = machineMirror.children.reduce("") { identifier, element in
|
||||
guard let value = element.value as? Int8, value != 0 else { return identifier }
|
||||
return identifier + String(UnicodeScalar(UInt8(value)))
|
||||
}
|
||||
|
||||
args.append(contentsOf: ["--device-model", model])
|
||||
|
||||
args.append(contentsOf: ["--device-display-name", UIDevice.modelName])
|
||||
|
||||
if checkAppEntitlement("com.apple.developer.kernel.increased-memory-limit") {
|
||||
args.append("--has-memory-entitlement")
|
||||
}
|
||||
|
||||
args.append(contentsOf: ["--system-language", config.language.rawValue])
|
||||
|
||||
args.append(contentsOf: ["--system-region", config.regioncode.rawValue])
|
||||
@ -360,18 +558,13 @@ class Ryujinx {
|
||||
}
|
||||
|
||||
func fetchFirmwareVersion() -> String {
|
||||
do {
|
||||
let firmwareVersionPointer = installed_firmware_version()
|
||||
if let pointer = firmwareVersionPointer {
|
||||
let firmwareVersion = String(cString: pointer)
|
||||
DispatchQueue.main.async {
|
||||
self.firmwareversion = firmwareVersion
|
||||
}
|
||||
return firmwareVersion
|
||||
let firmwareVersionPointer = installed_firmware_version()
|
||||
if let pointer = firmwareVersionPointer {
|
||||
let firmwareVersion = String(cString: pointer)
|
||||
DispatchQueue.main.async {
|
||||
self.firmwareversion = firmwareVersion
|
||||
}
|
||||
|
||||
} catch {
|
||||
print(error)
|
||||
return firmwareVersion
|
||||
}
|
||||
|
||||
return "0"
|
||||
@ -379,7 +572,7 @@ class Ryujinx {
|
||||
|
||||
func installFirmware(firmwarePath: String) {
|
||||
guard let cString = firmwarePath.cString(using: .utf8) else {
|
||||
print("Invalid firmware path")
|
||||
// print("Invalid firmware path")
|
||||
return
|
||||
}
|
||||
|
||||
@ -395,12 +588,12 @@ class Ryujinx {
|
||||
guard let titleIdCString = titleId.cString(using: .utf8),
|
||||
let pathCString = path.cString(using: .utf8)
|
||||
else {
|
||||
print("Invalid path")
|
||||
// print("Invalid path")
|
||||
return []
|
||||
}
|
||||
|
||||
let listPointer = get_dlc_nca_list(titleIdCString, pathCString)
|
||||
print("DLC parcing success: \(listPointer.success)")
|
||||
// print("DLC parcing success: \(listPointer.success)")
|
||||
guard listPointer.success else { return [] }
|
||||
|
||||
let list = Array(UnsafeBufferPointer(start: listPointer.items, count: Int(listPointer.size)))
|
||||
@ -452,7 +645,7 @@ class Ryujinx {
|
||||
let guid = generateGamepadId(joystickIndex: i)
|
||||
let name = String(cString: SDL_GameControllerName(controller))
|
||||
|
||||
print("Controller \(i): \(name), GUID: \(guid ?? "")")
|
||||
// print("Controller \(i): \(name), GUID: \(guid ?? "")")
|
||||
|
||||
guard let guid else {
|
||||
SDL_GameControllerClose(controller)
|
||||
@ -483,84 +676,163 @@ class Ryujinx {
|
||||
do {
|
||||
if fileManager.fileExists(atPath: registeredFolder) {
|
||||
try fileManager.removeItem(atPath: registeredFolder)
|
||||
print("Folder removed successfully.")
|
||||
// print("Folder removed successfully.")
|
||||
let version = fetchFirmwareVersion()
|
||||
|
||||
if version.isEmpty {
|
||||
self.firmwareversion = "0"
|
||||
} else {
|
||||
print("Firmware eeeeee \(version)")
|
||||
// print("Firmware eeeeee \(version)")
|
||||
}
|
||||
|
||||
} else {
|
||||
print("Folder does not exist.")
|
||||
// print("Folder does not exist.")
|
||||
}
|
||||
} catch {
|
||||
print("Error removing folder: \(error)")
|
||||
// print("Error removing folder: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func repeatuntilfindLayer() {
|
||||
Task { @MainActor in
|
||||
while self.metalLayer == nil {
|
||||
let layer = self.getMetalLayer(nil)
|
||||
|
||||
if layer != nil {
|
||||
self.metalLayer = layer
|
||||
break
|
||||
}
|
||||
|
||||
Thread.sleep(forTimeInterval: 0.1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@MainActor
|
||||
func getMetalLayer(_ window: OpaquePointer?) -> CAMetalLayer? {
|
||||
var window = window
|
||||
if window == nil {
|
||||
window = SDL_GetWindowFromID(1)
|
||||
}
|
||||
|
||||
var windowInfo = SDL_SysWMinfo()
|
||||
SDL_GetWindowWMInfo(window, &windowInfo)
|
||||
|
||||
|
||||
guard let uiWindow = windowInfo.info.uikit.window,
|
||||
let rootView = uiWindow.takeUnretainedValue().rootViewController?.view else {
|
||||
print("Unable to get root view")
|
||||
return nil
|
||||
}
|
||||
|
||||
func findMetalLayer(in view: UIView) -> CAMetalLayer? {
|
||||
if let metalLayer = view.layer as? CAMetalLayer {
|
||||
return metalLayer
|
||||
}
|
||||
|
||||
for subview in view.subviews {
|
||||
if let metalLayer = findMetalLayer(in: subview) {
|
||||
return metalLayer
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if let existingLayer = findMetalLayer(in: rootView) {
|
||||
print("Found Metal Layer")
|
||||
return existingLayer
|
||||
}
|
||||
print("found nothing")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
static func log(_ message: String) {
|
||||
print("[Ryujinx] \(message)")
|
||||
// print("[Ryujinx] \(message)")
|
||||
}
|
||||
|
||||
public func updateOrientation() -> Bool {
|
||||
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
||||
let window = windowScene.windows.first {
|
||||
return (window.bounds.size.height > window.bounds.size.width)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func ryuIsJITEnabled() {
|
||||
jitenabled = isJITEnabled()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public extension UIDevice {
|
||||
static let modelName: String = {
|
||||
var systemInfo = utsname()
|
||||
uname(&systemInfo)
|
||||
let machineMirror = Mirror(reflecting: systemInfo.machine)
|
||||
let identifier = machineMirror.children.reduce("") { identifier, element in
|
||||
guard let value = element.value as? Int8, value != 0 else { return identifier }
|
||||
return identifier + String(UnicodeScalar(UInt8(value)))
|
||||
}
|
||||
|
||||
func mapToDevice(identifier: String) -> String { // swiftlint:disable:this cyclomatic_complexity
|
||||
#if os(iOS)
|
||||
switch identifier {
|
||||
case "iPod5,1": return "iPod touch (5th generation)"
|
||||
case "iPod7,1": return "iPod touch (6th generation)"
|
||||
case "iPod9,1": return "iPod touch (7th generation)"
|
||||
case "iPhone3,1", "iPhone3,2", "iPhone3,3": return "iPhone 4"
|
||||
case "iPhone4,1": return "iPhone 4s"
|
||||
case "iPhone5,1", "iPhone5,2": return "iPhone 5"
|
||||
case "iPhone5,3", "iPhone5,4": return "iPhone 5c"
|
||||
case "iPhone6,1", "iPhone6,2": return "iPhone 5s"
|
||||
case "iPhone7,2": return "iPhone 6"
|
||||
case "iPhone7,1": return "iPhone 6 Plus"
|
||||
case "iPhone8,1": return "iPhone 6s"
|
||||
case "iPhone8,2": return "iPhone 6s Plus"
|
||||
case "iPhone9,1", "iPhone9,3": return "iPhone 7"
|
||||
case "iPhone9,2", "iPhone9,4": return "iPhone 7 Plus"
|
||||
case "iPhone10,1", "iPhone10,4": return "iPhone 8"
|
||||
case "iPhone10,2", "iPhone10,5": return "iPhone 8 Plus"
|
||||
case "iPhone10,3", "iPhone10,6": return "iPhone X"
|
||||
case "iPhone11,2": return "iPhone XS"
|
||||
case "iPhone11,4", "iPhone11,6": return "iPhone XS Max"
|
||||
case "iPhone11,8": return "iPhone XR"
|
||||
case "iPhone12,1": return "iPhone 11"
|
||||
case "iPhone12,3": return "iPhone 11 Pro"
|
||||
case "iPhone12,5": return "iPhone 11 Pro Max"
|
||||
case "iPhone13,1": return "iPhone 12 mini"
|
||||
case "iPhone13,2": return "iPhone 12"
|
||||
case "iPhone13,3": return "iPhone 12 Pro"
|
||||
case "iPhone13,4": return "iPhone 12 Pro Max"
|
||||
case "iPhone14,4": return "iPhone 13 mini"
|
||||
case "iPhone14,5": return "iPhone 13"
|
||||
case "iPhone14,2": return "iPhone 13 Pro"
|
||||
case "iPhone14,3": return "iPhone 13 Pro Max"
|
||||
case "iPhone14,7": return "iPhone 14"
|
||||
case "iPhone14,8": return "iPhone 14 Plus"
|
||||
case "iPhone15,2": return "iPhone 14 Pro"
|
||||
case "iPhone15,3": return "iPhone 14 Pro Max"
|
||||
case "iPhone15,4": return "iPhone 15"
|
||||
case "iPhone15,5": return "iPhone 15 Plus"
|
||||
case "iPhone16,1": return "iPhone 15 Pro"
|
||||
case "iPhone16,2": return "iPhone 15 Pro Max"
|
||||
case "iPhone17,3": return "iPhone 16"
|
||||
case "iPhone17,4": return "iPhone 16 Plus"
|
||||
case "iPhone17,1": return "iPhone 16 Pro"
|
||||
case "iPhone17,2": return "iPhone 16 Pro Max"
|
||||
case "iPhone17,5": return "iPhone 16e"
|
||||
case "iPhone8,4": return "iPhone SE"
|
||||
case "iPhone12,8": return "iPhone SE (2nd generation)"
|
||||
case "iPhone14,6": return "iPhone SE (3rd generation)"
|
||||
case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4": return "iPad 2"
|
||||
case "iPad3,1", "iPad3,2", "iPad3,3": return "iPad (3rd generation)"
|
||||
case "iPad3,4", "iPad3,5", "iPad3,6": return "iPad (4th generation)"
|
||||
case "iPad6,11", "iPad6,12": return "iPad (5th generation)"
|
||||
case "iPad7,5", "iPad7,6": return "iPad (6th generation)"
|
||||
case "iPad7,11", "iPad7,12": return "iPad (7th generation)"
|
||||
case "iPad11,6", "iPad11,7": return "iPad (8th generation)"
|
||||
case "iPad12,1", "iPad12,2": return "iPad (9th generation)"
|
||||
case "iPad13,18", "iPad13,19": return "iPad (10th generation)"
|
||||
case "iPad4,1", "iPad4,2", "iPad4,3": return "iPad Air"
|
||||
case "iPad5,3", "iPad5,4": return "iPad Air 2"
|
||||
case "iPad11,3", "iPad11,4": return "iPad Air (3rd generation)"
|
||||
case "iPad13,1", "iPad13,2": return "iPad Air (4th generation)"
|
||||
case "iPad13,16", "iPad13,17": return "iPad Air (5th generation)"
|
||||
case "iPad14,8", "iPad14,9": return "iPad Air (11-inch) (M2)"
|
||||
case "iPad14,10", "iPad14,11": return "iPad Air (13-inch) (M2)"
|
||||
case "iPad2,5", "iPad2,6", "iPad2,7": return "iPad mini"
|
||||
case "iPad4,4", "iPad4,5", "iPad4,6": return "iPad mini 2"
|
||||
case "iPad4,7", "iPad4,8", "iPad4,9": return "iPad mini 3"
|
||||
case "iPad5,1", "iPad5,2": return "iPad mini 4"
|
||||
case "iPad11,1", "iPad11,2": return "iPad mini (5th generation)"
|
||||
case "iPad14,1", "iPad14,2": return "iPad mini (6th generation)"
|
||||
case "iPad16,1", "iPad16,2": return "iPad mini (A17 Pro)"
|
||||
case "iPad6,3", "iPad6,4": return "iPad Pro (9.7-inch)"
|
||||
case "iPad7,3", "iPad7,4": return "iPad Pro (10.5-inch)"
|
||||
case "iPad8,1", "iPad8,2", "iPad8,3", "iPad8,4": return "iPad Pro (11-inch) (1st generation)"
|
||||
case "iPad8,9", "iPad8,10": return "iPad Pro (11-inch) (2nd generation)"
|
||||
case "iPad13,4", "iPad13,5", "iPad13,6", "iPad13,7": return "iPad Pro (11-inch) (3rd generation)"
|
||||
case "iPad14,3", "iPad14,4": return "iPad Pro (11-inch) (4th generation)"
|
||||
case "iPad16,3", "iPad16,4": return "iPad Pro (11-inch) (M4)"
|
||||
case "iPad6,7", "iPad6,8": return "iPad Pro (12.9-inch) (1st generation)"
|
||||
case "iPad7,1", "iPad7,2": return "iPad Pro (12.9-inch) (2nd generation)"
|
||||
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return "iPad Pro (12.9-inch) (3rd generation)"
|
||||
case "iPad8,11", "iPad8,12": return "iPad Pro (12.9-inch) (4th generation)"
|
||||
case "iPad13,8", "iPad13,9", "iPad13,10", "iPad13,11":return "iPad Pro (12.9-inch) (5th generation)"
|
||||
case "iPad14,5", "iPad14,6": return "iPad Pro (12.9-inch) (6th generation)"
|
||||
case "iPad16,5", "iPad16,6": return "iPad Pro (13-inch) (M4)"
|
||||
case "AppleTV5,3": return "Apple TV"
|
||||
case "AppleTV6,2": return "Apple TV 4K"
|
||||
case "AudioAccessory1,1": return "HomePod"
|
||||
case "AudioAccessory5,1": return "HomePod mini"
|
||||
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
|
||||
default: return identifier
|
||||
}
|
||||
#elseif os(tvOS)
|
||||
switch identifier {
|
||||
case "AppleTV5,3": return "Apple TV 4"
|
||||
case "AppleTV6,2", "AppleTV11,1", "AppleTV14,1": return "Apple TV 4K"
|
||||
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
|
||||
default: return identifier
|
||||
}
|
||||
#elseif os(visionOS)
|
||||
switch identifier {
|
||||
case "RealityDevice14,1": return "Apple Vision Pro"
|
||||
default: return identifier
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return mapToDevice(identifier: identifier)
|
||||
}()
|
||||
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ struct LaunchGameIntentDef: AppIntent {
|
||||
|
||||
let ryujinx = Ryujinx.shared.games
|
||||
|
||||
let name = findClosestGameName(input: gameName, games: ryujinx.flatMap(\.titleName))
|
||||
let name = findClosestGameName(input: gameName, games: ryujinx.compactMap(\.titleName))
|
||||
|
||||
let urlString = "melonx://game?name=\(name ?? gameName)"
|
||||
print(urlString)
|
||||
// print(urlString)
|
||||
if let url = URL(string: urlString) {
|
||||
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
||||
}
|
||||
|
@ -57,28 +57,21 @@ public struct Game: Identifiable, Equatable, Hashable {
|
||||
|
||||
gameTemp.icon = UIImage(data: imageData)
|
||||
} else {
|
||||
print("Invalid image size.")
|
||||
// print("Invalid image size.")
|
||||
}
|
||||
return gameTemp
|
||||
}
|
||||
|
||||
func createImage(from gameInfo: GameInfo) -> UIImage? {
|
||||
// Access the struct
|
||||
let gameInfoValue = gameInfo
|
||||
|
||||
// Get the image data
|
||||
let imageSize = Int(gameInfoValue.ImageSize)
|
||||
guard imageSize > 0, imageSize <= 1024 * 1024 else {
|
||||
print("Invalid image size.")
|
||||
// print("Invalid image size.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert the ImageData byte array to Swift's Data
|
||||
let imageData = Data(bytes: gameInfoValue.ImageData, count: imageSize)
|
||||
|
||||
// Create a UIImage (or NSImage on macOS)
|
||||
print(imageData)
|
||||
|
||||
return UIImage(data: imageData)
|
||||
}
|
||||
}
|
||||
|
38
src/MeloNX/MeloNX/App/Models/LatestVersionResponse.swift
Normal file
38
src/MeloNX/MeloNX/App/Models/LatestVersionResponse.swift
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// LatestVersionResponse.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by Bella on 12/03/2025.
|
||||
//
|
||||
|
||||
|
||||
struct LatestVersionResponse: Codable {
|
||||
let version_number: String
|
||||
let version_number_stripped: String
|
||||
let changelog: String
|
||||
let download_link: String
|
||||
|
||||
#if DEBUG
|
||||
static let example1 = LatestVersionResponse(
|
||||
version_number: "1.0.0",
|
||||
version_number_stripped: "100",
|
||||
changelog: """
|
||||
- Rewrite Display Code (SDL isn't used for display anymore)
|
||||
- Add New Onboarding / Setup
|
||||
- Better Performance
|
||||
- Remove "SDL Window" option in settings
|
||||
- Fix JIT Cache Regions
|
||||
- Fix how JIT is detected in Settings
|
||||
- Fix ABYX being swapped on controller.
|
||||
- Settings are now a config.json file
|
||||
- Fix Performance Overlay not showing when Virtual Controller is hidden
|
||||
- Add displaying logs when Loading or in-game
|
||||
- Fix Launching games from outside of the roms folder
|
||||
- Add Waiting for JIT popup
|
||||
- Fix spesific Games
|
||||
- Added Back Herobrine ("You were supposed to be the hero, Bryan")
|
||||
""",
|
||||
download_link: "https://example.com"
|
||||
)
|
||||
#endif
|
||||
}
|
@ -6,12 +6,11 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
// import SDL2
|
||||
import GameController
|
||||
import Darwin
|
||||
import UIKit
|
||||
import MetalKit
|
||||
// import SDL
|
||||
import CoreLocation
|
||||
|
||||
struct MoltenVKSettings: Codable, Hashable {
|
||||
let string: String
|
||||
@ -19,6 +18,8 @@ struct MoltenVKSettings: Codable, Hashable {
|
||||
}
|
||||
|
||||
struct ContentView: View {
|
||||
// MARK: - Properties
|
||||
|
||||
// Games
|
||||
@State private var game: Game?
|
||||
|
||||
@ -37,6 +38,7 @@ struct ContentView: View {
|
||||
|
||||
// JIT
|
||||
@AppStorage("jitStreamerEB") var jitStreamerEB: Bool = false
|
||||
@AppStorage("stikJIT") var stikJIT: Bool = false
|
||||
|
||||
// Other Configuration
|
||||
@State var isMK8: Bool = false
|
||||
@ -53,263 +55,255 @@ struct ContentView: View {
|
||||
private let animationDuration: Double = 1.0
|
||||
@State private var isAnimating = false
|
||||
@State var isLoading = true
|
||||
@State var jitNotEnabled = false
|
||||
@StateObject var ryujinx = Ryujinx.shared
|
||||
|
||||
// MARK: - SDL
|
||||
var sdlInitFlags: UInt32 = SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_VIDEO
|
||||
|
||||
// MARK: - Initialization
|
||||
init() {
|
||||
var defaultConfig = loadSettings()
|
||||
if defaultConfig == nil {
|
||||
saveSettings(config: .init(gamepath: ""))
|
||||
|
||||
defaultConfig = loadSettings()
|
||||
}
|
||||
|
||||
|
||||
_config = State(initialValue: defaultConfig!)
|
||||
|
||||
let defaultSettings: [MoltenVKSettings] = [ // Default MoltenVK Settings.
|
||||
let defaultSettings: [MoltenVKSettings] = [
|
||||
MoltenVKSettings(string: "MVK_USE_METAL_PRIVATE_API", value: "1"),
|
||||
MoltenVKSettings(string: "MVK_CONFIG_USE_METAL_PRIVATE_API", value: "1"),
|
||||
MoltenVKSettings(string: "MVK_DEBUG", value: "0"),
|
||||
MoltenVKSettings(string: "MVK_CONFIG_LOG_LEVEL", value: "0"),
|
||||
MoltenVKSettings(string: "MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS", value: "1"),
|
||||
// MoltenVKSettings(string: "MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS", value: "0"),
|
||||
// Uses more ram but makes performance higher, may add an option in settings to change or enable / disable this value (default 64)
|
||||
MoltenVKSettings(string: "MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS", value: "0"),
|
||||
MoltenVKSettings(string: "MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS", value: "0"),
|
||||
MoltenVKSettings(string: "MVK_CONFIG_MAX_ACTIVE_METAL_COMMAND_BUFFERS_PER_QUEUE", value: "512"),
|
||||
]
|
||||
|
||||
_settings = State(initialValue: defaultSettings)
|
||||
|
||||
// print(SDL_CONTROLLER_BUTTON_LEFTSTICK.rawValue)
|
||||
|
||||
initializeSDL()
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
var body: some View {
|
||||
if game != nil, !jitNotEnabled {
|
||||
// This is when the game starts to stop the animation
|
||||
ZStack {
|
||||
if #available(iOS 16, *) {
|
||||
EmulationView(startgame: $game)
|
||||
.persistentSystemOverlays(.hidden)
|
||||
} else {
|
||||
EmulationView(startgame: $game)
|
||||
}
|
||||
|
||||
if isLoading {
|
||||
ZStack {
|
||||
Color.black
|
||||
.opacity(0.8)
|
||||
emulationView
|
||||
.ignoresSafeArea(.all)
|
||||
}
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
.ignoresSafeArea(.all)
|
||||
}
|
||||
}
|
||||
} else if game != nil, ignoreJIT {
|
||||
ZStack {
|
||||
if #available(iOS 16, *) {
|
||||
EmulationView(startgame: $game)
|
||||
.persistentSystemOverlays(.hidden)
|
||||
} else {
|
||||
EmulationView(startgame: $game)
|
||||
}
|
||||
|
||||
if isLoading {
|
||||
ZStack {
|
||||
Color.black
|
||||
.opacity(0.8)
|
||||
emulationView
|
||||
.ignoresSafeArea(.all)
|
||||
}
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
.ignoresSafeArea(.all)
|
||||
}
|
||||
}
|
||||
} else if game != nil {
|
||||
Text("")
|
||||
.sheet(isPresented: $jitNotEnabled) {
|
||||
JITPopover() {
|
||||
jitNotEnabled = false
|
||||
}
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
if game != nil && (ryujinx.jitenabled || ignoreJIT) {
|
||||
gameView
|
||||
} else if game != nil && !ryujinx.jitenabled {
|
||||
jitErrorView
|
||||
} else {
|
||||
// This is the main menu view that includes the Settings and the Game Selector
|
||||
mainMenuView
|
||||
.onAppear() {
|
||||
quits = false
|
||||
|
||||
loadSettings()
|
||||
|
||||
isLoading = true
|
||||
|
||||
initControllerObservers() // This initializes the Controller Observers that refreshes the controller list when a new controller connecvts.
|
||||
}
|
||||
.onOpenURL() { url in
|
||||
if let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
|
||||
components.host == "game" {
|
||||
if let text = components.queryItems?.first(where: { $0.name == "id" })?.value {
|
||||
|
||||
game = Ryujinx.shared.games.first(where: { $0.titleId == text })
|
||||
} else if let text = components.queryItems?.first(where: { $0.name == "name" })?.value {
|
||||
game = Ryujinx.shared.games.first(where: { $0.titleName == text })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - View Components
|
||||
|
||||
private var gameView: some View {
|
||||
ZStack {
|
||||
if #available(iOS 16, *) {
|
||||
EmulationView(startgame: $game)
|
||||
.persistentSystemOverlays(.hidden)
|
||||
} else {
|
||||
EmulationView(startgame: $game)
|
||||
}
|
||||
|
||||
if isLoading {
|
||||
ZStack {
|
||||
Color.black.opacity(0.8)
|
||||
emulationView.ignoresSafeArea(.all)
|
||||
}
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
.ignoresSafeArea(.all)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var jitErrorView: some View {
|
||||
Text("")
|
||||
.fullScreenCover(isPresented:Binding(
|
||||
get: { !ryujinx.jitenabled },
|
||||
set: { newValue in
|
||||
ryujinx.jitenabled = newValue
|
||||
|
||||
ryujinx.ryuIsJITEnabled()
|
||||
})
|
||||
) {
|
||||
JITPopover() {
|
||||
ryujinx.jitenabled = false
|
||||
}
|
||||
// .interactiveDismissDisabled()
|
||||
}
|
||||
}
|
||||
|
||||
private var mainMenuView: some View {
|
||||
MainTabView(
|
||||
startemu: $game,
|
||||
config: $config,
|
||||
MVKconfig: $settings,
|
||||
controllersList: $controllersList,
|
||||
currentControllers: $currentControllers,
|
||||
onscreencontroller: $onscreencontroller
|
||||
)
|
||||
.onAppear {
|
||||
quits = false
|
||||
let _ = loadSettings()
|
||||
isLoading = true
|
||||
|
||||
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
|
||||
refreshControllersList()
|
||||
}
|
||||
|
||||
|
||||
// print(MTLHud.shared.isEnabled)
|
||||
|
||||
initControllerObservers()
|
||||
|
||||
Air.play(AnyView(
|
||||
ControllerListView(game: $game)
|
||||
))
|
||||
|
||||
checkJitStatus()
|
||||
}
|
||||
.onOpenURL { url in
|
||||
handleDeepLink(url)
|
||||
}
|
||||
}
|
||||
|
||||
private var emulationView: some View {
|
||||
GeometryReader { screenGeometry in
|
||||
ZStack {
|
||||
gameLoadingContent(screenGeometry: screenGeometry)
|
||||
|
||||
HStack{
|
||||
|
||||
VStack {
|
||||
if showlogsloading {
|
||||
LogFileView(isfps: true)
|
||||
.frame(alignment: .topLeading)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
|
||||
private func gameLoadingContent(screenGeometry: GeometryProxy) -> some View {
|
||||
HStack(spacing: screenGeometry.size.width * 0.04) {
|
||||
if let icon = game?.icon {
|
||||
Image(uiImage: icon)
|
||||
.resizable()
|
||||
.frame(
|
||||
width: min(screenGeometry.size.width * 0.25, 250),
|
||||
height: min(screenGeometry.size.width * 0.25, 250)
|
||||
)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 16))
|
||||
.shadow(color: .black.opacity(0.5), radius: 10, x: 0, y: 5)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: screenGeometry.size.height * 0.015) {
|
||||
Text("Loading \(game?.titleName ?? "Game")")
|
||||
.font(.system(size: min(screenGeometry.size.width * 0.04, 32)))
|
||||
.foregroundColor(.white)
|
||||
|
||||
loadingProgressBar(screenGeometry: screenGeometry)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, screenGeometry.size.width * 0.06)
|
||||
.padding(.vertical, screenGeometry.size.height * 0.05)
|
||||
.position(
|
||||
x: screenGeometry.size.width / 2,
|
||||
y: screenGeometry.size.height * 0.5
|
||||
)
|
||||
}
|
||||
|
||||
private func loadingProgressBar(screenGeometry: GeometryProxy) -> some View {
|
||||
GeometryReader { geometry in
|
||||
let containerWidth = min(screenGeometry.size.width * 0.35, 350)
|
||||
|
||||
ZStack(alignment: .leading) {
|
||||
Rectangle()
|
||||
.cornerRadius(10)
|
||||
.frame(width: containerWidth, height: min(screenGeometry.size.height * 0.015, 12))
|
||||
.foregroundColor(.gray.opacity(0.3))
|
||||
.shadow(color: .black.opacity(0.2), radius: 4, x: 0, y: 2)
|
||||
|
||||
Rectangle()
|
||||
.cornerRadius(10)
|
||||
.frame(width: clumpWidth, height: min(screenGeometry.size.height * 0.015, 12))
|
||||
.foregroundColor(.blue)
|
||||
.shadow(color: .blue.opacity(0.5), radius: 4, x: 0, y: 2)
|
||||
.offset(x: isAnimating ? containerWidth : -clumpWidth)
|
||||
.animation(
|
||||
Animation.linear(duration: 1.0)
|
||||
.repeatForever(autoreverses: false),
|
||||
value: isAnimating
|
||||
)
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: 16))
|
||||
.onAppear {
|
||||
isAnimating = true
|
||||
setupEmulation()
|
||||
|
||||
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
|
||||
if get_current_fps() != 0 {
|
||||
withAnimation {
|
||||
isLoading = false
|
||||
isAnimating = false
|
||||
}
|
||||
timer.invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: min(screenGeometry.size.height * 0.015, 12))
|
||||
.frame(width: min(screenGeometry.size.width * 0.35, 350))
|
||||
}
|
||||
|
||||
private func initializeSDL() {
|
||||
setMoltenVKSettings()
|
||||
SDL_SetMainReady()
|
||||
SDL_iPhoneSetEventPump(SDL_TRUE)
|
||||
SDL_Init(sdlInitFlags)
|
||||
initialize()
|
||||
}
|
||||
|
||||
private func initControllerObservers() {
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: .GCControllerDidConnect,
|
||||
object: nil,
|
||||
queue: .main) { notification in
|
||||
if let controller = notification.object as? GCController {
|
||||
print("Controller connected: \(controller.productCategory)")
|
||||
nativeControllers[controller] = .init(controller)
|
||||
refreshControllersList()
|
||||
}
|
||||
queue: .main
|
||||
) { notification in
|
||||
if let controller = notification.object as? GCController {
|
||||
// print("Controller connected: \(controller.productCategory)")
|
||||
nativeControllers[controller] = .init(controller)
|
||||
refreshControllersList()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: .GCControllerDidDisconnect,
|
||||
object: nil,
|
||||
queue: .main) { notification in
|
||||
if let controller = notification.object as? GCController {
|
||||
print("Controller disconnected: \(controller.productCategory)")
|
||||
nativeControllers[controller]?.cleanup()
|
||||
nativeControllers[controller] = nil
|
||||
refreshControllersList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - View Components
|
||||
private var emulationView: some View {
|
||||
GeometryReader { screenGeometry in
|
||||
ZStack {
|
||||
HStack(spacing: screenGeometry.size.width * 0.04) {
|
||||
if let icon = game?.icon {
|
||||
Image(uiImage: icon)
|
||||
.resizable()
|
||||
.frame(
|
||||
width: min(screenGeometry.size.width * 0.25, 250),
|
||||
height: min(screenGeometry.size.width * 0.25, 250)
|
||||
)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 16))
|
||||
.shadow(color: .black.opacity(0.5), radius: 10, x: 0, y: 5)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: screenGeometry.size.height * 0.015) {
|
||||
Text("Loading \(game?.titleName ?? "Game")")
|
||||
.font(.system(size: min(screenGeometry.size.width * 0.04, 32)))
|
||||
.foregroundColor(.white)
|
||||
|
||||
GeometryReader { geometry in
|
||||
let containerWidth = min(screenGeometry.size.width * 0.35, 350)
|
||||
|
||||
ZStack(alignment: .leading) {
|
||||
Rectangle()
|
||||
.cornerRadius(10)
|
||||
.frame(width: containerWidth, height: min(screenGeometry.size.height * 0.015, 12))
|
||||
.foregroundColor(.gray.opacity(0.3))
|
||||
.shadow(color: .black.opacity(0.2), radius: 4, x: 0, y: 2)
|
||||
|
||||
Rectangle()
|
||||
.cornerRadius(10)
|
||||
.frame(width: clumpWidth, height: min(screenGeometry.size.height * 0.015, 12))
|
||||
.foregroundColor(.blue)
|
||||
.shadow(color: .blue.opacity(0.5), radius: 4, x: 0, y: 2)
|
||||
.offset(x: isAnimating ? containerWidth : -clumpWidth)
|
||||
.animation(
|
||||
Animation.linear(duration: 1.0)
|
||||
.repeatForever(autoreverses: false),
|
||||
value: isAnimating
|
||||
)
|
||||
}
|
||||
.clipShape(RoundedRectangle(cornerRadius: 16))
|
||||
.onAppear {
|
||||
isAnimating = true
|
||||
|
||||
setupEmulation()
|
||||
|
||||
|
||||
Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
|
||||
if get_current_fps() != 0 {
|
||||
withAnimation {
|
||||
isLoading = false
|
||||
|
||||
isAnimating = false
|
||||
}
|
||||
|
||||
|
||||
|
||||
timer.invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: min(screenGeometry.size.height * 0.015, 12))
|
||||
.frame(width: min(screenGeometry.size.width * 0.35, 350))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, screenGeometry.size.width * 0.06)
|
||||
.padding(.vertical, screenGeometry.size.height * 0.05)
|
||||
.position(
|
||||
x: screenGeometry.size.width / 2,
|
||||
y: screenGeometry.size.height * 0.5
|
||||
)
|
||||
}
|
||||
|
||||
if showlogsloading {
|
||||
LogFileView(isfps: true)
|
||||
.frame(alignment: .topLeading)
|
||||
queue: .main
|
||||
) { notification in
|
||||
if let controller = notification.object as? GCController {
|
||||
// print("Controller disconnected: \(controller.productCategory)")
|
||||
nativeControllers[controller]?.cleanup()
|
||||
nativeControllers[controller] = nil
|
||||
refreshControllersList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var mainMenuView: some View {
|
||||
MainTabView(startemu: $game, config: $config, MVKconfig: $settings, controllersList: $controllersList, currentControllers: $currentControllers, onscreencontroller: $onscreencontroller)
|
||||
.onAppear() {
|
||||
Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { timer in
|
||||
refreshControllersList()
|
||||
}
|
||||
|
||||
Air.play(AnyView(
|
||||
VStack {
|
||||
Image(systemName: "gamecontroller")
|
||||
.font(.system(size: 300))
|
||||
.foregroundColor(.gray)
|
||||
.padding(.bottom, 10)
|
||||
|
||||
Text("Select Game")
|
||||
.font(.system(size: 150))
|
||||
.bold()
|
||||
}
|
||||
))
|
||||
|
||||
jitNotEnabled = !isJITEnabled()
|
||||
if jitNotEnabled {
|
||||
useTrollStore ? askForJIT() : jitStreamerEB ? enableJITEB() : print("no JIT")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
var SdlInitFlags: uint = SDL_INIT_EVENTS | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_VIDEO; // Initialises SDL2 for Events, Game Controller, Joystick, Audio and Video.
|
||||
private func initializeSDL() {
|
||||
setMoltenVKSettings()
|
||||
SDL_SetMainReady() // Sets SDL Ready
|
||||
SDL_iPhoneSetEventPump(SDL_TRUE) // Set iOS Event Pump to true
|
||||
SDL_Init(SdlInitFlags) // Initialises SDL2
|
||||
initialize()
|
||||
}
|
||||
|
||||
private func setupEmulation() {
|
||||
refreshControllersList()
|
||||
|
||||
isVCA = (currentControllers.first(where: { $0 == onscreencontroller }) != nil)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
@ -318,67 +312,114 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
private func refreshControllersList() {
|
||||
controllersList = Ryujinx.shared.getConnectedControllers()
|
||||
controllersList = ryujinx.getConnectedControllers()
|
||||
|
||||
if let onscreen = controllersList.first(where: { $0.name == Ryujinx.shared.virtualController.controllername }) {
|
||||
if let onscreen = controllersList.first(where: { $0.name == ryujinx.virtualController.controllername }) {
|
||||
self.onscreencontroller = onscreen
|
||||
}
|
||||
|
||||
controllersList.removeAll(where: { $0.id == "0" || (!$0.name.starts(with: "GC - ") && $0 != onscreencontroller) })
|
||||
controllersList.mutableForEach { $0.name = $0.name.replacingOccurrences(of: "GC - ", with: "") }
|
||||
|
||||
currentControllers = []
|
||||
|
||||
if controllersList.count == 1 {
|
||||
let controller = controllersList[0]
|
||||
currentControllers.append(controller)
|
||||
} else if (controllersList.count - 1) >= 1 {
|
||||
for controller in controllersList {
|
||||
if controller.id != onscreencontroller.id && !currentControllers.contains(where: { $0.id == controller.id }) {
|
||||
currentControllers.append(controller)
|
||||
if !currentControllers.isEmpty, !(currentControllers.count == 1) {
|
||||
var currentController: [Controller] = []
|
||||
|
||||
if currentController.count == 1 {
|
||||
currentController.append(controllersList[0])
|
||||
} else if (controllersList.count - 1) >= 1 {
|
||||
for controller in controllersList {
|
||||
if controller.id != onscreencontroller.id && !currentControllers.contains(where: { $0.id == controller.id }) {
|
||||
currentController.append(controller)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if currentController == currentControllers {
|
||||
currentControllers = []
|
||||
currentControllers = currentController
|
||||
}
|
||||
} else {
|
||||
currentControllers = []
|
||||
|
||||
if controllersList.count == 1 {
|
||||
currentControllers.append(controllersList[0])
|
||||
} else if (controllersList.count - 1) >= 1 {
|
||||
for controller in controllersList {
|
||||
if controller.id != onscreencontroller.id && !currentControllers.contains(where: { $0.id == controller.id }) {
|
||||
currentControllers.append(controller)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private func start(displayid: UInt32) {
|
||||
guard let game else { return }
|
||||
|
||||
config.gamepath = game.fileURL.path
|
||||
config.inputids = Array(Set(currentControllers.map(\.id)))
|
||||
|
||||
if mVKPreFillBuffer {
|
||||
let setting = MoltenVKSettings(string: "MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS", value: "2")
|
||||
setenv(setting.string, setting.value, 1)
|
||||
}
|
||||
|
||||
if syncqsubmits {
|
||||
let setting = MoltenVKSettings(string: "MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS", value: "2")
|
||||
setenv(setting.string, setting.value, 1)
|
||||
}
|
||||
configureEnvironmentVariables()
|
||||
|
||||
if config.inputids.isEmpty {
|
||||
config.inputids.append("0")
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
try Ryujinx.shared.start(with: config)
|
||||
try ryujinx.start(with: config)
|
||||
} catch {
|
||||
print("Error: \(error.localizedDescription)")
|
||||
// print("Error: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
private func configureEnvironmentVariables() {
|
||||
if mVKPreFillBuffer {
|
||||
mVKPreFillBuffer = false
|
||||
// setenv("MVK_CONFIG_PREFILL_METAL_COMMAND_BUFFERS", "2", 1)
|
||||
}
|
||||
|
||||
if syncqsubmits {
|
||||
setenv("MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS", "1", 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Sets MoltenVK Environment Variables
|
||||
private func setMoltenVKSettings() {
|
||||
settings.forEach { setting in
|
||||
setenv(setting.string, setting.value, 1)
|
||||
}
|
||||
}
|
||||
|
||||
private func checkJitStatus() {
|
||||
ryujinx.ryuIsJITEnabled()
|
||||
if jitStreamerEB {
|
||||
jitStreamerEB = false // byee jitstreamer eb
|
||||
}
|
||||
if !ryujinx.jitenabled {
|
||||
if useTrollStore {
|
||||
askForJIT()
|
||||
} else if stikJIT {
|
||||
enableJITStik()
|
||||
} else if jitStreamerEB {
|
||||
enableJITEB()
|
||||
} else {
|
||||
// print("no JIT")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleDeepLink(_ url: URL) {
|
||||
if let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
|
||||
components.host == "game" {
|
||||
DispatchQueue.main.async {
|
||||
if let text = components.queryItems?.first(where: { $0.name == "id" })?.value {
|
||||
game = ryujinx.games.first(where: { $0.titleId == text })
|
||||
} else if let text = components.queryItems?.first(where: { $0.name == "name" })?.value {
|
||||
game = ryujinx.games.first(where: { $0.titleName == text })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Array {
|
||||
@ -388,3 +429,136 @@ extension Array {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LocationManager: NSObject, CLLocationManagerDelegate {
|
||||
|
||||
private var locationManager: CLLocationManager
|
||||
|
||||
static let sharedInstance = LocationManager()
|
||||
|
||||
private override init() {
|
||||
locationManager = CLLocationManager()
|
||||
super.init()
|
||||
locationManager.delegate = self
|
||||
locationManager.desiredAccuracy = kCLLocationAccuracyBest
|
||||
locationManager.pausesLocationUpdatesAutomatically = false
|
||||
}
|
||||
|
||||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
|
||||
// print("wow")
|
||||
}
|
||||
|
||||
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
|
||||
print("Location manager failed with: \(error)")
|
||||
}
|
||||
|
||||
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
||||
if manager.authorizationStatus == .denied {
|
||||
print("Location services are disabled in settings.")
|
||||
} else {
|
||||
startUpdatingLocation()
|
||||
}
|
||||
}
|
||||
|
||||
func stop() {
|
||||
if UserDefaults.standard.bool(forKey: "location-enabled") {
|
||||
locationManager.stopUpdatingLocation()
|
||||
}
|
||||
}
|
||||
|
||||
func startUpdatingLocation() {
|
||||
if UserDefaults.standard.bool(forKey: "location-enabled") {
|
||||
locationManager.requestAlwaysAuthorization()
|
||||
locationManager.allowsBackgroundLocationUpdates = true
|
||||
locationManager.startUpdatingLocation()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct ControllerListView: View {
|
||||
@State private var selectedIndex = 0
|
||||
@Binding var game: Game?
|
||||
@ObservedObject private var ryujinx = Ryujinx.shared
|
||||
|
||||
var body: some View {
|
||||
List(ryujinx.games.indices, id: \.self) { index in
|
||||
let game = ryujinx.games[index]
|
||||
|
||||
HStack(spacing: 16) {
|
||||
// Game Icon
|
||||
Group {
|
||||
if let icon = game.icon {
|
||||
Image(uiImage: icon)
|
||||
.resizable()
|
||||
.aspectRatio(contentMode: .fill)
|
||||
} else {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
Image(systemName: "gamecontroller.fill")
|
||||
.font(.system(size: 24))
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: 55, height: 55)
|
||||
.cornerRadius(10)
|
||||
|
||||
// Game Info
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(game.titleName)
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
.foregroundColor(.primary)
|
||||
|
||||
HStack(spacing: 4) {
|
||||
Text(game.developer)
|
||||
|
||||
if !game.version.isEmpty && game.version != "0" {
|
||||
Text("•")
|
||||
Text("v\(game.version)")
|
||||
}
|
||||
}
|
||||
.font(.system(size: 14))
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.background(selectedIndex == index ? Color.blue.opacity(0.3) : .clear)
|
||||
}
|
||||
.onAppear(perform: setupControllerObservers)
|
||||
}
|
||||
|
||||
private func setupControllerObservers() {
|
||||
let dpadHandler: GCControllerDirectionPadValueChangedHandler = { _, _, yValue in
|
||||
if yValue == 1.0 {
|
||||
selectedIndex = max(0, selectedIndex - 1)
|
||||
} else if yValue == -1.0 {
|
||||
selectedIndex = min(ryujinx.games.count - 1, selectedIndex + 1)
|
||||
}
|
||||
}
|
||||
|
||||
for controller in GCController.controllers() {
|
||||
print("Controller connected: \(controller.vendorName ?? "Unknown")")
|
||||
controller.playerIndex = .index1
|
||||
|
||||
controller.microGamepad?.dpad.valueChangedHandler = dpadHandler
|
||||
controller.extendedGamepad?.dpad.valueChangedHandler = dpadHandler
|
||||
|
||||
controller.extendedGamepad?.buttonA.pressedChangedHandler = { _, _, pressed in
|
||||
if pressed {
|
||||
print("A button pressed")
|
||||
game = ryujinx.games[selectedIndex]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(
|
||||
forName: .GCControllerDidConnect,
|
||||
object: nil,
|
||||
queue: .main
|
||||
) { _ in
|
||||
setupControllerObservers()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,105 +7,172 @@
|
||||
|
||||
import SwiftUI
|
||||
import GameController
|
||||
import SwiftUIJoystick
|
||||
import CoreMotion
|
||||
|
||||
struct ControllerView: View {
|
||||
// MARK: - Properties
|
||||
@AppStorage("On-ScreenControllerScale") private var controllerScale: Double = 1.0
|
||||
@AppStorage("stick-button") private var stickButton = false
|
||||
@State private var isPortrait = true
|
||||
@State var hideDpad = false
|
||||
@State var hideABXY = false
|
||||
@Environment(\.verticalSizeClass) var verticalSizeClass
|
||||
|
||||
|
||||
// MARK: - Body
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
if geometry.size.height > geometry.size.width && UIDevice.current.userInterfaceIdiom != .pad {
|
||||
VStack {
|
||||
|
||||
Spacer()
|
||||
VStack {
|
||||
HStack {
|
||||
VStack {
|
||||
ShoulderButtonsViewLeft()
|
||||
ZStack {
|
||||
Joystick()
|
||||
DPadView()
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
VStack {
|
||||
ShoulderButtonsViewRight()
|
||||
ZStack {
|
||||
Joystick(iscool: true) // hope this works
|
||||
ABXYView()
|
||||
}
|
||||
Group {
|
||||
let isPad = UIDevice.current.userInterfaceIdiom == .pad
|
||||
|
||||
if isPortrait && !isPad {
|
||||
portraitLayout
|
||||
} else {
|
||||
landscapeLayout
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.onChange(of: verticalSizeClass) { _ in
|
||||
updateOrientation()
|
||||
}
|
||||
.onAppear(perform: updateOrientation)
|
||||
}
|
||||
|
||||
// MARK: - Layouts
|
||||
private var portraitLayout: some View {
|
||||
VStack {
|
||||
Spacer()
|
||||
VStack(spacing: 20) {
|
||||
HStack(spacing: 30) {
|
||||
VStack(spacing: 15) {
|
||||
ShoulderButtonsViewLeft()
|
||||
ZStack {
|
||||
JoystickController(showBackground: $hideDpad)
|
||||
if !hideDpad {
|
||||
DPadView()
|
||||
.animation(.easeInOut(duration: 0.2), value: hideDpad)
|
||||
}
|
||||
}
|
||||
|
||||
HStack {
|
||||
ButtonView(button: .start) // Adding the + button
|
||||
.padding(.horizontal, 40)
|
||||
ButtonView(button: .back) // Adding the - button
|
||||
.padding(.horizontal, 40)
|
||||
}
|
||||
|
||||
VStack(spacing: 15) {
|
||||
ShoulderButtonsViewRight()
|
||||
ZStack {
|
||||
JoystickController(iscool: true, showBackground: $hideABXY)
|
||||
if !hideABXY {
|
||||
ABXYView()
|
||||
.animation(.easeInOut(duration: 0.2), value: hideABXY)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// could be landscape
|
||||
VStack {
|
||||
|
||||
Spacer()
|
||||
VStack {
|
||||
HStack {
|
||||
|
||||
// gotta fuckin add + and - now
|
||||
VStack {
|
||||
ShoulderButtonsViewLeft()
|
||||
ZStack {
|
||||
Joystick()
|
||||
DPadView()
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
// Spacer()
|
||||
VStack {
|
||||
// Spacer()
|
||||
ButtonView(button: .back) // Adding the - button
|
||||
}
|
||||
Spacer()
|
||||
VStack {
|
||||
// Spacer()
|
||||
ButtonView(button: .start) // Adding the + button
|
||||
}
|
||||
// Spacer()
|
||||
}
|
||||
VStack {
|
||||
ShoulderButtonsViewRight()
|
||||
ZStack {
|
||||
Joystick(iscool: true) // hope this work s
|
||||
ABXYView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HStack(spacing: 60) {
|
||||
HStack {
|
||||
ButtonView(button: .leftStick)
|
||||
.padding()
|
||||
ButtonView(button: .start)
|
||||
}
|
||||
|
||||
HStack {
|
||||
ButtonView(button: .back)
|
||||
ButtonView(button: .rightStick)
|
||||
.padding()
|
||||
}
|
||||
// .padding(.bottom, geometry.size.height / 11) // also extremally broken (
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
private var landscapeLayout: some View {
|
||||
VStack {
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
VStack(spacing: 20) {
|
||||
ShoulderButtonsViewLeft()
|
||||
ZStack {
|
||||
JoystickController(showBackground: $hideDpad)
|
||||
if !hideDpad {
|
||||
DPadView()
|
||||
.animation(.easeInOut(duration: 0.2), value: hideDpad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
centerButtons
|
||||
|
||||
Spacer()
|
||||
|
||||
VStack(spacing: 20) {
|
||||
ShoulderButtonsViewRight()
|
||||
ZStack {
|
||||
JoystickController(iscool: true, showBackground: $hideABXY)
|
||||
if !hideABXY {
|
||||
ABXYView()
|
||||
.animation(.easeInOut(duration: 0.2), value: hideABXY)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var centerButtons: some View {
|
||||
Group {
|
||||
if stickButton {
|
||||
VStack {
|
||||
HStack(spacing: 50) {
|
||||
ButtonView(button: .leftStick)
|
||||
.padding()
|
||||
Spacer()
|
||||
ButtonView(button: .rightStick)
|
||||
.padding()
|
||||
}
|
||||
.padding(.top, 30)
|
||||
|
||||
HStack(spacing: 50) {
|
||||
ButtonView(button: .back)
|
||||
Spacer()
|
||||
ButtonView(button: .start)
|
||||
}
|
||||
}
|
||||
.padding(.bottom, 20)
|
||||
} else {
|
||||
HStack(spacing: 50) {
|
||||
ButtonView(button: .back)
|
||||
Spacer()
|
||||
ButtonView(button: .start)
|
||||
}
|
||||
.padding(.bottom, 20)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Methods
|
||||
|
||||
private func updateOrientation() {
|
||||
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
||||
let window = windowScene.windows.first {
|
||||
isPortrait = window.bounds.size.height > window.bounds.size.width
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct ShoulderButtonsViewLeft: View {
|
||||
@State var width: CGFloat = 160
|
||||
@State var height: CGFloat = 20
|
||||
@State private var width: CGFloat = 160
|
||||
@State private var height: CGFloat = 20
|
||||
@AppStorage("On-ScreenControllerScale") var controllerScale: Double = 1.0
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
HStack(spacing: 20) {
|
||||
ButtonView(button: .leftTrigger)
|
||||
.padding(.horizontal)
|
||||
ButtonView(button: .leftShoulder)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.frame(width: width, height: height)
|
||||
.onAppear() {
|
||||
.onAppear {
|
||||
if UIDevice.current.systemName.contains("iPadOS") {
|
||||
width *= 1.2
|
||||
height *= 1.2
|
||||
@ -118,19 +185,17 @@ struct ShoulderButtonsViewLeft: View {
|
||||
}
|
||||
|
||||
struct ShoulderButtonsViewRight: View {
|
||||
@State var width: CGFloat = 160
|
||||
@State var height: CGFloat = 20
|
||||
@State private var width: CGFloat = 160
|
||||
@State private var height: CGFloat = 20
|
||||
@AppStorage("On-ScreenControllerScale") var controllerScale: Double = 1.0
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
HStack(spacing: 20) {
|
||||
ButtonView(button: .rightShoulder)
|
||||
.padding(.horizontal)
|
||||
ButtonView(button: .rightTrigger)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.frame(width: width, height: height)
|
||||
.onAppear() {
|
||||
.onAppear {
|
||||
if UIDevice.current.systemName.contains("iPadOS") {
|
||||
width *= 1.2
|
||||
height *= 1.2
|
||||
@ -143,21 +208,21 @@ struct ShoulderButtonsViewRight: View {
|
||||
}
|
||||
|
||||
struct DPadView: View {
|
||||
@State var size: CGFloat = 145
|
||||
@State private var size: CGFloat = 145
|
||||
@AppStorage("On-ScreenControllerScale") var controllerScale: Double = 1.0
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack(spacing: 7) {
|
||||
ButtonView(button: .dPadUp)
|
||||
HStack {
|
||||
HStack(spacing: 22) {
|
||||
ButtonView(button: .dPadLeft)
|
||||
Spacer(minLength: 20)
|
||||
Spacer(minLength: 22)
|
||||
ButtonView(button: .dPadRight)
|
||||
}
|
||||
ButtonView(button: .dPadDown)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.frame(width: size, height: size)
|
||||
.onAppear() {
|
||||
.onAppear {
|
||||
if UIDevice.current.systemName.contains("iPadOS") {
|
||||
size *= 1.2
|
||||
}
|
||||
@ -168,22 +233,21 @@ struct DPadView: View {
|
||||
}
|
||||
|
||||
struct ABXYView: View {
|
||||
@State var size: CGFloat = 145
|
||||
@State private var size: CGFloat = 145
|
||||
@AppStorage("On-ScreenControllerScale") var controllerScale: Double = 1.0
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack(spacing: 7) {
|
||||
ButtonView(button: .X)
|
||||
HStack {
|
||||
HStack(spacing: 22) {
|
||||
ButtonView(button: .Y)
|
||||
Spacer(minLength: 20)
|
||||
Spacer(minLength: 22)
|
||||
ButtonView(button: .A)
|
||||
}
|
||||
ButtonView(button: .B)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.frame(width: size, height: size)
|
||||
.onAppear() {
|
||||
.onAppear {
|
||||
if UIDevice.current.systemName.contains("iPadOS") {
|
||||
size *= 1.2
|
||||
}
|
||||
@ -195,58 +259,109 @@ struct ABXYView: View {
|
||||
|
||||
struct ButtonView: View {
|
||||
var button: VirtualControllerButton
|
||||
@State var width: CGFloat = 45
|
||||
@State var height: CGFloat = 45
|
||||
@State var isPressed = false
|
||||
@State private var width: CGFloat = 45
|
||||
@State private var height: CGFloat = 45
|
||||
@State private var isPressed = false
|
||||
@AppStorage("onscreenhandheld") var onscreenjoy: Bool = false
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
@AppStorage("On-ScreenControllerScale") var controllerScale: Double = 1.0
|
||||
|
||||
|
||||
@State private var debounceTimer: Timer?
|
||||
|
||||
var body: some View {
|
||||
Image(systemName: buttonText)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: width, height: height)
|
||||
.foregroundColor(colorScheme == .dark ? Color.gray : Color.gray)
|
||||
.opacity(isPressed ? 0.4 : 0.7)
|
||||
.foregroundColor(true ? Color.white.opacity(0.5) : Color.black.opacity(0.5))
|
||||
.background(
|
||||
Group {
|
||||
if !button.isTrigger && button != .leftStick && button != .rightStick {
|
||||
Circle()
|
||||
.fill(true ? Color.gray.opacity(0.4) : Color.gray.opacity(0.3))
|
||||
.frame(width: width * 1.25, height: height * 1.25)
|
||||
} else if button == .leftStick || button == .rightStick {
|
||||
Image(systemName: buttonText)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: width * 1.25, height: height * 1.25)
|
||||
.foregroundColor(true ? Color.gray.opacity(0.4) : Color.gray.opacity(0.3))
|
||||
} else if button.isTrigger {
|
||||
Image(systemName: "" + String(turntobutton(buttonText)))
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: width * 1.25, height: height * 1.25)
|
||||
.foregroundColor(true ? Color.gray.opacity(0.4) : Color.gray.opacity(0.3))
|
||||
}
|
||||
}
|
||||
)
|
||||
.opacity(isPressed ? 0.6 : 1.0)
|
||||
.gesture(
|
||||
DragGesture(minimumDistance: 0)
|
||||
.onChanged { _ in
|
||||
if !self.isPressed {
|
||||
self.isPressed = true
|
||||
Ryujinx.shared.virtualController.setButtonState(1, for: button)
|
||||
Haptics.shared.play(.heavy)
|
||||
}
|
||||
handleButtonPress()
|
||||
}
|
||||
.onEnded { _ in
|
||||
self.isPressed = false
|
||||
Ryujinx.shared.virtualController.setButtonState(0, for: button)
|
||||
handleButtonRelease()
|
||||
}
|
||||
)
|
||||
.onAppear() {
|
||||
if button == .leftTrigger || button == .rightTrigger || button == .leftShoulder || button == .rightShoulder {
|
||||
width = 65
|
||||
}
|
||||
|
||||
|
||||
if button == .back || button == .start || button == .guide {
|
||||
width = 35
|
||||
height = 35
|
||||
}
|
||||
|
||||
if UIDevice.current.systemName.contains("iPadOS") {
|
||||
width *= 1.2
|
||||
height *= 1.2
|
||||
}
|
||||
|
||||
width *= CGFloat(controllerScale)
|
||||
height *= CGFloat(controllerScale)
|
||||
)
|
||||
.onAppear {
|
||||
configureSizeForButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func turntobutton(_ string: String) -> String {
|
||||
var sting = string
|
||||
if string.hasPrefix("zl") || string.hasPrefix("zr") {
|
||||
sting = String(string.dropFirst(3))
|
||||
} else {
|
||||
sting = String(string.dropFirst(2))
|
||||
}
|
||||
sting = sting.replacingOccurrences(of: "rectangle", with: "button")
|
||||
sting = sting.replacingOccurrences(of: ".fill", with: ".horizontal.fill")
|
||||
|
||||
return sting
|
||||
}
|
||||
|
||||
private func handleButtonPress() {
|
||||
if !isPressed {
|
||||
isPressed = true
|
||||
|
||||
debounceTimer?.invalidate()
|
||||
|
||||
Ryujinx.shared.virtualController.setButtonState(1, for: button)
|
||||
|
||||
Haptics.shared.play(.medium)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleButtonRelease() {
|
||||
if isPressed {
|
||||
isPressed = false
|
||||
|
||||
debounceTimer = Timer.scheduledTimer(withTimeInterval: 0.05, repeats: false) { _ in
|
||||
Ryujinx.shared.virtualController.setButtonState(0, for: button)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func configureSizeForButton() {
|
||||
if button.isTrigger {
|
||||
width = 70
|
||||
height = 40
|
||||
} else if button.isSmall {
|
||||
width = 35
|
||||
height = 35
|
||||
}
|
||||
|
||||
// Adjust for iPad
|
||||
if UIDevice.current.systemName.contains("iPadOS") {
|
||||
width *= 1.2
|
||||
height *= 1.2
|
||||
}
|
||||
|
||||
width *= CGFloat(controllerScale)
|
||||
height *= CGFloat(controllerScale)
|
||||
}
|
||||
|
||||
private var buttonText: String {
|
||||
switch button {
|
||||
@ -258,6 +373,10 @@ struct ButtonView: View {
|
||||
return "x.circle.fill"
|
||||
case .Y:
|
||||
return "y.circle.fill"
|
||||
case .leftStick:
|
||||
return "l.joystick.press.down.fill"
|
||||
case .rightStick:
|
||||
return "r.joystick.press.down.fill"
|
||||
case .dPadUp:
|
||||
return "arrowtriangle.up.circle.fill"
|
||||
case .dPadDown:
|
||||
@ -267,7 +386,7 @@ struct ButtonView: View {
|
||||
case .dPadRight:
|
||||
return "arrowtriangle.right.circle.fill"
|
||||
case .leftTrigger:
|
||||
return"zl.rectangle.roundedtop.fill"
|
||||
return "zl.rectangle.roundedtop.fill"
|
||||
case .rightTrigger:
|
||||
return "zr.rectangle.roundedtop.fill"
|
||||
case .leftShoulder:
|
||||
@ -275,16 +394,11 @@ struct ButtonView: View {
|
||||
case .rightShoulder:
|
||||
return "r.rectangle.roundedbottom.fill"
|
||||
case .start:
|
||||
return "plus.circle.fill" // System symbol for +
|
||||
return "plus.circle.fill"
|
||||
case .back:
|
||||
return "minus.circle.fill" // System symbol for -
|
||||
return "minus.circle.fill"
|
||||
case .guide:
|
||||
return "house.circle.fill"
|
||||
// This should be all the cases
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,7 +15,6 @@ class Haptics {
|
||||
private init() { }
|
||||
|
||||
func play(_ feedbackStyle: UIImpactFeedbackGenerator.FeedbackStyle) {
|
||||
print("haptics")
|
||||
UIImpactFeedbackGenerator(style: feedbackStyle).impactOccurred()
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,87 @@
|
||||
//
|
||||
// Joystick.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by Stossy11 on 21/03/2025.
|
||||
//
|
||||
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct Joystick: View {
|
||||
@Binding var position: CGPoint
|
||||
@State var joystickSize: CGFloat
|
||||
var boundarySize: CGFloat
|
||||
|
||||
@State private var offset: CGSize = .zero
|
||||
@Binding var showBackground: Bool
|
||||
|
||||
let sensitivity: CGFloat = 1.5
|
||||
|
||||
var dragGesture: some Gesture {
|
||||
DragGesture()
|
||||
.onChanged { value in
|
||||
withAnimation(.easeIn) {
|
||||
showBackground = true
|
||||
}
|
||||
|
||||
let translation = value.translation
|
||||
let distance = sqrt(translation.width * translation.width + translation.height * translation.height)
|
||||
let maxRadius = (boundarySize - joystickSize) / 2
|
||||
let extendedRadius = maxRadius + (joystickSize / 2)
|
||||
|
||||
if distance <= extendedRadius {
|
||||
offset = translation
|
||||
} else {
|
||||
let angle = atan2(translation.height, translation.width)
|
||||
offset = CGSize(width: cos(angle) * extendedRadius, height: sin(angle) * extendedRadius)
|
||||
}
|
||||
|
||||
position = CGPoint(
|
||||
x: max(-1, min(1, (offset.width / extendedRadius) * sensitivity)),
|
||||
y: max(-1, min(1, (offset.height / extendedRadius) * sensitivity))
|
||||
)
|
||||
}
|
||||
.onEnded { _ in
|
||||
offset = .zero
|
||||
position = .zero
|
||||
withAnimation(.easeOut) {
|
||||
showBackground = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(Color.clear.opacity(0))
|
||||
.frame(width: boundarySize, height: boundarySize)
|
||||
|
||||
if showBackground {
|
||||
Circle()
|
||||
.fill(Color.gray.opacity(0.4))
|
||||
.frame(width: boundarySize, height: boundarySize)
|
||||
.animation(.easeInOut(duration: 0.1), value: showBackground)
|
||||
}
|
||||
|
||||
Circle()
|
||||
.fill(Color.white.opacity(0.5))
|
||||
.frame(width: joystickSize, height: joystickSize)
|
||||
.background(
|
||||
Circle()
|
||||
.fill(Color.gray.opacity(0.3))
|
||||
.frame(width: joystickSize * 1.25, height: joystickSize * 1.25)
|
||||
)
|
||||
.offset(offset)
|
||||
.gesture(dragGesture)
|
||||
}
|
||||
.frame(width: boundarySize, height: boundarySize)
|
||||
.onChange(of: showBackground) { newValue in
|
||||
if newValue {
|
||||
joystickSize *= 1.4
|
||||
} else {
|
||||
joystickSize = (boundarySize * 0.2)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,13 +7,13 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SwiftUIJoystick
|
||||
|
||||
public struct Joystick: View {
|
||||
struct JoystickController: View {
|
||||
@State var iscool: Bool? = nil
|
||||
|
||||
@ObservedObject public var joystickMonitor = JoystickMonitor()
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
@Binding var showBackground: Bool
|
||||
@AppStorage("On-ScreenControllerScale") var controllerScale: Double = 1.0
|
||||
@State var position: CGPoint = CGPoint(x: 0, y: 0)
|
||||
var dragDiameter: CGFloat {
|
||||
var selfs = CGFloat(160)
|
||||
selfs *= controllerScale
|
||||
@ -23,34 +23,21 @@ public struct Joystick: View {
|
||||
|
||||
return selfs
|
||||
}
|
||||
private let shape: JoystickShape = .circle
|
||||
|
||||
public var body: some View {
|
||||
VStack{
|
||||
JoystickBuilder(
|
||||
monitor: self.joystickMonitor,
|
||||
width: self.dragDiameter,
|
||||
shape: .circle,
|
||||
background: {
|
||||
Text("")
|
||||
.hidden()
|
||||
},
|
||||
foreground: {
|
||||
Circle().fill(Color.gray)
|
||||
.opacity(0.7)
|
||||
},
|
||||
locksInPlace: false)
|
||||
.onChange(of: self.joystickMonitor.xyPoint) { newValue in
|
||||
let scaledX = Float(newValue.x)
|
||||
let scaledY = Float(newValue.y) // my dumbass broke this by having -y instead of y :/
|
||||
print("Joystick Position: (\(scaledX), \(scaledY))")
|
||||
|
||||
if iscool != nil {
|
||||
Ryujinx.shared.virtualController.thumbstickMoved(.right, x: newValue.x, y: newValue.y)
|
||||
} else {
|
||||
Ryujinx.shared.virtualController.thumbstickMoved(.left, x: newValue.x, y: newValue.y)
|
||||
VStack {
|
||||
Joystick(position: $position, joystickSize: dragDiameter * 0.2, boundarySize: dragDiameter, showBackground: $showBackground)
|
||||
.onChange(of: position) { newValue in
|
||||
let scaledX = Float(newValue.x)
|
||||
let scaledY = Float(newValue.y) // my dumbass broke this by having -y instead of y :/
|
||||
// print("Joystick Position: (\(scaledX), \(scaledY))")
|
||||
|
||||
if iscool != nil {
|
||||
Ryujinx.shared.virtualController.thumbstickMoved(.right, x: newValue.x, y: newValue.y)
|
||||
} else {
|
||||
Ryujinx.shared.virtualController.thumbstickMoved(.left, x: newValue.x, y: newValue.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class Air {
|
||||
}
|
||||
|
||||
@objc func didConnect(sender: NSNotification) {
|
||||
print("AirKit - Connect")
|
||||
// print("AirKit - Connect")
|
||||
self.connected = true
|
||||
guard let screen: UIScreen = sender.object as? UIScreen else { return }
|
||||
add(screen: screen) { success in
|
||||
@ -69,35 +69,35 @@ public class Air {
|
||||
|
||||
func add(screen: UIScreen, completion: @escaping (Bool) -> ()) {
|
||||
|
||||
print("AirKit - Add Screen")
|
||||
// print("AirKit - Add Screen")
|
||||
|
||||
airScreen = screen
|
||||
|
||||
airWindow = UIWindow(frame: airScreen!.bounds)
|
||||
|
||||
guard let viewController: UIViewController = hostingController else {
|
||||
print("AirKit - Add - Failed: Hosting Controller Not Found")
|
||||
// print("AirKit - Add - Failed: Hosting Controller Not Found")
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
|
||||
findWindowScene(for: airScreen!) { windowScene in
|
||||
guard let airWindowScene: UIWindowScene = windowScene else {
|
||||
print("AirKit - Add - Failed: Window Scene Not Found")
|
||||
// print("AirKit - Add - Failed: Window Scene Not Found")
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
self.airWindow?.rootViewController = viewController
|
||||
self.airWindow?.windowScene = airWindowScene
|
||||
self.airWindow?.isHidden = false
|
||||
print("AirKit - Add Screen - Done")
|
||||
// print("AirKit - Add Screen - Done")
|
||||
completion(true)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func findWindowScene(for screen: UIScreen, shouldRecurse: Bool = true, completion: @escaping (UIWindowScene?) -> ()) {
|
||||
print("AirKit - Find Window Scene")
|
||||
// print("AirKit - Find Window Scene")
|
||||
var matchingWindowScene: UIWindowScene? = nil
|
||||
let scenes = UIApplication.shared.connectedScenes
|
||||
for scene in scenes {
|
||||
@ -120,23 +120,23 @@ public class Air {
|
||||
}
|
||||
|
||||
@objc func didDisconnect() {
|
||||
print("AirKit - Disconnect")
|
||||
// print("AirKit - Disconnect")
|
||||
remove()
|
||||
connected = false
|
||||
}
|
||||
|
||||
func remove() {
|
||||
print("AirKit - Remove")
|
||||
// print("AirKit - Remove")
|
||||
airWindow = nil
|
||||
airScreen = nil
|
||||
}
|
||||
|
||||
@objc func didBecomeActive() {
|
||||
print("AirKit - App Active")
|
||||
// print("AirKit - App Active")
|
||||
}
|
||||
|
||||
@objc func willResignActive() {
|
||||
print("AirKit - App Inactive")
|
||||
// print("AirKit - App Inactive")
|
||||
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import SwiftUI
|
||||
public extension View {
|
||||
|
||||
func airPlay() -> some View {
|
||||
print("AirKit - airPlay")
|
||||
// print("AirKit - airPlay")
|
||||
Air.play(AnyView(self))
|
||||
return self
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ struct EmulationView: View {
|
||||
@Binding var startgame: Game?
|
||||
|
||||
@Environment(\.scenePhase) var scenePhase
|
||||
@State private var isInBackground = false
|
||||
@AppStorage("location-enabled") var locationenabled: Bool = false
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if isAirplaying {
|
||||
@ -26,7 +29,7 @@ struct EmulationView: View {
|
||||
.ignoresSafeArea()
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
.onAppear {
|
||||
Air.play(AnyView(MetalView().ignoresSafeArea()))
|
||||
Air.play(AnyView(MetalView().ignoresSafeArea().edgesIgnoringSafeArea(.all)))
|
||||
}
|
||||
} else {
|
||||
MetalView() // The Emulation View
|
||||
@ -88,12 +91,26 @@ struct EmulationView: View {
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
LocationManager.sharedInstance.startUpdatingLocation()
|
||||
Air.shared.connectionCallbacks.append { cool in
|
||||
DispatchQueue.main.async {
|
||||
isAirplaying = cool
|
||||
print(cool)
|
||||
// print(cool)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: scenePhase) { newPhase in
|
||||
// Detect when the app enters the background
|
||||
if newPhase == .background {
|
||||
stop_emulation(true)
|
||||
isInBackground = true
|
||||
} else if newPhase == .active {
|
||||
stop_emulation(false)
|
||||
isInBackground = false
|
||||
} else if newPhase == .inactive {
|
||||
stop_emulation(true)
|
||||
isInBackground = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ class MeloMTKView: MTKView {
|
||||
let index = activeTouches.firstIndex(of: touch)!
|
||||
|
||||
let scaledLocation = scaleToTargetResolution(location)!
|
||||
print("Touch began at: \(scaledLocation) and \(self.aspectRatio)")
|
||||
// // print("Touch began at: \(scaledLocation) and \(self.aspectRatio)")
|
||||
touch_began(Float(scaledLocation.x), Float(scaledLocation.y), Int32(index))
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ class MeloMTKView: MTKView {
|
||||
if let index = activeTouches.firstIndex(of: touch) {
|
||||
activeTouches.remove(at: index)
|
||||
|
||||
print("Touch ended for index \(index)")
|
||||
// // print("Touch ended for index \(index)")
|
||||
touch_ended(Int32(index))
|
||||
}
|
||||
}
|
||||
@ -139,14 +139,14 @@ class MeloMTKView: MTKView {
|
||||
guard let scaledLocation = scaleToTargetResolution(location) else {
|
||||
if let index = activeTouches.firstIndex(of: touch) {
|
||||
activeTouches.remove(at: index)
|
||||
print("Touch left active area, removed index \(index)")
|
||||
// // print("Touch left active area, removed index \(index)")
|
||||
touch_ended(Int32(index))
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if let index = activeTouches.firstIndex(of: touch) {
|
||||
print("Touch moved to: \(scaledLocation)")
|
||||
// // print("Touch moved to: \(scaledLocation)")
|
||||
touch_moved(Float(scaledLocation.x), Float(scaledLocation.y), Int32(index))
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ struct MetalView: UIViewRepresentable {
|
||||
func makeUIView(context: Context) -> UIView {
|
||||
|
||||
if Ryujinx.shared.emulationUIView == nil {
|
||||
var view = MeloMTKView()
|
||||
let view = MeloMTKView()
|
||||
|
||||
guard let metalLayer = view.layer as? CAMetalLayer else {
|
||||
fatalError("[Swift] Error: MTKView's layer is not a CAMetalLayer")
|
||||
@ -34,13 +34,19 @@ struct MetalView: UIViewRepresentable {
|
||||
return view
|
||||
}
|
||||
|
||||
let uiview = UIView()
|
||||
|
||||
uiview.layer.addSublayer(Ryujinx.shared.metalLayer!)
|
||||
|
||||
uiview.contentScaleFactor = Ryujinx.shared.metalLayer!.contentsScale
|
||||
|
||||
return uiview
|
||||
if Double(UIDevice.current.systemVersion)! < 17.0 {
|
||||
|
||||
let uiview = MTKView()
|
||||
let layer = Ryujinx.shared.metalLayer!
|
||||
|
||||
layer.frame = uiview.bounds
|
||||
|
||||
uiview.layer.addSublayer(layer)
|
||||
|
||||
return uiview
|
||||
} else {
|
||||
return Ryujinx.shared.emulationUIView!
|
||||
}
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: UIView, context: Context) {
|
||||
|
@ -10,7 +10,7 @@ import MetalKit
|
||||
|
||||
struct TouchView: UIViewRepresentable {
|
||||
func makeUIView(context: Context) -> UIView {
|
||||
var view = MeloMTKView()
|
||||
let view = MeloMTKView()
|
||||
return view
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
//
|
||||
// GameRequirementsCache.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by Stossy11 on 21/03/2025.
|
||||
//
|
||||
|
||||
|
||||
import Foundation
|
||||
|
||||
class GameCompatibiliryCache {
|
||||
static let shared = GameCompatibiliryCache()
|
||||
private let cacheKey = "gameRequirementsCache"
|
||||
private let timestampKey = "gameRequirementsCacheTimestamp"
|
||||
|
||||
private let cacheDuration: TimeInterval = Double.random(in: 3...5) * 24 * 60 * 60 // Randomly pick 3-5 days
|
||||
|
||||
func getCachedData() -> [GameRequirements]? {
|
||||
guard let cachedData = UserDefaults.standard.data(forKey: cacheKey),
|
||||
let timestamp = UserDefaults.standard.object(forKey: timestampKey) as? Date else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let timeElapsed = Date().timeIntervalSince(timestamp)
|
||||
if timeElapsed > cacheDuration {
|
||||
clearCache()
|
||||
return nil
|
||||
}
|
||||
|
||||
return try? JSONDecoder().decode([GameRequirements].self, from: cachedData)
|
||||
}
|
||||
|
||||
func setCachedData(_ data: [GameRequirements]) {
|
||||
if let encodedData = try? JSONEncoder().encode(data) {
|
||||
UserDefaults.standard.set(encodedData, forKey: cacheKey)
|
||||
UserDefaults.standard.set(Date(), forKey: timestampKey)
|
||||
}
|
||||
}
|
||||
|
||||
func clearCache() {
|
||||
UserDefaults.standard.removeObject(forKey: cacheKey)
|
||||
UserDefaults.standard.removeObject(forKey: timestampKey)
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ import SwiftUI
|
||||
struct GameInfoSheet: View {
|
||||
let game: Game
|
||||
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
var body: some View {
|
||||
iOSNav {
|
||||
@ -44,7 +44,7 @@ struct GameInfoSheet: View {
|
||||
.multilineTextAlignment(.center)
|
||||
Text(game.developer)
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.padding(.vertical, 3)
|
||||
}
|
||||
@ -56,7 +56,7 @@ struct GameInfoSheet: View {
|
||||
Text("**Version**")
|
||||
Spacer()
|
||||
Text(game.version)
|
||||
.foregroundStyle(Color.secondary)
|
||||
.foregroundColor(Color.secondary)
|
||||
}
|
||||
HStack {
|
||||
Text("**Title ID**")
|
||||
@ -69,36 +69,36 @@ struct GameInfoSheet: View {
|
||||
}
|
||||
Spacer()
|
||||
Text(game.titleId)
|
||||
.foregroundStyle(Color.secondary)
|
||||
.foregroundColor(Color.secondary)
|
||||
}
|
||||
HStack {
|
||||
Text("**Game Size**")
|
||||
Spacer()
|
||||
Text("\(fetchFileSize(for: game.fileURL) ?? 0) bytes")
|
||||
.foregroundStyle(Color.secondary)
|
||||
.foregroundColor(Color.secondary)
|
||||
}
|
||||
HStack {
|
||||
Text("**File Type**")
|
||||
Spacer()
|
||||
Text(getFileType(game.fileURL))
|
||||
.foregroundStyle(Color.secondary)
|
||||
.foregroundColor(Color.secondary)
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("**Game URL**")
|
||||
Text(trimGameURL(game.fileURL))
|
||||
.foregroundStyle(Color.secondary)
|
||||
.foregroundColor(Color.secondary)
|
||||
}
|
||||
} header: {
|
||||
Text("Information")
|
||||
}
|
||||
.headerProminence(.increased)
|
||||
// .headerProminence(.increased)
|
||||
}
|
||||
.navigationTitle(game.titleName)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Done") {
|
||||
dismiss()
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Dismiss") {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,7 @@ struct GameInfoSheet: View {
|
||||
return size
|
||||
}
|
||||
} catch {
|
||||
print("Error getting file size: \(error)")
|
||||
// print("Error getting file size: \(error)")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@ import SwiftUI
|
||||
|
||||
struct JITPopover: View {
|
||||
var onJITEnabled: () -> Void
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
@State var isJIT: Bool = false
|
||||
var body: some View {
|
||||
@ -35,8 +35,10 @@ struct JITPopover: View {
|
||||
|
||||
|
||||
if isJIT {
|
||||
dismiss()
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
onJITEnabled()
|
||||
|
||||
Ryujinx.shared.ryuIsJITEnabled()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,25 +6,20 @@
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
struct LogFileView: View {
|
||||
@State private var logs: [String] = []
|
||||
@StateObject var logsModel = LogViewModel()
|
||||
@State private var showingLogs = false
|
||||
|
||||
public var isfps: Bool
|
||||
|
||||
private let fileManager = FileManager.default
|
||||
private let maxDisplayLines = 10
|
||||
|
||||
private var dateFormatter: DateFormatter {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyy-MM-dd_HH-mm-ss"
|
||||
return formatter
|
||||
}
|
||||
private let maxDisplayLines = 4
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
ForEach(logs.suffix(maxDisplayLines), id: \.self) { log in
|
||||
ForEach(logsModel.logs.suffix(maxDisplayLines), id: \.self) { log in
|
||||
Text(log)
|
||||
.font(.caption)
|
||||
.foregroundColor(.white)
|
||||
@ -34,84 +29,38 @@ struct LogFileView: View {
|
||||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
startLogFileWatching()
|
||||
}
|
||||
.onChange(of: logs) { newLogs in
|
||||
print("Logs updated: \(newLogs.count) entries")
|
||||
}
|
||||
}
|
||||
|
||||
private func getLatestLogFile() -> URL? {
|
||||
let logsDirectory = URL.documentsDirectory.appendingPathComponent("Logs")
|
||||
let currentDate = Date()
|
||||
|
||||
do {
|
||||
try fileManager.createDirectory(at: logsDirectory, withIntermediateDirectories: true)
|
||||
|
||||
let logFiles = try fileManager.contentsOfDirectory(at: logsDirectory, includingPropertiesForKeys: [.creationDateKey])
|
||||
.filter {
|
||||
let filename = $0.lastPathComponent
|
||||
guard filename.hasPrefix("MeloNX_") && filename.hasSuffix(".log") else {
|
||||
return false
|
||||
}
|
||||
|
||||
let dateString = filename.replacingOccurrences(of: "MeloNX_", with: "").replacingOccurrences(of: ".log", with: "")
|
||||
guard let logDate = dateFormatter.date(from: dateString) else {
|
||||
return false
|
||||
}
|
||||
|
||||
return Calendar.current.isDate(logDate, inSameDayAs: currentDate)
|
||||
}
|
||||
|
||||
let sortedLogFiles = logFiles.sorted {
|
||||
$0.lastPathComponent > $1.lastPathComponent
|
||||
}
|
||||
|
||||
return sortedLogFiles.first
|
||||
} catch {
|
||||
print("Error finding log files: \(error)")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private func readLatestLogFile() {
|
||||
guard let logFileURL = getLatestLogFile() else {
|
||||
print("no logs?")
|
||||
return
|
||||
}
|
||||
print(logFileURL)
|
||||
|
||||
do {
|
||||
let logContents = try String(contentsOf: logFileURL)
|
||||
let allLines = logContents.components(separatedBy: .newlines)
|
||||
|
||||
DispatchQueue.global(qos: .userInteractive).async {
|
||||
self.logs = Array(allLines)
|
||||
}
|
||||
} catch {
|
||||
print("Error reading log file: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
private func startLogFileWatching() {
|
||||
showingLogs = true
|
||||
self.readLatestLogFile()
|
||||
Timer.scheduledTimer(withTimeInterval: 0.05, repeats: true) { timer in
|
||||
if showingLogs {
|
||||
self.readLatestLogFile()
|
||||
}
|
||||
|
||||
if isfps {
|
||||
if get_current_fps() != 0 {
|
||||
stopLogFileWatching()
|
||||
timer.invalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
private func stopLogFileWatching() {
|
||||
showingLogs = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class LogViewModel: ObservableObject {
|
||||
@Published var logs: [String] = []
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
init() {
|
||||
_ = LogCapture.shared
|
||||
|
||||
NotificationCenter.default.publisher(for: .newLogCaptured)
|
||||
.receive(on: RunLoop.main)
|
||||
.sink { [weak self] _ in
|
||||
self?.updateLogs()
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
updateLogs()
|
||||
}
|
||||
|
||||
func updateLogs() {
|
||||
logs = LogCapture.shared.capturedLogs
|
||||
}
|
||||
|
||||
func clearLogs() {
|
||||
LogCapture.shared.capturedLogs = []
|
||||
updateLogs()
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,74 @@
|
||||
//
|
||||
// MeloNXUpdateSheet.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by Stossy11 and Bella on 12/03/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MeloNXUpdateSheet: View {
|
||||
let updateInfo: LatestVersionResponse
|
||||
@Binding var isPresented: Bool
|
||||
|
||||
var body: some View {
|
||||
iOSNav {
|
||||
VStack {
|
||||
Text("Version \(updateInfo.version_number) is available. You are currently on Version \(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown").")
|
||||
|
||||
VStack {
|
||||
Text("Changelog:")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.font(.headline)
|
||||
|
||||
ScrollView {
|
||||
Text(updateInfo.changelog)
|
||||
.padding()
|
||||
}
|
||||
.frame(maxHeight: 400)
|
||||
.background(Color(.secondarySystemBackground))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
||||
}
|
||||
.padding(.top, 15)
|
||||
|
||||
|
||||
Spacer()
|
||||
if #available(iOS 15.0, *) {
|
||||
Button(action: {
|
||||
if let url = URL(string: updateInfo.download_link) {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}) {
|
||||
Text("Download Now")
|
||||
.font(.title3)
|
||||
.bold()
|
||||
.frame(width: 300, height: 40)
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.frame(alignment: .bottom)
|
||||
} else {
|
||||
Button(action: {
|
||||
if let url = URL(string: updateInfo.download_link) {
|
||||
UIApplication.shared.open(url)
|
||||
}
|
||||
}) {
|
||||
Text("Download Now")
|
||||
.font(.title3)
|
||||
.bold()
|
||||
.frame(width: 300, height: 40)
|
||||
}
|
||||
.frame(alignment: .bottom)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.navigationTitle("Version \(updateInfo.version_number) Available!")
|
||||
.toolbar {
|
||||
Button(action: {
|
||||
isPresented = false
|
||||
}) {
|
||||
Text("Close")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
//
|
||||
// GameDLCManagerSheet.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by XITRIX on 16/02/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct DownloadableContentNca: Codable, Hashable {
|
||||
var fullPath: String
|
||||
var titleId: UInt
|
||||
var enabled: Bool
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case fullPath = "path"
|
||||
case titleId = "title_id"
|
||||
case enabled = "is_enabled"
|
||||
}
|
||||
}
|
||||
|
||||
struct DownloadableContentContainer: Codable, Hashable {
|
||||
var containerPath: String
|
||||
var downloadableContentNcaList: [DownloadableContentNca]
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case containerPath = "path"
|
||||
case downloadableContentNcaList = "dlc_nca_list"
|
||||
}
|
||||
}
|
||||
|
||||
struct DLCManagerSheet: View {
|
||||
@Binding var game: Game!
|
||||
@State private var isSelectingGameDLC = false
|
||||
@State private var dlcs: [DownloadableContentContainer] = []
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
let withIndex = dlcs.enumerated().map { $0 }
|
||||
List(withIndex, id: \.element.containerPath) { index, dlc in
|
||||
Button(action: {
|
||||
let toggle = dlcs[index].downloadableContentNcaList.first?.enabled ?? true
|
||||
dlcs[index].downloadableContentNcaList.mutableForEach { $0.enabled = !toggle }
|
||||
Self.saveDlcs(game, dlc: dlcs)
|
||||
}) {
|
||||
HStack {
|
||||
Text((dlc.containerPath as NSString).lastPathComponent)
|
||||
.foregroundStyle(Color(uiColor: .label))
|
||||
Spacer()
|
||||
if dlc.downloadableContentNcaList.first?.enabled == true {
|
||||
Image(systemName: "checkmark.circle.fill")
|
||||
.foregroundStyle(Color.accentColor)
|
||||
.font(.system(size: 24))
|
||||
} else {
|
||||
Image(systemName: "circle")
|
||||
.foregroundStyle(Color(uiColor: .secondaryLabel))
|
||||
.font(.system(size: 24))
|
||||
}
|
||||
}
|
||||
}
|
||||
.contextMenu {
|
||||
Button {
|
||||
let path = URL.documentsDirectory.appendingPathComponent(dlc.containerPath)
|
||||
try? FileManager.default.removeItem(atPath: path.path)
|
||||
dlcs.remove(at: index)
|
||||
Self.saveDlcs(game, dlc: dlcs)
|
||||
} label: {
|
||||
Text("Remove DLC")
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("\(game.titleName) DLCs")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
Button("Add", systemImage: "plus") {
|
||||
isSelectingGameDLC = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
dlcs = Self.loadDlc(game)
|
||||
}
|
||||
.fileImporter(isPresented: $isSelectingGameDLC, allowedContentTypes: [.item], allowsMultipleSelection: true) { result in
|
||||
switch result {
|
||||
case .success(let urls):
|
||||
for url in urls {
|
||||
guard url.startAccessingSecurityScopedResource() else {
|
||||
print("Failed to access security-scoped resource")
|
||||
return
|
||||
}
|
||||
defer { url.stopAccessingSecurityScopedResource() }
|
||||
|
||||
do {
|
||||
let fileManager = FileManager.default
|
||||
let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
let dlcDirectory = documentsDirectory.appendingPathComponent("dlc")
|
||||
let romDlcDirectory = dlcDirectory.appendingPathComponent(game.titleId)
|
||||
|
||||
if !fileManager.fileExists(atPath: dlcDirectory.path) {
|
||||
try fileManager.createDirectory(at: dlcDirectory, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
if !fileManager.fileExists(atPath: romDlcDirectory.path) {
|
||||
try fileManager.createDirectory(at: romDlcDirectory, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
let dlcContent = Ryujinx.shared.getDlcNcaList(titleId: game.titleId, path: url.path)
|
||||
guard !dlcContent.isEmpty else { return }
|
||||
|
||||
let destinationURL = romDlcDirectory.appendingPathComponent(url.lastPathComponent)
|
||||
try? fileManager.copyItem(at: url, to: destinationURL)
|
||||
|
||||
let container = DownloadableContentContainer(
|
||||
containerPath: Self.relativeDlcDirectoryPath(for: game, dlcPath: destinationURL),
|
||||
downloadableContentNcaList: dlcContent
|
||||
)
|
||||
dlcs.append(container)
|
||||
|
||||
Self.saveDlcs(game, dlc: dlcs)
|
||||
} catch {
|
||||
print("Error copying game file: \(error)")
|
||||
}
|
||||
}
|
||||
case .failure(let err):
|
||||
print("File import failed: \(err.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension DLCManagerSheet {
|
||||
static func loadDlc(_ game: Game) -> [DownloadableContentContainer] {
|
||||
let jsonURL = dlcJsonPath(for: game)
|
||||
guard let data = try? Data(contentsOf: jsonURL),
|
||||
var result = try? JSONDecoder().decode([DownloadableContentContainer].self, from: data)
|
||||
else { return [] }
|
||||
|
||||
result = result.filter { container in
|
||||
let path = URL.documentsDirectory.appendingPathComponent(container.containerPath)
|
||||
return FileManager.default.fileExists(atPath: path.path)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
static func saveDlcs(_ game: Game, dlc: [DownloadableContentContainer]) {
|
||||
guard let data = try? JSONEncoder().encode(dlc) else { return }
|
||||
try? data.write(to: dlcJsonPath(for: game))
|
||||
}
|
||||
|
||||
static func relativeDlcDirectoryPath(for game: Game, dlcPath: URL) -> String {
|
||||
"dlc/\(game.titleId)/\(dlcPath.lastPathComponent)"
|
||||
}
|
||||
|
||||
static func dlcJsonPath(for game: Game) -> URL {
|
||||
URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game.titleId).appendingPathComponent("dlc.json")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension URL {
|
||||
@available(iOS, introduced: 15.0, deprecated: 16.0, message: "Use URL.documentsDirectory on iOS 16 and above")
|
||||
static var documentsDirectory: URL {
|
||||
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
return documentDirectory
|
||||
}
|
||||
}
|
@ -1,201 +0,0 @@
|
||||
//
|
||||
// GameUpdateManagerSheet.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by Stossy11 on 16/02/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct UpdateManagerSheet: View {
|
||||
@State private var items: [String] = []
|
||||
@State private var paths: [URL] = []
|
||||
@State private var selectedItem: String? = nil
|
||||
@Binding var game: Game?
|
||||
@State private var isSelectingGameUpdate = false
|
||||
@State private var jsonURL: URL? = nil
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
List(paths, id: \..self, selection: $selectedItem) { item in
|
||||
Button(action: {
|
||||
selectItem(item.lastPathComponent)
|
||||
}) {
|
||||
HStack {
|
||||
Text(item.lastPathComponent)
|
||||
.foregroundStyle(Color(uiColor: .label))
|
||||
Spacer()
|
||||
if selectedItem == "updates/\(game!.titleId)/\(item.lastPathComponent)" {
|
||||
Image(systemName: "checkmark.circle.fill")
|
||||
.foregroundStyle(Color.accentColor)
|
||||
.font(.system(size: 24))
|
||||
} else {
|
||||
Image(systemName: "circle")
|
||||
.foregroundStyle(Color(uiColor: .secondaryLabel))
|
||||
.font(.system(size: 24))
|
||||
}
|
||||
}
|
||||
}
|
||||
.contextMenu {
|
||||
Button {
|
||||
removeUpdate(item)
|
||||
} label: {
|
||||
Text("Remove Update")
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
print(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json"))
|
||||
|
||||
loadJSON(URL.documentsDirectory.appendingPathComponent("games").appendingPathComponent(game!.titleId).appendingPathComponent("updates.json"))
|
||||
}
|
||||
.navigationTitle("\(game!.titleName) Updates")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
Button("Add", systemImage: "plus") {
|
||||
isSelectingGameUpdate = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.fileImporter(isPresented: $isSelectingGameUpdate, allowedContentTypes: [.item]) { result in
|
||||
switch result {
|
||||
case .success(let url):
|
||||
guard url.startAccessingSecurityScopedResource() else {
|
||||
print("Failed to access security-scoped resource")
|
||||
return
|
||||
}
|
||||
defer { url.stopAccessingSecurityScopedResource() }
|
||||
|
||||
let gameInfo = game!
|
||||
|
||||
do {
|
||||
let fileManager = FileManager.default
|
||||
let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
let updatedDirectory = documentsDirectory.appendingPathComponent("updates")
|
||||
let romUpdatedDirectory = updatedDirectory.appendingPathComponent(gameInfo.titleId)
|
||||
|
||||
if !fileManager.fileExists(atPath: updatedDirectory.path) {
|
||||
try fileManager.createDirectory(at: updatedDirectory, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
if !fileManager.fileExists(atPath: romUpdatedDirectory.path) {
|
||||
try fileManager.createDirectory(at: romUpdatedDirectory, withIntermediateDirectories: true, attributes: nil)
|
||||
}
|
||||
|
||||
let destinationURL = romUpdatedDirectory.appendingPathComponent(url.lastPathComponent)
|
||||
try? fileManager.copyItem(at: url, to: destinationURL)
|
||||
|
||||
items.append("updates/" + gameInfo.titleId + "/" + url.lastPathComponent)
|
||||
selectItem(url.lastPathComponent)
|
||||
Ryujinx.shared.games = Ryujinx.shared.loadGames()
|
||||
loadJSON(jsonURL!)
|
||||
} catch {
|
||||
print("Error copying game file: \(error)")
|
||||
}
|
||||
case .failure(let err):
|
||||
print("File import failed: \(err.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func removeUpdate(_ game: URL) {
|
||||
let gameString = "updates/\(self.game!.titleId)/\(game.lastPathComponent)"
|
||||
paths.removeAll { $0 == game }
|
||||
items.removeAll { $0 == gameString }
|
||||
|
||||
if selectedItem == gameString {
|
||||
selectedItem = nil
|
||||
}
|
||||
|
||||
do {
|
||||
try FileManager.default.removeItem(at: game)
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
|
||||
saveJSON(selectedItem: selectedItem ?? "")
|
||||
Ryujinx.shared.games = Ryujinx.shared.loadGames()
|
||||
}
|
||||
|
||||
func saveJSON(selectedItem: String?) {
|
||||
guard let jsonURL = jsonURL else { return }
|
||||
do {
|
||||
let jsonDict = ["paths": items, "selected": selectedItem ?? self.selectedItem ?? ""] as [String: Any]
|
||||
let newData = try JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)
|
||||
try newData.write(to: jsonURL)
|
||||
} catch {
|
||||
print("Failed to update JSON: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func loadJSON(_ json: URL) {
|
||||
self.jsonURL = json
|
||||
|
||||
guard let jsonURL else { return }
|
||||
|
||||
do {
|
||||
let data = try Data(contentsOf: jsonURL)
|
||||
if let jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
|
||||
let list = jsonDict["paths"] as? [String]
|
||||
{
|
||||
|
||||
let filteredList = list.filter { relativePath in
|
||||
let path = URL.documentsDirectory.appendingPathComponent(relativePath)
|
||||
return FileManager.default.fileExists(atPath: path.path)
|
||||
}
|
||||
|
||||
let urls: [URL] = filteredList.map { relativePath in
|
||||
URL.documentsDirectory.appendingPathComponent(relativePath)
|
||||
}
|
||||
|
||||
items = filteredList
|
||||
paths = urls
|
||||
selectedItem = jsonDict["selected"] as? String
|
||||
}
|
||||
} catch {
|
||||
print("Failed to read JSON: \(error)")
|
||||
createDefaultJSON()
|
||||
}
|
||||
}
|
||||
|
||||
func createDefaultJSON() {
|
||||
guard let jsonURL = jsonURL else { return }
|
||||
let defaultData: [String: Any] = ["selected": "", "paths": []]
|
||||
do {
|
||||
let newData = try JSONSerialization.data(withJSONObject: defaultData, options: .prettyPrinted)
|
||||
try newData.write(to: jsonURL)
|
||||
items = []
|
||||
selectedItem = ""
|
||||
} catch {
|
||||
print("Failed to create default JSON: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
func selectItem(_ item: String) {
|
||||
let newSelection = "updates/\(game!.titleId)/\(item)"
|
||||
|
||||
guard let jsonURL else { return }
|
||||
|
||||
do {
|
||||
let data = try Data(contentsOf: jsonURL)
|
||||
var jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] ?? [:]
|
||||
|
||||
if let currentSelected = jsonDict["selected"] as? String, currentSelected == newSelection {
|
||||
jsonDict["selected"] = ""
|
||||
selectedItem = ""
|
||||
} else {
|
||||
jsonDict["selected"] = "\(newSelection)"
|
||||
selectedItem = newSelection
|
||||
}
|
||||
|
||||
jsonDict["paths"] = items
|
||||
|
||||
let newData = try JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)
|
||||
try newData.write(to: jsonURL)
|
||||
Ryujinx.shared.games = Ryujinx.shared.loadGames()
|
||||
} catch {
|
||||
print("Failed to update JSON: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,337 @@
|
||||
//
|
||||
// GameDLCManagerSheet.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by XITRIX on 16/02/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
// MARK: - Models
|
||||
struct DownloadableContentNca: Codable, Hashable {
|
||||
var fullPath: String
|
||||
var titleId: UInt
|
||||
var enabled: Bool
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case fullPath = "path"
|
||||
case titleId = "title_id"
|
||||
case enabled = "is_enabled"
|
||||
}
|
||||
}
|
||||
|
||||
struct DownloadableContentContainer: Codable, Hashable, Identifiable {
|
||||
var id: String { containerPath }
|
||||
var containerPath: String
|
||||
var downloadableContentNcaList: [DownloadableContentNca]
|
||||
|
||||
var filename: String {
|
||||
(containerPath as NSString).lastPathComponent
|
||||
}
|
||||
|
||||
var isEnabled: Bool {
|
||||
downloadableContentNcaList.first?.enabled == true
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case containerPath = "path"
|
||||
case downloadableContentNcaList = "dlc_nca_list"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - View
|
||||
struct DLCManagerSheet: View {
|
||||
// MARK: - Properties
|
||||
@Binding var game: Game!
|
||||
@State private var isSelectingGameDLC = false
|
||||
@State private var dlcs: [DownloadableContentContainer] = []
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
// MARK: - Body
|
||||
var body: some View {
|
||||
iOSNav {
|
||||
List {
|
||||
if dlcs.isEmpty {
|
||||
emptyStateView
|
||||
} else {
|
||||
ForEach(dlcs) { dlc in
|
||||
dlcRow(dlc)
|
||||
}
|
||||
.onDelete(perform: removeDLCs)
|
||||
}
|
||||
}
|
||||
.navigationTitle("\(game.titleName) DLCs")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button("Done") {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button {
|
||||
isSelectingGameDLC = true
|
||||
} label: {
|
||||
Label("Add DLC", systemImage: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
.fileImporter(
|
||||
isPresented: $isSelectingGameDLC,
|
||||
allowedContentTypes: [.item],
|
||||
allowsMultipleSelection: true,
|
||||
onCompletion: handleFileImport
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Views
|
||||
private var emptyStateView: some View {
|
||||
Group {
|
||||
if #available(iOS 17, *) {
|
||||
ContentUnavailableView(
|
||||
"No DLCs Found",
|
||||
systemImage: "puzzlepiece.extension",
|
||||
description: Text("Tap the + button to add game DLCs.")
|
||||
)
|
||||
} else {
|
||||
VStack(spacing: 20) {
|
||||
Spacer()
|
||||
|
||||
Image(systemName: "puzzlepiece.extension")
|
||||
.font(.system(size: 64))
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
Text("No DLCs Found")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
|
||||
Text("Tap the + button to add game DLCs.")
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.horizontal)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.listRowInsets(EdgeInsets())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func dlcRow(_ dlc: DownloadableContentContainer) -> some View {
|
||||
Group {
|
||||
if #available(iOS 15.0, *) {
|
||||
Button {
|
||||
toggleDLC(dlc)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(dlc.filename)
|
||||
.foregroundColor(.primary)
|
||||
Spacer()
|
||||
Image(systemName: dlc.isEnabled ? "checkmark.circle.fill" : "circle")
|
||||
.foregroundColor(dlc.isEnabled ? .primary : .secondary)
|
||||
.imageScale(.large)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
if let index = dlcs.firstIndex(where: { $0.id == dlc.id }) {
|
||||
removeDLC(at: IndexSet(integer: index))
|
||||
}
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Button {
|
||||
toggleDLC(dlc)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(dlc.filename)
|
||||
.foregroundColor(.primary)
|
||||
Spacer()
|
||||
Image(systemName: dlc.isEnabled ? "checkmark.circle.fill" : "circle")
|
||||
.foregroundColor(dlc.isEnabled ? .primary : .secondary)
|
||||
.imageScale(.large)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.contextMenu {
|
||||
Button {
|
||||
if let index = dlcs.firstIndex(where: { $0.id == dlc.id }) {
|
||||
removeDLC(at: IndexSet(integer: index))
|
||||
}
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
private func loadData() {
|
||||
dlcs = Self.loadDlc(game)
|
||||
}
|
||||
|
||||
private func toggleDLC(_ dlc: DownloadableContentContainer) {
|
||||
guard let index = dlcs.firstIndex(where: { $0.id == dlc.id }) else { return }
|
||||
|
||||
let toggle = !dlcs[index].isEnabled
|
||||
dlcs[index].downloadableContentNcaList = dlcs[index].downloadableContentNcaList.map { nca in
|
||||
var mutableNca = nca
|
||||
mutableNca.enabled = toggle
|
||||
return mutableNca
|
||||
}
|
||||
|
||||
Self.saveDlcs(game, dlc: dlcs)
|
||||
}
|
||||
|
||||
private func removeDLCs(at offsets: IndexSet) {
|
||||
offsets.forEach { removeDLC(at: IndexSet(integer: $0)) }
|
||||
}
|
||||
|
||||
private func removeDLC(at indexSet: IndexSet) {
|
||||
guard let index = indexSet.first else { return }
|
||||
|
||||
let dlcToRemove = dlcs[index]
|
||||
let path = URL.documentsDirectory.appendingPathComponent(dlcToRemove.containerPath)
|
||||
|
||||
do {
|
||||
try FileManager.default.removeItem(at: path)
|
||||
dlcs.remove(at: index)
|
||||
Self.saveDlcs(game, dlc: dlcs)
|
||||
} catch {
|
||||
print("Failed to remove DLC: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
private func handleFileImport(result: Result<[URL], Error>) {
|
||||
switch result {
|
||||
case .success(let urls):
|
||||
for url in urls {
|
||||
importDLC(from: url)
|
||||
}
|
||||
case .failure(let error):
|
||||
print("File import failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
private func importDLC(from url: URL) {
|
||||
guard url.startAccessingSecurityScopedResource() else {
|
||||
print("Failed to access security-scoped resource")
|
||||
return
|
||||
}
|
||||
defer { url.stopAccessingSecurityScopedResource() }
|
||||
|
||||
do {
|
||||
let fileManager = FileManager.default
|
||||
let dlcDirectory = URL.documentsDirectory.appendingPathComponent("dlc")
|
||||
let gameDlcDirectory = dlcDirectory.appendingPathComponent(game.titleId)
|
||||
|
||||
try fileManager.createDirectory(at: gameDlcDirectory, withIntermediateDirectories: true)
|
||||
|
||||
// Copy the DLC file
|
||||
let destinationURL = gameDlcDirectory.appendingPathComponent(url.lastPathComponent)
|
||||
try? fileManager.removeItem(at: destinationURL)
|
||||
try fileManager.copyItem(at: url, to: destinationURL)
|
||||
|
||||
// Fetch DLC metadata from Ryujinx
|
||||
let dlcContent = Ryujinx.shared.getDlcNcaList(titleId: game.titleId, path: destinationURL.path)
|
||||
guard !dlcContent.isEmpty else {
|
||||
print("No valid DLC content found")
|
||||
return
|
||||
}
|
||||
|
||||
let newDlcContainer = DownloadableContentContainer(
|
||||
containerPath: Self.relativeDlcDirectoryPath(for: game, dlcPath: destinationURL),
|
||||
downloadableContentNcaList: dlcContent
|
||||
)
|
||||
|
||||
dlcs.append(newDlcContainer)
|
||||
Self.saveDlcs(game, dlc: dlcs)
|
||||
|
||||
} catch {
|
||||
print("Error importing DLC: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Helper Methods
|
||||
private extension DLCManagerSheet {
|
||||
static func loadDlc(_ game: Game) -> [DownloadableContentContainer] {
|
||||
let jsonURL = dlcJsonPath(for: game)
|
||||
|
||||
do {
|
||||
try FileManager.default.createDirectory(at: jsonURL.deletingLastPathComponent(), withIntermediateDirectories: true)
|
||||
|
||||
guard FileManager.default.fileExists(atPath: jsonURL.path),
|
||||
let data = try? Data(contentsOf: jsonURL),
|
||||
var result = try? JSONDecoder().decode([DownloadableContentContainer].self, from: data)
|
||||
else { return [] }
|
||||
|
||||
result = result.filter { container in
|
||||
let path = URL.documentsDirectory.appendingPathComponent(container.containerPath)
|
||||
return FileManager.default.fileExists(atPath: path.path)
|
||||
}
|
||||
|
||||
return result
|
||||
} catch {
|
||||
// print("Error loading DLCs: \(error)")
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
static func saveDlcs(_ game: Game, dlc: [DownloadableContentContainer]) {
|
||||
do {
|
||||
let data = try JSONEncoder().encode(dlc)
|
||||
try data.write(to: dlcJsonPath(for: game))
|
||||
} catch {
|
||||
print("Error saving DLCs: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
static func relativeDlcDirectoryPath(for game: Game, dlcPath: URL) -> String {
|
||||
"dlc/\(game.titleId)/\(dlcPath.lastPathComponent)"
|
||||
}
|
||||
|
||||
static func dlcJsonPath(for game: Game) -> URL {
|
||||
URL.documentsDirectory
|
||||
.appendingPathComponent("games")
|
||||
.appendingPathComponent(game.titleId)
|
||||
.appendingPathComponent("dlc.json")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Array Extension
|
||||
extension Array where Element: AnyObject {
|
||||
mutating func mutableForEach(_ body: (inout Element) -> Void) {
|
||||
for index in indices {
|
||||
var element = self[index]
|
||||
body(&element)
|
||||
self[index] = element
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - URL Extension
|
||||
extension URL {
|
||||
@available(iOS, introduced: 14.0, deprecated: 16.0, message: "Use URL.documentsDirectory on iOS 16 and above")
|
||||
static var documentsDirectory: URL {
|
||||
let documentDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
|
||||
return documentDirectory
|
||||
}
|
||||
}
|
@ -0,0 +1,335 @@
|
||||
//
|
||||
// GameUpdateManagerSheet.swift
|
||||
// MeloNX
|
||||
//
|
||||
// Created by Stossy11 on 16/02/2025.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
struct UpdateManagerSheet: View {
|
||||
// MARK: - Properties
|
||||
@State private var updates: [UpdateItem] = []
|
||||
@Binding var game: Game?
|
||||
@State private var isSelectingGameUpdate = false
|
||||
@State private var jsonURL: URL? = nil
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
// MARK: - Models
|
||||
class UpdateItem: Identifiable, ObservableObject {
|
||||
let id = UUID()
|
||||
let url: URL
|
||||
let filename: String
|
||||
let path: String
|
||||
|
||||
@Published var isSelected: Bool = false
|
||||
|
||||
init(url: URL, filename: String, path: String, isSelected: Bool = false) {
|
||||
self.url = url
|
||||
self.filename = filename
|
||||
self.path = path
|
||||
self.isSelected = isSelected
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
var body: some View {
|
||||
iOSNav {
|
||||
List {
|
||||
if updates.isEmpty {
|
||||
emptyStateView
|
||||
} else {
|
||||
ForEach(updates) { update in
|
||||
updateRow(update)
|
||||
}
|
||||
.onDelete(perform: removeUpdates)
|
||||
}
|
||||
}
|
||||
.navigationTitle("\(game?.titleName ?? "Game") Updates")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button("Done") {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button {
|
||||
isSelectingGameUpdate = true
|
||||
} label: {
|
||||
Label("Add Update", systemImage: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
loadData()
|
||||
}
|
||||
}
|
||||
.fileImporter(isPresented: $isSelectingGameUpdate, allowedContentTypes: [.item], onCompletion: handleFileImport)
|
||||
}
|
||||
|
||||
// MARK: - Views
|
||||
private var emptyStateView: some View {
|
||||
Group {
|
||||
if #available(iOS 17, *) {
|
||||
ContentUnavailableView(
|
||||
"No Updates Found",
|
||||
systemImage: "arrow.down.circle",
|
||||
description: Text("Tap the + button to add game updates.")
|
||||
)
|
||||
} else {
|
||||
VStack(spacing: 20) {
|
||||
Spacer()
|
||||
|
||||
Image(systemName: "arrow.down.circle")
|
||||
.font(.system(size: 64))
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
Text("No Updates Found")
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
|
||||
Text("Tap the + button to add game updates.")
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
.multilineTextAlignment(.center)
|
||||
.padding(.horizontal)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.listRowInsets(EdgeInsets())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func updateRow(_ update: UpdateItem) -> some View {
|
||||
Group {
|
||||
if #available(iOS 15, *) {
|
||||
updateRowNew(update)
|
||||
} else {
|
||||
updateRowOld(update)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 15, *)
|
||||
private func updateRowNew(_ update: UpdateItem) -> some View {
|
||||
Button {
|
||||
toggleSelection(update)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(update.filename)
|
||||
.foregroundColor(.primary)
|
||||
Spacer()
|
||||
Image(systemName: update.isSelected ? "checkmark.circle.fill" : "circle")
|
||||
.foregroundColor(update.isSelected ? .primary : .secondary)
|
||||
.imageScale(.large)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.swipeActions(edge: .trailing) {
|
||||
Button(role: .destructive) {
|
||||
if let index = updates.firstIndex(where: { $0.path == update.path }) {
|
||||
removeUpdate(at: IndexSet(integer: index))
|
||||
}
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func updateRowOld(_ update: UpdateItem) -> some View {
|
||||
Button {
|
||||
toggleSelection(update)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(update.filename)
|
||||
.foregroundColor(.primary)
|
||||
Spacer()
|
||||
Image(systemName: update.isSelected ? "checkmark.circle.fill" : "circle")
|
||||
.foregroundColor(update.isSelected ? .primary : .secondary)
|
||||
.imageScale(.large)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.contextMenu {
|
||||
Button {
|
||||
if let index = updates.firstIndex(where: { $0.path == update.path }) {
|
||||
removeUpdate(at: IndexSet(integer: index))
|
||||
}
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
private func loadData() {
|
||||
guard let game = game else { return }
|
||||
|
||||
let documentsDirectory = URL.documentsDirectory
|
||||
jsonURL = documentsDirectory
|
||||
.appendingPathComponent("games")
|
||||
.appendingPathComponent(game.titleId)
|
||||
.appendingPathComponent("updates.json")
|
||||
|
||||
loadJSON()
|
||||
}
|
||||
|
||||
private func loadJSON() {
|
||||
guard let jsonURL = jsonURL else { return }
|
||||
|
||||
do {
|
||||
if !FileManager.default.fileExists(atPath: jsonURL.path) {
|
||||
createDefaultJSON()
|
||||
return
|
||||
}
|
||||
|
||||
let data = try Data(contentsOf: jsonURL)
|
||||
if let jsonDict = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
|
||||
let paths = jsonDict["paths"] as? [String],
|
||||
let selected = jsonDict["selected"] as? String {
|
||||
|
||||
let filteredPaths = paths.filter { relativePath in
|
||||
let path = URL.documentsDirectory.appendingPathComponent(relativePath)
|
||||
return FileManager.default.fileExists(atPath: path.path)
|
||||
}
|
||||
|
||||
updates = filteredPaths.map { relativePath in
|
||||
let url = URL.documentsDirectory.appendingPathComponent(relativePath)
|
||||
return UpdateItem(
|
||||
url: url,
|
||||
filename: url.lastPathComponent,
|
||||
path: relativePath,
|
||||
isSelected: selected == relativePath
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
print("Failed to read JSON: \(error)")
|
||||
createDefaultJSON()
|
||||
}
|
||||
}
|
||||
|
||||
private func createDefaultJSON() {
|
||||
guard let jsonURL = jsonURL else { return }
|
||||
|
||||
do {
|
||||
try FileManager.default.createDirectory(at: jsonURL.deletingLastPathComponent(), withIntermediateDirectories: true)
|
||||
|
||||
let defaultData: [String: Any] = ["selected": "", "paths": []]
|
||||
let newData = try JSONSerialization.data(withJSONObject: defaultData, options: .prettyPrinted)
|
||||
try newData.write(to: jsonURL)
|
||||
updates = []
|
||||
} catch {
|
||||
print("Failed to create default JSON: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
private func handleFileImport(result: Result<URL, Error>) {
|
||||
switch result {
|
||||
case .success(let selectedURL):
|
||||
guard let game = game,
|
||||
selectedURL.startAccessingSecurityScopedResource() else {
|
||||
print("Failed to access security-scoped resource")
|
||||
return
|
||||
}
|
||||
|
||||
defer { selectedURL.stopAccessingSecurityScopedResource() }
|
||||
|
||||
do {
|
||||
let fileManager = FileManager.default
|
||||
let updatesDirectory = URL.documentsDirectory.appendingPathComponent("updates")
|
||||
let gameUpdatesDirectory = updatesDirectory.appendingPathComponent(game.titleId)
|
||||
|
||||
// Create directories if needed
|
||||
try fileManager.createDirectory(at: gameUpdatesDirectory, withIntermediateDirectories: true)
|
||||
|
||||
// Copy the file
|
||||
let destinationURL = gameUpdatesDirectory.appendingPathComponent(selectedURL.lastPathComponent)
|
||||
try? fileManager.removeItem(at: destinationURL) // Remove if exists
|
||||
try fileManager.copyItem(at: selectedURL, to: destinationURL)
|
||||
|
||||
// Add to updates
|
||||
let relativePath = "updates/\(game.titleId)/\(selectedURL.lastPathComponent)"
|
||||
let newUpdate = UpdateItem(
|
||||
url: destinationURL,
|
||||
filename: selectedURL.lastPathComponent,
|
||||
path: relativePath
|
||||
)
|
||||
|
||||
updates.append(newUpdate)
|
||||
toggleSelection(newUpdate)
|
||||
|
||||
// Reload games
|
||||
Ryujinx.shared.games = Ryujinx.shared.loadGames()
|
||||
} catch {
|
||||
print("Error copying update file: \(error)")
|
||||
}
|
||||
|
||||
case .failure(let error):
|
||||
print("File import failed: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
private func toggleSelection(_ update: UpdateItem) {
|
||||
print("toggle selection \(update.path)")
|
||||
|
||||
updates = updates.map { item in
|
||||
var mutableItem = item
|
||||
mutableItem.isSelected = item.path == update.path && !update.isSelected
|
||||
// print(mutableItem.isSelected)
|
||||
// print(update.isSelected)
|
||||
return mutableItem
|
||||
}
|
||||
|
||||
// print(updates)
|
||||
|
||||
saveJSON()
|
||||
}
|
||||
|
||||
private func removeUpdates(at offsets: IndexSet) {
|
||||
offsets.forEach { removeUpdate(at: IndexSet(integer: $0)) }
|
||||
}
|
||||
|
||||
private func removeUpdate(at indexSet: IndexSet) {
|
||||
guard let index = indexSet.first else { return }
|
||||
|
||||
let updateToRemove = updates[index]
|
||||
|
||||
do {
|
||||
// Remove the file
|
||||
try FileManager.default.removeItem(at: updateToRemove.url)
|
||||
|
||||
// Remove from updates array
|
||||
updates.remove(at: index)
|
||||
|
||||
// Save changes
|
||||
saveJSON()
|
||||
|
||||
// Reload games
|
||||
Ryujinx.shared.games = Ryujinx.shared.loadGames()
|
||||
} catch {
|
||||
print("Failed to remove update: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
private func saveJSON() {
|
||||
guard let jsonURL = jsonURL else { return }
|
||||
|
||||
do {
|
||||
let paths = updates.map { $0.path }
|
||||
let selected = updates.first(where: { $0.isSelected })?.path ?? ""
|
||||
|
||||
let jsonDict = ["paths": paths, "selected": selected] as [String: Any]
|
||||
let newData = try JSONSerialization.data(withJSONObject: jsonDict, options: .prettyPrinted)
|
||||
try newData.write(to: jsonURL)
|
||||
} catch {
|
||||
print("Failed to update JSON: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
@ -8,8 +8,15 @@
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
import CryptoKit
|
||||
import UniformTypeIdentifiers
|
||||
import AVFoundation
|
||||
|
||||
|
||||
extension UIDocumentPickerViewController {
|
||||
@objc func fix_init(forOpeningContentTypes contentTypes: [UTType], asCopy: Bool) -> UIDocumentPickerViewController {
|
||||
return fix_init(forOpeningContentTypes: contentTypes, asCopy: true)
|
||||
}
|
||||
}
|
||||
|
||||
@main
|
||||
struct MeloNXApp: App {
|
||||
@ -18,261 +25,91 @@ struct MeloNXApp: App {
|
||||
@Environment(\.scenePhase) var scenePhase
|
||||
@State var alert: UIAlertController? = nil
|
||||
|
||||
@State var showOutOfDateSheet = false
|
||||
@State var updateInfo: LatestVersionResponse? = nil
|
||||
|
||||
@State var finished = false
|
||||
@AppStorage("hasbeenfinished") var finishedStorage: Bool = false
|
||||
|
||||
@AppStorage("location-enabled") var locationenabled: Bool = false
|
||||
@AppStorage("checkForUpdate") var checkForUpdate: Bool = true
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ZStack {
|
||||
if showed || DRM != 1 {
|
||||
|
||||
if finishedStorage {
|
||||
ContentView()
|
||||
} else {
|
||||
SetupView(finished: $finished)
|
||||
.onChange(of: finished) { newValue in
|
||||
withAnimation {
|
||||
withAnimation {
|
||||
finishedStorage = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Group {
|
||||
VStack {
|
||||
Spacer()
|
||||
|
||||
HStack {
|
||||
Text("Loading...")
|
||||
ProgressView()
|
||||
}
|
||||
Spacer()
|
||||
|
||||
Text(UIDevice.current.identifierForVendor?.uuidString ?? "")
|
||||
}
|
||||
}
|
||||
if finishedStorage {
|
||||
ContentView()
|
||||
.onAppear {
|
||||
initR()
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(Color.black.opacity(1))
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func initR() {
|
||||
if DRM == 1 {
|
||||
DispatchQueue.main.async { [self] in
|
||||
// drmcheck()
|
||||
InitializeRyujinx() { bool in
|
||||
if bool {
|
||||
print("Ryujinx Files Initialized Successfully")
|
||||
DispatchQueue.main.async { [self] in
|
||||
withAnimation {
|
||||
showed = true
|
||||
}
|
||||
|
||||
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
|
||||
InitializeRyujinx() { bool in
|
||||
if !bool, (scenePhase != .background || scenePhase == .inactive) {
|
||||
withAnimation {
|
||||
showed = false
|
||||
}
|
||||
if !(alert?.isViewLoaded ?? false) {
|
||||
alert = showDMCAAlert()
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
alert?.dismiss(animated: true)
|
||||
showed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if checkForUpdate {
|
||||
checkLatestVersion()
|
||||
}
|
||||
|
||||
} else {
|
||||
showDMCAAlert()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
func showAlert() -> UIAlertController? {
|
||||
// Create the alert controller
|
||||
if let mainWindow = UIApplication.shared.windows.last {
|
||||
let alertController = UIAlertController(title: "Enter license", message: "Enter license key:", preferredStyle: .alert)
|
||||
|
||||
// Add a text field to the alert
|
||||
alertController.addTextField { textField in
|
||||
textField.placeholder = "Enter key here"
|
||||
}
|
||||
|
||||
// Add the "OK" action
|
||||
let okAction = UIAlertAction(title: "OK", style: .default) { _ in
|
||||
// Get the text entered in the text field
|
||||
if let textField = alertController.textFields?.first, let enteredText = textField.text {
|
||||
print("Entered text: \(enteredText)")
|
||||
UserDefaults.standard.set(enteredText, forKey: "MeloDRMID")
|
||||
// drmcheck() { bool in
|
||||
// if bool {
|
||||
// showed = true
|
||||
// } else {
|
||||
// exit(0)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
alertController.addAction(okAction)
|
||||
|
||||
// Add a "Cancel" action
|
||||
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
||||
alertController.addAction(cancelAction)
|
||||
|
||||
// Present the alert
|
||||
mainWindow.rootViewController!.present(alertController, animated: true, completion: nil)
|
||||
|
||||
return alertController
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func showDMCAAlert() -> UIAlertController? {
|
||||
if let mainWindow = UIApplication.shared.windows.first {
|
||||
let alertController = UIAlertController(title: "Unauthorized Copy Notice", message: "This app was illegally leaked. Please report the download on the MeloNX Discord. In the meantime, check out Pomelo! \n -Stossy11", preferredStyle: .alert)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
mainWindow.rootViewController!.present(alertController, animated: true, completion: nil)
|
||||
}
|
||||
|
||||
return alertController
|
||||
} else {
|
||||
// uhoh
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func drmcheck(completion: @escaping (Bool) -> Void) {
|
||||
if let deviceid = UIDevice.current.identifierForVendor?.uuidString, let base64device = deviceid.data(using: .utf8)?.base64EncodedString() {
|
||||
if let value = UserDefaults.standard.string(forKey: "MeloDRMID") {
|
||||
if let url = URL(string: "https://mx.stossy11.com/auth/\(value)/\(base64device)") {
|
||||
print(url)
|
||||
// Create a URLSession
|
||||
let session = URLSession.shared
|
||||
|
||||
// Create a data task
|
||||
let task = session.dataTask(with: url) { data, response, error in
|
||||
// Handle errors
|
||||
if let error = error {
|
||||
exit(0)
|
||||
.sheet(isPresented: Binding(
|
||||
get: { showOutOfDateSheet && updateInfo != nil },
|
||||
set: { newValue in
|
||||
if !newValue {
|
||||
showOutOfDateSheet = false
|
||||
updateInfo = nil
|
||||
}
|
||||
}
|
||||
)) {
|
||||
if let updateInfo = updateInfo {
|
||||
MeloNXUpdateSheet(updateInfo: updateInfo, isPresented: $showOutOfDateSheet)
|
||||
}
|
||||
}
|
||||
|
||||
// Check response and data
|
||||
if let response = response as? HTTPURLResponse, response.statusCode == 200 {
|
||||
print("Successfully Recieved API Data")
|
||||
completion(true)
|
||||
} else if let response = response as? HTTPURLResponse, response.statusCode == 201 {
|
||||
print("Successfully Created Auth UUID")
|
||||
completion(true)
|
||||
} else {
|
||||
completion(false)
|
||||
} else {
|
||||
SetupView(finished: $finished)
|
||||
.onChange(of: finished) { newValue in
|
||||
withAnimation {
|
||||
withAnimation {
|
||||
finishedStorage = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start the task
|
||||
task.resume()
|
||||
}
|
||||
} else {
|
||||
completion(false)
|
||||
}
|
||||
} else {
|
||||
completion(false)
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
func InitializeRyujinx(completion: @escaping (Bool) -> Void) {
|
||||
let path = "aHR0cHM6Ly9teC5zdG9zc3kxMS5jb20v"
|
||||
|
||||
guard let value = Bundle.main.object(forInfoDictionaryKey: "MeloID") as? String, !value.isEmpty else {
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (detectRoms(path: path) != value) {
|
||||
completion(false)
|
||||
}
|
||||
|
||||
let configuration = URLSessionConfiguration.default
|
||||
configuration.requestCachePolicy = .reloadIgnoringLocalAndRemoteCacheData
|
||||
configuration.urlCache = nil
|
||||
|
||||
let session = URLSession(configuration: configuration)
|
||||
|
||||
guard let url = URL(string: addFolders(path)!) else {
|
||||
completion(false)
|
||||
return
|
||||
}
|
||||
|
||||
let task = session.dataTask(with: url) { data, response, error in
|
||||
if error != nil {
|
||||
completion(false)
|
||||
}
|
||||
func checkLatestVersion() {
|
||||
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.0.0"
|
||||
let strippedAppVersion = appVersion.replacingOccurrences(of: ".", with: "")
|
||||
|
||||
#if DEBUG
|
||||
let urlString = "http://192.168.178.116:8000/api/latest_release"
|
||||
#else
|
||||
let urlString = "https://melonx.net/api/latest_release"
|
||||
#endif
|
||||
|
||||
guard let httpResponse = response as? HTTPURLResponse else {
|
||||
completion(false)
|
||||
guard let url = URL(string: urlString) else {
|
||||
// print("Invalid URL")
|
||||
return
|
||||
}
|
||||
|
||||
if httpResponse.statusCode == 200 {
|
||||
completion(true)
|
||||
} else {
|
||||
completion(false)
|
||||
let task = URLSession.shared.dataTask(with: url) { data, response, error in
|
||||
if let error = error {
|
||||
// print("Error checking for new version: \(error)")
|
||||
return
|
||||
}
|
||||
|
||||
guard let data = data else {
|
||||
// print("No data received")
|
||||
return
|
||||
}
|
||||
|
||||
do {
|
||||
let latestVersionResponse = try JSONDecoder().decode(LatestVersionResponse.self, from: data)
|
||||
let latestAPIVersionStripped = latestVersionResponse.version_number_stripped
|
||||
|
||||
if Int(strippedAppVersion) ?? 0 > Int(latestAPIVersionStripped) ?? 0 {
|
||||
DispatchQueue.main.async {
|
||||
updateInfo = latestVersionResponse
|
||||
showOutOfDateSheet = true
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// print("Failed to decode response: \(error)")
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
task.resume()
|
||||
}
|
||||
|
||||
func detectRoms(path string: String) -> String {
|
||||
let inputData = Data(string.utf8)
|
||||
let romHash = SHA256.hash(data: inputData)
|
||||
return romHash.compactMap { String(format: "%02x", $0) }.joined()
|
||||
}
|
||||
|
||||
|
||||
|
||||
func addFolders(_ folderPath: String) -> String? {
|
||||
let fileManager = FileManager.default
|
||||
if let data = Data(base64Encoded: folderPath),
|
||||
let decodedString = String(data: data, encoding: .utf8), let fileURL = UIDevice.current.identifierForVendor?.uuidString {
|
||||
return decodedString + "auth/" + fileURL + "/"
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
extension String {
|
||||
|
||||
func print() {
|
||||
Swift.print(self)
|
||||
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ struct SetupView: View {
|
||||
var body: some View {
|
||||
iOSNav {
|
||||
ZStack {
|
||||
if UIDevice.current.userInterfaceIdiom == .pad {
|
||||
if UIDevice.current.systemName.contains("iPadOS") {
|
||||
iPadSetupView(
|
||||
finished: $finished,
|
||||
isImportingKeys: $isImportingKeys,
|
||||
@ -54,18 +54,25 @@ struct SetupView: View {
|
||||
) { result in
|
||||
handleFirmwareImport(result: result)
|
||||
}
|
||||
.alert(alertMessage, isPresented: $showAlert) {
|
||||
Button("OK", role: .cancel) {}
|
||||
.alert(isPresented: $showAlert) {
|
||||
Alert(title: Text(alertMessage), dismissButton: .default(Text("OK")))
|
||||
}
|
||||
.alert("Skip Setup?", isPresented: $showSkipAlert) {
|
||||
Button("Skip", role: .destructive) { finished = true }
|
||||
Button("Cancel", role: .cancel) {}
|
||||
.alert(isPresented: $showSkipAlert) {
|
||||
Alert(
|
||||
title: Text("Skip Setup?"),
|
||||
primaryButton: .destructive(Text("Skip")) {
|
||||
finished = true
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
)
|
||||
}
|
||||
.onAppear {
|
||||
initialize()
|
||||
finished = false
|
||||
keysImported = Ryujinx.shared.checkIfKeysImported()
|
||||
firmImported = (Ryujinx.shared.fetchFirmwareVersion() != "0")
|
||||
|
||||
let firmware = Ryujinx.shared.fetchFirmwareVersion()
|
||||
firmImported = (firmware == "" ? "0" : firmware) != "0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,6 +123,9 @@ struct SetupView: View {
|
||||
.font(.title)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(.primary)
|
||||
.onTapGesture(count: 2) {
|
||||
showSkipAlert = true
|
||||
}
|
||||
|
||||
Text("Set up your Nintendo Switch emulation environment by importing keys and firmware.")
|
||||
.font(.subheadline)
|
||||
@ -365,8 +375,8 @@ struct SetupView: View {
|
||||
|
||||
Ryujinx.shared.installFirmware(firmwarePath: fileURL.path)
|
||||
|
||||
|
||||
firmImported = (Ryujinx.shared.fetchFirmwareVersion() != "0")
|
||||
let firmware = Ryujinx.shared.fetchFirmwareVersion()
|
||||
firmImported = (firmware == "" ? "0" : firmware) != "0"
|
||||
alertMessage = "Firmware installed successfully"
|
||||
showAlert = true
|
||||
|
||||
@ -385,7 +395,7 @@ struct SetupView: View {
|
||||
|
||||
let iconFileName = iconFiles.last else {
|
||||
|
||||
print("Could not find icons in bundle")
|
||||
// print("Could not find icons in bundle")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 100 KiB |
Binary file not shown.
@ -0,0 +1,6 @@
|
||||
framework module RyujinxHelper {
|
||||
umbrella header "RyujinxHelper.h"
|
||||
export *
|
||||
|
||||
module * { export * }
|
||||
}
|
Binary file not shown.
@ -4,22 +4,22 @@
|
||||
<dict>
|
||||
<key>files</key>
|
||||
<dict>
|
||||
<key>Headers/RyujinxKeyboard.h</key>
|
||||
<key>Headers/RyujinxHelper.h</key>
|
||||
<data>
|
||||
5P7GN4g050n199pV6/+SpfMBgJc=
|
||||
</data>
|
||||
<key>Info.plist</key>
|
||||
<data>
|
||||
hYdI/ktAKwjBSfaJpt6Yc8UKLCY=
|
||||
UOH9NuuEcz5NQiQlrM2LNFaG2pI=
|
||||
</data>
|
||||
<key>Modules/module.modulemap</key>
|
||||
<data>
|
||||
0kFAMoTn+4Q1J/dM6uMLe3EhbL0=
|
||||
JDij7psMD6pZZpigUfkSQldib+I=
|
||||
</data>
|
||||
</dict>
|
||||
<key>files2</key>
|
||||
<dict>
|
||||
<key>Headers/RyujinxKeyboard.h</key>
|
||||
<key>Headers/RyujinxHelper.h</key>
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
@ -30,7 +30,7 @@
|
||||
<dict>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
K+ZyxKhTI4bMVZuHBIspvd2PFqvCOlVUFYmwF96O5NQ=
|
||||
5t/lQcpkzC5bwJqFQqIf6h1ldlhHouYzDawRVrnUeyM=
|
||||
</data>
|
||||
</dict>
|
||||
</dict>
|
@ -1,6 +0,0 @@
|
||||
framework module RyujinxKeyboard {
|
||||
umbrella header "RyujinxKeyboard.h"
|
||||
export *
|
||||
|
||||
module * { export * }
|
||||
}
|
Binary file not shown.
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>AvailableLibraries</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>BinaryPath</key>
|
||||
<string>MoltenVK.framework/MoltenVK</string>
|
||||
<key>LibraryIdentifier</key>
|
||||
<string>ios-arm64</string>
|
||||
<key>LibraryPath</key>
|
||||
<string>MoltenVK.framework</string>
|
||||
<key>SupportedArchitectures</key>
|
||||
<array>
|
||||
<string>arm64</string>
|
||||
</array>
|
||||
<key>SupportedPlatform</key>
|
||||
<string>ios</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>XFWK</string>
|
||||
<key>XCFrameworkFormatVersion</key>
|
||||
<string>1.0</string>
|
||||
</dict>
|
||||
</plist>
|
Binary file not shown.
Binary file not shown.
@ -38,8 +38,9 @@
|
||||
</array>
|
||||
<key>UIBackgroundModes</key>
|
||||
<array>
|
||||
<string>audio</string>
|
||||
<string>location</string>
|
||||
<string>processing</string>
|
||||
<string>audio</string>
|
||||
</array>
|
||||
<key>UIFileSharingEnabled</key>
|
||||
<true/>
|
||||
|
@ -72,5 +72,6 @@ namespace Ryujinx.Common.Logging
|
||||
TamperMachine,
|
||||
UI,
|
||||
Vic,
|
||||
Memory,
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,14 @@ using Ryujinx.Memory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
{
|
||||
class NoWxCache : IDisposable
|
||||
{
|
||||
private const int CodeAlignment = 4; // Bytes.
|
||||
private const int SharedCacheSize = 2047 * 1024 * 1024;
|
||||
private const int SharedCacheSize = 512 * 1024 * 1024;
|
||||
private const int LocalCacheSize = 128 * 1024 * 1024;
|
||||
|
||||
// How many calls to the same function we allow until we pad the shared cache to force the function to become available there
|
||||
@ -21,12 +22,14 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
{
|
||||
private readonly ReservedRegion _region;
|
||||
private readonly CacheMemoryAllocator _cacheAllocator;
|
||||
public readonly IJitMemoryAllocator Allocator;
|
||||
|
||||
public CacheMemoryAllocator Allocator => _cacheAllocator;
|
||||
public CacheMemoryAllocator CacheAllocator => _cacheAllocator;
|
||||
public IntPtr Pointer => _region.Block.Pointer;
|
||||
|
||||
public MemoryCache(IJitMemoryAllocator allocator, ulong size)
|
||||
{
|
||||
Allocator = allocator;
|
||||
_region = new(allocator, size);
|
||||
_cacheAllocator = new((int)size);
|
||||
}
|
||||
@ -101,9 +104,9 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
|
||||
private readonly IStackWalker _stackWalker;
|
||||
private readonly Translator _translator;
|
||||
private readonly MemoryCache _sharedCache;
|
||||
private readonly MemoryCache _localCache;
|
||||
private readonly PageAlignedRangeList _pendingMap;
|
||||
private readonly List<MemoryCache> _sharedCaches;
|
||||
private readonly List<MemoryCache> _localCaches;
|
||||
private readonly Dictionary<ulong, PageAlignedRangeList> _pendingMaps;
|
||||
private readonly object _lock;
|
||||
|
||||
class ThreadLocalCacheEntry
|
||||
@ -111,13 +114,15 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
public readonly int Offset;
|
||||
public readonly int Size;
|
||||
public readonly IntPtr FuncPtr;
|
||||
public readonly int CacheIndex;
|
||||
private int _useCount;
|
||||
|
||||
public ThreadLocalCacheEntry(int offset, int size, IntPtr funcPtr)
|
||||
public ThreadLocalCacheEntry(int offset, int size, IntPtr funcPtr, int cacheIndex)
|
||||
{
|
||||
Offset = offset;
|
||||
Size = size;
|
||||
FuncPtr = funcPtr;
|
||||
CacheIndex = cacheIndex;
|
||||
_useCount = 0;
|
||||
}
|
||||
|
||||
@ -134,12 +139,87 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
{
|
||||
_stackWalker = stackWalker;
|
||||
_translator = translator;
|
||||
_sharedCache = new(allocator, SharedCacheSize);
|
||||
_localCache = new(allocator, LocalCacheSize);
|
||||
_pendingMap = new(_sharedCache.ReprotectAsRx, RegisterFunction);
|
||||
_sharedCaches = new List<MemoryCache> { new(allocator, SharedCacheSize) };
|
||||
_localCaches = new List<MemoryCache> { new(allocator, LocalCacheSize) };
|
||||
_pendingMaps = new Dictionary<ulong, PageAlignedRangeList>();
|
||||
_lock = new();
|
||||
}
|
||||
|
||||
private PageAlignedRangeList GetPendingMapForCache(int cacheIndex)
|
||||
{
|
||||
ulong cacheKey = (ulong)cacheIndex;
|
||||
if (!_pendingMaps.TryGetValue(cacheKey, out var pendingMap))
|
||||
{
|
||||
pendingMap = new PageAlignedRangeList(
|
||||
(offset, size) => _sharedCaches[cacheIndex].ReprotectAsRx(offset, size),
|
||||
(address, func) => RegisterFunction(address, func));
|
||||
_pendingMaps[cacheKey] = pendingMap;
|
||||
}
|
||||
return pendingMap;
|
||||
}
|
||||
|
||||
private bool HasInAnyPendingMap(ulong guestAddress)
|
||||
{
|
||||
foreach (var pendingMap in _pendingMaps.Values)
|
||||
{
|
||||
if (pendingMap.Has(guestAddress))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int AllocateInSharedCache(int codeLength)
|
||||
{
|
||||
for (int i = 0; i < _sharedCaches.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (i << 28) | _sharedCaches[i].Allocate(codeLength);
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
// Try next cache
|
||||
}
|
||||
}
|
||||
|
||||
// All existing caches are full, create a new one
|
||||
lock (_lock)
|
||||
{
|
||||
var allocator = _sharedCaches[0].Allocator;
|
||||
_sharedCaches.Add(new(allocator, SharedCacheSize));
|
||||
return (_sharedCaches.Count - 1) << 28 | _sharedCaches[_sharedCaches.Count - 1].Allocate(codeLength);
|
||||
}
|
||||
}
|
||||
|
||||
private int AllocateInLocalCache(int codeLength)
|
||||
{
|
||||
for (int i = 0; i < _localCaches.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (i << 28) | _localCaches[i].Allocate(codeLength);
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
var allocator = _localCaches[0].Allocator;
|
||||
_localCaches.Add(new(allocator, LocalCacheSize));
|
||||
return (_localCaches.Count - 1) << 28 | _localCaches[_localCaches.Count - 1].Allocate(codeLength);
|
||||
}
|
||||
}
|
||||
|
||||
private static (int cacheIndex, int offset) SplitCacheOffset(int combinedOffset)
|
||||
{
|
||||
return (combinedOffset >> 28, combinedOffset & 0xFFFFFFF);
|
||||
}
|
||||
|
||||
public unsafe IntPtr Map(IntPtr framePointer, ReadOnlySpan<byte> code, ulong guestAddress, ulong guestSize)
|
||||
{
|
||||
if (TryGetThreadLocalFunction(guestAddress, out IntPtr funcPtr))
|
||||
@ -149,16 +229,18 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
if (!_pendingMap.Has(guestAddress) && !_translator.Functions.ContainsKey(guestAddress))
|
||||
if (!HasInAnyPendingMap(guestAddress) && !_translator.Functions.ContainsKey(guestAddress))
|
||||
{
|
||||
int funcOffset = _sharedCache.Allocate(code.Length);
|
||||
|
||||
funcPtr = _sharedCache.Pointer + funcOffset;
|
||||
int combinedOffset = AllocateInSharedCache(code.Length);
|
||||
var (cacheIndex, funcOffset) = SplitCacheOffset(combinedOffset);
|
||||
|
||||
MemoryCache cache = _sharedCaches[cacheIndex];
|
||||
funcPtr = cache.Pointer + funcOffset;
|
||||
code.CopyTo(new Span<byte>((void*)funcPtr, code.Length));
|
||||
|
||||
TranslatedFunction function = new(funcPtr, guestSize);
|
||||
|
||||
_pendingMap.Add(funcOffset, code.Length, guestAddress, function);
|
||||
|
||||
GetPendingMapForCache(cacheIndex).Add(funcOffset, code.Length, guestAddress, function);
|
||||
}
|
||||
|
||||
ClearThreadLocalCache(framePointer);
|
||||
@ -171,25 +253,63 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
int cacheIndex;
|
||||
int funcOffset;
|
||||
IntPtr mappedFuncPtr = IntPtr.Zero;
|
||||
|
||||
for (cacheIndex = 0; cacheIndex < _sharedCaches.Count; cacheIndex++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pendingMap = GetPendingMapForCache(cacheIndex);
|
||||
|
||||
pendingMap.Pad(_sharedCaches[cacheIndex].CacheAllocator);
|
||||
|
||||
int sizeAligned = BitUtils.AlignUp(code.Length, (int)MemoryBlock.GetPageSize());
|
||||
funcOffset = _sharedCaches[cacheIndex].Allocate(sizeAligned);
|
||||
|
||||
Debug.Assert((funcOffset & ((int)MemoryBlock.GetPageSize() - 1)) == 0);
|
||||
|
||||
IntPtr funcPtr1 = _sharedCaches[cacheIndex].Pointer + funcOffset;
|
||||
code.CopyTo(new Span<byte>((void*)funcPtr1, code.Length));
|
||||
|
||||
_sharedCaches[cacheIndex].ReprotectAsRx(funcOffset, sizeAligned);
|
||||
|
||||
return funcPtr1;
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
// Try next cache
|
||||
}
|
||||
}
|
||||
|
||||
// All existing caches are full, create a new one
|
||||
var allocator = _sharedCaches[0].Allocator;
|
||||
var newCache = new MemoryCache(allocator, SharedCacheSize);
|
||||
_sharedCaches.Add(newCache);
|
||||
cacheIndex = _sharedCaches.Count - 1;
|
||||
|
||||
var newPendingMap = GetPendingMapForCache(cacheIndex);
|
||||
|
||||
// Ensure we will get an aligned offset from the allocator.
|
||||
_pendingMap.Pad(_sharedCache.Allocator);
|
||||
|
||||
int sizeAligned = BitUtils.AlignUp(code.Length, (int)MemoryBlock.GetPageSize());
|
||||
int funcOffset = _sharedCache.Allocate(sizeAligned);
|
||||
newPendingMap.Pad(newCache.CacheAllocator);
|
||||
|
||||
int newSizeAligned = BitUtils.AlignUp(code.Length, (int)MemoryBlock.GetPageSize());
|
||||
funcOffset = newCache.Allocate(newSizeAligned);
|
||||
|
||||
Debug.Assert((funcOffset & ((int)MemoryBlock.GetPageSize() - 1)) == 0);
|
||||
|
||||
IntPtr funcPtr = _sharedCache.Pointer + funcOffset;
|
||||
IntPtr funcPtr = newCache.Pointer + funcOffset;
|
||||
code.CopyTo(new Span<byte>((void*)funcPtr, code.Length));
|
||||
|
||||
_sharedCache.ReprotectAsRx(funcOffset, sizeAligned);
|
||||
newCache.ReprotectAsRx(funcOffset, newSizeAligned);
|
||||
|
||||
return funcPtr;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryGetThreadLocalFunction(ulong guestAddress, out IntPtr funcPtr)
|
||||
{
|
||||
{
|
||||
if ((_threadLocalCache ??= new()).TryGetValue(guestAddress, out var entry))
|
||||
{
|
||||
if (entry.IncrementUseCount() >= MinCallsForPad)
|
||||
@ -200,7 +320,15 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_pendingMap.Pad(_sharedCache.Allocator);
|
||||
foreach (var pendingMap in _pendingMaps.Values)
|
||||
{
|
||||
// Get the cache index from the pendingMap key
|
||||
if (_pendingMaps.FirstOrDefault(x => x.Value == pendingMap).Key is ulong cacheIndex)
|
||||
{
|
||||
// Use the correct shared cache for padding based on the cache index
|
||||
pendingMap.Pad(_sharedCaches[(int)cacheIndex].CacheAllocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -224,12 +352,36 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
return;
|
||||
}
|
||||
|
||||
IEnumerable<ulong> callStack = _stackWalker.GetCallStack(
|
||||
framePointer,
|
||||
_localCache.Pointer,
|
||||
LocalCacheSize,
|
||||
_sharedCache.Pointer,
|
||||
SharedCacheSize);
|
||||
IntPtr[] cachePointers = new IntPtr[_localCaches.Count];
|
||||
int[] cacheSizes = new int[_localCaches.Count];
|
||||
|
||||
for (int i = 0; i < _localCaches.Count; i++)
|
||||
{
|
||||
cachePointers[i] = _localCaches[i].Pointer;
|
||||
cacheSizes[i] = LocalCacheSize;
|
||||
}
|
||||
|
||||
IntPtr[] sharedPointers = new IntPtr[_sharedCaches.Count];
|
||||
int[] sharedSizes = new int[_sharedCaches.Count];
|
||||
|
||||
for (int i = 0; i < _sharedCaches.Count; i++)
|
||||
{
|
||||
sharedPointers[i] = _sharedCaches[i].Pointer;
|
||||
sharedSizes[i] = SharedCacheSize;
|
||||
}
|
||||
|
||||
// Iterate over the arrays and pass each element to GetCallStack
|
||||
IEnumerable<ulong> callStack = null;
|
||||
for (int i = 0; i < _localCaches.Count; i++)
|
||||
{
|
||||
callStack = _stackWalker.GetCallStack(
|
||||
framePointer,
|
||||
cachePointers[i], // Passing each individual cachePointer
|
||||
cacheSizes[i], // Passing each individual cacheSize
|
||||
sharedPointers[i], // Passing each individual sharedPointer
|
||||
sharedSizes[i] // Passing each individual sharedSize
|
||||
);
|
||||
}
|
||||
|
||||
List<(ulong, ThreadLocalCacheEntry)> toDelete = new();
|
||||
|
||||
@ -237,7 +389,7 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
{
|
||||
// We only want to delete if the function is already on the shared cache,
|
||||
// otherwise we will keep translating the same function over and over again.
|
||||
bool canDelete = !_pendingMap.Has(address);
|
||||
bool canDelete = !HasInAnyPendingMap(address);
|
||||
if (!canDelete)
|
||||
{
|
||||
continue;
|
||||
@ -267,12 +419,14 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
_threadLocalCache.Remove(address);
|
||||
|
||||
int sizeAligned = BitUtils.AlignUp(entry.Size, pageSize);
|
||||
var (cacheIndex, offset) = SplitCacheOffset(entry.Offset);
|
||||
|
||||
_localCache.Free(entry.Offset, sizeAligned);
|
||||
_localCache.ReprotectAsRw(entry.Offset, sizeAligned);
|
||||
_localCaches[cacheIndex].Free(offset, sizeAligned);
|
||||
_localCaches[cacheIndex].ReprotectAsRw(offset, sizeAligned);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ClearEntireThreadLocalCache()
|
||||
{
|
||||
// Thread is exiting, delete everything.
|
||||
@ -287,9 +441,10 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
foreach ((_, ThreadLocalCacheEntry entry) in _threadLocalCache)
|
||||
{
|
||||
int sizeAligned = BitUtils.AlignUp(entry.Size, pageSize);
|
||||
var (cacheIndex, offset) = SplitCacheOffset(entry.Offset);
|
||||
|
||||
_localCache.Free(entry.Offset, sizeAligned);
|
||||
_localCache.ReprotectAsRw(entry.Offset, sizeAligned);
|
||||
_localCaches[cacheIndex].Free(offset, sizeAligned);
|
||||
_localCaches[cacheIndex].ReprotectAsRw(offset, sizeAligned);
|
||||
}
|
||||
|
||||
_threadLocalCache.Clear();
|
||||
@ -299,16 +454,17 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
private unsafe IntPtr AddThreadLocalFunction(ReadOnlySpan<byte> code, ulong guestAddress)
|
||||
{
|
||||
int alignedSize = BitUtils.AlignUp(code.Length, (int)MemoryBlock.GetPageSize());
|
||||
int funcOffset = _localCache.Allocate(alignedSize);
|
||||
int combinedOffset = AllocateInLocalCache(alignedSize);
|
||||
var (cacheIndex, funcOffset) = SplitCacheOffset(combinedOffset);
|
||||
|
||||
Debug.Assert((funcOffset & (int)(MemoryBlock.GetPageSize() - 1)) == 0);
|
||||
|
||||
IntPtr funcPtr = _localCache.Pointer + funcOffset;
|
||||
IntPtr funcPtr = _localCaches[cacheIndex].Pointer + funcOffset;
|
||||
code.CopyTo(new Span<byte>((void*)funcPtr, code.Length));
|
||||
|
||||
(_threadLocalCache ??= new()).Add(guestAddress, new(funcOffset, code.Length, funcPtr));
|
||||
(_threadLocalCache ??= new()).Add(guestAddress, new(funcOffset, code.Length, funcPtr, cacheIndex));
|
||||
|
||||
_localCache.ReprotectAsRx(funcOffset, alignedSize);
|
||||
_localCaches[cacheIndex].ReprotectAsRx(funcOffset, alignedSize);
|
||||
|
||||
return funcPtr;
|
||||
}
|
||||
@ -326,8 +482,18 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_localCache.Dispose();
|
||||
_sharedCache.Dispose();
|
||||
foreach (var cache in _localCaches)
|
||||
{
|
||||
cache.Dispose();
|
||||
}
|
||||
|
||||
foreach (var cache in _sharedCaches)
|
||||
{
|
||||
cache.Dispose();
|
||||
}
|
||||
|
||||
_localCaches.Clear();
|
||||
_sharedCaches.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,4 +503,4 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -606,26 +606,67 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
{
|
||||
return new TextureView(_gd, _device, info, Storage, FirstLayer + firstLayer, FirstLevel + firstLevel);
|
||||
}
|
||||
|
||||
|
||||
public byte[] GetData(int x, int y, int width, int height)
|
||||
{
|
||||
const int MaxChunkSize = 1024 * 1024 * 96; // 96MB Chunks
|
||||
|
||||
int size = width * height * Info.BytesPerPixel;
|
||||
using var bufferHolder = _gd.BufferManager.Create(_gd, size);
|
||||
|
||||
using (var cbs = _gd.CommandBufferPool.Rent())
|
||||
{
|
||||
var buffer = bufferHolder.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
|
||||
var image = GetImage().Get(cbs).Value;
|
||||
|
||||
CopyFromOrToBuffer(cbs.CommandBuffer, buffer, image, size, true, 0, 0, x, y, width, height);
|
||||
}
|
||||
|
||||
bufferHolder.WaitForFences();
|
||||
byte[] bitmap = new byte[size];
|
||||
GetDataFromBuffer(bufferHolder.GetDataStorage(0, size), size, Span<byte>.Empty).CopyTo(bitmap);
|
||||
|
||||
if (size <= MaxChunkSize)
|
||||
{
|
||||
using var bufferHolder = _gd.BufferManager.Create(_gd, size);
|
||||
using (var cbs = _gd.CommandBufferPool.Rent())
|
||||
{
|
||||
var buffer = bufferHolder.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
|
||||
var image = GetImage().Get(cbs).Value;
|
||||
CopyFromOrToBuffer(cbs.CommandBuffer, buffer, image, size, true, 0, 0, x, y, width, height);
|
||||
}
|
||||
|
||||
bufferHolder.WaitForFences();
|
||||
GetDataFromBuffer(bufferHolder.GetDataStorage(0, size), size, Span<byte>.Empty).CopyTo(bitmap);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
||||
int dataPerPixel = Info.BytesPerPixel;
|
||||
int rowStride = width * dataPerPixel;
|
||||
int rowsPerChunk = Math.Max(1, MaxChunkSize / rowStride);
|
||||
int originalHeight = height;
|
||||
int currentY = y;
|
||||
int bitmapOffset = 0;
|
||||
|
||||
while (currentY < y + originalHeight)
|
||||
{
|
||||
int chunkHeight = Math.Min(rowsPerChunk, y + originalHeight - currentY);
|
||||
|
||||
if (chunkHeight <= 0)
|
||||
break;
|
||||
|
||||
int chunkSize = chunkHeight * rowStride;
|
||||
|
||||
// Process this chunk
|
||||
using var bufferHolder = _gd.BufferManager.Create(_gd, chunkSize);
|
||||
using (var cbs = _gd.CommandBufferPool.Rent())
|
||||
{
|
||||
var buffer = bufferHolder.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
|
||||
var image = GetImage().Get(cbs).Value;
|
||||
CopyFromOrToBuffer(cbs.CommandBuffer, buffer, image, chunkSize, true, 0, 0, x, currentY, width, chunkHeight);
|
||||
}
|
||||
|
||||
bufferHolder.WaitForFences();
|
||||
GetDataFromBuffer(bufferHolder.GetDataStorage(0, chunkSize), chunkSize, Span<byte>.Empty)
|
||||
.CopyTo(new Span<byte>(bitmap, bitmapOffset, chunkSize));
|
||||
|
||||
currentY += chunkHeight;
|
||||
bitmapOffset += chunkSize;
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
||||
public PinnedSpan<byte> GetData()
|
||||
{
|
||||
BackgroundResource resources = _gd.BackgroundResources.Get();
|
||||
@ -738,14 +779,28 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
return GetDataFromBuffer(result, size, result);
|
||||
}
|
||||
|
||||
private ReadOnlySpan<byte> GetData(CommandBufferPool cbp, PersistentFlushBuffer flushBuffer, int layer, int level)
|
||||
private ReadOnlySpan<byte> GetData(CommandBufferPool cbp, PersistentFlushBuffer flushBuffer, int layer = 0, int level = 0)
|
||||
{
|
||||
const int MaxChunkSize = 1024 * 1024 * 96; // 96MB Chunks
|
||||
|
||||
int size = GetBufferDataLength(Info.GetMipSize(level));
|
||||
|
||||
Span<byte> result = flushBuffer.GetTextureData(cbp, this, size, layer, level);
|
||||
return GetDataFromBuffer(result, size, result);
|
||||
if (size <= MaxChunkSize)
|
||||
{
|
||||
Span<byte> result = flushBuffer.GetTextureData(cbp, this, size, layer, level);
|
||||
return GetDataFromBuffer(result, size, result);
|
||||
}
|
||||
|
||||
byte[] fullResult = new byte[size];
|
||||
|
||||
Span<byte> fullTextureData = flushBuffer.GetTextureData(cbp, this, size, layer, level);
|
||||
|
||||
GetDataFromBuffer(fullTextureData, size, fullTextureData).CopyTo(fullResult);
|
||||
|
||||
return fullResult;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SetData(MemoryOwner<byte> data)
|
||||
{
|
||||
@ -769,46 +824,167 @@ namespace Ryujinx.Graphics.Vulkan
|
||||
|
||||
private void SetData(ReadOnlySpan<byte> data, int layer, int level, int layers, int levels, bool singleSlice, Rectangle<int>? region = null)
|
||||
{
|
||||
const int MaxChunkSize = 1024 * 1024 * 96; // 96MB Chunks
|
||||
|
||||
int bufferDataLength = GetBufferDataLength(data.Length);
|
||||
|
||||
using var bufferHolder = _gd.BufferManager.Create(_gd, bufferDataLength);
|
||||
|
||||
Auto<DisposableImage> imageAuto = GetImage();
|
||||
|
||||
// Load texture data inline if the texture has been used on the current command buffer.
|
||||
|
||||
bool loadInline = Storage.HasCommandBufferDependency(_gd.PipelineInternal.CurrentCommandBuffer);
|
||||
|
||||
var cbs = loadInline ? _gd.PipelineInternal.CurrentCommandBuffer : _gd.PipelineInternal.GetPreloadCommandBuffer();
|
||||
|
||||
if (loadInline)
|
||||
|
||||
if (bufferDataLength <= MaxChunkSize)
|
||||
{
|
||||
_gd.PipelineInternal.EndRenderPass();
|
||||
ProcessChunk(data, layer, level, layers, levels, singleSlice, region);
|
||||
return;
|
||||
}
|
||||
|
||||
CopyDataToBuffer(bufferHolder.GetDataStorage(0, bufferDataLength), data);
|
||||
|
||||
var buffer = bufferHolder.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
|
||||
var image = imageAuto.Get(cbs).Value;
|
||||
|
||||
if (region.HasValue)
|
||||
|
||||
if (!region.HasValue && !singleSlice && layers > 1)
|
||||
{
|
||||
CopyFromOrToBuffer(
|
||||
cbs.CommandBuffer,
|
||||
buffer,
|
||||
image,
|
||||
bufferDataLength,
|
||||
false,
|
||||
layer,
|
||||
level,
|
||||
region.Value.X,
|
||||
region.Value.Y,
|
||||
region.Value.Width,
|
||||
region.Value.Height);
|
||||
int layerSize = data.Length / layers;
|
||||
int offset = 0;
|
||||
|
||||
for (int i = 0; i < layers; i++)
|
||||
{
|
||||
if (offset >= data.Length)
|
||||
break;
|
||||
|
||||
int currentLayer = layer + i;
|
||||
int currentLayerSize = Math.Min(layerSize, data.Length - offset);
|
||||
|
||||
if (currentLayerSize <= 0)
|
||||
break;
|
||||
|
||||
try
|
||||
{
|
||||
var layerData = data.Slice(offset, currentLayerSize);
|
||||
ProcessChunk(layerData, currentLayer, level, 1, levels, true);
|
||||
offset += layerSize;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (region.HasValue)
|
||||
{
|
||||
var rect = region.Value;
|
||||
|
||||
if (rect.Width <= 0 || rect.Height <= 0)
|
||||
return;
|
||||
|
||||
int dataPerPixel = data.Length / (rect.Width * rect.Height);
|
||||
|
||||
if (dataPerPixel <= 0)
|
||||
return;
|
||||
|
||||
int rowStride = rect.Width * dataPerPixel;
|
||||
|
||||
int rowsPerChunk = Math.Max(1, MaxChunkSize / rowStride);
|
||||
int originalHeight = rect.Height;
|
||||
int currentY = rect.Y;
|
||||
int offset = 0;
|
||||
|
||||
while (currentY < rect.Y + originalHeight)
|
||||
{
|
||||
int chunkHeight = Math.Min(rowsPerChunk, rect.Y + originalHeight - currentY);
|
||||
|
||||
if (chunkHeight <= 0)
|
||||
break;
|
||||
|
||||
var chunkRegion = new Rectangle<int>(rect.X, currentY, rect.Width, chunkHeight);
|
||||
|
||||
int chunkSize = chunkHeight * rowStride;
|
||||
|
||||
if (offset >= data.Length)
|
||||
break;
|
||||
|
||||
int safeChunkSize = Math.Min(chunkSize, data.Length - offset);
|
||||
|
||||
if (safeChunkSize <= 0)
|
||||
break;
|
||||
|
||||
try
|
||||
{
|
||||
var chunkData = data.Slice(offset, safeChunkSize);
|
||||
ProcessChunk(chunkData, layer, level, 1, 1, true, chunkRegion);
|
||||
|
||||
currentY += chunkHeight;
|
||||
offset += chunkSize;
|
||||
}
|
||||
catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyFromOrToBuffer(cbs.CommandBuffer, buffer, image, bufferDataLength, false, layer, level, layers, levels, singleSlice);
|
||||
ProcessChunk(data, layer, level, layers, levels, singleSlice, region);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessChunk(ReadOnlySpan<byte> chunkData, int chunkLayer, int chunkLevel, int chunkLayers, int chunkLevels, bool chunkSingleSlice, Rectangle<int>? chunkRegion = null)
|
||||
{
|
||||
int chunkBufferLength = GetBufferDataLength(chunkData.Length);
|
||||
|
||||
if (chunkBufferLength <= 0)
|
||||
return;
|
||||
|
||||
using var bufferHolder = _gd.BufferManager.Create(_gd, chunkBufferLength);
|
||||
|
||||
using (var imageAuto = GetImage())
|
||||
{
|
||||
bool loadInline = Storage.HasCommandBufferDependency(_gd.PipelineInternal.CurrentCommandBuffer);
|
||||
var cbs = loadInline ? _gd.PipelineInternal.CurrentCommandBuffer : _gd.PipelineInternal.GetPreloadCommandBuffer();
|
||||
|
||||
if (loadInline)
|
||||
{
|
||||
_gd.PipelineInternal.EndRenderPass();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CopyDataToBuffer(bufferHolder.GetDataStorage(0, chunkBufferLength), chunkData);
|
||||
|
||||
var buffer = bufferHolder.GetBuffer(cbs.CommandBuffer).Get(cbs).Value;
|
||||
var image = imageAuto.Get(cbs).Value;
|
||||
|
||||
if (chunkRegion.HasValue)
|
||||
{
|
||||
var region = chunkRegion.Value;
|
||||
|
||||
if (region.Width <= 0 || region.Height <= 0)
|
||||
return;
|
||||
|
||||
CopyFromOrToBuffer(
|
||||
cbs.CommandBuffer,
|
||||
buffer,
|
||||
image,
|
||||
chunkBufferLength,
|
||||
false,
|
||||
chunkLayer,
|
||||
chunkLevel,
|
||||
region.X,
|
||||
region.Y,
|
||||
region.Width,
|
||||
region.Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
CopyFromOrToBuffer(
|
||||
cbs.CommandBuffer,
|
||||
buffer,
|
||||
image,
|
||||
chunkBufferLength,
|
||||
false,
|
||||
chunkLayer,
|
||||
chunkLevel,
|
||||
chunkLayers,
|
||||
chunkLevels,
|
||||
chunkSingleSlice);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
_npads.NpadButtonDownEvent += HandleNpadButtonDownEvent;
|
||||
_npads.NpadButtonUpEvent += HandleNpadButtonUpEvent;
|
||||
|
||||
_keyboardRenderer = new SoftwareKeyboardRenderer(_device.UIHandler.HostUITheme);
|
||||
// _keyboardRenderer = new SoftwareKeyboardRenderer(_device.UIHandler.HostUITheme);
|
||||
}
|
||||
|
||||
return ResultCode.Success;
|
||||
@ -177,9 +177,9 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
{
|
||||
_npads?.Update();
|
||||
|
||||
_keyboardRenderer?.SetSurfaceInfo(surfaceInfo);
|
||||
// _keyboardRenderer?.SetSurfaceInfo(surfaceInfo);
|
||||
|
||||
return _keyboardRenderer?.DrawTo(destination, position) ?? false;
|
||||
return true; // _keyboardRenderer?.DrawTo(destination, position) ?? false;
|
||||
}
|
||||
|
||||
|
||||
@ -239,6 +239,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
StringLengthMax = _keyboardForegroundConfig.StringLengthMax,
|
||||
InitialText = initialText,
|
||||
};
|
||||
|
||||
_device.UIHandler.DisplayInputDialog(args, inputText =>
|
||||
{
|
||||
Console.WriteLine($"User entered: {inputText}");
|
||||
@ -470,7 +471,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
if (updateText)
|
||||
{
|
||||
_dynamicTextInputHandler.SetText(_textValue, _cursorBegin);
|
||||
_keyboardRenderer.UpdateTextState(_textValue, _cursorBegin, _cursorBegin, null, null);
|
||||
// _keyboardRenderer.UpdateTextState(_textValue, _cursorBegin, _cursorBegin, null, null);
|
||||
}
|
||||
|
||||
if ((newCalc.Flags & KeyboardCalcFlags.MustShow) != 0)
|
||||
@ -515,8 +516,8 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
|
||||
_dynamicTextInputHandler.TextProcessingEnabled = true;
|
||||
|
||||
_keyboardRenderer.UpdateCommandState(null, null, true);
|
||||
_keyboardRenderer.UpdateTextState(null, null, null, null, true);
|
||||
// _keyboardRenderer.UpdateCommandState(null, null, true);
|
||||
// _keyboardRenderer.UpdateTextState(null, null, null, null, true);
|
||||
}
|
||||
|
||||
private void DeactivateFrontend()
|
||||
@ -534,7 +535,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
{
|
||||
Logger.Debug?.Print(LogClass.ServiceAm, "Destroying software keyboard frontend");
|
||||
|
||||
_keyboardRenderer?.Dispose();
|
||||
// _keyboardRenderer?.Dispose();
|
||||
_keyboardRenderer = null;
|
||||
|
||||
if (_dynamicTextInputHandler != null)
|
||||
@ -568,8 +569,8 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
|
||||
_dynamicTextInputHandler.TextProcessingEnabled = typingEnabled;
|
||||
|
||||
_keyboardRenderer.UpdateTextState(null, null, null, null, typingEnabled);
|
||||
_keyboardRenderer.UpdateCommandState(null, null, controllerEnabled);
|
||||
// _keyboardRenderer.UpdateTextState(null, null, null, null, typingEnabled);
|
||||
// _keyboardRenderer.UpdateCommandState(null, null, controllerEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -596,7 +597,7 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
|
||||
_textValue = text;
|
||||
_cursorBegin = cursorBegin;
|
||||
_keyboardRenderer.UpdateTextState(text, cursorBegin, cursorEnd, overwriteMode, null);
|
||||
// _keyboardRenderer.UpdateTextState(text, cursorBegin, cursorEnd, overwriteMode, null);
|
||||
|
||||
PushUpdatedState(text, cursorBegin, KeyboardResult.NotSet);
|
||||
}
|
||||
@ -614,10 +615,10 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
switch (button)
|
||||
{
|
||||
case NpadButton.A:
|
||||
_keyboardRenderer.UpdateCommandState(_canAcceptController, null, null);
|
||||
// _keyboardRenderer.UpdateCommandState(_canAcceptController, null, null);
|
||||
break;
|
||||
case NpadButton.B:
|
||||
_keyboardRenderer.UpdateCommandState(null, _canAcceptController, null);
|
||||
// _keyboardRenderer.UpdateCommandState(null, _canAcceptController, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -633,11 +634,11 @@ namespace Ryujinx.HLE.HOS.Applets
|
||||
{
|
||||
case NpadButton.A:
|
||||
result = KeyboardResult.Accept;
|
||||
_keyboardRenderer.UpdateCommandState(false, null, null);
|
||||
// _keyboardRenderer.UpdateCommandState(false, null, null);
|
||||
break;
|
||||
case NpadButton.B:
|
||||
result = KeyboardResult.Cancel;
|
||||
_keyboardRenderer.UpdateCommandState(null, false, null);
|
||||
// _keyboardRenderer.UpdateCommandState(null, false, null);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ namespace Ryujinx.HLE.HOS.Applets.SoftwareKeyboard
|
||||
{
|
||||
_renderer = new SoftwareKeyboardRendererBase(uiTheme);
|
||||
|
||||
StartTextBoxBlinker(_textBoxBlinkTimedAction, _state, _stateLock);
|
||||
StartRenderer(_renderAction, _renderer, _state, _stateLock);
|
||||
// StartTextBoxBlinker(_textBoxBlinkTimedAction, _state, _stateLock);
|
||||
// StartRenderer(_renderAction, _renderer, _state, _stateLock);
|
||||
}
|
||||
|
||||
private static void StartTextBoxBlinker(TimedAction timedAction, SoftwareKeyboardUIState state, object stateLock)
|
||||
|
@ -561,7 +561,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
|
||||
|
||||
context.ResponseData.Write((int)_gyroscopeZeroDriftMode);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, sixAxisSensorHandle, _gyroscopeZeroDriftMode });
|
||||
// Logger.Stub?.PrintStub(LogClass.ServiceHid, new { appletResourceUserId, sixAxisSensorHandle, _gyroscopeZeroDriftMode });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ namespace Ryujinx.HLE
|
||||
|
||||
MemoryAllocationFlags memoryAllocationFlags = configuration.MemoryManagerMode == MemoryManagerMode.SoftwarePageTable
|
||||
? MemoryAllocationFlags.Reserve
|
||||
: MemoryAllocationFlags.Reserve | MemoryAllocationFlags.Mirrorable;
|
||||
: MemoryAllocationFlags.Reserve; // | MemoryAllocationFlags.Mirrorable;
|
||||
|
||||
#pragma warning disable IDE0055 // Disable formatting
|
||||
AudioDeviceDriver = AddAudioCompatLayers(Configuration.AudioDeviceDriver);
|
||||
|
@ -29,6 +29,17 @@ namespace Ryujinx.Headless.SDL2
|
||||
[Option("exclusive-fullscreen-height", Required = false, Default = 1080, HelpText = "Set vertical resolution for exclusive fullscreen mode.")]
|
||||
public int ExclusiveFullscreenHeight { get; set; }
|
||||
|
||||
// Host Information
|
||||
|
||||
[Option("device-model", Required = false, HelpText = "Set the current iDevice Model")]
|
||||
public string DeviceModel { get; set; }
|
||||
|
||||
[Option("has-memory-entitlement", Required = false, HelpText = "If the increased memory entitlement exists.")]
|
||||
public bool MemoryEnt { get; set; }
|
||||
|
||||
[Option("device-display-name", Required = false, HelpText = "Set the current iDevice display name.")]
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
// Input
|
||||
|
||||
[Option("correct-controller", Required = false, Default = false, HelpText = "Makes the on-screen controller (iOS) buttons correspond to what they show.")]
|
||||
@ -196,7 +207,7 @@ namespace Ryujinx.Headless.SDL2
|
||||
[Option("aspect-ratio", Required = false, Default = AspectRatio.Fixed16x9, HelpText = "Aspect Ratio applied to the renderer window.")]
|
||||
public AspectRatio AspectRatio { get; set; }
|
||||
|
||||
[Option("backend-threading", Required = false, Default = BackendThreading.Auto, HelpText = "Whether or not backend threading is enabled. The \"Auto\" setting will determine whether threading should be enabled at runtime.")]
|
||||
[Option("backend-threading", Required = false, Default = BackendThreading.On, HelpText = "Whether or not backend threading is enabled. The \"Auto\" setting will determine whether threading should be enabled at runtime.")]
|
||||
public BackendThreading BackendThreading { get; set; }
|
||||
|
||||
[Option("disable-macro-hle", Required = false, HelpText = "Disables high-level emulation of Macro code. Leaving this enabled improves performance but may cause graphical glitches in some games.")]
|
||||
|
@ -251,21 +251,21 @@ namespace Ryujinx.Headless.SDL2
|
||||
[UnmanagedCallersOnly(EntryPoint = "get_current_fps")]
|
||||
public static unsafe int GetFPS()
|
||||
{
|
||||
if (_window != null) {
|
||||
Switch Device = _window.Device;
|
||||
if (_window == null || _window.Device == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int intValue = (int)Device.Statistics.GetGameFrameRate();
|
||||
Switch Device = _window.Device;
|
||||
|
||||
return intValue;
|
||||
}
|
||||
return 0;
|
||||
|
||||
int intValue = (int)Device.Statistics.GetGameFrameRate();
|
||||
|
||||
return intValue;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "initialize")]
|
||||
public static unsafe void Initialize()
|
||||
{
|
||||
|
||||
AppDataManager.Initialize(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
|
||||
|
||||
if (_virtualFileSystem == null)
|
||||
@ -403,10 +403,22 @@ namespace Ryujinx.Headless.SDL2
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "stop_emulation")]
|
||||
public static void StopEmulation()
|
||||
public static void StopEmulation(bool shouldPause)
|
||||
{
|
||||
if (_window != null)
|
||||
{
|
||||
if (!shouldPause)
|
||||
{
|
||||
_window.Device.SetVolume(1);
|
||||
_window._isPaused = false;
|
||||
_window._pauseEvent.Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
_window.Device.SetVolume(0);
|
||||
_window._isPaused = true;
|
||||
_window._pauseEvent.Reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -886,19 +898,9 @@ namespace Ryujinx.Headless.SDL2
|
||||
{
|
||||
if (inputId == null)
|
||||
{
|
||||
if (index == PlayerIndex.Player1)
|
||||
{
|
||||
Logger.Info?.Print(LogClass.Application, $"{index} not configured, defaulting to default keyboard.");
|
||||
Logger.Info?.Print(LogClass.Application, $"{index} not configured");
|
||||
|
||||
// Default to keyboard
|
||||
inputId = "0";
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Info?.Print(LogClass.Application, $"{index} not configured");
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
IGamepad gamepad;
|
||||
@ -987,14 +989,28 @@ namespace Ryujinx.Headless.SDL2
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isNintendoStyle = gamepadName.Contains("Nintendo") || gamepadName.Contains("Joycons");
|
||||
bool isNintendoStyle = true; // gamepadName.Contains("Nintendo") || gamepadName.Contains("Joycons");
|
||||
|
||||
ControllerType currentController;
|
||||
if (index == PlayerIndex.Handheld)
|
||||
{
|
||||
currentController = ControllerType.Handheld;
|
||||
}
|
||||
else if (gamepadName.Contains("Joycons") || gamepadName.Contains("Backbone"))
|
||||
{
|
||||
currentController = ControllerType.JoyconPair;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentController = ControllerType.ProController;
|
||||
}
|
||||
|
||||
config = new StandardControllerInputConfig
|
||||
{
|
||||
Version = InputConfig.CurrentVersion,
|
||||
Backend = InputBackendType.GamepadSDL2,
|
||||
Id = null,
|
||||
ControllerType = ControllerType.JoyconPair,
|
||||
ControllerType = currentController,
|
||||
DeadzoneLeft = 0.1f,
|
||||
DeadzoneRight = 0.1f,
|
||||
RangeLeft = 1.0f,
|
||||
@ -1153,6 +1169,11 @@ namespace Ryujinx.Headless.SDL2
|
||||
_inputManager = new InputManager(new SDL2KeyboardDriver(), new SDL2GamepadDriver());
|
||||
}
|
||||
|
||||
if (OperatingSystem.IsIOS()) {
|
||||
Logger.Info?.Print(LogClass.Application, $"Current Device: {option.DisplayName} ({option.DeviceModel}) {Environment.OSVersion.Version}");
|
||||
Logger.Info?.Print(LogClass.Application, $"Increased Memory Limit: {option.MemoryEnt}");
|
||||
}
|
||||
|
||||
GraphicsConfig.EnableShaderCache = true;
|
||||
|
||||
if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS())
|
||||
|
@ -44,6 +44,9 @@ namespace Ryujinx.Headless.SDL2
|
||||
_mainThreadActions.Enqueue(action);
|
||||
}
|
||||
|
||||
public bool _isPaused;
|
||||
public ManualResetEvent _pauseEvent;
|
||||
|
||||
public NpadManager NpadManager;
|
||||
public TouchScreenManager TouchScreenManager;
|
||||
public Switch Device;
|
||||
@ -104,6 +107,7 @@ namespace Ryujinx.Headless.SDL2
|
||||
_gpuCancellationTokenSource = new CancellationTokenSource();
|
||||
_exitEvent = new ManualResetEvent(false);
|
||||
_gpuDoneEvent = new ManualResetEvent(false);
|
||||
_pauseEvent = new ManualResetEvent(true);
|
||||
_aspectRatio = aspectRatio;
|
||||
_enableMouse = enableMouse;
|
||||
HostUITheme = new HeadlessHostUiTheme();
|
||||
@ -298,6 +302,8 @@ namespace Ryujinx.Headless.SDL2
|
||||
return;
|
||||
}
|
||||
|
||||
_pauseEvent.WaitOne();
|
||||
|
||||
_ticks += _chrono.ElapsedTicks;
|
||||
|
||||
_chrono.Restart();
|
||||
@ -378,7 +384,6 @@ namespace Ryujinx.Headless.SDL2
|
||||
{
|
||||
while (_isActive)
|
||||
{
|
||||
|
||||
UpdateFrame();
|
||||
|
||||
SDL_PumpEvents();
|
||||
@ -486,7 +491,12 @@ namespace Ryujinx.Headless.SDL2
|
||||
|
||||
public bool DisplayMessageDialog(string title, string message)
|
||||
{
|
||||
SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, title, message, WindowHandle);
|
||||
if (OperatingSystem.IsIOS())
|
||||
{
|
||||
AlertHelper.ShowAlert(title, message, false);
|
||||
} else {
|
||||
SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, title, message, WindowHandle);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,13 +7,16 @@ namespace Ryujinx.Headless.SDL2
|
||||
{
|
||||
public static class AlertHelper
|
||||
{
|
||||
[DllImport("RyujinxKeyboard.framework/RyujinxKeyboard", CallingConvention = CallingConvention.Cdecl)]
|
||||
[DllImport("RyujinxHelper.framework/RyujinxHelper", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void showKeyboardAlert(string title, string message, string placeholder);
|
||||
|
||||
[DllImport("RyujinxKeyboard.framework/RyujinxKeyboard", CallingConvention = CallingConvention.Cdecl)]
|
||||
[DllImport("RyujinxHelper.framework/RyujinxHelper", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void showAlert(string title, string message, bool showCancel);
|
||||
|
||||
[DllImport("RyujinxHelper.framework/RyujinxHelper", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern IntPtr getKeyboardInput();
|
||||
|
||||
[DllImport("RyujinxKeyboard.framework/RyujinxKeyboard", CallingConvention = CallingConvention.Cdecl)]
|
||||
[DllImport("RyujinxHelper.framework/RyujinxHelper", CallingConvention = CallingConvention.Cdecl)]
|
||||
private static extern void clearKeyboardInput();
|
||||
|
||||
public static void ShowAlertWithTextInput(string title, string message, string placeholder, Action<string> onTextEntered)
|
||||
@ -38,5 +41,10 @@ namespace Ryujinx.Headless.SDL2
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void ShowAlert(string title, string message, bool cancel) {
|
||||
showAlert(title, message, cancel);
|
||||
}
|
||||
}
|
||||
}
|
@ -9,8 +9,18 @@ namespace Ryujinx.Input.SDL2
|
||||
{
|
||||
private readonly Dictionary<int, string> _gamepadsInstanceIdsMapping;
|
||||
private readonly List<string> _gamepadsIds;
|
||||
private readonly object _lock = new object();
|
||||
|
||||
public ReadOnlySpan<string> GamepadsIds => _gamepadsIds.ToArray();
|
||||
public ReadOnlySpan<string> GamepadsIds
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return _gamepadsIds.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string DriverName => "SDL2";
|
||||
|
||||
@ -35,7 +45,7 @@ namespace Ryujinx.Input.SDL2
|
||||
}
|
||||
}
|
||||
|
||||
private static string GenerateGamepadId(int joystickIndex)
|
||||
private string GenerateGamepadId(int joystickIndex)
|
||||
{
|
||||
Guid guid = SDL_JoystickGetDeviceGUID(joystickIndex);
|
||||
|
||||
@ -44,14 +54,16 @@ namespace Ryujinx.Input.SDL2
|
||||
return null;
|
||||
}
|
||||
|
||||
// Include joystickIndex at the start of the ID to maintain compatibility with GetJoystickIndexByGamepadId
|
||||
return joystickIndex + "-" + guid;
|
||||
}
|
||||
|
||||
private static int GetJoystickIndexByGamepadId(string id)
|
||||
private int GetJoystickIndexByGamepadId(string id)
|
||||
{
|
||||
string[] data = id.Split("-");
|
||||
|
||||
if (data.Length != 6 || !int.TryParse(data[0], out int joystickIndex))
|
||||
// Parse the joystick index from the ID string
|
||||
if (data.Length < 2 || !int.TryParse(data[0], out int joystickIndex))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -64,7 +76,11 @@ namespace Ryujinx.Input.SDL2
|
||||
if (_gamepadsInstanceIdsMapping.TryGetValue(joystickInstanceId, out string id))
|
||||
{
|
||||
_gamepadsInstanceIdsMapping.Remove(joystickInstanceId);
|
||||
_gamepadsIds.Remove(id);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
_gamepadsIds.Remove(id);
|
||||
}
|
||||
|
||||
OnGamepadDisconnected?.Invoke(id);
|
||||
}
|
||||
@ -74,6 +90,13 @@ namespace Ryujinx.Input.SDL2
|
||||
{
|
||||
if (SDL_IsGameController(joystickDeviceId) == SDL_bool.SDL_TRUE)
|
||||
{
|
||||
if (_gamepadsInstanceIdsMapping.ContainsKey(joystickInstanceId))
|
||||
{
|
||||
// Sometimes a JoyStick connected event fires after the app starts even though it was connected before
|
||||
// so it is rejected to avoid doubling the entries.
|
||||
return;
|
||||
}
|
||||
|
||||
string id = GenerateGamepadId(joystickDeviceId);
|
||||
|
||||
if (id == null)
|
||||
@ -81,16 +104,21 @@ namespace Ryujinx.Input.SDL2
|
||||
return;
|
||||
}
|
||||
|
||||
// Sometimes a JoyStick connected event fires after the app starts even though it was connected before
|
||||
// so it is rejected to avoid doubling the entries.
|
||||
if (_gamepadsIds.Contains(id))
|
||||
// Check if we already have this gamepad ID in our list
|
||||
lock (_lock)
|
||||
{
|
||||
return;
|
||||
if (_gamepadsIds.Contains(id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_gamepadsInstanceIdsMapping.TryAdd(joystickInstanceId, id))
|
||||
{
|
||||
_gamepadsIds.Add(id);
|
||||
lock (_lock)
|
||||
{
|
||||
_gamepadsIds.Add(id);
|
||||
}
|
||||
|
||||
OnGamepadConnected?.Invoke(id);
|
||||
}
|
||||
@ -103,13 +131,17 @@ namespace Ryujinx.Input.SDL2
|
||||
{
|
||||
SDL2Driver.Instance.OnJoyStickConnected -= HandleJoyStickConnected;
|
||||
SDL2Driver.Instance.OnJoystickDisconnected -= HandleJoyStickDisconnected;
|
||||
|
||||
|
||||
// Simulate a full disconnect when disposing
|
||||
foreach (string id in _gamepadsIds)
|
||||
{
|
||||
OnGamepadDisconnected?.Invoke(id);
|
||||
}
|
||||
|
||||
_gamepadsIds.Clear();
|
||||
lock (_lock)
|
||||
{
|
||||
_gamepadsIds.Clear();
|
||||
}
|
||||
|
||||
SDL2Driver.Instance.Dispose();
|
||||
}
|
||||
@ -130,11 +162,6 @@ namespace Ryujinx.Input.SDL2
|
||||
return null;
|
||||
}
|
||||
|
||||
if (id != GenerateGamepadId(joystickIndex))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
IntPtr gamepadHandle = SDL_GameControllerOpen(joystickIndex);
|
||||
|
||||
if (gamepadHandle == IntPtr.Zero)
|
||||
@ -145,4 +172,4 @@ namespace Ryujinx.Input.SDL2
|
||||
return new SDL2Gamepad(gamepadHandle, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user