Skip to content

Commit 7f0df95

Browse files
committed
fullscreen transitions fix, not yet tested
1 parent 1e7348c commit 7f0df95

4 files changed

Lines changed: 181 additions & 79 deletions

File tree

FlashpointSecurePlayer/FlashpointProxy.cs

Lines changed: 80 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ private static void GetSystemProxy(ref INTERNET_PER_CONN_OPTION_LIST internetPer
101101

102102
// allocate a block of memory of the options
103103
internetPerConnOptionList.pOptions = Marshal.AllocCoTaskMem(Marshal.SizeOf(internetPerConnOptionListOptions[0]) + Marshal.SizeOf(internetPerConnOptionListOptions[1]));
104+
104105
IntPtr internetPerConnOptionPointer = internetPerConnOptionList.pOptions;
105106

106107
// marshal data from a managed object to unmanaged memory
107-
for (int i = 0;i < internetPerConnOptionListOptions.Length;i++) {
108+
for (int i = 0; i < internetPerConnOptionListOptions.Length; i++) {
108109
Marshal.StructureToPtr(internetPerConnOptionListOptions[i], internetPerConnOptionPointer, false);
109110
internetPerConnOptionPointer = (IntPtr)((int)internetPerConnOptionPointer + Marshal.SizeOf(internetPerConnOptionListOptions[i]));
110111
}
@@ -121,7 +122,7 @@ private static void GetSystemProxy(ref INTERNET_PER_CONN_OPTION_LIST internetPer
121122

122123
// query internet options
123124
bool result = InternetQueryOption(IntPtr.Zero, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, ref internetPerConnOptionList, ref internetPerConnOptionListSize);
124-
125+
125126
if (!result) {
126127
throw new FlashpointProxyException("Could not query the Internet Options.");
127128
}
@@ -158,44 +159,50 @@ public static void Enable(string proxyServer) {
158159

159160
// allocate memory for the INTERNET_PER_CONN_OPTION_LIST Options
160161
internetPerConnOptionList.pOptions = Marshal.AllocCoTaskMem(Marshal.SizeOf(internetPerConnOptionListOptions[0]) + Marshal.SizeOf(internetPerConnOptionListOptions[1]));
161-
IntPtr internetPerConnOptionListOptionPointer = internetPerConnOptionList.pOptions;
162-
163-
// marshal data from a managed object to unmanaged memory
164-
for (int i = 0;i < internetPerConnOptionListOptions.Length;i++) {
165-
Marshal.StructureToPtr(internetPerConnOptionListOptions[i], internetPerConnOptionListOptionPointer, false);
166-
internetPerConnOptionListOptionPointer = (IntPtr)((long)internetPerConnOptionListOptionPointer + Marshal.SizeOf(internetPerConnOptionListOptions[i]));
167-
}
168-
169-
// fill the internetPerConnOptionList structure
170-
internetPerConnOptionList.dwSize = (uint)Marshal.SizeOf(internetPerConnOptionList);
171-
172-
// NULL == LAN, otherwise connectoid name
173-
internetPerConnOptionList.pszConnection = IntPtr.Zero;
174-
175-
// set two options
176-
internetPerConnOptionList.dwOptionCount = (uint)internetPerConnOptionListOptions.Length;
177-
internetPerConnOptionList.dwOptionError = 0;
178-
179-
// allocate memory for the INTERNET_PER_CONN_OPTION_LIST
180-
IntPtr internetPerConnOptionListPointer = Marshal.AllocCoTaskMem((int)internetPerConnOptionListSize);
181-
182-
// marshal data from a managed object to unmanaged memory
183-
Marshal.StructureToPtr(internetPerConnOptionList, internetPerConnOptionListPointer, true);
184162

185-
// set the options on the connection
186-
bool result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, internetPerConnOptionListPointer, internetPerConnOptionListSize);
187-
188-
// free the allocated memory
189-
Marshal.FreeCoTaskMem(internetPerConnOptionList.pOptions);
190-
Marshal.FreeCoTaskMem(internetPerConnOptionListPointer);
191-
192-
if (!InternetCloseHandle(internetHandle)) {
193-
throw new FlashpointProxyException("Could not close the Internet Handle.");
194-
}
195-
196-
// throw an exception if this operation failed
197-
if (!result) {
198-
throw new FlashpointProxyException("Could not set the Internet Options.");
163+
try {
164+
IntPtr internetPerConnOptionListOptionPointer = internetPerConnOptionList.pOptions;
165+
166+
// marshal data from a managed object to unmanaged memory
167+
for (int i = 0; i < internetPerConnOptionListOptions.Length; i++) {
168+
Marshal.StructureToPtr(internetPerConnOptionListOptions[i], internetPerConnOptionListOptionPointer, false);
169+
internetPerConnOptionListOptionPointer = (IntPtr)((long)internetPerConnOptionListOptionPointer + Marshal.SizeOf(internetPerConnOptionListOptions[i]));
170+
}
171+
172+
// fill the internetPerConnOptionList structure
173+
internetPerConnOptionList.dwSize = (uint)Marshal.SizeOf(internetPerConnOptionList);
174+
175+
// NULL == LAN, otherwise connectoid name
176+
internetPerConnOptionList.pszConnection = IntPtr.Zero;
177+
178+
// set two options
179+
internetPerConnOptionList.dwOptionCount = (uint)internetPerConnOptionListOptions.Length;
180+
internetPerConnOptionList.dwOptionError = 0;
181+
182+
// allocate memory for the INTERNET_PER_CONN_OPTION_LIST
183+
IntPtr internetPerConnOptionListPointer = Marshal.AllocCoTaskMem((int)internetPerConnOptionListSize);
184+
185+
try {
186+
// marshal data from a managed object to unmanaged memory
187+
Marshal.StructureToPtr(internetPerConnOptionList, internetPerConnOptionListPointer, true);
188+
189+
// set the options on the connection
190+
bool result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, internetPerConnOptionListPointer, internetPerConnOptionListSize);
191+
192+
if (!InternetCloseHandle(internetHandle)) {
193+
throw new FlashpointProxyException("Could not close the Internet Handle.");
194+
}
195+
196+
// throw an exception if this operation failed
197+
if (!result) {
198+
throw new FlashpointProxyException("Could not set the Internet Options.");
199+
}
200+
} finally {
201+
// free the allocated memory
202+
Marshal.FreeCoTaskMem(internetPerConnOptionListPointer);
203+
}
204+
} finally {
205+
Marshal.FreeCoTaskMem(internetPerConnOptionList.pOptions);
199206
}
200207
}
201208

@@ -216,35 +223,40 @@ public static void Disable() {
216223

217224
GetSystemProxy(ref internetPerConnOptionList, ref internetPerConnOptionListOptions);
218225

219-
// allocate memory
220-
IntPtr internetPerConnOptionListPointer = Marshal.AllocCoTaskMem((int)internetPerConnOptionListSize);
221-
222-
// convert structure to IntPtr
223-
Marshal.StructureToPtr(internetPerConnOptionList, internetPerConnOptionListPointer, true);
224-
225-
// set internet options
226-
bool result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, internetPerConnOptionListPointer, internetPerConnOptionListSize);
227-
228-
// free the allocated memory
229-
Marshal.FreeCoTaskMem(internetPerConnOptionList.pOptions);
230-
Marshal.FreeCoTaskMem(internetPerConnOptionListPointer);
231-
232-
// notify the system that the registry settings have been changed and cause
233-
// the proxy data to be reread from the registry for a handle
234-
if (result) {
235-
result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
236-
}
237-
238-
if (result) {
239-
result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
240-
}
241-
242-
if (!InternetCloseHandle(internetHandle)) {
243-
throw new FlashpointProxyException("Could not close the Internet Handle.");
244-
}
245-
246-
if (!result) {
247-
throw new FlashpointProxyException("Could not set the Internet Options.");
226+
try {
227+
// allocate memory
228+
IntPtr internetPerConnOptionListPointer = Marshal.AllocCoTaskMem((int)internetPerConnOptionListSize);
229+
230+
try {
231+
// convert structure to IntPtr
232+
Marshal.StructureToPtr(internetPerConnOptionList, internetPerConnOptionListPointer, true);
233+
234+
// set internet options
235+
bool result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, internetPerConnOptionListPointer, internetPerConnOptionListSize);
236+
237+
// notify the system that the registry settings have been changed and cause
238+
// the proxy data to be reread from the registry for a handle
239+
if (result) {
240+
result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
241+
}
242+
243+
if (result) {
244+
result = InternetSetOption(internetHandle, INTERNET_OPTION.INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);
245+
}
246+
247+
if (!InternetCloseHandle(internetHandle)) {
248+
throw new FlashpointProxyException("Could not close the Internet Handle.");
249+
}
250+
251+
if (!result) {
252+
throw new FlashpointProxyException("Could not set the Internet Options.");
253+
}
254+
} finally {
255+
// free the allocated memory
256+
Marshal.FreeCoTaskMem(internetPerConnOptionListPointer);
257+
}
258+
} finally {
259+
Marshal.FreeCoTaskMem(internetPerConnOptionList.pOptions);
248260
}
249261
}
250262
}

