Fix crashing when loading an inventory with more than max horses

This commit is contained in:
Bluzume 2021-11-24 21:27:08 -05:00
parent 0281573f69
commit db9c973477
3 changed files with 13 additions and 3 deletions

View file

@ -314,6 +314,12 @@ namespace HISP.Game
}
public RanchBuilding GetBuilding(int buildingId)
{
if (buildingId < 0)
return null;
if (buildingId >= buildings.Length)
return null;
return buildings[buildingId];
}
public void SetBuilding(int buildingId, RanchBuilding value)

View file

@ -1932,8 +1932,7 @@ namespace HISP.Server
while (reader.Read())
{
inv.AddHorse(ReadHorseInstance(reader), false);
inv.AddHorse(ReadHorseInstance(reader), false, true);
}

View file

@ -5531,7 +5531,7 @@ namespace HISP.Server
{
Ranch.RanchBuilding building = Ranch.RanchBuilding.GetRanchBuildingById(buildingId);
int ranchBuild = sender.LoggedinUser.LastClickedRanchBuilding;
if (ranchBuild == 0)
if (ranchBuild <= 0)
return;
if (sender.LoggedinUser.OwnedRanch != null)
{
@ -5540,7 +5540,12 @@ namespace HISP.Server
Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to remove more buildings than the limit.");
return;
}
Ranch.RanchBuilding ranchBuilding = sender.LoggedinUser.OwnedRanch.GetBuilding(ranchBuild - 1);
if (ranchBuilding == null)
return;
if (ranchBuilding.Id == buildingId)
{
sender.LoggedinUser.OwnedRanch.SetBuilding(ranchBuild - 1, null);