Various comment conversions + removed unused method
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
namespace Core.Utils.Cloners;
|
||||
|
||||
/**
|
||||
* Disabled as FastCloner library is 15% faster and consumes less memory than Json serialization
|
||||
*/
|
||||
/// <summary>
|
||||
/// Disabled as FastCloner library is 15% faster and consumes less memory than Json serialization
|
||||
/// </summary>
|
||||
public class JsonCloner : ICloner
|
||||
{
|
||||
protected JsonUtil _jsonUtil;
|
||||
|
||||
@@ -7,9 +7,10 @@ using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
namespace Core.Utils.Cloners;
|
||||
|
||||
/**
|
||||
* Not in use at the moment
|
||||
*/
|
||||
/// <summary>
|
||||
/// Not in use at the moment
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
public class ReflectionsCloner(ISptLogger<ReflectionsCloner> logger) : ICloner
|
||||
{
|
||||
private static Dictionary<Type, MemberInfo[]> MemberInfoCache = new();
|
||||
|
||||
@@ -36,12 +36,14 @@ public class ImporterUtil
|
||||
.ContinueWith(res => (T) res.Result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load files into objects recursively (asynchronous)
|
||||
* @param filepath Path to folder with files
|
||||
* @returns Promise
|
||||
* <T> return T type associated with this class
|
||||
*/
|
||||
/// <summary>
|
||||
/// Load files into objects recursively (asynchronous)
|
||||
/// </summary>
|
||||
/// <param name="filepath">Path to folder with files</param>
|
||||
/// <param name="loadedType"></param>
|
||||
/// <param name="onReadCallback"></param>
|
||||
/// <param name="onObjectDeserialized"></param>
|
||||
/// <returns>Task</returns>
|
||||
protected async Task<object> LoadRecursiveAsync(
|
||||
string filepath,
|
||||
Type loadedType,
|
||||
|
||||
@@ -334,9 +334,9 @@ public class RagfairOfferHolder(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear out internal expiredOffers dictionary of all items
|
||||
*/
|
||||
/// <summary>
|
||||
/// Clear out internal expiredOffers dictionary of all items
|
||||
/// </summary>
|
||||
public void ResetExpiredOfferIds()
|
||||
{
|
||||
lock (_expiredOfferIdsLock)
|
||||
|
||||
@@ -307,20 +307,19 @@ public class RandomUtil(ISptLogger<RandomUtil> _logger, ICloner _cloner)
|
||||
/// <returns>A biased random number within the specified range.</returns>
|
||||
public double GetBiasedRandomNumber(double min, double max, double shift, double n)
|
||||
{
|
||||
/**
|
||||
* This function generates a random number based on a gaussian distribution with an option to add a bias via shifting.
|
||||
*
|
||||
* Here's an example graph of how the probabilities can be distributed:
|
||||
* https://www.boost.org/doc/libs/1_49_0/libs/math/doc/sf_and_dist/graphs/normal_pdf.png
|
||||
*
|
||||
* Our parameter 'n' is sort of like σ (sigma) in the example graph.
|
||||
*
|
||||
* An 'n' of 1 means all values are equally likely. Increasing 'n' causes numbers near the edge to become less likely.
|
||||
* By setting 'shift' to whatever 'max' is, we can make values near 'min' very likely, while values near 'max' become extremely unlikely.
|
||||
*
|
||||
* Here's a place where you can play around with the 'n' and 'shift' values to see how the distribution changes:
|
||||
* http://jsfiddle.net/e08cumyx/
|
||||
*/
|
||||
// This function generates a random number based on a gaussian distribution with an option to add a bias via shifting.
|
||||
|
||||
// Here's an example graph of how the probabilities can be distributed:
|
||||
// https://www.boost.org/doc/libs/1_49_0/libs/math/doc/sf_and_dist/graphs/normal_pdf.png
|
||||
|
||||
// Our parameter 'n' is sort of like σ (sigma) in the example graph.
|
||||
|
||||
// An 'n' of 1 means all values are equally likely. Increasing 'n' causes numbers near the edge to become less likely.
|
||||
// By setting 'shift' to whatever 'max' is, we can make values near 'min' very likely, while values near 'max' become extremely unlikely.
|
||||
|
||||
// Here's a place where you can play around with the 'n' and 'shift' values to see how the distribution changes:
|
||||
// http://jsfiddle.net/e08cumyx/
|
||||
|
||||
if (max < min)
|
||||
{
|
||||
_logger.Error($"Invalid argument, Bounded random number generation max is smaller than min({max} < {min}");
|
||||
@@ -340,12 +339,11 @@ public class RandomUtil(ISptLogger<RandomUtil> _logger, ICloner _cloner)
|
||||
|
||||
if (shift > max - min)
|
||||
{
|
||||
/**
|
||||
* If a rolled number is out of bounds (due to bias being applied), we roll it again.
|
||||
* As the shifting increases, the chance of rolling a number within bounds decreases.
|
||||
* A shift that is equal to the available range only has a 50% chance of rolling correctly, theoretically halving performance.
|
||||
* Shifting even further drops the success chance very rapidly - so we want to warn against that
|
||||
**/
|
||||
// If a rolled number is out of bounds (due to bias being applied), we roll it again.
|
||||
// As the shifting increases, the chance of rolling a number within bounds decreases.
|
||||
// A shift that is equal to the available range only has a 50% chance of rolling correctly, theoretically halving performance.
|
||||
// Shifting even further drops the success chance very rapidly - so we want to warn against that
|
||||
|
||||
_logger.Warning(
|
||||
"Bias shift for random number generation is greater than the range of available numbers. This will have a severe performance impact"
|
||||
);
|
||||
|
||||
@@ -121,7 +121,6 @@ public class Watermark
|
||||
}
|
||||
|
||||
SetTitle();
|
||||
ResetCursor();
|
||||
Draw();
|
||||
}
|
||||
|
||||
@@ -144,11 +143,11 @@ public class Watermark
|
||||
return versionTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle singleplayer/settings/version
|
||||
* Get text shown in game on screen, can't be translated as it breaks bsgs client when certian characters are used
|
||||
* @returns string
|
||||
*/
|
||||
/// <summary>
|
||||
/// Handle singleplayer/settings/version
|
||||
/// Get text shown in game on screen, can't be translated as it breaks BSGs client when certain characters are used
|
||||
/// </summary>
|
||||
/// <returns>label text</returns>
|
||||
public string GetInGameVersionLabel()
|
||||
{
|
||||
var sptVersion = /*ProgramStatics.SPT_VERSION ||*/ sptConfig.SptVersion;
|
||||
@@ -159,29 +158,17 @@ public class Watermark
|
||||
return $"{sptConfig.ProjectName} {versionTag}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set window title
|
||||
*/
|
||||
/// <summary>
|
||||
/// Set window title
|
||||
/// </summary>
|
||||
protected void SetTitle()
|
||||
{
|
||||
Console.Title = versionLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset console cursor to top
|
||||
*/
|
||||
protected void ResetCursor()
|
||||
{
|
||||
/*
|
||||
if (!ProgramStatics.COMPILED) {
|
||||
process.stdout.write("\u001B[2J\u001B[0;0f");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the watermark
|
||||
*/
|
||||
/// <summary>
|
||||
/// Draw watermark on screen
|
||||
/// </summary>
|
||||
protected void Draw()
|
||||
{
|
||||
var result = new List<string>();
|
||||
|
||||
@@ -61,31 +61,6 @@ public class ModLoadOrder(ICloner cloner)
|
||||
return loadBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Is this not needed at all?
|
||||
*/
|
||||
public HashSet<string> GetModsOnLoadAfter(string mod)
|
||||
{
|
||||
if (!mods.ContainsKey(mod))
|
||||
{
|
||||
throw new Exception($"The mod {mod} does not exist!");
|
||||
}
|
||||
|
||||
var config = mods[mod];
|
||||
|
||||
var loadAfter = new HashSet<string>(config.LoadAfter);
|
||||
|
||||
foreach (var loadAfterMod in loadAfter)
|
||||
{
|
||||
if (!mods.ContainsKey(loadAfterMod))
|
||||
{
|
||||
loadAfter.Remove(loadAfterMod);
|
||||
}
|
||||
}
|
||||
|
||||
return loadAfter;
|
||||
}
|
||||
|
||||
protected void InvertLoadBefore(string mod)
|
||||
{
|
||||
var loadBefore = GetModsOnLoadBefore(mod);
|
||||
|
||||
@@ -117,7 +117,7 @@ public class ModValidator(
|
||||
}
|
||||
|
||||
// Returns if mod isnt compatible with this verison of spt
|
||||
if (!IsModCombatibleWithSpt(modToValidate))
|
||||
if (!IsModCompatibleWithSpt(modToValidate))
|
||||
{
|
||||
errorsFound = true;
|
||||
}
|
||||
@@ -173,21 +173,21 @@ public class ModValidator(
|
||||
return previndex - nextindex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for duplicate mods loaded, show error if any
|
||||
* @param modPackageData map of mod package.json data
|
||||
*/
|
||||
/// <summary>
|
||||
/// Check for duplicate mods loaded, show error if any
|
||||
/// </summary>
|
||||
/// <param name="modPackageData">Dictionary of mod package.json data</param>
|
||||
protected void CheckForDuplicateMods(Dictionary<string, PackageJsonData> modPackageData)
|
||||
{
|
||||
var grouppedMods = new Dictionary<string, List<PackageJsonData>>();
|
||||
var groupedMods = new Dictionary<string, List<PackageJsonData>>();
|
||||
|
||||
foreach (var mod in modPackageData.Values)
|
||||
{
|
||||
var name = $"{mod.Author}-{mod.Name}";
|
||||
grouppedMods.Add(name, [..(grouppedMods.GetValueOrDefault(name) ?? []), mod]);
|
||||
groupedMods.Add(name, [..(groupedMods.GetValueOrDefault(name) ?? []), mod]);
|
||||
|
||||
// if there's more than one entry for a given mod it means there's at least 2 mods with the same author and name trying to load.
|
||||
if (grouppedMods[name].Count > 1 && !skippedMods.Contains(name))
|
||||
if (groupedMods[name].Count > 1 && !skippedMods.Contains(name))
|
||||
{
|
||||
skippedMods.Add(name);
|
||||
}
|
||||
@@ -200,24 +200,23 @@ public class ModValidator(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of valid mods.
|
||||
*
|
||||
* @param mods mods to validate
|
||||
* @returns array of mod folder names
|
||||
*/
|
||||
/// <summary>
|
||||
/// Returns an array of valid mods
|
||||
/// </summary>
|
||||
/// <param name="mods">mods to validate</param>
|
||||
/// <returns>array of mod folder names</returns>
|
||||
protected List<SptMod> GetValidMods(List<SptMod> mods)
|
||||
{
|
||||
return mods.Where(ValidMod).ToList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is the passed in mod compatible with the running server version
|
||||
* @param mod Mod to check compatibiltiy with SPT
|
||||
* @returns True if compatible
|
||||
*/
|
||||
protected bool IsModCombatibleWithSpt(PackageJsonData mod)
|
||||
/// <summary>
|
||||
/// Is the passed in mod compatible with the running server version
|
||||
/// </summary>
|
||||
/// <param name="mod">Mod to check compatibility with SPT</param>
|
||||
/// <returns>True if compatible</returns>
|
||||
protected bool IsModCompatibleWithSpt(PackageJsonData mod)
|
||||
{
|
||||
var sptVersion = ProgramStatics.SPT_VERSION() ?? sptConfig.SptVersion;
|
||||
var modName = $"{mod.Author}-${mod.Name}";
|
||||
@@ -247,10 +246,10 @@ public class ModValidator(
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read loadorder.json (create if doesnt exist) and return sorted list of mods
|
||||
* @returns string array of sorted mod names
|
||||
*/
|
||||
/// <summary>
|
||||
/// Read loadorder.json (create if doesnt exist) and return sorted list of mods
|
||||
/// </summary>
|
||||
/// <returns>string array of sorted mod names</returns>
|
||||
public List<string> SortModsLoadOrder()
|
||||
{
|
||||
// if loadorder.json exists: load it, otherwise generate load order
|
||||
@@ -263,10 +262,10 @@ public class ModValidator(
|
||||
return modLoadOrder.GetLoadOrder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile mod and add into class property "imported"
|
||||
* @param mod Name of mod to compile/add
|
||||
*/
|
||||
/// <summary>
|
||||
/// Compile mod and add into class property "imported"
|
||||
/// </summary>
|
||||
/// <param name="mod">Name of mod to compile/add</param>
|
||||
protected void AddMod(SptMod mod)
|
||||
{
|
||||
// Add mod to imported list
|
||||
@@ -281,12 +280,11 @@ public class ModValidator(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given mod should be loaded or skipped.
|
||||
*
|
||||
* @param pkg mod package.json data
|
||||
* @returns
|
||||
*/
|
||||
/// <summary>
|
||||
/// Checks if a given mod should be loaded or skipped
|
||||
/// </summary>
|
||||
/// <param name="pkg">mod package.json data</param>
|
||||
/// <returns></returns>
|
||||
protected bool ShouldSkipMod(PackageJsonData pkg)
|
||||
{
|
||||
return skippedMods.Contains($"{pkg.Author}-{pkg.Name}");
|
||||
@@ -363,11 +361,11 @@ public class ModValidator(
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a mod passes a number of checks
|
||||
* @param modName name of mod in /mods/ to validate
|
||||
* @returns true if valid
|
||||
*/
|
||||
/// <summary>
|
||||
/// Validate a mod passes a number of checks
|
||||
/// </summary>
|
||||
/// <param name="mod">name of mod in /mods/ to validate</param>
|
||||
/// <returns>true if valid</returns>
|
||||
protected bool ValidMod(SptMod mod)
|
||||
{
|
||||
var modName = mod.PackageJson.Name;
|
||||
@@ -392,10 +390,10 @@ public class ModValidator(
|
||||
logger.Error(localisationService.GetText("modloader-is_client_mod", modName));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (containsJs || containsTs)
|
||||
{
|
||||
// TODO, needs new localisation!
|
||||
// TODO: needs new localisation!
|
||||
logger.Error("The mod is an old server mod, JS/TS files detected");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -76,10 +76,10 @@ public class ItemTplGenerator(
|
||||
_logger.Info("Generating items finished");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an object containing all items in the game with a generated name
|
||||
* @returns An object containing a generated item name to item ID association
|
||||
*/
|
||||
/// <summary>
|
||||
/// Return an object containing all items in the game with a generated name
|
||||
/// </summary>
|
||||
/// <returns>An object containing a generated item name to item ID association</returns>
|
||||
private Dictionary<string, string> GenerateItemsObject()
|
||||
{
|
||||
var itemsObject = new Dictionary<string, string>();
|
||||
@@ -175,10 +175,6 @@ public class ItemTplGenerator(
|
||||
return orderedItemsObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param orderedItemsObject The previously generated object of item name to item ID associations
|
||||
* @returns
|
||||
*/
|
||||
private Dictionary<string, string> GenerateWeaponsObject()
|
||||
{
|
||||
var weaponsObject = new Dictionary<string, string>();
|
||||
@@ -230,11 +226,11 @@ public class ItemTplGenerator(
|
||||
return orderedWeaponsObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear any non-alpha numeric characters, and fix multiple underscores
|
||||
* @param enumKey The enum key to sanitize
|
||||
* @returns The sanitized enum key
|
||||
*/
|
||||
/// <summary>
|
||||
/// Clear any non-alpha numeric characters, and fix multiple underscores
|
||||
/// </summary>
|
||||
/// <param name="enumKey">The enum key to sanitize</param>
|
||||
/// <returns>The sanitized enum key</returns>
|
||||
private string SanitizeEnumKey(string enumKey)
|
||||
{
|
||||
return enumKey
|
||||
@@ -323,11 +319,11 @@ public class ItemTplGenerator(
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a prefix for the passed in item
|
||||
* @param item The item to generate the prefix for
|
||||
* @returns The prefix of the given item
|
||||
*/
|
||||
/// <summary>
|
||||
/// Generate a prefix for the passed in item
|
||||
/// </summary>
|
||||
/// <param name="item">The item to generate the prefix for</param>
|
||||
/// <returns>The prefix of the given item</returns>
|
||||
private string GetItemPrefix(TemplateItem item)
|
||||
{
|
||||
var prefix = "";
|
||||
@@ -422,11 +418,11 @@ public class ItemTplGenerator(
|
||||
return GetAmmoPrefix(items[ammoItem]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the passed in item, formatted for use in an enum
|
||||
* @param item The item to generate the name for
|
||||
* @returns The name of the given item
|
||||
*/
|
||||
/// <summary>
|
||||
/// Return the name of the passed in item, formatted for use in an enum
|
||||
/// </summary>
|
||||
/// <param name="item">The item to generate the name for</param>
|
||||
/// <returns>The name of the given item</returns>
|
||||
private string GetItemName(TemplateItem item)
|
||||
{
|
||||
string? itemName = null;
|
||||
|
||||
Reference in New Issue
Block a user