make it working, more cleanup

master
t0stiman 2023-11-12 19:47:12 +01:00
parent 4e4ead80f3
commit 5f709ea385
9 changed files with 96 additions and 260 deletions

View File

@ -8,160 +8,64 @@ namespace dumb282tweaks;
[HarmonyPatch(typeof(TrainCar), "Start")] [HarmonyPatch(typeof(TrainCar), "Start")]
class CarPatch { class CarPatch {
static void Postfix(ref TrainCar __instance) { static void Postfix(ref TrainCar __instance)
// Smoke Deflector Type {
if(__instance != null && __instance.carType == TrainCarType.LocoSteamHeavy) { 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); string bodyPath = "LocoS282A_Body/Static_LOD0/s282_locomotive_body";
// 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 s282Body = __instance.transform.Find(bodyPath);
//Transform s282Mesh = __instance.transform.Find("LocoS282A_Body/s282_locomotive_body"); if (s282Body == null)
{
Error($"Couldn't find S282 body on '{__instance.transform.gameObject.name}' -> {bodyPath}");
return;
}
Material s282Mat = s282Body.GetComponent<MeshRenderer>().material; Material s282Mat = s282Body.GetComponent<MeshRenderer>().material;
s282Body.gameObject.SetActive(false);
if(Main.Settings.regularBody) {
GameObject s282BodyNew = UnityEngine.Object.Instantiate(s282BodyLoad);
s282BodyNew.transform.GetChild(0).GetComponent<MeshRenderer>().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<MeshRenderer>().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<MeshRenderer>().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<MeshRenderer>().material = s282Mat;
germanCab.transform.GetChild(1).GetComponent<MeshRenderer>().material = s282Mat;
germanCab.transform.GetChild(2).GetComponent<MeshRenderer>().material = s282Mat;
germanCab.transform.GetChild(3).GetComponent<MeshRenderer>().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 // Smoke Deflector
switch(Main.Settings.smokeDeflectorType) { switch(Main.Settings.smokeDeflectorType) {
case Settings.SmokeDeflectorType.None:
break;
case Settings.SmokeDeflectorType.Witte: 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<MeshRenderer>().material = s282Mat;
witteSmokeDeflector.transform.GetChild(1).GetComponent<MeshRenderer>().material = s282Mat;
witteSmokeDeflector.transform.GetChild(3).GetComponent<MeshRenderer>().material = s282Mat;
witteSmokeDeflector.transform.parent = __instance.transform;
witteSmokeDeflector.transform.localPosition = new Vector3(0, -0.15f, 6.9f);
witteSmokeDeflector.transform.localRotation = Quaternion.identity;
Log("witte"); 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<MeshRenderer>())
{
aMeshRenderer.material = s282Mat;
} }
break; break;
case Settings.SmokeDeflectorType.Wagner: 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<MeshRenderer>().material = s282Mat;
wagnerSmokeDeflector.transform.GetChild(1).GetComponent<MeshRenderer>().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"); 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<MeshRenderer>())
{
aMeshRenderer.material = s282Mat;
}
break; break;
} }
// Smoke Stack // Boiler
switch(Main.Settings.smokeStackType) { switch (Main.Settings.boilerType)
case Settings.SmokeStackType.Default: {
GameObject defaultSmokeStack = UnityEngine.Object.Instantiate(defaultSmokeStackLoad); 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<MeshRenderer>().material = s282Mat; foreach (var aMeshRenderer in streamlinedBoiler.GetComponentsInChildren<MeshRenderer>())
{
aMeshRenderer.material = s282Mat;
}
defaultSmokeStack.transform.parent = __instance.transform;
defaultSmokeStack.transform.localPosition = new Vector3(0, -0.15f, 6.98f);
defaultSmokeStack.transform.localRotation = Quaternion.identity;
break; break;
case Settings.SmokeStackType.Short:
GameObject shortSmokeStack = UnityEngine.Object.Instantiate(shortSmokeStackLoad);
shortSmokeStack.transform.GetChild(0).GetComponent<MeshRenderer>().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<MeshRenderer>().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<MeshRenderer>().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<MeshRenderer>().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<MeshRenderer>().material = s282Mat;
walkway.transform.parent = __instance.transform;
walkway.transform.localPosition = new Vector3(0, -0.15f, 6.98f);
walkway.transform.localRotation = Quaternion.identity;
} }
} }
} }

