mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-16 00:44:36 +01:00
Update static data, and don't hard code it
This commit is contained in:
64
nksrv/Utils/GameConfig.cs
Normal file
64
nksrv/Utils/GameConfig.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Newtonsoft.Json;
|
||||
using Swan.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace nksrv.Utils
|
||||
{
|
||||
public class GameConfigRoot
|
||||
{
|
||||
public StaticData StaticData { get; set; } = new();
|
||||
public string ResourceBaseURL { get; set; } = "";
|
||||
}
|
||||
|
||||
public class StaticData
|
||||
{
|
||||
public string Url { get; set; } = "";
|
||||
public string Version { get; set; } = "";
|
||||
public string Salt1 { get; set; } = "";
|
||||
public string Salt2 { get; set; } = "";
|
||||
|
||||
|
||||
public byte[] GetSalt1Bytes()
|
||||
{
|
||||
return Convert.FromBase64String(Salt1);
|
||||
}
|
||||
public byte[] GetSalt2Bytes()
|
||||
{
|
||||
return Convert.FromBase64String(Salt2);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GameConfig
|
||||
{
|
||||
private static GameConfigRoot? _root;
|
||||
public static GameConfigRoot Root
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_root == null)
|
||||
{
|
||||
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/gameconfig.json"))
|
||||
{
|
||||
Logger.Error("Gameconfig.json is not found, the game WILL NOT work!");
|
||||
_root = new GameConfigRoot();
|
||||
}
|
||||
Logger.Info("Loaded game config");
|
||||
|
||||
|
||||
_root = JsonConvert.DeserializeObject<GameConfigRoot>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/gameconfig.json"));
|
||||
|
||||
if (_root == null)
|
||||
{
|
||||
throw new Exception("Failed to read gameconfig.json");
|
||||
}
|
||||
}
|
||||
|
||||
return _root;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user