The Root folder on Crysis is crazy (dedicated server)

  • golden_elite13

    I already ran private servers in the past, but I never went through those weird things, or at least I don't remember the howtos, since it has been a while I didn't start a server on Crysis.

    To be sure it wasn't an SSM specific error, I tested with SafeWriting, Patriot, and without SSM, all give the same behaviour, and the first error that made me investigate this is the following:

    If my game is installed in a read-only folder, like the default installation path (e.g. C:\Program Files\Electronic Arts\Crytek\Crysis) and that I run the startup.bat (or whatever cmd environment to start the dedicated server, quick32.bat from SFW doesn't work either) WITHOUT admin rights on the game's folder, then the server crash at startup, but ONLY if the "-root" argument is specified in the .bat (whatever the path is, even to an external writeable path) and ONLY with the 32-bit dedicated server. Weird.

    I could just uninstall the game and reinstall it in a non read-only folder, or just run the server with admin rights, but well I got curious on this, it just made me wanna investigate further. I built a little DLL mod to print some values, which the code is really simple :

    #include "StdAfx.h"
    #include "Game.h"
    
    #include <CryLibrary.h>
    #include <platform_impl.h>
    
    
    extern "C"
    {
    	GAME_API IGame *CreateGame(IGameFramework* pGameFramework)
    	{
    		ModuleInitISystem(pGameFramework->GetISystem());
    
    		char dir[MAX_PATH];
    		GetCurrentDirectory(sizeof dir, dir);
    
    		CryLogAlways("[DEBUG] Current working directory: %s", dir);
    		CryLogAlways("[DEBUG] Mod dir: %s", pGameFramework->GetISystem()->GetIPak()->GetModDir());
    		CryLogAlways("[DEBUG] Root folder: %s", pGameFramework->GetISystem()->GetRootFolder());
    		CryLogAlways("[DEBUG] Log file path: %s", pGameFramework->GetISystem()->GetILog()->GetFileName());
    
    		static char pGameBuffer[sizeof(CGame)];
    		return new ((void*)pGameBuffer) CGame();
    	}
    }

    Here are my findings:

    - Whatever your current working directory is (that is, the server folder which contains your startup.bat), Crysis will change it to the game folder's (parent of the executable). Thus the CWD is never relevant. Mod and game files are only accessed from the game's folder. CWD cannot be used to load your server.cfg or output the server.log, only the "-root" argument does.

    - Server.log and server.cfg are accessed from the specified "-root" argument path if possible, otherwise in game's folder. If no write access on game's folder, Server.log is rather created in the user data folder of the game (usually in <Username>/My Games/Crysis). server.cfg won't be loaded from user folder, only from game's folder.

    - Whether you cd the game's folder before starting the server executable or start it from the server folder, does not change anything. Those two pieces of code are the same :
    cd C:\Program Files (x86)\Electronic Arts\Crytek\Crysis
    bin32\crysisdedicatedserver -root %ServerFolder% +exec "server.cfg"

    "C:\Program Files (x86)\Electronic Arts\Crytek\Crysis\bin32\crysisdedicatedserver" -root %ServerFolder% +exec "server.cfg"
    (%ServerFolder% is set to C:/Server, which is not write-protected). The 32-bit version of these commands does crash, the 64-bit does not crash but won't create the server.log in the path I specified. What if I want to read my daily log ? :D

    If I remove the whole -root argument, the game will default to its own folder for server.log and server.cfg, as I said, and the server won't crash (32-bit). If you don't specify the -root argument the game won't load your server.cfg from your server folder even if you start the .bat from that context, because the working directory gets overwritten.

    I got sure about these assertions by using the C++ code above, and it printed out those things, in the following cases :
    bin64\crysisdedicatedserver -root %ServerFolder% +exec "server.cfg" -mod CrysisMod

    =>
    [DEBUG] Current working directory: C:\Program Files (x86)\Electronic Arts\Crytek\Crysis
    [DEBUG] Mod dir: Mods\CrysisMod\
    [DEBUG] Root folder: C:/Server/
    [DEBUG] Log file path: C:/Server/Log.txt (or C:/Server/Server.log if write access to game's folder, in which case the log file is correctly created)

    Note this crazy "Log.txt" as default log file name, which is not created at all, even if C:/Server is not read-only. Also it's with the bin64 server only, bin32 crashes at start if no write access to game's folder.

    Whether I change the server folder path and pre-startup working directory or not, the working directory is always printed as the game's folder, only the "root folder" value and the log filename can change.

    This following does not make the server crash but you won't have the clean layout of a separate unprivileged server folder, because the SSM won't find my server folder, and I won't get my server.log in my server folder.

    bin32\crysisdedicatedserver +exec "server.cfg" -mod CrysisMod
    =>
    [DEBUG] Current working directory: C:\Program Files (x86)\Electronic Arts\Crytek\Crysis
    [DEBUG] Mod dir: Mods\CrysisMod\
    [DEBUG] Root folder:
    [DEBUG] Log file path: Server.log


    The point of all of this is to install the SSM once, and then tweak your server.cfg and other custom SSM files in another place.

    ~
    Does anyone has an idea about those behaviours ? Why the server.log is not created in my server folder when it could be, and why does the 32-bit version crash if the game's folder is read-only, but only with a root argument specified ? Is it impossible to properly run a clean crysis server without admin rights if the game is installed in a write-protected folder ?

    With 64-bit I don't get the server.log but otherwise it seems to be working, but well some SSMs like SafeWriting are 32-bit only :/

    A final funny thing :
    bin32\crysisdedicatedserver -root ""
    starts the game instead of the dedicated server :D

    0
  • golden_elite13

    If my post is too long or you don't understand my problem :

    - I just want the dedicated server to work, in a case where the game is installed in a write-protected folder, and my server folder be separate of it, to contain my server.cfg config, the output server.log, and have the SSM run my custom scripts in it and able to use the folder to output some data, without admin privileges. My startup.bat is also in my server folder, and gives the game the root of my path so it gives me my log files.

    => It currently doesn't work, 32-bit version crash without write privileges on game's folder, or won't crash only if I remove the -root argument, which also prevents me from having a separate folder for my server config and the output log. This works correctly only if i run the startup.bat with admin rights. On 64-bit it does not crash but I won't get the log file in my non-write-protected folder if I don't run with admin rights too.

    0
  • Comrade

    Well, almost everything in Crysis is more or less broken unfortunately.

    As you discovered, working directory is always set to the main Crysis directory. Therefore, it's useful to have the main directory writable. All relative paths are referenced to the working directory after all.

    I think the best approach is to have a single read-only Crysis installation. Then create separate Crysis directories for each server, but instead of making copies of the Crysis installation, create only empty subdirectories (Bin32, Bin64, Game, Mods) in each server directory. Then, in each of these subdirectories inside server directories, create symlinks to the actual files and directories in the read-only Crysis installation. If you need to modify any Crysis file on one of your servers, then just replace the symlink with an actual file. If you need to modify a file inside linked directory, then replace the symlink with an actual directory and link everything in it except the file you need to modify. You can also have server-specific maps and SSM versions. It's surprisingly versatile and it doesn't waste any disk space. Symlinks are supported on both Linux (https://ss64.com/bash/ln.html) and Windows (https://ss64.com/nt/mklink.html).

    0
  • golden_elite13

    Thank you mate.

    Didn't know until that day that Crysis was broken at this point, not being able to run a server as normal user on the default, read-only install directory :D

    The crysis server documentation doesn't even advises the user to install the game in a writeable directory or run the server with admin rights.

    Crazy Crytek :D

    0
  • golden_elite13

    I just tested out if the crash was due to the inability to create the log file, so I tried to pass a different path with the -logfile parameter and making it point to an absolute path to a writeable directory.

    This dumb shit server only keeps what come after the last backslash of the specified path, so you can only change the filename not the path :D

    0