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 GTAPosterPack v1.0.2
plugins/GTAPosterPack/GTAPosterPack.dll
Decompiled 3 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AshwoodPosterPack")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.2.0")] [assembly: AssemblyInformationalVersion("1.0.2")] [assembly: AssemblyProduct("AshwoodPosterPack")] [assembly: AssemblyTitle("AshwoodPosterPack")] [assembly: AssemblyVersion("1.0.2.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 AshwoodPosterPack { [BepInPlugin("novamods.valheim.ashwoodposterpack", "Ashwood Poster Pack", "1.0.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class AshwoodPosterPackPlugin : BaseUnityPlugin { private struct PosterDimensions { public float FrameWidth; public float FrameHeight; public float ArtWidth; public float ArtHeight; } private sealed class PosterDefinition { public readonly string PieceName; public readonly string DisplayName; public readonly string Description; public readonly string TextureKey; public readonly float OuterWidth; public readonly float OuterHeight; public PosterDefinition(string pieceName, string displayName, string description, string textureKey, float outerWidth, float outerHeight) { PieceName = pieceName; DisplayName = displayName; Description = description; TextureKey = textureKey; OuterWidth = outerWidth; OuterHeight = outerHeight; } } public const string ModGuid = "novamods.valheim.ashwoodposterpack"; public const string ModName = "Ashwood Poster Pack"; public const string ModVersion = "1.0.2"; private Texture2D _iconTexture; private Texture2D _frameTexture; private readonly Dictionary<string, Texture2D> _posterTextures = new Dictionary<string, Texture2D>(); private readonly PosterDefinition[] _definitions = new PosterDefinition[3] { new PosterDefinition("piece_nova_poster_lounge_feet", "Ashwood Poster - Lounge", "Framed lounge poster.", "poster_lounge_feet", 1.25f, 1.92f), new PosterDefinition("piece_nova_poster_poolside", "Ashwood Poster - Poolside", "Framed poolside poster.", "poster_poolside", 1.25f, 1.92f), new PosterDefinition("piece_nova_poster_gta_duo", "Ashwood Poster - Getaway", "Framed getaway poster.", "poster_gta_duo", 1.92f, 1.2f) }; private const float FrameThickness = 0.075f; private void Awake() { _iconTexture = LoadEmbeddedPng("AshwoodPosterPack.Assets.icon.png"); _frameTexture = LoadEmbeddedPng("AshwoodPosterPack.Assets.ashwood_frame.png"); _posterTextures["poster_lounge_feet"] = LoadEmbeddedPng("AshwoodPosterPack.Assets.poster_lounge_feet.png"); _posterTextures["poster_poolside"] = LoadEmbeddedPng("AshwoodPosterPack.Assets.poster_poolside.png"); _posterTextures["poster_gta_duo"] = LoadEmbeddedPng("AshwoodPosterPack.Assets.poster_gta_duo.png"); PrefabManager.OnVanillaPrefabsAvailable += RegisterPieces; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Ashwood Poster Pack 1.0.2 loaded. Waiting for vanilla prefabs."); } private void RegisterPieces() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterPieces; try { PosterDefinition[] definitions = _definitions; foreach (PosterDefinition def in definitions) { RegisterPoster(def); } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Registered {_definitions.Length} ashwood posters."); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed registering Ashwood Poster Pack: " + ex)); } } private void RegisterPoster(PosterDefinition def) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Expected O, but got Unknown //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) Texture2D val = _posterTextures[def.TextureKey]; if ((Object)(object)val == (Object)null) { throw new InvalidOperationException("Missing poster image: " + def.TextureKey); } PosterDimensions size = ComputePosterDimensions(val, def.OuterWidth, def.OuterHeight); Sprite icon = CreateIconSprite(val); PieceConfig val2 = new PieceConfig(); val2.Name = def.DisplayName; val2.Description = def.Description; val2.PieceTable = "Hammer"; val2.Category = "Furniture"; val2.Usage = new string[2] { PieceUsages.Decor, PieceUsages.Furniture }; val2.Icon = icon; val2.AllowedInDungeons = true; PieceConfig val3 = val2; val3.AddRequirement("FineWood", 2, true); CustomPiece val4 = new CustomPiece(def.PieceName, true, val3); GameObject piecePrefab = val4.PiecePrefab; if ((Object)(object)piecePrefab == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not create poster prefab: " + def.PieceName)); return; } MeshRenderer component = piecePrefab.GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null) { ((Renderer)component).enabled = false; } BuildPosterVisual(piecePrefab, def, val, size); BoxCollider val5 = piecePrefab.GetComponent<BoxCollider>(); if ((Object)(object)val5 == (Object)null) { val5 = piecePrefab.AddComponent<BoxCollider>(); } val5.size = new Vector3(size.FrameWidth, size.FrameHeight, 0.12f); val5.center = new Vector3(0f, size.FrameHeight * 0.5f, 0f); ((Collider)val5).isTrigger = false; if (!PieceManager.Instance.AddPiece(val4)) { ((BaseUnityPlugin)this).Logger.LogError((object)("Jotunn rejected piece: " + def.PieceName)); return; } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Registered {def.DisplayName}: original {((Texture)val).width}x{((Texture)val).height}px, art {size.ArtWidth:F4}x{size.ArtHeight:F4}m, frame {size.FrameWidth:F4}x{size.FrameHeight:F4}m"); } private static PosterDimensions ComputePosterDimensions(Texture2D image, float maxFrameWidth, float maxFrameHeight) { if ((Object)(object)image == (Object)null || ((Texture)image).width < 1 || ((Texture)image).height < 1) { throw new ArgumentException("The poster art must be a valid image."); } float num = maxFrameWidth - 0.15f; float num2 = maxFrameHeight - 0.15f; float num3 = (float)((Texture)image).width / (float)((Texture)image).height; float num4 = Mathf.Min(num, num2 * num3); float num5 = num4 / num3; return new PosterDimensions { ArtWidth = num4, ArtHeight = num5, FrameWidth = num4 + 0.15f, FrameHeight = num5 + 0.15f }; } private void BuildPosterVisual(GameObject root, PosterDefinition def, Texture2D art, PosterDimensions size) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Expected O, but got Unknown //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Expected O, but got Unknown //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0365: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_0407: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_0444: Unknown result type (might be due to invalid IL or missing references) //IL_046f: Unknown result type (might be due to invalid IL or missing references) //IL_047d: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_04b5: Unknown result type (might be due to invalid IL or missing references) //IL_04e4: Unknown result type (might be due to invalid IL or missing references) //IL_04fb: Unknown result type (might be due to invalid IL or missing references) //IL_0527: Unknown result type (might be due to invalid IL or missing references) //IL_053e: Unknown result type (might be due to invalid IL or missing references) //IL_0562: Unknown result type (might be due to invalid IL or missing references) //IL_058b: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) Shader val = FindShader("Standard", "Legacy Shaders/Diffuse"); Shader val2 = FindShader("Unlit/Texture", "Unlit/Transparent", "Legacy Shaders/Self-Illumin/Diffuse", "Standard", "Legacy Shaders/Diffuse"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { throw new InvalidOperationException("Could not find supported frame and art shaders for the posters."); } float num = 0.075f; float num2 = 0.055f; float num3 = 0.035f; float num4 = 0.022f; GameObject val3 = new GameObject("Poster visual"); val3.layer = root.layer; val3.transform.SetParent(root.transform, false); val3.transform.localPosition = Vector3.zero; float artWidth = size.ArtWidth; float artHeight = size.ArtHeight; float frameWidth = size.FrameWidth; float frameHeight = size.FrameHeight; float num5 = frameHeight * 0.5f; Material material = new Material(val) { name = def.DisplayName + " frame material" }; ApplyMainTexture(material, _frameTexture); SetColorIfPresent(material, new Color(0.92f, 0.9f, 0.88f, 1f)); SetSmoothness(material, 0.18f); SetMetallic(material, 0.02f); Material material2 = new Material(val) { name = def.DisplayName + " backing material" }; ApplyMainTexture(material2, _frameTexture); SetColorIfPresent(material2, new Color(0.18f, 0.16f, 0.15f, 1f)); SetSmoothness(material2, 0.05f); SetMetallic(material2, 0f); Material val4 = new Material(val2) { name = def.DisplayName + " art material" }; if (!val4.HasProperty("_MainTex") && !val4.HasProperty("_BaseMap")) { throw new InvalidOperationException("Selected poster shader has no supported texture slot: " + ((Object)val2).name); } ApplyMainTexture(val4, art); SetColorIfPresent(val4, Color.white); SetSmoothness(val4, 0f); SetMetallic(val4, 0f); if (val4.HasProperty("_Mode")) { val4.SetFloat("_Mode", 0f); } if (val4.HasProperty("_ZWrite")) { val4.SetInt("_ZWrite", 1); } if (val4.HasProperty("_Cull")) { val4.SetInt("_Cull", 2); } if (val4.HasProperty("_EmissionColor")) { val4.SetColor("_EmissionColor", new Color(0.36f, 0.36f, 0.36f)); if (((Object)val2).name == "Standard") { val4.EnableKeyword("_EMISSION"); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Poster " + def.DisplayName + " image " + ((Texture)art).width + "x" + ((Texture)art).height + " on shader " + ((Object)val2).name + "; double-sided art surfaces enabled.")); CreateBox(val3.transform, "Backing", new Vector3(0f, num5, num4 * -0.5f), new Vector3(frameWidth, frameHeight, num4), material2); CreateBox(val3.transform, "Frame Left", new Vector3((0f - (frameWidth - num)) * 0.5f, num5, num2 * 0.5f), new Vector3(num, frameHeight, num2), material); CreateBox(val3.transform, "Frame Right", new Vector3((frameWidth - num) * 0.5f, num5, num2 * 0.5f), new Vector3(num, frameHeight, num2), material); CreateBox(val3.transform, "Frame Top", new Vector3(0f, frameHeight - num * 0.5f, num2 * 0.5f), new Vector3(frameWidth, num, num2), material); CreateBox(val3.transform, "Frame Bottom", new Vector3(0f, num * 0.5f, num2 * 0.5f), new Vector3(frameWidth, num, num2), material); CreateBox(val3.transform, "Inner Lip Left", new Vector3((0f - (artWidth + num3)) * 0.5f, num5, 0.015f), new Vector3(num3, artHeight, 0.014f), material); CreateBox(val3.transform, "Inner Lip Right", new Vector3((artWidth + num3) * 0.5f, num5, 0.015f), new Vector3(num3, artHeight, 0.014f), material); CreateBox(val3.transform, "Inner Lip Top", new Vector3(0f, num + artHeight + num3 * 0.5f, 0.015f), new Vector3(artWidth + num3 * 2f, num3, 0.014f), material); CreateBox(val3.transform, "Inner Lip Bottom", new Vector3(0f, num - num3 * 0.5f, 0.015f), new Vector3(artWidth + num3 * 2f, num3, 0.014f), material); CreateQuad(val3.transform, "Art FRONT", new Vector3(0f, num5, 0.037f), artWidth, artHeight, val4, faceBackward: false); CreateQuad(val3.transform, "Art BACK", new Vector3(0f, num5, -0.037f), artWidth, artHeight, val4, faceBackward: true); } private static Shader FindShader(params string[] candidates) { string[] array = candidates; for (int i = 0; i < array.Length; i++) { Shader val = Shader.Find(array[i]); if ((Object)(object)val != (Object)null && val.isSupported) { return val; } } Material[] array2 = Resources.FindObjectsOfTypeAll<Material>(); foreach (Material val2 in array2) { if ((Object)(object)val2 == (Object)null || (Object)(object)val2.shader == (Object)null || !val2.shader.isSupported) { continue; } array = candidates; foreach (string text in array) { if (((Object)val2.shader).name == text) { return val2.shader; } } } return null; } private static void CreateBox(Transform parent, string name, Vector3 localPosition, Vector3 localScale, Material material) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)obj).name = name; obj.layer = ((Component)parent).gameObject.layer; obj.transform.SetParent(parent, false); obj.transform.localPosition = localPosition; obj.transform.localScale = localScale; Collider component = obj.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { component.enabled = false; } ((Renderer)obj.GetComponent<MeshRenderer>()).sharedMaterial = material; } private static void CreateQuad(Transform parent, string name, Vector3 localPosition, float width, float height, Material material, bool faceBackward) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Expected O, but got Unknown //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) float num = width * 0.5f; float num2 = height * 0.5f; Vector3[] vertices = (Vector3[])(object)new Vector3[4] { new Vector3(0f - num, 0f - num2, 0f), new Vector3(num, 0f - num2, 0f), new Vector3(0f - num, num2, 0f), new Vector3(num, num2, 0f) }; Vector2[] uv = (Vector2[])(object)((!faceBackward) ? new Vector2[4] { new Vector2(0f, 0f), new Vector2(1f, 0f), new Vector2(0f, 1f), new Vector2(1f, 1f) } : new Vector2[4] { new Vector2(1f, 0f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f) }); int[] triangles = ((!faceBackward) ? new int[6] { 0, 1, 2, 1, 3, 2 } : new int[6] { 0, 2, 1, 1, 2, 3 }); Vector3 val = (faceBackward ? Vector3.back : Vector3.forward); Mesh val2 = new Mesh(); ((Object)val2).name = name + " render mesh"; val2.vertices = vertices; val2.uv = uv; val2.triangles = triangles; val2.normals = (Vector3[])(object)new Vector3[4] { val, val, val, val }; Mesh val3 = val2; val3.RecalculateBounds(); GameObject val4 = new GameObject(name) { layer = ((Component)parent).gameObject.layer }; val4.transform.SetParent(parent, false); val4.transform.localPosition = localPosition; val4.AddComponent<MeshFilter>().sharedMesh = val3; ((Renderer)val4.AddComponent<MeshRenderer>()).sharedMaterial = material; } private static void ApplyMainTexture(Material material, Texture2D texture) { if (!((Object)(object)texture == (Object)null)) { if (material.HasProperty("_MainTex")) { material.SetTexture("_MainTex", (Texture)(object)texture); } if (material.HasProperty("_BaseMap")) { material.SetTexture("_BaseMap", (Texture)(object)texture); } } } private static void SetColorIfPresent(Material material, Color color) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (material.HasProperty("_Color")) { material.SetColor("_Color", color); } if (material.HasProperty("_BaseColor")) { material.SetColor("_BaseColor", color); } } private static void SetSmoothness(Material material, float value) { if (material.HasProperty("_Glossiness")) { material.SetFloat("_Glossiness", value); } if (material.HasProperty("_Smoothness")) { material.SetFloat("_Smoothness", value); } } private static void SetMetallic(Material material, float value) { if (material.HasProperty("_Metallic")) { material.SetFloat("_Metallic", value); } } private Sprite CreateIconSprite(Texture2D texture) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)texture == (Object)null) { texture = _iconTexture; } return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0.5f, 0.5f), 100f); } private Texture2D LoadEmbeddedPng(string resourceName) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); if (stream == null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Missing embedded resource: " + resourceName)); return null; } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); byte[] array = memoryStream.ToArray(); Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, array, false)) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not decode texture: " + resourceName)); return null; } ((Object)val).name = resourceName; ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)1; return val; } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Failed loading embedded PNG " + resourceName + ": " + ex)); return null; } } } }