Skip to content

Commit

Permalink
Merge pull request #2606 from SignatureBeef/otapi3
Browse files Browse the repository at this point in the history
Arm64 implementation for Raspberry PI
  • Loading branch information
QuiCM authored Mar 28, 2022
2 parents e7f0541 + 31a1651 commit 18ea183
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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

Expand Down
17 changes: 12 additions & 5 deletions TShockAPI/Extensions/DbExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public static QueryResult QueryReader(this IDbConnection olddb, string query, pa
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)
Expand Down Expand Up @@ -117,13 +117,13 @@ public static QueryResult QueryReaderDict(this IDbConnection olddb, string query
{
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);
}
}

Expand Down Expand Up @@ -274,11 +274,13 @@ public class QueryResult : IDisposable
{
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()
Expand All @@ -301,6 +303,11 @@ protected virtual void Dispose(bool disposing)
Reader.Dispose();
Reader = null;
}
if (Command != null)
{
Command.Dispose();
Command = null;
}
if (Connection != null)
{
Connection.Dispose();
Expand Down
18 changes: 11 additions & 7 deletions TShockAPI/TShock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ You should have received a copy of the GNU General Public License
using System.Net;
using System.Reflection;
using MaxMind;
using System.Data.SQLite;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using Rests;
Expand Down Expand Up @@ -259,9 +258,6 @@ public override void Initialize()
//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(SQLiteConnection).Assembly, ResolveNativeDep);

Main.SettingsUnlock_WorldEvil = true;

Expand Down Expand Up @@ -322,7 +318,7 @@ public override void Initialize()
{
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")
{
Expand Down Expand Up @@ -441,8 +437,16 @@ public override void Initialize()
}
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);
}
}
Expand Down
7 changes: 3 additions & 4 deletions TShockAPI/TShockAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" />
<PackageReference Include="MySql.Data" Version="8.0.27" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 6 additions & 4 deletions TShockLauncher.Tests/TShockLauncher.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 4 additions & 5 deletions TShockLauncher/TShockLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
<ProjectReference Include="..\TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj" ExcludeFromSingleFile="true" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ExcludeFromSingleFile="true" Condition="'$(PublishSingleFile)' == 'true'" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ReferenceOutputAssembly="false" Condition="'$(PublishSingleFile)' != 'true'" />
<Reference Include="HttpServer" ExcludeFromSingleFile="true" >
<Reference Include="HttpServer" ExcludeFromSingleFile="true">
<HintPath>..\prebuilts\HttpServer.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<!-- match tshocks dependencies so that publishing outputs all files to ./bin -->
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" />
<PackageReference Include="MySql.Data" Version="8.0.27" />
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.3" />
</ItemGroup>

<Target Name="MoveTShockDebug" AfterTargets="FinalCleanup;PostBuildEvent">
Expand Down
2 changes: 1 addition & 1 deletion TerrariaServerAPI

0 comments on commit 18ea183

Please sign in to comment.