Jump to content

Uninstalling LibJPEG and Taking Screenshots with DirectX9


Recommended Posts

  • Active+ Member

Hello. As you know, the LibJPEG library in Metin2 is only useful for taking screenshots. Other than that, it doesn't have any duties.

Those who have Directx9 and want to take better quality screenshots with this method can follow this guide carefully.
Those who use Directx8 can update the code I will give according to Directx8 and try it, I did not have the chance to try it.

Make sure you are determined before following the steps here. Because as a result of these operations, you will no longer have the libjpeg library, and the screenshot files will reach larger sizes than the jpg file, depending on the quality. (between 3-8MB)

The explanation will be a bit complicated, but if you follow each process in order, you will not have any problems. If you still have a problem, you can report it below.
 

First, let's get rid of libjpeg:

-> Enter the Client src/extern/lib folder and delete the .lib files whose file name starts with libjpeg...
-> Enter the Client src/EterLib folder and delete the JpegFile.cpp & JpegFile.h files. Open the EterLib project in Visual Studio in the same way, select these two files and remove them.

-> Open the client src/EterPythonLib/PythonGraphic.cpp file and remove the following include line and functions:

#include "../eterLib/JpegFile.h"
---------------------------------

void GenScreenShotTag(const char* src, DWORD crc32, char* leaf, size_t leafLen){
    const char* p = src;
    const char* n = p;
    while (n = strchr(p, '\\'))
        p = n + 1;

    _snprintf(leaf, leafLen, "YMIR_METIN2:%s:0x%.8x", p, crc32);
}

bool CPythonGraphic::SaveJPEG(const char* pszFileName, LPBYTE pbyBuffer, UINT uWidth, UINT uHeight)
{
    return jpeg_save(pbyBuffer, uWidth, uHeight, 100, pszFileName) != 0;
}

-> Where you delete these, you will see this function:

