forked from MeloNX/MeloNX
android - add string map
This commit is contained in:
parent
1c78587dfa
commit
269e7264e6
@ -42,7 +42,23 @@ namespace LibRyujinx
|
||||
private extern static JStringLocalRef createString(JEnvRef jEnv, IntPtr ch);
|
||||
|
||||
[DllImport("libryujinxjni")]
|
||||
private extern static void pushString(string ch);
|
||||
private extern static long storeString(string ch);
|
||||
[DllImport("libryujinxjni")]
|
||||
private extern static IntPtr getString(long id);
|
||||
|
||||
private static string GetStoredString(long id)
|
||||
{
|
||||
var pointer = getString(id);
|
||||
if (pointer != IntPtr.Zero)
|
||||
{
|
||||
var str = Marshal.PtrToStringAnsi(pointer) ?? "";
|
||||
|
||||
Marshal.FreeHGlobal(pointer);
|
||||
return str;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
[DllImport("libryujinxjni")]
|
||||
internal extern static void setRenderingThread();
|
||||
@ -514,11 +530,11 @@ namespace LibRyujinx
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_userGetOpenedUser")]
|
||||
public static void JniGetOpenedUser(JEnvRef jEnv, JObjectLocalRef jObj)
|
||||
public static JLong JniGetOpenedUser(JEnvRef jEnv, JObjectLocalRef jObj)
|
||||
{
|
||||
var userId = GetOpenedUser();
|
||||
|
||||
pushString(userId);
|
||||
return storeString(userId);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_userGetUserPicture")]
|
||||
|
@ -29,6 +29,7 @@ add_library( # Sets the name of the library.
|
||||
# Provides a relative path to your source file(s).
|
||||
vulkan_wrapper.cpp
|
||||
oboe.cpp
|
||||
string_helper.cpp
|
||||
ryujinx.cpp)
|
||||
|
||||
# Searches for a specified prebuilt library and stores the path as a
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <fcntl.h>
|
||||
#include "libraries/adrenotools/include/adrenotools/driver.h"
|
||||
#include "native_window.h"
|
||||
#include "string_helper.h"
|
||||
|
||||
// A macro to pass call to Vulkan and check for return value for success
|
||||
#define CALL_VK(func) \
|
||||
@ -46,5 +47,6 @@ JavaVM* _vm = nullptr;
|
||||
jobject _mainActivity = nullptr;
|
||||
jclass _mainActivityClass = nullptr;
|
||||
std::string _currentString = "";
|
||||
string_helper str_helper = string_helper();
|
||||
|
||||
#endif //RYUJINXNATIVE_RYUIJNX_H
|
||||
|
@ -312,24 +312,28 @@ Java_org_ryujinx_android_NativeHelpers_getProgressInfo(JNIEnv *env, jobject thiz
|
||||
return createStringFromStdString(env, progressInfo);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
long storeString(char* str){
|
||||
return str_helper.store_cstring(str);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
const char* getString(long id){
|
||||
auto str = str_helper.get_stored(id);
|
||||
auto cstr = (char*)::malloc(str.length() + 1);
|
||||
::strcpy(cstr, str.c_str());
|
||||
return cstr;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_ryujinx_android_NativeHelpers_storeStringJava(JNIEnv *env, jobject thiz, jstring string) {
|
||||
auto str = getStringPointer(env, string);
|
||||
return str_helper.store_cstring(str);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_ryujinx_android_NativeHelpers_popStringJava(JNIEnv *env, jobject thiz) {
|
||||
return createStringFromStdString(env, _currentString);
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_ryujinx_android_NativeHelpers_pushStringJava(JNIEnv *env, jobject thiz, jstring string) {
|
||||
_currentString = getStringPointer(env, string);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
void pushString(char* str){
|
||||
_currentString = str;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
const char* popString(){
|
||||
return _currentString.c_str();
|
||||
Java_org_ryujinx_android_NativeHelpers_getStringJava(JNIEnv *env, jobject thiz, jlong id) {
|
||||
return createStringFromStdString(env, str_helper.get_stored(id));
|
||||
}
|
||||
|
24
src/RyujinxAndroid/app/src/main/cpp/string_helper.cpp
Normal file
24
src/RyujinxAndroid/app/src/main/cpp/string_helper.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Emmanuel Hansen on 10/30/2023.
|
||||
//
|
||||
|
||||
#include "string_helper.h"
|
||||
|
||||
long string_helper::store_cstring(const char *cstr) {
|
||||
auto id = ++current_id;
|
||||
_map.insert({id, cstr});
|
||||
return id;
|
||||
}
|
||||
|
||||
long string_helper::store_string(const string& str) {
|
||||
auto id = ++current_id;
|
||||
_map.insert({id, str});
|
||||
return id;
|
||||
}
|
||||
|
||||
string string_helper::get_stored(long id) {
|
||||
auto str = _map[id];
|
||||
_map.erase(id);
|
||||
|
||||
return str;
|
||||
}
|
29
src/RyujinxAndroid/app/src/main/cpp/string_helper.h
Normal file
29
src/RyujinxAndroid/app/src/main/cpp/string_helper.h
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by Emmanuel Hansen on 10/30/2023.
|
||||
//
|
||||
|
||||
#ifndef RYUJINXANDROID_STRING_HELPER_H
|
||||
#define RYUJINXANDROID_STRING_HELPER_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
using namespace std;
|
||||
class string_helper {
|
||||
public:
|
||||
long store_cstring(const char * cstr);
|
||||
long store_string(const string& str);
|
||||
|
||||
string get_stored(long id);
|
||||
|
||||
string_helper(){
|
||||
_map = unordered_map<long,string>();
|
||||
current_id = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
unordered_map<long, string> _map;
|
||||
long current_id;
|
||||
};
|
||||
|
||||
|
||||
#endif //RYUJINXANDROID_STRING_HELPER_H
|
@ -28,6 +28,6 @@ class NativeHelpers {
|
||||
external fun setSwapInterval(nativeWindow: Long, swapInterval: Int): Int
|
||||
external fun getProgressInfo() : String
|
||||
external fun getProgressValue() : Float
|
||||
external fun pushStringJava(string: String)
|
||||
external fun popStringJava() : String
|
||||
external fun storeStringJava(string: String) : Long
|
||||
external fun getStringJava(id: Long) : String
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class RyujinxNative {
|
||||
external fun deviceSignalEmulationClose()
|
||||
external fun deviceGetDlcTitleId(path: String, ncaPath: String) : String
|
||||
external fun deviceGetDlcContentList(path: String, titleId: Long) : Array<String>
|
||||
external fun userGetOpenedUser()
|
||||
external fun userGetOpenedUser() : Long
|
||||
external fun userGetUserPicture(userId: String) : String
|
||||
external fun userSetUserPicture(userId: String, picture: String)
|
||||
external fun userGetUserName(userId: String) : String
|
||||
|
@ -106,8 +106,8 @@ class HomeViews {
|
||||
}
|
||||
|
||||
if (refreshUser.value) {
|
||||
native.userGetOpenedUser()
|
||||
user.value = NativeHelpers().popStringJava()
|
||||
val id = native.userGetOpenedUser()
|
||||
user.value = NativeHelpers().getStringJava(id)
|
||||
if (user.value.isNotEmpty()) {
|
||||
val decoder = Base64.getDecoder()
|
||||
pic.value = decoder.decode(native.userGetUserPicture(user.value))
|
||||
|
@ -48,9 +48,9 @@ class UserViews {
|
||||
fun Main(viewModel: MainViewModel? = null, navController: NavHostController? = null) {
|
||||
val ryujinxNative = RyujinxNative()
|
||||
val decoder = Base64.getDecoder()
|
||||
ryujinxNative.userGetOpenedUser()
|
||||
val id = ryujinxNative.userGetOpenedUser()
|
||||
val openedUser = remember {
|
||||
mutableStateOf(NativeHelpers().popStringJava())
|
||||
mutableStateOf(NativeHelpers().getStringJava(id))
|
||||
}
|
||||
|
||||
val openedUserPic = remember {
|
||||
|
Loading…
x
Reference in New Issue
Block a user