Skip to content

Commit

Permalink
fix loco mesh splitter patch
Browse files Browse the repository at this point in the history
  • Loading branch information
katycat5e committed Feb 4, 2025
1 parent c3d2e2c commit f2bdff8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
7 changes: 5 additions & 2 deletions SkinManagerMod/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using DVLangHelper.Runtime;
using SkinManagerMod.Items;
using System.Collections;
using SkinManagerMod.Patches;

namespace SkinManagerMod
{
Expand All @@ -20,6 +21,7 @@ public static class Main
public static UnityModManager.ModEntry Instance { get; private set; }
public static SkinManagerSettings Settings { get; private set; }
public static TranslationInjector TranslationInjector { get; private set; }
public static Harmony Harmony { get; private set; }
#nullable restore

public static string ExportFolderPath => Path.Combine(Instance.Path, Constants.EXPORT_FOLDER_NAME);
Expand Down Expand Up @@ -50,8 +52,9 @@ public static bool Load(UnityModManager.ModEntry modEntry)

UnloadWatcher.UnloadRequested += PaintFactory.DestroyInjectedShopData;

var harmony = new Harmony(Constants.MOD_ID);
harmony.PatchAll(Assembly.GetExecutingAssembly());
LocoMeshSplitterPatches.Initialize();
Harmony = new Harmony(Constants.MOD_ID);
Harmony.PatchAll(Assembly.GetExecutingAssembly());

Instance.OnGUI = OnGUI;
Instance.OnSaveGUI = OnSaveGUI;
Expand Down
38 changes: 26 additions & 12 deletions SkinManagerMod/Patches/LocoMeshSplitterPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,46 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using static UnityModManagerNet.UnityModManager;

namespace SkinManagerMod.Patches
{
[HarmonyPatch]
internal static class LocoMeshSplitterPatches
{
private static Type _paintSetupClass = AccessTools.TypeByName("LocoMeshSplitter.MeshLoaders.TrainCarPaintSetup");
private const string LMS_ModID = "LocoMeshSplitter";

public static bool Prepare()
public static void Initialize()
{
return (_paintSetupClass is not null);
if ((FindMod(LMS_ModID) is ModEntry lms) && lms.Active)
{
DoPatching();
}
else
{
toggleModsListen += OnModToggle;
}
}

public static void OnModToggle(ModEntry modEntry, bool enabled)
{
if (!enabled || (modEntry?.Info.Id != LMS_ModID)) return;

DoPatching();
}

public static IEnumerable<MethodBase> TargetMethods()
private static void DoPatching()
{
if (_paintSetupClass is not null)
Type _paintSetupClass = AccessTools.TypeByName("LocoMeshSplitter.MeshLoaders.TrainCarPaintSetup");

var methods = _paintSetupClass.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);

foreach (var target in methods)
{
var methods = AccessTools.GetDeclaredMethods(_paintSetupClass);
foreach (var method in methods)
{
yield return method;
}
Main.Log($"Patch {_paintSetupClass.FullName}.{target.Name}");
Main.Harmony.Patch(target, new HarmonyMethod(typeof(LocoMeshSplitterPatches), nameof(SkipMethod)));
}
}

[HarmonyPrefix]
public static bool SkipMethod()
{
return false;
Expand Down
19 changes: 12 additions & 7 deletions SkinManagerMod/TextureUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,20 @@ public static void ApplyTextures(MeshRenderer renderer, Skin skin, CarMaterialDa
var defaultMaterial = defaultData.GetMaterialForBaseTheme(skin.BaseTheme);

// Set scales etc
float metallic = defaultMaterial.GetFloat(PropNames.Metallic);
renderer.material.SetFloat(PropNames.Metallic, metallic);

float smoothness = defaultMaterial.GetFloat(PropNames.Smoothness);
renderer.material.SetFloat(PropNames.Smoothness, smoothness);
if (defaultMaterial.HasProperty(PropNames.Metallic))
{
float metallic = defaultMaterial.GetFloat(PropNames.Metallic);
renderer.material.SetFloat(PropNames.Metallic, metallic);

float intensity = defaultMaterial.GetFloat(PropNames.DetailNormalScale);
renderer.material.SetFloat(PropNames.DetailNormalScale, intensity);
float smoothness = defaultMaterial.GetFloat(PropNames.Smoothness);
renderer.material.SetFloat(PropNames.Smoothness, smoothness);
}

if (defaultMaterial.HasProperty(PropNames.DetailNormalScale))
{
float intensity = defaultMaterial.GetFloat(PropNames.DetailNormalScale);
renderer.material.SetFloat(PropNames.DetailNormalScale, intensity);
}

foreach (var defaultTexture in defaultData.AllTextures)
{
Expand Down

0 comments on commit f2bdff8

Please sign in to comment.