• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[Tutorial] GetGold (/gg) fix

Initiate Mage
Joined
Jan 15, 2014
Messages
1
Reaction score
0
#I'm not english.


Hello,
On this tutorial we will learn how to fix GetGold command.
The bug make your penya goes to 0 by exceeding of int max value
Ok, let's go.


First you have to open FuncTextCmd.cpp (Interface folder)
Search (CTRL+F): BOOL TextCmd_GetGold( CScanner& scanner )

You should have the following code:

PHP:
BOOL TextCmd_GetGold( CScanner& scanner )           
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
    int nGold = scanner.GetNumber(); 
    pUser->AddGold( nGold );
#endif // __WORLDSERVER 
    return TRUE;
}

Well, now we must check if nGold > 2147483646 (Max int size - 1):
First, create a variable call for example maxIntValue and assign it to 2147483646
PHP:
BOOL TextCmd_GetGold( CScanner& scanner ) 
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
                            int maxIntValue = 2147483646; // max int value  - 1
    int nGold = scanner.GetNumber(); 
    pUser->AddGold( nGold );
#endif // __WORLDSERVER 
    return TRUE;
}

Ok, well the variable is create. Now we must make a condition who check if nGold > MaxIntValue.
PHP:
BOOL TextCmd_GetGold( CScanner& scanner ) 
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
int maxIntValue = 2147483646; // max int value  - 1
int nGold = scanner.GetNumber(); 
if(nGold > MaxIntValue)
{
  pUser->AddText("Oversized !");
}
else
{
    int nGold = scanner.GetNumber(); 
    pUser->AddGold( nGold );
#endif // __WORLDSERVER 
}
    return TRUE;
}

Ok, right. The next part is optional. We must check if maxIntValue >= gold user + nGold.
That's simply check if user gold + nGold (input) is inferior than maxIntValue


PHP:
BOOL TextCmd_GetGold( CScanner& scanner ) 
{ 
#ifdef __WORLDSERVER
    CUser* pUser = (CUser*)scanner.dwValue;
int maxIntValue = 2147483646; // max int value  - 1
 int userGold = pUser->GetGold(); // Get user gold
int nGold = scanner.GetNumber(); 
if(nGold > MaxIntValue)
{
  pUser->AddText("Oversized !");
}
    else   
 {       
 if(maxIntValue >= (userGold + nGold))        
{ 
           pUser->AddGold( nGold );       
 }            
else        
{           
 pUser->AddGold(maxIntValue);      
  }    
}        
return TRUE;
}

Pastebin final link
with correct indentation:

Should work, bye ;)

 
Last edited:
Initiate Mage
Joined
Feb 24, 2014
Messages
1
Reaction score
0
Code:
BOOL TextCmd_GetGold( CScanner& scanner )          
{
#ifdef __WORLDSERVER
        CUser* pUser    = (CUser*)scanner.dwValue;
        int maxIntValue = 2147483646; 
        int userGold = pUser->GetGold();
       
        int nGold = scanner.GetNumber();
       
        if(nGold > (maxIntValue - userGold) )
        {
            maxIntValue = maxIntValue - userGold;
            pUser->AddGold(maxIntValue);
        }
        else
        {
            pUser->AddGold( nGold );    
        }      
#endif  // __WORLDSERVER       
        return TRUE;
}

i dont test it!
 
[R8]ℓσℓ32
Loyal Member
Joined
Oct 6, 2008
Messages
1,396
Reaction score
198
const int maxIntValue = INT_MAX;

Code:
BOOL TextCmd_GetGold( CScanner& scanner )          
{
#ifdef __WORLDSERVER
        CUser* pUser    = (CUser*)scanner.dwValue;
        int userGold = pUser->GetGold();
       
        int nGold = scanner.GetNumber();
       
        if(nGold > INT_MAX)
        {
                pUser->AddText("Valeur trop importante (max: 2147483646)");
        }
        else
        {
                if(INT_MAX >= (userGold + nGold))
                {
                        pUser->AddGold( nGold );
                }      
                else
                {
                        pUser->AddGold(INT_MAX);
                }
        }      
#endif  // __WORLDSERVER       
        return TRUE;
}
 
Back
Top