FlashpointSecurePlayer/ProcessSync.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,23 @@ public static void Start(Process process = null) {
125125
int jobobjectExtendedLimitInformationSize = Marshal.SizeOf(typeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
126126
IntPtr jobobjectExtendedLimitInformationPointer = Marshal.AllocHGlobal(jobobjectExtendedLimitInformationSize);
127127

128-
Marshal.StructureToPtr(jobobjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, false);
128+
try {
129+
Marshal.StructureToPtr(jobobjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, false);
129130

130-
bool result = SetInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, (uint)jobobjectExtendedLimitInformationSize);
131+
bool result = SetInformationJobObject(jobHandle, JOBOBJECTINFOCLASS.JobObjectExtendedLimitInformation, jobobjectExtendedLimitInformationPointer, (uint)jobobjectExtendedLimitInformationSize);
131132

132-
Marshal.FreeHGlobal(jobobjectExtendedLimitInformationPointer);
133+
if (process == null) {
134+
process = Process.GetCurrentProcess();
135+
}
133136

134-
if (process == null) {
135-
process = Process.GetCurrentProcess();
136-
}
137+
if (!result || !AssignProcessToJobObject(jobHandle, process.Handle)) {
138+
throw new JobObjectException("Could not set the Job Object Information or assign the Process to the Job Object.");
139+
}
137140

138-
if (!result || !AssignProcessToJobObject(jobHandle, process.Handle)) {
139-
throw new JobObjectException("Could not set the Job Object Information or assign the Process to the Job Object.");
141+
Started = true;
142+
} finally {
143+
Marshal.FreeHGlobal(jobobjectExtendedLimitInformationPointer);
140144
}
141-
142-
Started = true;
143145
}
144146
}
145147
}

