using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.BoneMenu.Elements;
using LabFusion.Preferences;
using LabFusion.SDK.Points;
using LabFusion.Utilities;
using MelonLoader;
using NameThingy;
using SLZ.Marrow.Warehouse;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Auto-changing Fusion Nicknames")]
[assembly: AssemblyDescription("Auto-changing Fusion Nicknames")]
[assembly: AssemblyCompany(null)]
[assembly: AssemblyProduct("NameThingy")]
[assembly: AssemblyCopyright("Developed by TomTTFB")]
[assembly: AssemblyTrademark(null)]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: MelonInfo(typeof(Main), "NameThingy", "1.0.0", "TomTTFB", null)]
[assembly: MelonColor(ConsoleColor.Cyan)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NameThingy;
internal class BoneMenu
{
private const string PresetsDirectoryName = "Presets";
private static MenuCategory _presetsCategory;
private static MenuCategory _utilitiesMenu;
private static Main _mainInstance;
private static void createPresetsMenu(MenuCategory category, Main mainInstance)
{
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
_mainInstance = mainInstance;
string directoryName = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
string path = Path.Combine(directoryName, "NameThingy", "Presets");
if (Directory.Exists(path))
{
string[] array = Directory.GetFiles(path, "*.ntpreset").ToArray();
if (array.Length != 0)
{
string[] array2 = array;
foreach (string path2 in array2)
{
string presetName = Path.GetFileNameWithoutExtension(path2);
string[] presetLines = File.ReadAllLines(path2);
string text = "Preset " + presetName.Substring(6);
string text2 = null;
string[] array3 = presetLines;
foreach (string text3 in array3)
{
if (text3.StartsWith("NAME="))
{
text2 = text3.Substring(5);
break;
}
}
if (!string.IsNullOrEmpty(text2))
{
category.CreateFunctionElement(text2, Color.white, (Action)delegate
{
mainInstance.ApplyPreset(presetLines, presetName, isRunning: false);
});
MelonLogger.Msg("Found preset: " + text, new object[1] { Color.green });
}
else
{
LogError(category, "Failed to find 'NAME=' line in preset: " + presetName);
}
}
}
else
{
LogError(category, "name.txt is not configured");
LogError(category, "Read ThunderStore Page");
LogError(category, "for the setup");
}
}
else
{
LogError(category, "Presets directory does not exist");
}
}
private static void createUtilitiesMenu(MenuCategory category, Main mainInstance)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
int nextPresetNumber = GetNextPresetNumber();
string newPresetName = $"preset{nextPresetNumber}.ntpreset";
category.CreateFunctionElement("Create Blank Preset File", Color.white, (Action)delegate
{
CreateBlankPresetFile(newPresetName);
}, "Apply Blank Preset");
}
private static void CreateBlankPresetFile(string newPresetName)
{
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Expected O, but got Unknown
string path = Path.Combine(Main.presetsFolderPath, newPresetName);
try
{
File.WriteAllText(path, "");
Melon<Main>.Logger.Msg("Blank .ntpreset file created: " + newPresetName, new object[1] { Color.green });
FusionNotifier.Send(new FusionNotification
{
isMenuItem = false,
isPopup = true,
title = NotificationText.op_Implicit("Success"),
message = NotificationText.op_Implicit("Created a blank .ntpreset file in your preset folder"),
showTitleOnPopup = true
});
}
catch (Exception ex)
{
Melon<Main>.Logger.Msg("Failed to create .ntpreset file: " + ex.Message, new object[1] { Color.red });
FusionNotifier.Send(new FusionNotification
{
isMenuItem = false,
isPopup = true,
title = NotificationText.op_Implicit("Error"),
message = NotificationText.op_Implicit("Failed to create a blank .ntpreset file in your preset folder"),
showTitleOnPopup = true
});
}
}
private static int GetNextPresetNumber()
{
int num = 0;
string[] files = Directory.GetFiles(Main.presetsFolderPath, "preset*.ntpreset");
string[] array = files;
foreach (string path in array)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
if (int.TryParse(fileNameWithoutExtension.Substring(6), out var result) && result > num)
{
num = result;
}
}
return num + 1;
}
private static void LogError(MenuCategory category, string errorMessage)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
MelonLogger.Error(errorMessage);
category.CreateFunctionElement(errorMessage, Color.red, (Action)null);
}
public static void CreateBoneMenu(MenuCategory rootCategory, Main mainInstance)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
_presetsCategory = rootCategory.CreateCategory("Presets", Color.white);
_utilitiesMenu = rootCategory.CreateCategory("Utilities", Color.white);
createPresetsMenu(_presetsCategory, mainInstance);
_presetsCategory.CreateFunctionElement("Stop/Pause", Color.red, (Action)StopPresetLoop);
}
private static void StopPresetLoop()
{
if (_mainInstance != null)
{
_mainInstance.StopPresetLoop();
}
else
{
MelonLogger.Warning("Main instance is null. Failed to stop the preset loop.");
}
}
}
internal class Main : MelonMod
{
internal const string Name = "NameThingy";
internal const string Description = "Auto-changing Fusion Nicknames";
internal const string Author = "TomTTFB";
internal const string Company = null;
internal const string Version = "1.0.0";
internal const string DownloadLink = null;
private const string PresetsDirectoryName = "Presets";
public bool sceneLoading;
public static string presetsFolderPath;
private bool isNamethingyRunning;
public float delay = 2f;
public string playerbits;
public int fps;
public int playerhealth;
public int sessiontime;
public string avatarname;
public string cpuname;
public string gpuname;
public float ramUsage;
public float gpuUsage;
public float cpuUsage;
public string avataragility;
public string avatarvitality;
public string avatarspeed;
public string avatarintelligence;
private Dictionary<string, string> variables;
private float startTime;
private Task runningPresetTask;
private CancellationTokenSource cancellationTokenSource;
public override void OnInitializeMelon()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
((MelonBase)this).OnInitializeMelon();
((MelonBase)this).LoggerInstance.Msg("Mod initialized!", new object[1] { Color.green });
CreateNameThingyFolders();
BoneMenu.CreateBoneMenu(MenuManager.CreateCategory("NameThingy", Color.yellow), this);
((MelonBase)this).LoggerInstance.Msg("BoneMenu initialized!", new object[1] { Color.green });
variables = new Dictionary<string, string>
{
{ "bits", playerbits },
{
"fps",
fps.ToString()
},
{
"health",
playerhealth.ToString()
},
{
"sessiontime",
sessiontime.ToString()
},
{ "avatar", avatarname },
{ "agility", avataragility },
{ "vitality", avatarvitality },
{ "speed", avatarspeed },
{ "intelligence", avatarintelligence },
{ "cpuname", cpuname },
{ "gpuname", gpuname },
{
"ramusage",
ramUsage.ToString()
},
{
"gpuusage",
gpuUsage.ToString()
},
{
"cpuusage",
cpuUsage.ToString()
}
};
startTime = Time.time;
}
public override void OnUpdate()
{
((MelonBase)this).OnUpdate();
if ((Object)(object)Player.rigManager != (Object)null)
{
playerbits = PointItemManager.GetBitCount().ToString();
fps = Mathf.RoundToInt(1f / Time.deltaTime);
playerhealth = Convert.ToInt32(Player.rigManager.health.curr_Health);
sessiontime = Mathf.RoundToInt(Time.time - startTime);
avatarname = ((Scannable)((CrateReferenceT<AvatarCrate>)(object)Player.rigManager.AvatarCrate).Crate).Title;
avataragility = Player.rigManager.avatar._agility.ToString("0.00");
avatarvitality = Player.rigManager.avatar._vitality.ToString("0.00");
avatarspeed = Player.rigManager.avatar._speed.ToString("0.00");
avatarintelligence = Player.rigManager.avatar._intelligence.ToString("0.00");
cpuname = SystemInfoHelper.GetCPUName();
gpuname = SystemInfoHelper.GetGPUName();
ramUsage = SystemInfoHelper.GetRAMUsage();
gpuUsage = SystemInfoHelper.GetGPUUsage();
cpuUsage = SystemInfoHelper.GetCPUUsage();
variables["bits"] = playerbits;
variables["fps"] = fps.ToString();
variables["health"] = playerhealth.ToString();
variables["sessiontime"] = sessiontime.ToString();
variables["avatar"] = avatarname;
variables["agility"] = avataragility;
variables["vitality"] = avatarvitality;
variables["speed"] = avatarspeed;
variables["intelligence"] = avatarintelligence;
variables["cpuname"] = cpuname;
variables["gpuname"] = gpuname;
variables["ramusage"] = ramUsage.ToString();
variables["gpuusage"] = gpuUsage.ToString();
variables["cpuusage"] = cpuUsage.ToString();
}
}
public override void OnFixedUpdate()
{
((MelonBase)this).OnFixedUpdate();
}
public override void OnLateUpdate()
{
((MelonBase)this).OnLateUpdate();
}
private bool EvaluateCondition(string condition)
{
string[] array = condition.Split(new char[1] { ' ' });
if (array.Length == 3)
{
string key = array[0];
string text = array[1];
string text2 = array[2];
if (variables.TryGetValue(key, out var value))
{
if (int.TryParse(value, out var result) && int.TryParse(text2, out var result2))
{
switch (text)
{
case "<":
return result < result2;
case "<=":
return result <= result2;
case ">":
return result > result2;
case ">=":
return result >= result2;
case "==":
return result == result2;
case "!=":
return result != result2;
}
}
else
{
string text3 = text;
string text4 = text3;
if (text4 == "==")
{
return value == text2;
}
if (text4 == "!=")
{
return value != text2;
}
}
}
}
return false;
}
public void ApplyPreset(string[] presetLines, string presetName, bool isRunning)
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
if (runningPresetTask != null && !runningPresetTask.IsCompleted)
{
FusionNotifier.Send(new FusionNotification
{
isMenuItem = false,
isPopup = true,
title = NotificationText.op_Implicit("Error"),
message = NotificationText.op_Implicit("A preset is already running, stop the current preset before running another one"),
showTitleOnPopup = true
});
return;
}
Melon<Main>.Logger.Msg("Loaded preset: " + presetName, new object[1] { Color.green });
FusionNotifier.Send(new FusionNotification
{
isMenuItem = false,
isPopup = true,
title = NotificationText.op_Implicit("Loaded"),
message = NotificationText.op_Implicit("Preset was loaded successfully"),
showTitleOnPopup = true
});
int lineIndex = 0;
int totalLines = presetLines.Length;
float presetDelay = delay;
cancellationTokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = cancellationTokenSource.Token;
runningPresetTask = Task.Run(async delegate
{
isNamethingyRunning = true;
for (int i = 0; i < totalLines; i++)
{
string line = presetLines[i];
if (line.StartsWith("DELAY="))
{
string delayValue = line.Substring(6);
if (float.TryParse(delayValue, out var parsedDelay))
{
presetDelay = parsedDelay;
Melon<Main>.Logger.Msg("Set preset delay: " + presetDelay, new object[1] { Color.green });
lineIndex = (i + 1) % totalLines;
break;
}
Melon<Main>.Logger.Msg("Failed to parse delay value: " + delayValue, new object[1] { Color.yellow });
}
}
while (isNamethingyRunning && !cancellationToken.IsCancellationRequested)
{
string line3 = presetLines[lineIndex];
if (!line3.StartsWith("#") && !line3.StartsWith("DELAY=") && !line3.StartsWith("NAME="))
{
if (line3.StartsWith("if "))
{
string condition = line3.Substring(3);
if (EvaluateCondition(condition))
{
lineIndex = (lineIndex + 1) % totalLines;
}
else
{
while (lineIndex < totalLines)
{
lineIndex = (lineIndex + 1) % totalLines;
line3 = presetLines[lineIndex];
if (line3.StartsWith("else: "))
{
lineIndex = (lineIndex + 1) % totalLines;
break;
}
}
}
continue;
}
string processedLine = ReplaceVariables(line3);
if (!string.IsNullOrEmpty(processedLine))
{
ClientSettings.Nickname.SetValue(processedLine);
Melon<Main>.Logger.Msg("Set nickname: " + processedLine, new object[1] { Color.green });
}
}
lineIndex = (lineIndex + 1) % totalLines;
await Task.Delay((int)(presetDelay * 1000f));
}
Melon<Main>.Logger.Msg("Preset loop stopped!", new object[1] { Color.red });
}, cancellationToken);
}
public void StopPresetLoop()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
if (cancellationTokenSource != null)
{
cancellationTokenSource.Cancel();
isNamethingyRunning = false;
runningPresetTask = null;
cancellationTokenSource.Dispose();
cancellationTokenSource = null;
}
FusionNotifier.Send(new FusionNotification
{
isMenuItem = false,
isPopup = true,
title = NotificationText.op_Implicit("Success"),
message = NotificationText.op_Implicit("Preset was stopped successfully"),
showTitleOnPopup = true
});
}
private void CreateNameThingyFolders()
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
string directoryName = Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
string text = Path.Combine(directoryName, "NameThingy");
Directory.CreateDirectory(text);
presetsFolderPath = Path.Combine(text, "Presets");
Directory.CreateDirectory(presetsFolderPath);
string fullPath = Path.GetFullPath(presetsFolderPath);
Melon<Main>.Logger.Msg("Presets folder path: " + fullPath, new object[1] { Color.green });
string sourceFilePath = Path.Combine(Directory.GetCurrentDirectory(), "example.ntpreset");
string newFileNameInPresets = "example.ntpreset";
CopyPremadeFileToPresets(sourceFilePath, newFileNameInPresets);
}
private void CopyPremadeFileToPresets(string sourceFilePath, string newFileNameInPresets)
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
string destFileName = Path.Combine(presetsFolderPath, newFileNameInPresets);
try
{
File.Copy(sourceFilePath, destFileName, overwrite: true);
Melon<Main>.Logger.Msg("Premade file copied to Presets folder: " + newFileNameInPresets, new object[1] { Color.green });
}
catch (Exception ex)
{
Melon<Main>.Logger.Msg("Failed to copy premade file to Presets folder: " + ex.Message, new object[1] { Color.red });
}
}
private string ReplaceVariables(string line)
{
foreach (KeyValuePair<string, string> variable in variables)
{
string oldValue = "{" + variable.Key + "}";
string value = variable.Value;
line = line.Replace(oldValue, value);
}
return line;
}
}
internal static class SystemInfoHelper
{
public static string GetCPUName()
{
string result = string.Empty;
try
{
using StreamReader streamReader = new StreamReader("/proc/cpuinfo");
string text;
while ((text = streamReader.ReadLine()) != null)
{
if (text.StartsWith("model name"))
{
int startIndex = text.IndexOf(":") + 2;
result = text.Substring(startIndex);
break;
}
}
}
catch (Exception)
{
result = "Unknown";
}
return result;
}
public static string GetGPUName()
{
return SystemInfo.graphicsDeviceName;
}
public static float GetRAMUsage()
{
return (float)GC.GetTotalMemory(forceFullCollection: false) / 1048576f;
}
public static int GetGPUUsage()
{
return SystemInfo.graphicsMemorySize;
}
public static int GetCPUUsage()
{
return SystemInfo.processorCount;
}
}