using System;
using System.Collections.Generic;
using System.Diagnostics;
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.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using On.RoR2;
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: AssemblyTitle("AutoArtifact")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoArtifact")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6083256f-0599-429c-bad4-4f68a768d167")]
[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 AutoArtifact
{
[BepInPlugin("com.Moffein.AutoArtifact", "AutoArtifact", "1.1.1")]
public class AutoArtifactPlugin : BaseUnityPlugin
{
public class ArtifactInfo
{
public ArtifactDef artifactDef;
public int stageClearCount;
public int playerCount;
public ArtifactInfo(ArtifactDef artifactDef, int stageClearCount, int playerCount)
{
this.artifactDef = artifactDef;
this.stageClearCount = stageClearCount;
this.playerCount = playerCount;
}
}
private static ConfigEntry<string> artifactListString;
public List<ArtifactInfo> artifactInfoList = new List<ArtifactInfo>();
public void Awake()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
ReadConfig();
RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(ParseArtifacts));
SceneDirector.Start += new hook_Start(SceneDirector_Start);
}
private void SceneDirector_Start(orig_Start orig, SceneDirector self)
{
if (NetworkServer.active && Object.op_Implicit((Object)(object)Run.instance) && Object.op_Implicit((Object)(object)RunArtifactManager.instance))
{
foreach (ArtifactInfo artifactInfo in artifactInfoList)
{
bool flag = artifactInfo.stageClearCount < 0 || Run.instance.stageClearCount >= artifactInfo.stageClearCount;
bool flag2 = artifactInfo.playerCount >= 0;
int num = Run.instance.participatingPlayerCount - artifactInfo.playerCount;
bool flag3 = !flag2 || num >= 0;
bool flag4 = flag3 && flag;
bool flag5 = RunArtifactManager.instance.IsArtifactEnabled(artifactInfo.artifactDef);
if (flag5 != flag4)
{
string text = (flag4 ? "Enabled" : "Disabled");
Debug.Log((object)("AutoArtifact: " + text + " " + artifactInfo.artifactDef.cachedName + ", Meets StageClearCount Requirement: " + flag + ", Meets PlayerCount Requirement: " + flag3));
RunArtifactManager.instance.SetArtifactEnabledServer(artifactInfo.artifactDef, flag4);
}
}
}
orig.Invoke(self);
}
private void ReadConfig()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_0030: Expected O, but got Unknown
artifactListString = ((BaseUnityPlugin)this).Config.Bind<string>(new ConfigDefinition("Settings", "Artifact List"), "", new ConfigDescription("List of artifacts separated by commas. Format is ArtifactName:StageClearCount:PlayerCount (ex. Command, Honor:10, Sacrifice:-1:5). Use negative numbers to skip a check (ex. Sacrifice:-1:5 means that StageCount requirement will be ignored, meaning only PlayerCount will determine whether the artifact should be activated).", (AcceptableValueBase)null, Array.Empty<object>()));
artifactListString.SettingChanged += ArtifactListString_SettingChanged;
}
private void ArtifactListString_SettingChanged(object sender, EventArgs e)
{
ParseArtifacts();
}
private void ParseArtifacts()
{
Debug.Log((object)"AutoArtifact: Parsing Artifact Stagecount List");
artifactInfoList.Clear();
string[] array = artifactListString.Value.Split(new char[1] { ',' });
string[] array2 = array;
foreach (string text in array2)
{
string text2 = text.Trim();
if (text2.Length <= 0)
{
continue;
}
ArtifactDef val = null;
int result = 0;
int result2 = -1;
string[] array3 = text.Split(new char[1] { ':' });
if (array3.Length != 0)
{
string partialName = array3[0].Trim();
val = GetArtifactDefFromString(partialName);
}
if ((Object)(object)val == (Object)null)
{
continue;
}
if (array3.Length > 1)
{
int.TryParse(array3[1].Trim(), out result);
if (array3.Length > 2)
{
int.TryParse(array3[2].Trim(), out result2);
}
}
artifactInfoList.Add(new ArtifactInfo(val, result, result2));
Debug.Log((object)("AutoArtifact: Added " + val.cachedName + " : " + result + " : " + result2));
}
}
private static ArtifactDef GetArtifactDefFromString(string partialName)
{
ArtifactDef val = ArtifactCatalog.FindArtifactDef(partialName);
if (Object.op_Implicit((Object)(object)val))
{
return val;
}
ArtifactDef[] artifactDefs = ArtifactCatalog.artifactDefs;
foreach (ArtifactDef val2 in artifactDefs)
{
if (GetArgNameForAtrifact(val2).ToLower().Contains(partialName.ToLower()))
{
return val2;
}
}
return null;
}
private static string GetArgNameForAtrifact(ArtifactDef artifactDef)
{
return Regex.Replace(Language.GetString(artifactDef.nameToken), "[ '-]", string.Empty);
}
}
}
namespace R2API.Utils
{
[AttributeUsage(AttributeTargets.Assembly)]
public class ManualNetworkRegistrationAttribute : Attribute
{
}
}