FlashpointSecurePlayer/Shared.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,40 @@ public struct MSLLHOOKSTRUCT {
317317
[return: MarshalAs(UnmanagedType.Bool)]
318318
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
319319

320+
public enum DWMWINDOWATTRIBUTE : uint {
321+
DWMWA_NCRENDERING_ENABLED,
322+
DWMWA_NCRENDERING_POLICY,
323+
DWMWA_TRANSITIONS_FORCEDISABLED,
324+
DWMWA_ALLOW_NCPAINT,
325+
DWMWA_CAPTION_BUTTON_BOUNDS,
326+
DWMWA_NONCLIENT_RTL_LAYOUT,
327+
DWMWA_FORCE_ICONIC_REPRESENTATION,
328+
DWMWA_FLIP3D_POLICY,
329+
DWMWA_EXTENDED_FRAME_BOUNDS,
330+
DWMWA_HAS_ICONIC_BITMAP,
331+
DWMWA_DISALLOW_PEEK,
332+
DWMWA_EXCLUDED_FROM_PEEK,
333+
DWMWA_CLOAK,
334+
DWMWA_CLOAKED,
335+
DWMWA_FREEZE_REPRESENTATION,
336+
DWMWA_PASSIVE_UPDATE_MODE,
337+
DWMWA_USE_HOSTBACKDROPBRUSH,
338+
DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
339+
DWMWA_WINDOW_CORNER_PREFERENCE = 33,
340+
DWMWA_BORDER_COLOR,
341+
DWMWA_CAPTION_COLOR,
342+
DWMWA_TEXT_COLOR,
343+
DWMWA_VISIBLE_FRAME_BORDER_THICKNESS,
344+
DWMWA_SYSTEMBACKDROP_TYPE,
345+
DWMWA_LAST
346+
}
347+
348+
[DllImport("DWMAPI.DLL")]
349+
public static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, IntPtr pvAttribute, uint cbAttribute);
350+
351+
[DllImport("DWMAPI.DLL")]
352+
public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, IntPtr pvAttribute, uint cbAttribute);
353+
320354
[StructLayout(LayoutKind.Sequential)]
321355
public struct SECURITY_ATTRIBUTES {
322356
public uint nLength;

FlashpointSecurePlayer/WebBrowserMode.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Drawing;
66
using System.IO;
77
using System.Linq;
8+
using System.Runtime.InteropServices;
89
using System.Security.Permissions;
910
using System.Text;
1011
using System.Windows.Forms;
@@ -55,6 +56,35 @@ private IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam) {
5556
return CallNextHookEx(mouseHook, nCode, wParam, lParam);
5657
}
5758

