Skip to content

Commit

Permalink
Merge pull request #1 from RenderBr/master
Browse files Browse the repository at this point in the history
External dependencies no longer required
  • Loading branch information
xcodian committed Dec 19, 2023
2 parents 2b95aea + df91525 commit 798f22f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
24 changes: 12 additions & 12 deletions PerPlayerLoot/FakeChestDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using System.IO.Streams;

using Newtonsoft.Json;
using System.Data.SQLite;
using Newtonsoft.Json.Bson;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.Data.Sqlite;

namespace PerPlayerLoot
{
Expand All @@ -32,7 +32,7 @@ public class FakeChestDatabase

public static HashSet<(int, int)> playerPlacedChests = new HashSet<(int, int)>(); // tile x, y of player placed chests

private static string connString = "Data Source=perplayerloot.sqlite;Version=3;";
private static string connString = "Data Source=tshock/perplayerloot.sqlite";

public FakeChestDatabase() { }

Expand All @@ -45,7 +45,7 @@ public void Initialize()
public void CreateTables()
{
TSPlayer.Server.SendInfoMessage("Setting up per-player chests database...");
using (SQLiteConnection conn = new SQLiteConnection(connString))
using (SqliteConnection conn = new SqliteConnection(connString))
{
conn.Open();

Expand All @@ -66,7 +66,7 @@ PRIMARY KEY (x, y)
);
";

using (var cmd = new SQLiteCommand(sql, conn))
using (var cmd = new SqliteCommand(sql, conn))
cmd.ExecuteNonQuery();

}
Expand All @@ -77,14 +77,14 @@ public void LoadFakeChests()
TSPlayer.Server.SendInfoMessage("Loading per-player loot chest inventories...");
int count = 0;

using (SQLiteConnection conn = new SQLiteConnection(connString))
using (SqliteConnection conn = new SqliteConnection(connString))
{
conn.Open();

// load loot chests
using (var cmd = new SQLiteCommand("SELECT id, playerUuid, x, y, items FROM chests;", conn))
using (var cmd = new SqliteCommand("SELECT id, playerUuid, x, y, items FROM chests;", conn))
{
SQLiteDataReader reader = cmd.ExecuteReader();
SqliteDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
Expand Down Expand Up @@ -138,9 +138,9 @@ public void LoadFakeChests()
}

// load tile exclusions
using (var cmd = new SQLiteCommand("SELECT x, y FROM placed;", conn))
using (var cmd = new SqliteCommand("SELECT x, y FROM placed;", conn))
{
SQLiteDataReader reader = cmd.ExecuteReader();
SqliteDataReader reader = cmd.ExecuteReader();

playerPlacedChests.Clear();

Expand All @@ -162,7 +162,7 @@ public void SaveFakeChests()
TSPlayer.Server.SendInfoMessage("Saving per-player loot chest inventories...");
int count = 0;

using (SQLiteConnection conn = new SQLiteConnection(connString))
using (SqliteConnection conn = new SqliteConnection(connString))
{
conn.Open();

Expand Down Expand Up @@ -198,7 +198,7 @@ public void SaveFakeChests()

var sql = @"REPLACE INTO chests (id, playerUuid, x, y, items) VALUES (@id, @playerUuid, @x, @y, @items);";

using (var cmd = new SQLiteCommand(sql, conn))
using (var cmd = new SqliteCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@id", chestId);
cmd.Parameters.AddWithValue("@playerUuid", playerUuid);
Expand All @@ -217,7 +217,7 @@ public void SaveFakeChests()
{
var sql = @"REPLACE INTO placed (x, y) VALUES (@x, @y);";

using (var cmd = new SQLiteCommand(sql, conn))
using (var cmd = new SqliteCommand(sql, conn))
{
cmd.Parameters.AddWithValue("@x", x);
cmd.Parameters.AddWithValue("@y", y);
Expand Down
2 changes: 1 addition & 1 deletion PerPlayerLoot/PPLPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PPLPlugin : TerrariaPlugin
#region info
public override string Name => "PerPlayerLoot";

public override Version Version => new Version(1, 0);
public override Version Version => new Version(2, 0);

public override string Author => "Codian";

Expand Down
8 changes: 0 additions & 8 deletions PerPlayerLoot/PerPlayerLoot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="OTAPI.Upcoming" Version="3.1.20" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
<PackageReference Include="TSAPI" Version="5.2.0" />
<PackageReference Include="TShock" Version="5.2.0" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo copying $(TargetDir)$(ProjectName).dll to tshock server dir...&#xD;&#xA;copy /Y &quot;$(TargetDir)$(ProjectName).dll&quot; &quot;A:\\TShock\\ServerPlugins\\$(ProjectName).dll&quot;" />
</Target>
</Project>
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ there for you to find!

## Installation
1. Copy `PerPlayerLoot.dll` into the `ServerPlugins` directory of your TShock
server.
2. Copy `System.Data.SQLite.dll` into the `bin` directory of your TShock server.
server. You can download this from the [GitHub Releases](https://github.com/xxcodianxx/PerPlayerLoot/releases/) of this repository.
3. Start a new world from scratch (yes, this is important, read below) and play!

> [!WARNING]
> If migrating from version `1.0` of the plugin, you need to move `perplayerloot.sqlite`
> from the server root directory to the `tshock` folder. You should see the file as `tshock/perplayerloot.sqlite`.
> If you do not do this, your existing world chests will behave like loot chests!
## How it Works
This plugin aims to not modify the server-side chest state
(`Terraria.Main.chest`) on chest interactions, in the hope that it can be as
Expand Down Expand Up @@ -58,4 +62,4 @@ possibly broken (which should rarely happen). In that case, the real chest in

Debug use only! When in a disabled state, any chests you place will become
loot chests, and any chest inventory accessed will be its **real inventory**,
not a per-player instanced one!
not a per-player instanced one!

0 comments on commit 798f22f

Please sign in to comment.