Skip to content

Enhanced Edition User Directory Detection

bardezbardez Member Posts: 41
edited November 2013 in General Modding
How is the user-space directory path determined? I'm thinking of cross-platform and cross-language scenarios here. Last week, I could safely assume on Windows 7 that my directory was "C:\Users\Bardez\Documents\Baldur's Gate - Enhanced Edition". I have no knowledge of OS X or possible Linux releases. Now that BG2:EE is out, it's a toss up between adding a " II" in the middle of the directory or not.

Determining if the install target is an Enhanced Edition is easy enough, but I'm curious how one could safely differentiate between BG2:EE and BG:EE, starting from chitin.key to find the user-space directory. Since the executables are running off of a code base maintained in parallel, the installs look a lot more similar than before. So how is the user directory determined? Is it hard-coded, registry written, etc.? Is there a 2DA file that defines it?

Working off of memory from when I did BGT, Near Infinity used the movies to differentiate the Infinity Engine installs. I recall from 2002 or so asking Jon Olav Hauglid to actually update the way he was doing it for NI due to BGT (I ran into trouble with NI thinking a BGT install was BG1), which he was kind enough to do. Using that same thinking, and applying it forward, what distinguishes the two games that no one would ever really want to copy between engine instances? Most media assets, creatures, etc. would be excluded from consideration due to the above concept. While snooping at the BG2:EE install, I see new resources of type 0x03FF that are not present in BG:EE, and those appear to be at least related to the tutorial videos in BG2:EE.

Is there a set way to determine, regardless of platform and language, what the related user-space directory for either game is going to be? Basically if you have, say a portrait pack mod or want to write something that detects assets available for a current user, how would one safely determine which user directory to use?

EDIT: Typo fixes, rewording for clarity.

Comments

  • IsayaIsaya Member, Translator (NDA) Posts: 752
    WeiDU 235 includes a new variable %USER_DIRECTORY% for that purpose, I think. WeiDU also has GAME_IS checks if you want to ensure your installer is the right environment.
    I'm sure the checks made by WeiDU to identify a game were made public somewhere but I can't remember where exactly.
  • bardezbardez Member Posts: 41
    I mean more from a programatic perspective, less WeiDU itself.
  • bardezbardez Member Posts: 41
    To clarify, I am thinking of the utility of using NI to load save games when modding. Since they were taken out of the application tree and put into user space, you can't easily load the save directory, because you don't know which user directory to load. So, I'm thinking from the programatic perspective, which is something WeiDU could implement, DLTCEP, NI, etc.

    Does the folder name change depending on native language? To what directory does the game installer use for user files (is it a documents subdirectory or something like that? I'm ignorant of OS X and its patterns).
  • IsayaIsaya Member, Translator (NDA) Posts: 752
    As I said, WeiDU already implement something to find out where this folder is and set the variable USER_DIRECTORY with the result. I understand that you would like to know how it does it. I believe asking the question in the weidu forum would help you get an answer.
  • bardezbardez Member Posts: 41
    Ah, I misunderstood. I thought you were indicating a new package level variable that could be set but the WeiDU script.
  • Troodon80Troodon80 Member, Developer Posts: 4,110
    There is a hardcoded value in both games. (Currently) BG:EE is at offset 0x005CFE68 in the executable and BG2:EE is at offset 0x005D3C70. I am unsure if this is just to write the INI file, as my ASM/DASM is a bit lacking these days. The user/personal/documents directory is presumably obtained by using one of the different functions available; e.g.: SHGetFolderPath (Win), FSFindFolder (Mac).

    That doesn't sound like what you are asking for though.

    If you were making a WeiDU script, then I would suggest simply having a check for a file that you know is unique to the particular game; though even that would be unreliable given that someone could easily copy items and other resources to either game.
  • bardezbardez Member Posts: 41
    @Troodon80 that's actually closer to what I was thinking, but new patches will invalidate those offsets.

    @Isaya WeiDU has the user folder hard-coded, so it just relies on which game was detected. And that appears to be based off of the containing folder in the case of enhanced editions. I don't think Overhaul allows you to install to any other directories than the default one, so that might be a safe assumption to mimic.

    Something as simple as naming the executable baldur.exe or baldur2.exe would allow someone to make assumptions, but that is not currently the case. I'll nose around some more to see if I can't find information to satisfy my curiosity.
  • Troodon80Troodon80 Member, Developer Posts: 4,110
    @bardez,
    bardez said:

    that's actually closer to what I was thinking, but new patches will invalidate those offsets.

    Precisely, so it's unreliable.

    Unfortunately, the containing folder—for example, 00766 for BG:EE—is also unreliable given that the Steam version doesn't have such a directory (though I'm not sure on this exact point, it might have).

    As I said, for installing to either game the best course right now would be to use FILE_EXISTS_IN_GAME in your TP2 file to determine which game is currently being installed for. Say, for instance, you have a mod that has modules that can be installed for either game, but uses something to detect which game and then skips the mods that are not compatible with the chosen game. For example, FILE_EXISTS_IN_GAME ~SECRET05.itm~. Since this item is exclusive to BG2, you could use it to determine the USER directory, Baldur's Gate - Enhanced Edition or Baldur's Gate II - Enhanced Edition. What you could do is find a script, perhaps, and use that instead. Items and spells can be extracted and copied to either game, but an area script would be somewhat useless if the area didn't exist and so it would limit the potential fault chance. (even though you can trust that someone out there will probably try.)

    That's about all I could suggest on that topic.
  • AranthysAranthys Member Posts: 722
    edited November 2013
    There should be a global windows variable that will tell you the "document" folder for the currently logged user if i'm not mistaken.

    Something like :
    %THAT_GLOBAL_VARIABLE%/games/Baldur's Gate : Enhanced Edition
    %THAT_GLOBAL_VARIABLE%/games/Baldur's Gate 2 : Enhanced Edition

    The "/games/Baldur's Gate : Enhanced Edition" parth is probably hardcoded, (if i'm not mistaken) and is in no way linked to the folder where the application has been installed.

    No idea for Linux or MacOS, but there should be something comparable there.
  • bardezbardez Member Posts: 41
    @Troodon80 I believe "00766" is the Beamdog ID for the application. It assuredly looked that way when using the Beamdog client to preload BG2:EE.
  • IsayaIsaya Member, Translator (NDA) Posts: 752
    Following WeiDU assumptions is probably the way to go. It was said several times that the developpers are using WeiDU and other community modding tools to build the game. So they can't go against it.
    As far as I know, WeiDU checks for the existence of files that are unique to each game to determine which game is installed in the current directory (from memory, mel01.cre for ToB, for instance). That is how the GAME_IS check is performed. I'm sure the list of these files was published in a discussion but I don't remember where that was. I may use other hints, such as the ini file name in order not to rely on a single test that could be deceived.

    Regarding the user directory, it's safe to assume that Beamdog can't change it now without breaking everybody's games. So one can apply the follow what's done principle once the game is released.
  • Troodon80Troodon80 Member, Developer Posts: 4,110
    bardez said:

    @Troodon80 I believe "00766" is the Beamdog ID for the application. It assuredly looked that way when using the Beamdog client to preload BG2:EE.

    @bardez, I have not tried downloading it via Steam, but if Steam does not use the same numerical sequence that Beamdog does then either it means that there is an extra check specifically for the Steam version, or it detects it through some other means other than the parent directory.
Sign In or Register to comment.