Skip to content

Commit

Permalink
Fixes for changes in SE 1.129 #62
Browse files Browse the repository at this point in the history
Changes to MyObjectBuilder_InventoryItem replace the Content property with PhysicalContent.
Removed obsolete repair feature.
Updated version for release.
  • Loading branch information
midspace committed Apr 7, 2016
1 parent 4e89c1d commit 640cba1
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 92 deletions.
2 changes: 0 additions & 2 deletions Main/SEToolbox/SEToolbox/Interop/SpaceEngineersExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Globalization;
using System.IO;
using System.Linq;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Common.ObjectBuilders.Definitions;
using SEToolbox.Models;
using SEToolbox.Support;
using VRage;
Expand Down
60 changes: 31 additions & 29 deletions Main/SEToolbox/SEToolbox/Interop/SpaceEngineersRepair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
using Sandbox.Common.ObjectBuilders;
using SEToolbox.Models;
using SEToolbox.Support;
using IDType = VRage.MyEntityIdentifier.ID_OBJECT_TYPE;
using VRage.ObjectBuilders;
using VRage;
using VRage.Game;
using IDType = VRage.MyEntityIdentifier.ID_OBJECT_TYPE;

public static class SpaceEngineersRepair
{
Expand Down Expand Up @@ -221,6 +219,8 @@ public static string RepairSandBox(WorldResource world)
}
else
{
// The game is sucessfully generating new characters now, so this code shouldn't be requried any more.
/*
str.AppendLine("! Could not find any Player Characters.");
character = new MyObjectBuilder_Character();
character.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.IDENTITY);
Expand All @@ -243,38 +243,34 @@ public static string RepairSandBox(WorldResource world)
character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
item.Amount = 1;
item.ItemId = 0;
item.Content = new MyObjectBuilder_Welder();
gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_Welder>();
gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;
item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject {GunEntity = gunEntity};
character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
item.Amount = 1;
item.ItemId = 1;
item.Content = new MyObjectBuilder_AngleGrinder();
gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_AngleGrinder>();
gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;
item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject { GunEntity = gunEntity };
character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
item.Amount = 1;
item.ItemId = 2;
item.Content = new MyObjectBuilder_HandDrill();
gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_HandDrill>();
gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;
item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject { GunEntity = gunEntity };
character.Inventory.Items.Add(item = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_InventoryItem>());
item.Amount = 1;
item.ItemId = 3;
item.Content = new MyObjectBuilder_AutomaticRifle();
gunEntity = SpaceEngineersCore.Resources.CreateNewObject<MyObjectBuilder_AutomaticRifle>();
gunEntity.EntityId = SpaceEngineersApi.GenerateEntityId(IDType.ENTITY);
gunEntity.PersistentFlags = MyPersistentEntityFlags2.None;
((MyObjectBuilder_PhysicalGunObject)item.PhysicalContent).GunEntity = gunEntity;
item.PhysicalContent = new MyObjectBuilder_PhysicalGunObject { GunEntity = gunEntity };
repairWorld.Checkpoint.ControlledObject = character.EntityId;
repairWorld.Checkpoint.CameraController = MyCameraControllerEnum.Entity;
Expand All @@ -285,6 +281,7 @@ public static string RepairSandBox(WorldResource world)
str.AppendLine("* Created new active Player.");
repairWorld.SaveCheckPointAndSector(true);
str.AppendLine("* Saved changes.");
*/
}
}
}
Expand All @@ -299,26 +296,31 @@ public static string RepairSandBox(WorldResource world)
character = repairWorld.FindAstronautCharacter()
?? repairWorld.FindPilotCharacter().Pilot;

