From 11b3108a9ad66fd15e4034b39a750b91afd75623 Mon Sep 17 00:00:00 2001 From: js6pak Date: Wed, 23 Dec 2020 21:31:18 +0100 Subject: [PATCH] Add CI --- .github/workflows/main.yml | 41 +++++ .gitmodules | 3 + AmongUs.props | 4 +- Reactor.Greenhouse/Program.cs | 23 ++- Reactor.Greenhouse/Reactor.Greenhouse.csproj | 2 +- Reactor.Greenhouse/Setup/GameManager.cs | 30 +++- .../Setup/Provider/SteamProvider.cs | 32 ++-- Reactor.sln | 30 ++++ build.ps1 | 2 + build.sh | 1 + build/Build.csproj | 17 +++ build/Program.cs | 141 ++++++++++++++++++ lib/Il2CppAssemblyUnhollower | 1 + .../lib => lib}/Il2CppDumper.dll | Bin 14 files changed, 301 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .gitmodules create mode 100644 build.ps1 create mode 100644 build.sh create mode 100644 build/Build.csproj create mode 100644 build/Program.cs create mode 160000 lib/Il2CppAssemblyUnhollower rename {Reactor.Greenhouse/lib => lib}/Il2CppDumper.dll (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..551eb8a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,41 @@ +name: Cake + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.101 + + - name: Download artifact + uses: dawidd6/action-download-artifact@v2 + with: + github_token: ${{secrets.GITHUB_TOKEN}} + workflow: main.yml + workflow_conclusion: success + branch: reactor + name: BepInEx-reactor + repo: NuclearPowered/BepInEx + + - name: Cake Action + run: sh build.sh + env: + STEAM: ${{ secrets.STEAM }} + + - uses: actions/upload-artifact@v2 + with: + name: Reactor.dll + path: Reactor/bin/Release/net472/Reactor.dll diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..822bf2e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/Il2CppAssemblyUnhollower"] + path = lib/Il2CppAssemblyUnhollower + url = https://github.com/NuclearPowered/Il2CppAssemblyUnhollower diff --git a/AmongUs.props b/AmongUs.props index 1622102..1936a08 100644 --- a/AmongUs.props +++ b/AmongUs.props @@ -57,6 +57,7 @@ $(AmongUs)\BepInEx\unhollowed\UnityEngine.IMGUIModule.dll + False $(AmongUs)\BepInEx\unhollowed\UnityEngine.UI.dll @@ -64,6 +65,7 @@ $(AmongUs)\BepInEx\unhollowed\UnityEngine.UIModule.dll + False @@ -73,4 +75,4 @@ - \ No newline at end of file + diff --git a/Reactor.Greenhouse/Program.cs b/Reactor.Greenhouse/Program.cs index c4cf1a7..a29a8ed 100644 --- a/Reactor.Greenhouse/Program.cs +++ b/Reactor.Greenhouse/Program.cs @@ -19,17 +19,21 @@ namespace Reactor.Greenhouse { private static Task Main(string[] args) { - var rootCommand = new RootCommand(); + var rootCommand = new RootCommand + { + new Option("steam"), + new Option("itch"), + }; - rootCommand.Handler = CommandHandler.Create(SearchAsync); + rootCommand.Handler = CommandHandler.Create(GenerateAsync); return rootCommand.InvokeAsync(args); } - private static async Task SearchAsync() + private static async Task GenerateAsync(bool steam, bool itch) { var gameManager = new GameManager(); - await gameManager.SetupAsync(); + await gameManager.SetupAsync(steam, itch); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { @@ -42,8 +46,15 @@ namespace Reactor.Greenhouse Console.WriteLine($"Generating mappings from {gameManager.PreObfuscation.Name} ({gameManager.PreObfuscation.Version})"); using var old = ModuleDefinition.ReadModule(File.OpenRead(gameManager.PreObfuscation.Dll)); - await GenerateAsync(gameManager.Steam, old); - await GenerateAsync(gameManager.Itch, old); + if (steam) + { + await GenerateAsync(gameManager.Steam, old); + } + + if (itch) + { + await GenerateAsync(gameManager.Itch, old); + } } private static async Task GenerateAsync(Game game, ModuleDefinition old) diff --git a/Reactor.Greenhouse/Reactor.Greenhouse.csproj b/Reactor.Greenhouse/Reactor.Greenhouse.csproj index 65c3ae9..89afe54 100644 --- a/Reactor.Greenhouse/Reactor.Greenhouse.csproj +++ b/Reactor.Greenhouse/Reactor.Greenhouse.csproj @@ -13,7 +13,7 @@ - lib\Il2CppDumper.dll + ..\lib\Il2CppDumper.dll diff --git a/Reactor.Greenhouse/Setup/GameManager.cs b/Reactor.Greenhouse/Setup/GameManager.cs index c771450..f899e6e 100644 --- a/Reactor.Greenhouse/Setup/GameManager.cs +++ b/Reactor.Greenhouse/Setup/GameManager.cs @@ -22,11 +22,11 @@ namespace Reactor.Greenhouse.Setup Itch = new Game(new ItchProvider(), "itch", Path.Combine(WorkPath, "itch")); } - public async Task SetupAsync() + public async Task SetupAsync(bool setupSteam, bool setupItch) { var preObfuscation = PreObfuscation.Provider.IsUpdateNeeded(); - var steam = Steam.Provider.IsUpdateNeeded(); - var itch = Itch.Provider.IsUpdateNeeded(); + var steam = setupSteam && Steam.Provider.IsUpdateNeeded(); + var itch = setupItch && Itch.Provider.IsUpdateNeeded(); if (preObfuscation || steam || itch) { @@ -54,8 +54,16 @@ namespace Reactor.Greenhouse.Setup ContentDownloader.ShutdownSteam3(); PreObfuscation.UpdateVersion(); - Steam.UpdateVersion(); - Itch.UpdateVersion(); + + if (setupSteam) + { + Steam.UpdateVersion(); + } + + if (setupItch) + { + Itch.UpdateVersion(); + } if (PreObfuscation.Version != "2020.9.9") { @@ -63,8 +71,16 @@ namespace Reactor.Greenhouse.Setup } PreObfuscation.Dump(); - Steam.Dump(); - Itch.Dump(); + + if (setupSteam) + { + Steam.Dump(); + } + + if (setupItch) + { + Itch.Dump(); + } } } } diff --git a/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs b/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs index 05ffe4a..543e323 100644 --- a/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs +++ b/Reactor.Greenhouse/Setup/Provider/SteamProvider.cs @@ -62,21 +62,31 @@ namespace Reactor.Greenhouse.Setup.Provider AccountSettingsStore.LoadFromFile("account.config"); - ContentDownloader.Config.RememberPassword = true; + var environmentVariable = Environment.GetEnvironmentVariable("STEAM"); - Console.Write("Steam username: "); - var username = Console.ReadLine(); - - string password = null; - - if (!AccountSettingsStore.Instance.LoginKeys.ContainsKey(username)) + if (environmentVariable != null) { - Console.Write("Steam password: "); - password = ContentDownloader.Config.SuppliedPassword = Util.ReadPassword(); - Console.WriteLine(); + var split = environmentVariable.Split(":"); + ContentDownloader.InitializeSteam3(split[0], split[1]); } + else + { + ContentDownloader.Config.RememberPassword = true; - ContentDownloader.InitializeSteam3(username, password); + Console.Write("Steam username: "); + var username = Console.ReadLine(); + + string password = null; + + if (!AccountSettingsStore.Instance.LoginKeys.ContainsKey(username)) + { + Console.Write("Steam password: "); + password = ContentDownloader.Config.SuppliedPassword = Util.ReadPassword(); + Console.WriteLine(); + } + + ContentDownloader.InitializeSteam3(username, password); + } ContentDownloader.Config.UsingFileList = true; ContentDownloader.Config.FilesToDownload = new List diff --git a/Reactor.sln b/Reactor.sln index b9e2daf..b98aa3a 100644 --- a/Reactor.sln +++ b/Reactor.sln @@ -7,6 +7,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reactor.Debugger", "Reactor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Reactor.Greenhouse", "Reactor.Greenhouse\Reactor.Greenhouse.csproj", "{00BF8959-652F-46B8-AA0F-891B4DA1112B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "build\Build.csproj", "{58AC4924-AC3D-45EA-80D7-E9F860FD1DD2}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{E2F4DAFA-E98C-4A7D-BA47-AAB0271A769D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssemblyUnhollower", "lib/Il2CppAssemblyUnhollower\AssemblyUnhollower\AssemblyUnhollower.csproj", "{64ABFD11-CE06-4220-A626-55B39AB85B62}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnhollowerBaseLib", "lib/Il2CppAssemblyUnhollower\UnhollowerBaseLib\UnhollowerBaseLib.csproj", "{17B4E6AE-EA5A-43BE-9184-5BBB6594C5E7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,5 +37,27 @@ Global {00BF8959-652F-46B8-AA0F-891B4DA1112B}.Debug|Any CPU.Build.0 = Debug|Any CPU {00BF8959-652F-46B8-AA0F-891B4DA1112B}.Release|Any CPU.ActiveCfg = Release|Any CPU {00BF8959-652F-46B8-AA0F-891B4DA1112B}.Release|Any CPU.Build.0 = Release|Any CPU + {58AC4924-AC3D-45EA-80D7-E9F860FD1DD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58AC4924-AC3D-45EA-80D7-E9F860FD1DD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58AC4924-AC3D-45EA-80D7-E9F860FD1DD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58AC4924-AC3D-45EA-80D7-E9F860FD1DD2}.Release|Any CPU.Build.0 = Release|Any CPU + {64ABFD11-CE06-4220-A626-55B39AB85B62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {64ABFD11-CE06-4220-A626-55B39AB85B62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {64ABFD11-CE06-4220-A626-55B39AB85B62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {64ABFD11-CE06-4220-A626-55B39AB85B62}.Release|Any CPU.Build.0 = Release|Any CPU + {17B4E6AE-EA5A-43BE-9184-5BBB6594C5E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17B4E6AE-EA5A-43BE-9184-5BBB6594C5E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17B4E6AE-EA5A-43BE-9184-5BBB6594C5E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17B4E6AE-EA5A-43BE-9184-5BBB6594C5E7}.Release|Any CPU.Build.0 = Release|Any CPU + {78FD0EDA-0F47-44E9-8FB1-6B4E64E21AD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78FD0EDA-0F47-44E9-8FB1-6B4E64E21AD7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78FD0EDA-0F47-44E9-8FB1-6B4E64E21AD7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78FD0EDA-0F47-44E9-8FB1-6B4E64E21AD7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {64ABFD11-CE06-4220-A626-55B39AB85B62} = {E2F4DAFA-E98C-4A7D-BA47-AAB0271A769D} + {58AC4924-AC3D-45EA-80D7-E9F860FD1DD2} = {E2F4DAFA-E98C-4A7D-BA47-AAB0271A769D} + {17B4E6AE-EA5A-43BE-9184-5BBB6594C5E7} = {E2F4DAFA-E98C-4A7D-BA47-AAB0271A769D} + {78FD0EDA-0F47-44E9-8FB1-6B4E64E21AD7} = {E2F4DAFA-E98C-4A7D-BA47-AAB0271A769D} EndGlobalSection EndGlobal diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..a707719 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,2 @@ +dotnet run --project build/Build.csproj -- $args +exit $LASTEXITCODE; \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..dfd6b85 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +dotnet run --project ./build/Build.csproj -- "$@" diff --git a/build/Build.csproj b/build/Build.csproj new file mode 100644 index 0000000..01bdca4 --- /dev/null +++ b/build/Build.csproj @@ -0,0 +1,17 @@ + + + Exe + net5.0 + $(MSBuildProjectDirectory)/.. + + + + + + ..\lib\Il2CppDumper.dll + + + + + + \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs new file mode 100644 index 0000000..1c0c84b --- /dev/null +++ b/build/Program.cs @@ -0,0 +1,141 @@ +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using AssemblyUnhollower; +using Cake.Common; +using Cake.Common.Diagnostics; +using Cake.Common.IO; +using Cake.Common.Tools.DotNetCore; +using Cake.Common.Tools.DotNetCore.Build; +using Cake.Common.Tools.DotNetCore.Run; +using Cake.Core; +using Cake.Frosting; +using DepotDownloader; +using Reactor.OxygenFilter; + +public static class Program +{ + public static int Main(string[] args) + { + return new CakeHost() + .UseContext() + .Run(args); + } +} + +public class BuildContext : FrostingContext +{ + public string TempPath { get; } = "bin/temp"; + public string AmongUsPath { get; } = "bin/Among Us"; + + public BuildContext(ICakeContext context) : base(context) + { + context.CreateDirectory(TempPath); + context.CreateDirectory(AmongUsPath); + } +} + +[TaskName("SetupAmongUs")] +public sealed class SetupAmongUsTask : AsyncFrostingTask +{ + public const uint AppId = 945360; + public const uint DepotId = 945361; + + public override async Task RunAsync(BuildContext context) + { + AccountSettingsStore.LoadFromFile("account.config"); + var steam = context.EnvironmentVariable("STEAM", null).Split(":"); + + context.Information("Logging into steam"); + ContentDownloader.InitializeSteam3(steam[0], steam[1]); + + ContentDownloader.Config.InstallDirectory = context.AmongUsPath; + + context.Information("Downloading the game from steam"); + await ContentDownloader.DownloadAppAsync(AppId, DepotId); + ContentDownloader.ShutdownSteam3(); + + context.Unzip(context.GetFiles("BepInEx_UnityIL2CPP_x86_*.zip").Single(), Path.Combine(context.AmongUsPath)); + } +} + +[TaskName("GenerateProxyAssembly")] +[IsDependentOn(typeof(SetupAmongUsTask))] +public sealed class GenerateProxyAssemblyTask : FrostingTask +{ + public override void Run(BuildContext context) + { + var dumperConfig = new Il2CppDumper.Config + { + GenerateScript = false, + GenerateDummyDll = true + }; + + context.Information("Generating Il2CppDumper intermediate assemblies"); + + var gameAssemblyPath = Path.Combine(context.AmongUsPath, "GameAssembly.dll"); + + Il2CppDumper.Il2CppDumper.PerformDump( + gameAssemblyPath, + Path.Combine(context.AmongUsPath, "Among Us_Data", "il2cpp_data", "Metadata", "global-metadata.dat"), + context.TempPath, dumperConfig, context.Debug + ); + + context.Information("Executing Reactor.Greenhouse"); + + context.DotNetCoreRun(".", "steam", new DotNetCoreRunSettings + { + WorkingDirectory = "Reactor.Greenhouse" + }); + + context.Information("Executing Reactor.OxygenFilter"); + + var oxygenFilter = new OxygenFilter(); + + var dumpedDll = new FileInfo(Path.Combine(context.TempPath, "DummyDll", "Assembly-CSharp.dll")); + oxygenFilter.Start(new FileInfo(Path.Combine("Reactor.Greenhouse", "work", "2020.12.9s.json")), dumpedDll, dumpedDll); + + context.Information("Executing Il2CppUnhollower generator"); + + UnhollowerBaseLib.LogSupport.InfoHandler += context.Information; + UnhollowerBaseLib.LogSupport.WarningHandler += context.Warning; + UnhollowerBaseLib.LogSupport.TraceHandler += context.Debug; + UnhollowerBaseLib.LogSupport.ErrorHandler += context.Error; + + var unityBaseLibDir = Path.Combine(context.AmongUsPath, "BepInEx", "unhollowed", "base"); + + var unhollowerOptions = new UnhollowerOptions + { + GameAssemblyPath = gameAssemblyPath, + MscorlibPath = Path.Combine(context.AmongUsPath, "mono", "Managed", "mscorlib.dll"), + SourceDir = Path.Combine(context.TempPath, "DummyDll"), + OutputDir = Path.Combine(context.AmongUsPath, "BepInEx", "unhollowed"), + UnityBaseLibsDir = unityBaseLibDir, + NoCopyUnhollowerLibs = true + }; + + AssemblyUnhollower.Program.Main(unhollowerOptions); + } +} + +[TaskName("Build")] +[IsDependentOn(typeof(GenerateProxyAssemblyTask))] +public sealed class BuildTask : FrostingTask +{ + public override void Run(BuildContext context) + { + context.DotNetCoreBuild("./Reactor/Reactor.csproj", new DotNetCoreBuildSettings + { + Configuration = "Release", + EnvironmentVariables = + { + ["AmongUs"] = Path.GetFullPath(context.AmongUsPath) + } + }); + } +} + +[IsDependentOn(typeof(BuildTask))] +public sealed class Default : FrostingTask +{ +} diff --git a/lib/Il2CppAssemblyUnhollower b/lib/Il2CppAssemblyUnhollower new file mode 160000 index 0000000..0d7585f --- /dev/null +++ b/lib/Il2CppAssemblyUnhollower @@ -0,0 +1 @@ +Subproject commit 0d7585fa90844fe0887e13c2828ecd2e4f84784d diff --git a/Reactor.Greenhouse/lib/Il2CppDumper.dll b/lib/Il2CppDumper.dll similarity index 100% rename from Reactor.Greenhouse/lib/Il2CppDumper.dll rename to lib/Il2CppDumper.dll