Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
FairBear committed Jun 8, 2020
1 parent aa1d884 commit e94ce4e
Show file tree
Hide file tree
Showing 11 changed files with 590 additions and 0 deletions.
114 changes: 114 additions & 0 deletions BoobController.cs
@@ -0,0 +1,114 @@
using ExtensibleSaveFormat;
using KKAPI;
using KKAPI.Chara;
using KKAPI.Maker;
using System.Collections.Generic;
using UnityEngine;

namespace HS2_BoobSettings
{
public class BoobController : CharaCustomFunctionController
{
public const string OVERRIDE_PHYSICS = "overridePhysics";
public const string DAMPING = "damping";
public const string ELASTICITY = "elasticity";
public const string STIFFNESS = "stiffness";
public const string INERT = "inert";

public const string OVERRIDE_GRAVITY = "overrideGravity";
public const string GRAVITY_X = "gravityX";
public const string GRAVITY_Y = "gravityY";
public const string GRAVITY_Z = "gravityZ";

public bool overridePhysics;
public float damping;
public float elasticity;
public float stiffness;
public float inert;

public bool overrideGravity;
public float gravityX;
public float gravityY;
public float gravityZ;

protected override void OnCardBeingSaved(GameMode currentGameMode)
{
PluginData data = new PluginData
{
data =
{
{ OVERRIDE_PHYSICS, overridePhysics },
{ DAMPING, damping },
{ ELASTICITY, elasticity },
{ STIFFNESS, stiffness },
{ INERT, inert },

{ OVERRIDE_GRAVITY, overrideGravity },
{ GRAVITY_X, gravityX },
{ GRAVITY_Y, gravityY },
{ GRAVITY_Z, gravityZ }
}
};

SetExtendedData(data);
}

protected override void OnReload(GameMode currentGameMode, bool maintainState)
{
Dictionary<string, object> data = GetExtendedData()?.data;

data.TryGetValue(OVERRIDE_PHYSICS, out overridePhysics, false);
data.TryGetValue(DAMPING, out damping, 0.14f);
data.TryGetValue(ELASTICITY, out elasticity, 0.17f);
data.TryGetValue(STIFFNESS, out stiffness, 0.5f);
data.TryGetValue(INERT, out inert, 0.8f);

data.TryGetValue(OVERRIDE_GRAVITY, out overrideGravity, false);
data.TryGetValue(GRAVITY_X, out gravityX, 0f);
data.TryGetValue(GRAVITY_Y, out gravityY, -0.0003f);
data.TryGetValue(GRAVITY_Z, out gravityZ, 0f);

if (MakerAPI.InsideAndLoaded &&
MakerAPI.GetCharacterLoadFlags().Body &&
MakerAPI.GetMakerBase().chaCtrl == ChaControl)
HS2_BoobSettings.MakerAPI_Update(this);
}

public void UpdateBone(DynamicBone_Ver02 bone)
{
if (bone == null)
return;

UpdateSoftness(bone);
UpdateWeight(bone);
}

public void UpdateSoftness(DynamicBone_Ver02 bone)
{
if (!overridePhysics)
return;

DynamicBone_Ver02.Particle particle;

for (int i = 0; (particle = bone.getParticle(i)) != null; i++)
{
particle.Damping = damping;
particle.Elasticity = elasticity;
particle.Stiffness = stiffness;
particle.Inert = inert;
}
}

public void UpdateWeight(DynamicBone_Ver02 bone)
{
if (!overrideGravity)
return;

Vector3 gravity = new Vector3(gravityX, gravityY, gravityZ);
bone.Gravity = gravity;

foreach (DynamicBone_Ver02.BonePtn v in bone.Patterns)
v.Gravity = gravity;
}
}
}
19 changes: 19 additions & 0 deletions Extensions.cs
@@ -0,0 +1,19 @@
using System.Collections.Generic;

namespace HS2_BoobSettings
{
public static class Extensions
{
public static bool TryGetValue<T>(this Dictionary<string, object> data, string key, out T value, T defaultValue)
{
if (data != null && data.TryGetValue(key, out object __value) && __value is T _value)
{
value = _value;
return true;
}

value = defaultValue;
return false;
}
}
}
38 changes: 38 additions & 0 deletions HS2_BoobSettings.cs
@@ -0,0 +1,38 @@
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Harmony;
using KKAPI.Chara;
using KKAPI.Maker;

