Skip to content

Commit

Permalink
Added KK Sunshine support (#27)
Browse files Browse the repository at this point in the history
Added Sunshine support to Browser Folders.

New projects created to prevent conflicts with KKAPI and KKSAPI.

Most code base is taken from KKP.

Updated all packages to newest versions
In FreeH, new CreateHook created in Overlord to prevent browser getting stuck when switching sexes
In Maker, moved _folderTreeView.Default to Init() and replaced Overlord.GetDefaultPath(CustomBase.ModeSex) to GetDefaultPath(sex) since CustomBase.ModeSex is always female.

* Added KKS to Folder Browser

* Maker working

* FreeH fixed
  • Loading branch information
CallMeSai authored Sep 14, 2021
1 parent 8c58825 commit c36838c
Show file tree
Hide file tree
Showing 18 changed files with 1,656 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public static ManualLogSource Logger
{
#if KK
return KK_BrowserFolders.Logger;
#elif KKS
return KKS_BrowserFolders.Logger;
#elif EC
return EC_BrowserFolders.Logger;
#else
Expand Down
15 changes: 15 additions & 0 deletions src/Illusion_BrowserFolders.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EC_BrowserFolders", "EC_Bro
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Common", "Common\Common.shproj", "{9303FD5B-13ED-4BBE-9625-B1EAF4287802}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KK_BrowserFolders_Hooks_KKS", "KK_BrowserFolders_Hooks_KKS\KK_BrowserFolders_Hooks_KKS.csproj", "{5F24613D-228D-4EFE-B3AD-EA8DA64BE688}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KKS_FolderBrowser", "KKS_FolderBrowser\KKS_FolderBrowser.csproj", "{867DB9DF-F1F2-43EF-98E7-F92CD2D01E49}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Common\Common.projitems*{206d2e71-0933-4b96-b74d-d07521eb58db}*SharedItemsImports = 4
Common_AIHS2\Common_AIHS2.projitems*{206d2e71-0933-4b96-b74d-d07521eb58db}*SharedItemsImports = 4
Common\Common.projitems*{30773058-5a9c-43a2-9e43-ce8b0b77140c}*SharedItemsImports = 4
Common\Common.projitems*{74c2db86-55bb-47b4-9805-51b5b992ef35}*SharedItemsImports = 4
Common\Common.projitems*{867db9df-f1f2-43ef-98e7-f92cd2d01e49}*SharedItemsImports = 4
Common\Common.projitems*{9303fd5b-13ed-4bbe-9625-b1eaf4287802}*SharedItemsImports = 13
Common_AIHS2\Common_AIHS2.projitems*{9808ef6d-057e-46e4-99ac-f7bbf2c5a057}*SharedItemsImports = 13
Common\Common.projitems*{ebd219d5-7a7a-4a9b-bae6-460ec5cf8c43}*SharedItemsImports = 4
Expand Down Expand Up @@ -63,6 +68,14 @@ Global
{30773058-5A9C-43A2-9E43-CE8B0B77140C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30773058-5A9C-43A2-9E43-CE8B0B77140C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30773058-5A9C-43A2-9E43-CE8B0B77140C}.Release|Any CPU.Build.0 = Release|Any CPU
{5F24613D-228D-4EFE-B3AD-EA8DA64BE688}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F24613D-228D-4EFE-B3AD-EA8DA64BE688}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F24613D-228D-4EFE-B3AD-EA8DA64BE688}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F24613D-228D-4EFE-B3AD-EA8DA64BE688}.Release|Any CPU.Build.0 = Release|Any CPU
{867DB9DF-F1F2-43EF-98E7-F92CD2D01E49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{867DB9DF-F1F2-43EF-98E7-F92CD2D01E49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{867DB9DF-F1F2-43EF-98E7-F92CD2D01E49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{867DB9DF-F1F2-43EF-98E7-F92CD2D01E49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -74,6 +87,8 @@ Global
{EBD219D5-7A7A-4A9B-BAE6-460EC5CF8C43} = {28447449-8DF7-4CFD-80BF-FF26290830E6}
{206D2E71-0933-4B96-B74D-D07521EB58DB} = {28447449-8DF7-4CFD-80BF-FF26290830E6}
{9808EF6D-057E-46E4-99AC-F7BBF2C5A057} = {28447449-8DF7-4CFD-80BF-FF26290830E6}
{5F24613D-228D-4EFE-B3AD-EA8DA64BE688} = {9067BD3D-B6BE-4462-8F81-E1D996C8E7DA}
{867DB9DF-F1F2-43EF-98E7-F92CD2D01E49} = {9067BD3D-B6BE-4462-8F81-E1D996C8E7DA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28F0A8B3-ACB9-46D0-995C-4D9717D8E724}
Expand Down
15 changes: 15 additions & 0 deletions src/KKS_FolderBrowser/BrowserType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace BrowserFolders
{
public enum BrowserType
{
NewGame,
FreeH,
Classroom,
HOutfit,
Maker,
Scene,
StudioChara,
StudioOutfit,
MakerOutfit
}
}
13 changes: 13 additions & 0 deletions src/KKS_FolderBrowser/BrowserTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace BrowserFolders
{
public sealed class BrowserTypeAttribute : Attribute
{
public BrowserType BrowserType { get; }
public BrowserTypeAttribute(BrowserType browserType)
{
BrowserType = browserType;
}
}
}
174 changes: 174 additions & 0 deletions src/KKS_FolderBrowser/KKS_BrowserFolders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Common;
using KKAPI;
using UnityEngine;

namespace BrowserFolders
{
[BepInPlugin(Guid, "Maker/Studio Browser Folders", Version)]
[BepInDependency(KoikatuAPI.GUID, KoikatuAPI.VersionConst)]
public class KKS_BrowserFolders : BaseUnityPlugin
{
public const string Guid = Constants.Guid;
public const string Version = Constants.Version;

internal static new ManualLogSource Logger { get; private set; }

private bool _isStudio;

private IFolderBrowser _sceneFolders;
private IFolderBrowser _makerFolders;
private IFolderBrowser _classroomFolders;
private IFolderBrowser _freeHFolders;
private IFolderBrowser _newGameFolders;
private IFolderBrowser _studioCharaFolders;
private IFolderBrowser _makerOutfitFolders;
private IFolderBrowser _studioOutfitFolders;
private IFolderBrowser _hOutfitFolders;

public static ConfigEntry<bool> EnableMaker { get; private set; }

public static ConfigEntry<bool> EnableMakerOutfit { get; private set; }
public static ConfigEntry<bool> EnableClassroom { get; private set; }
public static ConfigEntry<bool> EnableFreeH { get; private set; }
public static ConfigEntry<bool> EnableHOutfit { get; private set; }

public static ConfigEntry<bool> EnableStudio { get; private set; }
public static ConfigEntry<bool> EnableStudioChara { get; private set; }
public static ConfigEntry<bool> StudioSaveOverride { get; private set; }
public static ConfigEntry<bool> EnableStudioOutfit { get; private set; }

public static ConfigEntry<bool> ShowDefaultCharas { get; private set; }
public static ConfigEntry<bool> RandomCharaSubfolders { get; private set; }

internal void OnGUI()
{
if (_isStudio)
{
_sceneFolders?.OnGui();
_studioCharaFolders?.OnGui();
_studioOutfitFolders?.OnGui();
}
else
{
_makerFolders?.OnGui();
_classroomFolders?.OnGui();
_freeHFolders?.OnGui();
_newGameFolders?.OnGui();
_makerOutfitFolders?.OnGui();
_hOutfitFolders?.OnGui();
}
}

private void Awake()
{
Logger = base.Logger;

if (Application.productName == "CharaStudio")
_isStudio = true;

var browsers = LoadBrowsers();
if (browsers.Count == 0) return;

var maker = browsers.FirstOrDefault(x => x.Key == BrowserType.Maker).Value;
var makerOutfit = browsers.FirstOrDefault(x => x.Key == BrowserType.MakerOutfit).Value;
var classroom = browsers.FirstOrDefault(x => x.Key == BrowserType.Classroom).Value;
var newGame = browsers.FirstOrDefault(x => x.Key == BrowserType.NewGame).Value;
var freeH = browsers.FirstOrDefault(x => x.Key == BrowserType.FreeH).Value;
var scene = browsers.FirstOrDefault(x => x.Key == BrowserType.Scene).Value;
var hOutfit = browsers.FirstOrDefault(x => x.Key == BrowserType.HOutfit).Value;
var studioChara = browsers.FirstOrDefault(x => x.Key == BrowserType.StudioChara).Value;
var studioOutfit = browsers.FirstOrDefault(x => x.Key == BrowserType.StudioOutfit).Value;

if (maker != null)
EnableMaker = Config.Bind("Main game", "Enable folder browser in maker", true, "Changes take effect on game restart");

if (makerOutfit != null)
EnableMakerOutfit = Config.Bind("Main game", "Enable folder browser in maker for outfits", true, "Changes take effect on game restart");

if (classroom != null || newGame != null)
{
EnableClassroom = Config.Bind("Main game", "Enable folder browser in classroom/new game browser", true, "Changes take effect on game restart");
RandomCharaSubfolders = Config.Bind("Main game", "Search subfolders for random characters", true, "When filling the class with random characters (or in other cases where a random character is picked) choose random characters from the main directory AND all of its subdirectories. If false, only search in the main directory (UserData/chara/female).");
}

if (freeH != null)
EnableFreeH = Config.Bind("Main game", "Enable folder browser in Free H browser", true, "Changes take effect on game restart");

if (hOutfit != null)
EnableHOutfit = Config.Bind("Main game", "Enable folder browser in H preset browser", true, "Changes take effect on game restart.\n Kplug doesn't support this and will restore previous outfit when not main or out of H.");

if (scene != null || studioChara != null || studioOutfit != null)
{
EnableStudio = Config.Bind("Chara Studio", "Enable folder browser in scene browser", true, "Changes take effect on game restart");
StudioSaveOverride = Config.Bind("Chara Studio", "Save scenes to current folder", true, "When you select a custom folder to load a scene from, newly saved scenes will be saved to this folder.\nIf disabled, scenes are always saved to default folder (studio/scene).");
EnableStudioChara = Config.Bind("Chara Studio", "Enable folder browser in character browser", true, "Changes take effect on game restart");
EnableStudioOutfit = Config.Bind("Chara Studio", "Enable folder browser in outfit browser", true, "Changes take effect on game restart");
}

if (_isStudio)
{
if (scene != null && EnableStudio.Value)
_sceneFolders = (IFolderBrowser)Activator.CreateInstance(scene);

if (studioChara != null && EnableStudioChara.Value)
_studioCharaFolders = (IFolderBrowser)Activator.CreateInstance(studioChara);

if (studioOutfit != null && EnableStudioOutfit.Value)
_studioOutfitFolders = (IFolderBrowser)Activator.CreateInstance(studioOutfit);
}
else
{
ShowDefaultCharas = Config.Bind("Main game", "Show default character cards", true);

if (maker != null && EnableMaker.Value)
_makerFolders = (IFolderBrowser)Activator.CreateInstance(maker);

if (makerOutfit != null && EnableMakerOutfit.Value)
_makerOutfitFolders = (IFolderBrowser)Activator.CreateInstance(makerOutfit);

if (hOutfit != null && EnableHOutfit.Value)
_hOutfitFolders = (IFolderBrowser)Activator.CreateInstance(hOutfit);

if (EnableClassroom != null && EnableClassroom.Value)
{
if (classroom != null) _classroomFolders = (IFolderBrowser)Activator.CreateInstance(classroom);
if (newGame != null) _newGameFolders = (IFolderBrowser)Activator.CreateInstance(newGame);
}

if (freeH != null && EnableFreeH.Value)
_freeHFolders = (IFolderBrowser)Activator.CreateInstance(freeH);
}
}

private static List<KeyValuePair<BrowserType, Type>> LoadBrowsers()
{
try
{
string assHooks = "KK_BrowserFolders_Hooks_KKS";

return GetBrowsers(Assembly.Load(assHooks));
}
catch (FileNotFoundException ex) { Logger.LogWarning("Failed to load browsers - " + ex); }

return new List<KeyValuePair<BrowserType, Type>>();
}

private static List<KeyValuePair<BrowserType, Type>> GetBrowsers(Assembly ass)
{
var query = from t in ass.GetTypesSafe()
where t.IsClass
let attr = t.GetCustomAttributes(false).OfType<BrowserTypeAttribute>().FirstOrDefault()
where attr != null
group t by attr.BrowserType;
return query.Select(x => new KeyValuePair<BrowserType, Type>(x.Key, x.Single())).ToList();
}
}
}
Loading

0 comments on commit c36838c

Please sign in to comment.