From 359babd7782dfeece5e6ff40907a3c6f982461ac Mon Sep 17 00:00:00 2001
From: Linventif <linventif@gmail.com>
Date: Sat, 23 Sep 2023 03:40:50 +0200
Subject: [PATCH] load config after loading file

---
 lua/autorun/gmod_integration.lua | 50 +++++++++++++++++---------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/lua/autorun/gmod_integration.lua b/lua/autorun/gmod_integration.lua
index d3ca846..5fdd074 100644
--- a/lua/autorun/gmod_integration.lua
+++ b/lua/autorun/gmod_integration.lua
@@ -8,30 +8,6 @@ gmInte = gmInte || {}
 gmInte.version = "0.1.1"
 gmInte.config = gmInte.config || {}
 
-//
-// Init Data Folder and Load Config
-//
-
-if (SERVER) then
-	RunConsoleCommand("sv_hibernate_think", "1")
-
-    if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then
-        file.CreateDir("gm_integration")
-        file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
-    else
-        if (gmInte.config.id && gmInte.config.id != "") then return end
-
-        local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA"))
-        if (!oldConfig.version || (oldConfig.version < gmInte.version)) then
-            gmInte.config = table.Merge(gmInte.config, oldConfig)
-            gmInte.config.version = gmInte.version
-            file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
-        else
-            gmInte.config = oldConfig
-        end
-    end
-end
-
 //
 // Functions
 //
@@ -84,3 +60,29 @@ print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
 print(" ")
 loadAllFiles("gmod_integration")
 print(" ")
+
+//
+// Init Data Folder and Load Config
+//
+
+if (SERVER) then
+	RunConsoleCommand("sv_hibernate_think", "1")
+
+    if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then
+        file.CreateDir("gm_integration")
+        file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
+    else
+        if (gmInte.config.id && gmInte.config.id != "") then return end
+
+        local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA"))
+        if (!oldConfig.version || (oldConfig.version < gmInte.version)) then
+            PrintTable(gmInte.config)
+            table.Merge(gmInte.config, oldConfig)
+            PrintTable(gmInte.config)
+            gmInte.config.version = gmInte.version
+            file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
+        else
+            gmInte.config = oldConfig
+        end
+    end
+end
\ No newline at end of file