Skip to content

Commit

Permalink
Ashita: v4 allow custom ini-basename via polplugins.args
Browse files Browse the repository at this point in the history
  • Loading branch information
Renee Koecher committed Dec 30, 2022
1 parent d732066 commit dd48de2
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 28 deletions.
50 changes: 39 additions & 11 deletions XIPivot.Ashita_v4/polplugin/AshitaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,29 @@

#include <regex>
#include <iostream>
#include <string>

namespace XiPivot
{
namespace Pol
{
AshitaInterface::AshitaInterface(const char* args)
: IPolPlugin(),
m_pluginArgs(args ? args : "")
: IPolPlugin()
{
if (args != nullptr)
{
const std::string arg_string(args);
std::stringstream arg_stream(arg_string);
std::istream_iterator<std::string> args_begin(arg_stream);
std::istream_iterator<std::string> args_end;

m_pluginArgs = std::vector<std::string>(args_begin, args_end);

}
if (m_pluginArgs.empty())
{
m_pluginArgs = { "pivot" };
}
}

const char* AshitaInterface::GetName(void) const { return PluginName; }
Expand All @@ -64,7 +78,13 @@ namespace XiPivot

redirector.setLogProvider(this);

m_settingsPath = std::filesystem::path(m_ashitaCore->GetInstallPath()) / "config" / "pivot" / "pivot.ini";
// we support only a single argument which is the config file basename and defaults to 'pivot'
auto configFileName = std::filesystem::path(m_pluginArgs.at(0)).stem().replace_extension(".ini").string();

m_settingsRelPath = std::filesystem::path("pivot") / configFileName;
m_settingsPath = std::filesystem::path(m_ashitaCore->GetInstallPath()) / "config" / m_settingsRelPath;

logMessageF(LogLevel::Info, "Using config file: '%s'", m_settingsPath.string().c_str());

auto config = m_ashitaCore->GetConfigurationManager();
if (config != nullptr)
Expand All @@ -75,10 +95,10 @@ namespace XiPivot
return false;
}

if (!m_settings.load(config))
if (!m_settings.load(config, m_settingsRelPath))
{
logMessageF(LogLevel::Warn, "Failed to load config file, saving defaults instead");
m_settings.save(config, m_settingsPath);
m_settings.save(config, m_settingsRelPath, m_settingsPath);
}
m_settings.dump(this);

Expand All @@ -99,7 +119,7 @@ namespace XiPivot
memCache.setDebugLog(m_settings.debugLog);
memCache.setCacheAllocation(m_settings.cacheSize);
}
m_settings.save(config, m_settingsPath);
m_settings.save(config, m_settingsRelPath, m_settingsPath);
}

if (m_settings.cacheEnabled)
Expand Down Expand Up @@ -157,7 +177,7 @@ namespace XiPivot
m_settings.cacheSize = Core::MemCache::instance().getCacheAllocation();
m_settings.cachePurgeDelay = static_cast<uint32_t>(m_ui.getCachePurgeDelay());

m_settings.save(m_ashitaCore->GetConfigurationManager(), m_settingsPath);
m_settings.save(m_ashitaCore->GetConfigurationManager(), m_settingsRelPath, m_settingsPath);
m_settings.dump(this);
}

Expand Down Expand Up @@ -276,10 +296,10 @@ namespace XiPivot
dirty = false;
}

bool AshitaInterface::Settings::load(IConfigurationManager* config)
bool AshitaInterface::Settings::load(IConfigurationManager* config, const std::filesystem::path& relPath)
{
dirty = false;
if (config->Load(PluginName, ConfigPath))
if (config->Load(PluginName, relPath.string().c_str()))
{
const char* rP = config->GetString(PluginName, "settings", "root_path");
const bool dbg = config->GetBool(PluginName, "settings", "debug_log", false);
Expand Down Expand Up @@ -334,7 +354,7 @@ namespace XiPivot
log->logMessageF(Core::IDelegate::LogLevel::Debug, "");
}

void AshitaInterface::Settings::save(IConfigurationManager* config, const std::filesystem::path& absPath)
void AshitaInterface::Settings::save(IConfigurationManager* config, const std::filesystem::path& relPath, const std::filesystem::path& absPath)
{
config->Delete(PluginName);

Expand All @@ -361,10 +381,18 @@ namespace XiPivot

if (std::filesystem::exists(absPath))
{
std::filesystem::permissions(absPath,
std::filesystem::perms::owner_all | std::filesystem::perms::group_all,
std::filesystem::perm_options::replace);
std::filesystem::remove(absPath);
}

config->Save(PluginName, ConfigPath);
config->Save(PluginName, relPath.string().c_str());

std::filesystem::permissions(absPath,
std::filesystem::perms::owner_write | std::filesystem::perms::group_write | std::filesystem::perms::others_write,
std::filesystem::perm_options::remove);

dirty = false;
}
}
Expand Down
19 changes: 9 additions & 10 deletions XIPivot.Ashita_v4/polplugin/AshitaInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,10 @@ namespace XiPivot

