v1.1.5
This commit is contained in:
parent
714624d96a
commit
2102f0581f
96 changed files with 1279 additions and 413 deletions
|
|
@ -10,18 +10,13 @@ namespace jRandomSkills
|
|||
{
|
||||
public static class Config
|
||||
{
|
||||
private static readonly string configPath = Path.Combine(Instance.ModuleDirectory, "Config.json");
|
||||
private static readonly string configsFolder = Path.Combine(Instance.ModuleDirectory, "configs");
|
||||
private static readonly string configPath = Path.Combine(configsFolder, "config.json");
|
||||
private static ConfigModel config = LoadConfig();
|
||||
private static FileSystemWatcher? fileWatcher;
|
||||
|
||||
public static ConfigModel LoadedConfig => config;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
SetupFileWatcher();
|
||||
}
|
||||
|
||||
private static ConfigModel LoadConfig()
|
||||
public static ConfigModel LoadConfig()
|
||||
{
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
|
|
@ -64,6 +59,7 @@ namespace jRandomSkills
|
|||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(configsFolder);
|
||||
string json = JsonConvert.SerializeObject(config, Formatting.Indented);
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
|
|
@ -73,20 +69,6 @@ namespace jRandomSkills
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetupFileWatcher()
|
||||
{
|
||||
string? path = Path.GetDirectoryName(configPath);
|
||||
if (string.IsNullOrEmpty(path)) return;
|
||||
fileWatcher = new FileSystemWatcher(path)
|
||||
{
|
||||
Filter = Path.GetFileName(configPath),
|
||||
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size
|
||||
};
|
||||
|
||||
fileWatcher.Changed += (sender, e) => config = LoadConfig();
|
||||
fileWatcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
public static T GetValue<T>(object skill, string key)
|
||||
{
|
||||
var skillConfig = config.SkillsInfo.FirstOrDefault(s => s.Name == skill.ToString());
|
||||
|
|
@ -143,12 +125,18 @@ namespace jRandomSkills
|
|||
public string? AlternativeSkillButton { get; set; }
|
||||
public float SkillTimeBeforeStart { get; set; }
|
||||
public float SkillDescriptionDuration { get; set; }
|
||||
public bool DisableSpectateHUD { get; set; }
|
||||
public bool FlashingHtmlHudFix { get; set; }
|
||||
public bool CS2TraceRayDebug { get; set; }
|
||||
|
||||
public NormalCommand SetSkillCommands { get; set; }
|
||||
public NormalCommand SkillsListCommands { get; set; }
|
||||
public NormalCommand UseSkillCommands { get; set; }
|
||||
public NormalCommand HealCommands { get; set; }
|
||||
public NormalCommand ConsoleCommands { get; set; }
|
||||
public NormalCommand SetStaticSkillCommands { get; set; }
|
||||
public NormalCommand ChangeLanguageCommands { get; set; }
|
||||
public NormalCommand ReloadCommands { get; set; }
|
||||
public VotingCommand StartGameCommands { get; set; }
|
||||
public VotingCommand ChangeMapCommands { get; set; }
|
||||
public VotingCommand SwapCommands { get; set; }
|
||||
|
|
@ -167,6 +155,9 @@ namespace jRandomSkills
|
|||
AlternativeSkillButton = null;
|
||||
SkillTimeBeforeStart = 7;
|
||||
SkillDescriptionDuration = 7;
|
||||
FlashingHtmlHudFix = true;
|
||||
CS2TraceRayDebug = false;
|
||||
DisableSpectateHUD = false;
|
||||
|
||||
SetSkillCommands = new NormalCommand("ustawskill, ustaw_skill, setskill, set_skill, definirhabilidade, configurarhabilidade, 设置技能, 配置技能", "@jRandmosSkills/admin");
|
||||
SkillsListCommands = new NormalCommand("supermoc, skille, listamocy, supermoce, skills, listaHabilidades, habilidades, 技能列表, 超能力列表", "@jRandmosSkills/admin");
|
||||
|
|
@ -174,6 +165,8 @@ namespace jRandomSkills
|
|||
HealCommands = new NormalCommand("heal, ulecz, curar, tratar, 治疗, 治愈", "@jRandmosSkills/admin");
|
||||
ConsoleCommands = new NormalCommand("console, sv, 控制台, 服务器", "@jRandmosSkills/root");
|
||||
SetStaticSkillCommands = new NormalCommand("ustawstatycznyskill, ustaw_statyczny_skill, setstaticskill, set_static_skill", "@jRandmosSkills/admin");
|
||||
ChangeLanguageCommands = new NormalCommand("lang, language, changelang, change_lang, jezyk, język", "");
|
||||
ReloadCommands = new NormalCommand("reload, refresh", "@jRandmosSkills/admin");
|
||||
|
||||
StartGameCommands = new VotingCommand(true, "start, go, começar, iniciar, 开始, 启动", "@jRandmosSkills/admin", 15, 60, 15, 500, 2);
|
||||
ChangeMapCommands = new VotingCommand( true, "map, mapa, changemap, zmienmape, zmienmape, mudarMapa, trocarMapa, 更换地图, 更改地图", "@jRandmosSkills/admin", 25, 90, 15, 500, 2);
|
||||
|
|
|
|||
|
|
@ -25,16 +25,15 @@ public class FindTarget
|
|||
|
||||
if (targetresult.Players.Count == 0)
|
||||
{
|
||||
if (!ignoreMessage)
|
||||
{
|
||||
command.ReplyToCommand(Localization.GetTranslation("no_player"));
|
||||
}
|
||||
if (!ignoreMessage && command.CallingPlayer != null)
|
||||
command.ReplyToCommand(command.CallingPlayer.GetTranslation("no_player"));
|
||||
|
||||
return (new List<CCSPlayerController>(), string.Empty);
|
||||
}
|
||||
else if (singletarget && targetresult.Players.Count > 1)
|
||||
{
|
||||
command.ReplyToCommand(Localization.GetTranslation("duplicate_player"));
|
||||
if (command.CallingPlayer != null)
|
||||
command.ReplyToCommand(command.CallingPlayer.GetTranslation("duplicate_player"));
|
||||
return (new List<CCSPlayerController>(), string.Empty);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,47 @@
|
|||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using jRandomSkills.src.player;
|
||||
using MaxMind.Db;
|
||||
using Newtonsoft.Json;
|
||||
using System.Text.Json;
|
||||
using System.Net;
|
||||
|
||||
namespace jRandomSkills.src.utils
|
||||
{
|
||||
public static class Localization
|
||||
{
|
||||
private static readonly string path = Path.Combine(jRandomSkills.Instance.ModuleDirectory, "lang");
|
||||
private static readonly string languagesFolderPath = Path.Combine(jRandomSkills.Instance.ModuleDirectory, "languages");
|
||||
private static readonly Dictionary<string, Dictionary<string, string>> _translations = [];
|
||||
private static string langCode = "pl";
|
||||
|
||||
private static readonly string playersLanguageFileName = "playersLanguage.json";
|
||||
private static readonly string configsFolderPath = Path.Combine(jRandomSkills.Instance.ModuleDirectory, "configs");
|
||||
private static Dictionary<ulong, string> _playersLanguage = [];
|
||||
private static readonly string geoliteFilePath = Path.Combine(jRandomSkills.Instance.ModuleDirectory, "packages", "GeoLite2-Country.mmdb");
|
||||
public static readonly string[] chinaIsoCodes = ["CN", "TW", "HK", "MO", "SG"];
|
||||
public static readonly string[] portugalIsoCodes = ["PT", "BR", "AO", "CV", "GW", "MZ", "ST", "TL"];
|
||||
|
||||
private static string defaultLangCode = "en";
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
_translations.Clear();
|
||||
_playersLanguage.Clear();
|
||||
SetLangCode();
|
||||
LoadAllLanguages();
|
||||
LoadPlayersLanguage();
|
||||
}
|
||||
|
||||
|
||||
private static void SetLangCode()
|
||||
{
|
||||
langCode = Config.LoadedConfig.Settings.LangCode;
|
||||
defaultLangCode = Config.LoadedConfig.Settings.LangCode;
|
||||
}
|
||||
|
||||
private static void LoadAllLanguages()
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
if (!Directory.Exists(languagesFolderPath))
|
||||
return;
|
||||
|
||||
foreach (var file in Directory.GetFiles(path, "*.json"))
|
||||
foreach (var file in Directory.GetFiles(languagesFolderPath, "*.json"))
|
||||
LoadLanguage(file);
|
||||
}
|
||||
|
||||
|
|
@ -44,8 +58,54 @@ namespace jRandomSkills.src.utils
|
|||
_translations[code] = translations;
|
||||
}
|
||||
|
||||
public static string GetTranslation(string key, params object[] args)
|
||||
public static bool HasTranslation(string code)
|
||||
{
|
||||
return _translations.ContainsKey(code);
|
||||
}
|
||||
|
||||
public static string GetSkillName(this CCSPlayerController player, Skills skill)
|
||||
{
|
||||
string langCode = GetLangCode(player);
|
||||
return GetTranslation(skill.ToString().ToLower(), langCode);
|
||||
}
|
||||
|
||||
public static string GetSkillDescription(this CCSPlayerController player, Skills skill)
|
||||
{
|
||||
string langCode = GetLangCode(player);
|
||||
return GetTranslation($"{skill.ToString().ToLower()}_desc", langCode);
|
||||
}
|
||||
|
||||
public static void PrintTranslationToChatAll(string message, string[]? key, params object[][]? args)
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers().Where(p => !p.IsBot))
|
||||
{
|
||||
string langCode = GetLangCode(player);
|
||||
if (key == null)
|
||||
{
|
||||
player.PrintToChat(message);
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> translations = [];
|
||||
for (int i = 0; i < key.Length; i++)
|
||||
{
|
||||
object[] currentArgs = (args != null && i < args.Length) ? args[i] : [];
|
||||
string translation = GetTranslation(key[i], langCode, currentArgs);
|
||||
translations.Add(translation);
|
||||
}
|
||||
player.PrintToChat(string.Format(message, translations.ToArray()));
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetTranslation(this CCSPlayerController player, string key, params object[] args)
|
||||
{
|
||||
string langCode = GetLangCode(player);
|
||||
return GetTranslation(key, langCode, args);
|
||||
}
|
||||
|
||||
public static string GetTranslation(string key, string? langCode = null, params object[] args)
|
||||
{
|
||||
langCode ??= defaultLangCode;
|
||||
if (_translations.TryGetValue(langCode, out var langDict) && langDict.TryGetValue(key, out var translation))
|
||||
if (args.Length != 0 && args[0].ToString() == "welcome")
|
||||
return translation;
|
||||
|
|
@ -59,5 +119,84 @@ namespace jRandomSkills.src.utils
|
|||
|
||||
return key;
|
||||
}
|
||||
|
||||
private static string GetLangCode(CCSPlayerController? player)
|
||||
{
|
||||
if (player == null || !player.IsValid) return defaultLangCode;
|
||||
|
||||
string? fileLangCode = GetLangCodeFromFile(player.SteamID);
|
||||
if (!string.IsNullOrEmpty(fileLangCode))
|
||||
return fileLangCode;
|
||||
|
||||
string? geoliteLandCode = GetLangCodeFromDatabase(GetPlayerIP(player)) ?? defaultLangCode;
|
||||
ChangePlayerLanguage(player, geoliteLandCode);
|
||||
return geoliteLandCode;
|
||||
}
|
||||
|
||||
private static string? GetPlayerIP(CCSPlayerController? player)
|
||||
{
|
||||
if (player == null) return null;
|
||||
var playerIP = player.IpAddress;
|
||||
if (playerIP == null) return null;
|
||||
string[] parts = playerIP.Split(':');
|
||||
return parts.Length > 1 ? parts[0] : playerIP;
|
||||
}
|
||||
|
||||
private static string? GetLangCodeFromDatabase(string? playerIP)
|
||||
{
|
||||
if (string.IsNullOrEmpty(playerIP)) return null;
|
||||
if (!File.Exists(geoliteFilePath)) return null;
|
||||
using var reader = new Reader(geoliteFilePath);
|
||||
var ip = IPAddress.Parse(playerIP);
|
||||
var data = reader.Find<Dictionary<string, object>>(ip);
|
||||
if (data == null || data.Count == 0) return null;
|
||||
|
||||
if (data.TryGetValue("country", out var _country) && _country is Dictionary<string, object> country)
|
||||
if (country.TryGetValue("iso_code", out var _isoCode) && _isoCode is string isoCode)
|
||||
{
|
||||
if (portugalIsoCodes.Contains(isoCode))
|
||||
isoCode = "pt-br";
|
||||
if (chinaIsoCodes.Contains(isoCode))
|
||||
isoCode = "zh";
|
||||
isoCode = isoCode.ToLower();
|
||||
if (_translations.ContainsKey(isoCode))
|
||||
return isoCode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void LoadPlayersLanguage()
|
||||
{
|
||||
string filePath = Path.Combine(configsFolderPath, playersLanguageFileName);
|
||||
if (!File.Exists(filePath))
|
||||
return;
|
||||
|
||||
var jsonText = File.ReadAllText(filePath);
|
||||
_playersLanguage = JsonConvert.DeserializeObject<Dictionary<ulong, string>>(jsonText) ?? [];
|
||||
}
|
||||
|
||||
private static void SavePlayersLanguage()
|
||||
{
|
||||
Directory.CreateDirectory(configsFolderPath);
|
||||
string filePath = Path.Combine(configsFolderPath, playersLanguageFileName);
|
||||
var json = JsonConvert.SerializeObject(_playersLanguage);
|
||||
if (json != null)
|
||||
File.WriteAllText(filePath, json);
|
||||
}
|
||||
|
||||
private static string? GetLangCodeFromFile(ulong? playerSteamID)
|
||||
{
|
||||
if (playerSteamID == null || playerSteamID == 0) return null;
|
||||
if (_playersLanguage.TryGetValue((ulong)playerSteamID, out var langCode))
|
||||
return langCode;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void ChangePlayerLanguage(CCSPlayerController? player, string language)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
_playersLanguage[player.SteamID] = language;
|
||||
SavePlayersLanguage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using CounterStrikeSharp.API.Modules.Entities.Constants;
|
||||
using CounterStrikeSharp.API.Modules.Memory;
|
||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||
|
|
@ -11,6 +10,7 @@ using jRandomSkills.src.utils;
|
|||
using System.Runtime.InteropServices;
|
||||
using WASDMenuAPI.Classes;
|
||||
using WASDSharedAPI;
|
||||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
|
||||
namespace jRandomSkills
|
||||
{
|
||||
|
|
@ -111,8 +111,9 @@ namespace jRandomSkills
|
|||
Utilities.SetStateChanged(pawn, "CBaseEntity", "m_iMaxHealth");
|
||||
}
|
||||
|
||||
public static string GetDesignerName(CBasePlayerWeapon weapon)
|
||||
public static string GetDesignerName(CBasePlayerWeapon? weapon)
|
||||
{
|
||||
if (weapon == null || !weapon.IsValid) return string.Empty;
|
||||
string designerName = weapon.DesignerName;
|
||||
ushort index = weapon.AttributeManager.Item.ItemDefinitionIndex;
|
||||
|
||||
|
|
@ -128,6 +129,15 @@ namespace jRandomSkills
|
|||
return designerName;
|
||||
}
|
||||
|
||||
public static void EnableTransmit()
|
||||
{
|
||||
if (!Event.isTransmitRegistered)
|
||||
{
|
||||
jRandomSkills.Instance?.RegisterListener<CheckTransmit>(Event.CheckTransmit);
|
||||
Event.isTransmitRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static IWasdMenuManager? GetMenuManager()
|
||||
{
|
||||
if (jRandomSkills.Instance.MenuManager == null)
|
||||
|
|
@ -180,9 +190,9 @@ namespace jRandomSkills
|
|||
var skillData = SkillData.Skills.FirstOrDefault(s => s.Skill == playerInfo.Skill);
|
||||
if (skillData == null) return;
|
||||
|
||||
string infoLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='#FFFFFF'>{Localization.GetTranslation("your_skill")}:</font> <br>";
|
||||
string skillLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='{skillData.Color}'>{skillData.Name}</font> <br>"
|
||||
+ $"<font color='green'>{Localization.GetTranslation($"{playerInfo.Skill.ToString().ToLower()}_select_info")}</font>";
|
||||
string infoLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='#FFFFFF'>{player.GetTranslation("your_skill")}:</font> <br>";
|
||||
string skillLine = $"<font class='fontSize-l' class='fontWeight-Bold' color='{skillData.Color}'>{player.GetSkillName(skillData.Skill)}</font> <br>"
|
||||
+ $"<font color='green'>{player.GetTranslation($"{playerInfo.Skill.ToString().ToLower()}_select_info")}</font>";
|
||||
|
||||
var manager = GetMenuManager();
|
||||
if (manager == null) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue