Jump to content

SaveConfig() and StaticSaveConfig() not writing to files?


bunnytrain

Recommended Posts

I'm testing some in-game configuration settings, and I'm noticing a phenomenon where the XCom****.ini file that the game is reading my settings from is not getting updated when I call SaveConfig().

 

The relevant code looks like this:

class MCM_TestHarness extends UIScreenListener config(ModConfigMenu);

var config bool ENABLE_TEST_HARNESS;
var config bool P2G2C_SETTING;

// [ Bunch of code snipped out ]

function SaveButtonClicked(MCM_API_SettingsPage Page)
{
    `log("MCM: Save button clicked on page " $ string(Page.GetPageID()));
    self.P2G2C_SETTING = false;
    self.SaveConfig();
}

// [ Bunch of code snipped out ]

defaultproperties
{
    ScreenClass = class'MCM_OptionsScreen';
}

I'm testing it this way: I edit the file "XCOM 2\XComGame\Mods\ModConfigMenu\Config\XComModConfigMenu.ini" to set "P2G2C_SETTING=true", then run this such that in theory it should save a "false" value into the INI file. Then I close out of XCom 2.

 

When I go to inspect the INI file, it still says "P2G2C_SETTING=true". There's no "XComModConfigMenu.ini" file in "My Games\XCOM2\XComGame\Config" either.

 

Am I doing something wrong? Should it be called "DefaultModConfigMenu.ini" instead?

 

You can see the file (and the whole codebase) in its entirety here, but I've dumbed down the test case as much as I thought I possibly could. https://github.com/andrewgu/ModConfigMenu/blob/API_Revision_Staging/ModConfigMenu/ModConfigMenu/Src/ModConfigMenu/Classes/MCM_TestHarness.uc

Link to comment
Share on other sites

I'm curious if you're still trying to resolve this, or if you've come up with a solution.

 

In my testing, I haven't been able to figure out a reliable method of making a single class able to read from the mod's Config/ directory, while writing to the user's Config/ directory. Basically what I've experienced is that for SaveConfig(), if you try and load a configuration file from either the Mod-C directory or the User-C directory, the behavior is as follows. The only changes between these four tests, is what configuration files exist prior to running the test.

    Files Present  Reads From  Writes To
    Mod-Config/     Mod-C       nothing
    User-Config/    User-C      User-C
    Neither         nothing     User-C
    Both            Mod-C       nothing

I haven't looked in to StaticSaveConfig() all that much, because I don't really plan on needing to write to the mod's Config/ directory when the user's Config/ directory is available, but it has put me in a weird position where I honestly couldn't figure out how to make a single class read from Mod-C and write to User-C.

 

What I ended up doing was just create a configuration base class, and extend it twice, once for Mod-Config loading and once for User-Config saving:

class BaseConfig extends Object config(DoesntMatter);
var config bool IS_LOADED;
var config bool SOME_OPTION;


class ModConfig extends BaseConfig config(ActualConfigFile_Default);


class UserConfig extends BaseConfig config(ActualConfigFile);


function BaseConfig LoadConfig() {
  ModC = new class'ModConfig';
  UserC = new class'UserConfig';
  if (!UserC.IS_LOADED) {
    if (!ModC.IS_LOADED) {
      `log("No configuration available!");
      // could load reasonable defaults instead of failing
      //UserC.LoadReasonableDefaults();
      //UserC.SaveConfig();
      return None;
    } else {
      UserC.LoadFrom(ModC);
      UserC.SaveConfig();
    }
  }
  return UserC;
}

If the Mod-C configuration file is pre-created and called XComGameActualConfigFile_Default.ini, then the User-C configuration file (called XComGameActualConfigFile.ini) will load from itself if it exists, or manually load from the Mod-C if the User-C does not exist. Just make sure that IS_LOADED=true, which is the main flag that indicates that the configuration was loaded from the particular directory successfully.

 

But, if you have any particular insights, this is something that I would be interested in! This feels like a bit of a hacky solution, like I am missing something in UnrealScript that isn't properly documented, or maybe some of the C++ code would shed light on all this. For example, I'm pretty sure that localized text can't load unless the class also loads a configuration variable from a valid file. No idea why, but I couldn't get it to work at all until I did that.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...