-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert project to run under latest BepInEx builds (#1)
* Add nuget.config * Move projects to .NET6 and target latest Bep6 builds * Replace netFm with net6 and rename files to match * Update README.md * Fix dll paths * Re-add netFm projects * Update readme
- Loading branch information
1 parent
11fb5dc
commit 00c5c2a
Showing
38 changed files
with
952 additions
and
13 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
EnableFullScreenToggleIL2CPP_net6/EnableFullScreenToggle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using BepInEx.Unity.IL2CPP; | ||
using Il2CppInterop.Runtime.Injection; | ||
using UnityEngine; | ||
using Input = UnityEngine.Input; | ||
using KeyCode = UnityEngine.KeyCode; | ||
|
||
namespace BepInEx | ||
{ | ||
/// <summary> | ||
/// Allow toggling full screen with alt+enter in games where that has been disabled | ||
/// </summary> | ||
[BepInPlugin(GUID, PluginName, PluginVersion)] | ||
public class EnableFullScreenToggle : BasePlugin | ||
{ | ||
internal const string GUID = "BepInEx.EnableFullScreenToggleIL2CPP_net6"; | ||
internal const string PluginName = "Enable Full Screen Toggle"; | ||
internal const string PluginVersion = "0.7"; | ||
|
||
//Game Object shared between all BepInExUtility plugins | ||
public GameObject BepInExUtility; | ||
|
||
public override void Load() | ||
{ | ||
//IL2CPP don't automatically inherits Monobehavior, so needs to add separatelly | ||
ClassInjector.RegisterTypeInIl2Cpp<FullScreenToggleComponent>(); | ||
|
||
BepInExUtility = GameObject.Find("BepInExUtility"); | ||
|
||
if (BepInExUtility == null) | ||
{ | ||
BepInExUtility = new GameObject("BepInExUtility"); | ||
GameObject.DontDestroyOnLoad(BepInExUtility); | ||
BepInExUtility.hideFlags = HideFlags.HideAndDontSave; | ||
BepInExUtility.AddComponent<FullScreenToggleComponent>(); | ||
} | ||
else BepInExUtility.AddComponent<FullScreenToggleComponent>(); | ||
} | ||
} | ||
|
||
public class FullScreenToggleComponent : MonoBehaviour | ||
{ | ||
//Got this from BepInEx Discord pinned messages | ||
public FullScreenToggleComponent(IntPtr handle) : base(handle) { } | ||
|
||
internal void Update() | ||
{ | ||
if ((Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) && (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))) | ||
//This section of code is never reached on Unity builds where full screen can be toggled, it seems | ||
//We can safely toggle full screen without risk of it being toggled twice | ||
Screen.fullScreen = !Screen.fullScreen; | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
EnableFullScreenToggleIL2CPP_net6/EnableFullScreenToggleIL2CPP_net6.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<OutputType>Library</OutputType> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.664" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="Il2Cppmscorlib"> | ||
<HintPath>..\IL2CPP_net6\Il2Cppmscorlib.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Il2CppSystem"> | ||
<HintPath>..\IL2CPP_net6\Il2CppSystem.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Il2CppSystem.Core"> | ||
<HintPath>..\IL2CPP_net6\Il2CppSystem.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.AudioModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.AudioModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.CoreModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.IMGUIModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.IMGUIModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.InputLegacyModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.InputLegacyModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.InputModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.InputModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.TextRenderingModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.TextRenderingModule.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UI"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.UI.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.UIModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.UIModule.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> | ||
<Exec Command="xcopy "$(TargetPath)" "$(SolutionDir)bin\BepInEx\Plugins\" /s /i /y" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Reflection; | ||
using static BepInEx.EnableFullScreenToggle; | ||
|
||
[assembly: AssemblyTitle(GUID)] | ||
[assembly: AssemblyDescription(PluginName)] | ||
[assembly: AssemblyProduct(GUID)] | ||
[assembly: AssemblyVersion(PluginVersion)] | ||
[assembly: AssemblyFileVersion(PluginVersion)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using BepInEx.Configuration; | ||
using BepInEx.Unity.IL2CPP; | ||
using BepInEx.Unity.IL2CPP.Utils.Collections; | ||
using Il2CppInterop.Runtime.Injection; | ||
using UnityEngine; | ||
|
||
namespace BepInEx | ||
{ | ||
/// <summary> | ||
/// Enable window resizing in windowed mode. | ||
/// </summary> | ||
[BepInPlugin(GUID, PluginName, PluginVersion)] | ||
public class EnableResize : BasePlugin | ||
{ | ||
internal const string GUID = "BepInEx.EnableResizeIL2CPP_net6"; | ||
internal const string PluginName = "Enable Resize"; | ||
internal const string PluginVersion = "0.7"; | ||
|
||
//Game Object shared between all BepInExUtility plugins | ||
public GameObject BepInExUtility; | ||
|
||
internal static ConfigEntry<bool> ConfigEnableResize { get; private set; } | ||
|
||
public override void Load() | ||
{ | ||
ConfigEnableResize = Config.Bind("Config", "Enable Resize", true, "Whether to allow the game window to be resized."); | ||
|
||
//IL2CPP don't automatically inherits Monobehavior, so needs to add separatelly | ||
ClassInjector.RegisterTypeInIl2Cpp<EnableResizeComponent>(); | ||
|
||
BepInExUtility = GameObject.Find("BepInExUtility"); | ||
if (BepInExUtility == null) | ||
{ | ||
BepInExUtility = new GameObject("BepInExUtility"); | ||
GameObject.DontDestroyOnLoad(BepInExUtility); | ||
BepInExUtility.hideFlags = HideFlags.HideAndDontSave; | ||
BepInExUtility.AddComponent<EnableResizeComponent>(); | ||
} | ||
else BepInExUtility.AddComponent<EnableResizeComponent>(); | ||
} | ||
} | ||
|
||
public class EnableResizeComponent : MonoBehaviour | ||
{ | ||
//Got this from BepInEx Discord pinned messages | ||
public EnableResizeComponent(IntPtr handle) : base(handle) { } | ||
|
||
|
||
//MonoBehaviour code starts here | ||
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam); | ||
|
||
[DllImport("user32.dll", SetLastError = true)] | ||
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); | ||
|
||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount); | ||
|
||
[DllImport("user32.dll")] | ||
public static extern int GetWindowLong(IntPtr hWnd, int nIndex); | ||
|
||
[DllImport("user32.dll")] | ||
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); | ||
|
||
// Almost the same: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptra | ||
private const int GWL_STYLE = -16; | ||
|
||
// https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles | ||
private const int WS_CAPTION = 0XC00000; | ||
private const int WS_MAXIMIZEBOX = 0x10000; | ||
private const int WS_MINIMIZEBOX = 0x20000; | ||
private const int WS_SYSMENU = 0x80000; | ||
private const int WS_THICKFRAME = 0x40000; | ||
|
||
private const string GET_CLASS_NAME_MAGIC = "UnityWndClass"; | ||
private IntPtr WindowHandle = IntPtr.Zero; | ||
|
||
private int windowStyle = 0; | ||
private bool fullScreen = false; | ||
private int borderlessStyle = 1; | ||
private const int borderlessMask = WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME; | ||
private int resizableStyle = 1; | ||
private const int resizableMask = WS_THICKFRAME | WS_MAXIMIZEBOX; | ||
|
||
private WaitForSecondsRealtime oneSecond = new WaitForSecondsRealtime(1f); | ||
private bool isInitialized = false; | ||
|
||
internal void Awake() | ||
{ | ||
EnableResize.ConfigEnableResize.SettingChanged += (sender, args) => Initialize(); | ||
Initialize(); | ||
} | ||
|
||
private void Initialize() | ||
{ | ||
if (!EnableResize.ConfigEnableResize.Value) return; | ||
|
||
if (isInitialized) | ||
{ | ||
StartCoroutine(TestScreen().WrapToIl2Cpp()); | ||
return; | ||
} | ||
|
||
var pid = Process.GetCurrentProcess().Id; | ||
EnumWindows((w, param) => | ||
{ | ||
if (w == IntPtr.Zero) return true; | ||
if (GetWindowThreadProcessId(w, out uint lpdwProcessId) == 0) return true; | ||
if (lpdwProcessId != pid) return true; | ||
var cn = new StringBuilder(256); | ||
if (GetClassName(w, cn, cn.Capacity) == 0) return true; | ||
if (cn.ToString() != GET_CLASS_NAME_MAGIC) return true; | ||
WindowHandle = w; | ||
return false; | ||
}, IntPtr.Zero); | ||
|
||
if (WindowHandle == IntPtr.Zero) return; | ||
isInitialized = true; | ||
StartCoroutine(TestScreen().WrapToIl2Cpp()); | ||
} | ||
|
||
private IEnumerator TestScreen() | ||
{ | ||
while (true) | ||
{ | ||
if (!EnableResize.ConfigEnableResize.Value) yield break; | ||
|
||
fullScreen = Screen.fullScreen; | ||
windowStyle = GetWindowLong(WindowHandle, GWL_STYLE); | ||
|
||
// If zero, is in borderless mode | ||
borderlessStyle = windowStyle & borderlessMask; | ||
|
||
// if zero, is not resizable | ||
resizableStyle = windowStyle & resizableMask; | ||
|
||
if (resizableStyle == 0 && | ||
borderlessStyle != 0 && | ||
fullScreen == false) | ||
{ | ||
ResizeWindow(); | ||
} | ||
|
||
yield return oneSecond; | ||
} | ||
} | ||
|
||
private void ResizeWindow() | ||
{ | ||
if (fullScreen) return; | ||
if (borderlessStyle == 0) return; | ||
windowStyle = GetWindowLong(WindowHandle, GWL_STYLE); | ||
windowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX; | ||
SetWindowLong(WindowHandle, GWL_STYLE, windowStyle); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<OutputType>Library</OutputType> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.664" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="Il2Cppmscorlib"> | ||
<HintPath>..\IL2CPP_net6\Il2Cppmscorlib.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Il2CppSystem"> | ||
<HintPath>..\IL2CPP_net6\Il2CppSystem.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Il2CppSystem.Core"> | ||
<HintPath>..\IL2CPP_net6\Il2CppSystem.Core.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule"> | ||
<HintPath>..\IL2CPP_net6\UnityEngine.CoreModule.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> | ||
<Exec Command="xcopy "$(TargetPath)" "$(SolutionDir)bin\BepInEx\Plugins\" /s /i /y" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System.Reflection; | ||
using static BepInEx.EnableResize; | ||
|
||
[assembly: AssemblyTitle(GUID)] | ||
[assembly: AssemblyDescription(PluginName)] | ||
[assembly: AssemblyProduct(GUID)] | ||
[assembly: AssemblyVersion(PluginVersion)] | ||
[assembly: AssemblyFileVersion(PluginVersion)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.