bool CPythonGraphic::SaveScreenShot(const char* c_pszFileName)
{

-> Replace this function completely like this:

bool CPythonGraphic::SaveScreenShot()
{
    LPDIRECT3DSURFACE9 lpSurface = nullptr;
    D3DSURFACE_DESC stSurfaceDesc = {};

    uint32_t uWidth = stSurfaceDesc.Width;
    uint32_t uHeight = stSurfaceDesc.Height;

    ms_lpd3dDevice->CreateOffscreenPlainSurface(uWidth, uHeight, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &lpSurface, NULL);

    if (SUCCEEDED(ms_lpd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &lpSurface)))
    {
        if (!CreateDirectory("screenshot", NULL) && ERROR_ALREADY_EXISTS != GetLastError()) //yoksa oluştur
            return false;


        SYSTEMTIME st;
        GetSystemTime(&st);
        char szFileName[MAX_PATH];
        sprintf_s(szFileName, "screenshot/screenshot_%04d%02d%02d_%02d%02d%02d.bmp", // eşsiz
            st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

        D3DXSaveSurfaceToFile(szFileName, D3DXIFF_BMP, lpSurface, NULL, NULL);
    }
    else
        TraceError("CPythonGraphic::SaveScreenShot() - ScreenShot Basarisiz!");

    // yok et
    if (lpSurface)
    {
        lpSurface->Release();
        lpSurface = nullptr;
    }

    return true;
}

-> Then remove the following from the PythonGraphic.h file:

bool SaveJPEG(const char* pszFileName, LPBYTE pbyBuffer, UINT uWidth, UINT uHeight);

-> In the same file there will be:

bool SaveScreenShot(const char* szFileName);

-> Update this to:

bool SaveScreenShot();

-> Open PythonGraphicModule.cpp and delete this

PyObject* grpSaveScreenShot(PyObject* poSelf, PyObject* poArgs)
{
    struct tm* tmNow;
    time_t ct;

    ct = time(0);
    tmNow = localtime(&ct);

    char szPath[MAX_PATH + 256];
    SHGetSpecialFolderPath(NULL, szPath, CSIDL_PERSONAL, TRUE);
    //GetTempPath();
    strcat(szPath, "\\METIN2\\");

    if (-1 == _access(szPath, 0))
        if (!CreateDirectory(szPath, NULL))
        {
            TraceError("Failed to create directory [%s]\n", szPath);
            return Py_BuildValue("(is)", FALSE, "");
        }

    sprintf(szPath + strlen(szPath), "%02d%02d_%02d%02d%02d.jpg",
        tmNow->tm_mon + 1,
        tmNow->tm_mday,
        tmNow->tm_hour,
        tmNow->tm_min,
        tmNow->tm_sec);

    BOOL bResult = CPythonGraphic::Instance().SaveScreenShot(szPath);
    return Py_BuildValue("(is)", bResult, szPath);
}

-> and delete this:

{ "SaveScreenShot",                grpSaveScreenShot,                METH_VARARGS },

-> Find the following function in the same file

PyObject* grpSaveScreenShotToPath(PyObject* poSelf, PyObject* poArgs)
{

-> Replace this function completely with the code I gave below.

PyObject* grpSaveScreenShotToPath(PyObject* poSelf, PyObject* poArgs)
{
    CPythonGraphic::Instance().SaveScreenShot();
    return Py_BuildNone();
}

 

 

-> We are done with the client src. Now open root/game.py and find this function:

def SaveScreen(self):
        print "save screen"

        # SCREENSHOT_CWDSAVE
        if SCREENSHOT_CWDSAVE:
            if not os.path.exists(os.getcwd()+os.sep+"screenshot"):
                os.mkdir(os.getcwd()+os.sep+"screenshot")

            (succeeded, name) = grp.SaveScreenShotToPath(os.getcwd()+os.sep+"screenshot"+os.sep)
        elif SCREENSHOT_DIR:
            (succeeded, name) = grp.SaveScreenShot(SCREENSHOT_DIR)
        else:
            (succeeded, name) = grp.SaveScreenShot()
        # END_OF_SCREENSHOT_CWDSAVE

        if succeeded:
            pass
            """
            chat.AppendChat(chat.CHAT_TYPE_INFO, name + localeInfo.SCREENSHOT_SAVE1)
            chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SCREENSHOT_SAVE2)
            """
        else:
            chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.SCREENSHOT_SAVE_FAILURE)

-> ..and update it like this:

	def SaveScreen(self):
		grp.SaveScreenShotToPath()

.png

 

You can also search and delete the variables in the original Python code above from root.

I'm sorry for my bad english.

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

Thanks for release, but as far as i know it will not work with directx8, cause CreateOffscreenPlainSurface is not present there.

Little snippet where you can capture the whole screen with directx8 (not only game window sadly)

bool CPythonGraphic::SaveScreenShot()
{
	HRESULT hr;

	D3DDISPLAYMODE mode;
	if (FAILED(hr = ms_lpd3dDevice->GetDisplayMode(&mode))) {
		TraceError("CPythonGraphic::SaveScreenShot() - GetDisplayMode failed!");
		return false;
	}

	LPDIRECT3DSURFACE8 surf;
	if (FAILED(hr = ms_lpd3dDevice->CreateImageSurface(mode.Width, mode.Height, D3DFMT_A8R8G8B8, &surf))) {
		TraceError("CPythonGraphic::SaveScreenShot() - CreateImageSurface failed!");
		return false;
	}

	if (FAILED(hr = ms_lpd3dDevice->GetFrontBuffer(surf))) {
		TraceError("CPythonGraphic::SaveScreenShot() - GetFrontBuffer failed!");
		surf->Release();
		return false;
	}
	else
	{
		if (!CreateDirectory("screenshot", NULL) && ERROR_ALREADY_EXISTS != GetLastError()) {
			TraceError("CPythonGraphic::SaveScreenShot() - Failed to create or find screenshot folder failed!");
			return false;
		}

		SYSTEMTIME st;
		GetSystemTime(&st);
		char szFileName[MAX_PATH];
		sprintf_s(szFileName, "screenshot/screenshot_%04d%02d%02d_%02d%02d%02d.bmp",
			st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

		D3DXSaveSurfaceToFile(szFileName, D3DXIFF_BMP, surf, NULL, NULL);
	}

	if (surf)
	{
		surf->Release();
		surf = nullptr;
	}

	return true;
}

 

  • Good 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.