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

.INI File Cleaner or Enabler/Disabler


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 07-29-2018 , 19:32   .INI File Cleaner or Enabler/Disabler
Reply With Quote #1

I searched a little and didn't find something similar to what I was looking for, and I decided to try by myself and made a code that can disable and enable a whole .ini file or a single line by a command.

Put your .ini file here

PHP Code:
new const g_szIniFileName[] =    "plugins-custom.ini" 
Used an exemple when you wanna enable/disable bunnyhop plugin in the plugins-custom.ini:

Source code:

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN ".Ini file Enabler/Disabler"
#define VERSION "1.0"
#define AUTHOR "EFFx"

new const g_szIniFileName[] =    "plugins-custom.ini"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("amx_clean""cmdClean"ADMIN_IMMUNITY"<1|0 - Clean whole file>")
    
register_clcmd("amx_remove""cmdRemove"ADMIN_IMMUNITY"<1|0 - Remove whole file>")
}

public 
cmdClean(idlevelcid)
{
    if(!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED

    
new szWholeFile[2], bool:bIsWholeFile
    read_argv
(1szWholeFilecharsmax(szWholeFile))
    
    
bIsWholeFile bool:str_to_num(szWholeFile)
    if(!
enableLine(bIsWholeFilebIsWholeFile "" "bunnyhop.amxx"))
    {
        
console_print(id"[AMXX]: Line not found")
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED
}

public 
cmdRemove(idlevelcid)
{
    if(!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED

    
new szWholeFile[2], bool:bIsWholeFile
    read_argv
(1szWholeFilecharsmax(szWholeFile))

    
bIsWholeFile bool:str_to_num(szWholeFile)
    if(!
disableLine(bIsWholeFilebIsWholeFile "" "bunnyhop.amxx"))
    {
        
console_print(id"[AMXX]: Line not found")
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED
}

enableLine(bool:bWholeFileszLine[])
{
    new 
szFileName[64], szText[512]
    
get_configsdir(szFileNamecharsmax(szFileName))
    
format(szFileNamecharsmax(szFileName), "%s/%s"szFileNameg_szIniFileName)

    new 
iFile fopen(szFileName"rt"), i
    
while(!feof(iFile))
    {
        
fgets(iFileszTextcharsmax(szText))
        
trim(szText)
        
        
i++

        if(
szText[0] == ';')
        {
            if(!
bWholeFile && !equal(szText[1], szLine))
                continue
                        
            
replace(szTextcharsmax(szText), ";""")
            
write_file(szFileNameszText, (1))
            return 
true
        
}
    }
    
fclose(iFile)
    return 
false


disableLine(bool:bWholeFileszLine[])
{
    new 
szFileName[64], szText[512]
    
get_configsdir(szFileNamecharsmax(szFileName))
    
format(szFileNamecharsmax(szFileName), "%s/%s"szFileNameg_szIniFileName)

    new 
iFile fopen(szFileName"rt"), i
    
while(!feof(iFile))
    {
        
fgets(iFileszTextcharsmax(szText))
        
trim(szText)
        
        
i++

        if(
szText[0] != ';')
        {
            if(!
bWholeFile && !equal(szTextszLine))
                continue

            
format(szTextcharsmax(szText), ";%s"szText)
            
write_file(szFileNameszText, (1))
            return 
true
        
}
    }
    
fclose(iFile)
    return 
false

Used an example to completely remove the plugin instead of only add a ';' before it's name:

Source Code:

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define PLUGIN ".Ini file cleaner"
#define VERSION "1.0"
#define AUTHOR "EFFx"

new const g_szIniFileName[] =    "plugins-pubg.ini"

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("amx_clean""cmdClean"ADMIN_IMMUNITY"<1|0 - Clean whole file>")
}

public 
cmdClean(idlevelcid)
{
    if(!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED

    
new szWholeFile[2], bool:bIsWholeFile
    read_argv
(1szWholeFilecharsmax(szWholeFile))
    
    
bIsWholeFile bool:str_to_num(szWholeFile)
    if(!
cleanFile(bIsWholeFilebIsWholeFile "" "bunnyhop.amxx"))
    {
        
console_print(id"[AMXX]: Line not found")
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED
}

cleanFile(bool:bWholeFileszLine[])
{
    new 
szFileName[64], szText[512]
    
get_configsdir(szFileNamecharsmax(szFileName))
    
format(szFileNamecharsmax(szFileName), "%s/%s"szFileNameg_szIniFileName)

    new 
iFile fopen(szFileName"rt"), i
    
while(!feof(iFile))
    {
        
fgets(iFileszTextcharsmax(szText))
        
trim(szText)
        
        
i++

        if((
szText[0] == EOS) || !bWholeFile && !equal(szTextszLine))
            continue

        
replace(szTextcharsmax(szText), bWholeFile szText szLine"")
        
write_file(szFileNameszText, (1))
        
        if(
bWholeFile)
        {
            
cleanFile(bWholeFileszLine)
        }
        return 
true
    
}
    
fclose(iFile)
    return 
false

OBS: If you wanna disable/enable a plugin and it contains debug mode, you must add on enableLine() and disableLine() stock too, remember that it check if the line is equal, not if contains the same name.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 07-29-2018 at 19:55.
EFFx is offline
Old 08-02-2018, 05:33
klimbo13
This message has been deleted by Arkshine. Reason: Spam
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

Forum Jump


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


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