Restrict too lower values to prevent possible client bugs

This commit is contained in:
Alibek Omarov (a1batross) 2017-09-28 23:40:33 +03:00
parent be71073e93
commit 5885a6ccd4

View file

@ -60,6 +60,8 @@ public class XashActivity extends Activity {
public static boolean fGDBSafe = false; public static boolean fGDBSafe = false;
public static float mScale = 0, mTouchScaleX = 1, mTouchScaleY = 1; public static float mScale = 0, mTouchScaleX = 1, mTouchScaleY = 1;
public static int mForceHeight = 0, mForceWidth = 0; public static int mForceHeight = 0, mForceWidth = 0;
public static int mMinHeight = 240, mMinWidth = 320; // hl1 support 320 width, but mods may not.
public static boolean bIsCstrike = false;
private static boolean mHasVibrator; private static boolean mHasVibrator;
private int mReturingWithResultCode = 0; private int mReturingWithResultCode = 0;
@ -158,7 +160,7 @@ public class XashActivity extends Activity {
{ {
String newBaseDir = resultData.getStringExtra( "GetPath" ); String newBaseDir = resultData.getStringExtra( "GetPath" );
setNewBasedir( newBaseDir ); setNewBasedir( newBaseDir );
setFolderAsk( false ); // don't ask on next run setFolderAsk( this, false ); // don't ask on next run
Log.v( TAG, "Got new basedir from FPicker: " + newBaseDir ); Log.v( TAG, "Got new basedir from FPicker: " + newBaseDir );
} }
} }
@ -291,9 +293,14 @@ public class XashActivity extends Activity {
} }
} }
public void setFolderAsk( Boolean b ) public static void setFolderAsk( Context ctx, Boolean b )
{ {
SharedPreferences.Editor editor = mPref.edit(); SharedPreferences pref = ctx.getSharedPreferences( "engine", 0 );
if( pref.getBoolean( "folderask", true ) == b )
return;
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean( "folderask", b ); editor.putBoolean( "folderask", b );
editor.commit(); editor.commit();
@ -353,7 +360,7 @@ public class XashActivity extends Activity {
public void onClick( DialogInterface dialog, int whichButton ) public void onClick( DialogInterface dialog, int whichButton )
{ {
XashActivity act = XashActivity.this; XashActivity act = XashActivity.this;
act.setFolderAsk( true ); act.setFolderAsk( XashActivity.this, true );
act.finish(); act.finish();
} }
}) })
@ -415,16 +422,24 @@ public class XashActivity extends Activity {
{ {
mForceWidth = mPref.getInt( "resolution_width", 854 ); mForceWidth = mPref.getInt( "resolution_width", 854 );
mForceHeight = mPref.getInt( "resolution_height", 480 ); mForceHeight = mPref.getInt( "resolution_height", 480 );
if( mForceWidth < 10 || mForceHeight < 10 ) if( mForceWidth < mMinWidth || mForceHeight < mMinHeight )
mForceWidth = mForceHeight = 0; mForceWidth = mForceHeight = 0;
} }
else else
{ {
mScale = mPref.getFloat( "resolution_scale", 1 ); mScale = mPref.getFloat( "resolution_scale", 1 );
}
if( mScale < 0.5 ) if( mScale < 0.5 )
mScale = 0; mScale = 0;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
if( (float)metrics.widthPixels / mScale < (float)mMinWidth ||
(float)metrics.heightPixels / mScale < (float)mMinHeight )
{
mScale = 0;
}
}
} }
if( sdk >= 5 ) if( sdk >= 5 )
@ -444,6 +459,14 @@ public class XashActivity extends Activity {
String basedir = getStringExtraFromIntent( intent, "basedir", mPref.getString( "basedir", "/sdcard/xash/" ) ); String basedir = getStringExtraFromIntent( intent, "basedir", mPref.getString( "basedir", "/sdcard/xash/" ) );
String gdbsafe = intent.getStringExtra( "gdbsafe" ); String gdbsafe = intent.getStringExtra( "gdbsafe" );
bIsCstrike = ( gamedir == "cstrike" || gamedir == "czero" );
if( gamedir != "valve" )
{
mMinWidth = 640;
mMinHeight = 480;
}
if( gdbsafe != null || Debug.isDebuggerConnected() ) if( gdbsafe != null || Debug.isDebuggerConnected() )
{ {
fGDBSafe = true; fGDBSafe = true;
@ -974,7 +997,7 @@ class EngineSurface extends SurfaceView implements SurfaceHolder.Callback, View.
public void surfaceChanged( SurfaceHolder holder, int format, int width, int height ) public void surfaceChanged( SurfaceHolder holder, int format, int width, int height )
{ {
Log.v( TAG, "surfaceChanged()" ); Log.v( TAG, "surfaceChanged()" );
if( ( XashActivity.mForceHeight!= 0 && XashActivity.mForceWidth!= 0 || XashActivity.mScale!= 0 ) && !resizing ) if( ( XashActivity.mForceHeight!= 0 && XashActivity.mForceWidth!= 0 || XashActivity.mScale != 0 ) && !resizing )
{ {
int newWidth, newHeight; int newWidth, newHeight;
resizing = true; resizing = true;
@ -995,6 +1018,9 @@ class EngineSurface extends SurfaceView implements SurfaceHolder.Callback, View.
return; return;
} }
// Android may force only-landscape app to portait during lock
// Just don't notify engine in that case
if( width > height || mEngThread == null )
XashActivity.onNativeResize( width, height ); XashActivity.onNativeResize( width, height );
// holder.setFixedSize( width / 2, height / 2 ); // holder.setFixedSize( width / 2, height / 2 );
// Now start up the C app thread // Now start up the C app thread