using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using CommunityBadges.BadgeHandlers;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MoreBadges;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using Zorro.Core;
[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("CommunityBadges")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.2.0")]
[assembly: AssemblyInformationalVersion("0.2.0+ac656a39d1e14dc4ad3db8a4d90526c1e1f71e2c")]
[assembly: AssemblyProduct("CommunityBadges")]
[assembly: AssemblyTitle("CommunityBadges")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
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;
}
}
}
public enum BadgeEventType
{
PointReached,
ItemUsed,
VineGrabbed,
EndScreen,
ItemCooked,
DartHit,
ItemUsedOnFriend
}
namespace CommunityBadges
{
public static class Helpers
{
public static ushort[] GetCharacterItemIDs(Character character)
{
List<ushort> list = new List<ushort>();
if ((Object)(object)character.data.currentItem != (Object)null)
{
list.Add(character.data.currentItem.itemID);
}
ItemSlot[] itemSlots = character.player.itemSlots;
foreach (ItemSlot val in itemSlots)
{
if (val != null && (Object)(object)val.prefab != (Object)null)
{
list.Add(val.prefab.itemID);
}
}
BackpackData val2 = default(BackpackData);
if (!((ItemSlot)character.player.backpackSlot).IsEmpty() && ((ItemSlot)character.player.backpackSlot).data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val2))
{
ItemSlot[] itemSlots2 = val2.itemSlots;
foreach (ItemSlot val3 in itemSlots2)
{
if (val3 != null && (Object)(object)val3.prefab != (Object)null)
{
list.Add(val3.prefab.itemID);
}
}
}
return list.ToArray();
}
}
public static class Patches
{
[HarmonyPatch(typeof(MountainProgressHandler), "CheckAreaAchievement")]
public static class CheckAreaAchievementPatch
{
private static void Postfix(MountainProgressHandler __instance, ProgressPoint pointReached)
{
BadgeEventDispatcher.Dispatch(BadgeEventType.PointReached, new BadgeEventContext(__instance, pointReached));
}
}
[HarmonyPatch(typeof(CharacterVineClimbing), "GrabVineRpc")]
public static class GrabVineRpcPatch
{
private static void Postfix(CharacterVineClimbing __instance, PhotonView ropeView, int segmentIndex)
{
BadgeEventDispatcher.Dispatch(BadgeEventType.VineGrabbed, new BadgeEventContext(__instance));
}
}
[HarmonyPatch(typeof(EndScreen), "EndSequenceRoutine")]
public static class EndSequenceRoutinePatch
{
private static void Prefix(EndScreen __instance)
{
BadgeEventDispatcher.Dispatch(BadgeEventType.EndScreen, new BadgeEventContext(__instance));
}
}
[HarmonyPatch(typeof(ItemCooking), "FinishCooking")]
public static class FinishCookingRPCPatch
{
private static void Postfix(ItemCooking __instance)
{
Item component = ((Component)__instance).GetComponent<Item>();
if (!((Object)(object)component == (Object)null))
{
IntItemData data = ((ItemComponent)__instance).GetData<IntItemData>((DataEntryKey)1);
if (data != null)
{
BadgeEventDispatcher.Dispatch(BadgeEventType.ItemCooked, new BadgeEventContext(__instance, component, data.Value));
}
}
}
}
[HarmonyPatch(typeof(Action_RaycastDart), "RPC_DartImpact")]
public static class RPC_DartImpactPatch
{
private static void Postfix(Action_RaycastDart __instance, Player hitPlayer)
{
if (hitPlayer != null && hitPlayer.IsLocal)
{
Item component = ((Component)__instance).GetComponent<Item>();
if (!((Object)(object)component == (Object)null))
{
BadgeEventDispatcher.Dispatch(BadgeEventType.DartHit, new BadgeEventContext(__instance, component));
}
}
}
}
[HarmonyPatch(typeof(Item), "FinishCastSecondary")]
public static class FinishCastSecondaryPatch
{
private static void Prefix(Item __instance)
{
if (__instance.canUseOnFriend && Interaction.instance.hasValidTargetCharacter && (Object)(object)__instance.holderCharacter != (Object)null)
{
BadgeEventDispatcher.Dispatch(BadgeEventType.ItemUsedOnFriend, new BadgeEventContext(__instance, __instance));
}
}
}
[HarmonyPatch(typeof(RunManager), "StartRun")]
public static class StartRunPatch
{
private static void Prefix()
{
Plugin.hasDied = false;
}
}
[HarmonyPatch(typeof(Character), "RPCA_Die")]
public static class RPCA_DiePatch
{
private static void Prefix(Character __instance)
{
if (__instance.IsLocal)
{
Plugin.hasDied = true;
}
}
}
[HarmonyPatch(typeof(CharacterStats), "RecordHeight")]
private static class RecordHeightPatch
{
private static void Postfix(CharacterStats __instance)
{
if (__instance.character.IsLocal)
{
float heightInMeters = __instance.heightInMeters;
if (__instance.character.data.isGrounded)
{
Plugin.fallStartHeight = null;
}
else if (!Plugin.fallStartHeight.HasValue)
{
Plugin.fallStartHeight = heightInMeters;
}
}
}
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.snosz.communitybadges", "CommunityBadges", "0.2.0")]
public class Plugin : BaseUnityPlugin
{
public static class BadgeNames
{
public const string SharingIsCaringBadge = "Badge_CommunityBadges_SharingIsCaring";
public const string PeakScoutBadge = "Badge_CommunityBadges_PeakScout";
public const string NapTimeBadge = "Badge_CommunityBadges_NapTime";
public const string YouMonsterBadge = "Badge_CommunityBadges_YouMonster";
public const string OverpreparedBadge = "Badge_CommunityBadges_Overprepared";
public const string FallenABitBadge = "Badge_CommunityBadges_FallenABit";
public const string AcrobaticsBadge = "Badge_CommunityBadges_Acrobatics";
public const string BloodBagBadge = "Badge_CommunityBadges_BloodBag";
}
public static bool hasDied;
public static float? fallStartHeight;
public static Plugin Instance;
private static Harmony _harmony;
private AssetBundle badgesBundle;
private void Awake()
{
Instance = this;
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.snosz.communitybadges");
byte[] communitybadges = Resource1.communitybadges;
badgesBundle = AssetBundle.LoadFromMemory(communitybadges);
MoreBadgesPlugin.RegisterBadgeAssetBundle(badgesBundle);
BadgeEventDispatcher.Register(BadgeEventType.ItemUsedOnFriend, new CommunityBadgeHandlers.SharingIsCaringBadgeHandler());
BadgeEventDispatcher.Register(BadgeEventType.DartHit, new CommunityBadgeHandlers.NapTimeBadgeHandler());
BadgeEventDispatcher.Register(BadgeEventType.ItemCooked, new CommunityBadgeHandlers.YouMonsterBadgeHandler());
BadgeEventDispatcher.Register(BadgeEventType.PointReached, new CommunityBadgeHandlers.OverpreparedBadgeHandler());
BadgeEventDispatcher.Register(BadgeEventType.PointReached, new CommunityBadgeHandlers.BloodBagBadgeHandler());
BadgeEventDispatcher.Register(BadgeEventType.EndScreen, new CommunityBadgeHandlers.PeakScoutBadgeHandler());
BadgeEventDispatcher.Register(BadgeEventType.EndScreen, new CommunityBadgeHandlers.FallenABitBadgeHandler());
BadgeEventDispatcher.Register(BadgeEventType.VineGrabbed, new CommunityBadgeHandlers.AcrobaticsBadgeHandler());
}
}
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resource1
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("CommunityBadges.Resource1", typeof(Resource1).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] communitybadges
{
get
{
object @object = ResourceManager.GetObject("communitybadges", resourceCulture);
return (byte[])@object;
}
}
internal Resource1()
{
}
}
}
namespace CommunityBadges.BadgeHandlers
{
public class BadgeEventContext
{
public object Sender { get; }
public object[] Args { get; }
public BadgeEventContext(object sender, params object[] args)
{
Sender = sender;
Args = args;
}
}
public static class BadgeEventDispatcher
{
private static readonly Dictionary<BadgeEventType, List<IBadgeHandler>> _handlers = new Dictionary<BadgeEventType, List<IBadgeHandler>>();
public static void Register(BadgeEventType type, IBadgeHandler handler)
{
if (!_handlers.ContainsKey(type))
{
_handlers[type] = new List<IBadgeHandler>();
}
_handlers[type].Add(handler);
}
public static void Dispatch(BadgeEventType type, BadgeEventContext context)
{
if (!_handlers.TryGetValue(type, out List<IBadgeHandler> value))
{
return;
}
foreach (IBadgeHandler item in value)
{
item.OnEvent(context);
}
}
}
public class CommunityBadgeHandlers
{
public class OverpreparedBadgeHandler : IBadgeHandler
{
private static readonly ushort[] OverpreparedBadgeItemIDs = new ushort[8] { 99, 14, 42, 32, 15, 23, 13, 34 };
public void OnEvent(BadgeEventContext context)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
object obj = context.Args[0];
ProgressPoint val = (ProgressPoint)((obj is ProgressPoint) ? obj : null);
if (val == null || (int)val.biome != 5)
{
return;
}
Character localCharacter = Character.localCharacter;
if (!((Object)(object)localCharacter == (Object)null) && !localCharacter.data.dead)
{
Plugin instance = Plugin.Instance;
IEnumerable<ushort> source = Helpers.GetCharacterItemIDs(localCharacter).Distinct();
if (source.Count((ushort id) => OverpreparedBadgeItemIDs.Contains(id)) >= 6)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_Overprepared", 1);
}
}
}
}
public class BloodBagBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
object obj = context.Args[0];
ProgressPoint val = (ProgressPoint)((obj is ProgressPoint) ? obj : null);
if (val == null || (int)val.biome != 5)
{
return;
}
foreach (KeyValuePair<Bugfix, Character> allAttachedBug in Bugfix.AllAttachedBugs)
{
if ((Object)(object)allAttachedBug.Value == (Object)(object)Character.localCharacter)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_BloodBag", 1);
break;
}
}
}
}
public class AcrobaticsBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
object sender = context.Sender;
CharacterVineClimbing val = (CharacterVineClimbing)((sender is CharacterVineClimbing) ? sender : null);
if (Plugin.fallStartHeight.HasValue && !((Object)(object)val == (Object)null) && val.character.IsLocal)
{
float num = Plugin.fallStartHeight.Value - val.character.refs.stats.heightInMeters;
if (num >= 200f)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_Acrobatics", 1);
}
}
}
}
public class NapTimeBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
object obj = context.Args[0];
Item val = (Item)((obj is Item) ? obj : null);
if ((Object)(object)val != (Object)null && val.itemID == 70)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_NapTime", 1);
}
}
}
public class SharingIsCaringBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
object obj = context.Args[0];
Item val = (Item)((obj is Item) ? obj : null);
if ((Object)(object)val != (Object)null && val.itemID == 95)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_SharingIsCaring", 1);
}
}
}
public class YouMonsterBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
object obj = context.Args[0];
Item val = (Item)((obj is Item) ? obj : null);
int num = (int)context.Args[1];
if ((Object)(object)val != (Object)null && val.itemID == 13 && num == 1)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_YouMonster", 1);
}
}
}
public class PeakScoutBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
if (Ascents.currentAscent == 7)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_PeakScout", 1);
}
}
}
public class FallenABitBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
if (!Plugin.hasDied)
{
float runBasedFloat = Singleton<AchievementManager>.Instance.GetRunBasedFloat((RUNBASEDVALUETYPE)3);
if (runBasedFloat >= 2f)
{
MoreBadgesPlugin.AddProgress("Badge_CommunityBadges_FallenABit", 1);
}
}
}
}
public class AllInThisTogetherBadgeHandler : IBadgeHandler
{
public void OnEvent(BadgeEventContext context)
{
}
}
}
public interface IBadgeHandler
{
void OnEvent(BadgeEventContext context);
}
}