using System;
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 AtlasLib.Saving;
using AtlasLib.Utils;
using BepInEx;
using HarmonyLib;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AtlasLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AtlasLib")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cf4a38ab-c781-4066-83d2-47a9f5713d5c")]
[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 AtlasLib
{
[BepInPlugin("wafflethings.atlaslib", "AtlasLib", "3.0.7")]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "wafflethings.atlaslib";
private const string Name = "AtlasLib";
private const string Version = "3.0.7";
private void Start()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
new Harmony("wafflethings.atlaslib").PatchAll();
}
private void OnDestroy()
{
SaveFile.SaveAll();
}
}
}
namespace AtlasLib.Weapons
{
public class BasicWeapon : Weapon
{
private WeaponInfo _info;
public override WeaponInfo Info => _info;
public BasicWeapon(WeaponInfo info)
{
_info = info;
}
}
[HarmonyPatch]
public static class WeaponRegistry
{
public static readonly List<Weapon> Weapons = new List<Weapon>();
private static readonly SaveFile<Dictionary<int, Dictionary<string, int>>> s_weaponOwnership = SaveFile.RegisterFile(new SaveFile<Dictionary<int, Dictionary<string, int>>>("weapons_owned.json", null));
private static List<Weapon> s_guns = new List<Weapon>();
private static List<Weapon> s_fists = new List<Weapon>();
private static Dictionary<string, int> CurrentOwnershipDict
{
get
{
EnsureDictExistsForSlot();
return s_weaponOwnership.Data[GameProgressSaver.currentSlot];
}
}
public static bool CheckOwnership(string id)
{
if (id.StartsWith("weapon."))
{
throw new Exception("Id starts with 'weapon.'. Don't do that, it gets added automatically");
}
id = "weapon." + id;
if (!CurrentOwnershipDict.ContainsKey(id))
{
CurrentOwnershipDict.Add(id, 0);
}
return CurrentOwnershipDict[id] == 1;
}
public static void RegisterWeapon(Weapon weapon)
{
if (weapon.Info.WeaponType == WeaponType.Gun)
{
s_guns.Add(weapon);
}
else
{
s_fists.Add(weapon);
}
Weapons.Add(weapon);
}
public static void RegisterWeapons(IEnumerable<Weapon> weapons)
{
foreach (Weapon weapon in weapons)
{
RegisterWeapon(weapon);
}
}
private static void EnsureDictExistsForSlot()
{
if (!s_weaponOwnership.Data.ContainsKey(GameProgressSaver.currentSlot))
{
s_weaponOwnership.Data.Add(GameProgressSaver.currentSlot, new Dictionary<string, int>());
}
}
[HarmonyPatch(typeof(GunSetter), "ResetWeapons")]
[HarmonyPostfix]
private static void GiveGuns(GunSetter __instance)
{
s_guns = s_guns.OrderBy((Weapon gun) => gun.Info.OrderInSlot).ToList();
foreach (Weapon s_gun in s_guns)
{
if (s_gun.Selection != 0)
{
List<List<GameObject>> list = new List<List<GameObject>>
{
__instance.gunc.slot1,
__instance.gunc.slot2,
__instance.gunc.slot3,
__instance.gunc.slot4,
__instance.gunc.slot5,
__instance.gunc.slot6
};
GameObject val = s_gun.Create(((Component)__instance).transform);
list[s_gun.Info.Slot].Add(val);
val.SetActive(false);
}
}
}
[HarmonyPatch(typeof(FistControl), "ResetFists")]
[HarmonyPostfix]
private static void GiveFists(FistControl __instance)
{
s_fists = s_fists.OrderBy((Weapon gun) => gun.Info.OrderInSlot).ToList();
foreach (Weapon s_fist in s_fists)
{
if (s_fist.Selection == WeaponSelection.Disabled || !s_fist.Owned)
{
break;
}
GameObject val = s_fist.Create(((Component)__instance).transform);
val.SetActive(false);
MonoSingleton<FistControl>.Instance.spawnedArms.Add(val);
MonoSingleton<FistControl>.Instance.spawnedArmNums.Add(s_fist.Info.Slot);
}
}
[HarmonyPatch(typeof(GameProgressSaver), "CheckGear")]
[HarmonyPrefix]
private static bool CheckGearForCustoms(ref int __result, string gear)
{
foreach (Weapon weapon in Weapons)
{
if (weapon.Info?.Id != gear)
{
continue;
}
__result = CurrentOwnershipDict["weapon." + weapon.Info.Id];
return false;
}
return true;
}
[HarmonyPatch(typeof(GameProgressSaver), "AddGear")]
[HarmonyPrefix]
private static bool AddGearForCustoms(string gear)
{
foreach (Weapon weapon in Weapons)
{
if (weapon.Info.Id != gear)
{
continue;
}
CurrentOwnershipDict["weapon." + weapon.Info.Id] = 1;
return false;
}
return true;
}
}
public abstract class Weapon
{
public abstract WeaponInfo Info { get; }
public virtual WeaponSelection Selection => Owned ? ((WeaponSelection)MonoSingleton<PrefsManager>.Instance.GetInt("weapon." + Info.Id, 0)) : WeaponSelection.Disabled;
public virtual bool Owned => WeaponRegistry.CheckOwnership(Info.Id);
public virtual GameObject Create(Transform parent)
{
GameObject val = Object.Instantiate<GameObject>(Info.WeaponObjects[(int)(Selection - 1)], parent);
if (Info.UseFreshness)
{
MonoSingleton<StyleHUD>.Instance.weaponFreshness.Add(val, 10f);
}
return val;
}
}
[CreateAssetMenu(menuName = "AtlasLib/Weapon Info")]
public class WeaponInfo : ScriptableObject
{
public GameObject[] WeaponObjects = (GameObject[])(object)new GameObject[1];
public WeaponType WeaponType = WeaponType.Gun;
[Space(10f)]
public string Id = "rev0";
public int Slot = 0;
public int OrderInSlot;
public bool UseFreshness = true;
public WeaponInfo(GameObject[] weaponObjects, string id, int slot, WeaponType weaponType = WeaponType.Gun, int orderInSlot = 0, bool useFreshness = true)
{
WeaponObjects = weaponObjects;
Id = id;
Slot = slot;
WeaponType = weaponType;
OrderInSlot = orderInSlot;
UseFreshness = useFreshness;
}
}
public enum WeaponSelection
{
Disabled,
Standard,
Alternate
}
public enum WeaponType
{
Gun,
Fist
}
}
namespace AtlasLib.Utils
{
public class CoroutineRunner : MonoBehaviour
{
private static CoroutineRunner _instance;
public static CoroutineRunner Instance
{
get
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_instance == (Object)null)
{
_instance = new GameObject("AtlasLib Coroutines").AddComponent<CoroutineRunner>();
Object.DontDestroyOnLoad((Object)(object)((Component)_instance).gameObject);
}
return _instance;
}
}
}
public static class Inputs
{
public static bool FirePressed => MonoSingleton<InputManager>.Instance.InputSource.Fire1.WasPerformedThisFrame;
public static bool FireHeld => MonoSingleton<InputManager>.Instance.InputSource.Fire1.IsPressed;
public static bool FireReleased => MonoSingleton<InputManager>.Instance.InputSource.Fire1.WasCanceledThisFrame;
public static bool AltFirePressed => MonoSingleton<InputManager>.Instance.InputSource.Fire2.WasPerformedThisFrame;
public static bool AltFireHeld => MonoSingleton<InputManager>.Instance.InputSource.Fire2.IsPressed;
public static bool AltFireReleased => MonoSingleton<InputManager>.Instance.InputSource.Fire2.WasCanceledThisFrame;
public static bool PunchPressed => MonoSingleton<InputManager>.Instance.InputSource.Punch.WasPerformedThisFrame;
public static bool PunchHeld => MonoSingleton<InputManager>.Instance.InputSource.Punch.IsPressed;
public static bool PunchReleased => MonoSingleton<InputManager>.Instance.InputSource.Punch.WasCanceledThisFrame;
}
public static class PathUtils
{
public static string GameDirectory()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Invalid comparison between Unknown and I4
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Invalid comparison between Unknown and I4
string text = Application.dataPath;
if ((int)Application.platform == 1)
{
text = Utility.ParentDirectory(text, 2);
}
else if ((int)Application.platform == 2)
{
text = Utility.ParentDirectory(text, 1);
}
return text;
}
public static string ModPath()
{
return Assembly.GetCallingAssembly().Location.Substring(0, Assembly.GetCallingAssembly().Location.LastIndexOf(Path.DirectorySeparatorChar));
}
}
public static class UnityUtils
{
public static GameObject GetChild(this GameObject from, string name)
{
Transform obj = from.transform.Find(name);
return ((obj != null) ? ((Component)obj).gameObject : null) ?? null;
}
public static List<GameObject> FindSceneObjects(string sceneName)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
List<GameObject> list = new List<GameObject>();
GameObject[] array = Object.FindObjectsOfType<GameObject>();
foreach (GameObject val in array)
{
Scene scene = val.scene;
if (((Scene)(ref scene)).name == sceneName)
{
list.Add(val);
}
}
return list;
}
public static List<GameObject> ChildrenList(this GameObject from)
{
List<GameObject> list = new List<GameObject>();
for (int i = 0; i < from.transform.childCount; i++)
{
list.Add(((Component)from.transform.GetChild(i)).gameObject);
}
return list;
}
public static bool Contains(this LayerMask mask, int layer)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
return LayerMask.op_Implicit(mask) == (LayerMask.op_Implicit(mask) | (1 << layer));
}
}
}
namespace AtlasLib.Style
{
public class Style
{
public readonly string Id;
public readonly string Name;
public readonly Color Colour = StyleColours.White;
public readonly float FreshnessDecayMultiplier = 1f;
public string FullString
{
get
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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)
if (Colour != StyleColours.White)
{
return "<color=" + ColorUtility.ToHtmlStringRGB(Colour) + ">" + Name + "</color>";
}
return Name;
}
}
public Style(string id, string name, float freshnessDecayMultiplier = 1f)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Id = id;
Name = name;
FreshnessDecayMultiplier = freshnessDecayMultiplier;
}
public Style(string id, string name, Color colour)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
Id = id;
Name = name;
Colour = colour;
}
public Style(string id, string name, float freshnessDecayMultiplier, Color colour)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
Id = id;
Name = name;
Colour = colour;
FreshnessDecayMultiplier = freshnessDecayMultiplier;
}
}
public static class StyleColours
{
public static Color Cyan => Color.cyan;
public static Color Gray => Color.grey;
public static Color Green => Color.green;
public static Color Orange => new Color(1f, 0.5f, 0f);
public static Color White => Color.white;
}
[HarmonyPatch]
public static class StyleRegistry
{
private static List<Style> s_styles = new List<Style>();
public static void Register(Style style)
{
s_styles.Add(style);
}
[HarmonyPatch(typeof(StyleHUD), "Start")]
[HarmonyPostfix]
private static void AddCustomStyles(StyleHUD __instance)
{
foreach (Style s_style in s_styles)
{
if (s_style.FreshnessDecayMultiplier != 1f)
{
__instance.freshnessDecayMultiplierDict.Add(s_style.Id, s_style.FreshnessDecayMultiplier);
}
__instance.RegisterStyleItem(s_style.Id, s_style.FullString);
}
}
}
}
namespace AtlasLib.Saving
{
public class SaveFile<T> : SaveFile where T : new()
{
public T Data;
private T _defaultValue;
private string DefaultPath => Path.Combine("wafflethings", "AtlasLib");
internal SaveFile(string fileName, T defaultValue)
: base(fileName)
{
Data = new T();
_folder = DefaultPath;
_defaultValue = defaultValue;
}
public SaveFile(string fileName, string folder, T defaultValue)
: base(fileName)
{
Data = new T();
_folder = folder;
_defaultValue = defaultValue;
}
protected virtual string Serialize(T value)
{
return JsonConvert.SerializeObject((object)value);
}
protected virtual T Deserialize(string value)
{
return JsonConvert.DeserializeObject<T>(value);
}
protected override void LoadData()
{
if (!File.Exists(base.FilePath))
{
Data = _defaultValue;
return;
}
try
{
Data = Deserialize(File.ReadAllText(base.FilePath));
}
catch (JsonSerializationException)
{
Data = _defaultValue;
}
}
protected override void SaveData()
{
File.WriteAllText(base.FilePath, Serialize(Data));
}
}
public abstract class SaveFile
{
private static readonly List<SaveFile> s_saveFiles = new List<SaveFile>();
protected string _folder;
private readonly string _fileName;
private static string AppData => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
private string FileFolder => Path.Combine(AppData, _folder);
protected string FilePath => Path.Combine(FileFolder, _fileName);
protected SaveFile(string fileName)
{
_fileName = fileName;
}
protected abstract void LoadData();
protected abstract void SaveData();
public static void SaveAll()
{
foreach (SaveFile s_saveFile in s_saveFiles)
{
if (!Directory.Exists(s_saveFile.FileFolder))
{
Directory.CreateDirectory(s_saveFile.FileFolder);
}
s_saveFile.SaveData();
}
}
public static SaveFile<T> RegisterFile<T>(SaveFile<T> file) where T : new()
{
file.LoadData();
s_saveFiles.Add(file);
return file;
}
}
}
namespace AtlasLib.Pages
{
public class BasicPage : Page
{
private readonly GameObject _prefab;
public BasicPage(GameObject prefab)
{
_prefab = prefab;
}
public override void CreatePage(Transform parent)
{
base.CreatePage(parent);
Objects.Add(Object.Instantiate<GameObject>(_prefab, parent));
}
}
internal class DefaultWeaponPage : Page
{
private static readonly string[] s_page1Content = new string[12]
{
"RevolverButton", "ShotgunButton", "NailgunButton", "RailcannonButton", "RocketLauncherButton", "ArmButton", "RevolverWindow", "ShotgunWindow", "NailgunWindow", "RailcannonWindow",
"RocketLauncherWindow", "ArmWindow"
};
public override void CreatePage(Transform parent)
{
base.CreatePage(parent);
string[] array = s_page1Content;
foreach (string name in array)
{
Objects.Add(((Component)parent).gameObject.GetChild(name));
}
}
}
public abstract class Page
{
protected readonly List<GameObject> Objects = new List<GameObject>();
private readonly Dictionary<GameObject, bool> _state = new Dictionary<GameObject, bool>();
public virtual void CreatePage(Transform parent)
{
Objects.Clear();
_state.Clear();
}
public virtual void EnablePage()
{
foreach (GameObject @object in Objects)
{
if (!_state.ContainsKey(@object))
{
_state.Add(@object, @object.activeSelf);
}
@object.SetActive(_state[@object]);
}
}
public virtual void DisablePage()
{
foreach (GameObject @object in Objects)
{
_state[@object] = @object.activeSelf;
@object.SetActive(false);
}
}
}
[HarmonyPatch]
public static class PageRegistry
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static UnityAction <>9__8_0;
public static UnityAction <>9__8_1;
internal void <ShopStart>b__8_0()
{
ButtonScroll(isLeft: true);
}
internal void <ShopStart>b__8_1()
{
ButtonScroll(isLeft: false);
}
}
private static int s_currentPage;
private static readonly List<Page> s_pages = new List<Page>
{
new DefaultWeaponPage()
};
private static GameObject s_leftScrollButton;
private static GameObject s_rightScrollButton;
public static void RegisterPage(Page page, int at = -1)
{
if (at == -1)
{
s_pages.Add(page);
}
else
{
s_pages.Insert(at, page);
}
}
public static void RegisterPages(IEnumerable<Page> pages)
{
foreach (Page page in pages)
{
RegisterPage(page);
}
}
public static void RefreshPages(int changedBy)
{
if (s_pages.Count == 0)
{
s_leftScrollButton.SetActive(false);
s_leftScrollButton.SetActive(true);
return;
}
s_pages[s_currentPage].EnablePage();
if (changedBy != 0)
{
s_pages[s_currentPage - changedBy].DisablePage();
}
}
public static void ButtonScroll(bool isLeft)
{
if (isLeft)
{
if (s_currentPage > 0)
{
s_currentPage--;
RefreshPages(-1);
}
}
else if (s_currentPage < s_pages.Count - 1)
{
s_currentPage++;
RefreshPages(1);
}
}
[HarmonyPatch(typeof(ShopZone), "Start")]
[HarmonyPostfix]
private static void ShopStart(ShopZone __instance)
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Expected O, but got Unknown
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Expected O, but got Unknown
if (!((Object)(object)((Component)__instance).gameObject.GetChild("Canvas")?.GetChild("Weapons") != (Object)null))
{
return;
}
GameObject child = ((Component)__instance).gameObject.GetChild("Canvas/Weapons/BackButton (1)");
GameObject val = Object.Instantiate<GameObject>(child, child.transform.parent);
ShopButton component = val.GetComponent<ShopButton>();
component.toActivate = Array.Empty<GameObject>();
component.toDeactivate = Array.Empty<GameObject>();
s_leftScrollButton = Object.Instantiate<GameObject>(val, val.transform.parent);
RectTransform component2 = s_leftScrollButton.GetComponent<RectTransform>();
component2.sizeDelta -= new Vector2(component2.sizeDelta.x / 2f, 0f);
s_leftScrollButton.transform.localPosition = new Vector3(-220f, -145f, -45f);
s_rightScrollButton = Object.Instantiate<GameObject>(s_leftScrollButton, val.transform.parent);
s_rightScrollButton.transform.localPosition = new Vector3(-140f, -145f, -45f);
s_leftScrollButton.GetComponentInChildren<TMP_Text>().text = "<<";
((Transform)s_leftScrollButton.GetComponent<RectTransform>()).SetAsFirstSibling();
ButtonClickedEvent onClick = s_leftScrollButton.GetComponentInChildren<Button>().onClick;
object obj = <>c.<>9__8_0;
if (obj == null)
{
UnityAction val2 = delegate
{
ButtonScroll(isLeft: true);
};
<>c.<>9__8_0 = val2;
obj = (object)val2;
}
((UnityEvent)onClick).AddListener((UnityAction)obj);
s_rightScrollButton.GetComponentInChildren<TMP_Text>().text = ">>";
((Transform)s_rightScrollButton.GetComponent<RectTransform>()).SetAsFirstSibling();
ButtonClickedEvent onClick2 = s_rightScrollButton.GetComponentInChildren<Button>().onClick;
object obj2 = <>c.<>9__8_1;
if (obj2 == null)
{
UnityAction val3 = delegate
{
ButtonScroll(isLeft: false);
};
<>c.<>9__8_1 = val3;
obj2 = (object)val3;
}
((UnityEvent)onClick2).AddListener((UnityAction)obj2);
s_currentPage = 0;
foreach (Page s_page in s_pages)
{
s_page.CreatePage(((Component)__instance).gameObject.GetChild("Canvas/Weapons").transform);
if (s_page.GetType() != typeof(DefaultWeaponPage))
{
s_page.DisablePage();
}
}
Object.Destroy((Object)(object)val);
}
[HarmonyPatch(typeof(ShopZone), "TurnOn")]
[HarmonyPostfix]
private static void RefreshOnEntrance()
{
RefreshPages(0);
}
}
}