start modExample 21, fix bundleLoading being Null,

This commit is contained in:
CWX
2025-02-10 18:17:36 +00:00
parent fa179fdb02
commit b572f1da18
8 changed files with 39 additions and 11 deletions
+13 -8
View File
@@ -14,7 +14,7 @@ namespace Core.Loaders
get;
}
public IBundleManifestEntry Bundle
public BundleManifestEntry Bundle
{
get;
}
@@ -31,7 +31,7 @@ namespace Core.Loaders
public BundleInfo(
string modPath,
IBundleManifestEntry bundle,
BundleManifestEntry bundle,
string bundleHash)
{
ModPath = modPath;
@@ -92,14 +92,19 @@ namespace Core.Loaders
// TODO: Implement
var modBundlesJson = _fileUtil.ReadFile(Path.Combine(modPath, "bundles.json"));
var modBundles = _jsonUtil.Deserialize<IBundleManifest>(modBundlesJson);
var modBundles = _jsonUtil.Deserialize<BundleManifest>(modBundlesJson);
var bundleManifestArr = modBundles?.Manifest;
foreach (var bundleManifest in bundleManifestArr)
{
// TODO: complete
var relativeModPath = modPath.Substring(0, -1); //.replace(/\\/g, "/");
var bundleLocalPath = Path.Combine(modPath, "bundles", bundleManifest.Key); //.replace(/\\/g, "/");
// we currently get D:\HomeRepos\SPT-CS-Server\Server\bin\Debug\net9.0/user/mods/Mod3
// we want /user/mods/Mod3
var relativeModPath = modPath.Substring(0, modPath.Length - 1); // /\\/g, "/" - replaces all instances of \\ with /
// we currently get D:\HomeRepos\SPT-CS-Server\Server\bin\Debug\net9.0/user/mods/Mod3/bundles\assets/content/weapons/usable_items/item_bottle/textures/client_assets.bundle
// we want /user/mods/Mod3/bundles\assets/content/weapons/usable_items/item_bottle/textures/client_assets.bundle
var bundleLocalPath = Path.Combine(modPath, "bundles", bundleManifest.Key); // /\\/g, "/" - replaces all instances of \\ with /
if (!_bundleHashCacheService.CalculateAndMatchHash(bundleLocalPath))
{
@@ -123,13 +128,13 @@ namespace Core.Loaders
}
}
public interface IBundleManifest
public record BundleManifest
{
[JsonPropertyName("manifest")]
public List<IBundleManifestEntry> Manifest { get; set; }
public List<BundleManifestEntry> Manifest { get; set; }
}
public interface IBundleManifestEntry
public record BundleManifestEntry
{
[JsonPropertyName("key")]
public string Key {
@@ -11,7 +11,7 @@ namespace Core.Services
private readonly JsonUtil _jsonUtil;
private readonly HashUtil _hashUtil;
private readonly FileUtil _fileUtil;
protected readonly Dictionary<string, string> _bundleHashes;
protected readonly Dictionary<string, string> _bundleHashes = new Dictionary<string, string>();
protected const string _bundleHashCachePath = "./user/cache/bundleHashCache.json";
public BundleHashCacheService(