Add other mods

This commit is contained in:
2025-03-31 13:19:47 +02:00
parent bdc5488720
commit be593696b2
2266 changed files with 109313 additions and 512 deletions

View File

@@ -0,0 +1,118 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace FastForward
{
public partial class Mod : IAssemblyPlugin
{
public static List<DebugConsole.Command> addedCommands = new List<DebugConsole.Command>();
public static void addCommands()
{
addedCommands ??= new List<DebugConsole.Command>();
addedCommands.Add(new DebugConsole.Command("fastforward", "fastforward [seconds]: Fast forwards the game by x seconds. Note that large numbers may cause a long freeze.", (string[] args) =>
{
float seconds = 0;
if (args.Length > 0) { float.TryParse(args[0], out seconds); }
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
for (int i = 0; i < seconds * Timing.FixedUpdateRate; i++)
{
Screen.Selected?.Update(Timing.Step);
}
sw.Stop();
DebugConsole.NewMessage($"Fast-forwarded by {seconds} seconds (took {sw.ElapsedMilliseconds / 1000.0f} s).");
}));
addedCommands.Add(new DebugConsole.Command("fastforward_key", "", (string[] args) =>
{
if (args.Length > 0)
{
if (Enum.TryParse(typeof(Keys), args[0], out object k))
{
FFPressKey = (Keys)k;
}
else
{
FFPressKey = Keys.None;
}
}
log($"fastforward_key = {FFPressKey}");
saveSettings();
}));
addedCommands.Add(new DebugConsole.Command("fastforward_togglekey", "", (string[] args) =>
{
if (args.Length > 0)
{
if (Enum.TryParse(typeof(Keys), args[0], out object k))
{
FFToggleKey = (Keys)k;
}
else
{
FFToggleKey = Keys.None;
}
FFState = false;
}
log($"fastforward_key = {FFToggleKey}");
saveSettings();
}));
addedCommands.Add(new DebugConsole.Command("fastforward_speed", "", (string[] args) =>
{
if (args.Length > 0)
{
if (int.TryParse(args[0], out int i))
{
FFSpeed = i;
}
}
log($"fastforward_speed = {FFSpeed}");
saveSettings();
}));
addedCommands.Add(new DebugConsole.Command("printkeys", "", (string[] args) =>
{
var values = typeof(Keys).GetEnumValues();
foreach (var v in values)
{
log($"{(int)v} {v}");
}
}));
addedCommands.Add(new DebugConsole.Command("printcolors", "", (string[] args) =>
{
foreach (PropertyInfo prop in typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public))
{
log(prop, (Color)prop.GetValue(null));
}
}));
addedCommands.ForEach(c => DebugConsole.Commands.Add(c));
}
public static void removeCommands()
{
addedCommands.ForEach(c => DebugConsole.Commands.RemoveAll(which => which.Names.Contains(c.Names[0])));
addedCommands.Clear();
addedCommands = null;
}
}
}

View File

@@ -0,0 +1,35 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace FastForward
{
public partial class Mod : IAssemblyPlugin
{
public static void GameMain_Update_Postfix(GameTime gameTime, GameMain __instance)
{
bool ts = PlayerInput.GetKeyboardState.IsKeyDown(FFToggleKey);
if (!FFToggleKeyPressed && ts)
{
FFState = !FFState;
}
FFToggleKeyPressed = ts;
if (FFState ^ PlayerInput.GetKeyboardState.IsKeyDown(FFPressKey) && !__instance.Paused)
{
for (int i = 0; i < FFSpeed - 1; i++)
{
Screen.Selected?.Update(Timing.Step);
}
}
}
}
}

View File

@@ -0,0 +1,57 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System.IO;
namespace FastForward
{
public partial class Mod : IAssemblyPlugin
{
public Harmony harmony;
public static Keys FFPressKey = Keys.Q;
public static Keys FFToggleKey = Keys.None;
public static bool FFToggleKeyPressed = false;
public static bool FFState = false;
public static int FFSpeed = 3;
public void Initialize()
{
harmony = new Harmony("fastforward");
createFolders();
loadSettings();
saveSettings();
addCommands();
harmony.Patch(
original: typeof(GameMain).GetMethod("Update", AccessTools.all),
postfix: new HarmonyMethod(typeof(Mod).GetMethod("GameMain_Update_Postfix"))
);
}
public void Dispose()
{
harmony.UnpatchAll(harmony.Id);
harmony = null;
removeCommands();
}
public void OnLoadCompleted() { }
public void PreInitPatching() { }
public static void log(object msg, Color? cl = null, string line = "")
{
if (cl == null) cl = Color.Cyan;
LuaCsLogger.LogMessage($"{line}{msg ?? "null"}", cl, cl);
}
}
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System.IO;
using System.Xml.Linq;
namespace FastForward
{
public partial class Mod : IAssemblyPlugin
{
public static string ModSettingsFolder = "ModSettings\\";
public static string SettingsFolder = "ModSettings\\Fast Forward\\";
public static string SettingsFile = "ModSettings\\Fast Forward\\Settings.xml";
public static void createFolders()
{
if (!Directory.Exists(ModSettingsFolder)) Directory.CreateDirectory(ModSettingsFolder);
if (!Directory.Exists(SettingsFolder)) Directory.CreateDirectory(SettingsFolder);
}
public static void loadSettings()
{
try
{
if (!File.Exists(SettingsFile)) return;
XElement ff = XDocument.Load(SettingsFile).Element("FastForward");
if (ff == null) return;
if (ff.Element("Key") != null)
{
if (Enum.TryParse(typeof(Keys), ff.Element("Key").Value, out object k))
{
FFPressKey = (Keys)k;
}
}
if (ff.Element("ToggleKey") != null)
{
if (Enum.TryParse(typeof(Keys), ff.Element("ToggleKey").Value, out object k))
{
FFToggleKey = (Keys)k;
}
}
if (ff.Element("Speed") != null) int.TryParse(ff.Element("Speed").Value, out FFSpeed);
}
catch (Exception e) { log(e.Message, Color.Orange); }
}
public static void saveSettings()
{
XElement root = new XElement("FastForward",
new XElement("Key", FFPressKey),
new XElement("ToggleKey", FFToggleKey),
new XElement("Speed", FFSpeed)
);
XDocument xdoc = new XDocument(root);
xdoc.Save(SettingsFile);
}
}
}