Skip to content

Commit

Permalink
Removed obsolete feature to load overlays from specially named folders
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Mar 9, 2021
1 parent b03208e commit 9504491
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 98 deletions.
6 changes: 0 additions & 6 deletions Core_OverlayMods/Skin/KoiSkinOverlayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ protected override void OnReload(GameMode currentGameMode, bool maintainState)
&& texData is byte[] bytes && bytes.Length > 0)
{
_overlays.Add(texType, new OverlayTexture(bytes));
continue;
}

// Fall back to old-style overlays in a folder
var oldTex = KoiSkinOverlayMgr.GetOldStyleOverlayTex(texType, ChaControl);
if (oldTex != null)
_overlays.Add(texType, new OverlayTexture(oldTex));
}

if (needsUpdate || _overlays.Any())
Expand Down
33 changes: 0 additions & 33 deletions Core_OverlayMods/Skin/KoiSkinOverlayGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Powerful plugins
using System.Linq;
using BepInEx;
using BepInEx.Configuration;
using ExtensibleSaveFormat;
using KKAPI.Chara;
using KKAPI.Maker;
using KKAPI.Maker.UI;
Expand Down Expand Up @@ -50,32 +49,9 @@ public class KoiSkinOverlayGui : BaseUnityPlugin
private TexType _typeToLoad;
private FileSystemWatcher _texChangeWatcher;

#if KK
[Browsable(false)]
public static ConfigEntry<bool> RemoveOldFiles;
#endif

[Browsable(false)]
public static ConfigEntry<bool> WatchLoadedTexForChanges;

private static void ExtendedSaveOnCardBeingSaved(ChaFile chaFile)
{
#if KK
if (!MakerAPI.InsideMaker) return;

if (RemoveOldFiles.Value)
{
var ctrl = GetOverlayController();
foreach (var overlay in ctrl.Overlays)
{
var path = KoiSkinOverlayMgr.GetTexFilename(chaFile.parameter.fullname, overlay.Key);
if (File.Exists(path))
File.Delete(path);
}
}
#endif
}

private static KoiSkinOverlayController GetOverlayController()
{
return MakerAPI.GetCharacterControl().gameObject.GetComponent<KoiSkinOverlayController>();
Expand Down Expand Up @@ -224,11 +200,6 @@ private void SetupEyeInterface(RegisterSubCategoriesEvent e, KoiSkinOverlayMgr o

private static void AddConfigSettings(RegisterSubCategoriesEvent e, KoiSkinOverlayMgr owner, MakerCategory makerCategory)
{
#if KK
var tRemove = e.AddControl(new MakerToggle(makerCategory, "Remove overlays imported from BepInEx\\KoiSkinOverlay when saving cards (they are saved inside the card now and no longer necessary)", owner));
tRemove.Value = RemoveOldFiles.Value;
tRemove.ValueChanged.Subscribe(b => RemoveOldFiles.Value = b);
#endif
var tWatch = e.AddControl(new MakerToggle(makerCategory, "Watch last loaded texture file for changes", owner));
tWatch.Value = WatchLoadedTexForChanges.Value;
tWatch.ValueChanged.Subscribe(b => WatchLoadedTexForChanges.Value = b);
Expand Down Expand Up @@ -294,9 +265,6 @@ public static string GetDefaultLoadDir()

private void Awake()
{
#if KK
RemoveOldFiles = Config.AddSetting("Maker", "Remove old files", true, "Remove overlays imported from BepInEx\\KoiSkinOverlay when saving cards (they are saved inside the card now and no longer necessary)");
#endif
WatchLoadedTexForChanges = Config.AddSetting("Maker", "Watch loaded texture for changes", true);
WatchLoadedTexForChanges.SettingChanged += (sender, args) =>
{
Expand All @@ -310,7 +278,6 @@ private void Start()
MakerAPI.RegisterCustomSubCategories += RegisterCustomSubCategories;
MakerAPI.MakerExiting += MakerExiting;
CharacterApi.CharacterReloaded += (sender, args) => OnChaFileLoaded();
ExtendedSave.CardBeingSaved += ExtendedSaveOnCardBeingSaved;
}

private void Update()
Expand Down
59 changes: 0 additions & 59 deletions Core_OverlayMods/Skin/KoiSkinOverlayMgr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,64 +86,5 @@ public static TextureFormat GetSelectedOverlayTexFormat(bool isMask)
return CompressTextures.Value ? TextureFormat.DXT1 : TextureFormat.RG16;
return CompressTextures.Value ? TextureFormat.DXT5 : TextureFormat.ARGB32;
}

#if KK
internal static string GetTexFilename(string charFullname, TexType texType)
{
string name;

switch (texType)
{
case TexType.BodyOver:
name = "Body";
break;
case TexType.FaceOver:
name = "Face";
break;
case TexType.Unknown:
return null;
default:
name = texType.ToString();
break;
}

var legacyDir = Path.Combine(Paths.PluginPath, "KoiSkinOverlay");
var charFolder = $"{legacyDir}/{charFullname}";
var texFilename = $"{charFolder}/{name}.png";
return texFilename;
}
#endif

/// <summary>
/// Old loading logic from folders
/// </summary>
internal static byte[] GetOldStyleOverlayTex(TexType texType, ChaControl chaControl)
{
#if KK
var charFullname = chaControl.fileParam?.fullname;
if (!string.IsNullOrEmpty(charFullname))
{
var texFilename = GetTexFilename(charFullname, texType);

if (File.Exists(texFilename))
{
Logger.LogInfo($"Importing texture data for {charFullname} from file {texFilename}");

try
{
var fileTexBytes = File.ReadAllBytes(texFilename);
var overlayTex = Util.TextureFromBytes(fileTexBytes, TextureFormat.ARGB32);
if (overlayTex != null)
return overlayTex.EncodeToPNG();
}
catch (Exception ex)
{
Logger.LogError("[KSOX] Failed to load texture from file - " + ex.Message);
}
}
}
#endif
return null;
}
}
}

0 comments on commit 9504491

Please sign in to comment.