Merge pull request from GHSA-c8wx-65c7-q9r3

Co-authored-by: Slendy <josh@slendy.pw>
This commit is contained in:
sudokoko 2023-12-23 00:49:59 -05:00 committed by GitHub
commit ef87606ba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41069 additions and 1 deletions

View file

@ -0,0 +1,46 @@
using System.Collections.Immutable;
using LBPUnion.ProjectLighthouse.Files;
using LBPUnion.ProjectLighthouse.Logging;
using LBPUnion.ProjectLighthouse.Types.Logging;
using LBPUnion.ProjectLighthouse.Types.Resources;
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
public static class GameResourceHelper
{
private static readonly ImmutableList<string> textureGuids = ImmutableList<string>.Empty;
static GameResourceHelper()
{
List<string> guids = new();
using Stream? guidStream = typeof(GameResourceHelper).Assembly.GetManifestResourceStream("LBPUnion.ProjectLighthouse.Servers.GameServer.textureGuids.txt");
if (guidStream == null)
{
Logger.Warn("Failed to load texture guids, users may experience issues when setting level and profile icons", LogArea.Startup);
return;
}
using StreamReader reader = new(guidStream);
while (!reader.EndOfStream)
{
string? guid = reader.ReadLine();
if (guid == null) continue;
guids.Add(guid);
}
textureGuids = ImmutableList.Create(guids.ToArray());
}
public static bool IsValidTexture(string resource)
{
if (!FileHelper.IsResourceValid(resource)) return false;
if (resource.StartsWith("g"))
{
return textureGuids.Contains(resource[1..]);
}
return LbpFile.FromHash(resource)?.FileType is LbpFileType.Png or LbpFileType.Jpeg or LbpFileType.Plan
or LbpFileType.Painting or LbpFileType.Texture;
}
}