Skip to content

Commit 286c52c

Browse files
authored
update(core): v1.6.3 (#93)
2 parents d75feac + 7b2b0b6 commit 286c52c

File tree

7 files changed

+84
-7
lines changed

7 files changed

+84
-7
lines changed

CHANGELOG.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

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

5+
## v1.6.3 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.3)
6+
7+
### Core
8+
9+
- Added Crash Prevention for Schema/SDK accessing and for FireEvent.
10+
11+
![imgalt](https://cdn.skuzzi.ro/dfihge478fg3h478veriufh938wf.png)
12+
![imgalt](https://cdn.skuzzi.ro/vj9834uf09asweifmnjw398fj92hfivsewh98w.png)
13+
14+
### Crash Reporter
15+
16+
- Added arguments inside CallStack back.
17+
18+
### CEntityKeyValues
19+
20+
- Fixed crashes when map was changing.
21+
522
## v1.6.2 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.2)
623

724
### Exports
@@ -126,4 +143,4 @@ Over here will be noted all the update change logs.
126143

127144
- [+] Error Stack Trace
128145

129-
![ImgAlt](https://cdn.skuzzi.ro/zJIsaG8viy2FVsXbtQxmGxCmTJ62iKOD.png)
146+
![ImgAlt](https://cdn.skuzzi.ro/zJIsaG8viy2FVsXbtQxmGxCmTJ62iKOD.png)

src/engine/vgui/screentext.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ void ScreenText::SetRenderingTo(CEntityInstance* ent)
197197
}
198198

199199
void EraseScheduledCEntKeyVals() {
200-
for (auto e : scheduleForDelete) {
201-
delete e;
202-
}
200+
// for (auto e : scheduleForDelete) {
201+
// delete e;
202+
// }
203203
scheduleForDelete.clear();
204204
}

src/scripting/core.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ void SetupScriptingEnvironment(PluginObject plugin, EContext* ctx)
7272

7373
ADD_FUNCTION("OnFunctionContextRegister", [](FunctionContext* context) -> void {
7474
std::string function_call = replace(context->GetFunctionKey(), " ", "::");
75+
std::vector<std::string> arguments;
76+
for (int i = 0; i < context->GetArgumentsCount(); i++)
77+
arguments.push_back(context->GetArgumentAsString(i));
78+
function_call += "(" + implode(arguments, ", ") + ")";
79+
7580
context->temporaryData.push_back(g_callStack.RegisterPluginCallstack(FetchPluginName(context->GetPluginContext()), function_call));
7681
g_ResourceMonitor.StartTime("core", replace(context->GetFunctionKey(), " ", "::"));
7782
});

src/scripting/engine/events.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <scripting/core.h>
2+
#include <tools/crashreporter/crashreporter.h>
23
#include <memory/gamedata/gamedata.h>
34
#include <sdk/game.h>
5+
#include <utils/utils.h>
46

57
extern std::map<std::string, std::string> gameEventsRegister;
68
EValue SerializeData(std::any data, EContext* state);
@@ -178,7 +180,7 @@ LoadScriptingComponent(events, [](PluginObject plugin, EContext* ctx) -> void {
178180

179181
IGameEventListener2* playerListener = g_GameData.FetchSignature<GetLegacyGameEventListener>("LegacyGameEventListener")(slot);
180182
if (!g_gameEventManager->FindListener(playerListener, data->GetData<IGameEvent*>("event_data")->GetName())) {
181-
/* TODO: Crash Reporter - Report crash prevention */
183+
ReportPreventionIncident("Fire Event", string_format("Tried to fire event '%s' but the client isn't listening to this event.", data->GetData<IGameEvent*>("event_data")->GetName()));
182184
return;
183185
}
184186
playerListener->FireGameEvent(data->GetData<IGameEvent*>("event_data"));

src/scripting/sdk/schema.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sdk/components/CPlayerPawnComponent.h>
1212
#include <sdk/components/EmitSound_t.h>
1313
#include <sdk/components/CSingleRecipientFilter.h>
14+
#include <tools/crashreporter/crashreporter.h>
1415
#include <utils/common.h>
1516
#include <utils/utils.h>
1617

@@ -311,7 +312,7 @@ void SchemaCallback(PluginObject plugin, EContext* ctx) {
311312

312313
void* instance = data->GetData<void*>("class_ptr");
313314
if (!instance) {
314-
/* TODO: Crash Reporter - Report crash prevention */
315+
ReportPreventionIncident("Schema / SDK", string_format("Tried to get member '%s::%s' but the entity is invalid.", className.c_str(), fieldName.c_str()));
315316
return context->StopExecution();
316317
}
317318
context->SetReturn(AccessSDK(data->GetData<void*>("class_ptr"), className, fieldName, path, context->GetPluginContext()));
@@ -320,6 +321,12 @@ void SchemaCallback(PluginObject plugin, EContext* ctx) {
320321
std::string className = data->GetData<std::string>("class_name");
321322
std::string fieldName = explode(context->GetFunctionKey(), " ").back();
322323

324+
void* instance = data->GetData<void*>("class_ptr");
325+
if (!instance) {
326+
ReportPreventionIncident("Schema / SDK", string_format("Tried to set member '%s::%s' but the entity is invalid.", className.c_str(), fieldName.c_str()));
327+
return context->StopExecution();
328+
}
329+
323330
UpdateSDK(data->GetData<void*>("class_ptr"), className, fieldName, context->GetArgument<EValue>(0), context->GetPluginContext());
324331
context->StopExecution();
325332
});
@@ -333,7 +340,7 @@ void SchemaCallback(PluginObject plugin, EContext* ctx) {
333340
if (classFuncs.find(path) != classFuncs.end()) {
334341
void* instance = data->GetData<void*>("class_ptr");
335342
if (!instance) {
336-
/* TODO: Crash Reporter - Report crash prevention */
343+
ReportPreventionIncident("Schema / SDK", string_format("Tried to call function '%s::%s' but the entity is invalid.", className.c_str(), function_name.c_str()));
337344
return context->StopExecution();
338345
}
339346
return;

src/tools/crashreporter/crashreporter.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ bool BeginCrashListener() {
5353
}
5454
}
5555

56+
if (!Files::ExistsPath("addons/swiftly/dumps/prevention"))
57+
{
58+
if (!Files::CreateDirectory("addons/swiftly/dumps/prevention"))
59+
{
60+
PLUGIN_PRINTF("Crash Listener", "Couldn't create dumps prevention folder.\n");
61+
return false;
62+
}
63+
}
64+
5665
startup_cmd = CommandLine()->GetCmdLine();
5766
std::vector<std::string> exp = explode(startup_cmd, " ");
5867
std::vector<std::string> exp2;
@@ -181,6 +190,15 @@ bool BeginCrashListener() {
181190
}
182191
}
183192

193+
if (!Files::ExistsPath("addons/swiftly/dumps/prevention"))
194+
{
195+
if (!Files::CreateDirectory("addons/swiftly/dumps/prevention"))
196+
{
197+
PLUGIN_PRINTF("Crash Listener", "Couldn't create dumps prevention folder.\n");
198+
return false;
199+
}
200+
}
201+
184202
startup_cmd = CommandLine()->GetCmdLine();
185203
std::vector<std::string> exp = explode(startup_cmd, " ");
186204
std::vector<std::string> exp2;
@@ -253,4 +271,28 @@ void WriteCrashDump(std::vector<std::string> functionStack)
253271

254272
Files::Append(file_path, string_format("================================\nCommand: %s\nMap: %s\nVersion: %s (%s)\n================================\n\n%s\n\n%s", startup_cmd.c_str(), engine->GetServerGlobals() ? engine->GetServerGlobals()->mapname.ToCStr() : "None", g_Plugin.GetVersion(), GITHUB_SHA, implode(functionStack, "\n").c_str(), WritePluginsCallStack().c_str()), false);
255273
PLUGIN_PRINTF("Crash Reporter", "A dump log file has been created at: %s\n", file_path.c_str());
274+
exit(1);
275+
}
276+
277+
void ReportPreventionIncident(std::string category, std::string incident_str)
278+
{
279+
PLUGIN_PRINTF("Crash Prevention", "A crash has been prevented by Swiftly Core and the details will be listed below:\n");
280+
281+
TextTable backtraceTable('-', '|', '+');
282+
283+
backtraceTable.add(" Category ");
284+
backtraceTable.add(" Message ");
285+
backtraceTable.endOfRow();
286+
287+
backtraceTable.add(string_format(" %s ", category.c_str()));
288+
backtraceTable.add(string_format(" %s ", incident_str.c_str()));
289+
backtraceTable.endOfRow();
290+
291+
PrintTextTable("Crash Prevention", backtraceTable);
292+
293+
std::string file_path = string_format("addons/swiftly/dumps/prevention/incident.%s.log", get_uuid().c_str());
294+
if (Files::ExistsPath(file_path)) Files::Delete(file_path);
295+
296+
Files::Append(file_path, string_format("================================\nCategory: %s\nDetails: %s\n\n%s", category.c_str(), incident_str.c_str(), WritePluginsCallStack().c_str()), false);
297+
PLUGIN_PRINTF("Crash Prevention", "A log file has been created at: %s\n", file_path.c_str());
256298
}
+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#ifndef _tools_crashreporter_h
22
#define _tools_crashreporter_h
33

4+
#include <string>
5+
46
bool BeginCrashListener();
57
void EndCrashListener();
68

9+
void ReportPreventionIncident(std::string category, std::string incident_str);
10+
711
#endif

0 commit comments

Comments
 (0)