generated from Valheim-Modding/JotunnModStub
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from jpw1991/35-hp-not-working-correctly
2.1.1: CVL updated to 2.3.1; add HeavyLogging config for optional hea…
- Loading branch information
Showing
15 changed files
with
165 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using ChebsMercenaries.Minions; | ||
using HarmonyLib; | ||
|
||
// ReSharper disable InconsistentNaming | ||
// ReSharper disable UnusedParameter.Local | ||
|
||
// Harmony patching is very sensitive regarding parameter names. Everything in this region should be hand crafted | ||
// and not touched by well-meaning but clueless IDE optimizations. | ||
// eg. | ||
// * __instance MUST be named with exactly two underscores. | ||
// * ___m_drops MUST be named with exactly three underscores. | ||
// * Unused parameters must be left there because they must match the method to override | ||
// * All patch methods need to be static | ||
// | ||
// This is because all of this has a special meaning to Harmony. | ||
|
||
namespace ChebsMercenaries.Patches | ||
{ | ||
[HarmonyPatch] | ||
public class ZNetScenePatches | ||
{ | ||
// Steal the Player's material from the player and give it to the mercenaries so that their armour displays | ||
// properly. Thanks to JustAFrogger for this solution. | ||
[HarmonyPatch(typeof(ZNetScene), nameof(ZNetScene.Awake)), HarmonyPostfix] | ||
public static void ZNetScenePatch(ZNetScene __instance) | ||
{ | ||
var playerPrefab = __instance.GetPrefab("Player"); | ||
if (playerPrefab == null) | ||
{ | ||
Jotunn.Logger.LogError($"ZNetScenePatches: Failed to get player prefab. Armor may not display" + | ||
$"correctly on mercenaries."); | ||
return; | ||
} | ||
|
||
if (!playerPrefab.TryGetComponent(out VisEquipment playerVisEquipment)) | ||
{ | ||
Jotunn.Logger.LogError($"ZNetScenePatches: Failed to get Player's VisEquipment " + | ||
$"component. Armor may not display correctly on mercenaries."); | ||
return; | ||
} | ||
|
||
var male = playerVisEquipment.m_models[0].m_baseMaterial; | ||
var female = playerVisEquipment.m_models[1].m_baseMaterial; | ||
|
||
BasePlugin.MercenaryPrefabPaths.ForEach(prefabFileName => | ||
{ | ||
var prefabName = prefabFileName.Replace(".prefab", ""); | ||
var mercPrefab = __instance.GetPrefab(prefabName); | ||
if (mercPrefab == null) | ||
{ | ||
Jotunn.Logger.LogError($"ZNetScenePatches: Failed to get {prefabName}. Armor may not display" + | ||
$"correctly on mercenaries."); | ||
return; | ||
} | ||
|
||
if (!mercPrefab.TryGetComponent(out VisEquipment visEquipment)) | ||
{ | ||
Jotunn.Logger.LogError($"ZNetScenePatches: Failed to get {prefabName}'s VisEquipment " + | ||
$"component. Armor may not display correctly on mercenaries."); | ||
return; | ||
} | ||
|
||
visEquipment.m_bodyModel.material = prefabName.Contains("Female") ? female : male; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.