Skip to content

Commit ccf7b18

Browse files
committed
feat(scripting/player/weapons): GetSilencerType
1 parent ca9ead2 commit ccf7b18

File tree

12 files changed

+90
-2
lines changed

12 files changed

+90
-2
lines changed

docgen/data/data.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@
14081408
"position": 1,
14091409
"description": "To use the Swiftly Logging system you need the following code in your plugin.",
14101410
"content": {
1411-
"cpp": "```cpp\n#include <swiftly/logger.h>\n\nLogger *logger = nullptr;\n\nvoid OnProgramLoad(const char *pluginName, const char *mainFilePath)\n{\n ...\n logger = new Logger(mainFilePath, pluginName);\n ...\n}\n```"
1411+
"cpp": "```cpp\n#include <swiftly/menus.h>\n\nMenus *menus = nullptr;\n\nvoid OnProgramLoad(const char *pluginName, const char *mainFilePath)\n{\n ...\n menus = new Menus(pluginName);\n ...\n}\n```"
14121412
}
14131413
},
14141414
"register": {
@@ -2635,6 +2635,19 @@
26352635
},
26362636
"additional": {}
26372637
},
2638+
"getsilencertype": {
2639+
"title": "GetSilencerType",
2640+
"template": "function-syntax",
2641+
"language": "both",
2642+
"description": "Returns the silencer type of the weapon.",
2643+
"variable": {
2644+
"cpp": "weapon->GetSilencerType",
2645+
"lua": "weapon:GetSilencerType"
2646+
},
2647+
"return": "WeaponSilencerType",
2648+
"params": {},
2649+
"additional": {}
2650+
},
26382651
"getnextprimaryattacktick": {
26392652
"title": "GetNextPrimaryAttackTick",
26402653
"template": "function-syntax",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# WeaponSilencerType
2+
3+
```cpp
4+
enum WeaponSilencerType : uint32_t
5+
{
6+
NONE = 0x0,
7+
DETACHABLE = 0x1,
8+
INTEGRATED = 0x2,
9+
};
10+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# WeaponSilencerType
2+
3+
```lua
4+
WeaponSilencerType = {
5+
None = 0,
6+
Detachable = 1,
7+
Integrated = 2
8+
}
9+
```

docgen/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const GenerateLuaType = (param) => {
3333
else if (param == "HudDestination") return "HudDestination";
3434
else if (param == "PlayerStat") return "PlayerStat";
3535
else if (param == "WeaponSlot") return "WeaponSlot";
36+
else if (param == "WeaponSilencerType") return "WeaponSilencerType";
3637
else throw `${param} not implemented`;
3738
}
3839

plugin_files/scripting/includes/swiftly/player/weapon.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef void (*Player_Weapon_SetAttackTick)(uint32_t, uint32_t, int32_t);
3939
typedef float (*Player_Weapon_GetAttackTickRatio)(uint32_t, uint32_t);
4040
typedef void (*Player_Weapon_SetAttackTickRatio)(uint32_t, uint32_t, float);
4141

42+
typedef WeaponSilencerType (*Player_Weapon_GetSilencerType)(uint32_t, uint32_t);
43+
4244
class Weapon
4345
{
4446
private:
@@ -308,6 +310,18 @@ class Weapon
308310
NOT_SUPPORTED("scripting_Player_Weapon_SetNextSecondaryAttackTickRatio");
309311
}
310312

313+
WeaponSilencerType GetSilencerType()
314+
{
315+
void *player_WeaponGetSilencerType = FetchFunctionPtr(nullptr, "scripting_Player_Weapon_GetSilencerType");
316+
if (player_WeaponGetSilencerType)
317+
return reinterpret_cast<Player_Weapon_GetSilencerType>(player_WeaponGetSilencerType)(this->m_playerSlot, this->m_weaponID);
318+
else
319+
{
320+
NOT_SUPPORTED("scripting_Player_Weapon_GetSilencerType");
321+
return WeaponSilencerType::NONE;
322+
}
323+
}
324+
311325
uint32_t GetID()
312326
{
313327
return this->m_weaponID;

plugin_files/scripting/includes/swiftly/types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,11 @@ enum WeaponSlot : uint32_t
150150
LAST = 0xC,
151151
};
152152

153+
enum WeaponSilencerType : uint32_t
154+
{
155+
NONE = 0x0,
156+
DETACHABLE = 0x1,
157+
INTEGRATED = 0x2,
158+
};
159+
153160
#endif

src/components/Plugins/inc/Scripting.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ SMM_API void scripting_Player_Weapon_Drop(uint32 playerId, uint32 slot);
204204
SMM_API void scripting_Player_Weapon_SetClipAmmo(uint32 playerId, uint32 slot, int ammo);
205205
SMM_API void scripting_Player_Weapon_SetClip2Ammo(uint32 playerId, uint32 slot, int ammo);
206206
SMM_API void scripting_Player_Weapon_SetReserveAmmo(uint32 playerId, uint32 slot, int ammo);
207-
207+
SMM_API uint32_t scripting_Player_Weapon_GetSilencerType(uint32 playerId, uint32 slot);
208208
SMM_API int32_t scripting_Player_Weapon_GetNextPrimaryAttackTick(uint32 playerId, uint32 slot);
209209
SMM_API int32_t scripting_Player_Weapon_GetNextSecondaryAttackTick(uint32 playerId, uint32 slot);
210210
SMM_API void scripting_Player_Weapon_SetNextPrimaryAttackTick(uint32 playerId, uint32 slot, int32_t tick);

src/components/Plugins/src/language/lua/player.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ void SetupLuaPlayer(luacpp::LuaState *state, Plugin *plugin)
317317
{ return base->slot; })
318318
.DefMember("SetNametag", [](LuaPlayerTwoArgsClass *base, const char *text) -> void
319319
{ scripting_Player_Weapon_SetNametag(base->playerSlot, base->slot, text); })
320+
.DefMember("GetSilencerType", [](LuaPlayerTwoArgsClass *base) -> uint32_t
321+
{ return scripting_Player_Weapon_GetSilencerType(base->playerSlot, base->slot); })
320322
.DefMember("SetClipAmmo", [](LuaPlayerTwoArgsClass *base, int ammo) -> void
321323
{ scripting_Player_Weapon_SetClipAmmo(base->playerSlot, base->slot, ammo); })
322324
.DefMember("SetClip2Ammo", [](LuaPlayerTwoArgsClass *base, int ammo) -> void

src/components/Plugins/src/language/lua/types.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ void SetupLuaTypes(luacpp::LuaState *state, Plugin *plugin)
158158
WeaponSlotTable.SetInteger("First", 0x0);
159159
WeaponSlotTable.SetInteger("Last", 0xC);
160160

161+
auto WeaponSilencerTypeTable = state->CreateTable("WeaponSilencerType");
162+
163+
WeaponSilencerTypeTable.SetInteger("None", 0x0);
164+
WeaponSilencerTypeTable.SetInteger("Detachable", 0x1);
165+
WeaponSilencerTypeTable.SetInteger("Integrated", 0x2);
166+
161167
state->CreateInteger(0, "TEAM_NONE");
162168
state->CreateInteger(1, "TEAM_SPECTATOR");
163169
state->CreateInteger(2, "TEAM_T");

src/components/Plugins/src/scripting/Player.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,23 @@ SMM_API void scripting_Player_Weapon_SetNextSecondaryAttackTickRatio(uint32 play
739739
weapon->m_flNextSecondaryAttackTickRatio = ratio;
740740
}
741741

742+
SMM_API uint32_t scripting_Player_Weapon_GetSilencerType(uint32 playerId, uint32 slot)
743+
{
744+
Player *player = g_playerManager->GetPlayer(playerId);
745+
if (!player)
746+
return CSWeaponSilencerType::WEAPONSILENCER_NONE;
747+
748+
CBasePlayerWeapon *weapon = player->GetPlayerWeaponFromID(slot);
749+
if (!weapon)
750+
return CSWeaponSilencerType::WEAPONSILENCER_NONE;
751+
752+
CCSWeaponBaseVData *vData = weapon->GetWeaponVData();
753+
if (!vData)
754+
return CSWeaponSilencerType::WEAPONSILENCER_NONE;
755+
756+
return vData->m_eSilencerType();
757+
}
758+
742759
SMM_API void scripting_Player_Weapon_SetReserveAmmo(uint32 playerId, uint32 slot, int ammo)
743760
{
744761
Player *player = g_playerManager->GetPlayer(playerId);

0 commit comments

Comments
 (0)