Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AssetHelper/AssetHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<ItemGroup>
<PackageReference Include="AssetsTools.NET" Version="3.0.3" GeneratePathProperty="true" />
<PackageReference Include="AssetHelperLib" Version="0.10.1" GeneratePathProperty="true" />
<PackageReference Include="AssetHelperLib" Version="0.11.0" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions AssetHelper/Core/BundleMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using AssetHelperLib.IO;
using AssetsTools.NET;
using AssetsTools.NET.Extra;
using Silksong.AssetHelper.Internal;
Expand Down Expand Up @@ -113,8 +114,8 @@ internal static List<string> DetermineDirectDepsInternal(string bundleName, out

AssetsManager mgr = new();
string sceneBundlePath = Path.Combine(AssetPaths.BundleFolder, bundleFile);
using MemoryStream ms = new(File.ReadAllBytes(sceneBundlePath));
BundleFileInstance bun = mgr.LoadBundleFile(ms, sceneBundlePath);
using RentedFileArray rfa = new(sceneBundlePath);
BundleFileInstance bun = mgr.LoadBundleFile(rfa.Stream, sceneBundlePath);

AssetsFileInstance afileInst = mgr.LoadAssetsFileFromBundle(bun, 0, false);
AssetsFile afile = afileInst.file;
Expand Down
23 changes: 23 additions & 0 deletions AssetHelper/Plugin/LoadingPage/LoadingScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ void Awake()
subtextRect.anchoredPosition = new Vector2(0, -45);
}

#if DEBUG
{
GameObject memTextObj = new("MemText");
memTextObj.transform.SetParent(_canvasObject.transform);
Text _memText = memTextObj.AddComponent<Text>();

_memText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
_memText.text = string.Empty;
_memText.fontSize = 20;
_memText.alignment = TextAnchor.MiddleCenter;
_memText.color = Color.white;

RectTransform memtextRect = _memText.rectTransform;
memtextRect.anchorMin = new Vector2(0.5f, 0.5f);
memtextRect.anchorMax = new Vector2(0.5f, 0.5f);
memtextRect.pivot = new Vector2(0.5f, 1f);
memtextRect.sizeDelta = new Vector2(800, 100);
memtextRect.anchoredPosition = new Vector2(0, -90);

memTextObj.AddComponent<MemoryWatcher>();
}
#endif

// For testing
_statusText.text = "Loading...";
}
Expand Down
29 changes: 29 additions & 0 deletions AssetHelper/Plugin/LoadingPage/MemoryWatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using UnityEngine;
using UnityEngine.UI;

namespace Silksong.AssetHelper.Plugin.LoadingPage;


/// <summary>
/// Unscientific class to watch memory usage.
/// </summary>
[RequireComponent(typeof(Text))]
internal class MemoryWatcher : MonoBehaviour
{
private long maxSoFar = 0;

private Text _text;

void Awake()
{
_text = GetComponent<Text>();
}

void Update()
{
long mem = GC.GetTotalMemory(forceFullCollection: false);
maxSoFar = mem > maxSoFar ? mem : maxSoFar;
_text.text = $"Memory: {mem:E}\nMax {maxSoFar:E}";
}
}
9 changes: 9 additions & 0 deletions AssetHelper/Plugin/StartupOverrideManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using AssetHelperLib.IO;
using MonoDetour.HookGen;
using Silksong.AssetHelper.Core;
using Silksong.AssetHelper.Plugin.LoadingPage;
Expand Down Expand Up @@ -43,6 +45,9 @@ private static IEnumerator WrapStartManagerStart(StartManager self, IEnumerator
// This should already be the case, but we should check just in case it matters.
yield return new WaitUntil(() => AddressablesData.IsAddressablesLoaded);

// Assign the shared array pool for IO at the start of the procedure
RentedFileArray.Pool = ArrayPool<byte>.Create(250 * 1024 * 1024, 5);

LoadingScreen screen = LoadingScreenExtensions.Create<LoadingScreen>();

bool failed = false;
Expand Down Expand Up @@ -98,6 +103,10 @@ private static IEnumerator WrapStartManagerStart(StartManager self, IEnumerator

// Even if there was an error, still let them into the game normally
UObject.Destroy(screen);

// Clear the pool now that it's no longer in use; in theory the GC can reclaim it/when if it wants.
RentedFileArray.Pool = null;

yield return null;

yield return original;
Expand Down
6 changes: 3 additions & 3 deletions AssetHelper/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
".NETStandard,Version=v2.1": {
"AssetHelperLib": {
"type": "Direct",
"requested": "[0.10.1, )",
"resolved": "0.10.1",
"contentHash": "qRX+I2d6T0WVcJrxPV7bBlGD37B1Eg5GAo36+72lXOJqgHjhnJrgOcnqtwm9vRaOaBfnzMV3f8+myTioLeT9cw=="
"requested": "[0.11.0, )",
"resolved": "0.11.0",
"contentHash": "1YIHnp3S+gBLa1NzFTtSmMFA+zT7D0mCgCPqPhVa4pv5CKpJQgSiZPeiRxzMDvDMK0sdGa6O6/Uuh1pPIrBYlw=="
},
"AssetsTools.NET": {
"type": "Direct",
Expand Down