Skip to content

Commit

Permalink
Enhanced CCSPlayerItem::GetItemInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Feb 12, 2020
1 parent 3f6d9db commit 593d1e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions regamedll/dlls/API/CSPlayerItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ EXT_FUNC void CCSPlayerItem::SetItemInfo(ItemInfo *pInfo)
{
Q_memcpy(&m_ItemInfo, pInfo, sizeof(m_ItemInfo));
}

EXT_FUNC int CCSPlayerItem::GetItemInfo(ItemInfo *pInfo)
{
Q_memcpy(pInfo, &m_ItemInfo, sizeof(*pInfo));
return 1;
}
13 changes: 12 additions & 1 deletion regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4783,7 +4783,12 @@ int EXT_FUNC GetWeaponData(edict_t *pEdict, struct weapon_data_s *info)
// Get The ID
ItemInfo II;
Q_memset(&II, 0, sizeof(II));

#ifdef REGAMEDLL_API
pPlayerItem->CSPlayerItem()->GetItemInfo(&II);
#else
weapon->GetItemInfo(&II);
#endif

if (II.iId >= 0 && II.iId < MAX_WEAPONS)
{
Expand Down Expand Up @@ -4916,7 +4921,13 @@ void EXT_FUNC UpdateClientData(const edict_t *ent, int sendweapons, struct clien
Q_memset(&II, 0, sizeof(II));

CBasePlayerWeapon *weapon = (CBasePlayerWeapon *)pPlayer->m_pActiveItem->GetWeaponPtr();
if (weapon && weapon->UseDecrement() && weapon->GetItemInfo(&II))
if (weapon && weapon->UseDecrement() &&
#ifdef REGAMEDLL_API
weapon->CSPlayerItem()->GetItemInfo(&II)
#else
weapon->GetItemInfo(&II)
#endif
)
{
cd->m_iId = II.iId;

Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,11 @@ void CBasePlayer::PackDeadPlayerItems()
ItemInfo info;
if (pPlayerItem->iItemSlot() < KNIFE_SLOT && !bShieldDropped)
{
#ifdef REGAMEDLL_API
if (pPlayerItem->CSPlayerItem()->GetItemInfo(&info))
#else
if (pPlayerItem->GetItemInfo(&info))
#endif
{
if (info.iWeight > nBestWeight)
{
Expand Down
1 change: 1 addition & 0 deletions regamedll/public/regamedll/API/CSPlayerItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CCSPlayerItem: public CCSAnimating
}

virtual void SetItemInfo(ItemInfo *pInfo);
virtual int GetItemInfo(ItemInfo *pInfo);

CBasePlayerItem *BasePlayerItem() const;

Expand Down

7 comments on commit 593d1e1

@StevenKal
Copy link
Contributor

@StevenKal StevenKal commented on 593d1e1 Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never forget to "push" the API version (as it has been sometimes forgotten, especially in ReHLDS)!
Please update it to v5.14.

@fl0werD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never forget to "push" the API version (as it has been sometimes forgotten, especially in ReHLDS)!
Please update it to v5.14.

Why? Back-compatibility isn't broken.

@StevenKal
Copy link
Contributor

@StevenKal StevenKal commented on 593d1e1 Feb 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1: To be able to know if the "ReGameDLL_CS" binary on a server can handle this function (via version check), so you can know, on a plugin, if such function (in this case, the "CCSPlayerItem::GetItemInfo"), can be used or not, and adapt your code regarding this (including error message & plugin pause).
Note: But on such case, I'll personnaly directly use the member value (CCSPlayerItem's "m_ItemInfo") for more reliability with older versions, since it was added much before and can be supported on older versions of ReGameDLL_CS.
#2: API version is usually updated when new hook chain(s) are added, those last are added "at the suite of the list" and do not break backward compatibility too, so why not do it there too?
Note: Plugins using latest hook chains, have to check if the current ReGameDLL_CS can support a specific hook chain, that's all (same as above).
#3: There is nothing "wrong" at increasing the API version everytime the external API (usable by Metamod's modules) is updated.
#4: I'm currently finalizing "my own version" of the ReAPI module for AMX Mod, builded myself from scratch and completely different than the AMX Mod X's one by original Re* projects authors, and each function includes a version check related to "the one it needs" in order to properly know if this can be used or not (whatever for functions or hook chains). Maybe you do not care, or maybe, again, I'll receive some "get the f*** out", blablabla! But I've just wanted to add a "one more real, final & useful reason".

@StevenKal
Copy link
Contributor

@StevenKal StevenKal commented on 593d1e1 Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flowerd wrote:
Простите, не кричите на меня. Потом прочитаю, что Вы написали.

Je ne vous ai pas crié dessus ! Cependant, je devrai le faire pour le fait d'écrire en Russe ! Ce qui me casse les couilles, encore & encore...

@fl0werD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alexandr Sabitov, [2/14/20, 3:48 AM]
нарушается совместимость или нет?

s1lent, [2/14/20, 1:31 PM]
nope

@StevenKal
Copy link
Contributor

@StevenKal StevenKal commented on 593d1e1 Feb 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flowerd:

Before 4AM:
Простите, не кричите на меня. Потом прочитаю, что Вы написали.

StevenKal: "Je ne vous ai pas crié dessus ! Cependant, je devrai le faire pour le fait d'écrire en Russe ! Ce qui me casse les couilles, encore & encore..."

And later:
Alexandr Sabitov, [2/14/20, 3:48 AM]
нарушается совместимость или нет?
s1lent, [2/14/20, 1:31 PM]
nope

Where those messages did they go?! I guess repository owner can "s1lently" remove them! Or, you removed your message(s) letting mine in a "stupid monologue"? Hum...
But well, I've seen s1lent has just updated the API a few minuts ago, so problem solved. Good.

@fl0werD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted my msgs.

Please sign in to comment.