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

Solved Optional VPhysics extension


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-22-2020 , 14:54   Optional VPhysics extension
Reply With Quote #1

I don't know what I'm doing. Nothing works. I want to make the VPhysics extension optional since the plugin is only using "Phys_ApplyTorqueCenter" native.

Trying to make the plugin compile with or without the vphysics.inc (so it can be downloaded from the forum without extra requirements) and have the plugin run with or without the VPhysics extension being installed.

Am I blind? I don't see how to detect if the extension is running, something like RegPluginLibrary. Since theres no way to determine if the extension is running I'm blindly calling Phys_ApplyTorqueCenter, which then throws "Native is not bound" error when the extension is not installed.

This makes the plugin compile with or without include and still run with or without the extension, except with the above error when ext missing:

PHP Code:
#undef  REQUIRE_EXTENSIONS

// Putting this in the plugin stops it from being required and plugin not running if the include and extension are missing.
public Extension:__ext_vphysics 
{
    
name "VPhysics",
    
file "vphysics.ext",
    
autoload 1,
    
#if defined REQUIRE_EXTENSIONS
        
required 1,
    
#else
        
required 0,
    
#endif
}

#tryinclude <vphysics>

// Using both defines since version on limetech is older and uses first define, the one on github with new syntax uses second define.
#if !defined _sdktools_phys_included
    #if !defined _vphysics_included
        
native void Phys_ApplyTorqueCenter(int iEntity, const float[3torque);
    
#endif
#endif

#define REQUIRE_EXTENSIONS 
Also have set:
PHP Code:
public APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    
MarkNativeAsOptional("Phys_ApplyTorqueCenter");

Btw asherkin: if you see this, the link to vphysics on https://limetech.io/projects/ points to TF2Items:
Spoiler
__________________

Last edited by Silvers; 01-26-2020 at 16:18.
Silvers is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 01-26-2020 , 15:09   Re: Optional VPhysics extension
Reply With Quote #2

I faced same issue in our 'sound attenuation' plugin. The only official way I know is:

PHP Code:
if (GetExtensionFileStatus("VoiceHook.ext") == 1
but it is not reliable since heavily depends on filename. Easily can break your plugin by next extension update (or admin can decide to rename).
And that's bad sm doesn't expose more functions for such check, at least to retrieve extension's name by index.

There is one walkaround: you can send ServerCommandEx cmd:
Spoiler

to intercept server answer.
So, by parsing that you can surely identify whether extension of your interest is loaded.
Again, until somebody patch sm exts command to hide output.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-31-2020 , 16:50   Re: Optional VPhysics extension
Reply With Quote #3

You can use GetFeatureStatus to check if the native is available.
__________________
asherkin is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-31-2020 , 18:47   Re: Optional VPhysics extension
Reply With Quote #4

Quote:
Originally Posted by asherkin View Post
You can use GetFeatureStatus to check if the native is available.
Urgh, excellent! Thanks, wish I knew this before. Way too many functions I don't know about, and even more new ones with the latest versions of SourceMod. Feel like a page to list them all with a small explanation would be beneficial. I tried searching the SM API for various keywords but didn't think "feature".

Will use for any future work using optional extensions. Thanks again.
__________________
Silvers 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 08:17.


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