[Tool/Web/Other] [WIP]SA-MP ALS Hooking Generator
#1

SA-MP ALS Hooking Generator 0.3b


About
This is a simple app to generate the code needed to do an ALS hook on any callback.
Dont know what ALS Hooking is? Please check this posts for more info.

https://sampforum.blast.hk/showthread.php?tid=85907

Whats this do?
The app will generate code to hook one or more callbacks defining all the ALS code for you
with your set prefix.


supports both pre & post code for OnGameModeInit().
The interface has checkboxs with a list of all callbacks to select to hook.


Is this better/faster than y_hooks?
Quote:
Originally Posted by ******
Посмотреть сообщение
For reference, ALS and y_hooks are pretty much equal in run-time speed, but you're right that y_hooks takes longer to compile (though this has been vastly improved) and ALS takes longer to write - so if you have a tool to generate ALS code then that's a win!
Now I found y_hooks to be wonderful, and I use it myself, so it would depend on
where/what you using ALS over y_hooks, Do you want to depend on another lib,
would depend on your code, if your already using YSI then I would use y_hooks.


What language is this written in?
VS c# 2010


Update
After the discussion held here, ****** had some great ideas and some tips that I have implemented.
So credits to ****** for his tips & ideas!

List of changes
0.3b:
  • Fixed a bug in code that was generated for OnGameModeInit()
0.3a:
  • Fixed a bug in code that was generated to check for null strings.
0.3:
  • Added full support for custom functions
  • Added support for storing weather a callback exists or not.
0.2:
  • When no prefix is set, prompt user to enter one.
  • Code now generates support for null strings.
  • Added more to the interface to allow for Custom Callbacks ALS code generation.
    Read below in "Custom Callbacks" to learn how to use it.
Custom Callbacks
Adding a custom callback is easier than ever.
When you launch the ALS generator you'll see a group box
(See ss2.jpg from the attachments)
It takes 3 Parameters:
  • Name //This is the Callback Name ex: OnSomeCallBack
  • Format //This is the format specifier ex: isf
  • Arguments //This is the arguments list ex: playerid,text[],Float:fVal
Add these values and hit the Add Button.
Note that when using a string argument in a custom function
the code to check for null string is also generated for you!.
New in 0.3*
You can now add and remove custom callbacks from a list
before generating the ALS code.

Note
OnGameModeInit() is always generated. If its the only function you want to hook
Just set your prefix and hit generate!.

Future Release
I have planed for a future release that will load all callbacks from a file making it easy
to permanently add your custom callbacks. This will allow me to add the function hooking support
along with release a simple file for updating the app. This will require a rewrite of the hole system
so will not be done right away but over the next few weeks. I have another project to do before this.

Suggestions
Note this is a work in progress but fully functional,
any suggestions will be taken into consideration.


regards,
Reply
#2

what does this exactly do... ?
Reply
#3

it will generate code like
pawn Код:
//--------------OnGameModeInit Hook-------------------

public OnGameModeInit()
{
    new ret = 1;
    //your OnGameModeInit pre code here

    if (funcidx("Prefix_OnGameModeInit") != -1)
    {
        ret = CallLocalFunction("Prefix_OnGameModeInit", "");
    }
    //your OnGameModeInit post code here

    return ret;
}
#if defined _ALS_OnGameModeInit
    #undef OnGameModeInit
#else
    #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit Prefix_OnGameModeInit
forward Prefix_OnGameModeInit();
This allows you to hook any callbacks
check out this post to see more info about ALS Hooking
https://sampforum.blast.hk/showthread.php?tid=85907

this app just generates the proper code for you
Reply
#4

nice... but i read the topic and i dont see why would i need to create different functions if i have all the native ones that i need?
Reply
#5

then this is probably not for you.

The reason is so when you make an include that uses callbacks
you HOOK them and both your functions and the native callbacks get called.
Its mostly for if your making a library of some sort.
If you dont make this kinda stuff this is not for you,
Reply
#6

Quote:
Originally Posted by Jonny5
Посмотреть сообщение
The reason is so when you make an include that uses callbacks
you HOOK them and both your functions and the native callbacks get called.
Its mostly for if your making a library of some sort.
If you dont make this kinda stuff this is not for you,
****** already did y_hook include, and it's much better
Reply
#7

this is not an include, Its a app that will generate code in the ALS_ format,
Which has been around long before y_hooks
and which ****** standardized

I know all about y_hooks, (iv used them in some of my modes)

I dont know if its "better" or just easier.
(I do think he has done something with #emit to make calling the hooks faster than ALS)

This is for if you dont want to use y_hooks in your lib,
y_hooks add a big compile time on, Im guessing from all the marcos text replacements.

this is for people who write ALS code! simple as that, if your not into hooking your own functions
with ALS and writing include's or libraries then you wont need this.

regards,
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
Nice work! Definitely worth reputation. A few suggestions:
+1
Time Saving
Reply
#9

Not Bad ^^

7/10

Update please Anymore Functions
Reply
#10

Quote:
Originally Posted by ******
Посмотреть сообщение
Nice work! Definitely worth reputation. A few thoughts:

1) Add a "custom" option - the patterns are pretty constant, though I'm not sure how parameters would work just yet (but shouldn't be too hard). This way people don't need to rely on waiting for updates when new callbacks are added - either officially or through other libraries.

