full rewrite of the loader

This commit is contained in:
Linventif 2023-09-20 15:15:20 +02:00
parent 43fdddc005
commit e9e1e354a8

View File

@ -1,5 +1,3 @@
//
if game.SinglePlayer() then return end if game.SinglePlayer() then return end
// //
@ -11,52 +9,79 @@ gmInte.version = "0.1.0"
gmInte.config = gmInte.config || {} gmInte.config = gmInte.config || {}
// //
// Files // Init Data Folder and Load Config
// //
// Load config if (SERVER) then
if SERVER then RunConsoleCommand("sv_hibernate_think", "1")
// Include all Server files
include("gmod_integration/sv_config.lua") if (file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA"))) then
// check if config exists, if not, create it
if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then
// create directory
file.CreateDir("gm_integration") file.CreateDir("gm_integration")
file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true))
end else
// if custom config exists, use it, else use default config if (gmInte.config.id && gmInte.config.id != "") then return end
if (!gmInte.config.id || gmInte.config.id == "") then
gmInte.config = util.JSONToTable(file.Read("gm_integration/config.json", "DATA")) local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA"))
if (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
end end
// //
// Load all files // Functions
// //
// Include all Shared files local function loadAllFiles(folder)
include("gmod_integration/shared/sh_http.lua") local files, folders = file.Find(folder .. "/*", "LUA")
include("gmod_integration/shared/sh_main.lua") for k, v in SortedPairs(files) do
include("gmod_integration/shared/sh_languages.lua") local path = folder .. "/" .. v
print("| Loading File: " .. path)
if string.StartWith(v, "cl_") then
if SERVER then
AddCSLuaFile(path)
else
include(path)
end
elseif string.StartWith(v, "sv_") then
if SERVER then
include(path)
end
elseif string.StartWith(v, "sh_") then
if SERVER then
AddCSLuaFile(path)
end
include(path)
end
end
for k, v in SortedPairs(folders, true) do
loadAllFiles(folder .. "/" .. v, name)
end
end
if SERVER then //
// Disable hibernate think // Load Files
RunConsoleCommand("sv_hibernate_think", "1") //
// Include all Server files print(" ")
include("gmod_integration/server/sv_main.lua") print(" ")
include("gmod_integration/server/sv_net.lua") print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
include("gmod_integration/server/sv_hook.lua") print(" - - ")
include("gmod_integration/server/sv_con.lua") print(" - Gmod Integration v" .. gmInte.version .. " - ")
print(" - Create by Linventif - ")
// Send all Shared files to the Client print(" - - ")
AddCSLuaFile("gmod_integration/shared/sh_http.lua") print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
AddCSLuaFile("gmod_integration/shared/sh_main.lua") print(" - - ")
AddCSLuaFile("gmod_integration/shared/sh_languages.lua") print(" - Thanks for using Gmod Integration ! - ")
print(" - If you have any questions, please contact us on Discord! - ")
// Send all Client files to the Client print(" - https://gmod-integration.com/discord - ")
AddCSLuaFile("gmod_integration/client/cl_main.lua") print(" - - ")
elseif CLIENT then print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
// Include all Client files print(" ")
include("gmod_integration/client/cl_main.lua") loadAllFiles("gmod_integration")
end print(" ")
print(" ")