Skip to content

Commit

Permalink
Core + Interfaces: CreateFileW => fopen_s which works on Win11 as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renee Koecher committed May 20, 2023
1 parent 9f5a937 commit 314a17b
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 109 deletions.
16 changes: 8 additions & 8 deletions XIPivot.Ashita_v4/polplugin/AshitaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace XiPivot

redirector.setDebugLog(m_settings.debugLog);
redirector.setRootPath(m_settings.rootPath.string());
redirector.setRedirectCreateFileW(m_settings.redirectCFW);
redirector.setRedirectFOpenS(m_settings.redirectFOpenS);

for (const auto& path : m_settings.overlays)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ namespace XiPivot
m_settings.rootPath = Core::Redirector::instance().rootPath();
m_settings.overlays = Core::Redirector::instance().overlayList();

m_settings.redirectCFW = Core::Redirector::instance().getRedirectCreateFileW();
m_settings.redirectFOpenS = Core::Redirector::instance().getRedirectFOpenS();

m_settings.cacheEnabled = Core::MemCache::instance().hooksActive();
m_settings.cacheSize = Core::MemCache::instance().getCacheAllocation();
Expand Down Expand Up @@ -238,7 +238,7 @@ namespace XiPivot

/* protected parts */

bool AshitaInterface::runCFWHook(const wchar_t*)
bool AshitaInterface::runFOpenSHook(const char*)
{
return m_ashitaCore->GetDirect3DDevice() != nullptr;
}
Expand Down Expand Up @@ -289,7 +289,7 @@ namespace XiPivot
rootPath = std::filesystem::current_path() / "DATs";
overlays.clear();
debugLog = false;
redirectCFW = false;
redirectFOpenS = true;
cacheEnabled = false;
cacheSize = 0;
cachePurgeDelay = 600;
Expand All @@ -303,11 +303,11 @@ namespace XiPivot
{
const char* rP = config->GetString(PluginName, "settings", "root_path");
const bool dbg = config->GetBool(PluginName, "settings", "debug_log", false);
const bool rCFW = config->GetBool(PluginName, "settings", "redirect_cfw", false);
const bool rFOS = config->GetBool(PluginName, "settings", "redirect_fopens", true);

debugLog = dbg;
rootPath = (rP ? rP : rootPath);
redirectCFW = rCFW;
redirectFOpenS = rFOS;

overlays.clear();

Expand Down Expand Up @@ -340,7 +340,7 @@ namespace XiPivot
log->logMessage(Core::IDelegate::LogLevel::Debug, ">> pivot settings <<");
log->logMessageF(Core::IDelegate::LogLevel::Debug, "root_path %s", rootPath.string().c_str());
log->logMessageF(Core::IDelegate::LogLevel::Debug, "debug_log %s", debugLog ? "true" : "false");
log->logMessageF(Core::IDelegate::LogLevel::Debug, "redirect_cfw %s", redirectCFW ? "true" : "false");
log->logMessageF(Core::IDelegate::LogLevel::Debug, "redirect_fopens %s", redirectFOpenS ? "true" : "false");
log->logMessage(Core::IDelegate::LogLevel::Debug, "overlays:");

for (unsigned i = 0; i < overlays.size(); ++i)
Expand All @@ -360,7 +360,7 @@ namespace XiPivot

config->SetValue(PluginName, "settings", "root_path", rootPath.string().c_str());
config->SetValue(PluginName, "settings", "debug_log", debugLog ? "true" : "false");
config->SetValue(PluginName, "settings", "redirect_cfw", redirectCFW ? "true" : "false");
config->SetValue(PluginName, "settings", "redirect_fopens", redirectFOpenS ? "true" : "false");

for (unsigned i = 0; i < overlays.size(); ++i)
{
Expand Down
6 changes: 3 additions & 3 deletions XIPivot.Ashita_v4/polplugin/AshitaInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace XiPivot
{
static constexpr auto PluginName = "pivot";
static constexpr auto PluginAuthor = "Heals";
static constexpr auto PluginVersion = 4.1501;
static constexpr auto PluginVersion = 4.1502;
static constexpr auto PluginUrl = "https://github.com/Shirk/XIPivot";
static constexpr auto PluginDescr = "Runtime DAT, sfx and bgm replacement manager.";
static constexpr auto PluginCommand = "pivot";
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace XiPivot
void logMessageF(Core::IDelegate::LogLevel level, std::string msg, ...) override;

protected:
virtual bool runCFWHook(const wchar_t* path) override;
virtual bool runFOpenSHook(const char* path) override;

private:

Expand All @@ -97,7 +97,7 @@ namespace XiPivot
uint32_t cacheSize;
uint32_t cachePurgeDelay;

bool redirectCFW;
bool redirectFOpenS;

bool dirty;
};
Expand Down
20 changes: 18 additions & 2 deletions XIPivot.Ashita_v4/polplugin/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace XiPivot
/* lazy update the GUI values */
m_guiState.flags.cacheEnable = Core::MemCache::instance().hooksActive();
m_guiState.flags.debugLog = Core::Redirector::instance().getDebugLog();
m_guiState.flags.redirectCFW = Core::Redirector::instance().getRedirectCreateFileW();
m_guiState.flags.redirectFOpenS = Core::Redirector::instance().getRedirectFOpenS();

m_guiState.values.cachePurgeDelay = static_cast<int32_t>(m_cachePurgeDelay);
m_guiState.values.cacheSizeMB = Core::MemCache::instance().getCacheAllocation() / 0x100000;
Expand Down Expand Up @@ -228,6 +228,14 @@ namespace XiPivot
}
settingsChanged = true;
}

