[Plugin] Native Fallback – Ignore missing natives
#1

Introduction
When a script that references missing natives is executed, an error is raised even though the natives may not actually be called in the script and aren't required for its normal functioning. This plugin provides a so-called fallback implementation for any missing native and allows the script to be executed in all cases.

Details
This plugin by default creates 256 (can be adjusted before recompilation) stub fallback functions and registers them in place of missing natives before any code is actually executed (a message is printed to the log for every native). When the fallback implementation is called, run-time error 19 (not found) is raised, stopping the execution of the script (and a message is again printed with the name of the function).

When more than 256 native functions are missing, a generic fallback function is provided instead, but it cannot display the name of the function due to limitations of AMX.

If you want to customize the fallback function, you can hook it via PawnPlus.
Reply
#2

Good work!
Is it like nativechack?
Reply
#3

Quote:
Originally Posted by liguanhua123
View Post
Good work!
Is it like nativechack?
Nativechecker or crashdetect tell you the name of the native function that is missing. This does it as well, but provides you with a fallback implementation so that the script can be still executed.
Reply
#4

Seems to me it would be easier to fix the problem than beat around the bush with this. It gives a false sense that everything is okay now you have given the noobs justification to be retarded. Just my take.

1-Star we don't need idiots trying to fix their scripts in idiot ways. Don't get me wrong you did good making it but it's purpose promotes laziness and stupidity where there should be none.
Reply
#5

Quote:
Originally Posted by Pottus
View Post
Seems to me it would be easier to fix the problem than beat around the bush with this. It gives a false sense that everything is okay now you have given the noobs justification to be retarded. Just my take.

1-Star we don't need idiots trying to fix their scripts in idiot ways. Don't get me wrong you did good making it but it's purpose promotes laziness and stupidity where there should be none.
This can't be used to fix a native missing problem anybody is facing. One way or another, missing natives will eventually impair the functionality of the script, if you use them. However, when I wanted to test different versions of certain plugins, it was a pain to always have to recompile the gamemode when some minor inessential function was missing. Not all native functions are essential; if you use this plugin, you agree that missing natives are not essential, and even then, you get a bunch of warnings in the log for natives that aren't implemented.

Another use ****** has suggested would be for a script to check if a certain native is provided; there is currently no way to do that without proxy filterscripts.
Reply
#6

NativeFallback v1.1 released!
  • Hook mechanism modified to fix a bug in GCC.
  • bool:NativeExists(const name[]) and bool:MapNative(index, const name[]) added to assist with using optional natives.
There are two ways to use these new natives. Both natives are usable even if the plugin isn't loaded, but they return false in that case.

NativeFallback required
If you are fine with having a dependency on NativeFallback, just declare the native normally. Then use NativeExists to check if it is implemented:
pawn Code:
native OptionalNative();
new bool:OptionalNativeExists;

main()
{
    OptionalNativeExists = NativeExists("OptionalNative"); // true if the native was registered and no fallback was generated
    if(OptionalNativeExists)
    {
        OptionalNative();
    }
}
Without NativeFallback, this code would fail at initialization, since it uses a native that was not registered.

NativeFallback not required
If you want to use an optional native but not have NativeFallback as a dependency, you can use MapNative:

pawn Code:
#define OptionalNativeId -321651 // pick a unique negative identifier (unique to the script only)
native OptionalNative() = OptionalNativeId; // set it as the index of your native
new bool:OptionalNativeExists;

main()
{
    OptionalNativeExists = MapNative(OptionalNativeId, "OptionalNative"); // maps the specified native to your unique index
    if(OptionalNativeExists)
    {
        OptionalNative();
    }
}
This way, you call the native via its new identifier in your script, and if the mapping was performed correctly, it will call the specified native function. You can also change OptionalNative to anything else if you keep its name as the string.

If NativeFallback is not installed, MapNative simply returns false. You should not call the missing native in this case, as it may cause a crash.
Reply
#7

Maybe I should have given them they benefit of the doubt - sorry. You're right, the ability to detect natives at run-time and configure them is not a totally original idea; we've wanted it for a long time. However, it has never been done before. So maybe not a completely original idea, but quite original. Some of the techniques used here were, to the best of my knowledge, invented less than two days ago, thus finally making the ability to implement it a reality.
Reply
#8

Useful but not original idea
Reply
#9

Quote:
Originally Posted by ******
View Post
Err, what? This is literally the first plugin ever to do this, in many many years of SA:MP and even more of pawn. Can you point to anyone else that has done this to render it "unoriginal"?
He probably thought its something related to in-game falling or whatever.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)