using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using DiskCardGame;
using GBC;
using HarmonyLib;
using InscryptionAPI.Ascension;
using InscryptionAPI.Guid;
using InscryptionAPI.Helpers;
using InscryptionAPI.Sound;
using Pixelplacement;
using UnityEngine;
using UnityEngine.SceneManagement;
[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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Infiniscryption.Achievements")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Infinite Inscryption - Achievements")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("Infiniscryption.Achievements")]
[assembly: AssemblyTitle("Infiniscryption.Achievements")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace Infiniscryption.Achievements;
[BepInPlugin("zorro.inscryption.infiniscryption.achievements", "Achievements Plugin", "1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class AchievementsPlugin : BaseUnityPlugin
{
public const string PluginGuid = "zorro.inscryption.infiniscryption.achievements";
public const string PluginName = "Achievements Plugin";
internal const string PluginVersion = "1.0";
internal static ManualLogSource Log;
private void Awake()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
ModdedAchievementManager.AchievementById((Achievement)30);
Harmony val = new Harmony("zorro.inscryption.infiniscryption.achievements");
SceneManager.sceneLoaded += OnSceneLoaded;
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Achievements Plugin is loaded!");
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
Log.LogDebug((object)("Scene loaded " + ((Scene)(ref scene)).name + ". Initializing achievement popup handler"));
AchievementPopupHandler.Initialize(((Scene)(ref scene)).name);
}
}
[HarmonyPatch]
public class AchievementPopupHandler : ManagedBehaviour
{
public const float POPUP_TIMER = 5f;
private List<Achievement> showQueue = new List<Achievement>();
private AchievementBadge PopupBadge;
public static AchievementPopupHandler Instance { get; private set; }
public void TryShowUnlockAchievement(Achievement id)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: 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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
ModdedAchievementManager.AchievementDefinition achievementDefinition = ModdedAchievementManager.AchievementById(id);
ModdedAchievementManager.AchievementGroupDefinition achievementGroupDefinition = ModdedAchievementManager.GroupByAchievementId(id);
if ((Object)(object)achievementDefinition.IconSprite == (Object)null)
{
return;
}
if (((Component)this).gameObject.activeSelf)
{
showQueue.Add(id);
return;
}
AchievementsPlugin.Log.LogDebug((object)$"Showing achievement popup for {id}");
PopupBadge.ToastAchievement(id);
((Component)this).gameObject.SetActive(true);
Tween.Value(-0.3f, 0.4f, (Action<float>)delegate(float v)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
PopupBadge.ViewportPosition.offset = new Vector2(0f, v);
}, 0.2f, 0f, (AnimationCurve)null, (LoopType)0, (Action)null, (Action)null, true);
AudioController.Instance.PlaySound2D(achievementGroupDefinition.AudioCue, (MixerGroup)0, 0.75f, 0f, (Pitch)null, (Repetition)null, (Randomization)null, (Distortion)null, false);
AchievementsPlugin.Log.LogDebug((object)$"Scheduling achievement popup close for {id}");
CustomCoroutine.WaitThenExecute(5f, (Action)delegate
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
AchievementsPlugin.Log.LogDebug((object)$"Closing achievement popup for {id}");
Tween.Value(0.4f, -0.3f, (Action<float>)delegate(float v)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
PopupBadge.ViewportPosition.offset = new Vector2(0f, v);
}, 0.2f, 0f, (AnimationCurve)null, (LoopType)0, (Action)null, (Action)delegate
{
((Component)this).gameObject.SetActive(false);
}, true);
if (showQueue.Count > 0)
{
Achievement next = showQueue[0];
showQueue.RemoveAt(0);
CustomCoroutine.WaitThenExecute(1f, (Action)delegate
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
TryShowUnlockAchievement(next);
}, false);
}
}, false);
}
internal static void Initialize(string sceneName)
{
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
try
{
GameObject val = null;
Camera val2 = null;
Vector3 localScale = default(Vector3);
((Vector3)(ref localScale))..ctor(2f, 2f, 1f);
bool flag = sceneName.Equals("Ascension_Configure", StringComparison.InvariantCultureIgnoreCase);
if (flag)
{
val = ((Component)Singleton<AscensionMenuScreens>.Instance).gameObject;
val2 = Camera.main;
((Vector3)(ref localScale))..ctor(1f, 1f, 1f);
}
else
{
val = ((Component)((Component)Singleton<UIManager>.Instance.Canvas).transform.parent).gameObject;
val2 = val.GetComponent<Camera>();
}
AchievementBadge achievementBadge = AchievementBadge.Create(val.transform, val2);
((Component)achievementBadge).gameObject.transform.localScale = localScale;
achievementBadge.ViewportPosition.offset = new Vector2(0f, flag ? 0.3f : (-0.3f));
AchievementPopupHandler achievementPopupHandler = ((Component)achievementBadge).gameObject.AddComponent<AchievementPopupHandler>();
achievementPopupHandler.PopupBadge = achievementBadge;
Instance = achievementPopupHandler;
((Component)achievementBadge).gameObject.SetActive(false);
}
catch (Exception ex)
{
AchievementsPlugin.Log.LogInfo((object)("Could not create singleton Achievement Popup Handler for scene " + sceneName));
AchievementsPlugin.Log.LogInfo((object)ex);
}
}
}
[HarmonyPatch]
public class AchievementScreen : AscensionRunSetupScreenBase
{
public static readonly Screen ScreenID = GuidManager.GetEnumValue<Screen>("zorro.inscryption.infiniscryption.achievements", "AchievementsScreen");
private List<AchievementBadge> Badges = new List<AchievementBadge>();
private MainInputInteractable leftPageButton = null;
private MainInputInteractable rightPageButton = null;
private PixelText pageNumbers = null;
private List<ModdedAchievementManager.AchievementGroup> AllGroups = new List<ModdedAchievementManager.AchievementGroup>();
public override string headerText => "Choose Active Packs";
public override bool showCardDisplayer => false;
public override bool showCardPanel => false;
public static AchievementScreen Instance { get; private set; }
private ModdedAchievementManager.AchievementGroup ActiveGroup => AllGroups[ActiveGroupIndex];
private int ActiveGroupIndex { get; set; } = 0;
private int GroupPage { get; set; } = 0;
internal static AchievementScreen CreateInstance()
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Instance != (Object)null)
{
Object.DestroyImmediate((Object)(object)((Component)Instance).gameObject);
}
Instance = AscensionRunSetupScreenBase.BuildScreen(typeof(AchievementScreen), (Screen)5, (Screen)5) as AchievementScreen;
GameObject unlockSummaryScreen = Singleton<AscensionMenuScreens>.Instance.unlockSummaryScreen;
Transform val = unlockSummaryScreen.transform.Find("Stats/ScreenAnchor");
List<Transform> list = new List<Transform>();
foreach (Transform item2 in ((Component)val).transform)
{
Transform item = item2;
list.Add(item);
}
if (((Component)list[list.Count - 1]).gameObject.GetComponentInChildren<PixelText>().Text.Equals(Localization.Translate("- ACHIEVEMENTS -"), StringComparison.InvariantCultureIgnoreCase))
{
((MainInputInteractable)((Component)list[list.Count - 1]).gameObject.GetComponentInChildren<AscensionMenuInteractable>()).CursorSelectStarted = delegate
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Singleton<AscensionMenuScreens>.Instance.SwitchToScreen(ScreenID);
};
return Instance;
}
GameObject val2 = Object.Instantiate<GameObject>(((Component)list[list.Count - 1]).gameObject, list[list.Count - 1].parent);
val2.transform.localPosition = new Vector3(val2.transform.localPosition.x, val2.transform.localPosition.y - 0.11f, val2.transform.localPosition.z);
val2.GetComponentInChildren<PixelText>().SetText(Localization.Translate("- ACHIEVEMENTS -"), false);
((MainInputInteractable)val2.GetComponentInChildren<AscensionMenuInteractable>()).CursorSelectStarted = delegate
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Singleton<AscensionMenuScreens>.Instance.SwitchToScreen(ScreenID);
};
return Instance;
}
public override void InitializeScreen(GameObject partialScreen)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0359: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_0437: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("GameIcons");
val.transform.SetParent(partialScreen.transform);
AnchorToScreenEdge val2 = val.AddComponent<AnchorToScreenEdge>();
val2.anchorToMidpoint = true;
val2.anchorToBottom = false;
val2.anchorYOffset = -0.25f;
val2.worldAnchor = partialScreen.transform.Find("Footer");
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 2; j++)
{
AchievementBadge achievementBadge = AchievementBadge.Create(val.transform, Camera.main, (j == 0) ? 0.5f : 1f);
((Component)achievementBadge).gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
ViewportRelativePosition component = ((Component)achievementBadge).GetComponent<ViewportRelativePosition>();
component.viewportAnchor = new Vector2(0.09f + 0.5f * (float)j, 0.75f - 0.175f * (float)i);
component.offset = new Vector2(0f, 0f);
float num = ((j == 0) ? 0.5f : 1f);
((Component)achievementBadge).gameObject.SetActive(false);
Badges.Add(achievementBadge);
}
}
(AscensionMenuInteractable, AscensionMenuInteractable) tuple = AscensionRunSetupScreenBase.BuildPaginators(val.transform, false);
base.leftButton = (MainInputInteractable)(object)tuple.Item1;
base.rightButton = (MainInputInteractable)(object)tuple.Item2;
Action<MainInputInteractable> b = delegate(MainInputInteractable mii)
{
((AscensionRunSetupScreenBase)this).LeftButtonClicked(mii);
};
Action<MainInputInteractable> b2 = delegate(MainInputInteractable mii)
{
((AscensionRunSetupScreenBase)this).RightButtonClicked(mii);
};
base.leftButton.CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(base.leftButton.CursorSelectStarted, b);
base.rightButton.CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(base.rightButton.CursorSelectStarted, b2);
((Component)base.leftButton).gameObject.GetComponent<ViewportRelativePosition>().viewportAnchor = new Vector2(0.239f, 0.92f);
((Component)base.rightButton).gameObject.GetComponent<ViewportRelativePosition>().viewportAnchor = new Vector2(0.761f, 0.92f);
(AscensionMenuInteractable, AscensionMenuInteractable) tuple2 = AscensionRunSetupScreenBase.BuildPaginators(val.transform, false);
leftPageButton = (MainInputInteractable)(object)tuple2.Item1;
rightPageButton = (MainInputInteractable)(object)tuple2.Item2;
Action<MainInputInteractable> b3 = delegate(MainInputInteractable mii)
{
LeftPageButtonClicked(mii);
};
Action<MainInputInteractable> b4 = delegate(MainInputInteractable mii)
{
RightPageButtonClicked(mii);
};
leftPageButton.CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(leftPageButton.CursorSelectStarted, b3);
rightPageButton.CursorSelectStarted = (Action<MainInputInteractable>)Delegate.Combine(rightPageButton.CursorSelectStarted, b4);
((Component)leftPageButton).gameObject.GetComponent<ViewportRelativePosition>().viewportAnchor = new Vector2(0.65f, 0.1f);
((Component)rightPageButton).gameObject.GetComponent<ViewportRelativePosition>().viewportAnchor = new Vector2(0.8f, 0.1f);
GameObject val3 = Object.Instantiate<GameObject>(ResourceBank.Get<GameObject>("prefabs/gbcui/PixelTextCanvas"), val.transform);
((Object)val3).name = "PageNumber";
val3.layer = ((Component)base.screenTitle).gameObject.layer;
pageNumbers = val3.GetComponent<PixelText>();
pageNumbers.SetText("1 / 1", false);
pageNumbers.SetColor(GameColors.Instance.red);
ViewportRelativePosition val4 = val3.AddComponent<ViewportRelativePosition>();
val4.viewportCam = Camera.main;
val4.viewportAnchor = new Vector2(0.725f, 0.105f);
((Behaviour)val4).enabled = true;
val3.SetActive(true);
((Component)base.continueButton).gameObject.SetActive(false);
base.challengeHeaderDisplay.headerPointsLines.lines.ForEach(delegate(PixelText pt)
{
((Component)pt).gameObject.SetActive(false);
});
base.challengeFooterLines.lines.ForEach(delegate(PixelText pt)
{
((Component)pt).gameObject.SetActive(false);
});
((Component)base.screenTitle).gameObject.transform.localPosition = new Vector3(0f, -0.17f, 0f);
}
private void SyncComponents()
{
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
ModdedAchievementManager.AchievementGroupDefinition achievementGroupDefinition = ModdedAchievementManager.GroupById(ActiveGroup);
base.screenTitle.SetText(Localization.Translate(achievementGroupDefinition.EnglishGroupName), false);
base.screenTitle.SetText(Localization.Translate(achievementGroupDefinition.EnglishGroupName), false);
int num = Mathf.CeilToInt((float)achievementGroupDefinition.Achievements.Count() / (float)Badges.Count);
pageNumbers.SetText($"{GroupPage + 1} / {num}", false);
int num2 = Badges.Count * GroupPage;
int count = Math.Min(Badges.Count, achievementGroupDefinition.Achievements.Count - num2);
List<ModdedAchievementManager.AchievementDefinition> range = achievementGroupDefinition.Achievements.GetRange(num2, count);
string text = string.Join(", ", range);
AchievementsPlugin.Log.LogDebug((object)("Displaying achievements " + text));
Badges.ForEach(delegate(AchievementBadge b)
{
((Component)b).gameObject.SetActive(false);
});
for (int i = 0; i < range.Count; i++)
{
try
{
AchievementsPlugin.Log.LogDebug((object)("Setting achievement " + range[i].EnglishName + " active"));
Badges[i].DisplayAchievement(range[i].ID);
((Component)Badges[i]).gameObject.SetActive(true);
}
catch (Exception ex)
{
AchievementsPlugin.Log.LogError((object)ex);
((Component)Badges[i]).gameObject.SetActive(false);
}
}
}
private void LeftPageButtonClicked(MainInputInteractable button)
{
try
{
if (GroupPage > 0)
{
GroupPage--;
SyncComponents();
}
}
catch
{
ActiveGroupIndex = 0;
GroupPage = 0;
SyncComponents();
}
}
private void RightPageButtonClicked(MainInputInteractable button)
{
try
{
int num = Mathf.CeilToInt((float)ModdedAchievementManager.GroupById(ActiveGroup).Achievements.Count / (float)Badges.Count);
if (GroupPage < num - 1)
{
GroupPage++;
SyncComponents();
}
}
catch
{
ActiveGroupIndex = 0;
GroupPage = 0;
SyncComponents();
}
}
public override void LeftButtonClicked(MainInputInteractable button)
{
try
{
if (ActiveGroupIndex > 0)
{
ActiveGroupIndex--;
GroupPage = 0;
SyncComponents();
}
}
catch
{
ActiveGroupIndex = 0;
GroupPage = 0;
SyncComponents();
}
}
public override void RightButtonClicked(MainInputInteractable button)
{
try
{
if (ActiveGroupIndex < AllGroups.Count - 1)
{
ActiveGroupIndex++;
GroupPage = 0;
SyncComponents();
}
}
catch
{
ActiveGroupIndex = 0;
GroupPage = 0;
SyncComponents();
}
}
public override void OnEnable()
{
Badges.ForEach(delegate(AchievementBadge b)
{
b.ReAlign();
});
AllGroups.Clear();
AllGroups.AddRange(from ag in GuidManager.GetValues<ModdedAchievementManager.AchievementGroup>()
where ag != 0 && ModdedAchievementManager.GroupById(ag) != null
select ag);
ActiveGroupIndex = 0;
GroupPage = 0;
SyncComponents();
SyncComponents();
((AscensionRunSetupScreenBase)this).OnEnable();
}
[HarmonyPatch(typeof(AscensionMenuScreens), "ConfigurePostGameScreens")]
[HarmonyPostfix]
private static void InitializeScreensOnStart()
{
CreateInstance();
}
[HarmonyPatch(typeof(AscensionMenuScreens), "DeactivateAllScreens")]
[HarmonyPostfix]
private static void DeactivateAllCustomScreens()
{
if ((Object)(object)Instance != (Object)null)
{
((Component)Instance).gameObject.SetActive(false);
}
}
[HarmonyPatch(typeof(AscensionMenuScreens), "ScreenSwitchSequence")]
[HarmonyPostfix]
[HarmonyPriority(100)]
private static IEnumerator SwitchToScreen(IEnumerator sequenceEvent, Screen screen)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
while (sequenceEvent.MoveNext())
{
yield return sequenceEvent.Current;
}
yield return (object)new WaitForSeconds(0.05f);
if ((Object)(object)Instance != (Object)null && ScreenID == screen)
{
((Component)Instance).gameObject.SetActive(true);
((Component)Instance).gameObject.SetActive(false);
((Component)Instance).gameObject.SetActive(true);
}
}
}
public class AchievementBadge : ManagedBehaviour
{
private static int ORTHO_LAYER
{
get
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
return ((Scene)(ref activeScene)).name.Equals("Ascension_Configure", StringComparison.InvariantCultureIgnoreCase) ? LayerMask.NameToLayer("GBCUI") : LayerMask.NameToLayer("OrthographicUI");
}
}
public ViewportRelativePosition ViewportPosition { get; set; }
private SpriteRenderer AchievementSprite { get; set; }
private float? RightAnchor { get; set; }
private PixelText HeaderDisplayer { get; set; }
private PixelText AchievementTitleDisplayer { get; set; }
public void ReAlign()
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
RectTransform component = ((Component)((Component)HeaderDisplayer).transform.Find("Text")).GetComponent<RectTransform>();
RectTransform component2 = ((Component)((Component)AchievementTitleDisplayer).transform.Find("Text")).GetComponent<RectTransform>();
if (!RightAnchor.HasValue)
{
component.sizeDelta = new Vector2(165f, 50f);
component2.sizeDelta = new Vector2(165f, 50f);
return;
}
float x = Camera.main.ViewportToWorldPoint(new Vector3(RightAnchor.Value, 0.5f, 0f)).x;
AchievementsPlugin.Log.LogDebug((object)$"Setting right edge to {RightAnchor.Value} = {x} from {((Component)component2).gameObject.transform.position.x}");
component.sizeDelta = new Vector2((x - ((Component)component).gameObject.transform.position.x) / ((Transform)component).lossyScale.x, 50f);
component2.sizeDelta = new Vector2((x - ((Component)component2).gameObject.transform.position.x) / ((Transform)component).lossyScale.x, 50f);
}
public void ToastAchievement(Achievement id)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
ModdedAchievementManager.AchievementDefinition achievementDefinition = ModdedAchievementManager.AchievementById(id);
ModdedAchievementManager.AchievementGroupDefinition achievementGroupDefinition = ModdedAchievementManager.GroupByAchievementId(id);
AchievementSprite.sprite = achievementDefinition.IconSprite;
AchievementTitleDisplayer.SetText(Localization.Translate(achievementDefinition.EnglishName), false);
HeaderDisplayer.SetText(Localization.Translate("Achievement Unlocked"), false);
}
public void DisplayAchievement(Achievement id)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
ModdedAchievementManager.AchievementDefinition achievementDefinition = ModdedAchievementManager.AchievementById(id);
ModdedAchievementManager.AchievementGroupDefinition achievementGroupDefinition = ModdedAchievementManager.GroupByAchievementId(id);
if (achievementDefinition != null && achievementGroupDefinition != null)
{
AchievementsPlugin.Log.LogDebug((object)("Displaying " + achievementDefinition.EnglishName));
AchievementsPlugin.Log.LogDebug((object)$"Unlocked? {achievementDefinition.IsUnlocked}");
if (achievementDefinition.Secret && !achievementDefinition.IsUnlocked)
{
AchievementSprite.sprite = achievementGroupDefinition.LockedSprite;
HeaderDisplayer.SetText(Localization.Translate("Secret Achievement"), false);
AchievementTitleDisplayer.SetText(Localization.Translate("Revealed Once Unlocked"), false);
}
else
{
AchievementSprite.sprite = (achievementDefinition.IsUnlocked ? achievementDefinition.IconSprite : achievementGroupDefinition.LockedSprite);
AchievementTitleDisplayer.SetText(Localization.Translate(achievementDefinition.EnglishDescription), false);
HeaderDisplayer.SetText(Localization.Translate(achievementDefinition.EnglishName), false);
}
}
}
public static AchievementBadge Create(Transform parent, Camera viewportCam = null, float? rightAnchor = null)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("AchievementDisplayer");
val.transform.SetParent(parent);
val.transform.localPosition = new Vector3(0f, 0f, 1f);
val.transform.localScale = new Vector3(2.5f, 2.5f, 1f);
val.SetActive(false);
AchievementBadge achievementBadge = val.AddComponent<AchievementBadge>();
achievementBadge.RightAnchor = rightAnchor;
if ((Object)(object)viewportCam != (Object)null)
{
val.layer = ORTHO_LAYER;
achievementBadge.ViewportPosition = val.AddComponent<ViewportRelativePosition>();
achievementBadge.ViewportPosition.viewportCam = viewportCam;
achievementBadge.ViewportPosition.viewportAnchor = new Vector2(0.4f, 0f);
achievementBadge.ViewportPosition.offset = new Vector2(0f, 0.5f);
((Behaviour)achievementBadge.ViewportPosition).enabled = true;
}
GameObject val2 = new GameObject("AchievementIcon");
val2.transform.SetParent(val.transform);
if ((Object)(object)viewportCam != (Object)null)
{
val2.layer = ORTHO_LAYER;
}
val2.transform.localPosition = new Vector3(-0.25f, 0f, 0f);
val2.transform.localScale = new Vector3(1f, 1f, 1f);
achievementBadge.AchievementSprite = val2.AddComponent<SpriteRenderer>();
achievementBadge.AchievementSprite.sprite = ModdedAchievementManager.AchievementById((Achievement)30).IconSprite;
((Renderer)achievementBadge.AchievementSprite).enabled = true;
((Renderer)achievementBadge.AchievementSprite).sortingOrder = 230;
GameObject val3 = Object.Instantiate<GameObject>(ResourceBank.Get<GameObject>("prefabs/gbcui/PixelTextCanvas"), val.transform);
((Object)val3).name = "CongratsTitle";
if ((Object)(object)viewportCam != (Object)null)
{
val3.layer = ORTHO_LAYER;
}
RectTransform component = ((Component)val3.transform.Find("Text")).GetComponent<RectTransform>();
component.pivot = new Vector2(0f, 1f);
val3.transform.localPosition = new Vector3(-0.11f, 0.3f, 0f);
achievementBadge.HeaderDisplayer = val3.GetComponent<PixelText>();
achievementBadge.HeaderDisplayer.mainText.alignment = (TextAnchor)3;
achievementBadge.HeaderDisplayer.SetColor(GameColors.Instance.nearWhite);
achievementBadge.HeaderDisplayer.SetText(Localization.Translate("Achievement Unlocked"), false);
GameObject val4 = Object.Instantiate<GameObject>(ResourceBank.Get<GameObject>("prefabs/gbcui/PixelTextCanvas"), val.transform);
((Object)val4).name = "AchievementTitle";
if ((Object)(object)viewportCam != (Object)null)
{
val4.layer = ORTHO_LAYER;
}
RectTransform component2 = ((Component)val4.transform.Find("Text")).GetComponent<RectTransform>();
component2.pivot = new Vector2(0f, 1f);
val4.transform.localPosition = new Vector3(-0.11f, 0f, 0f);
achievementBadge.AchievementTitleDisplayer = val4.GetComponent<PixelText>();
achievementBadge.AchievementTitleDisplayer.mainText.alignment = (TextAnchor)0;
achievementBadge.AchievementTitleDisplayer.SetColor(GameColors.Instance.red);
achievementBadge.AchievementTitleDisplayer.SetText(Localization.Translate(ModdedAchievementManager.AchievementById((Achievement)30).EnglishName), false);
achievementBadge.ReAlign();
return achievementBadge;
}
}
[HarmonyPatch]
public static class ModdedAchievementManager
{
public enum AchievementGroup
{
StoryAchievements,
KayceesModAchievements
}
public class AchievementGroupDefinition
{
public AchievementGroup ID { get; internal set; }
public string EnglishGroupName { get; internal set; }
public string AudioCue { get; set; }
public bool IsDefault { get; internal set; }
public Sprite LockedSprite { get; internal set; }
public List<AchievementDefinition> Achievements => new List<AchievementDefinition>(AllAchievements.Where((AchievementDefinition ad) => ad.GroupID == ID));
}
public class AchievementDefinition
{
public Achievement ID { get; internal set; }
public AchievementGroup GroupID { get; internal set; }
public string EnglishName { get; internal set; }
public string EnglishDescription { get; internal set; }
public Sprite IconSprite { get; internal set; }
public bool Secret { get; internal set; }
public bool IsUnlocked => SaveManager.SaveFile.unlockedAchievements != null && SaveManager.SaveFile.unlockedAchievements.Contains(ID);
}
private static readonly AudioClip DefaultAudioClip;
private static readonly Rect ICON_RECT;
private static readonly Vector2 ICON_PIVOT;
private static List<AchievementDefinition> AllAchievements;
private static List<AchievementGroupDefinition> AllAchievementGroups;
private static List<AudioClip> clipsToPatchIn;
static ModdedAchievementManager()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Invalid comparison between Unknown and I4
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
DefaultAudioClip = SoundManager.LoadAudioClip("achievement_default.wav");
ICON_RECT = new Rect(0f, 0f, 22f, 22f);
ICON_PIVOT = new Vector2(0.5f, 0.5f);
AllAchievements = new List<AchievementDefinition>();
AllAchievementGroups = new List<AchievementGroupDefinition>();
clipsToPatchIn = new List<AudioClip> { DefaultAudioClip };
AllAchievementGroups.Clear();
NewGroup(AchievementGroup.KayceesModAchievements, "Kaycee's Mod Achievements", ((Object)DefaultAudioClip).name, TextureHelper.GetImageAsTexture("KMOD_LOCKED.png", typeof(ModdedAchievementManager).Assembly, (FilterMode)0), isDefault: true);
NewGroup(AchievementGroup.StoryAchievements, "Story Achievements", null, null, isDefault: true);
AllAchievements.Clear();
foreach (Achievement ach in Enum.GetValues(typeof(Achievement)))
{
Achievement_t val = ((IEnumerable<Achievement_t>)AchievementsList.m_Achievements).FirstOrDefault((Func<Achievement_t, bool>)((Achievement_t at) => at.m_eAchievementID == ach));
if (val == null)
{
AchievementsPlugin.Log.LogWarning((object)$"Could not find a definition for achievement {(object)ach}");
continue;
}
AchievementGroup achievementGroup = (((int)ach >= 30) ? AchievementGroup.KayceesModAchievements : AchievementGroup.StoryAchievements);
Texture2D icon = ((achievementGroup == AchievementGroup.KayceesModAchievements) ? TextureHelper.GetImageAsTexture($"{(object)ach}.png", typeof(ModdedAchievementManager).Assembly, (FilterMode)0) : null);
New(ach, val.m_strName, val.m_strDescription, secret: true, achievementGroup, icon);
}
}
internal static AchievementGroupDefinition NewGroup(AchievementGroup id, string name, string audioCue, Texture2D lockedTexture, bool isDefault)
{
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
if (AllAchievementGroups.Any((AchievementGroupDefinition agd) => agd.ID == id))
{
throw new InvalidOperationException($"An achievement group with ID {id} already exists!");
}
if ((Object)(object)lockedTexture != (Object)null && (((Texture)lockedTexture).width != 22 || ((Texture)lockedTexture).height != 22))
{
throw new InvalidOperationException("Locked icon texture must be 22x22 pixels");
}
Sprite lockedSprite = (((Object)(object)lockedTexture == (Object)null) ? GroupById(AchievementGroup.KayceesModAchievements).LockedSprite : Sprite.Create(lockedTexture, ICON_RECT, ICON_PIVOT));
AchievementGroupDefinition achievementGroupDefinition = new AchievementGroupDefinition
{
ID = id,
EnglishGroupName = name,
AudioCue = audioCue,
LockedSprite = lockedSprite
};
AllAchievementGroups.Add(achievementGroupDefinition);
return achievementGroupDefinition;
}
public static AchievementGroupDefinition NewGroup(string modGuid, string englishGroupName, string audioCue, Texture2D lockedTexture)
{
return NewGroup(GuidManager.GetEnumValue<AchievementGroup>(modGuid, englishGroupName), englishGroupName, audioCue, lockedTexture, isDefault: false);
}
public static AchievementGroupDefinition NewGroup(string modGuid, string englishGroupName, AudioClip audioCue, Texture2D lockedTexture)
{
if (!clipsToPatchIn.Any((AudioClip ac) => ((Object)ac).name.Equals(((Object)audioCue).name)))
{
clipsToPatchIn.Add(audioCue);
}
return NewGroup(GuidManager.GetEnumValue<AchievementGroup>(modGuid, englishGroupName), englishGroupName, ((Object)audioCue).name, lockedTexture, isDefault: false);
}
public static AchievementGroupDefinition NewGroup(string modGuid, string englishGroupName, Texture2D lockedTexture)
{
return NewGroup(GuidManager.GetEnumValue<AchievementGroup>(modGuid, englishGroupName), englishGroupName, ((Object)DefaultAudioClip).name, lockedTexture, isDefault: false);
}
public static AchievementGroupDefinition NewGroup(string modGuid, string englishGroupName)
{
return NewGroup(GuidManager.GetEnumValue<AchievementGroup>(modGuid, englishGroupName), englishGroupName, ((Object)DefaultAudioClip).name, null, isDefault: false);
}
internal static AchievementDefinition New(Achievement id, string achievementEnglishName, string achievementEnglishDescription, bool secret, AchievementGroup groupId, Texture2D icon)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: 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)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
if (AllAchievements.Any((AchievementDefinition agd) => agd.ID == id))
{
throw new InvalidOperationException($"An achievement with ID {id} already exists!");
}
if ((Object)(object)icon != (Object)null && (((Texture)icon).width != 22 || ((Texture)icon).height != 22))
{
throw new InvalidOperationException("Achievement icon texture must be 22x22 pixels");
}
AchievementDefinition achievementDefinition = new AchievementDefinition
{
ID = id,
GroupID = groupId,
EnglishName = achievementEnglishName,
EnglishDescription = achievementEnglishDescription,
IconSprite = Sprite.Create(icon, ICON_RECT, ICON_PIVOT),
Secret = secret
};
AllAchievements.Add(achievementDefinition);
return achievementDefinition;
}
public static AchievementDefinition New(string modGuid, string achievementEnglishName, string achievementEnglishDescription, bool secret, AchievementGroup groupId, Texture2D icon)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return New(GuidManager.GetEnumValue<Achievement>(modGuid, achievementEnglishName), achievementEnglishName, achievementEnglishDescription, secret, groupId, icon);
}
public static AchievementDefinition AchievementById(Achievement id)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
return AllAchievements.FirstOrDefault((AchievementDefinition ad) => ad.ID == id);
}
public static AchievementGroupDefinition GroupById(AchievementGroup id)
{
return AllAchievementGroups.FirstOrDefault((AchievementGroupDefinition agd) => agd.ID == id);
}
public static AchievementGroupDefinition GroupByAchievementId(Achievement id)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
AchievementDefinition achievementDefinition = AchievementById(id);
if (achievementDefinition == null)
{
return null;
}
return GroupById(achievementDefinition.GroupID);
}
[HarmonyPatch(typeof(AchievementManager), "Unlock")]
[HarmonyPrefix]
[HarmonyPriority(700)]
private static bool Unlock(Achievement achievementID)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
bool flag = GroupByAchievementId(achievementID)?.IsDefault ?? false;
if (SaveManager.SaveFile.unlockedAchievements != null && !SaveManager.SaveFile.unlockedAchievements.Contains(achievementID))
{
SaveManager.SaveFile.unlockedAchievements.Add(achievementID);
if ((Object)(object)AchievementPopupHandler.Instance != (Object)null)
{
AchievementPopupHandler.Instance.TryShowUnlockAchievement(achievementID);
}
}
if (flag && (Object)(object)AchievementManager.platformHandler != (Object)null)
{
AchievementManager.platformHandler.Unlock(achievementID);
}
return false;
}
[HarmonyPatch(typeof(AudioController), "Awake")]
[HarmonyPostfix]
internal static void LoadMyCustomAudio(ref AudioController __instance)
{
foreach (AudioClip clip in clipsToPatchIn)
{
if ((Object)(object)clip != (Object)null && !__instance.SFX.Any((AudioClip ac) => ((Object)ac).name.Equals(((Object)clip).name, StringComparison.InvariantCultureIgnoreCase)))
{
__instance.SFX.Add(clip);
}
}
}
}