-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d371c3
commit b5b4e89
Showing
9 changed files
with
506 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,9 @@ | ||
using KK_Plugins; | ||
using System.Reflection; | ||
using static KK_Plugins.ShaderSwapper; | ||
|
||
[assembly: AssemblyTitle(PluginNameInternal)] | ||
[assembly: AssemblyProduct(PluginNameInternal)] | ||
[assembly: AssemblyDescription(PluginName + " for " + Constants.GameName)] | ||
[assembly: AssemblyVersion(PluginVersion)] | ||
[assembly: AssemblyFileVersion(PluginVersion)] |
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,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>a27f5e6b-5e24-4609-a634-1a704ebbf1d9</ProjectGuid> | ||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" /> | ||
<PropertyGroup /> | ||
<Import Project="ShaderSwapper.Core.projitems" Label="Shared" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<MSBuildAllProjects Condition="'$(MSBuildVersion)' == '' Or '$(MSBuildVersion)' < '16.0'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> | ||
<HasSharedItems>true</HasSharedItems> | ||
<SharedGUID>a27f5e6b-5e24-4609-a634-1a704ebbf1d9</SharedGUID> | ||
</PropertyGroup> | ||
<PropertyGroup Label="Configuration"> | ||
<Import_RootNamespace>ShaderSwapper.Core</Import_RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildThisFileDirectory)AssemblyInfo.cs" /> | ||
<Compile Include="$(MSBuildThisFileDirectory)ShaderSwapper.cs" /> | ||
</ItemGroup> | ||
</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,120 @@ | ||
using BepInEx; | ||
using BepInEx.Configuration; | ||
using BepInEx.Logging; | ||
using KK_Plugins.MaterialEditor; | ||
using KKAPI.Maker; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using static KK_Plugins.MaterialEditor.MaterialEditorCharaController; | ||
using static MaterialEditorAPI.MaterialAPI; | ||
|
||
namespace KK_Plugins | ||
{ | ||
[BepInDependency(MaterialEditorPlugin.PluginGUID, MaterialEditorPlugin.PluginVersion)] | ||
[BepInPlugin(PluginGUID, PluginName, PluginVersion)] | ||
public class ShaderSwapper : BaseUnityPlugin | ||
{ | ||
public const string PluginGUID = "com.deathweasel.bepinex.shaderswapper"; | ||
public const string PluginName = "Shader Swapper"; | ||
public const string PluginNameInternal = Constants.Prefix + "_ShaderSwapper"; | ||
public const string PluginVersion = "1.0"; | ||
internal static new ManualLogSource Logger; | ||
|
||
internal static ConfigEntry<KeyboardShortcut> SwapShadersHotkey { get; private set; } | ||
|
||
private readonly Dictionary<string, string> VanillaPlusShaders = new Dictionary<string, string> | ||
{ | ||
{"Shader Forge/main_skin", "xukmi/SkinPlus" }, | ||
{"Koikano/main_skin", "xukmi/SkinPlus" }, | ||
{"Shader Forge/main_hair", "xukmi/HairPlus" }, | ||
{"Koikano/hair_main_sun", "xukmi/HairPlus" }, | ||
{"Shader Forge/main_hair_front", "xukmi/HairFrontPlus" }, | ||
{"Koikano/hair_main_sun_front", "xukmi/HairFrontPlus" }, | ||
{"Shader Forge/toon_eye_lod0", "xukmi/EyePlus" }, | ||
{"Koikano/main_eye", "xukmi/EyePlus" }, | ||
{"Shader Forge/toon_eyew_lod0", "xukmi/EyeWPlus" }, | ||
{"Koikano/main_eyew", "xukmi/EyeWPlus" }, | ||
{"Shader Forge/main_opaque", "xukmi/MainOpaquePlus" }, | ||
{"Shader Forge/main_opaque2", "xukmi/MainOpaquePlus" }, | ||
{"Koikano/main_clothes_opaque", "xukmi/MainOpaquePlus" }, | ||
{"Shader Forge/main_alpha", "xukmi/MainAlphaPlus" }, | ||
{"Koikano/main_clothes_alpha", "xukmi/MainAlphaPlus" }, | ||
{"Shader Forge/main_item", "xukmi/MainItemPlus" }, | ||
{"Koikano/main_clothes_item", "xukmi/MainItemPlus" }, | ||
}; | ||
|
||
private void Awake() | ||
{ | ||
Logger = base.Logger; | ||
SwapShadersHotkey = Config.Bind("Keyboard Shortcuts", "Swap Shaders", new KeyboardShortcut(KeyCode.P, KeyCode.RightControl), "Swap all shaders to the equivalent Vanilla+ shader."); | ||
} | ||
|
||
private void Update() | ||
{ | ||
if (SwapShadersHotkey.Value.IsDown()) | ||
{ | ||
if (!MakerAPI.InsideAndLoaded) | ||
return; | ||
var controller = GetController(MakerAPI.GetCharacterControl()); | ||
for (var i = 0; i < controller.ChaControl.objClothes.Length; i++) | ||
SwapToVanillaPlusClothes(controller, i); | ||
for (var i = 0; i < controller.ChaControl.objHair.Length; i++) | ||
SwapToVanillaPlusHair(controller, i); | ||
for (var i = 0; i < controller.ChaControl.GetAccessoryObjects().Length; i++) | ||
SwapToVanillaPlusAccessory(controller, i); | ||
SwapToVanillaPlusBody(controller); | ||
} | ||
} | ||
|
||
public static MaterialEditorCharaController GetController(ChaControl chaControl) | ||
{ | ||
if (chaControl == null || chaControl.gameObject == null) | ||
return null; | ||
return chaControl.gameObject.GetComponent<MaterialEditorCharaController>(); | ||
} | ||
|
||
private void SwapToVanillaPlus(MaterialEditorCharaController controller, int slot, ObjectType objectType, Material mat, GameObject go) | ||
{ | ||
if (controller.GetMaterialShader(slot, ObjectType.Clothing, mat, go) == null) | ||
{ | ||
if (VanillaPlusShaders.TryGetValue(mat.shader.name, out var vanillaPlusShaderName)) | ||
{ | ||
int renderQueue = mat.renderQueue; | ||
controller.SetMaterialShader(slot, objectType, mat, vanillaPlusShaderName, go); | ||
controller.SetMaterialShaderRenderQueue(slot, objectType, mat, renderQueue, go); | ||
if (mat.shader.name == "xukmi/MainAlphaPlus") | ||
controller.SetMaterialFloatProperty(slot, objectType, mat, "Cutoff", 0.1f, go); | ||
} | ||
} | ||
} | ||
|
||
private void SwapToVanillaPlusClothes(MaterialEditorCharaController controller, int slot) | ||
{ | ||
var go = controller.ChaControl.objClothes[slot]; | ||
foreach (var renderer in GetRendererList(go)) | ||
foreach (var material in GetMaterials(go, renderer)) | ||
SwapToVanillaPlus(controller, slot, ObjectType.Clothing, material, go); | ||
} | ||
private void SwapToVanillaPlusHair(MaterialEditorCharaController controller, int slot) | ||
{ | ||
var go = controller.ChaControl.objHair[slot]; | ||
foreach (var renderer in GetRendererList(go)) | ||
foreach (var material in GetMaterials(go, renderer)) | ||
SwapToVanillaPlus(controller, slot, ObjectType.Hair, material, go); | ||
} | ||
private void SwapToVanillaPlusAccessory(MaterialEditorCharaController controller, int slot) | ||
{ | ||
var go = controller.ChaControl.GetAccessoryObject(slot); | ||
if (go != null) | ||
foreach (var renderer in GetRendererList(go)) | ||
foreach (var material in GetMaterials(go, renderer)) | ||
SwapToVanillaPlus(controller, slot, ObjectType.Accessory, material, go); | ||
} | ||
private void SwapToVanillaPlusBody(MaterialEditorCharaController controller) | ||
{ | ||
foreach (var renderer in GetRendererList(controller.ChaControl.gameObject)) | ||
foreach (var material in GetMaterials(controller.ChaControl.gameObject, renderer)) | ||
SwapToVanillaPlus(controller, 0, ObjectType.Character, material, controller.ChaControl.gameObject); | ||
} | ||
} | ||
} |
Oops, something went wrong.