diff --git a/MattRandomCompany/Config.cs b/MattRandomCompany/Config.cs new file mode 100644 index 0000000..01aa49c --- /dev/null +++ b/MattRandomCompany/Config.cs @@ -0,0 +1,185 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using BepInEx.Configuration; +using GameNetcodeStuff; +using HarmonyLib; +using Unity.Collections; +using Unity.Netcode; + +namespace RandomCompany +{ + [Serializable] + class Config : SyncedInstance + { + + //Scrap + + public readonly ConfigEntry scrapSpawnMulLower; + public readonly ConfigEntry scrapSpawnMulUpper; + public readonly ConfigEntry scrapSpawnMulEnabled; + + public readonly ConfigEntry scrapValueMulLower; + public readonly ConfigEntry scrapValueMulUpper; + public readonly ConfigEntry scrapValueMulEnabled; + + + // Factory + + public readonly ConfigEntry factorySizeMulLower; + public readonly ConfigEntry factorySizeMulUpper; + public readonly ConfigEntry factorySizeMulEnabled; + + //Player Controller + + public readonly ConfigEntry moveSpeedMulLower; + public readonly ConfigEntry moveSpeedMulUpper; + public readonly ConfigEntry moveSpeedMulEnabled; + + public readonly ConfigEntry sprintTimeMulLower; + public readonly ConfigEntry sprintTimeMulUpper; + public readonly ConfigEntry sprintTimeMulEnabled; + + public readonly ConfigEntry jumpForceMulLower; + public readonly ConfigEntry jumpForceMulUpper; + public readonly ConfigEntry jumpForceMulEnabled; + + public readonly ConfigEntry climbSpeedMulLower; + public readonly ConfigEntry climbSpeedMulUpper; + public readonly ConfigEntry climbSpeedMulEnabled; + + public readonly ConfigEntry insanityMulLower; + public readonly ConfigEntry insanityMulUpper; + public readonly ConfigEntry insanityMulEnabled; + + public readonly ConfigEntry healthRegenMulLower; + public readonly ConfigEntry healthRegenMulUpper; + public readonly ConfigEntry healthRegenMulEnabled; + + public Config(ConfigFile cfg) { + InitInstance(this); + cfg.SaveOnConfigSet = false; + + // Scrap + + scrapSpawnMulLower = cfg.Bind("General.Scrap", "ScrapSpawnMultiplierLowerBound", 1, "The Minimum Scrap Spawn Rate Multiplier"); + scrapSpawnMulUpper = cfg.Bind("General.Scrap", "ScrapSpawnMultiplierUpperBound", 1, "The Maximum Scrap Spawn Rate Multiplier"); + scrapSpawnMulEnabled = cfg.Bind("General.Scrap.Toggles", "ScrapSpawnRateMultiplierEnabled", true, "Enables Scrap Spawn Rate Multiplier ... true : enabled ... false : disabled"); + + scrapValueMulLower = cfg.Bind("General.Scrap", "ScrapValueMultiplierLowerBound", 1, "The Minimum Scrap Value Multiplier"); + scrapValueMulUpper = cfg.Bind("General.Scrap", "ScrapValueMultiplierUpperBound", 1, "The Maximum Scrap Value Multiplier"); + scrapValueMulEnabled = cfg.Bind("General.Scrap.Toggles", "ScrapValueMultiplierEnabled", true, "Enables Scrap Value Multiplier ... true : enabled ... false : disabled"); + + // Factory + + factorySizeMulLower = cfg.Bind("General.Factory", "FactorySizeMultiplierLowerBound", 1, "The Minimum Factory Size Multiplier"); + factorySizeMulUpper = cfg.Bind("General.Factory", "FactorySizeMultiplierUpperBound", 1, "The Maximum Factory Size Multiplier"); + factorySizeMulEnabled = cfg.Bind("General.Factory.Toggles", "FactorySizeMultipierEnabled", true, "Enables Factory Size Multiplier ... true : enabled ... false : disabled"); + + // Player Controller + + moveSpeedMulLower = cfg.Bind("General.Movement", "MoveSpeedMultiplierLowerBound", 1, "The Minimum Movement Speed Multiplier"); + moveSpeedMulUpper = cfg.Bind("General.Movement", "MoveSpeedMultiplierUpperBound", 1, "The Maximum Movement Speed Multiplier"); + moveSpeedMulEnabled = cfg.Bind("General.Movement.Toggles", "MoveSpeedEnabled", true, "Enables Player Movement Speed Multiplier ... true : enabled ... false : disabled"); + + sprintTimeMulLower = cfg.Bind("General.Movement", "SprintTimeMultiplierLowerBound", 1, "The Minimum Multiplier for Sprint Time"); + sprintTimeMulUpper = cfg.Bind("General.Movement", "SprintTimeMultiplierUpperBound", 1, "The Maximum Multiplier for Sprint Time"); + sprintTimeMulEnabled = cfg.Bind("General.Movement.Toggles", "SprintTimeMultiplierEnabled", true, "Enables Sprint Time Multiplier ... true : enabled ... false : disabled"); + + jumpForceMulLower = cfg.Bind("General.Movement", "JumpForceMultiplierLowerBound", 1, "The Minimum Multiplier for Jump Force"); + jumpForceMulUpper = cfg.Bind("General.Movement", "JumpForceMultiplierUpperBound", 1, "The Maximum Multiplier for Jump Force"); + jumpForceMulEnabled = cfg.Bind("General.Movement.Toggles", "JumpForceMultiplierEnabled", true, "Enables Jump Force Multiplier ... true : enabled ... false : disabled"); + + climbSpeedMulLower = cfg.Bind("General.Movement", "ClimbSpeedMultiplierLowerBound", 1, "The Minimum Climb Speed Multiplier"); + climbSpeedMulUpper = cfg.Bind("General.Movement", "ClimbSpeedMultiplierUpperBound", 1, "The Maximum Climb Speed Multiplier"); + climbSpeedMulEnabled = cfg.Bind("General.Movement.Toggles", "ClimbSpeedMultiplierEnabled", true, "Enables Player Climb Speed Multiplier ... true : enabled ... false : disabled"); + + insanityMulLower = cfg.Bind("General.PlayerCharacteristics", "InsanitySpeedMultiplierLowerBound", 1, "The Minimum Insanity Speed Multiplier"); + insanityMulUpper = cfg.Bind("General.PlayerCharacteristics", "InsanitySpeedMultiplierUpperBound", 1, "The Maximum Insanity Speed Multiplier"); + insanityMulEnabled = cfg.Bind("General.PlayerCharacteristics.Toggles", "InsanitySpeedMultiplierEnabled", true, "Enables Insanity Speed Multiplier ... true : enabled ... false : disabled"); + + healthRegenMulLower = cfg.Bind("General.PlayerCharacteristics", "HealthRegenTimerLowerBound", 1, "The Minimum Health Regen Timer Multiplier : larger regen timer means slower health regen"); + healthRegenMulUpper = cfg.Bind("General.PlayerCharacteristics", "HealthRegenTimerUpperBound", 1, "The Maximum Health Regen Timer Multiplier : larger regen timer means slower health regen"); + healthRegenMulEnabled = cfg.Bind("General.PlayerCharacteristics", "HealthRegenTimerEnabled", true, "Enables Health Regen Timer Multiplier ... true : enabled ... false : disabled"); + + ClearOrphanedEntries(cfg); + + cfg.Save(); + cfg.SaveOnConfigSet = true; + + } + + public static void RequestSync() + { + if (!IsClient) return; + + FastBufferWriter stream = new FastBufferWriter(IntSize, Allocator.Temp); + MessageManager.SendNamedMessage("Random Company_OnRequestConfigSync", 0uL, stream); + } + + public static void OnRequestSync(ulong clientId, FastBufferReader _) + { + if (!IsHost) return; + + RandomCompany.logMessage($"Config sync request received from client: {clientId}"); + + byte[] array = SerializeToBytes(Instance); + int value = array.Length; + + FastBufferWriter stream = new FastBufferWriter(value + IntSize, Allocator.Temp); + + try + { + stream.WriteValueSafe(in value, default); + stream.WriteBytesSafe(array); + + MessageManager.SendNamedMessage("Random Company_OnReceiveConfigSync", clientId, stream); + } + catch (Exception e) + { + RandomCompany.logMessage($"Error occurred syncing config with client: {clientId}\n{e}"); + } + } + + public static void OnReceiveSync(ulong _, FastBufferReader reader) + { + if (!reader.TryBeginRead(IntSize)) + { + RandomCompany.logMessage("Config sync error: Could not begin reading buffer."); + return; + } + + reader.ReadValueSafe(out int val, default); + if (!reader.TryBeginRead(val)) + { + RandomCompany.logMessage("Config sync error: Host could not sync."); + return; + } + + byte[] data = new byte[val]; + reader.ReadBytesSafe(ref data, val); + + SyncInstance(data); + + RandomCompany.logMessage("Successfully synced config with host."); + } + + + + [HarmonyPostfix] + [HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")] + public static void PlayerLeave() + { + Config.RevertSync(); + } + static void ClearOrphanedEntries(ConfigFile cfg) + { + PropertyInfo orphanedEntriesProp = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries"); + var orphanedEntries = (Dictionary)orphanedEntriesProp.GetValue(cfg); + orphanedEntries.Clear(); + } + } +} diff --git a/MattRandomCompany/NuGet.Config b/MattRandomCompany/NuGet.Config new file mode 100644 index 0000000..1864ded --- /dev/null +++ b/MattRandomCompany/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MattRandomCompany/Patches/PlayerControllerBPatch.cs b/MattRandomCompany/Patches/PlayerControllerBPatch.cs new file mode 100644 index 0000000..e6f0e9b --- /dev/null +++ b/MattRandomCompany/Patches/PlayerControllerBPatch.cs @@ -0,0 +1,226 @@ +using BepInEx; +using GameNetcodeStuff; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RandomCompany.Patches +{ + [HarmonyPatch(typeof(PlayerControllerB))] + internal class PlayerControllerBPatch + { + + // insanity + + private static System.Random random; + + private static float movementSpeed; + private static float movementSpeedMulUpper; + private static float movementSpeedMulLower; + private static bool movementSpeedMulEnabled; + + private static float sprintTime; + private static float sprintTimeMulUpper; + private static float sprintTimeMulLower; + private static bool sprintTimeMulEnabled; + + private static float jumpForce; + private static float jumpForceMulUpper; + private static float jumpForceMulLower; + private static bool jumpForceMulEnabled; + + private static float climbSpeed; + private static float climbSpeedMultiplierUpper; + private static float climbSpeedMultiplierLower; + private static bool climbSpeedMultiplierEnabled; + + private static float insanityMul; + private static float insanityMulLower; + private static float insanityMulUpper; + private static bool insanityMulEnabled; + + private static float healthRegenMul; + private static float healthRegenMulUpper; + private static float healthRegenMulLower; + private static bool healthRegenMulEnabled; + private static bool healthMultiplied; + + public PlayerControllerBPatch() + { + random = new Random(); + + try + { + // Load movement speed multiplier values + movementSpeed = 0; + movementSpeedMulUpper = Config.Instance.moveSpeedMulUpper.Value; + movementSpeedMulLower = Config.Instance.moveSpeedMulLower.Value; + movementSpeedMulEnabled = Config.Instance.moveSpeedMulEnabled.Value; + if (movementSpeedMulLower > movementSpeedMulUpper || !movementSpeedMulEnabled) + { + movementSpeedMulLower = 1; + movementSpeedMulUpper = 1; + } + + // Load sprint time multiplier values + sprintTime = 0; + sprintTimeMulLower = Config.Instance.sprintTimeMulLower.Value; + sprintTimeMulUpper = Config.Instance.sprintTimeMulUpper.Value; + sprintTimeMulEnabled = Config.Instance.sprintTimeMulEnabled.Value; + if (sprintTimeMulLower > sprintTimeMulUpper || !sprintTimeMulEnabled) + { + sprintTimeMulLower = 1; + sprintTimeMulUpper = 1; + } + + // Load jump force values + jumpForce = 0; + jumpForceMulUpper = Config.Instance.jumpForceMulLower.Value; + jumpForceMulUpper = Config.Instance.jumpForceMulUpper.Value; + jumpForceMulEnabled = Config.Instance.jumpForceMulEnabled.Value; + if(jumpForceMulLower > jumpForceMulUpper || !jumpForceMulEnabled) + { + jumpForceMulLower = 1; + jumpForceMulUpper = 1; + } + + // Load climb speed multiplier values + climbSpeed = 0; + climbSpeedMultiplierUpper = Config.Instance.climbSpeedMulUpper.Value; + climbSpeedMultiplierLower = Config.Instance.climbSpeedMulLower.Value; + climbSpeedMultiplierEnabled = Config.Instance.climbSpeedMulEnabled.Value; + if (climbSpeedMultiplierLower > climbSpeedMultiplierUpper || !climbSpeedMultiplierEnabled) + { + climbSpeedMultiplierLower = 1; + climbSpeedMultiplierUpper = 1; + } + + // Load insanity multiplier values + insanityMul = 0; + insanityMulLower = Config.Instance.insanityMulLower.Value; + insanityMulUpper = Config.Instance.insanityMulUpper.Value; + insanityMulEnabled = Config.Instance.insanityMulEnabled.Value; + if(insanityMulLower > insanityMulUpper || !insanityMulEnabled) + { + insanityMulLower = 1; + insanityMulUpper = 1; + } + + // Load health regen values + healthRegenMul = 0; + healthRegenMulLower = Config.Instance.healthRegenMulLower.Value; + healthRegenMulUpper = Config.Instance.healthRegenMulUpper.Value; + healthRegenMulEnabled = Config.Instance.healthRegenMulEnabled.Value; + healthMultiplied = false; + if(healthRegenMulLower > healthRegenMulUpper || !healthRegenMulEnabled) { + healthRegenMulLower = 1; + healthRegenMulUpper = 1; + } + } + catch(Exception ex) + { + RandomCompany.logMessage("Error " + ex); + } + } + [HarmonyPatch("Update")] + [HarmonyPostfix] + static void RandomizePlayerControllerPatch(PlayerControllerB __instance) + { + // error handling + if(__instance == null) + { + RandomCompany.logMessage("failed to retrieve PlayerControllerB reference"); + return; + } + + // Set Player movement speed + if (movementSpeed == 0) + { + movementSpeed = __instance.movementSpeed * (movementSpeedMulLower + (float)(random.NextDouble() * (movementSpeedMulUpper - movementSpeedMulLower))); + } + __instance.movementSpeed = movementSpeed; + + // Set Player sprint time + if(sprintTime == 0) + { + sprintTime = __instance.sprintTime * (sprintTimeMulLower + (float)(random.NextDouble() * (sprintTimeMulUpper - sprintTimeMulLower))); + } + __instance.sprintTime = sprintTime; + + // Set Player jump force + if(jumpForce == 0) + { + + jumpForce = __instance.jumpForce * (jumpForceMulLower + (float)(random.NextDouble() * (jumpForceMulUpper - jumpForceMulLower))); + } + __instance.jumpForce = jumpForce; + + // Set Player climb speed + if (climbSpeed == 0) + { + climbSpeed = __instance.climbSpeed * (movementSpeedMulLower + (float)(random.NextDouble() * (climbSpeedMultiplierUpper - climbSpeedMultiplierLower))); + } + __instance.climbSpeed = climbSpeed; + + // Set player insanity multiplier + if(insanityMul == 0) + { + insanityMul = __instance.insanitySpeedMultiplier * (insanityMulLower + (float)(random.NextDouble() * (insanityMulUpper - insanityMulLower))); + } + __instance.insanitySpeedMultiplier = insanityMul; + + } + + + [HarmonyPatch("LateUpdate")] + [HarmonyPostfix] + static void RandomizeLateUpdatePatch(PlayerControllerB __instance) + { + random = new Random(); + + // Apply health regen timer multiplier + if(healthRegenMul == 0) + { + healthRegenMul = healthRegenMulLower + (float)(random.NextDouble() * (healthRegenMulUpper - healthRegenMulLower)); + } + if(__instance.healthRegenerateTimer == 1 && !healthMultiplied) + { + __instance.healthRegenerateTimer *= healthRegenMul; + healthMultiplied = true; + } + if(__instance.healthRegenerateTimer < 1) + { + healthMultiplied = false; + } + } + + [HarmonyPostfix] + [HarmonyPatch("ConnectClientToPlayerObject")] + public static void InitializeLocalPlayer() + { + if (Config.IsHost) + { + try + { + Config.MessageManager.RegisterNamedMessageHandler("ModName_OnRequestConfigSync", Config.OnRequestSync); + Config.Synced = true; + } + catch (Exception e) + { + RandomCompany.logMessage(e.ToString()); + } + + return; + } + + Config.Synced = false; + Config.MessageManager.RegisterNamedMessageHandler("ModName_OnReceiveConfigSync", Config.OnReceiveSync); + Config.RequestSync(); + } + + } +} diff --git a/MattRandomCompany/Patches/RoundManagerPatch.cs b/MattRandomCompany/Patches/RoundManagerPatch.cs new file mode 100644 index 0000000..31fa310 --- /dev/null +++ b/MattRandomCompany/Patches/RoundManagerPatch.cs @@ -0,0 +1,102 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BepInEx.Configuration; +using GameNetcodeStuff; + +namespace RandomCompany.Patches +{ + [HarmonyPatch(typeof(RoundManager))] + internal class RoundManagerPatch + { + private static System.Random random; + + // + + private static float scrapSpawnMul; + private static float scrapSpawnMulLower; // minimum value for min and max scrap multiplier + private static float scrapSpawnMulUpper; // maximum value for min and max scrap multiplier + private static bool scrapSpawnMulEnabled; + + private static float scrapValueMul; + private static float scrapValueMulLower; // minimum value for scrap value multiplier + private static float scrapValueMulUpper; // maximum value for scrap value multiplier + private static bool scrapValueMulEnabled; + + private static float factorySizeMul; + private static float factorySizeMulLower; + private static float factorySizeMulUpper; + private static bool factorySizeMulEnabled; + + public RoundManagerPatch() + { + scrapSpawnMul = 0; + scrapSpawnMulLower = Config.Instance.scrapSpawnMulLower.Value; + scrapSpawnMulUpper = Config.Instance.scrapSpawnMulUpper.Value; + scrapSpawnMulEnabled = Config.Instance.scrapSpawnMulEnabled.Value; + if (scrapSpawnMulLower > scrapSpawnMulUpper || !scrapSpawnMulEnabled) + { + scrapSpawnMulLower = 1; + scrapSpawnMulUpper = 1; + } + + scrapValueMul = 0; + scrapValueMulLower = Config.Instance.scrapValueMulLower.Value; + scrapValueMulUpper = Config.Instance.scrapValueMulUpper.Value; + scrapValueMulEnabled = Config.Instance.scrapValueMulEnabled.Value; + if (scrapValueMulLower > scrapValueMulUpper || !scrapValueMulEnabled) + { + scrapValueMulLower = 1; + scrapValueMulUpper = 1; + } + + factorySizeMul = 0; + factorySizeMulLower = Config.Instance.factorySizeMulLower.Value; + factorySizeMulUpper = Config.Instance.factorySizeMulUpper.Value; + factorySizeMulEnabled = Config.Instance.factorySizeMulEnabled.Value; + if (factorySizeMulLower > factorySizeMulUpper || !factorySizeMulEnabled) + { + factorySizeMulLower = 1; + factorySizeMulUpper = 1; + } + } + + + + [HarmonyPatch(nameof(RoundManager.SpawnScrapInLevel))] + [HarmonyPrefix] + static void RandomizeSpawnScrapPatch(ref RoundManager __instance) + { + random = new Random(); + + // Apply scrap spawn multiplier + if (scrapSpawnMul == 0) + { + scrapSpawnMul = __instance.scrapAmountMultiplier * (scrapSpawnMulLower + (float)(random.NextDouble() * (scrapSpawnMulUpper - scrapSpawnMulLower))); + } + __instance.scrapAmountMultiplier = scrapSpawnMul; + + // Apply scrap value multiplier + if (scrapValueMul == 0) + { + scrapValueMul = __instance.scrapValueMultiplier * (scrapValueMulLower + (float)(random.NextDouble() * (scrapValueMulUpper - scrapValueMulLower))); + } + __instance.scrapValueMultiplier = scrapValueMul; + } + + [HarmonyPatch(nameof(RoundManager.GenerateNewFloor))] + [HarmonyPrefix] + static void RandomizeGenerateNewFloorPatch(ref RoundManager __instance) + { + // Apply factory size multiplier + if (factorySizeMul == 0) + { + factorySizeMul = __instance.currentLevel.factorySizeMultiplier * (factorySizeMulLower + (float)(random.NextDouble() * (factorySizeMulUpper - factorySizeMulLower))); + } + __instance.currentLevel.factorySizeMultiplier = factorySizeMul; + } + } +} diff --git a/MattRandomCompany/Plugin.cs b/MattRandomCompany/Plugin.cs new file mode 100644 index 0000000..9da3105 --- /dev/null +++ b/MattRandomCompany/Plugin.cs @@ -0,0 +1,64 @@ +using BepInEx; +using BepInEx.Logging; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BepInEx.Configuration; +using RandomCompany.Patches; +using UnityEngine.Networking; +using Unity.Netcode; + +namespace RandomCompany +{ + /* + * What is randomized? + * Scrap spawn rates (.5x to 2x scrap) + * Scrap values + * + */ + + [BepInPlugin(modGUID, modName, modVersion)] + public class RandomCompany : BaseUnityPlugin + { + private const string modGUID = "M-Partridge.RandomCompany"; + private const string modName = "Random Company"; + private const string modVersion = "1.0.0"; + + private readonly Harmony harmony = new Harmony(modGUID); + + public static RandomCompany instance { get; private set; } = null; + private RoundManagerPatch rmp; + private PlayerControllerBPatch pcbp; + + internal static Config cfg { get; private set; } = null; + internal ManualLogSource mls; + + void Awake() + { + if (instance == null) + { + instance = this; + } + + mls = BepInEx.Logging.Logger.CreateLogSource(modGUID); + + cfg = new Config(base.Config); + rmp = new RoundManagerPatch(); + pcbp = new PlayerControllerBPatch(); + + mls.LogInfo(modName + " has started"); + + harmony.PatchAll(); + + + + } + public static void logMessage(string message) + { + instance.mls.LogInfo(modName + " : " + message); + } + } +} diff --git a/MattRandomCompany/RandomCompany.csproj b/MattRandomCompany/RandomCompany.csproj new file mode 100644 index 0000000..07ffdf8 --- /dev/null +++ b/MattRandomCompany/RandomCompany.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {2CCBA115-2782-4C0D-A62F-4FE348BF389A} + Library + Properties + RandomCompany + RandomCompany + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\0Harmony.dll + + + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Assembly-CSharp.dll + + + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\core\BepInEx.dll + + + + + + + + + + + False + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Collections.dll + + + + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.dll + + + ..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.CoreModule.dll + + + + + + + + + + + + \ No newline at end of file diff --git a/MattRandomCompany/SynchedInstance.cs b/MattRandomCompany/SynchedInstance.cs new file mode 100644 index 0000000..2c9becc --- /dev/null +++ b/MattRandomCompany/SynchedInstance.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Threading.Tasks; +using Unity.Netcode; + +namespace RandomCompany +{ + [Serializable] + public class SyncedInstance + { + internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager; + internal static bool IsClient => NetworkManager.Singleton.IsClient; + internal static bool IsHost => NetworkManager.Singleton.IsHost; + + [NonSerialized] + protected static int IntSize = 4; + + public static T Default { get; private set; } + public static T Instance { get; private set; } + + public static bool Synced { get; internal set; } + + protected void InitInstance(T instance) + { + Default = instance; + Instance = instance; + + // Makes sure the size of an integer is correct for the current system. + // We use 4 by default as that's the size of an int on 32 and 64 bit systems. + IntSize = sizeof(int); + } + + internal static void SyncInstance(byte[] data) + { + Instance = DeserializeFromBytes(data); + Synced = true; + } + + internal static void RevertSync() + { + Instance = Default; + Synced = false; + } + + public static byte[] SerializeToBytes(T val) + { + BinaryFormatter bf = new BinaryFormatter(); + MemoryStream stream = new MemoryStream(); + + try + { + bf.Serialize(stream, val); + return stream.ToArray(); + } + catch (Exception e) + { + RandomCompany.logMessage($"Error serializing instance: {e}"); + return null; + } + } + + public static T DeserializeFromBytes(byte[] data) + { + BinaryFormatter bf = new BinaryFormatter(); + MemoryStream stream = new MemoryStream(data); + + try + { + return (T)bf.Deserialize(stream); + } + catch (Exception e) + { + RandomCompany.logMessage($"Error deserializing instance: {e}"); + return default; + } + } + } +} diff --git a/MattRandomCompany/build/RandomCompany.dll b/MattRandomCompany/build/RandomCompany.dll new file mode 100644 index 0000000..0a57b85 Binary files /dev/null and b/MattRandomCompany/build/RandomCompany.dll differ diff --git a/MattRandomCompany/build/thunderstore.zip b/MattRandomCompany/build/thunderstore.zip new file mode 100644 index 0000000..54210a0 Binary files /dev/null and b/MattRandomCompany/build/thunderstore.zip differ diff --git a/MattRandomCompany/thunderstore/README.md b/MattRandomCompany/thunderstore/README.md new file mode 100644 index 0000000..8f8d6c7 --- /dev/null +++ b/MattRandomCompany/thunderstore/README.md @@ -0,0 +1,4 @@ +# Template Mod + +Put your description here! +Default icon by @lilujk on github. \ No newline at end of file diff --git a/MattRandomCompany/thunderstore/icon.png b/MattRandomCompany/thunderstore/icon.png new file mode 100644 index 0000000..07bc949 Binary files /dev/null and b/MattRandomCompany/thunderstore/icon.png differ diff --git a/MattRandomCompany/thunderstore/manifest.json b/MattRandomCompany/thunderstore/manifest.json new file mode 100644 index 0000000..da42bd0 --- /dev/null +++ b/MattRandomCompany/thunderstore/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "Template Mod", + "version_number": "0.0.1", + "website_url": "https://github.com/LCOS-Lethal-Company-Open-Source/LCOS-Mods", + "description": "A template mod", + "dependencies": [ + "BepInEx-BepInExPack-5.4.2100" + ] +} \ No newline at end of file diff --git a/MattTutorialMod/NuGet.Config b/MattTutorialMod/NuGet.Config new file mode 100644 index 0000000..1864ded --- /dev/null +++ b/MattTutorialMod/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MattTutorialMod/Patches/PlayerControllerBPatch.cs b/MattTutorialMod/Patches/PlayerControllerBPatch.cs new file mode 100644 index 0000000..4df6be5 --- /dev/null +++ b/MattTutorialMod/Patches/PlayerControllerBPatch.cs @@ -0,0 +1,21 @@ +using GameNetcodeStuff; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LCTutoritalMod.Patches +{ + [HarmonyPatch(typeof(PlayerControllerB))] + internal class PlayerControllerBPatch + { + [HarmonyPatch("Update")] + [HarmonyPostfix] + static void infiniteSprintPatch(ref float ___sprintMeter) + { + ___sprintMeter = 1f; + } + } +} diff --git a/MattTutorialMod/Plugin.cs b/MattTutorialMod/Plugin.cs new file mode 100644 index 0000000..b32cdea --- /dev/null +++ b/MattTutorialMod/Plugin.cs @@ -0,0 +1,39 @@ +using BepInEx; +using BepInEx.Logging; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LCTutoritalMod +{ + [BepInPlugin(modGUID, modName, modVersion)] + public class TutorialModBase : BaseUnityPlugin + { + private const string modGUID = "M-Partridge.LCTutorialMod"; + private const string modName = "LC Tutorial Mod"; + private const string modVersion = "1.0.0"; + + private readonly Harmony harmony = new Harmony(modGUID); + + private static TutorialModBase instance; + + internal ManualLogSource mls; + + void Awake() + { + if(instance == null) + { + instance = this; + } + + mls = BepInEx.Logging.Logger.CreateLogSource(modGUID); + + mls.LogInfo(modName + " has started"); + + harmony.PatchAll(); + } + } +} diff --git a/MattTutorialMod/Template.csproj b/MattTutorialMod/Template.csproj new file mode 100644 index 0000000..9096afb --- /dev/null +++ b/MattTutorialMod/Template.csproj @@ -0,0 +1,38 @@ + + + + netstandard2.1 + LCTutorialMod + A tutorial mod that gives the player infinite sprint + 1.0.0 + true + latest + + + + + + + + + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Assembly-CSharp.dll + + + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\UnityEngine.dll + + + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.TextMeshPro.dll + + + C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\Lethal Company_Data\Managed\Unity.Netcode.Runtime.dll + + + + + + + + + + + diff --git a/MattTutorialMod/build/LCTutoritalMod.dll b/MattTutorialMod/build/LCTutoritalMod.dll new file mode 100644 index 0000000..05eef55 Binary files /dev/null and b/MattTutorialMod/build/LCTutoritalMod.dll differ diff --git a/MattTutorialMod/build/thunderstore.zip b/MattTutorialMod/build/thunderstore.zip new file mode 100644 index 0000000..54210a0 Binary files /dev/null and b/MattTutorialMod/build/thunderstore.zip differ diff --git a/MattTutorialMod/thunderstore/README.md b/MattTutorialMod/thunderstore/README.md new file mode 100644 index 0000000..5306a14 --- /dev/null +++ b/MattTutorialMod/thunderstore/README.md @@ -0,0 +1,4 @@ +# LC Tutorial Mod + +A patch that gives players infinite sprint +Default icon by @lilujk on github. \ No newline at end of file diff --git a/MattTutorialMod/thunderstore/icon.png b/MattTutorialMod/thunderstore/icon.png new file mode 100644 index 0000000..07bc949 Binary files /dev/null and b/MattTutorialMod/thunderstore/icon.png differ diff --git a/MattTutorialMod/thunderstore/manifest.json b/MattTutorialMod/thunderstore/manifest.json new file mode 100644 index 0000000..0c14aba --- /dev/null +++ b/MattTutorialMod/thunderstore/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "LC Tutorial Mod", + "version_number": "1.0.0", + "website_url": "https://github.com/LCOS-Lethal-Company-Open-Source/LCOS-Mods", + "description": "A patch to give players infinite sprint", + "dependencies": [ + "BepInEx-BepInExPack-5.4.2100" + ] +} \ No newline at end of file