Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of AssetPlacer v0.1.1
Tomatobird.AssetPlacer.dll
Decompiled 4 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Tomatobird.AssetPlacer")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyInformationalVersion("0.1.1+716382ffcf26700d72dc0c02cb8fef0517cbe4e9")] [assembly: AssemblyProduct("AssetPlacer")] [assembly: AssemblyTitle("Tomatobird.AssetPlacer")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace AssetPlacer { [BepInPlugin("Tomatobird.AssetPlacer", "AssetPlacer", "0.1.1")] public class AssetPlacer : BaseUnityPlugin { internal static string objectPrefix = "TBAssetPlacer_"; private static string contentFolder = "AssetPlacer"; public static AssetPlacer Instance { get; private set; } = null; internal static ManualLogSource Logger { get; private set; } = null; internal Dictionary<int, string[]> PrefabSettings { get; private set; } = new Dictionary<int, string[]>(); internal static List<GameObject> GameObjects { get; private set; } = new List<GameObject>(); private string ConfigContentPath => Path.Combine(Paths.ConfigPath, "AssetPlacer"); private void Awake() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; Instance = this; int num = ((BaseUnityPlugin)this).Config.Bind<int>("General", "PrefabCount", 1, new ConfigDescription("How many prefab configurations should be created?", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())).Value + 1; bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UseConfigFolder", true, "Should assets be looked up from the config folder? Creates the folder if doesnt exist yet.").Value; bool value2 = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UsePluginsFolder", true, "Should assets be looked up from the plugins folder?").Value; contentFolder = ((BaseUnityPlugin)this).Config.Bind<string>("General", "FolderName", "AssetPlacer", "Name of folder to look for assets from in plugins.").Value; Logger.LogDebug((object)("ConfigContent path is: " + ConfigContentPath)); if (value && !CreatePaths(ConfigContentPath)) { AddAssets(ConfigContentPath); } if (value2) { string[] directories = Directory.GetDirectories(Paths.PluginPath, contentFolder, SearchOption.AllDirectories); string[] array = directories; foreach (string text in array) { Logger.LogDebug((object)("Adding assets from " + text)); AddAssets(text); } } for (int j = 1; j < num; j++) { string text2 = ((BaseUnityPlugin)this).Config.Bind<string>($"Prefab{j}", $"Prefab{j.ToString()}Name", "name", $"Name of Prefab {j.ToString()}. Names of the prefabs can be seen ").Value.Trim(); string value3 = ((BaseUnityPlugin)this).Config.Bind<string>($"Prefab{j}", $"Prefab{j.ToString()}SceneList", "CompanyBuilding", $"Scenes that Prefab {j.ToString()} should spawn on. ex: (CompanyBuilding, Level2Assurance)").Value; string text3 = ((BaseUnityPlugin)this).Config.Bind<string>($"Prefab{j}", $"Prefab{j.ToString()}Position", "0 0 0", $"The position of Prefab {j.ToString()} (x y z)").Value.Trim(); string text4 = ((BaseUnityPlugin)this).Config.Bind<string>($"Prefab{j}", $"Prefab{j.ToString()}Rotation", "0 0 0", $"The rotation of Prefab {j.ToString()} (x y z)").Value.Trim(); string text5 = ((BaseUnityPlugin)this).Config.Bind<string>($"Prefab{j}", $"Prefab{j.ToString()}Scale", "1 1 1", $"The scale of Prefab {j.ToString()} (x y z)").Value.Trim(); PrefabSettings.Add(j, new string[5] { text2, value3, text3, text4, text5 }); } Logger.LogDebug((object)("GameObjects in array: " + GameObjects.Count())); Logger.LogDebug((object)("PrefabSettings in dictionary: " + PrefabSettings.Count())); if (GameObjects.Count() != 0 && PrefabSettings.Count() != 0 && (value || value2)) { SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.sceneUnloaded += OnSceneUnloaded; } Logger.LogInfo((object)"Tomatobird.AssetPlacer v0.1.1 has loaded!"); } private void AddAssets(string path) { try { string[] files = Directory.GetFiles(path); Logger.LogDebug((object)"Iterating assets"); string[] array = files; foreach (string text in array) { Logger.LogDebug((object)("Iterating... " + text)); GameObject[] array2 = AssetBundle.LoadFromFile(Path.Combine(path, text)).LoadAllAssets<GameObject>(); Logger.LogDebug((object)("Assets length: " + array2.Length)); GameObject[] array3 = array2; foreach (GameObject val in array3) { Logger.LogInfo((object)$"Inserting '{((Object)val).name}' to the GameObjects list."); GameObjects.Add(val); } } } catch (Exception ex) { Logger.LogError((object)("There was an exception while trying to iterate through the files to add assets to placeable assets list. " + ex.Message)); } } private bool CreatePaths(string path) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); Logger.LogInfo((object)"AssetBundles directory created."); return true; } return false; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) Logger.LogDebug((object)("Scene Loaded: " + ((Scene)(ref scene)).name)); foreach (KeyValuePair<int, string[]> prefabSetting in PrefabSettings) { if (!prefabSetting.Value[1].Contains(((Scene)(ref scene)).name)) { continue; } foreach (GameObject gameObject in GameObjects) { if (prefabSetting.Value[0] == ((Object)gameObject).name) { Vector3 val = ParseVector3FromString(prefabSetting.Value[2]); Vector3 val2 = ParseVector3FromString(prefabSetting.Value[3]); Vector3 val3 = ParseVector3FromString(prefabSetting.Value[4]); Logger.LogDebug((object)$"Spawnning object {((Object)gameObject).name} at {val}, {val2}, {val3}"); Quaternion identity = Quaternion.identity; ((Quaternion)(ref identity)).eulerAngles = val2; GameObject val4 = Object.Instantiate<GameObject>(gameObject, val, identity); val4.transform.localScale = val3; ((Object)val4).name = objectPrefix + ((Object)val4).name; } } } } private void OnSceneUnloaded(Scene scene) { GameObject[] array = Object.FindObjectsOfType<GameObject>(); GameObject[] array2 = array; foreach (GameObject val in array2) { if (((Object)val).name.Contains(objectPrefix)) { Logger.LogDebug((object)("Destroying object: " + ((Object)val).name)); Object.Destroy((Object)(object)val); } } } private static Vector3 ParseVector3FromString(string s) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) try { string[] array = s.Split(' '); return new Vector3(float.Parse(array[0].Trim(), CultureInfo.InvariantCulture), float.Parse(array[1].Trim(), CultureInfo.InvariantCulture), float.Parse(array[2].Trim(), CultureInfo.InvariantCulture)); } catch (IndexOutOfRangeException ex) { Logger.LogError((object)("Specified string could not be parsed for a Vector3. Please use the correct format. Example: '-14.6 4.6 0' " + ex.Message)); } catch (ArgumentOutOfRangeException ex2) { Logger.LogError((object)("Specified string could not be parsed for a Vector3. Please use the correct format. Example: '-14.6 4.6 0' " + ex2.Message)); } catch (ArgumentNullException ex3) { Logger.LogError((object)("ArgumentNullException while trying to parse Vector3. " + ex3.Message)); } catch (FormatException ex4) { Logger.LogError((object)("FormatException while trying to parse Vector3. " + ex4.Message)); } return default(Vector3); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Tomatobird.AssetPlacer"; public const string PLUGIN_NAME = "AssetPlacer"; public const string PLUGIN_VERSION = "0.1.1"; } }