Skip to content

Commit aaf9a16

Browse files
authored
Update/v1.6.1 (#91)
2 parents bc2a6c2 + 129e399 commit aaf9a16

File tree

14 files changed

+185
-131
lines changed

14 files changed

+185
-131
lines changed

.github/workflows/builder.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
id: version
2828
with:
2929
release_branch: master
30-
increment: minor
30+
increment: patch
3131
use_api: true
3232

3333
extensions_build:

CHANGELOG.md

+27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

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

5+
## v1.6.1 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.1)
6+
7+
### VGUI
8+
9+
- [+] Fix Memory Leak
10+
- [+] Fix Entity Spawn
11+
12+
### Exports
13+
14+
- [+] Fix Return Value
15+
16+
### Weapon
17+
18+
- [+] Fix CBasePlayerWeapon
19+
- [+] Fix CCSWeaponBase
20+
- [+] Fix CBasePlayerWeaponVData
21+
- [+] Fix CCSWeaponBaseVData
22+
23+
### Core Commands
24+
25+
- [+] sw status
26+
- [+] sw list
27+
28+
### Player
29+
30+
- [+] Fix Buttons
31+
532
## v1.6.0 - [Release](https://github.com/swiftly-solution/swiftly/releases/tag/v1.6.0)
633

734
### Memory

src/core/entrypoint.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,11 @@ void SwiftlyS2::AllPluginsLoaded()
274274

275275
std::string currentMap = "None";
276276

277+
void EraseScheduledCEntKeyVals();
278+
277279
void SwiftlyS2::OnLevelInit(char const* pMapName, char const* pMapEntities, char const* pOldLevel, char const* pLandmarkName, bool loadGame, bool background)
278280
{
281+
EraseScheduledCEntKeyVals();
279282
currentMap = pMapName;
280283
g_pluginManager.ExecuteEvent("core", "OnMapLoad", { currentMap }, nullptr);
281284
}

src/engine/vgui/screentext.cpp

+29-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include <server/configuration/configuration.h>
55
#include <sdk/schema.h>
66
#include <entities/system.h>
7-
#include <public/entity2/entitykeyvalues.h>
7+
8+
std::vector<CEntityKeyValues*> scheduleForDelete;
89

910
ScreenText::~ScreenText()
1011
{
@@ -28,6 +29,8 @@ void ScreenText::Create(Color color, std::string font, int size, bool drawBackgr
2829

2930
CEntityKeyValues* pMenuKV = new CEntityKeyValues();
3031

32+
scheduleForDelete.push_back(pMenuKV);
33+
3134
pMenuKV->SetBool("enabled", true);
3235
pMenuKV->SetFloat("world_units_per_pixel", (0.25 / 1050) * size);
3336
pMenuKV->SetInt("justify_horizontal", 0);
@@ -38,13 +41,14 @@ void ScreenText::Create(Color color, std::string font, int size, bool drawBackgr
3841
pMenuKV->SetString("font_name", font.c_str());
3942
pMenuKV->SetColor("color", color);
4043

41-
if(drawBackground) {
44+
if (drawBackground) {
4245
pMenuKV->SetBool("draw_background", true);
4346

44-
if(isMenu) {
47+
if (isMenu) {
4548
pMenuKV->SetFloat("background_border_width", 0.2);
4649
pMenuKV->SetFloat("background_border_height", 0.15);
47-
} else {
50+
}
51+
else {
4852
pMenuKV->SetFloat("background_border_width", g_Config.FetchValue<float>("core.vgui.textBackground.paddingX"));
4953
pMenuKV->SetFloat("background_border_height", g_Config.FetchValue<float>("core.vgui.textBackground.paddingY"));
5054
}
@@ -68,7 +72,7 @@ void ScreenText::SetupViewForPlayer(Player* player)
6872
if (!pViewModel) return;
6973

7074
g_entSystem.AcceptInput(pScreenEntity, "SetParent", pViewModel, nullptr, "!activator", 0);
71-
schema::SetProp<CHandle<CEntityInstance>>(pScreenEntity, "CBaseEntity", "m_hOwnerEntity", ((CEntityInstance*)pViewModel)->GetRefEHandle());
75+
schema::SetProp<CHandle<CEntityInstance>>(pScreenEntity, "CBaseEntity", "m_hOwnerEntity", ((CEntityInstance*)(pViewModel))->GetRefEHandle());
7276
}
7377

7478
void ScreenText::SetText(std::string text)
@@ -88,31 +92,31 @@ void ScreenText::SetPosition(float posX, float posY)
8892

8993
if (!m_player) return;
9094
if (m_player->IsFakeClient()) return;
91-
if(!pScreenEntity) return;
95+
if (!pScreenEntity) return;
9296

9397
auto pawn = m_player->GetPlayerPawn();
94-
if(!pawn) return;
98+
if (!pawn) return;
9599

96-
if(schema::GetProp<uint32_t>(pawn, "CBaseEntity", "m_lifeState") == 2) {
100+
if (schema::GetProp<uint32_t>(pawn, "CBaseEntity", "m_lifeState") == 2) {
97101
auto controller = m_player->GetController();
98-
if(!controller) return;
99-
if(schema::GetProp<bool>(controller, "CCSPlayerController", "m_bControllingBot")) return;
102+
if (!controller) return;
103+
if (schema::GetProp<bool>(controller, "CCSPlayerController", "m_bControllingBot")) return;
100104

101105
auto observerServices = schema::GetProp<void*>(pawn, "CBasePlayerPawn", "m_pObserverServices");
102-
if(!observerServices) return;
106+
if (!observerServices) return;
103107

104108
CHandle<CEntityInstance> observerTarget = schema::GetProp<CHandle<CEntityInstance>>(observerServices, "CPlayer_ObserverServices", "m_hObserverTarget");
105-
if(!observerTarget) return;
109+
if (!observerTarget) return;
106110

107111
auto observerController = schema::GetProp<CHandle<CEntityInstance>>(observerTarget.Get(), "CCSPlayerPawnBase", "m_hOriginalController");
108-
if(!observerController) return;
112+
if (!observerController) return;
109113

110114
CHandle<CEntityInstance> pawnHandle = schema::GetProp<CHandle<CEntityInstance>>(observerController, "CCSPlayerController", "m_hPlayerPawn");
111-
if(!pawnHandle) return;
115+
if (!pawnHandle) return;
112116
pawn = (void*)(pawnHandle.Get());
113117
}
114118

115-
if(!pawn) return;
119+
if (!pawn) return;
116120

117121
QAngle eyeAngles = schema::GetProp<QAngle>(pawn, "CCSPlayerPawnBase", "m_angEyeAngles");
118122
Vector fwd, right, up;
@@ -126,13 +130,13 @@ void ScreenText::SetPosition(float posX, float posY)
126130
QAngle ang(0, eyeAngles.y + 270, 90 - eyeAngles.x);
127131

128132
void* bodyComponent = schema::GetProp<void*>(pawn, "CBaseEntity", "m_CBodyComponent");
129-
if(bodyComponent) return;
133+
if (!bodyComponent) return;
130134

131135
void* sceneNode = schema::GetProp<void*>(bodyComponent, "CBodyComponent", "m_pSceneNode");
132-
if(!sceneNode) return;
136+
if (!sceneNode) return;
133137

134138
void* camServices = schema::GetProp<void*>(pawn, "CBasePlayerPawn", "m_pCameraServices");
135-
if(!camServices) return;
139+
if (!camServices) return;
136140

137141
float oldZ = schema::GetProp<float>(camServices, "CPlayer_CameraServices", "m_flOldPlayerViewOffsetZ");
138142

@@ -190,4 +194,11 @@ bool ScreenText::IsRenderingTo(CHandle<CEntityInstance> renderingTo)
190194
void ScreenText::SetRenderingTo(CEntityInstance* ent)
191195
{
192196
pRenderingTo.Set(ent);
197+
}
198+
199+
void EraseScheduledCEntKeyVals() {
200+
for (auto e : scheduleForDelete) {
201+
delete e;
202+
}
203+
scheduleForDelete.clear();
193204
}

src/engine/vgui/screentext.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string>
55
#include <server/player/player.h>
66
#include "ehandle.h"
7+
#include <public/entity2/entitykeyvalues.h>
78

89
class ScreenText
910
{

src/entities/listener.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <public/entity2/entitykeyvalues.h>
88

99
CEntityListener g_entityListener;
10-
std::map<void*, void*> entKeyVal;
1110

1211
void CEntityListener::OnEntitySpawned(CEntityInstance* pEntity)
1312
{
@@ -42,9 +41,4 @@ void CEntityListener::OnEntityDeleted(CEntityInstance* pEntity)
4241
{
4342
ClassData* entity = new ClassData({ { "should_mark_freeable", true }, { "class_name", std::string("CEntityInstance") }, { "class_ptr", (void*)pEntity } }, "SDKClass", nullptr);
4443
g_pluginManager.ExecuteEvent("core", "OnEntityDeleted", { entity }, {});
45-
46-
if (entKeyVal.find(pEntity) != entKeyVal.end()) {
47-
delete (CEntityKeyValues*)entKeyVal[pEntity];
48-
entKeyVal.erase(pEntity);
49-
}
5044
}

src/entities/system.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ typedef void (*UTIL_Remove)(void*);
88
typedef void* (*UTIL_CreateEntityByName)(const char*, int);
99
typedef void (*CEntityInstance_AcceptInput)(void*, const char*, void*, void*, variant_t*, int);
1010

11-
extern std::map<void*, void*> entKeyVal;
1211
void* gameRules = nullptr;
1312

1413
CGameEntitySystem* GameEntitySystem()
@@ -49,9 +48,6 @@ void EntitySystem::StartupServer(const GameSessionConfiguration_t& config, ISour
4948
void EntitySystem::Spawn(void* entity, void* keyvalues)
5049
{
5150
g_GameData.FetchSignature<CBaseEntity_DispatchSpawn>("CBaseEntity_DispatchSpawn")(entity, keyvalues);
52-
53-
if (entKeyVal.find(entity) != entKeyVal.end()) delete (CEntityKeyValues*)entKeyVal[entity];
54-
entKeyVal[entity] = keyvalues;
5551
}
5652

5753
void EntitySystem::Despawn(void* entity)

src/scripting/engine/events.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <sdk/game.h>
44

55
extern std::map<std::string, std::string> gameEventsRegister;
6+
EValue SerializeData(std::any data, EContext* state);
67

78
typedef IGameEventListener2* (*GetLegacyGameEventListener)(CPlayerSlot slot);
89

@@ -59,8 +60,7 @@ LoadScriptingComponent(events, [](PluginObject plugin, EContext* ctx) -> void {
5960
auto event_name = context->GetArgumentOr<std::string>(0, "");
6061
auto event_data = context->GetArgumentOr<std::string>(1, "[]");
6162

62-
auto evObject = MAKE_CLASS_INSTANCE("Event", { { "plugin_name", FetchPluginName(context->GetPluginContext()) } }).cast<ClassData*>();
63-
63+
ClassData* evObject = new ClassData({ { "plugin_name", FetchPluginName(context->GetPluginContext()) }, { "should_mark_freeable", true } }, "Event", nullptr);
6464
std::vector<std::any> returnValues;
6565

6666
returnValues.push_back((int)g_pluginManager.ExecuteEventJSON(FetchPluginName(context->GetPluginContext()), event_name, event_data, evObject));
@@ -183,11 +183,14 @@ LoadScriptingComponent(events, [](PluginObject plugin, EContext* ctx) -> void {
183183
ADD_CLASS_FUNCTION("Event", "SetReturn", [](FunctionContext* context, ClassData* data) -> void {
184184
if (context->GetArgumentsCount() < 1) return;
185185

186-
data->SetData("event_return", context->GetArgument<std::any>(0));
186+
std::any val = context->GetArgument<std::any>(0);
187+
data->SetData("event_return", val);
187188
});
188189

189190
ADD_CLASS_FUNCTION("Event", "GetReturn", [](FunctionContext* context, ClassData* data) -> void {
190-
if (data->HasData("event_return")) context->SetReturn(data->GetData<std::any>("event_return"));
191+
if (data->HasData("event_return")) {
192+
context->SetReturn(data->GetAnyData("event_return"));
193+
}
191194
});
192195

193196
ADD_CLASS_FUNCTION("Event", "SetNoBroadcast", [](FunctionContext* context, ClassData* data) -> void {

0 commit comments

Comments
 (0)