Jump to content

Windows opening at the wrong position


Gurgarath

Recommended Posts

  • Forum Moderator
Hello!

Many people complained about a "7 pixel bug" on some clients. For example the client will open a few pixels too far from the left-side of the screen. Usually between 7 and 9 pixel on the right.

I still do not know why it happens for some people and not for other. I thought about a visual studio toolset, a screen configuration or whatever but it turns out to be harder to know why it actually happens, I also had only two people talking about this so I cannot get accurate data. Anyway, let's get started it's really easy.

The bug looks like this, take from the official client it looks like 1 or 2 pixels only. But it looks almost exactly like it at some moments.

First, make sure your metin2.cfg is correct and does not display a weird resolution (like 1913 * 1080).

BcbiMfXxP8V5POQotw34jLiw0bPDJde1APmVhG4Q

Then just add this small line in PythonApplication.cpp:

This is the hidden content, please

Right after this one:

AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

EDIT:

If you happen to have it on the second window as well, move the line under the bAnotherWindow check. Just like this:

Spoiler

unknown.png

And voilà, it's fixed. Don't hesistate to add or remove one pixel if needed.

It's really small and looks like a workaround but I did it really quickly. I didn't test this fix on clients / computers not having the actual bug. If it is a client issue it shouldn't cause any problems, if it's a computer issue, I might need more data to fine-tune the fix. Don't forget to share some data if you have.

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 95
  • Eyes 1
  • Facepalm 1
  • Think 1
  • Good 28
  • Love 5
  • Love 37

Gurgarath
coming soon

Link to comment
Share on other sites

1 hour ago, Gurgarath said:

Hello!

Many people complained about a "7 pixel bug" on some clients. For example the client will open a few pixels too far from the left-side of the screen. Usually between 7 and 9 pixel on the right.

I still do not know why it happens for some people and not for other. I thought about a visual studio toolset, a screen configuration or whatever but it turns out to be harder to know why it actually happens, I also had only two people talking about this so I cannot get accurate data. Anyway, let's get started it's really easy.

The bug looks

Hidden Content

  • Give reaction to this post to see the hidden content.

, take from the official client it looks like 1 or 2 pixels only. But it looks almost exactly like it at some moments.

 

First, make sure your metin2.cfg is correct and does not display a weird resolution (like 1913 * 1080).

BcbiMfXxP8V5POQotw34jLiw0bPDJde1APmVhG4Q

Then just add this small line in PythonApplication.cpp:

SetPosition(-8, 0);

Right after this one:

AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

And voilà, it's fixed. Don't hesistate to add or remove one pixel if needed.

It's really small and looks like a workaround but I did it really quickly. I didn't test this fix on clients / computers not having the actual bug. If it is a client issue it shouldn't cause any problems, if it's a computer issue, I might need more data to fine-tune the fix. Don't forget to share some data if you have.

And voilà it’s ok !

Edited by Metin2 Dev
Core X - External 2 Internal
  • Lmao 2

231343gifyalabi.gif

Link to comment
Share on other sites

  • Active Member

@ GurgarathThanks for trying to fix this problem, but after this fix I can see no difference and the client window is still not centered. Because something is changing the client resolution right after starting the client, so it couldn't be overwritten by editing the config.

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Forum Moderator
8 minutes ago, martysama0134 said:

8px is too much. I see 1px in the other monitor. I suggest you -7.

zmvMP5u.png

Thanks for your share but that's what I said, to adjust to your needs. At first I was going for 7 then needed 8, Haios needed 9 for example.

j9pC6pkmoJlXAAAAABJRU5ErkJggg.png

Also, you can add it into "bAnotherWindow" condition if you have the bug more than once with multiple clients.

unknown.png

 

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 2

Gurgarath
coming soon

Link to comment
Share on other sites

  • Active+ Member

Those ~5px are for the shadows if I'm not mistaken.

Also the ideea made by Ymir to open the client in two diferent position is stupid.

