Skip to content

Commit

Permalink
[unity]简化UnityExports4Puerts.h
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Sep 30, 2024
1 parent d273c28 commit fe6970b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ ${bridgeInfos.map(genBridge).join('\n')}
static BridgeFuncInfo g_bridgeFuncInfos[] = {
${FOR(bridgeInfos, info => t`
{"${info.Signature}", (MethodPointer)b_${info.Signature}},
{"${info.Signature}", (Il2CppMethodPointer)b_${info.Signature}},
`)}
{nullptr, nullptr}
};
MethodPointer FindBridgeFunc(const char* signature)
Il2CppMethodPointer FindBridgeFunc(const char* signature)
{
auto begin = &g_bridgeFuncInfos[0];
auto end = &g_bridgeFuncInfos[sizeof(g_bridgeFuncInfos) / sizeof(BridgeFuncInfo) - 1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ using namespace il2cpp::vm;

namespace puerts
{

struct CSharpMethodInfo
{
std::string Name;
Expand All @@ -53,22 +52,23 @@ struct CSharpMethodInfo
std::vector<WrapData*> OverloadDatas;
};

struct FieldWrapData
{
FieldWrapFuncPtr Getter;
FieldWrapFuncPtr Setter;
FieldInfo *FieldInfo;
size_t Offset;
Il2CppClass* TypeInfo;
};

struct CSharpFieldInfo
{
std::string Name;
bool IsStatic;
FieldWrapData *Data;
};

struct JsClassInfoHeader
{
const void* TypeId;
const void* SuperTypeId;
Il2CppClass* Class;
bool IsValueType;
Il2CppMethodPointer DelegateBridge;
WrapData** CtorWrapDatas;
};

struct JsClassInfo : public JsClassInfoHeader
{
std::string Name;
Expand Down Expand Up @@ -1741,7 +1741,7 @@ Il2CppObject* GetJSObjectValue(Il2CppObject* jsObject, Il2CppString* key, Il2Cpp

WrapFuncPtr FindWrapFunc(const char* signature);
struct FieldWrapFuncInfo * FindFieldWrapFuncInfo(const char* signature);
MethodPointer FindBridgeFunc(const char* signature);
Il2CppMethodPointer FindBridgeFunc(const char* signature);

puerts::UnityExports* GetUnityExports()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@

namespace puerts
{
typedef void (*FieldWrapFuncPtr)(pesapi_callback_info info, FieldInfo* field, size_t offset, Il2CppClass* fieldType);
typedef bool (*WrapFuncPtr)(MethodInfo* method, Il2CppMethodPointer methodPointer, pesapi_callback_info info, bool checkArgument, struct WrapData* wrapData);

struct FieldWrapData
{
FieldWrapFuncPtr Getter;
FieldWrapFuncPtr Setter;
FieldInfo *FieldInfo;
size_t Offset;
Il2CppClass* TypeInfo;
};

struct WrapData
{
WrapFuncPtr Wrap;
MethodInfo* Method;
Il2CppMethodPointer MethodPointer;
bool IsStatic;
bool IsExtensionMethod;
bool HasParamArray;
int OptionalNum;
Il2CppClass* TypeInfos[0];
};

// begin function in Puerts_il2cpp.cpp
Il2CppObject* JsValueToCSRef(Il2CppClass *klass, pesapi_env env, pesapi_value jsval);

Expand Down Expand Up @@ -108,7 +132,7 @@ struct WrapFuncInfo
struct BridgeFuncInfo
{
const char* Signature;
MethodPointer Method;
Il2CppMethodPointer Method;
};

struct FieldWrapFuncInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ struct PObjectRefInfo

#if defined(USE_OUTSIZE_UNITY)

typedef void (*MethodPointer)();
typedef void MethodType;
typedef bool (*WrapFuncPtr)(MethodType* method, MethodPointer methodPointer, const v8::FunctionCallbackInfo<v8::Value>& info, bool checkArgument, struct WrapData* wrapData);

typedef void (*FieldWrapFuncPtr)(const v8::FunctionCallbackInfo<v8::Value>& info, void* fieldInfo, size_t offset, void* typeInfo);

typedef void TypeIdType;
typedef void* (*GetJsClassInfoFunc)(const void* TypeId, bool TryLazyLoad);

typedef void (*SetNativePtrFunc)(v8::Object* obj, void* ptr, void* type_id);

Expand All @@ -36,14 +30,8 @@ typedef const void* (*CSharpTypeToTypeIdFunc)(const void *type);
typedef v8::Value* (*GetModuleExecutorFunc)(v8::Context* env);

#else

#define MethodPointer Il2CppMethodPointer

typedef MethodInfo MethodType;
typedef bool (*WrapFuncPtr)(MethodType* method, Il2CppMethodPointer methodPointer, pesapi_callback_info info, bool checkArgument, struct WrapData* wrapData);
typedef void (*FieldWrapFuncPtr)(pesapi_callback_info info, FieldInfo* field, size_t offset, Il2CppClass* fieldType);

typedef Il2CppClass TypeIdType;

typedef struct JsClassInfoHeader* (*GetJsClassInfoFunc)(const void* TypeId, bool TryLazyLoad);

typedef void (*SetNativePtrFunc)(pesapi_value obj, void* ptr, const void* type_id);

Expand All @@ -55,7 +43,6 @@ typedef pesapi_value (*GetModuleExecutorFunc)(pesapi_env env);

#endif

typedef struct JsClassInfoHeader* (*GetJsClassInfoFunc)(const void* TypeId, bool TryLazyLoad);

typedef void* (*GetRuntimeObjectFromPersistentObjectFunc)(pesapi_env env, pesapi_value pvalue);

Expand All @@ -65,28 +52,6 @@ typedef void(*LogCallbackFunc)(const char* value);

typedef void (*SetExtraDataFunc)(pesapi_env env, struct PObjectRefInfo* objectInfo);

struct WrapData
{
WrapFuncPtr Wrap;
MethodType* Method;
MethodPointer MethodPointer;
bool IsStatic;
bool IsExtensionMethod;
bool HasParamArray;
int OptionalNum;
TypeIdType* TypeInfos[0];
};

struct JsClassInfoHeader
{
const void* TypeId;
const void* SuperTypeId;
TypeIdType* Class;
bool IsValueType;
MethodPointer DelegateBridge;
WrapData** CtorWrapDatas;
};

struct UnityExports
{
//.cpp api
Expand Down
41 changes: 3 additions & 38 deletions unity/cli/UnityExports4Puerts.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ struct PObjectRefInfo

#if defined(USE_OUTSIZE_UNITY)

typedef void (*MethodPointer)();
typedef void MethodType;
typedef bool (*WrapFuncPtr)(MethodType* method, MethodPointer methodPointer, const v8::FunctionCallbackInfo<v8::Value>& info, bool checkArgument, struct WrapData* wrapData);

typedef void (*FieldWrapFuncPtr)(const v8::FunctionCallbackInfo<v8::Value>& info, void* fieldInfo, size_t offset, void* typeInfo);

typedef void TypeIdType;
typedef void* (*GetJsClassInfoFunc)(const void* TypeId, bool TryLazyLoad);

typedef void (*SetNativePtrFunc)(v8::Object* obj, void* ptr, void* type_id);

Expand All @@ -36,14 +30,8 @@ typedef const void* (*CSharpTypeToTypeIdFunc)(const void *type);
typedef v8::Value* (*GetModuleExecutorFunc)(v8::Context* env);

#else

#define MethodPointer Il2CppMethodPointer

typedef MethodInfo MethodType;
typedef bool (*WrapFuncPtr)(MethodType* method, Il2CppMethodPointer methodPointer, pesapi_callback_info info, bool checkArgument, struct WrapData* wrapData);
typedef void (*FieldWrapFuncPtr)(pesapi_callback_info info, FieldInfo* field, size_t offset, Il2CppClass* fieldType);

typedef Il2CppClass TypeIdType;

typedef struct JsClassInfoHeader* (*GetJsClassInfoFunc)(const void* TypeId, bool TryLazyLoad);

typedef void (*SetNativePtrFunc)(pesapi_value obj, void* ptr, const void* type_id);

Expand All @@ -55,7 +43,6 @@ typedef pesapi_value (*GetModuleExecutorFunc)(pesapi_env env);

#endif

typedef struct JsClassInfoHeader* (*GetJsClassInfoFunc)(const void* TypeId, bool TryLazyLoad);

typedef void* (*GetRuntimeObjectFromPersistentObjectFunc)(pesapi_env env, pesapi_value pvalue);

Expand All @@ -65,28 +52,6 @@ typedef void(*LogCallbackFunc)(const char* value);

typedef void (*SetExtraDataFunc)(pesapi_env env, struct PObjectRefInfo* objectInfo);

struct WrapData
{
WrapFuncPtr Wrap;
MethodType* Method;
MethodPointer MethodPointer;
bool IsStatic;
bool IsExtensionMethod;
bool HasParamArray;
int OptionalNum;
TypeIdType* TypeInfos[0];
};

struct JsClassInfoHeader
{
const void* TypeId;
const void* SuperTypeId;
TypeIdType* Class;
bool IsValueType;
MethodPointer DelegateBridge;
WrapData** CtorWrapDatas;
};

struct UnityExports
{
//.cpp api
Expand Down
4 changes: 2 additions & 2 deletions unity/native_src_il2cpp/Src/Puerts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ static void SetRuntimeObjectToPersistentObject(pesapi_env env, pesapi_value pval
}


static JsClassInfoHeader* GetJsClassInfo(const void* TypeId, bool TryLazyLoad)
static void* GetJsClassInfo(const void* TypeId, bool TryLazyLoad)
{
auto ClassDefinition = FindClassByID(TypeId, TryLazyLoad);
if (!ClassDefinition)
{
return nullptr;
}

return static_cast<JsClassInfoHeader*>(ClassDefinition->Data);
return ClassDefinition->Data;
}

static v8::Value* GetModuleExecutor(v8::Context* env)
Expand Down

0 comments on commit fe6970b

Please sign in to comment.