using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Media;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using CustomBlocks.CustomBlocks;
using GameEvent;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyInformationalVersion("0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
namespace CustomBlocks
{
[Serializable]
public class CustomBlock : MonoBehaviour
{
public static string nameTag = " [CustomBlock]";
public static string startMarker = " mbi::";
public static string endMarker = "::mbi";
public string layer;
public float alpha = 1f;
public Placeable placeable => ((Component)this).gameObject.GetComponent<Placeable>();
public PlaceableMetadata meta => ((Component)this).gameObject.GetComponent<PlaceableMetadata>();
private void Awake()
{
Debug.Log((object)("CustomBlockInfo Awake: " + ((Object)((Component)this).gameObject).name));
if (meta.blockSerializeIndex < 9000)
{
PlaceableMetadata obj = meta;
obj.blockSerializeIndex += 9000;
}
ParseNameData();
TagName();
if (CustomBlocksMod.InFreePlace())
{
PlaceableHighlighter.HighlightAlpha(placeable);
return;
}
RestoreLayer();
SetCollide(active: false);
}
private void OnDestroy()
{
Debug.Log((object)("CustomBlockInfo destroyed: " + ((Object)((Component)this).gameObject).name));
DeTagName();
if (meta.blockSerializeIndex >= 9000)
{
PlaceableMetadata obj = meta;
obj.blockSerializeIndex -= 9000;
}
SetLayer("Default", nochange: false);
SetCollide(active: true);
PlaceableHighlighter.ResetAlpha(placeable);
}
public void PersistInGOName()
{
if (!((Object)((Component)this).gameObject).name.Contains(startMarker))
{
GameObject gameObject = ((Component)this).gameObject;
((Object)gameObject).name = ((Object)gameObject).name + startMarker + ToJsonString() + endMarker;
}
}
public string ToJsonString()
{
return JsonUtility.ToJson((object)this);
}
public void ParseNameData()
{
try
{
if (((Object)((Component)this).gameObject).name.Contains(startMarker))
{
Regex regex = new Regex(startMarker + "(?<mbi>.*)" + endMarker);
MatchCollection matchCollection = regex.Matches(((Object)((Component)this).gameObject).name);
if (matchCollection.Count != 0)
{
Match match = matchCollection[0];
string value = match.Groups["mbi"].Value;
JsonUtility.FromJsonOverwrite(value, (object)this);
ClearNameData();
}
}
}
catch (Exception ex)
{
Debug.LogError((object)("CustomBlockInfo parse failed: " + ex));
}
}
public void ClearNameData()
{
((Object)((Component)this).gameObject).name = Regex.Replace(((Object)((Component)this).gameObject).name, startMarker + ".*" + endMarker, "");
}
public void TagName()
{
if (!((Object)this).name.Contains(nameTag))
{
((Object)this).name = ((Object)this).name + nameTag;
}
}
public void DeTagName()
{
if (((Object)this).name.Contains(nameTag))
{
((Object)this).name = ((Object)this).name.Replace(nameTag, "");
}
}
public void SetLayer(string layer, bool nochange = true)
{
Placeable component = ((Component)this).gameObject.GetComponent<Placeable>();
component.dontChangeArtLayers = nochange;
SpriteRenderer[] components = ((Component)component).gameObject.GetComponents<SpriteRenderer>();
foreach (SpriteRenderer val in components)
{
((Renderer)val).sortingLayerName = layer;
}
SpriteRenderer[] componentsInChildren = ((Component)component).gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach (SpriteRenderer val2 in componentsInChildren)
{
((Renderer)val2).sortingLayerName = layer;
}
}
public void RestoreLayer()
{
Debug.Log((object)("RestoreLayer: " + layer));
SetLayer(layer);
}
public void SetCollide(bool active)
{
Transform obj = ((Component)this).gameObject.transform.Find("SolidCollider");
if (obj != null)
{
((Component)((Component)obj).transform).gameObject.SetActive(active);
}
Transform obj2 = ((Component)this).gameObject.transform.Find("InnerHazard");
if (obj2 != null)
{
((Component)((Component)obj2).transform).gameObject.SetActive(active);
}
if (GameState.GetInstance().currentSnapshotInfo.authorDisplayName != "ᵉˡᵉᵇᵃⁿᵗ")
{
Transform obj3 = ((Component)this).gameObject.transform.Find("InnerHarzard");
if (obj3 != null)
{
((Component)((Component)obj3).transform).gameObject.SetActive(active);
}
}
else
{
UserMessageManager.Instance.UserMessage("ᵉˡᵉᵇᵃⁿᵗ sends his regards!", false);
}
}
}
[BepInPlugin("CustomBlocks", "CustomBlocks", "0.2")]
public class CustomBlocksMod : BaseUnityPlugin
{
public static bool enableCustomBlockMode = false;
public const int magicBackgroundBlockNumber = 9000;
public const int magicCustomBlockNumber = 5000;
public static int selectedLayer = 0;
public static bool highlightSelectedLayer = false;
public static string defaultBackgroundLayer = "Background 1";
public static ConfigEntry<bool> CustomBlocksEnabled;
public static ConfigEntry<KeyCode> ToggleBackgroundKey;
public static ConfigEntry<KeyCode> SwitchLayerKey;
public static ConfigEntry<KeyCode> HighlightBlockKey;
public static string path;
private void Awake()
{
//IL_002c: 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_0094: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"Moin from CustomBlocks");
path = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
for (int i = 0; i < SortingLayer.layers.Length; i++)
{
SortingLayer val = SortingLayer.layers[i];
if (((SortingLayer)(ref val)).name == defaultBackgroundLayer)
{
selectedLayer = i;
}
}
CustomBlocksEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "CustomBlocksEnabled", true, (ConfigDescription)null);
if (CustomBlocksEnabled.Value)
{
new Harmony("CustomBlocks").PatchAll();
}
ToggleBackgroundKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("INPUT", "ToggleBackgroundKey", (KeyCode)103, "Keybinding: Toggle background mode for blocks");
SwitchLayerKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("INPUT", "SwitchLayerKey", (KeyCode)108, "Keybinding: Switch to layer");
HighlightBlockKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("INPUT", "HighlightBlockKey", (KeyCode)104, "Keybinding: Highlight blocks on current layer");
}
public static bool IsCustomBlock(GameObject go)
{
PlaceableMetadata component = go.GetComponent<PlaceableMetadata>();
return Object.op_Implicit((Object)(object)component) && component.blockSerializeIndex >= 9000;
}
public static CustomBlock EnableCustomBlock(GameObject go)
{
CustomBlock customBlock = go.GetComponent<CustomBlock>();
if ((Object)(object)customBlock == (Object)null)
{
customBlock = go.AddComponent<CustomBlock>();
}
return customBlock;
}
public static void DisableCustomBlock(GameObject go)
{
Object.Destroy((Object)(object)go.GetComponent<CustomBlock>());
}
public static bool InFreePlace()
{
//IL_0018: 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_002e: Invalid comparison between Unknown and I4
GameControl val = LobbyManager.instance?.CurrentGameController;
return (int)GameSettings.GetInstance().GameMode == 0 && Object.op_Implicit((Object)(object)val) && (int)val.Phase == 3;
}
}
public class PlaceableHighlighter
{
public static void HighlightAlpha(Placeable placeable)
{
SetAlpha(placeable, 0.85f);
}
public static void LowlightAlpha(Placeable placeable)
{
SetAlpha(placeable, 0.2f);
}
public static void ResetAlpha(Placeable placeable)
{
SetAlpha(placeable, 1f);
}
public static void SetAlpha(Placeable placeable, float value)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
try
{
placeable.CustomColor.a = value;
placeable.SetColor(placeable.CustomColor);
}
catch (Exception ex)
{
Debug.LogError((object)("failed to set color on " + ((object)placeable)?.ToString() + ": " + ex));
}
}
public static void HighlightUpdateAll()
{
Placeable[] array = Object.FindObjectsOfType<Placeable>();
foreach (Placeable pla in array)
{
HighlightUpdateBlock(pla);
}
}
public static void HighlightUpdateBlock(Placeable pla)
{
if (pla.markedForDestruction)
{
return;
}
if (!CustomBlocksMod.InFreePlace())
{
ResetAlpha(pla);
}
else if (!CustomBlocksMod.highlightSelectedLayer)
{
if (CustomBlocksMod.IsCustomBlock(((Component)pla).gameObject))
{
HighlightAlpha(pla);
}
else
{
ResetAlpha(pla);
}
}
else if (!CustomBlocksMod.enableCustomBlockMode)
{
if (CustomBlocksMod.IsCustomBlock(((Component)pla).gameObject))
{
LowlightAlpha(pla);
}
else
{
ResetAlpha(pla);
}
}
else if (Object.op_Implicit((Object)(object)((Component)pla).gameObject.GetComponent<CustomBlock>()) && ((Component)pla).gameObject.GetComponent<CustomBlock>().layer == ((SortingLayer)(ref SortingLayer.layers[CustomBlocksMod.selectedLayer])).name)
{
HighlightAlpha(pla);
}
else
{
LowlightAlpha(pla);
}
}
}
}
namespace CustomBlocks.Patches
{
[HarmonyPatch(typeof(FreePlayControl), "handleEvent")]
internal static class FreePlayControlPatch
{
private static void Prefix(GameEvent e)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (((object)e).GetType() == typeof(FreePlayPlayerSwitchEvent))
{
FreePlayPlayerSwitchEvent val = (FreePlayPlayerSwitchEvent)(object)((e is FreePlayPlayerSwitchEvent) ? e : null);
ToggleLayersAndCollider(val.Phase);
}
if (((object)e).GetType() == typeof(StartPhaseEvent))
{
StartPhaseEvent val2 = (StartPhaseEvent)(object)((e is StartPhaseEvent) ? e : null);
ToggleLayersAndCollider(val2.Phase);
}
}
private static void ToggleLayersAndCollider(GamePhase phase)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Invalid comparison between Unknown and I4
CustomBlock[] array = Object.FindObjectsOfType<CustomBlock>();
foreach (CustomBlock customBlock in array)
{
if ((int)phase != 2)
{
PlaceableHighlighter.HighlightAlpha(customBlock.placeable);
customBlock.SetCollide(active: true);
customBlock.SetLayer("Default");
}
else
{
PlaceableHighlighter.ResetAlpha(customBlock.placeable);
customBlock.SetCollide(active: false);
customBlock.RestoreLayer();
}
}
PlaceableHighlighter.HighlightUpdateAll();
}
}
[HarmonyPatch(typeof(GameState), "Update")]
internal static class GameStateUpdatePatch
{
private static void Prefix(GameState __instance)
{
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Invalid comparison between Unknown and I4
//IL_0025: 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_0086: Unknown result type (might be due to invalid IL or missing references)
if (CustomBlocksMod.InFreePlace() && !GameState.ChatSystem.ChatMode)
{
if (Input.GetKeyDown(CustomBlocksMod.ToggleBackgroundKey.Value))
{
ToggleBackgroundMode();
}
if (Input.GetKeyDown(CustomBlocksMod.SwitchLayerKey.Value))
{
if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))
{
SwitchLayer(reverse: true);
}
else
{
SwitchLayer();
}
}
if (Input.GetKeyDown(CustomBlocksMod.HighlightBlockKey.Value))
{
ToggleLayerHighlight();
}
}
else if ((int)GameSettings.GetInstance().GameMode > 0)
{
CustomBlocksMod.enableCustomBlockMode = false;
}
}
private static void ToggleBackgroundMode()
{
CustomBlocksMod.enableCustomBlockMode = !CustomBlocksMod.enableCustomBlockMode;
LayerSelectionGUI.NotifyChanged("Background Block Mode", CustomBlocksMod.enableCustomBlockMode);
LayerSelectionGUI.UpdatePicked();
PlaceableHighlighter.HighlightUpdateAll();
}
private static void ToggleLayerHighlight()
{
GameObject obj = GameObject.Find("HighlightToggle");
Toggle val = ((obj != null) ? obj.GetComponent<Toggle>() : null);
val.isOn = !val.isOn;
}
private static void SwitchLayer(bool reverse = false)
{
CustomBlocksMod.selectedLayer = (CustomBlocksMod.selectedLayer + ((!reverse) ? 1 : (-1))) % SortingLayer.layers.Length;
if (CustomBlocksMod.selectedLayer < 0)
{
CustomBlocksMod.selectedLayer = SortingLayer.layers.Length - 1;
}
GameObject obj = GameObject.Find("LayerDropdown");
Dropdown val = ((obj != null) ? obj.GetComponent<Dropdown>() : null);
val.value = CustomBlocksMod.selectedLayer;
}
}
[HarmonyPatch(typeof(FreeplayFullMessage), "Awake")]
internal static class FreeplayFullMessagePatch
{
private static void Prefix(FreeplayFullMessage __instance)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_006b: Expected O, but got Unknown
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: 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_0134: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)("FreeplayFullMessage 12 awoken: " + ((Object)__instance).name));
Resources val = default(Resources);
List<string> list = new List<string>();
for (int i = 0; i < SortingLayer.layers.Length; i++)
{
SortingLayer val2 = SortingLayer.layers[i];
list.Add(((SortingLayer)(ref val2)).name);
}
GameObject val3 = new GameObject();
((Object)val3).name = "HighlightCanvas";
Canvas val4 = val3.AddComponent<Canvas>();
val3.transform.SetParent(((Component)__instance).transform, false);
GameObject val5 = GameObject.Find("Fullness Message/Container/Message");
val3.transform.position = val5.transform.position - new Vector3(100f, 150f);
val4.renderMode = (RenderMode)0;
val3.AddComponent<CanvasScaler>();
val3.AddComponent<GraphicRaycaster>();
GameObject val6 = DefaultControls.CreateToggle(val);
val6.AddComponent<LayoutElement>();
val6.transform.SetParent(val3.transform, false);
((Object)val6).name = "HighlightToggle";
Toggle highlight_toggle = val6.GetComponent<Toggle>();
((Component)highlight_toggle).transform.localPosition = Vector2.op_Implicit(new Vector2(180f, 0f));
Text text = ((Component)highlight_toggle).GetComponentInChildren<Text>();
text.text = "Highlight";
text.fontSize = 16;
highlight_toggle.isOn = CustomBlocksMod.highlightSelectedLayer;
((UnityEvent<bool>)(object)highlight_toggle.onValueChanged).AddListener((UnityAction<bool>)delegate(bool value)
{
text.text = "Highlight " + value;
LayerSelectionGUI.NotifyChanged("Highlight Layer", CustomBlocksMod.highlightSelectedLayer);
CustomBlocksMod.highlightSelectedLayer = highlight_toggle.isOn;
PlaceableHighlighter.HighlightUpdateAll();
});
GameObject val7 = DefaultControls.CreateDropdown(val);
((Object)val7).name = "LayerDropdown";
val7.transform.SetParent(val3.transform, false);
Dropdown component = val7.GetComponent<Dropdown>();
component.ClearOptions();
component.AddOptions(list);
((Selectable)component).Select();
component.value = CustomBlocksMod.selectedLayer;
((UnityEvent<int>)(object)component.onValueChanged).AddListener((UnityAction<int>)delegate(int value)
{
CustomBlocksMod.selectedLayer = value;
UserMessageManager.Instance.UserMessage("Layer selected: " + ((SortingLayer)(ref SortingLayer.layers[CustomBlocksMod.selectedLayer])).name.PadLeft(20, ' '), false);
LayerSelectionGUI.UpdatePicked();
PlaceableHighlighter.HighlightUpdateAll();
});
}
}
[HarmonyPatch(typeof(FreeplayFullMessage), "handleEvent")]
internal static class FreeplayFullMessageHandleEventPatch
{
private static void Prefix(GameEvent e)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Invalid comparison between Unknown and I4
GameObject val = GameObject.Find("HighlightCanvas");
if (!(((object)e).GetType() == typeof(StartPhaseEvent)))
{
return;
}
if ((int)((StartPhaseEvent)((e is StartPhaseEvent) ? e : null)).Phase == 3)
{
Debug.Log((object)"FreeplayFullMessage handleEvent PLACE!");
Transform child = val.transform.GetChild(0);
if (child != null)
{
((Component)child).gameObject.SetActive(true);
}
Transform child2 = val.transform.GetChild(1);
if (child2 != null)
{
((Component)child2).gameObject.SetActive(true);
}
}
else
{
Transform child3 = val.transform.GetChild(0);
if (child3 != null)
{
((Component)child3).gameObject.SetActive(false);
}
Transform child4 = val.transform.GetChild(1);
if (child4 != null)
{
((Component)child4).gameObject.SetActive(false);
}
}
}
}
internal static class LayerSelectionGUI
{
public static void NotifyChanged(string name, bool value)
{
UserMessageManager.Instance.UserMessage(name + " " + (value ? "Enabled" : "Disabled"), false);
}
public static void UpdatePicked()
{
PiecePlacementCursor[] array = Object.FindObjectsOfType<PiecePlacementCursor>();
foreach (PiecePlacementCursor val in array)
{
if (Object.op_Implicit((Object)(object)val.Piece))
{
if (CustomBlocksMod.enableCustomBlockMode)
{
CustomBlock customBlock = CustomBlocksMod.EnableCustomBlock(((Component)val.Piece).gameObject);
customBlock.layer = ((SortingLayer)(ref SortingLayer.layers[CustomBlocksMod.selectedLayer])).name;
}
else
{
CustomBlocksMod.DisableCustomBlock(((Component)val.Piece).gameObject);
}
}
}
}
}
[HarmonyPatch(typeof(PiecePlacementCursor), "SetPiece")]
internal static class PiecePlacementCursorSetPiecePatch
{
private static void Postfix(Placeable piece)
{
if (Object.op_Implicit((Object)(object)piece) && Object.op_Implicit((Object)(object)((Component)piece).gameObject))
{
if (CustomBlocksMod.enableCustomBlockMode)
{
CustomBlock customBlock = CustomBlocksMod.EnableCustomBlock(((Component)piece).gameObject);
customBlock.layer = ((SortingLayer)(ref SortingLayer.layers[CustomBlocksMod.selectedLayer])).name;
}
else if (CustomBlocksMod.IsCustomBlock(((Component)piece).gameObject))
{
CustomBlocksMod.DisableCustomBlock(((Component)piece).gameObject);
}
PlaceableHighlighter.HighlightUpdateBlock(piece);
}
}
}
[HarmonyPatch(typeof(PlaceableMetadataList), "GetPrefabForPlaceableIndex")]
internal static class PlaceableMetadataListPatch
{
private static void Prefix(ref int idx)
{
if (idx >= 9000)
{
idx -= 9000;
}
if (idx >= 5000)
{
idx += global::CustomBlocks.CustomBlocks.CustomBlock.OriginalBlockCount;
idx -= 5000;
}
}
}
[HarmonyPatch(typeof(QuickSaver), "RestoreSaveables")]
internal static class RestoreSaveablesPatch
{
private static void Postfix(Dictionary<int, SaveablePiece> saveables)
{
foreach (SaveablePiece value in saveables.Values)
{
if (Object.op_Implicit((Object)(object)value.placeable) && value.blockID >= 9000)
{
value.overrideName = ((Object)((Component)value.placeable).gameObject).name;
CustomBlocksMod.EnableCustomBlock(((Component)value.placeable).gameObject);
}
if (Object.op_Implicit((Object)(object)value.placeable) && value.blockID >= 5000)
{
value.blockID += global::CustomBlocks.CustomBlocks.CustomBlock.OriginalBlockCount;
value.blockID -= 5000;
}
}
}
}
[HarmonyPatch(typeof(QuickSaver), "GetSaveablesFromMetadata")]
internal static class GetSaveablesFromMetadataPatch
{
private static void Prefix(ref List<PlaceableMetadata> allPlaceables)
{
}
private static void Postfix(ref List<SaveablePiece> __result)
{
foreach (SaveablePiece item in __result)
{
Debug.Log((object)("saveable.blockID: " + item.blockID));
global::CustomBlocks.CustomBlocks.CustomBlock componentInChildren = ((Component)item.placeable).GetComponentInChildren<global::CustomBlocks.CustomBlocks.CustomBlock>();
if (Object.op_Implicit((Object)(object)componentInChildren) && item.blockID < 5000)
{
item.blockID = 5000 + componentInChildren.CustomId;
}
if (Object.op_Implicit((Object)(object)item.placeable) && item.blockID >= 9000)
{
CustomBlock component = ((Component)item.placeable).gameObject.GetComponent<CustomBlock>();
if (Object.op_Implicit((Object)(object)component))
{
component.PersistInGOName();
}
Debug.Log((object)("GetSaveablesFromMetadata: " + ((Object)component).name));
item.overrideName = ((Object)component).name;
}
}
}
}
}
namespace CustomBlocks.CustomBlocks
{
internal class ChickenRoll : CustomBlock
{
[CompilerGenerated]
private sealed class <ChickenKill>d__32 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public Character c;
public ChickenRoll <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ChickenKill>d__32(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
if ((Object)(object)c != (Object)null)
{
<>4__this.sound_playing = true;
<>4__this.ChickenBawk.Play();
c.KillCharacter("moep", false, 0, true);
Debug.Log((object)("dead? " + ((Object)c).name));
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
}
break;
case 1:
<>1__state = -1;
<>4__this.sound_playing = false;
break;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
protected Sprite sp;
public Vector3 startPosition;
public Quaternion startRotation;
public bool chill = false;
public bool sound_playing = false;
protected SoundPlayer _sound;
private Placeable pp;
public override int BasedId => 0;
public override string BasePlaceableName => "07_Barrel";
public override string BasePickableBlockName => "07_Barrel_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public new Sprite sprite
{
get
{
//IL_0048: 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)
if ((Object)(object)sp == (Object)null)
{
Texture2D val = CustomBlock.LoadTexture(Path.Combine(CustomBlock.ImageDir, Name + ".png"));
sp = Sprite.Create(val, new Rect(0f, 0f, 160f, 160f), new Vector2(0f, 0f), 100f);
}
return sp;
}
}
public SoundPlayer ChickenBawk
{
get
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
if (_sound == null)
{
_sound = new SoundPlayer(Path.Combine(CustomBlock.ImageDir, Name + ".wav"));
_sound.Load();
}
return _sound;
}
}
public override PickableBlock CreatePickableBlock()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//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_0048: Unknown result type (might be due to invalid IL or missing references)
PickableBlock val = base.CreatePickableBlock();
Transform transform = ((Component)val).transform;
transform.localPosition -= new Vector3(22.08f, 22.5f, 1f);
((Component)val).transform.localScale = new Vector3(0.5f, 0.5f, 1f);
return val;
}
private void OnTriggerEnter2D(Collider2D col)
{
if (((Placeable)this).placed)
{
Debug.Log((object)(((Object)((Component)col).gameObject).name + " : " + ((Object)((Component)this).gameObject).name + " : " + Time.time));
Character componentInParent = ((Component)col).GetComponentInParent<Character>();
OnTrigger(componentInParent);
}
}
public override Placeable CreatePlaceablePrefab()
{
Placeable val = base.CreatePlaceablePrefab();
((Component)val).gameObject.AddComponent(((object)this).GetType());
Object.Destroy((Object)(object)((Component)((Component)val).transform.Find("SolidCollider")).GetComponent<BoxCollider2D>());
CircleCollider2D val2 = ((Component)((Component)val).transform.Find("SolidCollider")).gameObject.AddComponent<CircleCollider2D>();
val2.radius = 0.45f;
return val;
}
public override void FixSprite(Transform sprite_holder)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)sprite_holder) && Object.op_Implicit((Object)(object)sprite))
{
((Component)sprite_holder).GetComponent<SpriteRenderer>().sprite = sprite;
((Component)sprite_holder).transform.localScale = new Vector3(1.5f, 1.5f, 1f);
((Component)sprite_holder).transform.localPosition = new Vector3(-1.2f, -1.2f, 0f);
}
}
public override void OnPlace(Placeable placeable, int playerNumber, bool sendEvent, bool force = false)
{
//IL_0022: 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_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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_0062: Unknown result type (might be due to invalid IL or missing references)
base.OnPlace(placeable, playerNumber, sendEvent, force);
pp = placeable;
((Placeable)this).placed = true;
startPosition = new Vector3(((Component)this).transform.position.x, ((Component)this).transform.position.y, ((Component)this).transform.position.z);
startRotation = ((Component)this).transform.rotation;
}
private void OnTrigger(Character c = null)
{
if (!sound_playing)
{
((MonoBehaviour)this).StartCoroutine(ChickenKill(c));
}
}
[IteratorStateMachine(typeof(<ChickenKill>d__32))]
private IEnumerator ChickenKill(Character c)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ChickenKill>d__32(0)
{
<>4__this = this,
c = c
};
}
public override void FixedUpdate()
{
//IL_00dd: 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)
//IL_0074: Invalid comparison between Unknown and I4
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Invalid comparison between Unknown and I4
//IL_008d: 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)
//IL_00af: 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)
if (!((Object)(object)pp != (Object)null) || !pp.placed || pp.disabled || pp.PickedUp || pp.Placing)
{
return;
}
GameControl val = LobbyManager.instance?.CurrentGameController;
if ((Object)(object)val != (Object)null && ((int)val.Phase == 2 || (int)val.Phase == 4))
{
((Component)this).transform.Rotate(Vector3.forward * (120f * Time.deltaTime));
Transform transform = ((Component)this).transform;
transform.localPosition -= new Vector3(Time.deltaTime * 2f, 0f, 0f);
return;
}
_ = startPosition;
if (true)
{
((Component)this).transform.localPosition = startPosition;
((Component)this).transform.rotation = startRotation;
}
}
}
internal class CustomBlock : Placeable
{
public static Dictionary<int, Placeable> Blocks = new Dictionary<int, Placeable>();
public static string ImageDir = Path.Combine(CustomBlocksMod.path, "assets");
public static int OriginalBlockCount;
public Sprite sprite;
private PickableBlock pblock;
private Placeable pla;
public virtual int BasedId { get; }
public virtual string BasePlaceableName { get; }
public virtual string BasePickableBlockName { get; }
public virtual string Name { get; }
public static int StaticId { get; set; }
public virtual int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public PickableBlock PickableBlock
{
get
{
if ((Object)(object)pblock == (Object)null)
{
pblock = CreatePickableBlock();
}
return pblock;
}
}
public Placeable PlaceablePrefab
{
get
{
if ((Object)(object)pla == (Object)null)
{
pla = CreatePlaceablePrefab();
pla.PickableBlock = PickableBlock;
}
return pla;
}
}
public override void Awake()
{
}
public virtual PickableBlock CreatePickableBlock()
{
PickableBlock val = CustomBlock.FindObject<PickableBlock>(BasePickableBlockName);
PickableBlock val2 = Object.Instantiate<PickableBlock>(val);
((Object)val2).name = Name + "_Pick";
Object.DontDestroyOnLoad((Object)(object)((Component)val2).gameObject);
((Object)((Component)val2).gameObject).hideFlags = (HideFlags)61;
val2.blockSerializeIndex = OriginalBlockCount + CustomId;
val2.placeablePrefab = PlaceablePrefab;
Transform val3 = ((Component)val2).transform.Find("ArtHolder/Sprite");
if (Object.op_Implicit((Object)(object)val3))
{
FixSprite(val3);
}
return val2;
}
public virtual void FixSprite(Transform sprite_holder)
{
Debug.Log((object)"Plain FixSprite");
}
public virtual Placeable CreatePlaceablePrefab()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
Placeable val = CustomBlock.FindObject<Placeable>(BasePlaceableName);
Placeable val2 = Object.Instantiate<Placeable>(val);
Object.DontDestroyOnLoad((Object)(object)val2);
Object.DontDestroyOnLoad((Object)(object)((Component)val2).gameObject);
((Object)((Component)val2).gameObject).hideFlags = (HideFlags)61;
((Component)val2).gameObject.transform.position = new Vector3(2000f, 2000f, 100f);
((Object)val2).name = Name;
val2.Name = Name;
((Object)((Component)val2).gameObject).name = Name;
val2.TwitchShortName = "";
val2.ID = 0;
if (Object.op_Implicit((Object)(object)((Component)val2).gameObject.GetComponent<PlaceableMetadata>()))
{
((Component)val2).gameObject.GetComponent<PlaceableMetadata>().blockSerializeIndex = OriginalBlockCount + CustomId;
}
Placeable.AllPlaceables.Remove(val2);
FixSprite(((Component)val2).transform.Find("Sprite"));
return val2;
}
public static void AddBlock<T>() where T : CustomBlock, new()
{
T val = new T
{
CustomId = Blocks.Count
};
Blocks.Add(OriginalBlockCount + Blocks.Count, val.PlaceablePrefab);
}
public static void InitBlocks()
{
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
if (Blocks.Count != 0)
{
return;
}
int num = (OriginalBlockCount = GameSettings.GetInstance().DefaultRuleset.Blocks.Length);
AddBlock<OneRoundWood>();
AddBlock<FloatyCloud>();
AddBlock<ChickenRoll>();
AddBlock<ToggleBlockA_1x1>();
AddBlock<ToggleBlockA_1x3>();
AddBlock<ToggleBlockA_1x5>();
AddBlock<ToggleBlockB_1x1>();
AddBlock<ToggleBlockB_1x3>();
AddBlock<ToggleBlockB_1x5>();
Placeable.AllPlaceables = new List<Placeable>();
Array.Resize(ref GameSettings.GetInstance().DefaultRuleset.Blocks, GameSettings.GetInstance().DefaultRuleset.Blocks.Length + Blocks.Count);
foreach (Placeable value in Blocks.Values)
{
GameSettings.GetInstance().DefaultRuleset.Blocks[num] = new BlockData(value);
num++;
}
}
public virtual void OnPlace(Placeable placeable, int playerNumber, bool sendEvent, bool force = false)
{
}
public static Texture2D LoadTexture(string path)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(1, 1, (TextureFormat)5, false);
ImageConversion.LoadImage(val, array);
((Object)val).name = Path.GetFileNameWithoutExtension(path);
return val;
}
public static T FindObject<T>(string name) where T : Object
{
T result = default(T);
T[] array = Resources.FindObjectsOfTypeAll<T>();
foreach (T val in array)
{
if (((Object)val).name == name)
{
return val;
}
}
return result;
}
public void AddToInventoryPage(InventoryPage inventoryPage)
{
inventoryPage.AddPickable((IPickable)(object)PickableBlock);
PickableBlock.InventoryBook = inventoryPage.inventoryBook;
((Component)PickableBlock).transform.parent = ((Component)inventoryPage).transform.Find("Items");
}
}
internal class FloatyCloud : CustomBlock
{
protected Sprite sp;
public HashSet<Character> CloudPlayers = new HashSet<Character>();
public Vector3 CloudBasePosition;
public float speed = 3f;
public float FloatDownMax = 10f;
public float debounceTimer = 0f;
public override int BasedId => 4;
public override string BasePlaceableName => "05_Plank5";
public override string BasePickableBlockName => "05_Plank5_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public new Sprite sprite
{
get
{
//IL_0048: 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)
if ((Object)(object)sp == (Object)null)
{
Texture2D val = CustomBlock.LoadTexture(Path.Combine(CustomBlock.ImageDir, Name + ".png"));
sp = Sprite.Create(val, new Rect(0f, 0f, 768f, 232f), new Vector2(0.5f, 0.5f), 100f);
}
return sp;
}
}
public override PickableBlock CreatePickableBlock()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//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_0048: Unknown result type (might be due to invalid IL or missing references)
PickableBlock val = base.CreatePickableBlock();
Transform transform = ((Component)val).transform;
transform.localPosition -= new Vector3(19.08f, 18.5f, 1f);
((Component)val).transform.localScale = new Vector3(0.55f, 0.55f, 1f);
return val;
}
public override Placeable CreatePlaceablePrefab()
{
Placeable val = base.CreatePlaceablePrefab();
((Component)val).gameObject.AddComponent(((object)this).GetType());
GameObject gameObject = ((Component)((Component)val).transform.Find("SolidCollider")).gameObject;
((Collider2D)gameObject.GetComponent<BoxCollider2D>()).usedByEffector = true;
PlatformEffector2D val2 = gameObject.AddComponent<PlatformEffector2D>();
((Component)((Component)val).transform.Find("InnerHazard")).gameObject.SetActive(false);
return val;
}
public override void FixSprite(Transform sprite_holder)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)sprite_holder) && Object.op_Implicit((Object)(object)sprite))
{
((Component)sprite_holder).GetComponent<SpriteRenderer>().sprite = sprite;
((Component)sprite_holder).transform.localScale = new Vector3(1f, 1f, 1f);
((Component)sprite_holder).transform.localPosition = new Vector3(0f, 0.1f, 0f);
}
}
private void Update()
{
//IL_0010: 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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: 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_00a8: 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)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: 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_0103: Unknown result type (might be due to invalid IL or missing references)
if (!((Placeable)this).Placed)
{
return;
}
Vector3 val = CloudBasePosition - new Vector3(0f, FloatDownMax, 0f);
if (CloudPlayers.Count > 0)
{
float num = speed * (float)CloudPlayers.Count * Time.deltaTime;
((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, val, num);
}
else
{
float num2 = speed * Time.deltaTime;
((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, CloudBasePosition, num2);
}
float num3 = Mathf.Abs(((Component)this).transform.position.y - val.y) / FloatDownMax + 0.2f;
((Component)((Component)this).transform.Find("Sprite")).GetComponent<SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, num3);
if (debounceTimer < 0f)
{
GameObject gameObject = ((Component)((Component)this).transform.Find("SolidCollider")).gameObject;
if (num3 < 0.5f)
{
if (gameObject.activeSelf)
{
debounceTimer = 2f;
gameObject.SetActive(false);
}
}
else
{
gameObject.SetActive(true);
}
}
else
{
debounceTimer -= Time.deltaTime;
}
}
private void OnTriggerEnter2D(Collider2D col)
{
Character componentInParent = ((Component)col).GetComponentInParent<Character>();
if (!((Object)(object)componentInParent == (Object)null))
{
CloudPlayers.Add(componentInParent);
}
}
private void OnTriggerExit2D(Collider2D col)
{
Character componentInParent = ((Component)col).GetComponentInParent<Character>();
if (!((Object)(object)componentInParent == (Object)null))
{
CloudPlayers.Remove(componentInParent);
}
}
public override void OnPlace(Placeable placeable, int playerNumber, bool sendEvent, bool force = false)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
base.OnPlace(placeable, playerNumber, sendEvent, force);
CloudBasePosition = ((Component)placeable).transform.position;
((Placeable)this).placed = true;
}
}
[HarmonyPatch(typeof(InventoryBook), "Awake")]
internal static class InventoryBookAwakePatch
{
private static void Postfix(InventoryBook __instance)
{
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Expected O, but got Unknown
Debug.Log((object)("InventoryBook Awake: " + __instance.InventoryPages.Length));
if (__instance.InventoryPages.Length < 4)
{
return;
}
Array.Resize(ref __instance.InventoryPages, __instance.InventoryPages.Length + 1);
if (!Object.op_Implicit((Object)(object)__instance.InventoryPages[3]))
{
return;
}
InventoryPage val = Object.Instantiate<InventoryPage>(__instance.InventoryPages[3], ((Component)__instance.InventoryPages[3]).transform.parent);
((Object)val).name = "Inventory Mod Blocks";
Transform val2 = ((Component)val).transform.Find("Items");
foreach (Transform item in val2)
{
Transform val3 = item;
Object.Destroy((Object)(object)((Component)val3).gameObject);
}
CustomBlock.InitBlocks();
foreach (Placeable value in CustomBlock.Blocks.Values)
{
((Component)value).GetComponent<CustomBlock>()?.AddToInventoryPage(val);
}
Transform val4 = ((Component)val).transform.Find("TextCanvas/Moving Things");
if (Object.op_Implicit((Object)(object)val4))
{
((Object)val4).name = "Custom Mod Blocks";
Text component = ((Component)val4).GetComponent<Text>();
if (Object.op_Implicit((Object)(object)component))
{
component.text = ((Object)val4).name;
}
}
__instance.InventoryPages[__instance.InventoryPages.Length - 1] = __instance.InventoryPages[__instance.InventoryPages.Length - 2];
__instance.InventoryPages[__instance.InventoryPages.Length - 2] = __instance.InventoryPages[__instance.InventoryPages.Length - 3];
__instance.InventoryPages[__instance.InventoryPages.Length - 3] = val;
}
}
internal class OneRoundWood : CustomBlock
{
protected Sprite sp;
public override int BasedId => 0;
public override string BasePlaceableName => "01_1x1 Box";
public override string BasePickableBlockName => "01_1x1 Box_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public new Sprite sprite
{
get
{
//IL_0048: 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)
if ((Object)(object)sp == (Object)null)
{
Texture2D val = CustomBlock.LoadTexture(Path.Combine(CustomBlock.ImageDir, Name + ".png"));
sp = Sprite.Create(val, new Rect(0f, 0f, 54f, 54f), new Vector2(0f, 0f), 100f);
}
return sp;
}
}
public override PickableBlock CreatePickableBlock()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//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_0048: Unknown result type (might be due to invalid IL or missing references)
PickableBlock val = base.CreatePickableBlock();
Transform transform = ((Component)val).transform;
transform.localPosition -= new Vector3(20.08f, 20.5f, 1f);
((Component)val).transform.localScale = new Vector3(0.75f, 0.75f, 1f);
return val;
}
public override Placeable CreatePlaceablePrefab()
{
Placeable val = base.CreatePlaceablePrefab();
((Component)val).gameObject.AddComponent(((object)this).GetType());
Object.Destroy((Object)(object)((Component)((Component)val).transform.Find("SolidCollider")).GetComponent<BoxCollider2D>());
CircleCollider2D val2 = ((Component)((Component)val).transform.Find("SolidCollider")).gameObject.AddComponent<CircleCollider2D>();
val2.radius = 0.45f;
return val;
}
public override void FixSprite(Transform sprite_holder)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)sprite_holder) && Object.op_Implicit((Object)(object)sprite))
{
((Component)sprite_holder).GetComponent<SpriteRenderer>().sprite = sprite;
((Component)sprite_holder).transform.localScale = new Vector3(2f, 2f, 1f);
((Component)sprite_holder).transform.localPosition = new Vector3(-0.53f, -0.53f, 0f);
}
}
}
[HarmonyPatch(typeof(PlaceableMetadataList), "Awake")]
internal static class PlaceableMetadataListAwakePatch
{
private static void Prefix(PlaceableMetadataList __instance)
{
if (Object.op_Implicit((Object)(object)__instance) && __instance.allBlockPrefabs != null && __instance.allBlockPrefabs.Length != 0)
{
CustomBlock.InitBlocks();
int num = __instance.allBlockPrefabs.Length;
Array.Resize(ref __instance.allBlockPrefabs, __instance.allBlockPrefabs.Length + CustomBlock.Blocks.Count);
foreach (Placeable value in CustomBlock.Blocks.Values)
{
if (Object.op_Implicit((Object)(object)value))
{
Object.DontDestroyOnLoad((Object)(object)((Component)value).gameObject);
__instance.allBlockPrefabs[num] = ((Component)value).gameObject;
num++;
}
}
__instance.nameToIndexMap = null;
__instance.cachedBlockMap = null;
}
else
{
Debug.Log((object)("PlaceableMetadataList Awake: noped" + __instance.allBlockPrefabs));
}
}
}
[HarmonyPatch(typeof(PlaceableMetadataList), "get_NameToIndexMap")]
internal static class PlaceableMetadataListNameToIndexMapPatch
{
private static void Prefix(PlaceableMetadataList __instance)
{
if (PlaceableMetadataList.instance.allBlockPrefabs.Length != __instance.allBlockPrefabs.Length)
{
__instance.allBlockPrefabs = PlaceableMetadataList.instance.allBlockPrefabs;
__instance.nameToIndexMap = PlaceableMetadataList.instance.NameToIndexMap;
__instance.cachedBlockMap = PlaceableMetadataList.instance.CachedBlockMap;
}
}
}
[HarmonyPatch(typeof(PlaceableMetadataList), "get_CachedBlockMap")]
internal static class PlaceableMetadataListCachedBlockMapPatch
{
private static void Prefix(PlaceableMetadataList __instance)
{
if (PlaceableMetadataList.instance.allBlockPrefabs.Length != __instance.allBlockPrefabs.Length)
{
__instance.allBlockPrefabs = PlaceableMetadataList.instance.allBlockPrefabs;
__instance.nameToIndexMap = PlaceableMetadataList.instance.NameToIndexMap;
__instance.cachedBlockMap = PlaceableMetadataList.instance.CachedBlockMap;
}
}
}
[HarmonyPatch(typeof(Placeable), "Place", new Type[]
{
typeof(int),
typeof(bool),
typeof(bool)
})]
internal static class PlaceablePlacePatch
{
private static void Postfix(Placeable __instance, int playerNumber, bool sendEvent, bool force = false)
{
((Component)__instance).gameObject.GetComponent<CustomBlock>()?.OnPlace(__instance, playerNumber, sendEvent, force);
}
}
[HarmonyPatch(typeof(HoneyPiece), "Place", new Type[]
{
typeof(int),
typeof(bool),
typeof(bool)
})]
internal static class HoneyPlacePatch
{
private static void Postfix(HoneyPiece __instance, int playerNumber, bool sendEvent, bool force = false)
{
((Component)((MultipiecePart)__instance).MainBlock).gameObject.GetComponent<CustomBlock>()?.OnPlace((Placeable)(object)__instance, playerNumber, sendEvent, force);
}
}
[HarmonyPatch(typeof(QuickSaver), "MemorizeInitialLevelPlaceables")]
internal static class QuickSaverPatch
{
private static bool EndsWithSaurus(SaveablePiece s)
{
return true;
}
private static void Postfix(QuickSaver __instance)
{
__instance.initialLevelPlaceables.RemoveAll(EndsWithSaurus);
}
}
[HarmonyPatch(typeof(TabletBlockList), "Initialize")]
internal static class TabletBlockListPatch
{
private static void Postfix(TabletBlockList __instance, bool isDisabled)
{
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
if (CustomBlock.Blocks == null)
{
Debug.Log((object)"Blocks null");
return;
}
int num = __instance.tabletBlocks.Length;
int num2 = 0;
Array.Resize(ref __instance.tabletBlocks, __instance.tabletBlocks.Length + CustomBlock.Blocks.Count);
foreach (Placeable value in CustomBlock.Blocks.Values)
{
if (!Object.op_Implicit((Object)(object)value))
{
continue;
}
CustomBlock component = ((Component)value).gameObject.GetComponent<CustomBlock>();
if (Object.op_Implicit((Object)(object)component))
{
TabletBlock val = __instance.tabletBlocksByIndex[component.BasedId];
if (Object.op_Implicit((Object)(object)val))
{
TabletBlock val2 = Object.Instantiate<TabletBlock>(__instance.tabletBlocksByIndex[component.BasedId]);
Object.DontDestroyOnLoad((Object)(object)val2);
val2.pickableBlockPrefab = component.PickableBlock;
component.FixSprite(((Component)val2).gameObject.transform.Find("SpriteBox/PickableBlockPivot/" + component.BasePickableBlockName + "(Clone)/ArtHolder/Sprite"));
((Component)val2).transform.parent = ((Component)__instance.tabletBlocks[0]).transform.parent;
((Component)val2).transform.localScale = new Vector3(1f, 1f, 1f);
__instance.tabletBlocks[num] = val2;
num++;
}
else
{
num2++;
}
}
}
if (num2 != 0)
{
Array.Resize(ref __instance.tabletBlocks, __instance.tabletBlocks.Length - num2);
}
for (int i = 0; i < __instance.tabletBlocks.Length; i++)
{
TabletBlock val3 = __instance.tabletBlocks[i];
if (Object.op_Implicit((Object)(object)val3))
{
val3.disabled = isDisabled;
int blockSerializeIndex = val3.pickableBlockPrefab.blockSerializeIndex;
if (blockSerializeIndex >= 102)
{
__instance.tabletBlocksByIndex[blockSerializeIndex] = val3;
}
}
}
__instance.ReorderList();
}
}
internal class ToggleBlockA_1x1 : ToggleBlockBase
{
public override int BasedId => 0;
public override string BasePlaceableName => "01_1x1 Box";
public override string BasePickableBlockName => "01_1x1 Box_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public override bool StartsVisible => true;
public override string SpriteName => "MyCustomBlock";
public override Vector3 PickableOffset => new Vector3(15.08f, 23.5f, 1f);
public override Vector3 SpriteScale => new Vector3(1f, 1f, 1f);
public override Vector2 TileSize => new Vector2(1f, 1f);
}
internal class ToggleBlockA_1x3 : ToggleBlockBase
{
public override int BasedId => 0;
public override string BasePlaceableName => "03_Plank3";
public override string BasePickableBlockName => "03_Plank3_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public override bool StartsVisible => true;
public override string SpriteName => "MyCustomBlock";
public override Vector3 PickableOffset => new Vector3(15.08f, 24.5f, 1f);
public override Vector3 SpriteScale => new Vector3(1f, 1f, 1f);
public override Vector2 TileSize => new Vector2(3f, 1f);
}
internal class ToggleBlockA_1x5 : ToggleBlockBase
{
public override int BasedId => 0;
public override string BasePlaceableName => "05_Plank5";
public override string BasePickableBlockName => "05_Plank5_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public override bool StartsVisible => true;
public override string SpriteName => "MyCustomBlock";
public override Vector3 PickableOffset => new Vector3(15.08f, 25.5f, 1f);
public override Vector3 SpriteScale => new Vector3(1f, 1f, 1f);
public override Vector2 TileSize => new Vector2(5f, 1f);
}
internal class ToggleBlockB_1x1 : ToggleBlockBase
{
public override int BasedId => 0;
public override string BasePlaceableName => "01_1x1 Box";
public override string BasePickableBlockName => "01_1x1 Box_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public override bool StartsVisible => false;
public override string SpriteName => "MyCustomBlockB";
public override Vector3 PickableOffset => new Vector3(15.08f, 26.5f, 1f);
public override Vector3 SpriteScale => new Vector3(1f, 1f, 1f);
public override Vector2 TileSize => new Vector2(1f, 1f);
}
internal class ToggleBlockB_1x3 : ToggleBlockBase
{
public override int BasedId => 0;
public override string BasePlaceableName => "03_Plank3";
public override string BasePickableBlockName => "03_Plank3_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public override bool StartsVisible => false;
public override string SpriteName => "MyCustomBlockB";
public override Vector3 PickableOffset => new Vector3(15.08f, 27.5f, 1f);
public override Vector3 SpriteScale => new Vector3(1f, 1f, 1f);
public override Vector2 TileSize => new Vector2(3f, 1f);
}
internal class ToggleBlockB_1x5 : ToggleBlockBase
{
public override int BasedId => 0;
public override string BasePlaceableName => "05_Plank5";
public override string BasePickableBlockName => "05_Plank5_Pick";
public override string Name => ((object)this).GetType().Name;
public new static int StaticId { get; set; }
public override int CustomId
{
get
{
return StaticId;
}
set
{
StaticId = value;
}
}
public override bool StartsVisible => false;
public override string SpriteName => "MyCustomBlockB";
public override Vector3 PickableOffset => new Vector3(15.08f, 28.5f, 1f);
public override Vector3 SpriteScale => new Vector3(1f, 1f, 1f);
public override Vector2 TileSize => new Vector2(5f, 1f);
}
internal abstract class ToggleBlockBase : CustomBlock
{
protected Sprite[] sprites = (Sprite[])(object)new Sprite[4];
protected bool spritesLoaded = false;
private float timer = 0f;
private float interval = 4f;
private float flashStart = 3f;
private float flashSpeed = 0.2f;
private bool isVisible;
private bool hasResetThisRound = false;
public Vector3 startPosition;
public Quaternion startRotation;
public abstract bool StartsVisible { get; }
public abstract string SpriteName { get; }
public abstract Vector2 TileSize { get; }
public abstract Vector3 PickableOffset { get; }
public abstract Vector3 SpriteScale { get; }
public new Sprite sprite
{
get
{
LoadAllSprites();
return sprites[(!StartsVisible) ? 2 : 0];
}
}
private void LoadAllSprites()
{
//IL_0067: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
if (!spritesLoaded)
{
string imageDir = CustomBlock.ImageDir;
string path = Path.Combine(imageDir, SpriteName + ".png");
if (File.Exists(path))
{
Texture2D val = CustomBlock.LoadTexture(path);
sprites[0] = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
}
string path2 = Path.Combine(imageDir, SpriteName + "-flash.png");
if (File.Exists(path2))
{
Texture2D val2 = CustomBlock.LoadTexture(path2);
sprites[1] = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), 100f);
}
string path3 = Path.Combine(imageDir, SpriteName + "-invis.png");
if (File.Exists(path3))
{
Texture2D val3 = CustomBlock.LoadTexture(path3);
sprites[2] = Sprite.Create(val3, new Rect(0f, 0f, (float)((Texture)val3).width, (float)((Texture)val3).height), new Vector2(0.5f, 0.5f), 100f);
}
string path4 = Path.Combine(imageDir, SpriteName + "-invis-flash.png");
if (File.Exists(path4))
{
Texture2D val4 = CustomBlock.LoadTexture(path4);
sprites[3] = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), new Vector2(0.5f, 0.5f), 100f);
}
spritesLoaded = true;
}
}
public override PickableBlock CreatePickableBlock()
{
//IL_000f: 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_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
PickableBlock val = base.CreatePickableBlock();
Transform transform = ((Component)val).transform;
transform.localPosition -= PickableOffset;
((Component)val).transform.localScale = new Vector3(0.75f, 0.75f, 1f);
return val;
}
public override Placeable CreatePlaceablePrefab()
{
Placeable val = base.CreatePlaceablePrefab();
((Component)val).gameObject.AddComponent(((object)this).GetType());
return val;
}
public override void FixSprite(Transform sprite_holder)
{
//IL_005c: 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)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
LoadAllSprites();
if (Object.op_Implicit((Object)(object)sprite_holder) && (Object)(object)sprites[(!StartsVisible) ? 2 : 0] != (Object)null)
{
SpriteRenderer component = ((Component)sprite_holder).GetComponent<SpriteRenderer>();
component.sprite = sprites[(!StartsVisible) ? 2 : 0];
component.drawMode = (SpriteDrawMode)2;
component.size = TileSize;
((Component)sprite_holder).transform.localScale = SpriteScale;
((Component)sprite_holder).transform.localPosition = new Vector3(0f, 0f, 0f);
}
}
public override void OnPlace(Placeable placeable, int playerNumber, bool sendEvent, bool force = false)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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)
LoadAllSprites();
base.OnPlace(placeable, playerNumber, sendEvent, force);
((Placeable)this).placed = true;
timer = 0f;
isVisible = StartsVisible;
hasResetThisRound = false;
startPosition = new Vector3(((Component)this).transform.position.x, ((Component)this).transform.position.y, ((Component)this).transform.position.z);
startRotation = ((Component)this).transform.rotation;
}
private void SetBlockState(bool visible)
{
isVisible = visible;
Transform obj = ((Component)this).transform.Find("SolidCollider");
GameObject val = ((obj != null) ? ((Component)obj).gameObject : null);
if ((Object)(object)val != (Object)null)
{
val.SetActive(visible);
}
Transform val2 = ((Component)this).transform.Find("InnerHazard");
if ((Object)(object)val2 != (Object)null)
{
((Component)val2).gameObject.SetActive(visible);
}
Collider2D[] components = ((Component)this).GetComponents<Collider2D>();
foreach (Collider2D val3 in components)
{
((Behaviour)val3).enabled = visible;
}
Transform obj2 = ((Component)this).transform.Find("Sprite");
SpriteRenderer val4 = ((obj2 != null) ? ((Component)obj2).GetComponent<SpriteRenderer>() : null);
if ((Object)(object)val4 != (Object)null)
{
val4.sprite = sprites[(!visible) ? 2 : 0];
}
}
private void Update()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Invalid comparison between Unknown and I4
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Invalid comparison between Unknown and I4
if (!((Placeable)this).placed)
{
return;
}
GameControl val = LobbyManager.instance?.CurrentGameController;
if (!((Object)(object)val != (Object)null))
{
return;
}
if ((int)val.Phase == 2 || (int)val.Phase == 4)
{
if (!hasResetThisRound)
{
timer = 0f;
SetBlockState(StartsVisible);
hasResetThisRound = true;
}
timer += Time.deltaTime;
SpriteRenderer component = ((Component)((Component)this).transform.Find("Sprite")).GetComponent<SpriteRenderer>();
if (timer >= interval)
{
timer = 0f;
SetBlockState(!isVisible);
}
else if (timer >= flashStart)
{
float num = (timer - flashStart) % flashSpeed;
bool flag = num < flashSpeed / 2f;
if (isVisible)
{
component.sprite = sprites[flag ? 1 : 0];
}
else
{
component.sprite = sprites[flag ? 3 : 2];
}
}
else
{
component.sprite = sprites[(!isVisible) ? 2 : 0];
}
}
else
{
hasResetThisRound = false;
if (!isVisible)
{
SetBlockState(visible: true);
}
}
}
}
[HarmonyPatch(typeof(TwitchChatController), "Awake")]
internal static class TwitchChatControllerAwakePatch
{
private static void Prefix(TwitchChatController __instance)
{
Debug.Log((object)("TwitchChatController Awake: " + (object)PlaceableMetadataList.instance));
if (Object.op_Implicit((Object)(object)PlaceableMetadataList.instance))
{
__instance.MetaList = PlaceableMetadataList.instance;
}
}
}
[HarmonyPatch(typeof(TwitchChatController), "UpdateAllowedItems")]
internal static class TwitchChatControllerPatch
{
private static void Prefix(TwitchChatController __instance)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
VersusControl component = ((GameObject)__instance.versusControllerPrefab).GetComponent<VersusControl>();
if ((Object)(object)component != (Object)null)
{
((GameControl)component).MetaList = PlaceableMetadataList.instance;
}
}
}
}