namespace HS2_BoobSettings
{
[BepInProcess("HoneySelect2")]
[BepInProcess("StudioNEOV2")]
[BepInPlugin(GUID, Name, Version)]
public partial class HS2_BoobSettings : BaseUnityPlugin
{
const string GUID = "com.fairbair.hs2_boobsettings";
const string Name = "HS2 Boob Settings";
const string Version = "1.0.0";


const string SECTION_GENERAL = "General";


public static ConfigEntry<float> SliderMin { get; set; }
public static ConfigEntry<float> SliderMax { get; set; }

public void Awake()
{
SliderMin = Config.Bind(SECTION_GENERAL, "Slider Min. Value", -100f);
SliderMax = Config.Bind(SECTION_GENERAL, "Slider Max. Value", 100f);


MakerAPI.RegisterCustomSubCategories += MakerAPI_RegisterCustomSubCategories;
MakerAPI.MakerFinishedLoading += MakerAPI_MakerFinishedLoading;

CharacterApi.RegisterExtraBehaviour<BoobController>(GUID);
HarmonyWrapper.PatchAll(typeof(HS2_BoobSettings));
}
}
}
81 changes: 81 additions & 0 deletions HS2_BoobSettings.csproj
@@ -0,0 +1,81 @@
<?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>{5C2C91EA-F206-4FC9-951F-C04FFA20C2EB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HS2_BoobSettings</RootNamespace>
<AssemblyName>HS2_BoobSettings</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>F:\illusion\HoneySelect2\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>F:\illusion\HoneySelect2\HoneySelect2_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>F:\illusion\HoneySelect2\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="BepInEx.Harmony">
<HintPath>F:\illusion\HoneySelect2\BepInEx\core\BepInEx.Harmony.dll</HintPath>
</Reference>
<Reference Include="HS2API">
<HintPath>F:\illusion\HoneySelect2\BepInEx\plugins\HS2API.dll</HintPath>
</Reference>
<Reference Include="HS2_ExtensibleSaveFormat">
<HintPath>F:\illusion\HoneySelect2\BepInEx\plugins\HS2_BepisPlugins\HS2_ExtensibleSaveFormat.dll</HintPath>
</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="UniRx, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>F:\illusion\HoneySelect2\HoneySelect2_Data\Managed\UniRx.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>F:\illusion\HoneySelect2\HoneySelect2_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>F:\illusion\HoneySelect2\HoneySelect2_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BoobController.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Hooks.cs" />
<Compile Include="HS2_BoobSettings.cs" />
<Compile Include="MakerAPI.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions HS2_BoobSettings.sln
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30128.74
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HS2_BoobSettings", "HS2_BoobSettings.csproj", "{5C2C91EA-F206-4FC9-951F-C04FFA20C2EB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5C2C91EA-F206-4FC9-951F-C04FFA20C2EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C2C91EA-F206-4FC9-951F-C04FFA20C2EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C2C91EA-F206-4FC9-951F-C04FFA20C2EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C2C91EA-F206-4FC9-951F-C04FFA20C2EB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {16074925-51A2-4E7D-AA5B-B1DB29F250FA}
EndGlobalSection
EndGlobal
101 changes: 101 additions & 0 deletions Hooks.cs
@@ -0,0 +1,101 @@
using AIChara;
using HarmonyLib;
using UnityEngine;

namespace HS2_BoobSettings
{
public partial class HS2_BoobSettings
{
[HarmonyPrefix]
[HarmonyPatch(typeof(BustSoft), "ReCalc")]
public static bool PatchPrefix_BustSoft_ReCalc(ChaControl ___chaCtrl, ChaInfo ___info, int[] changePtn)
{
if (___chaCtrl == null ||
___info == null ||
changePtn.Length == 0)
return false;

BoobController controller = ___chaCtrl.GetComponent<BoobController>();

if (controller == null ||
!controller.overridePhysics)
return true;

Util.UpdateSoftness(
___chaCtrl.GetDynamicBoneBustAndHip(ChaControlDefine.DynamicBoneKind.BreastL),
changePtn,
controller.damping,
controller.elasticity,
controller.stiffness
);
Util.UpdateSoftness(
___chaCtrl.GetDynamicBoneBustAndHip(ChaControlDefine.DynamicBoneKind.BreastR),
changePtn,
controller.damping,
controller.elasticity,
controller.stiffness
);
// Inert rarely gets updated. This makes sure it does.
___chaCtrl.ChangeBustInert(false);

return false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(ChaControl), "ChangeBustInert")]
public static bool PatchPrefix_ChaControl_ChangeBustInert(ChaControl __instance, bool h)
{
BoobController controller = __instance.GetComponent<BoobController>();

if (controller == null ||
!controller.overridePhysics)
return true;

Util.UpdateInert(
__instance.GetDynamicBoneBustAndHip(ChaControlDefine.DynamicBoneKind.BreastL),
controller.inert
);
Util.UpdateInert(
__instance.GetDynamicBoneBustAndHip(ChaControlDefine.DynamicBoneKind.BreastR),
controller.inert
);

return false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(BustGravity), "ReCalc")]
public static bool PatchPrefix_BustGravity_ReCalc(ChaControl ___chaCtrl, ChaInfo ___info, int[] changePtn)
{
if (___chaCtrl == null ||
___info == null ||
changePtn.Length == 0)
return false;

BoobController controller = ___chaCtrl.GetComponent<BoobController>();

if (controller == null ||
!controller.overrideGravity)
return true;

Vector3 gravity = new Vector3(
controller.gravityX,
controller.gravityY,
controller.gravityZ
);

Util.UpdateGravity(
___chaCtrl.GetDynamicBoneBustAndHip(ChaControlDefine.DynamicBoneKind.BreastL),
changePtn,
gravity
);
Util.UpdateGravity(
___chaCtrl.GetDynamicBoneBustAndHip(ChaControlDefine.DynamicBoneKind.BreastR),
changePtn,
gravity
);

return false;
}
}
}

0 comments on commit e94ce4e

Please sign in to comment.