diff --git a/README.md b/README.md new file mode 100644 index 0000000..ab06622 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +## Wireshark + +Wireshark is a wire accelarator for terraria, which can run in both jit and aot mode. + +### Usage + +#### JIT mode + +Just load WireShark mod into the game and enjoy + +#### AOT mode + +Now that only Windows platform is supported, but migrating to other platforms is easy. + +1. Codegen + +Load WireShark mod into game, and enter the map once. The mod will write `impl.cpp` into your mod folder. + +2. Compile + +move the file `impl.cpp` to WireSharkLib folder and run cmake, release mode is suggested. + +3. Run + +move the `libWireSharkLib.dll` to your mod folder, **disable the WireShark mod** and load WireSharkRuntime mod into the game and enter the same map as which you run codegen on. \ No newline at end of file diff --git a/WireAccelerator.cs b/WireAccelerator.cs deleted file mode 100644 index eb5d051..0000000 --- a/WireAccelerator.cs +++ /dev/null @@ -1,460 +0,0 @@ -using Microsoft.Xna.Framework; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Terraria; -using Terraria.DataStructures; -using Terraria.GameContent.Events; -using Terraria.ID; -using Terraria.ModLoader; -using WireShark.Tiles; -using static System.Threading.Thread; -using static WireShark.WiringWrapper; - -namespace WireShark { - public static unsafe class WireAccelerator - { - private static readonly HashSet _sourceTable = new HashSet() { - 135, 314, 428, 442, 440, 136, 144, 441, 468, 132, 411, TileID.LogicGate, TileID.LogicSensor - }; - - private struct Node { - public int X, Y; - public int Dir; - public Node(int x, int y, int dir) { - X = x; - Y = y; - Dir = dir; - } - }; - - // D, U, R, L - private static readonly int[] dx = { 0, 0, 1, -1 }; - private static readonly int[] dy = { 1, -1, 0, 0 }; - public static TileInfo[][] _connectionInfos; - private static int[,,] _inputConnectedCompoents; - private static ConnectionQ[,,] _inputConnectedCompoentsQ; - - private static byte GetWireID(int X, int Y) { - var tile = Main.tile[X, Y]; - if (tile == null) return 0; - byte mask = 0; - if (tile.BlueWire) mask |= 1; - if (tile.GreenWire) mask |= 2; - if (tile.RedWire) mask |= 4; - if (tile.YellowWire) mask |= 8; - return mask; - } - - private static ConnectionQ now_number; - - static WireAccelerator() - { - now_number = new ConnectionQ - { - arr = Array.Empty(), - skipIndex = 0 - }; - } - - // internal static Point16 triggeredBy; - - [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - public static void Activate(int x, int y, int wire) - { - var info = _inputConnectedCompoentsQ[x, y, wire]; - - var k = 0; - for (; k < info.skipIndex; ++k) - info.arr[k].HitWire(); - for (++k; k < info.arr.Length; ++k) - info.arr[k].HitWire(); - } - - private static ConcurrentQueue> disposing = new(); - - [ThreadStatic] - private static Ref __vis; - - private static int[,,,] _vis - { - get - { - if (__vis?.Value == null) - { - var ___vis = new int[Main.maxTilesX, Main.maxTilesY, 4, 3]; - for (var i = 0; i < Main.maxTilesX; i++) - { - for (var j = 0; j < Main.maxTilesY; j++) - { - for (var k = 0; k < 4; k++) - { - ___vis[i, j, k, 0] = -1; - ___vis[i, j, k, 1] = -1; - ___vis[i, j, k, 2] = -1; - } - } - } - - __vis = new Ref(___vis); - disposing.Enqueue(__vis); - } - - return __vis.Value; - } - } - - private static int[,,] _visIndexCache; - private static byte[,] _wireCache; - private static TileInfo[,] _tileCache; - internal static bool noWireOrder = true; - - public static void Preprocess() - { - _inputConnectedCompoents = new int[Main.maxTilesX, Main.maxTilesY, 4]; - _inputConnectedCompoentsQ = new ConnectionQ[Main.maxTilesX, Main.maxTilesY, 4]; - _boxes = new (); - _pixelBoxMap = new(); - _visIndexCache = new int[Main.maxTilesX, Main.maxTilesY, 4]; - _tileCache = new TileInfo[Main.maxTilesX, Main.maxTilesY]; - _wireCache = new byte[Main.maxTilesX, Main.maxTilesY]; - - for (var i = 0; i < Main.maxTilesX; i++) { - for (var j = 0; j < Main.maxTilesY; j++) - { - _wireCache[i, j] = GetWireID(i, j); - for (var k = 0; k < 4; k++) - { - _inputConnectedCompoents[i, j, k] = -1; - - var curTile = Main.tile[i, j]; - var dir = k; - if (curTile != null) - { - if (curTile.TileType == TileID.WirePipe) - { - var s = GetWireBoxIndex(curTile, dir); - _visIndexCache[i, j, k] = s; - } - else if (curTile.TileType == TileID.PixelBox) - { - _visIndexCache[i, j, k] = dir / 2; - } - else - { - _visIndexCache[i, j, k] = 0; - } - } - } - } - - if (i % 100 == 0) Main.statusText = $"preprocess initializing {i * 1f / Main.maxTilesX:P1}"; - } - - var count = 0; - var tasks = new List<(int, int, int, int)>(); - - for (var j = 0; j < Main.maxTilesY; j++) - { - for (var i = 0; i < Main.maxTilesX; i++) { - if (Main.tile[i, j] != null) - { - if (!_sourceTable.Contains(Main.tile[i, j].TileType)) continue; - int wireid = _wireCache[i, j]; - if (wireid == 0) continue; - for (var k = 0; k < 4; k++) { - if (((wireid >> k) & 1) == 0) continue; - _inputConnectedCompoents[i, j, k] = count; - tasks.Add((count++, k, i, j)); - //var info = BFSWires(_connectionInfos.Count, k, i, j); - //_inputConnectedCompoents[i, j, k] = _connectionInfos.Count; - //_connectionInfos.Add(info); - } - - } - } - - if (j % 100 == 0) Main.statusText = $"generating tasks {j * 1f / Main.maxTilesY:P1}"; - } - - _connectionInfos = new TileInfo[count][]; - int finished = 0, total = tasks.Count; - new Thread(() => - { - while (finished != total) - { - if (finished > 0) - Main.statusText =$"preprocessing circuit {finished * 1f / total:P1}"; - Sleep(100); - } - }).Start(); - tasks.AsParallel().WithDegreeOfParallelism(threadCount).ForAll(task => - { - if (noWireOrder && _vis[task.Item3, task.Item4, task.Item2, 0] != -1) - _connectionInfos[task.Item1] = _connectionInfos[_vis[task.Item3, task.Item4, task.Item2, 0]]; - else - _connectionInfos[task.Item1] = BFSWires(_vis, task.Item1, task.Item2, task.Item3, task.Item4); - Interlocked.Increment(ref finished); - }); - - _tileCache = null; - _pixelBoxMap = null; - - foreach (var r in disposing) - r.Value = null; - disposing.Clear(); - _refreshedBoxes = new PixelBox[_boxes.Count]; - boxCount = 0; - _boxes = null; - - } - - private class ConnectionQ - { - public TileInfo[] arr; - public int skipIndex; - } - - - private static bool IsAppliance(int i, int j) { - var tile = Main.tile[i, j]; - var type = (int)tile.TileType; - if (ModContent.GetModTile(type) != null) - return true; - if (tile.HasActuator) return true; - if (!tile.HasTile) return false; - switch (type) - { - case 144: - case 421 when !tile.HasActuator: - case 422 when !tile.HasActuator: - case >= 255 and <= 268 when !tile.HasActuator: - case 419: - case 406: - case 452: - case 411: - case 425: - case 405: - case 209: - case 212: - case 215: - case 130: - case 131: - case 387: - case 386: - case 389: - case 388: - case 11: - case 10: - case 216: - case 497: - case 15 when tile.TileFrameY / 40 == 1: - case 15 when tile.TileFrameY / 40 == 20: - case 335: - case 338: - case 235: - case 4: - case 429: - case 149: - case 244: - case 565: - case 42: - case 93: - case 126: - case 95: - case 100: - case 173: - case 564: - case 593: - case 594: - case 34: - case 314: - case 33: - case 174: - case 49: - case 372: - case 92: - case 137: - case 443: - case 531: - case 139: - case 35: - case 207: - case 410: - case 480: - case 509: - case 455: - case 141: - case 210: - case 142: - case 143: - case 105: - case 349: - case 506: - case 546: - case 557: - return true; - } - return false; - } - - private static int GetWireBoxIndex2(Tile tile, int dir, int i) { - var frame = tile.TileFrameX / 18; - if (frame == 0) { - if (i != dir) return 0; - if (dir == 0 || dir == 1) return 1; - else return 2; - } else if (frame == 1) { - if ((dir == 0 && i != 3) || (dir == 3 && i != 0) || (dir == 1 && i != 2) || (dir == 2 && i != 1)) { - return 0; - } - if (dir == 0 || dir == 3) return 1; - else return 2; - } else { - if ((dir == 0 && i != 2) || (dir == 2 && i != 0) || (dir == 1 && i != 3) || (dir == 3 && i != 1)) { - return 0; - } - if (dir == 0 || dir == 3) return 1; - else return 2; - } - } - - private static int GetWireBoxIndex(Tile tile, int dir) { - var frame = tile.TileFrameX / 18; - if (frame == 0) { - if (dir == 0 || dir == 1) return 1; - else return 2; - } else if (frame == 1) { - if (dir == 0 || dir == 2) return 1; - else return 2; - } else { - if (dir == 0 || dir == 3) return 1; - else return 2; - } - } - - private static List _boxes; - public static PixelBox[] _refreshedBoxes; - public static int boxCount = 0; - private static Dictionary _pixelBoxMap; - internal static int threadCount = 1; - - private static TileInfo[] BFSWires(int[,,,] _vis, int id, int wireid, int x, int y) { - var Q = new Queue(); - Q.Enqueue(new Node(x, y, 0)); - var outputs = new List(); - var wirebit = 1 << wireid; - while (Q.Count > 0) { - var node = Q.Dequeue(); - //if (node.X == 2129 && node.Y == 282) Debugger.Break(); - // 到达当前点使用的是哪个方向 - var dir = node.Dir; - var curTile = Main.tile[node.X, node.Y]; - var index = _visIndexCache[node.X, node.Y, dir]; - - try - { - if (_vis[node.X, node.Y, wireid, index] == id) continue; - _vis[node.X, node.Y, wireid, index] = id; - } - catch (Exception e) - { - throw new Exception($"{node.X}, {node.Y}, {wireid}, {index}"); - } - - var pt = new Point16(node.X, node.Y); - - if (curTile.HasTile) { - if (Main.tile[node.X, node.Y].TileType == TileID.PixelBox) { - if (!_pixelBoxMap.TryGetValue(pt, out var box)) - _pixelBoxMap.Add(pt, box = new PixelBox() - { - tile = Main.tile[node.X, node.Y], - x = node.X, - y = node.Y - }); - _boxes.Add(box); - TileInfo tile = dir < 2 - ? new PixelBoxVertical(box, node.X, node.Y) - : new PixelBoxHorizontal(box, node.X, node.Y); - outputs.Add(tile); - _tileCache[node.X, node.Y] = tile; - } else if (_tileCache[node.X, node.Y] != null) - { - outputs.Add(_tileCache[node.X, node.Y]); - } - else if (IsAppliance(node.X, node.Y)) - { - var tile = TileInfo.CreateTileInfo(node.X, node.Y); - outputs.Add(tile); - _tileCache[node.X, node.Y] = tile; - } - } - - for (var i = 0; i < 4; i++) { - var nx = dx[i] + node.X; - var ny = dy[i] + node.Y; - if (nx < 2 || nx >= Main.maxTilesX - 2 || ny < 2 || ny >= Main.maxTilesY - 2) continue; - var tile = Main.tile[nx, ny]; - if (tile == null) continue; - if (curTile.TileType == TileID.WirePipe) { - if (GetWireBoxIndex2(curTile, dir, i) == 0) continue; - } else if (curTile.TileType == TileID.PixelBox) - { - if (dir != i) continue; - } - if ((_wireCache[nx, ny] & wirebit) != 0) { - Q.Enqueue(new Node(nx, ny, i)); - } - } - } - - return outputs.ToArray(); - } - - public static void Postprocess() - { - for (var i = 0; i < Main.maxTilesX; i++) - { - for (var j = 0; j < Main.maxTilesY; j++) - { - for (var k = 0; k < 4; k++) - { - if (_inputConnectedCompoents[i, j, k] == -1) - _inputConnectedCompoentsQ[i, j, k] = now_number; - else - { - var q = new ConnectionQ - { - arr = _connectionInfos[_inputConnectedCompoents[i, j, k]] - }; - - var t = 0; - for (; t < q.arr.Length; t++) - { - var info = q.arr[t]; - if (info.i == i && info.j == j) break; - } - q.skipIndex = t; - - _inputConnectedCompoentsQ[i, j, k] = q; - } - } - } - - if (i % 100 == 0) Main.statusText = $"caching {i * 1f / Main.maxTilesX:P1}"; - } - - _connectionInfos = null; - _inputConnectedCompoents = null; - } - } -} diff --git a/.gitattributes b/WireShark/.gitattributes similarity index 100% rename from .gitattributes rename to WireShark/.gitattributes diff --git a/.gitignore b/WireShark/.gitignore similarity index 100% rename from .gitignore rename to WireShark/.gitignore diff --git a/Items/Test.cs b/WireShark/Items/Test.cs similarity index 100% rename from Items/Test.cs rename to WireShark/Items/Test.cs diff --git a/Items/Test.png b/WireShark/Items/Test.png similarity index 100% rename from Items/Test.png rename to WireShark/Items/Test.png diff --git a/Localization/en-US_Mods.WireShark.hjson b/WireShark/Localization/en-US_Mods.WireShark.hjson similarity index 100% rename from Localization/en-US_Mods.WireShark.hjson rename to WireShark/Localization/en-US_Mods.WireShark.hjson diff --git a/LogicGate.cs b/WireShark/LogicGate.cs similarity index 85% rename from LogicGate.cs rename to WireShark/LogicGate.cs index ea5c3f0..e630be4 100644 --- a/LogicGate.cs +++ b/WireShark/LogicGate.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Terraria; using Terraria.DataStructures; using Terraria.GameContent.Events; @@ -26,7 +27,7 @@ public enum PixelBoxState internal abstract class PixelBoxBase : TileInfo { - protected PixelBox box; + public PixelBox box; protected PixelBoxBase(PixelBox box, int i, int j) { this.box = box; @@ -68,13 +69,19 @@ public PixelBoxHorizontal(PixelBox box, int i, int j) : base(box, i, j) } } - internal abstract class LogicGate + internal abstract unsafe class LogicGate { - public int lampon, x, y; + public int x, y; public Tile mapTile; public int lamptotal; + public int* lampon = (int*) Marshal.AllocHGlobal(sizeof(int)); public bool erroronly = false; public abstract void UpdateLogicGate(); + + ~LogicGate() + { + Marshal.FreeHGlobal((IntPtr) lampon); + } } } diff --git a/Properties/launchSettings.json b/WireShark/Properties/launchSettings.json similarity index 96% rename from Properties/launchSettings.json rename to WireShark/Properties/launchSettings.json index 07e2f8d..8da89ff 100644 --- a/Properties/launchSettings.json +++ b/WireShark/Properties/launchSettings.json @@ -1,16 +1,16 @@ -{ - "profiles": { - "Terraria": { - "commandName": "Executable", - "executablePath": "dotnet", - "commandLineArgs": "$(tMLPath)", - "workingDirectory": "$(tMLSteamPath)" - }, - "TerrariaServer": { - "commandName": "Executable", - "executablePath": "dotnet", - "commandLineArgs": "$(tMLServerPath)", - "workingDirectory": "$(tMLSteamPath)" - } - } +{ + "profiles": { + "Terraria": { + "commandName": "Executable", + "executablePath": "dotnet", + "commandLineArgs": "$(tMLPath)", + "workingDirectory": "$(tMLSteamPath)" + }, + "TerrariaServer": { + "commandName": "Executable", + "executablePath": "dotnet", + "commandLineArgs": "$(tMLServerPath)", + "workingDirectory": "$(tMLSteamPath)" + } + } } \ No newline at end of file diff --git a/QuickLinkedList.cs b/WireShark/QuickLinkedList.cs similarity index 86% rename from QuickLinkedList.cs rename to WireShark/QuickLinkedList.cs index 44980a6..86f9b67 100644 --- a/QuickLinkedList.cs +++ b/WireShark/QuickLinkedList.cs @@ -9,14 +9,13 @@ namespace WireShark { - internal unsafe class QuickLinkedList + internal unsafe struct QuickLinkedList { public readonly T* cachePtr = (T*) Marshal.AllocHGlobal(1024 * 1024 * 10 * sizeof(T)); private int tail = 0; - - ~QuickLinkedList() + + public QuickLinkedList() { - Marshal.FreeHGlobal((IntPtr) cachePtr); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/TileInfo.cs b/WireShark/TileInfo.cs similarity index 95% rename from TileInfo.cs rename to WireShark/TileInfo.cs index 1481b3f..87b4763 100644 --- a/TileInfo.cs +++ b/WireShark/TileInfo.cs @@ -1,148 +1,148 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using SteelSeries.GameSense.DeviceZone; -using Terraria; -using Terraria.DataStructures; -using Terraria.ModLoader; - -namespace WireShark -{ - public abstract class TileInfo - { - private class ModTileInfo : TileInfo - { - private readonly ModTile _modTile; - public ModTileInfo(ModTile tile) - { - _modTile = tile; - } - - protected override void HitWireInternal() - { - if (tile.HasActuator) - WiringWrapper.ActuateForced(i, j); - _modTile.HitWire(i, j); - } - } - - private class ActuatorTile : TileInfo - { - protected override void HitWireInternal() - { - if (tile.HasActuator) - WiringWrapper.ActuateForced(i, j); - } - } - - public override string ToString() - { - return $"{tile}@({i},{j})"; - } - - public int i, j; - public long hash; - - public ushort type - { - get => tile.TileType; - set => tile.TileType = value; - } - - public Tile tile; - - private static Dictionary tileinfo = new Dictionary(); - - - static TileInfo() - { - foreach (var type in typeof(TileInfo).Assembly.GetTypes()) - { - if (!typeof(TileInfo).IsAssignableFrom(type) || type.IsAbstract) continue; - var name = type.Name; - if (int.TryParse(name.Substring(4), out var id)) - tileinfo.Add(id, type); - } - } - - public static TileInfo CreateTileInfo(int x, int y) - { - TileInfo result; - var mtile = ModContent.GetModTile(Main.tile[x, y].TileType); - if (mtile != null) - { - result = new ModTileInfo(mtile); - } - else if (tileinfo.TryGetValue(Main.tile[x, y].TileType, out var t)) - { - result = Activator.CreateInstance(t) as TileInfo; - } - else - { - result = new ActuatorTile(); - } - - result.tile = Main.tile[x, y]; - result.i = x; - result.j = y; - result.hash = ((long) x << 32) + y; - return result; - } - - protected abstract void HitWireInternal(); - - [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - public void HitWire() - { - HitWireInternal(); - } - } -} -/* -if (TileLoader.CloseDoorID(Main.tile[i, j]) >= 0) -{ - if (WorldGen.CloseDoor(i, j, true)) return; -} -else if (TileLoader.OpenDoorID(Main.tile[i, j]) >= 0) -{ - int num66 = 1; - if (Main.rand.Next(2) == 0) - { - num66 = -1; - } - - if (WorldGen.OpenDoor(i, j, num66)) - { - return; - } - - if (WorldGen.OpenDoor(i, j, -num66)) - { - return; - } -} -else if (TileLoader.IsTorch(type)) -{ - if (tile.frameX < 66) - { - Tile tile4 = tile; - tile4.frameX += 66; - } - else - { - Tile tile5 = tile; - tile5.frameX -= 66; - } - - return; -} -else if (TileLoader.IsModMusicBox(tile)) -{ - WorldGen.SwitchMB(i, j); - return; -} -*/ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using SteelSeries.GameSense.DeviceZone; +using Terraria; +using Terraria.DataStructures; +using Terraria.ModLoader; + +namespace WireShark +{ + public abstract class TileInfo + { + private class ModTileInfo : TileInfo + { + private readonly ModTile _modTile; + public ModTileInfo(ModTile tile) + { + _modTile = tile; + } + + protected override void HitWireInternal() + { + if (tile.HasActuator) + WiringWrapper.ActuateForced(i, j); + _modTile.HitWire(i, j); + } + } + + private class ActuatorTile : TileInfo + { + protected override void HitWireInternal() + { + if (tile.HasActuator) + WiringWrapper.ActuateForced(i, j); + } + } + + public override string ToString() + { + return $"{tile}@({i},{j})"; + } + + public int i, j; + public long hash; + + public ushort type + { + get => tile.TileType; + set => tile.TileType = value; + } + + public Tile tile; + + private static Dictionary tileinfo = new Dictionary(); + + + static TileInfo() + { + foreach (var type in typeof(TileInfo).Assembly.GetTypes()) + { + if (!typeof(TileInfo).IsAssignableFrom(type) || type.IsAbstract) continue; + var name = type.Name; + if (int.TryParse(name.Substring(4), out var id)) + tileinfo.Add(id, type); + } + } + + public static TileInfo CreateTileInfo(int x, int y) + { + TileInfo result; + var mtile = ModContent.GetModTile(Main.tile[x, y].TileType); + if (mtile != null) + { + result = new ModTileInfo(mtile); + } + else if (tileinfo.TryGetValue(Main.tile[x, y].TileType, out var t)) + { + result = Activator.CreateInstance(t) as TileInfo; + } + else + { + result = new ActuatorTile(); + } + + result.tile = Main.tile[x, y]; + result.i = x; + result.j = y; + result.hash = ((long) x << 32) + y; + return result; + } + + protected abstract void HitWireInternal(); + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + public void HitWire() + { + HitWireInternal(); + } + } +} +/* +if (TileLoader.CloseDoorID(Main.tile[i, j]) >= 0) +{ + if (WorldGen.CloseDoor(i, j, true)) return; +} +else if (TileLoader.OpenDoorID(Main.tile[i, j]) >= 0) +{ + int num66 = 1; + if (Main.rand.Next(2) == 0) + { + num66 = -1; + } + + if (WorldGen.OpenDoor(i, j, num66)) + { + return; + } + + if (WorldGen.OpenDoor(i, j, -num66)) + { + return; + } +} +else if (TileLoader.IsTorch(type)) +{ + if (tile.frameX < 66) + { + Tile tile4 = tile; + tile4.frameX += 66; + } + else + { + Tile tile5 = tile; + tile5.frameX -= 66; + } + + return; +} +else if (TileLoader.IsModMusicBox(tile)) +{ + WorldGen.SwitchMB(i, j); + return; +} +*/ diff --git a/Tiles/Tile100.cs b/WireShark/Tiles/Tile100.cs similarity index 100% rename from Tiles/Tile100.cs rename to WireShark/Tiles/Tile100.cs diff --git a/Tiles/Tile105.cs b/WireShark/Tiles/Tile105.cs similarity index 99% rename from Tiles/Tile105.cs rename to WireShark/Tiles/Tile105.cs index 09e55c0..13c67bb 100644 --- a/Tiles/Tile105.cs +++ b/WireShark/Tiles/Tile105.cs @@ -385,11 +385,11 @@ protected override void HitWireInternal() Main.npc[num141].type == NPCID.Mechanic || Main.npc[num141].type == NPCID.Steampunker || Main.npc[num141].type == NPCID.PartyGirl || - Main.npc[num141].type == NPCID.Stylist; - if (Main.npc[num141].active && NPCLoader.CanGoToStatue(Main.npc[num141], false).HasValue) - { - array2.Add(num141); - num140++; + Main.npc[num141].type == NPCID.Stylist; + if (Main.npc[num141].active && NPCLoader.CanGoToStatue(Main.npc[num141], false).HasValue) + { + array2.Add(num141); + num140++; } } diff --git a/Tiles/Tile126.cs b/WireShark/Tiles/Tile126.cs similarity index 100% rename from Tiles/Tile126.cs rename to WireShark/Tiles/Tile126.cs diff --git a/Tiles/Tile130.cs b/WireShark/Tiles/Tile130.cs similarity index 100% rename from Tiles/Tile130.cs rename to WireShark/Tiles/Tile130.cs diff --git a/Tiles/Tile131.cs b/WireShark/Tiles/Tile131.cs similarity index 100% rename from Tiles/Tile131.cs rename to WireShark/Tiles/Tile131.cs diff --git a/Tiles/Tile137.cs b/WireShark/Tiles/Tile137.cs similarity index 100% rename from Tiles/Tile137.cs rename to WireShark/Tiles/Tile137.cs diff --git a/Tiles/Tile139.cs b/WireShark/Tiles/Tile139.cs similarity index 100% rename from Tiles/Tile139.cs rename to WireShark/Tiles/Tile139.cs diff --git a/Tiles/Tile141.cs b/WireShark/Tiles/Tile141.cs similarity index 100% rename from Tiles/Tile141.cs rename to WireShark/Tiles/Tile141.cs diff --git a/Tiles/Tile142.cs b/WireShark/Tiles/Tile142.cs similarity index 100% rename from Tiles/Tile142.cs rename to WireShark/Tiles/Tile142.cs diff --git a/Tiles/Tile143.cs b/WireShark/Tiles/Tile143.cs similarity index 100% rename from Tiles/Tile143.cs rename to WireShark/Tiles/Tile143.cs diff --git a/Tiles/Tile144.cs b/WireShark/Tiles/Tile144.cs similarity index 100% rename from Tiles/Tile144.cs rename to WireShark/Tiles/Tile144.cs diff --git a/Tiles/Tile149.cs b/WireShark/Tiles/Tile149.cs similarity index 100% rename from Tiles/Tile149.cs rename to WireShark/Tiles/Tile149.cs diff --git a/Tiles/Tile173.cs b/WireShark/Tiles/Tile173.cs similarity index 100% rename from Tiles/Tile173.cs rename to WireShark/Tiles/Tile173.cs diff --git a/Tiles/Tile174.cs b/WireShark/Tiles/Tile174.cs similarity index 100% rename from Tiles/Tile174.cs rename to WireShark/Tiles/Tile174.cs diff --git a/Tiles/Tile207.cs b/WireShark/Tiles/Tile207.cs similarity index 100% rename from Tiles/Tile207.cs rename to WireShark/Tiles/Tile207.cs diff --git a/Tiles/Tile209.cs b/WireShark/Tiles/Tile209.cs similarity index 100% rename from Tiles/Tile209.cs rename to WireShark/Tiles/Tile209.cs diff --git a/Tiles/Tile210.cs b/WireShark/Tiles/Tile210.cs similarity index 100% rename from Tiles/Tile210.cs rename to WireShark/Tiles/Tile210.cs diff --git a/Tiles/Tile212.cs b/WireShark/Tiles/Tile212.cs similarity index 100% rename from Tiles/Tile212.cs rename to WireShark/Tiles/Tile212.cs diff --git a/Tiles/Tile215.cs b/WireShark/Tiles/Tile215.cs similarity index 100% rename from Tiles/Tile215.cs rename to WireShark/Tiles/Tile215.cs diff --git a/Tiles/Tile216.cs b/WireShark/Tiles/Tile216.cs similarity index 100% rename from Tiles/Tile216.cs rename to WireShark/Tiles/Tile216.cs diff --git a/Tiles/Tile235.cs b/WireShark/Tiles/Tile235.cs similarity index 100% rename from Tiles/Tile235.cs rename to WireShark/Tiles/Tile235.cs diff --git a/Tiles/Tile244.cs b/WireShark/Tiles/Tile244.cs similarity index 100% rename from Tiles/Tile244.cs rename to WireShark/Tiles/Tile244.cs diff --git a/Tiles/Tile255.cs b/WireShark/Tiles/Tile255.cs similarity index 100% rename from Tiles/Tile255.cs rename to WireShark/Tiles/Tile255.cs diff --git a/Tiles/Tile256.cs b/WireShark/Tiles/Tile256.cs similarity index 100% rename from Tiles/Tile256.cs rename to WireShark/Tiles/Tile256.cs diff --git a/Tiles/Tile257.cs b/WireShark/Tiles/Tile257.cs similarity index 100% rename from Tiles/Tile257.cs rename to WireShark/Tiles/Tile257.cs diff --git a/Tiles/Tile258.cs b/WireShark/Tiles/Tile258.cs similarity index 100% rename from Tiles/Tile258.cs rename to WireShark/Tiles/Tile258.cs diff --git a/Tiles/Tile259.cs b/WireShark/Tiles/Tile259.cs similarity index 100% rename from Tiles/Tile259.cs rename to WireShark/Tiles/Tile259.cs diff --git a/Tiles/Tile260.cs b/WireShark/Tiles/Tile260.cs similarity index 100% rename from Tiles/Tile260.cs rename to WireShark/Tiles/Tile260.cs diff --git a/Tiles/Tile261.cs b/WireShark/Tiles/Tile261.cs similarity index 100% rename from Tiles/Tile261.cs rename to WireShark/Tiles/Tile261.cs diff --git a/Tiles/Tile262.cs b/WireShark/Tiles/Tile262.cs similarity index 100% rename from Tiles/Tile262.cs rename to WireShark/Tiles/Tile262.cs diff --git a/Tiles/Tile263.cs b/WireShark/Tiles/Tile263.cs similarity index 100% rename from Tiles/Tile263.cs rename to WireShark/Tiles/Tile263.cs diff --git a/Tiles/Tile264.cs b/WireShark/Tiles/Tile264.cs similarity index 100% rename from Tiles/Tile264.cs rename to WireShark/Tiles/Tile264.cs diff --git a/Tiles/Tile265.cs b/WireShark/Tiles/Tile265.cs similarity index 100% rename from Tiles/Tile265.cs rename to WireShark/Tiles/Tile265.cs diff --git a/Tiles/Tile266.cs b/WireShark/Tiles/Tile266.cs similarity index 100% rename from Tiles/Tile266.cs rename to WireShark/Tiles/Tile266.cs diff --git a/Tiles/Tile267.cs b/WireShark/Tiles/Tile267.cs similarity index 100% rename from Tiles/Tile267.cs rename to WireShark/Tiles/Tile267.cs diff --git a/Tiles/Tile268.cs b/WireShark/Tiles/Tile268.cs similarity index 100% rename from Tiles/Tile268.cs rename to WireShark/Tiles/Tile268.cs diff --git a/Tiles/Tile314.cs b/WireShark/Tiles/Tile314.cs similarity index 100% rename from Tiles/Tile314.cs rename to WireShark/Tiles/Tile314.cs diff --git a/Tiles/Tile33.cs b/WireShark/Tiles/Tile33.cs similarity index 100% rename from Tiles/Tile33.cs rename to WireShark/Tiles/Tile33.cs diff --git a/Tiles/Tile335.cs b/WireShark/Tiles/Tile335.cs similarity index 100% rename from Tiles/Tile335.cs rename to WireShark/Tiles/Tile335.cs diff --git a/Tiles/Tile338.cs b/WireShark/Tiles/Tile338.cs similarity index 100% rename from Tiles/Tile338.cs rename to WireShark/Tiles/Tile338.cs diff --git a/Tiles/Tile34.cs b/WireShark/Tiles/Tile34.cs similarity index 100% rename from Tiles/Tile34.cs rename to WireShark/Tiles/Tile34.cs diff --git a/Tiles/Tile349.cs b/WireShark/Tiles/Tile349.cs similarity index 100% rename from Tiles/Tile349.cs rename to WireShark/Tiles/Tile349.cs diff --git a/Tiles/Tile35.cs b/WireShark/Tiles/Tile35.cs similarity index 100% rename from Tiles/Tile35.cs rename to WireShark/Tiles/Tile35.cs diff --git a/Tiles/Tile386.cs b/WireShark/Tiles/Tile386.cs similarity index 100% rename from Tiles/Tile386.cs rename to WireShark/Tiles/Tile386.cs diff --git a/Tiles/Tile387.cs b/WireShark/Tiles/Tile387.cs similarity index 100% rename from Tiles/Tile387.cs rename to WireShark/Tiles/Tile387.cs diff --git a/Tiles/Tile388.cs b/WireShark/Tiles/Tile388.cs similarity index 100% rename from Tiles/Tile388.cs rename to WireShark/Tiles/Tile388.cs diff --git a/Tiles/Tile389.cs b/WireShark/Tiles/Tile389.cs similarity index 100% rename from Tiles/Tile389.cs rename to WireShark/Tiles/Tile389.cs diff --git a/Tiles/Tile4.cs b/WireShark/Tiles/Tile4.cs similarity index 100% rename from Tiles/Tile4.cs rename to WireShark/Tiles/Tile4.cs diff --git a/Tiles/Tile405.cs b/WireShark/Tiles/Tile405.cs similarity index 100% rename from Tiles/Tile405.cs rename to WireShark/Tiles/Tile405.cs diff --git a/Tiles/Tile406.cs b/WireShark/Tiles/Tile406.cs similarity index 100% rename from Tiles/Tile406.cs rename to WireShark/Tiles/Tile406.cs diff --git a/Tiles/Tile410.cs b/WireShark/Tiles/Tile410.cs similarity index 100% rename from Tiles/Tile410.cs rename to WireShark/Tiles/Tile410.cs diff --git a/Tiles/Tile411.cs b/WireShark/Tiles/Tile411.cs similarity index 100% rename from Tiles/Tile411.cs rename to WireShark/Tiles/Tile411.cs diff --git a/Tiles/Tile419.cs b/WireShark/Tiles/Tile419.cs similarity index 72% rename from Tiles/Tile419.cs rename to WireShark/Tiles/Tile419.cs index 23da063..ce4d675 100644 --- a/Tiles/Tile419.cs +++ b/WireShark/Tiles/Tile419.cs @@ -1,5 +1,7 @@ using System; +using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace WireShark.Tiles; @@ -16,13 +18,8 @@ public unsafe class Tile419Normal : Tile419 [MethodImpl(MethodImplOptions.AggressiveOptimization)] protected override void HitWireInternal() { - //lgate.lampon += (add = -add); - //WiringWrapper._LampsToCheck.AddLast(lgate); - - var frame = (short)(18 - *frameX); - lgate.lampon += frame == 18 ? 1 : -1; + *lampon += add = -add; WiringWrapper._LampsToCheck.AddLast(lgate); - *frameX = frame; } } public unsafe class Tile419NormalOnError : Tile419 @@ -30,11 +27,15 @@ public unsafe class Tile419NormalOnError : Tile419 [MethodImpl(MethodImplOptions.AggressiveOptimization)] protected override void HitWireInternal() { - //lgate.lampon += (add = -add); - - var frame = (short) (18 - *frameX); - lgate.lampon += frame == 18 ? 1 : -1; - *frameX = frame; + *lampon += add = -add; + } +} +public unsafe class Tile419NormalOnOneError : Tile419 +{ + [MethodImpl(MethodImplOptions.AggressiveOptimization)] + protected override void HitWireInternal() + { + *lampon = 1 - *lampon; } } public unsafe class Tile419NormalUnconnected : Tile419 @@ -57,10 +58,17 @@ protected override void HitWireInternal() public unsafe class Tile419 : TileInfo { internal LogicGate lgate; - internal short* frameX; + // internal short* frameX; + internal int* lampon; + internal GCHandle? handle; internal int add; protected override void HitWireInternal() { throw new NotImplementedException(); } + + ~Tile419() + { + handle?.Free(); + } } \ No newline at end of file diff --git a/Tiles/Tile42.cs b/WireShark/Tiles/Tile42.cs similarity index 100% rename from Tiles/Tile42.cs rename to WireShark/Tiles/Tile42.cs diff --git a/Tiles/Tile421.cs b/WireShark/Tiles/Tile421.cs similarity index 100% rename from Tiles/Tile421.cs rename to WireShark/Tiles/Tile421.cs diff --git a/Tiles/Tile422.cs b/WireShark/Tiles/Tile422.cs similarity index 100% rename from Tiles/Tile422.cs rename to WireShark/Tiles/Tile422.cs diff --git a/Tiles/Tile425.cs b/WireShark/Tiles/Tile425.cs similarity index 100% rename from Tiles/Tile425.cs rename to WireShark/Tiles/Tile425.cs diff --git a/Tiles/Tile429.cs b/WireShark/Tiles/Tile429.cs similarity index 100% rename from Tiles/Tile429.cs rename to WireShark/Tiles/Tile429.cs diff --git a/Tiles/Tile443.cs b/WireShark/Tiles/Tile443.cs similarity index 100% rename from Tiles/Tile443.cs rename to WireShark/Tiles/Tile443.cs diff --git a/Tiles/Tile452.cs b/WireShark/Tiles/Tile452.cs similarity index 100% rename from Tiles/Tile452.cs rename to WireShark/Tiles/Tile452.cs diff --git a/Tiles/Tile455.cs b/WireShark/Tiles/Tile455.cs similarity index 100% rename from Tiles/Tile455.cs rename to WireShark/Tiles/Tile455.cs diff --git a/Tiles/Tile92.cs b/WireShark/Tiles/Tile92.cs similarity index 100% rename from Tiles/Tile92.cs rename to WireShark/Tiles/Tile92.cs diff --git a/Tiles/Tile93.cs b/WireShark/Tiles/Tile93.cs similarity index 100% rename from Tiles/Tile93.cs rename to WireShark/Tiles/Tile93.cs diff --git a/Tiles/Tile95.cs b/WireShark/Tiles/Tile95.cs similarity index 100% rename from Tiles/Tile95.cs rename to WireShark/Tiles/Tile95.cs diff --git a/WireShark/WireAccelerator.cs b/WireShark/WireAccelerator.cs new file mode 100644 index 0000000..aeaa256 --- /dev/null +++ b/WireShark/WireAccelerator.cs @@ -0,0 +1,999 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent.Events; +using Terraria.ID; +using Terraria.ModLoader; +using WireShark.Tiles; +using static System.Net.WebRequestMethods; +using static System.Threading.Thread; +using static WireShark.WiringWrapper; + +namespace WireShark +{ + public static unsafe class WireAccelerator + { + private static readonly HashSet _sourceTable = new HashSet() + { + 135, 314, 428, 442, 440, 136, 144, 441, 468, 132, 411, TileID.LogicGate, TileID.LogicSensor + }; + + private struct Node + { + public int X, Y; + public int Dir; + + public Node(int x, int y, int dir) + { + X = x; + Y = y; + Dir = dir; + } + }; + + // D, U, R, L + private static readonly int[] dx = {0, 0, 1, -1}; + private static readonly int[] dy = {1, -1, 0, 0}; + public static TileInfo[][] _connectionInfos; + private static int[,,] _inputConnectedCompoents; + private static ConnectionQ[,,] _inputConnectedCompoentsQ; + + private static byte GetWireID(int X, int Y) + { + var tile = Main.tile[X, Y]; + if (tile == null) return 0; + byte mask = 0; + if (tile.BlueWire) mask |= 1; + if (tile.GreenWire) mask |= 2; + if (tile.RedWire) mask |= 4; + if (tile.YellowWire) mask |= 8; + return mask; + } + + private static ConnectionQ now_number; + + static WireAccelerator() + { + now_number = new ConnectionQ + { + arr = Array.Empty(), + skipIndex = 0 + }; + } + + // internal static Point16 triggeredBy; + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + public static void Activate(int x, int y, int wire) + { + var info = _inputConnectedCompoentsQ[x, y, wire]; + + var k = 0; + for (; k < info.skipIndex; ++k) + info.arr[k].HitWire(); + for (++k; k < info.arr.Length; ++k) + info.arr[k].HitWire(); + } + + private static ConcurrentQueue> disposing = new(); + + [ThreadStatic] private static Ref __vis; + + private static int[,,,] _vis + { + get + { + if (__vis?.Value == null) + { + var ___vis = new int[Main.maxTilesX, Main.maxTilesY, 4, 3]; + for (var i = 0; i < Main.maxTilesX; i++) + { + for (var j = 0; j < Main.maxTilesY; j++) + { + for (var k = 0; k < 4; k++) + { + ___vis[i, j, k, 0] = -1; + ___vis[i, j, k, 1] = -1; + ___vis[i, j, k, 2] = -1; + } + } + } + + __vis = new Ref(___vis); + disposing.Enqueue(__vis); + } + + return __vis.Value; + } + } + + private static int[,,] _visIndexCache; + private static byte[,] _wireCache; + private static TileInfo[,] _tileCache; + internal static bool noWireOrder = true; + + public static void Preprocess() + { + _inputConnectedCompoents = new int[Main.maxTilesX, Main.maxTilesY, 4]; + _inputConnectedCompoentsQ = new ConnectionQ[Main.maxTilesX, Main.maxTilesY, 4]; + _boxes = new(); + _pixelBoxMap = new(); + _visIndexCache = new int[Main.maxTilesX, Main.maxTilesY, 4]; + _tileCache = new TileInfo[Main.maxTilesX, Main.maxTilesY]; + _wireCache = new byte[Main.maxTilesX, Main.maxTilesY]; + + for (var i = 0; i < Main.maxTilesX; i++) + { + for (var j = 0; j < Main.maxTilesY; j++) + { + _wireCache[i, j] = GetWireID(i, j); + for (var k = 0; k < 4; k++) + { + _inputConnectedCompoents[i, j, k] = -1; + + var curTile = Main.tile[i, j]; + var dir = k; + if (curTile != null) + { + if (curTile.TileType == TileID.WirePipe) + { + var s = GetWireBoxIndex(curTile, dir); + _visIndexCache[i, j, k] = s; + } + else if (curTile.TileType == TileID.PixelBox) + { + _visIndexCache[i, j, k] = dir / 2; + } + else + { + _visIndexCache[i, j, k] = 0; + } + } + } + } + + if (i % 100 == 0) Main.statusText = $"preprocess initializing {i * 1f / Main.maxTilesX:P1}"; + } + + var count = 0; + + var tasks = new List<(int, int, int, int)>(); + + for (var j = 0; j < Main.maxTilesY; j++) + { + for (var i = 0; i < Main.maxTilesX; i++) + { + if (Main.tile[i, j] != null) + { + if (!_sourceTable.Contains(Main.tile[i, j].TileType)) continue; + int wireid = _wireCache[i, j]; + if (wireid == 0) continue; + for (var k = 0; k < 4; k++) + { + if (((wireid >> k) & 1) == 0) continue; + _inputConnectedCompoents[i, j, k] = count; + tasks.Add((count++, k, i, j)); + //var info = BFSWires(_connectionInfos.Count, k, i, j); + //_inputConnectedCompoents[i, j, k] = _connectionInfos.Count; + //_connectionInfos.Add(info); + } + + } + } + + if (j % 100 == 0) Main.statusText = $"generating tasks {j * 1f / Main.maxTilesY:P1}"; + } + + _connectionInfos = new TileInfo[count][]; + int finished = 0, total = tasks.Count; + new Thread(() => + { + while (finished != total) + { + if (finished > 0) + Main.statusText = $"preprocessing circuit {finished * 1f / total:P1}"; + Sleep(100); + } + }).Start(); + tasks.AsParallel().WithDegreeOfParallelism(threadCount).ForAll(task => + { + if (noWireOrder && _vis[task.Item3, task.Item4, task.Item2, 0] != -1) + _connectionInfos[task.Item1] = _connectionInfos[_vis[task.Item3, task.Item4, task.Item2, 0]]; + else + _connectionInfos[task.Item1] = BFSWires(_vis, task.Item1, task.Item2, task.Item3, task.Item4); + Interlocked.Increment(ref finished); + }); + + _tileCache = null; + _pixelBoxMap = null; + + foreach (var r in disposing) + r.Value = null; + disposing.Clear(); + _refreshedBoxes = new PixelBox[_boxes.Count]; + boxCount = 0; + _boxes = null; + + } + + private class ConnectionQ + { + public TileInfo[] arr; + public int skipIndex; + } + + + private static bool IsAppliance(int i, int j) + { + var tile = Main.tile[i, j]; + var type = (int) tile.TileType; + if (ModContent.GetModTile(type) != null) + return true; + if (tile.HasActuator) return true; + if (!tile.HasTile) return false; + switch (type) + { + case 144: + case 421 when !tile.HasActuator: + case 422 when !tile.HasActuator: + case >= 255 and <= 268 when !tile.HasActuator: + case 419: + case 406: + case 452: + case 411: + case 425: + case 405: + case 209: + case 212: + case 215: + case 130: + case 131: + case 387: + case 386: + case 389: + case 388: + case 11: + case 10: + case 216: + case 497: + case 15 when tile.TileFrameY / 40 == 1: + case 15 when tile.TileFrameY / 40 == 20: + case 335: + case 338: + case 235: + case 4: + case 429: + case 149: + case 244: + case 565: + case 42: + case 93: + case 126: + case 95: + case 100: + case 173: + case 564: + case 593: + case 594: + case 34: + case 314: + case 33: + case 174: + case 49: + case 372: + case 92: + case 137: + case 443: + case 531: + case 139: + case 35: + case 207: + case 410: + case 480: + case 509: + case 455: + case 141: + case 210: + case 142: + case 143: + case 105: + case 349: + case 506: + case 546: + case 557: + return true; + } + + return false; + } + + private static int GetWireBoxIndex2(Tile tile, int dir, int i) + { + var frame = tile.TileFrameX / 18; + if (frame == 0) + { + if (i != dir) return 0; + if (dir == 0 || dir == 1) return 1; + else return 2; + } + else if (frame == 1) + { + if ((dir == 0 && i != 3) || (dir == 3 && i != 0) || (dir == 1 && i != 2) || (dir == 2 && i != 1)) + { + return 0; + } + + if (dir == 0 || dir == 3) return 1; + else return 2; + } + else + { + if ((dir == 0 && i != 2) || (dir == 2 && i != 0) || (dir == 1 && i != 3) || (dir == 3 && i != 1)) + { + return 0; + } + + if (dir == 0 || dir == 3) return 1; + else return 2; + } + } + + private static int GetWireBoxIndex(Tile tile, int dir) + { + var frame = tile.TileFrameX / 18; + if (frame == 0) + { + if (dir == 0 || dir == 1) return 1; + else return 2; + } + else if (frame == 1) + { + if (dir == 0 || dir == 2) return 1; + else return 2; + } + else + { + if (dir == 0 || dir == 3) return 1; + else return 2; + } + } + + private static List _boxes; + public static PixelBox[] _refreshedBoxes; + public static int boxCount = 0; + private static Dictionary _pixelBoxMap; + internal static int threadCount = 1; + + private static TileInfo[] BFSWires(int[,,,] _vis, int id, int wireid, int x, int y) + { + var Q = new Queue(); + Q.Enqueue(new Node(x, y, 0)); + var outputs = new List(); + var wirebit = 1 << wireid; + while (Q.Count > 0) + { + var node = Q.Dequeue(); + //if (node.X == 2129 && node.Y == 282) Debugger.Break(); + // 到达当前点使用的是哪个方向 + var dir = node.Dir; + var curTile = Main.tile[node.X, node.Y]; + var index = _visIndexCache[node.X, node.Y, dir]; + + try + { + if (_vis[node.X, node.Y, wireid, index] == id) continue; + _vis[node.X, node.Y, wireid, index] = id; + } + catch (Exception e) + { + throw new Exception($"{node.X}, {node.Y}, {wireid}, {index}"); + } + + var pt = new Point16(node.X, node.Y); + + if (curTile.HasTile) + { + if (Main.tile[node.X, node.Y].TileType == TileID.PixelBox) + { + if (!_pixelBoxMap.TryGetValue(pt, out var box)) + _pixelBoxMap.Add(pt, box = new PixelBox() + { + tile = Main.tile[node.X, node.Y], + x = node.X, + y = node.Y + }); + _boxes.Add(box); + TileInfo tile = dir < 2 + ? new PixelBoxVertical(box, node.X, node.Y) + : new PixelBoxHorizontal(box, node.X, node.Y); + outputs.Add(tile); + _tileCache[node.X, node.Y] = tile; + } + else if (_tileCache[node.X, node.Y] != null) + { + outputs.Add(_tileCache[node.X, node.Y]); + } + else if (IsAppliance(node.X, node.Y)) + { + var tile = TileInfo.CreateTileInfo(node.X, node.Y); + outputs.Add(tile); + _tileCache[node.X, node.Y] = tile; + } + } + + for (var i = 0; i < 4; i++) + { + var nx = dx[i] + node.X; + var ny = dy[i] + node.Y; + if (nx < 2 || nx >= Main.maxTilesX - 2 || ny < 2 || ny >= Main.maxTilesY - 2) continue; + var tile = Main.tile[nx, ny]; + if (tile == null) continue; + if (curTile.TileType == TileID.WirePipe) + { + if (GetWireBoxIndex2(curTile, dir, i) == 0) continue; + } + else if (curTile.TileType == TileID.PixelBox) + { + if (dir != i) continue; + } + + if ((_wireCache[nx, ny] & wirebit) != 0) + { + Q.Enqueue(new Node(nx, ny, i)); + } + } + } + + return outputs.ToArray(); + } + + public static void Postprocess() + { + for (var i = 0; i < Main.maxTilesX; i++) + { + for (var j = 0; j < Main.maxTilesY; j++) + { + for (var k = 0; k < 4; k++) + { + if (_inputConnectedCompoents[i, j, k] == -1) + _inputConnectedCompoentsQ[i, j, k] = now_number; + else + { + var q = new ConnectionQ + { + arr = _connectionInfos[_inputConnectedCompoents[i, j, k]] + }; + + var t = 0; + for (; t < q.arr.Length; t++) + { + var info = q.arr[t]; + if (info.i == i && info.j == j) break; + } + + q.skipIndex = t; + + _inputConnectedCompoentsQ[i, j, k] = q; + } + } + } + + if (i % 100 == 0) Main.statusText = $"caching {i * 1f / Main.maxTilesX:P1}"; + } + + using var sw = new StreamWriter(new FileStream( + Path.Combine(ModLoader.ModPath, "impl.cpp"), + FileMode.Create, FileAccess.Write)); + + CodeEmit(sw); + // do codegen + /* + using var sw = new StreamWriter(new FileStream( + @"D:\Users\Administrator\Documents\My Games\Terraria\tModLoader\ModSources\WireSharkLib\impl.cpp", + FileMode.Create, FileAccess.Write)); + + sw.WriteLine(""" + #include + + #include "interface.h" + #include "tile.h" + #include "logicgate.h" + #include "runtime.h" + + namespace + { + """); + + var types = new HashSet(); + + var added = new Dictionary(); + var logicGates = new HashSet(); + + foreach (var wire in _connectionInfos) + { + if (added.ContainsKey(wire)) continue; + var id = added[wire] = added.Count + 1; + + var tileTypes = new List(); + var tileNames = new List(); + + foreach (var tile in wire) + { + var name = $"tile_{tile.i}_{tile.j}"; + + if (types.Contains(name)) continue; + types.Add(name); + + tileNames.Add(name); + + var type = "invoke_tile"; + var initializer = $"{{{tile.i}, {tile.j}}}"; + + if (tile is Tile419 t) + { + if (t.lgate != null) + { + logicGates.Add(t); + } + + type = t switch + { + Tile419Normal a => "normal_lamp", + Tile419Error a => "error_lamp", + Tile419NormalOnError a => "normal_on_error_lamp", + Tile419NormalUnconnected a => "unconnected_lamp", + Tile419ErrorUnconnected a => "unconnected_lamp", + _ => "invoke_tile" + }; + + initializer = string.Empty; + } + else if (tile is WireState ws) + { + type = "wire_state"; + initializer = $"{{{(ws.state ? "true" : "false")}}}"; + } + + tileTypes.Add(type); + sw.WriteLine($"{type} {name}{initializer};"); + } + + var tileType = string.Concat(tileTypes.Select(x => $", {x}")); + var allLogic = tileTypes.All(x => x != "invoke_tile"); + var tileInst = string.Join(", ", tileNames.Select(n => $"&{n}")); + sw.WriteLine($"auto wire_{id} = wire<{(allLogic ? "true" : "false")}{tileType}> {{{{{tileInst}}}}};"); + + } + + foreach (var t in logicGates) + { + var gname = $"gate_{t.lgate.x}_{t.lgate.y}"; + if (types.Contains(gname)) continue; + types.Add(gname); + + var classname = t.lgate switch + { + AllOnGate => "all_on_gate", + AnyOnGate => "any_on_gate", + AllOffGate => "all_off_gate", + AnyOffGate => "any_off_gate", + OneOnGate => "one_on_gate", + NotOneOnGate => "not_one_on_gate", + ErrorGate => "error_gate", + OneErrorGate => "one_error_gate", + _ => "unreachable" + }; + var output = new[] + { + _inputConnectedCompoents[t.lgate.x, t.lgate.y, 0], + _inputConnectedCompoents[t.lgate.x, t.lgate.y, 1], + _inputConnectedCompoents[t.lgate.x, t.lgate.y, 2], + _inputConnectedCompoents[t.lgate.x, t.lgate.y, 3], + } + .Where(x => x != -1) + .Select(x => $"wire_{added[_connectionInfos[x]]}").ToArray(); + + var tileType = string.Join(", ", output.Select(x => $"decltype({x})")); + var tileInst = string.Join(", ", output.Select(x => $"&{x}")); + tileInst = $"{{{t.lgate.lampon}, {t.lgate.lamptotal}, {(t.lgate.mapTile.TileFrameX == 18 ? "true" : "false")}, {{{tileInst}}}}}"; + + if (t.lgate is OneErrorGate gate) + { + var states = new[] + { + gate.state1, gate.state2, gate.state3, gate.state4 + }.Where(s => s != OneErrorGate.alwaysFalse).ToArray(); + var stateInit = string.Join(", ", states.Select(s => $"&tile_{s.i}_{s.j}")); + tileType = $"{states.Length}, {tileType}"; + tileInst = $"{tileInst}, {(gate.originalState ? "true" : "false")}, {{{stateInit}}}"; + } + + sw.WriteLine($"auto {gname} = {classname}<{tileType}> {{{tileInst}}};"); + } + + sw.WriteLine(); + + sw.WriteLine(""" + } + + void WireInit() + { + """); + + foreach (var tile in logicGates) + { + var name = $"tile_{tile.i}_{tile.j}"; + var gate = $"gate_{tile.lgate.x}_{tile.lgate.y}"; + var lamp_on = $"&{gate}.lamp_on"; + var checker = $"{{decltype({gate})::check, &{gate}}}"; + switch (tile) + { + case Tile419Normal: + sw.WriteLine($"{name} = normal_lamp{{{tile.add}, {lamp_on}, {checker}}};"); + break; + case Tile419Error: + sw.WriteLine($"{name} = error_lamp{{{checker}}};"); + break; + case Tile419NormalOnError: + sw.WriteLine($"{name} = normal_on_error_lamp{{{tile.add}, {lamp_on}}};"); + break; + } + } + + for (var i = 0; i < Main.maxTilesX; i++) + { + for (var j = 0; j < Main.maxTilesY; j++) + { + for (var k = 0; k < 4; ++k) + { + var id = _inputConnectedCompoents[i, j, k]; + if (id == -1) continue; + + var name = $"wire_{added[_connectionInfos[id]]}"; + sw.WriteLine($" wires[{i}][{j}][{k}] = {{decltype({name})::wrapper, &{name}}};"); + } + } + } + + sw.WriteLine(""" + } + """); + */ + _connectionInfos = null; + _inputConnectedCompoents = null; + + } + + private struct Task : IEquatable + { + public int i, j; + public TileInfo[] conn; + + public bool Equals(Task other) + { + return other.conn.SequenceEqual(conn); + } + + public override bool Equals(object obj) + { + return obj is Task other && Equals(other); + } + + public override int GetHashCode() + { + unchecked + { + return conn.Aggregate(0, (current, t) => current * 31 + t.GetHashCode()); + } + } + } + + public static bool IsTrigger(int i, int j) + { + var tile = Main.tile[i, j]; + if (ModContent.GetModTile(tile.TileType) != null) + return true; + if (!tile.HasTile) return false; + switch (tile.TileType) + { + case TileID.LogicGate: + case TileID.Lever: + case TileID.Switches: + case TileID.PressurePlates: + case TileID.WeightedPressurePlate: + case TileID.ProjectilePressurePad: + case TileID.Timers: + return true; + } + + return false; + } + + private static void CodeEmit(StreamWriter sw) + { + sw.WriteLine(""" + #include "pixel_box.h" + #include "logic_gate.h" + #include "common.h" + #include "interop.h" + """); + + var gatesId = new Dictionary(); + var gates2Id = new Dictionary(); + var boxId = new Dictionary(); + var funcId = new Dictionary(); + var addId = new Dictionary(); + var stateId = new Dictionary(); + ; + var sb = new StringBuilder(); + + var funcs = new int[8400, 2400]; + + for (int i = 0; i < Main.maxTilesX; ++i) + for (int j = 0; j < Main.maxTilesY; ++j) + { + if (!IsTrigger(i, j)) continue; + var conns = new List(); + + var id = _inputConnectedCompoents[i, j, 0]; + if (id != -1) conns.Add(_connectionInfos[id]); + id = _inputConnectedCompoents[i, j, 1]; + if (id != -1) conns.Add(_connectionInfos[id]); + id = _inputConnectedCompoents[i, j, 2]; + if (id != -1) conns.Add(_connectionInfos[id]); + id = _inputConnectedCompoents[i, j, 3]; + if (id != -1) conns.Add(_connectionInfos[id]); + + var conn = conns.SelectMany(x => x).Where(t => t.i != i || t.j != j).ToArray(); + if (conn.Length == 0) continue; + + var wire = new Task + { + i = i, j = j, + conn = conn, + }; + + try + { + if (funcId.ContainsKey(wire)) + { + continue; + } + funcId[wire] = funcId.Count; + } + finally + { + funcs[i, j] = funcId[wire] + 1; + } + + sb.AppendLine($"static void func_{funcId[wire]}() {{"); + + foreach (var tile in wire.conn) + { + switch (tile) + { + case Tile419 t: + { + if (t.lgate != null) + { + if (t.lgate is OneErrorGate) + gates2Id.TryAdd(t.lgate, gates2Id.Count); + else + gatesId.TryAdd(t.lgate, gatesId.Count); + } + + addId.TryAdd(t, addId.Count); + + var gate_checker = t.lgate switch + { + AllOnGate => $"all_on_gate_checker<{t.lgate.lamptotal}>", + AllOffGate => "all_off_gate_checker", + AnyOffGate => $"any_off_gate_checker<{t.lgate.lamptotal}>", + AnyOnGate => "any_on_gate_checker", + OneOnGate => "one_on_gate_checker", + NotOneOnGate => "not_one_on_gate_checker", + OneErrorGate => "one_error_gate_checker", + ErrorGate => $"error_gate_checker<{t.lgate.lamptotal}>", + _ => string.Empty + }; + switch (t) + { + case Tile419Normal: + { + sb.AppendLine($""" + gates[{gatesId[t.lgate]}].lamp_on += adds[{addId[t]}] = -adds[{addId[t]}]; + lamps_to_check.push({gate_checker}, &gates[{gatesId[t.lgate]}]); + """); + break; + } + case Tile419NormalOnError: + { + sb.AppendLine($""" + gates[{gatesId[t.lgate]}].lamp_on += adds[{addId[t]}] = -adds[{addId[t]}]; + """); + break; + } + case Tile419Error: + { + if (t.lgate is OneErrorGate err) + { + int stateNum = 0; + if (err.state1 != OneErrorGate.alwaysFalse) ++stateNum; + if (err.state2 != OneErrorGate.alwaysFalse) ++stateNum; + if (err.state3 != OneErrorGate.alwaysFalse) ++stateNum; + if (err.state4 != OneErrorGate.alwaysFalse) ++stateNum; + sb.AppendLine($""" + lamps_to_check.push({gate_checker}<{stateNum}>, &one_error_gates[{gates2Id[t.lgate]}]); + """); + } + else + { + sb.AppendLine($""" + lamps_to_check.push({gate_checker}, &gates[{gatesId[t.lgate]}]); + """); + } + + break; + } + case Tile419NormalOnOneError: + { + sb.AppendLine($""" + one_error_gates[{gates2Id[t.lgate]}].lamp_on = 1 - one_error_gates[{gates2Id[t.lgate]}].lamp_on; + """); + break; + } + } + + break; + } + case PixelBoxBase t: + { + boxId.TryAdd(t.box, boxId.Count); + var state = t is PixelBoxVertical ? 2 : 1; + sb.AppendLine($""" + boxes[{boxId[t.box]}].state |= {state}; + box_to_update.push(&boxes[{boxId[t.box]}]); + """); + break; + } + case WireState t: + { + stateId.TryAdd(t, stateId.Count); + sb.AppendLine($""" + states[{stateId[t]}] ^= true; + """); + break; + } + default: + { + sb.AppendLine($""" + HitTile({tile.i}, {tile.j}); + """); + break; + } + } + } + + sb.AppendLine("}"); + } + + var arr = string.Join(", ", gatesId.OrderBy(p => p.Value) + .Select(pair => $"{{{*pair.Key.lampon}, 0, {(pair.Key.mapTile.TileFrameX == 18 ? "true" : "false")}," + + $"{{{pair.Key.x}, {pair.Key.y}, &gates[{pair.Value}].last_active}}}}")); + sw.WriteLine($"static logic_gate gates[{gatesId.Count}] = {{{arr}}};"); + + arr = string.Join(", ", stateId.OrderBy(p => p.Value) + .Select(pair => pair.Key.state ? "true" : "false")); + sw.WriteLine($"static bool states[{stateId.Count}] = {{{arr}}};"); + + stateId[OneErrorGate.alwaysFalse] = -1; + arr = string.Join(", ", gates2Id.OrderBy(p => p.Value) + .Select(pair => + { + var l = pair.Key as OneErrorGate; + return $"{{{{&states[{stateId[l.state1]}], &states[{stateId[l.state2]}], " + + $"&states[{stateId[l.state3]}], &states[{stateId[l.state4]}]}}, {(l.originalState ? "true" : "false")}, " + + $"{{{pair.Key.x}, {pair.Key.y}, &one_error_gates[{pair.Value}].last_active}}}}"; + })); + sw.WriteLine($"static one_error_gate one_error_gates[{gates2Id.Count}] = {{{arr}}};"); + + arr = string.Join(", ", boxId.OrderBy(p => p.Value) + .Select(pair => $"{{0, {pair.Key.x}, {pair.Key.y}, nullptr}}")); + sw.WriteLine($"static pixel_box boxes[{boxId.Count}] = {{{arr}}};"); + + + arr = string.Join(", ", addId.OrderBy(p => p.Value) + .Select(pair => $"{pair.Key.add}")); + sw.WriteLine($"static int adds[{addId.Count}] = {{{arr}}};"); + + /* + // logic_gate initialize + + foreach (var pair in gatesId.OrderBy(p => p.Value)) + { + sw.WriteLine($"gates[{pair.Value}] = {{{*pair.Key.lampon}, 0, {(pair.Key.mapTile.TileFrameX == 18 ? "true" : "false")}," + + $"{{{pair.Key.x}, {pair.Key.y}, &gates[{pair.Value}].last_active}}}};"); + } + + // state initialize + + foreach (var state in stateId.OrderBy(p => p.Value)) + { + sw.WriteLine($"states[{state.Value}] = {(state.Key.state ? "true" : "false")};"); + } + + // one_error_gate initialize + + foreach (var pair in gates2Id.OrderBy(p => p.Value)) + { + var l = pair.Key as OneErrorGate; + sw.WriteLine($"one_error_gates[{pair.Value}] = {{" + + $"{{&states[{stateId[l.state1]}], &states[{stateId[l.state2]}], " + + $"&states[{stateId[l.state3]}], &states[{stateId[l.state4]}]}}, {(l.originalState ? "true" : "false")}, " + + $"{{{pair.Key.x}, {pair.Key.y}, &gates[{pair.Value}].last_active}}}};"); + } + + // add initializer + + foreach (var pair in addId.OrderBy(p => p.Value)) + { + sw.WriteLine($"adds[{pair.Value}] = {pair.Key.add};"); + } + + // pixel box initalizer + + foreach (var pair in boxId.OrderBy(p => p.Value)) + { + sw.WriteLine($"boxes[{pair.Value}] = {{0, {pair.Key.x}, {pair.Key.y}, nullptr}};"); + }*/ + + + sw.WriteLine(sb.ToString()); + + // input component initialize + + arr = string.Join(",", funcs.OfType().Select(x => x == 0 ? "0" : $"func_{x - 1}")); + sw.WriteLine($"Connection inputConnectedCompoents[maxTilesX][maxTilesY] = {{{arr}}};"); + + /* + for (var i = 0; i < Main.maxTilesX; i++) + { + sw.WriteLine(); + for (var j = 0; j < Main.maxTilesY; j++) + { + for (var k = 0; k < 4; ++k) + { + var id = _inputConnectedCompoents[i, j, k]; + if (id == -1) continue; + sw.WriteLine($" inputConnectedCompoents[{i}][{j}][{k}] = func_{funcId[_connectionInfos[id]]};"); + } + } + } + sw.WriteLine("};");*/ + + + sw.WriteLine($$""" + pixel_box* GetPixelBoxPointer() + { + return boxes; + } + int GetPixelBoxCount() + { + return {{boxId.Count}}; + } + """); + + } + } +} diff --git a/WireConfig.cs b/WireShark/WireConfig.cs similarity index 100% rename from WireConfig.cs rename to WireShark/WireConfig.cs diff --git a/WireShark.cs b/WireShark/WireShark.cs similarity index 97% rename from WireShark.cs rename to WireShark/WireShark.cs index 778359b..c268781 100644 --- a/WireShark.cs +++ b/WireShark/WireShark.cs @@ -1,113 +1,113 @@ -using Terraria; -using Terraria.ModLoader; -using Terraria.IO; - -namespace WireShark { - public class WireShark : Mod { - - private static void Preprocess() - { - WiringWrapper.Initialize(); - WireAccelerator.Preprocess(); - WiringWrapper.Initialize_GatesDone(); - WiringWrapper.Initialize_LogicLamps(); - WireAccelerator.Postprocess(); - } - public override void Load() - { - WorldFile.OnWorldLoad += Preprocess; - Terraria.On_Wiring.Actuate += Wiring_Actuate; - Terraria.On_Wiring.ActuateForced += Wiring_ActuateForced; - Terraria.On_Wiring.CheckMech += Wiring_CheckMech; - Terraria.On_Wiring.DeActive += Wiring_DeActive; - Terraria.On_Wiring.HitSwitch += Wiring_HitSwitch; - Terraria.On_Wiring.Initialize += Wiring_Initialize; - Terraria.On_Wiring.PokeLogicGate += Wiring_PokeLogicGate; - Terraria.On_Wiring.ReActive += Wiring_ReActive; - Terraria.On_Wiring.SetCurrentUser += Wiring_SetCurrentUser; - Terraria.On_Wiring.SkipWire_int_int += Wiring_SkipWire_int_int; - Terraria.On_Wiring.SkipWire_Point16 += Wiring_SkipWire_Point16; - Terraria.On_Wiring.TripWire += Wiring_TripWire; - Terraria.On_Wiring.UpdateMech += Wiring_UpdateMech; - Terraria.On_WorldGen.StartRoomCheck += WorldGen_StartRoomCheck; - } - - private bool WorldGen_StartRoomCheck(Terraria.On_WorldGen.orig_StartRoomCheck orig, int x, int y) { - return false; - } - - private void Wiring_UpdateMech(Terraria.On_Wiring.orig_UpdateMech orig) { - WiringWrapper.UpdateMech(); - } - - private void Wiring_SkipWire_Point16(Terraria.On_Wiring.orig_SkipWire_Point16 orig, Terraria.DataStructures.Point16 point) { - - } - - private void Wiring_SkipWire_int_int(Terraria.On_Wiring.orig_SkipWire_int_int orig, int x, int y) { - - } - - private void Wiring_SetCurrentUser(Terraria.On_Wiring.orig_SetCurrentUser orig, int plr) { - WiringWrapper.SetCurrentUser(plr); - } - - private void Wiring_ReActive(Terraria.On_Wiring.orig_ReActive orig, int i, int j) { - WiringWrapper.ReActive(i, j); - } - - private void Wiring_PokeLogicGate(Terraria.On_Wiring.orig_PokeLogicGate orig, int lampX, int lampY) { - WiringWrapper.PokeLogicGate(lampX, lampY); - } - - private void Wiring_Initialize(Terraria.On_Wiring.orig_Initialize orig) { - WiringWrapper.Initialize(); - } - - - private void Wiring_HitSwitch(Terraria.On_Wiring.orig_HitSwitch orig, int i, int j) { - WiringWrapper.HitSwitch(i, j); - } - - private void Wiring_DeActive(Terraria.On_Wiring.orig_DeActive orig, int i, int j) { - WiringWrapper.DeActive(i, j); - } - - private bool Wiring_CheckMech(Terraria.On_Wiring.orig_CheckMech orig, int i, int j, int time) { - return WiringWrapper.CheckMech(i, j, time); - } - - private void Wiring_ActuateForced(Terraria.On_Wiring.orig_ActuateForced orig, int i, int j) { - WiringWrapper.ActuateForced(i, j); - } - - private bool Wiring_Actuate(Terraria.On_Wiring.orig_Actuate orig, int i, int j) { - return WiringWrapper.Actuate(i, j); - } - - - private void Wiring_TripWire(Terraria.On_Wiring.orig_TripWire orig, int left, int top, int width, int height) { - WiringWrapper.BigTripWire(left, top, width, height); - } - - - public override void Unload() - { - WorldFile.OnWorldLoad -= Preprocess; - Terraria.On_Wiring.Actuate -= Wiring_Actuate; - Terraria.On_Wiring.ActuateForced -= Wiring_ActuateForced; - Terraria.On_Wiring.CheckMech -= Wiring_CheckMech; - Terraria.On_Wiring.DeActive -= Wiring_DeActive; - Terraria.On_Wiring.HitSwitch -= Wiring_HitSwitch; - Terraria.On_Wiring.Initialize -= Wiring_Initialize; - Terraria.On_Wiring.PokeLogicGate -= Wiring_PokeLogicGate; - Terraria.On_Wiring.ReActive -= Wiring_ReActive; - Terraria.On_Wiring.SetCurrentUser -= Wiring_SetCurrentUser; - Terraria.On_Wiring.SkipWire_int_int -= Wiring_SkipWire_int_int; - Terraria.On_Wiring.SkipWire_Point16 -= Wiring_SkipWire_Point16; - Terraria.On_Wiring.TripWire -= Wiring_TripWire; - Terraria.On_Wiring.UpdateMech -= Wiring_UpdateMech; - Terraria.On_WorldGen.StartRoomCheck -= WorldGen_StartRoomCheck; - } - } -} +using Terraria; +using Terraria.ModLoader; +using Terraria.IO; + +namespace WireShark { + public class WireShark : Mod { + + private static void Preprocess() + { + WiringWrapper.Initialize(); + WireAccelerator.Preprocess(); + WiringWrapper.Initialize_GatesDone(); + WiringWrapper.Initialize_LogicLamps(); + WireAccelerator.Postprocess(); + } + public override void Load() + { + WorldFile.OnWorldLoad += Preprocess; + Terraria.On_Wiring.Actuate += Wiring_Actuate; + Terraria.On_Wiring.ActuateForced += Wiring_ActuateForced; + Terraria.On_Wiring.CheckMech += Wiring_CheckMech; + Terraria.On_Wiring.DeActive += Wiring_DeActive; + Terraria.On_Wiring.HitSwitch += Wiring_HitSwitch; + Terraria.On_Wiring.Initialize += Wiring_Initialize; + Terraria.On_Wiring.PokeLogicGate += Wiring_PokeLogicGate; + Terraria.On_Wiring.ReActive += Wiring_ReActive; + Terraria.On_Wiring.SetCurrentUser += Wiring_SetCurrentUser; + Terraria.On_Wiring.SkipWire_int_int += Wiring_SkipWire_int_int; + Terraria.On_Wiring.SkipWire_Point16 += Wiring_SkipWire_Point16; + Terraria.On_Wiring.TripWire += Wiring_TripWire; + Terraria.On_Wiring.UpdateMech += Wiring_UpdateMech; + Terraria.On_WorldGen.StartRoomCheck += WorldGen_StartRoomCheck; + } + + private bool WorldGen_StartRoomCheck(Terraria.On_WorldGen.orig_StartRoomCheck orig, int x, int y) { + return false; + } + + private void Wiring_UpdateMech(Terraria.On_Wiring.orig_UpdateMech orig) { + WiringWrapper.UpdateMech(); + } + + private void Wiring_SkipWire_Point16(Terraria.On_Wiring.orig_SkipWire_Point16 orig, Terraria.DataStructures.Point16 point) { + + } + + private void Wiring_SkipWire_int_int(Terraria.On_Wiring.orig_SkipWire_int_int orig, int x, int y) { + + } + + private void Wiring_SetCurrentUser(Terraria.On_Wiring.orig_SetCurrentUser orig, int plr) { + WiringWrapper.SetCurrentUser(plr); + } + + private void Wiring_ReActive(Terraria.On_Wiring.orig_ReActive orig, int i, int j) { + WiringWrapper.ReActive(i, j); + } + + private void Wiring_PokeLogicGate(Terraria.On_Wiring.orig_PokeLogicGate orig, int lampX, int lampY) { + WiringWrapper.PokeLogicGate(lampX, lampY); + } + + private void Wiring_Initialize(Terraria.On_Wiring.orig_Initialize orig) { + WiringWrapper.Initialize(); + } + + + private void Wiring_HitSwitch(Terraria.On_Wiring.orig_HitSwitch orig, int i, int j) { + WiringWrapper.HitSwitch(i, j); + } + + private void Wiring_DeActive(Terraria.On_Wiring.orig_DeActive orig, int i, int j) { + WiringWrapper.DeActive(i, j); + } + + private bool Wiring_CheckMech(Terraria.On_Wiring.orig_CheckMech orig, int i, int j, int time) { + return WiringWrapper.CheckMech(i, j, time); + } + + private void Wiring_ActuateForced(Terraria.On_Wiring.orig_ActuateForced orig, int i, int j) { + WiringWrapper.ActuateForced(i, j); + } + + private bool Wiring_Actuate(Terraria.On_Wiring.orig_Actuate orig, int i, int j) { + return WiringWrapper.Actuate(i, j); + } + + + private void Wiring_TripWire(Terraria.On_Wiring.orig_TripWire orig, int left, int top, int width, int height) { + WiringWrapper.BigTripWire(left, top, width, height); + } + + + public override void Unload() + { + WorldFile.OnWorldLoad -= Preprocess; + Terraria.On_Wiring.Actuate -= Wiring_Actuate; + Terraria.On_Wiring.ActuateForced -= Wiring_ActuateForced; + Terraria.On_Wiring.CheckMech -= Wiring_CheckMech; + Terraria.On_Wiring.DeActive -= Wiring_DeActive; + Terraria.On_Wiring.HitSwitch -= Wiring_HitSwitch; + Terraria.On_Wiring.Initialize -= Wiring_Initialize; + Terraria.On_Wiring.PokeLogicGate -= Wiring_PokeLogicGate; + Terraria.On_Wiring.ReActive -= Wiring_ReActive; + Terraria.On_Wiring.SetCurrentUser -= Wiring_SetCurrentUser; + Terraria.On_Wiring.SkipWire_int_int -= Wiring_SkipWire_int_int; + Terraria.On_Wiring.SkipWire_Point16 -= Wiring_SkipWire_Point16; + Terraria.On_Wiring.TripWire -= Wiring_TripWire; + Terraria.On_Wiring.UpdateMech -= Wiring_UpdateMech; + Terraria.On_WorldGen.StartRoomCheck -= WorldGen_StartRoomCheck; + } + } +} diff --git a/WireShark.csproj b/WireShark/WireShark.csproj similarity index 97% rename from WireShark.csproj rename to WireShark/WireShark.csproj index 7fa9f59..dd32be3 100644 --- a/WireShark.csproj +++ b/WireShark/WireShark.csproj @@ -1,14 +1,14 @@ - - - - - WireShark - net6.0 - AnyCPU - latest - true - - - - + + + + + WireShark + net6.0 + AnyCPU + latest + true + + + + \ No newline at end of file diff --git a/WireShark.sln b/WireShark/WireShark.sln similarity index 56% rename from WireShark.sln rename to WireShark/WireShark.sln index 3b8a9ec..faa28f8 100644 --- a/WireShark.sln +++ b/WireShark/WireShark.sln @@ -1,20 +1,32 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31005.135 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34322.80 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireShark", "WireShark.csproj", "{5748FAAB-F885-4673-83DD-50582E7CE5D4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Debug|x64.ActiveCfg = Debug|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Debug|x64.Build.0 = Debug|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Debug|x86.ActiveCfg = Debug|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Debug|x86.Build.0 = Debug|Any CPU {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Release|Any CPU.ActiveCfg = Release|Any CPU {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Release|Any CPU.Build.0 = Release|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Release|x64.ActiveCfg = Release|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Release|x64.Build.0 = Release|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Release|x86.ActiveCfg = Release|Any CPU + {5748FAAB-F885-4673-83DD-50582E7CE5D4}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WiringWrapper.cs b/WireShark/WiringWrapper.cs similarity index 95% rename from WiringWrapper.cs rename to WireShark/WiringWrapper.cs index 557086d..c48f595 100644 --- a/WiringWrapper.cs +++ b/WireShark/WiringWrapper.cs @@ -44,7 +44,6 @@ public static void Initialize() // _wireAccelerator = new WireAccelerator(); _wireList = new QuickLinkedList(); // _wireDirectionList = new DoubleStack(1024, 0); - _toProcess = new Dictionary(); _GatesCurrent = new QuickLinkedList(); _GatesNext = new QuickLinkedList(); _LampsToCheck = new QuickLinkedList(); @@ -60,13 +59,6 @@ public static void Initialize() public static void Unload() { onLogicLampChange = null; - // _wireAccelerator = null; - _wireList = null; - // _wireDirectionList = null; - _toProcess = null; - _GatesCurrent = null; - _GatesNext = null; - _LampsToCheck = null; _inPumpX = null; _inPumpY = null; _outPumpX = null; @@ -389,17 +381,14 @@ private static void XferWater() } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - public static void TripWireWithLogicVanillaSingle(int l, int t) + private static void TripWireWithLogicVanillaSingle(int l, int t) { - if (Main.netMode == NetmodeID.MultiplayerClient) - { - return; - } TripWireSingle(l, t); PixelBoxPass(); LogicGatePassVanilla(); } + // entry point public static void BigTripWire(int l, int t, int w, int h) { if (Main.netMode == NetmodeID.MultiplayerClient) @@ -723,19 +712,20 @@ private static void LogicGatePassVanilla() { _LampsToCheck.cachePtr[i].UpdateLogicGate(); } + _LampsToCheck.Clear(); /* while (_LampsToCheck.Count > 0) { _LampsToCheck.Dequeue().UpdateLogicGate(); - + // Point16 point = ; // CheckLogicGate((int)point.X, (int)point.Y); } */ - //if (_GatesNext.Count > 0) - // Main.NewText($"gate counts to check = {_GatesNext.Count}"); - while (_GatesNext.Count > 0) + //if (_GatesNext.Count > 0) + // Main.NewText($"gate counts to check = {_GatesNext.Count}"); + while (_GatesNext.Count > 0) { Utils.Swap(ref _GatesCurrent, ref _GatesNext); for (int i = 0; i < _GatesCurrent.Count; ++i) @@ -747,6 +737,7 @@ private static void LogicGatePassVanilla() TripWireWithLogicVanillaSingle(key.X, key.Y); } } + _GatesCurrent.Clear(); /* while (_GatesCurrent.Count > 0) @@ -761,8 +752,6 @@ private static void LogicGatePassVanilla() }*/ } } - - Clear_Gates(); if (Wiring.blockPlayerTeleportationForOneIteration) { Wiring.blockPlayerTeleportationForOneIteration = false; @@ -772,11 +761,11 @@ private static void LogicGatePassVanilla() internal static LogicGate[,] onLogicLampChange; - private class AllOnGate : LogicGate + internal class AllOnGate : LogicGate { public override void UpdateLogicGate() { - var cur = lampon == lamptotal; + var cur = *lampon == lamptotal; //Main.NewText($"update {GetType().Name} => {active} to {cur}, {lampon} / {lamptotal} @({x}, {y})"); if ((mapTile.TileFrameX == 18) ^ cur) { @@ -786,11 +775,11 @@ public override void UpdateLogicGate() } } - private class AnyOnGate : LogicGate + internal class AnyOnGate : LogicGate { public override void UpdateLogicGate() { - var cur = lampon > 0; + var cur = *lampon > 0; //Main.NewText($"update {GetType().Name} => {active} to {cur}, {lampon} / {lamptotal} @({x}, {y})"); if ((mapTile.TileFrameX == 18) ^ cur) { @@ -800,11 +789,11 @@ public override void UpdateLogicGate() } } - private class AnyOffGate : LogicGate + internal class AnyOffGate : LogicGate { public override void UpdateLogicGate() { - var cur = lampon != lamptotal; + var cur = *lampon != lamptotal; //Main.NewText($"update {GetType().Name} => {active} to {cur}, {lampon} / {lamptotal} @({x}, {y})"); if ((mapTile.TileFrameX == 18) ^ cur) { @@ -814,11 +803,11 @@ public override void UpdateLogicGate() } } - private class AllOffGate : LogicGate + internal class AllOffGate : LogicGate { public override void UpdateLogicGate() { - var cur = lampon == 0; + var cur = *lampon == 0; //Main.NewText($"update {GetType().Name} => {active} to {cur}, {lampon} / {lamptotal} @({x}, {y})"); if ((mapTile.TileFrameX == 18) ^ cur) { @@ -828,11 +817,11 @@ public override void UpdateLogicGate() } } - private class OneOnGate : LogicGate + internal class OneOnGate : LogicGate { public override void UpdateLogicGate() { - var cur = lampon == 1; + var cur = *lampon == 1; //Main.NewText($"update {GetType().Name} => {active} to {cur}, {lampon} / {lamptotal} @({x}, {y})"); if ((mapTile.TileFrameX == 18) ^ cur) { @@ -842,11 +831,11 @@ public override void UpdateLogicGate() } } - private class NotOneOnGate : LogicGate + internal class NotOneOnGate : LogicGate { public override void UpdateLogicGate() { - var cur = lampon != 1; + var cur = *lampon != 1; //Main.NewText($"update {GetType().Name} => {active} to {cur}, {lampon} / {lamptotal} @({x}, {y})"); if ((mapTile.TileFrameX == 18) ^ cur) { @@ -856,7 +845,7 @@ public override void UpdateLogicGate() } } - private class ErrorGate : LogicGate + internal class ErrorGate : LogicGate { public ErrorGate() { @@ -865,13 +854,13 @@ public ErrorGate() public override void UpdateLogicGate() { - if (Main.rand.NextDouble() * lamptotal < lampon) + if (Main.rand.NextDouble() * lamptotal < *lampon) if (_GatesDone[x, y] != cur_gatesdone) _GatesNext.AddLast(new Point16(x, y)); } } - - private class WireState : TileInfo + + internal class WireState : TileInfo { public bool state; protected override void HitWireInternal() @@ -880,7 +869,7 @@ protected override void HitWireInternal() } } - private unsafe class OneErrorGate : LogicGate + internal unsafe class OneErrorGate : LogicGate { public bool originalState; @@ -950,7 +939,7 @@ private static void CacheLogicGate(int x, int y) } lgate.lamptotal = lamps.Count; - lgate.lampon = onnum; + *lgate.lampon = onnum; lgate.mapTile = tile; lgate.x = x; lgate.y = y; @@ -999,7 +988,7 @@ public static void Initialize_LogicLamps() { if (info is Tile419 && onLogicLampChange[info.i, info.j] is OneErrorGate gate) { - gate.originalState = gate.lampon > 0; + gate.originalState = *gate.lampon > 0; if (info.tile.TileFrameX != 36) { state ??= new WireState {i = info.i, j = info.j, tile = info.tile, hash = ((long) info.i << 32) + info.j}; @@ -1037,12 +1026,19 @@ public static void Initialize_LogicLamps() var p = 0; + var changedDict = new Dictionary(); + foreach (var arr in uniqueConnection.Values) { for (int i = 0; i < arr.Length; ++i) { if (arr[i] is Tile419) { + if (changedDict.TryGetValue(arr[i], out var val)) + { + arr[i] = val; + continue; + } var lgate = onLogicLampChange[arr[i].i, arr[i].j]; Tile419 newTile; if (lgate == null) @@ -1053,7 +1049,11 @@ public static void Initialize_LogicLamps() else { if (arr[i].tile.TileFrameX == 36) newTile = new Tile419Error(); - else if (lgate.erroronly) newTile = new Tile419NormalOnError(); + else if (lgate.erroronly) + { + if (lgate is OneErrorGate) newTile = new Tile419NormalOnOneError(); + else newTile = new Tile419NormalOnError(); + } else newTile = new Tile419Normal(); } @@ -1063,7 +1063,12 @@ public static void Initialize_LogicLamps() newTile.tile = arr[i].tile; newTile.lgate = lgate; newTile.add = newTile.tile.TileFrameX == 18 ? 1 : -1; - newTile.frameX = (short *)Unsafe.AsPointer(ref newTile.tile.TileFrameX); + if (lgate != null) + { + newTile.lampon = lgate.lampon; + } + + changedDict[arr[i]] = newTile; arr[i] = newTile; } @@ -1180,12 +1185,6 @@ public static void ReActive(int i, int j) // Token: 0x04000C71 RID: 3185 internal static QuickLinkedList _wireList; - // Token: 0x04000C72 RID: 3186 - public static DoubleStack _wireDirectionList; - - // Token: 0x04000C73 RID: 3187 - public static Dictionary _toProcess; - // Token: 0x04000C74 RID: 3188 private static QuickLinkedList _GatesCurrent; diff --git a/build.txt b/WireShark/build.txt similarity index 100% rename from build.txt rename to WireShark/build.txt diff --git a/description.txt b/WireShark/description.txt similarity index 100% rename from description.txt rename to WireShark/description.txt diff --git a/WireSharkLib/.gitignore b/WireSharkLib/.gitignore new file mode 100644 index 0000000..f70d6a4 --- /dev/null +++ b/WireSharkLib/.gitignore @@ -0,0 +1,3 @@ +.idea/ +cmake-build-*/ +impl.cpp \ No newline at end of file diff --git a/WireSharkLib/CMakeLists.txt b/WireSharkLib/CMakeLists.txt new file mode 100644 index 0000000..1d0c56c --- /dev/null +++ b/WireSharkLib/CMakeLists.txt @@ -0,0 +1,32 @@ +cmake_minimum_required(VERSION 3.27) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") + +include_directories(.) + +add_library(WireSharkLib SHARED + quick_queue.h + wiring_wrapper.h + wiring_wrapper.cpp + common.h + logic_gate.h + pixel_box.h + interop.h + impl.cpp + interop.cpp +) + +add_executable(WireSharkLibTest + quick_queue.h + wiring_wrapper.h + wiring_wrapper.cpp + common.h + logic_gate.h + pixel_box.h + interop.h + impl.cpp + interop.cpp + test.cpp +) +target_link_libraries(WireSharkLib -static-libgcc -static-libstdc++) \ No newline at end of file diff --git a/WireSharkLib/common.h b/WireSharkLib/common.h new file mode 100644 index 0000000..5938b14 --- /dev/null +++ b/WireSharkLib/common.h @@ -0,0 +1,40 @@ +// +// Created by Administrator on 2023/12/15. +// + +#ifndef COMMON_H +#define COMMON_H + +#include +#include "quick_queue.h" + +constexpr int maxTilesX = 8400, maxTilesY = 2400; + +using Vector2 = std::pair; + +inline Vector2* teleport; +inline Vector2 teleport_t[8]; + +using Connection = void (*) (); + +extern Connection inputConnectedCompoents[maxTilesX][maxTilesY]; + +struct bind { + void (*func)(void *ptr); + + void *ptr; + + void operator()() const + { + func(ptr); + } + + template + bind (void (*func)(T *ptr), T2* ptr) : func(reinterpret_cast(func)), ptr(ptr) {} + + bind() : func(nullptr), ptr(nullptr) {} +}; + +inline quick_queue lamps_to_check; + +#endif //COMMON_H diff --git a/WireSharkLib/interop.cpp b/WireSharkLib/interop.cpp new file mode 100644 index 0000000..3d381c4 --- /dev/null +++ b/WireSharkLib/interop.cpp @@ -0,0 +1,34 @@ +// +// Created by Administrator on 2023/12/15. +// +#include "interop.h" +#include "wiring_wrapper.h" + +#include + +void BigTripWire(int l, int t, int w, int h) { + wiring_wrapper::BigTripWire(l, t, w, h); +} + +void HitTile(int x, int y) { + // std::cout << "[debug] wire triggered: " << x << ", " << y << std::endl; + triggers.push(x); + triggers.push(y); +} + +void Teleport(const Vector2& from, const Vector2& to) { + triggers.push(from.first); + triggers.push(from.second); + triggers.push(to.first); + triggers.push(to.second); +} + +void RetrieveUpdates(UpdateInfo* info) { + info->teleports = teleports.cache; + info->teleport_len = teleports.tail / 4; + info->triggers = triggers.cache; + info->trigger_len = triggers.tail / 2; + + teleports.tail = 0; + triggers.tail = 0; +} diff --git a/WireSharkLib/interop.h b/WireSharkLib/interop.h new file mode 100644 index 0000000..5a0437e --- /dev/null +++ b/WireSharkLib/interop.h @@ -0,0 +1,36 @@ +// +// Created by Administrator on 2023/12/15. +// + +#ifndef INTEROP_H +#define INTEROP_H + +#include "pixel_box.h" +#include "common.h" + +#include "quick_queue.h" + +inline quick_queue teleports; +inline quick_queue triggers; + +extern "C" { + struct UpdateInfo { + float* teleports; + int teleport_len; + int* triggers; + int trigger_len; + }; + + void RetrieveUpdates(UpdateInfo* info); + + // these methods are implemented by codegen + pixel_box* GetPixelBoxPointer(); + int GetPixelBoxCount(); + void BigTripWire(int l, int t, int w, int h); +} + +void HitTile(int x, int y); + +void Teleport(const Vector2 &from, const Vector2 &to); + +#endif //INTEROP_H diff --git a/WireSharkLib/logic_gate.h b/WireSharkLib/logic_gate.h new file mode 100644 index 0000000..62c85d3 --- /dev/null +++ b/WireSharkLib/logic_gate.h @@ -0,0 +1,111 @@ +// +// Created by Administrator on 2023/12/15. +// + +#ifndef LOGIC_GATES_H +#define LOGIC_GATES_H + +#include +#include + +#include "quick_queue.h" +#include + +struct gate_info { + int x, y; + int *last_active; +}; + +struct logic_gate { + int lamp_on, last_active; + bool active; + gate_info info; +}; + +inline int update_round; + +inline quick_queue gates_next, gates_current; + +template +void all_on_gate_checker(logic_gate *gate) { + auto cur = gate->lamp_on == lamp_total; + if (cur ^ gate->active) { + gate->active = cur; + if (update_round != gate->last_active) + gates_next.push(gate->info); + } +} + +inline void any_on_gate_checker(logic_gate *gate) { + auto cur = gate->lamp_on != 0; + if (cur ^ gate->active) { + gate->active = cur; + if (update_round != gate->last_active) + gates_next.push(gate->info); + } +} + +template +void any_off_gate_checker(logic_gate *gate) { + auto cur = gate->lamp_on != lamp_total; + if (cur ^ gate->active) { + gate->active = cur; + if (update_round != gate->last_active) + gates_next.push(gate->info); + } +} + +inline void all_off_gate_checker(logic_gate *gate) { + auto cur = gate->lamp_on == 0; + if (cur ^ gate->active) { + gate->active = cur; + if (update_round != gate->last_active) + gates_next.push(gate->info); + } +} + +inline void one_on_gate_checker(logic_gate *gate) { + auto cur = gate->lamp_on == 1; + if (cur ^ gate->active) { + gate->active = cur; + if (update_round != gate->last_active) + gates_next.push(gate->info); + } +} + +inline void not_one_on_gate_checker(logic_gate *gate) { + auto cur = gate->lamp_on != 1; + if (cur ^ gate->active) { + gate->active = cur; + if (update_round != gate->last_active) + gates_next.push(gate->info); + } +} + +static auto generator = std::default_random_engine(); + +template +void error_gate_checker(logic_gate *gate) { + if (generator() % lamp_total < gate->lamp_on) { + gates_next.push(gate->info); + } +} + +struct one_error_gate { + std::array states; + bool originalState; + gate_info info; + int last_active = 0; +}; + +template +void one_error_gate_checker(one_error_gate *gate) { + auto state = gate->originalState; + if constexpr (n > 0) state ^= *gate->states[0]; + if constexpr (n > 1) state ^= *gate->states[1]; + if constexpr (n > 2) state ^= *gate->states[2]; + if constexpr (n > 3) state ^= *gate->states[3]; + if (state) gates_next.push(gate->info); +} + +#endif //LOGIC_GATES_H diff --git a/WireSharkLib/pixel_box.h b/WireSharkLib/pixel_box.h new file mode 100644 index 0000000..8d2c42e --- /dev/null +++ b/WireSharkLib/pixel_box.h @@ -0,0 +1,18 @@ +// +// Created by Administrator on 2023/12/15. +// + +#ifndef PIXEL_BOX_H +#define PIXEL_BOX_H + +#include "quick_queue.h" + +struct pixel_box { + int state; + int x, y; + short *TileFrameX; +}; + +inline quick_queue box_to_update; + +#endif //PIXEL_BOX_H diff --git a/WireSharkLib/quick_queue.h b/WireSharkLib/quick_queue.h new file mode 100644 index 0000000..e56d727 --- /dev/null +++ b/WireSharkLib/quick_queue.h @@ -0,0 +1,16 @@ +#ifndef QUEUE_H +#define QUEUE_H + +template +class quick_queue +{ +public: + T* cache; + int tail = 0; + quick_queue() { cache = new T[1024 * 1024 * 10]; } + + template + void push(Args... args) { new(cache + (tail++)) T(args...); } +}; + +#endif \ No newline at end of file diff --git a/WireSharkLib/test.cpp b/WireSharkLib/test.cpp new file mode 100644 index 0000000..bccf11a --- /dev/null +++ b/WireSharkLib/test.cpp @@ -0,0 +1,35 @@ +// +// Created by Administrator on 2023/12/16. +// + + +#include "interop.h" + +int main() { + /* + freopen("test.txt", "w", stdout); + for (int i = 0; i < maxTilesX; ++i) { + for (int j = 0; j < maxTilesY; ++j) { + int t = 0; + for (int k = 0; k < 4; ++k) + if (inputConnectedCompoents[i][j][k]) + t |= 1 << k; + std::cout << (t ? (char)('a' + t) : ' '); + } + std::cout << std::endl; + } + //BigTripWire(2702, 2081, 1, 1); + for (int i = 0; i < maxTilesX; ++i) + for (int j = 0; j < maxTilesY; ++j) + if (inputConnectedCompoents[i][j]) + std::cout << i << ", " << j << std::endl; + std::string s; + std::cout << "counting" << std::endl; + BigTripWire(349, 752, 1, 1); + std::cout << "reseting" << std::endl; + BigTripWire(342 , 752, 1, 1); + std::cout << "counting" << std::endl; + BigTripWire(349, 752, 1, 1);*/ + + BigTripWire(354, 752, 1, 1); +} diff --git a/WireSharkLib/wiring_wrapper.cpp b/WireSharkLib/wiring_wrapper.cpp new file mode 100644 index 0000000..1cc0f1a --- /dev/null +++ b/WireSharkLib/wiring_wrapper.cpp @@ -0,0 +1,71 @@ +// +// Created by Administrator on 2023/12/15. +// + +#include "wiring_wrapper.h" +#include +#include + +#include "common.h" +#include "logic_gate.h" +#include "pixel_box.h" +#include "interop.h" + +void wiring_wrapper::BigTripWire(int l, int t, int w, int h) { + for (int i = 0; i < w; ++i) + for (int j = 0; j < h; ++j) + TripWireSingle(l + i, t + j); +} + +void wiring_wrapper::TripWireSingle(const int l, const int t) { + if (inputConnectedCompoents[l][t]) { + // std::cout << "invoke input connected components @" << l << ", " << t << std::endl; + inputConnectedCompoents[l][t](); + } + + PixelBoxPass(); + LogicGatePass(); +} + +void wiring_wrapper::PixelBoxPass() { + while (box_to_update.tail) { + --box_to_update.tail; + const auto box = box_to_update.cache[box_to_update.tail]; + if (box->state == 3) { + *box->TileFrameX = 18 - *box->TileFrameX; + } + box->state = 0; + } +} + +void wiring_wrapper::LogicGatePass() { + if (gates_current.tail) return; + ++update_round; + + while (lamps_to_check.tail) { + while (lamps_to_check.tail) { + --lamps_to_check.tail; + lamps_to_check.cache[lamps_to_check.tail](); + } + + while (gates_next.tail) { + { + auto t = gates_next; + gates_next = gates_current; + gates_current = t; + } + + for (int i = 0; i < gates_current.tail; ++i) { + auto& [x, y, t] = gates_current.cache[i]; + if (!t) { + + } else if (*t != update_round) { + *t = update_round; + TripWireSingle(x, y); + } + } + + gates_current.tail = 0; + } + } +} diff --git a/WireSharkLib/wiring_wrapper.h b/WireSharkLib/wiring_wrapper.h new file mode 100644 index 0000000..13b2223 --- /dev/null +++ b/WireSharkLib/wiring_wrapper.h @@ -0,0 +1,22 @@ +// +// Created by Administrator on 2023/12/15. +// + +#ifndef WIRING_WRAPPER_H +#define WIRING_WRAPPER_H + +namespace wiring_wrapper { + + void BigTripWire(int l, int t, int w, int h); + + void TripWireSingle(int l, int t); + + void PixelBoxPass(); + + void LogicGatePass(); + +}; + + + +#endif //WIRING_WRAPPER_H diff --git a/WireSharkRuntime/.gitattributes b/WireSharkRuntime/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/WireSharkRuntime/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/WireSharkRuntime/.gitignore b/WireSharkRuntime/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/WireSharkRuntime/.gitignore @@ -0,0 +1,340 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb \ No newline at end of file diff --git a/WireSharkRuntime/DLLManager.cs b/WireSharkRuntime/DLLManager.cs new file mode 100644 index 0000000..d237f04 --- /dev/null +++ b/WireSharkRuntime/DLLManager.cs @@ -0,0 +1,78 @@ +using System; +using System.IO; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Terraria; +using Terraria.ModLoader; + +namespace WireSharkRuntime; + +public static unsafe class DLLManager +{ + private const string libPath = "libWireSharkLib.dll"; + + [StructLayout(LayoutKind.Sequential)] + private struct PixelBox + { + public int state, x, y; + public short* TileFrameX; + + public override string ToString() + { + return $"pixelBox(x: {x}, y: {y}, state: {state})"; + } + } + + [DllImport(libPath)] + public static extern void BigTripWire(int x, int y, int w, int h); + + [DllImport(libPath)] + private static extern PixelBox* GetPixelBoxPointer(); + [DllImport(libPath)] + private static extern int GetPixelBoxCount(); + + [StructLayout(LayoutKind.Sequential)] + private struct UpdateInfo + { + public float* teleports; + public int teleport_len; + public int* triggers; + public int trigger_len; + }; + + [DllImport(libPath)] + private static extern void RetrieveUpdates(UpdateInfo* info); + + public static void Load() + { + NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), + (lib, _, _) => + lib == libPath + ? NativeLibrary.Load(Path.GetFullPath(Path.Combine(ModLoader.ModPath, libPath))) + : IntPtr.Zero); + + var count = GetPixelBoxCount(); + var ptr = GetPixelBoxPointer(); + + for (var i = 0; i < count; i++) + { + var tile = Main.tile[ptr[i].x, ptr[i].y]; + ptr[i].TileFrameX = (short *) Unsafe.AsPointer(ref tile.TileFrameX); + } + } + + public static void PostUpdate() + { + UpdateInfo info; + RetrieveUpdates(&info); + + for (var i = 0; i < info.trigger_len; ++i) + { + var x = info.triggers[2 * i]; + var y = info.triggers[2 * i + 1]; + + WireAccelerator._tileCache[x, y].HitWire(); + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Localization/en-US_Mods.WireShark.hjson b/WireSharkRuntime/Localization/en-US_Mods.WireShark.hjson new file mode 100644 index 0000000..f61f4b1 --- /dev/null +++ b/WireSharkRuntime/Localization/en-US_Mods.WireShark.hjson @@ -0,0 +1,6 @@ +Items: { + Test: { + DisplayName: Test + Tooltip: "" + } +} diff --git a/WireSharkRuntime/LogicGate.cs b/WireSharkRuntime/LogicGate.cs new file mode 100644 index 0000000..b9581d3 --- /dev/null +++ b/WireSharkRuntime/LogicGate.cs @@ -0,0 +1,43 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent.Events; +using Terraria.ModLoader; +using WireShark.Tiles; + +namespace WireShark +{ + //just a ref for state + public class PixelBox + { + [Flags] + public enum PixelBoxState + { + None = 0, + Vertical = 1, + Horizontal = 2 + } + + public PixelBoxState state; + public Tile tile; + public int x, y; + } + + internal abstract unsafe class LogicGate + { + public int x, y; + public Tile mapTile; + public int lamptotal; + public int* lampon = (int*) Marshal.AllocHGlobal(sizeof(int)); + public bool erroronly = false; + + public abstract void UpdateLogicGate(); + + ~LogicGate() + { + Marshal.FreeHGlobal((IntPtr) lampon); + } + } +} diff --git a/WireSharkRuntime/Properties/launchSettings.json b/WireSharkRuntime/Properties/launchSettings.json new file mode 100644 index 0000000..8da89ff --- /dev/null +++ b/WireSharkRuntime/Properties/launchSettings.json @@ -0,0 +1,16 @@ +{ + "profiles": { + "Terraria": { + "commandName": "Executable", + "executablePath": "dotnet", + "commandLineArgs": "$(tMLPath)", + "workingDirectory": "$(tMLSteamPath)" + }, + "TerrariaServer": { + "commandName": "Executable", + "executablePath": "dotnet", + "commandLineArgs": "$(tMLServerPath)", + "workingDirectory": "$(tMLSteamPath)" + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/TileInfo.cs b/WireSharkRuntime/TileInfo.cs new file mode 100644 index 0000000..88d43be --- /dev/null +++ b/WireSharkRuntime/TileInfo.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using SteelSeries.GameSense.DeviceZone; +using Terraria; +using Terraria.DataStructures; +using Terraria.ModLoader; + +namespace WireShark +{ + public abstract class TileInfo + { + private class ModTileInfo : TileInfo + { + private readonly ModTile _modTile; + public ModTileInfo(ModTile tile) + { + _modTile = tile; + } + + protected override void HitWireInternal() + { + if (tile.HasActuator) + Wiring.ActuateForced(i, j); + _modTile.HitWire(i, j); + } + } + + private class ActuatorTile : TileInfo + { + protected override void HitWireInternal() + { + if (tile.HasActuator) + Wiring.ActuateForced(i, j); + } + } + + public override string ToString() + { + return $"{tile}@({i},{j})"; + } + + public int i, j; + public long hash; + + public ushort type + { + get => tile.TileType; + set => tile.TileType = value; + } + + public Tile tile; + + private static Dictionary tileinfo = new Dictionary(); + + + static TileInfo() + { + foreach (var type in typeof(TileInfo).Assembly.GetTypes()) + { + if (!typeof(TileInfo).IsAssignableFrom(type) || type.IsAbstract) continue; + var name = type.Name; + if (int.TryParse(name.Substring(4), out var id)) + tileinfo.Add(id, type); + } + } + + public static TileInfo CreateTileInfo(int x, int y) + { + TileInfo result; + var mtile = ModContent.GetModTile(Main.tile[x, y].TileType); + if (mtile != null) + { + result = new ModTileInfo(mtile); + } + else if (tileinfo.TryGetValue(Main.tile[x, y].TileType, out var t)) + { + result = Activator.CreateInstance(t) as TileInfo; + } + else + { + result = new ActuatorTile(); + } + + result.tile = Main.tile[x, y]; + result.i = x; + result.j = y; + result.hash = ((long) x << 32) + y; + return result; + } + + protected abstract void HitWireInternal(); + + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] + public void HitWire() + { + HitWireInternal(); + } + } +} +/* +if (TileLoader.CloseDoorID(Main.tile[i, j]) >= 0) +{ + if (WorldGen.CloseDoor(i, j, true)) return; +} +else if (TileLoader.OpenDoorID(Main.tile[i, j]) >= 0) +{ + int num66 = 1; + if (Main.rand.Next(2) == 0) + { + num66 = -1; + } + + if (WorldGen.OpenDoor(i, j, num66)) + { + return; + } + + if (WorldGen.OpenDoor(i, j, -num66)) + { + return; + } +} +else if (TileLoader.IsTorch(type)) +{ + if (tile.frameX < 66) + { + Tile tile4 = tile; + tile4.frameX += 66; + } + else + { + Tile tile5 = tile; + tile5.frameX -= 66; + } + + return; +} +else if (TileLoader.IsModMusicBox(tile)) +{ + WorldGen.SwitchMB(i, j); + return; +} +*/ diff --git a/WireSharkRuntime/Tiles/Tile100.cs b/WireSharkRuntime/Tiles/Tile100.cs new file mode 100644 index 0000000..c61fdda --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile100.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile100 : Tile173 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile105.cs b/WireSharkRuntime/Tiles/Tile105.cs new file mode 100644 index 0000000..afcf217 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile105.cs @@ -0,0 +1,420 @@ +using System.Collections.Generic; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; + +namespace WireShark.Tiles; + +public class Tile105 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num128 = j - tile.TileFrameY / 18; + var num129 = tile.TileFrameX / 18; + var num130 = 0; + while (num129 >= 2) + { + num129 -= 2; + num130++; + } + + num129 = i - num129; + num129 = i - tile.TileFrameX % 36 / 18; + num128 = j - tile.TileFrameY % 54 / 18; + num130 = tile.TileFrameX / 36 + tile.TileFrameY / 54 * 55; + + + var num131 = num129 * 16 + 16; + var num132 = (num128 + 3) * 16; + var num133 = -1; + var num134 = -1; + var flag11 = true; + var flag12 = false; + switch (num130) + { + case 51: + num134 = Utils.SelectRandom(Main.rand, new short[] + { + 299, + 538 + }); + break; + case 52: + num134 = 356; + break; + case 53: + num134 = 357; + break; + case 54: + num134 = Utils.SelectRandom(Main.rand, new short[] + { + 355, + 358 + }); + break; + case 55: + num134 = Utils.SelectRandom(Main.rand, new short[] + { + 367, + 366 + }); + break; + case 56: + num134 = Utils.SelectRandom(Main.rand, new short[] + { + 359, + 359, + 359, + 359, + 360 + }); + break; + case 57: + num134 = 377; + break; + case 58: + num134 = 300; + break; + case 59: + num134 = Utils.SelectRandom(Main.rand, new short[] + { + 364, + 362 + }); + break; + case 60: + num134 = 148; + break; + case 61: + num134 = 361; + break; + case 62: + num134 = Utils.SelectRandom(Main.rand, new short[] + { + 487, + 486, + 485 + }); + break; + case 63: + num134 = 164; + flag11 &= NPC.MechSpawn(num131, num132, 165); + break; + case 64: + num134 = 86; + flag12 = true; + break; + case 65: + num134 = 490; + break; + case 66: + num134 = 82; + break; + case 67: + num134 = 449; + break; + case 68: + num134 = 167; + break; + case 69: + num134 = 480; + break; + case 70: + num134 = 48; + break; + case 71: + num134 = Utils.SelectRandom(Main.rand, new short[] + { + 170, + 180, + 171 + }); + flag12 = true; + break; + case 72: + num134 = 481; + break; + case 73: + num134 = 482; + break; + case 74: + num134 = 430; + break; + case 75: + num134 = 489; + break; + } + + if (num134 != -1 && Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, num134) && + flag11) + { + if (!flag12 || !Collision.SolidTiles(num129 - 2, num129 + 3, num128, num128 + 2)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, num134, 0, 0f, 0f, 0f, 0f, 255); + } + else + { + var position = new Vector2(num131 - 4, num132 - 22) - new Vector2(10f); + Utils.PoofOfSmoke(position); + } + } + + if (num133 <= -1) + { + switch (num130) + { + case 4: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 1)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, 1, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 7: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 49)) + { + num133 = NPC.NewNPC(null, num131 - 4, num132 - 6, 49, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 8: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 55)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, 55, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 9: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 46)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, 46, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 10: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 21)) + { + num133 = NPC.NewNPC(null, num131, num132, 21, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 18: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 67)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, 67, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 23: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 63)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, 63, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 27: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 85)) + { + num133 = NPC.NewNPC(null, num131 - 9, num132, 85, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 28: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 74)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, Utils.SelectRandom(Main.rand, + new short[] + { + 74, + 297, + 298 + }), 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 34: + { + for (var num135 = 0; num135 < 2; num135++) + { + for (var num136 = 0; num136 < 3; num136++) + { + var tile22 = Main.tile[num129 + num135, num128 + num136]; + tile22.TileType = 349; + tile22.TileFrameX = (short) (num135 * 18 + 216); + tile22.TileFrameY = (short) (num136 * 18); + } + } + + Animation.NewTemporaryAnimation(0, 349, num129, num128); + if (Main.netMode == NetmodeID.Server) + { + } + + break; + } + case 42: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 58)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, 58, 0, 0f, 0f, 0f, 0f, 255); + } + + break; + } + case 37: + { + if (Wiring.CheckMech(num129, num128, 600) && Item.MechSpawn(num131, num132, 58) && + Item.MechSpawn(num131, num132, 1734) && Item.MechSpawn(num131, num132, 1867)) + { + Item.NewItem(null, num131, num132 - 16, 0, 0, 58, 1, false, 0, false, false); + } + + break; + } + case 50: + { + if (Wiring.CheckMech(num129, num128, 30) && NPC.MechSpawn(num131, num132, 65)) + { + if (!Collision.SolidTiles(num129 - 2, num129 + 3, num128, num128 + 2)) + { + num133 = NPC.NewNPC(null, num131, num132 - 12, 65, 0, 0f, 0f, 0f, 0f, 255); + } + else + { + var position2 = new Vector2(num131 - 4, num132 - 22) - new Vector2(10f); + Utils.PoofOfSmoke(position2); + } + } + + break; + } + case 2: + { + if (Wiring.CheckMech(num129, num128, 600) && Item.MechSpawn(num131, num132, 184) && + Item.MechSpawn(num131, num132, 1735) && Item.MechSpawn(num131, num132, 1868)) + { + Item.NewItem(null, num131, num132 - 16, 0, 0, 184, 1, false, 0, false, false); + } + + break; + } + case 17: + { + if (Wiring.CheckMech(num129, num128, 600) && Item.MechSpawn(num131, num132, 166)) + { + Item.NewItem(null, num131, num132 - 20, 0, 0, 166, 1, false, 0, false, false); + } + + break; + } + case 40: + { + if (Wiring.CheckMech(num129, num128, 300)) + { + var array = new List(); + var num137 = 0; + for (var num138 = 0; num138 < 200; num138++) + { + var vanillaCanGo = Main.npc[num138].type == NPCID.Merchant || + Main.npc[num138].type == NPCID.ArmsDealer || + Main.npc[num138].type == NPCID.Guide || + Main.npc[num138].type == NPCID.Demolitionist || + Main.npc[num138].type == NPCID.Clothier || + Main.npc[num138].type == NPCID.GoblinTinkerer || + Main.npc[num138].type == NPCID.Wizard || + Main.npc[num138].type == NPCID.SantaClaus || + Main.npc[num138].type == NPCID.Truffle || + Main.npc[num138].type == NPCID.DyeTrader || + Main.npc[num138].type == NPCID.Cyborg || + Main.npc[num138].type == NPCID.Painter || + Main.npc[num138].type == NPCID.WitchDoctor || + Main.npc[num138].type == NPCID.Pirate || + Main.npc[num138].type == NPCID.LightningBug || + Main.npc[num138].type == NPCID.Angler || + Main.npc[num138].type == NPCID.DD2Bartender; + if (Main.npc[num138].active && + NPCLoader.CanGoToStatue(Main.npc[num138], true).HasValue) + { + array.Add(num138); + num137++; + } + } + + if (num137 > 0) + { + var num139 = array[Main.rand.Next(num137)]; + Main.npc[num139].position.X = num131 - Main.npc[num139].width / 2; + Main.npc[num139].position.Y = num132 - Main.npc[num139].height - 1; + + NPCLoader.OnGoToStatue(Main.npc[num139], true); + } + } + + break; + } + case 41: + { + if (Wiring.CheckMech(num129, num128, 300)) + { + var array2 = new List(); + var num140 = 0; + for (var num141 = 0; num141 < 200; num141++) + { + var vanillaCanGo2 = Main.npc[num141].type == NPCID.Nurse || + Main.npc[num141].type == NPCID.Dryad || + Main.npc[num141].type == NPCID.Mechanic || + Main.npc[num141].type == NPCID.Steampunker || + Main.npc[num141].type == NPCID.PartyGirl || + Main.npc[num141].type == NPCID.Stylist; + if (Main.npc[num141].active && NPCLoader.CanGoToStatue(Main.npc[num141], false).HasValue) + { + array2.Add(num141); + num140++; + } + } + + if (num140 > 0) + { + var num142 = array2[Main.rand.Next(num140)]; + Main.npc[num142].position.X = num131 - Main.npc[num142].width / 2; + Main.npc[num142].position.Y = num132 - Main.npc[num142].height - 1; + + NPCLoader.OnGoToStatue(Main.npc[num142], false); + } + + } + + break; + } + } + } + + if (num133 >= 0) + { + Main.npc[num133].value = 0f; + Main.npc[num133].npcSlots = 0f; + Main.npc[num133].SpawnedFromStatue = true; + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile126.cs b/WireSharkRuntime/Tiles/Tile126.cs new file mode 100644 index 0000000..e44d098 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile126.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile126 : Tile173 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile130.cs b/WireSharkRuntime/Tiles/Tile130.cs new file mode 100644 index 0000000..d7e7bb4 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile130.cs @@ -0,0 +1,29 @@ +using Terraria; +using Terraria.ID; + +namespace WireShark.Tiles; + +public class Tile130 : TileInfo +{ + protected override void HitWireInternal() + { + { + if (Main.tile[i, j - 1] != null && Main.tile[i, j - 1].HasTile) + { + if (TileID.Sets.BasicChest[Main.tile[i, j - 1].TileType] || + TileID.Sets.BasicChestFake[Main.tile[i, j - 1].TileType]) + { + return; + } + + if (Main.tile[i, j - 1].TileType == 88) + { + return; + } + } + + tile.TileType = 131; + WorldGen.SquareTileFrame(i, j, true); + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile131.cs b/WireSharkRuntime/Tiles/Tile131.cs new file mode 100644 index 0000000..c49f146 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile131.cs @@ -0,0 +1,13 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile131 : TileInfo +{ + protected override void HitWireInternal() + { + + tile.TileType = 130; + WorldGen.SquareTileFrame(i, j, true); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile137.cs b/WireSharkRuntime/Tiles/Tile137.cs new file mode 100644 index 0000000..75e810b --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile137.cs @@ -0,0 +1,323 @@ +using Microsoft.Xna.Framework; +using Terraria; + +namespace WireShark.Tiles; + +public class Tile137 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num99 = tile.TileFrameY / 18; + var zero = Vector2.Zero; + var speedX = 0f; + var speedY = 0f; + var num100 = 0; + var damage2 = 0; + switch (num99) + { + case 0: + case 1: + case 2: + if (Wiring.CheckMech(i, j, 200)) + { + var num101 = (tile.TileFrameX == 0) ? -1 : ((tile.TileFrameX == 18) ? 1 : 0); + var num102 = (tile.TileFrameX < 36) ? 0 : ((tile.TileFrameX < 72) ? -1 : 1); + zero = new Vector2(i * 16 + 8 + 10 * num101, j * 16 + 9 + num102 * 9); + var num103 = 3f; + if (num99 == 0) + { + num100 = 98; + damage2 = 20; + num103 = 12f; + } + + if (num99 == 1) + { + num100 = 184; + damage2 = 40; + num103 = 12f; + } + + if (num99 == 2) + { + num100 = 187; + damage2 = 40; + num103 = 5f; + } + + speedX = num101 * num103; + speedY = num102 * num103; + } + + break; + case 3: + if (Wiring.CheckMech(i, j, 300)) + { + var num104 = 200; + for (var num105 = 0; num105 < 1000; num105++) + { + if (Main.projectile[num105].active && Main.projectile[num105].type == num100) + { + var num106 = (new Vector2(i * 16 + 8, j * 18 + 8) - + Main.projectile[num105].Center).Length(); + if (num106 < 50f) + { + num104 -= 50; + } + else if (num106 < 100f) + { + num104 -= 15; + } + else if (num106 < 200f) + { + num104 -= 10; + } + else if (num106 < 300f) + { + num104 -= 8; + } + else if (num106 < 400f) + { + num104 -= 6; + } + else if (num106 < 500f) + { + num104 -= 5; + } + else if (num106 < 700f) + { + num104 -= 4; + } + else if (num106 < 900f) + { + num104 -= 3; + } + else if (num106 < 1200f) + { + num104 -= 2; + } + else + { + num104--; + } + } + } + + if (num104 > 0) + { + num100 = 185; + damage2 = 40; + var num107 = 0; + var num108 = 0; + switch (tile.TileFrameX / 18) + { + case 0: + case 1: + num107 = 0; + num108 = 1; + break; + case 2: + num107 = 0; + num108 = -1; + break; + case 3: + num107 = -1; + num108 = 0; + break; + case 4: + num107 = 1; + num108 = 0; + break; + } + + speedX = 4 * num107 + Main.rand.Next(-20 + ((num107 == 1) ? 20 : 0), + 21 - ((num107 == -1) ? 20 : 0)) * 0.05f; + speedY = 4 * num108 + Main.rand.Next(-20 + ((num108 == 1) ? 20 : 0), + 21 - ((num108 == -1) ? 20 : 0)) * 0.05f; + zero = new Vector2(i * 16 + 8 + 14 * num107, j * 16 + 8 + 14 * num108); + } + } + + break; + case 4: + if (Wiring.CheckMech(i, j, 90)) + { + var num109 = 0; + var num110 = 0; + switch (tile.TileFrameX / 18) + { + case 0: + case 1: + num109 = 0; + num110 = 1; + break; + case 2: + num109 = 0; + num110 = -1; + break; + case 3: + num109 = -1; + num110 = 0; + break; + case 4: + num109 = 1; + num110 = 0; + break; + } + + speedX = 8 * num109; + speedY = 8 * num110; + damage2 = 60; + num100 = 186; + zero = new Vector2(i * 16 + 8 + 18 * num109, j * 16 + 8 + 18 * num110); + } + + break; + } + + switch (num99 + 10) + { + case 0: + if (Wiring.CheckMech(i, j, 200)) + { + var num111 = -1; + if (tile.TileFrameX != 0) + { + num111 = 1; + } + + speedX = 12 * num111; + damage2 = 20; + num100 = 98; + zero = new Vector2(i * 16 + 8, j * 16 + 7); + zero.X += 10 * num111; + zero.Y += 2f; + } + + break; + case 1: + if (Wiring.CheckMech(i, j, 200)) + { + var num112 = -1; + if (tile.TileFrameX != 0) + { + num112 = 1; + } + + speedX = 12 * num112; + damage2 = 40; + num100 = 184; + zero = new Vector2(i * 16 + 8, j * 16 + 7); + zero.X += 10 * num112; + zero.Y += 2f; + } + + break; + case 2: + if (Wiring.CheckMech(i, j, 200)) + { + var num113 = -1; + if (tile.TileFrameX != 0) + { + num113 = 1; + } + + speedX = 5 * num113; + damage2 = 40; + num100 = 187; + zero = new Vector2(i * 16 + 8, j * 16 + 7); + zero.X += 10 * num113; + zero.Y += 2f; + } + + break; + case 3: + if (Wiring.CheckMech(i, j, 300)) + { + num100 = 185; + var num114 = 200; + for (var num115 = 0; num115 < 1000; num115++) + { + if (Main.projectile[num115].active && Main.projectile[num115].type == num100) + { + var num116 = (new Vector2(i * 16 + 8, j * 18 + 8) - + Main.projectile[num115].Center).Length(); + if (num116 < 50f) + { + num114 -= 50; + } + else if (num116 < 100f) + { + num114 -= 15; + } + else if (num116 < 200f) + { + num114 -= 10; + } + else if (num116 < 300f) + { + num114 -= 8; + } + else if (num116 < 400f) + { + num114 -= 6; + } + else if (num116 < 500f) + { + num114 -= 5; + } + else if (num116 < 700f) + { + num114 -= 4; + } + else if (num116 < 900f) + { + num114 -= 3; + } + else if (num116 < 1200f) + { + num114 -= 2; + } + else + { + num114--; + } + } + } + + if (num114 > 0) + { + speedX = Main.rand.Next(-20, 21) * 0.05f; + speedY = 4f + Main.rand.Next(0, 21) * 0.05f; + damage2 = 40; + zero = new Vector2(i * 16 + 8, j * 16 + 16); + zero.Y += 6f; + Projectile.NewProjectile(null, (int) zero.X, (int) zero.Y, speedX, speedY, num100, + damage2, 2f, Main.myPlayer, 0f, 0f); + } + } + + break; + case 4: + if (Wiring.CheckMech(i, j, 90)) + { + speedX = 0f; + speedY = 8f; + damage2 = 60; + num100 = 186; + zero = new Vector2(i * 16 + 8, j * 16 + 16); + zero.Y += 10f; + } + + break; + } + + if (num100 != 0) + { + Projectile.NewProjectile(null, (int) zero.X, (int) zero.Y, speedX, speedY, num100, damage2, 2f, + Main.myPlayer, 0f, 0f); + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile139.cs b/WireSharkRuntime/Tiles/Tile139.cs new file mode 100644 index 0000000..1153f5b --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile139.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile139 : Tile35 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile141.cs b/WireSharkRuntime/Tiles/Tile141.cs new file mode 100644 index 0000000..85ffe68 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile141.cs @@ -0,0 +1,15 @@ +using Terraria; +using Terraria.ID; + +namespace WireShark.Tiles; + +public class Tile141 : TileInfo +{ + protected override void HitWireInternal() + { + WorldGen.KillTile(i, j, false, false, true); + + Projectile.NewProjectile(null, i * 16 + 8, j * 16 + 8, 0f, 0f, ProjectileID.Explosives, 500, 10f, + Main.myPlayer, 0f, 0f); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile142.cs b/WireSharkRuntime/Tiles/Tile142.cs new file mode 100644 index 0000000..36062c7 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile142.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile142 : Tile143 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile143.cs b/WireSharkRuntime/Tiles/Tile143.cs new file mode 100644 index 0000000..41e1c04 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile143.cs @@ -0,0 +1,11 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile143 : TileInfo +{ + protected override void HitWireInternal() + { + Main.NewText("pump not implemented"); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile144.cs b/WireSharkRuntime/Tiles/Tile144.cs new file mode 100644 index 0000000..6085829 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile144.cs @@ -0,0 +1,13 @@ +using Terraria; +using WireSharkRuntime; + +namespace WireShark.Tiles; + +public class Tile144 : TileInfo +{ + protected override void HitWireInternal() + { + WiringWrapper.HitSwitch(i, j); + WorldGen.SquareTileFrame(i, j, true); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile149.cs b/WireSharkRuntime/Tiles/Tile149.cs new file mode 100644 index 0000000..309ced8 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile149.cs @@ -0,0 +1,20 @@ +namespace WireShark.Tiles; + +public class Tile149 : TileInfo +{ + protected override void HitWireInternal() + { + { + if (tile.TileFrameX < 54) + { + var tile8 = tile; + tile8.TileFrameX += 54; + } + else + { + var tile9 = tile; + tile9.TileFrameX -= 54; + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile173.cs b/WireSharkRuntime/Tiles/Tile173.cs new file mode 100644 index 0000000..5b667af --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile173.cs @@ -0,0 +1,39 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile173 : TileInfo +{ + protected override void HitWireInternal() + { + { + int num86; + for (num86 = tile.TileFrameY / 18; num86 >= 2; num86 -= 2) + { + } + + num86 = j - num86; + var num87 = tile.TileFrameX / 18; + if (num87 > 1) + { + num87 -= 2; + } + + num87 = i - num87; + short num88 = 36; + if (Main.tile[num87, num86].TileFrameX > 0) + { + num88 = -36; + } + + var tile15 = Main.tile[num87, num86]; + tile15.TileFrameX += num88; + var tile16 = Main.tile[num87, num86 + 1]; + tile16.TileFrameX += num88; + var tile17 = Main.tile[num87 + 1, num86]; + tile17.TileFrameX += num88; + var tile18 = Main.tile[num87 + 1, num86 + 1]; + tile18.TileFrameX += num88; + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile174.cs b/WireSharkRuntime/Tiles/Tile174.cs new file mode 100644 index 0000000..e5277b2 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile174.cs @@ -0,0 +1,18 @@ +namespace WireShark.Tiles; + +public class Tile174 : TileInfo +{ + protected override void HitWireInternal() + { + { + short num95 = 18; + if (tile.TileFrameX > 0) + { + num95 = -18; + } + + var tile20 = tile; + tile20.TileFrameX += num95; + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile207.cs b/WireSharkRuntime/Tiles/Tile207.cs new file mode 100644 index 0000000..9a53cbd --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile207.cs @@ -0,0 +1,11 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile207 : TileInfo +{ + protected override void HitWireInternal() + { + WorldGen.SwitchFountain(i, j); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile209.cs b/WireSharkRuntime/Tiles/Tile209.cs new file mode 100644 index 0000000..6359841 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile209.cs @@ -0,0 +1,86 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile209 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num34 = tile.TileFrameX % 72 / 18; + var num35 = tile.TileFrameY % 54 / 18; + var num36 = i - num34; + var num37 = j - num35; + var num38 = tile.TileFrameY / 54; + var num39 = tile.TileFrameX / 72; + var num40 = -1; + if (num34 == 1 || num34 == 2) + { + num40 = num35; + } + + var num41 = 0; + if (num34 == 3) + { + num41 = -54; + } + + if (num34 == 0) + { + num41 = 54; + } + + if (num38 >= 8 && num41 > 0) + { + num41 = 0; + } + + if (num38 == 0 && num41 < 0) + { + num41 = 0; + } + + var flag = false; + if (num41 != 0) + { + for (var num42 = num36; num42 < num36 + 4; num42++) + { + for (var num43 = num37; num43 < num37 + 3; num43++) + { + Main.tile[num42, num43].TileFrameY = (short) (Main.tile[num42, num43].TileFrameY + num41); + } + } + + flag = true; + } + + if ((num39 == 3 || num39 == 4) && (num40 == 0 || num40 == 1)) + { + num41 = ((num39 == 3) ? 72 : -72); + for (var num44 = num36; num44 < num36 + 4; num44++) + { + for (var num45 = num37; num45 < num37 + 3; num45++) + { + Main.tile[num44, num45].TileFrameX = (short) (Main.tile[num44, num45].TileFrameX + num41); + } + } + + flag = true; + } + + if (flag) + { + } + + if (num40 != -1) + { + bool flag2 = !((num39 == 3 || num39 == 4) && num40 < 2); + + if (Wiring.CheckMech(num36, num37, 30) && flag2) + { + WorldGen.ShootFromCannon(num36, num37, num38, num39 + 1, 0, 0f, Main.myPlayer, true); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile210.cs b/WireSharkRuntime/Tiles/Tile210.cs new file mode 100644 index 0000000..716a492 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile210.cs @@ -0,0 +1,11 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile210 : TileInfo +{ + protected override void HitWireInternal() + { + WorldGen.ExplodeMine(i, j, true); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile212.cs b/WireSharkRuntime/Tiles/Tile212.cs new file mode 100644 index 0000000..55953e2 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile212.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.Xna.Framework; +using Terraria; + +namespace WireShark.Tiles; + +public class Tile212 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num46 = tile.TileFrameX % 54 / 18; + var num47 = tile.TileFrameY % 54 / 18; + var num48 = i - num46; + var num49 = j - num47; + var num148 = (short) (tile.TileFrameX / 54); + var num50 = -1; + if (num46 == 1) + { + num50 = num47; + } + + var num51 = 0; + if (num46 == 0) + { + num51 = -54; + } + + if (num46 == 2) + { + num51 = 54; + } + + if (num148 >= 1 && num51 > 0) + { + num51 = 0; + } + + if (num148 == 0 && num51 < 0) + { + num51 = 0; + } + + var flag3 = false; + if (num51 != 0) + { + for (var num52 = num48; num52 < num48 + 3; num52++) + { + for (var num53 = num49; num53 < num49 + 3; num53++) + { + Main.tile[num52, num53].TileFrameX = (short) (Main.tile[num52, num53].TileFrameX + num51); + } + } + + flag3 = true; + } + + if (flag3) + { + } + + if (num50 != -1 && Wiring.CheckMech(num48, num49, 10)) + { + var num149 = 12f + Main.rand.Next(450) * 0.01f; + float num54 = Main.rand.Next(85, 105); + float num150 = Main.rand.Next(-35, 11); + var type2 = 166; + var damage = 0; + var knockBack = 0f; + var vector = new Vector2((num48 + 2) * 16 - 8, (num49 + 2) * 16 - 8); + if (tile.TileFrameX / 54 == 0) + { + num54 *= -1f; + vector.X -= 12f; + } + else + { + vector.X += 12f; + } + + var num55 = num54; + var num56 = num150; + var num57 = (float) Math.Sqrt(num55 * num55 + num56 * num56); + num57 = num149 / num57; + num55 *= num57; + num56 *= num57; + Projectile.NewProjectile(null, vector.X, vector.Y, num55, num56, type2, damage, knockBack, Main.myPlayer, 0f, 0f); + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile215.cs b/WireSharkRuntime/Tiles/Tile215.cs new file mode 100644 index 0000000..ed82b1b --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile215.cs @@ -0,0 +1,29 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile215 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num58 = tile.TileFrameX % 54 / 18; + var num59 = tile.TileFrameY % 36 / 18; + var num60 = i - num58; + var num61 = j - num59; + var num62 = 36; + if (Main.tile[num60, num61].TileFrameY >= 36) + { + num62 = -36; + } + + for (var num63 = num60; num63 < num60 + 3; num63++) + { + for (var num64 = num61; num64 < num61 + 2; num64++) + { + Main.tile[num63, num64].TileFrameY = (short) (Main.tile[num63, num64].TileFrameY + num62); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile216.cs b/WireSharkRuntime/Tiles/Tile216.cs new file mode 100644 index 0000000..9b9b534 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile216.cs @@ -0,0 +1,11 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile216 : TileInfo +{ + protected override void HitWireInternal() + { + WorldGen.LaunchRocket(i, j, true); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile235.cs b/WireSharkRuntime/Tiles/Tile235.cs new file mode 100644 index 0000000..ad28fc9 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile235.cs @@ -0,0 +1,112 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; + +namespace WireShark.Tiles; + +public class Tile235 : TileInfo +{ + public static Vector2[] _teleport = new Vector2[2]; + + static Tile235() + { + _teleport[0] = new Vector2(-1, -1); + _teleport[1] = new Vector2(-1, -1); + } + protected override unsafe void HitWireInternal() + { + int num153 = i - tile.TileFrameX / 18; + if (_teleport[0].X == -1f) + { + _teleport[0].X = num153; + _teleport[0].Y = j; + if (tile.IsHalfBlock) + { + _teleport[0].Y += 0.5f; + } + } + else if (_teleport[0].X != num153 || _teleport[0].Y != j) + { + _teleport[1].X = num153; + _teleport[1].Y = j; + if (tile.IsHalfBlock) + { + _teleport[1].Y += 0.5f; + } + + Teleport(); + _teleport[0] = new Vector2(-1, -1); + _teleport[1] = new Vector2(-1, -1); + } + } + private static bool TeleporterHitboxIntersects(Rectangle teleporter, Rectangle entity) + { + Rectangle rectangle = Rectangle.Union(teleporter, entity); + return rectangle.Width <= teleporter.Width + entity.Width && rectangle.Height <= teleporter.Height + entity.Height; + } + + private static void Teleport() + { + if (_teleport[0].X < _teleport[1].X + 3f && _teleport[0].X > _teleport[1].X - 3f && _teleport[0].Y > _teleport[1].Y - 3f && _teleport[0].Y < _teleport[1].Y) + { + return; + } + Rectangle[] array = new Rectangle[2]; + array[0].X = (int)(_teleport[0].X * 16f); + array[0].Width = 48; + array[0].Height = 48; + array[0].Y = (int)(_teleport[0].Y * 16f - (float)array[0].Height); + array[1].X = (int)(_teleport[1].X * 16f); + array[1].Width = 48; + array[1].Height = 48; + array[1].Y = (int)(_teleport[1].Y * 16f - (float)array[1].Height); + for (int i = 0; i < 2; i++) + { + Vector2 vector = new Vector2((float)(array[1].X - array[0].X), (float)(array[1].Y - array[0].Y)); + if (i == 1) + { + vector = new Vector2((float)(array[0].X - array[1].X), (float)(array[0].Y - array[1].Y)); + } + if (!Wiring.blockPlayerTeleportationForOneIteration) + { + for (int j = 0; j < 255; j++) + { + if (Main.player[j].active && !Main.player[j].dead && !Main.player[j].teleporting && TeleporterHitboxIntersects(array[i], Main.player[j].Hitbox)) + { + Vector2 vector2 = Main.player[j].position + vector; + Main.player[j].teleporting = true; + if (Main.netMode == 2) + { + RemoteClient.CheckSection(j, vector2, 1); + } + Main.player[j].Teleport(vector2, 0, 0); + if (Main.netMode == 2) + { + NetMessage.SendData(65, -1, -1, null, 0, (float)j, vector2.X, vector2.Y, 0, 0, 0); + } + } + } + } + for (int k = 0; k < 200; k++) + { + if (Main.npc[k].active && !Main.npc[k].teleporting && Main.npc[k].lifeMax > 5 && !Main.npc[k].boss && !Main.npc[k].noTileCollide) + { + int type = Main.npc[k].type; + if (!NPCID.Sets.TeleportationImmune[type] && TeleporterHitboxIntersects(array[i], Main.npc[k].Hitbox)) + { + Main.npc[k].teleporting = true; + Main.npc[k].Teleport(Main.npc[k].position + vector, 0, 0); + } + } + } + } + for (int l = 0; l < 255; l++) + { + Main.player[l].teleporting = false; + } + for (int m = 0; m < 200; m++) + { + Main.npc[m].teleporting = false; + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile244.cs b/WireSharkRuntime/Tiles/Tile244.cs new file mode 100644 index 0000000..b7f5eaa --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile244.cs @@ -0,0 +1,37 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile244 : TileInfo +{ + protected override void HitWireInternal() + { + { + int num74; + for (num74 = tile.TileFrameX / 18; num74 >= 3; num74 -= 3) + { + } + + int num75; + for (num75 = tile.TileFrameY / 18; num75 >= 3; num75 -= 3) + { + } + + var num76 = i - num74; + var num77 = j - num75; + var num78 = 54; + if (Main.tile[num76, num77].TileFrameX >= 54) + { + num78 = -54; + } + + for (var num79 = num76; num79 < num76 + 3; num79++) + { + for (var num80 = num77; num80 < num77 + 2; num80++) + { + Main.tile[num79, num80].TileFrameX = (short) (Main.tile[num79, num80].TileFrameX + num78); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile255.cs b/WireSharkRuntime/Tiles/Tile255.cs new file mode 100644 index 0000000..62d593a --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile255.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile255 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile256.cs b/WireSharkRuntime/Tiles/Tile256.cs new file mode 100644 index 0000000..9ada032 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile256.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile256 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile257.cs b/WireSharkRuntime/Tiles/Tile257.cs new file mode 100644 index 0000000..e164d80 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile257.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile257 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile258.cs b/WireSharkRuntime/Tiles/Tile258.cs new file mode 100644 index 0000000..593cdc5 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile258.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile258 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile259.cs b/WireSharkRuntime/Tiles/Tile259.cs new file mode 100644 index 0000000..2c99ab4 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile259.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile259 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile260.cs b/WireSharkRuntime/Tiles/Tile260.cs new file mode 100644 index 0000000..9e2d272 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile260.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile260 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile261.cs b/WireSharkRuntime/Tiles/Tile261.cs new file mode 100644 index 0000000..cf83ec3 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile261.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile261 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile262.cs b/WireSharkRuntime/Tiles/Tile262.cs new file mode 100644 index 0000000..defcb1a --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile262.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile262 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile263.cs b/WireSharkRuntime/Tiles/Tile263.cs new file mode 100644 index 0000000..6b904a9 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile263.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile263 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile264.cs b/WireSharkRuntime/Tiles/Tile264.cs new file mode 100644 index 0000000..3a84672 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile264.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile264 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile265.cs b/WireSharkRuntime/Tiles/Tile265.cs new file mode 100644 index 0000000..ff89ad0 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile265.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile265 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile266.cs b/WireSharkRuntime/Tiles/Tile266.cs new file mode 100644 index 0000000..4206ab9 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile266.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile266 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile267.cs b/WireSharkRuntime/Tiles/Tile267.cs new file mode 100644 index 0000000..5441561 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile267.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile267 : Tile268 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile268.cs b/WireSharkRuntime/Tiles/Tile268.cs new file mode 100644 index 0000000..dea16d5 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile268.cs @@ -0,0 +1,23 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile268 : TileInfo +{ + protected override void HitWireInternal() + { + if (!tile.HasActuator) + { + if (type >= 262) + { + type -= 7; + } + else + { + type += 7; + } + + WorldGen.SquareTileFrame(i, j, true); + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile314.cs b/WireSharkRuntime/Tiles/Tile314.cs new file mode 100644 index 0000000..a1e655d --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile314.cs @@ -0,0 +1,16 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile314 : TileInfo +{ + protected override void HitWireInternal() + { + { + if (Wiring.CheckMech(i, j, 5)) + { + Minecart.FlipSwitchTrack(i, j); + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile33.cs b/WireSharkRuntime/Tiles/Tile33.cs new file mode 100644 index 0000000..d4b155c --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile33.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile33 : Tile174 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile335.cs b/WireSharkRuntime/Tiles/Tile335.cs new file mode 100644 index 0000000..e7ff454 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile335.cs @@ -0,0 +1,20 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile335 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num67 = j - tile.TileFrameY / 18; + var num68 = i - tile.TileFrameX / 18; + + + if (Wiring.CheckMech(num68, num67, 30)) + { + WorldGen.LaunchRocketSmall(num68, num67, true); + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile338.cs b/WireSharkRuntime/Tiles/Tile338.cs new file mode 100644 index 0000000..7c50431 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile338.cs @@ -0,0 +1,35 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile338 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num69 = j - tile.TileFrameY / 18; + var num70 = i - tile.TileFrameX / 18; + + + if (Wiring.CheckMech(num70, num69, 30)) + { + var flag5 = false; + for (var num71 = 0; num71 < 1000; num71++) + { + if (Main.projectile[num71].active && Main.projectile[num71].aiStyle == 73 && + Main.projectile[num71].ai[0] == num70 && Main.projectile[num71].ai[1] == num69) + { + flag5 = true; + break; + } + } + + if (!flag5) + { + Projectile.NewProjectile(null, num70 * 16 + 8, num69 * 16 + 2, 0f, 0f, + 419 + Main.rand.Next(4), 0, 0f, Main.myPlayer, num70, num69); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile34.cs b/WireSharkRuntime/Tiles/Tile34.cs new file mode 100644 index 0000000..32551e8 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile34.cs @@ -0,0 +1,39 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile34 : TileInfo +{ + protected override void HitWireInternal() + { + { + int num89; + for (num89 = tile.TileFrameY / 18; num89 >= 3; num89 -= 3) + { + } + + var num90 = j - num89; + var num91 = tile.TileFrameX % 108 / 18; + if (num91 > 2) + { + num91 -= 3; + } + + num91 = i - num91; + short num92 = 54; + if (Main.tile[num91, num90].TileFrameX % 108 > 0) + { + num92 = -54; + } + + for (var num93 = num91; num93 < num91 + 3; num93++) + { + for (var num94 = num90; num94 < num90 + 3; num94++) + { + var tile19 = Main.tile[num93, num94]; + tile19.TileFrameX += num92; + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile349.cs b/WireSharkRuntime/Tiles/Tile349.cs new file mode 100644 index 0000000..55114d0 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile349.cs @@ -0,0 +1,46 @@ +using Terraria; +using Terraria.ID; + +namespace WireShark.Tiles; + +public class Tile349 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num143 = j - tile.TileFrameY / 18; + int num144; + for (num144 = tile.TileFrameX / 18; num144 >= 2; num144 -= 2) + { + } + + num144 = i - num144; + + + short num145; + if (Main.tile[num144, num143].TileFrameX == 0) + { + num145 = 216; + } + else + { + num145 = -216; + } + + for (var num146 = 0; num146 < 2; num146++) + { + for (var num147 = 0; num147 < 3; num147++) + { + var tile23 = Main.tile[num144 + num146, num143 + num147]; + tile23.TileFrameX += num145; + } + } + + if (Main.netMode == NetmodeID.Server) + { + } + + Animation.NewTemporaryAnimation((num145 > 0) ? 0 : 1, 349, num144, num143); + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile35.cs b/WireSharkRuntime/Tiles/Tile35.cs new file mode 100644 index 0000000..1d796a1 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile35.cs @@ -0,0 +1,11 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile35 : TileInfo +{ + protected override void HitWireInternal() + { + WorldGen.SwitchMB(i, j); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile386.cs b/WireSharkRuntime/Tiles/Tile386.cs new file mode 100644 index 0000000..ae4c40a --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile386.cs @@ -0,0 +1,22 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile386 : TileInfo +{ + protected override void HitWireInternal() + { + { + var value = type == 387; + var num65 = WorldGen.ShiftTrapdoor(i, j, true, -1).ToInt(); + if (num65 == 0) + { + num65 = -WorldGen.ShiftTrapdoor(i, j, false, -1).ToInt(); + } + + if (num65 != 0) + { + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile387.cs b/WireSharkRuntime/Tiles/Tile387.cs new file mode 100644 index 0000000..ae909a7 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile387.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile387 : Tile386 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile388.cs b/WireSharkRuntime/Tiles/Tile388.cs new file mode 100644 index 0000000..688a700 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile388.cs @@ -0,0 +1,12 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile388 : TileInfo +{ + protected override void HitWireInternal() + { + var flag4 = type == 389; + WorldGen.ShiftTallGate(i, j, flag4); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile389.cs b/WireSharkRuntime/Tiles/Tile389.cs new file mode 100644 index 0000000..854a48e --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile389.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile389 : Tile388 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile4.cs b/WireSharkRuntime/Tiles/Tile4.cs new file mode 100644 index 0000000..36928e6 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile4.cs @@ -0,0 +1,16 @@ +namespace WireShark.Tiles; + +public class Tile4 : TileInfo +{ + protected override void HitWireInternal() + { + if (tile.TileFrameX < 66) + { + tile.TileFrameX += 66; + } + else + { + tile.TileFrameX -= 66; + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile405.cs b/WireSharkRuntime/Tiles/Tile405.cs new file mode 100644 index 0000000..ba12917 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile405.cs @@ -0,0 +1,29 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile405 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num27 = tile.TileFrameX % 54 / 18; + var num28 = tile.TileFrameY % 36 / 18; + var num29 = i - num27; + var num30 = j - num28; + var num31 = 54; + if (Main.tile[num29, num30].TileFrameX >= 54) + { + num31 = -54; + } + + for (var num32 = num29; num32 < num29 + 3; num32++) + { + for (var num33 = num30; num33 < num30 + 2; num33++) + { + Main.tile[num32, num33].TileFrameX = (short) (Main.tile[num32, num33].TileFrameX + num31); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile406.cs b/WireSharkRuntime/Tiles/Tile406.cs new file mode 100644 index 0000000..c0ec049 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile406.cs @@ -0,0 +1,29 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile406 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num2 = tile.TileFrameX % 54 / 18; + var num3 = tile.TileFrameY % 54 / 18; + var num4 = i - num2; + var num5 = j - num3; + var num6 = 54; + if (Main.tile[num4, num5].TileFrameY >= 108) + { + num6 = -108; + } + + for (var k = num4; k < num4 + 3; k++) + { + for (var l = num5; l < num5 + 3; l++) + { + Main.tile[k, l].TileFrameY = (short) (Main.tile[k, l].TileFrameY + num6); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile410.cs b/WireSharkRuntime/Tiles/Tile410.cs new file mode 100644 index 0000000..6137265 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile410.cs @@ -0,0 +1,11 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile410 : TileInfo +{ + protected override void HitWireInternal() + { + WorldGen.SwitchMonolith(i, j); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile411.cs b/WireSharkRuntime/Tiles/Tile411.cs new file mode 100644 index 0000000..68ceebd --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile411.cs @@ -0,0 +1,29 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile411 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num12 = tile.TileFrameX % 36 / 18; + var num13 = tile.TileFrameY % 36 / 18; + var num14 = i - num12; + var num15 = j - num13; + var num16 = 36; + if (Main.tile[num14, num15].TileFrameX >= 36) + { + num16 = -36; + } + + for (var num17 = num14; num17 < num14 + 2; num17++) + { + for (var num18 = num15; num18 < num15 + 2; num18++) + { + Main.tile[num17, num18].TileFrameX = (short) (Main.tile[num17, num18].TileFrameX + num16); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile419.cs b/WireSharkRuntime/Tiles/Tile419.cs new file mode 100644 index 0000000..2edadf7 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile419.cs @@ -0,0 +1,14 @@ +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace WireShark.Tiles; + +public unsafe class Tile419 : TileInfo +{ + protected override void HitWireInternal() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile42.cs b/WireSharkRuntime/Tiles/Tile42.cs new file mode 100644 index 0000000..3a30275 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile42.cs @@ -0,0 +1,28 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile42 : TileInfo +{ + protected override void HitWireInternal() + { + { + int num81; + for (num81 = tile.TileFrameY / 18; num81 >= 2; num81 -= 2) + { + } + + var num82 = j - num81; + short num83 = 18; + if (tile.TileFrameX > 0) + { + num83 = -18; + } + + var tile10 = Main.tile[i, num82]; + tile10.TileFrameX += num83; + var tile11 = Main.tile[i, num82 + 1]; + tile11.TileFrameX += num83; + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile421.cs b/WireSharkRuntime/Tiles/Tile421.cs new file mode 100644 index 0000000..a2accc2 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile421.cs @@ -0,0 +1,18 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile421 : TileInfo +{ + protected override void HitWireInternal() + { + { + if (!tile.HasActuator) + { + tile.TileType = 422; + WorldGen.SquareTileFrame(i, j, true); + + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile422.cs b/WireSharkRuntime/Tiles/Tile422.cs new file mode 100644 index 0000000..4b08857 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile422.cs @@ -0,0 +1,15 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile422 : TileInfo +{ + protected override void HitWireInternal() + { + if (!tile.HasActuator) + { + tile.TileType = 421; + WorldGen.SquareTileFrame(i, j, true); + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile425.cs b/WireSharkRuntime/Tiles/Tile425.cs new file mode 100644 index 0000000..b6cff43 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile425.cs @@ -0,0 +1,67 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; + +namespace WireShark.Tiles; + +public class Tile425 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num19 = tile.TileFrameX % 36 / 18; + var num20 = tile.TileFrameY % 36 / 18; + var num21 = i - num19; + var num22 = j - num20; + for (var num23 = num21; num23 < num21 + 2; num23++) + { + for (var num24 = num22; num24 < num22 + 2; num24++) + { + } + } + + if (!Main.AnnouncementBoxDisabled) + { + var pink = Color.Pink; + var num25 = Sign.ReadSign(num21, num22, false); + if (num25 != -1 && Main.sign[num25] != null && + !string.IsNullOrWhiteSpace(Main.sign[num25].text)) + { + if (Main.AnnouncementBoxRange == -1) + { + if (Main.netMode == NetmodeID.SinglePlayer) + { + Main.NewTextMultiline(Main.sign[num25].text, false, pink, 460); + return; + } + + if (Main.netMode == NetmodeID.Server) + { + } + } + else if (Main.netMode == NetmodeID.SinglePlayer) + { + if (Main.player[Main.myPlayer] + .Distance(new Vector2(num21 * 16 + 16, num22 * 16 + 16)) <= + Main.AnnouncementBoxRange) + { + Main.NewTextMultiline(Main.sign[num25].text, false, pink, 460); + } + } + else if (Main.netMode == NetmodeID.Server) + { + for (var num26 = 0; num26 < 255; num26++) + { + if (Main.player[num26].active && + Main.player[num26] + .Distance(new Vector2(num21 * 16 + 16, num22 * 16 + 16)) <= + Main.AnnouncementBoxRange) + { + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile429.cs b/WireSharkRuntime/Tiles/Tile429.cs new file mode 100644 index 0000000..1c6fa98 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile429.cs @@ -0,0 +1,12 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile429 : TileInfo +{ + protected override void HitWireInternal() + { + { + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile443.cs b/WireSharkRuntime/Tiles/Tile443.cs new file mode 100644 index 0000000..ea0be78 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile443.cs @@ -0,0 +1,38 @@ +using Microsoft.Xna.Framework; +using Terraria; + +namespace WireShark.Tiles; + +public class Tile443 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num117 = tile.TileFrameX / 36; + var num118 = i - (tile.TileFrameX - num117 * 36) / 18; + if (Wiring.CheckMech(num118, j, 200)) + { + var vector2 = Vector2.Zero; + var zero2 = Vector2.Zero; + var num119 = 654; + var damage3 = 20; + if (num117 < 2) + { + vector2 = new Vector2(num118 + 1, j) * 16f; + zero2 = new Vector2(0f, -8f); + } + else + { + vector2 = new Vector2(num118 + 1, j + 1) * 16f; + zero2 = new Vector2(0f, 8f); + } + + if (num119 != 0) + { + Projectile.NewProjectile(null, (int) vector2.X, (int) vector2.Y, zero2.X, zero2.Y, num119, + damage3, 2f, Main.myPlayer, 0f, 0f); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile452.cs b/WireSharkRuntime/Tiles/Tile452.cs new file mode 100644 index 0000000..88bf561 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile452.cs @@ -0,0 +1,29 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile452 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num7 = tile.TileFrameX % 54 / 18; + var num8 = tile.TileFrameY % 54 / 18; + var num9 = i - num7; + var num10 = j - num8; + var num11 = 54; + if (Main.tile[num9, num10].TileFrameX >= 54) + { + num11 = -54; + } + + for (var m = num9; m < num9 + 3; m++) + { + for (var n = num10; n < num10 + 3; n++) + { + Main.tile[m, n].TileFrameX = (short) (Main.tile[m, n].TileFrameX + num11); + } + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile455.cs b/WireSharkRuntime/Tiles/Tile455.cs new file mode 100644 index 0000000..377aa00 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile455.cs @@ -0,0 +1,11 @@ +using Terraria.GameContent.Events; + +namespace WireShark.Tiles; + +public class Tile455 : TileInfo +{ + protected override void HitWireInternal() + { + BirthdayParty.ToggleManualParty(); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile92.cs b/WireSharkRuntime/Tiles/Tile92.cs new file mode 100644 index 0000000..b44521a --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile92.cs @@ -0,0 +1,24 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile92 : TileInfo +{ + protected override void HitWireInternal() + { + { + var num96 = j - tile.TileFrameY / 18; + short num97 = 18; + if (tile.TileFrameX > 0) + { + num97 = -18; + } + + for (var num98 = num96; num98 < num96 + 6; num98++) + { + var tile21 = Main.tile[i, num98]; + tile21.TileFrameX += num97; + } + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile93.cs b/WireSharkRuntime/Tiles/Tile93.cs new file mode 100644 index 0000000..c4f4ab7 --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile93.cs @@ -0,0 +1,30 @@ +using Terraria; + +namespace WireShark.Tiles; + +public class Tile93 : TileInfo +{ + protected override void HitWireInternal() + { + { + int num84; + for (num84 = tile.TileFrameY / 18; num84 >= 3; num84 -= 3) + { + } + + num84 = j - num84; + short num85 = 18; + if (tile.TileFrameX > 0) + { + num85 = -18; + } + + var tile12 = Main.tile[i, num84]; + tile12.TileFrameX += num85; + var tile13 = Main.tile[i, num84 + 1]; + tile13.TileFrameX += num85; + var tile14 = Main.tile[i, num84 + 2]; + tile14.TileFrameX += num85; + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/Tiles/Tile95.cs b/WireSharkRuntime/Tiles/Tile95.cs new file mode 100644 index 0000000..9f7cc6e --- /dev/null +++ b/WireSharkRuntime/Tiles/Tile95.cs @@ -0,0 +1,6 @@ +namespace WireShark.Tiles; + +public class Tile95 : Tile173 +{ + +} \ No newline at end of file diff --git a/WireSharkRuntime/WireAccelerator.cs b/WireSharkRuntime/WireAccelerator.cs new file mode 100644 index 0000000..98e28aa --- /dev/null +++ b/WireSharkRuntime/WireAccelerator.cs @@ -0,0 +1,145 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Terraria; +using Terraria.DataStructures; +using Terraria.GameContent.Events; +using Terraria.ID; +using Terraria.ModLoader; +using WireShark; + +namespace WireSharkRuntime +{ + public static class WireAccelerator + { + static WireAccelerator() + { + var _vis = new int[Main.maxTilesX, Main.maxTilesY, 4, 3]; + for (var i = 0; i < Main.maxTilesX; i++) + { + for (var j = 0; j < Main.maxTilesY; j++) + { + for (var k = 0; k < 4; k++) + { + _vis[i, j, k, 0] = -1; + _vis[i, j, k, 1] = -1; + _vis[i, j, k, 2] = -1; + } + } + } + } + + public static TileInfo[,] _tileCache; + + public static void Preprocess() + { + _tileCache = new TileInfo[Main.maxTilesX, Main.maxTilesY]; + + for (var i = 0; i < Main.maxTilesX; i++) + { + for (var j = 0; j < Main.maxTilesY; j++) + { + if (IsAppliance(i, j)) + { + _tileCache[i, j] = TileInfo.CreateTileInfo(i, j); + } + } + + if (i % 100 == 0) Main.statusText = $"preprocess initializing {i * 1f / Main.maxTilesX:P1}"; + } + } + + private static bool IsAppliance(int i, int j) + { + var tile = Main.tile[i, j]; + var type = (int) tile.TileType; + if (ModContent.GetModTile(type) != null) + return true; + if (tile.HasActuator) return true; + if (!tile.HasTile) return false; + switch (type) + { + case 144: + case 421 when !tile.HasActuator: + case 422 when !tile.HasActuator: + case >= 255 and <= 268 when !tile.HasActuator: + case 419: + case 406: + case 452: + case 411: + case 425: + case 405: + case 209: + case 212: + case 215: + case 130: + case 131: + case 387: + case 386: + case 389: + case 388: + case 11: + case 10: + case 216: + case 497: + case 15 when tile.TileFrameY / 40 == 1: + case 15 when tile.TileFrameY / 40 == 20: + case 335: + case 338: + case 235: + case 4: + case 429: + case 149: + case 244: + case 565: + case 42: + case 93: + case 126: + case 95: + case 100: + case 173: + case 564: + case 593: + case 594: + case 34: + case 314: + case 33: + case 174: + case 49: + case 372: + case 92: + case 137: + case 443: + case 531: + case 139: + case 35: + case 207: + case 410: + case 480: + case 509: + case 455: + case 141: + case 210: + case 142: + case 143: + case 105: + case 349: + case 506: + case 546: + case 557: + return true; + } + + return false; + } + } +} diff --git a/WireSharkRuntime/WireSharkRuntime.cs b/WireSharkRuntime/WireSharkRuntime.cs new file mode 100644 index 0000000..6387f70 --- /dev/null +++ b/WireSharkRuntime/WireSharkRuntime.cs @@ -0,0 +1,57 @@ +using Terraria.ModLoader; +using Terraria.IO; +using WireShark; +using Terraria.GameInput; + +namespace WireSharkRuntime { + public class WireSharkRuntime : Mod { + + private static void Preprocess() + { + WireAccelerator.Preprocess(); + } + + public override void Load() + { + WorldFile.OnWorldLoad += Preprocess; + Terraria.On_Wiring.HitSwitch += Wiring_HitSwitch; + Terraria.On_Wiring.SkipWire_int_int += Wiring_SkipWire_int_int; + Terraria.On_Wiring.SkipWire_Point16 += Wiring_SkipWire_Point16; + Terraria.On_Wiring.TripWire += Wiring_TripWire; + Terraria.On_WorldGen.StartRoomCheck += WorldGen_StartRoomCheck; + + DLLManager.Load(); + } + + private bool WorldGen_StartRoomCheck(Terraria.On_WorldGen.orig_StartRoomCheck orig, int x, int y) { + return false; + } + + private void Wiring_SkipWire_Point16(Terraria.On_Wiring.orig_SkipWire_Point16 orig, Terraria.DataStructures.Point16 point) { + + } + + private void Wiring_SkipWire_int_int(Terraria.On_Wiring.orig_SkipWire_int_int orig, int x, int y) { + + } + + private void Wiring_HitSwitch(Terraria.On_Wiring.orig_HitSwitch orig, int i, int j) { + WiringWrapper.HitSwitch(i, j); + } + + private void Wiring_TripWire(Terraria.On_Wiring.orig_TripWire orig, int left, int top, int width, int height) { + WiringWrapper.BigTripWire(left, top, width, height); + } + + + public override void Unload() + { + WorldFile.OnWorldLoad -= Preprocess; + Terraria.On_Wiring.HitSwitch -= Wiring_HitSwitch; + Terraria.On_Wiring.SkipWire_int_int -= Wiring_SkipWire_int_int; + Terraria.On_Wiring.SkipWire_Point16 -= Wiring_SkipWire_Point16; + Terraria.On_Wiring.TripWire -= Wiring_TripWire; + Terraria.On_WorldGen.StartRoomCheck -= WorldGen_StartRoomCheck; + } + } +} diff --git a/WireSharkRuntime/WireSharkRuntime.csproj b/WireSharkRuntime/WireSharkRuntime.csproj new file mode 100644 index 0000000..8827b71 --- /dev/null +++ b/WireSharkRuntime/WireSharkRuntime.csproj @@ -0,0 +1,14 @@ + + + + + WireSharkRuntime + net6.0 + AnyCPU + latest + true + + + + + \ No newline at end of file diff --git a/WireSharkRuntime/WireSharkRuntime.sln b/WireSharkRuntime/WireSharkRuntime.sln new file mode 100644 index 0000000..6edd35f --- /dev/null +++ b/WireSharkRuntime/WireSharkRuntime.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34322.80 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireSharkRuntime", "WireSharkRuntime.csproj", "{0F7E73EE-B121-46AC-9A99-17D7BD155E45}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0F7E73EE-B121-46AC-9A99-17D7BD155E45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F7E73EE-B121-46AC-9A99-17D7BD155E45}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F7E73EE-B121-46AC-9A99-17D7BD155E45}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F7E73EE-B121-46AC-9A99-17D7BD155E45}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F9D869BB-A4B5-439F-BDF9-29DC2B391B34} + EndGlobalSection +EndGlobal diff --git a/WireSharkRuntime/WireSharkSystem.cs b/WireSharkRuntime/WireSharkSystem.cs new file mode 100644 index 0000000..86477cc --- /dev/null +++ b/WireSharkRuntime/WireSharkSystem.cs @@ -0,0 +1,12 @@ +using Terraria.ModLoader; + +namespace WireSharkRuntime; + +public class WireSharkSystem : ModSystem +{ + public override void PostUpdateEverything() + { + base.PostUpdateEverything(); + DLLManager.PostUpdate(); + } +} \ No newline at end of file diff --git a/WireSharkRuntime/WiringWrapper.cs b/WireSharkRuntime/WiringWrapper.cs new file mode 100644 index 0000000..bcc4d86 --- /dev/null +++ b/WireSharkRuntime/WiringWrapper.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using log4net.Core; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.IO; +using Terraria.Map; +using Terraria.ModLoader; +using WireShark.Tiles; +using WireSharkRuntime; + +namespace WireSharkRuntime +{ + public static class WiringWrapper + { + public static void HitSwitch(int i, int j) + { + if (!WorldGen.InWorld(i, j, 0)) + { + return; + } + if (Main.tile[i, j] == null) + { + return; + } + if (Main.tile[i, j].TileType == 135 || Main.tile[i, j].TileType == 314 || Main.tile[i, j].TileType == 423 || Main.tile[i, j].TileType == 428 || Main.tile[i, j].TileType == 442) + { + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); + BigTripWire(i, j, 1, 1); + return; + } + if (Main.tile[i, j].TileType == 440) + { + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16 + 16, j * 16 + 16)); + BigTripWire(i, j, 3, 3); + return; + } + if (Main.tile[i, j].TileType == 136) + { + if (Main.tile[i, j].TileFrameY == 0) + { + Main.tile[i, j].TileFrameY = 18; + } + else + { + Main.tile[i, j].TileFrameY = 0; + } + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); + BigTripWire(i, j, 1, 1); + return; + } + if (Main.tile[i, j].TileType == 144) + { + if (Main.tile[i, j].TileFrameY == 0) + { + Main.tile[i, j].TileFrameY = 18; + if (Main.netMode != NetmodeID.MultiplayerClient) + { + Wiring.CheckMech(i, j, 18000); + } + } + else + { + Main.tile[i, j].TileFrameY = 0; + } + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); + return; + } + if (Main.tile[i, j].TileType == 441 || Main.tile[i, j].TileType == 468) + { + var num = Main.tile[i, j].TileFrameX / 18 * -1; + var num2 = Main.tile[i, j].TileFrameY / 18 * -1; + num %= 4; + if (num < -1) + { + num += 2; + } + num += i; + num2 += j; + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); + BigTripWire(num, num2, 2, 2); + return; + } + if (Main.tile[i, j].TileType == 132 || Main.tile[i, j].TileType == 411) + { + short num3 = 36; + var num4 = Main.tile[i, j].TileFrameX / 18 * -1; + var num5 = Main.tile[i, j].TileFrameY / 18 * -1; + num4 %= 4; + if (num4 < -1) + { + num4 += 2; + num3 = -36; + } + num4 += i; + num5 += j; + if (Main.netMode != NetmodeID.MultiplayerClient && Main.tile[num4, num5].TileType == 411) + { + Wiring.CheckMech(num4, num5, 60); + } + for (var k = num4; k < num4 + 2; k++) + { + for (var l = num5; l < num5 + 2; l++) + { + if (Main.tile[k, l].TileType == 132 || Main.tile[k, l].TileType == 411) + { + var tile = Main.tile[k, l]; + tile.TileFrameX += num3; + } + } + } + WorldGen.TileFrame(num4, num5, false, false); + SoundEngine.PlaySound(SoundID.Mech, new Vector2(i * 16, j * 16)); + BigTripWire(num4, num5, 2, 2); + } + } + + // entry point + public static void BigTripWire(int l, int t, int w, int h) + { + if (Main.netMode == NetmodeID.MultiplayerClient) + { + return; + } + + DLLManager.BigTripWire(l, t, w, h); + } + } +} \ No newline at end of file diff --git a/WireSharkRuntime/build.txt b/WireSharkRuntime/build.txt new file mode 100644 index 0000000..b23dcc2 --- /dev/null +++ b/WireSharkRuntime/build.txt @@ -0,0 +1,3 @@ +displayName = 电路加速器运行时 +author = cc004 +version = 0.1 \ No newline at end of file diff --git a/WireSharkRuntime/description.txt b/WireSharkRuntime/description.txt new file mode 100644 index 0000000..e7084b6 --- /dev/null +++ b/WireSharkRuntime/description.txt @@ -0,0 +1 @@ +电路加速器 is a pretty cool mod, it does...this. Modify this file with a description of your mod. \ No newline at end of file diff --git a/tModLoader.targets b/tModLoader.targets new file mode 100644 index 0000000..6866cee --- /dev/null +++ b/tModLoader.targets @@ -0,0 +1,3 @@ + + + \ No newline at end of file