MyObjectBuilder_Inventory inventory = character.Inventory;
requiredItems.ForEach(
delegate(string subtypeName)
{
if (!inventory.Items.Any(i =>
i.PhysicalContent != null &&
i.PhysicalContent.SubtypeName == subtypeName))
var inventoryBase = character.ComponentContainer.Components.FirstOrDefault(e => e.TypeId == "MyInventoryBase");
MyObjectBuilder_Inventory inventory = inventoryBase?.Component as MyObjectBuilder_Inventory;

if (inventory != null)
{
requiredItems.ForEach(
delegate(string subtypeName)
{
statusNormal = false;
str.AppendLine("! Replaced astronaut's missing " + subtypeName + ".");
saveAfterScan = true;
inventory.Items.Add(new MyObjectBuilder_InventoryItem
if (!inventory.Items.Any(i =>
i.PhysicalContent != null &&
i.PhysicalContent.SubtypeName == subtypeName))
{
Amount = 1,
Content = new MyObjectBuilder_PhysicalGunObject { SubtypeName = subtypeName },
ItemId = inventory.nextItemId
});
inventory.nextItemId++;
}
});
statusNormal = false;
str.AppendLine("! Replaced astronaut's missing " + subtypeName + ".");
saveAfterScan = true;
inventory.Items.Add(new MyObjectBuilder_InventoryItem
{
Amount = 1,
PhysicalContent = new MyObjectBuilder_PhysicalGunObject {SubtypeName = subtypeName},
ItemId = inventory.nextItemId,
});
inventory.nextItemId++;
}
});
}
}

// Scan through all items.
Expand Down
2 changes: 0 additions & 2 deletions Main/SEToolbox/SEToolbox/Interop/SpaceEngineersResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.IO;
using System.Linq;
using System.Reflection;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Common.ObjectBuilders.Definitions;
using SEToolbox.Support;
using VRage.Game;
using VRage.ObjectBuilders;
Expand Down
12 changes: 5 additions & 7 deletions Main/SEToolbox/SEToolbox/Models/ExplorerModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
using System.Linq;
using System.Windows.Shell;
using System.Windows.Threading;

using Microsoft.VisualBasic.FileIO;
using Sandbox.Common.ObjectBuilders;
using Sandbox.Common.ObjectBuilders.Definitions;
using SEToolbox.Interfaces;
using SEToolbox.Interop;
using SEToolbox.Interop.Asteroids;
using SEToolbox.Support;
using VRageMath;
using IDType = VRage.MyEntityIdentifier.ID_OBJECT_TYPE;
using VRage.ObjectBuilders;
using VRage;
using VRage.Game;
using VRage.ObjectBuilders;
using VRageMath;
using IDType = VRage.MyEntityIdentifier.ID_OBJECT_TYPE;

