Raised This Month: $7 Target: $400
 1% 

Problems with reading .INI file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 03-24-2023 , 04:16   Problems with reading .INI file
Reply With Quote #1

Here's the thing. I'm making a plugin to change player models as you might have known. I'm using two .INI files, one is for model list (let's say file1.ini) and second is for model data (as section) for team, gender, etc (let's say file2.ini). I'm using popular amx_settings_api to read those .INIs

But now i'm facing a problem. I have around 120 model list at file1.ini (i know it's a lot, bear with me) so as file2.ini have 120 sections. I want to add more, so i add a new list to file1 and new section to file2. When game is loading, it will show "MSG_ReadBitString: buffer overflow error". Then i tought maybe it's too much. So i'm replacing an existing line at file1 and replacing a section at file2. Started the game again, it's still giving same error. I even tried reducing by deleting ~5 lists + sections but nothing changed.

My code :
PHP Code:
public Read_PlayerModels()
{
    new 
g_szConfigDir[64], sPath[64]
    
get_configsdir(g_szConfigDircharsmax(g_szConfigDir))
    
format(sPathcharsmax(sPath), "%s/%s"g_szConfigDirMODEL_DB);

    if (!
file_exists(sPath))
    {
        new 
text[64]
        
format(text63"ERROR! Couldn't Open File: %s!"MODEL_DB)
        
set_fail_state(text);
    }
    
    new 
linedata[1024], iLine 1;
    new 
file fopen(sPath"rt");

    while (
file && !feof(file))
    {
        
fgets(filelinedatacharsmax(linedata));
        
replace(linedatacharsmax(linedata), "^n""");
        
        if (!
linedata[0] || linedata[0] == ';')
            continue;
        if (
iLine MAX_PLAYER)
        {
            
set_fail_state("Error! Too Many Player Data.")
            continue
        }
        
        
copy(g_mdl_name[iLine], 63linedata)
        
        
Read_PlayerModels_INI(iLine)
        
PrecacheModelData(iLine)
        
Read_Admin_Stuffs(iLine)
        
        
g_totalmdl iLine
        iLine
++;
    }
    
fclose(file);
}

public 
Read_PlayerModels_INI(iLine)
{
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "displayname"g_mdl_ign[iLine], 32)
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "sex"g_mdl_sex[iLine])
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "classtype"g_classtyp[iLine], 32)
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "handmodel"g_mdl_hand[iLine])
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "team"g_mdl_team[iLine])
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "extendedvox"g_extended_vox[iLine], 32)

If it's too much to handle, i'm ok if i have to reduce it. But why still gives same error even after rerducing it? What's wrong with my code? Is it need to reduce further like 50 section or what? Btw i'm using amxmodx 1.10.0 5467 latest and i'm not using this plugin for multiplayer, so no need to think abt that.

complete lists of my player models and source are attached below
Attached Files
File Type: ini ccx_humanclass_list.ini (1.4 KB, 30 views)
File Type: ini ccx_humanclass_cfg.ini (12.4 KB, 31 views)
File Type: sma Get Plugin or Get Source (addon_csocharacters_xtended.sma - 25 views - 42.7 KB)

Last edited by asdian; 03-25-2023 at 08:49. Reason: changed to php instead of code
asdian is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 03-24-2023 , 13:07   Re: Problems with reading .INI file
Reply With Quote #2

i made some changes and i explained why

PHP Code:
public Read_PlayerModels()
{
    new 
g_szConfigDir[64], sPath[64]
    
get_configsdir(g_szConfigDircharsmax(g_szConfigDir))
    
//formatex is faster
    //use format only when you need to use string content as a parameter in itself
    //example: format(szPath, charsmax(szPath), "%s", szPath)
    
formatex(sPathcharsmax(sPath), "%s/%s"g_szConfigDirMODEL_DB);

    if (!
file_exists(sPath))
    {
        
//don't need to create a new varible, you can format the text in function parameters
        
set_fail_state("ERROR! File %s does not exists!"MODEL_DB));
    }
    
    new 
linedata[1024], iLine 1;
    new 
file fopen(sPath"rt");

    
//check if file has been opened
    
if(file)
    {
        
//run loop if the next exists, less functions better performance
        
while (fgets(filelinedatacharsmax(linedata)))
        {
            
replace(linedatacharsmax(linedata), "^n""");
            
            if (!
linedata[0] || linedata[0] == ';')
                continue;
            
            if (
iLine MAX_PLAYER)
            {
                
fclose(file);
                
set_fail_state("Error! Too Many Player Data.")
                
//don't need to call continue if the plugin will enter in a fail state
            
}
            
            
//you must pass the size of the buffer where you copy the string
            
copy(g_mdl_name[iLine], charsmax(g_mdl_name[]), linedata)
            
            
Read_PlayerModels_INI(iLine)
            
PrecacheModelData(iLine)
            
Read_Admin_Stuffs(iLine)
            
            
g_totalmdl iLine
            iLine
++;
        }
    }
    else 
    {
        
fclose(file);
        
set_fail_state("File %s couldn't be opened."szPath)
    }

    
