Do not use SKSE messaging in the Steam DLL, TestMode is off by default

This commit is contained in:
Eddoursul 2022-09-20 13:56:38 +02:00
parent fec0932935
commit 6782dbcde9
8 changed files with 21 additions and 31 deletions

View File

@ -6,7 +6,7 @@ message("Using toolchain file ${CMAKE_TOOLCHAIN_FILE}.")
########################################################################################################################
project(
EnderalSteam
VERSION 1.0.0
VERSION 1.0.1
DESCRIPTION "Enderal SE Steam Support"
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)

View File

@ -10,7 +10,7 @@ namespace Achievements {
{
std::map<std::string, bool> settings{
{ "SendAchievementsToLE", false },
{ "TestMode", true },
{ "TestMode", false },
{ "ShowWarningOnInitFail", true }
};
LoadINI(&settings, "Data/SKSE/Plugins/EnderalSteam.ini");
@ -36,9 +36,9 @@ namespace Achievements {
bool success = SteamAPI_Init();
if (success) {
logger::info("Steam api init was successfull");
logger::info("{}", "Steam api init was successfull");
} else {
logger::error("Error while initializing the steam api");
logger::error("{}", "Error while initializing the steam api");
if (settings.at("ShowWarningOnInitFail")) {
RE::DebugMessageBox("Unable to initialize Steam achievements. Try to restart the game and the Steam client. This warning can be disabled in SKSE\\Plugins\\EnderalSteam.ini.");
}
@ -47,12 +47,12 @@ namespace Achievements {
SteamInstance(new AchievementHolder());
}
else {
logger::info("Already initialized steam api, skipping it");
logger::info("{}", "Already initialized steam api, skipping it");
}
}
catch (const std::exception& ex) {
std::string msg = "Exception while initializing the Steam API, steam achievements will not be available: " + std::string(ex.what());
logger::error(msg.c_str());
logger::error("{}", msg.c_str());
if (settings.at("ShowWarningOnInitFail")) {
RE::DebugMessageBox("Unable to initialize Steam achievements. Try to restart the game and the Steam client. This warning can be disabled in SKSE\\Plugins\\EnderalSteam.ini.");
}
@ -66,30 +66,30 @@ namespace Achievements {
void AchievementHolder::onUserStatsReceived(UserStatsReceived_t * event) {
try {
std::string msg = "User id: " + std::to_string(event->m_steamIDUser.ConvertToUint64()) + ", game id: " + std::to_string(event->m_nGameID) + ", success state: " + std::to_string(event->m_eResult);
logger::info(msg.c_str());
logger::info("{}", msg.c_str());
uint32 achievementCount = this->stats->GetNumAchievements();
msg = "There are " + std::to_string(achievementCount) + " achievements";
logger::info(msg.c_str());
logger::info("{}", msg.c_str());
}
catch (const std::exception& ex) {
std::string msg = "Exception during steam callback: onUserStatsReceived. Failed to print data: " + std::string(ex.what());
logger::info(msg.c_str());
logger::info("{}", msg.c_str());
}
}
bool AchievementHolder::setAchievementUnlocked(const char * achievementName)
{
std::string msg = "Unlocking achievement: " + std::string(achievementName);
logger::info(msg.c_str());
logger::info("{}", msg.c_str());
bool success = this->stats->SetAchievement(achievementName);
if (!success) {
logger::error("Error while unlocking achievement");
logger::error("{}", "Error while unlocking achievement");
return false;
}
success = this->stats->StoreStats();
if (!success) {
logger::error("Error while storing unlocked achievement");
logger::error("{}", "Error while storing unlocked achievement");
}
return success;
}

View File

@ -19,11 +19,9 @@ auto EventListener::ProcessEvent(
-> RE::BSEventNotifyControl
{
if (a_event->opening && a_event->menuName == "Main Menu") {
SKSE::GetTaskInterface()->AddTask([]() {
logger::info("Main menu opened, trying to init steam API.");
Achievements::startSteam();
});
RE::UI::GetSingleton()->RemoveEventSink<RE::MenuOpenCloseEvent>(GetSingleton());
logger::info("{}", "Main menu opened, trying to init steam API.");
Achievements::startSteam();
}
return RE::BSEventNotifyControl::kContinue;

View File

@ -24,15 +24,6 @@ namespace {
spdlog::set_default_logger(std::move(log));
spdlog::set_pattern("[%l] %v"s);
}
void InitializeMessaging()
{
GetMessagingInterface()->RegisterListener([](MessagingInterface::Message* message) {
if (message->type == MessagingInterface::kPostLoad) {
EventListener::Install();
}
});
}
}
SKSEPluginLoad(const LoadInterface* skse) {
@ -46,7 +37,8 @@ SKSEPluginLoad(const LoadInterface* skse) {
logger::info("{} {} is loading...", plugin->GetName(), version);
Init(skse);
InitializeMessaging();
EventListener::Install();
GetPapyrusInterface()->Register(Papyrus::Bind);

View File

@ -6,7 +6,7 @@ namespace Papyrus
bool Bind(VM* a_vm)
{
if (!a_vm) {
logger::critical("couldn't get VM State"sv);
logger::critical("{}", "couldn't get VM State"sv);
return false;
}

View File

@ -11,7 +11,7 @@ namespace Papyrus::PapyrusFunctions
return SteamInstance()->setAchievementUnlocked(achievement.c_str());
} else {
RE::DebugNotification(std::format("Achievement unlocked: {}", achievement.c_str()).c_str());
logger::info(std::format("Achievement unlocked: {}", achievement.c_str()).c_str());
logger::info("{}", std::format("Achievement unlocked: {}", achievement.c_str()).c_str());
return true;
}
}
@ -19,6 +19,6 @@ namespace Papyrus::PapyrusFunctions
inline void Bind(VM& a_vm)
{
BIND(CallUnlockAchievement);
logger::info("Registered CallUnlockAchievement"sv);
logger::info("{}", "Registered CallUnlockAchievement"sv);
}
}

View File

@ -73,6 +73,6 @@ inline void LoadINI(std::map<std::string, bool>* settings, const char* iniPath)
}
} catch (const std::exception& e) {
logger::error(e.what());
logger::error("{}", e.what());
}
}

View File

@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
"name": "enderal-se-steam",
"version-string": "1.0.0",
"version-string": "1.0.1",
"port-version": 0,
"description": "Enderal SE Steam Support",
"homepage": "https://eddoursul.win/mods/enderal-se/",