public static IEnumerable <CodeInstruction> Transpiler(ILGenerator ilGenerator, MethodBase original, IEnumerable <CodeInstruction> instructions) { List <CodeInstruction> codes = new List <CodeInstruction>(instructions); // File.WriteAllLines("before.txt", codes.Select(c => c.ToString())); int index = codes.FindIndex(c => c.operand is string && ((string)c.operand).Contains("with incompatible version")); AsphaltLog.WriteLine("[EcoVersionHack] Found first index to patch: " + index); int i = 1; while (codes[index].opcode.Name != "br" && codes[index].opcode.Name != "ret") { codes.RemoveAt(index); i++; } codes.RemoveAt(index); AsphaltLog.WriteLine($"[EcoVersionHack] Removed {i} instructions!"); // File.WriteAllLines("after.txt", codes.Select(c => c.ToString())); return(codes.AsEnumerable()); }
public static void Shift(User user, string pDirectionAndAmount = "1") { try { Direction direction = WorldEditManager.GetDirectionAndAmount(user, pDirectionAndAmount, out int amount); if (direction == Direction.Unknown) { return; } WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.ShiftSelection(direction.ToVec() * amount)) { user.Player.SendTemporaryMessage($"Shifted selection {amount} {direction}"); } else { user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!"); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public override InteractResult OnActRight(InteractionContext context) { try { if (context.BlockPosition == null || !context.BlockPosition.HasValue) { return(InteractResult.Success); } var pos = context.BlockPosition.Value; pos.X = pos.X < 0 ? pos.X + Shared.Voxel.World.VoxelSize.X : pos.X; pos.Z = pos.Z < 0 ? pos.Z + Shared.Voxel.World.VoxelSize.Z : pos.Z; pos.X = pos.X % Shared.Voxel.World.VoxelSize.X; pos.Z = pos.Z % Shared.Voxel.World.VoxelSize.Z; WorldEditUserData weud = WorldEditManager.GetUserData(context.Player.User.Name); weud.SecondPos = pos; context.Player.SendTemporaryMessage($"Second Position set to ({pos.x}, {pos.y}, {pos.z})"); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } return(InteractResult.NoOp); }
public static void RmWand(User user) { try { user.Inventory.TryRemoveItems(WorldEditManager.getWandItemStack()); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Stack(User user, string pDirectionAndAmount = "1") { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.FirstPos == null || weud.SecondPos == null) { user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!"); return; } var vectors = weud.GetSortedVectors(); Direction dir = WorldEditManager.GetDirectionAndAmount(user, pDirectionAndAmount, out int amount); weud.StartEditingBlocks(); UserSession session = weud.GetNewSession(); long changedBlocks = 0; for (int i = 1; i <= amount; i++) { Vector3i offset = dir.ToVec() * (vectors.Higher - vectors.Lower) * i; for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { var pos = new Vector3i(x, y, z); weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos + offset), pos + offset); var sourceBlock = Eco.World.World.GetBlock(pos); WorldEditManager.SetBlock(sourceBlock.GetType(), pos + offset, session, pos, sourceBlock); changedBlocks++; } } } } // int changedBlocks = (int)((vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z)) * amount; user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed."); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Distr(User user) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.FirstPos == null || weud.SecondPos == null) { user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!"); return; } var vectors = weud.GetSortedVectors(); Dictionary <string, long> mBlocks = new Dictionary <string, long>(); for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { // Console.WriteLine($"{x} {y} {z}"); var pos = new Vector3i(x, y, z); var block = Eco.World.World.GetBlock(pos).GetType().ToString(); long count; mBlocks.TryGetValue(block, out count); mBlocks[block] = count + 1; } } } double amountBlocks = mBlocks.Values.Sum(); // (vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z); user.SendMessage($"total blocks: {amountBlocks}", false); foreach (var entry in mBlocks) { string percent = (Math.Round((entry.Value / amountBlocks) * 100, 2)).ToString() + "%"; string nameOfBlock = entry.Key.Substring(entry.Key.LastIndexOf(".") + 1); user.SendMessage($"{entry.Value.ToString().PadRight(6)} {percent.PadRight(6)} {nameOfBlock}", false); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Up(User user, int pCount = 1) { try { Vector3 pos = user.Player.Position; var newpos = new Vector3i((int)pos.X, (int)pos.Y + pCount, (int)pos.Z); WorldEditManager.SetBlock(typeof(StoneBlock), newpos); newpos.Y += 2; user.Player.SetPosition(newpos); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Set(User user, string pTypeName) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.FirstPos == null || weud.SecondPos == null) { user.Player.SendTemporaryMessage($"Please set both Points with the Wand Tool first!"); return; } Type blockType = BlockUtils.GetBlockType(pTypeName); if (blockType == null) { user.Player.SendTemporaryMessage($"No BlockType with name {pTypeName} found!"); return; } var vectors = weud.GetSortedVectors(); weud.StartEditingBlocks(); long changedBlocks = 0; for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { var pos = new Vector3i(x, y, z); weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos), pos); WorldEditManager.SetBlock(blockType, pos); changedBlocks++; } } } user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed."); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Import(User user, string pFileName) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.LoadClipboard(pFileName)) { user.Player.SendTemporaryMessage($"Import done. Use //paste"); } else { user.Player.SendTemporaryMessage($"Schematic file not found!"); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Export(User user, string pFileName) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.SaveClipboard(pFileName)) { user.Player.SendTemporaryMessage($"Export done."); } else { user.Player.SendTemporaryMessage($"Please //copy a selection first!"); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Rotate(User user, int pDegree = 90) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.RotateClipboard(pDegree)) { user.Player.SendTemporaryMessage($"Rotation in clipboard done."); } else { user.Player.SendTemporaryMessage($"Please copy a selection first!"); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Paste(User user) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.LoadSelectionFromClipboard(user, weud)) { user.Player.SendTemporaryMessage($"Paste done."); } else { user.Player.SendTemporaryMessage($"Please copy a selection first!"); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Copy(User user) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.SaveSelectionToClipboard(user)) { user.Player.SendTemporaryMessage($"Copy done."); } else { user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!"); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Undo(User user) { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.Undo()) { user.Player.SendTemporaryMessage($"Undo done."); } else { user.Player.SendTemporaryMessage($"You can't use undo right now!"); } } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void Replace(User user, string pTypeNames = "") { try { string[] splitted = pTypeNames.Split(' '); string toFind = splitted[0].ToLower(); string toReplace = string.Empty; if (splitted.Length >= 2) { toReplace = pTypeNames.Split(' ')[1].ToLower(); } WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.FirstPos == null || weud.SecondPos == null) { user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!"); return; } Type blockTypeToFind = BlockUtils.GetBlockType(toFind); if (blockTypeToFind == null) { user.Player.SendTemporaryMessage($"No BlockType with name {toFind} found!"); return; } Type blockTypeToReplace = null; if (toReplace != string.Empty) { blockTypeToReplace = BlockUtils.GetBlockType(toReplace); if (blockTypeToReplace == null) { user.Player.SendTemporaryMessage($"No BlockType with name { toReplace } found!"); return; } } var vectors = weud.GetSortedVectors(); long changedBlocks = 0; //if toReplace is string empty we will replace everything except empty with toFind type weud.StartEditingBlocks(); if (toReplace != string.Empty) { for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { var pos = new Vector3i(x, y, z); var block = Eco.World.World.GetBlock(pos); if (block != null && block.GetType() == blockTypeToFind) { weud.AddBlockChangedEntry(block, pos); WorldEditManager.SetBlock(blockTypeToReplace, pos); changedBlocks++; } } } } } else { for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { var pos = new Vector3i(x, y, z); var block = Eco.World.World.GetBlock(pos); if (block != null && block.GetType() != typeof(EmptyBlock)) { weud.AddBlockChangedEntry(block, pos); WorldEditManager.SetBlock(blockTypeToFind, pos); changedBlocks++; } } } } } user.Player.SendTemporaryMessage($"{changedBlocks} blocks changed."); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }
public static void SetBlock(Type pType, Vector3i pPosition, UserSession pSession = null, Vector3i?pSourcePosition = null, Block pSourceBlock = null, byte[] pData = null) { if (pType == null || pType.DerivesFrom <PickupableBlock>()) { pType = typeof(EmptyBlock); } WorldObjectBlock worldObjectBlock = Eco.World.World.GetBlock(pPosition) as WorldObjectBlock; if (worldObjectBlock != null) { if (worldObjectBlock.WorldObjectHandle.Object.Position3i == pPosition) { worldObjectBlock.WorldObjectHandle.Object.Destroy(); } } if (pType == typeof(EmptyBlock)) { Eco.World.World.DeleteBlock(pPosition); return; } var constuctor = pType.GetConstructor(Type.EmptyTypes); if (constuctor != null) { Eco.World.World.SetBlock(pType, pPosition); return; } Type[] types = new Type[1]; types[0] = typeof(WorldPosition3i); constuctor = pType.GetConstructor(types); if (constuctor != null) { object obj = null; if (pData != null) { MemoryStream ms = new MemoryStream(pData); obj = EcoSerializer.Deserialize(ms); } if (pType.DerivesFrom <PlantBlock>()) { PlantSpecies ps = null; Plant pb = null; if (obj != null) { pb = (Plant)obj; ps = pb.Species; } else { ps = WorldUtils.GetPlantSpecies(pType); if (pSourceBlock != null) { pb = PlantBlock.GetPlant(pPosition); } } Plant newplant = EcoSim.PlantSim.SpawnPlant(ps, pPosition); if (pb != null) { newplant.YieldPercent = pb.YieldPercent; newplant.Dead = pb.Dead; newplant.DeadType = pb.DeadType; newplant.GrowthPercent = pb.GrowthPercent; newplant.DeathTime = pb.DeathTime; newplant.Tended = pb.Tended; } return; } AsphaltLog.WriteLine("Unknown Type: " + pType); } types[0] = typeof(WorldObject); constuctor = pType.GetConstructor(types); if (constuctor != null) { WorldObject wObject = null; if (pSourceBlock != null) { wObject = ((WorldObjectBlock)pSourceBlock).WorldObjectHandle.Object; //if this is not the "main block" of an object do nothing if (wObject.Position3i != pSourcePosition.Value) { return; } } else if (pData != null) { MemoryStream ms = new MemoryStream(pData); var obj = EcoSerializer.Deserialize(ms); if (obj is WorldObject) { wObject = obj as WorldObject; } else { throw new InvalidOperationException("obj is not WorldObjectBlock"); } } if (wObject == null) { return; } // WorldObject newObject = WorldObjectUtil.Spawn(wObject.GetType().Name, wObject.Creator.User, pPosition); // newObject.Rotation = wObject.Rotation; WorldObject newObject = (WorldObject)Activator.CreateInstance(wObject.GetType(), true); newObject = WorldObjectManager.Add(newObject, wObject.Creator.User, pPosition, wObject.Rotation); { StorageComponent newSC = newObject.GetComponent <StorageComponent>(); if (newSC != null) { StorageComponent oldPSC = wObject.GetComponent <StorageComponent>(); newSC.Inventory.AddItems(oldPSC.Inventory.Stacks); // newSC.Inventory.OnChanged.Invoke(null); } } { CustomTextComponent newTC = newObject.GetComponent <CustomTextComponent>(); if (newTC != null) { CustomTextComponent oldTC = wObject.GetComponent <CustomTextComponent>(); typeof(CustomTextComponent).GetProperty("Text", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(newTC, oldTC.Text); } } return; } AsphaltLog.WriteLine("Unknown Type: " + pType); }
public static void Move(User user, string pDirectionAndAmount = "1") { try { WorldEditUserData weud = WorldEditManager.GetUserData(user.Name); if (weud.FirstPos == null || weud.SecondPos == null) { user.Player.SendTemporaryMessage($"Please set both points with the Wand Tool first!"); return; } var vectors = weud.GetSortedVectors(); Direction dir = WorldEditManager.GetDirectionAndAmount(user, pDirectionAndAmount, out int amount); weud.StartEditingBlocks(); UserSession session = weud.GetNewSession(); Vector3i offset = dir.ToVec() * amount; // if (dir == Direction.Up) // offset *= vectors.Higher.Y - vectors.Lower.Y; long changedBlocks = 0; Action <int, int, int> action = (int x, int y, int z) => { var pos = new Vector3i(x, y, z); weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos), pos); weud.AddBlockChangedEntry(Eco.World.World.GetBlock(pos + offset), pos + offset); var sourceBlock = Eco.World.World.GetBlock(pos); WorldEditManager.SetBlock(sourceBlock.GetType(), pos + offset, session, pos, sourceBlock); WorldEditManager.SetBlock(typeof(EmptyBlock), pos, session); changedBlocks++; }; if (dir == Direction.Left || dir == Direction.Back || dir == Direction.Down) { for (int x = vectors.Lower.X; x != vectors.Higher.X; x = (x + 1) % Shared.Voxel.World.VoxelSize.X) { for (int y = vectors.Lower.Y; y < vectors.Higher.Y; y++) { for (int z = vectors.Lower.Z; z != vectors.Higher.Z; z = (z + 1) % Shared.Voxel.World.VoxelSize.Z) { action.Invoke(x, y, z); } } } } else { /* for (int x = vectors.Higher.X - 1; x >= vectors.Lower.X; x--) * for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--) * for (int z = vectors.Higher.Z - 1; z >= vectors.Lower.Z; z--)*/ int x = vectors.Higher.X - 1; if (x < 0) { x = x + Shared.Voxel.World.VoxelSize.X; } int startZ = vectors.Higher.Z - 1; if (startZ < 0) { startZ = startZ + Shared.Voxel.World.VoxelSize.Z; } // Console.WriteLine("--------------"); // Console.WriteLine(vectors.Lower); // Console.WriteLine(vectors.Higher); for (; x != (vectors.Lower.X - 1); x--) { if (x < 0) { x = x + Shared.Voxel.World.VoxelSize.X; } for (int y = vectors.Higher.Y - 1; y >= vectors.Lower.Y; y--) { for (int z = startZ; z != (vectors.Lower.Z - 1); z--) { if (z < 0) { z = z + Shared.Voxel.World.VoxelSize.Z; } // Console.WriteLine($"{x} {y} {z}"); action.Invoke(x, y, z); } } } } // int changedBlocks = (int)((vectors.Higher.X - vectors.Lower.X) * (vectors.Higher.Y - vectors.Lower.Y) * (vectors.Higher.Z - vectors.Lower.Z)) * amount; user.Player.SendTemporaryMessage($"{changedBlocks} blocks moved."); } catch (Exception e) { AsphaltLog.WriteError(e.ToStringPretty()); } }