Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the ChaControl.UpdateWet NullReferenceException
- Loading branch information
1 parent
5607302
commit 9bf7398
Showing
5 changed files
with
189 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using AIChara; | ||
using BepInEx; | ||
using BepInEx.Logging; | ||
using Common; | ||
using HarmonyLib; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
namespace IllusionFixes | ||
{ | ||
[BepInPlugin(GUID, PluginName, Constants.PluginsVersion)] | ||
public class FixUpdateWet : BaseUnityPlugin | ||
{ | ||
public const string GUID = "HS2_Fix_UpdateWet"; | ||
public const string PluginName = "Fix UpdateWet Exceptions"; | ||
|
||
private static FixUpdateWet Instance; | ||
|
||
private ManualLogSource Log => Logger; | ||
|
||
public void Start() | ||
{ | ||
Instance = this; | ||
PatchMe(); | ||
} | ||
|
||
private static void PatchMe() | ||
{ | ||
Harmony harmony = new Harmony(GUID); | ||
harmony.PatchAll(typeof(FixUpdateWet)); | ||
} | ||
|
||
// Some modded items have null renderers in the CmpHair or CmpClothes MB setup | ||
// This is harmless everywhere but throws an error in ChaControl.UpdateWet which causes wet effects to not apply properly and a major logging | ||
// driven performance hit | ||
|
||
// This fixes it by simply removing the non-existent renderer from the array which *I think* is entirely safe...doesn't seem to cause an issue | ||
// I mean, the renderer isn't there anyway...hence it being null ;) | ||
|
||
[HarmonyPrefix, HarmonyPatch(typeof(ChaControl), "UpdateWet")] | ||
static void UpdateWetPreHook(ChaControl __instance) | ||
{ | ||
// Cleanup broken renderers | ||
foreach (CmpHair hair in __instance.cmpHair) | ||
{ | ||
if (hair != null && hair.rendHair != null && hair.rendHair.Contains(null)) | ||
{ | ||
hair.rendHair = hair.rendHair.Where(r => r != null).ToArray(); | ||
} | ||
if (hair != null && hair.rendAccessory != null && hair.rendAccessory.Contains(null)) | ||
{ | ||
hair.rendAccessory = hair.rendAccessory.Where(r => r != null).ToArray(); | ||
} | ||
} | ||
foreach (CmpClothes clothes in __instance.cmpClothes) | ||
{ | ||
if (clothes != null && clothes.rendNormal01 != null && clothes.rendNormal01.Contains(null)) | ||
{ | ||
clothes.rendNormal01 = clothes.rendNormal01.Where(r => r != null).ToArray(); | ||
} | ||
if (clothes != null && clothes.rendNormal02 != null && clothes.rendNormal02.Contains(null)) | ||
{ | ||
clothes.rendNormal02 = clothes.rendNormal02.Where(r => r != null).ToArray(); | ||
} | ||
if (clothes != null && clothes.rendNormal03 != null && clothes.rendNormal03.Contains(null)) | ||
{ | ||
clothes.rendNormal03 = clothes.rendNormal03.Where(r => r != null).ToArray(); | ||
} | ||
} | ||
} | ||
} | ||
} |
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,97 @@ | ||
<?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> | ||
<ProjectGuid>{BDB643DB-EE18-4620-AF42-0BD66B829240}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>IllusionFixes</RootNamespace> | ||
<AssemblyName>HS2_Fix_UpdateWet</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</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;HS2</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>..\..\bin\BepInEx\plugins\IllusionFixes\</OutputPath> | ||
<DefineConstants>TRACE;HS2</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="0Harmony, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.BepInEx.Harmony.2.2.0.1\lib\net35\0Harmony.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp.2020.5.29.2\lib\net46\Assembly-CSharp.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.2020.5.29.2\lib\net46\Assembly-CSharp-firstpass.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="BepInEx, Version=5.4.4.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.BepInEx.5.4.4\lib\net35\BepInEx.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="BepInEx.Harmony, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.BepInEx.Harmony.2.2.0.1\lib\net35\BepInEx.Harmony.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.2\lib\net46\UnityEngine.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.2\lib\net46\UnityEngine.CoreModule.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="FixUpdateWet.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="..\Common\Common.projitems" Label="Shared" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp.targets" Condition="Exists('..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp.targets')" /> | ||
<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.HoneySelect2.Assembly-CSharp.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp.targets'))" /> | ||
<Error Condition="!Exists('..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.targets'))" /> | ||
<Error Condition="!Exists('..\..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.2\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.2\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets'))" /> | ||
<Error Condition="!Exists('..\..\packages\IllusionLibs.BepInEx.Harmony.2.2.0.1\build\IllusionLibs.BepInEx.Harmony.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\IllusionLibs.BepInEx.Harmony.2.2.0.1\build\IllusionLibs.BepInEx.Harmony.targets'))" /> | ||
</Target> | ||
<Import Project="..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.targets" Condition="Exists('..\..\packages\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.2020.5.29.2\build\IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass.targets')" /> | ||
<Import Project="..\..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.2\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets" Condition="Exists('..\..\packages\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.2018.4.11.2\build\IllusionLibs.HoneySelect2.UnityEngine.CoreModule.targets')" /> | ||
<Import Project="..\..\packages\IllusionLibs.BepInEx.Harmony.2.2.0.1\build\IllusionLibs.BepInEx.Harmony.targets" Condition="Exists('..\..\packages\IllusionLibs.BepInEx.Harmony.2.2.0.1\build\IllusionLibs.BepInEx.Harmony.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,5 @@ | ||
using System.Reflection; | ||
|
||
[assembly: AssemblyTitle(IllusionFixes.FixUpdateWet.GUID)] | ||
[assembly: AssemblyProduct(IllusionFixes.FixUpdateWet.GUID)] | ||
[assembly: AssemblyDescription(IllusionFixes.FixUpdateWet.PluginName)] |
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="IllusionLibs.BepInEx" version="5.4.4" targetFramework="net471" /> | ||
<package id="IllusionLibs.BepInEx.Harmony" version="2.2.0.1" targetFramework="net471" /> | ||
<package id="IllusionLibs.HoneySelect2.Assembly-CSharp" version="2020.5.29.2" targetFramework="net471" /> | ||
<package id="IllusionLibs.HoneySelect2.Assembly-CSharp-firstpass" version="2020.5.29.2" targetFramework="net471" /> | ||
<package id="IllusionLibs.HoneySelect2.UnityEngine.CoreModule" version="2018.4.11.2" targetFramework="net471" /> | ||
</packages> |