diff --git a/Capy64/API/IPlugin.cs b/Capy64/API/IPlugin.cs index 94193d5..42a10d2 100644 --- a/Capy64/API/IPlugin.cs +++ b/Capy64/API/IPlugin.cs @@ -1,10 +1,5 @@ using KeraLua; using Microsoft.Extensions.DependencyInjection; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.API; diff --git a/Capy64/BIOS/Bios.cs b/Capy64/BIOS/Bios.cs index 6d14143..57f44a1 100644 --- a/Capy64/BIOS/Bios.cs +++ b/Capy64/BIOS/Bios.cs @@ -5,18 +5,10 @@ using Capy64.Eventing.Events; using Capy64.LuaRuntime; using Capy64.LuaRuntime.Libraries; using KeraLua; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Input; using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Threading; -using System.Xml.Linq; using System.Diagnostics; +using System.IO; namespace Capy64.BIOS; diff --git a/Capy64/BIOS/PanicScreen.cs b/Capy64/BIOS/PanicScreen.cs index b2c3077..a67bb9f 100644 --- a/Capy64/BIOS/PanicScreen.cs +++ b/Capy64/BIOS/PanicScreen.cs @@ -1,12 +1,6 @@ using Capy64.Core; using Capy64.LuaRuntime.Libraries; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.BIOS; @@ -30,8 +24,8 @@ public class PanicScreen Term.Clear(); var title = " Capy64 "; - var halfX = Term.Width / 2 + 1; - Term.SetCursorPosition(halfX - title.Length / 2, 2); + var halfX = (Term.Width / 2) + 1; + Term.SetCursorPosition(halfX - (title.Length / 2), 2); Term.ForegroundColor = BackgroundColor; Term.BackgroundColor = ForegroundColor; Term.Write(title); @@ -41,7 +35,8 @@ public class PanicScreen Term.SetCursorPosition(1, 4); Print(error + '\n'); - if (details is not null) { + if (details is not null) + { Print(details); } } @@ -51,7 +46,7 @@ public class PanicScreen foreach (var ch in txt) { Term.Write(ch.ToString()); - if(Term.CursorPosition.X >= Term.Width || ch == '\n') + if (Term.CursorPosition.X >= Term.Width || ch == '\n') { Term.SetCursorPosition(1, (int)Term.CursorPosition.Y + 1); } diff --git a/Capy64/BIOS/RuntimeInputEvents.cs b/Capy64/BIOS/RuntimeInputEvents.cs index eb7279f..7730cf1 100644 --- a/Capy64/BIOS/RuntimeInputEvents.cs +++ b/Capy64/BIOS/RuntimeInputEvents.cs @@ -1,10 +1,5 @@ -using Capy64.Eventing.Events; -using Capy64.Eventing; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Capy64.Eventing; +using Capy64.Eventing.Events; using Capy64.LuaRuntime; using Microsoft.Xna.Framework.Input; @@ -103,7 +98,7 @@ internal class RuntimeInputEvents e.IsHeld, }); - if (e.Mods.HasFlag(InputManager.Modifiers.LCtrl) || e.Mods.HasFlag(InputManager.Modifiers.RCtrl) && !e.IsHeld) + if (e.Mods.HasFlag(InputManager.Modifiers.LCtrl) || (e.Mods.HasFlag(InputManager.Modifiers.RCtrl) && !e.IsHeld)) { if (e.Key == Keys.C) { diff --git a/Capy64/Capy64.cs b/Capy64/Capy64.cs index feeaa22..b5e6d23 100644 --- a/Capy64/Capy64.cs +++ b/Capy64/Capy64.cs @@ -2,20 +2,16 @@ using Capy64.Core; using Capy64.Eventing; using Capy64.Extensions; -using Capy64.Eventing.Events; using Capy64.LuaRuntime; using Capy64.PluginManager; -using KeraLua; using Microsoft.Extensions.DependencyInjection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using static Capy64.Utils; using System.IO; +using System.Linq; +using static Capy64.Utils; namespace Capy64; diff --git a/Capy64/Configuration/HTTP.cs b/Capy64/Configuration/HTTP.cs index 089ff11..6e0e1d7 100644 --- a/Capy64/Configuration/HTTP.cs +++ b/Capy64/Configuration/HTTP.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Capy64.Configuration; +namespace Capy64.Configuration; class HTTP { diff --git a/Capy64/Configuration/WebSockets.cs b/Capy64/Configuration/WebSockets.cs index d2adde8..ab112ff 100644 --- a/Capy64/Configuration/WebSockets.cs +++ b/Capy64/Configuration/WebSockets.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; - -namespace Capy64.Configuration; +namespace Capy64.Configuration; class WebSockets { diff --git a/Capy64/Core/Audio.cs b/Capy64/Core/Audio.cs index aeadc5f..c8b5377 100644 --- a/Capy64/Core/Audio.cs +++ b/Capy64/Core/Audio.cs @@ -1,7 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using System; -using System.Threading.Channels; namespace Capy64.Core; @@ -30,11 +29,12 @@ public class Audio { var outBuffer = new byte[SamplesPerBuffer * bytesPerSample]; - for (int i = 0; i < from.Length; i++) { + for (int i = 0; i < from.Length; i++) + { var floatSample = MathHelper.Clamp(from[i], -1.0f, 1.0f); var shortSample = (short)(floatSample * short.MaxValue); - int index = i * bytesPerSample + bytesPerSample; + int index = (i * bytesPerSample) + bytesPerSample; if (!BitConverter.IsLittleEndian) { diff --git a/Capy64/Core/Drawing.cs b/Capy64/Core/Drawing.cs index a5be972..b588bce 100644 --- a/Capy64/Core/Drawing.cs +++ b/Capy64/Core/Drawing.cs @@ -81,7 +81,7 @@ public class Drawing : IDisposable if (point.X < 0 || point.Y < 0) return; if (point.X >= _canvas.Width || point.Y >= _canvas.Height) return; - grid[point.X + point.Y * _canvas.Width] = color; + grid[point.X + (point.Y * _canvas.Width)] = color; _canvas.SetData(grid); } @@ -94,7 +94,7 @@ public class Drawing : IDisposable { if (point.X < 0 || point.Y < 0) continue; if (point.X >= _canvas.Width || point.Y >= _canvas.Height) continue; - grid[point.X + point.Y * _canvas.Width] = color; + grid[point.X + (point.Y * _canvas.Width)] = color; } _canvas.SetData(grid); } @@ -103,7 +103,7 @@ public class Drawing : IDisposable { var grid = new Color[_canvas.Width * _canvas.Height]; _canvas.GetData(grid); - grid[point.X + point.Y * _canvas.Width] = color; + grid[point.X + (point.Y * _canvas.Width)] = color; _canvas.SetData(grid); } @@ -113,7 +113,7 @@ public class Drawing : IDisposable _canvas.GetData(grid); foreach (var point in points) { - grid[point.X + point.Y * _canvas.Width] = color; + grid[point.X + (point.Y * _canvas.Width)] = color; } _canvas.SetData(grid); } diff --git a/Capy64/Eventing/EventEmitter.cs b/Capy64/Eventing/EventEmitter.cs index acaf5ea..d50a459 100644 --- a/Capy64/Eventing/EventEmitter.cs +++ b/Capy64/Eventing/EventEmitter.cs @@ -85,7 +85,7 @@ public class EventEmitter public void RaiseTick(TickEvent ev) { - if(OnTick is not null) + if (OnTick is not null) { OnTick(this, ev); } @@ -93,7 +93,7 @@ public class EventEmitter public void RaiseInit() { - if(OnInit is not null) + if (OnInit is not null) { OnInit(this, EventArgs.Empty); } @@ -101,7 +101,7 @@ public class EventEmitter public void RaiseScreenSizeChange() { - if(OnScreenSizeChange is not null) + if (OnScreenSizeChange is not null) { OnScreenSizeChange(this, EventArgs.Empty); } diff --git a/Capy64/Eventing/Events/TickEvent.cs b/Capy64/Eventing/Events/TickEvent.cs index 6d81b78..430e605 100644 --- a/Capy64/Eventing/Events/TickEvent.cs +++ b/Capy64/Eventing/Events/TickEvent.cs @@ -1,9 +1,5 @@ using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Eventing.Events; diff --git a/Capy64/Extensions/Bindings/SDL2.cs b/Capy64/Extensions/Bindings/SDL2.cs index 357b016..1769827 100644 --- a/Capy64/Extensions/Bindings/SDL2.cs +++ b/Capy64/Extensions/Bindings/SDL2.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Extensions.Bindings; diff --git a/Capy64/Extensions/GameWindowExtensions.cs b/Capy64/Extensions/GameWindowExtensions.cs index 976beba..94005e4 100644 --- a/Capy64/Extensions/GameWindowExtensions.cs +++ b/Capy64/Extensions/GameWindowExtensions.cs @@ -1,11 +1,6 @@ using Capy64.Extensions.Bindings; using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace Capy64.Extensions; @@ -29,7 +24,7 @@ public static class GameWindowExtensions SDL_WINDOW_INPUT_FOCUS = 0x00000200, SDL_WINDOW_MOUSE_FOCUS = 0x00000400, SDL_WINDOW_FULLSCREEN_DESKTOP = - (SDL_WINDOW_FULLSCREEN | 0x00001000), + SDL_WINDOW_FULLSCREEN | 0x00001000, SDL_WINDOW_FOREIGN = 0x00000800, SDL_WINDOW_ALLOW_HIGHDPI = 0x00002000, SDL_WINDOW_MOUSE_CAPTURE = 0x00004000, diff --git a/Capy64/IGame.cs b/Capy64/IGame.cs index 0cbe8d8..61748bb 100644 --- a/Capy64/IGame.cs +++ b/Capy64/IGame.cs @@ -20,7 +20,7 @@ public interface IGame EventEmitter EventEmitter { get; } void ConfigureServices(IServiceProvider serviceProvider); - int Width { get; set; } + int Width { get; set; } int Height { get; set; } float Scale { get; set; } void UpdateSize(); diff --git a/Capy64/LuaRuntime/Constants.cs b/Capy64/LuaRuntime/Constants.cs index 054a7e0..dfbefbd 100644 --- a/Capy64/LuaRuntime/Constants.cs +++ b/Capy64/LuaRuntime/Constants.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Capy64.LuaRuntime; +namespace Capy64.LuaRuntime; public class Constants { diff --git a/Capy64/LuaRuntime/Extensions/Utils.cs b/Capy64/LuaRuntime/Extensions/Utils.cs index bd34702..ece813c 100644 --- a/Capy64/LuaRuntime/Extensions/Utils.cs +++ b/Capy64/LuaRuntime/Extensions/Utils.cs @@ -1,12 +1,8 @@ using KeraLua; using System; using System.Collections; -using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Extensions; public static class Utils diff --git a/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs b/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs index 6515c39..309be16 100644 --- a/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs +++ b/Capy64/LuaRuntime/Handlers/BinaryReadHandle.cs @@ -2,9 +2,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Handlers; @@ -18,92 +16,58 @@ public class BinaryReadHandle : IHandle Stream = new BinaryReader(stream, Encoding.ASCII); } - public BinaryReadHandle(BinaryReader stream) + private static readonly Dictionary functions = new() { - Stream = stream; - } + ["nextByte"] = L_NextByte, + ["nextShort"] = L_NextShort, + ["nextInt"] = L_NextInt, + ["nextLong"] = L_NextLong, + ["nextSByte"] = L_NextSByte, + ["nextUShort"] = L_NextUShort, + ["nextUInt"] = L_NextUInt, + ["nextULong"] = L_NextULong, + ["nextHalf"] = L_NextHalf, + ["nextFloat"] = L_NextFloat, + ["nextDouble"] = L_NextDouble, + ["nextChar"] = L_NextChar, + ["nextString"] = L_NextString, + ["nextBoolean"] = L_NextBoolean, + ["close"] = L_Close, + }; public void Push(Lua L, bool newTable = true) { if (newTable) L.NewTable(); - L.PushString("nextByte"); - L.PushCFunction(L_NextByte); - L.SetTable(-3); - - L.PushString("nextShort"); - L.PushCFunction(L_NextShort); - L.SetTable(-3); - - L.PushString("nextInt"); - L.PushCFunction(L_NextInt); - L.SetTable(-3); - - L.PushString("nextLong"); - L.PushCFunction(L_NextLong); - L.SetTable(-3); - - L.PushString("nextSByte"); - L.PushCFunction(L_NextSByte); - L.SetTable(-3); - - L.PushString("nextUShort"); - L.PushCFunction(L_NextUShort); - L.SetTable(-3); - - L.PushString("nextUInt"); - L.PushCFunction(L_NextUInt); - L.SetTable(-3); - - L.PushString("nextULong"); - L.PushCFunction(L_NextULong); - L.SetTable(-3); - - L.PushString("nextHalf"); - L.PushCFunction(L_NextHalf); - L.SetTable(-3); - - L.PushString("nextFloat"); - L.PushCFunction(L_NextFloat); - L.SetTable(-3); - - L.PushString("nextDouble"); - L.PushCFunction(L_NextDouble); - L.SetTable(-3); - - L.PushString("nextChar"); - L.PushCFunction(L_NextChar); - L.SetTable(-3); - - L.PushString("nextString"); - L.PushCFunction(L_NextString); - L.SetTable(-3); - - L.PushString("nextBoolean"); - L.PushCFunction(L_NextBoolean); - L.SetTable(-3); - - L.PushString("close"); - L.PushCFunction(L_Close); - L.SetTable(-3); + foreach (var pair in functions) + { + L.PushString(pair.Key); + L.PushCFunction(pair.Value); + L.SetTable(-3); + } L.PushString("_handle"); L.PushObject(this); L.SetTable(-3); } + private static BinaryReadHandle GetHandle(Lua L, bool gc = true) + { + L.CheckType(1, LuaType.Table); + L.PushString("_handle"); + L.GetTable(1); + return L.ToObject(-1, gc); + } + private static int L_NextByte(IntPtr state) { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); var count = (int)L.OptNumber(2, 1); L.ArgumentCheck(count >= 1, 2, "count must be a positive integer"); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -133,11 +97,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -154,11 +114,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -175,11 +131,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -196,11 +148,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -217,11 +165,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -238,11 +182,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -259,11 +199,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -280,11 +216,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -301,11 +233,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -322,11 +250,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -343,13 +267,10 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); var count = (int)L.OptNumber(2, 1); L.ArgumentCheck(count >= 1, 2, "count must be a positive integer"); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -379,13 +300,10 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); var count = (int)L.OptNumber(2, 1); L.ArgumentCheck(count >= 1, 2, "count must be a positive integer"); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -412,11 +330,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -433,10 +347,7 @@ public class BinaryReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, true); + var h = GetHandle(L, true); if (h is null || h.IsClosed) return 0; diff --git a/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs b/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs index 3796fb0..af1e363 100644 --- a/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs +++ b/Capy64/LuaRuntime/Handlers/BinaryWriteHandle.cs @@ -2,131 +2,372 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Handlers; -[Obsolete("Work in progress")] public class BinaryWriteHandle : IHandle { - private readonly BinaryWriter _stream; - private bool isClosed = false; + private readonly BinaryWriter Stream; + private bool IsClosed = false; public BinaryWriteHandle(Stream stream) { - _stream = new BinaryWriter(stream); + Stream = new BinaryWriter(stream, Encoding.ASCII); } - public BinaryWriteHandle(BinaryWriter stream) + private static readonly Dictionary functions = new() { - _stream = stream; - } + ["writeByte"] = L_WriteByte, + ["writeShort"] = L_WriteShort, + ["writeInt"] = L_WriteInt, + ["writeLong"] = L_WriteLong, + ["writeSByte"] = L_WriteSByte, + ["writeUShort"] = L_WriteUShort, + ["writeUInt"] = L_WriteUInt, + ["writeULong"] = L_WriteULong, + ["writeHalf"] = L_WriteHalf, + ["writeFloat"] = L_WriteFloat, + ["writeDouble"] = L_WriteDouble, + ["writeChar"] = L_WriteChar, + ["writeString"] = L_WriteString, + ["writeBoolean"] = L_WriteBoolean, + ["flush"] = L_Flush, + ["close"] = L_Close, + }; public void Push(Lua L, bool newTable = true) { - throw new NotImplementedException(); + if (newTable) + L.NewTable(); + + foreach (var pair in functions) + { + L.PushString(pair.Key); + L.PushCFunction(pair.Value); + L.SetTable(-3); + } + + L.PushString("_handle"); + L.PushObject(this); + L.SetTable(-3); } - /*public void Push(Lua L) + private static BinaryWriteHandle GetHandle(Lua L, bool gc = true) { - L.NewTable(); - - L.PushString("readAll"); - L.PushCFunction(L_ReadAll); - L.SetTable(-3); - - L.PushString("readLine"); - L.PushCFunction(L_ReadLine); - L.SetTable(-3); - - L.PushString("read"); - L.PushCFunction(L_Read); - L.SetTable(-3); - - L.PushString("close"); - L.PushCFunction(L_Close); - L.SetTable(-3); + L.CheckType(1, LuaType.Table); + L.PushString("_handle"); + L.GetTable(1); + return L.ToObject(-1, gc); } - private int L_ReadAll(IntPtr state) + private static int L_WriteByte(IntPtr state) { var L = Lua.FromIntPtr(state); - if (isClosed) - L.Error("handle is closed"); - - if (ended) + byte[] buffer; + if (L.IsInteger(2)) { - L.PushNil(); - return 1; + buffer = new[] + { + (byte)L.ToInteger(2), + }; } - - //var content = _stream.read; - L.PushString(content); - - return 1; - } - - private int L_ReadLine(IntPtr state) - { - var L = Lua.FromIntPtr(state); - - if (isClosed) - L.Error("handle is closed"); - - if (ended) + else if (L.IsTable(2)) { - L.PushNil(); - return 1; + var len = L.RawLen(2); + buffer = new byte[len]; + + for (int i = 1; i <= len; i++) + { + L.PushInteger(i); + L.GetTable(2); + var b = L.CheckInteger(-1); + L.Pop(1); + buffer[i - 1] = (byte)b; + } } - - var line = _stream.ReadLine(); - - if (line is null) - L.PushNil(); else - L.PushString(line); - - return 1; - } - - private int L_Read(IntPtr state) - { - var L = Lua.FromIntPtr(state); - var count = (int)L.OptNumber(1, 1); - - L.ArgumentCheck(count < 1, 1, "count must be a positive integer"); - - if (ended) - L.Error("handle is closed"); - - if (_stream.EndOfStream) { - L.PushNil(); - return 1; + L.ArgumentError(2, "integer or table expected, got " + L.Type(2)); + return 0; } - var chunk = new char[count]; + var h = GetHandle(L, false); - _stream.Read(chunk, 0, count); + if (h is null || h.IsClosed) + L.Error("handle is closed"); - L.PushString(new string(chunk)); - - return 1; - } - - private int L_Close(IntPtr state) - { - var L = Lua.FromIntPtr(state); - - if (isClosed) - return 0; - - _stream.Close(); - - isClosed = true; + h.Stream.Write(buffer); return 0; - }*/ + } + + private static int L_WriteShort(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckInteger(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((short)b); + + return 0; + } + + private static int L_WriteInt(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckInteger(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((int)b); + + return 0; + } + + private static int L_WriteLong(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckInteger(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write(b); + + return 0; + } + + private static int L_WriteSByte(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckInteger(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((sbyte)b); + + return 0; + } + + private static int L_WriteUShort(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckInteger(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((ushort)b); + + return 0; + } + + private static int L_WriteUInt(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckInteger(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((uint)b); + + return 0; + } + + private static int L_WriteULong(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckInteger(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((ulong)b); + + return 0; + } + + private static int L_WriteHalf(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckNumber(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((Half)b); + + return 0; + } + + private static int L_WriteFloat(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckNumber(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((float)b); + + return 0; + } + + private static int L_WriteDouble(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckNumber(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write((double)b); + + return 0; + } + + private static int L_WriteChar(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + byte[] buffer; + if (L.IsString(2)) + { + var str = L.ToString(2); + buffer = Encoding.ASCII.GetBytes(str); + } + else if (L.IsTable(2)) + { + var len = L.RawLen(2); + var tmpBuffer = new List(); + + for (int i = 1; i <= len; i++) + { + L.PushInteger(i); + L.GetTable(2); + var b = L.CheckString(-1); + L.Pop(1); + var chunk = Encoding.ASCII.GetBytes(b); + foreach (var c in chunk) + { + tmpBuffer.Add(c); + } + } + + buffer = tmpBuffer.ToArray(); + } + else + { + L.ArgumentError(2, "integer or table expected, got " + L.Type(2)); + return 0; + } + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write(buffer); + + return 0; + } + + private static int L_WriteString(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var b = L.CheckString(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write(b); + + return 0; + } + + private static int L_WriteBoolean(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + L.CheckType(2, LuaType.Boolean); + var b = L.ToBoolean(2); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Write(b); + + return 0; + } + + private static int L_Flush(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var h = GetHandle(L, false); + + if (h is null || h.IsClosed) + L.Error("handle is closed"); + + h.Stream.Flush(); + + return 0; + } + + private static int L_Close(IntPtr state) + { + var L = Lua.FromIntPtr(state); + + var h = GetHandle(L, true); + + if (h is null || h.IsClosed) + return 0; + + h.Stream.Close(); + + h.IsClosed = true; + + return 0; + } } diff --git a/Capy64/LuaRuntime/Handlers/IHandle.cs b/Capy64/LuaRuntime/Handlers/IHandle.cs index 3414fba..5b3fbcc 100644 --- a/Capy64/LuaRuntime/Handlers/IHandle.cs +++ b/Capy64/LuaRuntime/Handlers/IHandle.cs @@ -1,9 +1,4 @@ using KeraLua; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Handlers; diff --git a/Capy64/LuaRuntime/Handlers/ReadHandle.cs b/Capy64/LuaRuntime/Handlers/ReadHandle.cs index 89c1f11..2a6dd52 100644 --- a/Capy64/LuaRuntime/Handlers/ReadHandle.cs +++ b/Capy64/LuaRuntime/Handlers/ReadHandle.cs @@ -2,10 +2,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Handlers; @@ -18,40 +14,44 @@ public class ReadHandle : IHandle Stream = new StreamReader(stream); } + private static readonly Dictionary functions = new() + { + ["readAll"] = L_ReadAll, + ["readLine"] = L_ReadLine, + ["read"] = L_Read, + ["close"] = L_Close, + }; + public void Push(Lua L, bool newTable = true) { if (newTable) L.NewTable(); - L.PushString("readAll"); - L.PushCFunction(L_ReadAll); - L.SetTable(-3); - - L.PushString("readLine"); - L.PushCFunction(L_ReadLine); - L.SetTable(-3); - - L.PushString("read"); - L.PushCFunction(L_Read); - L.SetTable(-3); - - L.PushString("close"); - L.PushCFunction(L_Close); - L.SetTable(-3); + foreach (var pair in functions) + { + L.PushString(pair.Key); + L.PushCFunction(pair.Value); + L.SetTable(-3); + } L.PushString("_handle"); L.PushObject(this); L.SetTable(-3); } + private static ReadHandle GetHandle(Lua L, bool gc = true) + { + L.CheckType(1, LuaType.Table); + L.PushString("_handle"); + L.GetTable(1); + return L.ToObject(-1, gc); + } + private static int L_ReadAll(IntPtr state) { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -72,10 +72,7 @@ public class ReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -94,16 +91,11 @@ public class ReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); var count = (int)L.OptNumber(2, 1); - - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); - - L.ArgumentCheck(count >= 1, 2, "count must be a positive integer"); + var h = GetHandle(L, false); + if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -126,10 +118,7 @@ public class ReadHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, true); + var h = GetHandle(L, true); if (h is null || h.IsClosed) return 0; diff --git a/Capy64/LuaRuntime/Handlers/WriteHandle.cs b/Capy64/LuaRuntime/Handlers/WriteHandle.cs index 8454675..eb82202 100644 --- a/Capy64/LuaRuntime/Handlers/WriteHandle.cs +++ b/Capy64/LuaRuntime/Handlers/WriteHandle.cs @@ -2,9 +2,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Handlers; @@ -22,47 +19,50 @@ public class WriteHandle : IHandle Stream = stream; } + private static readonly Dictionary functions = new() + { + ["write"] = L_Write, + ["writeLine"] = L_WriteLine, + ["flush"] = L_Flush, + ["close"] = L_Close, + }; + public void Push(Lua L, bool newTable = true) { if (newTable) L.NewTable(); - L.PushString("write"); - L.PushCFunction(L_Write); - L.SetTable(-3); - - L.PushString("writeLine"); - L.PushCFunction(L_WriteLine); - L.SetTable(-3); - - L.PushString("flush"); - L.PushCFunction(L_Flush); - L.SetTable(-3); - - L.PushString("close"); - L.PushCFunction(L_Close); - L.SetTable(-3); + foreach (var pair in functions) + { + L.PushString(pair.Key); + L.PushCFunction(pair.Value); + L.SetTable(-3); + } L.PushString("_handle"); L.PushObject(this); L.SetTable(-3); } + private static WriteHandle GetHandle(Lua L, bool gc = true) + { + L.CheckType(1, LuaType.Table); + L.PushString("_handle"); + L.GetTable(1); + return L.ToObject(-1, gc); + } + private static int L_Write(IntPtr state) { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); var content = L.CheckString(2); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); - h.Stream.Write(content); return 0; @@ -72,17 +72,13 @@ public class WriteHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); var content = L.CheckString(2); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); - h.Stream.WriteLine(content); return 0; @@ -92,10 +88,7 @@ public class WriteHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, false); + var h = GetHandle(L, false); if (h is null || h.IsClosed) L.Error("handle is closed"); @@ -109,10 +102,7 @@ public class WriteHandle : IHandle { var L = Lua.FromIntPtr(state); - L.CheckType(1, LuaType.Table); - L.PushString("_handle"); - L.GetTable(1); - var h = L.ToObject(-1, true); + var h = GetHandle(L, true); if (h is null || h.IsClosed) return 0; diff --git a/Capy64/LuaRuntime/ILuaEvent.cs b/Capy64/LuaRuntime/ILuaEvent.cs index b26bfb4..0818c92 100644 --- a/Capy64/LuaRuntime/ILuaEvent.cs +++ b/Capy64/LuaRuntime/ILuaEvent.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Capy64.LuaRuntime; +namespace Capy64.LuaRuntime; public interface ILuaEvent { diff --git a/Capy64/LuaRuntime/Libraries/FileSystem.cs b/Capy64/LuaRuntime/Libraries/FileSystem.cs index ca9f8f0..f06caf9 100644 --- a/Capy64/LuaRuntime/Libraries/FileSystem.cs +++ b/Capy64/LuaRuntime/Libraries/FileSystem.cs @@ -6,8 +6,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; -using System.Threading; namespace Capy64.LuaRuntime.Libraries; @@ -487,7 +485,7 @@ public class FileSystem : IPlugin fileAccess = FileAccess.Read; break; case 'w': - fileMode = FileMode.CreateNew; + fileMode = FileMode.Create; fileAccess = FileAccess.Write; break; case 'a': @@ -515,17 +513,27 @@ public class FileSystem : IPlugin var fileStream = File.Open(path, fileMode, fileAccess, FileShare.ReadWrite); - // todo: add binary mode + IHandle handle; if (fileAccess == FileAccess.Read) { - var handle = new ReadHandle(fileStream); - handle.Push(L); + if (binaryMode) + handle = new BinaryReadHandle(fileStream); + else + handle = new ReadHandle(fileStream); } else if (fileAccess == FileAccess.Write) { - var handle = new WriteHandle(fileStream); - handle.Push(L); + if (binaryMode) + handle = new BinaryWriteHandle(fileStream); + else + handle = new WriteHandle(fileStream); } + else + { + throw new InvalidOperationException(); + } + + handle.Push(L); return 1; } diff --git a/Capy64/LuaRuntime/Libraries/Graphics.cs b/Capy64/LuaRuntime/Libraries/Graphics.cs index 8ba51b7..3ab7c05 100644 --- a/Capy64/LuaRuntime/Libraries/Graphics.cs +++ b/Capy64/LuaRuntime/Libraries/Graphics.cs @@ -1,5 +1,4 @@ using Capy64.API; -using Capy64.Core; using KeraLua; using Microsoft.Xna.Framework; using System; @@ -81,7 +80,7 @@ public class Graphics : IPlugin L.ArgumentCheck(L.IsNumber(-1), 1, "expected number at index " + (i + 1)); var y = (int)L.ToNumber(-1) - 1; L.Pop(1); - + pts.Add(new Point(x, y)); } diff --git a/Capy64/LuaRuntime/Libraries/HTTP.cs b/Capy64/LuaRuntime/Libraries/HTTP.cs index 7726cb8..a47792f 100644 --- a/Capy64/LuaRuntime/Libraries/HTTP.cs +++ b/Capy64/LuaRuntime/Libraries/HTTP.cs @@ -5,7 +5,6 @@ using KeraLua; using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Net.Http; @@ -155,7 +154,7 @@ public class HTTP : IPlugin reqTask.ContinueWith(async (task) => { - if(task.IsFaulted || task.IsCanceled) + if (task.IsFaulted || task.IsCanceled) { _game.LuaRuntime.PushEvent("http_failure", requestId, task.Exception?.Message); return; diff --git a/Capy64/LuaRuntime/Libraries/OS.cs b/Capy64/LuaRuntime/Libraries/OS.cs index 1add392..7d69022 100644 --- a/Capy64/LuaRuntime/Libraries/OS.cs +++ b/Capy64/LuaRuntime/Libraries/OS.cs @@ -1,10 +1,6 @@ using Capy64.API; using KeraLua; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Libraries; diff --git a/Capy64/LuaRuntime/Libraries/Screen.cs b/Capy64/LuaRuntime/Libraries/Screen.cs index 48f56df..80642a9 100644 --- a/Capy64/LuaRuntime/Libraries/Screen.cs +++ b/Capy64/LuaRuntime/Libraries/Screen.cs @@ -1,12 +1,6 @@ using Capy64.API; -using Capy64.Core; using KeraLua; -using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Libraries; diff --git a/Capy64/LuaRuntime/Libraries/Term.cs b/Capy64/LuaRuntime/Libraries/Term.cs index 0eb22a6..a1d3a82 100644 --- a/Capy64/LuaRuntime/Libraries/Term.cs +++ b/Capy64/LuaRuntime/Libraries/Term.cs @@ -173,7 +173,7 @@ internal class Term : IPlugin if (!save) return; - CharGrid[(int)pos.X + (int)pos.Y * Width] = new Char + CharGrid[(int)pos.X + ((int)pos.Y * Width)] = new Char { Character = ch, Foreground = ForegroundColor, @@ -186,7 +186,7 @@ internal class Term : IPlugin if (pos.X < 0 || pos.Y < 0 || pos.X >= Width || pos.Y >= Height) return; - var ch = CharGrid[(int)pos.X + (int)pos.Y * Width] ?? + var ch = CharGrid[(int)pos.X + ((int)pos.Y * Width)] ?? new Char { Character = ' ', @@ -199,9 +199,9 @@ internal class Term : IPlugin public static void RedrawAll() { - for(int y = 0; y < Height; y++) + for (int y = 0; y < Height; y++) { - for(int x = 0; x < Width; x++) + for (int x = 0; x < Width; x++) { RedrawPos(new(x, y)); } @@ -210,7 +210,7 @@ internal class Term : IPlugin public static void DumpScreen(bool clear = false) { - if(clear) + if (clear) Console.Clear(); Console.WriteLine("\n /{0}", new string('-', Width)); for (int i = 0; i < CharGrid.Length; i++) @@ -244,7 +244,7 @@ internal class Term : IPlugin if (_cursorPosition.X < 0 || _cursorPosition.Y < 0 || _cursorPosition.X >= Width || _cursorPosition.Y >= Height) return; - var ch = CharGrid[(int)_cursorPosition.X + (int)_cursorPosition.Y * Width] ?? + var ch = CharGrid[(int)_cursorPosition.X + ((int)_cursorPosition.Y * Width)] ?? new Char { Character = ' ', @@ -453,8 +453,8 @@ internal class Term : IPlugin var x = (int)L.CheckNumber(1); var y = (int)L.CheckNumber(2); - L.PushInteger(x * CharWidth - CharWidth + 1); - L.PushInteger(y * CharHeight - CharHeight + 1); + L.PushInteger((x * CharWidth) - CharWidth + 1); + L.PushInteger((y * CharHeight) - CharHeight + 1); return 2; } @@ -466,8 +466,8 @@ internal class Term : IPlugin var x = (int)L.CheckNumber(1) - 1; var y = (int)L.CheckNumber(2) - 1; - L.PushInteger(x / CharWidth + 1); - L.PushInteger(y / CharHeight + 1); + L.PushInteger((x / CharWidth) + 1); + L.PushInteger((y / CharHeight) + 1); return 2; } diff --git a/Capy64/LuaRuntime/Libraries/Timer.cs b/Capy64/LuaRuntime/Libraries/Timer.cs index c39aaa7..8efbd5b 100644 --- a/Capy64/LuaRuntime/Libraries/Timer.cs +++ b/Capy64/LuaRuntime/Libraries/Timer.cs @@ -1,11 +1,6 @@ using Capy64.API; using KeraLua; -using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime.Libraries; diff --git a/Capy64/LuaRuntime/LuaDelegateEvent.cs b/Capy64/LuaRuntime/LuaDelegateEvent.cs index a74ce6d..ddbf1d4 100644 --- a/Capy64/LuaRuntime/LuaDelegateEvent.cs +++ b/Capy64/LuaRuntime/LuaDelegateEvent.cs @@ -1,9 +1,5 @@ using KeraLua; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime; diff --git a/Capy64/LuaRuntime/LuaException.cs b/Capy64/LuaRuntime/LuaException.cs index 6afa5d7..7ba3929 100644 --- a/Capy64/LuaRuntime/LuaException.cs +++ b/Capy64/LuaRuntime/LuaException.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime; diff --git a/Capy64/LuaRuntime/Runtime.cs b/Capy64/LuaRuntime/Runtime.cs index d66723d..61fb3fe 100644 --- a/Capy64/LuaRuntime/Runtime.cs +++ b/Capy64/LuaRuntime/Runtime.cs @@ -5,9 +5,7 @@ using System; using System.Collections.Concurrent; using System.IO; using System.Linq; -using System.Reflection; using System.Text; -using System.Threading; namespace Capy64.LuaRuntime; @@ -79,7 +77,8 @@ public class Runtime /// public void PushEvent(string name, Func handler) { - eventQueue.Enqueue(new LuaDelegateEvent { + eventQueue.Enqueue(new LuaDelegateEvent + { Name = name, Handler = handler }); @@ -102,7 +101,7 @@ public class Runtime private bool ResumeThread(ILuaEvent ev) { - + if (filters.Length > 0 && !filters.Contains(ev.Name)) { @@ -119,7 +118,7 @@ public class Runtime var status = Thread.Resume(null, evpars, out int pars); if (status is LuaStatus.OK or LuaStatus.Yield) { - if(Disposing) + if (Disposing) return false; filters = new string[pars]; for (int i = 0; i < pars; i++) @@ -141,7 +140,7 @@ public class Runtime { Thread.PushString(ev.Name); - switch(ev) + switch (ev) { case LuaEvent e: diff --git a/Capy64/LuaRuntime/Sandbox.cs b/Capy64/LuaRuntime/Sandbox.cs index 8aa7bce..6e4d335 100644 --- a/Capy64/LuaRuntime/Sandbox.cs +++ b/Capy64/LuaRuntime/Sandbox.cs @@ -2,13 +2,9 @@ using Capy64.LuaRuntime.Libraries; using KeraLua; using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.IO; using System.Linq; -using System.Runtime.InteropServices; using System.Text; -using System.Threading.Tasks; namespace Capy64.LuaRuntime; @@ -278,7 +274,7 @@ internal class Sandbox L.Error(L.ToString(-1)); return 0; } - + L.PushCopy(-2); L.Insert(1); L.SetTop(1); diff --git a/Capy64/PluginManager/PluginLoadContext.cs b/Capy64/PluginManager/PluginLoadContext.cs index e571602..5150fd2 100644 --- a/Capy64/PluginManager/PluginLoadContext.cs +++ b/Capy64/PluginManager/PluginLoadContext.cs @@ -1,10 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.Runtime.Loader; -using System.Text; -using System.Threading.Tasks; namespace Capy64.PluginManager { diff --git a/Capy64/Program.cs b/Capy64/Program.cs index a1164d7..cbdf657 100644 --- a/Capy64/Program.cs +++ b/Capy64/Program.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using System; using System.IO; using var game = new Capy64.Capy64(); diff --git a/Capy64/Utils.cs b/Capy64/Utils.cs index a3b546f..36f4b36 100644 --- a/Capy64/Utils.cs +++ b/Capy64/Utils.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Capy64; +namespace Capy64; public static class Utils { @@ -15,7 +9,7 @@ public static class Utils public static void UnpackRGB(uint packed, out byte r, out byte g, out byte b) { b = (byte)(packed & 0xff); - g = (byte)(packed >> 8 & 0xff); - r = (byte)(packed >> 16 & 0xff); + g = (byte)((packed >> 8) & 0xff); + r = (byte)((packed >> 16) & 0xff); } } diff --git a/Capy64/Worker.cs b/Capy64/Worker.cs index 18a583d..88787a5 100644 --- a/Capy64/Worker.cs +++ b/Capy64/Worker.cs @@ -1,9 +1,5 @@ using Microsoft.Extensions.Hosting; -using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks;