Jump to content

Recommended Posts

  • Bot

A sub script is a file with a .sub extension that is used to cut a small portion of a larger image. 

Today I will present you a easyer way to use this sub technique without creating the actual .sub file.
 

Spoiler
// 1. Register a new extension we call ".memsub"
// In file ScriptLib/Resource.cpp search:
    m_resManager.RegisterAllowedExtension("sub", NewSubImage);
	
// Add under it:
    m_resManager.RegisterAllowedExtension("memsub", NewSubImage);
	
	
// 2. In file EterLib/GrpSubImage.h search:
	protected:
		CGraphicImage::TRef m_roImage;
		
// Add under it:
        std::string m_strFileName;
		
		
// 3. In file EterLib/GrpSubImage.cpp we need to modify the constructor like this:
CGraphicSubImage::CGraphicSubImage(const char* c_szFileName) : CGraphicImage(c_szFileName), m_strFileName(c_szFileName)
{
}

// And the destructor like this:
CGraphicSubImage::~CGraphicSubImage()
{
    m_roImage = nullptr;
    m_strFileName.clear();
}


// 4. In file EterLib/GrpSubImage.cpp we change the function OnLoadLike this:
bool CGraphicSubImage::OnLoad(int iSize, const void* c_pvBuf)
{
    if (m_strFileName.find(".memsub") != std::string::npos)
    {
        // Ensure the file name contains ".dds"
        size_t ddsPos = m_strFileName.find(".dds");
        if (ddsPos == std::string::npos)
            return false;

        // Ensure the file name ends with ".memsub"
        size_t memsubPos = m_strFileName.find(".memsub", ddsPos);
        if (memsubPos == std::string::npos || memsubPos + 7 != m_strFileName.length())
            return false;

        // Get the full image file name with ".dds"
        std::string imageFileName = m_strFileName.substr(0, ddsPos + 4);  // +4 to include ".dds"

        // Get the rect info part of the string
        std::string rectInfo =
            m_strFileName.substr(ddsPos + 5, memsubPos - ddsPos - 5);  // +5 to skip ".dds" and the underscore

        // Split the rect info into left, top, right, bottom
        size_t start = 0;
        size_t end   = rectInfo.find('_');
        if (end == std::string::npos)
            return false;

        // Parse left
        int left = std::stoi(rectInfo.substr(start, end - start));
        start    = end + 1;

        // Parse top
        end = rectInfo.find('_', start);
        if (end == std::string::npos)
            return false;
        int top = std::stoi(rectInfo.substr(start, end - start));
        start   = end + 1;

        // Parse right
        end = rectInfo.find('_', start);
        if (end == std::string::npos)
            return false;
        int right = std::stoi(rectInfo.substr(start, end - start));
        start     = end + 1;

        // Parse bottom
        int bottom = std::stoi(rectInfo.substr(start));

        // Validate the rectangle coordinates
        if (left >= right || top >= bottom)
        {
            TraceError("Invalid rectangle coordinates in %s: left=%d, right=%d, top=%d, bottom=%d",
                       m_strFileName.c_str(), left, right, top, bottom);
            return false;
        }

        // Set the image file name
        SetImageFileName(imageFileName.c_str());

        // Check if image is successfully loaded
        if (m_roImage.IsNull())
        {
            TraceError("Failed to load %s while loading %s", imageFileName.c_str(), GetFileName());
            return false;
        }

        // Set the rectangle
        m_rect.left   = left;
        m_rect.right  = right;
        m_rect.top    = top;
        m_rect.bottom = bottom;
    }
    else
    {
        // Place your current function content here
    }

    return true;
}

 

 

How to use it? 
 

self.LoadImage("d:/ymir work/ui/newskillcommon.dds_224_544_256_576.memsub")

The format is:
ddsFileName_rectLeft_rectTop_rectRight_rectBottom.memsub

 

  • Love 1

english_banner.gif

Link to comment
https://metin2.dev/topic/32948-in-memory-sub-image/
Share on other sites

  • Bot
9 minutes ago, hachiwari said:

Hm, okay, this solution seems too strange to me. Why not overload the function like this:

self.LoadImage("d:/ymir work/ui/newskillcommon.dds", 224, 544, 256, 576)

 

You are free to post this solution.


I coded like that because I wanted a quick and easy solution. 

english_banner.gif

Link to comment
https://metin2.dev/topic/32948-in-memory-sub-image/#findComment-166860
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • 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.