public class ExplorerModel : BaseModel
{
Expand Down Expand Up @@ -773,10 +771,10 @@ private void MergeData(MyObjectBuilder_CubeGrid cubeGridObject, ref Dictionary<I
}

var pistonBase = cubeGrid as MyObjectBuilder_PistonBase;
if (pistonBase != null)
if (pistonBase != null && pistonBase.TopBlockId.HasValue)
{
// reattach PistonBase (and ExtendedPistonBase) to correct entity.
pistonBase.TopBlockId = MergeId(pistonBase.TopBlockId, ref idReplacementTable);
pistonBase.TopBlockId = MergeId(pistonBase.TopBlockId.Value, ref idReplacementTable);
}

var shipConnector = cubeGrid as MyObjectBuilder_ShipConnector;
Expand Down
19 changes: 8 additions & 11 deletions Main/SEToolbox/SEToolbox/Models/InventoryEditorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
using System.IO;
using System.Linq;
using System.Xml.Serialization;

using Sandbox.Common.ObjectBuilders;
using Sandbox.Common.ObjectBuilders.Definitions;
using SEToolbox.Interop;
using SEToolbox.Support;
using VRage.Game;
Expand Down Expand Up @@ -222,7 +219,7 @@ private void UpdateGeneralFromEntityBase()

private InventoryModel CreateItem(MyObjectBuilder_InventoryItem item, string contentPath)
{
var definition = SpaceEngineersApi.GetDefinition(item.Content.TypeId, item.Content.SubtypeName) as MyObjectBuilder_PhysicalItemDefinition;
var definition = SpaceEngineersApi.GetDefinition(item.PhysicalContent.TypeId, item.PhysicalContent.SubtypeName) as MyObjectBuilder_PhysicalItemDefinition;

string name;
string textureFile;
Expand All @@ -231,7 +228,7 @@ private InventoryModel CreateItem(MyObjectBuilder_InventoryItem item, string con

if (definition == null)
{
name = item.Content.SubtypeName + " " + item.Content.TypeId.ToString();
name = item.PhysicalContent.SubtypeName + " " + item.PhysicalContent.TypeId.ToString();
massMultiplyer = 1;
volumeMultiplyer = 1;
textureFile = null;
Expand All @@ -248,14 +245,14 @@ private InventoryModel CreateItem(MyObjectBuilder_InventoryItem item, string con
{
Name = name,
Amount = (decimal)item.Amount,
SubtypeId = item.Content.SubtypeName,
TypeId = item.Content.TypeId,
SubtypeId = item.PhysicalContent.SubtypeName,
TypeId = item.PhysicalContent.TypeId,
MassMultiplyer = massMultiplyer,
VolumeMultiplyer = volumeMultiplyer,
TextureFile = textureFile,
IsUnique = item.Content.TypeId == SpaceEngineersTypes.PhysicalGunObject || item.Content.TypeId == SpaceEngineersTypes.OxygenContainerObject,
IsInteger = item.Content.TypeId == SpaceEngineersTypes.Component || item.Content.TypeId == SpaceEngineersTypes.AmmoMagazine,
IsDecimal = item.Content.TypeId == SpaceEngineersTypes.Ore || item.Content.TypeId == SpaceEngineersTypes.Ingot,
IsUnique = item.PhysicalContent.TypeId == SpaceEngineersTypes.PhysicalGunObject || item.PhysicalContent.TypeId == SpaceEngineersTypes.OxygenContainerObject,
IsInteger = item.PhysicalContent.TypeId == SpaceEngineersTypes.Component || item.PhysicalContent.TypeId == SpaceEngineersTypes.AmmoMagazine,
IsDecimal = item.PhysicalContent.TypeId == SpaceEngineersTypes.Ore || item.PhysicalContent.TypeId == SpaceEngineersTypes.Ingot,
Exists = definition != null, // item no longer exists in Space Engineers definitions.
};

Expand All @@ -278,7 +275,7 @@ internal void RemoveItem(int index)
var invItem = _inventory.Items[index];

// Remove HandWeapon if item is HandWeapon.
if (_character != null && _character.HandWeapon != null && invItem.Content.TypeId == SpaceEngineersTypes.PhysicalGunObject)
if (_character != null && _character.HandWeapon != null && invItem.PhysicalContent.TypeId == SpaceEngineersTypes.PhysicalGunObject)
{
if (((MyObjectBuilder_PhysicalGunObject)invItem.PhysicalContent).GunEntity != null &&
((MyObjectBuilder_PhysicalGunObject)invItem.PhysicalContent).GunEntity.EntityId == _character.HandWeapon.EntityId)
Expand Down
22 changes: 10 additions & 12 deletions Main/SEToolbox/SEToolbox/Models/ResourceReportModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
using System.Text;
using System.Web.UI;
using System.Xml;

using Sandbox.Common.ObjectBuilders;
using Sandbox.Common.ObjectBuilders.Definitions;
using SEToolbox.ImageLibrary;
using SEToolbox.Interfaces;
using SEToolbox.Interop;
using SEToolbox.Interop.Asteroids;
using SEToolbox.Support;
using VRage.Game;
using VRageMath;
using VRage.ObjectBuilders;
using VRageMath;

public class ResourceReportModel : BaseModel
{
Expand Down Expand Up @@ -373,13 +371,13 @@ public void GenerateReport()
{
var floating = (StructureFloatingObjectModel)entity;

if (floating.FloatingObject.Item.Content.TypeId == SpaceEngineersTypes.Ore || floating.FloatingObject.Item.Content.TypeId == SpaceEngineersTypes.Ingot)
if (floating.FloatingObject.Item.PhysicalContent.TypeId == SpaceEngineersTypes.Ore || floating.FloatingObject.Item.PhysicalContent.TypeId == SpaceEngineersTypes.Ingot)
{
TallyItems(floating.FloatingObject.Item.Content.TypeId, floating.FloatingObject.Item.Content.SubtypeName, (decimal)floating.FloatingObject.Item.Amount, contentPath, accumulateUnusedOres, accumulateItems, accumulateComponents);
TallyItems(floating.FloatingObject.Item.PhysicalContent.TypeId, floating.FloatingObject.Item.PhysicalContent.SubtypeName, (decimal)floating.FloatingObject.Item.Amount, contentPath, accumulateUnusedOres, accumulateItems, accumulateComponents);
}
else
{
TallyItems(floating.FloatingObject.Item.Content.TypeId, floating.FloatingObject.Item.Content.SubtypeName, (decimal)floating.FloatingObject.Item.Amount, contentPath, accumulateUsedOres, accumulateItems, accumulateComponents);
TallyItems(floating.FloatingObject.Item.PhysicalContent.TypeId, floating.FloatingObject.Item.PhysicalContent.SubtypeName, (decimal)floating.FloatingObject.Item.Amount, contentPath, accumulateUsedOres, accumulateItems, accumulateComponents);
}
}
else if (entity is StructureCharacterModel)
Expand All @@ -394,7 +392,7 @@ public void GenerateReport()
{
foreach (var item in character.Character.Inventory.Items)
{
TallyItems(item.Content.TypeId, item.Content.SubtypeName, (decimal)item.Amount, contentPath, accumulatePlayerOres, accumulateItems, accumulateComponents);
TallyItems(item.PhysicalContent.TypeId, item.PhysicalContent.SubtypeName, (decimal)item.Amount, contentPath, accumulatePlayerOres, accumulateItems, accumulateComponents);
}
}
}
Expand Down Expand Up @@ -536,17 +534,17 @@ public void GenerateReport()
{
if (isNpc)
{
TallyItems(item.Content.TypeId, item.Content.SubtypeName, (decimal)item.Amount, contentPath, accumulateNpcOres, accumulateItems, accumulateComponents);
TallyItems(item.PhysicalContent.TypeId, item.PhysicalContent.SubtypeName, (decimal)item.Amount, contentPath, accumulateNpcOres, accumulateItems, accumulateComponents);
}
else
{
if (item.Content.TypeId == SpaceEngineersTypes.Ore || item.Content.TypeId == SpaceEngineersTypes.Ingot)
if (item.PhysicalContent.TypeId == SpaceEngineersTypes.Ore || item.PhysicalContent.TypeId == SpaceEngineersTypes.Ingot)
{
TallyItems(item.Content.TypeId, item.Content.SubtypeName, (decimal)item.Amount, contentPath, accumulateUnusedOres, accumulateItems, accumulateComponents);
TallyItems(item.PhysicalContent.TypeId, item.PhysicalContent.SubtypeName, (decimal)item.Amount, contentPath, accumulateUnusedOres, accumulateItems, accumulateComponents);
}
else
{
TallyItems(item.Content.TypeId, item.Content.SubtypeName, (decimal)item.Amount, contentPath, accumulateUsedOres, accumulateItems, accumulateComponents);
TallyItems(item.PhysicalContent.TypeId, item.PhysicalContent.SubtypeName, (decimal)item.Amount, contentPath, accumulateUsedOres, accumulateItems, accumulateComponents);
}
}
}
Expand All @@ -565,7 +563,7 @@ public void GenerateReport()
{
foreach (var item in character.Inventory.Items)
{
TallyItems(item.Content.TypeId, item.Content.SubtypeName, (decimal)item.Amount, contentPath, accumulatePlayerOres, accumulateItems, accumulateComponents);
TallyItems(item.PhysicalContent.TypeId, item.PhysicalContent.SubtypeName, (decimal)item.Amount, contentPath, accumulatePlayerOres, accumulateItems, accumulateComponents);
}
}
}
Expand Down
Loading

0 comments on commit 640cba1

Please sign in to comment.