Skip to content

Commit 00c5c2a

Browse files
authored
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
1 parent 11fb5dc commit 00c5c2a

38 files changed

+952
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using BepInEx.Unity.IL2CPP;
3+
using Il2CppInterop.Runtime.Injection;
4+
using UnityEngine;
5+
using Input = UnityEngine.Input;
6+
using KeyCode = UnityEngine.KeyCode;
7+
8+
namespace BepInEx
9+
{
10+
/// <summary>
11+
/// Allow toggling full screen with alt+enter in games where that has been disabled
12+
/// </summary>
13+
[BepInPlugin(GUID, PluginName, PluginVersion)]
14+
public class EnableFullScreenToggle : BasePlugin
15+
{
16+
internal const string GUID = "BepInEx.EnableFullScreenToggleIL2CPP_net6";
17+
internal const string PluginName = "Enable Full Screen Toggle";
18+
internal const string PluginVersion = "0.7";
19+
20+
//Game Object shared between all BepInExUtility plugins
21+
public GameObject BepInExUtility;
22+
23+
public override void Load()
24+
{
25+
//IL2CPP don't automatically inherits Monobehavior, so needs to add separatelly
26+
ClassInjector.RegisterTypeInIl2Cpp<FullScreenToggleComponent>();
27+
28+
BepInExUtility = GameObject.Find("BepInExUtility");
29+
30+
if (BepInExUtility == null)
31+
{
32+
BepInExUtility = new GameObject("BepInExUtility");
33+
GameObject.DontDestroyOnLoad(BepInExUtility);
34+
BepInExUtility.hideFlags = HideFlags.HideAndDontSave;
35+
BepInExUtility.AddComponent<FullScreenToggleComponent>();
36+
}
37+
else BepInExUtility.AddComponent<FullScreenToggleComponent>();
38+
}
39+
}
40+
41+
public class FullScreenToggleComponent : MonoBehaviour
42+
{
43+
//Got this from BepInEx Discord pinned messages
44+
public FullScreenToggleComponent(IntPtr handle) : base(handle) { }
45+
46+
internal void Update()
47+
{
48+
if ((Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt)) && (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)))
49+
//This section of code is never reached on Unity builds where full screen can be toggled, it seems
50+
//We can safely toggle full screen without risk of it being toggled twice
51+
Screen.fullScreen = !Screen.fullScreen;
52+
}
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<OutputType>Library</OutputType>
5+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.664" />
9+
</ItemGroup>
10+
<ItemGroup>
11+
<Reference Include="Il2Cppmscorlib">
12+
<HintPath>..\IL2CPP_net6\Il2Cppmscorlib.dll</HintPath>
13+
</Reference>
14+
<Reference Include="Il2CppSystem">
15+
<HintPath>..\IL2CPP_net6\Il2CppSystem.dll</HintPath>
16+
</Reference>
17+
<Reference Include="Il2CppSystem.Core">
18+
<HintPath>..\IL2CPP_net6\Il2CppSystem.Core.dll</HintPath>
19+
</Reference>
20+
<Reference Include="UnityEngine">
21+
<HintPath>..\IL2CPP_net6\UnityEngine.dll</HintPath>
22+
</Reference>
23+
<Reference Include="UnityEngine.AudioModule">
24+
<HintPath>..\IL2CPP_net6\UnityEngine.AudioModule.dll</HintPath>
25+
</Reference>
26+
<Reference Include="UnityEngine.CoreModule">
27+
<HintPath>..\IL2CPP_net6\UnityEngine.CoreModule.dll</HintPath>
28+
</Reference>
29+
<Reference Include="UnityEngine.IMGUIModule">
30+
<HintPath>..\IL2CPP_net6\UnityEngine.IMGUIModule.dll</HintPath>
31+
</Reference>
32+
<Reference Include="UnityEngine.InputLegacyModule">
33+
<HintPath>..\IL2CPP_net6\UnityEngine.InputLegacyModule.dll</HintPath>
34+
</Reference>
35+
<Reference Include="UnityEngine.InputModule">
36+
<HintPath>..\IL2CPP_net6\UnityEngine.InputModule.dll</HintPath>
37+
</Reference>
38+
<Reference Include="UnityEngine.TextRenderingModule">
39+
<HintPath>..\IL2CPP_net6\UnityEngine.TextRenderingModule.dll</HintPath>
40+
</Reference>
41+
<Reference Include="UnityEngine.UI">
42+
<HintPath>..\IL2CPP_net6\UnityEngine.UI.dll</HintPath>
43+
</Reference>
44+
<Reference Include="UnityEngine.UIModule">
45+
<HintPath>..\IL2CPP_net6\UnityEngine.UIModule.dll</HintPath>
46+
</Reference>
47+
</ItemGroup>
48+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
49+
<Exec Command="xcopy &quot;$(TargetPath)&quot; &quot;$(SolutionDir)bin\BepInEx\Plugins\&quot; /s /i /y" />
50+
</Target>
51+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Reflection;
2+
using static BepInEx.EnableFullScreenToggle;
3+
4+
[assembly: AssemblyTitle(GUID)]
5+
[assembly: AssemblyDescription(PluginName)]
6+
[assembly: AssemblyProduct(GUID)]
7+
[assembly: AssemblyVersion(PluginVersion)]
8+
[assembly: AssemblyFileVersion(PluginVersion)]

