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 Microsoft.Win32.SafeHandles;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using LibHac.Tools.Fs;
namespace LibRyujinx namespace LibRyujinx
{ {
@ -89,9 +90,9 @@ namespace LibRyujinx
} }
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceInitialize")] [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")] [UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceGetGameStats")]
@ -235,10 +236,10 @@ namespace LibRyujinx
var count = getArrayLength(jEnv, extensionsArray); var count = getArrayLength(jEnv, extensionsArray);
for(int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
var obj = getObjectArrayElement(jEnv, extensionsArray, i); var obj = getObjectArrayElement(jEnv, extensionsArray, i);
var ext = obj.Transform<JObjectLocalRef,JStringLocalRef>(); var ext = obj.Transform<JObjectLocalRef, JStringLocalRef>();
extensions.Add(GetString(jEnv, ext)); extensions.Add(GetString(jEnv, ext));
} }
@ -284,13 +285,26 @@ namespace LibRyujinx
RunLoop(); 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")] [UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceGetGameInfo")]
public static JObjectLocalRef JniGetGameInfo(JEnvRef jEnv, JObjectLocalRef jObj, JInt fileDescriptor, JBoolean isXci) public static JObjectLocalRef JniGetGameInfo(JEnvRef jEnv, JObjectLocalRef jObj, JInt fileDescriptor, JBoolean isXci)
{ {
using var stream = OpenFile(fileDescriptor); using var stream = OpenFile(fileDescriptor);
var info = GetGameInfo(stream, isXci) ?? new GameInfo(); 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"); var javaClassName = GetCCharSequence("org/ryujinx/android/viewmodels/GameInfo");
JEnvValue value = jEnv.Environment; JEnvValue value = jEnv.Environment;
@ -305,7 +319,7 @@ namespace LibRyujinx
var findClass = findClassPtr.GetUnsafeDelegate<FindClassDelegate>(); var findClass = findClassPtr.GetUnsafeDelegate<FindClassDelegate>();
var newGlobalRef = newGlobalRefPtr.GetUnsafeDelegate <NewGlobalRefDelegate>(); var newGlobalRef = newGlobalRefPtr.GetUnsafeDelegate<NewGlobalRefDelegate>();
var getFieldId = getFieldIdPtr.GetUnsafeDelegate<GetFieldIdDelegate>(); var getFieldId = getFieldIdPtr.GetUnsafeDelegate<GetFieldIdDelegate>();
var getMethod = getMethodPtr.GetUnsafeDelegate<GetMethodIdDelegate>(); var getMethod = getMethodPtr.GetUnsafeDelegate<GetMethodIdDelegate>();
var newObject = newObjectPtr.GetUnsafeDelegate<NewObjectDelegate>(); var newObject = newObjectPtr.GetUnsafeDelegate<NewObjectDelegate>();
@ -316,9 +330,7 @@ namespace LibRyujinx
var newGlobal = newGlobalRef(jEnv, javaClass._value); var newGlobal = newGlobalRef(jEnv, javaClass._value);
var constructor = getMethod(jEnv, javaClass, GetCCharSequence("<init>"), GetCCharSequence("()V")); var constructor = getMethod(jEnv, javaClass, GetCCharSequence("<init>"), GetCCharSequence("()V"));
var newObj = newObject(jEnv, javaClass, constructor, 0); var newObj = newObject(jEnv, javaClass, constructor, 0);
sha = SHA256.Create();
using var sha = SHA256.Create();
var iconCacheByte = sha.ComputeHash(info.Icon ?? new byte[0]); var iconCacheByte = sha.ComputeHash(info.Icon ?? new byte[0]);
var iconCache = BitConverter.ToString(iconCacheByte).Replace("-", ""); var iconCache = BitConverter.ToString(iconCacheByte).Replace("-", "");

View File

@ -15,17 +15,17 @@ namespace LibRyujinx
[UnmanagedCallersOnly(EntryPoint = "device_initialize")] [UnmanagedCallersOnly(EntryPoint = "device_initialize")]
public static bool InitializeDeviceNative() 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) if (SwitchDevice == null)
{ {
return false; return false;
} }
return SwitchDevice.InitializeContext(isHostMapped); return SwitchDevice.InitializeContext(isHostMapped, useNce);
} }
[UnmanagedCallersOnly(EntryPoint = "device_load")] [UnmanagedCallersOnly(EntryPoint = "device_load")]

View File

@ -83,7 +83,7 @@ namespace LibRyujinx
Logger.SetEnable(LogLevel.AccessLog, false); Logger.SetEnable(LogLevel.AccessLog, false);
Logger.AddTarget(new AsyncLogTargetWrapper( Logger.AddTarget(new AsyncLogTargetWrapper(
new FileLogTarget(ReleaseInformation.GetBaseApplicationDirectory(), "file"), new FileLogTarget(basePath, "file"),
1000, 1000,
AsyncLogTargetOverflowAction.Block 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) public static GameInfo GetGameInfo(Stream gameStream, bool isXci)
{ {
var gameInfo = new GameInfo(); var gameInfo = new GameInfo();
@ -530,7 +538,7 @@ namespace LibRyujinx
UserChannelPersistence = new UserChannelPersistence(); UserChannelPersistence = new UserChannelPersistence();
} }
public bool InitializeContext(bool isHostMapped) public bool InitializeContext(bool isHostMapped, bool useNce)
{ {
if(LibRyujinx.Renderer == null) if(LibRyujinx.Renderer == null)
{ {