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

delete, CloseHandle...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 08-15-2017 , 15:57   delete, CloseHandle...
Reply With Quote #1

Hi,
Now I want to be sure what "delete" actually does. like if I do:
PHP Code:
delete TimerHandle
I need to check if Handle is " != null " ?
I need to set to to " null " after the delete ?

If the second is: no, why (for example) here they did it " = null "


And this is just out of curiosity, does "delete" 'calls' "CloseHandle" right? Because in some error logs i've found Invalid Handle (error), in the line of "delete" 'reporting CloseHandle as function'


Last think:
What's the main difference between using:
PHP Code:
delete TimerHandle;
CloseHandle(TimerHandle);
KillTimer(TimerHandle); 
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!

Last edited by Papero; 08-15-2017 at 16:01.
Papero is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-15-2017 , 16:48   Re: delete, CloseHandle...
Reply With Quote #2

PHP Code:
delete X
This equal
PHP Code:
CloseHandle(X);
null
Read more

PHP Code:
CloseHandle(Handle hndl); 
Just close handle.
PHP Code:
KillTimer(Handle timerbool autoClose false); 
"If autoClose is true, the data that was passed to CreateTimer() will be closed as a handle if TIMER_DATA_HNDL_CLOSE was not specified."
If autoClose is false, equal to CloseHandle().
Overwise will call CloseHandle on data before close timer handle.

By the way, Handle is methodmap for now and have Handle.Close() method, that can be called on all "handled" types.
PHP Code:
Handle g_var;

public 
void OnPluginStart()
{
    
g_var.Close();

P.S. In case if you no matter to set variable to 0, like in menu callback. Calling close will more effective.
PHP Code:
public int MenuHandler(Menu menuMenuAction actionint param1int param2)
{
    if (
action == MenuAction_End)
        
menu.Close();


Last edited by Kailo; 08-15-2017 at 16:52.
Kailo is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 08-15-2017 , 17:16   Re: delete, CloseHandle...
Reply With Quote #3

Thanks for the reply,

So, makes no sense what they (AM Developers) did here?
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 08-15-2017 , 17:19   Re: delete, CloseHandle...
Reply With Quote #4

Quote:
Originally Posted by Papero View Post
Thanks for the reply,

So, makes no sense what they (AM Developers) did here?
That's probably just an oversight. The plugins were all written in the old syntax before being converted over to the new syntax. Line 381 is not necessary there.
__________________
ddhoward is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 08-15-2017 , 19:48   Re: delete, CloseHandle...
Reply With Quote #5

In general, the base plugins were converted through basically automated find and replace.
Fyren is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-16-2017 , 09:24   Re: delete, CloseHandle...
Reply With Quote #6

It is sad to say, but the base plugins should not really be used as a reference in any way.

Large portions of the code are absolutely awful, while they generally work fine, they're all very old from the very early days of SourceMod and do not get much love.
__________________
asherkin is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-16-2017 , 09:25   Re: delete, CloseHandle...
Reply With Quote #7

Quote:
Originally Posted by Kailo View Post
PHP Code:
delete X
This equal
PHP Code:
CloseHandle(X);
null
Not quite, it is equivalent to
PHP Code:
if (!= null) {
  
CloseHandle(X);
  
null;

__________________

Last edited by asherkin; 08-16-2017 at 09:26.
asherkin is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 08-16-2017 , 09:40   Re: delete, CloseHandle...
Reply With Quote #8

Quote:
Originally Posted by asherkin View Post
Not quite, it is equivalent to
PHP Code:
if (!= null) {
  
CloseHandle(X);
  
null;

hmm... I'm not sure about it. SM 1.8. May be in 1.9 this is so.
Quote:
Originally Posted by Kailo
I wrote sample
PHP Code:
Handle g_var;

public 
void OnPluginStart()
{
    
delete g_var;

Opcode of this sample is
Code:
proc // start of OnPluginStart
break
break
load.pri 2220 // load g_var adress to primary register
push.pri // pass (push in stack) g_var as 1st parametr for CloseHandle call
sysreq.n 2 1 // Call CloseHandle
zero 2220 // Set g_var to 0
zero.pri 
retn

Last edited by Kailo; 08-16-2017 at 09:43.
Kailo is offline
Reply



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 23:18.


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