You are not logged in.
Pages: 1
My problem: I play games a lot and want to sync my savegames and settings between laptop and pc.
This is my approach: I have a launch script that every game gets run with. This launch script changes the $HOME environment variable to a special "Savegames" folder in my home directory, now I can just sync this whole folder.
This works fine with most games I've tried until now. However there is one (Prey) that still puts the savegames in $HOME/.prey instead of $HOME/Savegames/.prey !
So, essentially, my question is: What's the best way to trick a program that I have a different home directory?
Offline
You might try creating ~/Savegames/.prey and then make a softlink :
ln -s ~/Savegames/.prey ~/.prey
Note that that won't work if ~/.prey already exists. You may want to create ~/Savegames/.prey by moving ~/.prey the the Savegames directory
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Probably by setting the XDG_CONFIG_HOME variable for your game specifically.
Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy
Offline
You might try creating ~/Savegames/.prey and then make a softlink :
ln -s ~/Savegames/.prey ~/.prey
I already considered that, the drawback is that I have to tell the script the save game folder for every game, which I don't really want to do...
Probably by setting the XDG_CONFIG_HOME variable for your game specifically.
I've now literally set every XDG_* and any other environment variable that had my login name in it. Still the game finds out about my real home folder.
Offline
You can always edit the source
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Not for commercial games... wish I could
I guess I'll go for the symlink way then, even if its stupid...
Last edited by scrawl (2011-11-26 19:04:37)
Offline
While the symlink way is probably the best way to do it, if you want to change your home directory in the bash session you're in, you can enter:
export HOME=/home/*user*/Savegames/.prey
Which if you're launching the game from a terminal should make it recognize it as your home folder.
Offline
It could be reading the home directory using the getpwnam(3) function, or directly from /etc/passwd. You can probably find out by running something like:
ltrace -e getpwnam,getpwuid,getpwnam_r,getpwuid_r my_prey_executable >/dev/null
If this is the case, given that we don't have the source, maybe one could write a library with a fake version of the appropriate function and set LD_PRELOAD to make the game use it?
Or maybe it's simply writing stuff to the current directory and you just happen to always launch it from your home directory.
If all else fails, you could run the games as a separate user (using su or sudo) and treat that user's home folder as the savegames folder.
Offline
ltrace -e getpwnam,getpwuid,getpwnam_r,getpwuid_r ./prey.x86 >/dev/null
getpwuid(1000, 0xf73c22a0, 1, 0, 0x84fb520) = 0xf7577c70
getpwuid(1000, 0, 248144, -1, -1) = 0xf7577c70
If this is the case, given that we don't have the source, maybe one could write a library with a fake version of the appropriate function and set LD_PRELOAD to make the game use it?
Sounds like overkill
Last edited by scrawl (2011-11-28 00:00:26)
Offline
ltrace -e getpwnam,getpwuid,getpwnam_r,getpwuid_r ./prey.x86 >/dev/null getpwuid(1000, 0xf73c22a0, 1, 0, 0x84fb520) = 0xf7577c70 getpwuid(1000, 0, 248144, -1, -1) = 0xf7577c70
If this is the case, given that we don't have the source, maybe one could write a library with a fake version of the appropriate function and set LD_PRELOAD to make the game use it?
Sounds like overkill
Well, I decided to give it a try. I'm not really a C programmer, but it was actually much easier than expected. This was quite helpful: http://www.technovelty.org/code/c/override.html
Save the code below as libfakehome.c and change the path (FAKE_HOMEDIR) to what you want:
#define FAKE_HOMEDIR "/opt/games"
#define FAKE_HOMEDIR_UID 1000
#define _GNU_SOURCE 1
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <pwd.h>
#include <dlfcn.h>
struct passwd *getpwuid(uid_t uid) {
static struct passwd fake;
struct passwd *(*real_getpwuid)(uid_t) = dlsym(RTLD_NEXT, "getpwuid");
struct passwd *pwentry;
pwentry = real_getpwuid(uid);
if (uid != FAKE_HOMEDIR_UID) {
return pwentry;
}
if (pwentry == NULL) {
fprintf(stderr, "Failed to fake home directory.\n");
return NULL;
}
fake = *pwentry;
fake.pw_dir = FAKE_HOMEDIR;
fprintf(stderr, "Faking home directory: %s\n", fake.pw_dir);
return &fake;
}
Compile it:
gcc -shared -fPIC -ldl -o /somewhere/libfakehome.so libfakehome.c
And run it:
LD_PRELOAD=/somewhere/libfakehome.so ./prey.x86
Offline
Wow, that looks really cool!
How would I compile it for x86 (Since I'm running 64 bit arch, but prey is 32 bit)?
Edit: Solved: install gcc-multilib and compile with -m32 flag.
and it just works Thank you very much
Maybe I will release something when I'm finished. I'm doing a collection of scripts to make installing/running games across multiple linuxes easier (Current features are shared savegame folder, and script to launch on different XServer for games that don't allow you to tab out - in the future maybe also wine support and a game database ala playonlinux)
Last edited by scrawl (2011-11-28 16:09:51)
Offline
Pages: 1