Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Improved log output for mod loading #527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 26 additions & 16 deletions Sources/Sandbox.Game/Definitions/MyDefinitionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ private static void FailModLoading(MyModContext context, int phase = -1, int pha
MyDefinitionErrors.Add(context, "MOD SKIPPED, Cannot load definition file, see log for details", TErrorSeverity.Critical);
else
MyDefinitionErrors.Add(context, String.Format("MOD PARTIALLY SKIPPED, LOADED ONLY {0}/{1} PHASES, see logfile for details", phase + 1, phaseNum), TErrorSeverity.Critical);

if (context.IsBaseGame)
{
// When original definition fails to load, return to main menu
Expand Down Expand Up @@ -1153,9 +1152,8 @@ void LoadPhase3(MyObjectBuilder_Definitions objBuilder, MyModContext context, De
{
MySandboxGame.Log.WriteLine("Loading cube blocks");
InitCubeBlocks(context, definitionSet.m_blockPositions, objBuilder.CubeBlocks);

ToDefinitions(context, definitionSet.m_definitionsById, definitionSet.m_uniqueCubeBlocksBySize, objBuilder.CubeBlocks, failOnDebug);

MySandboxGame.Log.WriteLine("Created block definitions");
foreach (var size in definitionSet.m_uniqueCubeBlocksBySize)
PrepareBlockBlueprints(context, definitionSet.m_blueprintsById, size);
}
Expand All @@ -1167,7 +1165,7 @@ void LoadPhase4(MyObjectBuilder_Definitions objBuilder, MyModContext context, De
{
if (MySandboxGame.Static != null)
{
MySandboxGame.Log.WriteLine("Loading prefabs");
MySandboxGame.Log.WriteLine("Loading Prefab: " + context.CurrentFile);
InitPrefabs(context, definitionSet.m_prefabs, objBuilder.Prefabs, failOnDebug);
}
}
Expand Down Expand Up @@ -2030,6 +2028,10 @@ private static void InitComponents(MyModContext context,
Check(res[i].Id.TypeId == typeof(MyObjectBuilder_Component), res[i].Id.TypeId, failOnDebug, UNKNOWN_ENTRY_MESSAGE);
Check(!output.ContainsKey(res[i].Id), res[i].Id, failOnDebug);
output[res[i].Id] = res[i];
if (!context.IsBaseGame)
{
MySandboxGame.Log.WriteLine("Loaded component: " + res[i].Id);
}
}
}

Expand Down Expand Up @@ -2146,7 +2148,10 @@ private static void PrepareBlockBlueprints(MyModContext context,
foreach (var entry in cubeBlocks)
{
var cubeBlock = entry.Value;

if (!context.IsBaseGame)
{
MySandboxGame.Log.WriteLine("Loading cube block: " + entry.Key);
}
if (!MyFakes.ENABLE_NON_PUBLIC_BLOCKS && cubeBlock.Public == false) continue;

var uniqueCubeBlock = cubeBlock.UniqueVersion;
Expand Down Expand Up @@ -2608,6 +2613,10 @@ private static void InitVoxelMaterials(MyModContext context,

Check(!output.ContainsKey(res[i].Id.SubtypeName), res[i].Id.SubtypeName, failOnDebug);
output[res[i].Id.SubtypeName] = res[i];
if (!context.IsBaseGame)
{
MySandboxGame.Log.WriteLine("Loaded voxel material: " + res[i].Id.SubtypeName);
}
}
}

Expand Down Expand Up @@ -3995,18 +4004,18 @@ private static void ToDefinitions(MyModContext context,
for (int i = 0; i < cubeBlocks.Length; ++i)
{
var currentDef = cubeBlocks[i];

var result = InitDefinition<MyCubeBlockDefinition>(context, currentDef);
result.UniqueVersion = result;

// add to cubeBlocks without variant
Debug.Assert((int)result.CubeSize < outputCubeBlocks.Length, "CubeSize >= cubeBlocksBySize.Length");
outputCubeBlocks[(int)result.CubeSize][result.Id] = result;

// add to definitions (including variants for backward compatibility)
Check(!outputDefinitions.ContainsKey(result.Id), result.Id, failOnDebug);
outputDefinitions[result.Id] = result;

if (!context.IsBaseGame)
{
MySandboxGame.Log.WriteLine("Created definition for: " + result.DisplayNameText);
}
//if (currentDef.Variants != null)
//{
// result.Color = Color.Gray;
Expand Down Expand Up @@ -4039,12 +4048,10 @@ private static T InitDefinition<T>(MyModContext context, MyObjectBuilder_Definit
UpdateModableContent(result.Context, builder);

result.Init(builder, result.Context);

if (MyFakes.ENABLE_ALL_IN_SURVIVAL)
{
result.AvailableInSurvival = true;
}

return result;
}

Expand All @@ -4065,7 +4072,7 @@ private static void ProcessField(MyModContext context, object fieldOwnerInstance
if (extensions.Length > 0 && field.FieldType == typeof(string))
{
string contentFile = (string)field.GetValue(fieldOwnerInstance);
ProcessContentFilePath(context, ref contentFile, extensions);
ProcessContentFilePath(context, ref contentFile, extensions, true);
field.SetValue(fieldOwnerInstance, contentFile);
}
else if(field.FieldType == typeof(string[]))
Expand All @@ -4075,7 +4082,7 @@ private static void ProcessField(MyModContext context, object fieldOwnerInstance
if (stringArray != null)
{
for (int fileIndex = 0; fileIndex < stringArray.Length; ++fileIndex)
ProcessContentFilePath(context, ref stringArray[fileIndex], extensions);
ProcessContentFilePath(context, ref stringArray[fileIndex], extensions, false);

field.SetValue(fieldOwnerInstance, stringArray);
}
Expand Down Expand Up @@ -4105,7 +4112,7 @@ private static void ProcessField(MyModContext context, object fieldOwnerInstance
}
}

private static void ProcessContentFilePath(MyModContext context, ref string contentFile, object[] extensions)
private static void ProcessContentFilePath(MyModContext context, ref string contentFile, object[] extensions, bool logNoExtensions)
{
if (string.IsNullOrEmpty(contentFile))
return;
Expand All @@ -4114,7 +4121,10 @@ private static void ProcessContentFilePath(MyModContext context, ref string cont

if (extensions.IsNullOrEmpty())
{
MyDefinitionErrors.Add(context, "None file extensions.", TErrorSeverity.Warning);
if (logNoExtensions)
{
MyDefinitionErrors.Add(context, "No file extensions.", TErrorSeverity.Warning);
}
return;
}

Expand Down Expand Up @@ -4145,6 +4155,7 @@ private static void ProcessContentFilePath(MyModContext context, ref string cont
}
else
{
MyDefinitionErrors.Add(context, "Resource not found, setting to null or error model. Resource name: " + contentFile, TErrorSeverity.Error);
if (contentFile.EndsWith(".mwm"))
{
contentFile = @"Models\Debug\Error.mwm";
Expand All @@ -4153,7 +4164,6 @@ private static void ProcessContentFilePath(MyModContext context, ref string cont
{
contentFile = null;
}
MyDefinitionErrors.Add(context, "Resource not found, setting to null or error model: " + contentFile, TErrorSeverity.Error);
}
}

Expand Down