add overload for loading game info from path

This commit is contained in:
Emmanuel Hansen 2023-07-04 11:55:19 +00:00
parent 9c510fec3e
commit 28eb812018
3 changed files with 33 additions and 13 deletions

View File

@ -20,6 +20,7 @@ using System.IO;
using Microsoft.Win32.SafeHandles;
using Newtonsoft.Json.Linq;
using System.Security.Cryptography;
using LibHac.Tools.Fs;
namespace LibRyujinx
{
@ -89,9 +90,9 @@ namespace LibRyujinx
}
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceInitialize")]
public static JBoolean JniInitializeDeviceNative(JEnvRef jEnv, JObjectLocalRef jObj, JBoolean isHostMapped)
public static JBoolean JniInitializeDeviceNative(JEnvRef jEnv, JObjectLocalRef jObj, JBoolean isHostMapped, JBoolean useNce)
{
return InitializeDevice(isHostMapped);
return InitializeDevice(isHostMapped, useNce);
}
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceGetGameStats")]
@ -284,13 +285,26 @@ namespace LibRyujinx
RunLoop();
}
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceGetGameInfoFromPath")]
public static JObjectLocalRef JniGetGameInfo(JEnvRef jEnv, JObjectLocalRef jObj, JStringLocalRef path)
{
var info = GetGameInfo(GetString(jEnv, path)) ?? new GameInfo();
SHA256 sha;
return GetInfo(jEnv, info, out sha);
}
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceGetGameInfo")]
public static JObjectLocalRef JniGetGameInfo(JEnvRef jEnv, JObjectLocalRef jObj, JInt fileDescriptor, JBoolean isXci)
{
using var stream = OpenFile(fileDescriptor);
var info = GetGameInfo(stream, isXci) ?? new GameInfo();
SHA256 sha;
return GetInfo(jEnv, info, out sha);
}
private static JObjectLocalRef GetInfo(JEnvRef jEnv, GameInfo info, out SHA256 sha)
{
var javaClassName = GetCCharSequence("org/ryujinx/android/viewmodels/GameInfo");
JEnvValue value = jEnv.Environment;
@ -316,9 +330,7 @@ namespace LibRyujinx
var newGlobal = newGlobalRef(jEnv, javaClass._value);
var constructor = getMethod(jEnv, javaClass, GetCCharSequence("<init>"), GetCCharSequence("()V"));
var newObj = newObject(jEnv, javaClass, constructor, 0);
using var sha = SHA256.Create();
sha = SHA256.Create();
var iconCacheByte = sha.ComputeHash(info.Icon ?? new byte[0]);
var iconCache = BitConverter.ToString(iconCacheByte).Replace("-", "");

View File

@ -15,17 +15,17 @@ namespace LibRyujinx
[UnmanagedCallersOnly(EntryPoint = "device_initialize")]
public static bool InitializeDeviceNative()
{
return InitializeDevice(true);
return InitializeDevice(true, false);
}
public static bool InitializeDevice(bool isHostMapped)
public static bool InitializeDevice(bool isHostMapped, bool useNce)
{
if (SwitchDevice == null)
{
return false;
}
return SwitchDevice.InitializeContext(isHostMapped);
return SwitchDevice.InitializeContext(isHostMapped, useNce);
}
[UnmanagedCallersOnly(EntryPoint = "device_load")]

View File

@ -83,7 +83,7 @@ namespace LibRyujinx
Logger.SetEnable(LogLevel.AccessLog, false);
Logger.AddTarget(new AsyncLogTargetWrapper(
new FileLogTarget(ReleaseInformation.GetBaseApplicationDirectory(), "file"),
new FileLogTarget(basePath, "file"),
1000,
AsyncLogTargetOverflowAction.Block
));
@ -115,6 +115,14 @@ namespace LibRyujinx
};
}
public static GameInfo GetGameInfo(string file)
{
using var stream = File.Open(file, FileMode.Open);
return GetGameInfo(stream, file.ToLower().EndsWith("xci"));
}
public static GameInfo GetGameInfo(Stream gameStream, bool isXci)
{
var gameInfo = new GameInfo();
@ -530,7 +538,7 @@ namespace LibRyujinx
UserChannelPersistence = new UserChannelPersistence();
}
public bool InitializeContext(bool isHostMapped)
public bool InitializeContext(bool isHostMapped, bool useNce)
{
if(LibRyujinx.Renderer == null)
{