using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SwingTrail")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Geezt Jeez")]
[assembly: AssemblyProduct("SFT by FhpSlime")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("SwingTrail")]
[assembly: ComVisible(false)]
[assembly: Guid("3a45c3cf-230c-4310-952f-0887d4266a22")]
[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: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace SkyboxChange;
[BepInPlugin("GeeztJeez.SkyboxChange", "SkyboxChange", "1.0.0")]
internal class Loader : BaseUnityPlugin
{
private static ConfigEntry<bool> configEnableMod;
public string skyboxFolderPath = "Skybox";
public AssetBundle assetBundle;
private List<Texture2D> skyboxTextures = new List<Texture2D>();
public static bool Enabled => configEnableMod.Value;
private void Awake()
{
((MonoBehaviour)this).StartCoroutine("Call");
}
private IEnumerator Call()
{
yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)Object.FindObjectOfType<ServiceLocator>() != (Object)null));
yield return (object)new WaitUntil((Func<bool>)(() => ServiceLocator.GetService<ISaveLoaderService>() != null));
Debug.Log((object)"Loading SkyboxChange.");
new Harmony("SkyboxChange").PatchAll();
Bundle("skychangebundle");
DoConfig();
Check();
LoadSkyboxTextures();
ChangeSkyboxRandom();
SceneManager.sceneLoaded += SceneLoaded;
((MonoBehaviour)this).StartCoroutine(GenerateSettings());
Debug.Log((object)"Loaded SkyboxChange Successfully!");
}
private IEnumerator GenerateSettings()
{
GlobalSettingsHandler service = null;
yield return (object)new WaitUntil((Func<bool>)(() => Object.op_Implicit((Object)(object)(service = ServiceLocator.GetService<GlobalSettingsHandler>()))));
List<SettingsInstance> list = service.GameplaySettings.ToList();
SettingsInstance val2 = new SettingsInstance();
val2.settingsType = (SettingsType)0;
val2.options = new string[2] { "On", "Off" };
val2.currentValue = ((!configEnableMod.Value) ? 1 : 0);
val2.m_settingsKey = "Use Skybox Change";
val2.toolTip = "Enables Skybox Change mod.";
SettingsInstance val3 = val2;
val3.OnValueChanged += delegate(int val)
{
configEnableMod.Value = val == 0;
};
list.Add(val3);
((object)service).GetType().GetField("m_gameplaySettings", (BindingFlags)(-1)).SetValue(service, list.ToArray());
}
private void DoConfig()
{
configEnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable Sky Change");
}
public void Check()
{
if (!Directory.Exists(skyboxFolderPath))
{
Directory.CreateDirectory(skyboxFolderPath);
}
}
public void ChangeSkyboxRandom()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
if (skyboxTextures.Count > 0)
{
int num = Random.Range(0, skyboxTextures.Count);
RenderSettings.skybox = CreateSkyMaterial(num);
Debug.Log((object)("Using textures: " + ((Object)skyboxTextures[num]).name));
}
else
{
RenderSettings.skybox = (Material)assetBundle.LoadAsset("SkyMat");
Debug.LogWarning((object)("No skybox textures found in the folder: " + skyboxFolderPath));
Debug.LogWarning((object)"Using template sky material");
}
}
public void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
ChangeSkyboxRandom();
}
private void Bundle(string name)
{
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
assetBundle = AssetBundle.LoadFromStream(stream);
}
public void LoadSkyboxTextures()
{
string[] files = Directory.GetFiles(skyboxFolderPath);
foreach (string text in files)
{
if (IsImageFile(text))
{
Texture2D item = Resources.Load<Texture2D>(text);
skyboxTextures.Add(item);
Debug.Log((object)("Added texture" + text));
}
else
{
Debug.LogError((object)("Failed added texture (Incorrect file image extension): " + text));
}
}
}
public bool IsImageFile(string filePath)
{
string text = Path.GetExtension(filePath).ToLower();
switch (text)
{
default:
return text == ".bmp";
case ".png":
case ".jpg":
case ".jpeg":
return true;
}
}
public Material CreateSkyMaterial(int randomIndex)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
Material val = new Material((Material)assetBundle.LoadAsset("SkyMat"));
val.SetTexture("_Tex", (Texture)(object)SetCubeMap(skyboxTextures[randomIndex]));
return val;
}
private Cubemap SetCubeMap(Texture2D texture)
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
if ((Object)(object)texture != (Object)null)
{
Cubemap val = new Cubemap(((Texture)texture).width, texture.format, false);
val.SetPixels(texture.GetPixels(), (CubemapFace)0);
val.SetPixels(texture.GetPixels(), (CubemapFace)1);
val.SetPixels(texture.GetPixels(), (CubemapFace)2);
val.SetPixels(texture.GetPixels(), (CubemapFace)3);
val.SetPixels(texture.GetPixels(), (CubemapFace)4);
val.SetPixels(texture.GetPixels(), (CubemapFace)5);
val.Apply();
RenderSettings.skybox.SetTexture("_Tex", (Texture)(object)val);
return val;
}
return new Cubemap(((Texture)texture).width, texture.format, false);
}
}