2) Does this check for "\0" in callbacks with strings? They can be passed empty strings but can't pass them on again.

3) "funcidx" is either used purely in "OnModeInit" or not at all. Wrapping every "CallLocalFunction" in a call to "funcidx" has no gain - the result is normally found in advance and that saved value used. Check the "Optimisations" section of my post you linked to.

4) I'd suggest leaving the "Prefix" box empty by default and prompting for input if it is left blank to aovid everyone just using the defaults blindly (which they will - I did it without even thinking).

I was going to make a note about long callbacks, but I see you've already covered that, so that's even better!



For reference, ALS and y_hooks are pretty much equal in run-time speed, but you're right that y_hooks takes longer to compile (though this has been vastly improved) and ALS takes longer to write - so if you have a tool to generate ALS code then that's a win!
1.) did not even think about this, Great idea and will be added!
Do you think having having it load the custom Callbacks from files would be better?
I could load for each Lib, and have a file for new SAMP callbacks, that could be added to
until I make official update. This way I could write simple list file for each to support YSI, Streamer ect...
I think I may go that route.

2.) this does no checks, it just creates a skeleton ALS function for you,
I assume the scripter will handle any checks, but If its something I can add
I defiantly will. If you can post an example of what you mean that would be great.

3.) I thought doing it this way would return the next callbacks return, I will go back and re-read!
EDIT: I see the only advantage is OnGameModeInit() I will fix this.

4.)Yes you are correct! I will make that change,

Nice ideas!! and thanks for the tips, I will implement them ASAP.


Quote:
Originally Posted by Johann95
Посмотреть сообщение
Not Bad ^^

7/10

Update please Anymore Functions
I plan a version for functions to, just need some time to go threw them and
see what ones I want to support, I wont be supporting some functions(db, file, ect..)

If there is any more ideas/features please post them and I will review/add them.

and thanks for the feedback guys!
Reply
#11

Quote:
Originally Posted by Jonny5
View Post
1.) did not even think about this, Great idea and will be added!
Do you think having having it load the custom Callbacks from files would be better?
I could load for each Lib, and have a file for new SAMP callbacks, that could be added to
until I make official update. This way I could write simple list file for each to support YSI, Streamer ect...
I think I may go that route.
Yeah, that might be a better route for multiple ones.

Quote:
Originally Posted by Jonny5
View Post
2.) this does no checks, it just creates a skeleton ALS function for you,
I assume the scripter will handle any checks, but If its something I can add
I defiantly will. If you can post an example of what you mean that would be great.
OnPlayerDialogResponse is the main culprit for this:

pawn Code:
return CallLocalFunction("Prefix_OnDialogResponse", "iiiis",playerid, dialogid, response, listitem, inputtext);
If they didn't type anything in (say on a message box), this will actually crash. Instead you need:

pawn Code:
return CallLocalFunction("Prefix_OnDialogResponse", "iiiis",playerid, dialogid, response, listitem, inputtext[0] ? inputtext : "\1\0");
Where "\1\0" is the standard "almost" empty string used when an empty string can't, but should, be used. I'm not sure if it's possible to call the other string callbacks with an empty string, but I always do the checks incase some hack tool manages to send an empty chat message or something similar.

Quote:
Originally Posted by Jonny5
View Post
3.) I thought doing it this way would return the next callbacks return, I will go back and re-read!
EDIT: I see the only advantage is OnGameModeInit() I will fix this.

4.)Yes you are correct! I will make that change,

Nice ideas!! and thanks for the tips, I will implement them ASAP.
Cool, no problem.
Reply
#12

Okay I see this is needed, And easy to add.
Ill post the updated version when complete.

~J5
Reply
#13

Updated to 0.2
added all of y_less's tips/ideas.
Read the main post for details.

Please report any bugs/problems in this topic.

and I do have a question for Y_Less if you happen to read this topic again.
i noticed a few new 0.3e callbacks that are long

OnPlayerEditAttachedObject
OnPlayerClickPlayerTextDraw

have you come up with a standard short name for these?
also What should the max prefix length be?

thx
Reply
#14

I use "Obj" for "Object" and "TD" for "TextDraw" in fixes.inc, though I've not actually had to use them. As for prefix length, no idea - it depends on which callbacks you hook and wether you get a warning.
Reply
#15

Okay i made one more update,
I think the output should be correct now,

if you guys can test this for me and let me know any errors that would be great.
All features should be working.
Reply
#16

Hi, sorry but this doesn't work: I'm using your 0.3b version and when compiling I'm always getting the same error:

Code:
error 021: symbol already defined: "lvgz2_OnGameModeInit"
The error is always in the .pwn file (not in the .inc file), and the number of the line is always the next of that of OnGameModeInit (for example, if in my gamemode I have the callback OnGameModeInit in the line 34, the error is in the line 35).
Reply
#17

Hmm now I had no problems, so forget what I said in my previous post. I don't know what happened...
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)