diff --git a/dumb282tweaks/Main.cs b/dumb282tweaks/Main.cs index 5983373..a13f15e 100644 --- a/dumb282tweaks/Main.cs +++ b/dumb282tweaks/Main.cs @@ -6,8 +6,20 @@ using UnityModManagerNet; using UnityEngine; using System.Collections.Generic; using DV; +using DV.Utils; +using DV.Simulation; +using DV.Common; +using System.Linq; +using System.Threading.Tasks; +using DV.RemoteControls; +using DV.Wheels; +using DV.Simulation.Cars; +using DV.ThingTypes; +using LocoSim.Implementations; +using static Oculus.Avatar.CAPI; using UnityEngine.UI; using System.ComponentModel; +using static UnityModManagerNet.UnityModManager.Param; namespace dumb282tweaks; @@ -16,6 +28,8 @@ public static class Main { public static UnityModManager.ModEntry Instance { get; private set; } public static dumb282tweaksSettings Settings { get; private set; } + public static bool enabled; + private static readonly string[] cabTypeTexts = new[] { "Default", //"Soviet", @@ -28,7 +42,8 @@ public static class Main { "German" }; - private static AssetBundle loadedAssetBundle; + public static GameObject fullCabLoad; + public static GameObject smokeDeflectorLoad; // Load private static bool Load(UnityModManager.ModEntry modEntry) { @@ -44,7 +59,13 @@ public static class Main { harmony = new Harmony(Instance.Info.Id); harmony.PatchAll(Assembly.GetExecutingAssembly()); - WorldStreamingInit.LoadingFinished += GameLoaded; + // Asset Loading + var assetPath = Path.Combine(Instance.Path.ToString(), "assets\\"); + var fullCabBundle = AssetBundle.LoadFromFile(Path.Combine(assetPath, "FullCab")); + var smokeDeflectorBundle = AssetBundle.LoadFromFile(Path.Combine(assetPath, "SmokeDeflector")); + fullCabLoad = fullCabBundle.LoadAsset("Assets/fullcab.prefab"); + smokeDeflectorLoad = smokeDeflectorBundle.LoadAsset("Assets/SmokeDeflector.prefab"); + } catch (Exception ex) { Instance.Logger.LogException($"Failed to load {Instance.Info.DisplayName}:", ex); harmony?.UnpatchAll(Instance.Info.Id); @@ -54,35 +75,10 @@ public static class Main { return true; } - private static void GameLoaded() { - WorldMover worldMoverScript = GameObject.Find("WorldMover").GetComponent(); - - // Asset Loading - var modelPath = Path.Combine(Instance.Path.ToString(), "assets\\fullcab"); - var loadedAssetBundle = AssetBundle.LoadFromFile(modelPath); - - GameObject fullCabLoad = loadedAssetBundle.LoadAsset("Assets/fullcab.prefab"); - - //GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); - GameObject fullCab = GameObject.Instantiate(fullCabLoad); - fullCab.transform.position = PlayerManager.GetWorldAbsolutePlayerPosition() + new Vector3(0, 6, 0); - fullCab.transform.localScale = new Vector3(1, 1, 1); - - fullCab.transform.position += WorldMover.currentMove; - worldMoverScript.AddObjectToMove(fullCab.transform); - - // Find all GameObjects - //foreach(GameObject obj in Resources.FindObjectsOfTypeAll()) { - - //} - } - // GUI Rendering static void OnGUI(UnityModManager.ModEntry modEntry) { GUILayout.BeginVertical(); - Settings.toggleTweaks = GUILayout.Toggle(Settings.toggleTweaks, "Toggle Tweaks"); - GUILayout.Label("Cab Type"); Settings.cabType = (CabType)GUILayout.SelectionGrid((int)Settings.cabType, cabTypeTexts, 1, "toggle"); GUILayout.Space(2); @@ -96,21 +92,29 @@ public static class Main { Settings.Save(modEntry); } - // Logger Commands - public static void Log(string message) { - Instance.Logger.Log(message); - } - public static void Warning(string message) { - Instance.Logger.Warning(message); - } - public static void Error(string message) { - Instance.Logger.Error(message); + [HarmonyPatch(typeof(TrainCar), "Start")] + class CarPatch { + static void Postfix(ref TrainCar __instance) { + if(__instance is not null && __instance.carType == TrainCarType.LocoSteamHeavy) { + GameObject fullCab = UnityEngine.Object.Instantiate(fullCabLoad); + fullCab.transform.parent = __instance.transform; + fullCab.transform.localPosition = new Vector3(0, 3, 0); + fullCab.transform.localRotation = Quaternion.identity; + fullCab.transform.localScale = new Vector3(1, 1, 1); + + GameObject smokeDeflector = UnityEngine.Object.Instantiate(smokeDeflectorLoad); + smokeDeflector.transform.parent = __instance.transform; + smokeDeflector.transform.localPosition = new Vector3(0, 2.55f, 10.23f); + smokeDeflector.transform.localRotation = Quaternion.identity; + smokeDeflector.transform.localScale = new Vector3(1, 1, 1); + } + } } public enum CabType { [Description("Default 282 Cab")] Default, - [Description("German Type Cab")] + [Description("German Cab")] German } @@ -132,4 +136,15 @@ public static class Main { Save(this, modEntry); } } + + // Logger Commands + public static void Log(string message) { + Instance.Logger.Log(message); + } + public static void Warning(string message) { + Instance.Logger.Warning(message); + } + public static void Error(string message) { + Instance.Logger.Error(message); + } } diff --git a/dumb282tweaks/dumb282tweaks.csproj b/dumb282tweaks/dumb282tweaks.csproj index a282cfb..bcb50c7 100644 --- a/dumb282tweaks/dumb282tweaks.csproj +++ b/dumb282tweaks/dumb282tweaks.csproj @@ -31,9 +31,69 @@ G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\Assembly-CSharp-firstpass.dll + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.BrakeSystem.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Common.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.ControllerAnchors.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Highlighting.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Interaction.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Inventory.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Localization.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.NAudio.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.PointSet.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.RadioPlayer.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Scenarios.CRUD.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Simulation.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Telemetry.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.TerrainSystem.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.TerrainTools.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.ThingTypes.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.UI.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.UIFramework.dll + + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.UserManagement.dll + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.Utils.dll + + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\DV.WeatherSystem.dll + G:\SteamLibrary\steamapps\common\Derail Valley\DerailValley_Data\Managed\UnityEngine.dll