Skip to content

Commit

Permalink
Added KK_PoseFolders
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathWeasel1337 committed Apr 1, 2019
1 parent 0a81da0 commit 4fca01f
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 0 deletions.
6 changes: 6 additions & 0 deletions KK_Plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_HCharaAdjustment", "KK_H
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_RandomCharacterGenerator", "KK_RandomCharacterGenerator\KK_RandomCharacterGenerator.csproj", "{7E21E1CC-356E-41BB-ABDD-BD0F99710361}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_PoseFolders", "KK_PoseFolders\KK_PoseFolders.csproj", "{4F27E216-A311-469C-891A-8E57F330A68F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -153,6 +155,10 @@ Global
{7E21E1CC-356E-41BB-ABDD-BD0F99710361}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E21E1CC-356E-41BB-ABDD-BD0F99710361}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E21E1CC-356E-41BB-ABDD-BD0F99710361}.Release|Any CPU.Build.0 = Release|Any CPU
{4F27E216-A311-469C-891A-8E57F330A68F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F27E216-A311-469C-891A-8E57F330A68F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F27E216-A311-469C-891A-8E57F330A68F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F27E216-A311-469C-891A-8E57F330A68F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
108 changes: 108 additions & 0 deletions KK_PoseFolders/KK_PoseFolders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using BepInEx;
using Harmony;
using Studio;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using UnityEngine;
using UnityEngine.Events;

namespace KK_PoseFolders
{
[BepInPlugin(GUID, PluginName, Version)]
public class KK_PoseFolders : BaseUnityPlugin
{
public const string GUID = "com.deathweasel.bepinex.posefolders";
public const string PluginName = "Pose Folders";
public const string Version = "1.0";

private const string USERDATA = "userdata";
private const string DEFAULT_ROOT = "studio/pose";
private static readonly int UserdataRoot = new DirectoryInfo(USERDATA).FullName.Length + 1; //+1 for slash
private static DirectoryInfo CurrentDirectory = new DirectoryInfo(USERDATA + "/" + DEFAULT_ROOT);
private static readonly int DefaultRootLength = CurrentDirectory.FullName.Length;

private static GameObject v_prefabNode;
private static Transform v_transformRoot;

private void Main()
{
if (!CurrentDirectory.Exists) CurrentDirectory.Create();
var harmony = HarmonyInstance.Create(GUID);
harmony.PatchAll(typeof(KK_PoseFolders));
}

private static string GetFolder()
{
if (!CurrentDirectory.Exists)
CurrentDirectory = new DirectoryInfo(USERDATA + "/" + DEFAULT_ROOT);
return CurrentDirectory.FullName.Substring(UserdataRoot);
}

private static IEnumerable<CodeInstruction> ReplacePath(IEnumerable<CodeInstruction> _instructions)
{
var instructions = new List<CodeInstruction>(_instructions);

for (var i = 0; i < instructions.Count; i++)
{
var inst = instructions[i];
if (inst.opcode == OpCodes.Ldstr && inst.operand?.ToString() == DEFAULT_ROOT)
{
inst.opcode = OpCodes.Call;
inst.operand = AccessTools.Method(typeof(KK_PoseFolders), nameof(GetFolder));
break;
}
}

return instructions;
}

[HarmonyTranspiler, HarmonyPatch(typeof(PauseRegistrationList), "InitList")]
public static IEnumerable<CodeInstruction> tpl_PauseRegistrationList_InitList(IEnumerable<CodeInstruction> _instructions) => ReplacePath(_instructions);

[HarmonyTranspiler, HarmonyPatch(typeof(PauseCtrl), "Save")]
public static IEnumerable<CodeInstruction> tpl_PauseCtrl_Save(IEnumerable<CodeInstruction> _instructions) => ReplacePath(_instructions);

private static Transform AddListButton(string text, UnityAction callback)
{
var prefabNode = Instantiate(v_prefabNode);
prefabNode.transform.SetParent(v_transformRoot, false);
var component = prefabNode.GetComponent<StudioNode>();
component.active = true;
component.addOnClick = callback;
component.text = text;

return prefabNode.transform;
}

[HarmonyPostfix, HarmonyPatch(typeof(PauseRegistrationList), "InitList")]
public static void post_PauseRegistrationList_InitList(PauseRegistrationList __instance)
{
if (v_prefabNode == null)
{
v_prefabNode = (GameObject)AccessTools.Field(typeof(PauseRegistrationList), "prefabNode").GetValue(__instance);
v_transformRoot = (Transform)AccessTools.Field(typeof(PauseRegistrationList), "transformRoot").GetValue(__instance);
}

foreach (var subDir in CurrentDirectory.GetDirectories().Reverse())
{
AddListButton($"[{subDir.Name}]", () =>
{
CurrentDirectory = subDir;
Traverse.Create(__instance).Method("InitList").GetValue();
}).SetAsFirstSibling();
}
var fn = CurrentDirectory.FullName;
if (fn.Length > DefaultRootLength)
{
AddListButton("..", () =>
{
CurrentDirectory = CurrentDirectory.Parent;
Traverse.Create(__instance).Method("InitList").GetValue();
}).SetAsFirstSibling();
}
}
}
}
68 changes: 68 additions & 0 deletions KK_PoseFolders/KK_PoseFolders.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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>{4F27E216-A311-469C-891A-8E57F330A68F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KK_PoseFolders</RootNamespace>
<AssemblyName>KK_PoseFolders</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>embedded</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\lib\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\lib\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\lib\BepInEx.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="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\lib\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="KK_PoseFolders.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if exist C:\Illusion\Koikatu\BepInEx (
copy /y $(TargetPath) C:\illusion\Koikatu\BepInEx\$(TargetFileName)
)</PostBuildEvent>
</PropertyGroup>
</Project>
36 changes: 36 additions & 0 deletions KK_PoseFolders/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("KK_PoseFolders")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KK_PoseFolders")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4f27e216-a311-469c-891a-8e57f330a68f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion(KK_PoseFolders.KK_PoseFolders.Version)]
[assembly: AssemblyFileVersion(KK_PoseFolders.KK_PoseFolders.Version)]

0 comments on commit 4fca01f

Please sign in to comment.