fclose(file);
}

public 
Read_PlayerModels_INI(iLine)
{
    
//when passing size of an array or a buffer, you must pass the size -1 because the last "place" is reserved for end of string byte (that means g_mdl_ign[32] = '^0' and can't be changed)
    //better use sizeof(g_mdl_ign) - 1 or charsmax(g_mdl_gign)
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "displayname"g_mdl_ign[iLine], charsmax(g_mdl_ign[]))
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "sex"g_mdl_sex[iLine])
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "classtype"g_classtyp[iLine], charsmax(g_classtyp[]))
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "handmodel"g_mdl_hand[iLine])
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "team"g_mdl_team[iLine])
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "extendedvox"g_extended_vox[iLine], charsmax(g_extended_vox[]))

hope this will help even if i have never worked with zombie plague

and next time when you post code use php /php

Last edited by lexzor; 03-24-2023 at 13:29.
lexzor is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 03-25-2023 , 12:34   Re: Problems with reading .INI file
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
i made some changes and i explained why

PHP Code:
public Read_PlayerModels()
{
    new 
g_szConfigDir[64], sPath[64]
    
get_configsdir(g_szConfigDircharsmax(g_szConfigDir))
    
//formatex is faster
    //use format only when you need to use string content as a parameter in itself
    //example: format(szPath, charsmax(szPath), "%s", szPath)
    
formatex(sPathcharsmax(sPath), "%s/%s"g_szConfigDirMODEL_DB);

    if (!
file_exists(sPath))
    {
        
//don't need to create a new varible, you can format the text in function parameters
        
set_fail_state("ERROR! File %s does not exists!"MODEL_DB));
    }
    
    new 
linedata[1024], iLine 1;
    new 
file fopen(sPath"rt");

    
//check if file has been opened
    
if(file)
    {
        
//run loop if the next exists, less functions better performance
        
while (fgets(filelinedatacharsmax(linedata)))
        {
            
replace(linedatacharsmax(linedata), "^n""");
            
            if (!
linedata[0] || linedata[0] == ';')
                continue;
            
            if (
iLine MAX_PLAYER)
            {
                
fclose(file);
                
set_fail_state("Error! Too Many Player Data.")
                
//don't need to call continue if the plugin will enter in a fail state
            
}
            
            
//you must pass the size of the buffer where you copy the string
            
copy(g_mdl_name[iLine], charsmax(g_mdl_name[]), linedata)
            
            
Read_PlayerModels_INI(iLine)
            
PrecacheModelData(iLine)
            
Read_Admin_Stuffs(iLine)
            
            
g_totalmdl iLine
            iLine
++;
        }
    }
    else 
    {
        
fclose(file);
        
set_fail_state("File %s couldn't be opened."szPath)
    }

    
fclose(file);
}

public 
Read_PlayerModels_INI(iLine)
{
    
//when passing size of an array or a buffer, you must pass the size -1 because the last "place" is reserved for end of string byte (that means g_mdl_ign[32] = '^0' and can't be changed)
    //better use sizeof(g_mdl_ign) - 1 or charsmax(g_mdl_gign)
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "displayname"g_mdl_ign[iLine], charsmax(g_mdl_ign[]))
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "sex"g_mdl_sex[iLine])
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "classtype"g_classtyp[iLine], charsmax(g_classtyp[]))
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "handmodel"g_mdl_hand[iLine])
    
amx_load_setting_int(MODEL_CFGg_mdl_name[iLine], "team"g_mdl_team[iLine])
    
amx_load_setting_string(MODEL_CFGg_mdl_name[iLine], "extendedvox"g_extended_vox[iLine], charsmax(g_extended_vox[]))

hope this will help even if i have never worked with zombie plague

and next time when you post code use php /php
thank you. i've tried but unfortunately the issue still persist
asdian is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 03-25-2023 , 13:30   Re: Problems with reading .INI file
Reply With Quote #4

can you post the code where "displayname" parameter from amx_load_setting_string is initialized?
lexzor is offline
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 03-26-2023 , 11:54   Re: Problems with reading .INI file
Reply With Quote #5

Quote:
Originally Posted by lexzor View Post
can you post the code where "displayname" parameter from amx_load_setting_string is initialized?
"displayname" is a key of a section, so it is not something to initalize. if you mean parameter that uses "displayname" as the key, so the answer is "g_mdl_ign[MAX_PLAYER][32]"

-> "MAX_PLAYER" is max number of player model, not max player of the game

[model]
team=
displayname=
..etc

Last edited by asdian; 03-26-2023 at 11:57.
asdian is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 03-26-2023 , 12:54   Re: Problems with reading .INI file
Reply With Quote #6

after reading the initial post i realised i was wrong because it is a client error.


this can be caused by a network packet containing more data than it expects and is attempting to read past the end of the packet buffer

try to run plugin without any models and see if the problem persist. if not that means a model or a sound is causing this problem.
lexzor is offline
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 00:23.


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