Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f8ec878796 | ||
|
9ff21f9ab6 | ||
|
aa021085cf | ||
|
1f5d881860 | ||
|
1f664100bd | ||
|
1f5e1ffa80 |
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT_DIR=$(dirname $(realpath $0))
|
||||
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
||||
RYUJINX_BIN="Ryujinx"
|
||||
|
||||
if [ -f "$SCRIPT_DIR/Ryujinx.Ava" ]; then
|
||||
|
@@ -10,6 +10,7 @@ using Ryujinx.Ava.UI.Helpers;
|
||||
using Ryujinx.Ava.UI.ViewModels;
|
||||
using Ryujinx.Ava.UI.Windows;
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.HLE.HOS;
|
||||
using Ryujinx.Ui.Common.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -36,7 +37,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
viewModel.SelectedApplication.Favorite = !viewModel.SelectedApplication.Favorite;
|
||||
|
||||
@@ -51,9 +52,10 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
|
||||
public void OpenUserSaveDirectory_Click(object sender, RoutedEventArgs args)
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
OpenSaveDirectory(viewModel, SaveDataType.Account, userId: new UserId((ulong)viewModel.AccountManager.LastOpenedUser.UserId.High, (ulong)viewModel.AccountManager.LastOpenedUser.UserId.Low));
|
||||
if ((sender as MenuItem)?.DataContext is MainWindowViewModel viewModel)
|
||||
{
|
||||
OpenSaveDirectory(viewModel, SaveDataType.Account, userId: new UserId((ulong)viewModel.AccountManager.LastOpenedUser.UserId.High, (ulong)viewModel.AccountManager.LastOpenedUser.UserId.Low));
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenDeviceSaveDirectory_Click(object sender, RoutedEventArgs args)
|
||||
@@ -70,9 +72,9 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
OpenSaveDirectory(viewModel, SaveDataType.Bcat, userId: default);
|
||||
}
|
||||
|
||||
private void OpenSaveDirectory(MainWindowViewModel viewModel, SaveDataType saveDataType, UserId userId)
|
||||
private static void OpenSaveDirectory(MainWindowViewModel viewModel, SaveDataType saveDataType, UserId userId)
|
||||
{
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
if (!ulong.TryParse(viewModel.SelectedApplication.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong titleIdNumber))
|
||||
{
|
||||
@@ -94,7 +96,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
await TitleUpdateWindow.Show(viewModel.VirtualFileSystem, ulong.Parse(viewModel.SelectedApplication.TitleId, NumberStyles.HexNumber), viewModel.SelectedApplication.TitleName);
|
||||
}
|
||||
@@ -104,7 +106,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
await DownloadableContentManagerWindow.Show(viewModel.VirtualFileSystem, ulong.Parse(viewModel.SelectedApplication.TitleId, NumberStyles.HexNumber), viewModel.SelectedApplication.TitleName);
|
||||
}
|
||||
@@ -114,7 +116,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
await new CheatWindow(viewModel.VirtualFileSystem, viewModel.SelectedApplication.TitleId, viewModel.SelectedApplication.TitleName).ShowDialog(viewModel.TopLevel as Window);
|
||||
}
|
||||
@@ -124,10 +126,10 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
string modsBasePath = viewModel.VirtualFileSystem.ModLoader.GetModsBasePath();
|
||||
string titleModsPath = viewModel.VirtualFileSystem.ModLoader.GetTitleDir(modsBasePath, viewModel.SelectedApplication.TitleId);
|
||||
string modsBasePath = ModLoader.GetModsBasePath();
|
||||
string titleModsPath = ModLoader.GetTitleDir(modsBasePath, viewModel.SelectedApplication.TitleId);
|
||||
|
||||
OpenHelper.OpenFolder(titleModsPath);
|
||||
}
|
||||
@@ -137,10 +139,10 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
string sdModsBasePath = viewModel.VirtualFileSystem.ModLoader.GetSdModsBasePath();
|
||||
string titleModsPath = viewModel.VirtualFileSystem.ModLoader.GetTitleDir(sdModsBasePath, viewModel.SelectedApplication.TitleId);
|
||||
string sdModsBasePath = ModLoader.GetSdModsBasePath();
|
||||
string titleModsPath = ModLoader.GetTitleDir(sdModsBasePath, viewModel.SelectedApplication.TitleId);
|
||||
|
||||
OpenHelper.OpenFolder(titleModsPath);
|
||||
}
|
||||
@@ -150,7 +152,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
UserResult result = await ContentDialogHelper.CreateConfirmationDialog(LocaleManager.Instance[LocaleKeys.DialogWarning],
|
||||
LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogPPTCDeletionMessage, viewModel.SelectedApplication.TitleName),
|
||||
@@ -197,7 +199,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
UserResult result = await ContentDialogHelper.CreateConfirmationDialog(LocaleManager.Instance[LocaleKeys.DialogWarning],
|
||||
LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogShaderDeletionMessage, viewModel.SelectedApplication.TitleName),
|
||||
@@ -253,7 +255,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
string ptcDir = Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.TitleId, "cache", "cpu");
|
||||
string mainDir = Path.Combine(ptcDir, "0");
|
||||
@@ -274,7 +276,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
string shaderCacheDir = Path.Combine(AppDataManager.GamesDirPath, viewModel.SelectedApplication.TitleId, "cache", "shader");
|
||||
|
||||
@@ -291,7 +293,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
await ApplicationHelper.ExtractSection(NcaSectionType.Logo, viewModel.SelectedApplication.Path, viewModel.SelectedApplication.TitleName);
|
||||
}
|
||||
@@ -301,7 +303,7 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
await ApplicationHelper.ExtractSection(NcaSectionType.Data, viewModel.SelectedApplication.Path, viewModel.SelectedApplication.TitleName);
|
||||
}
|
||||
@@ -311,10 +313,10 @@ namespace Ryujinx.Ava.UI.Controls
|
||||
{
|
||||
var viewModel = (sender as MenuItem)?.DataContext as MainWindowViewModel;
|
||||
|
||||
if (viewModel.SelectedApplication != null)
|
||||
if (viewModel?.SelectedApplication != null)
|
||||
{
|
||||
await ApplicationHelper.ExtractSection(NcaSectionType.Code, viewModel.SelectedApplication.Path, viewModel.SelectedApplication.TitleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,8 +35,8 @@ namespace Ryujinx.Ava.UI.Windows
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
string modsBasePath = virtualFileSystem.ModLoader.GetModsBasePath();
|
||||
string titleModsPath = virtualFileSystem.ModLoader.GetTitleDir(modsBasePath, titleId);
|
||||
string modsBasePath = ModLoader.GetModsBasePath();
|
||||
string titleModsPath = ModLoader.GetTitleDir(modsBasePath, titleId);
|
||||
ulong titleIdValue = ulong.Parse(titleId, System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
_enabledCheatsPath = Path.Combine(titleModsPath, "cheats", "enabled.txt");
|
||||
|
@@ -157,11 +157,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
|
||||
{
|
||||
BufferDescriptor sb = info.SBuffers[index];
|
||||
|
||||
ulong sbDescAddress = _channel.BufferManager.GetComputeUniformBufferAddress(0);
|
||||
|
||||
int sbDescOffset = 0x310 + sb.Slot * 0x10;
|
||||
|
||||
sbDescAddress += (ulong)sbDescOffset;
|
||||
ulong sbDescAddress = _channel.BufferManager.GetComputeUniformBufferAddress(sb.SbCbSlot);
|
||||
sbDescAddress += (ulong)sb.SbCbOffset * 4;
|
||||
|
||||
SbDescriptor sbDescriptor = _channel.MemoryManager.Physical.Read<SbDescriptor>(sbDescAddress);
|
||||
|
||||
|
@@ -351,11 +351,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
||||
{
|
||||
BufferDescriptor sb = info.SBuffers[index];
|
||||
|
||||
ulong sbDescAddress = _channel.BufferManager.GetGraphicsUniformBufferAddress(stage, 0);
|
||||
|
||||
int sbDescOffset = 0x110 + stage * 0x100 + sb.Slot * 0x10;
|
||||
|
||||
sbDescAddress += (ulong)sbDescOffset;
|
||||
ulong sbDescAddress = _channel.BufferManager.GetGraphicsUniformBufferAddress(stage, sb.SbCbSlot);
|
||||
sbDescAddress += (ulong)sb.SbCbOffset * 4;
|
||||
|
||||
SbDescriptor sbDescriptor = _channel.MemoryManager.Physical.Read<SbDescriptor>(sbDescAddress);
|
||||
|
||||
|
@@ -537,7 +537,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
if (hostTexture != null && texture.Target == Target.TextureBuffer)
|
||||
{
|
||||
// Ensure that the buffer texture is using the correct buffer as storage.
|
||||
// Buffers are frequently re-created to accomodate larger data, so we need to re-bind
|
||||
// Buffers are frequently re-created to accommodate larger data, so we need to re-bind
|
||||
// to ensure we're not using a old buffer that was already deleted.
|
||||
_channel.BufferManager.SetBufferTextureStorage(stage, hostTexture, texture.Range.GetSubRange(0).Address, texture.Size, bindingInfo, bindingInfo.Format, false);
|
||||
|
||||
@@ -666,7 +666,7 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
if (hostTexture != null && texture.Target == Target.TextureBuffer)
|
||||
{
|
||||
// Ensure that the buffer texture is using the correct buffer as storage.
|
||||
// Buffers are frequently re-created to accomodate larger data, so we need to re-bind
|
||||
// Buffers are frequently re-created to accommodate larger data, so we need to re-bind
|
||||
// to ensure we're not using a old buffer that was already deleted.
|
||||
|
||||
Format format = bindingInfo.Format;
|
||||
@@ -879,4 +879,4 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||
Array.Clear(_imageState);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -68,6 +68,9 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
|
||||
private int _referenceCount = 1;
|
||||
|
||||
private ulong _dirtyStart = ulong.MaxValue;
|
||||
private ulong _dirtyEnd = ulong.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the buffer.
|
||||
/// </summary>
|
||||
@@ -221,6 +224,26 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
}
|
||||
|
||||
_sequenceNumber = _context.SequenceNumber;
|
||||
_dirtyStart = ulong.MaxValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (_dirtyStart != ulong.MaxValue)
|
||||
{
|
||||
ulong end = address + size;
|
||||
|
||||
if (end > _dirtyStart && address < _dirtyEnd)
|
||||
{
|
||||
if (_modifiedRanges != null)
|
||||
{
|
||||
_modifiedRanges.ExcludeModifiedRegions(_dirtyStart, _dirtyEnd - _dirtyStart, _loadDelegate);
|
||||
}
|
||||
else
|
||||
{
|
||||
LoadRegion(_dirtyStart, _dirtyEnd - _dirtyStart);
|
||||
}
|
||||
|
||||
_dirtyStart = ulong.MaxValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,7 +314,7 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inherit modified ranges from another buffer.
|
||||
/// Inherit modified and dirty ranges from another buffer.
|
||||
/// </summary>
|
||||
/// <param name="from">The buffer to inherit from</param>
|
||||
public void InheritModifiedRanges(Buffer from)
|
||||
@@ -320,6 +343,11 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
|
||||
_modifiedRanges.InheritRanges(from._modifiedRanges, registerRangeAction);
|
||||
}
|
||||
|
||||
if (from._dirtyStart != ulong.MaxValue)
|
||||
{
|
||||
ForceDirty(from._dirtyStart, from._dirtyEnd - from._dirtyStart);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -338,6 +366,44 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear the dirty range that overlaps with the given region.
|
||||
/// </summary>
|
||||
/// <param name="address">Start address of the modified region</param>
|
||||
/// <param name="size">Size of the modified region</param>
|
||||
private void ClearDirty(ulong address, ulong size)
|
||||
{
|
||||
if (_dirtyStart != ulong.MaxValue)
|
||||
{
|
||||
ulong end = address + size;
|
||||
|
||||
if (end > _dirtyStart && address < _dirtyEnd)
|
||||
{
|
||||
if (address <= _dirtyStart)
|
||||
{
|
||||
// Cut off the start.
|
||||
|
||||
if (end < _dirtyEnd)
|
||||
{
|
||||
_dirtyStart = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dirtyStart = ulong.MaxValue;
|
||||
}
|
||||
}
|
||||
else if (end >= _dirtyEnd)
|
||||
{
|
||||
// Cut off the end.
|
||||
|
||||
_dirtyEnd = address;
|
||||
}
|
||||
|
||||
// If fully contained, do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicate that a region of the buffer was modified, and must be loaded from memory.
|
||||
/// </summary>
|
||||
@@ -357,6 +423,8 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
mSize = maxSize;
|
||||
}
|
||||
|
||||
ClearDirty(mAddress, mSize);
|
||||
|
||||
if (_modifiedRanges != null)
|
||||
{
|
||||
_modifiedRanges.ExcludeModifiedRegions(mAddress, mSize, _loadDelegate);
|
||||
@@ -380,14 +448,12 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force a region of the buffer to be dirty. Avoids reprotection and nullifies sequence number check.
|
||||
/// Force a region of the buffer to be dirty within the memory tracking. Avoids reprotection and nullifies sequence number check.
|
||||
/// </summary>
|
||||
/// <param name="mAddress">Start address of the modified region</param>
|
||||
/// <param name="mSize">Size of the region to force dirty</param>
|
||||
public void ForceDirty(ulong mAddress, ulong mSize)
|
||||
private void ForceTrackingDirty(ulong mAddress, ulong mSize)
|
||||
{
|
||||
_modifiedRanges?.Clear(mAddress, mSize);
|
||||
|
||||
if (_useGranular)
|
||||
{
|
||||
_memoryTrackingGranular.ForceDirty(mAddress, mSize);
|
||||
@@ -399,6 +465,39 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Force a region of the buffer to be dirty. Avoids reprotection and nullifies sequence number check.
|
||||
/// </summary>
|
||||
/// <param name="mAddress">Start address of the modified region</param>
|
||||
/// <param name="mSize">Size of the region to force dirty</param>
|
||||
public void ForceDirty(ulong mAddress, ulong mSize)
|
||||
{
|
||||
_modifiedRanges?.Clear(mAddress, mSize);
|
||||
|
||||
ulong end = mAddress + mSize;
|
||||
|
||||
if (_dirtyStart == ulong.MaxValue)
|
||||
{
|
||||
_dirtyStart = mAddress;
|
||||
_dirtyEnd = end;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Is the new range more than a page away from the existing one?
|
||||
|
||||
if ((long)(mAddress - _dirtyEnd) >= (long)MemoryManager.PageSize ||
|
||||
(long)(_dirtyStart - end) >= (long)MemoryManager.PageSize)
|
||||
{
|
||||
ForceTrackingDirty(mAddress, mSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
_dirtyStart = Math.Min(_dirtyStart, mAddress);
|
||||
_dirtyEnd = Math.Max(_dirtyEnd, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs copy of all the buffer data from one buffer to another.
|
||||
/// </summary>
|
||||
|
@@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
||||
private const ushort FileFormatVersionMajor = 1;
|
||||
private const ushort FileFormatVersionMinor = 2;
|
||||
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
|
||||
private const uint CodeGenVersion = 4735;
|
||||
private const uint CodeGenVersion = 2237;
|
||||
|
||||
private const string SharedTocFileName = "shared.toc";
|
||||
private const string SharedDataFileName = "shared.data";
|
||||
|
@@ -104,7 +104,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
|
||||
private static GpuVendor GetGpuVendor()
|
||||
{
|
||||
string vendor = GL.GetString(StringName.Vendor).ToLower();
|
||||
string vendor = GL.GetString(StringName.Vendor).ToLowerInvariant();
|
||||
|
||||
if (vendor == "nvidia corporation")
|
||||
{
|
||||
@@ -112,7 +112,7 @@ namespace Ryujinx.Graphics.OpenGL
|
||||
}
|
||||
else if (vendor == "intel")
|
||||
{
|
||||
string renderer = GL.GetString(StringName.Renderer).ToLower();
|
||||
string renderer = GL.GetString(StringName.Renderer).ToLowerInvariant();
|
||||
|
||||
return renderer.Contains("mesa") ? GpuVendor.IntelUnix : GpuVendor.IntelWindows;
|
||||
}
|
||||
|
@@ -5,13 +5,27 @@ namespace Ryujinx.Graphics.Shader
|
||||
// New fields should be added to the end of the struct to keep disk shader cache compatibility.
|
||||
|
||||
public readonly int Binding;
|
||||
public readonly int Slot;
|
||||
public readonly byte Slot;
|
||||
public readonly byte SbCbSlot;
|
||||
public readonly ushort SbCbOffset;
|
||||
public BufferUsageFlags Flags;
|
||||
|
||||
public BufferDescriptor(int binding, int slot)
|
||||
{
|
||||
Binding = binding;
|
||||
Slot = slot;
|
||||
Slot = (byte)slot;
|
||||
SbCbSlot = 0;
|
||||
SbCbOffset = 0;
|
||||
|
||||
Flags = BufferUsageFlags.None;
|
||||
}
|
||||
|
||||
public BufferDescriptor(int binding, int slot, int sbCbSlot, int sbCbOffset)
|
||||
{
|
||||
Binding = binding;
|
||||
Slot = (byte)slot;
|
||||
SbCbSlot = (byte)sbCbSlot;
|
||||
SbCbOffset = (ushort)sbCbOffset;
|
||||
|
||||
Flags = BufferUsageFlags.None;
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ namespace Ryujinx.Graphics.Shader
|
||||
/// Flags that indicate how a buffer will be used in a shader.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum BufferUsageFlags
|
||||
public enum BufferUsageFlags : byte
|
||||
{
|
||||
None = 0,
|
||||
|
||||
|
@@ -16,6 +16,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
public const int UbeDescsSize = StorageDescSize * UbeMaxCount;
|
||||
public const int UbeFirstCbuf = 8;
|
||||
|
||||
public const int DriverReservedCb = 0;
|
||||
|
||||
public static bool UsesGlobalMemory(Instruction inst, StorageKind storageKind)
|
||||
{
|
||||
return (inst.IsAtomic() && storageKind == StorageKind.GlobalMemory) ||
|
||||
|
@@ -8,6 +8,20 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
{
|
||||
static class GlobalToStorage
|
||||
{
|
||||
private struct SearchResult
|
||||
{
|
||||
public static SearchResult NotFound => new SearchResult(-1, 0);
|
||||
public bool Found => SbCbSlot != -1;
|
||||
public int SbCbSlot { get; }
|
||||
public int SbCbOffset { get; }
|
||||
|
||||
public SearchResult(int sbCbSlot, int sbCbOffset)
|
||||
{
|
||||
SbCbSlot = sbCbSlot;
|
||||
SbCbOffset = sbCbOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public static void RunPass(BasicBlock block, ShaderConfig config, ref int sbUseMask, ref int ubeUseMask)
|
||||
{
|
||||
int sbStart = GetStorageBaseCbOffset(config.Stage);
|
||||
@@ -49,30 +63,33 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
{
|
||||
Operand source = operation.GetSource(0);
|
||||
|
||||
int storageIndex = SearchForStorageBase(block, source, sbStart, sbEnd);
|
||||
|
||||
if (storageIndex >= 0)
|
||||
var result = SearchForStorageBase(config, block, source);
|
||||
if (!result.Found)
|
||||
{
|
||||
// Storage buffers are implemented using global memory access.
|
||||
// If we know from where the base address of the access is loaded,
|
||||
// we can guess which storage buffer it is accessing.
|
||||
// We can then replace the global memory access with a storage
|
||||
// buffer access.
|
||||
node = ReplaceGlobalWithStorage(block, node, config, storageIndex);
|
||||
continue;
|
||||
}
|
||||
else if (config.Stage == ShaderStage.Compute && operation.Inst == Instruction.LoadGlobal)
|
||||
|
||||
if (config.Stage == ShaderStage.Compute &&
|
||||
operation.Inst == Instruction.LoadGlobal &&
|
||||
result.SbCbSlot == DriverReservedCb &&
|
||||
result.SbCbOffset >= UbeBaseOffset &&
|
||||
result.SbCbOffset < UbeBaseOffset + UbeDescsSize)
|
||||
{
|
||||
// Here we effectively try to replace a LDG instruction with LDC.
|
||||
// The hardware only supports a limited amount of constant buffers
|
||||
// so NVN "emulates" more constant buffers using global memory access.
|
||||
// Here we try to replace the global access back to a constant buffer
|
||||
// load.
|
||||
storageIndex = SearchForStorageBase(block, source, ubeStart, ubeStart + ubeEnd);
|
||||
|
||||
if (storageIndex >= 0)
|
||||
{
|
||||
node = ReplaceLdgWithLdc(node, config, storageIndex);
|
||||
}
|
||||
node = ReplaceLdgWithLdc(node, config, (result.SbCbOffset - UbeBaseOffset) / StorageDescSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Storage buffers are implemented using global memory access.
|
||||
// If we know from where the base address of the access is loaded,
|
||||
// we can guess which storage buffer it is accessing.
|
||||
// We can then replace the global memory access with a storage
|
||||
// buffer access.
|
||||
node = ReplaceGlobalWithStorage(block, node, config, config.GetSbSlot((byte)result.SbCbSlot, (ushort)result.SbCbOffset));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,7 +176,9 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
|
||||
if (byteOffset == null)
|
||||
{
|
||||
Operand baseAddrLow = Cbuf(0, baseAddressCbOffset);
|
||||
(int sbCbSlot, int sbCbOffset) = config.GetSbCbInfo(storageIndex);
|
||||
|
||||
Operand baseAddrLow = Cbuf(sbCbSlot, sbCbOffset);
|
||||
Operand baseAddrTrunc = Local();
|
||||
|
||||
Operand alignMask = Const(-config.GpuAccessor.QueryHostStorageBufferOffsetAlignment());
|
||||
@@ -360,20 +379,20 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
return node;
|
||||
}
|
||||
|
||||
private static int SearchForStorageBase(BasicBlock block, Operand globalAddress, int sbStart, int sbEnd)
|
||||
private static SearchResult SearchForStorageBase(ShaderConfig config, BasicBlock block, Operand globalAddress)
|
||||
{
|
||||
globalAddress = Utils.FindLastOperation(globalAddress, block);
|
||||
|
||||
if (globalAddress.Type == OperandType.ConstantBuffer)
|
||||
{
|
||||
return GetStorageIndex(globalAddress, sbStart, sbEnd);
|
||||
return GetStorageIndex(config, globalAddress);
|
||||
}
|
||||
|
||||
Operation operation = globalAddress.AsgOp as Operation;
|
||||
|
||||
if (operation == null || operation.Inst != Instruction.Add)
|
||||
{
|
||||
return -1;
|
||||
return SearchResult.NotFound;
|
||||
}
|
||||
|
||||
Operand src1 = operation.GetSource(0);
|
||||
@@ -382,34 +401,65 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
if ((src1.Type == OperandType.LocalVariable && src2.Type == OperandType.Constant) ||
|
||||
(src2.Type == OperandType.LocalVariable && src1.Type == OperandType.Constant))
|
||||
{
|
||||
Operand baseAddr;
|
||||
|
||||
if (src1.Type == OperandType.LocalVariable)
|
||||
{
|
||||
operation = Utils.FindLastOperation(src1, block).AsgOp as Operation;
|
||||
baseAddr = Utils.FindLastOperation(src1, block);
|
||||
}
|
||||
else
|
||||
{
|
||||
operation = Utils.FindLastOperation(src2, block).AsgOp as Operation;
|
||||
baseAddr = Utils.FindLastOperation(src2, block);
|
||||
}
|
||||
|
||||
var result = GetStorageIndex(config, baseAddr);
|
||||
if (result.Found)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
operation = baseAddr.AsgOp as Operation;
|
||||
|
||||
if (operation == null || operation.Inst != Instruction.Add)
|
||||
{
|
||||
return -1;
|
||||
return SearchResult.NotFound;
|
||||
}
|
||||
}
|
||||
|
||||
var selectedResult = SearchResult.NotFound;
|
||||
|
||||
for (int index = 0; index < operation.SourcesCount; index++)
|
||||
{
|
||||
Operand source = operation.GetSource(index);
|
||||
|
||||
int storageIndex = GetStorageIndex(source, sbStart, sbEnd);
|
||||
var result = GetStorageIndex(config, source);
|
||||
|
||||
if (storageIndex != -1)
|
||||
// If we already have a result, we give preference to the ones from
|
||||
// the driver reserved constant buffer, as those are the ones that
|
||||
// contains the base address.
|
||||
if (result.Found && (!selectedResult.Found || result.SbCbSlot == GlobalMemory.DriverReservedCb))
|
||||
{
|
||||
return storageIndex;
|
||||
selectedResult = result;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return selectedResult;
|
||||
}
|
||||
|
||||
private static SearchResult GetStorageIndex(ShaderConfig config, Operand operand)
|
||||
{
|
||||
if (operand.Type == OperandType.ConstantBuffer)
|
||||
{
|
||||
int slot = operand.GetCbufSlot();
|
||||
int offset = operand.GetCbufOffset();
|
||||
|
||||
if ((offset & 3) == 0)
|
||||
{
|
||||
return new SearchResult(slot, offset);
|
||||
}
|
||||
}
|
||||
|
||||
return SearchResult.NotFound;
|
||||
}
|
||||
|
||||
private static int GetStorageIndex(Operand operand, int sbStart, int sbEnd)
|
||||
|
@@ -68,7 +68,6 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations
|
||||
}
|
||||
|
||||
ConstantFolding.RunPass(operation);
|
||||
|
||||
Simplification.RunPass(operation);
|
||||
|
||||
if (DestIsLocalVar(operation))
|
||||
|
@@ -110,9 +110,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
Operand BindingRangeCheck(int cbOffset, out Operand baseAddrLow)
|
||||
{
|
||||
baseAddrLow = Cbuf(0, cbOffset);
|
||||
Operand baseAddrHigh = Cbuf(0, cbOffset + 1);
|
||||
Operand size = Cbuf(0, cbOffset + 2);
|
||||
baseAddrLow = Cbuf(DriverReservedCb, cbOffset);
|
||||
Operand baseAddrHigh = Cbuf(DriverReservedCb, cbOffset + 1);
|
||||
Operand size = Cbuf(DriverReservedCb, cbOffset + 2);
|
||||
|
||||
Operand offset = PrependOperation(Instruction.Subtract, addrLow, baseAddrLow);
|
||||
Operand borrow = PrependOperation(Instruction.CompareLessU32, addrLow, baseAddrLow);
|
||||
@@ -134,9 +134,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
sbUseMask &= ~(1 << slot);
|
||||
|
||||
config.SetUsedStorageBuffer(slot, isWrite);
|
||||
|
||||
int cbOffset = GetStorageCbOffset(config.Stage, slot);
|
||||
slot = config.GetSbSlot(DriverReservedCb, (ushort)cbOffset);
|
||||
|
||||
config.SetUsedStorageBuffer(slot, isWrite);
|
||||
|
||||
Operand inRange = BindingRangeCheck(cbOffset, out Operand baseAddrLow);
|
||||
|
||||
|
@@ -125,6 +125,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
private readonly Dictionary<TextureInfo, TextureMeta> _usedTextures;
|
||||
private readonly Dictionary<TextureInfo, TextureMeta> _usedImages;
|
||||
|
||||
private readonly Dictionary<int, int> _sbSlots;
|
||||
private readonly Dictionary<int, int> _sbSlotsReverse;
|
||||
|
||||
private BufferDescriptor[] _cachedConstantBufferDescriptors;
|
||||
private BufferDescriptor[] _cachedStorageBufferDescriptors;
|
||||
private TextureDescriptor[] _cachedTextureDescriptors;
|
||||
@@ -152,6 +155,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
_usedTextures = new Dictionary<TextureInfo, TextureMeta>();
|
||||
_usedImages = new Dictionary<TextureInfo, TextureMeta>();
|
||||
|
||||
_sbSlots = new Dictionary<int, int>();
|
||||
_sbSlotsReverse = new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
public ShaderConfig(
|
||||
@@ -770,9 +776,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
usedMask |= (int)GpuAccessor.QueryConstantBufferUse();
|
||||
}
|
||||
|
||||
return _cachedConstantBufferDescriptors = GetBufferDescriptors(
|
||||
return _cachedConstantBufferDescriptors = GetUniformBufferDescriptors(
|
||||
usedMask,
|
||||
0,
|
||||
UsedFeatures.HasFlag(FeatureFlags.CbIndexing),
|
||||
out _firstConstantBufferBinding,
|
||||
GpuAccessor.QueryBindingConstantBuffer);
|
||||
@@ -785,7 +790,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
return _cachedStorageBufferDescriptors;
|
||||
}
|
||||
|
||||
return _cachedStorageBufferDescriptors = GetBufferDescriptors(
|
||||
return _cachedStorageBufferDescriptors = GetStorageBufferDescriptors(
|
||||
_usedStorageBuffers,
|
||||
_usedStorageBuffersWrite,
|
||||
true,
|
||||
@@ -793,7 +798,48 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
GpuAccessor.QueryBindingStorageBuffer);
|
||||
}
|
||||
|
||||
private static BufferDescriptor[] GetBufferDescriptors(
|
||||
private static BufferDescriptor[] GetUniformBufferDescriptors(int usedMask, bool isArray, out int firstBinding, Func<int, int> getBindingCallback)
|
||||
{
|
||||
firstBinding = 0;
|
||||
int lastSlot = -1;
|
||||
bool hasFirstBinding = false;
|
||||
var descriptors = new BufferDescriptor[BitOperations.PopCount((uint)usedMask)];
|
||||
|
||||
for (int i = 0; i < descriptors.Length; i++)
|
||||
{
|
||||
int slot = BitOperations.TrailingZeroCount(usedMask);
|
||||
|
||||
if (isArray)
|
||||
{
|
||||
// The next array entries also consumes bindings, even if they are unused.
|
||||
for (int j = lastSlot + 1; j < slot; j++)
|
||||
{
|
||||
int binding = getBindingCallback(j);
|
||||
|
||||
if (!hasFirstBinding)
|
||||
{
|
||||
firstBinding = binding;
|
||||
hasFirstBinding = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastSlot = slot;
|
||||
descriptors[i] = new BufferDescriptor(getBindingCallback(slot), slot);
|
||||
|
||||
if (!hasFirstBinding)
|
||||
{
|
||||
firstBinding = descriptors[i].Binding;
|
||||
hasFirstBinding = true;
|
||||
}
|
||||
|
||||
usedMask &= ~(1 << slot);
|
||||
}
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private BufferDescriptor[] GetStorageBufferDescriptors(
|
||||
int usedMask,
|
||||
int writtenMask,
|
||||
bool isArray,
|
||||
@@ -827,7 +873,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
lastSlot = slot;
|
||||
|
||||
descriptors[i] = new BufferDescriptor(getBindingCallback(slot), slot);
|
||||
(int sbCbSlot, int sbCbOffset) = GetSbCbInfo(slot);
|
||||
|
||||
descriptors[i] = new BufferDescriptor(getBindingCallback(slot), slot, sbCbSlot, sbCbOffset);
|
||||
|
||||
if (!hasFirstBinding)
|
||||
{
|
||||
@@ -924,6 +972,40 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
return FindDescriptorIndex(GetImageDescriptors(), texOp);
|
||||
}
|
||||
|
||||
public int GetSbSlot(byte sbCbSlot, ushort sbCbOffset)
|
||||
{
|
||||
int key = PackSbCbInfo(sbCbSlot, sbCbOffset);
|
||||
|
||||
if (!_sbSlots.TryGetValue(key, out int slot))
|
||||
{
|
||||
slot = _sbSlots.Count;
|
||||
_sbSlots.Add(key, slot);
|
||||
_sbSlotsReverse.Add(slot, key);
|
||||
}
|
||||
|
||||
return slot;
|
||||
}
|
||||
|
||||
public (int, int) GetSbCbInfo(int slot)
|
||||
{
|
||||
if (_sbSlotsReverse.TryGetValue(slot, out int key))
|
||||
{
|
||||
return UnpackSbCbInfo(key);
|
||||
}
|
||||
|
||||
throw new ArgumentException($"Invalid slot {slot}.", nameof(slot));
|
||||
}
|
||||
|
||||
private static int PackSbCbInfo(int sbCbSlot, int sbCbOffset)
|
||||
{
|
||||
return sbCbOffset | ((int)sbCbSlot << 16);
|
||||
}
|
||||
|
||||
private static (int, int) UnpackSbCbInfo(int key)
|
||||
{
|
||||
return ((byte)(key >> 16), (ushort)key);
|
||||
}
|
||||
|
||||
public ShaderProgramInfo CreateProgramInfo(ShaderIdentification identification = ShaderIdentification.None)
|
||||
{
|
||||
return new ShaderProgramInfo(
|
||||
|
@@ -89,7 +89,7 @@ namespace Ryujinx.HLE.HOS
|
||||
}
|
||||
|
||||
// Title independent mods
|
||||
public class PatchCache
|
||||
private class PatchCache
|
||||
{
|
||||
public List<Mod<DirectoryInfo>> NsoPatches { get; }
|
||||
public List<Mod<DirectoryInfo>> NroPatches { get; }
|
||||
@@ -107,14 +107,14 @@ namespace Ryujinx.HLE.HOS
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<ulong, ModCache> AppMods; // key is TitleId
|
||||
public PatchCache Patches;
|
||||
private readonly Dictionary<ulong, ModCache> _appMods; // key is TitleId
|
||||
private PatchCache _patches;
|
||||
|
||||
private static readonly EnumerationOptions _dirEnumOptions;
|
||||
private static readonly EnumerationOptions DirEnumOptions;
|
||||
|
||||
static ModLoader()
|
||||
{
|
||||
_dirEnumOptions = new EnumerationOptions
|
||||
DirEnumOptions = new EnumerationOptions
|
||||
{
|
||||
MatchCasing = MatchCasing.CaseInsensitive,
|
||||
MatchType = MatchType.Simple,
|
||||
@@ -125,37 +125,73 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
public ModLoader()
|
||||
{
|
||||
AppMods = new Dictionary<ulong, ModCache>();
|
||||
Patches = new PatchCache();
|
||||
_appMods = new Dictionary<ulong, ModCache>();
|
||||
_patches = new PatchCache();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
private void Clear()
|
||||
{
|
||||
AppMods.Clear();
|
||||
Patches = new PatchCache();
|
||||
_appMods.Clear();
|
||||
_patches = new PatchCache();
|
||||
}
|
||||
|
||||
private static bool StrEquals(string s1, string s2) => string.Equals(s1, s2, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public string GetModsBasePath() => EnsureBaseDirStructure(AppDataManager.GetModsPath());
|
||||
public string GetSdModsBasePath() => EnsureBaseDirStructure(AppDataManager.GetSdModsPath());
|
||||
public static string GetModsBasePath() => EnsureBaseDirStructure(AppDataManager.GetModsPath());
|
||||
public static string GetSdModsBasePath() => EnsureBaseDirStructure(AppDataManager.GetSdModsPath());
|
||||
|
||||
private string EnsureBaseDirStructure(string modsBasePath)
|
||||
private static string EnsureBaseDirStructure(string modsBasePath)
|
||||
{
|
||||
var modsDir = new DirectoryInfo(modsBasePath);
|
||||
|
||||
modsDir.CreateSubdirectory(AmsContentsDir);
|
||||
modsDir.CreateSubdirectory(AmsNsoPatchDir);
|
||||
modsDir.CreateSubdirectory(AmsNroPatchDir);
|
||||
// modsDir.CreateSubdirectory(AmsKipPatchDir); // uncomment when KIPs are supported
|
||||
// TODO: uncomment when KIPs are supported
|
||||
// modsDir.CreateSubdirectory(AmsKipPatchDir);
|
||||
|
||||
return modsDir.FullName;
|
||||
}
|
||||
|
||||
private static DirectoryInfo FindTitleDir(DirectoryInfo contentsDir, string titleId)
|
||||
=> contentsDir.EnumerateDirectories($"{titleId}*", _dirEnumOptions).FirstOrDefault();
|
||||
=> contentsDir.EnumerateDirectories($"{titleId}*", DirEnumOptions).FirstOrDefault();
|
||||
|
||||
public string GetTitleDir(string modsBasePath, string titleId)
|
||||
private static void AddModsFromDirectory(ModCache mods, DirectoryInfo dir, string titleId)
|
||||
{
|
||||
System.Text.StringBuilder types = new();
|
||||
|
||||
foreach (var modDir in dir.EnumerateDirectories())
|
||||
{
|
||||
types.Clear();
|
||||
Mod<DirectoryInfo> mod = new("", null);
|
||||
|
||||
if (StrEquals(RomfsDir, modDir.Name))
|
||||
{
|
||||
mods.RomfsDirs.Add(mod = new Mod<DirectoryInfo>($"<{titleId} RomFs>", modDir));
|
||||
types.Append('R');
|
||||
}
|
||||
else if (StrEquals(ExefsDir, modDir.Name))
|
||||
{
|
||||
mods.ExefsDirs.Add(mod = new Mod<DirectoryInfo>($"<{titleId} ExeFs>", modDir));
|
||||
types.Append('E');
|
||||
}
|
||||
else if (StrEquals(CheatDir, modDir.Name))
|
||||
{
|
||||
types.Append('C', QueryCheatsDir(mods, modDir));
|
||||
}
|
||||
else
|
||||
{
|
||||
AddModsFromDirectory(mods, modDir, titleId);
|
||||
}
|
||||
|
||||
if (types.Length > 0)
|
||||
{
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Found mod '{mod.Name}' [{types}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetTitleDir(string modsBasePath, string titleId)
|
||||
{
|
||||
var contentsDir = new DirectoryInfo(Path.Combine(modsBasePath, AmsContentsDir));
|
||||
var titleModsPath = FindTitleDir(contentsDir, titleId);
|
||||
@@ -170,17 +206,32 @@ namespace Ryujinx.HLE.HOS
|
||||
}
|
||||
|
||||
// Static Query Methods
|
||||
public static void QueryPatchDirs(PatchCache cache, DirectoryInfo patchDir)
|
||||
private static void QueryPatchDirs(PatchCache cache, DirectoryInfo patchDir)
|
||||
{
|
||||
if (cache.Initialized || !patchDir.Exists) return;
|
||||
if (cache.Initialized || !patchDir.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var patches = cache.KipPatches;
|
||||
string type = null;
|
||||
List<Mod<DirectoryInfo>> patches;
|
||||
string type;
|
||||
|
||||
if (StrEquals(AmsNsoPatchDir, patchDir.Name)) { patches = cache.NsoPatches; type = "NSO"; }
|
||||
else if (StrEquals(AmsNroPatchDir, patchDir.Name)) { patches = cache.NroPatches; type = "NRO"; }
|
||||
else if (StrEquals(AmsKipPatchDir, patchDir.Name)) { patches = cache.KipPatches; type = "KIP"; }
|
||||
else return;
|
||||
if (StrEquals(AmsNsoPatchDir, patchDir.Name))
|
||||
{
|
||||
patches = cache.NsoPatches; type = "NSO";
|
||||
}
|
||||
else if (StrEquals(AmsNroPatchDir, patchDir.Name))
|
||||
{
|
||||
patches = cache.NroPatches; type = "NRO";
|
||||
}
|
||||
else if (StrEquals(AmsKipPatchDir, patchDir.Name))
|
||||
{
|
||||
patches = cache.KipPatches; type = "KIP";
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var modDir in patchDir.EnumerateDirectories())
|
||||
{
|
||||
@@ -189,9 +240,12 @@ namespace Ryujinx.HLE.HOS
|
||||
}
|
||||
}
|
||||
|
||||
public static void QueryTitleDir(ModCache mods, DirectoryInfo titleDir)
|
||||
private static void QueryTitleDir(ModCache mods, DirectoryInfo titleDir)
|
||||
{
|
||||
if (!titleDir.Exists) return;
|
||||
if (!titleDir.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fsFile = new FileInfo(Path.Combine(titleDir.FullName, RomfsContainer));
|
||||
if (fsFile.Exists)
|
||||
@@ -205,64 +259,15 @@ namespace Ryujinx.HLE.HOS
|
||||
mods.ExefsContainers.Add(new Mod<FileInfo>($"<{titleDir.Name} ExeFs>", fsFile));
|
||||
}
|
||||
|
||||
System.Text.StringBuilder types = new System.Text.StringBuilder(5);
|
||||
|
||||
foreach (var modDir in titleDir.EnumerateDirectories())
|
||||
{
|
||||
types.Clear();
|
||||
Mod<DirectoryInfo> mod = new Mod<DirectoryInfo>("", null);
|
||||
|
||||
if (StrEquals(RomfsDir, modDir.Name))
|
||||
{
|
||||
mods.RomfsDirs.Add(mod = new Mod<DirectoryInfo>($"<{titleDir.Name} RomFs>", modDir));
|
||||
types.Append('R');
|
||||
}
|
||||
else if (StrEquals(ExefsDir, modDir.Name))
|
||||
{
|
||||
mods.ExefsDirs.Add(mod = new Mod<DirectoryInfo>($"<{titleDir.Name} ExeFs>", modDir));
|
||||
types.Append('E');
|
||||
}
|
||||
else if (StrEquals(CheatDir, modDir.Name))
|
||||
{
|
||||
for (int i = 0; i < QueryCheatsDir(mods, modDir); i++)
|
||||
{
|
||||
types.Append('C');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var romfs = new DirectoryInfo(Path.Combine(modDir.FullName, RomfsDir));
|
||||
var exefs = new DirectoryInfo(Path.Combine(modDir.FullName, ExefsDir));
|
||||
var cheat = new DirectoryInfo(Path.Combine(modDir.FullName, CheatDir));
|
||||
|
||||
if (romfs.Exists)
|
||||
{
|
||||
mods.RomfsDirs.Add(mod = new Mod<DirectoryInfo>(modDir.Name, romfs));
|
||||
types.Append('R');
|
||||
}
|
||||
|
||||
if (exefs.Exists)
|
||||
{
|
||||
mods.ExefsDirs.Add(mod = new Mod<DirectoryInfo>(modDir.Name, exefs));
|
||||
types.Append('E');
|
||||
}
|
||||
|
||||
if (cheat.Exists)
|
||||
{
|
||||
for (int i = 0; i < QueryCheatsDir(mods, cheat); i++)
|
||||
{
|
||||
types.Append('C');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (types.Length > 0) Logger.Info?.Print(LogClass.ModLoader, $"Found mod '{mod.Name}' [{types}]");
|
||||
}
|
||||
AddModsFromDirectory(mods, titleDir, titleDir.Name);
|
||||
}
|
||||
|
||||
public static void QueryContentsDir(ModCache mods, DirectoryInfo contentsDir, ulong titleId)
|
||||
{
|
||||
if (!contentsDir.Exists) return;
|
||||
if (!contentsDir.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Searching mods for {((titleId & 0x1000) != 0 ? "DLC" : "Title")} {titleId:X16}");
|
||||
|
||||
@@ -302,9 +307,16 @@ namespace Ryujinx.HLE.HOS
|
||||
continue;
|
||||
}
|
||||
|
||||
int oldCheatsCount = mods.Cheats.Count;
|
||||
|
||||
// A cheat file can contain several cheats for the same executable, so the file must be parsed in
|
||||
// order to properly enumerate them.
|
||||
mods.Cheats.AddRange(GetCheatsInFile(file));
|
||||
|
||||
if (mods.Cheats.Count - oldCheatsCount > 0)
|
||||
{
|
||||
numMods++;
|
||||
}
|
||||
}
|
||||
|
||||
return numMods;
|
||||
@@ -313,57 +325,54 @@ namespace Ryujinx.HLE.HOS
|
||||
private static IEnumerable<Cheat> GetCheatsInFile(FileInfo cheatFile)
|
||||
{
|
||||
string cheatName = DefaultCheatName;
|
||||
List<string> instructions = new List<string>();
|
||||
List<Cheat> cheats = new List<Cheat>();
|
||||
List<string> instructions = new();
|
||||
List<Cheat> cheats = new();
|
||||
|
||||
using (StreamReader cheatData = cheatFile.OpenText())
|
||||
using StreamReader cheatData = cheatFile.OpenText();
|
||||
while (cheatData.ReadLine() is { } line)
|
||||
{
|
||||
string line;
|
||||
while ((line = cheatData.ReadLine()) != null)
|
||||
line = line.Trim();
|
||||
|
||||
if (line.StartsWith('['))
|
||||
{
|
||||
line = line.Trim();
|
||||
|
||||
if (line.StartsWith('['))
|
||||
// This line starts a new cheat section.
|
||||
if (!line.EndsWith(']') || line.Length < 3)
|
||||
{
|
||||
// This line starts a new cheat section.
|
||||
if (!line.EndsWith(']') || line.Length < 3)
|
||||
{
|
||||
// Skip the entire file if there's any error while parsing the cheat file.
|
||||
// Skip the entire file if there's any error while parsing the cheat file.
|
||||
|
||||
Logger.Warning?.Print(LogClass.ModLoader, $"Ignoring cheat '{cheatFile.FullName}' because it is malformed");
|
||||
Logger.Warning?.Print(LogClass.ModLoader, $"Ignoring cheat '{cheatFile.FullName}' because it is malformed");
|
||||
|
||||
return new List<Cheat>();
|
||||
}
|
||||
|
||||
// Add the previous section to the list.
|
||||
if (instructions.Count != 0)
|
||||
{
|
||||
cheats.Add(new Cheat($"<{cheatName} Cheat>", cheatFile, instructions));
|
||||
}
|
||||
|
||||
// Start a new cheat section.
|
||||
cheatName = line.Substring(1, line.Length - 2);
|
||||
instructions = new List<string>();
|
||||
return Array.Empty<Cheat>();
|
||||
}
|
||||
else if (line.Length > 0)
|
||||
|
||||
// Add the previous section to the list.
|
||||
if (instructions.Count > 0)
|
||||
{
|
||||
// The line contains an instruction.
|
||||
instructions.Add(line);
|
||||
cheats.Add(new Cheat($"<{cheatName} Cheat>", cheatFile, instructions));
|
||||
}
|
||||
|
||||
// Start a new cheat section.
|
||||
cheatName = line.Substring(1, line.Length - 2);
|
||||
instructions = new List<string>();
|
||||
}
|
||||
|
||||
// Add the last section being processed.
|
||||
if (instructions.Count != 0)
|
||||
else if (line.Length > 0)
|
||||
{
|
||||
cheats.Add(new Cheat($"<{cheatName} Cheat>", cheatFile, instructions));
|
||||
// The line contains an instruction.
|
||||
instructions.Add(line);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the last section being processed.
|
||||
if (instructions.Count > 0)
|
||||
{
|
||||
cheats.Add(new Cheat($"<{cheatName} Cheat>", cheatFile, instructions));
|
||||
}
|
||||
|
||||
return cheats;
|
||||
}
|
||||
|
||||
// Assumes searchDirPaths don't overlap
|
||||
public static void CollectMods(Dictionary<ulong, ModCache> modCaches, PatchCache patches, params string[] searchDirPaths)
|
||||
private static void CollectMods(Dictionary<ulong, ModCache> modCaches, PatchCache patches, params string[] searchDirPaths)
|
||||
{
|
||||
static bool IsPatchesDir(string name) => StrEquals(AmsNsoPatchDir, name) ||
|
||||
StrEquals(AmsNroPatchDir, name) ||
|
||||
@@ -375,7 +384,7 @@ namespace Ryujinx.HLE.HOS
|
||||
{
|
||||
if (IsContentsDir(searchDir.Name))
|
||||
{
|
||||
foreach (var (titleId, cache) in modCaches)
|
||||
foreach ((ulong titleId, ModCache cache) in modCaches)
|
||||
{
|
||||
QueryContentsDir(cache, searchDir, titleId);
|
||||
}
|
||||
@@ -419,15 +428,15 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
foreach (ulong titleId in titles)
|
||||
{
|
||||
AppMods[titleId] = new ModCache();
|
||||
_appMods[titleId] = new ModCache();
|
||||
}
|
||||
|
||||
CollectMods(AppMods, Patches, searchDirPaths);
|
||||
CollectMods(_appMods, _patches, searchDirPaths);
|
||||
}
|
||||
|
||||
internal IStorage ApplyRomFsMods(ulong titleId, IStorage baseStorage)
|
||||
{
|
||||
if (!AppMods.TryGetValue(titleId, out ModCache mods) || mods.RomfsDirs.Count + mods.RomfsContainers.Count == 0)
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.RomfsDirs.Count + mods.RomfsContainers.Count == 0)
|
||||
{
|
||||
return baseStorage;
|
||||
}
|
||||
@@ -487,7 +496,7 @@ namespace Ryujinx.HLE.HOS
|
||||
return newStorage;
|
||||
}
|
||||
|
||||
private static void AddFiles(IFileSystem fs, string modName, HashSet<string> fileSet, RomFsBuilder builder)
|
||||
private static void AddFiles(IFileSystem fs, string modName, ISet<string> fileSet, RomFsBuilder builder)
|
||||
{
|
||||
foreach (var entry in fs.EnumerateEntries()
|
||||
.Where(f => f.Type == DirectoryEntryType.File)
|
||||
@@ -509,7 +518,7 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
internal bool ReplaceExefsPartition(ulong titleId, ref IFileSystem exefs)
|
||||
{
|
||||
if (!AppMods.TryGetValue(titleId, out ModCache mods) || mods.ExefsContainers.Count == 0)
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.ExefsContainers.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -537,13 +546,13 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
internal ModLoadResult ApplyExefsMods(ulong titleId, NsoExecutable[] nsos)
|
||||
{
|
||||
ModLoadResult modLoadResult = new ModLoadResult
|
||||
ModLoadResult modLoadResult = new()
|
||||
{
|
||||
Stubs = new BitVector32(),
|
||||
Replaces = new BitVector32()
|
||||
};
|
||||
|
||||
if (!AppMods.TryGetValue(titleId, out ModCache mods) || mods.ExefsDirs.Count == 0)
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.ExefsDirs.Count == 0)
|
||||
{
|
||||
return modLoadResult;
|
||||
}
|
||||
@@ -561,7 +570,7 @@ namespace Ryujinx.HLE.HOS
|
||||
{
|
||||
var nsoName = ProcessConst.ExeFsPrefixes[i];
|
||||
|
||||
FileInfo nsoFile = new FileInfo(Path.Combine(mod.Path.FullName, nsoName));
|
||||
FileInfo nsoFile = new(Path.Combine(mod.Path.FullName, nsoName));
|
||||
if (nsoFile.Exists)
|
||||
{
|
||||
if (modLoadResult.Replaces[1 << i])
|
||||
@@ -580,7 +589,7 @@ namespace Ryujinx.HLE.HOS
|
||||
modLoadResult.Stubs[1 << i] |= File.Exists(Path.Combine(mod.Path.FullName, nsoName + StubExtension));
|
||||
}
|
||||
|
||||
FileInfo npdmFile = new FileInfo(Path.Combine(mod.Path.FullName, "main.npdm"));
|
||||
FileInfo npdmFile = new(Path.Combine(mod.Path.FullName, "main.npdm"));
|
||||
if (npdmFile.Exists)
|
||||
{
|
||||
if (modLoadResult.Npdm != null)
|
||||
@@ -611,7 +620,7 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
internal void ApplyNroPatches(NroExecutable nro)
|
||||
{
|
||||
var nroPatches = Patches.NroPatches;
|
||||
var nroPatches = _patches.NroPatches;
|
||||
|
||||
if (nroPatches.Count == 0) return;
|
||||
|
||||
@@ -622,9 +631,9 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
internal bool ApplyNsoPatches(ulong titleId, params IExecutable[] programs)
|
||||
{
|
||||
IEnumerable<Mod<DirectoryInfo>> nsoMods = Patches.NsoPatches;
|
||||
IEnumerable<Mod<DirectoryInfo>> nsoMods = _patches.NsoPatches;
|
||||
|
||||
if (AppMods.TryGetValue(titleId, out ModCache mods))
|
||||
if (_appMods.TryGetValue(titleId, out ModCache mods))
|
||||
{
|
||||
nsoMods = nsoMods.Concat(mods.ExefsDirs);
|
||||
}
|
||||
@@ -636,7 +645,7 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
internal void LoadCheats(ulong titleId, ProcessTamperInfo tamperInfo, TamperMachine tamperMachine)
|
||||
{
|
||||
if (tamperInfo == null || tamperInfo.BuildIds == null || tamperInfo.CodeAddresses == null)
|
||||
if (tamperInfo?.BuildIds == null || tamperInfo.CodeAddresses == null)
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ModLoader, "Unable to install cheat because the associated process is invalid");
|
||||
|
||||
@@ -645,14 +654,14 @@ namespace Ryujinx.HLE.HOS
|
||||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Build ids found for title {titleId:X16}:\n {String.Join("\n ", tamperInfo.BuildIds)}");
|
||||
|
||||
if (!AppMods.TryGetValue(titleId, out ModCache mods) || mods.Cheats.Count == 0)
|
||||
if (!_appMods.TryGetValue(titleId, out ModCache mods) || mods.Cheats.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var cheats = mods.Cheats;
|
||||
var processExes = tamperInfo.BuildIds.Zip(tamperInfo.CodeAddresses, (k, v) => new { k, v })
|
||||
.ToDictionary(x => x.k.Substring(0, Math.Min(Cheat.CheatIdSize, x.k.Length)), x => x.v);
|
||||
.ToDictionary(x => x.k[..Math.Min(Cheat.CheatIdSize, x.k.Length)], x => x.v);
|
||||
|
||||
foreach (var cheat in cheats)
|
||||
{
|
||||
@@ -758,4 +767,4 @@ namespace Ryujinx.HLE.HOS
|
||||
return count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.Loader;
|
||||
using LibHac.Ns;
|
||||
using Ryujinx.HLE.HOS;
|
||||
using Ryujinx.HLE.Loaders.Processes.Extensions;
|
||||
using ApplicationId = LibHac.Ncm.ApplicationId;
|
||||
|
||||
@@ -17,8 +18,8 @@ namespace Ryujinx.HLE.Loaders.Processes
|
||||
|
||||
device.Configuration.VirtualFileSystem.ModLoader.CollectMods(
|
||||
new[] { programId },
|
||||
device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(),
|
||||
device.Configuration.VirtualFileSystem.ModLoader.GetSdModsBasePath());
|
||||
ModLoader.GetModsBasePath(),
|
||||
ModLoader.GetSdModsBasePath());
|
||||
|
||||
if (programId != 0)
|
||||
{
|
||||
@@ -36,4 +37,4 @@ namespace Ryujinx.HLE.Loaders.Processes
|
||||
return processResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,6 +8,7 @@ using LibHac.Ns;
|
||||
using LibHac.Tools.FsSystem;
|
||||
using LibHac.Tools.FsSystem.NcaUtils;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.HLE.HOS;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ApplicationId = LibHac.Ncm.ApplicationId;
|
||||
@@ -35,8 +36,8 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
|
||||
// Collecting mods related to AocTitleIds and ProgramId.
|
||||
device.Configuration.VirtualFileSystem.ModLoader.CollectMods(
|
||||
device.Configuration.ContentManager.GetAocTitleIds().Prepend(metaLoader.GetProgramId()),
|
||||
device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(),
|
||||
device.Configuration.VirtualFileSystem.ModLoader.GetSdModsBasePath());
|
||||
ModLoader.GetModsBasePath(),
|
||||
ModLoader.GetSdModsBasePath());
|
||||
|
||||
// Load Nacp file.
|
||||
var nacpData = new BlitStruct<ApplicationControlProperty>(1);
|
||||
|
@@ -460,16 +460,16 @@ namespace Ryujinx.Ui.Widgets
|
||||
|
||||
private void OpenTitleModDir_Clicked(object sender, EventArgs args)
|
||||
{
|
||||
string modsBasePath = _virtualFileSystem.ModLoader.GetModsBasePath();
|
||||
string titleModsPath = _virtualFileSystem.ModLoader.GetTitleDir(modsBasePath, _titleIdText);
|
||||
string modsBasePath = ModLoader.GetModsBasePath();
|
||||
string titleModsPath = ModLoader.GetTitleDir(modsBasePath, _titleIdText);
|
||||
|
||||
OpenHelper.OpenFolder(titleModsPath);
|
||||
}
|
||||
|
||||
private void OpenTitleSdModDir_Clicked(object sender, EventArgs args)
|
||||
{
|
||||
string sdModsBasePath = _virtualFileSystem.ModLoader.GetSdModsBasePath();
|
||||
string titleModsPath = _virtualFileSystem.ModLoader.GetTitleDir(sdModsBasePath, _titleIdText);
|
||||
string sdModsBasePath = ModLoader.GetSdModsBasePath();
|
||||
string titleModsPath = ModLoader.GetTitleDir(sdModsBasePath, _titleIdText);
|
||||
|
||||
OpenHelper.OpenFolder(titleModsPath);
|
||||
}
|
||||
|
@@ -28,8 +28,8 @@ namespace Ryujinx.Ui.Windows
|
||||
builder.Autoconnect(this);
|
||||
_baseTitleInfoLabel.Text = $"Cheats Available for {titleName} [{titleId:X16}]";
|
||||
|
||||
string modsBasePath = virtualFileSystem.ModLoader.GetModsBasePath();
|
||||
string titleModsPath = virtualFileSystem.ModLoader.GetTitleDir(modsBasePath, titleId.ToString("X16"));
|
||||
string modsBasePath = ModLoader.GetModsBasePath();
|
||||
string titleModsPath = ModLoader.GetTitleDir(modsBasePath, titleId.ToString("X16"));
|
||||
|
||||
_enabledCheatsPath = System.IO.Path.Combine(titleModsPath, "cheats", "enabled.txt");
|
||||
|
||||
|
Reference in New Issue
Block a user