Skip to content

Commit 55de78a

Browse files
committed
HOI4 latest version support
1 parent d543c53 commit 55de78a

File tree

6 files changed

+112
-10
lines changed

6 files changed

+112
-10
lines changed

References/CopyAll/Maps/HeartsofIronIVParserMap.json

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
}, {
8080
"DirectoryPath": "common\\equipment_groups",
8181
"PreferredParser": "DefaultParser"
82+
}, {
83+
"DirectoryPath": "common\\focus_inlay_windows",
84+
"PreferredParser": "HOI4WholeTextParser"
8285
}, {
8386
"DirectoryPath": "common\\game_rules",
8487
"PreferredParser": "DefaultParser"
@@ -157,6 +160,12 @@
157160
}, {
158161
"DirectoryPath": "common\\profile_pictures",
159162
"PreferredParser": "HOI4WholeTextParser"
163+
}, {
164+
"DirectoryPath": "common\\raids",
165+
"PreferredParser": "HOI4WholeTextParser"
166+
}, {
167+
"DirectoryPath": "common\\raids\\categories",
168+
"PreferredParser": "HOI4WholeTextParser"
160169
}, {
161170
"DirectoryPath": "common\\resistance_activity",
162171
"PreferredParser": "DefaultParser"
@@ -169,6 +178,9 @@
169178
}, {
170179
"DirectoryPath": "common\\ribbons",
171180
"PreferredParser": "HOI4InnerLayerParser"
181+
}, {
182+
"DirectoryPath": "common\\scientist_traits",
183+
"PreferredParser": "DefaultParser"
172184
}, {
173185
"DirectoryPath": "common\\scorers\\country",
174186
"PreferredParser": "DefaultParser"
@@ -184,6 +196,21 @@
184196
}, {
185197
"DirectoryPath": "common\\scripted_triggers",
186198
"PreferredParser": "DefaultParser"
199+
}, {
200+
"DirectoryPath": "common\\script_constants",
201+
"PreferredParser": "DefaultParser"
202+
}, {
203+
"DirectoryPath": "common\\special_projects\\projects",
204+
"PreferredParser": "HOI4WholeTextParser"
205+
}, {
206+
"DirectoryPath": "common\\special_projects\\project_tags",
207+
"PreferredParser": "HOI4WholeTextParser"
208+
}, {
209+
"DirectoryPath": "common\\special_projects\\prototype_rewards",
210+
"PreferredParser": "HOI4WholeTextParser"
211+
}, {
212+
"DirectoryPath": "common\\special_projects\\specialization",
213+
"PreferredParser": "HOI4WholeTextParser"
187214
}, {
188215
"DirectoryPath": "common\\state_category",
189216
"PreferredParser": "HOI4InnerLayerParser"
@@ -262,6 +289,9 @@
262289
}, {
263290
"DirectoryPath": "dlc\\dlc002_polish_content_pack\\gfx\\models\\units\\pol_dlc",
264291
"PreferredParser": "GenericGraphicsParser"
292+
}, {
293+
"DirectoryPath": "dlc\\dlc002_polish_content_pack\\interface",
294+
"PreferredParser": "GenericGraphicsParser"
265295
}, {
266296
"DirectoryPath": "dlc\\dlc021_anniversary_pack\\portraits",
267297
"PreferredParser": "GenericKeyParser"
@@ -306,10 +336,10 @@
306336
"PreferredParser": "GenericWholeTextParser"
307337
}, {
308338
"DirectoryPath": "gfx\\particles",
309-
"PreferredParser": "HOI4WholeTextParser"
339+
"PreferredParser": "GenericGraphicsParser"
310340
}, {
311341
"DirectoryPath": "gfx\\particles",
312-
"PreferredParser": "GenericGraphicsParser"
342+
"PreferredParser": "HOI4WholeTextParser"
313343
}, {
314344
"DirectoryPath": "gfx\\train_gfx_database",
315345
"PreferredParser": "HOI4WholeTextParser"
@@ -441,7 +471,7 @@
441471
"PreferredParser": "GenericGraphicsParser"
442472
}, {
443473
"DirectoryPath": "portraits",
444-
"PreferredParser": "GenericKeyParser"
474+
"PreferredParser": "HOI4WholeTextParser"
445475
}, {
446476
"DirectoryPath": "previewer_assets\\assetviewer_interface",
447477
"PreferredParser": "GenericGraphicsParser"
@@ -457,6 +487,9 @@
457487
}, {
458488
"DirectoryPath": "sound\\gui",
459489
"PreferredParser": "GenericWholeTextParser"
490+
}, {
491+
"DirectoryPath": "sound\\gui\\gtd",
492+
"PreferredParser": "GenericWholeTextParser"
460493
}, {
461494
"DirectoryPath": "tests",
462495
"PreferredParser": "HOI4WholeTextParser"

src/IronyModManager.Parser.Common/Constants.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Created : 02-16-2020
55
//
66
// Last Modified By : Mario
7-
// Last Modified On : 09-10-2024
7+
// Last Modified On : 02-12-2025
88
// ***********************************************************************
99
// <copyright file="Constants.cs" company="Mario">
1010
// Mario
@@ -251,6 +251,11 @@ public static class HOI4
251251
/// </summary>
252252
public static readonly string DifficultySettings = MergePath(CommonPath, "difficulty_settings");
253253

254+
/// <summary>
255+
/// The focus inlay windows
256+
/// </summary>
257+
public static readonly string FocusInlayWindows = MergePath(CommonPath, "focus_inlay_windows");
258+
254259
/// <summary>
255260
/// The generation
256261
/// </summary>
@@ -259,6 +264,7 @@ public static class HOI4
259264
/// <summary>
260265
/// The graphical culture type
261266
/// </summary>
267+
// ReSharper disable once StringLiteralTypo -- Please tell me resharper how should I rename a filename that is not under my control
262268
public static readonly string GraphicalCultureType = MergePath(CommonPath, "graphicalculturetype.txt");
263269

264270
/// <summary>
@@ -306,6 +312,11 @@ public static class HOI4
306312
/// </summary>
307313
public static readonly string PeaceConference = MergePath(CommonPath, "peace_conference");
308314

315+
/// <summary>
316+
/// The portraits
317+
/// </summary>
318+
public static readonly string Portraits = MergePath("portraits");
319+
309320
/// <summary>
310321
/// The profile backgrounds
311322
/// </summary>
@@ -316,6 +327,11 @@ public static class HOI4
316327
/// </summary>
317328
public static readonly string ProfilePictures = MergePath(CommonPath, "profile_pictures");
318329

330+
/// <summary>
331+
/// The raid categories
332+
/// </summary>
333+
public static readonly string Raids = MergePath(CommonPath, "raids");
334+
319335
/// <summary>
320336
/// The resources
321337
/// </summary>
@@ -336,6 +352,11 @@ public static class HOI4
336352
/// </summary>
337353
public static readonly string ScriptedGui = MergePath(CommonPath, "scripted_guis");
338354

355+
/// <summary>
356+
/// The special projects
357+
/// </summary>
358+
public static readonly string SpecialProjects = MergePath(CommonPath, "special_projects");
359+
339360
/// <summary>
340361
/// The state categories
341362
/// </summary>

src/IronyModManager.Parser.Common/Parsers/BaseParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ protected virtual string EvalElementForId(IScriptElement value)
159159
/// <returns>IEnumerable&lt;IDefinition&gt;.</returns>
160160
protected virtual IEnumerable<IDefinition> EvalForErrorsOnly(ParserArgs args)
161161
{
162+
var maxLengthValidation = CodeParser.VerifyAllowedLength(args.Lines);
163+
if (maxLengthValidation != null)
164+
{
165+
return [TranslateScriptError(maxLengthValidation, args)];
166+
}
167+
162168
if (args.ValidationType == ValidationType.SkipAll)
163169
{
164170
return null;

src/IronyModManager.Parser.Common/Parsers/ICodeParser.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
// Created : 02-22-2020
55
//
66
// Last Modified By : Mario
7-
// Last Modified On : 01-29-2022
7+
// Last Modified On : 02-12-2025
88
// ***********************************************************************
99
// <copyright file="ICodeParser.cs" company="Mario">
1010
// Mario
1111
// </copyright>
1212
// <summary></summary>
1313
// ***********************************************************************
14+
1415
using System;
1516
using System.Collections.Generic;
17+
using System.Linq;
1618
using IronyModManager.Parser.Common.Parsers.Models;
1719

1820
namespace IronyModManager.Parser.Common.Parsers
@@ -61,7 +63,6 @@ public interface ICodeParser
6163
/// <param name="file">The file.</param>
6264
/// <param name="performSimpleCheck">if set to <c>true</c> [perform simple check].</param>
6365
/// <returns>IParseResponse.</returns>
64-
6566
IParseResponse ParseScript(IEnumerable<string> lines, string file, bool performSimpleCheck = false);
6667

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

85+
/// <summary>
86+
/// Verifies the length of the allowed.
87+
/// </summary>
88+
/// <param name="lines">The lines.</param>
89+
/// <returns>IScriptError.</returns>
90+
IScriptError VerifyAllowedLength(IEnumerable<string> lines);
91+
8492
#endregion Methods
8593
}
8694
}

src/IronyModManager.Parser/CodeParser.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Created : 02-22-2020
55
//
66
// Last Modified By : Mario
7-
// Last Modified On : 02-06-2025
7+
// Last Modified On : 02-12-2025
88
// ***********************************************************************
99
// <copyright file="CodeParser.cs" company="Mario">
1010
// Mario
@@ -36,6 +36,11 @@ public class CodeParser : ICodeParser
3636
{
3737
#region Fields
3838

39+
/// <summary>
40+
/// The maximum lines
41+
/// </summary>
42+
protected const int MaxLines = 100000;
43+
3944
/// <summary>
4045
/// The trace back tolerance
4146
/// </summary>
@@ -283,6 +288,23 @@ public IScriptError PerformValidityCheck(IEnumerable<string> lines, string file,
283288
return null;
284289
}
285290

291+
/// <summary>
292+
/// Verifies the length of the allowed.
293+
/// </summary>
294+
/// <param name="lines">The lines.</param>
295+
/// <returns>IScriptError.</returns>
296+
public IScriptError VerifyAllowedLength(IEnumerable<string> lines)
297+
{
298+
if (lines.Count() > MaxLines)
299+
{
300+
var error = DIResolver.Get<IScriptError>();
301+
error.Message = "File exceeded allowed number of lines.";
302+
return error;
303+
}
304+
305+
return null;
306+
}
307+
286308
/// <summary>
287309
/// Formats the code terminators.
288310
/// </summary>
@@ -389,7 +411,7 @@ protected IScriptElement GetElement(List<char> code, ref int index)
389411
elOperator = GetElementCharacter(code, index);
390412
}
391413

392-
if (!Common.Constants.Scripts.Operators.Any(p => p == elOperator))
414+
if (Common.Constants.Scripts.Operators.All(p => p != elOperator))
393415
{
394416
if (Common.Constants.Scripts.InlineOperators.Any(p => p.Equals(elKey.Value, StringComparison.OrdinalIgnoreCase)))
395417
{
@@ -737,11 +759,20 @@ protected void IgnoreElementWhiteSpace(List<char> code, ref int index)
737759
/// <param name="file">The file.</param>
738760
/// <param name="lines">The lines.</param>
739761
/// <returns>IEnumerable&lt;IScriptElement&gt;.</returns>
762+
/// <exception cref="System.ArgumentException"></exception>
740763
protected IEnumerable<IScriptElement> ParseElements(string file, IEnumerable<string> lines)
741764
{
765+
var error = VerifyAllowedLength(lines);
766+
if (error != null)
767+
{
768+
throw new ArgumentException(error.Message);
769+
}
770+
742771
var result = new List<IScriptElement>();
743772
var validCodeLines = CleanCode(file, lines);
744773
var code = string.Join(Environment.NewLine, validCodeLines).ToList();
774+
775+
// ReSharper disable once LoopCanBeConvertedToQuery
745776
for (var i = 0; i < code.Count; i++)
746777
{
747778
var element = GetElement(code, ref i);

src/IronyModManager.Parser/Games/HOI4/WholeTextParser.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Created : 02-18-2020
55
//
66
// Last Modified By : Mario
7-
// Last Modified On : 10-17-2024
7+
// Last Modified On : 02-12-2025
88
// ***********************************************************************
99
// <copyright file="WholeTextParser.cs" company="Mario">
1010
// Mario
@@ -44,7 +44,8 @@ public class WholeTextParser : Generic.WholeTextParser, IGameParser
4444
[
4545
Common.Constants.HOI4.Countries, Common.Constants.HOI4.Ideas, Common.Constants.HOI4.AIStrategyPlanes, Common.Constants.HOI4.AIStrategy, Common.Constants.HOI4.IntelligenceAgencies, Common.Constants.HOI4.ScriptedGui,
4646
Common.Constants.HOI4.Units, Common.Constants.HOI4.History, Common.Constants.HOI4.Generation, Common.Constants.HOI4.IdeaTags, Common.Constants.HOI4.Terrain, Common.Constants.HOI4.ProfilePictures,
47-
Common.Constants.HOI4.PeaceConference, Common.Constants.HOI4.ProfileBackgrounds, Common.Constants.HOI4.MIO
47+
Common.Constants.HOI4.PeaceConference, Common.Constants.HOI4.ProfileBackgrounds, Common.Constants.HOI4.MIO, Common.Constants.HOI4.FocusInlayWindows, Common.Constants.HOI4.Raids,
48+
Common.Constants.HOI4.SpecialProjects, Common.Constants.HOI4.Portraits
4849
];
4950

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

0 commit comments

Comments
 (0)