Announcement

Collapse
No announcement yet.

How to get available display resolutions without dllbind.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to get available display resolutions without dllbind.

    So, you want to populate your options menu dropdown with the supported display resolutions in UDK-2012-05 and later?

    Code:
    function GetSupportedResolutions()
    {
    	local array<string> TheStrings;
    	local string TempString;
    
    	TempString = class'WorldInfo'.static.GetWorldInfo().GetALocalPlayerController().ConsoleCommand("DUMPAVAILABLERESOLUTIONS", false);
    	ParseStringIntoArray(TempString, TheStrings, "\n", true);
    	for(i=0; i<TheStrings.Length; i++)
    	{
    		`log("Found"@TheStrings[i]);
    	}
    }
    The function is poorly named as this pseudocode isnt storing or returning anything currently as the vars are all local. Also probably needs some protection against accessed nones, although the PC and Viewport really should exist ;p Alter to taste, copypasta will not work.

    The convoluted Player Controller reference is because this is lifted from our GFxMoviePlayer object class. ConsoleCommand() has to be called on an actor in this instance- the movieplayer implementation doesnt seem to return anything to store.

    It appears that some entries are duplicated, perhaps due to colourdepth variations, but that info is not visible; so you should perhaps write a few lines to strip the array of duplicate references for now.

    Code:
    	for(i=TheStrings.Length-1; i >= 0; i--)
    	{
    		if(i>0 && TheStrings[i] == TheStrings[i-1])
    			TheStrings.Remove(i,1);
    	}
    To get the current viewport resolution and whether it's windowed

    Code:
    function GetCurrentResolution()
    {
    	local PlayerController PC;
    	local Vector2D VSize;
    	local bool bIsFullScreen;
    
    	PC = class'WorldInfo'.static.GetWorldInfo().GetALocalPlayerController();
    	LocalPlayer(PC.Player).ViewportClient.GetViewportSize(VSize);
    	`log("Current Resolution"@((int(VSize.X))$"x"$(int(VSize.Y)))));
    	bIsFullscreen = LocalPlayer(PC.Player).ViewportClient.IsFullScreenViewport();
    	`log("Fullscreen"@bIsFullscreen);
    }
    When you're ready to set the resolution, some form of

    Code:
    	//Fullscreen
    	PC.ConsoleCommand("setres"@TheStrings[n]$"f");
    	//Windowed
    	PC.ConsoleCommand("setres"@TheStrings[n]$"w");
    This might work in a build or two before 2012-05. In older builds, dumpavailableresolutions didnt store anything, I've not verified which; ymmv.

    (With thanks to nick_p (epic) and SolidSnake)

    #2
    Nice one, mister Jetfire. I saw someone attempt to use that console function without success, but I hadn't got around to experimenting with the later builds to test it. I'll update my tutorial with a link to here.

    Comment


      #3
      Yea, nick_p did a native code change to make it work for us. Sorry to obsolete your tutorial ;p

      Comment


        #4
        Originally posted by Jetfire View Post
        Yea, nick_p did a native code change to make it work for us. Sorry to obsolete your tutorial ;p
        It's progress. And for the better

        Comment


          #5
          Did they fix this as well for the other console commands that dumps all systemsettings?

          Comment


            #6
            No idea, probably not. Sounds more hassle than its worth any way- you can read any of those values from the config on demand, and pick and choose the ones you want, and not have to faff around mapping array entries to intended parameters. I certainly wouldnt recommend directly exposing ALL the vars to users in an options menu either?

            Comment


              #7
              Care to elaborate on "you can read any of those values from the config on demand", as far as I know you can only mirror them or use DLLBind to read those config properties from the ini yourself.

              No obviously :P

              [Edit]: I just tried it on "Scale Dump" and this is definitely working now! Sweet

              Comment


                #8
                My bad, seems not everything we want to get at is declared as config. Also getting at them via a class's default value (defprop values are set from the config when a class is loaded) means it probably wont pick up on runtime changes. Will get back if anything sensible drops out
                Scale Dump isnt writing to a string for me on 2012-05 :/

                Comment


                  #9
                  PS hivemind has verified that SCALE DUMP does indeed write properly to string in the 2012-07 build, doesn't in 05 we're currently on. Crisis averted. It seems that it's the only way to get those values aside from reading the .ini directly in dllbind'd library.

                  Comment


                    #10
                    Wow !!

                    Thanks a lot !

                    Comment


                      #11
                      wish i had saw this about 3 weeks ago, really needed some resolution options for my uni project. does this display the screen screen res X refresh rate? if not could it easily be added?

                      Comment


                        #12
                        It doesn't list refresh rates.

                        Comment


                          #13
                          I'm not sure if that's doable in UScript and if it isn't then DLLBind should be fine. In your case you'd want to access dmDisplayFrequency from the DEVMODE structure; here's a quick example
                          Code:
                          #include <stdio.h>
                          #include <windows.h>
                          #include <wchar.h>
                          
                          extern "C"
                          {
                          	__declspec( dllexport ) int RefreshRate()
                          	{
                          		DEVMODE __sScreen;
                          		memset( &__sScreen, 0, sizeof( __sScreen ) );
                          		if( !EnumDisplaySettings( NULL, 0, &__sScreen ) )
                          		{
                          			MessageBoxW( NULL, L"Could not get refresh rate.", L"Fail window", MB_ICONERROR );
                          			return -1;
                          		}
                          		wchar_t __cMessage[ 80 ];
                          		swprintf( __cMessage, 80, L"Current refresh rate: %i Hz", __sScreen.dmDisplayFrequency );
                          		MessageBoxW( NULL, __cMessage, L"Refresh-rate window.", MB_OK );
                          	}
                          }
                          Although I've used MessageBoxW - it isn't needed. If you don't want a message box then you can remove it.

                          Comment


                            #14
                            Originally posted by reinrag View Post
                            I'm not sure if that's doable in UScript and if it isn't then DLLBind should be fine. In your case you'd want to access dmDisplayFrequency from the DEVMODE structure; here's a quick example
                            Code:
                            #include <stdio.h>
                            #include <windows.h>
                            #include <wchar.h>
                            
                            extern "C"
                            {
                            	__declspec( dllexport ) int RefreshRate()
                            	{
                            		DEVMODE __sScreen;
                            		memset( &__sScreen, 0, sizeof( __sScreen ) );
                            		if( !EnumDisplaySettings( NULL, 0, &__sScreen ) )
                            		{
                            			MessageBoxW( NULL, L"Could not get refresh rate.", L"Fail window", MB_ICONERROR );
                            			return -1;
                            		}
                            		wchar_t __cMessage[ 80 ];
                            		swprintf( __cMessage, 80, L"Current refresh rate: %i Hz", __sScreen.dmDisplayFrequency );
                            		MessageBoxW( NULL, __cMessage, L"Refresh-rate window.", MB_OK );
                            	}
                            }
                            Although I've used MessageBoxW - it isn't needed. If you don't want a message box then you can remove it.
                            Thanks for you guys help.

                            Comment


                              #15
                              Thanks a lot for this !

                              Comment

                              Working...
                              X