-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SBPR_Fix_ResourceUnloadOptimizations (#38)
- Loading branch information
Showing
7 changed files
with
196 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/SBPR_Fix_ResourceUnloadOptimizations/SBPR.ResourceUnloadOptimizations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using BepInEx; | ||
using Common; | ||
using HarmonyLib; | ||
using System; | ||
using System.Collections; | ||
using UnityEngine; | ||
|
||
namespace IllusionFixes | ||
{ | ||
[BepInProcess(Constants.GameProcessName)] | ||
[BepInProcess(Constants.GameProcessName32bit)] | ||
[BepInPlugin(GUID, PluginName, Constants.PluginsVersion)] | ||
public partial class ResourceUnloadOptimizations : BaseUnityPlugin | ||
{ | ||
public const string GUID = "SBPR_Fix_ResourceUnloadOptimizations"; | ||
|
||
private static Coroutine _currentCleanupAfterLoading = null; | ||
|
||
private static IEnumerator CleanupAfterAsyncLoading() | ||
{ | ||
yield return null; | ||
while (GetIsNowLoadingFade()) | ||
{ | ||
yield return null; | ||
} | ||
|
||
// force a single unload once large load operation finishes | ||
while (_currentOperation != null && !_currentOperation.isDone) | ||
{ | ||
yield return null; | ||
} | ||
_currentOperation = _originalUnload(); | ||
yield return null; | ||
// force GC | ||
GC.Collect(GC.MaxGeneration); | ||
_currentCleanupAfterLoading = null; | ||
} | ||
|
||
partial class Hooks | ||
{ | ||
// deploy happens when: | ||
// - main game save is loaded | ||
// - Time of day changes | ||
// - entering main game map from another scene (h-scene, changing room, etc.) | ||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(SexyBeach.MapScene), nameof(SexyBeach.MapScene.Deploy))] | ||
public static void DeployPostfix(SexyBeach.MapScene __instance) | ||
{ | ||
if (!OptimizeMemoryUsage.Value || __instance == null) return; | ||
if (_currentCleanupAfterLoading != null) __instance.StopCoroutine(_currentCleanupAfterLoading); | ||
_currentCleanupAfterLoading = __instance.StartCoroutine(CleanupAfterAsyncLoading()); | ||
} | ||
|
||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/SBPR_Fix_ResourceUnloadOptimizations/SBPR_Fix_ResourceUnloadOptimizations.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>IllusionFixes</RootNamespace> | ||
<AssemblyName>SBPR_Fix_ResourceUnloadOptimizations</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
<ProjectGuid>{09D5D602-4CFD-43C3-AD7E-58E5072E8127}</ProjectGuid> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>embedded</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\..\bin\BepInEx\plugins\IllusionFixes\</OutputPath> | ||
<DefineConstants>TRACE;DEBUG;SBPR</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>embedded</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>..\..\bin\BepInEx\plugins\IllusionFixes\</OutputPath> | ||
<DefineConstants>TRACE;SBPR</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<DebugSymbols>true</DebugSymbols> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony, Version=2.5.4.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.BepInEx.Harmony.2.5.4\lib\net35\0Harmony.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\..\IllusionLibs\packaging\SexyBeachPR\libraries\Assembly-CSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="BepInEx, Version=5.4.15.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.BepInEx.5.4.15\lib\net35\BepInEx.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="MonoMod.RuntimeDetour, Version=21.8.5.1, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.BepInEx.MonoMod.21.8.5.1\lib\net35\MonoMod.RuntimeDetour.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="MonoMod.Utils, Version=21.8.5.1, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.BepInEx.MonoMod.21.8.5.1\lib\net35\MonoMod.Utils.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\..\IllusionLibs\packaging\SexyBeachPR\libraries\UnityEngine.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="SBPR.ResourceUnloadOptimizations.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Folder Include="Properties\" /> | ||
</ItemGroup> | ||
<Import Project="..\Common\Common.projitems" Label="Shared" /> | ||
<Import Project="..\Core_Fix_ResourceUnloadOptimizations\Core_Fix_ResourceUnloadOptimizations.projitems" Label="Shared" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<PropertyGroup> | ||
<PostBuildEvent>IF EXIST $(SolutionDir)PostBuild.bat CALL "$(SolutionDir)PostBuild.bat" $(TargetPath) SBPR</PostBuildEvent> | ||
</PropertyGroup> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\..\packages\IllusionLibs.BepInEx.Harmony.2.5.4\build\IllusionLibs.BepInEx.Harmony.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\IllusionLibs.BepInEx.Harmony.2.5.4\build\IllusionLibs.BepInEx.Harmony.targets'))" /> | ||
<Error Condition="!Exists('..\..\packages\IllusionLibs.BepInEx.MonoMod.21.8.5.1\build\IllusionLibs.BepInEx.MonoMod.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\IllusionLibs.BepInEx.MonoMod.21.8.5.1\build\IllusionLibs.BepInEx.MonoMod.targets'))" /> | ||
</Target> | ||
<Import Project="..\..\packages\IllusionLibs.BepInEx.Harmony.2.5.4\build\IllusionLibs.BepInEx.Harmony.targets" Condition="Exists('..\..\packages\IllusionLibs.BepInEx.Harmony.2.5.4\build\IllusionLibs.BepInEx.Harmony.targets')" /> | ||
<Import Project="..\..\packages\IllusionLibs.BepInEx.MonoMod.21.8.5.1\build\IllusionLibs.BepInEx.MonoMod.targets" Condition="Exists('..\..\packages\IllusionLibs.BepInEx.MonoMod.21.8.5.1\build\IllusionLibs.BepInEx.MonoMod.targets')" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="IllusionLibs.BepInEx" version="5.4.15" targetFramework="net35" developmentDependency="true" /> | ||
<package id="IllusionLibs.BepInEx.Harmony" version="2.5.4" targetFramework="net35" developmentDependency="true" /> | ||
<package id="IllusionLibs.BepInEx.MonoMod" version="21.8.5.1" targetFramework="net35" developmentDependency="true" /> | ||
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" /> | ||
<package id="MonoMod.RuntimeDetour" version="19.8.2.3" targetFramework="net35" /> | ||
<package id="MonoMod.Utils" version="19.8.2.3" targetFramework="net35" /> | ||
</packages> |