SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 08/02/2019, 10:24 PM   #1
IllidanS4
Huge Clucker
 
IllidanS4's Avatar
 
Join Date: Feb 2013
Posts: 337
Reputation: 255
Default Native Fallback Ignore missing natives

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.
__________________
PawnPlus
YSF
Yet Another Lua Plugin
Long Function Names
 i_quat.inc 


kingsofsa.cz:8888 running Cinematic Mode

Last edited by IllidanS4; 14/02/2019 at 07:12 PM.
IllidanS4 is offline   Reply With Quote
Old 08/02/2019, 11:47 PM   #2
liguanhua123
Little Clucker
 
liguanhua123's Avatar
 
Join Date: Jun 2013
Location: China
Posts: 37
Reputation: 13
Default Re: Native Fallback Ignore missing natives

Good work!
Is it like nativechack?
__________________
My Projects:https://github.com/li123856
Battle Mode:[CSGO-SAMP-][PUBG-SAMP-]
Freedom Mode:[FreeMan1][FreeMan2][FreeMan3][FreeMan4]

liguanhua123 is offline   Reply With Quote
Old 09/02/2019, 12:00 AM   #3
IllidanS4
Huge Clucker
 
IllidanS4's Avatar
 
Join Date: Feb 2013
Posts: 337
Reputation: 255
Default Re: Native Fallback Ignore missing natives

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.
__________________
PawnPlus
YSF
Yet Another Lua Plugin
Long Function Names
 i_quat.inc 


kingsofsa.cz:8888 running Cinematic Mode
IllidanS4 is offline   Reply With Quote
Old 09/02/2019, 12:56 AM   #4
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,856
Reputation: 1292
Default Re: Native Fallback Ignore missing natives

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.

Last edited by Pottus; 09/02/2019 at 02:13 AM.
Pottus is offline   Reply With Quote
Old 09/02/2019, 01:30 PM   #5
IllidanS4
Huge Clucker
 
IllidanS4's Avatar
 
Join Date: Feb 2013
Posts: 337
Reputation: 255
Default Re: Native Fallback Ignore missing natives

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.
__________________
PawnPlus
YSF
Yet Another Lua Plugin
Long Function Names
 i_quat.inc 


kingsofsa.cz:8888 running Cinematic Mode
IllidanS4 is offline   Reply With Quote
Old 14/02/2019, 07:25 PM   #6
IllidanS4
Huge Clucker
 
IllidanS4's Avatar
 
Join Date: Feb 2013
Posts: 337
Reputation: 255
Default Re: Native Fallback Ignore missing natives

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.
__________________
PawnPlus
YSF
Yet Another Lua Plugin
Long Function Names
 i_quat.inc 


kingsofsa.cz:8888 running Cinematic Mode
IllidanS4 is offline   Reply With Quote
Old 14/02/2019, 07:59 PM   #7
TokicMajstor
Big Clucker
 
TokicMajstor's Avatar
 
Join Date: Oct 2018
Location: Bosnia And Herzegovina
Posts: 177
Reputation: 1
Default Re: Native Fallback Ignore missing natives

Useful but not original idea
__________________


If Iam better than you = you're noob
If you're better than me = you're cheater
If everyone is better than me = I have lags
#Logic
TokicMajstor is offline   Reply With Quote
Old 14/02/2019, 08:21 PM   #8
iAmir
Banned
 
Join Date: May 2017
Location: Iran
Posts: 118
Reputation: 191
Default Re: Native Fallback Ignore missing natives

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.
iAmir is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[LINUX HELP]Missing Service Binary Missing: samp03svr xSiiLenTx Scripting Help 1 17/08/2012 12:03 AM
Use SA:MP natives in a Plugin [LoD]Hauke Plugin Development 6 16/12/2010 10:37 PM
Natives GaGlets(R) Help Archive 0 01/08/2010 02:45 AM
MySQL Natives missing Castle Help Archive 0 19/04/2009 07:33 PM


All times are GMT. The time now is 02:05 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.