forked from CosmicDreamsOfCode/FrostyToolsuite
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FrostyStringGeneration project initial
- Loading branch information
Showing
40 changed files
with
69,595 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Frosty.Hash; | ||
using FrostySdk.Interfaces; | ||
using FrostySdk.IO; | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows.Shapes; | ||
|
||
namespace FrostySdk | ||
{ | ||
public static class StringsManager | ||
{ | ||
private static Dictionary<int, string> strings = new Dictionary<int, string>(); | ||
|
||
public static string GetString(int hash) | ||
{ | ||
if (!strings.TryGetValue(hash, out var value)) | ||
{ | ||
return "0x" + hash.ToString("x8"); | ||
} | ||
return value; | ||
} | ||
|
||
/// <summary> | ||
/// Loads all resolved hashes | ||
/// </summary> | ||
/// <param name="path">The file to be read from for hashes.</param> | ||
public static void LoadStringList(string path = "strings.txt", ILogger logger = null) | ||
{ | ||
if (!File.Exists(path)) | ||
{ | ||
return; | ||
} | ||
|
||
strings.Clear(); | ||
|
||
try | ||
{ | ||
var allLines = File.ReadAllLines(path); | ||
int totalLines = allLines.Length; | ||
int concurrencyLevel = Environment.ProcessorCount; | ||
var partitioner = Partitioner.Create(0, totalLines, Math.Max(totalLines / concurrencyLevel, 1)); | ||
var localDictionaries = new ConcurrentBag<Dictionary<int, string>>(); | ||
|
||
int processedCount = 0; | ||
int logIntervals = 20; | ||
int logInterval = Math.Max(totalLines / logIntervals, 1); | ||
|
||
Parallel.ForEach(partitioner, range => | ||
{ | ||
var localDict = new Dictionary<int, string>(range.Item2 - range.Item1); | ||
|
||
for (int i = range.Item1; i < range.Item2; i++) | ||
{ | ||
var currentString = allLines[i]; | ||
int hash = Fnv1.HashString(currentString); | ||
localDict[hash] = currentString; | ||
if (logger != null) | ||
{ | ||
int countSoFar = Interlocked.Increment(ref processedCount); | ||
if (countSoFar % logInterval == 0 || countSoFar == totalLines) | ||
{ | ||
double progress = (double)countSoFar / totalLines * 100.0; | ||
logger.Log($"progress: {progress}"); | ||
} | ||
} | ||
} | ||
|
||
localDictionaries.Add(localDict); | ||
}); | ||
|
||
var finalDictionary = new Dictionary<int, string>(totalLines); | ||
foreach (var dict in localDictionaries) | ||
{ | ||
foreach (var kvp in dict) | ||
{ | ||
finalDictionary[kvp.Key] = kvp.Value; | ||
} | ||
} | ||
|
||
strings = finalDictionary; | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger?.Log($"Error loading strings: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[*.cs] | ||
|
||
# CS1591: Missing XML comment for publicly visible type or member | ||
dotnet_diagnostic.CS1591.severity = none | ||
|
||
#place catch statements on a new line | ||
csharp_new_line_before_catch = true | ||
#place else statements on a new line | ||
csharp_new_line_before_else = true | ||
#require members of object intializers to be on separate lines | ||
csharp_new_line_before_members_in_object_initializers = true | ||
#require braces to be on a new line for methods, control_blocks, types, lambdas, and object_collection_array_initializers (also known as "Allman" style) | ||
csharp_new_line_before_open_brace = methods, control_blocks, types, lambdas, object_collection_array_initializers |
Oops, something went wrong.