From e50c3abff4cef66267cf7453f6585af73ecd8db4 Mon Sep 17 00:00:00 2001
From: Oleksandr Nemesh <prevter@gmail.com>
Date: Fri, 12 Apr 2024 22:45:08 +0300
Subject: [PATCH] Fix loading bar going out of bounds (#688)

The actual reason lies in the loader implementation, which for some reason can sometimes count up the `m_refreshedModCount` twice for some mods which are disabled.

This small change checks the actual loaded mod count instead of relying on an incorrect `LoaderImpl` member and fixes issue #687.
---
 loader/src/hooks/LoadingLayer.cpp | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/loader/src/hooks/LoadingLayer.cpp b/loader/src/hooks/LoadingLayer.cpp
index fb7a86a1..8822c4da 100644
--- a/loader/src/hooks/LoadingLayer.cpp
+++ b/loader/src/hooks/LoadingLayer.cpp
@@ -146,13 +146,27 @@ struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
         LoaderImpl::get()->updateResources(true);
         this->continueLoadAssets();
     }
+
+    int getLoadedMods() {
+        auto allMods = Loader::get()->getAllMods();
+        return std::count_if(allMods.begin(), allMods.end(), [&](auto& item) {
+            return item->isEnabled();
+        });
+    }
+
+    int getEnabledMods() {
+        auto allMods = Loader::get()->getAllMods();
+        return std::count_if(allMods.begin(), allMods.end(), [&](auto& item) {
+            return item->shouldLoad();
+        });
+    }
     
     int getCurrentStep() {
-        return m_fields->m_geodeLoadStep + m_loadStep + 1 + LoaderImpl::get()->m_refreshedModCount;
+        return m_fields->m_geodeLoadStep + m_loadStep + getLoadedMods();
     }
 
     int getTotalStep() {
-        return 18 + m_fields->m_totalMods;
+        return 3 + 14 + getEnabledMods();
     }
 
     void updateLoadingBar() {