Files
OpenRoyale/native/include/primitives.h
T
2026-07-09 07:40:42 +02:00

45 lines
2.5 KiB
C++

// primitives.h - reconstructed core engine primitives of libg.so (Titan).
//
// These are the small utility functions the engine's JNI roots call most often (see CALL_GRAPH.md).
// They are reconstructed for FUNCTIONAL EQUIVALENCE from radare2 evidence (imported symbols + string
// references), not byte-for-byte. Names stay as sub_<addr> placeholders.
//
// sub_20d578 debug mutex LOCK (evidence: pthread_mutex_lock + "Trying to set mutex lock from
// %s but its already locked from %s")
// sub_20d650 debug mutex UNLOCK (evidence: pthread_mutex_unlock + "mutexUnlock called when mutex
// is not even locked")
// sub_20d828 JNI GetMethodID (evidence: string "getJMethod"; JNIEnv vtable deref at +0x14 area)
// sub_2116f4 monotonic time (evidence: clock_gettime)
#pragma once
#include <jni.h>
#include <cstdint>
#include <pthread.h>
namespace titan {
// A debug/owner-tracked recursive-safe mutex, matching the two helpers' observed behaviour
// (warn-on-conflict lock, warn-on-unlocked unlock). The original stores an owner label per mutex.
struct DebugMutex {
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
const char* owner = nullptr; // caller label of the current holder (TODO: exact storage)
bool locked = false;
};
bool sub_20d578(DebugMutex& mtx, const char* caller = nullptr); // lock; returns acquired (bool)
void sub_20d650(DebugMutex& mtx); // unlock
bool sub_20d62c(DebugMutex& mtx); // lock wrapper returning success bool (&1)
jmethodID sub_20d828(JNIEnv* env, jobject obj, const char* name, const char* sig); // GetMethodID helper
int64_t sub_2116f4(); // monotonic time, nanoseconds
// JNI method-id cache (engine->Java up-call bridge). createGameMain pre-caches ~81 method ids at
// boot via sub_20de14 -> sub_20dbb8 ("cacheJMethod"). Reconstructed for functional equivalence:
// resolve a (static or instance) methodID on a class and store it so up-call sites can retrieve it.
// sub_20dbb8(env, clazz, name, sig, isStatic) cache + return a method id
// sub_20de14(env, clazz, name, sig) wrapper: sub_20dbb8(..., isStatic=true)
jmethodID sub_20dbb8(JNIEnv* env, jclass clazz, const char* name, const char* sig, bool isStatic);
jmethodID sub_20de14(JNIEnv* env, jclass clazz, const char* name, const char* sig);
// Retrieve a previously cached method id (by name+sig), or nullptr.
jmethodID titan_cached_method(const char* name, const char* sig);
} // namespace titan