AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Optional VPhysics extension (https://forums.alliedmods.net/showthread.php?t=321057)

Silvers 01-22-2020 14:54

Optional VPhysics extension
 
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:

Dragokas 01-26-2020 15:09

Re: Optional VPhysics extension
 
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.

asherkin 01-31-2020 16:50

Re: Optional VPhysics extension
 
You can use GetFeatureStatus to check if the native is available.

Silvers 01-31-2020 18:47

Re: Optional VPhysics extension
 
Quote:

Originally Posted by asherkin (Post 2682325)
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.


All times are GMT -4. The time now is 10:48.

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