using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using InventoryFramework;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using MultiSide.shared;
using Newtonsoft.Json;
using Photon.Client;
using UnityEngine;
using UnityEngine.SceneManagement;
using mszcubemod;
using mszcubemod.Components;
using mszcubemod.Networking;
using mszcubemod.Rendering;
using mszcubemod.Textures;
using mszcubemod.World;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Zerocraft")]
[assembly: MelonInfo(typeof(Core), "Zerocraft", "4.0.1", "gameknight963", null)]
[assembly: MelonOptionalDependencies(new string[] { "Multiside.shared", "PhotonClient" })]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("mszcubemod")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3ef9dac-a187-4b92-8f3f-cf1931a29dee")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 mszcubemod
{
public class Core : MelonMod
{
private GameObject? playerCamera;
private GameObject? ghostCube;
public static readonly string ModResources = Path.Combine(MelonEnvironment.ModsDirectory, "Zerocraft");
private Block? activeBlock;
private bool _previewMode;
private void SetPreviewMode(bool preview)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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_003d: Unknown result type (might be due to invalid IL or missing references)
_previewMode = preview;
if ((Object)(object)ghostCube != (Object)null)
{
Object.Destroy((Object)(object)ghostCube);
}
if (activeBlock == null)
{
return;
}
ghostCube = (_previewMode ? CubeFactory.CreateCube(Vector3.zero, activeBlock.Texture, activeBlock.Size) : CubeFactory.CreateWireframeCube(Vector3.zero, activeBlock.Size));
ghostCube.SetActive(false);
if (!_previewMode)
{
BoxCollider component = ghostCube.GetComponent<BoxCollider>();
if (component != null)
{
((Collider)component).enabled = false;
}
}
}
private static void PlaceBlock(string blockId, Vector3 position)
{
//IL_0006: 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)
WorldManager.Instance.PlaceBlock(blockId, position);
CubeNetworking.Instance?.SendPlace(blockId, position);
}
private static void DeleteBlock(Vector3 position)
{
//IL_0005: 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)
WorldManager.Instance.DeleteBlock(position);
CubeNetworking.Instance?.SendDelete(position);
}
public override void OnInitializeMelon()
{
//IL_0054: 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)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
WorldManager.Instance.Initialize(BlockLoader.LoadAll());
CubeNetworking.Init();
foreach (Block block in WorldManager.Instance.Blocks)
{
Texture2D val = BlockPreviewRenderer.CreateIsometricPreview(block.Texture);
Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
InventoryManager.Instance.RegisterItem(new ItemDefinition(block.Id, block.Name, val2));
}
InventoryManager.Instance.OnItemSelected += delegate(InventoryItem? item)
{
if (item == null)
{
activeBlock = null;
GameObject? obj = ghostCube;
if (obj != null)
{
obj.SetActive(false);
}
}
else
{
activeBlock = WorldManager.Instance.Blocks.FirstOrDefault((Block b) => b.Id == item.Definition.Id);
if (activeBlock != null)
{
SetPreviewMode(_previewMode);
}
}
};
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
if (!(sceneName != "Version 1.9 POST"))
{
playerCamera = GameObject.Find("playerCamera");
}
}
public override void OnUpdate()
{
//IL_000f: 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_0046: 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_005b: 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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: 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_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)playerCamera == (Object)null)
{
return;
}
Scene activeScene = SceneManager.GetActiveScene();
if (((Scene)(ref activeScene)).name != "Version 1.9 POST")
{
return;
}
if (Input.GetMouseButtonDown(1) && activeBlock != null)
{
if (!RaycastFromCamera(out var hit))
{
return;
}
Vector3 position = SnapToGrid(((RaycastHit)(ref hit)).point + Vector3.Scale(activeBlock.Size * 0.5f, ((RaycastHit)(ref hit)).normal), activeBlock.Size);
PlaceBlock(activeBlock.Id, position);
}
PlacedBlockComponent placedBlockComponent = default(PlacedBlockComponent);
if (Input.GetMouseButtonDown(0) && activeBlock != null)
{
if (!RaycastFromCamera(out var hit2) || !Object.op_Implicit((Object)(object)((RaycastHit)(ref hit2)).transform) || !((Component)((RaycastHit)(ref hit2)).collider).TryGetComponent<PlacedBlockComponent>(ref placedBlockComponent))
{
return;
}
DeleteBlock(((RaycastHit)(ref hit2)).transform.position);
}
if (!((Object)(object)ghostCube != (Object)null) || activeBlock == null)
{
return;
}
if (RaycastFromCamera(out var hit3))
{
ghostCube.SetActive(true);
if (_previewMode)
{
ghostCube.transform.position = SnapToGrid(((RaycastHit)(ref hit3)).point + Vector3.Scale(ghostCube.transform.localScale * 0.5f, ((RaycastHit)(ref hit3)).normal), activeBlock.Size);
}
else if (((Component)((RaycastHit)(ref hit3)).collider).TryGetComponent<PlacedBlockComponent>(ref placedBlockComponent))
{
ghostCube.transform.position = ((RaycastHit)(ref hit3)).transform.position;
}
}
else
{
ghostCube.SetActive(false);
}
}
private bool RaycastFromCamera(out RaycastHit hit)
{
//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_002e: Unknown result type (might be due to invalid IL or missing references)
if (playerCamera == null)
{
throw new InvalidOperationException();
}
return Physics.Raycast(new Ray(playerCamera.transform.position, playerCamera.transform.forward), ref hit, 4f);
}
private static Vector3 SnapToGrid(Vector3 position, Vector3 snapGrid)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: 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_0032: 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_0044: 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)
return new Vector3(Mathf.Round(position.x / snapGrid.x) * snapGrid.x, Mathf.Round(position.y / snapGrid.y) * snapGrid.y, Mathf.Round(position.z / snapGrid.z) * snapGrid.z);
}
}
}
namespace mszcubemod.World
{
public class Block
{
public static readonly Vector3 DefaultCubeSize = new Vector3(1f, 1f, 1f);
public string Id { get; set; } = "";
public string Name { get; set; } = "";
public Vector3 Size { get; set; } = new Vector3(0.5f, 0.5f, 0.5f);
public TransparencyMode Transparency { get; set; }
public IBlockTexture Texture { get; private set; }
public Block(string id, string name, IBlockTexture texture, Vector3? size = null, TransparencyMode transparency = TransparencyMode.Opaque)
{
//IL_0026: 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_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
Size = (Vector3)(((??)size) ?? DefaultCubeSize);
Id = id;
Name = name;
Texture = texture;
Transparency = transparency;
}
}
public class BlockData
{
public string? Name { get; set; }
public Vector3? Size { get; set; }
public TransparencyMode? Transparency { get; set; }
public float? AnimationSpeed { get; set; }
public float[]? FrameDurations { get; set; }
}
public static class BlockLoader
{
public static List<Block> LoadAll()
{
List<Block> list = new List<Block>();
string[] files = Directory.GetFiles(Core.ModResources);
foreach (string text in files)
{
string text2 = Path.GetExtension(text).ToLower();
if (!(text2 != ".png") || !(text2 != ".jpg"))
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
list.Add(new Block(fileNameWithoutExtension, fileNameWithoutExtension, new UniformBlockTexture(TextureLoader.Load(text))));
}
}
files = Directory.GetDirectories(Core.ModResources);
foreach (string obj in files)
{
string fileName = Path.GetFileName(obj);
BlockData blockData = null;
string text3 = Path.Combine(obj, "blockdata.json");
if (File.Exists(text3))
{
blockData = JsonConvert.DeserializeObject<BlockData>(File.ReadAllText(text3)) ?? throw new InvalidOperationException(text3 + " is malformed or invalid");
}
TransparencyMode valueOrDefault = (blockData?.Transparency).GetValueOrDefault();
IBlockTexture texture = LoadTexture(obj, fileName, blockData);
list.Add(new Block(fileName, blockData?.Name ?? fileName, texture, blockData?.Size, valueOrDefault));
}
return list;
}
private static IBlockTexture LoadTexture(string dir, string id, BlockData? data)
{
string text = Directory.GetFiles(dir, id + ".png").Concat(Directory.GetFiles(dir, id + ".jpg")).FirstOrDefault();
if (text != null)
{
Texture2D val = TextureLoader.Load(text);
if (((Texture)val).height > ((Texture)val).width)
{
return new UniformAnimatedBlockTexture(SliceAnimation(val, data?.FrameDurations, data?.AnimationSpeed));
}
return new UniformBlockTexture(val);
}
return LoadCompositeTexture(dir, data);
}
private static IBlockTexture LoadCompositeTexture(string dir, BlockData? data)
{
Texture2D val = TextureLoader.Load(FindFace(dir, "up"));
Texture2D val2 = TextureLoader.Load(FindFace(dir, "down"));
Texture2D val3 = TextureLoader.Load(FindFace(dir, "north"));
Texture2D val4 = TextureLoader.Load(FindFace(dir, "south"));
Texture2D val5 = TextureLoader.Load(FindFace(dir, "east"));
Texture2D val6 = TextureLoader.Load(FindFace(dir, "west"));
if (!((IEnumerable<Texture2D>)(object)new Texture2D[6] { val, val2, val3, val4, val5, val6 }).Any((Texture2D t) => ((Texture)t).height > ((Texture)t).width))
{
return new CompositeBlockTexture(val, val2, val3, val4, val5, val6);
}
return new CompositeAnimatedBlockTexture(SliceAnimation(val, data?.FrameDurations, data?.AnimationSpeed), SliceAnimation(val2, data?.FrameDurations, data?.AnimationSpeed), SliceAnimation(val3, data?.FrameDurations, data?.AnimationSpeed), SliceAnimation(val4, data?.FrameDurations, data?.AnimationSpeed), SliceAnimation(val5, data?.FrameDurations, data?.AnimationSpeed), SliceAnimation(val6, data?.FrameDurations, data?.AnimationSpeed));
}
private static string FindFace(string dir, string face)
{
return Directory.GetFiles(dir, face + ".png").Concat(Directory.GetFiles(dir, face + ".jpg")).FirstOrDefault() ?? throw new FileNotFoundException("Missing face texture '" + face + "' in " + dir);
}
private static AnimatedTexture SliceAnimation(Texture2D tex, float[]? frameDurations, float? animationSpeed)
{
//IL_0037: 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_0044: Expected O, but got Unknown
int width = ((Texture)tex).width;
int num = ((Texture)tex).height / width;
Texture2D[] array = (Texture2D[])(object)new Texture2D[num];
for (int i = 0; i < num; i++)
{
Color[] pixels = tex.GetPixels(0, ((Texture)tex).height - (i + 1) * width, width, width);
Texture2D val = new Texture2D(width, width, tex.format, false);
val.SetPixels(pixels);
val.Apply();
array[i] = val;
}
float[] durations = frameDurations ?? Enumerable.Repeat(animationSpeed ?? 0.1f, num).ToArray();
return new AnimatedTexture(array, durations);
}
}
public static class BlockPreviewRenderer
{
public static Texture2D CreateIsometricPreview(IBlockTexture blockTexture, int size = 64)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
//IL_0060: 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_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0196: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: 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_0272: Unknown result type (might be due to invalid IL or missing references)
int num = size / 2;
float num2 = (float)size / 6f;
float num3 = (float)size / 6f * 4f;
int num4 = Mathf.RoundToInt(num2 * 2f + num3);
int num5 = (size - num4) / 2 + Mathf.RoundToInt(num3);
Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
Color[] array = (Color[])(object)new Color[size * size];
for (int i = 0; i < array.Length; i++)
{
array[i] = Color.clear;
}
Color[] array2 = SampleTexture(blockTexture.Up, size, size);
Color[] array3 = SampleTexture(blockTexture.East, size, size);
Color[] array4 = SampleTexture(blockTexture.West, size, size);
for (int j = 0; j < size; j++)
{
for (int k = 0; k < size; k++)
{
float num6 = (float)j / (float)(size - 1);
float num7 = (float)k / (float)(size - 1);
int num8 = Mathf.RoundToInt((num6 - num7) * (float)num + (float)num);
int num9 = Mathf.RoundToInt((float)num5 + (num6 + num7) * num2);
if (num8 >= 0 && num8 < size && num9 >= 0 && num9 < size)
{
BlendPixel(array, size, num8, num9, array2[k * size + j]);
}
}
}
for (int l = 0; l < size; l++)
{
for (int m = 0; m < size; m++)
{
float num10 = (float)l / (float)(size - 1);
float num11 = (float)m / (float)(size - 1);
int num12 = Mathf.RoundToInt(num10 * (float)num);
int num13 = Mathf.RoundToInt((float)num5 + (1f - num10) * num2 - num11 * num3);
if (num12 >= 0 && num12 < size && num13 >= 0 && num13 < size)
{
Color val2 = array3[m * size + l];
Color src = val2 * 0.75f;
src.a = val2.a;
BlendPixel(array, size, num12, num13, src);
}
}
}
for (int n = 0; n < size; n++)
{
for (int num14 = 0; num14 < size; num14++)
{
float num15 = (float)n / (float)(size - 1);
float num16 = (float)num14 / (float)(size - 1);
int num17 = Mathf.RoundToInt((float)num + num15 * (float)num);
int num18 = Mathf.RoundToInt((float)num5 + num15 * num2 - num16 * num3);
if (num17 >= 0 && num17 < size && num18 >= 0 && num18 < size)
{
Color val3 = array4[num14 * size + n];
Color src2 = val3 * 0.88f;
src2.a = val3.a;
BlendPixel(array, size, num17, num18, src2);
}
}
}
val.SetPixels(array);
val.Apply();
return val;
}
public static Sprite CreateIsometricSprite(IBlockTexture blockTexture, int size = 64)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = CreateIsometricPreview(blockTexture, size);
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
}
private static Color[] SampleTexture(Texture2D src, int w, int h)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
Color[] array = (Color[])(object)new Color[w * h];
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
array[i * w + j] = src.GetPixelBilinear((float)j / (float)w, (float)i / (float)h);
}
}
return array;
}
private static void BlendPixel(Color[] pixels, int width, int x, int y, Color src)
{
//IL_0000: 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_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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_0045: 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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: 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_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: 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_009f: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
if (!(src.a <= 0f))
{
int num = y * width + x;
Color val = pixels[num];
float num2 = src.a + val.a * (1f - src.a);
if (!(num2 <= 0f))
{
pixels[num] = new Color((src.r * src.a + val.r * val.a * (1f - src.a)) / num2, (src.g * src.a + val.g * val.a * (1f - src.a)) / num2, (src.b * src.a + val.b * val.a * (1f - src.a)) / num2, num2);
}
}
}
}
internal record PlacedBlock(string BlockId, Vector3 Position, GameObject Object);
internal class WorldManager
{
private readonly List<Block> _blocks = new List<Block>();
private readonly Dictionary<Vector3, PlacedBlock> placedBlocks = new Dictionary<Vector3, PlacedBlock>();
public static WorldManager Instance { get; } = new WorldManager();
public IReadOnlyList<Block> Blocks { get; }
public IReadOnlyDictionary<Vector3, PlacedBlock> PlacedBlocks => placedBlocks;
private WorldManager()
{
Blocks = _blocks.AsReadOnly();
}
public void Initialize(List<Block> blocks)
{
_blocks.AddRange(blocks);
}
public void PlaceBlock(string blockId, Vector3 position)
{
//IL_0029: 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_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
Block block = Blocks.FirstOrDefault((Block b) => b.Id == blockId);
if (block != null)
{
GameObject val = CubeFactory.CreateCube(position, block.Texture, block.Size, block.Transparency);
placedBlocks[position] = new PlacedBlock(blockId, position, val);
}
}
public void DeleteBlock(Vector3 position)
{
//IL_0006: 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_0015: Unknown result type (might be due to invalid IL or missing references)
if (!placedBlocks.TryGetValue(position, out PlacedBlock value))
{
MelonLogger.Warning($"Attempted to delete non-existant block at {position}!");
}
placedBlocks.Remove(position);
Object.Destroy((Object)(object)value.Object);
}
public void RegisterBlock(Block block)
{
if (_blocks.Any((Block b) => b.Id == block.Id))
{
throw new InvalidOperationException("Block '" + block.Id + "' is already registered.");
}
_blocks.Add(block);
}
}
}
namespace mszcubemod.Textures
{
public class AnimatedTexture
{
private readonly Texture2D[] _frames;
private readonly float[] _durations;
private int _currentFrame;
public Texture2D Texture => _frames[_currentFrame];
public event Action? Updated;
public AnimatedTexture(Texture2D[] frames, float[] durations)
{
if (frames.Length < 2)
{
throw new ArgumentException("Animation must contain at least two frames.");
}
if (frames.Length != durations.Length)
{
throw new ArgumentException("There must be one duration for every frame.");
}
if (durations.Any((float duration) => duration <= 0f))
{
throw new ArgumentException("All animation frame durations must be greater than zero.");
}
_frames = frames.ToArray();
_durations = durations.ToArray();
}
internal void Start()
{
MelonCoroutines.Start(Animate());
}
private IEnumerator Animate()
{
while (true)
{
yield return (object)new WaitForSeconds(_durations[_currentFrame]);
_currentFrame = (_currentFrame + 1) % _frames.Length;
this.Updated?.Invoke();
}
}
}
public class CompositeAnimatedBlockTexture : IAnimatedBlockTexture, IBlockTexture
{
private readonly AnimatedTexture _up;
private readonly AnimatedTexture _down;
private readonly AnimatedTexture _north;
private readonly AnimatedTexture _south;
private readonly AnimatedTexture _east;
private readonly AnimatedTexture _west;
public Texture2D Up => _up.Texture;
public Texture2D Down => _down.Texture;
public Texture2D North => _north.Texture;
public Texture2D South => _south.Texture;
public Texture2D East => _east.Texture;
public Texture2D West => _west.Texture;
public event Action? Updated;
public CompositeAnimatedBlockTexture(AnimatedTexture up, AnimatedTexture down, AnimatedTexture north, AnimatedTexture south, AnimatedTexture east, AnimatedTexture west)
{
_up = up;
_down = down;
_north = north;
_south = south;
_east = east;
_west = west;
_up.Updated += delegate
{
this.Updated?.Invoke();
};
_down.Updated += delegate
{
this.Updated?.Invoke();
};
_north.Updated += delegate
{
this.Updated?.Invoke();
};
_south.Updated += delegate
{
this.Updated?.Invoke();
};
_east.Updated += delegate
{
this.Updated?.Invoke();
};
_west.Updated += delegate
{
this.Updated?.Invoke();
};
_up.Start();
_down.Start();
_north.Start();
_south.Start();
_east.Start();
_west.Start();
}
}
public class CompositeBlockTexture : IBlockTexture
{
public Texture2D Up { get; }
public Texture2D Down { get; }
public Texture2D North { get; }
public Texture2D South { get; }
public Texture2D East { get; }
public Texture2D West { get; }
public CompositeBlockTexture(Texture2D up, Texture2D down, Texture2D north, Texture2D south, Texture2D east, Texture2D west)
{
Up = up;
Down = down;
North = north;
South = south;
East = east;
West = west;
}
}
public interface IAnimatedBlockTexture : IBlockTexture
{
event Action? Updated;
}
public interface IBlockTexture
{
Texture2D Up { get; }
Texture2D Down { get; }
Texture2D North { get; }
Texture2D South { get; }
Texture2D East { get; }
Texture2D West { get; }
}
public static class TextureLoader
{
public static Texture2D Load(byte[] texture)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_001d: 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_002d: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
if (!ImageConversion.LoadImage(val, texture))
{
throw new InvalidDataException("Failed to load texture.");
}
((Object)val).hideFlags = (HideFlags)32;
((Texture)val).filterMode = (FilterMode)0;
return val;
}
public static Texture2D Load(Stream stream)
{
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return Load(memoryStream.ToArray());
}
public static Texture2D Load(string texturePath)
{
using Stream stream = File.OpenRead(texturePath);
return Load(stream);
}
}
public class UniformAnimatedBlockTexture : IAnimatedBlockTexture, IBlockTexture
{
private readonly AnimatedTexture _animatedTexture;
public Texture2D Up => _animatedTexture.Texture;
public Texture2D Down => _animatedTexture.Texture;
public Texture2D North => _animatedTexture.Texture;
public Texture2D South => _animatedTexture.Texture;
public Texture2D East => _animatedTexture.Texture;
public Texture2D West => _animatedTexture.Texture;
public event Action? Updated;
public UniformAnimatedBlockTexture(AnimatedTexture texture)
{
_animatedTexture = texture;
texture.Updated += delegate
{
this.Updated?.Invoke();
};
texture.Start();
}
}
public class UniformBlockTexture : IBlockTexture
{
private readonly Texture2D _texture;
public Texture2D Up => _texture;
public Texture2D Down => _texture;
public Texture2D North => _texture;
public Texture2D South => _texture;
public Texture2D East => _texture;
public Texture2D West => _texture;
public UniformBlockTexture(Texture2D texture)
{
_texture = texture;
}
}
}
namespace mszcubemod.Rendering
{
public static class CubeFactory
{
private const string cubeName = "zcube";
public static GameObject CreateCube(Vector3 position, IBlockTexture texture, Vector3 scale, TransparencyMode transparency = TransparencyMode.Opaque)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0017: 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)
GameObject val = new GameObject("zcube");
val.transform.position = position;
val.transform.localScale = scale;
MeshFilter val2 = val.AddComponent<MeshFilter>();
MeshRenderer val3 = val.AddComponent<MeshRenderer>();
val2.mesh = BuildCubeMesh();
Material[] materials = (Material[])(object)new Material[6]
{
CreateTextureMaterial(texture.West, transparency),
CreateTextureMaterial(texture.East, transparency),
CreateTextureMaterial(texture.Up, transparency),
CreateTextureMaterial(texture.Down, transparency),
CreateTextureMaterial(texture.North, transparency),
CreateTextureMaterial(texture.South, transparency)
};
((Renderer)val3).materials = materials;
IAnimatedBlockTexture animated = texture as IAnimatedBlockTexture;
if (animated != null)
{
animated.Updated += delegate
{
materials[0].mainTexture = (Texture)(object)animated.West;
materials[1].mainTexture = (Texture)(object)animated.East;
materials[2].mainTexture = (Texture)(object)animated.Up;
materials[3].mainTexture = (Texture)(object)animated.Down;
materials[4].mainTexture = (Texture)(object)animated.North;
materials[5].mainTexture = (Texture)(object)animated.South;
};
}
val.AddComponent<BoxCollider>();
val.AddComponent<PlacedBlockComponent>();
return val;
}
public static GameObject CreateWireframeCube(Vector3 position, Vector3 size)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0011: 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_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_0039: 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_0045: 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_0052: 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_0060: 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_006c: 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_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: 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_0092: 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_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_00c4: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Expected O, but got Unknown
//IL_0201: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Unknown result type (might be due to invalid IL or missing references)
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_0259: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("cubePreview");
val.transform.position = position;
Vector3 val2 = size * 0.5f;
Vector3[] array = (Vector3[])(object)new Vector3[8]
{
new Vector3(0f - val2.x, 0f - val2.y, 0f - val2.z),
new Vector3(val2.x, 0f - val2.y, 0f - val2.z),
new Vector3(val2.x, val2.y, 0f - val2.z),
new Vector3(0f - val2.x, val2.y, 0f - val2.z),
new Vector3(0f - val2.x, 0f - val2.y, val2.z),
new Vector3(val2.x, 0f - val2.y, val2.z),
new Vector3(val2.x, val2.y, val2.z),
new Vector3(0f - val2.x, val2.y, val2.z)
};
int[][] obj = new int[12][]
{
new int[2] { 0, 1 },
new int[2] { 1, 2 },
new int[2] { 2, 3 },
new int[2] { 3, 0 },
new int[2] { 4, 5 },
new int[2] { 5, 6 },
new int[2] { 6, 7 },
new int[2] { 7, 4 },
new int[2] { 0, 4 },
new int[2] { 1, 5 },
new int[2] { 2, 6 },
new int[2] { 3, 7 }
};
Material val3 = new Material(Shader.Find("Unlit/Color"));
val3.color = Color.black;
int[][] array2 = obj;
foreach (int[] array3 in array2)
{
GameObject val4 = new GameObject("Edge");
val4.transform.SetParent(val.transform, false);
LineRenderer obj2 = val4.AddComponent<LineRenderer>();
obj2.positionCount = 2;
obj2.SetPosition(0, array[array3[0]]);
obj2.SetPosition(1, array[array3[1]]);
obj2.startWidth = 0.02f;
obj2.endWidth = 0.02f;
((Renderer)obj2).material = val3;
obj2.useWorldSpace = false;
}
return val;
}
private static Mesh BuildCubeMesh()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Expected O, but got Unknown
//IL_001e: 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_0039: 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_0054: 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_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: 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)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: 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_012e: 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_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: 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_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: 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_01bf: 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)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0310: Unknown result type (might be due to invalid IL or missing references)
//IL_0315: Unknown result type (might be due to invalid IL or missing references)
//IL_0326: Unknown result type (might be due to invalid IL or missing references)
//IL_032b: 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_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_0357: Unknown result type (might be due to invalid IL or missing references)
//IL_0368: Unknown result type (might be due to invalid IL or missing references)
//IL_036d: Unknown result type (might be due to invalid IL or missing references)
//IL_037f: Unknown result type (might be due to invalid IL or missing references)
//IL_0384: Unknown result type (might be due to invalid IL or missing references)
//IL_0396: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
//IL_03db: Unknown result type (might be due to invalid IL or missing references)
//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0409: Unknown result type (might be due to invalid IL or missing references)
//IL_040e: Unknown result type (might be due to invalid IL or missing references)
//IL_0420: Unknown result type (might be due to invalid IL or missing references)
//IL_0425: Unknown result type (might be due to invalid IL or missing references)
//IL_0437: Unknown result type (might be due to invalid IL or missing references)
//IL_043c: Unknown result type (might be due to invalid IL or missing references)
//IL_044e: Unknown result type (might be due to invalid IL or missing references)
//IL_0453: Unknown result type (might be due to invalid IL or missing references)
//IL_0465: Unknown result type (might be due to invalid IL or missing references)
//IL_046a: Unknown result type (might be due to invalid IL or missing references)
//IL_047c: Unknown result type (might be due to invalid IL or missing references)
//IL_0481: Unknown result type (might be due to invalid IL or missing references)
//IL_0493: Unknown result type (might be due to invalid IL or missing references)
//IL_0498: Unknown result type (might be due to invalid IL or missing references)
//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
//IL_04af: Unknown result type (might be due to invalid IL or missing references)
//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
Mesh val = new Mesh();
Vector3[] vertices = (Vector3[])(object)new Vector3[24]
{
new Vector3(0.5f, -0.5f, -0.5f),
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(0.5f, 0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(0.5f, -0.5f, -0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(-0.5f, -0.5f, 0.5f),
new Vector3(0.5f, -0.5f, 0.5f),
new Vector3(0.5f, 0.5f, 0.5f),
new Vector3(-0.5f, 0.5f, 0.5f),
new Vector3(0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, -0.5f, -0.5f),
new Vector3(-0.5f, 0.5f, -0.5f),
new Vector3(0.5f, 0.5f, -0.5f)
};
Vector2[] uv = (Vector2[])(object)new Vector2[24]
{
new Vector2(0f, 0f),
new Vector2(0f, 1f),
new Vector2(1f, 1f),
new Vector2(1f, 0f),
new Vector2(0f, 0f),
new Vector2(0f, 1f),
new Vector2(1f, 1f),
new Vector2(1f, 0f),
new Vector2(0f, 0f),
new Vector2(0f, 1f),
new Vector2(1f, 1f),
new Vector2(1f, 0f),
new Vector2(0f, 0f),
new Vector2(0f, 1f),
new Vector2(1f, 1f),
new Vector2(1f, 0f),
new Vector2(0f, 0f),
new Vector2(1f, 0f),
new Vector2(1f, 1f),
new Vector2(0f, 1f),
new Vector2(0f, 0f),
new Vector2(1f, 0f),
new Vector2(1f, 1f),
new Vector2(0f, 1f)
};
val.vertices = vertices;
val.uv = uv;
val.subMeshCount = 6;
for (int i = 0; i < 6; i++)
{
int num = i * 4;
val.SetTriangles(new int[6]
{
num,
num + 1,
num + 2,
num,
num + 2,
num + 3
}, i);
}
val.RecalculateNormals();
val.RecalculateBounds();
return val;
}
private static Material CreateTextureMaterial(Texture2D tex, TransparencyMode transparency = TransparencyMode.Opaque)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
Material val = new Material(Shader.Find("Standard"));
val.SetTexture("_MainTex", (Texture)(object)tex);
switch (transparency)
{
case TransparencyMode.Cutout:
val.SetFloat("_Mode", 1f);
val.SetFloat("_Cutoff", 0.5f);
val.EnableKeyword("_ALPHATEST_ON");
val.renderQueue = 2450;
break;
case TransparencyMode.Transparent:
val.SetFloat("_Mode", 3f);
val.EnableKeyword("_ALPHABLEND_ON");
val.SetInt("_SrcBlend", 5);
val.SetInt("_DstBlend", 10);
val.SetInt("_ZWrite", 0);
val.renderQueue = 3000;
break;
}
return val;
}
}
public enum TransparencyMode : byte
{
Opaque,
Cutout,
Transparent
}
}
namespace mszcubemod.Networking
{
internal class CubeNetworking
{
private const string ChannelPlace = "zerocraft.place";
private const string ChannelDelete = "zerocraft.delete";
private const string ChannelWorldStateRequest = "zerocraft.worldstate.request";
private const string ChannelWorldStateResponse = "zerocraft.worldstate.response";
public static CubeNetworking? Instance { get; private set; }
private CubeNetworking()
{
}
public static void Init()
{
if (AppDomain.CurrentDomain.GetAssemblies().Any((Assembly a) => a.GetName().Name == "Multiside.shared"))
{
Instance = new CubeNetworking();
Instance.InitNetwork();
}
}
private void InitNetwork()
{
if (NetworkRegistry.Provider != null)
{
Subscribe(NetworkRegistry.Provider);
}
else
{
NetworkRegistry.OnProviderRegistered += Subscribe;
}
}
private void Subscribe(INetworkProvider provider)
{
provider.OnReceived += OnReceived;
provider.OnRoomJoined += OnRoomJoined;
}
private void OnReceived(int actor, string channel, object data)
{
switch (channel)
{
case "zerocraft.place":
{
PhotonHashtable val = (PhotonHashtable)((data is PhotonHashtable) ? data : null);
if (val != null)
{
HandlePlace(val);
}
break;
}
case "zerocraft.delete":
{
PhotonHashtable val2 = (PhotonHashtable)((data is PhotonHashtable) ? data : null);
if (val2 != null)
{
HandleDelete(val2);
}
break;
}
case "zerocraft.worldstate.request":
HandleWorldStateRequest(actor);
break;
case "zerocraft.worldstate.response":
if (data is PhotonHashtable[] blocks)
{
HandleWorldStateResponse(blocks);
}
break;
}
}
private void OnRoomJoined()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
INetworkProvider provider = NetworkRegistry.Provider;
if (provider != null)
{
provider.Send("zerocraft.worldstate.request", (object)new PhotonHashtable(), true);
}
}
private void HandlePlace(PhotonHashtable ht)
{
//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_0039: Unknown result type (might be due to invalid IL or missing references)
if (ht[(object)"blockId"] is string blockId && ht[(object)"position"] is Vector3 position)
{
WorldManager.Instance.PlaceBlock(blockId, position);
}
}
private void HandleDelete(PhotonHashtable ht)
{
//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_0023: Unknown result type (might be due to invalid IL or missing references)
if (ht[(object)"position"] is Vector3 position)
{
WorldManager.Instance.DeleteBlock(position);
}
}
private void HandleWorldStateRequest(int requesterActor)
{
INetworkProvider provider = NetworkRegistry.Provider;
if (provider != null && provider.IsMasterClient)
{
PhotonHashtable[] array = WorldManager.Instance.PlacedBlocks.Values.Select((Func<PlacedBlock, PhotonHashtable>)((PlacedBlock b) => new PhotonHashtable
{
[(object)"blockId"] = b.BlockId,
[(object)"position"] = b.Position
})).ToArray();
provider.SendTo(requesterActor, "zerocraft.worldstate.response", (object)array, true);
}
}
private void HandleWorldStateResponse(PhotonHashtable[] blocks)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
foreach (PhotonHashtable val in blocks)
{
if (val[(object)"blockId"] is string blockId && val[(object)"position"] is Vector3 position)
{
WorldManager.Instance.PlaceBlock(blockId, position);
}
}
}
public void SendPlace(string blockId, Vector3 position)
{
//IL_000f: 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_0028: 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_003b: Expected O, but got Unknown
INetworkProvider provider = NetworkRegistry.Provider;
if (provider != null)
{
provider.Send("zerocraft.place", (object)new PhotonHashtable
{
[(object)"blockId"] = blockId,
[(object)"position"] = position
}, true);
}
}
public void SendDelete(Vector3 position)
{
//IL_000f: 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_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
INetworkProvider provider = NetworkRegistry.Provider;
if (provider != null)
{
provider.Send("zerocraft.delete", (object)new PhotonHashtable { [(object)"position"] = position }, true);
}
}
}
}
namespace mszcubemod.Converters
{
public class Vector3Converter : JsonConverter<Vector3>
{
public override Vector3 ReadJson(JsonReader reader, Type objectType, Vector3 existingValue, bool hasExistingValue, JsonSerializer serializer)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
float[] array = serializer.Deserialize<float[]>(reader);
if (array == null || array.Length != 3)
{
throw new JsonSerializationException("Expected a float array with 3 elements, got " + (array?.Length.ToString() ?? "null") + ".");
}
return new Vector3(array[0], array[1], array[2]);
}
public override void WriteJson(JsonWriter writer, Vector3 value, JsonSerializer serializer)
{
//IL_000a: 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_001c: Unknown result type (might be due to invalid IL or missing references)
serializer.Serialize(writer, (object)new float[3] { value.x, value.y, value.z });
}
}
}
namespace mszcubemod.Components
{
[RegisterTypeInIl2Cpp]
public class PlacedBlockComponent : MonoBehaviour
{
}
}
namespace System.Runtime.CompilerServices
{
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal static class IsExternalInit
{
}
}