View File

@ -1,32 +1,32 @@
using HarmonyLib; // using HarmonyLib;
using UnityEngine; // using UnityEngine;
//
using static dumb282tweaks.Main; // using static dumb282tweaks.Main;
//
namespace dumb282tweaks; // namespace dumb282tweaks;
//
[HarmonyPatch(typeof(TrainCar), "LoadInterior")] // [HarmonyPatch(typeof(TrainCar), "LoadInterior")]
class InteriorPatch { // class InteriorPatch {
static void Postfix(ref TrainCar __instance) { // static void Postfix(ref TrainCar __instance) {
Transform s282Interior = __instance.interior; // Transform s282Interior = __instance.interior;
Transform externalInteractables = s282Interior.transform.Find("LocoS282A_ExternalInteractables(Clone)"); // Transform externalInteractables = s282Interior.transform.Find("LocoS282A_ExternalInteractables(Clone)");
// The fact that in game it actually is called "things" is funny to me // // 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 cab = s282Interior.transform.Find("LocoS282A_Interior(Clone)/Static/Cab");
Transform things = s282Interior.transform.Find("LocoS282A_Interior(Clone)/Static/Things"); // Transform things = s282Interior.transform.Find("LocoS282A_Interior(Clone)/Static/Things");
Transform windowRMove = externalInteractables.transform.Find("Interactables/WindowR"); // Transform windowRMove = externalInteractables.transform.Find("Interactables/WindowR");
Transform windowLMove = externalInteractables.transform.Find("Interactables/WindowL"); // Transform windowLMove = externalInteractables.transform.Find("Interactables/WindowL");
//
Log(externalInteractables.name); // Log(externalInteractables.name);
//
switch(Main.Settings.cabType) { // switch(Main.Settings.cabType) {
case Settings.CabType.Default: // case Settings.CabType.Default:
break; // break;
case Settings.CabType.German: // case Settings.CabType.German:
cab.gameObject.SetActive(false); // cab.gameObject.SetActive(false);
things.gameObject.SetActive(false); // things.gameObject.SetActive(false);
windowRMove.gameObject.SetActive(false); // windowRMove.gameObject.SetActive(false);
windowLMove.gameObject.SetActive(false); // windowLMove.gameObject.SetActive(false);
break; // break;
} // }
} // }
} // }

View File

