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

Override function values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 05-25-2017 , 13:58   Override function values
Reply With Quote #1

I hooked CreateSphereObject function:

PHP Code:
SH_DECL_HOOK6(IPhysicsEnvironmentCreateSphereObjectSH_NOATTRIB0IPhysicsObject *, float int , const Vector &, const QAngle &, objectparams_t *, bool  ); 
PHP Code:
SH_ADD_HOOK_MEMFUNC(IPhysicsEnvironmentCreateSphereObjectg_pPhysicsEnvironment, &g_interface, &Test::CreateSphereObjectfalse); 
Here is my problem:
PHP Code:
IPhysicsObject *Test::CreateSphereObjectfloat radiusint materialIndex, const Vector &position, const QAngle &anglesobjectparams_t *pParamsbool isStatic ) {
    
//I need to override the values: radius, material Index, position... and pass it further, hos can I do that?

I tried RETURN_META_VALUE_MNEWPARAMS and RETURN_META_NEWPARAMS, neither way it works (compile time errors):
PHP Code:
    RETURN_META_NEWPARAMS(MRES_IGNORED, &IPhysicsEnvironment::CreateSphereObject, (radiusmaterialIndexpositionanglespParamsisStatic));
    
RETURN_META_VALUE_MNEWPARAMS(MRES_IGNOREDNULLCreateSphereObject, (radiusmaterialIndexpositionanglespParamsisStatic)); 
kadet.89 is offline
Send a message via Skype™ to kadet.89
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-25-2017 , 14:19   Re: Override function values
Reply With Quote #2

https://wiki.alliedmods.net/SourceHo...ing_Parameters

RETURN_META_VALUE_NEWPARAMS is what you want, RETURN_META_VALUE_MNEWPARAMS is for manual hooks, RETURN_META_NEWPARAMS and RETURN_META_MNEWPARAMS are for void functions.
__________________
asherkin is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 05-25-2017 , 14:31   Re: Override function values
Reply With Quote #3

Thanks!
One more question, should it look like this:
PHP Code:
RETURN_META_VALUE_NEWPARAMS(MRES_IGNOREDNULLCreateSphereObject, (radiusmaterialIndexpositionanglespParamsisStatic)); 
What is "value" i.e. NULL in this case and how can I access the IPhysicsObject * pointer?
kadet.89 is offline
Send a message via Skype™ to kadet.89
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-25-2017 , 14:45   Re: Override function values
Reply With Quote #4

Quote:
Originally Posted by kadet.89 View Post
One more question, should it look like this:
PHP Code:
RETURN_META_VALUE_NEWPARAMS(MRES_IGNOREDNULLCreateSphereObject, (radiusmaterialIndexpositionanglespParamsisStatic)); 
No, CreateSphereObject needs to be fully qualified, see the sample linked.

PHP Code:
RETURN_META_VALUE_NEWPARAMS(MRES_IGNOREDNULL, &IPhysicsEnvironment::CreateSphereObject, (radiusmaterialIndexpositionanglespParamsisStatic)); 
Quote:
Originally Posted by kadet.89 View Post
What is "value" i.e. NULL in this case and how can I access the IPhysicsObject * pointer?
What is going to be returned, which is ignored, because you're using MRES_IGNORED.

This is all on the page. https://wiki.alliedmods.net/SourceHo...Hook_Functions

You need to use a post hook to get the returned IPhysicsObject *, alongside the pre hook to modify the parameters.

See META_RESULT_ORIG_RET(type), META_RESULT_OVERRIDE_RET(type), and META_RESULT_STATUS in sourcehook.h.
__________________
asherkin is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 05-25-2017 , 15:14   Re: Override function values
Reply With Quote #5

Thanks, it compiles, though I can't test it, my IPhysicsEnvironment isn't the one, the engine uses.
I get it from iphysics:
PHP Code:
    GET_V_IFACE_CURRENT(GetPhysicsFactoryiphysicsIPhysics,  VPHYSICS_INTERFACE_VERSION);
    
IPhysicsEnvironment *g_pPhysicsEnvironment iphysics->GetActiveEnvironmentByIndex(0); 
Is it possible to get the internal IPhysicsEnvironment *physenv ?

Last edited by kadet.89; 05-25-2017 at 15:21.
kadet.89 is offline
Send a message via Skype™ to kadet.89
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-25-2017 , 15:58   Re: Override function values
Reply With Quote #6

Look at my VPhysics extension, you can also use DVP hooks to hook all instances of a class.
__________________
asherkin is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 05-27-2017 , 07:42   Re: Override function values
Reply With Quote #7

asherkin, I'm going to use SH_ADD_DVPHOOK. According to the documentation it requries vtable offset
PHP Code:
SH_ADD_DVPHOOK(Interface, Function, VirtualTableHandlerPost
In my case it's 10:
Code:
// Auto reconstructed from vtable block @ 0x0014B220
// from "vphysics_srv.so", by ida_vtables.idc
0	CPhysicsEnvironment::~CPhysicsEnvironment()
1	CPhysicsEnvironment::~CPhysicsEnvironment()
2	CPhysicsEnvironment::SetDebugOverlay(void * (*)(char  const*,int *))
3	CPhysicsEnvironment::GetDebugOverlay(void)
4	CPhysicsEnvironment::SetGravity(Vector  const&)
5	CPhysicsEnvironment::GetGravity(Vector *)const
6	CPhysicsEnvironment::SetAirDensity(float)
7	CPhysicsEnvironment::GetAirDensity(void)const
8	CPhysicsEnvironment::CreatePolyObject(CPhysCollide  const*,int,Vector  const&,QAngle  const&,objectparams_t *)
9	CPhysicsEnvironment::CreatePolyObjectStatic(CPhysCollide  const*,int,Vector  const&,QAngle  const&,objectparams_t *)
10	CPhysicsEnvironment::CreateSphereObject(float,int,Vector  const&,QAngle  const&,objectparams_t *,bool)
The question is, if I have the exectly same abstruct interface, is there a way to tell the DVPHOOK to calculate the offset from this interface in compile time? To avoid using gamedata configs

Last edited by kadet.89; 05-27-2017 at 07:45.
kadet.89 is offline
Send a message via Skype™ to kadet.89
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-27-2017 , 07:50   Re: Override function values
Reply With Quote #8

You're still not reading the wiki - it doesn't take a vtable index, it takes a pointer to the vtable.

https://wiki.alliedmods.net/SourceHo...Simple_Hooks_2

That said, you probably want SH_ADD_VPHOOK instead (which just takes any instance of the class, and you have one of those already).
__________________

Last edited by asherkin; 05-27-2017 at 07:50.
asherkin 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 09:57.


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