Skip to content

Commit

Permalink
Port State Functions, is custom made change in SKSE code made by JCon…
Browse files Browse the repository at this point in the history
…tainer original author
  • Loading branch information
fjsaneiro committed Feb 6, 2018
1 parent 917f0f9 commit 948aabc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
10 changes: 10 additions & 0 deletions dep/skse/skse64/PapyrusNativeFunctionDef.inl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@
#undef LATENT_SPEC
#undef CLASS_NAME

#define ACCEPTS_STATE

#define VOID_SPEC 0
#include "skse64/PapyrusNativeFunctionDef_Base.inl"
#define VOID_SPEC 1
#include "skse64/PapyrusNativeFunctionDef_Base.inl"

#undef ACCEPTS_STATE

#undef CLASS_NAME
#undef NUM_PARAMS
68 changes: 61 additions & 7 deletions dep/skse/skse64/PapyrusNativeFunctionDef_Base.inl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ public:
#else
T_Result
#endif
(* CallbackType)(T_Base * base
(*CallbackType)(
#ifdef ACCEPTS_STATE
T_Base & state
#else
T_Base * base
#endif
#if NUM_PARAMS >= 1
, T_Arg0 arg0
#endif
Expand Down Expand Up @@ -125,6 +130,15 @@ public:
, T_Arg9 arg9
#endif
);

# ifdef ACCEPTS_STATE

struct shit {
CallbackType callback;
T_Base & state;
};

# endif

// Callback with long signature
typedef
Expand All @@ -135,7 +149,12 @@ public:
#else
T_Result
#endif
(* CallbackType_LongSig)(VMClassRegistry* registry, UInt32 stackId, T_Base * base
(* CallbackType_LongSig)(VMClassRegistry* registry, UInt32 stackId,
#ifdef ACCEPTS_STATE
T_Base & state
#else
T_Base * base
#endif
#if NUM_PARAMS >= 1
, T_Arg0 arg0
#endif
Expand Down Expand Up @@ -169,23 +188,43 @@ public:
);

// Short signature
CLASS_NAME(const char * fnName, const char * className, CallbackType callback, VMClassRegistry * registry)
:NativeFunction(fnName, className, IsStaticType <T_Base>::value, NUM_PARAMS)
#ifndef ACCEPTS_STATE
CLASS_NAME(const char * fnName, const char * className, CallbackType callback, VMClassRegistry * registry)
: NativeFunction(fnName, className, IsStaticType <T_Base>::value, NUM_PARAMS)
#else
CLASS_NAME(const char * fnName, const char * className, CallbackType callback, VMClassRegistry * registry, T_Base& state)
: NativeFunction(fnName, className, IsStaticType <StaticFunctionTag>::value, NUM_PARAMS)
#endif
{
// store callback
# ifdef ACCEPTS_STATE
m_callback = new shit{ callback, state };
_VMESSAGE("NativeFunction.Ctor %s state %p %p", fnName, &state, &((shit*)m_callback)->state);
# else
m_callback = (void *)callback;
# endif

m_bUseLongSignature = false;

InitParams(registry);
}

// Long signature
#ifndef ACCEPTS_STATE
CLASS_NAME(const char * fnName, const char * className, CallbackType_LongSig callback, VMClassRegistry * registry)
:NativeFunction(fnName, className, IsStaticType <T_Base>::value, NUM_PARAMS)
#else
CLASS_NAME(const char * fnName, const char * className, CallbackType_LongSig callback, VMClassRegistry * registry, T_Base& state)
:NativeFunction(fnName, className, IsStaticType <T_Base>::value, NUM_PARAMS)
#endif
{
// store callback
# ifdef ACCEPTS_STATE
m_callback = new shit{ callback, state };
_VMESSAGE("NativeFunction.Ctor %s state %p %p", fnName, &state, &((shit*)m_callback)->state);
# else
m_callback = (void *)callback;
# endif

m_bUseLongSignature = true;

Expand Down Expand Up @@ -246,7 +285,8 @@ public:

// get argument list
UInt32 argOffset = CALL_MEMBER_FN(state->argList, GetOffset)(state);


# ifndef ACCEPTS_STATE
T_Base * base = NULL;

// extract base object pointer for non-static types
Expand All @@ -255,6 +295,9 @@ public:
UnpackValue(&base, baseValue);
if (!base) return false;
}
# else
//_VMESSAGE("NativeFunction.Run state %p", &((shit*)m_callback)->state);
# endif

// extract parameters
#if NUM_PARAMS >= 1
Expand Down Expand Up @@ -307,7 +350,13 @@ public:
#elif !VOID_SPEC
T_Result result =
#endif
((CallbackType_LongSig)m_callback)(registry, stackId, base
#ifdef ACCEPTS_STATE
(((shit*)m_callback)->callback)(
((shit*)m_callback)->state
#else
((CallbackType_LongSig)m_callback)(registry, stackId, base
#endif

#if NUM_PARAMS >= 1
, arg0
#endif
Expand Down Expand Up @@ -359,7 +408,12 @@ public:
#elif !VOID_SPEC
T_Result result =
#endif
((CallbackType)m_callback)(base
#ifdef ACCEPTS_STATE
(((shit*)m_callback)->callback)(
((shit*)m_callback)->state
#else
((CallbackType)m_callback)(base
#endif
#if NUM_PARAMS >= 1
, arg0
#endif
Expand Down

0 comments on commit 948aabc

Please sign in to comment.