@@ -65,21 +65,19 @@ EventResult Plugin::TriggerEvent(std::string invokedBy, std::string eventName, s
65
65
if (eventName != " OnGameTick" ) REGISTER_CALLSTACK (this ->GetName (), string_format (" Event: %s(invokedBy=\" %s\" ,payload=\" %s\" ,event=%p)" , eventName.c_str (), invokedBy.c_str (), eventPayload.c_str (), (void *)event));
66
66
PERF_RECORD (string_format (" event:%s:%s" , invokedBy.c_str (), eventName.c_str ()), this ->GetName ());
67
67
68
- EValue payload (ctx, eventPayload);
69
- if (ctx->GetKind () == ContextKinds::JavaScript)
70
- payload = EValue (ctx, JS_NewUint8ArrayCopy ((JSContext*)ctx->GetState (), (uint8_t *)(eventPayload.data ()), eventPayload.size ()));
71
-
72
68
int res = (int )EventResult::Continue;
73
69
try
74
70
{
75
71
EValue func = *this ->globalEventHandler ;
76
- auto result = func (event, invokedBy, eventName, payload);
77
72
78
- if (!result.isNumber ())
79
- return EventResult::Continue;
73
+ if (ctx->GetKind () == ContextKinds::JavaScript) {
74
+ EValue val (ctx, JS_NewUint8ArrayCopy ((JSContext*)ctx->GetState (), (uint8_t *)(eventPayload.data ()), eventPayload.size ()));
75
+ res = func (event, invokedBy, eventName, val).cast_or <int >(0 );
76
+ } else {
77
+ res = func (event, invokedBy, eventName, eventPayload).cast_or <int >(0 );
78
+ }
80
79
81
- res = result.cast <int >();
82
- if (res < (int )EventResult::Continue || res >(int )EventResult::Handled)
80
+ if (res < (int )EventResult::Continue || res > (int )EventResult::Handled)
83
81
return EventResult::Continue;
84
82
}
85
83
catch (EException& e)
0 commit comments