@ -26,28 +26,14 @@ public static class Main {
"Default", "Default",
"Streamlined" "Streamlined"
}; };
public static readonly string[] smokeStackTypeTexts = new[] { // public static readonly string[] smokeStackTypeTexts = new[] {
"Default", // "Default",
"Short", // "Short",
}; // };
// Base
[AllowNull] public static GameObject s282BodyLoad;
// Boilers
[AllowNull] public static GameObject streamlineLoad;
// Cabs
[AllowNull] public static GameObject defaultCabLoad;
[AllowNull] public static GameObject germanCabLoad;
[AllowNull] public static GameObject wagnerSmokeDeflectorsLoad; [AllowNull] public static GameObject wagnerSmokeDeflectorsLoad;
[AllowNull] public static GameObject witteSmokeDeflectorsLoad; [AllowNull] public static GameObject witteSmokeDeflectorsLoad;
[AllowNull] public static GameObject streamlinedBoilerLoad;
[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;
// Load // Load
private static bool Load(UnityModManager.ModEntry modEntry) { private static bool Load(UnityModManager.ModEntry modEntry) {
@ -63,44 +49,12 @@ public static class Main {
harmony = new Harmony(Instance.Info.Id); harmony = new Harmony(Instance.Info.Id);
harmony.PatchAll(Assembly.GetExecutingAssembly()); 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<GameObject>("Assets/WagnerSmokeDeflectors.prefab");
witteSmokeDeflectorsLoad = AssetBundle.LoadFromFile(Path.Combine(assetPath, "wittesmokedeflectors")).LoadAsset<GameObject>("Assets/WitteSmokeDeflectors.prefab");
streamlinedBoilerLoad = AssetBundle.LoadFromFile(Path.Combine(assetPath, "streamline")).LoadAsset<GameObject>("Assets/Streamline.prefab");
// Base
string baseAssetPath = Path.Combine(assetPath, "Base\\");
var s282BodyBundle = AssetBundle.LoadFromFile(Path.Combine(baseAssetPath, "s282body"));
s282BodyLoad = s282BodyBundle.LoadAsset<GameObject>("Assets/S282Body.prefab");
// Boilers
string boilersAssetPat = Path.Combine(assetPath, "Boilers\\");
var streamlineBundle = AssetBundle.LoadFromFile(Path.Combine(boilersAssetPat, "streamline"));
streamlineLoad = streamlineBundle.LoadAsset<GameObject>("Assets/Streamline.prefab");
// Cabs
string cabsAssetPath = Path.Combine(assetPath, "Cabs\\");
var defaultCabBundle = AssetBundle.LoadFromFile(Path.Combine(cabsAssetPath, "defaultcab"));
defaultCabLoad = defaultCabBundle.LoadAsset<GameObject>("Assets/DefaultCab.prefab");
var germanCabBundle = AssetBundle.LoadFromFile(Path.Combine(cabsAssetPath, "germancab"));
germanCabLoad = germanCabBundle.LoadAsset<GameObject>("Assets/GermanCab.prefab");
// Smoke Deflectors
string smokeDeflectorsAssetPath = Path.Combine(assetPath, "SmokeDeflectors\\");
var wagnerSmokeDeflectorsBundle = AssetBundle.LoadFromFile(Path.Combine(smokeDeflectorsAssetPath, "wagnersmokedeflectors"));
wagnerSmokeDeflectorsLoad = wagnerSmokeDeflectorsBundle.LoadAsset<GameObject>("Assets/WagnerSmokeDeflectors.prefab");
var witteSmokeDeflectorsBundle = AssetBundle.LoadFromFile(Path.Combine(smokeDeflectorsAssetPath, "wittesmokedeflectors"));
witteSmokeDeflectorsLoad = witteSmokeDeflectorsBundle.LoadAsset<GameObject>("Assets/WitteSmokeDeflectors.prefab");
// Smoke Stacks
string smokeStacksAssetPath = Path.Combine(assetPath, "SmokeStacks\\");
var defaultSmokeStackBundle = AssetBundle.LoadFromFile(Path.Combine(smokeStacksAssetPath, "defaultsmokestack"));
defaultSmokeStackLoad = defaultSmokeStackBundle.LoadAsset<GameObject>("Assets/DefaultSmokeStack.prefab");
var shortSmokeStackBundle = AssetBundle.LoadFromFile(Path.Combine(smokeStacksAssetPath, "shortsmokestack"));
shortSmokeStackLoad = shortSmokeStackBundle.LoadAsset<GameObject>("Assets/ShortSmokeStack.prefab");
// Extras
string extrasAssetPath = Path.Combine(assetPath, "Extras\\");
var cowCatcherBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "cowcatcher"));
cowCatcherLoad = cowCatcherBundle.LoadAsset<GameObject>("Assets/CowCatcher.prefab");
var frontCoverBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "frontcover"));
frontCoverLoad = frontCoverBundle.LoadAsset<GameObject>("Assets/FrontCover.prefab");
var railingsBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "railings"));
railingsLoad = railingsBundle.LoadAsset<GameObject>("Assets/Railings.prefab");
var walkwayBundle = AssetBundle.LoadFromFile(Path.Combine(extrasAssetPath, "walkway"));
walkwayLoad = walkwayBundle.LoadAsset<GameObject>("Assets/Walkway.prefab");
} catch(Exception ex) { } catch(Exception ex) {
Instance.Logger.LogException($"Failed to load {Instance.Info.DisplayName}:", ex); Instance.Logger.LogException($"Failed to load {Instance.Info.DisplayName}:", ex);
harmony?.UnpatchAll(Instance.Info.Id); 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("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("Also, reloading a save will currently break things and the tweaks won't load. This isn't good.");
GUILayout.Label("Boiler Type"); GUILayout.Space(2f);
Settings.boilerType = (Settings.BoilerType) GUILayout.SelectionGrid((int) Settings.boilerType, boilerTypeTexts, 1, "toggle");
GUILayout.Label("Cab Type"); //todo this is not implemented
Settings.cabType = (Settings.CabType)GUILayout.SelectionGrid((int) Settings.cabType, cabTypeTexts, 1, "toggle"); // GUILayout.Label("Cab Type");
// Settings.cabType = (Settings.CabType) GUILayout.SelectionGrid((int) Settings.cabType, cabTypeTexts, 1, "toggle");
GUILayout.Label("Smoke Deflector Type"); GUILayout.Label("Smoke Deflector Type");
Settings.smokeDeflectorType = (Settings.SmokeDeflectorType) GUILayout.SelectionGrid((int) Settings.smokeDeflectorType, smokeDeflectorTypeTexts, 1, "toggle"); 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"); GUILayout.Label("Boiler Type");
Settings.cowCatcher = GUILayout.Toggle(Settings.cowCatcher, "Cow Catcher"); Settings.boilerType = (Settings.BoilerType) GUILayout.SelectionGrid((int) Settings.boilerType, boilerTypeTexts, 1, "toggle");
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.EndVertical(); GUILayout.EndVertical();
} }

