Skip to content

Commit

Permalink
Use available mods over loaded ones where relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
piepie62 committed Aug 22, 2024
1 parent 5f8f1de commit f0896b1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion BG3Extender/Extender/Shared/ExtensionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ namespace bg3se
}

lua::Restriction restriction(*lua, lua::State::RestrictAll);
for (auto const& mod : modManager->BaseModule.LoadOrderedModules) {
for (auto const& mod : modManager->AvailableMods) {
auto configIt = modConfigs_.find(mod.Info.ModuleUUIDString);
if (configIt != modConfigs_.end()) {
auto const & config = configIt->second;
Expand Down
2 changes: 1 addition & 1 deletion BG3Extender/Extender/Shared/StatLoadOrderHelper.inl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void StatLoadOrderHelper::UpdateModDirectoryMap()

auto modManager = gExtender->GetCurrentExtensionState()->GetModManager();
if (modManager) {
for (auto const& mod : modManager->BaseModule.LoadOrderedModules) {
for (auto const& mod : modManager->AvailableMods) {
modDirectoryToModMap_.insert(std::make_pair(mod.Info.Directory, mod.Info.ModuleUUIDString));
}
}
Expand Down
6 changes: 3 additions & 3 deletions BG3Extender/Extender/Shared/UserVariables.inl
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ void ModVariableManager::OnSessionLoading()
auto modManager = isServer_ ? GetStaticSymbols().GetModManagerServer() : GetStaticSymbols().GetModManagerClient();
if (modManager != nullptr) {
uint32_t nextIndex{ 0 };
for (auto const& mod : modManager->BaseModule.LoadOrderedModules) {
for (auto const& mod : modManager->AvailableMods) {
modIndices_.set(mod.Info.ModuleUUID, nextIndex++);
}
} else {
Expand Down Expand Up @@ -1291,9 +1291,9 @@ CachedModVariableManager::~CachedModVariableManager()
Guid CachedModVariableManager::ModIndexToGuid(uint32_t modIndex)
{
if (isServer_) {
return GetStaticSymbols().GetModManagerServer()->BaseModule.LoadOrderedModules[modIndex].Info.ModuleUUID;
return GetStaticSymbols().GetModManagerServer()->AvailableMods[modIndex].Info.ModuleUUID;
} else {
return GetStaticSymbols().GetModManagerClient()->BaseModule.LoadOrderedModules[modIndex].Info.ModuleUUID;
return GetStaticSymbols().GetModManagerClient()->AvailableMods[modIndex].Info.ModuleUUID;
}
}

Expand Down
2 changes: 1 addition & 1 deletion BG3Extender/GameDefinitions/GameHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace bg3se
return nullptr;
}

for (auto const& mod : BaseModule.LoadOrderedModules) {
for (auto const& mod : AvailableMods) {
if (mod.Info.ModuleUUIDString == modUuidFS) {
return &mod;
}
Expand Down
48 changes: 46 additions & 2 deletions BG3Extender/Lua/Libs/Mod.inl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,48 @@ bool IsModLoaded(FixedString modNameGuid)
return false;
}

/// <summary>
/// Returns whether the module with the specified GUID is available, i.e. in the mod directory.
///
/// Example:
/// ```lua
/// if (Ext.IsModAvailable("5cc23efe-f451-c414-117d-b68fbc53d32d")) then
/// Ext.Print("Mod available")
/// end
/// ```
/// </summary>
/// <param name="modNameGuid">UUID of mod to check</param>
bool IsModAvailable(char const* modNameGuid)
{
auto modUuid = Guid::Parse(modNameGuid);
if (modUuid) {
auto modManager = gExtender->GetCurrentExtensionState()->GetModManager();
for (auto const& mod : modManager->AvailableMods) {
if (mod.Info.ModuleUUID == *modUuid) {
return true;
}
}
}

return false;
}

/// <summary>
/// Returns the list of available module UUIDs.
/// </summary>
/// <returns></returns>
ObjectSet<Guid> GetAvailableMods()
{
ObjectSet<Guid> mods;
auto modManager = gExtender->GetCurrentExtensionState()->GetModManager();

for (auto const& mod : modManager->AvailableMods) {
mods.Add(mod.Info.ModuleUUID);
}

return mods;
}

/// <summary>
/// Returns the list of loaded module UUIDs in the order they're loaded in.
/// </summary>
Expand All @@ -52,7 +94,7 @@ Array<FixedString> GetLoadOrder()
}

/// <summary>
/// Returns detailed information about the specified (loaded) module.
/// Returns detailed information about the specified (available) module.
/// </summary>
/// <param name="modNameGuid">Mod UUID to query</param>
Module* GetMod(FixedString modNameGuid)
Expand All @@ -61,7 +103,7 @@ Module* GetMod(FixedString modNameGuid)

auto modUuid = Guid::Parse(modNameGuid.GetStringView());
if (modUuid) {
for (auto& mod : modManager->BaseModule.LoadOrderedModules) {
for (auto& mod : modManager->AvailableMods) {
if (mod.Info.ModuleUUID == *modUuid) {
return &mod;
}
Expand Down Expand Up @@ -92,7 +134,9 @@ void RegisterModLib()
DECLARE_MODULE(Mod, Both)
BEGIN_MODULE()
MODULE_FUNCTION(IsModLoaded)
MODULE_FUNCTION(IsModAvailable)
MODULE_FUNCTION(GetLoadOrder)
MODULE_FUNCTION(GetAvailableMods)
MODULE_FUNCTION(GetMod)
MODULE_FUNCTION(GetBaseMod)
MODULE_FUNCTION(GetModManager)
Expand Down

0 comments on commit f0896b1

Please sign in to comment.