if (redirector.getRedirectFOpenS() != m_guiState.flags.redirectFOpenS)
{
redirector.setRedirectFOpenS(m_guiState.flags.redirectFOpenS);

m_guiState.state.showRestartNotice = true;
settingsChanged = true;
}
}

/* handle cache purges as part of the cyclic process call */
Expand Down Expand Up @@ -293,6 +301,14 @@ namespace XiPivot
break;
}
}

if (m_guiState.state.showRestartNotice)
{
imgui->NewLine();
imgui->TextColored(ImVec4(1.0, 0.75, 0.55, 1.0), "Please restart your client for changes to take effect.");
imgui->NewLine();
}

imgui->End();
}

Expand Down Expand Up @@ -470,7 +486,7 @@ namespace XiPivot

void UserInterface::RenderAdvancedConfigUI(IGuiManager* const imgui)
{
imgui->Checkbox("redirect CreateFileW", &m_guiState.flags.redirectCFW);
imgui->Checkbox("redirect Ashita ResourceManager", &m_guiState.flags.redirectFOpenS);

imgui->NewLine();
imgui->TextDisabled("This flag causes pivot to try and redirect Ashita's access to DAT files.");
Expand Down
31 changes: 16 additions & 15 deletions XIPivot.Ashita_v4/polplugin/UserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,37 @@ namespace XiPivot
{
struct
{
bool debugLog;
bool cacheEnable;
bool redirectCFW;
bool debugLog = false;
bool cacheEnable = false;
bool redirectFOpenS = false;
} flags;

struct
{
int32_t cacheSizeMB;
int32_t cachePurgeDelay;
int32_t cacheSizeMB = 0;
int32_t cachePurgeDelay = 600;
struct Core::MemCache::CacheStatus cacheStats;
} values;

struct
{
std::string rootPath;
std::vector<std::string> allOverlays;
std::vector<std::string> activeOverlays;
std::string rootPath = "";
std::vector<std::string> allOverlays = {};
std::vector<std::string> activeOverlays = {};
} constants;

struct
{
std::string addOverlayName;
std::string deleteOverlayName;
std::string addOverlayName = "";
std::string deleteOverlayName = "";

bool showConfigWindow;
bool showCacheOverlay;
bool applyCacheChanges;
bool applyCLIChanges;
bool showConfigWindow = false;
bool showCacheOverlay = false;
bool applyCacheChanges = false;
bool applyCLIChanges = false;
bool showRestartNotice = false;

int activeTab;
int activeTab = 0;
} state;

} m_guiState;
Expand Down
1 change: 1 addition & 0 deletions XIPivot.Core/XIPivot.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)3rdParty\Microsoft.Detours\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
2 changes: 1 addition & 1 deletion XIPivot.Core/src/Delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace XiPivot

virtual void logMessage(LogLevel level, std::string message) = 0;
virtual void logMessageF(LogLevel level, std::string fmt, ...) = 0;
virtual bool runCFWHook(const wchar_t*) { return false; };
virtual bool runFOpenSHook(const char*) { return false; };
};

class DummyDelegate : public IDelegate
Expand Down
Loading

0 comments on commit 314a17b

Please sign in to comment.