View File

@ -25,28 +25,12 @@ public static class Settings {
[Description("Wagner Smoke Deflectors")] [Description("Wagner Smoke Deflectors")]
Wagner, Wagner,
} }
public enum SmokeStackType {
[Description("Default Smoke Stack")]
Default,
[Description("Short Smoke Stack")]
Short,
}
} }
public class dumb282tweaksSettings : UnityModManager.ModSettings { public class dumb282tweaksSettings : UnityModManager.ModSettings {
public bool bluetooth = false; // public CabType cabType = CabType.Default;
public bool flattensyour282 = false;
public bool regularBody = true;
public BoilerType boilerType = BoilerType.Default;
public CabType cabType = CabType.Default;
public SmokeDeflectorType smokeDeflectorType = SmokeDeflectorType.Wagner; public SmokeDeflectorType smokeDeflectorType = SmokeDeflectorType.Wagner;
public SmokeStackType smokeStackType = SmokeStackType.Default; public BoilerType boilerType = BoilerType.Default;
public bool cowCatcher = true;
public bool frontCover = false;
public bool railings = true;
public bool walkway = true;
public override void Save(UnityModManager.ModEntry modEntry) { public override void Save(UnityModManager.ModEntry modEntry) {
Save(this, modEntry); Save(this, modEntry);

View File

@ -4,7 +4,7 @@ param (
) )
Set-Location "$PSScriptRoot" Set-Location "$PSScriptRoot"
$FilesToInclude = "info.json","build/*","LICENSE" $FilesToInclude = "info.json","build/*","LICENSE","assets"
$modInfo = Get-Content -Raw -Path "info.json" | ConvertFrom-Json $modInfo = Get-Content -Raw -Path "info.json" | ConvertFrom-Json
$modId = $modInfo.Id $modId = $modInfo.Id
@ -20,6 +20,7 @@ $ZipOutDir = "$ZipWorkDir/$modId"
New-Item "$ZipOutDir" -ItemType Directory -Force New-Item "$ZipOutDir" -ItemType Directory -Force
Copy-Item -Force -Path $FilesToInclude -Destination "$ZipOutDir" Copy-Item -Force -Path $FilesToInclude -Destination "$ZipOutDir"
Copy-Item -Force -Path "assets/*" -Destination "$ZipOutDir/assets"
if (!$NoArchive) if (!$NoArchive)
{ {