using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BorderlessWindow")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Press F7 to enable borderless window")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d2d866fd73d0e86b799bd7475b8582103b6a59b8")]
[assembly: AssemblyProduct("BorderlessWindow")]
[assembly: AssemblyTitle("BorderlessWindow")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace EnableBorderlessWindow
{
[BepInPlugin("com.parapcio.borderlesswindow", "Borderless_Window", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private bool isBorderless = false;
private const int GWL_STYLE = -16;
private const uint WS_BORDER = 8388608u;
private const uint WS_DLGFRAME = 4194304u;
private const uint WS_CAPTION = 12582912u;
private const uint WS_SYSMENU = 524288u;
private const uint WS_THICKFRAME = 262144u;
private const uint WS_MINIMIZEBOX = 131072u;
private const uint WS_MAXIMIZEBOX = 65536u;
private const int SWP_SHOWWINDOW = 64;
private const int SWP_FRAMECHANGED = 32;
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
private static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
private void Awake()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
Object.DontDestroyOnLoad((Object)(object)this);
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"Borderless Window Plugin loaded");
new Harmony("com.parapcio.borderlesswindow").PatchAll();
}
private void Update()
{
if (((ButtonControl)Keyboard.current.f7Key).wasPressedThisFrame)
{
ToggleBorderlessWindowed();
}
}
private void ToggleBorderlessWindowed()
{
IntPtr activeWindow = GetActiveWindow();
if (!isBorderless)
{
uint windowLong = GetWindowLong(activeWindow, -16);
windowLong &= 0xFF30FFFFu;
SetWindowLong(activeWindow, -16, windowLong);
int systemWidth = Display.main.systemWidth;
int systemHeight = Display.main.systemHeight;
SetWindowPos(activeWindow, 0, 0, 0, systemWidth, systemHeight, 96u);
Log.LogInfo((object)"borderless window enabled");
isBorderless = true;
}
else
{
uint windowLong2 = GetWindowLong(activeWindow, -16);
windowLong2 |= 0xCF0000u;
SetWindowLong(activeWindow, -16, windowLong2);
int systemWidth2 = Display.main.systemWidth;
int systemHeight2 = Display.main.systemHeight;
int x = (Display.main.systemWidth - systemWidth2) / 2;
int y = (Display.main.systemHeight - systemHeight2) / 2;
SetWindowPos(activeWindow, 0, x, y, systemWidth2, systemHeight2, 96u);
Log.LogInfo((object)"windowed mode restored");
isBorderless = false;
}
}
}
}