59+
private bool TransitionsForceDisabled {
60+
get {
61+
int attributeValueSize = Marshal.SizeOf(typeof(int));
62+
IntPtr attributeValuePointer = Marshal.AllocHGlobal(attributeValueSize);
63+
64+
try {
65+
DwmGetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, attributeValuePointer, (uint)attributeValueSize);
66+
return (Marshal.ReadInt32(attributeValuePointer, 0) != 0) ? true : false;
67+
} finally {
68+
Marshal.FreeHGlobal(attributeValuePointer);
69+
}
70+
}
71+
72+
set {
73+
int attributeValue = value ? 1 : 0;
74+
75+
int attributeValueSize = Marshal.SizeOf(attributeValue);
76+
IntPtr attributeValuePointer = Marshal.AllocHGlobal(attributeValueSize);
77+
78+
try {
79+
Marshal.WriteInt32(attributeValuePointer, 0, attributeValue);
80+
81+
DwmSetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, attributeValuePointer, (uint)attributeValueSize);
82+
} finally {
83+
Marshal.FreeHGlobal(attributeValuePointer);
84+
}
85+
}
86+
}
87+
5888
private const int FULLSCREEN_EXIT_LABEL_TIMER_TIME = 2500;
5989

6090
private System.Windows.Forms.Timer exitFullscreenLabelTimer = null;
@@ -121,6 +151,12 @@ public bool Fullscreen {
121151
closableWebBrowserLocation = closableWebBrowser.Location;
122152
closableWebBrowserSize = closableWebBrowser.Size;
123153

154+
try {
155+
TransitionsForceDisabled = true;
156+
} catch {
157+
// Fail silently.
158+
}
159+
124160
// need to do this first to have an effect if starting maximized
125161
WindowState = FormWindowState.Normal;
126162
// disable resizing
@@ -145,7 +181,13 @@ public bool Fullscreen {
145181

146182
// commit by bringing the window to the front
147183
BringToFront();
148-
} else {
184+
185+
try {
186+
TransitionsForceDisabled = false;
187+
} catch {
188+
// Fail silently.
189+
}
190+
} else {
149191
// hide "Press F11 to exit fullscreen" label
150192
ExitFullscreenLabelTimer = false;
151193

@@ -156,6 +198,12 @@ public bool Fullscreen {
156198
}
157199
}
158200

201+
try {
202+
TransitionsForceDisabled = true;
203+
} catch {
204+
// Fail silently.
205+
}
206+
159207
// need to do this first to reset the window to its former size
160208
FormBorderStyle = FormBorderStyle.Sizable;
161209
// exit fullscreen
@@ -178,6 +226,12 @@ public bool Fullscreen {
178226

179227
// commit by bringing the window to the front
180228
BringToFront();
229+
230+
try {
231+
TransitionsForceDisabled = false;
232+
} catch {
233+
// Fail silently.
234+
}
181235
}
182236
}
183237
}

0 commit comments

Comments
 (0)