diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65ee8303..ced85b9e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,28 +12,38 @@ on: jobs: build: name: Create artifacts - runs-on: ubuntu-latest + runs-on: windows-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x.x' - name: Build Winch + shell: bash run: dotnet build -c ${{ inputs.build_type }} - name: Copy WinchConsole into Winch folder + shell: bash run: | cp -r WinchConsole/bin/* Winch/bin/ + - name: Copy WinchLauncher into Winch folder + shell: bash + run: | + cp -r WinchLauncher/bin/* Winch/bin/ + - name: Upload Winch Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Winch path: Winch/bin - name: Move Example Mods + shell: bash run: | for mod in DisasterButton ExampleItems IntroSkipper do @@ -42,7 +52,7 @@ jobs: done - name: Upload Example Mod Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: Winch Examples path: | diff --git a/.github/workflows/manual_nuget.yml b/.github/workflows/manual_nuget.yml index 42c7e7c4..6bce15ca 100644 --- a/.github/workflows/manual_nuget.yml +++ b/.github/workflows/manual_nuget.yml @@ -20,7 +20,7 @@ jobs: if: github.ref == 'refs/heads/master' steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get version id: version uses: notiz-dev/github-action-json-property@release @@ -30,7 +30,7 @@ jobs: - name: Set up nuget uses: NuGet/setup-nuget@v1.0.5 - name: Download Winch Asset - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Winch path: Winch/bin diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index 4088a1e2..8d0f6bcd 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -33,7 +33,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download Winch Asset - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Winch path: Winch @@ -46,7 +46,7 @@ jobs: cd .. - name: Download Example Mods - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Winch Examples path: Examples @@ -78,7 +78,7 @@ jobs: if: github.ref == 'refs/heads/master' steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get version id: version uses: notiz-dev/github-action-json-property@release @@ -88,7 +88,7 @@ jobs: - name: Set up nuget uses: NuGet/setup-nuget@v1.0.5 - name: Download Winch Asset - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: Winch path: Winch/bin diff --git a/Winch.Examples/IntroSkipper/SplashControllerPatcher.cs b/Winch.Examples/IntroSkipper/SplashControllerPatcher.cs index 26a74cee..c027dcdb 100644 --- a/Winch.Examples/IntroSkipper/SplashControllerPatcher.cs +++ b/Winch.Examples/IntroSkipper/SplashControllerPatcher.cs @@ -1,16 +1,36 @@ -using HarmonyLib; +using System; +using HarmonyLib; using Winch.Core; namespace IntroSkipper; -[HarmonyPatch(typeof(SplashController))] -[HarmonyPatch(nameof(SplashController.OnEnable))] +[HarmonyPatch] internal static class SplashControllerPatcher { - public static bool Prefix() + [HarmonyPrefix] + [HarmonyPatch(typeof(SceneLoader), nameof(SceneLoader.ShouldShowSplashScreen))] + public static bool SceneLoader_ShouldShowSplashScreen(SceneLoader __instance, ref bool __result) + { + // Base game checks for save files here without null checking + __result = false; + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(SplashController), nameof(SplashController.OnEnable))] + public static bool SplashController_OnEnable() { WinchCore.Log.Info("Skipping Splash Screen..."); - GameManager.Instance.Loader.LoadStartupFromSplash(); + try + { + GameManager.Instance.Loader.LoadStartupFromSplash(); + } + catch (Exception e) + { + // version 1.5.4 made it throw an exception before, let's keep this try-catch just in case (would result in a black screen that bricks the game) + WinchCore.Log.Error(e); + } + return false; } } \ No newline at end of file diff --git a/Winch.Examples/IntroSkipper/mod_meta.json b/Winch.Examples/IntroSkipper/mod_meta.json index ed3b2521..f61adc8d 100644 --- a/Winch.Examples/IntroSkipper/mod_meta.json +++ b/Winch.Examples/IntroSkipper/mod_meta.json @@ -1,7 +1,7 @@ { "Name": "Intro Skipper", "ModGUID": "hacktix.introskipper", - "Version": "1.0.0", + "Version": "1.0.1", "ModAssembly": "IntroSkipper.dll", "MinWinchVersion": "alpha-1.4", "ApplyPatches": true diff --git a/Winch.sln b/Winch.sln index 4ceb150f..461d6264 100644 --- a/Winch.sln +++ b/Winch.sln @@ -11,9 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DisasterButton", "Winch.Exa EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExampleItems", "Winch.Examples\ExampleItems\ExampleItems.csproj", "{C112288E-E993-44F3-B7B0-FB4BD37F18EA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinchConsole", "WinchConsole\WinchConsole.csproj", "{D5CFABA9-FA58-474F-A394-E197BDF38FDD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinchConsole", "WinchConsole\WinchConsole.csproj", "{D5CFABA9-FA58-474F-A394-E197BDF38FDD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinchCommon", "WinchCommon\WinchCommon.csproj", "{EF5F69E6-FD4D-4314-B187-A89D00BF9355}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinchCommon", "WinchCommon\WinchCommon.csproj", "{EF5F69E6-FD4D-4314-B187-A89D00BF9355}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinchLauncher", "WinchLauncher\WinchLauncher.csproj", "{45CB6021-0D96-4231-9F53-4C73597998D8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -45,6 +47,10 @@ Global {EF5F69E6-FD4D-4314-B187-A89D00BF9355}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF5F69E6-FD4D-4314-B187-A89D00BF9355}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF5F69E6-FD4D-4314-B187-A89D00BF9355}.Release|Any CPU.Build.0 = Release|Any CPU + {45CB6021-0D96-4231-9F53-4C73597998D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45CB6021-0D96-4231-9F53-4C73597998D8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45CB6021-0D96-4231-9F53-4C73597998D8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45CB6021-0D96-4231-9F53-4C73597998D8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Winch/mod_meta.json b/Winch/mod_meta.json index cd58fd24..d4fdd5cc 100644 --- a/Winch/mod_meta.json +++ b/Winch/mod_meta.json @@ -2,5 +2,5 @@ "Name": "Winch", "Author": "Hacktix", "ModGUID": "hacktix.winch", - "Version": "0.5.3" + "Version": "0.6.0" } diff --git a/WinchLauncher/Launcher.cs b/WinchLauncher/Launcher.cs new file mode 100644 index 00000000..13f41009 --- /dev/null +++ b/WinchLauncher/Launcher.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace WinchLauncher; + +internal static class Launcher +{ + public static void Main(string[] args) + { + StartGame(); + + // Keep the window open until the user presses a key + // Console.WriteLine("Press any key to exit..."); + // Console.ReadKey(); + } + + /// + /// Adapted from OWML https://github.com/ow-mods/owml/blob/master/src/OWML.Launcher/App.cs + /// + public static void StartGame() + { + string gamePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + + var dllPath = Path.Combine(gamePath, "DREDGE_Data/Managed/Assembly-CSharp.dll"); + + void StartGameViaExe() + { + Console.WriteLine("Defaulting to running exe. If you bought DREDGE on Epic Games this will not work. Run the game from there directly"); + Process.Start(Path.Combine(gamePath, "DREDGE.exe")); + } + + bool isEpic = false, isSteam = false; + + Assembly assembly = null; + try + { + assembly = Assembly.LoadFrom(dllPath); + } + catch (Exception e) + { + Console.WriteLine("Failed to load assembly: " + e.Message); + StartGameViaExe(); + return; + } + + try + { + List types; + try + { + types = assembly.GetExportedTypes().Select(x => x.Name).ToList(); + } + catch (ReflectionTypeLoadException ex) + { + Console.WriteLine("Only partially loaded assembly: " + ex.Message); + + // Apparently this can happen + types = ex.Types.Where(x => x != null).Select(x => x.Name).ToList(); + } + + types.Sort(); + isEpic = types.Any(x => x == "EOSScreenshotStrategy"); + isSteam = types.Any(x => x == "SteamEntitlementStrategy"); + + foreach (var type in types) + { + Console.WriteLine(type); + } + } + catch (Exception e) + { + Console.WriteLine("Failed to load types from assembly: " + e.Message); + StartGameViaExe(); + return; + } + + try + { + if (isEpic && !isSteam) + { + Console.WriteLine("Identified as Epic install"); + + Process.Start(new ProcessStartInfo("com.epicgames.launcher://apps/8b454b47f5544fc6829cf0fed42ebae0%3Aeac6533129434f98a6b04a81cbcaf357%3A65c25644a2e0444d8766967a008b1d69?action=launch&silent=true") { UseShellExecute = true }); + } + else if (!isEpic && isSteam) + { + Console.WriteLine("Identified as Steam install"); + + Process.Start(new ProcessStartInfo("steam://rungameid/1562430") { UseShellExecute = true }); + } + else + { + Console.WriteLine("Couldn't identify vendor"); + + StartGameViaExe(); + } + } + catch (Exception e) + { + Console.WriteLine("Failed to start process: " + e.Message); + StartGameViaExe(); + return; + } + } +} diff --git a/WinchLauncher/WinchLauncher.csproj b/WinchLauncher/WinchLauncher.csproj new file mode 100644 index 00000000..db166cd6 --- /dev/null +++ b/WinchLauncher/WinchLauncher.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + latest + false + false + + + + + + +