Raised This Month: $12 Target: $400
 3% 

[TF2] Getting CEconItemView


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 02-15-2016 , 21:58   [TF2] Getting CEconItemView
Reply With Quote #1

CTFPlayer::ReapplyItemUpgrades takes in a CTFPlayer and a CEconItemView as parameters.

From an item entity index returned by TF2Items_GiveNamedItem, is there a way to get the CEconItemView of that item to pass into that function?

Some people told me that's only accessible from an extension only, but I noticed here that psychonic managed to be able to send in a CEconItemView to CTFDroppedWeapon::Create.

CTFPlayer::ReapplyItemUpgrades is called in MvM to apply upgrades purchased from the upgrades station to the players' weapons. I want to call this after an item from TF2Items is generated since GiveNamedItem doesn't call CTFPlayer::ReapplyItemUpgrades (and therefore, when a player respawns, the upgrades don't *always* appear on the item given by TF2Items).

So something like this would occur in the plugin:

PHP Code:
int ItemEntity TF2Items_GiveNamedItem(clienthItem);
CloseHandle(hItem);
SDKCall(ReapplyItemUpgradesclient, ????); 
The ???? is the CEconItemView. What do I put in there? Also, how do I prep the sdkcall for this function? (I have the gamedata already.) Any insight or advice would be helpful. Thanks!
Potato Uno is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-16-2016 , 08:19   Re: [TF2] Getting CEconItemView
Reply With Quote #2

To get a pointer to the existing CEIV on a weapon, you can use the same method used in the plugin you linked.

PHP Code:
    // Offset of the CEconItemView class inlined on the weapon.
    // Manually using FindSendPropInfo as 1) it's a sendtable, not a value,
    // and 2) we just want a pointer to it, not the value at that address.
    
int itemOffset FindSendPropInfo("CTFWeaponBase""m_Item");
    if (
itemOffset == -1)
        
ThrowError("Failed to find m_Item on CTFWeaponBase");

    
///////////////

    
Address ptrCEIV GetEntityAddress(fromWeapon) + view_as<Address>(itemOffset); 
psychonic is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 02-16-2016 , 10:46   Re: [TF2] Getting CEconItemView
Reply With Quote #3

Does that work if the item is a wearable like demoknight shields or do I need to find a different item offset? (If so, what do I find?)

Thanks for the help!

Spoiler
Potato Uno is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-16-2016 , 11:19   Re: [TF2] Getting CEconItemView
Reply With Quote #4

Quote:
Originally Posted by Potato Uno View Post
Does that work if the item is a wearable like demoknight shields or do I need to find a different item offset? (If so, what do I find?)
I believe so, but you'll likely need to change the net class being used for the lookup since the shield isn't a base TF weapon and has a different inheritance tree.

Replace "CTFWeaponBase" with whatever you get from GetEntityNetClass should work.

Edit: As a safety, you should probably also check that the returned offset isn't -1 (not found).

Last edited by psychonic; 02-16-2016 at 11:20.
psychonic is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 02-16-2016 , 11:57   Re: [TF2] Getting CEconItemView
Reply With Quote #5

I got that to work, thanks! I have one last question and it's not related to CEconItemView.

Gamedata:

Spoiler


The below code triggers SetFailState:

PHP Code:
    // CTFPlayer::ReapplyItemUpgrades(CTFPlayer *this, CEconItemView *int)
    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(hConfSDKConf_Virtual"CTFPlayer::ReapplyItemUpgrades");
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
    
FixUpgrades EndPrepSDKCall();
    if (
FixUpgrades == INVALID_HANDLE)
        
SetFailState("[FP] Call was aborted: Could not initialize call to CTFPlayer::ReapplyItemUpgrades. You need new gamedata."); 
The below code works perfectly fine:

PHP Code:
    // CTFPlayer::ReapplyItemUpgrades(CTFPlayer *this, CEconItemView *int)
    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetSignature(SDKLibrary_Server"\x55\x8B\xEC\x83\xEC\x0C\x57\x8B\xF9\x8B\x07\x8B\x80\xEC\x06\x00\x00"17);
    
PrepSDKCall_AddParameter(SDKType_PlainOldDataSDKPass_Plain);
    
FixUpgrades EndPrepSDKCall();
    if (
FixUpgrades == INVALID_HANDLE)
        
SetFailState("[FP] Call was aborted: Could not initialize call to CTFPlayer::ReapplyItemUpgrades. You need new gamedata."); 
Why does hard-coding the gamedata into the plugin work but reading from a config file fails? Either the signature is busted (I don't think so) or my keyvalue is somehow malformed.

Thanks!

Last edited by Potato Uno; 02-16-2016 at 11:58.
Potato Uno is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 02-16-2016 , 12:11   Re: [TF2] Getting CEconItemView
Reply With Quote #6

Shouldn't it be SDKConf_Signature instead of SDKConf_Virtual?
__________________
...
Oshizu is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-16-2016 , 12:20   Re: [TF2] Getting CEconItemView
Reply With Quote #7

SDKConf_Virtual makes it expect an offset into a vtable rather than a signature
Miu is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 02-16-2016 , 12:29   Re: [TF2] Getting CEconItemView
Reply With Quote #8

Fixed it.

It was a combination of me using the wrong function name in PrepSDKCall_SetFromConf, using SDKConf_Virtual instead of SDKConf_Signature and editing the sp file but not recompiling and reloading it onto the server. At one point I was checking if I even screwed up the encoding of the file (UTF-8 w/o BOM).

Please award me the dumbass and moron of 2016 award.

Thanks for all the help!

Last edited by Potato Uno; 02-16-2016 at 12:32.
Potato Uno is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 02-16-2016 , 12:48   Re: [TF2] Getting CEconItemView
Reply With Quote #9

[QUOTE=Potato Uno;2393450]Please award me the dumbass and moron of 2016 award./QUOTE]

I don't think you deserve that.
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 02-16-2016 , 17:14   Re: [TF2] Getting CEconItemView
Reply With Quote #10

DemoMan shields are their own class, but as I recall it's derived from CTFWearable.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:29.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode