Skip to content

Commit

Permalink
HOI4 latest version support
Browse files Browse the repository at this point in the history
  • Loading branch information
bcssov committed Feb 12, 2025
1 parent d543c53 commit 55de78a
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 10 deletions.
39 changes: 36 additions & 3 deletions References/CopyAll/Maps/HeartsofIronIVParserMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
}, {
"DirectoryPath": "common\\equipment_groups",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common\\focus_inlay_windows",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\game_rules",
"PreferredParser": "DefaultParser"
Expand Down Expand Up @@ -157,6 +160,12 @@
}, {
"DirectoryPath": "common\\profile_pictures",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\raids",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\raids\\categories",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\resistance_activity",
"PreferredParser": "DefaultParser"
Expand All @@ -169,6 +178,9 @@
}, {
"DirectoryPath": "common\\ribbons",
"PreferredParser": "HOI4InnerLayerParser"
}, {
"DirectoryPath": "common\\scientist_traits",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common\\scorers\\country",
"PreferredParser": "DefaultParser"
Expand All @@ -184,6 +196,21 @@
}, {
"DirectoryPath": "common\\scripted_triggers",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common\\script_constants",
"PreferredParser": "DefaultParser"
}, {
"DirectoryPath": "common\\special_projects\\projects",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\special_projects\\project_tags",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\special_projects\\prototype_rewards",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\special_projects\\specialization",
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "common\\state_category",
"PreferredParser": "HOI4InnerLayerParser"
Expand Down Expand Up @@ -262,6 +289,9 @@
}, {
"DirectoryPath": "dlc\\dlc002_polish_content_pack\\gfx\\models\\units\\pol_dlc",
"PreferredParser": "GenericGraphicsParser"
}, {
"DirectoryPath": "dlc\\dlc002_polish_content_pack\\interface",
"PreferredParser": "GenericGraphicsParser"
}, {
"DirectoryPath": "dlc\\dlc021_anniversary_pack\\portraits",
"PreferredParser": "GenericKeyParser"
Expand Down Expand Up @@ -306,10 +336,10 @@
"PreferredParser": "GenericWholeTextParser"
}, {
"DirectoryPath": "gfx\\particles",
"PreferredParser": "HOI4WholeTextParser"
"PreferredParser": "GenericGraphicsParser"
}, {
"DirectoryPath": "gfx\\particles",
"PreferredParser": "GenericGraphicsParser"
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "gfx\\train_gfx_database",
"PreferredParser": "HOI4WholeTextParser"
Expand Down Expand Up @@ -441,7 +471,7 @@
"PreferredParser": "GenericGraphicsParser"
}, {
"DirectoryPath": "portraits",
"PreferredParser": "GenericKeyParser"
"PreferredParser": "HOI4WholeTextParser"
}, {
"DirectoryPath": "previewer_assets\\assetviewer_interface",
"PreferredParser": "GenericGraphicsParser"
Expand All @@ -457,6 +487,9 @@
}, {
"DirectoryPath": "sound\\gui",
"PreferredParser": "GenericWholeTextParser"
}, {
"DirectoryPath": "sound\\gui\\gtd",
"PreferredParser": "GenericWholeTextParser"
}, {
"DirectoryPath": "tests",
"PreferredParser": "HOI4WholeTextParser"
Expand Down
23 changes: 22 additions & 1 deletion src/IronyModManager.Parser.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-16-2020
//
// Last Modified By : Mario
// Last Modified On : 09-10-2024
// Last Modified On : 02-12-2025
// ***********************************************************************
// <copyright file="Constants.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -251,6 +251,11 @@ public static class HOI4
/// </summary>
public static readonly string DifficultySettings = MergePath(CommonPath, "difficulty_settings");

/// <summary>
/// The focus inlay windows
/// </summary>
public static readonly string FocusInlayWindows = MergePath(CommonPath, "focus_inlay_windows");

/// <summary>
/// The generation
/// </summary>
Expand All @@ -259,6 +264,7 @@ public static class HOI4
/// <summary>
/// The graphical culture type
/// </summary>
// ReSharper disable once StringLiteralTypo -- Please tell me resharper how should I rename a filename that is not under my control
public static readonly string GraphicalCultureType = MergePath(CommonPath, "graphicalculturetype.txt");

/// <summary>
Expand Down Expand Up @@ -306,6 +312,11 @@ public static class HOI4
/// </summary>
public static readonly string PeaceConference = MergePath(CommonPath, "peace_conference");

/// <summary>
/// The portraits
/// </summary>
public static readonly string Portraits = MergePath("portraits");

/// <summary>
/// The profile backgrounds
/// </summary>
Expand All @@ -316,6 +327,11 @@ public static class HOI4
/// </summary>
public static readonly string ProfilePictures = MergePath(CommonPath, "profile_pictures");

/// <summary>
/// The raid categories
/// </summary>
public static readonly string Raids = MergePath(CommonPath, "raids");

/// <summary>
/// The resources
/// </summary>
Expand All @@ -336,6 +352,11 @@ public static class HOI4
/// </summary>
public static readonly string ScriptedGui = MergePath(CommonPath, "scripted_guis");

/// <summary>
/// The special projects
/// </summary>
public static readonly string SpecialProjects = MergePath(CommonPath, "special_projects");

/// <summary>
/// The state categories
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/IronyModManager.Parser.Common/Parsers/BaseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ protected virtual string EvalElementForId(IScriptElement value)
/// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
protected virtual IEnumerable<IDefinition> EvalForErrorsOnly(ParserArgs args)
{
var maxLengthValidation = CodeParser.VerifyAllowedLength(args.Lines);
if (maxLengthValidation != null)
{
return [TranslateScriptError(maxLengthValidation, args)];
}

if (args.ValidationType == ValidationType.SkipAll)
{
return null;
Expand Down
12 changes: 10 additions & 2 deletions src/IronyModManager.Parser.Common/Parsers/ICodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
// Created : 02-22-2020
//
// Last Modified By : Mario
// Last Modified On : 01-29-2022
// Last Modified On : 02-12-2025
// ***********************************************************************
// <copyright file="ICodeParser.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using IronyModManager.Parser.Common.Parsers.Models;

namespace IronyModManager.Parser.Common.Parsers
Expand Down Expand Up @@ -61,7 +63,6 @@ public interface ICodeParser
/// <param name="file">The file.</param>
/// <param name="performSimpleCheck">if set to <c>true</c> [perform simple check].</param>
/// <returns>IParseResponse.</returns>

IParseResponse ParseScript(IEnumerable<string> lines, string file, bool performSimpleCheck = false);

/// <summary>
Expand All @@ -81,6 +82,13 @@ public interface ICodeParser
/// <returns>IScriptError.</returns>
IScriptError PerformValidityCheck(IEnumerable<string> lines, string file, bool performSimpleCheck = false);

/// <summary>
/// Verifies the length of the allowed.
/// </summary>
/// <param name="lines">The lines.</param>
/// <returns>IScriptError.</returns>
IScriptError VerifyAllowedLength(IEnumerable<string> lines);

#endregion Methods
}
}
35 changes: 33 additions & 2 deletions src/IronyModManager.Parser/CodeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-22-2020
//
// Last Modified By : Mario
// Last Modified On : 02-06-2025
// Last Modified On : 02-12-2025
// ***********************************************************************
// <copyright file="CodeParser.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -36,6 +36,11 @@ public class CodeParser : ICodeParser
{
#region Fields

/// <summary>
/// The maximum lines
/// </summary>
protected const int MaxLines = 100000;

/// <summary>
/// The trace back tolerance
/// </summary>
Expand Down Expand Up @@ -283,6 +288,23 @@ public IScriptError PerformValidityCheck(IEnumerable<string> lines, string file,
return null;
}

/// <summary>
/// Verifies the length of the allowed.
/// </summary>
/// <param name="lines">The lines.</param>
/// <returns>IScriptError.</returns>
public IScriptError VerifyAllowedLength(IEnumerable<string> lines)
{
if (lines.Count() > MaxLines)
{
var error = DIResolver.Get<IScriptError>();
error.Message = "File exceeded allowed number of lines.";
return error;
}

return null;
}

/// <summary>
/// Formats the code terminators.
/// </summary>
Expand Down Expand Up @@ -389,7 +411,7 @@ protected IScriptElement GetElement(List<char> code, ref int index)
elOperator = GetElementCharacter(code, index);
}

if (!Common.Constants.Scripts.Operators.Any(p => p == elOperator))
if (Common.Constants.Scripts.Operators.All(p => p != elOperator))
{
if (Common.Constants.Scripts.InlineOperators.Any(p => p.Equals(elKey.Value, StringComparison.OrdinalIgnoreCase)))
{
Expand Down Expand Up @@ -737,11 +759,20 @@ protected void IgnoreElementWhiteSpace(List<char> code, ref int index)
/// <param name="file">The file.</param>
/// <param name="lines">The lines.</param>
/// <returns>IEnumerable&lt;IScriptElement&gt;.</returns>
/// <exception cref="System.ArgumentException"></exception>
protected IEnumerable<IScriptElement> ParseElements(string file, IEnumerable<string> lines)
{
var error = VerifyAllowedLength(lines);
if (error != null)
{
throw new ArgumentException(error.Message);
}

var result = new List<IScriptElement>();
var validCodeLines = CleanCode(file, lines);
var code = string.Join(Environment.NewLine, validCodeLines).ToList();

// ReSharper disable once LoopCanBeConvertedToQuery
for (var i = 0; i < code.Count; i++)
{
var element = GetElement(code, ref i);
Expand Down
7 changes: 5 additions & 2 deletions src/IronyModManager.Parser/Games/HOI4/WholeTextParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 02-18-2020
//
// Last Modified By : Mario
// Last Modified On : 10-17-2024
// Last Modified On : 02-12-2025
// ***********************************************************************
// <copyright file="WholeTextParser.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -44,7 +44,8 @@ public class WholeTextParser : Generic.WholeTextParser, IGameParser
[
Common.Constants.HOI4.Countries, Common.Constants.HOI4.Ideas, Common.Constants.HOI4.AIStrategyPlanes, Common.Constants.HOI4.AIStrategy, Common.Constants.HOI4.IntelligenceAgencies, Common.Constants.HOI4.ScriptedGui,
Common.Constants.HOI4.Units, Common.Constants.HOI4.History, Common.Constants.HOI4.Generation, Common.Constants.HOI4.IdeaTags, Common.Constants.HOI4.Terrain, Common.Constants.HOI4.ProfilePictures,
Common.Constants.HOI4.PeaceConference, Common.Constants.HOI4.ProfileBackgrounds, Common.Constants.HOI4.MIO
Common.Constants.HOI4.PeaceConference, Common.Constants.HOI4.ProfileBackgrounds, Common.Constants.HOI4.MIO, Common.Constants.HOI4.FocusInlayWindows, Common.Constants.HOI4.Raids,
Common.Constants.HOI4.SpecialProjects, Common.Constants.HOI4.Portraits
];

#endregion Fields
Expand All @@ -56,6 +57,8 @@ public class WholeTextParser : Generic.WholeTextParser, IGameParser
/// </summary>
/// <param name="codeParser">The code parser.</param>
/// <param name="logger">The logger.</param>
/// <seealso cref="T:IronyModManager.Parser.Common.Parsers.IDefaultParser" />
/// <remarks>Initializes a new instance of the <see cref="T:IronyModManager.Parser.Common.Parsers.BaseParser" /> class.</remarks>
public WholeTextParser(ICodeParser codeParser, ILogger logger) : base(codeParser, logger)
{
}
Expand Down

0 comments on commit 55de78a

Please sign in to comment.