Decompiled source of ArtifactOfCare v1.0.1

ArtifactOfCare.dll

Decompiled a month ago
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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using R2API;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[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("ArtifactOfCare")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4b64d896d0729159dddba7597aecf49a5645cc28")]
[assembly: AssemblyProduct("ArtifactOfCare")]
[assembly: AssemblyTitle("ArtifactOfCare")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ArtifactOfCare;

public abstract class ArtifactBase
{
	public ArtifactDef ArtifactDef;

	public abstract string ArtifactName { get; }

	public abstract string ArtifactLangTokenName { get; }

	public abstract string ArtifactDescription { get; }

	public abstract Sprite ArtifactEnabledIcon { get; }

	public abstract Sprite ArtifactDisabledIcon { get; }

	public bool ArtifactEnabled => RunArtifactManager.instance.IsArtifactEnabled(ArtifactDef);

	public abstract void Init(ConfigFile config);

	protected void CreateLang()
	{
		LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_NAME", ArtifactName);
		LanguageAPI.Add("ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION", ArtifactDescription);
	}

	protected void CreateArtifact()
	{
		ArtifactDef = ScriptableObject.CreateInstance<ArtifactDef>();
		ArtifactDef.cachedName = "ARTIFACT_" + ArtifactLangTokenName;
		ArtifactDef.nameToken = "ARTIFACT_" + ArtifactLangTokenName + "_NAME";
		ArtifactDef.descriptionToken = "ARTIFACT_" + ArtifactLangTokenName + "_DESCRIPTION";
		ArtifactDef.smallIconSelectedSprite = ArtifactEnabledIcon;
		ArtifactDef.smallIconDeselectedSprite = ArtifactDisabledIcon;
		ContentAddition.AddArtifactDef(ArtifactDef);
	}

	public abstract void Hooks();
}
internal class ArtifactCare : ArtifactBase
{
	public static ConfigEntry<int> TimesToPrintMessageOnStart;

	public override string ArtifactName => "Artifact of Care";

	public override string ArtifactLangTokenName => "KERMIR_ARTIFACT_OF_CARE";

	public override string ArtifactDescription => "When enabled, most items and money will become shared. Some Multiplayer bonuses are reduced.";

	public override Sprite ArtifactEnabledIcon => Main.MainAssets.LoadAsset<Sprite>("ArtifactOfCare_On.png");

	public override Sprite ArtifactDisabledIcon => Main.MainAssets.LoadAsset<Sprite>("ArtifactOfCare_Off.png");

	public override void Init(ConfigFile config)
	{
		Log.Debug("Initializing Artifact Of Care Artifact");
		CreateLang();
		CreateArtifact();
		Hooks();
	}

	public override void Hooks()
	{
		Run.onRunStartGlobal += ToggleShareSuite;
	}

	private void ToggleShareSuite(Run run)
	{
		if (NetworkServer.active)
		{
			if (base.ArtifactEnabled)
			{
				Log.Debug("Enabling ShareSuite");
				Console.instance.SubmitCmd((NetworkUser)null, "ss_Enabled True", false);
			}
			else
			{
				Log.Debug("Disabling ShareSuite");
				Console.instance.SubmitCmd((NetworkUser)null, "ss_Enabled False", false);
			}
		}
	}
}
internal static class Log
{
	private static ManualLogSource _logSource;

	internal static void Init(ManualLogSource logSource)
	{
		_logSource = logSource;
	}

	internal static void Debug(object data)
	{
		_logSource.LogDebug(data);
	}

	internal static void Error(object data)
	{
		_logSource.LogError(data);
	}

	internal static void Fatal(object data)
	{
		_logSource.LogFatal(data);
	}

	internal static void Info(object data)
	{
		_logSource.LogInfo(data);
	}

	internal static void Message(object data)
	{
		_logSource.LogMessage(data);
	}

	internal static void Warning(object data)
	{
		_logSource.LogWarning(data);
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("Kermir.ArtifactOfcare", "ArtifactOfcare", "1.0.0")]
public class Main : BaseUnityPlugin
{
	public const string PluginGUID = "Kermir.ArtifactOfcare";

	public const string PluginAuthor = "Kermir";

	public const string PluginName = "ArtifactOfcare";

	public const string PluginVersion = "1.0.0";

	public static AssetBundle MainAssets;

	public List<ArtifactBase> Artifacts = new List<ArtifactBase>();

	public void Awake()
	{
		Log.Init(((BaseUnityPlugin)this).Logger);
		using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ArtifactOfCare.aocassets"))
		{
			MainAssets = AssetBundle.LoadFromStream(stream);
		}
		IEnumerable<Type> enumerable = from type in Assembly.GetExecutingAssembly().GetTypes()
			where !type.IsAbstract && type.IsSubclassOf(typeof(ArtifactBase))
			select type;
		foreach (Type item in enumerable)
		{
			ArtifactBase artifactBase = (ArtifactBase)Activator.CreateInstance(item);
			if (ValidateArtifact(artifactBase, Artifacts))
			{
				artifactBase.Init(((BaseUnityPlugin)this).Config);
			}
		}
	}

	public bool ValidateArtifact(ArtifactBase artifact, List<ArtifactBase> artifactList)
	{
		bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Artifact: " + artifact.ArtifactName, "Enable Artifact?", true, "Should this artifact appear for selection?").Value;
		if (value)
		{
			artifactList.Add(artifact);
		}
		return value;
	}
}