-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
0a81da0
commit 4fca01f
Showing
4 changed files
with
218 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,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(); | ||
} | ||
} | ||
} | ||
} |
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,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> |
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,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)] |