miuu-custom-cosmetic-loader/PatchEntryPoint.cs

53 lines
1.3 KiB
C#
Raw Normal View History

2023-08-26 12:29:43 -04:00
using HarmonyLib;
using System;
2023-08-26 17:59:50 -04:00
using System.IO;
using System.Reflection;
using UnityEngine;
2023-08-26 12:29:43 -04:00
using UnityEngine.SceneManagement;
namespace CustomCosmeticLoader
{
public static class PatchEntryPoint
{
private static bool IsPatched = false;
public static void Start()
{
SceneManager.sceneLoaded += beginPatch;
}
private static void beginPatch(Scene scene, LoadSceneMode mode)
{
if (!IsPatched)
{
new Harmony("com.thearst3rd.customcosmeticloader").PatchAll();
IsPatched = true;
SceneManager.sceneLoaded -= beginPatch;
2023-08-26 17:59:50 -04:00
LoadCosmetics();
Config.Init();
2023-08-26 12:29:43 -04:00
}
}
2023-08-26 17:59:50 -04:00
private static void LoadCosmetics()
{
string skinsPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
skinsPath = Path.Combine(skinsPath, "skins");
if (!Directory.Exists(skinsPath))
{
2023-09-04 16:38:48 -04:00
Shared.Log(skinsPath + " directory does not exist, no skins to load");
return;
}
string printStr = "Loaded custom skins: ";
foreach (string skinFile in Directory.GetFiles(skinsPath))
{
string skinName = Path.GetFileNameWithoutExtension(skinFile);
printStr += skinName + ", ";
Texture2D skinTexture = new Texture2D(2, 2);
skinTexture.LoadImage(File.ReadAllBytes(skinFile));
Config.skins.Add(skinName, skinTexture);
}
2023-09-04 16:38:48 -04:00
Shared.Log(printStr);
2023-08-26 17:59:50 -04:00
}
2023-08-26 12:29:43 -04:00
}
}