Skip to content

update(core): v1.6.2 #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"semaphore": "cpp",
"*.tcc": "cpp",
"future": "cpp",
"variant": "cpp"
"variant": "cpp",
"csetjmp": "cpp"
}
}
5 changes: 5 additions & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ for sdk_target in MMSPlugin.sdk_targets:
"/IGNORE:4101,4267,4244,4005,4003,4530",
]

if os.getenv("SWIFTLY_VERSION") != None:
binary.compiler.defines += [
"SWIFTLY_VERSION=\"" + os.getenv("SWIFTLY_VERSION") + "\""
]

binary.compiler.cxxincludes += [
os.path.join(builder.sourcePath, 'vendor'),
os.path.join(builder.sourcePath, 'vendor', 'lua-rapidjson', 'rapidjson', 'include'),
Expand Down
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

Over here will be noted all the update change logs.

## v1.6.2 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.2)

### Exports

- Now the earliest point you can call exports is from `OnPluginStart`.

### MySQL

- Windows Fix: Gibberish queries

### Commands

- Swiftly Version

### JavaScript Optimization

- Optimized the memory from a minimum of 3MB per each plugin to a minimum of ~300KB. This was tested with a bare-bone plugin with just the mandatory functions included.

### Events

- Prevent crashes on FireEventToClient
- Sharing event object causing undefined behaviour
- JavaScript: Sometimes not setting out the correct value for EventResult

### Player

- Fix IP Address save

## v1.6.1 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.1)

### VGUI
Expand Down
6 changes: 4 additions & 2 deletions plugin_files/bin/scripting/0_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const LoadEventFile = (global) => {
const handlers = eventHandlers[eventName]
for (let i = 0; i < handlers.length; i++) {
if ((typeof handlers[i].handle) == "function") {
const result = (handlers[i].handle.apply(null, eventData) || EventResult.Continue);
let result = (handlers[i].handle.apply(null, eventData));
if (result == null || result == undefined) result = EventResult.Continue;
if (result != EventResult.Continue) return result
}
}
Expand All @@ -28,7 +29,8 @@ const LoadEventFile = (global) => {
const handlers = eventHandlers[eventName]
for (let i = 0; i < handlers.length; i++) {
if ((typeof handlers[i].handle) == "function") {
const result = (handlers[i].handle.apply(null, eventData) || EventResult.Continue);
let result = (handlers[i].handle.apply(null, eventData));
if (result == null || result == undefined) result = EventResult.Continue;
if (result != EventResult.Continue) return result
}
}
Expand Down
45 changes: 27 additions & 18 deletions src/plugins/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ PluginObject::PluginObject(std::string m_name, ContextKinds m_kind)

PluginObject::~PluginObject()
{
if (eventFunctionPtr)
{
delete eventFunctionPtr;
}
}

void PluginObject::RegisterEventHandlerJSON(EValue* functionPtr)
Expand Down Expand Up @@ -57,9 +53,6 @@ void PluginObject::UnregisterEventHandling(std::string eventName)

EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventName, std::vector<std::any> eventPayload, ClassData* eventObject)
{
if (GetPluginState() == PluginState_t::Stopped && eventName != "OnPluginStart" && eventName != "OnAllPluginsLoaded")
return EventResult::Continue;

if (!eventFunctionPtr)
return EventResult::Continue;

Expand All @@ -73,11 +66,14 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
EventResult response = EventResult::Continue;
try
{
if (!eventObject) {
ClassData tmpObject({ { "plugin_name", invokedBy } }, "Event", ctx);
eventObject = &tmpObject;
ClassData* localObj = eventObject;
bool created = false;
if (!localObj) {
localObj = new ClassData({ { "plugin_name", invokedBy } }, "Event", ctx);
created = true;
}
auto value = (*eventFunctionPtr)(eventObject, eventName, eventPayload);

auto value = (*eventFunctionPtr)(localObj, eventName, eventPayload);
if (value.isNumber())
{
int result = value.cast<int>();
Expand All @@ -86,6 +82,7 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
else
response = (EventResult)result;
}
if (created) delete localObj;
}
catch (EException& e)
{
Expand All @@ -101,9 +98,6 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN

EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string eventName, std::string eventPayload, ClassData* eventObject)
{
if (GetPluginState() == PluginState_t::Stopped && eventName != "OnPluginStart" && eventName != "OnAllPluginsLoaded")
return EventResult::Continue;

if (!eventFunctionPtr)
return EventResult::Continue;

Expand All @@ -117,11 +111,14 @@ EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string ev
EventResult response = EventResult::Continue;
try
{
if (!eventObject) {
ClassData tmpObject({ { "plugin_name", invokedBy } }, "Event", ctx);
eventObject = &tmpObject;
ClassData* localObj = eventObject;
bool created = false;
if (!localObj) {
localObj = new ClassData({ { "plugin_name", invokedBy } }, "Event", ctx);
created = true;
}
auto value = (*eventFunctionPtrJSON)(eventObject, eventName, eventPayload);

auto value = (*eventFunctionPtrJSON)(localObj, eventName, eventPayload);
if (value.isNumber())
{
int result = value.cast<int>();
Expand All @@ -130,6 +127,7 @@ EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string ev
else
response = (EventResult)result;
}
if (created) delete localObj;
}
catch (EException& e)
{
Expand Down Expand Up @@ -304,6 +302,17 @@ void PluginObject::DestroyScriptingEnvironment()
g_commandsManager.UnregisterCommand(command);

eventHandlers.clear();

if (eventFunctionPtr) {
delete eventFunctionPtr;
eventFunctionPtr = nullptr;
}

if (eventFunctionPtrJSON) {
delete eventFunctionPtrJSON;
eventFunctionPtrJSON = nullptr;
}

delete ctx;
}

Expand Down
4 changes: 4 additions & 0 deletions src/scripting/engine/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ LoadScriptingComponent(events, [](PluginObject plugin, EContext* ctx) -> void {
if (slot < 0 || slot >= GetMaxGameClients()) return;

IGameEventListener2* playerListener = g_GameData.FetchSignature<GetLegacyGameEventListener>("LegacyGameEventListener")(slot);
if (!g_gameEventManager->FindListener(playerListener, data->GetData<IGameEvent*>("event_data")->GetName())) {
/* TODO: Crash Reporter - Report crash prevention */
return;
}
playerListener->FireGameEvent(data->GetData<IGameEvent*>("event_data"));
});

Expand Down
2 changes: 0 additions & 2 deletions src/scripting/entities/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,5 @@ LoadScriptingComponent(weapons, [](PluginObject plugin, EContext* ctx) -> void {
}
}
}

SetStateChanged((uintptr_t)vmbodyComponent, "CBaseEntity", "m_CBodyComponent", 0);
});
})
22 changes: 9 additions & 13 deletions src/scripting/network/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <utils/common.h>
#include <utils/utils.h>

#ifdef strdup
#undef strdup
#endif

void Query(IDatabase* db, std::string query, EValue callback, EContext* L)
{
if (db->GetKind() != "mysql" && db->GetKind() != "sqlite") {
Expand All @@ -17,8 +21,11 @@ void Query(IDatabase* db, std::string query, EValue callback, EContext* L)
if (databaseRequestsQueue.isTable())
databaseRequestsQueue.setProperty(uuid, EValue(callback));

const char* nq = (const char*)(strdup(query.c_str()));
if (!nq) return;

DatabaseQueryQueue queue = {
query,
nq,
uuid,
};
db->AddQueryQueue(queue);
Expand Down Expand Up @@ -120,18 +127,7 @@ LoadScriptingComponent(database, [](PluginObject plugin, EContext* ctx) -> void

EValue callback = context->GetArgument<EValue>(1);

std::string uuid = get_uuid();

EValue databaseRequestsQueue = EValue::getGlobal(context->GetPluginContext(), "databaseRequestsQueue");
if (databaseRequestsQueue.isTable()) {
databaseRequestsQueue.setProperty(uuid, EValue(callback));
}

DatabaseQueryQueue queue = {
query,
uuid,
};
db->AddQueryQueue(queue);
Query(db, query, callback, context->GetPluginContext());
});

ADD_CLASS_FUNCTION("Database", "QueryBuilder", [](FunctionContext* context, ClassData* data) -> void {
Expand Down
2 changes: 1 addition & 1 deletion src/server/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Player::Player(bool m_isFakeClient, int m_slot, const char* m_name, uint64_t m_x
connectTime = time(0);
name = m_name;
xuid = m_xuid;
ip_address = ip_address;
this->ip_address = ip_address;

centerMessageEvent = g_gameEventManager->CreateEvent("show_survival_respawn_status", true);

Expand Down
2 changes: 1 addition & 1 deletion vendor/embedder