using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peak.Network;
using Photon.Pun;
using Photon.Realtime;
using SpongePEAK.Core.Logging;
using SpongePEAK.Core.Patching;
using SpongePEAK.Lib.Features;
using SpongePEAK.Lib.Net;
using SpongePEAK.Lib.Plugin;
using SpongePEAK.Lib.UI;
using SpongePEAK.Tweaked.Features;
using SpongePEAK.Tweaked.Net;
using SpongePEAK.Tweaked.Patches;
using SpongePEAK.Tweaked.Tweaks;
using SpongePEAK.Tweaked.UI;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("sponge")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) sponge")]
[assembly: AssemblyDescription("Host-controlled run rules: scale or disable stamina, hunger, damage and statuses.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ddcbf023fcb4c2065ad9b038910633cd4a3a93b0")]
[assembly: AssemblyProduct("SpongePEAKTweaked")]
[assembly: AssemblyTitle("com.sponge.peaktweaked")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 SpongePEAK.Tweaked
{
[BepInPlugin("com.sponge.peaktweaked", "SpongePEAKTweaked", "1.0.0")]
public sealed class TweakedPlugin : SpongePlugin
{
public const string Guid = "com.sponge.peaktweaked";
private FeatureRegistry _registry;
private RunTweaksFeature _tweaks;
private CustomNameFeature _name;
private CampfireSafeZoneFeature _campfire;
private const string RulesKey = "sponge.tweakrules";
private HostRuleSet _rules;
protected override string DisplayName => "SpongePEAKTweaked";
protected override void OnLoad()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
_registry = new FeatureRegistry(((BaseUnityPlugin)this).Config, ((SpongePlugin)this).Log);
_tweaks = new RunTweaksFeature();
_tweaks.Configure(((BaseUnityPlugin)this).Config);
_name = new CustomNameFeature();
_name.Configure(((BaseUnityPlugin)this).Config);
_rules = new HostRuleSet("sponge.tweakrules", ((SpongePlugin)this).Log);
_rules.Declare("CampfireSafeZone", true);
CampfireSafeZoneFeature.Rules = _rules;
_campfire = new CampfireSafeZoneFeature();
_campfire.Configure(((BaseUnityPlugin)this).Config);
_registry.Register((ModFeature)(object)_tweaks);
_registry.Register((ModFeature)(object)_name);
_registry.Register((ModFeature)(object)_campfire);
_registry.EnableAll(((SpongePlugin)this).Patches);
_rules.Start();
}
private void Update()
{
if (_tweaks != null && ((ModFeature)_tweaks).IsActive)
{
_tweaks.Tick();
}
if (_name != null && ((ModFeature)_name).IsActive)
{
_name.Tick();
}
if (_campfire != null && ((ModFeature)_campfire).IsActive)
{
_campfire.Tick();
}
}
protected override void OnUnload()
{
_tweaks?.Cleanup();
_name?.Cleanup();
_campfire?.Cleanup();
HostRuleSet rules = _rules;
if (rules != null)
{
rules.Stop();
}
CampfireSafeZoneFeature.Rules = null;
}
}
}
namespace SpongePEAK.Tweaked.UI
{
public sealed class NamePrompt
{
private readonly NameStore _store;
private readonly ModLog _log;
private GameObject _root;
private ModalCursorWindow _modal;
private TMP_InputField _field;
private TextMeshProUGUI _preview;
private TextMeshProUGUI _current;
private Button _setButton;
private Button _revertButton;
public bool IsOpen { get; private set; }
public NamePrompt(NameStore store, ModLog log)
{
_store = store;
_log = log;
}
public void Open()
{
if (!((Object)(object)_root == (Object)null) || Build())
{
IsOpen = true;
_root.SetActive(true);
ModalCursorWindow modal = _modal;
if (modal != null)
{
modal.SetOpen(true);
}
if ((Object)(object)_field != (Object)null)
{
_field.text = (_store.HasCustomName ? _store.Chosen : string.Empty);
_field.ActivateInputField();
}
Refresh();
}
}
public void Close()
{
if (IsOpen)
{
IsOpen = false;
ModalCursorWindow modal = _modal;
if (modal != null)
{
modal.SetOpen(false);
}
if ((Object)(object)_root != (Object)null)
{
_root.SetActive(false);
}
}
}
public void Toggle()
{
if (IsOpen)
{
Close();
}
else
{
Open();
}
}
public void Tick()
{
if (IsOpen && (Input.GetKeyDown((KeyCode)13) || Input.GetKeyDown((KeyCode)271)))
{
Commit();
}
}
private bool Build()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
try
{
_root = new GameObject("SpongeUI_NamePrompt", new Type[3]
{
typeof(Canvas),
typeof(CanvasScaler),
typeof(GraphicRaycaster)
});
Object.DontDestroyOnLoad((Object)(object)_root);
Canvas component = _root.GetComponent<Canvas>();
component.renderMode = (RenderMode)0;
component.sortingOrder = 520;
CanvasScaler component2 = _root.GetComponent<CanvasScaler>();
component2.uiScaleMode = (ScaleMode)1;
component2.referenceResolution = new Vector2(1920f, 1080f);
component2.matchWidthOrHeight = 0.5f;
RectTransform val = NewRect("Panel", _root.transform);
Vector2 anchorMin = (val.anchorMax = new Vector2(0.5f, 0.5f));
val.anchorMin = anchorMin;
val.pivot = new Vector2(0.5f, 0.5f);
val.sizeDelta = new Vector2(560f, 300f);
val.anchoredPosition = Vector2.zero;
((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = new Color(0.13f, 0.1f, 0.07f, 0.97f);
Label(val, "CHANGE NAME", 24f, new Vector2(0f, -18f), new Color(0.98f, 0.86f, 0.55f), (TextAlignmentOptions)514);
BuildField(val);
_preview = Label(val, "", 16f, new Vector2(0f, -132f), new Color(1f, 1f, 1f, 0.8f), (TextAlignmentOptions)514);
_current = Label(val, "", 15f, new Vector2(0f, -158f), new Color(1f, 1f, 1f, 0.5f), (TextAlignmentOptions)514);
BuildButtons(val);
_modal = _root.AddComponent<ModalCursorWindow>();
_modal.SetLogger(_log);
_modal.Closed = delegate
{
IsOpen = false;
if ((Object)(object)_root != (Object)null)
{
_root.SetActive(false);
}
};
_root.SetActive(false);
return true;
}
catch (Exception ex)
{
ModLog log = _log;
if (log != null)
{
log.Exception("Could not build the name prompt", ex);
}
_root = null;
return false;
}
}
private void BuildField(RectTransform panel)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = NewRect("Field", (Transform)(object)panel);
val.anchorMin = new Vector2(0f, 1f);
val.anchorMax = new Vector2(1f, 1f);
val.pivot = new Vector2(0.5f, 1f);
val.sizeDelta = new Vector2(-64f, 48f);
val.anchoredPosition = new Vector2(0f, -70f);
((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = new Color(0.05f, 0.04f, 0.03f, 0.95f);
RectTransform val2 = NewRect("TextArea", (Transform)(object)val);
val2.anchorMin = Vector2.zero;
val2.anchorMax = Vector2.one;
val2.offsetMin = new Vector2(12f, 4f);
val2.offsetMax = new Vector2(-12f, -4f);
((Component)val2).gameObject.AddComponent<RectMask2D>();
RectTransform obj = NewRect("Text", (Transform)(object)val2);
Fill(obj);
TextMeshProUGUI val3 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>();
((TMP_Text)val3).fontSize = 20f;
((TMP_Text)val3).alignment = (TextAlignmentOptions)4097;
((Graphic)val3).color = Color.white;
Inherit(val3);
RectTransform obj2 = NewRect("Placeholder", (Transform)(object)val2);
Fill(obj2);
TextMeshProUGUI val4 = ((Component)obj2).gameObject.AddComponent<TextMeshProUGUI>();
((TMP_Text)val4).text = "Type a name...";
((TMP_Text)val4).fontSize = 20f;
((TMP_Text)val4).alignment = (TextAlignmentOptions)4097;
((Graphic)val4).color = new Color(1f, 1f, 1f, 0.35f);
Inherit(val4);
_field = ((Component)val).gameObject.AddComponent<TMP_InputField>();
_field.textViewport = val2;
_field.textComponent = (TMP_Text)(object)val3;
_field.placeholder = (Graphic)(object)val4;
_field.caretColor = Color.white;
_field.characterLimit = 64;
((UnityEvent<string>)(object)_field.onValueChanged).AddListener((UnityAction<string>)delegate
{
Refresh();
});
}
private void BuildButtons(RectTransform panel)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = NewRect("Set", (Transform)(object)panel);
Vector2 val2 = default(Vector2);
((Vector2)(ref val2))..ctor(0.5f, 0f);
val.anchorMax = val2;
val.anchorMin = val2;
val.pivot = new Vector2(0.5f, 0f);
val.sizeDelta = new Vector2(150f, 36f);
val.anchoredPosition = new Vector2(-170f, 22f);
_setButton = PeakStyle.CreateButton("SET NAME", (Transform)(object)val, (Action)Commit);
RectTransform val3 = NewRect("Revert", (Transform)(object)panel);
((Vector2)(ref val2))..ctor(0.5f, 0f);
val3.anchorMax = val2;
val3.anchorMin = val2;
val3.pivot = new Vector2(0.5f, 0f);
val3.sizeDelta = new Vector2(180f, 36f);
val3.anchoredPosition = new Vector2(0f, 22f);
_revertButton = PeakStyle.CreateButton("USE STEAM NAME", (Transform)(object)val3, (Action)delegate
{
_store.Clear();
Close();
});
RectTransform val4 = NewRect("Cancel", (Transform)(object)panel);
((Vector2)(ref val2))..ctor(0.5f, 0f);
val4.anchorMax = val2;
val4.anchorMin = val2;
val4.pivot = new Vector2(0.5f, 0f);
val4.sizeDelta = new Vector2(150f, 36f);
val4.anchoredPosition = new Vector2(170f, 22f);
PeakStyle.CreateButton("CANCEL", (Transform)(object)val4, (Action)Close);
}
private void Commit()
{
if (!((Object)(object)_field == (Object)null) && NameRules.Clean(_field.text).Length != 0 && _store.Set(_field.text))
{
Close();
}
}
private void Refresh()
{
string text = NameRules.Clean(((Object)(object)_field != (Object)null) ? _field.text : string.Empty);
bool flag = text.Length > 0;
if ((Object)(object)_preview != (Object)null)
{
((TMP_Text)_preview).text = (flag ? ("Others will see: " + text) : "Enter a name. Formatting tags are removed.");
}
if ((Object)(object)_current != (Object)null)
{
string steamName = _store.SteamName;
((TMP_Text)_current).text = ((!_store.HasCustomName) ? ((steamName.Length > 0) ? ("Currently using your Steam name (" + steamName + ").") : "Currently using your Steam name.") : ((steamName.Length > 0) ? ("Currently overriding your Steam name (" + steamName + ").") : "Currently overriding your Steam name."));
}
if ((Object)(object)_setButton != (Object)null)
{
((Selectable)_setButton).interactable = flag;
}
if ((Object)(object)_revertButton != (Object)null)
{
((Selectable)_revertButton).interactable = _store.HasCustomName;
}
}
private static RectTransform NewRect(string name, Transform parent)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
((Transform)component).SetParent(parent, false);
return component;
}
private static void Fill(RectTransform rect)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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)
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.one;
rect.offsetMin = Vector2.zero;
rect.offsetMax = Vector2.zero;
}
private TextMeshProUGUI Label(RectTransform panel, string text, float size, Vector2 position, Color color, TextAlignmentOptions align)
{
//IL_0016: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: 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_008a: Unknown result type (might be due to invalid IL or missing references)
RectTransform obj = NewRect("Label", (Transform)(object)panel);
obj.anchorMin = new Vector2(0f, 1f);
obj.anchorMax = new Vector2(1f, 1f);
obj.pivot = new Vector2(0.5f, 1f);
obj.sizeDelta = new Vector2(-48f, size + 10f);
obj.anchoredPosition = position;
TextMeshProUGUI obj2 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>();
((TMP_Text)obj2).text = text;
((TMP_Text)obj2).fontSize = size;
((TMP_Text)obj2).alignment = align;
((Graphic)obj2).color = color;
Inherit(obj2);
return obj2;
}
private static void Inherit(TextMeshProUGUI text)
{
GameObject buttonTemplate = PeakStyle.ButtonTemplate;
TextMeshProUGUI val = ((buttonTemplate != null) ? buttonTemplate.GetComponentInChildren<TextMeshProUGUI>(true) : null);
if ((Object)(object)((val != null) ? ((TMP_Text)val).font : null) != (Object)null)
{
((TMP_Text)text).font = ((TMP_Text)val).font;
}
}
}
internal static class PassportNameUI
{
internal static NameStore Store;
internal static Action OpenPrompt;
internal static ModLog Log;
private const string ButtonName = "SpongeTweaked_RenameButton";
internal static void OnPassportOpened(PassportManager manager)
{
if (!((Object)(object)manager == (Object)null) && Store != null)
{
RefreshName(manager);
EnsureButton(manager);
}
}
private static void RefreshName(PassportManager manager)
{
try
{
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter == (Object)null)
{
return;
}
string characterName = localCharacter.characterName;
if (!string.IsNullOrEmpty(characterName))
{
if ((Object)(object)manager.nameText != (Object)null)
{
((TMP_Text)manager.nameText).text = characterName;
}
if ((Object)(object)manager.passportNumberText != (Object)null)
{
((TMP_Text)manager.passportNumberText).text = PassportManager.GeneratePassportNumber(characterName);
}
}
}
catch (Exception ex)
{
ModLog log = Log;
if (log != null)
{
log.Exception("Could not refresh the passport name", ex);
}
}
}
private static void EnsureButton(PassportManager manager)
{
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
try
{
TextMeshProUGUI nameText = manager.nameText;
if ((Object)(object)nameText == (Object)null || (Object)(object)((TMP_Text)nameText).transform.parent == (Object)null)
{
return;
}
Transform parent = ((TMP_Text)nameText).transform.parent;
if (!((Object)(object)parent.Find("SpongeTweaked_RenameButton") != (Object)null))
{
GameObject val = Object.Instantiate<GameObject>(((Component)nameText).gameObject, parent, false);
((Object)val).name = "SpongeTweaked_RenameButton";
val.SetActive(true);
LocalizedText[] componentsInChildren = val.GetComponentsInChildren<LocalizedText>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
}
TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
if ((Object)(object)component == (Object)null)
{
Object.Destroy((Object)(object)val);
return;
}
((TMP_Text)component).text = "[ change name ]";
((Graphic)component).raycastTarget = true;
((TMP_Text)component).fontSize = Mathf.Max(6f, ((TMP_Text)nameText).fontSize * 0.5f);
((TMP_Text)component).alignment = ((TMP_Text)nameText).alignment;
PlaceBeside(nameText, val);
AddClickHandler(val);
}
}
catch (Exception ex)
{
ModLog log = Log;
if (log != null)
{
log.Exception("Could not add the rename button to the passport", ex);
}
}
}
private static void PlaceBeside(TextMeshProUGUI label, GameObject clone)
{
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: 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_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: 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)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
RectTransform rectTransform = ((TMP_Text)label).rectTransform;
RectTransform component = clone.GetComponent<RectTransform>();
if (!((Object)(object)component == (Object)null))
{
component.anchorMin = rectTransform.anchorMin;
component.anchorMax = rectTransform.anchorMax;
component.pivot = rectTransform.pivot;
((Transform)component).localScale = ((Transform)rectTransform).localScale;
((Transform)component).localRotation = ((Transform)rectTransform).localRotation;
component.sizeDelta = new Vector2(96f, rectTransform.sizeDelta.y);
float num = 0f;
try
{
num = ((TMP_Text)label).GetPreferredValues(((TMP_Text)label).text).x;
}
catch (Exception)
{
num = rectTransform.sizeDelta.x * 0.5f;
}
float num2 = Mathf.Min(num + 24f, rectTransform.sizeDelta.x + 110f);
component.anchoredPosition = rectTransform.anchoredPosition + new Vector2(num2, 0f);
}
}
private static void AddClickHandler(GameObject clone)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
TextMeshProUGUI text = clone.GetComponent<TextMeshProUGUI>();
Color idle = new Color(((Graphic)text).color.r, ((Graphic)text).color.g, ((Graphic)text).color.b, 0.65f);
Color hot = ((Graphic)text).color;
((Graphic)text).color = idle;
EventTrigger trigger = clone.AddComponent<EventTrigger>();
Add(trigger, (EventTriggerType)4, delegate
{
try
{
OpenPrompt?.Invoke();
}
catch (Exception ex)
{
ModLog log = Log;
if (log != null)
{
log.Exception("Rename prompt failed to open", ex);
}
}
});
Add(trigger, (EventTriggerType)0, delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
((Graphic)text).color = hot;
});
Add(trigger, (EventTriggerType)1, delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
((Graphic)text).color = idle;
});
}
private static void Add(EventTrigger trigger, EventTriggerType type, Action<BaseEventData> action)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
Entry val = new Entry
{
eventID = type
};
((UnityEvent<BaseEventData>)(object)val.callback).AddListener((UnityAction<BaseEventData>)delegate(BaseEventData data)
{
action(data);
});
trigger.triggers.Add(val);
}
}
[HarmonyPatch(typeof(PassportManager), "ToggleOpen")]
internal static class PassportOpenPatch
{
[HarmonyPostfix]
private static void Postfix(PassportManager __instance)
{
if (!((Object)(object)__instance == (Object)null) && ((MenuWindow)__instance).isOpen)
{
PassportNameUI.OnPassportOpened(__instance);
}
}
}
public sealed class TweakWindow
{
private readonly TweakState _state;
private readonly ModLog _log;
private GameObject _root;
private ModalCursorWindow _modal;
private RectTransform _content;
private ScrollRect _scroll;
private TextMeshProUGUI _summary;
private TextMeshProUGUI _notice;
private readonly Dictionary<string, (Slider slider, Toggle toggle, TextMeshProUGUI label)> _rows = new Dictionary<string, (Slider, Toggle, TextMeshProUGUI)>();
private bool _suppressCallbacks;
public bool IsOpen { get; private set; }
private static bool CanEdit
{
get
{
if (PhotonNetwork.InRoom)
{
return PhotonNetwork.IsMasterClient;
}
return true;
}
}
public TweakWindow(TweakState state, ModLog log)
{
_state = state;
_log = log;
}
public void Toggle()
{
if (IsOpen)
{
Close();
}
else if (!((Object)(object)_root == (Object)null) || Build())
{
IsOpen = true;
_root.SetActive(true);
ModalCursorWindow modal = _modal;
if (modal != null)
{
modal.SetOpen(true);
}
RefreshValues();
}
}
public void Close()
{
if (IsOpen)
{
IsOpen = false;
ModalCursorWindow modal = _modal;
if (modal != null)
{
modal.SetOpen(false);
}
if ((Object)(object)_root != (Object)null)
{
_root.SetActive(false);
}
}
}
public void Tick()
{
if (IsOpen)
{
RefreshValues();
}
}
private bool Build()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
try
{
_root = new GameObject("SpongeUI_RunRules", new Type[3]
{
typeof(Canvas),
typeof(CanvasScaler),
typeof(GraphicRaycaster)
});
Object.DontDestroyOnLoad((Object)(object)_root);
Canvas component = _root.GetComponent<Canvas>();
component.renderMode = (RenderMode)0;
component.sortingOrder = 500;
CanvasScaler component2 = _root.GetComponent<CanvasScaler>();
component2.uiScaleMode = (ScaleMode)1;
component2.referenceResolution = new Vector2(1920f, 1080f);
component2.matchWidthOrHeight = 0.5f;
RectTransform val = NewRect("Panel", _root.transform);
Vector2 anchorMin = (val.anchorMax = new Vector2(0.5f, 0.5f));
val.anchorMin = anchorMin;
val.pivot = new Vector2(0.5f, 0.5f);
val.sizeDelta = new Vector2(720f, 800f);
val.anchoredPosition = Vector2.zero;
((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = new Color(0.13f, 0.1f, 0.07f, 0.96f);
Title(val, "RUN RULES", 28f, new Vector2(0f, -16f), new Color(0.98f, 0.86f, 0.55f));
_notice = Title(val, "", 16f, new Vector2(0f, -52f), new Color(1f, 0.72f, 0.4f));
_summary = Title(val, "", 16f, new Vector2(0f, -74f), new Color(1f, 1f, 1f, 0.6f));
RectTransform val3 = NewRect("List", (Transform)(object)val);
val3.anchorMin = new Vector2(0f, 0f);
val3.anchorMax = new Vector2(1f, 1f);
val3.offsetMin = new Vector2(24f, 62f);
val3.offsetMax = new Vector2(-24f, -100f);
_content = val3;
_scroll = ScrollableList.Ensure((Transform)(object)_content, _log, 2f);
BuildRows();
Footer(val);
_modal = _root.AddComponent<ModalCursorWindow>();
_modal.SetLogger(_log);
_modal.Closed = delegate
{
IsOpen = false;
if ((Object)(object)_root != (Object)null)
{
_root.SetActive(false);
}
};
_root.SetActive(false);
return true;
}
catch (Exception ex)
{
ModLog log = _log;
if (log != null)
{
log.Exception("Could not build the run rules window", ex);
}
_root = null;
return false;
}
}
private void BuildRows()
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
foreach (IGrouping<string, TweakDefinition> item in from t in TweakCatalog.All
group t by t.Category)
{
RectTransform obj = NewRect("Header_" + item.Key, (Transform)(object)_content);
obj.sizeDelta = new Vector2(0f, 30f);
Size(obj, 30f);
TextMeshProUGUI obj2 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>();
((TMP_Text)obj2).text = item.Key.ToUpperInvariant();
((TMP_Text)obj2).fontSize = 17f;
((TMP_Text)obj2).alignment = (TextAlignmentOptions)4097;
((Graphic)obj2).color = new Color(0.98f, 0.86f, 0.55f, 0.85f);
Inherit(obj2);
foreach (TweakDefinition item2 in item)
{
BuildRow(item2);
}
}
}
private void BuildRow(TweakDefinition tweak)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_028a: Unknown result type (might be due to invalid IL or missing references)
//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
//IL_030e: Unknown result type (might be due to invalid IL or missing references)
//IL_0324: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_033c: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Unknown result type (might be due to invalid IL or missing references)
//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0406: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = NewRect("Row_" + tweak.Id, (Transform)(object)_content);
val.sizeDelta = new Vector2(0f, 32f);
Size(val, 32f);
RectTransform obj = NewRect("Label", (Transform)(object)val);
obj.anchorMin = new Vector2(0f, 0f);
obj.anchorMax = new Vector2(0.45f, 1f);
obj.offsetMin = new Vector2(8f, 0f);
obj.offsetMax = Vector2.zero;
TextMeshProUGUI val2 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>();
((TMP_Text)val2).fontSize = 16f;
((TMP_Text)val2).alignment = (TextAlignmentOptions)4097;
((Graphic)val2).color = Color.white;
Inherit(val2);
if (tweak.Kind == TweakKind.Switch)
{
((TMP_Text)val2).text = tweak.Label;
RectTransform val3 = NewRect("Toggle", (Transform)(object)val);
val3.anchorMin = new Vector2(0.47f, 0.15f);
val3.anchorMax = new Vector2(0.52f, 0.85f);
val3.offsetMin = Vector2.zero;
val3.offsetMax = Vector2.zero;
Image val4 = ((Component)val3).gameObject.AddComponent<Image>();
((Graphic)val4).color = new Color(0.05f, 0.04f, 0.03f, 0.95f);
RectTransform obj2 = NewRect("Check", (Transform)(object)val3);
obj2.anchorMin = new Vector2(0.18f, 0.18f);
obj2.anchorMax = new Vector2(0.82f, 0.82f);
obj2.offsetMin = Vector2.zero;
obj2.offsetMax = Vector2.zero;
Image val5 = ((Component)obj2).gameObject.AddComponent<Image>();
((Graphic)val5).color = new Color(0.98f, 0.86f, 0.55f);
Toggle val6 = ((Component)val3).gameObject.AddComponent<Toggle>();
((Selectable)val6).targetGraphic = (Graphic)(object)val4;
val6.graphic = (Graphic)(object)val5;
((UnityEvent<bool>)(object)val6.onValueChanged).AddListener((UnityAction<bool>)delegate(bool v)
{
if (!_suppressCallbacks)
{
Apply(tweak.Id, v ? 1f : 0f);
}
});
_rows[tweak.Id] = (null, val6, val2);
return;
}
RectTransform val7 = NewRect("Slider", (Transform)(object)val);
val7.anchorMin = new Vector2(0.47f, 0.25f);
val7.anchorMax = new Vector2(0.88f, 0.75f);
val7.offsetMin = Vector2.zero;
val7.offsetMax = Vector2.zero;
Image val8 = ((Component)val7).gameObject.AddComponent<Image>();
((Graphic)val8).color = new Color(0.05f, 0.04f, 0.03f, 0.95f);
RectTransform val9 = NewRect("Fill Area", (Transform)(object)val7);
val9.anchorMin = Vector2.zero;
val9.anchorMax = Vector2.one;
val9.offsetMin = Vector2.zero;
val9.offsetMax = Vector2.zero;
RectTransform val10 = NewRect("Fill", (Transform)(object)val9);
val10.anchorMin = Vector2.zero;
val10.anchorMax = new Vector2(1f, 1f);
val10.offsetMin = Vector2.zero;
val10.offsetMax = Vector2.zero;
((Graphic)((Component)val10).gameObject.AddComponent<Image>()).color = new Color(0.98f, 0.86f, 0.55f, 0.75f);
Slider val11 = ((Component)val7).gameObject.AddComponent<Slider>();
val11.fillRect = val10;
((Selectable)val11).targetGraphic = (Graphic)(object)val8;
val11.minValue = 0.01f;
val11.maxValue = 5f;
((UnityEvent<float>)(object)val11.onValueChanged).AddListener((UnityAction<float>)delegate(float v)
{
if (!_suppressCallbacks)
{
Apply(tweak.Id, Mathf.Round(v * 100f) / 100f);
}
});
RectTransform val12 = NewRect("Reset", (Transform)(object)val);
val12.anchorMin = new Vector2(0.9f, 0.15f);
val12.anchorMax = new Vector2(0.99f, 0.85f);
val12.offsetMin = Vector2.zero;
val12.offsetMax = Vector2.zero;
PeakStyle.CreateButton("1x", (Transform)(object)val12, (Action)delegate
{
Apply(tweak.Id, 1f);
});
_rows[tweak.Id] = (val11, null, val2);
}
private void Footer(RectTransform panel)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = NewRect("ResetAll", (Transform)(object)panel);
Vector2 val2 = default(Vector2);
((Vector2)(ref val2))..ctor(0f, 0f);
val.anchorMax = val2;
val.anchorMin = val2;
val.pivot = new Vector2(0f, 0f);
val.sizeDelta = new Vector2(150f, 34f);
val.anchoredPosition = new Vector2(24f, 16f);
PeakStyle.CreateButton("RESET ALL", (Transform)(object)val, (Action)delegate
{
if (CanEdit)
{
_state.Reset();
_state.Publish();
RefreshValues();
}
});
RectTransform val3 = NewRect("Close", (Transform)(object)panel);
((Vector2)(ref val2))..ctor(1f, 0f);
val3.anchorMax = val2;
val3.anchorMin = val2;
val3.pivot = new Vector2(1f, 0f);
val3.sizeDelta = new Vector2(150f, 34f);
val3.anchoredPosition = new Vector2(-24f, 16f);
PeakStyle.CreateButton("CLOSE", (Transform)(object)val3, (Action)Close);
}
private void RefreshValues()
{
bool canEdit = CanEdit;
_suppressCallbacks = true;
try
{
foreach (TweakDefinition item in TweakCatalog.All)
{
if (_rows.TryGetValue(item.Id, out (Slider, Toggle, TextMeshProUGUI) value))
{
float num = _state.Get(item.Id);
if ((Object)(object)value.Item2 != (Object)null)
{
value.Item2.isOn = num >= 0.5f;
((Selectable)value.Item2).interactable = canEdit;
}
if ((Object)(object)value.Item1 != (Object)null)
{
value.Item1.value = Mathf.Clamp(num, 0.01f, 5f);
((Selectable)value.Item1).interactable = canEdit;
((TMP_Text)value.Item3).text = $"{item.Label} {num:0.##}x";
}
}
}
}
finally
{
_suppressCallbacks = false;
}
if ((Object)(object)_notice != (Object)null)
{
((TMP_Text)_notice).text = (canEdit ? string.Empty : "The host controls these. Shown for reference.");
}
if ((Object)(object)_summary != (Object)null)
{
((TMP_Text)_summary).text = (_state.AnyActive ? $"{_state.ActiveCount} rule(s) changed from vanilla." : "Everything is at vanilla values.");
}
}
private void Apply(string id, float value)
{
if (CanEdit)
{
_state.Set(id, value);
_state.Publish();
RefreshValues();
}
}
private static RectTransform NewRect(string name, Transform parent)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
((Transform)component).SetParent(parent, false);
return component;
}
private static void Size(RectTransform rect, float height)
{
LayoutElement obj = ((Component)rect).gameObject.AddComponent<LayoutElement>();
obj.preferredHeight = height;
obj.minHeight = height;
}
private TextMeshProUGUI Title(RectTransform panel, string text, float size, Vector2 position, Color color)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: 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_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
RectTransform obj = NewRect("Text_" + text, (Transform)(object)panel);
obj.anchorMin = new Vector2(0f, 1f);
obj.anchorMax = new Vector2(1f, 1f);
obj.pivot = new Vector2(0.5f, 1f);
obj.sizeDelta = new Vector2(-40f, size + 12f);
obj.anchoredPosition = position;
TextMeshProUGUI obj2 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>();
((TMP_Text)obj2).text = text;
((TMP_Text)obj2).fontSize = size;
((TMP_Text)obj2).alignment = (TextAlignmentOptions)514;
((Graphic)obj2).color = color;
Inherit(obj2);
return obj2;
}
private static void Inherit(TextMeshProUGUI text)
{
GameObject buttonTemplate = PeakStyle.ButtonTemplate;
TextMeshProUGUI val = ((buttonTemplate != null) ? buttonTemplate.GetComponentInChildren<TextMeshProUGUI>(true) : null);
if ((Object)(object)((val != null) ? ((TMP_Text)val).font : null) != (Object)null)
{
((TMP_Text)text).font = ((TMP_Text)val).font;
}
}
}
}
namespace SpongePEAK.Tweaked.Tweaks
{
public static class NameRules
{
public const int MaxLength = 32;
private static readonly Regex RichText = new Regex("<[^>]*>", RegexOptions.Compiled);
public static string Clean(string raw)
{
if (string.IsNullOrEmpty(raw))
{
return string.Empty;
}
string text = RichText.Replace(raw, string.Empty);
text = text.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ');
text = text.Trim();
if (text.Length > 32)
{
text = text.Substring(0, 32).Trim();
}
return text;
}
public static bool IsAcceptable(string raw)
{
return Clean(raw).Length > 0;
}
}
public sealed class NameStore
{
private ModLog _log;
private ConfigEntry<string> _chosen;
public string Chosen => NameRules.Clean(_chosen?.Value ?? string.Empty);
public bool HasCustomName => Chosen.Length > 0;
public static string Current => PhotonNetwork.NickName ?? string.Empty;
public string SteamName
{
get
{
try
{
return NameRules.Clean(NetworkingUtilities.GetUsername());
}
catch (Exception ex)
{
ModLog log = _log;
if (log != null)
{
log.Exception("Could not read the Steam name", ex);
}
return string.Empty;
}
}
}
public string Effective
{
get
{
string chosen = Chosen;
if (chosen.Length > 0)
{
return chosen;
}
string current = Current;
if (current.Length > 0)
{
return current;
}
return SteamName;
}
}
public event Action Changed;
public NameStore(ModLog log)
{
_log = log;
}
public void SetLogger(ModLog log)
{
_log = log;
}
public void Configure(ConfigFile config)
{
_chosen = config.Bind<string>("Identity", "DisplayName", string.Empty, "Your in-game name. Empty means use the Steam name. Editable from the passport.");
}
public bool Set(string raw)
{
string text = NameRules.Clean(raw);
if (text.Length == 0)
{
ModLog log = _log;
if (log != null)
{
log.Warning((object)"Rejected an empty or markup-only name.");
}
return false;
}
string steamName = SteamName;
if (steamName.Length > 0 && string.Equals(text, steamName, StringComparison.Ordinal))
{
Clear();
return true;
}
if (_chosen != null)
{
_chosen.Value = text;
}
Apply();
this.Changed?.Invoke();
return true;
}
public void Clear()
{
if (_chosen != null)
{
_chosen.Value = string.Empty;
}
try
{
string steamName = SteamName;
if (steamName.Length > 0)
{
PhotonNetwork.NickName = steamName;
ModLog log = _log;
if (log != null)
{
log.Info((object)("Display name reset to the Steam name '" + steamName + "'."));
}
}
}
catch (Exception ex)
{
ModLog log2 = _log;
if (log2 != null)
{
log2.Exception("Could not restore the Steam name", ex);
}
}
this.Changed?.Invoke();
}
public void Apply()
{
string chosen = Chosen;
if (chosen.Length == 0)
{
return;
}
try
{
if (!(PhotonNetwork.NickName == chosen))
{
PhotonNetwork.NickName = chosen;
ModLog log = _log;
if (log != null)
{
log.Info((object)("Display name set to '" + chosen + "'."));
}
}
}
catch (Exception ex)
{
ModLog log2 = _log;
if (log2 != null)
{
log2.Exception("Could not apply the display name", ex);
}
}
}
}
public enum TweakKind
{
Scale,
Switch
}
public sealed class TweakDefinition
{
public string Id { get; }
public string Label { get; }
public string Category { get; }
public TweakKind Kind { get; }
public string Description { get; }
public float Neutral
{
get
{
if (Kind != TweakKind.Scale)
{
return 1f;
}
return 1f;
}
}
public TweakDefinition(string id, string label, string category, TweakKind kind, string description)
{
Id = id;
Label = label;
Category = category;
Kind = kind;
Description = description;
}
}
public static class TweakCatalog
{
public const float MinScale = 0.01f;
public const float MaxScale = 5f;
public const string Survival = "Survival";
public const string Damage = "Damage";
public const string Statuses = "Statuses";
public const string StaminaEnabled = "stamina.enabled";
public const string StaminaUsage = "stamina.usage";
public const string HungerEnabled = "hunger.enabled";
public const string HungerRate = "hunger.rate";
public const string DamageEnabled = "damage.enabled";
public const string DamageScale = "damage.scale";
public const string FallDamageScale = "damage.fall";
public const string StatusPrefix = "status.";
public static IReadOnlyList<TweakDefinition> All { get; } = Build();
public static TweakDefinition Find(string id)
{
foreach (TweakDefinition item in All)
{
if (string.Equals(item.Id, id, StringComparison.Ordinal))
{
return item;
}
}
return null;
}
public unsafe static string StatusId(STATUSTYPE status)
{
return "status." + ((object)(*(STATUSTYPE*)(&status))/*cast due to .constrained prefix*/).ToString();
}
private static List<TweakDefinition> Build()
{
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
List<TweakDefinition> list = new List<TweakDefinition>
{
new TweakDefinition("stamina.enabled", "Stamina", "Survival", TweakKind.Switch, "Off: climbing, sprinting and jumping cost no stamina."),
new TweakDefinition("stamina.usage", "Stamina usage", "Survival", TweakKind.Scale, "Scales every stamina cost: climbing, sprinting, jumping, ropes and vines."),
new TweakDefinition("hunger.enabled", "Hunger", "Survival", TweakKind.Switch, "Off: hunger never accrues on its own."),
new TweakDefinition("hunger.rate", "Hunger rate", "Survival", TweakKind.Scale, "Scales how fast hunger builds up."),
new TweakDefinition("damage.enabled", "Damage", "Damage", TweakKind.Switch, "Off: nothing can injure you. Other statuses still apply."),
new TweakDefinition("damage.scale", "Damage taken", "Damage", TweakKind.Scale, "Scales all injury taken, from any source."),
new TweakDefinition("damage.fall", "Fall damage", "Damage", TweakKind.Scale, "Scales injury from falling only.")
};
foreach (STATUSTYPE value in Enum.GetValues(typeof(STATUSTYPE)))
{
list.Add(new TweakDefinition(StatusId(value), ((object)value/*cast due to .constrained prefix*/).ToString(), "Statuses", TweakKind.Scale, $"Scales how fast {(object)value} builds up. 0.01 is almost none, 5 is five times."));
}
return list;
}
}
public sealed class TweakState
{
public const string PropertyKey = "sponge.tweaks";
private const char PairSeparator = ';';
private const char ValueSeparator = '=';
private readonly Dictionary<string, float> _values = new Dictionary<string, float>(StringComparer.Ordinal);
private readonly ModLog _log;
public bool AnyActive => _values.Count > 0;
public int ActiveCount => _values.Count;
public IEnumerable<KeyValuePair<string, float>> Active => _values.OrderBy<KeyValuePair<string, float>, string>((KeyValuePair<string, float> pair) => pair.Key, StringComparer.Ordinal);
public event Action Changed;
public TweakState(ModLog log)
{
_log = log;
}
public float Get(string id)
{
if (_values.TryGetValue(id, out var value))
{
return value;
}
return TweakCatalog.Find(id)?.Neutral ?? 1f;
}
public bool IsOn(string id)
{
return Get(id) >= 0.5f;
}
public float StatusScale(STATUSTYPE status)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
return Get(TweakCatalog.StatusId(status));
}
public void Set(string id, float value)
{
TweakDefinition tweakDefinition = TweakCatalog.Find(id);
if (tweakDefinition != null)
{
value = ((tweakDefinition.Kind != TweakKind.Scale) ? ((value >= 0.5f) ? 1f : 0f) : Math.Max(0.01f, Math.Min(5f, value)));
if (Math.Abs(value - tweakDefinition.Neutral) < 0.0001f)
{
_values.Remove(id);
}
else
{
_values[id] = value;
}
this.Changed?.Invoke();
}
}
public void Reset()
{
if (_values.Count != 0)
{
_values.Clear();
this.Changed?.Invoke();
}
}
public void Publish()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0027: Expected O, but got Unknown
if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
return;
}
try
{
Hashtable val = new Hashtable();
((Dictionary<object, object>)val).Add((object)"sponge.tweaks", (object)Serialize());
Hashtable val2 = val;
PhotonNetwork.CurrentRoom.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null);
ModLog log = _log;
if (log != null)
{
log.Debug((object)$"Published {_values.Count} tweak(s) to the room.");
}
}
catch (Exception ex)
{
ModLog log2 = _log;
if (log2 != null)
{
log2.Exception("Failed to publish tweaks", ex);
}
}
}
public bool ApplyRemote(string payload)
{
Dictionary<string, float> dictionary = Deserialize(payload);
if (dictionary.Count == _values.Count && dictionary.All((KeyValuePair<string, float> pair) => _values.TryGetValue(pair.Key, out var value) && Math.Abs(value - pair.Value) < 0.0001f))
{
return false;
}
_values.Clear();
foreach (KeyValuePair<string, float> item in dictionary)
{
_values[item.Key] = item.Value;
}
ModLog log = _log;
if (log != null)
{
log.Info((object)$"Applied {_values.Count} tweak(s) from the host.");
}
this.Changed?.Invoke();
return true;
}
public bool ApplyFromRoom()
{
if (PhotonNetwork.InRoom)
{
Room currentRoom = PhotonNetwork.CurrentRoom;
if (((currentRoom != null) ? ((RoomInfo)currentRoom).CustomProperties : null) != null)
{
if (((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"sponge.tweaks", out object value) && value is string payload)
{
return ApplyRemote(payload);
}
return ApplyRemote(string.Empty);
}
}
return false;
}
private string Serialize()
{
StringBuilder stringBuilder = new StringBuilder();
foreach (KeyValuePair<string, float> value in _values)
{
if (stringBuilder.Length > 0)
{
stringBuilder.Append(';');
}
stringBuilder.Append(value.Key).Append('=').Append(value.Value.ToString("0.####", CultureInfo.InvariantCulture));
}
return stringBuilder.ToString();
}
private Dictionary<string, float> Deserialize(string payload)
{
Dictionary<string, float> dictionary = new Dictionary<string, float>(StringComparer.Ordinal);
if (string.IsNullOrEmpty(payload))
{
return dictionary;
}
string[] array = payload.Split(';');
foreach (string text in array)
{
if (string.IsNullOrEmpty(text))
{
continue;
}
int num = text.IndexOf('=');
if (num > 0)
{
string text2 = text.Substring(0, num);
string s = text.Substring(num + 1);
if (TweakCatalog.Find(text2) != null && float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
{
dictionary[text2] = result;
}
}
}
return dictionary;
}
}
}
namespace SpongePEAK.Tweaked.Patches
{
[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
internal static class AddStatusPatch
{
internal static TweakState State;
[HarmonyPrefix]
[HarmonyPriority(200)]
private static void Prefix(STATUSTYPE statusType, ref float amount)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Invalid comparison between Unknown and I4
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Invalid comparison between Unknown and I4
if (State == null || !State.AnyActive || amount <= 0f)
{
return;
}
if ((int)statusType == 0)
{
if (!State.IsOn("damage.enabled"))
{
amount = 0f;
return;
}
amount *= State.Get("damage.scale");
if (FallDamagePatch.InFallDamage)
{
amount *= State.Get("damage.fall");
}
}
if ((int)statusType == 1 && !State.IsOn("hunger.enabled"))
{
amount = 0f;
return;
}
amount *= State.StatusScale(statusType);
if ((int)statusType == 1)
{
amount *= State.Get("hunger.rate");
}
}
}
[HarmonyPatch(typeof(CharacterMovement), "CheckFallDamage")]
internal static class FallDamagePatch
{
internal static bool InFallDamage;
[HarmonyPrefix]
[HarmonyPriority(200)]
private static void Prefix()
{
InFallDamage = true;
}
[HarmonyFinalizer]
private static void Finalizer()
{
InFallDamage = false;
}
}
[HarmonyPatch(typeof(Character), "UseStamina")]
internal static class UseStaminaPatch
{
internal static TweakState State;
[HarmonyPrefix]
[HarmonyPriority(200)]
private static bool Prefix(ref float usage, ref bool __result)
{
if (CampfireSafeZoneFeature.LocalPlayerProtected)
{
__result = true;
return false;
}
if (State == null || !State.AnyActive)
{
return true;
}
if (!State.IsOn("stamina.enabled"))
{
__result = true;
return false;
}
usage *= State.Get("stamina.usage");
return true;
}
}
}
namespace SpongePEAK.Tweaked.Net
{
public sealed class TweakSync : IInRoomCallbacks, IMatchmakingCallbacks
{
private readonly TweakState _state;
private readonly ModLog _log;
private bool _registered;
public TweakSync(TweakState state, ModLog log)
{
_state = state;
_log = log;
}
public void Start()
{
if (!_registered)
{
PhotonNetwork.AddCallbackTarget((object)this);
_registered = true;
}
}
public void Stop()
{
if (_registered)
{
PhotonNetwork.RemoveCallbackTarget((object)this);
_registered = false;
}
}
public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
{
if (propertiesThatChanged != null && ((Dictionary<object, object>)(object)propertiesThatChanged).ContainsKey((object)"sponge.tweaks") && !PhotonNetwork.IsMasterClient)
{
_state.ApplyFromRoom();
}
}
public void OnJoinedRoom()
{
if (PhotonNetwork.IsMasterClient)
{
_state.Publish();
}
else
{
_state.ApplyFromRoom();
}
}
public void OnMasterClientSwitched(Player newMasterClient)
{
if (newMasterClient != null && PhotonNetwork.IsMasterClient)
{
_state.ApplyFromRoom();
ModLog log = _log;
if (log != null)
{
log.Info((object)"Promoted to host; keeping the run's current tweaks.");
}
}
}
public void OnLeftRoom()
{
_state.Reset();
}
public void OnPlayerEnteredRoom(Player newPlayer)
{
}
public void OnPlayerLeftRoom(Player otherPlayer)
{
}
public void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
{
}
public void OnFriendListUpdate(List<FriendInfo> friendList)
{
}
public void OnCreatedRoom()
{
}
public void OnCreateRoomFailed(short returnCode, string message)
{
}
public void OnJoinRoomFailed(short returnCode, string message)
{
}
public void OnJoinRandomFailed(short returnCode, string message)
{
}
}
}
namespace SpongePEAK.Tweaked.Features
{
public sealed class CampfireSafeZoneFeature : ModFeature
{
public const string RuleId = "CampfireSafeZone";
public const bool RuleDefault = true;
private ConfigEntry<float> _radius;
private ConfigEntry<bool> _relaxFogRule;
private float _nextScan;
private static Campfire[] _campfires;
private static float _nextFind;
public override string Name => "CampfireSafeZone";
public override string Description => "Near a lit campfire, stops stamina drain and optionally lets the gloom pause when any player is resting rather than all of them. Hunger protection is already vanilla.";
public override string Replaces => "flipf17-CampfireSafeZone";
public override string Section => "Tweaks";
internal static HostRuleSet Rules { get; set; }
internal static float Radius { get; private set; } = 15f;
internal static bool RelaxFogRule { get; private set; }
internal static bool LocalPlayerProtected { get; private set; }
public void Configure(ConfigFile config)
{
_radius = config.Bind<float>("Tweaks", "CampfireSafeRadius", 15f, "How close to a lit campfire stamina protection reaches, in metres.");
_relaxFogRule = config.Bind<bool>("Tweaks", "CampfireRelaxFogRule", true, "Vanilla pauses the gloom only while EVERY player is near the fire. With this on, one resting player is enough, so a scout going ahead does not restart the timer for the group.");
}
protected override void OnEnable(PatchHost patches, ModLog log)
{
Radius = Mathf.Clamp(_radius?.Value ?? 15f, 3f, 40f);
RelaxFogRule = _relaxFogRule?.Value ?? true;
if (!patches.PatchType(typeof(CampfireFogPatch)))
{
log.Warning((object)"Campfire fog relaxation unavailable; stamina protection still works.");
}
log.Info((object)"Campfire safe zone ready; host rule 'CampfireSafeZone' decides whether it applies.");
}
public void Tick()
{
if (!((ModFeature)this).IsActive)
{
LocalPlayerProtected = false;
}
else if (Rules == null || !Rules.IsOn("CampfireSafeZone"))
{
LocalPlayerProtected = false;
}
else if (!(Time.time < _nextScan))
{
_nextScan = Time.time + 0.25f;
LocalPlayerProtected = ComputeProtected();
}
}
private static bool ComputeProtected()
{
//IL_0032: 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_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
try
{
Character localCharacter = Character.localCharacter;
if ((Object)(object)localCharacter == (Object)null || (Object)(object)localCharacter.data == (Object)null || localCharacter.data.dead)
{
return false;
}
Vector3 center = localCharacter.Center;
if (_campfires == null || Time.time >= _nextFind)
{
_campfires = Object.FindObjectsByType<Campfire>((FindObjectsInactive)0, (FindObjectsSortMode)0);
_nextFind = Time.time + 10f;
}
Campfire[] campfires = _campfires;
foreach (Campfire val in campfires)
{
if (!((Object)(object)val == (Object)null) && val.Lit)
{
Vector3 val2 = center - ((Component)val).transform.position;
if (((Vector3)(ref val2)).sqrMagnitude <= Radius * Radius)
{
return true;
}
}
}
}
catch (Exception)
{
}
return false;
}
public void Cleanup()
{
LocalPlayerProtected = false;
Rules = null;
_campfires = null;
}
}
[HarmonyPatch(typeof(Campfire), "ApplyCampfireProtection")]
internal static class CampfireFogPatch
{
[HarmonyPostfix]
private static void Postfix(Campfire __instance)
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
if (!CampfireSafeZoneFeature.RelaxFogRule || CampfireSafeZoneFeature.Rules == null || !CampfireSafeZoneFeature.Rules.IsOn("CampfireSafeZone"))
{
return;
}
try
{
OrbFogHandler instance = Singleton<OrbFogHandler>.Instance;
if ((Object)(object)instance == (Object)null || instance.PlayersAreResting || (Object)(object)__instance == (Object)null || !__instance.Lit)
{
return;
}
foreach (Character allCharacter in Character.AllCharacters)
{
if (!((Object)(object)allCharacter == (Object)null) && !allCharacter.isBot && !((Object)(object)allCharacter.data == (Object)null) && !allCharacter.data.dead && Vector3.Distance(allCharacter.Center, ((Component)__instance).transform.position) <= CampfireSafeZoneFeature.Radius)
{
instance.PlayersAreResting = true;
break;
}
}
}
catch (Exception)
{
}
}
}
public sealed class CustomNameFeature : ModFeature, IMatchmakingCallbacks
{
private NameStore _store;
private NamePrompt _prompt;
private ModLog _log;
private bool _registered;
public override string Name => "CustomName";
public override string Description => "Adds a 'change name' control to the passport, letting you pick the name other players see. Until you set one, your Steam name is used.";
public override string Replaces => "";
public override string Section => "Identity";
public void Configure(ConfigFile config)
{
_store = new NameStore(null);
_store.Configure(config);
}
protected override void OnEnable(PatchHost patches, ModLog log)
{
_log = log;
if (_store == null)
{
_store = new NameStore(log);
}
_store.SetLogger(log);
_prompt = new NamePrompt(_store, log);
PassportNameUI.Store = _store;
PassportNameUI.Log = log;
PassportNameUI.OpenPrompt = delegate
{
_prompt.Open();
};
if (!patches.PatchType(typeof(PassportOpenPatch)))
{
((ModFeature)this).Fail("could not patch PassportManager.ToggleOpen");
return;
}
PhotonNetwork.AddCallbackTarget((object)this);
_registered = true;
if (PhotonNetwork.InRoom)
{
_store.Apply();
}
log.Info((object)(_store.HasCustomName ? ("Custom name active: '" + _store.Chosen + "'. Change it from the passport.") : "Custom name available: using your Steam name until you pick one in the passport."));
}
public void Tick()
{
_prompt?.Tick();
}
public void Cleanup()
{
_prompt?.Close();
if (_registered)
{
PhotonNetwork.RemoveCallbackTarget((object)this);
_registered = false;
}
PassportNameUI.Store = null;
PassportNameUI.OpenPrompt = null;
}
public void OnJoinedRoom()
{
try
{
_store?.Apply();
}
catch (Exception ex)
{
ModLog log = _log;
if (log != null)
{
log.Exception("Could not apply the display name on join", ex);
}
}
}
public void OnCreatedRoom()
{
}
public void OnCreateRoomFailed(short returnCode, string message)
{
}
public void OnJoinRoomFailed(short returnCode, string message)
{
}
public void OnJoinRandomFailed(short returnCode, string message)
{
}
public void OnLeftRoom()
{
}
public void OnFriendListUpdate(List<FriendInfo> friendList)
{
}
}
public sealed class RunTweaksFeature : ModFeature
{
private ConfigEntry<KeyCode> _hotkey;
private TweakState _state;
private TweakSync _sync;
private TweakWindow _window;
private ModLog _log;
public override string Name => "RunTweaks";
public override string Description => "Lets the host scale or disable stamina, hunger, damage and individual statuses for everyone.";
public override string Replaces => "";
public override string Section => "Tweaks";
public void Configure(ConfigFile config)
{
_hotkey = config.Bind<KeyCode>("Tweaks", "PanelHotkey", (KeyCode)285, "Key that opens the run tweaks panel.");
}
protected override void OnEnable(PatchHost patches, ModLog log)
{
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
_log = log;
_state = new TweakState(log);
_window = new TweakWindow(_state, log);
_sync = new TweakSync(_state, log);
MenuIntegration.AddPauseMenuButton("RUN RULES", (Action)OpenIfHost);
AddStatusPatch.State = _state;
UseStaminaPatch.State = _state;
if (!patches.PatchType(typeof(AddStatusPatch)))
{
((ModFeature)this).Fail("could not patch CharacterAfflictions.AddStatus");
return;
}
if (!patches.PatchType(typeof(UseStaminaPatch)))
{
((ModFeature)this).Fail("could not patch Character.UseStamina");
return;
}
if (!patches.PatchType(typeof(FallDamagePatch)))
{
log.Warning((object)"Fall damage scaling unavailable; falls follow the general damage scale.");
}
_sync.Start();
ConfigEntry<KeyCode> hotkey = _hotkey;
log.Info((object)$"Run tweaks ready; press {(object)(KeyCode)((hotkey == null) ? 285 : ((int)hotkey.Value))} to open the panel.");
}
public void Tick()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
if (_window != null)
{
ConfigEntry<KeyCode> hotkey = _hotkey;
if (Input.GetKeyDown((KeyCode)((hotkey == null) ? 285 : ((int)hotkey.Value))))
{
_window.Toggle();
}
_window.Tick();
}
}
private void OpenIfHost()
{
if (!PhotonNetwork.IsMasterClient && !PhotonNetwork.OfflineMode)
{
ModLog log = _log;
if (log != null)
{
log.Info((object)"Run rules are set by the host.");
}
}
else
{
_window?.Toggle();
}
}
public void Cleanup()
{
_window?.Close();
_sync?.Stop();
AddStatusPatch.State = null;
UseStaminaPatch.State = null;
}
}
}