logo
Main

Forums

Downloads

Unreal-Netiquette

Donate for Oldunreal:
Donate

borderline

Links to our wiki:
Wiki

Walkthrough

Links

Tutorials

Unreal Reference

Usermaps

borderline

Contact us:
Submit News
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic [Ugly snippet]Disabling DEP (Read 773 times)
han
Global Moderator
Unreal Rendering Guru
Developer Team
*****
Offline


Oldunreal member

Posts: 564
Location: Germany
Joined: Dec 10th, 2014
Gender: Male
[Ugly snippet]Disabling DEP
Nov 6th, 2015 at 3:07pm
Print Post  
As Galaxy and Fire package choke when DEP is enable, and you have a custom launcher, you should try to disable it in case it is opt-out, or notify the user that he should turn off dep. I basically call this shortly after appInit() in my launchers. Code is ugly, and needs to be split up and rewritten.

Code
Select All
/*=============================================================================
	RevDEP.cpp: Revision DEP handling.
	Copyright 2015 Sebastian Kaufel. All Rights Reserved.

	Revision history:
		* Created by Sebastian Kaufel

	TODO:
		* Refactor code to some general purpose DEP functions instead
			of a large one.
=============================================================================*/

#include "windows.h"
#include "RevisionCorePrivate.h"

/*-----------------------------------------------------------------------------
	DEP. -- FIXME Add FreeLibrary !
-----------------------------------------------------------------------------*/

#ifndef LoadLibraryX
	#define LoadLibraryX(a)					TCHAR_CALL_OS(LoadLibraryW(a),LoadLibraryA(TCHAR_TO_ANSI(a)))
#endif

typedef BOOL (WINAPI *GetProcessDEPPolicyFunc)( HANDLE hProcess, LPDWORD lpFlags, PBOOL lpPermanent );
typedef BOOL (WINAPI *SetProcessDEPPolicyFunc)( DWORD dwFlags );

// Returns 1 if either DEP is/was disabled or it is probably not available at all.
// Just returns 0 after user confirmation (if Ask=1).
UBOOL appMitigateDEP( UBOOL Ask )
{
	// Load Kernel32.dll.
	HINSTANCE hInstance = LoadLibraryX(TEXT("Kernel32.dll"));
	if ( !hInstance )
	{
		debugf( NAME_Warning, TEXT("Failed to load library Kernel32.dll (%#x)."), GetLastError() );
		return 1;
	}

	// Load GetProcessDEPPolicy().
	GetProcessDEPPolicyFunc GetProcessDEPPolicy = (GetProcessDEPPolicyFunc)GetProcAddress( hInstance, "GetProcessDEPPolicy" );
	if ( !GetProcessDEPPolicy )
	{
		debugf( NAME_Warning, TEXT("Failed to load GetProcessDEPPolicy() out of library Kernel32.dll (%#x)."), GetLastError() );
		return 1;
	}

	// Load SetProcessDEPPolicy().
	SetProcessDEPPolicyFunc SetProcessDEPPolicy = (SetProcessDEPPolicyFunc)GetProcAddress( hInstance, "SetProcessDEPPolicy" );
	if ( !SetProcessDEPPolicy )
	{
		debugf( NAME_Warning, TEXT("Failed to load SetProcessDEPPolicy() out of library Kernel32.dll (%#x)."), GetLastError() );
		return 1;
	}

	DWORD Flags=0;
	BOOL Permanent=0;
	if ( !GetProcessDEPPolicy(GetCurrentProcess(),&Flags,&Permanent) )
	{
		debugf( NAME_Warning, TEXT("Failed to read process Data Execution Prevention policy (%#x)."), GetLastError() );
		return 1;
	}

	debugf( NAME_Init, TEXT("DEP Policy is %i:%i"), Flags, Permanent );

	// Notice user if things are bad.
	if ( Flags && Permanent )
	{
		if ( Ask )
			return !GWarn->YesNof( TEXT("Data Execution Prevention is enabled for this process and cannot be disabled. The game is likely to crash due to known incompatibilities. Would you like to exit the game now?") );
		else
			return 0;
	}

	// Nothing to do.
	if ( Flags==0 )
		return 1;

	// Try disabling DEP for this process in case system DEP policy is OptOut.
	if ( !SetProcessDEPPolicy(0) )
		debugf( NAME_Warning, TEXT("Failed to set process Data Execution Prevention policy (%#x)."), GetLastError() );

	if ( !GetProcessDEPPolicy(GetCurrentProcess(),&Flags,&Permanent) )
	{
		debugf( NAME_Warning, TEXT("Failed to read process Data Execution Prevention policy (%#x)."), GetLastError() );
		return 1;
	}

	debugf( NAME_Init, TEXT("DEP Policy changed to %i:%i"), Flags, Permanent );

	// Notice user if things are bad.
	if ( Flags )
	{
		if ( Ask )
			return !GWarn->YesNof( TEXT("Data Execution Prevention is enabled for this process and disabling failed. The game is likely to crash due to known incompatibilities. Would you like to exit the game now?") );
		else
			return 0;
	}

	return 1;
}

/*-----------------------------------------------------------------------------
	The end.
-----------------------------------------------------------------------------*/ 

  

HX on Mod DB. Revision on Steam.
Back to top
 
IP Logged
 
スマイル・ドラゴン
Betatester
Offline


『smile。。。』

Posts: 1236
Location: Independence, KS
Joined: Feb 10th, 2008
Gender: Male
Re: [Ugly snippet]Disabling DEP
Reply #1 - Dec 21st, 2015 at 12:11am
Print Post  
Forgive me for asking but, isn't there a ACT shim that accomplishes the same thing you're doing in your native code?
  

I am the dragon without a name.
rk-__-ght.: / κυνικός Δράκων / スマイル・ドラゴン / Draco Nihil
Back to top
IP Logged
 
han
Global Moderator
Unreal Rendering Guru
Developer Team
*****
Offline


Oldunreal member

Posts: 564
Location: Germany
Joined: Dec 10th, 2014
Gender: Male
Re: [Ugly snippet]Disabling DEP
Reply #2 - Dec 21st, 2015 at 8:25pm
Print Post  
スマイル・ドラゴン wrote on Dec 21st, 2015 at 12:11am:
Forgive me for asking but, isn't there a ACT shim that accomplishes the same thing you're doing in your native code?

I can remember seeing sth. like that in for Unreal.exe. However it seems to be not set for each ue1 game, however as I usually use a custom launcher for my projects with another executable name (mostly to also have distinct User.ini and Default.ini/DefUser.ini files), it is would not be affected by any ACT shim for the stock exectuable.
Despite that it puts out a warning if DEP is enforced by system settings.
  

HX on Mod DB. Revision on Steam.
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint
Bookmarks: del.icio.us Digg Facebook Google Google+ Linked in reddit StumbleUpon Twitter Yahoo