Skip to content

Commit 5a9b147

Browse files
authored
update(core): v1.6.2 (#92)
2 parents aaf9a16 + 8a1c755 commit 5a9b147

File tree

10 files changed

+81
-38
lines changed

10 files changed

+81
-38
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"semaphore": "cpp",
9595
"*.tcc": "cpp",
9696
"future": "cpp",
97-
"variant": "cpp"
97+
"variant": "cpp",
98+
"csetjmp": "cpp"
9899
}
99100
}

AMBuilder

+5
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ for sdk_target in MMSPlugin.sdk_targets:
305305
"/IGNORE:4101,4267,4244,4005,4003,4530",
306306
]
307307

308+
if os.getenv("SWIFTLY_VERSION") != None:
309+
binary.compiler.defines += [
310+
"SWIFTLY_VERSION=\"" + os.getenv("SWIFTLY_VERSION") + "\""
311+
]
312+
308313
binary.compiler.cxxincludes += [
309314
os.path.join(builder.sourcePath, 'vendor'),
310315
os.path.join(builder.sourcePath, 'vendor', 'lua-rapidjson', 'rapidjson', 'include'),

CHANGELOG.md

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
Over here will be noted all the update change logs.
44

5+
## v1.6.2 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.2)
6+
7+
### Exports
8+
9+
- Now the earliest point you can call exports is from `OnPluginStart`.
10+
11+
### MySQL
12+
13+
- Windows Fix: Gibberish queries
14+
15+
### Commands
16+
17+
- Swiftly Version
18+
19+
### JavaScript Optimization
20+
21+
- 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.
22+
23+
### Events
24+
25+
- Prevent crashes on FireEventToClient
26+
- Sharing event object causing undefined behaviour
27+
- JavaScript: Sometimes not setting out the correct value for EventResult
28+
29+
### Player
30+
31+
- Fix IP Address save
32+
533
## v1.6.1 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.1)
634

735
### VGUI

plugin_files/bin/scripting/0_events.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const LoadEventFile = (global) => {
1010
const handlers = eventHandlers[eventName]
1111
for (let i = 0; i < handlers.length; i++) {
1212
if ((typeof handlers[i].handle) == "function") {
13-
const result = (handlers[i].handle.apply(null, eventData) || EventResult.Continue);
13+
let result = (handlers[i].handle.apply(null, eventData));
14+
if (result == null || result == undefined) result = EventResult.Continue;
1415
if (result != EventResult.Continue) return result
1516
}
1617
}
@@ -28,7 +29,8 @@ const LoadEventFile = (global) => {
2829
const handlers = eventHandlers[eventName]
2930
for (let i = 0; i < handlers.length; i++) {
3031
if ((typeof handlers[i].handle) == "function") {
31-
const result = (handlers[i].handle.apply(null, eventData) || EventResult.Continue);
32+
let result = (handlers[i].handle.apply(null, eventData));
33+
if (result == null || result == undefined) result = EventResult.Continue;
3234
if (result != EventResult.Continue) return result
3335
}
3436
}

src/plugins/object.cpp

+27-18
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ PluginObject::PluginObject(std::string m_name, ContextKinds m_kind)
1919

2020
PluginObject::~PluginObject()
2121
{
22-
if (eventFunctionPtr)
23-
{
24-
delete eventFunctionPtr;
25-
}
2622
}
2723

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

5854
EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventName, std::vector<std::any> eventPayload, ClassData* eventObject)
5955
{
60-
if (GetPluginState() == PluginState_t::Stopped && eventName != "OnPluginStart" && eventName != "OnAllPluginsLoaded")
61-
return EventResult::Continue;
62-
6356
if (!eventFunctionPtr)
6457
return EventResult::Continue;
6558

@@ -73,11 +66,14 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
7366
EventResult response = EventResult::Continue;
7467
try
7568
{
76-
if (!eventObject) {
77-
ClassData tmpObject({ { "plugin_name", invokedBy } }, "Event", ctx);
78-
eventObject = &tmpObject;
69+
ClassData* localObj = eventObject;
70+
bool created = false;
71+
if (!localObj) {
72+
localObj = new ClassData({ { "plugin_name", invokedBy } }, "Event", ctx);
73+
created = true;
7974
}
80-
auto value = (*eventFunctionPtr)(eventObject, eventName, eventPayload);
75+
76+
auto value = (*eventFunctionPtr)(localObj, eventName, eventPayload);
8177
if (value.isNumber())
8278
{
8379
int result = value.cast<int>();
@@ -86,6 +82,7 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
8682
else
8783
response = (EventResult)result;
8884
}
85+
if (created) delete localObj;
8986
}
9087
catch (EException& e)
9188
{
@@ -101,9 +98,6 @@ EventResult PluginObject::TriggerEvent(std::string invokedBy, std::string eventN
10198

10299
EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string eventName, std::string eventPayload, ClassData* eventObject)
103100
{
104-
if (GetPluginState() == PluginState_t::Stopped && eventName != "OnPluginStart" && eventName != "OnAllPluginsLoaded")
105-
return EventResult::Continue;
106-
107101
if (!eventFunctionPtr)
108102
return EventResult::Continue;
109103

@@ -117,11 +111,14 @@ EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string ev
117111
EventResult response = EventResult::Continue;
118112
try
119113
{
120-
if (!eventObject) {
121-
ClassData tmpObject({ { "plugin_name", invokedBy } }, "Event", ctx);
122-
eventObject = &tmpObject;
114+
ClassData* localObj = eventObject;
115+
bool created = false;
116+
if (!localObj) {
117+
localObj = new ClassData({ { "plugin_name", invokedBy } }, "Event", ctx);
118+
created = true;
123119
}
124-
auto value = (*eventFunctionPtrJSON)(eventObject, eventName, eventPayload);
120+
121+
auto value = (*eventFunctionPtrJSON)(localObj, eventName, eventPayload);
125122
if (value.isNumber())
126123
{
127124
int result = value.cast<int>();
@@ -130,6 +127,7 @@ EventResult PluginObject::TriggerEventJSON(std::string invokedBy, std::string ev
130127
else
131128
response = (EventResult)result;
132129
}
130+
if (created) delete localObj;
133131
}
134132
catch (EException& e)
135133
{
@@ -304,6 +302,17 @@ void PluginObject::DestroyScriptingEnvironment()
304302
g_commandsManager.UnregisterCommand(command);
305303

306304
eventHandlers.clear();
305+
306+
if (eventFunctionPtr) {
307+
delete eventFunctionPtr;
308+
eventFunctionPtr = nullptr;
309+
}
310+
311+
if (eventFunctionPtrJSON) {
312+
delete eventFunctionPtrJSON;
313+
eventFunctionPtrJSON = nullptr;
314+
}
315+
307316
delete ctx;
308317
}
309318

src/scripting/engine/events.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ LoadScriptingComponent(events, [](PluginObject plugin, EContext* ctx) -> void {
177177
if (slot < 0 || slot >= GetMaxGameClients()) return;
178178

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

src/scripting/entities/weapons.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,5 @@ LoadScriptingComponent(weapons, [](PluginObject plugin, EContext* ctx) -> void {
390390
}
391391
}
392392
}
393-
394-
SetStateChanged((uintptr_t)vmbodyComponent, "CBaseEntity", "m_CBodyComponent", 0);
395393
});
396394
})

src/scripting/network/database.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include <utils/common.h>
66
#include <utils/utils.h>
77

8+
#ifdef strdup
9+
#undef strdup
10+
#endif
11+
812
void Query(IDatabase* db, std::string query, EValue callback, EContext* L)
913
{
1014
if (db->GetKind() != "mysql" && db->GetKind() != "sqlite") {
@@ -17,8 +21,11 @@ void Query(IDatabase* db, std::string query, EValue callback, EContext* L)
1721
if (databaseRequestsQueue.isTable())
1822
databaseRequestsQueue.setProperty(uuid, EValue(callback));
1923

24+
const char* nq = (const char*)(strdup(query.c_str()));
25+
if (!nq) return;
26+
2027
DatabaseQueryQueue queue = {
21-
query,
28+
nq,
2229
uuid,
2330
};
2431
db->AddQueryQueue(queue);
@@ -120,18 +127,7 @@ LoadScriptingComponent(database, [](PluginObject plugin, EContext* ctx) -> void
120127

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

123-
std::string uuid = get_uuid();
124-
125-
EValue databaseRequestsQueue = EValue::getGlobal(context->GetPluginContext(), "databaseRequestsQueue");
126-
if (databaseRequestsQueue.isTable()) {
127-
databaseRequestsQueue.setProperty(uuid, EValue(callback));
128-
}
129-
130-
DatabaseQueryQueue queue = {
131-
query,
132-
uuid,
133-
};
134-
db->AddQueryQueue(queue);
130+
Query(db, query, callback, context->GetPluginContext());
135131
});
136132

137133
ADD_CLASS_FUNCTION("Database", "QueryBuilder", [](FunctionContext* context, ClassData* data) -> void {

src/server/player/player.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Player::Player(bool m_isFakeClient, int m_slot, const char* m_name, uint64_t m_x
129129
connectTime = time(0);
130130
name = m_name;
131131
xuid = m_xuid;
132-
ip_address = ip_address;
132+
this->ip_address = ip_address;
133133

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

0 commit comments

Comments
 (0)