Merge pull request #7374 from DeadlySurprise/cashOverflowFix

Added a check for overflowing player credits
This commit is contained in:
Paul Chote
2015-02-20 17:24:57 +00:00

View File

@@ -79,8 +79,35 @@ namespace OpenRA.Traits
public void GiveCash(int num) public void GiveCash(int num)
{ {
Cash += num; if (Cash < int.MaxValue)
Earned += num; {
try
{
checked
{
Cash += num;
}
}
catch (OverflowException)
{
Cash = int.MaxValue;
}
}
if (Earned < int.MaxValue)
{
try
{
checked
{
Earned += num;
}
}
catch (OverflowException)
{
Earned = int.MaxValue;
}
}
} }
public bool TakeCash(int num) public bool TakeCash(int num)