Android changes

This commit is contained in:
KeatonTheBot committed 2025-05-16 23:42:48 -05:00
1 parent df21f6019e
commit e8e4c5aa61
464 files changed
+23351 -1429

No files matched your search

@@ -0,0 +1,49 @@
using Ryujinx.Common.Logging;
using Ryujinx.Common.Logging.Formatters;
using Ryujinx.Common.Logging.Targets;
using System;
namespace LibKenjinx
{
public class AndroidLogTarget : ILogTarget
{
private readonly string _name;
private readonly DefaultLogFormatter _formatter;
string ILogTarget.Name { get => _name; }
public AndroidLogTarget(string name)
{
_name = name;
_formatter = new DefaultLogFormatter();
}
public void Log(object sender, LogEventArgs args)
{
Logcat.AndroidLogPrint(GetLogLevel(args.Level), _name, _formatter.Format(args));
}
private static Logcat.LogLevel GetLogLevel(LogLevel logLevel)
{
return logLevel switch
{
LogLevel.Debug => Logcat.LogLevel.Debug,
LogLevel.Stub => Logcat.LogLevel.Info,
LogLevel.Info => Logcat.LogLevel.Info,
LogLevel.Warning => Logcat.LogLevel.Warn,
LogLevel.Error => Logcat.LogLevel.Error,
LogLevel.Guest => Logcat.LogLevel.Info,
LogLevel.AccessLog => Logcat.LogLevel.Info,
LogLevel.Notice => Logcat.LogLevel.Info,
LogLevel.Trace => Logcat.LogLevel.Verbose,
_ => throw new NotImplementedException(),
};
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}
}
+128
View File
@@ -0,0 +1,128 @@
using LibHac.Tools.Fs;
using Ryujinx.Common.Logging;
using Ryujinx.HLE;
using Ryujinx.HLE.HOS.Applets;
using Ryujinx.HLE.HOS.Applets.SoftwareKeyboard;
using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationProxy.Types;
using Ryujinx.HLE.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace LibKenjinx.Android
{
internal class AndroidUIHandler : IHostUIHandler, IDisposable
{
private bool _isDisposed;
private bool _isOkPressed;
private string? _input;
private ManualResetEvent _resetEvent = new ManualResetEvent(false);
public IHostUITheme HostUITheme => throw new NotImplementedException();
public IDynamicTextInputHandler CreateDynamicTextInputHandler()
{
throw new NotImplementedException();
}
public bool DisplayErrorAppletDialog(string title, string message, string[] buttonsText)
{
Interop.UpdateUiHandler(title ?? "",
message ?? "",
"",
1,
0,
0,
KeyboardMode.Default,
"",
"");
return _isOkPressed;
}
public bool DisplayInputDialog(SoftwareKeyboardUIArgs args, out string userText)
{
_input = null;
_resetEvent.Reset();
Interop.UpdateUiHandler("Software Keyboard",
args.HeaderText ?? "",
args.GuideText ?? "",
2,
args.StringLengthMin,
args.StringLengthMax,
args.KeyboardMode,
args.SubtitleText ?? "",
args.InitialText ?? "");
_resetEvent.WaitOne();
userText = _input ?? "";
return _isOkPressed;
}
public bool DisplayMessageDialog(string title, string message)
{
Interop.UpdateUiHandler(title ?? "",
message ?? "",
"",
1,
0,
0,
KeyboardMode.Default,
"",
"");
return _isOkPressed;
}
public bool DisplayMessageDialog(ControllerAppletUIArgs args)
{
string playerCount = args.PlayerCountMin == args.PlayerCountMax ? $"exactly {args.PlayerCountMin}" : $"{args.PlayerCountMin}-{args.PlayerCountMax}";
string message = $"Application requests **{playerCount}** player(s) with:\n\n"
+ $"**TYPES:** {args.SupportedStyles}\n\n"
+ $"**PLAYERS:** {string.Join(", ", args.SupportedPlayers)}\n\n"
+ (args.IsDocked ? "Docked mode set. `Handheld` is also invalid.\n\n" : "")
+ "_Please reconfigure Input now and then press OK._";
return DisplayMessageDialog("Controller Applet", message);
}
public bool DisplayCabinetDialog(out string userText)
{
userText="";
return false;
}
public void DisplayCabinetMessageDialog()
{
}
public void ExecuteProgram(Switch device, ProgramSpecifyKind kind, ulong value)
{
// throw new NotImplementedException();
}
internal void SetResponse(bool isOkPressed, string input)
{
if (_isDisposed)
{
return;
}
_isOkPressed = isOkPressed;
_input = input;
_resetEvent.Set();
}
public void Dispose()
{
_isDisposed = true;
}
}
}
+232
View File
@@ -0,0 +1,232 @@
using LibKenjinx.Jni;
using LibKenjinx.Jni.Identifiers;
using LibKenjinx.Jni.Pointers;
using LibKenjinx.Jni.Primitives;
using LibKenjinx.Jni.References;
using LibKenjinx.Jni.Values;
using Rxmxnx.PInvoke;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Memory;
using Ryujinx.HLE.HOS.Applets.SoftwareKeyboard;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace LibKenjinx.Android
{
internal unsafe static class Interop
{
internal const string BaseClassName = "org/kenjinx/android/KenjinxNative";
private static JGlobalRef? _classId;
private static ConcurrentDictionary<(string method, string descriptor), JMethodId> _methodCache = new ConcurrentDictionary<(string method, string descriptor), JMethodId>();
private static (string name, string descriptor)[] _methods = new[]
{
("test", "()V"),
("updateUiHandler", "(JJJIIIIJJ)V"),
("frameEnded", "()V"),
("updateProgress", "(JF)V"),
("getSurfacePtr", "()J"),
("getWindowHandle", "()J")
};
internal static void Initialize(JEnvRef jniEnv)
{
var vm = JniHelper.GetVirtualMachine(jniEnv);
if (_classId == null)
{
var className = new ReadOnlySpan<Byte>(Encoding.UTF8.GetBytes(BaseClassName));
using (IReadOnlyFixedMemory<Byte>.IDisposable cName = className.GetUnsafeValPtr()
.GetUnsafeFixedContext(className.Length))
{
_classId = JniHelper.GetGlobalClass(jniEnv, cName);
if (_classId == null)
{
Logger.Info?.Print(LogClass.Application, $"Class Id {BaseClassName} not found");
return;
}
}
}
foreach (var x in _methods)
{
CacheMethod(jniEnv, x.name, x.descriptor);
}
JniEnv._jvm = vm;
}
private static void CacheMethod(JEnvRef jEnv, string name, string descriptor)
{
if (!_methodCache.TryGetValue((name, descriptor), out var method))
{
var methodName = new ReadOnlySpan<Byte>(Encoding.UTF8.GetBytes(name));
var descriptorId = new ReadOnlySpan<Byte>(Encoding.UTF8.GetBytes(descriptor));
using (IReadOnlyFixedMemory<Byte>.IDisposable mName = methodName.GetUnsafeValPtr()
.GetUnsafeFixedContext(methodName.Length))
using (IReadOnlyFixedMemory<Byte>.IDisposable dName = descriptorId.GetUnsafeValPtr()
.GetUnsafeFixedContext(descriptorId.Length))
{
var methodId = JniHelper.GetStaticMethodId(jEnv, (JClassLocalRef)(_classId.Value.Value), mName, dName);
if (methodId == null)
{
Logger.Warning?.Print(LogClass.Application, $"Java Method Id {name} not found");
return;
}
method = methodId.Value;
_methodCache[(name, descriptor)] = method;
}
}
}
private static void CallVoidMethod(string name, string descriptor, params JValue[] values)
{
using var env = JniEnv.Create();
if (_methodCache.TryGetValue((name, descriptor), out var method))
{
if (descriptor.EndsWith("V"))
{
JniHelper.CallStaticVoidMethod(env.Env, (JClassLocalRef)(_classId.Value.Value), method, values);
}
}
}
private static JLong CallLongMethod(string name, string descriptor, params JValue[] values)
{
using var env = JniEnv.Create();
if (_methodCache.TryGetValue((name, descriptor), out var method))
{
if (descriptor.EndsWith("J"))
return JniHelper.CallStaticLongMethod(env.Env, (JClassLocalRef)(_classId.Value.Value), method, values) ?? (JLong)(-1);
}
return (JLong)(-1);
}
public static void Test()
{
CallVoidMethod("test", "()V");
}
public static void FrameEnded(double time)
{
CallVoidMethod("frameEnded", "()V");
}
public static void UpdateProgress(string info, float progress)
{
using var infoPtr = new TempNativeString(info);
CallVoidMethod("updateProgress", "(JF)V", new JValue[]
{
JValue.Create(infoPtr.AsBytes()),
JValue.Create(progress.AsBytes())
});
}
public static JLong GetSurfacePtr()
{
return CallLongMethod("getSurfacePtr", "()J");
}
public static JLong GetWindowsHandle()
{
return CallLongMethod("getWindowHandle", "()J");
}
public static void UpdateUiHandler(string newTitle,
string newMessage,
string newWatermark,
int newType,
int min,
int max,
KeyboardMode nMode,
string newSubtitle,
string newInitialText)
{
using var titlePointer = new TempNativeString(newTitle);
using var messagePointer = new TempNativeString(newMessage);
using var watermarkPointer = new TempNativeString(newWatermark);
using var subtitlePointer = new TempNativeString(newSubtitle);
using var newInitialPointer = new TempNativeString(newInitialText);
CallVoidMethod("updateUiHandler", "(JJJIIIIJJ)V", new JValue[]
{
JValue.Create(titlePointer.AsBytes()),
JValue.Create(messagePointer.AsBytes()),
JValue.Create(watermarkPointer.AsBytes()),
JValue.Create(newType.AsBytes()),
JValue.Create(min.AsBytes()),
JValue.Create(max.AsBytes()),
JValue.Create(nMode.AsBytes()),
JValue.Create(subtitlePointer.AsBytes()),
JValue.Create(newInitialPointer.AsBytes())
});
}
private class TempNativeString : IDisposable
{
private JLong _jPointer;
public TempNativeString(string value)
{
Pointer = Marshal.StringToHGlobalAuto(value);
JPointer = (JLong)Pointer;
}
public nint Pointer { get; private set; }
public JLong JPointer { get => _jPointer; private set => _jPointer = value; }
public Span<byte> AsBytes()
{
return _jPointer.AsBytes();
}
public void Dispose()
{
if (Pointer != IntPtr.Zero)
{
Marshal.FreeHGlobal(Pointer);
}
Pointer = IntPtr.Zero;
}
}
private class JniEnv : IDisposable
{
internal static JavaVMRef? _jvm;
private readonly JEnvRef _env;
private readonly bool _newAttach;
public JEnvRef Env => _env;
private JniEnv(JEnvRef env, bool newAttach)
{
_env = env;
_newAttach = newAttach;
}
public void Dispose()
{
if(_newAttach)
{
JniHelper.Detach(_jvm!.Value);
}
}
public static JniEnv? Create()
{
bool newAttach = false;
ReadOnlySpan<Byte> threadName = "JvmCall"u8;
var env = _jvm == null ? default : JniHelper.Attach(_jvm.Value, threadName.GetUnsafeValPtr().GetUnsafeFixedContext(threadName.Length),
out newAttach);
return env != null ? new JniEnv(env.Value, newAttach) : null;
}
}
}
}
+357
View File
@@ -0,0 +1,357 @@
using LibKenjinx.Jni.Identifiers;
using LibKenjinx.Jni.Pointers;
using LibKenjinx.Jni.Primitives;
using LibKenjinx.Jni.References;
using LibKenjinx.Jni.Values;
using System;
using Rxmxnx.PInvoke;
namespace LibKenjinx.Jni;
internal delegate Int32 GetVersionDelegate(JEnvRef env);
internal delegate JResult RegisterNativesDelegate(JEnvRef env, JClassLocalRef jClass,
ReadOnlyValPtr<JNativeMethod> methods0, Int32 nMethods);
internal delegate JResult UnregisterNativesDelegate(JEnvRef env, JClassLocalRef jClass);
internal delegate JResult MonitorEnterDelegate(JEnvRef env, JObjectLocalRef jClass);
internal delegate JResult MonitorExitDelegate(JEnvRef env, JObjectLocalRef jClass);
internal delegate JResult GetVirtualMachineDelegate(JEnvRef env, out JavaVMRef jvm);
internal delegate JResult DestroyVirtualMachineDelegate(JavaVMRef vm);
internal delegate JResult AttachCurrentThreadDelegate(JavaVMRef vm, out JEnvRef env, in JavaVMAttachArgs args);
internal delegate JResult DetachCurrentThreadDelegate(JavaVMRef vm);
internal delegate JResult GetEnvDelegate(JavaVMRef vm, out JEnvRef env, Int32 version);
internal delegate JResult AttachCurrentThreadAsDaemonDelegate(JavaVMRef vm, out JEnvRef env, in JavaVMAttachArgs args);
internal delegate JResult GetCreatedVirtualMachinesDelegate(ValPtr<JavaVMRef> buffer0, Int32 bufferLength,
out Int32 totalVms);
internal delegate JStringLocalRef NewStringDelegate(JEnvRef env, ReadOnlyValPtr<Char> chars0, Int32 length);
internal delegate Int32 GetStringLengthDelegate(JEnvRef env, JStringLocalRef jString);
internal delegate ReadOnlyValPtr<Char>
GetStringCharsDelegate(JEnvRef env, JStringLocalRef jString, out JBoolean isCopy);
internal delegate void ReleaseStringCharsDelegate(JEnvRef env, JStringLocalRef jString, ReadOnlyValPtr<Char> chars0);
internal delegate JStringLocalRef NewStringUtfDelegate(JEnvRef env, ReadOnlyValPtr<Byte> utf8Chars0);
internal delegate Int32 GetStringUtfLengthDelegate(JEnvRef env, JStringLocalRef jString);
internal delegate ReadOnlyValPtr<Byte> GetStringUtfCharsDelegate(JEnvRef env, JStringLocalRef jString,
out JBoolean isCopy);
internal delegate void ReleaseStringUtfCharsDelegate(JEnvRef env, JStringLocalRef jString,
ReadOnlyValPtr<Byte> utf8Chars0);
internal delegate void GetStringRegionDelegate(JEnvRef env, JStringLocalRef jString, Int32 startIndex, Int32 length,
ValPtr<Char> buffer0);
internal delegate void GetStringUtfRegionDelegate(JEnvRef env, JStringLocalRef jString, Int32 startIndex, Int32 length,
ValPtr<Byte> buffer0);
internal delegate ReadOnlyValPtr<Char> GetStringCriticalDelegate(JEnvRef env, JStringLocalRef jString,
out JBoolean isCopy);
internal delegate void ReleaseStringCriticalDelegate(JEnvRef env, JStringLocalRef jString, ReadOnlyValPtr<Char> chars0);
internal delegate JObjectLocalRef CallStaticObjectMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JBoolean CallStaticBooleanMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JByte CallStaticByteMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JChar CallStaticCharMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JShort CallStaticShortMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JInt CallStaticIntMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JLong CallStaticLongMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JFloat CallStaticFloatMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JDouble CallStaticDoubleMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate void CallStaticVoidMethodADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JObjectLocalRef GetStaticObjectFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JBoolean GetStaticBooleanFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JByte GetStaticByteFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JChar GetStaticCharFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JShort GetStaticShortFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JInt GetStaticIntFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JLong GetStaticLongFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JFloat GetStaticFloatFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate JDouble GetStaticDoubleFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField);
internal delegate void SetStaticObjectFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField,
JObjectLocalRef value);
internal delegate void SetStaticBooleanFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField,
JBoolean value);
internal delegate void SetStaticByteFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField, JByte value);
internal delegate void SetStaticCharFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField, JChar value);
internal delegate void SetStaticShortFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField, JShort value);
internal delegate void SetStaticIntFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField, JInt value);
internal delegate void SetStaticLongFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField, JLong value);
internal delegate void SetStaticFloatFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField, JFloat value);
internal delegate void SetStaticDoubleFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId jField, JDouble value);
internal delegate JMethodId FromReflectedMethodDelegate(JEnvRef env, JObjectLocalRef method);
internal delegate JFieldId FromReflectedFieldDelegate(JEnvRef env, JObjectLocalRef field);
internal delegate JResult PushLocalFrameDelegate(JEnvRef env, Int32 capacity);
internal delegate JObjectLocalRef PopLocalFrameDelegate(JEnvRef env, JObjectLocalRef result);
internal delegate JGlobalRef NewGlobalRefDelegate(JEnvRef env, JObjectLocalRef localRef);
internal delegate void DeleteGlobalRefDelegate(JEnvRef env, JGlobalRef globalRef);
internal delegate void DeleteLocalRefDelegate(JEnvRef env, JObjectLocalRef localRef);
internal delegate JBoolean IsSameObjectDelegate(JEnvRef env, JObjectLocalRef obj1, JObjectLocalRef obj2);
internal delegate JObjectLocalRef NewLocalRefDelegate(JEnvRef env, JObjectLocalRef objRef);
internal delegate JResult EnsureLocalCapacityDelegate(JEnvRef env, Int32 capacity);
internal delegate JWeakRef NewWeakGlobalRefDelegate(JEnvRef env, JObjectLocalRef obj);
internal delegate void DeleteWeakGlobalRefDelegate(JEnvRef env, JWeakRef jWeak);
internal delegate JReferenceType GetObjectRefTypeDelegate(JEnvRef env, JObjectLocalRef obj);
internal delegate JObjectLocalRef CallNonVirtualObjectMethodADelegate(JEnvRef env, JObjectLocalRef obj,
JClassLocalRef jClass, JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JBoolean CallNonVirtualBooleanMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JByte CallNonVirtualByteMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JChar CallNonVirtualCharMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JShort CallNonVirtualShortMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JInt CallNonVirtualIntMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JLong CallNonVirtualLongMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JFloat CallNonVirtualFloatMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JDouble CallNonVirtualDoubleMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate void CallNonVirtualVoidMethodADelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass,
JMethodId jMethod, ReadOnlyValPtr<JValue> args0);
internal delegate JObjectLocalRef CallObjectMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JBoolean CallBooleanMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JByte CallByteMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JChar CallCharMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JShort CallShortMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JInt CallIntMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JLong CallLongMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JFloat CallFloatMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JDouble CallDoubleMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate void CallVoidMethodADelegate(JEnvRef env, JObjectLocalRef obj, JMethodId jMethod,
ReadOnlyValPtr<JValue> args0);
internal delegate JObjectLocalRef GetObjectFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JBoolean GetBooleanFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JByte GetByteFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JChar GetCharFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JShort GetShortFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JInt GetIntFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JLong GetLongFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JFloat GetFloatFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate JDouble GetDoubleFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField);
internal delegate void SetObjectFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JObjectLocalRef value);
internal delegate void SetBooleanFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JBoolean value);
internal delegate void SetByteFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JByte value);
internal delegate void SetCharFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JChar value);
internal delegate void SetShortFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JShort value);
internal delegate void SetIntFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JInt value);
internal delegate void SetLongFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JLong value);
internal delegate void SetFloatFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JFloat value);
internal delegate void SetDoubleFieldDelegate(JEnvRef env, JObjectLocalRef obj, JFieldId jField, JDouble value);
internal delegate JResult ThrowDelegate(JEnvRef env, JThrowableLocalRef obj);
internal delegate JResult ThrowNewDelegate(JEnvRef env, JClassLocalRef jClass, ReadOnlyValPtr<Byte> messageChars0);
internal delegate JThrowableLocalRef ExceptionOccurredDelegate(JEnvRef env);
internal delegate void ExceptionDescribeDelegate(JEnvRef env);
internal delegate void ExceptionClearDelegate(JEnvRef env);
internal delegate void FatalErrorDelegate(JEnvRef env, ReadOnlyValPtr<Byte> messageChars0);
internal delegate JBoolean ExceptionCheckDelegate(JEnvRef env);
internal delegate JObjectLocalRef NewDirectByteBufferDelegate(JEnvRef env, IntPtr address, Int64 capacity);
internal delegate IntPtr GetDirectBufferAddressDelegate(JEnvRef env, JObjectLocalRef buffObj);
internal delegate Int64 GetDirectBufferCapacityDelegate(JEnvRef env, JObjectLocalRef buffObj);
internal delegate JClassLocalRef DefineClassDelegate(JEnvRef env, ReadOnlyValPtr<Byte> nameChars0,
JObjectLocalRef loader, IntPtr binaryData, Int32 len);
internal delegate JClassLocalRef FindClassDelegate(JEnvRef env, ReadOnlyValPtr<Byte> nameChars0);
internal delegate JObjectLocalRef ToReflectedMethodDelegate(JEnvRef env, JClassLocalRef jClass, JMethodId methodId,
JBoolean isStatic);
internal delegate JClassLocalRef GetSuperclassDelegate(JEnvRef env, JClassLocalRef sub);
internal delegate JBoolean IsAssignableFromDelegate(JEnvRef env, JClassLocalRef sub, JClassLocalRef sup);
internal delegate JClassLocalRef GetObjectClassDelegate(JEnvRef env, JObjectLocalRef obj);
internal delegate JBoolean IsInstanceOfDelegate(JEnvRef env, JObjectLocalRef obj, JClassLocalRef jClass);
internal delegate JObjectLocalRef ToReflectedFieldDelegate(JEnvRef env, JClassLocalRef jClass, JFieldId fieldId,
JBoolean isStatic);
internal delegate JMethodId GetMethodIdDelegate(JEnvRef env, JClassLocalRef jClass, ReadOnlyValPtr<Byte> nameChars0,
ReadOnlyValPtr<Byte> signatureChars0);
internal delegate JFieldId GetFieldIdDelegate(JEnvRef env, JClassLocalRef jClass, ReadOnlyValPtr<Byte> nameChars0,
ReadOnlyValPtr<Byte> signatureChars0);
internal delegate JMethodId GetStaticMethodIdDelegate(JEnvRef env, JClassLocalRef jClass,
ReadOnlyValPtr<Byte> nameChars0, ReadOnlyValPtr<Byte> signatureChars0);
internal delegate JFieldId GetStaticFieldIdDelegate(JEnvRef env, JClassLocalRef jClass, ReadOnlyValPtr<Byte> nameChars0,
ReadOnlyValPtr<Byte> signatureChars0);
internal delegate Int32 GetArrayLengthDelegate(JEnvRef env, JArrayLocalRef array);
internal delegate JArrayLocalRef NewObjectArrayDelegate(JEnvRef env, Int32 length, JClassLocalRef jClass,
JObjectLocalRef init);
internal delegate JObjectLocalRef GetObjectArrayElementDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 index);
internal delegate void SetObjectArrayElementDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 index,
JObjectLocalRef obj);
internal delegate JArrayLocalRef NewBooleanArrayDelegate(JEnvRef env, Int32 length);
internal delegate JArrayLocalRef NewByteArrayDelegate(JEnvRef env, Int32 length);
internal delegate JArrayLocalRef NewCharArrayDelegate(JEnvRef env, Int32 length);
internal delegate JArrayLocalRef NewShortArrayDelegate(JEnvRef env, Int32 length);
internal delegate JArrayLocalRef NewIntArrayDelegate(JEnvRef env, Int32 length);
internal delegate JArrayLocalRef NewLongArrayDelegate(JEnvRef env, Int32 length);
internal delegate JArrayLocalRef NewFloatArrayDelegate(JEnvRef env, Int32 length);
internal delegate JArrayLocalRef NewDoubleArrayDelegate(JEnvRef env, Int32 length);
internal delegate ValPtr<JBoolean> GetBooleanArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
out JBoolean isCopy);
internal delegate ValPtr<JByte> GetByteArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef, out JBoolean isCopy);
internal delegate ValPtr<JChar> GetCharArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef, out JBoolean isCopy);
internal delegate ValPtr<JShort> GetShortArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
out JBoolean isCopy);
internal delegate ValPtr<JInt> GetIntArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef, out JBoolean isCopy);
internal delegate ValPtr<JLong> GetLongArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef, out JBoolean isCopy);
internal delegate ValPtr<JFloat> GetFloatArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
out JBoolean isCopy);
internal delegate ValPtr<JDouble> GetDoubleArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
out JBoolean isCopy);
internal delegate void ReleaseBooleanArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JBoolean> elements0, JReleaseMode mode);
internal delegate void ReleaseByteArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JByte> elements0, JReleaseMode mode);
internal delegate void ReleaseCharArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JChar> elements0, JReleaseMode mode);
internal delegate void ReleaseShortArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JShort> elements0, JReleaseMode mode);
internal delegate void ReleaseIntArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JInt> elements0, JReleaseMode mode);
internal delegate void ReleaseLongArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JLong> elements0, JReleaseMode mode);
internal delegate void ReleaseFloatArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JFloat> elements0, JReleaseMode mode);
internal delegate void ReleaseDoubleArrayElementsDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ReadOnlyValPtr<JDouble> elements0, JReleaseMode mode);
internal delegate void GetBooleanArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex,
Int32 length, ValPtr<JBoolean> buffer0);
internal delegate void GetByteArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ValPtr<JByte> buffer0);
internal delegate void GetCharArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ValPtr<JChar> buffer0);
internal delegate void GetShortArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ValPtr<JShort> buffer0);
internal delegate void GetIntArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ValPtr<JInt> buffer0);
internal delegate void GetLongArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ValPtr<JLong> buffer0);
internal delegate void GetFloatArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ValPtr<JFloat> buffer0);
internal delegate void GetDoubleArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex,
Int32 length, ValPtr<JDouble> buffer0);
internal delegate void SetBooleanArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex,
Int32 length, ReadOnlyValPtr<JBoolean> buffer0);
internal delegate void SetByteArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ReadOnlyValPtr<JByte> buffer0);
internal delegate void SetCharArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ReadOnlyValPtr<JChar> buffer0);
internal delegate void SetShortArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ReadOnlyValPtr<JShort> buffer0);
internal delegate void SetIntArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ReadOnlyValPtr<JInt> buffer0);
internal delegate void SetLongArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ReadOnlyValPtr<JLong> buffer0);
internal delegate void SetFloatArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex, Int32 length,
ReadOnlyValPtr<JFloat> buffer0);
internal delegate void SetDoubleArrayRegionDelegate(JEnvRef env, JArrayLocalRef arrayRef, Int32 startIndex,
Int32 length, ReadOnlyValPtr<JDouble> buffer0);
internal delegate ValPtr<Byte> GetPrimitiveArrayCriticalDelegate(JEnvRef env, JArrayLocalRef arrayRef,
out JBoolean isCopy);
internal delegate void ReleasePrimitiveArrayCriticalDelegate(JEnvRef env, JArrayLocalRef arrayRef,
ValPtr<Byte> elements, JReleaseMode mode);
internal delegate JObjectLocalRef NewObjectADelegate(JEnvRef env, JClassLocalRef jClass, JMethodId jMethod,
ReadOnlyValPtr<JValue> arg0);
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.Identifiers
{
public readonly struct JFieldId : IEquatable<JFieldId>
{
#pragma warning disable 0649
private readonly IntPtr _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JFieldId other)
=> this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj)
=> obj is JFieldId other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static Boolean operator ==(JFieldId a, JFieldId b) => a.Equals(b);
public static Boolean operator !=(JFieldId a, JFieldId b) => !a.Equals(b);
#endregion
}
}
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.Identifiers
{
public readonly struct JMethodId : IEquatable<JMethodId>
{
#pragma warning disable 0649
private readonly IntPtr _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JMethodId other)
=> this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj)
=> obj is JMethodId other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static Boolean operator ==(JMethodId a, JMethodId b) => a.Equals(b);
public static Boolean operator !=(JMethodId a, JMethodId b) => !a.Equals(b);
#endregion
}
}
@@ -0,0 +1,12 @@
using System;
namespace LibKenjinx.Jni
{
public enum JReferenceType : Int32
{
InvalidRefType = 0,
LocalRefType = 1,
GlobalRefType = 2,
WeakGlobalRefType = 3
}
}
@@ -0,0 +1,11 @@
using System;
namespace LibKenjinx.Jni
{
public enum JReleaseMode : Int32
{
Free = 0,
Commit = 1,
Abort = 2,
}
}
+15
View File
@@ -0,0 +1,15 @@
using System;
namespace LibKenjinx.Jni
{
public enum JResult : Int32
{
Ok = 0,
Error = -1,
DetachedThreadError = -2,
VersionError = -3,
MemoryError = -4,
ExitingVMError = -5,
InvalidArgumentsError = -6,
}
}
+251
View File
@@ -0,0 +1,251 @@
using LibKenjinx.Jni.Identifiers;
using LibKenjinx.Jni.Pointers;
using LibKenjinx.Jni.Primitives;
using LibKenjinx.Jni.References;
using LibKenjinx.Jni.Values;
using System;
using Rxmxnx.PInvoke;
namespace LibKenjinx.Jni
{
internal static class JniHelper
{
public const Int32 JniVersion = 0x00010006; //JNI_VERSION_1_6;
public static JEnvRef? Attach(JavaVMRef javaVm, IReadOnlyFixedMemory<Byte> threadName, out Boolean newAttach)
{
ref JavaVMValue value = ref javaVm.VirtualMachine;
ref JInvokeInterface jInvoke = ref value.Functions;
IntPtr getEnvPtr = jInvoke.GetEnvPointer;
GetEnvDelegate getEnv = getEnvPtr.GetUnsafeDelegate<GetEnvDelegate>()!;
if (getEnv(javaVm, out JEnvRef jEnv, JniHelper.JniVersion) == JResult.Ok)
{
newAttach = false;
return jEnv;
}
JavaVMAttachArgs args = new() { Version = JniHelper.JniVersion, Name = threadName.ValuePointer, };
IntPtr attachCurrentThreadPtr = jInvoke.AttachCurrentThreadPointer;
AttachCurrentThreadDelegate attachCurrentThread =
attachCurrentThreadPtr.GetUnsafeDelegate<AttachCurrentThreadDelegate>()!;
newAttach = true;
return attachCurrentThread(javaVm, out jEnv, in args) == JResult.Ok ? jEnv : null;
}
public static JEnvRef? AttachDaemon(JavaVMRef javaVm, IReadOnlyFixedMemory<Byte> daemonName)
{
ref JavaVMValue value = ref javaVm.VirtualMachine;
ref JInvokeInterface jInvoke = ref value.Functions;
JavaVMAttachArgs args = new() { Version = JniHelper.JniVersion, Name = daemonName.ValuePointer, };
IntPtr attachCurrentThreadAsDaemonPtr = jInvoke.AttachCurrentThreadAsDaemonPointer;
AttachCurrentThreadAsDaemonDelegate attachCurrentThreadAsDaemon =
attachCurrentThreadAsDaemonPtr.GetUnsafeDelegate<AttachCurrentThreadAsDaemonDelegate>()!;
return attachCurrentThreadAsDaemon(javaVm, out JEnvRef jEnv, in args) == JResult.Ok ? jEnv : null;
}
public static void Detach(JavaVMRef javaVm)
{
ref JavaVMValue value = ref javaVm.VirtualMachine;
ref JInvokeInterface jInvoke = ref value.Functions;
IntPtr detachCurrentThreadPtr = jInvoke.DetachCurrentThreadPointer;
DetachCurrentThreadDelegate detachCurrentThread =
detachCurrentThreadPtr.GetUnsafeDelegate<DetachCurrentThreadDelegate>()!;
detachCurrentThread(javaVm);
}
public static JGlobalRef? GetGlobalClass(JEnvRef jEnv, IReadOnlyFixedMemory<Byte> className)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr findClassPtr = jInterface.FindClassPointer;
FindClassDelegate findClass = findClassPtr.GetUnsafeDelegate<FindClassDelegate>()!;
JClassLocalRef jClass = findClass(jEnv, className.ValuePointer);
if (JniHelper.ExceptionCheck(jEnv))
return default;
IntPtr newGlobalRefPtr = jInterface.NewGlobalRefPointer;
NewGlobalRefDelegate newGlobalRef = newGlobalRefPtr.GetUnsafeDelegate<NewGlobalRefDelegate>()!;
JGlobalRef jGlobal = newGlobalRef(jEnv, (JObjectLocalRef)jClass);
JniHelper.RemoveLocal(jEnv, (JObjectLocalRef)jClass);
return !JniHelper.ExceptionCheck(jEnv) ? jGlobal : null;
}
public static void RemoveLocal(JEnvRef jEnv, JObjectLocalRef jObject)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr deleteLocalRefPtr = jInterface.DeleteLocalRefPointer;
DeleteLocalRefDelegate deleteLocalRef = deleteLocalRefPtr.GetUnsafeDelegate<DeleteLocalRefDelegate>()!;
deleteLocalRef(jEnv, jObject);
}
public static void RemoveGlobal(JEnvRef jEnv, JGlobalRef jObject)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr deleteGlobalRefPtr = jInterface.DeleteGlobalRefPointer;
DeleteGlobalRefDelegate deleteGlobalRef = deleteGlobalRefPtr.GetUnsafeDelegate<DeleteGlobalRefDelegate>()!;
deleteGlobalRef(jEnv, jObject);
}
public static void RemoveWeakGlobal(JEnvRef jEnv, JWeakRef jObject)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr deleteWeakGlobalRefPtr = jInterface.DeleteWeakGlobalRefPointer;
DeleteWeakGlobalRefDelegate deleteWeakGlobalRef =
deleteWeakGlobalRefPtr.GetUnsafeDelegate<DeleteWeakGlobalRefDelegate>()!;
deleteWeakGlobalRef(jEnv, jObject);
}
public static JStringLocalRef? CreateString(JEnvRef jEnv, String textValue)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr newStringPtr = jInterface.NewStringPointer;
NewStringDelegate newString = newStringPtr.GetUnsafeDelegate<NewStringDelegate>()!;
using IReadOnlyFixedMemory<Char>.IDisposable ctx = textValue.AsMemory().GetFixedContext();
JStringLocalRef jString = newString(jEnv, ctx.ValuePointer, ctx.Values.Length);
return !JniHelper.ExceptionCheck(jEnv) ? jString : null;
}
public static JWeakRef? CreateWeakGlobal(JEnvRef jEnv, JObjectLocalRef jObject)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr newWeakGlobalRefPtr = jInterface.NewWeakGlobalRefPointer;
NewWeakGlobalRefDelegate newWeakGlobalRef = newWeakGlobalRefPtr.GetUnsafeDelegate<NewWeakGlobalRefDelegate>()!;
JWeakRef jWeak = newWeakGlobalRef(jEnv, jObject);
return !JniHelper.ExceptionCheck(jEnv) ? jWeak : null;
}
private static Boolean ExceptionCheck(JEnvRef jEnv)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr exceptionCheckPtr = jInterface.ExceptionCheckPointer;
ExceptionCheckDelegate exceptionCheck = exceptionCheckPtr.GetUnsafeDelegate<ExceptionCheckDelegate>()!;
if (!exceptionCheck(jEnv))
return false;
IntPtr exceptionDescribePtr = jInterface.ExceptionDescribePointer;
IntPtr exceptionClearPtr = jInterface.ExceptionClearPointer;
ExceptionDescribeDelegate exceptionDescribe =
exceptionDescribePtr.GetUnsafeDelegate<ExceptionDescribeDelegate>()!;
ExceptionClearDelegate exceptionClear = exceptionClearPtr.GetUnsafeDelegate<ExceptionClearDelegate>()!;
exceptionDescribe(jEnv);
exceptionClear(jEnv);
return true;
}
public static JavaVMRef? GetVirtualMachine(JEnvRef jEnv)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr getJavaVmPtr = jInterface.GetJavaVMPointer;
GetVirtualMachineDelegate getJavaVm = getJavaVmPtr.GetUnsafeDelegate<GetVirtualMachineDelegate>()!;
return getJavaVm(jEnv, out JavaVMRef javaVm) == JResult.Ok ? javaVm : null;
}
public static Boolean? IsValidGlobalWeak(JEnvRef jEnv, JWeakRef jWeak)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr isSameObjectPtr = jInterface.IsSameObjectPointer;
IsSameObjectDelegate isSameObject = isSameObjectPtr.GetUnsafeDelegate<IsSameObjectDelegate>()!;
JBoolean result = isSameObject(jEnv, (JObjectLocalRef)jWeak, default);
return !JniHelper.ExceptionCheck(jEnv) ? !result : null;
}
public static JMethodId? GetMethodId(JEnvRef jEnv, JClassLocalRef jClass, IReadOnlyFixedMemory<Byte> methodName,
IReadOnlyFixedMemory<Byte> descriptor)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr getMethodIdPtr = jInterface.GetMethodIdPointer;
GetMethodIdDelegate getMethodId = getMethodIdPtr.GetUnsafeDelegate<GetMethodIdDelegate>()!;
JMethodId methodId = getMethodId(jEnv, jClass, methodName.ValuePointer, descriptor.ValuePointer);
return !JniHelper.ExceptionCheck(jEnv) ? methodId : null;
}
public static JMethodId? GetStaticMethodId(JEnvRef jEnv, JClassLocalRef jClass,
IReadOnlyFixedMemory<Byte> methodName, IReadOnlyFixedMemory<Byte> descriptor)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr getStaticMethodIdPtr = jInterface.GetStaticMethodIdPointer;
GetStaticMethodIdDelegate getStaticMethodId =
getStaticMethodIdPtr.GetUnsafeDelegate<GetStaticMethodIdDelegate>()!;
JMethodId jMethodId = getStaticMethodId(jEnv, jClass, methodName.ValuePointer, descriptor.ValuePointer);
return !JniHelper.ExceptionCheck(jEnv) ? jMethodId : null;
}
public static void CallStaticVoidMethod(JEnvRef jEnv, JClassLocalRef jClass, JMethodId jMethodId,
params JValue[] args)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr callStaticVoidMethodPtr = jInterface.CallStaticVoidMethodAPointer;
CallStaticVoidMethodADelegate callStaticVoidMethod =
callStaticVoidMethodPtr.GetUnsafeDelegate<CallStaticVoidMethodADelegate>()!;
using IReadOnlyFixedMemory<JValue>.IDisposable fArgs = args.AsMemory().GetFixedContext();
callStaticVoidMethod(jEnv, jClass, jMethodId, fArgs.ValuePointer);
}
public static JObjectLocalRef? CallStaticObjectMethod(JEnvRef jEnv, JClassLocalRef jClass, JMethodId jMethodId,
params JValue[] args)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr callStaticObjectMethodPtr = jInterface.CallStaticObjectMethodAPointer;
CallStaticObjectMethodADelegate callStaticObjectMethod =
callStaticObjectMethodPtr.GetUnsafeDelegate<CallStaticObjectMethodADelegate>()!;
using IReadOnlyFixedMemory<JValue>.IDisposable fArgs = args.AsMemory().GetFixedContext();
JObjectLocalRef jObject = callStaticObjectMethod(jEnv, jClass, jMethodId, fArgs.ValuePointer);
return !JniHelper.ExceptionCheck(jEnv) ? jObject : null;
}
public static JLong? CallStaticLongMethod(JEnvRef jEnv, JClassLocalRef jClass, JMethodId jMethodId,
params JValue[] args)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr callStaticLongMethodPtr = jInterface.CallStaticLongMethodAPointer;
CallStaticLongMethodADelegate callStaticLongMethod =
callStaticLongMethodPtr.GetUnsafeDelegate<CallStaticLongMethodADelegate>()!;
using IReadOnlyFixedMemory<JValue>.IDisposable fArgs = args.AsMemory().GetFixedContext();
JLong jLong = callStaticLongMethod(jEnv, jClass, jMethodId, fArgs.ValuePointer);
return !JniHelper.ExceptionCheck(jEnv) ? jLong : null;
}
public static void CallVoidMethod(JEnvRef jEnv, JObjectLocalRef jObject, JMethodId jMethodId, params JValue[] args)
{
ref readonly JEnvValue value = ref jEnv.Environment;
ref JNativeInterface jInterface = ref value.Functions;
IntPtr callVoidMethodPtr = jInterface.CallVoidMethodAPointer;
CallVoidMethodADelegate callVoidMethod = callVoidMethodPtr.GetUnsafeDelegate<CallVoidMethodADelegate>()!;
using IReadOnlyFixedMemory<JValue>.IDisposable fArgs = args.AsMemory().GetFixedContext();
callVoidMethod(jEnv, jObject, jMethodId, fArgs.ValuePointer);
}
}
}
@@ -0,0 +1,37 @@
using LibKenjinx.Jni.Values;
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Pointers
{
public readonly struct JEnvRef : IEquatable<JEnvRef>
{
#pragma warning disable 0649
private readonly IntPtr _value;
#pragma warning restore 0649
public JEnvRef(IntPtr val)
{
_value = val;
}
#region Operators
public static Boolean operator ==(JEnvRef a, JEnvRef b) => a._value.Equals(b._value);
public static Boolean operator !=(JEnvRef a, JEnvRef b) => !a._value.Equals(b._value);
#endregion
#region Public Properties
internal readonly ref JEnvValue Environment => ref this._value.GetUnsafeReference<JEnvValue>();
#endregion
#region Public Methods
public Boolean Equals(JEnvRef other) => this._value.Equals(other._value);
#endregion
#region Overrided Methods
public override Boolean Equals(Object obj) => obj is JEnvRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,31 @@
using LibKenjinx.Jni.Values;
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Pointers;
public readonly struct JavaVMRef : IEquatable<JavaVMRef>
{
#pragma warning disable 0649
private readonly IntPtr _value;
#pragma warning restore 0649
#region Operators
public static Boolean operator ==(JavaVMRef a, JavaVMRef b) => a._value.Equals(b._value);
public static Boolean operator !=(JavaVMRef a, JavaVMRef b) => !a._value.Equals(b._value);
#endregion
#region Public Properties
internal readonly ref JavaVMValue VirtualMachine => ref this._value.GetUnsafeReference<JavaVMValue>();
#endregion
#region Public Methods
public Boolean Equals(JavaVMRef other) => this._value.Equals(other._value);
#endregion
#region Overrided Methods
public override Boolean Equals(Object obj) => obj is JavaVMRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
@@ -0,0 +1,67 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives;
public readonly struct JBoolean : IComparable<Boolean>, IEquatable<Boolean>
{
internal static readonly Type Type = typeof(JBoolean);
private const Byte trueByte = 1;
private const Byte falseByte = 0;
public static readonly CString Signature = (CString)"Z";
private readonly Byte _value;
private Boolean Value => this._value == JBoolean.trueByte;
private JBoolean(Boolean value) => this._value = value ? JBoolean.trueByte : JBoolean.falseByte;
#region Operators
public static implicit operator JBoolean(Boolean value) => new(value);
public static implicit operator Boolean(JBoolean jValue) => jValue._value == 1;
public static JBoolean operator !(JBoolean a) => new(!a.Value);
public static JBoolean operator |(JBoolean a, JBoolean b) => new(a.Value || b.Value);
public static JBoolean operator |(Boolean a, JBoolean b) => new(a || b.Value);
public static JBoolean operator |(JBoolean a, Boolean b) => new(a.Value || b);
public static JBoolean operator &(JBoolean a, JBoolean b) => new(a.Value && b.Value);
public static JBoolean operator &(Boolean a, JBoolean b) => new(a && b.Value);
public static JBoolean operator &(JBoolean a, Boolean b) => new(a.Value && b);
public static Boolean operator ==(JBoolean a, JBoolean b) => a._value.Equals(b._value);
public static Boolean operator ==(Boolean a, JBoolean b) => a.Equals(b._value);
public static Boolean operator ==(JBoolean a, Boolean b) => a._value.Equals(b);
public static Boolean operator !=(JBoolean a, JBoolean b) => !a._value.Equals(b._value);
public static Boolean operator !=(Boolean a, JBoolean b) => !a.Equals(b._value);
public static Boolean operator !=(JBoolean a, Boolean b) => !a._value.Equals(b);
public static Boolean operator >(JBoolean a, JBoolean b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(Boolean a, JBoolean b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JBoolean a, Boolean b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JBoolean a, JBoolean b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(Boolean a, JBoolean b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JBoolean a, Boolean b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JBoolean a, JBoolean b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(Boolean a, JBoolean b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JBoolean a, Boolean b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JBoolean a, JBoolean b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(Boolean a, JBoolean b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JBoolean a, Boolean b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(Boolean other) => this._value.CompareTo(other);
public Int32 CompareTo(JBoolean other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj)
=> obj is JBoolean jvalue ? this.CompareTo(jvalue) :
obj is Boolean value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(Boolean other) => this._value.Equals(other);
public Boolean Equals(JBoolean other) => this._value.Equals(other._value);
public String ToString(IFormatProvider formatProvider) => this._value.ToString(formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj)
=> obj is JBoolean jvalue ? this.Equals(jvalue) :
obj is Boolean value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
@@ -0,0 +1,74 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives
{
public readonly struct JByte : IComparable<SByte>, IEquatable<SByte>, IFormattable
{
internal static readonly Type Type = typeof(JByte);
public static readonly CString Signature = (CString)"B";
private readonly SByte _value;
private JByte(SByte value) => this._value = value;
private JByte(Int32 value) => this._value = Convert.ToSByte(value);
#region Operators
public static implicit operator JByte(SByte value) => new(value);
public static implicit operator SByte(JByte jValue) => jValue._value;
public static JByte operator +(JByte a) => a;
public static JByte operator ++(JByte a) => new(a._value + 1);
public static JByte operator -(JByte a) => new(-a._value);
public static JByte operator --(JByte a) => new(a._value - 1);
public static JByte operator +(JByte a, JByte b) => new(a._value + b._value);
public static JByte operator +(SByte a, JByte b) => new(a + b._value);
public static JByte operator +(JByte a, SByte b) => new(a._value + b);
public static JByte operator -(JByte a, JByte b) => new(a._value - b._value);
public static JByte operator -(SByte a, JByte b) => new(a - b._value);
public static JByte operator -(JByte a, SByte b) => new(a._value - b);
public static JByte operator *(JByte a, JByte b) => new(a._value * b._value);
public static JByte operator *(SByte a, JByte b) => new(a * b._value);
public static JByte operator *(JByte a, SByte b) => new(a._value * b);
public static JByte operator /(JByte a, JByte b) => new(a._value / b._value);
public static JByte operator /(SByte a, JByte b) => new(a / b._value);
public static JByte operator /(JByte a, SByte b) => new(a._value / b);
public static JByte operator %(JByte a, JByte b) => new(a._value % b._value);
public static JByte operator %(SByte a, JByte b) => new(a % b._value);
public static JByte operator %(JByte a, SByte b) => new(a._value % b);
public static Boolean operator ==(JByte a, JByte b) => a._value.Equals(b._value);
public static Boolean operator ==(SByte a, JByte b) => a.Equals(b._value);
public static Boolean operator ==(JByte a, SByte b) => a._value.Equals(b);
public static Boolean operator !=(JByte a, JByte b) => !a._value.Equals(b._value);
public static Boolean operator !=(SByte a, JByte b) => !a.Equals(b._value);
public static Boolean operator !=(JByte a, SByte b) => !a._value.Equals(b);
public static Boolean operator >(JByte a, JByte b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(SByte a, JByte b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JByte a, SByte b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JByte a, JByte b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(SByte a, JByte b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JByte a, SByte b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JByte a, JByte b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(SByte a, JByte b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JByte a, SByte b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JByte a, JByte b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(SByte a, JByte b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JByte a, SByte b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(SByte other) => this._value.CompareTo(other);
public Int32 CompareTo(JByte other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj) => obj is JByte jValue ? this.CompareTo(jValue) : obj is SByte value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(SByte other) => this._value.Equals(other);
public Boolean Equals(JByte other) => this._value.Equals(other._value);
public String ToString(String format, IFormatProvider formatProvider) => this._value.ToString(format, formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj) => obj is JByte jvalue ? this.Equals(jvalue) : obj is SByte value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,56 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives
{
public readonly struct JChar : IComparable<Char>, IEquatable<Char>
{
internal static readonly Type Type = typeof(JChar);
public static readonly CString Signature = (CString)"C";
private readonly Char _value;
private JChar(Char value) => this._value = value;
#region Operators
public static implicit operator JChar(Char value) => new(value);
public static explicit operator JChar(Int16 value) => new((Char)value);
public static implicit operator Char(JChar jValue) => jValue._value;
public static explicit operator Int16(JChar jValue) => (Int16)jValue._value;
public static Boolean operator ==(JChar a, JChar b) => a._value.Equals(b._value);
public static Boolean operator ==(Char a, JChar b) => a.Equals(b._value);
public static Boolean operator ==(JChar a, Char b) => a._value.Equals(b);
public static Boolean operator !=(JChar a, JChar b) => !a._value.Equals(b._value);
public static Boolean operator !=(Char a, JChar b) => !a.Equals(b._value);
public static Boolean operator !=(JChar a, Char b) => !a._value.Equals(b);
public static Boolean operator >(JChar a, JChar b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(Char a, JChar b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JChar a, Char b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JChar a, JChar b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(Char a, JChar b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JChar a, Char b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JChar a, JChar b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(Char a, JChar b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JChar a, Char b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JChar a, JChar b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(Char a, JChar b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JChar a, Char b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(Char other) => this._value.CompareTo(other);
public Int32 CompareTo(JChar other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj) => obj is JChar jvalue ? this.CompareTo(jvalue) : obj is Char value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(Char other) => this._value.Equals(other);
public Boolean Equals(JChar other) => this._value.Equals(other._value);
public String ToString(IFormatProvider formatProvider) => this._value.ToString(formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj) => obj is JChar jvalue ? this.Equals(jvalue) : obj is Char value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,70 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives
{
public readonly struct JDouble : IComparable<Double>, IEquatable<Double>, IFormattable
{
internal static readonly Type Type = typeof(JDouble);
public static readonly CString Signature = (CString)"D";
private readonly Double _value;
private JDouble(Double value) => this._value = value;
#region Operators
public static implicit operator JDouble(Double value) => new(value);
public static implicit operator Double(JDouble jValue) => jValue._value;
public static JDouble operator +(JDouble a) => a;
public static JDouble operator ++(JDouble a) => new(a._value + 1);
public static JDouble operator -(JDouble a) => new(-a._value);
public static JDouble operator --(JDouble a) => new(a._value - 1);
public static JDouble operator +(JDouble a, JDouble b) => new(a._value + b._value);
public static JDouble operator +(Double a, JDouble b) => new(a + b._value);
public static JDouble operator +(JDouble a, Double b) => new(a._value + b);
public static JDouble operator -(JDouble a, JDouble b) => new(a._value - b._value);
public static JDouble operator -(Double a, JDouble b) => new(a - b._value);
public static JDouble operator -(JDouble a, Double b) => new(a._value - b);
public static JDouble operator *(JDouble a, JDouble b) => new(a._value * b._value);
public static JDouble operator *(Double a, JDouble b) => new(a * b._value);
public static JDouble operator *(JDouble a, Double b) => new(a._value * b);
public static JDouble operator /(JDouble a, JDouble b) => new(a._value / b._value);
public static JDouble operator /(Double a, JDouble b) => new(a / b._value);
public static JDouble operator /(JDouble a, Double b) => new(a._value / b);
public static Boolean operator ==(JDouble a, JDouble b) => a._value.Equals(b._value);
public static Boolean operator ==(Double a, JDouble b) => a.Equals(b._value);
public static Boolean operator ==(JDouble a, Double b) => a._value.Equals(b);
public static Boolean operator !=(JDouble a, JDouble b) => !a._value.Equals(b._value);
public static Boolean operator !=(Double a, JDouble b) => !a.Equals(b._value);
public static Boolean operator !=(JDouble a, Double b) => !a._value.Equals(b);
public static Boolean operator >(JDouble a, JDouble b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(Double a, JDouble b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JDouble a, Double b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JDouble a, JDouble b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(Double a, JDouble b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JDouble a, Double b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JDouble a, JDouble b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(Double a, JDouble b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JDouble a, Double b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JDouble a, JDouble b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(Double a, JDouble b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JDouble a, Double b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(Double other) => this._value.CompareTo(other);
public Int32 CompareTo(JDouble other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj) => obj is JDouble jvalue ? this.CompareTo(jvalue) : obj is Double value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(Double other) => this._value.Equals(other);
public Boolean Equals(JDouble other) => this._value.Equals(other._value);
public String ToString(String format, IFormatProvider formatProvider) => this._value.ToString(format, formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj) => obj is JDouble jvalue ? this.Equals(jvalue) : obj is Double value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,70 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives
{
public readonly struct JFloat : IComparable<Single>, IEquatable<Single>, IFormattable
{
internal static readonly Type Type = typeof(JFloat);
public static readonly CString Signature = (CString)"F";
private readonly Single _value;
private JFloat(Single value) => this._value = value;
#region Operators
public static implicit operator JFloat(Single value) => new(value);
public static implicit operator Single(JFloat jValue) => jValue._value;
public static JFloat operator +(JFloat a) => a;
public static JFloat operator ++(JFloat a) => new(a._value + 1);
public static JFloat operator -(JFloat a) => new(-a._value);
public static JFloat operator --(JFloat a) => new(a._value - 1);
public static JFloat operator +(JFloat a, JFloat b) => new(a._value + b._value);
public static JFloat operator +(Single a, JFloat b) => new(a + b._value);
public static JFloat operator +(JFloat a, Single b) => new(a._value + b);
public static JFloat operator -(JFloat a, JFloat b) => new(a._value - b._value);
public static JFloat operator -(Single a, JFloat b) => new(a - b._value);
public static JFloat operator -(JFloat a, Single b) => new(a._value - b);
public static JFloat operator *(JFloat a, JFloat b) => new(a._value * b._value);
public static JFloat operator *(Single a, JFloat b) => new(a * b._value);
public static JFloat operator *(JFloat a, Single b) => new(a._value * b);
public static JFloat operator /(JFloat a, JFloat b) => new(a._value / b._value);
public static JFloat operator /(Single a, JFloat b) => new(a / b._value);
public static JFloat operator /(JFloat a, Single b) => new(a._value / b);
public static Boolean operator ==(JFloat a, JFloat b) => a._value.Equals(b._value);
public static Boolean operator ==(Single a, JFloat b) => a.Equals(b._value);
public static Boolean operator ==(JFloat a, Single b) => a._value.Equals(b);
public static Boolean operator !=(JFloat a, JFloat b) => !a._value.Equals(b._value);
public static Boolean operator !=(Single a, JFloat b) => !a.Equals(b._value);
public static Boolean operator !=(JFloat a, Single b) => !a._value.Equals(b);
public static Boolean operator >(JFloat a, JFloat b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(Single a, JFloat b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JFloat a, Single b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JFloat a, JFloat b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(Single a, JFloat b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JFloat a, Single b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JFloat a, JFloat b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(Single a, JFloat b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JFloat a, Single b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JFloat a, JFloat b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(Single a, JFloat b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JFloat a, Single b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(Single other) => this._value.CompareTo(other);
public Int32 CompareTo(JFloat other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj) => obj is JFloat jvalue ? this.CompareTo(jvalue) : obj is Single value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(Single other) => this._value.Equals(other);
public Boolean Equals(JFloat other) => this._value.Equals(other._value);
public String ToString(String format, IFormatProvider formatProvider) => this._value.ToString(format, formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj) => obj is JFloat jvalue ? this.Equals(jvalue) : obj is Single value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,73 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives
{
public readonly struct JInt : IComparable<Int32>, IEquatable<Int32>, IFormattable
{
internal static readonly Type Type = typeof(JInt);
public static readonly CString Signature = (CString)"I";
private readonly Int32 _value;
private JInt(Int32 value) => this._value = value;
#region Operators
public static implicit operator JInt(Int32 value) => new(value);
public static implicit operator Int32(JInt jValue) => jValue._value;
public static JInt operator +(JInt a) => a;
public static JInt operator ++(JInt a) => new(a._value + 1);
public static JInt operator -(JInt a) => new(-a._value);
public static JInt operator --(JInt a) => new(a._value - 1);
public static JInt operator +(JInt a, JInt b) => new(a._value + b._value);
public static JInt operator +(Int32 a, JInt b) => new(a + b._value);
public static JInt operator +(JInt a, Int32 b) => new(a._value + b);
public static JInt operator -(JInt a, JInt b) => new(a._value - b._value);
public static JInt operator -(Int32 a, JInt b) => new(a - b._value);
public static JInt operator -(JInt a, Int32 b) => new(a._value - b);
public static JInt operator *(JInt a, JInt b) => new(a._value * b._value);
public static JInt operator *(Int32 a, JInt b) => new(a * b._value);
public static JInt operator *(JInt a, Int32 b) => new(a._value * b);
public static JInt operator /(JInt a, JInt b) => new(a._value / b._value);
public static JInt operator /(Int32 a, JInt b) => new(a / b._value);
public static JInt operator /(JInt a, Int32 b) => new(a._value / b);
public static JInt operator %(JInt a, JInt b) => new(a._value % b._value);
public static JInt operator %(Int32 a, JInt b) => new(a % b._value);
public static JInt operator %(JInt a, Int32 b) => new(a._value % b);
public static Boolean operator ==(JInt a, JInt b) => a._value.Equals(b._value);
public static Boolean operator ==(Int32 a, JInt b) => a.Equals(b._value);
public static Boolean operator ==(JInt a, Int32 b) => a._value.Equals(b);
public static Boolean operator !=(JInt a, JInt b) => !a._value.Equals(b._value);
public static Boolean operator !=(Int32 a, JInt b) => !a.Equals(b._value);
public static Boolean operator !=(JInt a, Int32 b) => !a._value.Equals(b);
public static Boolean operator >(JInt a, JInt b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(Int32 a, JInt b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JInt a, Int32 b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JInt a, JInt b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(Int32 a, JInt b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JInt a, Int32 b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JInt a, JInt b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(Int32 a, JInt b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JInt a, Int32 b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JInt a, JInt b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(Int32 a, JInt b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JInt a, Int32 b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(Int32 other) => this._value.CompareTo(other);
public Int32 CompareTo(JInt other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj) => obj is JInt jValue ? this.CompareTo(jValue) : obj is Int32 value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(Int32 other) => this._value.Equals(other);
public Boolean Equals(JInt other) => this._value.Equals(other._value);
public String ToString(String format, IFormatProvider formatProvider) => this._value.ToString(format, formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj) => obj is JInt jvalue ? this.Equals(jvalue) : obj is Int32 value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,73 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives
{
public readonly struct JLong : IComparable<Int64>, IEquatable<Int64>, IFormattable
{
internal static readonly Type Type = typeof(JLong);
public static readonly CString Signature = (CString)"J";
private readonly Int64 _value;
private JLong(Int64 value) => this._value = value;
#region Operators
public static implicit operator JLong(Int64 value) => new(value);
public static implicit operator Int64(JLong jValue) => jValue._value;
public static JLong operator +(JLong a) => a;
public static JLong operator ++(JLong a) => new(a._value + 1);
public static JLong operator -(JLong a) => new(-a._value);
public static JLong operator --(JLong a) => new(a._value - 1);
public static JLong operator +(JLong a, JLong b) => new(a._value + b._value);
public static JLong operator +(Int64 a, JLong b) => new(a + b._value);
public static JLong operator +(JLong a, Int64 b) => new(a._value + b);
public static JLong operator -(JLong a, JLong b) => new(a._value - b._value);
public static JLong operator -(Int64 a, JLong b) => new(a - b._value);
public static JLong operator -(JLong a, Int64 b) => new(a._value - b);
public static JLong operator *(JLong a, JLong b) => new(a._value * b._value);
public static JLong operator *(Int64 a, JLong b) => new(a * b._value);
public static JLong operator *(JLong a, Int64 b) => new(a._value * b);
public static JLong operator /(JLong a, JLong b) => new(a._value / b._value);
public static JLong operator /(Int64 a, JLong b) => new(a / b._value);
public static JLong operator /(JLong a, Int64 b) => new(a._value / b);
public static JLong operator %(JLong a, JLong b) => new(a._value % b._value);
public static JLong operator %(Int64 a, JLong b) => new(a % b._value);
public static JLong operator %(JLong a, Int64 b) => new(a._value % b);
public static Boolean operator ==(JLong a, JLong b) => a._value.Equals(b._value);
public static Boolean operator ==(Int64 a, JLong b) => a.Equals(b._value);
public static Boolean operator ==(JLong a, Int64 b) => a._value.Equals(b);
public static Boolean operator !=(JLong a, JLong b) => !a._value.Equals(b._value);
public static Boolean operator !=(Int64 a, JLong b) => !a.Equals(b._value);
public static Boolean operator !=(JLong a, Int64 b) => !a._value.Equals(b);
public static Boolean operator >(JLong a, JLong b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(Int64 a, JLong b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JLong a, Int64 b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JLong a, JLong b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(Int64 a, JLong b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JLong a, Int64 b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JLong a, JLong b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(Int64 a, JLong b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JLong a, Int64 b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JLong a, JLong b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(Int64 a, JLong b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JLong a, Int64 b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(Int64 other) => this._value.CompareTo(other);
public Int32 CompareTo(JLong other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj) => obj is JLong jvalue ? this.CompareTo(jvalue) : obj is Int64 value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(Int64 other) => this._value.Equals(other);
public Boolean Equals(JLong other) => this._value.Equals(other._value);
public String ToString(String format, IFormatProvider formatProvider) => this._value.ToString(format, formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj) => obj is JLong jvalue ? this.Equals(jvalue) : obj is Int64 value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,74 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Primitives
{
public readonly struct JShort : IComparable<Int16>, IEquatable<Int16>, IFormattable
{
internal static readonly Type Type = typeof(JShort);
public static readonly CString Signature = (CString)"S";
private readonly Int16 _value;
private JShort(Int16 value) => this._value = value;
private JShort(Int32 value) => this._value = Convert.ToInt16(value);
#region Operators
public static implicit operator JShort(Int16 value) => new(value);
public static implicit operator Int16(JShort jValue) => jValue._value;
public static JShort operator +(JShort a) => a;
public static JShort operator ++(JShort a) => new(a._value + 1);
public static JShort operator -(JShort a) => new(-a._value);
public static JShort operator --(JShort a) => new(a._value - 1);
public static JShort operator +(JShort a, JShort b) => new(a._value + b._value);
public static JShort operator +(Int16 a, JShort b) => new(a + b._value);
public static JShort operator +(JShort a, Int16 b) => new(a._value + b);
public static JShort operator -(JShort a, JShort b) => new(a._value - b._value);
public static JShort operator -(Int16 a, JShort b) => new(a - b._value);
public static JShort operator -(JShort a, Int16 b) => new(a._value - b);
public static JShort operator *(JShort a, JShort b) => new(a._value * b._value);
public static JShort operator *(Int16 a, JShort b) => new(a * b._value);
public static JShort operator *(JShort a, Int16 b) => new(a._value * b);
public static JShort operator /(JShort a, JShort b) => new(a._value / b._value);
public static JShort operator /(Int16 a, JShort b) => new(a / b._value);
public static JShort operator /(JShort a, Int16 b) => new(a._value / b);
public static JShort operator %(JShort a, JShort b) => new(a._value % b._value);
public static JShort operator %(Int16 a, JShort b) => new(a % b._value);
public static JShort operator %(JShort a, Int16 b) => new(a._value % b);
public static Boolean operator ==(JShort a, JShort b) => a._value.Equals(b._value);
public static Boolean operator ==(Int16 a, JShort b) => a.Equals(b._value);
public static Boolean operator ==(JShort a, Int16 b) => a._value.Equals(b);
public static Boolean operator !=(JShort a, JShort b) => !a._value.Equals(b._value);
public static Boolean operator !=(Int16 a, JShort b) => !a.Equals(b._value);
public static Boolean operator !=(JShort a, Int16 b) => !a._value.Equals(b);
public static Boolean operator >(JShort a, JShort b) => a._value.CompareTo(b._value) > 0;
public static Boolean operator >(Int16 a, JShort b) => a.CompareTo(b._value) > 0;
public static Boolean operator >(JShort a, Int16 b) => a._value.CompareTo(b) > 0;
public static Boolean operator <(JShort a, JShort b) => a._value.CompareTo(b._value) < 0;
public static Boolean operator <(Int16 a, JShort b) => a.CompareTo(b._value) < 0;
public static Boolean operator <(JShort a, Int16 b) => a._value.CompareTo(b) < 0;
public static Boolean operator >=(JShort a, JShort b) => a._value.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(Int16 a, JShort b) => a.CompareTo(b._value) > 0 || a.Equals(b._value);
public static Boolean operator >=(JShort a, Int16 b) => a._value.CompareTo(b) > 0 || a._value.Equals(b);
public static Boolean operator <=(JShort a, JShort b) => a._value.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(Int16 a, JShort b) => a.CompareTo(b._value) < 0 || a.Equals(b._value);
public static Boolean operator <=(JShort a, Int16 b) => a._value.CompareTo(b) < 0 || a._value.Equals(b);
#endregion
#region Public Methods
public Int32 CompareTo(Int16 other) => this._value.CompareTo(other);
public Int32 CompareTo(JShort other) => this._value.CompareTo(other._value);
public Int32 CompareTo(Object obj) => obj is JShort jvalue ? this.CompareTo(jvalue) : obj is Int16 value ? this.CompareTo(value) : this._value.CompareTo(obj);
public Boolean Equals(Int16 other) => this._value.Equals(other);
public Boolean Equals(JShort other) => this._value.Equals(other._value);
public String ToString(String format, IFormatProvider formatProvider) => this._value.ToString(format, formatProvider);
#endregion
#region Overrided Methods
public override String ToString() => this._value.ToString();
public override Boolean Equals(Object obj) => obj is JShort jvalue ? this.Equals(jvalue) : obj is Int16 value ? this.Equals(value) : this._value.Equals(obj);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,26 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.References;
public readonly struct JArrayLocalRef : IEquatable<JArrayLocalRef>
{
#pragma warning disable 0649
private readonly JObjectLocalRef _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JArrayLocalRef other) => this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj) => obj is JArrayLocalRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static explicit operator JObjectLocalRef(JArrayLocalRef a) => a._value;
public static Boolean operator ==(JArrayLocalRef a, JArrayLocalRef b) => a.Equals(b);
public static Boolean operator !=(JArrayLocalRef a, JArrayLocalRef b) => !a.Equals(b);
#endregion
}
@@ -0,0 +1,29 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.References;
public readonly struct JClassLocalRef : IEquatable<JClassLocalRef>
{
#pragma warning disable 0649
private readonly JObjectLocalRef _value;
#pragma warning restore 0649
private JClassLocalRef(JObjectLocalRef value) => this._value = value;
#region Public Methods
public Boolean Equals(JClassLocalRef other) => this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj) => obj is JClassLocalRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static explicit operator JObjectLocalRef(JClassLocalRef a) => a._value;
public static explicit operator JClassLocalRef(JObjectLocalRef a) => new(a);
public static Boolean operator ==(JClassLocalRef a, JClassLocalRef b) => a.Equals(b);
public static Boolean operator !=(JClassLocalRef a, JClassLocalRef b) => !a.Equals(b);
#endregion
}
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.References;
public readonly struct JGlobalRef : IEquatable<JGlobalRef>
{
#pragma warning disable 0649
private readonly JObjectLocalRef _value;
public JObjectLocalRef Value => _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JGlobalRef other) => this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj) => obj is JGlobalRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static explicit operator JObjectLocalRef(JGlobalRef a) => a._value;
public static Boolean operator ==(JGlobalRef a, JGlobalRef b) => a.Equals(b);
public static Boolean operator !=(JGlobalRef a, JGlobalRef b) => !a.Equals(b);
#endregion
}
@@ -0,0 +1,28 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.References
{
public readonly struct JObjectLocalRef : IEquatable<JObjectLocalRef>
{
#pragma warning disable 0649
private readonly IntPtr _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JObjectLocalRef other)
=> this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj)
=> obj is JObjectLocalRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static Boolean operator ==(JObjectLocalRef a, JObjectLocalRef b) => a.Equals(b);
public static Boolean operator !=(JObjectLocalRef a, JObjectLocalRef b) => !a.Equals(b);
#endregion
}
}
@@ -0,0 +1,27 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.References;
public readonly struct JStringLocalRef : IEquatable<JStringLocalRef>
{
#pragma warning disable 0649
private readonly JObjectLocalRef _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JStringLocalRef other) => this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj)
=> obj is JStringLocalRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static explicit operator JObjectLocalRef(JStringLocalRef a) => a._value;
public static Boolean operator ==(JStringLocalRef a, JStringLocalRef b) => a.Equals(b);
public static Boolean operator !=(JStringLocalRef a, JStringLocalRef b) => !a.Equals(b);
#endregion
}
@@ -0,0 +1,27 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.References;
public readonly struct JThrowableLocalRef : IEquatable<JThrowableLocalRef>
{
#pragma warning disable 0649
private readonly JObjectLocalRef _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JThrowableLocalRef other) => this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj)
=> obj is JThrowableLocalRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static explicit operator JObjectLocalRef(JThrowableLocalRef a) => a._value;
public static Boolean operator ==(JThrowableLocalRef a, JThrowableLocalRef b) => a.Equals(b);
public static Boolean operator !=(JThrowableLocalRef a, JThrowableLocalRef b) => !a.Equals(b);
#endregion
}
@@ -0,0 +1,26 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.References;
public readonly struct JWeakRef : IEquatable<JWeakRef>
{
#pragma warning disable 0649
private readonly JObjectLocalRef _value;
#pragma warning restore 0649
#region Public Methods
public Boolean Equals(JWeakRef other) => this._value.Equals(other._value);
#endregion
#region Override Methods
public override Boolean Equals([NotNullWhen(true)] Object obj) => obj is JWeakRef other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
#region Operators
public static explicit operator JObjectLocalRef(JWeakRef a) => a._value;
public static Boolean operator ==(JWeakRef a, JWeakRef b) => a.Equals(b);
public static Boolean operator !=(JWeakRef a, JWeakRef b) => !a.Equals(b);
#endregion
}
@@ -0,0 +1,30 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Values
{
internal readonly struct JEnvValue : IEquatable<JEnvValue>
{
#pragma warning disable 0649
private readonly IntPtr _value;
#pragma warning restore 0649
#region Operators
public static Boolean operator ==(JEnvValue a, JEnvValue b) => a._value.Equals(b._value);
public static Boolean operator !=(JEnvValue a, JEnvValue b) => !a._value.Equals(b._value);
#endregion
#region Public Properties
internal readonly ref JNativeInterface Functions => ref this._value.GetUnsafeReference<JNativeInterface>();
#endregion
#region Public Methods
public Boolean Equals(JEnvValue other) => this._value.Equals(other._value);
#endregion
#region Overrided Methods
public override Boolean Equals(Object obj) => obj is JEnvValue other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
}
@@ -0,0 +1,20 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace LibKenjinx.Jni.Values
{
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "This struct is created only by binary operations.")]
public readonly struct JInvokeInterface
{
#pragma warning disable 0169
private readonly IntPtr _reserved0;
private readonly IntPtr _reserved1;
private readonly IntPtr _reserved2;
#pragma warning restore 0169
internal IntPtr DestroyJavaVMPointer { get; init; }
internal IntPtr AttachCurrentThreadPointer { get; init; }
internal IntPtr DetachCurrentThreadPointer { get; init; }
internal IntPtr GetEnvPointer { get; init; }
internal IntPtr AttachCurrentThreadAsDaemonPointer { get; init; }
}
}
@@ -0,0 +1,247 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace LibKenjinx.Jni.Values;
[SuppressMessage("CodeQuality", "IDE0051:Remove unused private members",
Justification = "This struct is created only by binary operations.")]
[StructLayout(LayoutKind.Sequential)]
public readonly struct JNativeInterface
{
#pragma warning disable 0169
private readonly IntPtr _reserved0;
private readonly IntPtr _reserved1;
private readonly IntPtr _reserved2;
private readonly IntPtr _reserved3;
#pragma warning restore 0169
internal readonly IntPtr GetVersionPointer { get; init; }
internal readonly IntPtr DefineClassPointer { get; init; }
internal readonly IntPtr FindClassPointer { get; init; }
internal readonly IntPtr FromReflectedMethodPointer { get; init; }
internal readonly IntPtr FromReflectedFieldPointer { get; init; }
internal readonly IntPtr ToReflectedMethodPointer { get; init; }
internal readonly IntPtr GetSuperclassPointer { get; init; }
internal readonly IntPtr IsAssignableFromPointer { get; init; }
internal readonly IntPtr ToReflectedFieldPointer { get; init; }
internal readonly IntPtr ThrowPointer { get; init; }
internal readonly IntPtr ThrowNewPointer { get; init; }
internal readonly IntPtr ExceptionOccurredPointer { get; init; }
internal readonly IntPtr ExceptionDescribePointer { get; init; }
internal readonly IntPtr ExceptionClearPointer { get; init; }
internal readonly IntPtr FatalErrorPointer { get; init; }
internal readonly IntPtr PushLocalFramePointer { get; init; }
internal readonly IntPtr PopLocalFramePointer { get; init; }
internal readonly IntPtr NewGlobalRefPointer { get; init; }
internal readonly IntPtr DeleteGlobalRefPointer { get; init; }
internal readonly IntPtr DeleteLocalRefPointer { get; init; }
internal readonly IntPtr IsSameObjectPointer { get; init; }
internal readonly IntPtr NewLocalRefPointer { get; init; }
internal readonly IntPtr EnsureLocalCapacityPointer { get; init; }
internal readonly IntPtr AllocObjectPointer { get; init; }
internal readonly IntPtr NewObjectPointer { get; init; }
internal readonly IntPtr NewObjectVPointer { get; init; }
internal readonly IntPtr NewObjectAPointer { get; init; }
internal readonly IntPtr GetObjectClassPointer { get; init; }
internal readonly IntPtr IsInstanceOfPointer { get; init; }
internal readonly IntPtr GetMethodIdPointer { get; init; }
private readonly IntPtr CallObjectMethodPointer { get; init; }
private readonly IntPtr CallObjectMethodVPointer { get; init; }
internal readonly IntPtr CallObjectMethodAPointer { get; init; }
private readonly IntPtr CallBooleanMethodPointer { get; init; }
private readonly IntPtr CallBooleanMethodVPointer { get; init; }
internal readonly IntPtr CallBooleanMethodAPointer { get; init; }
private readonly IntPtr CallByteMethodPointer { get; init; }
private readonly IntPtr CallByteMethodVPointer { get; init; }
internal readonly IntPtr CallByteMethodAPointer { get; init; }
private readonly IntPtr CallCharMethodPointer { get; init; }
private readonly IntPtr CallCharMethodVPointer { get; init; }
internal readonly IntPtr CallCharMethodAPointer { get; init; }
private readonly IntPtr CallShortMethodPointer { get; init; }
private readonly IntPtr CallShortMethodVPointer { get; init; }
internal readonly IntPtr CallShortMethodAPointer { get; init; }
private readonly IntPtr CallIntMethodPointer { get; init; }
private readonly IntPtr CallIntMethodVPointer { get; init; }
internal readonly IntPtr CallIntMethodAPointer { get; init; }
private readonly IntPtr CallLongMethodPointer { get; init; }
private readonly IntPtr CallLongMethodVPointer { get; init; }
internal readonly IntPtr CallLongMethodAPointer { get; init; }
private readonly IntPtr CallFloatMethodPointer { get; init; }
private readonly IntPtr CallFloatMethodVPointer { get; init; }
internal readonly IntPtr CallFloatMethodAPointer { get; init; }
private readonly IntPtr CallDoubleMethodPointer { get; init; }
private readonly IntPtr CallDoubleMethodVPointer { get; init; }
internal readonly IntPtr CallDoubleMethodAPointer { get; init; }
private readonly IntPtr CallVoidMethodPointer { get; init; }
private readonly IntPtr CallVoidMethodVPointer { get; init; }
internal readonly IntPtr CallVoidMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualObjectMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualObjectMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualObjectMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualBooleanMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualBooleanMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualBooleanMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualByteMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualByteMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualByteMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualCharMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualCharMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualCharMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualShortMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualShortMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualShortMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualIntMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualIntMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualIntMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualLongMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualLongMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualLongMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualFloatMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualFloatMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualFloatMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualDoubleMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualDoubleMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualDoubleMethodAPointer { get; init; }
private readonly IntPtr CallNonVirtualVoidMethodPointer { get; init; }
private readonly IntPtr CallNonVirtualVoidMethodVPointer { get; init; }
internal readonly IntPtr CallNonVirtualVoidMethodAPointer { get; init; }
internal readonly IntPtr GetFieldIdPointer { get; init; }
internal readonly IntPtr GetObjectFieldPointer { get; init; }
internal readonly IntPtr GetBooleanFieldPointer { get; init; }
internal readonly IntPtr GetByteFieldPointer { get; init; }
internal readonly IntPtr GetCharFieldPointer { get; init; }
internal readonly IntPtr GetShortFieldPointer { get; init; }
internal readonly IntPtr GetIntFieldPointer { get; init; }
internal readonly IntPtr GetLongFieldPointer { get; init; }
internal readonly IntPtr GetFloatFieldPointer { get; init; }
internal readonly IntPtr GetDoubleFieldPointer { get; init; }
internal readonly IntPtr SetObjectFieldPointer { get; init; }
internal readonly IntPtr SetBooleanFieldPointer { get; init; }
internal readonly IntPtr SetByteFieldPointer { get; init; }
internal readonly IntPtr SetCharFieldPointer { get; init; }
internal readonly IntPtr SetShortFieldPointer { get; init; }
internal readonly IntPtr SetIntFieldPointer { get; init; }
internal readonly IntPtr SetLongFieldPointer { get; init; }
internal readonly IntPtr SetFloatFieldPointer { get; init; }
internal readonly IntPtr SetDoubleFieldPointer { get; init; }
internal readonly IntPtr GetStaticMethodIdPointer { get; init; }
private readonly IntPtr CallStaticObjectMethodPointer { get; init; }
private readonly IntPtr CallStaticObjectMethodVPointer { get; init; }
internal readonly IntPtr CallStaticObjectMethodAPointer { get; init; }
private readonly IntPtr CallStaticBooleanMethodPointer { get; init; }
private readonly IntPtr CallStaticBooleanMethodVPointer { get; init; }
internal readonly IntPtr CallStaticBooleanMethodAPointer { get; init; }
private readonly IntPtr CallStaticByteMethodPointer { get; init; }
private readonly IntPtr CallStaticByteMethodVPointer { get; init; }
internal readonly IntPtr CallStaticByteMethodAPointer { get; init; }
private readonly IntPtr CallStaticCharMethodPointer { get; init; }
private readonly IntPtr CallStaticCharMethodVPointer { get; init; }
internal readonly IntPtr CallStaticCharMethodAPointer { get; init; }
private readonly IntPtr CallStaticShortMethodPointer { get; init; }
private readonly IntPtr CallStaticShortMethodVPointer { get; init; }
internal readonly IntPtr CallStaticShortMethodAPointer { get; init; }
private readonly IntPtr CallStaticIntMethodPointer { get; init; }
private readonly IntPtr CallStaticIntMethodVPointer { get; init; }
internal readonly IntPtr CallStaticIntMethodAPointer { get; init; }
private readonly IntPtr CallStaticLongMethodPointer { get; init; }
private readonly IntPtr CallStaticLongMethodVPointer { get; init; }
internal readonly IntPtr CallStaticLongMethodAPointer { get; init; }
private readonly IntPtr CallStaticFloatMethodPointer { get; init; }
private readonly IntPtr CallStaticFloatMethodVPointer { get; init; }
internal readonly IntPtr CallStaticFloatMethodAPointer { get; init; }
private readonly IntPtr CallStaticDoubleMethodPointer { get; init; }
private readonly IntPtr CallStaticDoubleMethodVPointer { get; init; }
internal readonly IntPtr CallStaticDoubleMethodAPointer { get; init; }
private readonly IntPtr CallStaticVoidMethodPointer { get; init; }
private readonly IntPtr CallStaticVoidMethodVPointer { get; init; }
internal readonly IntPtr CallStaticVoidMethodAPointer { get; init; }
internal readonly IntPtr GetStaticFieldIdPointer { get; init; }
internal readonly IntPtr GetStaticObjectFieldPointer { get; init; }
internal readonly IntPtr GetStaticBooleanFieldPointer { get; init; }
internal readonly IntPtr GetStaticByteFieldPointer { get; init; }
internal readonly IntPtr GetStaticCharFieldPointer { get; init; }
internal readonly IntPtr GetStaticShortFieldPointer { get; init; }
internal readonly IntPtr GetStaticIntFieldPointer { get; init; }
internal readonly IntPtr GetStaticLongFieldPointer { get; init; }
internal readonly IntPtr GetStaticFloatFieldPointer { get; init; }
internal readonly IntPtr GetStaticDoubleFieldPointer { get; init; }
internal readonly IntPtr SetStaticObjectFieldPointer { get; init; }
internal readonly IntPtr SetStaticBooleanFieldPointer { get; init; }
internal readonly IntPtr SetStaticByteFieldPointer { get; init; }
internal readonly IntPtr SetStaticCharFieldPointer { get; init; }
internal readonly IntPtr SetStaticShortFieldPointer { get; init; }
internal readonly IntPtr SetStaticIntFieldPointer { get; init; }
internal readonly IntPtr SetStaticLongFieldPointer { get; init; }
internal readonly IntPtr SetStaticFloatFieldPointer { get; init; }
internal readonly IntPtr SetStaticDoubleFieldPointer { get; init; }
internal readonly IntPtr NewStringPointer { get; init; }
internal readonly IntPtr GetStringLengthPointer { get; init; }
internal readonly IntPtr GetStringCharsPointer { get; init; }
internal readonly IntPtr ReleaseStringCharsPointer { get; init; }
internal readonly IntPtr NewStringUtfPointer { get; init; }
internal readonly IntPtr GetStringUtfLengthPointer { get; init; }
internal readonly IntPtr GetStringUtfCharsPointer { get; init; }
internal readonly IntPtr ReleaseStringUtfCharsPointer { get; init; }
internal readonly IntPtr GetArrayLengthPointer { get; init; }
internal readonly IntPtr NewObjectArrayPointer { get; init; }
internal readonly IntPtr GetObjectArrayElementPointer { get; init; }
internal readonly IntPtr SetObjectArrayElementPointer { get; init; }
internal readonly IntPtr NewBooleanArrayPointer { get; init; }
internal readonly IntPtr NewByteArrayPointer { get; init; }
internal readonly IntPtr NewCharArrayPointer { get; init; }
internal readonly IntPtr NewShortArrayPointer { get; init; }
internal readonly IntPtr NewIntArrayPointer { get; init; }
internal readonly IntPtr NewLongArrayPointer { get; init; }
internal readonly IntPtr NewFloatArrayPointer { get; init; }
internal readonly IntPtr NewDoubleArrayPointer { get; init; }
internal readonly IntPtr GetBooleanArrayElementsPointer { get; init; }
internal readonly IntPtr GetByteArrayElementsPointer { get; init; }
internal readonly IntPtr GetCharArrayElementsPointer { get; init; }
internal readonly IntPtr GetShortArrayElementsPointer { get; init; }
internal readonly IntPtr GetIntArrayElementsPointer { get; init; }
internal readonly IntPtr GetLongArrayElementsPointer { get; init; }
internal readonly IntPtr GetFloatArrayElementsPointer { get; init; }
internal readonly IntPtr GetDoubleArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseBooleanArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseByteArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseCharArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseShortArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseIntArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseLongArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseFloatArrayElementsPointer { get; init; }
internal readonly IntPtr ReleaseDoubleArrayElementsPointer { get; init; }
internal readonly IntPtr GetBooleanArrayRegionPointer { get; init; }
internal readonly IntPtr GetByteArrayRegionPointer { get; init; }
internal readonly IntPtr GetCharArrayRegionPointer { get; init; }
internal readonly IntPtr GetShortArrayRegionPointer { get; init; }
internal readonly IntPtr GetIntArrayRegionPointer { get; init; }
internal readonly IntPtr GetLongArrayRegionPointer { get; init; }
internal readonly IntPtr GetFloatArrayRegionPointer { get; init; }
internal readonly IntPtr GetDoubleArrayRegionPointer { get; init; }
internal readonly IntPtr SetBooleanArrayRegionPointer { get; init; }
internal readonly IntPtr SetByteArrayRegionPointer { get; init; }
internal readonly IntPtr SetCharArrayRegionPointer { get; init; }
internal readonly IntPtr SetShortArrayRegionPointer { get; init; }
internal readonly IntPtr SetIntArrayRegionPointer { get; init; }
internal readonly IntPtr SetLongArrayRegionPointer { get; init; }
internal readonly IntPtr SetFloatArrayRegionPointer { get; init; }
internal readonly IntPtr SetDoubleArrayRegionPointer { get; init; }
internal readonly IntPtr RegisterNativesPointer { get; init; }
internal readonly IntPtr UnregisterNativesPointer { get; init; }
internal readonly IntPtr MonitorEnterPointer { get; init; }
internal readonly IntPtr MonitorExitPointer { get; init; }
internal readonly IntPtr GetJavaVMPointer { get; init; }
internal readonly IntPtr GetStringRegionPointer { get; init; }
internal readonly IntPtr GetStringUtfRegionPointer { get; init; }
internal readonly IntPtr GetPrimitiveArrayCriticalPointer { get; init; }
internal readonly IntPtr ReleasePrimitiveArrayCriticalPointer { get; init; }
internal readonly IntPtr GetStringCriticalPointer { get; init; }
internal readonly IntPtr ReleaseStringCriticalPointer { get; init; }
internal readonly IntPtr NewWeakGlobalRefPointer { get; init; }
internal readonly IntPtr DeleteWeakGlobalRefPointer { get; init; }
internal readonly IntPtr ExceptionCheckPointer { get; init; }
internal readonly IntPtr NewDirectByteBufferPointer { get; init; }
internal readonly IntPtr GetDirectBufferAddressPointer { get; init; }
internal readonly IntPtr GetDirectBufferCapacityPointer { get; init; }
internal readonly IntPtr GetObjectRefTypePointer { get; init; }
}
@@ -0,0 +1,11 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Values;
public readonly struct JNativeMethod
{
internal ReadOnlyValPtr<Byte> Name { get; init; }
internal ReadOnlyValPtr<Byte> Signature { get; init; }
internal IntPtr Pointer { get; init; }
}
@@ -0,0 +1,46 @@
using System;
using System.Runtime.CompilerServices;
using LibKenjinx.Jni.References;
using Rxmxnx.PInvoke;
namespace LibKenjinx.Jni.Values;
internal readonly struct JValue
{
private delegate Boolean IsDefaultDelegate(in JValue value);
private static readonly Int32 size = NativeUtilities.SizeOf<JValue>();
private static readonly IsDefaultDelegate isDefault = JValue.GetIsDefault();
#pragma warning disable 0649
#pragma warning disable 0169
private readonly Byte _value1;
private readonly Byte _value2;
private readonly Int16 _value3;
private readonly Int32 _value4;
#pragma warning restore 0169
#pragma warning restore 0649
public Boolean IsDefault => JValue.isDefault(this);
public static JValue Create(in ReadOnlySpan<Byte> source)
{
Byte[] result = new Byte[JValue.size];
for (Int32 i = 0; i < source.Length; i++)
result[i] = source[i];
return result.ToValue<JValue>();
}
private static IsDefaultDelegate GetIsDefault() => Environment.Is64BitProcess ? JValue.DefaultLong : JValue.Default;
private static Boolean Default(in JValue jValue)
=> jValue._value1 + jValue._value2 + jValue._value3 == default && jValue._value4 == default;
private static Boolean DefaultLong(in JValue jValue)
=> Unsafe.AsRef(in jValue).Transform<JValue, Int64>() == default;
public static explicit operator JValue(JObjectLocalRef a) => JValue.Create(NativeUtilities.AsBytes(in a));
}
@@ -0,0 +1,13 @@
using LibKenjinx.Jni.References;
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Values;
public readonly struct JavaVMAttachArgs
{
internal Int32 Version { get; init; }
internal ReadOnlyValPtr<Byte> Name { get; init; }
internal JObjectLocalRef Group { get; init; }
}
@@ -0,0 +1,12 @@
using System;
namespace LibKenjinx.Jni.Values
{
public readonly struct JavaVMInitArgs
{
internal Int32 Version { get; init; }
internal Int32 OptionsLenght { get; init; }
internal IntPtr Options { get; init; }
internal Boolean IgnoreUnrecognized { get; init; }
}
}
@@ -0,0 +1,10 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Values;
public readonly struct JavaVMOption
{
internal ReadOnlyValPtr<Byte> Name { get; init; }
internal IntPtr ExtraInfo { get; init; }
}
@@ -0,0 +1,29 @@
using Rxmxnx.PInvoke;
using System;
namespace LibKenjinx.Jni.Values;
internal readonly struct JavaVMValue : IEquatable<JavaVMValue>
{
#pragma warning disable 0649
private readonly IntPtr _value;
#pragma warning restore 0649
#region Operators
public static Boolean operator ==(JavaVMValue a, JavaVMValue b) => a._value.Equals(b._value);
public static Boolean operator !=(JavaVMValue a, JavaVMValue b) => !a._value.Equals(b._value);
#endregion
#region Public Properties
internal readonly ref JInvokeInterface Functions => ref this._value.GetUnsafeReference<JInvokeInterface>();
#endregion
#region Public Methods
public Boolean Equals(JavaVMValue other) => this._value.Equals(other._value);
#endregion
#region Overrided Methods
public override Boolean Equals(Object obj) => obj is JavaVMValue other && this.Equals(other);
public override Int32 GetHashCode() => this._value.GetHashCode();
#endregion
}
@@ -0,0 +1,581 @@
using LibHac.Tools.FsSystem;
using LibKenjinx.Android;
using LibKenjinx.Jni.Pointers;
using Ryujinx.Audio.Backends.OpenAL;
using Ryujinx.Common;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.Common.Logging.Targets;
using Ryujinx.HLE;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.Input;
using Silk.NET.Core.Loader;
using Silk.NET.Vulkan;
using Silk.NET.Vulkan.Extensions.KHR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Threading;
namespace LibKenjinx
{
public static partial class LibKenjinx
{
private static long _surfacePtr;
private static long _window = 0;
public static VulkanLoader? VulkanLoader { get; private set; }
[DllImport("libkenjinxjni")]
internal extern static void setRenderingThread();
[DllImport("libkenjinxjni")]
internal extern static void debug_break(int code);
[DllImport("libkenjinxjni")]
internal extern static void setCurrentTransform(long native_window, int transform);
public delegate IntPtr JniCreateSurface(IntPtr native_surface, IntPtr instance);
[UnmanagedCallersOnly(EntryPoint = "javaInitialize")]
public unsafe static bool JniInitialize(IntPtr jpathId, IntPtr jniEnv)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
PlatformInfo.IsBionic = true;
Logger.AddTarget(
new AsyncLogTargetWrapper(
new AndroidLogTarget("KenjinxLog"),
1000,
AsyncLogTargetOverflowAction.Block
));
var path = Marshal.PtrToStringAnsi(jpathId);
var init = Initialize(path);
Interop.Initialize(new JEnvRef(jniEnv));
Interop.Test();
return init;
}
[UnmanagedCallersOnly(EntryPoint = "deviceReloadFilesystem")]
public static void JnaReloadFileSystem()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SwitchDevice?.ReloadFileSystem();
}
[UnmanagedCallersOnly(EntryPoint = "deviceInitialize")]
public static bool JnaDeviceInitialize(int memoryManagerMode,
bool useNce,
int memoryConfiguration,
int systemLanguage,
int regionCode,
int vSyncMode,
bool enableDockedMode,
bool enablePtc,
bool enableInternetAccess,
bool enableFsIntegrityChecks,
int fsGlobalAccessLogMode,
IntPtr timeZonePtr,
bool ignoreMissingServices)
{
debug_break(4);
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
AudioDriver = new OpenALHardwareDeviceDriver();
var timezone = Marshal.PtrToStringAnsi(timeZonePtr);
return InitializeDevice((MemoryManagerMode)memoryManagerMode,
useNce,
(MemoryConfiguration)memoryConfiguration,
(SystemLanguage)systemLanguage,
(RegionCode)regionCode,
(VSyncMode)vSyncMode,
enableDockedMode,
enablePtc,
enableInternetAccess,
enableFsIntegrityChecks,
fsGlobalAccessLogMode,
timezone,
ignoreMissingServices);
}
[UnmanagedCallersOnly(EntryPoint = "deviceGetGameFifo")]
public static double JnaGetGameFifo()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var stats = SwitchDevice?.EmulationContext?.Statistics.GetFifoPercent() ?? 0;
return stats;
}
[UnmanagedCallersOnly(EntryPoint = "deviceGetGameFrameTime")]
public static double JnaGetGameFrameTime()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var stats = SwitchDevice?.EmulationContext?.Statistics.GetGameFrameTime() ?? 0;
return stats;
}
[UnmanagedCallersOnly(EntryPoint = "deviceGetGameFrameRate")]
public static double JnaGetGameFrameRate()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var stats = SwitchDevice?.EmulationContext?.Statistics.GetGameFrameRate() ?? 0;
return stats;
}
[UnmanagedCallersOnly(EntryPoint = "deviceLaunchMiiEditor")]
public static bool JNALaunchMiiEditApplet()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
if (SwitchDevice?.EmulationContext == null)
{
return false;
}
return LaunchMiiEditApplet();
}
[UnmanagedCallersOnly(EntryPoint = "deviceGetDlcContentList")]
public static IntPtr JniGetDlcContentListNative(IntPtr pathPtr, long titleId)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var list = GetDlcContentList(Marshal.PtrToStringAnsi(pathPtr) ?? "", (ulong)titleId);
return CreateStringArray(list);
}
[UnmanagedCallersOnly(EntryPoint = "deviceGetDlcTitleId")]
public static long JniGetDlcTitleIdNative(IntPtr pathPtr, IntPtr ncaPath)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
return Marshal.StringToHGlobalAnsi(GetDlcTitleId(Marshal.PtrToStringAnsi(pathPtr) ?? "", Marshal.PtrToStringAnsi(ncaPath) ?? ""));
}
[UnmanagedCallersOnly(EntryPoint = "deviceSignalEmulationClose")]
public static void JniSignalEmulationCloseNative()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SignalEmulationClose();
}
[UnmanagedCallersOnly(EntryPoint = "deviceCloseEmulation")]
public static void JniCloseEmulationNative()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
CloseEmulation();
}
[UnmanagedCallersOnly(EntryPoint = "deviceReinitEmulation")]
public static void JniReinitEmulationNative()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
ReinitEmulation();
}
[UnmanagedCallersOnly(EntryPoint = "deviceLoadDescriptor")]
public static bool JnaLoadApplicationNative(int descriptor, int type, int updateDescriptor)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
if (SwitchDevice?.EmulationContext == null)
{
return false;
}
var stream = OpenFile(descriptor);
var update = updateDescriptor == -1 ? null : OpenFile(updateDescriptor);
return LoadApplication(stream, (FileType)type, update);
}
[UnmanagedCallersOnly(EntryPoint = "deviceVerifyFirmware")]
public static IntPtr JniVerifyFirmware(int descriptor, bool isXci)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var stream = OpenFile(descriptor);
IntPtr stringHandle = 0;
string? version = "0.0";
try
{
version = VerifyFirmware(stream, isXci)?.VersionString;
}
catch (Exception _)
{
Logger.Error?.Print(LogClass.Service, $"Unable to verify firmware. Exception: {_}");
}
if (version != null)
{
stringHandle = Marshal.StringToHGlobalAnsi(version);
}
return stringHandle;
}
[UnmanagedCallersOnly(EntryPoint = "deviceInstallFirmware")]
public static void JniInstallFirmware(int descriptor, bool isXci)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var stream = OpenFile(descriptor);
InstallFirmware(stream, isXci);
}
[UnmanagedCallersOnly(EntryPoint = "deviceGetInstalledFirmwareVersion")]
public static IntPtr JniGetInstalledFirmwareVersion()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var version = GetInstalledFirmwareVersion() ?? "0.0";
return Marshal.StringToHGlobalAnsi(version);
}
[UnmanagedCallersOnly(EntryPoint = "graphicsInitialize")]
public static bool JnaGraphicsInitialize(float resScale,
float maxAnisotropy,
bool fastGpuTime,
bool fast2DCopy,
bool enableMacroJit,
bool enableMacroHLE,
bool enableShaderCache,
bool enableTextureRecompression,
int backendThreading)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SearchPathContainer.Platform = UnderlyingPlatform.Android;
return InitializeGraphics(new GraphicsConfiguration()
{
ResScale = resScale,
MaxAnisotropy = maxAnisotropy,
FastGpuTime = fastGpuTime,
Fast2DCopy = fast2DCopy,
EnableMacroJit = enableMacroJit,
EnableMacroHLE = enableMacroHLE,
EnableShaderCache = enableShaderCache,
EnableTextureRecompression = enableTextureRecompression,
BackendThreading = (BackendThreading)backendThreading
});
}
[UnmanagedCallersOnly(EntryPoint = "graphicsInitializeRenderer")]
public unsafe static bool JnaGraphicsInitializeRenderer(char** extensionsArray,
int extensionsLength,
long driverHandle)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
if (Renderer != null)
{
return false;
}
List<string?> extensions = new();
for (int i = 0; i < extensionsLength; i++)
{
extensions.Add(Marshal.PtrToStringAnsi((IntPtr)extensionsArray[i]));
}
if (driverHandle != 0)
{
VulkanLoader = new VulkanLoader((IntPtr)driverHandle);
}
CreateSurface createSurfaceFunc = instance =>
{
_surfacePtr = Interop.GetSurfacePtr();
_window = Interop.GetWindowsHandle();
var api = VulkanLoader?.GetApi() ?? Vk.GetApi();
if (api.TryGetInstanceExtension(new Instance(instance), out KhrAndroidSurface surfaceExtension))
{
var createInfo = new AndroidSurfaceCreateInfoKHR
{
SType = StructureType.AndroidSurfaceCreateInfoKhr,
Window = (nint*)_surfacePtr,
};
var result = surfaceExtension.CreateAndroidSurface(new Instance(instance), createInfo, null, out var surface);
return (nint)surface.Handle;
}
return IntPtr.Zero;
};
return InitializeGraphicsRenderer(GraphicsBackend.Vulkan, createSurfaceFunc, extensions.ToArray());
}
[UnmanagedCallersOnly(EntryPoint = "graphicsRendererSetSize")]
public static void JnaSetRendererSizeNative(int width, int height)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
Renderer?.Window?.SetSize(width, height);
}
[UnmanagedCallersOnly(EntryPoint = "graphicsRendererRunLoop")]
public static void JniRunLoopNative()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SetSwapBuffersCallback(() =>
{
var time = SwitchDevice.EmulationContext.Statistics.GetGameFrameTime();
Interop.FrameEnded(time);
});
RunLoop();
}
[UnmanagedCallersOnly(EntryPoint = "loggingSetEnabled")]
public static void JniSetLoggingEnabledNative(int logLevel, bool enabled)
{
Logger.SetEnable((LogLevel)logLevel, enabled);
}
[UnmanagedCallersOnly(EntryPoint = "loggingEnabledGraphicsLog")]
public static void JniSetLoggingEnabledGraphicsLog(bool enabled)
{
_enableGraphicsLogging = enabled;
}
[UnmanagedCallersOnly(EntryPoint = "deviceGetGameInfo")]
public unsafe static void JniGetGameInfo(int fileDescriptor, IntPtr extension, IntPtr infoPtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
using var stream = OpenFile(fileDescriptor);
var ext = Marshal.PtrToStringAnsi(extension);
var info = GetGameInfo(stream, ext.ToLower()) ?? GetDefaultInfo(stream);
var i = (GameInfoNative*)infoPtr;
var n = new GameInfoNative(info);
i->TitleId = n.TitleId;
i->TitleName = n.TitleName;
i->Version = n.Version;
i->FileSize = n.FileSize;
i->Icon = n.Icon;
i->Version = n.Version;
i->Developer = n.Developer;
}
[UnmanagedCallersOnly(EntryPoint = "graphicsRendererSetVsync")]
public static void JnaSetVsyncStateNative(int vSyncMode)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SetVsyncState((VSyncMode)vSyncMode);
}
[UnmanagedCallersOnly(EntryPoint = "inputInitialize")]
public static void JnaInitializeInput(int width, int height)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
InitializeInput(width, height);
}
[UnmanagedCallersOnly(EntryPoint = "inputSetClientSize")]
public static void JnaSetClientSize(int width, int height)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SetClientSize(width, height);
}
[UnmanagedCallersOnly(EntryPoint = "inputSetTouchPoint")]
public static void JnaSetTouchPoint(int x, int y)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SetTouchPoint(x, y);
}
[UnmanagedCallersOnly(EntryPoint = "inputReleaseTouchPoint")]
public static void JnaReleaseTouchPoint()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
ReleaseTouchPoint();
}
[UnmanagedCallersOnly(EntryPoint = "inputUpdate")]
public static void JniUpdateInput()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
UpdateInput();
}
[UnmanagedCallersOnly(EntryPoint = "inputSetButtonPressed")]
public static void JnaSetButtonPressed(int button, int id)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SetButtonPressed((GamepadButtonInputId)button, id);
}
[UnmanagedCallersOnly(EntryPoint = "inputSetButtonReleased")]
public static void JnaSetButtonReleased(int button, int id)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SetButtonReleased((GamepadButtonInputId)button, id);
}
[UnmanagedCallersOnly(EntryPoint = "inputSetAccelerometerData")]
public static void JniSetAccelerometerData(float x, float y, float z, int id)
{
var accel = new Vector3(x, y, z);
SetAccelerometerData(accel, id);
}
[UnmanagedCallersOnly(EntryPoint = "inputSetGyroData")]
public static void JniSetGyroData(float x, float y, float z, int id)
{
var gryo = new Vector3(x, y, z);
SetGryoData(gryo, id);
}
[UnmanagedCallersOnly(EntryPoint = "inputSetStickAxis")]
public static void JnaSetStickAxis(int stick, float x, float y, int id)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
SetStickAxis((StickInputId)stick, new Vector2(float.IsNaN(x) ? 0 : x, float.IsNaN(y) ? 0 : y), id);
}
[UnmanagedCallersOnly(EntryPoint = "inputConnectGamepad")]
public static int JnaConnectGamepad(int index)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
return ConnectGamepad(index);
}
[UnmanagedCallersOnly(EntryPoint = "userGetOpenedUser")]
public static IntPtr JniGetOpenedUser()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = GetOpenedUser();
var ptr = Marshal.StringToHGlobalAnsi(userId);
return ptr;
}
[UnmanagedCallersOnly(EntryPoint = "userGetUserPicture")]
public static IntPtr JniGetUserPicture(IntPtr userIdPtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = Marshal.PtrToStringAnsi(userIdPtr) ?? "";
return Marshal.StringToHGlobalAnsi(GetUserPicture(userId));
}
[UnmanagedCallersOnly(EntryPoint = "userSetUserPicture")]
public static void JniGetUserPicture(IntPtr userIdPtr, IntPtr picturePtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = Marshal.PtrToStringAnsi(userIdPtr) ?? "";
var picture = Marshal.PtrToStringAnsi(picturePtr) ?? "";
SetUserPicture(userId, picture);
}
[UnmanagedCallersOnly(EntryPoint = "userGetUserName")]
public static IntPtr JniGetUserName(IntPtr userIdPtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = Marshal.PtrToStringAnsi(userIdPtr) ?? "";
return Marshal.StringToHGlobalAnsi(GetUserName(userId));
}
[UnmanagedCallersOnly(EntryPoint = "userSetUserName")]
public static void JniSetUserName(IntPtr userIdPtr, IntPtr userNamePtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = Marshal.PtrToStringAnsi(userIdPtr) ?? "";
var userName = Marshal.PtrToStringAnsi(userNamePtr) ?? "";
SetUserName(userId, userName);
}
[UnmanagedCallersOnly(EntryPoint = "userGetAllUsers")]
public static IntPtr JniGetAllUsers()
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var users = GetAllUsers();
return CreateStringArray(users.ToList());
}
[UnmanagedCallersOnly(EntryPoint = "userAddUser")]
public static void JniAddUser(IntPtr userNamePtr, IntPtr picturePtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userName = Marshal.PtrToStringAnsi(userNamePtr) ?? "";
var picture = Marshal.PtrToStringAnsi(picturePtr) ?? "";
AddUser(userName, picture);
}
[UnmanagedCallersOnly(EntryPoint = "userDeleteUser")]
public static void JniDeleteUser(IntPtr userIdPtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = Marshal.PtrToStringAnsi(userIdPtr) ?? "";
DeleteUser(userId);
}
[UnmanagedCallersOnly(EntryPoint = "uiHandlerSetup")]
public static void JniSetupUiHandler()
{
SetupUiHandler();
}
[UnmanagedCallersOnly(EntryPoint = "uiHandlerSetResponse")]
public static void JniSetUiHandlerResponse(bool isOkPressed, IntPtr input)
{
SetUiHandlerResponse(isOkPressed, Marshal.PtrToStringAnsi(input) ?? "");
}
[UnmanagedCallersOnly(EntryPoint = "userOpenUser")]
public static void JniOpenUser(IntPtr userIdPtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = Marshal.PtrToStringAnsi(userIdPtr) ?? "";
OpenUser(userId);
}
[UnmanagedCallersOnly(EntryPoint = "userCloseUser")]
public static void JniCloseUser(IntPtr userIdPtr)
{
Logger.Trace?.Print(LogClass.Application, "Jni Function Call");
var userId = Marshal.PtrToStringAnsi(userIdPtr) ?? "";
CloseUser(userId);
}
}
internal static partial class Logcat
{
[LibraryImport("liblog", StringMarshalling = StringMarshalling.Utf8)]
private static partial void __android_log_print(LogLevel level, string? tag, string format, string args, IntPtr ptr);
internal static void AndroidLogPrint(LogLevel level, string? tag, string message) =>
__android_log_print(level, tag, "%s", message, IntPtr.Zero);
internal enum LogLevel
{
Unknown = 0x00,
Default = 0x01,
Verbose = 0x02,
Debug = 0x03,
Info = 0x04,
Warn = 0x05,
Error = 0x06,
Fatal = 0x07,
Silent = 0x08,
}
}
}