Jump to content

Recommended Posts

  • Active+ Member

To make translations much easier for all languages, I thought it would be an interesting idea to load item_names.txt separately from item_proto.

This way, the item_names.txt file will be available inside each language folder
(locale/ro, locale/en, locale/pt, locale/es, etc.) and will be loaded after item_proto. 

 

INSTALLATION

UserInterface/Locale_inc.h

Add:

#define ENABLE_ITEM_NAMES_SEPARATED_READ


UserInterface/PythonApplication.cpp
 

Search:

    char szItemProto[256];

Add after:

#ifdef ENABLE_ITEM_NAMES_SEPARATED_READ
    char szItemNames[256];
#endif

Search:

    snprintf(szItemProto,    sizeof(szItemProto),    "%s/item_proto",    localePath);

Add after:

#ifdef ENABLE_ITEM_NAMES_SEPARATED_READ
    snprintf(szItemNames,    sizeof(szItemNames),    "%s/item_names.txt",    localePath);
#endif

Search:

    if (!rkItemMgr.LoadItemTable(szItemProto))
    {
        TraceError("LoadLocaleData - LoadItemProto(%s) Error", szItemProto);
        return false;
    }

Add after:

#ifdef ENABLE_ITEM_NAMES_SEPARATED_READ
    if (!rkItemMgr.LoadItemNames(szItemNames))
    {
        Tracenf("LoadLocaleData - LoadItemNames(%s) Error", szItemNames);
    }
#endif



GameLib/ItemData.cpp
 

Search:

const char * CItemData::GetName() const
{
    return m_ItemTable.szLocaleName;
}

Add after:

#ifdef ENABLE_ITEM_NAMES_SEPARATED_READ
void CItemData::SetItemNames(const std::string& name)
{
    strncpy(m_ItemTable.szLocaleName, name.c_str(), sizeof(m_ItemTable.szLocaleName) - 1);
    m_ItemTable.szLocaleName[sizeof(m_ItemTable.szLocaleName) - 1] = '\0';
}
#endif


GameLib/ItemData.h
 

Search:

#include "../eterGrnLib/Thing.h"

Add after:

#include "../UserInterface/Locale_inc.h"

Search:

        const char * GetSummary() const;

Add after:

#ifdef ENABLE_ITEM_NAMES_SEPARATED_READ
        void SetItemNames(const std::string& name);
#endif


GameLib/ItemManager.cpp
 

 Search:

DWORD GetHashCode( const char* pString )

Add before:

#ifdef ENABLE_ITEM_NAMES_SEPARATED_READ
bool CItemManager::LoadItemNames(const char* c_szFileName)
{
    const VOID* pvData;
    CMappedFile kFile;

    if (!CEterPackManager::Instance().Get(kFile, c_szFileName, &pvData))
    {
        Tracenf("CItemManager::LoadItemNames(c_szFileName=%s) - Load Error", c_szFileName);
        return false;
    }

    CMemoryTextFileLoader kTextFileLoader;
    kTextFileLoader.Bind(kFile.Size(), pvData);

    CTokenVector kTokenVector;
    for (DWORD i = 0; i < kTextFileLoader.GetLineCount(); ++i)
    {
        if (!kTextFileLoader.SplitLineByTab(i, &kTokenVector))
            continue;

        if (kTokenVector.size() < 2)
            continue;

        DWORD dwVnum = static_cast<DWORD>(atoi(kTokenVector[0].c_str()));
        std::string c_rstName = kTokenVector[1];

        if (c_rstName.length() >= CItemData::ITEM_NAME_MAX_LEN)
        {
            c_rstName.resize(CItemData::ITEM_NAME_MAX_LEN - 1);
        }

        TItemMap::iterator f = m_ItemMap.find(dwVnum);
        if (f == m_ItemMap.end())
            continue;

        CItemData* pkItemDataFind = f->second;
        pkItemDataFind->SetItemNames(c_rstName);
    }

    return true;
}
#endif


GameLib/ItemManager.h
 

Search:

        bool            LoadItemTable(const char* c_szFileName);

Add:

#ifdef ENABLE_ITEM_NAMES_SEPARATED_READ
        bool            LoadItemNames(const char* c_szFileName);
#endif


 

Place the item_names.txt file inside your locale directory, for example in the 'ro' or 'en' folder, or in the folder corresponding to the language.

locale/ro/item_names.txt
locale/en/item_names.txt
locale/es/item_names.txt
locale/pt/item_names.txt


 

 

 
  • Love 1
Link to comment
https://metin2.dev/topic/34223-read-item_namestxt-separately/
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.