From 699047d119cb11537ab6976155ea917fd579d771 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 27 Mar 2022 19:31:43 +1000 Subject: [PATCH 1/6] Bump TSAPI/OTAPI & other deps for arm64 This should allow monomod hooks to run on a raspberrypi (no apple silicon yet) --- TShockAPI/TShockAPI.csproj | 4 ++-- TShockLauncher.Tests/TShockLauncher.Tests.csproj | 10 ++++++---- TShockLauncher/TShockLauncher.csproj | 6 +++--- TerrariaServerAPI | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 1e55a7b4..0976c16d 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -28,8 +28,8 @@ - - + + diff --git a/TShockLauncher.Tests/TShockLauncher.Tests.csproj b/TShockLauncher.Tests/TShockLauncher.Tests.csproj index 9f321340..18e0cc78 100644 --- a/TShockLauncher.Tests/TShockLauncher.Tests.csproj +++ b/TShockLauncher.Tests/TShockLauncher.Tests.csproj @@ -7,10 +7,12 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive +all + diff --git a/TShockLauncher/TShockLauncher.csproj b/TShockLauncher/TShockLauncher.csproj index 26a462d3..d84c9a12 100644 --- a/TShockLauncher/TShockLauncher.csproj +++ b/TShockLauncher/TShockLauncher.csproj @@ -16,15 +16,15 @@ - + ..\prebuilts\HttpServer.dll - - + + diff --git a/TerrariaServerAPI b/TerrariaServerAPI index f386f7a0..047baef3 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit f386f7a09b488bb6363cd704ddf9b7359415218f +Subproject commit 047baef38969ac1b8bc4b5c23a9f2fc7836f3751 From c063aabbc008e371b0fcf26ef1c42d9831e7b750 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 27 Mar 2022 21:38:58 +1000 Subject: [PATCH 2/6] Switch to Microsoft.Data.Sqlite for arm64 There is a slight change the the way QueryResult works in order to satisfy the variances in the new library. Disposing of the command with the reader appears to solve this, and hopefully, with minimal impact to plugins. --- TShockAPI/Extensions/DbExt.cs | 17 ++++++++++++----- TShockAPI/TShock.cs | 17 ++++++++++++----- TShockAPI/TShockAPI.csproj | 3 +-- TShockLauncher/TShockLauncher.csproj | 3 +-- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/TShockAPI/Extensions/DbExt.cs b/TShockAPI/Extensions/DbExt.cs index b4fc7c31..6d52aec2 100644 --- a/TShockAPI/Extensions/DbExt.cs +++ b/TShockAPI/Extensions/DbExt.cs @@ -65,13 +65,13 @@ namespace TShockAPI.DB try { db.Open(); - using (var com = db.CreateCommand()) + var com = db.CreateCommand(); // this will be disposed via the QueryResult instance { com.CommandText = query; for (int i = 0; i < args.Length; i++) com.AddParameter("@" + i, args[i]); - return new QueryResult(db, com.ExecuteReader()); + return new QueryResult(db, com.ExecuteReader(), com); } } catch (Exception ex) @@ -117,13 +117,13 @@ namespace TShockAPI.DB { var db = olddb.CloneEx(); db.Open(); - using (var com = db.CreateCommand()) + var com = db.CreateCommand(); // this will be disposed via the QueryResult instance { com.CommandText = query; foreach (var kv in values) com.AddParameter("@" + kv.Key, kv.Value); - return new QueryResult(db, com.ExecuteReader()); + return new QueryResult(db, com.ExecuteReader(), com); } } @@ -274,11 +274,13 @@ namespace TShockAPI.DB { public IDbConnection Connection { get; protected set; } public IDataReader Reader { get; protected set; } + public IDbCommand Command { get; protected set; } - public QueryResult(IDbConnection conn, IDataReader reader) + public QueryResult(IDbConnection conn, IDataReader reader, IDbCommand command) { Connection = conn; Reader = reader; + Command = command; } ~QueryResult() @@ -301,6 +303,11 @@ namespace TShockAPI.DB Reader.Dispose(); Reader = null; } + if (Command != null) + { + Command.Dispose(); + Command = null; + } if (Connection != null) { Connection.Dispose(); diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 798b5a5b..3d0fd494 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -28,7 +28,6 @@ using System.Linq; using System.Net; using System.Reflection; using MaxMind; -using System.Data.SQLite; using MySql.Data.MySqlClient; using Newtonsoft.Json; using Rests; @@ -261,7 +260,7 @@ namespace TShockAPI }; // if sqlite.interop cannot be found, try and search the runtimes folder. this usually happens when debugging tsapi // since it does not have the dependency installed directly - NativeLibrary.SetDllImportResolver(typeof(SQLiteConnection).Assembly, ResolveNativeDep); + NativeLibrary.SetDllImportResolver(typeof(Microsoft.Data.Sqlite.SqliteConnection).Assembly, ResolveNativeDep); Main.SettingsUnlock_WorldEvil = true; @@ -322,7 +321,7 @@ namespace TShockAPI { string sql = Path.Combine(SavePath, Config.Settings.SqliteDBPath); Directory.CreateDirectory(Path.GetDirectoryName(sql)); - DB = new SQLiteConnection(string.Format("Data Source={0},Version=3", sql)); + DB = new Microsoft.Data.Sqlite.SqliteConnection(string.Format("Data Source={0}", sql)); } else if (Config.Settings.StorageType.ToLower() == "mysql") { @@ -441,8 +440,16 @@ namespace TShockAPI } catch (Exception ex) { - Log.ConsoleError("Fatal Startup Exception"); - Log.ConsoleError(ex.ToString()); + if (Log is not null) + { + Log.ConsoleError("Fatal Startup Exception"); + Log.ConsoleError(ex.ToString()); + } + else + { + Console.WriteLine("Fatal Startup Exception"); + Console.WriteLine(ex.ToString()); + } Environment.Exit(1); } } diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 0976c16d..ffb1afb4 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -30,8 +30,7 @@ - - + diff --git a/TShockLauncher/TShockLauncher.csproj b/TShockLauncher/TShockLauncher.csproj index d84c9a12..fa29a381 100644 --- a/TShockLauncher/TShockLauncher.csproj +++ b/TShockLauncher/TShockLauncher.csproj @@ -25,8 +25,7 @@ - - + From 0ff4988cfbadea0039b17937a4126bfdf181d90a Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 27 Mar 2022 21:41:40 +1000 Subject: [PATCH 3/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35263cf4..a18cba6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes (TShock 5.0.0) * Reduced load/save console spam. (@SignatureBeef, @YehnBeep) +* Replaced SQLite library with Microsoft.Data.Sqlite for arm64 support (@SignatureBeef) ## Upcoming changes From b01c75b2741a58bfb6d2ad8c853567d5ab681ad8 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 27 Mar 2022 21:54:28 +1000 Subject: [PATCH 4/6] Remove older SQLite SetDllImportResolver call --- TShockAPI/TShock.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 3d0fd494..81c429ec 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -258,9 +258,6 @@ namespace TShockAPI //TShock handles this args.Result = OTAPI.Hooks.NetMessage.PlayerAnnounceResult.None; }; - // if sqlite.interop cannot be found, try and search the runtimes folder. this usually happens when debugging tsapi - // since it does not have the dependency installed directly - NativeLibrary.SetDllImportResolver(typeof(Microsoft.Data.Sqlite.SqliteConnection).Assembly, ResolveNativeDep); Main.SettingsUnlock_WorldEvil = true; From 6f0bf12b867dac17a3e462f80ec54de2689a7a29 Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 28 Mar 2022 07:49:53 +1000 Subject: [PATCH 5/6] Update CHANGELOG.md Co-authored-by: Lucas Nicodemus --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a18cba6a..4b76852f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes (TShock 5.0.0) * Reduced load/save console spam. (@SignatureBeef, @YehnBeep) -* Replaced SQLite library with Microsoft.Data.Sqlite for arm64 support (@SignatureBeef) +* Replaced SQLite library with Microsoft.Data.Sqlite for arm64 support. (@SignatureBeef) ## Upcoming changes From 31a16513cf6fb6b2a07597029d8e809bb82a9655 Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 28 Mar 2022 07:56:54 +1000 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b76852f..ec5032c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin ## Upcoming changes (TShock 5.0.0) * Reduced load/save console spam. (@SignatureBeef, @YehnBeep) * Replaced SQLite library with Microsoft.Data.Sqlite for arm64 support. (@SignatureBeef) +* Initial support for MonoMod hooks on Raspberry Pi (arm64). (@kevzhao2) ## Upcoming changes