EnableFullScreenToggleIL2CPP_netFm/EnableFullScreenToggleIL2CPP_netFm.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{F37EF379-2D98-469F-8CBF-EC995F54D7DF}</ProjectGuid>
7+
<ProjectGuid>{8AF94CAA-E027-4AA4-9EE9-87FB1FDF8275}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>EnableFullScreenToggleIL2CPP_netFm</RootNamespace>
+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
using System;
2+
using System.Collections;
3+
using System.Diagnostics;
4+
using System.Runtime.InteropServices;
5+
using System.Text;
6+
using BepInEx.Configuration;
7+
using BepInEx.Unity.IL2CPP;
8+
using BepInEx.Unity.IL2CPP.Utils.Collections;
9+
using Il2CppInterop.Runtime.Injection;
10+
using UnityEngine;
11+
12+
namespace BepInEx
13+
{
14+
/// <summary>
15+
/// Enable window resizing in windowed mode.
16+
/// </summary>
17+
[BepInPlugin(GUID, PluginName, PluginVersion)]
18+
public class EnableResize : BasePlugin
19+
{
20+
internal const string GUID = "BepInEx.EnableResizeIL2CPP_net6";
21+
internal const string PluginName = "Enable Resize";
22+
internal const string PluginVersion = "0.7";
23+
24+
//Game Object shared between all BepInExUtility plugins
25+
public GameObject BepInExUtility;
26+
27+
internal static ConfigEntry<bool> ConfigEnableResize { get; private set; }
28+
29+
public override void Load()
30+
{
31+
ConfigEnableResize = Config.Bind("Config", "Enable Resize", true, "Whether to allow the game window to be resized.");
32+
33+
//IL2CPP don't automatically inherits Monobehavior, so needs to add separatelly
34+
ClassInjector.RegisterTypeInIl2Cpp<EnableResizeComponent>();
35+
36+
BepInExUtility = GameObject.Find("BepInExUtility");
37+
if (BepInExUtility == null)
38+
{
39+
BepInExUtility = new GameObject("BepInExUtility");
40+
GameObject.DontDestroyOnLoad(BepInExUtility);
41+
BepInExUtility.hideFlags = HideFlags.HideAndDontSave;
42+
BepInExUtility.AddComponent<EnableResizeComponent>();
43+
}
44+
else BepInExUtility.AddComponent<EnableResizeComponent>();
45+
}
46+
}
47+
48+
public class EnableResizeComponent : MonoBehaviour
49+
{
50+
//Got this from BepInEx Discord pinned messages
51+
public EnableResizeComponent(IntPtr handle) : base(handle) { }
52+
53+
54+
//MonoBehaviour code starts here
55+
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
56+
57+
[DllImport("user32.dll")]
58+
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
59+
60+
[DllImport("user32.dll", SetLastError = true)]
61+
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
62+
63+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
64+
private static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
65+
66+
[DllImport("user32.dll")]
67+
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
68+
69+
[DllImport("user32.dll")]
70+
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
71+
72+
// Almost the same: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowlongptra
73+
private const int GWL_STYLE = -16;
74+
75+
// https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles
76+
private const int WS_CAPTION = 0XC00000;
77+
private const int WS_MAXIMIZEBOX = 0x10000;
78+
private const int WS_MINIMIZEBOX = 0x20000;
79+
private const int WS_SYSMENU = 0x80000;
80+
private const int WS_THICKFRAME = 0x40000;
81+
82+
private const string GET_CLASS_NAME_MAGIC = "UnityWndClass";
83+
private IntPtr WindowHandle = IntPtr.Zero;
84+
85+
private int windowStyle = 0;
86+
private bool fullScreen = false;
87+
private int borderlessStyle = 1;
88+
private const int borderlessMask = WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SYSMENU | WS_THICKFRAME;
89+
private int resizableStyle = 1;
90+
private const int resizableMask = WS_THICKFRAME | WS_MAXIMIZEBOX;
91+
92+
private WaitForSecondsRealtime oneSecond = new WaitForSecondsRealtime(1f);
93+
private bool isInitialized = false;
94+
95+
internal void Awake()
96+
{
97+
EnableResize.ConfigEnableResize.SettingChanged += (sender, args) => Initialize();
98+
Initialize();
99+
}
100+
101+
private void Initialize()
102+
{
103+
if (!EnableResize.ConfigEnableResize.Value) return;
104+
105+
if (isInitialized)
106+
{
107+
StartCoroutine(TestScreen().WrapToIl2Cpp());
108+
return;
109+
}
110+
111+
var pid = Process.GetCurrentProcess().Id;
112+
EnumWindows((w, param) =>
113+
{
114+
if (w == IntPtr.Zero) return true;
115+
if (GetWindowThreadProcessId(w, out uint lpdwProcessId) == 0) return true;
116+
if (lpdwProcessId != pid) return true;
117+
var cn = new StringBuilder(256);
118+
if (GetClassName(w, cn, cn.Capacity) == 0) return true;
119+
if (cn.ToString() != GET_CLASS_NAME_MAGIC) return true;
120+
WindowHandle = w;
121+
return false;
122+
}, IntPtr.Zero);
123+
124+
if (WindowHandle == IntPtr.Zero) return;
125+
isInitialized = true;
126+
StartCoroutine(TestScreen().WrapToIl2Cpp());
127+
}
128+
129+
private IEnumerator TestScreen()
130+
{
131+
while (true)
132+
{
133+
if (!EnableResize.ConfigEnableResize.Value) yield break;
134+
135+
fullScreen = Screen.fullScreen;
136+
windowStyle = GetWindowLong(WindowHandle, GWL_STYLE);
137+
138+
// If zero, is in borderless mode
139+
borderlessStyle = windowStyle & borderlessMask;
140+
141+
// if zero, is not resizable
142+
resizableStyle = windowStyle & resizableMask;
143+
144+
if (resizableStyle == 0 &&
145+
borderlessStyle != 0 &&
146+
fullScreen == false)
147+
{
148+
ResizeWindow();
149+
}
150+
151+
yield return oneSecond;
152+
}
153+
}
154+
155+
private void ResizeWindow()
156+
{
157+
if (fullScreen) return;
158+
if (borderlessStyle == 0) return;
159+
windowStyle = GetWindowLong(WindowHandle, GWL_STYLE);
160+
windowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
161+
SetWindowLong(WindowHandle, GWL_STYLE, windowStyle);
162+
}
163+
}
164+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net6.0</TargetFramework>
4+
<OutputType>Library</OutputType>
5+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.664" />
9+
</ItemGroup>
10+
<ItemGroup>
11+
<Reference Include="Il2Cppmscorlib">
12+
<HintPath>..\IL2CPP_net6\Il2Cppmscorlib.dll</HintPath>
13+
</Reference>
14+
<Reference Include="Il2CppSystem">
15+
<HintPath>..\IL2CPP_net6\Il2CppSystem.dll</HintPath>
16+
</Reference>
17+
<Reference Include="Il2CppSystem.Core">
18+
<HintPath>..\IL2CPP_net6\Il2CppSystem.Core.dll</HintPath>
19+
</Reference>
20+
<Reference Include="UnityEngine">
21+
<HintPath>..\IL2CPP_net6\UnityEngine.dll</HintPath>
22+
</Reference>
23+
<Reference Include="UnityEngine.CoreModule">
24+
<HintPath>..\IL2CPP_net6\UnityEngine.CoreModule.dll</HintPath>
25+
</Reference>
26+
</ItemGroup>
27+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
28+
<Exec Command="xcopy &quot;$(TargetPath)&quot; &quot;$(SolutionDir)bin\BepInEx\Plugins\&quot; /s /i /y" />
29+
</Target>
30+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System.Reflection;
2+
using static BepInEx.EnableResize;
3+
4+
[assembly: AssemblyTitle(GUID)]
5+
[assembly: AssemblyDescription(PluginName)]
6+
[assembly: AssemblyProduct(GUID)]
7+
[assembly: AssemblyVersion(PluginVersion)]
8+
[assembly: AssemblyFileVersion(PluginVersion)]

EnableResizeIL2CPP_netFm/EnableResizeIL2CPP_netFm.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{9921DE3B-DEF2-4470-BD8F-23F207128844}</ProjectGuid>
7+
<ProjectGuid>{3E576FAF-8682-44A3-BD1A-71B0924E9EEE}</ProjectGuid>
88
<OutputType>Library</OutputType>
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>EnableResizeIL2CPP_netFm</RootNamespace>

0 commit comments

Comments
 (0)