Skip to content

Commit 279e0ba

Browse files
committed
verify entity name length
1 parent 4df3b3c commit 279e0ba

7 files changed

Lines changed: 46 additions & 3 deletions

File tree

src/ModVerify/Verifiers/CommandBar/CommandBarVerifier.SingleComponent.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AET.ModVerify.Reporting;
2+
using PG.StarWarsGame.Engine;
23
using PG.StarWarsGame.Engine.CommandBar.Components;
34
using System;
45
using System.Threading;
@@ -9,12 +10,24 @@ partial class CommandBarVerifier
910
{
1011
private void VerifySingleComponent(CommandBarBaseComponent component, CancellationToken token)
1112
{
13+
VerifyName(component);
1214
VerifyCommandBarModel(component, token);
1315
VerifyComponentBone(component);
1416

1517
// TODO: Textures
1618
}
1719

20+
private void VerifyName(CommandBarBaseComponent component)
21+
{
22+
if (component.Name.Length > PGConstants.MaxCommandBarComponentNameBuffer)
23+
{
24+
AddError(VerificationError.Create(this, VerifierErrorCodes.NameTooLong,
25+
// Deliberately not reporting the buffer length as max, as it's considered to be internal data
26+
$"The CommandBarShellComponent name '{component.Name}' is too long. Maximum length is {PGConstants.MaxCommandBarComponentName}.",
27+
VerificationSeverity.Critical, [], component.Name));
28+
}
29+
}
30+
1831
private void VerifyCommandBarModel(CommandBarBaseComponent component, CancellationToken token)
1932
{
2033
if (component is not CommandBarShellComponent shellComponent)

src/ModVerify/Verifiers/GameObjects/GameObjectTypeVerifier.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Threading;
3+
using AET.ModVerify.Reporting;
34
using AET.ModVerify.Settings;
45
using AET.ModVerify.Verifiers.Commons;
56
using PG.StarWarsGame.Engine;
@@ -29,6 +30,12 @@ public GameObjectTypeVerifier(
2930

3031
protected override void VerifyEntity(GameObject entity, string[] context, double progress, CancellationToken token)
3132
{
33+
if (entity.Name.Length >= PGConstants.MaxGameObjectTypeName)
34+
{
35+
AddError(VerificationError.Create(this, VerifierErrorCodes.NameTooLong,
36+
$"The GameObjectType name '{entity.Name}' is too long. Maximum length is {PGConstants.MaxGameObjectTypeName}.",
37+
VerificationSeverity.Critical, entity.Name));
38+
}
3239
VerifyXRefs(entity, context);
3340
VerifyModels(entity, context, token);
3441
VerifyIcons(entity, context);

src/ModVerify/Verifiers/SfxEvents/SfxEventVerifier.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
using AET.ModVerify.Settings;
1+
using AET.ModVerify.Reporting;
2+
using AET.ModVerify.Settings;
23
using AET.ModVerify.Verifiers.Commons;
34
using AnakinRaW.CommonUtilities.FileSystem.Normalization;
45
using Microsoft.Extensions.DependencyInjection;
56
using PG.StarWarsGame.Engine;
7+
using PG.StarWarsGame.Engine.Audio.Sfx;
68
using PG.StarWarsGame.Engine.Localization;
79
using System;
810
using System.Collections.Generic;
911
using System.IO.Abstractions;
1012
using System.Threading;
11-
using PG.StarWarsGame.Engine.Audio.Sfx;
1213

1314
namespace AET.ModVerify.Verifiers.SfxEvents;
1415

@@ -45,6 +46,12 @@ public SfxEventVerifier(
4546

4647
protected override void VerifyEntity(SfxEvent entity, string[] context, double progress, CancellationToken token)
4748
{
49+
if (entity.Name.Length >= PGConstants.MaxSFXEventName)
50+
{
51+
AddError(VerificationError.Create(this, VerifierErrorCodes.NameTooLong,
52+
$"The SFXEvent name '{entity.Name}' is too long. Maximum length is {PGConstants.MaxSFXEventName}.",
53+
VerificationSeverity.Critical, entity.Name));
54+
}
4855
VerifyPresetRef(entity, context);
4956
VerifySamples(entity, context, token);
5057
}

src/ModVerify/Verifiers/VerifierErrorCodes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public static class VerifierErrorCodes
2020
public const string Duplicate = "DUP00";
2121
public const string MissingXRef = "XREF00";
2222

23+
public const string NameTooLong = "NAME00";
24+
2325
public const string MissingPreset = "SFX00";
2426

2527
public const string SampleNotPCM = "WAV00";

src/PetroglyphTools/PG.StarWarsGame.Engine/GameObjects/GameObjectTypeGameManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,13 @@ void AddTerrainMappingModels()
7474
}
7575
}
7676
}
77+
78+
public GameObject? FindObjectType(string? name)
79+
{
80+
if (string.IsNullOrEmpty(name))
81+
return null;
82+
var nameCrc = _hashingService.GetCrc32Upper(name, PGConstants.DefaultPGEncoding);
83+
NamedEntries.TryGetFirstValue(nameCrc, out var gameObject);
84+
return gameObject;
85+
}
7786
}

src/PetroglyphTools/PG.StarWarsGame.Engine/GameObjects/IGameObjectTypeGameManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public interface IGameObjectTypeGameManager : IGameManager<GameObject>
2020
/// An <see cref="IEnumerable{T}"/> containing the names of the models associated with the specified <see cref="GameObject"/>.
2121
/// </returns>
2222
IEnumerable<string> GetModels(GameObject gameObject);
23+
24+
GameObject? FindObjectType(string name);
2325
}

src/PetroglyphTools/PG.StarWarsGame.Engine/PGConstants.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ public static class PGConstants
1515
public const int MaxSFXEventDatabaseFileName = 259;
1616
public const int MaxSFXEventName = 255;
1717
public const int MaxGameObjectDatabaseFileName = 127;
18-
public const int MaxCommandBarDatabaseFileName = 259;
18+
public const int MaxCommandBarDatabaseFileName = 271;
1919
public const int MaxCommandBarComponentName = 255;
20+
// The actual engine's buffer size that holds name.
21+
public const int MaxCommandBarComponentNameBuffer = 263;
22+
public const int MaxGameObjectTypeName = 127;
2023

2124
public const int MaxGuiDialogMegaTextureFileName = 255;
2225

0 commit comments

Comments
 (0)