struct Settings
{
static constexpr auto ConfigPath = "pivot\\pivot.ini";

Settings();

bool load(IConfigurationManager* config);
void save(IConfigurationManager* config, const std::filesystem::path& absPath);
bool load(IConfigurationManager* config, const std::filesystem::path& relPath);
void save(IConfigurationManager* config, const std::filesystem::path& relPath, const std::filesystem::path& absPath);
void dump(Core::IDelegate* log);

bool debugLog;
Expand All @@ -104,13 +102,14 @@ namespace XiPivot
bool dirty;
};

IAshitaCore* m_ashitaCore = nullptr;
ILogManager* m_logManager = nullptr;
IAshitaCore* m_ashitaCore = nullptr;
ILogManager* m_logManager = nullptr;

std::string m_pluginArgs;
std::filesystem::path m_settingsPath;
Settings m_settings;
UserInterface m_ui;
std::vector<std::string> m_pluginArgs;
std::filesystem::path m_settingsRelPath;
std::filesystem::path m_settingsPath;
Settings m_settings;
UserInterface m_ui;
};
}
}
Expand Down
25 changes: 18 additions & 7 deletions XIPivot.Ashita_v4/resources/docs/pivot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ The goals behind XIPivot are simple:
- 5) -- OPTIONAL --
- Instead of following 4) you can use the command `/pivot` in-game to open the configuration GUI

## Using a custom configuration in your ashita profile

If required you can specify the basename for pivots configuration file (the default is 'pivot').
This can be used to have different pivot settings for different Ashita .ini files:

- 1) Open your ashita profile and find the section `[ashita.polplugins.args]`
- 2) add a line like this: `pivot = foobar`

In this case `foobar` is the name of your custom configuration and pivot will look for `<ashita>\config\pivot\foobar.ini`.


### Example - XI-View, XI-Vision and Ammelila's HD-Remake:

Directory structure:
Expand Down Expand Up @@ -75,10 +86,10 @@ debug_log=false
[cache]
enabled=true
max_age=600
size=512
size=128
```

XIPivot defaults to look for your overlays inside the `DATs/` directory next to the `pivot.dll`.
Pivot defaults to look for your overlays inside the `DATs/` directory next to the `pivot.dll`.
If you prefer a different path you can add the key `'root_path'` to `pivot.ini` like so:

```ini
Expand All @@ -92,17 +103,17 @@ root_path=C:\my\awesome\addons
2=FFXI-HD

[cache]
enabled=true
enabled=false
max_age=600
size=512
size=128
```

This instructs to XIPivot to search for overlays inside `"C:\my\awesome\addons"` instead.
This instructs to pivot to search for overlays inside `"C:\my\awesome\addons"` instead.
(If you're unsure **don't set this parameter** and things should just work).

## In-Game commands

XIPivot makes the in-game command `/pivot` available to load and unload overlays at runtime.
Pivot makes the in-game command `/pivot` available to load and unload overlays at runtime.
If the command `/pivot` is used without parameters it will open an in-game GUI for configuration.

The following parameters are supported:
Expand Down Expand Up @@ -147,6 +158,6 @@ Currently none known

## Disclaimer

I tested XIPivot to the best of my capabilities but I can not guarantee that it works without bugs for 100% of the time.
I tested Pivot to the best of my capabilities but I can not guarantee that it works without bugs for 100% of the time.
Use at your own discretion, I take no responsibility for any client crashes or data loss.

0 comments on commit dd48de2

Please sign in to comment.