Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using Sandbox.Definitions;
using System.Collections.Generic;
using Sandbox.ModAPI;
using VRage.Game.Components;
using VRage.Network;
using VRage.Utils;

namespace SC.FixBlockCategories
{
[MySessionComponentDescriptor(MyUpdateOrder.NoUpdate, int.MaxValue)] // load last
internal class MainSession : MySessionComponentBase
{
private HashSet<string> _nullSubtypes = new HashSet<string>();
private Dictionary<string, string> _subtypeToTypePairing = new Dictionary<string, string>();

public override void LoadData()
{
MyLog.Default.WriteLineAndConsole($"[FixBlockCategories] Start check...");

_subtypeToTypePairing = new Dictionary<string, string>();
foreach (var def in MyDefinitionManager.Static.GetAllDefinitions())
{
var blockdef = def as MyCubeBlockDefinition;
if (blockdef == null)
continue;

if (string.IsNullOrEmpty(blockdef.Id.SubtypeName))
{
_nullSubtypes.Add(blockdef.Id.TypeId.ToString().Replace("MyObjectBuilder_", ""));
continue;
}

_subtypeToTypePairing[blockdef.Id.SubtypeName] = blockdef.Id.TypeId.ToString().Replace("MyObjectBuilder_", "");
}

foreach (var catdef in MyDefinitionManager.Static.GetCategories().Values)
{
MyLog.Default.WriteLineAndConsole($"[FixBlockCategories] CHK {catdef.Name}");
var replaced = new HashSet<string>();
foreach (var item in catdef.ItemIds)
{
var name = FixItemName(catdef.Name, item);
if (name != null)
replaced.Add(name);
}
catdef.ItemIds = replaced;
}

MyLog.Default.WriteLineAndConsole($"[FixBlockCategories] Finished.");
}

private string FixItemName(string categoryName, string subtypeId)
{
// already valid
if (subtypeId.Contains("/"))
return subtypeId;

string typeId;
if (_subtypeToTypePairing.TryGetValue(subtypeId, out typeId)) // keen broke block category items with just subtypeid
{
MyLog.Default.WriteLineAndConsole($"[FixBlockCategories] Replaced {categoryName}::{typeId + "/" + subtypeId}");
return typeId + "/" + subtypeId;
}
else if (_nullSubtypes.Contains(subtypeId))
{
// subtype-less blocks (i.e. gravity generator)
MyLog.Default.WriteLineAndConsole($"[FixBlockCategories] Replaced {categoryName}::{subtypeId + "/(null)"}");
return subtypeId + "/(null)";
}

MyLog.Default.WriteLineAndConsole($"[FixBlockCategories] Removed {categoryName}::{subtypeId} (does the block exist?)");
return null;
}
}
}
4 changes: 4 additions & 0 deletions Utility Mods/FixBlockCategories/metadata.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<ModMetadata xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ModVersion>1.0</ModVersion>
</ModMetadata>
11 changes: 11 additions & 0 deletions Utility Mods/FixBlockCategories/modinfo_main.sbmi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<MyObjectBuilder_ModInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SteamIDOwner>76561198274566684</SteamIDOwner>
<WorkshopId>0</WorkshopId>
<WorkshopIds>
<WorkshopId>
<Id>3473465973</Id>
<ServiceName>Steam</ServiceName>
</WorkshopId>
</WorkshopIds>
</MyObjectBuilder_ModInfo>
Binary file added Utility Mods/FixBlockCategories/thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.