added streamlining and settings and a bit more probably

master
EvilPunkin 2023-08-21 17:03:27 -07:00
parent 2ef5b0cc46
commit a487a1d521
6 changed files with 147 additions and 55 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -20,6 +20,7 @@ using static Oculus.Avatar.CAPI;
using UnityEngine.UI;
using System.ComponentModel;
using static UnityModManagerNet.UnityModManager.Param;
using static dumb282tweaks.Main;
namespace dumb282tweaks;
@ -32,18 +33,55 @@ public static class Main {
private static readonly string[] cabTypeTexts = new[] {
"Default",
//"Soviet",
"German"
};
public enum CabType {
[Description("Default 282 Cab")]
Default,
[Description("German Cab")]
German
}
private static readonly string[] smokeDeflectorTypeTexts = new[] {
"Default",
"Soviet",
"German"
"None",
"Witte",
"Wagner"
};
public enum SmokeDeflectorType {
[Description("No Smoke Deflectors")]
None,
[Description("Witte Smoke Deflectors")]
Witte,
[Description("Wagner Smoke Deflectors")]
Wagner,
}
public static GameObject fullCabLoad;
public static GameObject smokeDeflectorLoad;
private static readonly string[] boilerTypeTexts = new[] {
"Default",
"Streamlined"
};
public enum BoilerType {
[Description("Default Boiler")]
Default,
[Description("Streamlined Boiler")]
Streamlined,
}
public class dumb282tweaksSettings : UnityModManager.ModSettings {
public bool toggleTweaks = true;
public CabType cabType = CabType.Default;
public SmokeDeflectorType smokeDeflectorType = SmokeDeflectorType.Wagner;
public BoilerType boilerType = BoilerType.Default;
public override void Save(UnityModManager.ModEntry modEntry) {
Save(this, modEntry);
}
}
public static string assetPath;
//public static GameObject germanCabLoad;
public static GameObject wagnerSmokeDeflectorsLoad;
public static GameObject witteSmokeDeflectorsLoad;
public static GameObject streamlinedBoilerLoad;
// Load
private static bool Load(UnityModManager.ModEntry modEntry) {
@ -55,18 +93,23 @@ public static class Main {
Instance.OnGUI = OnGUI;
Instance.OnSaveGUI = OnSaveGUI;
modEntry.Logger.Log("gam");
harmony = new Harmony(Instance.Info.Id);
harmony.PatchAll(Assembly.GetExecutingAssembly());
modEntry.Logger.Log("gamer");
// 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<GameObject>("Assets/fullcab.prefab");
smokeDeflectorLoad = smokeDeflectorBundle.LoadAsset<GameObject>("Assets/SmokeDeflector.prefab");
assetPath = Path.Combine(Instance.Path.ToString(), "assets\\");
// Smoke Deflectors
var wagnerSmokeDeflectorsBundle = AssetBundle.LoadFromFile(Path.Combine(assetPath, "wagnersmokedeflectors"));
wagnerSmokeDeflectorsLoad = wagnerSmokeDeflectorsBundle.LoadAsset<GameObject>("Assets/WagnerSmokeDeflectors.prefab");
var witteSmokeDeflectorsBundle = AssetBundle.LoadFromFile(Path.Combine(assetPath, "wittesmokedeflectors"));
witteSmokeDeflectorsLoad = witteSmokeDeflectorsBundle.LoadAsset<GameObject>("Assets/WitteSmokeDeflectors.prefab");
} catch (Exception ex) {
// Boiler
var streamlinedBoilerBundle = AssetBundle.LoadFromFile(Path.Combine(assetPath, "streamline"));
streamlinedBoilerLoad = streamlinedBoilerBundle.LoadAsset<GameObject>("Assets/Streamline.prefab");
} catch(Exception ex) {
Instance.Logger.LogException($"Failed to load {Instance.Info.DisplayName}:", ex);
harmony?.UnpatchAll(Instance.Info.Id);
return false;
@ -79,64 +122,102 @@ public static class Main {
static void OnGUI(UnityModManager.ModEntry modEntry) {
GUILayout.BeginVertical();
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("Cab Type");
Settings.cabType = (CabType)GUILayout.SelectionGrid((int)Settings.cabType, cabTypeTexts, 1, "toggle");
Settings.cabType = (CabType)GUILayout.SelectionGrid((int) Settings.cabType, cabTypeTexts, 1, "toggle");
GUILayout.Space(2);
GUILayout.Label("Smoke Deflector Type");
Settings.smokeDeflectorType = (SmokeDeflectorType) GUILayout.SelectionGrid((int) Settings.smokeDeflectorType, smokeDeflectorTypeTexts, 1, "toggle");
GUILayout.Label("Boiler Type");
Settings.boilerType = (BoilerType) GUILayout.SelectionGrid((int) Settings.boilerType, boilerTypeTexts, 1, "toggle");
GUILayout.EndVertical();
}
static void OnSaveGUI(UnityModManager.ModEntry modEntry) {
Settings.Save(modEntry);
}
[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);
//switch(Settings.cabType) {
// case CabType.Default:
// break;
// case CabType.German:
// if(__instance != null && __instance.carType == TrainCarType.LocoSteamHeavy) {
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);
}
}
// var fullCabBundle = AssetBundle.LoadFromFile(Path.Combine(assetPath, "fullcab"));
// var fullCabLoad = fullCabBundle.LoadAsset<GameObject>("Assets/FullCab.prefab");
// GameObject fullCab = UnityEngine.Object.Instantiate(fullCabLoad);
// fullCab.transform.parent = __instance.transform;
// fullCab.transform.localPosition = new Vector3(0, 3, 0);
// fullCab.transform.localRotation = Quaternion.identity;
// }
// break;
//}
// Smoke Deflector Type
if(__instance != null && __instance.carType == TrainCarType.LocoSteamHeavy) {
// This is a terrible way to get the material 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
Material s282Mat = __instance.transform.GetChild(5).transform.GetChild(0).transform.GetChild(0).GetComponent<MeshRenderer>().material;
Log(Path.Combine(assetPath, "wittesmokedeflectors"));
switch(Settings.smokeDeflectorType) {
case SmokeDeflectorType.None:
break;
case SmokeDeflectorType.Witte:
GameObject witteSmokeDeflector = UnityEngine.Object.Instantiate(witteSmokeDeflectorsLoad);
// This is also 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;
//Log(smokeDeflector.GetComponent<MeshRenderer>().material.name.ToString());
witteSmokeDeflector.transform.parent = __instance.transform;
witteSmokeDeflector.transform.localPosition = new Vector3(0, 2.1f, 5f);
witteSmokeDeflector.transform.localRotation = Quaternion.identity;
break;
case SmokeDeflectorType.Wagner:
GameObject wagnerSmokeDeflector = UnityEngine.Object.Instantiate(wagnerSmokeDeflectorsLoad);
// This is also a terrible way to set the material of the smoke deflectors, but oh well
wagnerSmokeDeflector.transform.GetChild(0).GetComponent<MeshRenderer>().material = s282Mat;
wagnerSmokeDeflector.transform.GetChild(1).GetComponent<MeshRenderer>().material = s282Mat;
//Log(smokeDeflector.GetComponent<MeshRenderer>().material.name.ToString());
wagnerSmokeDeflector.transform.parent = __instance.transform;
wagnerSmokeDeflector.transform.localPosition = new Vector3(0, 2.1f, 5f);
wagnerSmokeDeflector.transform.localRotation = Quaternion.identity;
break;
}
public enum CabType {
[Description("Default 282 Cab")]
Default,
[Description("German Cab")]
German
}
switch(Settings.boilerType) {
case BoilerType.Default:
break;
case BoilerType.Streamlined:
GameObject streamlinedBoiler = UnityEngine.Object.Instantiate(streamlinedBoilerLoad);
public enum SmokeDeflectorType {
[Description("No Smoke Deflectors")]
None,
[Description("Soviet Smoke Deflectors")]
Soviet,
[Description("German Smoke Deflectors")]
German,
}
// This is also a terrible way to set the material of the smoke deflectors, but oh well
streamlinedBoiler.transform.GetChild(0).GetComponent<MeshRenderer>().material = s282Mat;
streamlinedBoiler.transform.GetChild(1).GetComponent<MeshRenderer>().material = s282Mat;
streamlinedBoiler.transform.GetChild(2).GetComponent<MeshRenderer>().material = s282Mat;
streamlinedBoiler.transform.GetChild(3).GetComponent<MeshRenderer>().material = s282Mat;
public class dumb282tweaksSettings : UnityModManager.ModSettings {
public bool toggleTweaks = true;
public CabType cabType = CabType.German;
public SmokeDeflectorType smokeDeflectorType = SmokeDeflectorType.Soviet;
public override void Save(UnityModManager.ModEntry modEntry) {
Save(this, modEntry);
//Log(smokeDeflector.GetComponent<MeshRenderer>().material.name.ToString());
streamlinedBoiler.transform.parent = __instance.transform;
streamlinedBoiler.transform.localPosition = new Vector3(0, 2.15f, 5.1f);
streamlinedBoiler.transform.localRotation = Quaternion.identity;
break;
}
}
}
}
// Logger Commands
public static void Log(string message) {
Instance.Logger.Log(message);

11
dumb282tweaks/Patch282.cs Normal file
View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dumb282tweaks {
internal class Patch282 {
}
}