using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using I2.Loc;
using Microsoft.CodeAnalysis;
using On.I2.Loc;
using On.Voxels.TowerDefense.ProfileInternals;
using UnityEngine;
using Voxels.TowerDefense;
using Voxels.TowerDefense.ProfileInternals;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BNAPI
{
public static class CustomSprites
{
public static Dictionary<string, Sprite> Sprites = new Dictionary<string, Sprite>();
public static void AddCustomSprite(string path, string name)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
try
{
Texture2D val = new Texture2D(200, 200);
char directorySeparatorChar = Path.DirectorySeparatorChar;
ImageConversion.LoadImage(val, File.ReadAllBytes(path + directorySeparatorChar + name + ".png"));
((Texture)val).filterMode = (FilterMode)1;
((Texture)val).wrapMode = (TextureWrapMode)1;
Sprites[name] = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2((float)(((Texture)val).width / 2), (float)(((Texture)val).height / 2)));
Plugin.logger.LogInfo((object)("Added custom sprite with id " + name + "!"));
}
catch (Exception ex)
{
Plugin.logger.LogError((object)("Failed to add sprite " + path + "\\" + name));
Plugin.logger.LogError((object)ex);
}
}
}
public static class CustomText
{
[CompilerGenerated]
private static class <>O
{
public static hook_AddSource <0>__LocalizationManager_AddSource;
}
public static event Action CustomTermsAdded;
internal static void ApplyHooks()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
object obj = <>O.<0>__LocalizationManager_AddSource;
if (obj == null)
{
hook_AddSource val = LocalizationManager_AddSource;
<>O.<0>__LocalizationManager_AddSource = val;
obj = (object)val;
}
LocalizationManager.AddSource += (hook_AddSource)obj;
}
private static void LocalizationManager_AddSource(orig_AddSource orig, LanguageSourceData source)
{
orig.Invoke(source);
CustomText.CustomTermsAdded?.Invoke();
source.UpdateDictionary(false);
}
public static void AddCustomTerm(string term, string text)
{
try
{
LanguageSourceData val = LocalizationManager.Sources[0];
val.AddTerm(term);
val.mTerms[val.mTerms.Count - 1].SetTranslation(0, text, (string)null);
Plugin.logger.LogInfo((object)("TRANSLATED \"" + term + "\" TO \"" + text + "\""));
}
catch (Exception ex)
{
Plugin.logger.LogError((object)("FAILED TO TRANSLATE \"" + term + "\""));
Plugin.logger.LogError((object)ex);
}
}
}
public static class CustomTraits
{
[CompilerGenerated]
private static class <>O
{
public static hook_InitStartingUpgrades <0>__MetaInventory_InitStartingUpgrades;
}
public static List<string> startingTraits = new List<string>();
internal static void ApplyHooks()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
object obj = <>O.<0>__MetaInventory_InitStartingUpgrades;
if (obj == null)
{
hook_InitStartingUpgrades val = MetaInventory_InitStartingUpgrades;
<>O.<0>__MetaInventory_InitStartingUpgrades = val;
obj = (object)val;
}
MetaInventory.InitStartingUpgrades += (hook_InitStartingUpgrades)obj;
}
private static void MetaInventory_InitStartingUpgrades(orig_InitStartingUpgrades orig, MetaInventory self)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Expected O, but got Unknown
foreach (string startingTrait in startingTraits)
{
HeroUpgradeDefinition registeredTrait = GetRegisteredTrait(startingTrait);
if (!((Object)(object)registeredTrait == (Object)null))
{
UpgradeEntry val = self.Get(registeredTrait);
if (val == null)
{
self.upgrades.Add(new UpgradeEntry(SerializableHeroUpgrade.op_Implicit(registeredTrait), true));
}
else if (!val.isStarting)
{
val.isStarting = true;
}
}
}
List<int> ids = new List<int>();
foreach (UpgradeEntry upgrade in self.upgrades)
{
HeroUpgradeDefinition definition = upgrade.upgrade.definition;
if ((Object)(object)definition == (Object)null)
{
ids.Add(self.upgrades.IndexOf(upgrade));
}
}
if (ids.Count > 0)
{
self.upgrades.RemoveAll((UpgradeEntry x) => ids.Contains(self.upgrades.IndexOf(x)));
}
orig.Invoke(self);
}
public static HeroUpgradeDefinition GetRegisteredTrait(string traitID)
{
if (!ResourceList<HeroUpgradeDefinition>.dictionary.ContainsKey(traitID))
{
Plugin.logger.LogWarning((object)("Cannot find registered trait with ID " + traitID + "."));
return null;
}
return ResourceList<HeroUpgradeDefinition>.dictionary[traitID];
}
public static void RegisterTrait(HeroUpgradeDefinition trait, string traitID, bool alwaysUnlocked = false)
{
ResourceList<HeroUpgradeDefinition>.list.Add(trait);
ResourceList<HeroUpgradeDefinition>.dictionary.Add(traitID, ArrayExtensions.Last<HeroUpgradeDefinition>(ResourceList<HeroUpgradeDefinition>.list));
Plugin.logger.LogInfo((object)("Registered trait " + traitID));
if (alwaysUnlocked)
{
startingTraits.Add(traitID);
Plugin.logger.LogInfo((object)("Added trait " + traitID + " to starting traits!"));
}
}
}
[BepInPlugin("nacu.bnapi", "BN Mod API", "1.0")]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource logger;
public const string VERSION = "1.0";
public void OnEnable()
{
logger = ((BaseUnityPlugin)this).Logger;
CustomText.ApplyHooks();
CustomTraits.ApplyHooks();
logger.LogInfo((object)"API loaded");
}
}
}
namespace System.Runtime.Versioning
{
public class TargetFrameworkAttribute : Attribute
{
public string FrameworkName { get; set; }
public string FrameworkDisplayName { get; set; }
public TargetFrameworkAttribute(string frameworkName)
{
FrameworkName = frameworkName;
}
}
}