2023-09-01 00:24:32 +00:00
|
|
|
using DV.ThingTypes;
|
|
|
|
using HarmonyLib;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2023-11-12 15:35:28 +00:00
|
|
|
using static dumb282tweaks.Main;
|
|
|
|
|
2023-09-01 00:24:32 +00:00
|
|
|
namespace dumb282tweaks;
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(TrainCar), "Start")]
|
|
|
|
class CarPatch {
|
2023-11-12 18:47:12 +00:00
|
|
|
static void Postfix(ref TrainCar __instance)
|
|
|
|
{
|
2023-11-25 14:38:56 +00:00
|
|
|
if (__instance == null || __instance.carType != TrainCarType.LocoSteamHeavy)
|
2023-11-12 18:47:12 +00:00
|
|
|
{
|
2023-11-25 14:38:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
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;
|
|
|
|
}
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
Material s282Mat = s282Body.GetComponent<MeshRenderer>().material;
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
// Smoke Deflector
|
|
|
|
Log($"Applying {MySettings.smokeDeflectorType.ToString()}");
|
2023-11-12 18:47:12 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
switch(MySettings.smokeDeflectorType) {
|
|
|
|
case Settings.SmokeDeflectorType.Witte:
|
|
|
|
{
|
|
|
|
GameObject witteSmokeDeflector = Object.Instantiate(witteSmokeDeflectorsPrefab, __instance.transform);
|
|
|
|
witteSmokeDeflector.transform.localPosition = new Vector3(0.0f, 2.1f, 5f);
|
|
|
|
witteSmokeDeflector.transform.localRotation = Quaternion.identity;
|
2023-11-12 18:47:12 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
foreach (var aMeshRenderer in witteSmokeDeflector.GetComponentsInChildren<MeshRenderer>())
|
|
|
|
{
|
|
|
|
aMeshRenderer.material = s282Mat;
|
|
|
|
}
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Settings.SmokeDeflectorType.Wagner:
|
|
|
|
{
|
|
|
|
GameObject wagnerSmokeDeflector = Object.Instantiate(wagnerSmokeDeflectorsPrefab, __instance.transform);
|
|
|
|
wagnerSmokeDeflector.transform.localPosition = new Vector3(0.0f, 2.1f, 5f);
|
|
|
|
wagnerSmokeDeflector.transform.localRotation = Quaternion.identity;
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
foreach (var aMeshRenderer in wagnerSmokeDeflector.GetComponentsInChildren<MeshRenderer>())
|
|
|
|
{
|
|
|
|
aMeshRenderer.material = s282Mat;
|
|
|
|
}
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
break;
|
2023-09-01 00:24:32 +00:00
|
|
|
}
|
2023-11-25 14:38:56 +00:00
|
|
|
case Settings.SmokeDeflectorType.Chinese:
|
|
|
|
ApplyChineseSmokeDeflector(ref __instance, s282Body);
|
|
|
|
break;
|
|
|
|
}
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
// Boiler
|
|
|
|
Log($"Applying {MySettings.boilerType.ToString()}");
|
2023-11-12 18:47:12 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
switch (MySettings.boilerType)
|
|
|
|
{
|
|
|
|
case Settings.BoilerType.Streamlined:
|
|
|
|
GameObject streamlinedBoiler = Object.Instantiate(streamlinedBoilerPrefab, __instance.transform);
|
|
|
|
streamlinedBoiler.transform.localPosition = new Vector3(0.0f, 2.15f, 5.1f);
|
|
|
|
streamlinedBoiler.transform.localRotation = Quaternion.identity;
|
2023-09-01 00:24:32 +00:00
|
|
|
|
2023-11-25 14:38:56 +00:00
|
|
|
foreach (var aMeshRenderer in streamlinedBoiler.GetComponentsInChildren<MeshRenderer>())
|
|
|
|
{
|
|
|
|
aMeshRenderer.material = s282Mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void ApplyChineseSmokeDeflector(ref TrainCar locomotive, Transform body)
|
|
|
|
{
|
|
|
|
//hide smoke box door
|
|
|
|
var smokeboxDoorPath = "LocoS282A_Body/Static_LOD0/s282_locomotive_smokebox_door";
|
|
|
|
Transform smokeBoxDoor = locomotive.transform.Find(smokeboxDoorPath);
|
|
|
|
if (smokeBoxDoor == null)
|
|
|
|
{
|
|
|
|
Error($"Couldn't find S282 smoke box door on '{locomotive.transform.gameObject.name}' -> {smokeboxDoorPath}");
|
|
|
|
return;
|
2023-09-01 00:24:32 +00:00
|
|
|
}
|
2023-11-25 14:38:56 +00:00
|
|
|
smokeBoxDoor.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
//show deflector and stuff
|
|
|
|
GameObject chineseSmokeDeflector = Object.Instantiate(chineseSmokeDeflectorsPrefab, body);
|
|
|
|
chineseSmokeDeflector.transform.localPosition = smokeBoxDoor.localPosition;
|
|
|
|
|
|
|
|
//todo apply S282 material?
|
|
|
|
// foreach (var aMeshRenderer in chineseSmokeDeflector.GetComponentsInChildren<MeshRenderer>())
|
|
|
|
// {
|
|
|
|
// if (aMeshRenderer.material.name == "S282") //todo
|
|
|
|
// {
|
|
|
|
// aMeshRenderer.material = s282Mat;
|
|
|
|
// }
|
|
|
|
// }
|
2023-09-01 00:24:32 +00:00
|
|
|
}
|
|
|
|
}
|