Please disclose if any significant portion of your mod was created 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 CookiesPresents v0.6.1
CookiesPresents.dll
Decompiled 2 years agousing System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Newtonsoft.Json; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("CookiesPresents")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("CookiesPresents")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("ae703313-8310-432d-a90d-1bac34d7b4bb")] [assembly: AssemblyFileVersion("0.5.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.5.0.0")] namespace CookiesGift; [BepInPlugin("ChocolateCookies.CookiesPresents", "CookiesPresents", "0.5.0")] public class CookiesGiftBase : BaseUnityPlugin { private const string modGUID = "ChocolateCookies.CookiesPresents"; private const string modName = "CookiesPresents"; internal const string modVersion = "0.5.0"; internal static List<Material> giftBoxMats = new List<Material>(); internal static List<Texture2D> giftBoxTextures = new List<Texture2D>(); internal static List<string> giftBoxNames = new List<string>(); private readonly Harmony harmony = new Harmony("ChocolateCookies.CookiesPresents"); private static CookiesGiftBase Instance; private ConfigEntry<string> assetBundleName; private ConfigEntry<string> jsonFileName; private void Awake() { Instance = this; ((BaseUnityPlugin)this).Logger.LogInfo((object)"THE GIFT THAT KEEPS ON GIVIN'!"); assetBundleName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "AssetBundleName", "giftbundle", "The name of the asset bundle that contains the gift box materials and textures."); jsonFileName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "JsonFileName", "giftboxes.json", "The name of the JSON file that contains the gift box configuration."); AssetBundle bundle = LoadAssetBundle(assetBundleName.Value); LoadGiftBoxConfiguration(bundle); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Got {giftBoxMats.Count} materials and {giftBoxTextures.Count} textures."); harmony.PatchAll(typeof(GiftPatch)); } private AssetBundle LoadAssetBundle(string bundleName) { return AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), bundleName)); } private void LoadGiftBoxConfiguration(AssetBundle bundle) { string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), jsonFileName.Value); if (File.Exists(text)) { foreach (GiftBoxConfig item3 in JsonConvert.DeserializeObject<List<GiftBoxConfig>>(File.ReadAllText(text))) { Material item = bundle.LoadAsset<Material>("Assets/ModelTextures/" + item3.material); Texture2D item2 = bundle.LoadAsset<Texture2D>("Assets/ModelTextures/" + item3.texture); giftBoxMats.Add(item); giftBoxTextures.Add(item2); giftBoxNames.Add(item3.name); } return; } ((BaseUnityPlugin)this).Logger.LogError((object)("JSON file not found at: " + text)); } } public class GiftBoxConfig { public string name { get; set; } public string material { get; set; } public string texture { get; set; } } [HarmonyPatch(typeof(GrabbableObject))] internal class GiftPatch { [HarmonyPatch("Start")] [HarmonyPostfix] private static void CreatePatch(GrabbableObject __instance) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown if (!(((Object)__instance.itemProperties).name == "GiftBox")) { return; } int index = Random.Range(0, CookiesGiftBase.giftBoxMats.Count); Material val = CookiesGiftBase.giftBoxMats[index]; Texture2D val2 = CookiesGiftBase.giftBoxTextures[index]; string text = CookiesGiftBase.giftBoxNames[index]; MeshRenderer componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<MeshRenderer>(); if ((Object)(object)componentInChildren != (Object)null) { ScanNodeProperties componentInChildren2 = ((Component)componentInChildren).GetComponentInChildren<ScanNodeProperties>(); if ((Object)(object)componentInChildren2 != (Object)null) { __instance.itemProperties.itemName = text; componentInChildren2.headerText = text; Material val3 = new Material(val); val3.mainTexture = (Texture)(object)val2; ((Renderer)componentInChildren).material = val3; Debug.Log((object)$"Gift Box Name: {text}, Material: {val}, Texture: {val2}"); } } } }