Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to .NET 9 and OTAPI Static Hooks for ARM64 #3050

Draft
wants to merge 11 commits into
base: general-devel
Choose a base branch
from
6 changes: 3 additions & 3 deletions .github/workflows/ci-otapi3-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
environment: release

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.400
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/ci-otapi3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- uses: actions/setup-dotnet@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.100'
dotnet-version: 9.0.x

- name: Run tests
run: dotnet test
Expand All @@ -25,53 +25,53 @@ jobs:
arch: ["win-x64", "osx-x64", "linux-x64", "linux-arm64", "linux-arm"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- uses: actions/setup-dotnet@v3
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.100'
dotnet-version: 9.0.x

- name: Install msgfmt
run: sudo apt-get install -y gettext

- name: Produce installer
run: |
cd TShockInstaller
dotnet publish -r ${{ matrix.arch }} -f net6.0 -c Release -p:PublishSingleFile=true --self-contained true
dotnet publish -r ${{ matrix.arch }} -f net9.0 -c Release -p:PublishSingleFile=true --self-contained true

- name: Produce build
run: |
cd TShockLauncher
dotnet publish -r ${{ matrix.arch }} -f net6.0 -c Release -p:PublishSingleFile=true --self-contained false
dotnet publish -r ${{ matrix.arch }} -f net9.0 -c Release -p:PublishSingleFile=true --self-contained false

- name: Chmod scripts
if: ${{ matrix.arch != 'win-x64' }}
run: |
chmod +x TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/TShock.Server
chmod +x TShockLauncher/bin/Release/net9.0/${{ matrix.arch }}/publish/TShock.Server

- name: Copy installer
run: |
cp TShockInstaller/bin/Release/net6.0/${{ matrix.arch }}/publish/* TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/
cp TShockInstaller/bin/Release/net9.0/${{ matrix.arch }}/publish/* TShockLauncher/bin/Release/net9.0/${{ matrix.arch }}/publish/

# preserve file perms: https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
- name: Tarball artifact (non-Windows)
if: ${{ matrix.arch != 'win-x64' }}
run: |
cd TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/
cd TShockLauncher/bin/Release/net9.0/${{ matrix.arch }}/publish/
tar -cvf ../../../../../../TShock-Beta-${{ matrix.arch }}-Release.tar *

- name: Upload artifact (non-Windows)
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ matrix.arch != 'win-x64' }}
with:
name: TShock-Beta-${{ matrix.arch }}-Release
path: TShock-Beta-${{ matrix.arch }}-Release.tar

- name: Upload artifact (Windows)
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: ${{ matrix.arch == 'win-x64' }}
with:
name: TShock-Beta-${{ matrix.arch }}-Release
path: TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/
path: TShockLauncher/bin/Release/net9.0/${{ matrix.arch }}/publish/
7 changes: 2 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/TShockLauncher/bin/Debug/net6.0/TShock.Run.dll",
"windows": {
"program": "${workspaceFolder}/TShockLauncher/bin/Debug/net6.0/TShock.dll",
},
"program": "${workspaceFolder}/TShockLauncher/bin/Debug/net9.0/TShock.Server.dll",
"args": [],
"cwd": "${workspaceFolder}/TShockLauncher/bin/Debug/net6.0/",
"cwd": "${workspaceFolder}/TShockLauncher/bin/Debug/net9.0/",
"console": "integratedTerminal",
"stopAtEntry": false
},
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{
"label": "Remote Publish",
"options": {
"cwd": "TShockLauncher/bin/Debug/net6.0/linux-arm64"
"cwd": "TShockLauncher/bin/Debug/net9.0/linux-arm64"
},
"command": "C:\\Program Files\\PuTTY\\pscp.exe",
"type": "process",
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TARGETPLATFORM and BUILDPLATFORM are automatically filled in by Docker buildx.
# They should not be set in the global scope manually.

FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:6.0 AS builder
FROM --platform=${BUILDPLATFORM} mcr.microsoft.com/dotnet/sdk:9.0 AS builder

# Copy build context
WORKDIR /TShock
Expand All @@ -27,7 +27,7 @@ RUN \
*) echo "Error: Unsupported platform ${TARGETPLATFORM}" && exit 1 \
;; \
esac && \
dotnet publish -o output/ -r "${ARCH}" -v m -f net6.0 -c Release -p:PublishSingleFile=true --self-contained false
dotnet publish -o output/ -r "${ARCH}" -v m -f net9.0 -c Release -p:PublishSingleFile=true --self-contained false

# Runtime image
FROM --platform=${TARGETPLATFORM} mcr.microsoft.com/dotnet/runtime:6.0 AS runner
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ If you want to run the `TShockLauncher` (which runs a server), run:
To produce a packaged release (suitable for distribution), run:

1. `cd TShockLauncher`
1. `dotnet publish -r win-x64 -f net6.0 -c Release -p:PublishSingleFile=true --self-contained false`
1. `dotnet publish -r win-x64 -f net9.0 -c Release -p:PublishSingleFile=true --self-contained false`

Note that in this example, you'd be building for `win-x64`. You can build for `win-x64`, `osx-x64`, `linux-x64`, `linux-arm64`, `linux-arm`. Your release will be in the `TShockLauncher/bin/Release/net6.0/` folder under the architecture you specified.
Note that in this example, you'd be building for `win-x64`. You can build for `win-x64`, `osx-x64`, `linux-x64`, `linux-arm64`, `linux-arm`. Your release will be in the `TShockLauncher/bin/Release/net9.0/` folder under the architecture you specified.

### Working with Terraria

Expand Down
4 changes: 2 additions & 2 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ TShock是为泰拉瑞亚服务器和社区开发的一个工具箱。这个工
如果要生成打包后的发行版,运行:

1. `cd TShockLauncher`
1. `dotnet publish -r win-x64 -f net6.0 -c Release -p:PublishSingleFile=true --self-contained false`
1. `dotnet publish -r win-x64 -f net9.0 -c Release -p:PublishSingleFile=true --self-contained false`

注意在这个例子中你将会生成`win-x64`架构的版本。你也可以生成`win-x64`、`osx-x64`、`linux-x64`、`linux-arm64`、`linux-arm`的版本。你可以在`TShockLauncher/bin/Release/net6.0/`文件夹下对应架构的文件夹里找到生成后的发行版。
注意在这个例子中你将会生成`win-x64`架构的版本。你也可以生成`win-x64`、`osx-x64`、`linux-x64`、`linux-arm64`、`linux-arm`的版本。你可以在`TShockLauncher/bin/Release/net9.0/`文件夹下对应架构的文件夹里找到生成后的发行版。

### 跟泰拉瑞亚本体代码交互

Expand Down
18 changes: 4 additions & 14 deletions TShockAPI/TShock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,6 @@
Hooks.AccountHooks.AccountDelete += OnAccountDelete;
Hooks.AccountHooks.AccountCreate += OnAccountCreate;

On.Terraria.RemoteClient.Reset += RemoteClient_Reset;

GetDataHandlers.InitGetDataHandler();
Commands.InitCommands();

Expand All @@ -449,7 +447,7 @@
// Initialize the AchievementManager, which is normally only done on clients.
Game._achievements = new AchievementManager();

IL.Terraria.Initializers.AchievementInitializer.Load += OnAchievementInitializerLoad;
OTAPI.Hooks.Initializers.AchievementInitializerLoad += OnAchievementInitializerLoad;

// Actually call AchievementInitializer.Load, which is also normally only done on clients.
AchievementInitializer.Load();
Expand Down Expand Up @@ -498,17 +496,9 @@
}
}

private static void RemoteClient_Reset(On.Terraria.RemoteClient.orig_Reset orig, RemoteClient client)
{
client.ClientUUID = null;
orig(client);
}

private static void OnAchievementInitializerLoad(ILContext il)
private static void OnAchievementInitializerLoad(object sender, OTAPI.Hooks.Initializers.AchievementInitializerLoadEventArgs args)

Check failure on line 499 in TShockAPI/TShock.cs

View workflow job for this annotation

GitHub Actions / build (win-x64)

The type name 'Initializers' does not exist in the type 'Hooks'

Check failure on line 499 in TShockAPI/TShock.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm)

The type name 'Initializers' does not exist in the type 'Hooks'

Check failure on line 499 in TShockAPI/TShock.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64)

The type name 'Initializers' does not exist in the type 'Hooks'

Check failure on line 499 in TShockAPI/TShock.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64)

The type name 'Initializers' does not exist in the type 'Hooks'

Check failure on line 499 in TShockAPI/TShock.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64)

The type name 'Initializers' does not exist in the type 'Hooks'

Check failure on line 499 in TShockAPI/TShock.cs

View workflow job for this annotation

GitHub Actions / test

The type name 'Initializers' does not exist in the type 'Hooks'
{
// Modify AchievementInitializer.Load to remove the Main.netMode == 2 check (occupies the first 4 IL instructions)
for (var i = 0; i < 4; i++)
il.Body.Instructions.RemoveAt(0);
args.ShouldLoad = true;
}

protected void CrashReporter_HeapshotRequesting(object sender, EventArgs e)
Expand All @@ -532,7 +522,7 @@
}
SaveManager.Instance.Dispose();

IL.Terraria.Initializers.AchievementInitializer.Load -= OnAchievementInitializerLoad;
OTAPI.Hooks.Initializers.AchievementInitializerLoad -= OnAchievementInitializerLoad;

ModuleManager.Dispose();

Expand Down
8 changes: 4 additions & 4 deletions TShockAPI/TShockAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<!--
Expand Down Expand Up @@ -33,9 +33,9 @@

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="GetText.NET" Version="1.7.14" />
<PackageReference Include="MySql.Data" Version="8.0.31" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.11" />
<PackageReference Include="GetText.NET" Version="8.0.5" />
<PackageReference Include="MySql.Data" Version="9.1.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions TShockInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

string? url = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
url = $"https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.11/dotnet-runtime-6.0.11-osx-{arch}.tar.gz";
url = $"https://dotnetcli.azureedge.net/dotnet/Runtime/9.0.0/dotnet-runtime-9.0.0-osx-{arch}.tar.gz";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
url = $"https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.11/dotnet-runtime-6.0.11-win-{arch}.zip";
url = $"https://dotnetcli.azureedge.net/dotnet/Runtime/9.0.0/dotnet-runtime-9.0.0-win-{arch}.zip";
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
url = $"https://dotnetcli.azureedge.net/dotnet/Runtime/6.0.11/dotnet-runtime-6.0.11-linux-{arch}.tar.gz";
url = $"https://dotnetcli.azureedge.net/dotnet/Runtime/9.0.0/dotnet-runtime-9.0.0-linux-{arch}.tar.gz";

if(url is null)
{
Expand Down
2 changes: 1 addition & 1 deletion TShockInstaller/TShockInstaller.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>5.0.0</Version>
Expand Down
6 changes: 3 additions & 3 deletions TShockLauncher.Tests/GroupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public void TestPermissions()
groups.AddPermissions("test", new() { "abc" });

var hasperm = groups.GetGroupByName("test").Permissions.Contains("abc");
Assert.IsTrue(hasperm);
Assert.That(hasperm, Is.True);

groups.DeletePermissions("test", new() { "abc" });

hasperm = groups.GetGroupByName("test").Permissions.Contains("abc");
Assert.IsFalse(hasperm);
Assert.That(hasperm, Is.False);

groups.DeleteGroup("test");

var g = groups.GetGroupByName("test");
Assert.IsNull(g);
Assert.That(g, Is.Null);
}
}

11 changes: 6 additions & 5 deletions TShockLauncher.Tests/ServerInitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ public class ServerInitTests
public void EnsureBoots()
{
var are = new AutoResetEvent(false);
On.Terraria.Main.hook_DedServ cb = (On.Terraria.Main.orig_DedServ orig, Terraria.Main instance) =>
HookEvents.HookDelegate<Terraria.Main, HookEvents.Terraria.Main.DedServEventArgs> cb = (instance, args) =>
{
args.ContinueExecution = false;
are.Set();
Debug.WriteLine("Server init process successful");
};
On.Terraria.Main.DedServ += cb;
HookEvents.Terraria.Main.DedServ += cb;

new Thread(() => TerrariaApi.Server.Program.Main(new string[] { })).Start();
new Thread(() => TerrariaApi.Server.Program.Main([])).Start();

var hit = are.WaitOne(TimeSpan.FromSeconds(10));

On.Terraria.Main.DedServ -= cb;
HookEvents.Terraria.Main.DedServ -= cb;

Assert.IsTrue(hit);
Assert.That(hit, Is.True);
}
}

15 changes: 9 additions & 6 deletions TShockLauncher.Tests/TShockLauncher.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
23 changes: 11 additions & 12 deletions TShockLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,12 @@ You should have received a copy of the GNU General Public License
*/

using System.Reflection;
using TShockPluginManager;

if (args.Length > 0 && args[0].ToLower() == "plugins")
{
var items = args.ToList();
items.RemoveAt(0);
await NugetCLI.Main(items);
return;
}


Dictionary<string, Assembly> _cache = new Dictionary<string, Assembly>();

System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += Default_Resolving;

Start();
await StartAsync();

/// <summary>
/// Resolves a module from the ./bin folder, either with a .dll by preference or .exe
Expand All @@ -53,6 +43,7 @@ You should have received a copy of the GNU General Public License
if (_cache.TryGetValue(arg2.Name, out Assembly? asm) && asm is not null) return asm;

var loc = Path.Combine(AppContext.BaseDirectory, "bin", arg2.Name + ".dll");

if (File.Exists(loc))
asm = arg1.LoadFromAssemblyPath(loc);

Expand All @@ -70,7 +61,15 @@ You should have received a copy of the GNU General Public License
/// Initiates the TSAPI server.
/// </summary>
/// <remarks>This method exists so that the resolver can attach before TSAPI needs its dependencies.</remarks>
void Start()
async Task StartAsync()
{
if (args.Length > 0 && args[0].ToLower() == "plugins")
{
var items = args.ToList();
items.RemoveAt(0);
await TShockPluginManager.NugetCLI.Main(items);
return;
}

TerrariaApi.Server.Program.Main(args);
}
Loading
Loading