I consider opening the windowed client on the center it's the best solution:

		if (Windowed)
		{
			m_isWindowed = true;

			RECT rc;
			GetClientRect(&rc);
		
			int windowWidth = rc.right - rc.left;
			int windowHeight = (rc.bottom - rc.top);
		
			// 80 is the gap for the taskbar, you can increase it
			CMSApplication::SetPosition((GetScreenWidth() - windowWidth) / 2, (GetScreenHeight() - windowHeight - 80) / 2);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

 

  • Metin2 Dev 1
  • Good 1
  • Love 2
Link to comment
Share on other sites

  • Forum Moderator
On 9/20/2021 at 2:29 PM, Abel(Tiger) said:

Those ~5px are for the shadows if I'm not mistaken.

Also the ideea made by Ymir to open the client in two diferent position is stupid.

I consider opening the windowed client on the center it's the best solution:

		if (Windowed)
		{
			m_isWindowed = true;

			RECT rc;
			GetClientRect(&rc);
		
			int windowWidth = rc.right - rc.left;
			int windowHeight = (rc.bottom - rc.top);
		
			// 80 is the gap for the taskbar, you can increase it
			CMSApplication::SetPosition((GetScreenWidth() - windowWidth) / 2, (GetScreenHeight() - windowHeight - 80) / 2);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

 

I've talked about this with Intel and yeah, the whole check is clumsy, it works only for the second window and if you open it during a specific timestamp. However the fact that it opens at the opposite of the second one is an approach I could understand, but centering it would erase any clumsyness

On 9/20/2021 at 5:04 PM, Maze said:

how do I fix the second window position?

I personally had no issue with the second window, but here you are. Undo the original tutorial and do this (it will render the whole if useless though so you can as well remove it):

unknown.png

 

Edited by Metin2 Dev
Core X - External 2 Internal

Gurgarath
coming soon

Link to comment
Share on other sites

3 minutes ago, Gurgarath said:

I've talked about this with Intel and yeah, the whole check is clumsy, it works only for the second window and if you open it during a specific timestamp. However the fact that it opens at the opposite of the second one is an approach I could understand, but centering it would erase any clumsyness

I personally had no issue with the second window, but here you are. Undo the original tutorial and do this:

unknown.png

 

I have it like this, but only the first window is centered on me, the second keeps appearing further to the side

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Forum Moderator
12 minutes ago, Maze said:

I have it like this, but only the first window is centered on me, the second keeps appearing further to the side

Oh, yes, this isn't a bug this is a feature. Ymir did that on purpose. You can use @Abel(Tiger) fix for this, every window will open on the center of the screen (which is what most modern games do).

Gurgarath
coming soon

Link to comment
Share on other sites

  • Honorable Member
7 hours ago, Abel(Tiger) said:

Those ~5px are for the shadows if I'm not mistaken.

Also the ideea made by Ymir to open the client in two diferent position is stupid.

I consider opening the windowed client on the center it's the best solution:

		if (Windowed)
		{
			m_isWindowed = true;

			RECT rc;
			GetClientRect(&rc);
		
			int windowWidth = rc.right - rc.left;
			int windowHeight = (rc.bottom - rc.top);
		
			// 80 is the gap for the taskbar, you can increase it
			CMSApplication::SetPosition((GetScreenWidth() - windowWidth) / 2, (GetScreenHeight() - windowHeight - 80) / 2);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

 

I used GetWindowRect to calculate the dropshadow area automatically:

		AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

		if (Windowed)
		{
			m_isWindowed = true;
			RECT rc{};
			GetClientRect(&rc);
			auto windowWidth = rc.right - rc.left;
			auto windowHeight = (rc.bottom - rc.top);
			//TraceError("windowWidth %d == %d windowHeight %d == %d", windowWidth, m_pySystem.GetWidth(), windowHeight, m_pySystem.GetHeight());
			RECT rc2{};
			GetWindowRect(&rc2);
			auto windowWidth2 = rc2.right - rc2.left;
			auto windowHeight2 = (rc2.bottom - rc2.top);
			//TraceError("windowWidth2 %d windowHeight2 %d", windowWidth2, windowHeight2);
			auto windowWidthDiff = windowWidth2 - windowWidth;
			auto windowHeightDiff = windowHeight2 - windowHeight;
			//TraceError("windowWidthDiff %d windowHeightDiff %d", windowWidthDiff, windowHeightDiff);
			//TraceError("GetLastError %d", ::GetLastError());
			constexpr auto taskbarSize = 80;
			auto dropshadowSize = (windowWidthDiff / 2 != 0) ? (windowWidthDiff / 2 - 1) : 0;
			CMSApplication::SetPosition(((GetScreenWidth() - windowWidth) / 2) - dropshadowSize, (GetScreenHeight() - windowHeight - taskbarSize) / 2);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

This one is for 1920x1080 res

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrect

Old way with second window:

		AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

		if (Windowed)
		{
			m_isWindowed = true;
			RECT rc{};
			GetClientRect(&rc);
			auto windowWidth = rc.right - rc.left;
			auto windowHeight = (rc.bottom - rc.top);
			//TraceError("windowWidth %d == %d windowHeight %d == %d", windowWidth, m_pySystem.GetWidth(), windowHeight, m_pySystem.GetHeight());
			RECT rc2{};
			GetWindowRect(&rc2);
			auto windowWidth2 = rc2.right - rc2.left;
			auto windowHeight2 = (rc2.bottom - rc2.top);
			//TraceError("windowWidth2 %d windowHeight2 %d", windowWidth2, windowHeight2);
			auto windowWidthDiff = windowWidth2 - windowWidth;
			auto windowHeightDiff = windowHeight2 - windowHeight;
			//TraceError("windowWidthDiff %d windowHeightDiff %d", windowWidthDiff, windowHeightDiff);
			//TraceError("GetLastError %d", ::GetLastError());
			auto dropshadowSize = (windowWidthDiff / 2 != 0) ? (windowWidthDiff / 2 - 1) : 0;
#ifdef ENABLE_CENTERED_CLIENT_WINDOW
			constexpr auto taskbarSize = 80;
			CMSApplication::SetPosition(((GetScreenWidth() - windowWidth) / 2) - dropshadowSize, (GetScreenHeight() - windowHeight - taskbarSize) / 2);
#else
			constexpr auto taskbarSize = 73;
			constexpr auto titlebarSize = 10;
			if (bAnotherWindow)
				CMSApplication::SetPosition(GetScreenWidth() - windowWidth - dropshadowSize, GetScreenHeight() - windowHeight - taskbarSize);
			else
				SetPosition(-dropshadowSize, -titlebarSize);
#endif
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

 

Edited by martysama0134
  • Metin2 Dev 18
  • Good 6
  • Love 7
Link to comment
Share on other sites

  • Active Member

I don't know why it happens, but my metin2.cfg is not able to save the 1920x1080 resolution. Everytime when I start the client, the metin2.cfg is overwritten by 1920x1010 resolution. Can someone tell me why it happens or how to make it starting with the saved resolution? Thanks

I did it like this to make the window centered:

Spoiler
		if (Windowed)
		{
			m_isWindowed = true;
			RECT rc{};
			GetClientRect(&rc);
			auto windowWidth = rc.right - rc.left;
			auto windowHeight = (rc.bottom - rc.top);
			//TraceError("windowWidth %d == %d windowHeight %d == %d", windowWidth, m_pySystem.GetWidth(), windowHeight, m_pySystem.GetHeight());
			RECT rc2{};
			GetWindowRect(&rc2);
			auto windowWidth2 = rc2.right - rc2.left;
			auto windowHeight2 = (rc2.bottom - rc2.top);
			//TraceError("windowWidth2 %d windowHeight2 %d", windowWidth2, windowHeight2);
			auto windowWidthDiff = windowWidth2 - windowWidth;
			auto windowHeightDiff = windowHeight2 - windowHeight;
			//TraceError("windowWidthDiff %d windowHeightDiff %d", windowWidthDiff, windowHeightDiff);
			//TraceError("GetLastError %d", ::GetLastError());
			constexpr auto taskbarSize = 73;
			auto dropshadowSize = (windowWidthDiff / 2 != 0) ? (windowWidthDiff / 2 - 1) : 0;
			CMSApplication::SetPosition((((GetScreenWidth() - windowWidth) / 2)-1) - dropshadowSize, (GetScreenHeight() - windowHeight - taskbarSize) / 2);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

 

But I'm little bit confused about the 1920x1010 resolution in metin2.cfg everytime when I start the client.

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Management
25 minutes ago, ReFresh said:

But I'm little bit confused about the 1920x1010 resolution in metin2.cfg everytime when I start the client.

Same, 2560x1080 => I start the Metin2Client => 2560x1009 (with kraizy 2014) xD

  • Windows 11 64 Bits
  • Taskbar Height : 49px
  • Program Title Bar Height : 31px
  • Good 1
Link to comment
Share on other sites

5jgDc9M.jpg

 

		if (Windowed)
		{
			m_isWindowed = true;

			RECT workArea;
			SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);

			const UINT workAreaWidth = (workArea.right - workArea.left);
			const UINT workAreaHeight = (workArea.bottom - workArea.top);

			const UINT windowWidth = m_pySystem.GetWidth() + GetSystemMetrics(SM_CXBORDER) * 2 + GetSystemMetrics(SM_CXDLGFRAME) * 2 + GetSystemMetrics(SM_CXFRAME) * 2;
			const UINT windowHeight = m_pySystem.GetHeight() + GetSystemMetrics(SM_CYBORDER) * 2 + GetSystemMetrics(SM_CYDLGFRAME) * 2 + GetSystemMetrics(SM_CYFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);

			const UINT x = workAreaWidth / 2 - windowWidth / 2;
			const UINT y = workAreaHeight / 2 - windowHeight / 2;

			SetPosition(x, y);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}
Edited by Metin2 Dev
Core X - External 2 Internal
  • Scream 1
  • Good 3
Link to comment
Share on other sites

  • Forum Moderator
1 hour ago, ReFresh said:

I don't know why it happens, but my metin2.cfg is not able to save the 1920x1080 resolution. Everytime when I start the client, the metin2.cfg is overwritten by 1920x1010 resolution. Can someone tell me why it happens or how to make it starting with the saved resolution? Thanks

I did it like this to make the window centered:

  Reveal hidden contents

But I'm little bit confused about the 1920x1010 resolution in metin2.cfg everytime when I start the client.

It is the size of the "playable area", not the size of the whole application.

For example: unknown.png

Spoiler

unknown.png

 

Edited by Metin2 Dev
Core X - External 2 Internal

Gurgarath
coming soon

Link to comment
Share on other sites

  • Forum Moderator
9 minutes ago, ReFresh said:

So why did you mention this? I don't really understand then. 

Because someone I've talked with had an issue with his width in the metin2.cfg. This is the main issue as width is the issue and I wanted people to double-check that they had no issue there. Height on the contrary has nothing to do with the bug, that's why I've kept it normal in my example. Also, the width of the client should be your full monitor width, unless you have your sidebar on the side.

 

  • Good 1

Gurgarath
coming soon

Link to comment
Share on other sites

9 hours ago, Denizeri24 said:

5jgDc9M.jpg

 

		if (Windowed)
		{
			m_isWindowed = true;

			RECT workArea;
			SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);

			const UINT workAreaWidth = (workArea.right - workArea.left);
			const UINT workAreaHeight = (workArea.bottom - workArea.top);

			const UINT windowWidth = m_pySystem.GetWidth() + GetSystemMetrics(SM_CXBORDER) * 2 + GetSystemMetrics(SM_CXDLGFRAME) * 2 + GetSystemMetrics(SM_CXFRAME) * 2;
			const UINT windowHeight = m_pySystem.GetHeight() + GetSystemMetrics(SM_CYBORDER) * 2 + GetSystemMetrics(SM_CYDLGFRAME) * 2 + GetSystemMetrics(SM_CYFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);

			const UINT x = workAreaWidth / 2 - windowWidth / 2;
			const UINT y = workAreaHeight / 2 - windowHeight / 2;

			SetPosition(x, y);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

It works perfectly. Thanks.

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

15 hours ago, martysama0134 said:

I used GetWindowRect to calculate the dropshadow area automatically:

		AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

		if (Windowed)
		{
			m_isWindowed = true;
			RECT rc{};
			GetClientRect(&rc);
			auto windowWidth = rc.right - rc.left;
			auto windowHeight = (rc.bottom - rc.top);
			//TraceError("windowWidth %d == %d windowHeight %d == %d", windowWidth, m_pySystem.GetWidth(), windowHeight, m_pySystem.GetHeight());
			RECT rc2{};
			GetWindowRect(&rc2);
			auto windowWidth2 = rc2.right - rc2.left;
			auto windowHeight2 = (rc2.bottom - rc2.top);
			//TraceError("windowWidth2 %d windowHeight2 %d", windowWidth2, windowHeight2);
			auto windowWidthDiff = windowWidth2 - windowWidth;
			auto windowHeightDiff = windowHeight2 - windowHeight;
			//TraceError("windowWidthDiff %d windowHeightDiff %d", windowWidthDiff, windowHeightDiff);
			//TraceError("GetLastError %d", ::GetLastError());
			constexpr auto taskbarSize = 80;
			auto dropshadowSize = (windowWidthDiff / 2 != 0) ? (windowWidthDiff / 2 - 1) : 0;
			CMSApplication::SetPosition(((GetScreenWidth() - windowWidth) / 2) - dropshadowSize, (GetScreenHeight() - windowHeight - taskbarSize) / 2);
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

This one is for 1920x1080 res

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrect

Old way with second window:

		AdjustSize(m_pySystem.GetWidth(), m_pySystem.GetHeight());

		if (Windowed)
		{
			m_isWindowed = true;
			RECT rc{};
			GetClientRect(&rc);
			auto windowWidth = rc.right - rc.left;
			auto windowHeight = (rc.bottom - rc.top);
			//TraceError("windowWidth %d == %d windowHeight %d == %d", windowWidth, m_pySystem.GetWidth(), windowHeight, m_pySystem.GetHeight());
			RECT rc2{};
			GetWindowRect(&rc2);
			auto windowWidth2 = rc2.right - rc2.left;
			auto windowHeight2 = (rc2.bottom - rc2.top);
			//TraceError("windowWidth2 %d windowHeight2 %d", windowWidth2, windowHeight2);
			auto windowWidthDiff = windowWidth2 - windowWidth;
			auto windowHeightDiff = windowHeight2 - windowHeight;
			//TraceError("windowWidthDiff %d windowHeightDiff %d", windowWidthDiff, windowHeightDiff);
			//TraceError("GetLastError %d", ::GetLastError());
			auto dropshadowSize = (windowWidthDiff / 2 != 0) ? (windowWidthDiff / 2 - 1) : 0;
#ifdef ENABLE_CENTERED_CLIENT_WINDOW
			constexpr auto taskbarSize = 80;
			CMSApplication::SetPosition(((GetScreenWidth() - windowWidth) / 2) - dropshadowSize, (GetScreenHeight() - windowHeight - taskbarSize) / 2);
#else
			constexpr auto taskbarSize = 73;
			constexpr auto titlebarSize = 10;
			if (bAnotherWindow)
				CMSApplication::SetPosition(GetScreenWidth() - windowWidth - dropshadowSize, GetScreenHeight() - windowHeight - taskbarSize);
			else
				SetPosition(-dropshadowSize, -titlebarSize);
#endif
		}
		else
		{
			m_isWindowed = false;
			SetPosition(0, 0);
		}

 

kr9BAPO.png

It not works well with the vs19/22 titlebar, as you see the titlebar's top is slammed down. (It's white here, open the image in new tab)
Is it possible to fix somehow? or change the titlebar height smaller like it was in vs2013?

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Honorable Member
1 hour ago, xifati said:

kr9BAPO.png

It not works well with the vs19/22 titlebar, as you see the titlebar's top is slammed down. (It's white here, open the image in new tab)
Is it possible to fix somehow? or change the titlebar height smaller like it was in vs2013?

I cut it in order to see the whole client in 1920x1080 res (otherwise the Windows taskbar will eat up some pixels), Set titlebarSize to 0, otherwise set titlebarSize to 0 only if m_pySystem.GetHeight() >= 1000.

auto titlebarSize = (m_pySystem.GetHeight() >= 1000) ? 10 : 0;

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 3
  • Good 1
Link to comment
Share on other sites

  • Contributor
16 hours ago, Gurgarath said:

It is the size of the "playable area", not the size of the whole application.

For example: unknown.png

  Reveal hidden contents

unknown.png

 

Can we edit the playable area? I think the best method to solve the height problem is to subtract some pixel, if it's possible.
(So the taskbar will not hide the bottom of the client)

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.