using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using SideLoader;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public enum EyeColor
{
Blue,
Green,
Brown,
Purple,
Red,
Yellow
}
namespace FemmeReskin;
[BepInPlugin("lumi.femmereskin", "FemmeReskin", "1.2.0")]
public class FemmeReskin : BaseUnityPlugin
{
internal static ManualLogSource Log;
public static ConfigEntry<EyeColor> EyeColor;
public static ConfigEntry<bool> ApplyMakeup;
public const string GUID = "lumi.femmereskin";
public const string NAME = "FemmeReskin";
public const string VERSION = "1.2.0";
public const string PackID = "femmereskin";
private SLPack SLPack;
internal void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
EyeColor = ((BaseUnityPlugin)this).Config.Bind<EyeColor>("General", "Eye Color", global::EyeColor.Green, "Eye color. Selection will only apply to the first head option for feminine characters of the Auraian race.");
ApplyMakeup = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Apply Makeup", true, "Applying makeup will alter the appearance of the character.");
SL.OnPacksLoaded += SL_OnPacksLoaded;
EyeColor.SettingChanged += OnSettingChanged;
ApplyMakeup.SettingChanged += OnSettingChanged;
}
private void SL_OnPacksLoaded()
{
try
{
SLPack = SL.GetSLPack("femmereskin");
UpdateObjects(CharacterManager.CharacterVisualsPresets.FHeadsWhite);
UpdateSkins(CharacterManager.CharacterVisualsPresets.FSkins);
}
catch (Exception ex)
{
Log.LogError((object)("Error updating textures: \n" + ex.Message));
}
}
private void OnSettingChanged(object sender, EventArgs e)
{
try
{
UpdateObjects(CharacterManager.CharacterVisualsPresets.FHeadsWhite);
UpdateSkins(CharacterManager.CharacterVisualsPresets.FSkins);
Log.LogMessage((object)"Textures updated.");
}
catch (Exception ex)
{
Log.LogError((object)("Error updating textures: \n" + ex.Message));
}
}
private void UpdateObjects(GameObject[] GameObjects)
{
SkinnedMeshRenderer val2 = default(SkinnedMeshRenderer);
foreach (GameObject val in GameObjects)
{
if (val.TryGetComponent<SkinnedMeshRenderer>(ref val2))
{
Texture2D texture = GetTexture(ApplyMakeup.Value ? (((Object)val).name + "_" + EyeColor.Value.ToString() + "_Makeup") : (((Object)val).name + "_" + EyeColor.Value));
Texture2D textureNormal = GetTextureNormal(((Object)val).name);
if ((Object)(object)texture != (Object)null)
{
UpdateTexture(((Renderer)val2).material, texture, textureNormal);
}
}
}
}
private void UpdateSkins(Material[] Materials)
{
foreach (Material val in Materials)
{
Texture2D texture = GetTexture(((Object)val).name);
Texture2D textureNormal = GetTextureNormal(((Object)val).name);
if ((Object)(object)texture != (Object)null)
{
UpdateTexture(val, texture, textureNormal);
}
}
}
private Texture2D GetTexture(string modelName)
{
if (SLPack == null)
{
Log.LogError((object)"SLPack not found, can't update textures");
}
else if (SLPack.Texture2D.ContainsKey(modelName))
{
return SLPack.Texture2D[modelName];
}
return null;
}
private Texture2D GetTextureNormal(string modelName)
{
if (SLPack == null)
{
Log.LogError((object)"SLPack not found, can't update textures");
}
else if (SLPack.Texture2D.ContainsKey(modelName + "_n"))
{
return SLPack.Texture2D[modelName + "_n"];
}
return null;
}
private void UpdateTexture(Material Material, Texture2D NewMainTexture, Texture2D NormalMap = null)
{
if ((Object)(object)NewMainTexture != (Object)null)
{
Material.mainTexture = (Texture)(object)NewMainTexture;
Log.LogMessage((object)("Successfully updated texture for " + ((Object)Material).name + " to " + ((Object)NewMainTexture).name));
if ((Object)(object)NormalMap != (Object)null)
{
Material.SetTexture("_NormTex", (Texture)(object)NormalMap);
Log.LogMessage((object)("Successfully updated normal map for " + ((Object)Material).name + " to " + ((Object)NormalMap).name));
}
}
}
}