• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTClient's cache files

Dercas

Active Member
Joined
Nov 15, 2008
Messages
88
Reaction score
29
Hi all,

I've been trying to move the OTClient's cache from %AppData% to the client's main folder, to 'cache' folder. I've been trying to work on resourcemanager.cpp but with no success.
Any ideas, suggestions?
 
Not sure on OTClient, but here are some informations from OTCV8 that might be useful:

You have "writeDir", which is defined on ResourceManager::setupWriteDir. This writeDir is going to be used to write minimaps, config files and others. This is by default defined by "PHYSFS_getPrefDir", which is the "cache" folder that you mentioned.
If you change that folder, you will be done.
 
Not sure on OTClient, but here are some informations from OTCV8 that might be useful:

You have "writeDir", which is defined on ResourceManager::setupWriteDir. This writeDir is going to be used to write minimaps, config files and others. This is by default defined by "PHYSFS_getPrefDir", which is the "cache" folder that you mentioned.
If you change that folder, you will be done.
Thanks! I will give it a try again today

@edit
Okay, so, this part in resourcemanager.cpp:
C++:
bool ResourceManager::setupWriteDir(const std::string& product, const std::string& app) {
#ifdef ANDROID
    const char* localDir = g_androidState->activity->internalDataPath;
#else
    const char* localDir = PHYSFS_getPrefDir(product.c_str(), app.c_str());
#endif

    if (!localDir) {
        g_logger.fatal(stdext::format("Unable to get local dir, error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
        return false;
    }

    if (!PHYSFS_mount(localDir, NULL, 0)) {
        g_logger.fatal(stdext::format("Unable to mount local directory '%s': %s", localDir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
        return false;
    }

    if (!PHYSFS_setWriteDir(localDir)) {
        g_logger.fatal(stdext::format("Unable to set write dir '%s': %s", localDir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
        return false;
    }

#ifndef ANDROID
    m_writeDir = std::filesystem::path(std::filesystem::u8path(localDir));
#endif
    return true;
}

Replaced with:

C++:
bool ResourceManager::setupWriteDir(const std::string& product, const std::string& app) {
    std::string localDir;

#ifdef ANDROID
    localDir = g_androidState->activity->internalDataPath;
#else
    // Construct path in local app folder
    std::filesystem::path currentPath = std::filesystem::current_path();
    std::filesystem::path appDataFolder = currentPath / "AppData" / product / app;
    localDir = appDataFolder.u8string(); // Convert to string
#endif

    if (!PHYSFS_mount(localDir.c_str(), NULL, 0)) {
        g_logger.fatal(stdext::format("Unable to mount local directory '%s': %s", localDir.c_str(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
        return false;
    }

    if (!PHYSFS_setWriteDir(localDir.c_str())) {
        g_logger.fatal(stdext::format("Unable to set write dir '%s': %s", localDir.c_str(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
        return false;
    }

    m_writeDir = localDir;
    return true;
}

& It seems to work. Need a bit more testing to see if no errors occur but it seems to load the settings/save minimap etc. in the mainfolder/AppData/Otclientv8/ <name from init lua>
 
Last edited:
Yeah, this is exactly the place!
You can use another function in order to get the current path too, instead of std::filesystem::current_path(). No big differences at all, just a matter of organization:
g_platform.getCurrentDir()

Also it is worth to note:
  • you should test the updater after this changes. Update the .exe and data.zip
  • if you are already running a server and the players have the old client, it is better to you change the "app" name, this way the updater/launch will not mess with older clients that your playerbase may have

Just a note for others:
The downside of this changes is, if you have any trouble with some update or for any reason you need to ask players to re-download the client, they may loose the maps and configs (but you can ask them to just copy the "AppData" from previous version to the new one).
The gain of this changes is that you do not need to ask the players to "go to %appdata% bla bla bla" and as most of the players just do not know how to do it (yes, its true)
 
Last edited:
More simple, do this:

Create a folder called cache inside OTC folder, and in init.lua, replace this:
Code:
g_resources.setupUserWriteDir(('%s/'):format(g_app.getCompactName()))

for this:
Code:
g_resources.setWriteDir(g_resources.getWorkDir() .. 'cache')
 
More simple, do this:

Create a folder called cache inside OTC folder, and in init.lua, replace this:
Code:
g_resources.setupUserWriteDir(('%s/'):format(g_app.getCompactName()))

for this:
Code:
g_resources.setWriteDir(g_resources.getWorkDir() .. 'cache')
This won't work with otcv8 until a lot of changes in the source. This may work in mehah release
 
Back
Top