diff --git a/(unusedfolder) assets/fullcab b/assets/fullcab similarity index 100% rename from (unusedfolder) assets/fullcab rename to assets/fullcab diff --git a/(unusedfolder) assets/streamline b/assets/streamline similarity index 100% rename from (unusedfolder) assets/streamline rename to assets/streamline diff --git a/(unusedfolder) assets/wagnersmokedeflectors b/assets/wagnersmokedeflectors similarity index 100% rename from (unusedfolder) assets/wagnersmokedeflectors rename to assets/wagnersmokedeflectors diff --git a/(unusedfolder) assets/wittesmokedeflectors b/assets/wittesmokedeflectors similarity index 100% rename from (unusedfolder) assets/wittesmokedeflectors rename to assets/wittesmokedeflectors diff --git a/dumb282tweaks/CarPatch.cs b/dumb282tweaks/CarPatch.cs index a4bbbe9..d73d584 100644 --- a/dumb282tweaks/CarPatch.cs +++ b/dumb282tweaks/CarPatch.cs @@ -8,160 +8,64 @@ namespace dumb282tweaks; [HarmonyPatch(typeof(TrainCar), "Start")] class CarPatch { - static void Postfix(ref TrainCar __instance) { - // Smoke Deflector Type - if(__instance != null && __instance.carType == TrainCarType.LocoSteamHeavy) { - // This is a terrible way to get the mesh of the locomotive since a simple gameobject reordering will break it, but it's alright for now. If something breaks, just note that this is likely the reason - Transform s282Body = __instance.transform.GetChild(5).transform.GetChild(0).transform.GetChild(0); - // This is a better way of getting the mesh, but I don't feel like trying to understand transform.Find, so I'll come back this later.I think the directory with slashes needs to be exactly parents and children, no skipping levels - //Transform s282Mesh = __instance.transform.Find("LocoS282A_Body/s282_locomotive_body"); + static void Postfix(ref TrainCar __instance) + { + if(__instance != null && __instance.carType == TrainCarType.LocoSteamHeavy) + { + string bodyPath = "LocoS282A_Body/Static_LOD0/s282_locomotive_body"; + Transform s282Body = __instance.transform.Find(bodyPath); + if (s282Body == null) + { + Error($"Couldn't find S282 body on '{__instance.transform.gameObject.name}' -> {bodyPath}"); + return; + } + Material s282Mat = s282Body.GetComponent().material; - s282Body.gameObject.SetActive(false); - - if(Main.Settings.regularBody) { - GameObject s282BodyNew = UnityEngine.Object.Instantiate(s282BodyLoad); - - s282BodyNew.transform.GetChild(0).GetComponent().material = s282Mat; - - s282BodyNew.transform.parent = __instance.transform; - s282BodyNew.transform.localPosition = new Vector3(0, -0.13f, 6.98f); - s282BodyNew.transform.localRotation = Quaternion.identity; - } - - //switch(Main.Settings.boilerType) { - // case Settings.BoilerType.Default: - // break; - // case Settings.BoilerType.Streamlined: - // GameObject streamlinedBoiler = UnityEngine.Object.Instantiate(streamlineLoad); - - // streamlinedBoiler.transform.GetChild(0).GetComponent().material = s282Mat; - - // streamlinedBoiler.transform.parent = __instance.transform; - // streamlinedBoiler.transform.localPosition = new Vector3(0, 2.15f, 5.1f); - // streamlinedBoiler.transform.localRotation = Quaternion.identity; - // break; - //} - - // Cab Type - switch(Main.Settings.cabType) { - case Settings.CabType.Default: - GameObject defaultCab = UnityEngine.Object.Instantiate(defaultCabLoad); - - defaultCab.transform.GetChild(0).GetComponent().material = s282Mat; - - defaultCab.transform.parent = __instance.transform; - defaultCab.transform.localPosition = new Vector3(0, -0.13f, 6.98f); - defaultCab.transform.localRotation = Quaternion.identity; - break; - case Settings.CabType.German: - GameObject germanCab = UnityEngine.Object.Instantiate(germanCabLoad); - - germanCab.transform.GetChild(0).GetComponent().material = s282Mat; - germanCab.transform.GetChild(1).GetComponent().material = s282Mat; - germanCab.transform.GetChild(2).GetComponent().material = s282Mat; - germanCab.transform.GetChild(3).GetComponent().material = s282Mat; - - germanCab.transform.parent = __instance.transform; - germanCab.transform.localPosition = new Vector3(0, -0.13f, 6.98f); - germanCab.transform.localRotation = Quaternion.identity; - //Log(externalInteractables.name); - - //externalInteractables.gameObject.SetActive(false); - break; - } // Smoke Deflector switch(Main.Settings.smokeDeflectorType) { - case Settings.SmokeDeflectorType.None: - break; case Settings.SmokeDeflectorType.Witte: - GameObject witteSmokeDeflector = UnityEngine.Object.Instantiate(witteSmokeDeflectorsLoad); - - //This is a terrible way to set the material of the smoke deflectors, but oh well - witteSmokeDeflector.transform.GetChild(0).GetComponent().material = s282Mat; - witteSmokeDeflector.transform.GetChild(1).GetComponent().material = s282Mat; - witteSmokeDeflector.transform.GetChild(3).GetComponent().material = s282Mat; - - witteSmokeDeflector.transform.parent = __instance.transform; - witteSmokeDeflector.transform.localPosition = new Vector3(0, -0.15f, 6.9f); - witteSmokeDeflector.transform.localRotation = Quaternion.identity; Log("witte"); - if(Main.Settings.bluetooth) { - witteSmokeDeflector.transform.GetChild(0).gameObject.SetActive(false); + + GameObject witteSmokeDeflector = Object.Instantiate(witteSmokeDeflectorsLoad, __instance.transform); + witteSmokeDeflector.transform.localPosition = new Vector3(0.0f, 2.1f, 5f); + witteSmokeDeflector.transform.localRotation = Quaternion.identity; + + foreach (var aMeshRenderer in witteSmokeDeflector.GetComponentsInChildren()) + { + aMeshRenderer.material = s282Mat; } + break; case Settings.SmokeDeflectorType.Wagner: - GameObject wagnerSmokeDeflector = UnityEngine.Object.Instantiate(wagnerSmokeDeflectorsLoad); - - // This is still a terrible way to set the material of the smoke deflectors - wagnerSmokeDeflector.transform.GetChild(0).GetComponent().material = s282Mat; - wagnerSmokeDeflector.transform.GetChild(1).GetComponent().material = s282Mat; - - wagnerSmokeDeflector.transform.parent = __instance.transform; - wagnerSmokeDeflector.transform.localPosition = new Vector3(0, -0.15f, 6.98f); - wagnerSmokeDeflector.transform.localRotation = Quaternion.identity; Log("witten't"); + + GameObject wagnerSmokeDeflector = Object.Instantiate(wagnerSmokeDeflectorsLoad, __instance.transform); + wagnerSmokeDeflector.transform.localPosition = new Vector3(0.0f, 2.1f, 5f); + wagnerSmokeDeflector.transform.localRotation = Quaternion.identity; + + foreach (var aMeshRenderer in wagnerSmokeDeflector.GetComponentsInChildren()) + { + aMeshRenderer.material = s282Mat; + } + break; } - // Smoke Stack - switch(Main.Settings.smokeStackType) { - case Settings.SmokeStackType.Default: - GameObject defaultSmokeStack = UnityEngine.Object.Instantiate(defaultSmokeStackLoad); + // Boiler + switch (Main.Settings.boilerType) + { + case Settings.BoilerType.Streamlined: + GameObject streamlinedBoiler = Object.Instantiate(streamlinedBoilerLoad, __instance.transform); + streamlinedBoiler.transform.localPosition = new Vector3(0.0f, 2.15f, 5.1f); + streamlinedBoiler.transform.localRotation = Quaternion.identity; - defaultSmokeStack.transform.GetChild(0).GetComponent().material = s282Mat; + foreach (var aMeshRenderer in streamlinedBoiler.GetComponentsInChildren()) + { + aMeshRenderer.material = s282Mat; + } - defaultSmokeStack.transform.parent = __instance.transform; - defaultSmokeStack.transform.localPosition = new Vector3(0, -0.15f, 6.98f); - defaultSmokeStack.transform.localRotation = Quaternion.identity; break; - case Settings.SmokeStackType.Short: - GameObject shortSmokeStack = UnityEngine.Object.Instantiate(shortSmokeStackLoad); - - shortSmokeStack.transform.GetChild(0).GetComponent().material = s282Mat; - - shortSmokeStack.transform.parent = __instance.transform; - shortSmokeStack.transform.localPosition = new Vector3(0, -0.15f, 6.98f); - shortSmokeStack.transform.localRotation = Quaternion.identity; - break; - } - - // Extras - if(Main.Settings.cowCatcher) { - GameObject cowCatcher = UnityEngine.Object.Instantiate(cowCatcherLoad); - - cowCatcher.transform.GetChild(0).GetComponent().material = s282Mat; - - cowCatcher.transform.parent = __instance.transform; - cowCatcher.transform.localPosition = new Vector3(0, -0.15f, 6.98f); - cowCatcher.transform.localRotation = Quaternion.identity; - } - if(Main.Settings.frontCover) { - GameObject frontCover = UnityEngine.Object.Instantiate(frontCoverLoad); - - frontCover.transform.GetChild(0).GetComponent().material = s282Mat; - - frontCover.transform.parent = __instance.transform; - frontCover.transform.localPosition = new Vector3(0, -0.15f, 6.98f); - frontCover.transform.localRotation = Quaternion.identity; - } - if(Main.Settings.railings) { - GameObject railings = UnityEngine.Object.Instantiate(railingsLoad); - - railings.transform.GetChild(0).GetComponent().material = s282Mat; - - railings.transform.parent = __instance.transform; - railings.transform.localPosition = new Vector3(0, -0.15f, 6.98f); - railings.transform.localRotation = Quaternion.identity; - } - if(Main.Settings.walkway) { - GameObject walkway = UnityEngine.Object.Instantiate(walkwayLoad); - - walkway.transform.GetChild(0).GetComponent().material = s282Mat; - - walkway.transform.parent = __instance.transform; - walkway.transform.localPosition = new Vector3(0, -0.15f, 6.98f); - walkway.transform.localRotation = Quaternion.identity; } } } diff --git a/dumb282tweaks/InteriorPatch.cs b/dumb282tweaks/InteriorPatch.cs index be03b23..e5a4626 100644 --- a/dumb282tweaks/InteriorPatch.cs +++ b/dumb282tweaks/InteriorPatch.cs @@ -1,32 +1,32 @@ -using HarmonyLib; -using UnityEngine; - -using static dumb282tweaks.Main; - -namespace dumb282tweaks; - -[HarmonyPatch(typeof(TrainCar), "LoadInterior")] -class InteriorPatch { - static void Postfix(ref TrainCar __instance) { - Transform s282Interior = __instance.interior; - Transform externalInteractables = s282Interior.transform.Find("LocoS282A_ExternalInteractables(Clone)"); - // The fact that in game it actually is called "things" is funny to me - Transform cab = s282Interior.transform.Find("LocoS282A_Interior(Clone)/Static/Cab"); - Transform things = s282Interior.transform.Find("LocoS282A_Interior(Clone)/Static/Things"); - Transform windowRMove = externalInteractables.transform.Find("Interactables/WindowR"); - Transform windowLMove = externalInteractables.transform.Find("Interactables/WindowL"); - - Log(externalInteractables.name); - - switch(Main.Settings.cabType) { - case Settings.CabType.Default: - break; - case Settings.CabType.German: - cab.gameObject.SetActive(false); - things.gameObject.SetActive(false); - windowRMove.gameObject.SetActive(false); - windowLMove.gameObject.SetActive(false); - break; - } - } -} +// using HarmonyLib; +// using UnityEngine; +// +// using static dumb282tweaks.Main; +// +// namespace dumb282tweaks; +// +// [HarmonyPatch(typeof(TrainCar), "LoadInterior")] +// class InteriorPatch { +// static void Postfix(ref TrainCar __instance) { +// Transform s282Interior = __instance.interior; +// Transform externalInteractables = s282Interior.transform.Find("LocoS282A_ExternalInteractables(Clone)"); +// // The fact that in game it actually is called "things" is funny to me +// Transform cab = s282Interior.transform.Find("LocoS282A_Interior(Clone)/Static/Cab"); +// Transform things = s282Interior.transform.Find("LocoS282A_Interior(Clone)/Static/Things"); +// Transform windowRMove = externalInteractables.transform.Find("Interactables/WindowR"); +// Transform windowLMove = externalInteractables.transform.Find("Interactables/WindowL"); +// +// Log(externalInteractables.name); +// +// switch(Main.Settings.cabType) { +// case Settings.CabType.Default: +// break; +// case Settings.CabType.German: +// cab.gameObject.SetActive(false); +// things.gameObject.SetActive(false); +// windowRMove.gameObject.SetActive(false); +// windowLMove.gameObject.SetActive(false); +// break; +// } +// } +// } diff --git a/dumb282tweaks/Main.cs b/dumb282tweaks/Main.cs index 518e045..c805120 100644 --- a/dumb282tweaks/Main.cs +++ b/dumb282tweaks/Main.cs @@ -26,28 +26,14 @@ public static class Main { "Default", "Streamlined" }; - public static readonly string[] smokeStackTypeTexts = new[] { - "Default", - "Short", - }; - // Base - [AllowNull] public static GameObject s282BodyLoad; - // Boilers - [AllowNull] public static GameObject streamlineLoad; - // Cabs - [AllowNull] public static GameObject defaultCabLoad; - [AllowNull] public static GameObject germanCabLoad; + // public static readonly string[] smokeStackTypeTexts = new[] { + // "Default", + // "Short", + // }; [AllowNull] public static GameObject wagnerSmokeDeflectorsLoad; [AllowNull] public static GameObject witteSmokeDeflectorsLoad; - - [AllowNull] public static GameObject defaultSmokeStackLoad; - [AllowNull] public static GameObject shortSmokeStackLoad; - - [AllowNull] public static GameObject cowCatcherLoad; - [AllowNull] public static GameObject frontCoverLoad; - [AllowNull] public static GameObject railingsLoad; - [AllowNull] public static GameObject walkwayLoad; + [AllowNull] public static GameObject streamlinedBoilerLoad; // Load private static bool Load(UnityModManager.ModEntry modEntry) { @@ -63,44 +49,12 @@ public static class Main { harmony = new Harmony(Instance.Info.Id); harmony.PatchAll(Assembly.GetExecutingAssembly()); - string assetPath = Path.Combine(Instance.Path.ToString(), "assets\\"); + string assetPath = Path.Combine(Instance.Path, "assets\\"); + + wagnerSmokeDeflectorsLoad = AssetBundle.LoadFromFile(Path.Combine(assetPath, "wagnersmokedeflectors")).LoadAsset("Assets/WagnerSmokeDeflectors.prefab"); + witteSmokeDeflectorsLoad = AssetBundle.LoadFromFile(Path.Combine(assetPath, "wittesmokedeflectors")).LoadAsset("Assets/WitteSmokeDeflectors.prefab"); + streamlinedBoilerLoad = AssetBundle.LoadFromFile(Path.Combine(assetPath, "streamline")).LoadAsset("Assets/Streamline.prefab"); - // Base - string baseAssetPath = Path.Combine(assetPath, "Base\\"); - var s282BodyBundle = AssetBundle.LoadFromFile(Path.Combine(baseAssetPath, "s282body")); - s282BodyLoad = s282BodyBundle.LoadAsset("Assets/S282Body.prefab"); - // Boilers - string boilersAssetPat = Path.Combine(assetPath, "Boilers\\"); - var streamlineBundle = AssetBundle.LoadFromFile(Path.Combine(boilersAssetPat, "streamline")); - streamlineLoad = streamlineBundle.LoadAsset("Assets/Streamline.prefab"); - // Cabs - string cabsAssetPath = Path.Combine(assetPath, "Cabs\\"); - var defaultCabBundle = AssetBundle.LoadFromFile(Path.Combine(cabsAssetPath, "defaultcab")); - defaultCabLoad = defaultCabBundle.LoadAsset("Assets/DefaultCab.prefab"); - var germanCabBundle = AssetBundle.LoadFromFile(Path.Combine(cabsAssetPath, "germancab")); - germanCabLoad = germanCabBundle.LoadAsset("Assets/GermanCab.prefab"); - // Smoke Deflectors - string smokeDeflectorsAssetPath = Path.Combine(assetPath, "SmokeDeflectors\\"); - var wagnerSmokeDeflectorsBundle = AssetBundle.LoadFromFile(Path.Combine(smokeDeflectorsAssetPath, "wagnersmokedeflectors")); - wagnerSmokeDeflectorsLoad = wagnerSmokeDeflectorsBundle.LoadAsset("Assets/WagnerSmokeDeflectors.prefab"); - var witteSmokeDeflectorsBundle = AssetBundle.LoadFromFile(Path.Combine(smokeDeflectorsAssetPath, "wittesmokedeflectors")); - witteSmokeDeflectorsLoad = witteSmokeDeflectorsBundle.LoadAsset("Assets/WitteSmokeDeflectors.prefab"); - // Smoke Stacks - string smokeStacksAssetPath = Path.Combine(assetPath, "SmokeStacks\\"); - var defaultSmokeStackBundle = AssetBundle.LoadFromFile(Path.Combine(smokeStacksAssetPath, "defaultsmokestack")); - defaultSmokeStackLoad = defaultSmokeStackBundle.LoadAsset("Assets/DefaultSmokeStack.prefab"); - var shortSmokeStackBundle = AssetBundle.LoadFromFile(Path.Combine(smokeStacksAssetPath, "shortsmokestack")); - shortSmokeStackLoad = shortSmokeStackBundle.LoadAsset("Assets/ShortSmokeStack.prefab"); - // Extras - string extrasAssetPath = Path.Combine(assetPath, "Extras\\"); - var cowCatcherBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "cowcatcher")); - cowCatcherLoad = cowCatcherBundle.LoadAsset("Assets/CowCatcher.prefab"); - var frontCoverBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "frontcover")); - frontCoverLoad = frontCoverBundle.LoadAsset("Assets/FrontCover.prefab"); - var railingsBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "railings")); - railingsLoad = railingsBundle.LoadAsset("Assets/Railings.prefab"); - var walkwayBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "walkway")); - walkwayLoad = walkwayBundle.LoadAsset("Assets/Walkway.prefab"); } catch(Exception ex) { Instance.Logger.LogException($"Failed to load {Instance.Info.DisplayName}:", ex); harmony?.UnpatchAll(Instance.Info.Id); @@ -117,24 +71,17 @@ public static class Main { GUILayout.Label("These settings are applied on train spawn, meaning rejoining the game will refresh all 282 locos to the settings specified here, but if you don't unload the train it will keep whatever settings were there previously. This is a temporary solution until I have a proper GUI implemented."); GUILayout.Label("Also, reloading a save will currently break things and the tweaks won't load. This isn't good."); - GUILayout.Label("Boiler Type"); - Settings.boilerType = (Settings.BoilerType) GUILayout.SelectionGrid((int) Settings.boilerType, boilerTypeTexts, 1, "toggle"); - GUILayout.Label("Cab Type"); - Settings.cabType = (Settings.CabType)GUILayout.SelectionGrid((int) Settings.cabType, cabTypeTexts, 1, "toggle"); + GUILayout.Space(2f); + + //todo this is not implemented + // GUILayout.Label("Cab Type"); + // Settings.cabType = (Settings.CabType) GUILayout.SelectionGrid((int) Settings.cabType, cabTypeTexts, 1, "toggle"); + GUILayout.Label("Smoke Deflector Type"); Settings.smokeDeflectorType = (Settings.SmokeDeflectorType) GUILayout.SelectionGrid((int) Settings.smokeDeflectorType, smokeDeflectorTypeTexts, 1, "toggle"); - GUILayout.Label("Smoke Stack Type"); - Settings.smokeStackType = (Settings.SmokeStackType) GUILayout.SelectionGrid((int) Settings.smokeStackType, smokeStackTypeTexts, 1, "toggle"); - GUILayout.Label("Extras"); - Settings.cowCatcher = GUILayout.Toggle(Settings.cowCatcher, "Cow Catcher"); - Settings.frontCover = GUILayout.Toggle(Settings.frontCover, "Front Cover"); - Settings.railings = GUILayout.Toggle(Settings.railings, "Railings"); - Settings.walkway = GUILayout.Toggle(Settings.walkway, "Walkway"); - - GUILayout.Label("The dumb in Dumb S282 Tweaks"); - Settings.bluetooth = GUILayout.Toggle(Settings.bluetooth, "Bluetooth"); - Settings.flattensyour282 = GUILayout.Toggle(Settings.flattensyour282, "Flattens Your 282"); + GUILayout.Label("Boiler Type"); + Settings.boilerType = (Settings.BoilerType) GUILayout.SelectionGrid((int) Settings.boilerType, boilerTypeTexts, 1, "toggle"); GUILayout.EndVertical(); } diff --git a/dumb282tweaks/Settings.cs b/dumb282tweaks/Settings.cs index 2030f2a..b46b151 100644 --- a/dumb282tweaks/Settings.cs +++ b/dumb282tweaks/Settings.cs @@ -25,28 +25,12 @@ public static class Settings { [Description("Wagner Smoke Deflectors")] Wagner, } - public enum SmokeStackType { - [Description("Default Smoke Stack")] - Default, - [Description("Short Smoke Stack")] - Short, - } } public class dumb282tweaksSettings : UnityModManager.ModSettings { - public bool bluetooth = false; - public bool flattensyour282 = false; - - public bool regularBody = true; - public BoilerType boilerType = BoilerType.Default; - public CabType cabType = CabType.Default; + // public CabType cabType = CabType.Default; public SmokeDeflectorType smokeDeflectorType = SmokeDeflectorType.Wagner; - public SmokeStackType smokeStackType = SmokeStackType.Default; - - public bool cowCatcher = true; - public bool frontCover = false; - public bool railings = true; - public bool walkway = true; + public BoilerType boilerType = BoilerType.Default; public override void Save(UnityModManager.ModEntry modEntry) { Save(this, modEntry); diff --git a/package.ps1 b/package.ps1 index 0a2de59..bdf7568 100644 --- a/package.ps1 +++ b/package.ps1 @@ -4,7 +4,7 @@ param ( ) Set-Location "$PSScriptRoot" -$FilesToInclude = "info.json","build/*","LICENSE" +$FilesToInclude = "info.json","build/*","LICENSE","assets" $modInfo = Get-Content -Raw -Path "info.json" | ConvertFrom-Json $modId = $modInfo.Id @@ -20,6 +20,7 @@ $ZipOutDir = "$ZipWorkDir/$modId" New-Item "$ZipOutDir" -ItemType Directory -Force Copy-Item -Force -Path $FilesToInclude -Destination "$ZipOutDir" +Copy-Item -Force -Path "assets/*" -Destination "$ZipOutDir/assets" if (!$NoArchive) {