Skip to content

Commit 729880b

Browse files
committed
fix(events): Not always sending a string for event payload
1 parent d5088fb commit 729880b

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/plugins/Plugin.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,19 @@ EventResult Plugin::TriggerEvent(std::string invokedBy, std::string eventName, s
6565
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));
6666
PERF_RECORD(string_format("event:%s:%s", invokedBy.c_str(), eventName.c_str()), this->GetName());
6767

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-
7268
int res = (int)EventResult::Continue;
7369
try
7470
{
7571
EValue func = *this->globalEventHandler;
76-
auto result = func(event, invokedBy, eventName, payload);
7772

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+
}
8079

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)
8381
return EventResult::Continue;
8482
}
8583
catch (EException& e)

0 commit comments

Comments
 (0)