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 Map Upgrade Updated v1.1.0
MapUpgrade.dll
Decompiled 4 months agousing System; using 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 System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using REPOLib; using REPOLib.Modules; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("MapUpgrade")] [assembly: AssemblyDescription("R.E.P.O. Map Upgrade Mod! Originally developed by Ardot66, updated by Jettcodey.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Ardot66, Jettcodey")] [assembly: AssemblyProduct("MapUpgrade")] [assembly: AssemblyCopyright("")] [assembly: ComVisible(false)] [assembly: Guid("0bb70cc2-9b49-4a31-8adc-e4218f4f39b5")] [assembly: AssemblyFileVersion("1.1.0")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.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 Ardot.Jettcodey.REPO.MapUpgrade { public class MapToolChanges : MonoBehaviour { public record struct BackgroundObject(Transform Object, Vector3 OriginalScale) { [CompilerGenerated] private readonly bool PrintMembers(StringBuilder builder) { //IL_0027: 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) builder.Append("Object = "); builder.Append(Object); builder.Append(", OriginalScale = "); Vector3 originalScale = OriginalScale; builder.Append(((object)(Vector3)(ref originalScale)).ToString()); return true; } } public static MapToolChanges Instance; public static ConfigEntry<float> DefaultSize; public static ConfigEntry<float> ZoomRate; public MapToolController MapTool; public Camera MapCamera; public BackgroundObject[] BackgroundObjects = new BackgroundObject[3]; public const float ZoomScale = 2f; public float MaxZoom = 1f; public bool MapEnabled = true; private static FieldInfo _activeField; private float _lastZoom = -1f; public static void Init() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown ZoomRate = Plugin.Config.Bind<float>("Map", "ZoomSpeed", 1f, new ConfigDescription("Controls the speed that the map is zoomed", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>())); DefaultSize = Plugin.Config.Bind<float>("Map", "DefaultSize", 1f, new ConfigDescription("The starting size of the map", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>())); Plugin.Harmony.Patch((MethodBase)AccessTools.Method(typeof(PlayerAvatar), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(MapToolChanges), "PlayerAwakePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } public static void PlayerAwakePostfix(PlayerAvatar __instance) { ((Component)__instance.mapToolController).gameObject.AddComponent<MapToolChanges>(); } public void Awake() { MapTool = ((Component)this).GetComponent<MapToolController>(); if (_activeField == null) { _activeField = Utils.GetField<MapToolController>("Active"); } int backgroundObjectIndex = 0; Utils.ForObjectsInTree(((Component)Map.Instance).transform.parent, delegate(Transform transform) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) Camera component = ((Component)transform).GetComponent<Camera>(); if ((Object)(object)component != (Object)null) { MapCamera = component; } switch (((Object)transform).name) { case "Fog": case "Scanlines": case "Background": BackgroundObjects[backgroundObjectIndex] = new BackgroundObject(transform, transform.localScale); backgroundObjectIndex++; break; case "Completed": return false; } return true; }); SetZoom(DefaultSize.Value); } public void Start() { if ((Object)(object)PlayerAvatar.instance != (Object)null) { Plugin.UpdatePlayerMapTool(PlayerAvatar.instance); } } public void Update() { if (MapEnabled && (bool)_activeField.GetValue(MapTool)) { float axisRaw = Input.GetAxisRaw("Mouse ScrollWheel"); if (Mathf.Abs(axisRaw) > 0.0001f) { float zoom = Mathf.Clamp(MapCamera.orthographicSize / 2f - axisRaw * ZoomRate.Value, 0.5f, MaxZoom); SetZoom(zoom); } } } public void SetMapEnabled(bool enabled) { ((Renderer)MapTool.DisplayMesh).enabled = enabled; ((Behaviour)((Component)((Component)MapTool.DisplayMesh).transform.parent).GetComponentInChildren<Light>()).enabled = enabled; MapEnabled = enabled; } public void SetMaxZoom(float zoom) { if (Mathf.Abs(zoom - MaxZoom) > 0.1f) { SetZoom(zoom); } MaxZoom = zoom; } public void SetZoom(float zoom) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!(Mathf.Abs(zoom - _lastZoom) < 0.001f)) { _lastZoom = zoom; MapCamera.orthographicSize = zoom * 2f; for (int i = 0; i < BackgroundObjects.Length; i++) { BackgroundObject backgroundObject = BackgroundObjects[i]; Vector3 originalScale = backgroundObject.OriginalScale; backgroundObject.Object.localScale = new Vector3(originalScale.x * zoom, originalScale.y, originalScale.z * zoom); } } } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Ardot.Jettcodey.REPO.MapUpgrade"; public const string PLUGIN_NAME = "Map Upgrade"; public const string PLUGIN_VERSION = "1.1.0"; } [BepInPlugin("Ardot.Jettcodey.REPO.MapUpgrade", "Map Upgrade", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public static ConfigFile Config; public static Harmony Harmony; internal static ManualLogSource Logger; public static ConfigEntry<bool> MapRequiresUpgrade; public static ConfigEntry<float> MinCost; public static ConfigEntry<float> MaxCost; public static ConfigEntry<float> MapSizeIncrease; public static string getPath() { return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "mapupgrade.file"); } private void Awake() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown Logger = ((BaseUnityPlugin)this).Logger; Config = ((BaseUnityPlugin)this).Config; Harmony = new Harmony("Ardot.Jettcodey.REPO.MapUpgrade"); InitConfig(); MapToolChanges.Init(); Logger.LogInfo((object)"Plugin Map Upgrade v1.1.0 loaded successfully."); Logger.LogInfo((object)"Mod originally developed by Ardot66, updated by Jettcodey!"); BundleLoader.LoadBundle(getPath(), (Action<AssetBundle>)delegate(AssetBundle assetBundle) { string[] array = new string[1] { "Map Upgrade" }; string[] array2 = array; foreach (string text in array2) { try { Item val = assetBundle.LoadAsset<Item>(text); if ((Object)(object)val == (Object)null) { Logger.LogError((object)("Failed loading Item asset '" + text + "' from bundle.")); } else { GameObject val2 = assetBundle.LoadAsset<GameObject>(text); if ((Object)(object)val2 == (Object)null) { Logger.LogError((object)("Failed loading prefab for upgrade '" + text + "'. Make sure the prefab is included in the bundle.")); } else { string name = (((Object)val2).name = text ?? ""); ((Object)val).name = name; val.itemName = text ?? ""; Value val3 = ScriptableObject.CreateInstance<Value>(); val3.valueMin = MinCost.Value / 4f; val3.valueMax = MaxCost.Value / 4f; val.value = val3; ItemAttributes val4 = val2.GetComponent<ItemAttributes>() ?? val2.AddComponent<ItemAttributes>(); val4.item = val; Upgrader upgrader = val2.GetComponent<Upgrader>() ?? val2.AddComponent<Upgrader>(); PrefabRef val5 = Items.RegisterItem(val4); if (val5 == null) { Logger.LogWarning((object)("Items.RegisterItem returned null for '" + text + "'. It may already be registered or there was an error.")); } else { Logger.LogInfo((object)("Registered upgrade item '" + text + "'.")); } Upgrades.RegisterUpgrade(text, val, (Action<PlayerAvatar, int>)null, (Action<PlayerAvatar, int>)null); } } } catch (Exception arg) { Logger.LogError((object)$"Exception while registering upgrade '{text}': {arg}"); } } }, false); Config.SettingChanged += OnConfigChanged; } private void InitConfig() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown MapRequiresUpgrade = Config.Bind<bool>("Upgrade", "MapRequiresUpgrade", true, "If true, one map upgrade is required before the map can be used"); MinCost = Config.Bind<float>("Upgrade", "MinCost", 7000f, new ConfigDescription("The minimum price of a MapUpgrade in the shop", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50000f), Array.Empty<object>())); MaxCost = Config.Bind<float>("Upgrade", "MaxCost", 10000f, new ConfigDescription("The maximum price of a MapUpgrade in the shop", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50000f), Array.Empty<object>())); MapSizeIncrease = Config.Bind<float>("Upgrade", "MapSizeIncrease", 0.5f, new ConfigDescription("The amount that the map increases in size for every map upgrade", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>())); } private void OnConfigChanged(object sender, SettingChangedEventArgs e) { if ((e.ChangedSetting == MapSizeIncrease || e.ChangedSetting == MapRequiresUpgrade) && (Object)(object)PlayerAvatar.instance != (Object)null) { Update_MapUpgrade(); } } public static void Update_MapUpgrade() { if (LevelGenerator.Instance.Generated && !SemiFunc.MenuLevel() && (Object)(object)PlayerAvatar.instance != (Object)null) { UpdateAllPlayersMapTool(); } } public static void UpdateAllPlayersMapTool() { if (!((Object)(object)GameDirector.instance == (Object)null) && GameDirector.instance.PlayerList != null) { for (int i = 0; i < GameDirector.instance.PlayerList.Count; i++) { PlayerAvatar player = GameDirector.instance.PlayerList[i]; UpdatePlayerMapTool(player); } } } public static void UpdatePlayerMapTool(PlayerAvatar player) { if ((Object)(object)player == (Object)null || (Object)(object)player.mapToolController == (Object)null) { return; } MapToolChanges component = ((Component)player.mapToolController).GetComponent<MapToolChanges>(); if (!((Object)(object)component == (Object)null)) { int stat = Upgrader.GetStat(player.steamID, "playerUpgradeMapUpgrade"); int num = stat; if (!MapRequiresUpgrade.Value && num == 0) { num = 1; } component.SetMapEnabled(num > 0); component.SetMaxZoom(MapToolChanges.DefaultSize.Value + (float)(num - 1) * MapSizeIncrease.Value); } } } public class Upgrader : MonoBehaviourPunCallbacks { public ItemToggle _itemToggle; private PhotonView _photonView; private void Start() { _itemToggle = ((Component)this).GetComponent<ItemToggle>(); _photonView = ((Component)this).GetComponent<PhotonView>(); if (!StatsManager.instance.dictionaryOfDictionaries.ContainsKey("playerUpgradeMapUpgrade")) { StatsManager.instance.dictionaryOfDictionaries["playerUpgradeMapUpgrade"] = new Dictionary<string, int>(); } } public static void UpdateStat(int amount, string steamId, string stat) { if (!StatsManager.instance.dictionaryOfDictionaries.ContainsKey(stat)) { StatsManager.instance.dictionaryOfDictionaries[stat] = new Dictionary<string, int>(); } Dictionary<string, int> dictionary = StatsManager.instance.dictionaryOfDictionaries[stat]; if (!dictionary.ContainsKey(steamId)) { dictionary[steamId] = 0; } dictionary[steamId] += amount; Plugin.Update_MapUpgrade(); } public static int GetStat(string steamId, string upgradeName) { if (!StatsManager.instance.dictionaryOfDictionaries.ContainsKey(upgradeName)) { return 0; } Dictionary<string, int> dictionary = StatsManager.instance.dictionaryOfDictionaries[upgradeName]; int value; return dictionary.TryGetValue(steamId, out value) ? value : 0; } public void UpgradeMapUpgrade() { PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(_itemToggle.playerTogglePhotonID); if (!((Object)(object)val == (Object)null)) { string text = SemiFunc.PlayerGetSteamID(val); Plugin.Logger.LogInfo((object)string.Format("Your Map Upgrade level before: {0}", GetStat(text, "playerUpgradeMapUpgrade"))); UpdateStat(1, text, "playerUpgradeMapUpgrade"); if (SemiFunc.IsMultiplayer() && Utils.IsHost() && (Object)(object)_photonView != (Object)null) { _photonView.RPC("SyncUpgradeRPC", (RpcTarget)1, new object[2] { text, 1 }); } Plugin.Logger.LogInfo((object)string.Format("Your Map Upgrade level after: {0}", GetStat(text, "playerUpgradeMapUpgrade"))); } } [PunRPC] private void SyncUpgradeRPC(string steamId, int amount) { if (!StatsManager.instance.dictionaryOfDictionaries.ContainsKey("playerUpgradeMapUpgrade")) { StatsManager.instance.dictionaryOfDictionaries["playerUpgradeMapUpgrade"] = new Dictionary<string, int>(); } Dictionary<string, int> dictionary = StatsManager.instance.dictionaryOfDictionaries["playerUpgradeMapUpgrade"]; if (!dictionary.ContainsKey(steamId)) { dictionary[steamId] = 0; } dictionary[steamId] += amount; Plugin.Update_MapUpgrade(); } } public static class Utils { private static readonly Dictionary<Type, Dictionary<string, FieldInfo>> _fieldCache = new Dictionary<Type, Dictionary<string, FieldInfo>>(); public static object Get<O>(this O obj, string field) { return GetField<O>(field).GetValue(obj); } public static T Get<T, O>(this O obj, string field) { return (T)obj.Get(field); } public static void Set<T>(this T obj, string field, object value) { GetField<T>(field).SetValue(obj, value); } public static FieldInfo GetField<T>(string field) { Type typeFromHandle = typeof(T); if (!_fieldCache.TryGetValue(typeFromHandle, out Dictionary<string, FieldInfo> value)) { value = new Dictionary<string, FieldInfo>(); _fieldCache[typeFromHandle] = value; } if (!value.TryGetValue(field, out var value2)) { value2 = (value[field] = AccessTools.Field(typeFromHandle, field)); } return value2; } public static bool IsHost() { return SemiFunc.IsMasterClientOrSingleplayer(); } public static void ForObjectsInTree(Transform root, Predicate<Transform> action) { Stack<Transform> stack = new Stack<Transform>(); stack.Push(root); while (stack.Count > 0) { Transform val = stack.Pop(); if (action(val)) { for (int num = val.childCount - 1; num >= 0; num--) { stack.Push(val.GetChild(num)); } } } } } }