diff --git a/TShock.sln b/TShock.sln index 45ac4bdb..af1bc555 100644 --- a/TShock.sln +++ b/TShock.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockAPI", "TShockAPI\TSho EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TerrariaServerAPI", "TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj", "{6877506E-ADC6-4142-98A6-79E4FA02855A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockLauncher", "TShockLauncher\TShockLauncher.csproj", "{2A312452-A43F-43E3-8AEB-E22F9A35C210}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -53,6 +55,22 @@ Global {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|x64.Build.0 = Release|Any CPU {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|x86.ActiveCfg = Release|Any CPU {6877506E-ADC6-4142-98A6-79E4FA02855A}.Release|x86.Build.0 = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|x64.ActiveCfg = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|x64.Build.0 = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|x86.ActiveCfg = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Debug|x86.Build.0 = Debug|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|Any CPU.Build.0 = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|x64.ActiveCfg = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|x64.Build.0 = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|x86.ActiveCfg = Release|Any CPU + {2A312452-A43F-43E3-8AEB-E22F9A35C210}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj index 2eed28be..408d2d3c 100644 --- a/TShockAPI/TShockAPI.csproj +++ b/TShockAPI/TShockAPI.csproj @@ -27,16 +27,8 @@ Pryaxis & TShock Contributors TShockAPI Copyright © Pryaxis & TShock Contributors 2011-2021 - - true - - Program - $(SolutionDir)\TShockAPI\bin\Debug\net6.0\TerrariaServerAPI.dll - $(SolutionDir)\TShockAPI\bin\Debug\net6.0\ - true - @@ -54,18 +46,4 @@ - - - - - - - - - - - - - - diff --git a/TShockLauncher/Program.cs b/TShockLauncher/Program.cs new file mode 100644 index 00000000..091b8967 --- /dev/null +++ b/TShockLauncher/Program.cs @@ -0,0 +1,66 @@ +/* +TShock, a server mod for Terraria +Copyright (C) 2011-2019 Pryaxis & TShock Contributors + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* + * The purpose of this project is to be the launcher of the TSAPI server. + * We use this project: + * - to copy/move around TShockAPI.dll (the TShock plugin to TSAPI) + * - to publishing TShock releases. + * - move dependencies to a ./bin folder + * + * The assembly name of this launcher (TShock.exe) was decided on by a community poll. + */ + +using System.Reflection; + +Dictionary _cache = new Dictionary(); + +System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += Default_Resolving; + +Start(); + +/// +/// Resolves a module from the ./bin folder, either with a .dll by preference or .exe +/// +Assembly? Default_Resolving(System.Runtime.Loader.AssemblyLoadContext arg1, AssemblyName arg2) +{ + if (arg2?.Name is null) return null; + if (_cache.TryGetValue(arg2.Name, out Assembly? asm) && asm is not null) return asm; + + var loc = Path.Combine(Environment.CurrentDirectory, "bin", arg2.Name + ".dll"); + if (File.Exists(loc)) + asm = arg1.LoadFromAssemblyPath(loc); + + loc = Path.ChangeExtension(loc, ".exe"); + if (File.Exists(loc)) + asm = arg1.LoadFromAssemblyPath(loc); + + if(asm is not null) + _cache[arg2.Name] = asm; + + return asm; +} + +/// +/// Initiates the TSAPI server. +/// +/// This method exists so that the resolver can attach before TSAPI needs its dependencies. +void Start() +{ + TerrariaApi.Server.Program.Main(args); +} diff --git a/TShockLauncher/TShockLauncher.csproj b/TShockLauncher/TShockLauncher.csproj new file mode 100644 index 00000000..9ca38814 --- /dev/null +++ b/TShockLauncher/TShockLauncher.csproj @@ -0,0 +1,105 @@ + + + + Exe + net6.0 + enable + enable + TShock + + + + + + false + + + ..\prebuilts\HttpServer.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /* + This is a patch to allow self contained apps to run from the root while having the modules in a ./bin folder. + https://github.com/dotnet/sdk/issues/10366 + + The script replaces the ./TShock.dll with ./bin/TShock.dll + alternates: dnSpy(does this method), NetCoreBeauty + */ + var find = Encoding.UTF8.GetBytes("TShock.dll\0"); + var replace = Encoding.UTF8.GetBytes("bin" + Path.DirectorySeparatorChar + "TShock.dll\0"); + var contents = File.ReadAllBytes(HostExe); + + var matches = 0; + var offset = Array.FindIndex(contents, (b) => { + matches = (b == find[matches]) ? matches + 1 : 0; + return matches == find.Length; + }); + if (offset > -1) offset -= find.Length - 1; + + var x = 0; + Array.ForEach(replace, _ => { contents[offset + x] = replace[x++]; }); + + File.WriteAllBytes(HostExe, contents); + + + + + + + + + + + + + + + + File.WriteAllText(Path.Combine(OutPath, "TShock.exe"), "#!/bin/bash\n./bin/TShock"); + + + + + + + + + diff --git a/TShockLauncher/runtimeconfig.template.json b/TShockLauncher/runtimeconfig.template.json new file mode 100644 index 00000000..181a42f9 --- /dev/null +++ b/TShockLauncher/runtimeconfig.template.json @@ -0,0 +1,5 @@ +{ + "additionalProbingPaths": [ + "../ServerPlugins" + ] +} diff --git a/TerrariaServerAPI b/TerrariaServerAPI index d9935022..a0b3dacf 160000 --- a/TerrariaServerAPI +++ b/TerrariaServerAPI @@ -1 +1 @@ -Subproject commit d9935022b6ec3ea089d63e2ed8a7225668ce32cb +Subproject commit a0b3dacfeea710cc62c8be43dc607678908f9fc8