forked from valheimPlus/ValheimPlus
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79d93c9
commit 19413a1
Showing
2 changed files
with
25 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,52 @@ | ||
using HarmonyLib; | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
using HarmonyLib; | ||
using JetBrains.Annotations; | ||
using UnityEngine; | ||
using ValheimPlus.Configurations; | ||
using HarmonyLib.Tools; | ||
using MonoMod.Utils; | ||
|
||
namespace ValheimPlus | ||
namespace ValheimPlus.GameClasses | ||
{ | ||
[HarmonyPatch(typeof(SE_Rested), nameof(SE_Rested.UpdateTTL))] | ||
public static class SE_Rested_UpdateTTL_Patch | ||
public static class Se_Rested_UpdateTtl_Patch | ||
{ | ||
/// <summary> | ||
/// Updates the time per rested comfort level. | ||
/// </summary> | ||
[HarmonyPrefix] | ||
public static void Prefix(ref float ___m_TTLPerComfortLevel) | ||
[UsedImplicitly] | ||
public static void Prefix(SE_Rested __instance) | ||
{ | ||
if (Configuration.Current.Player.IsEnabled) | ||
{ | ||
___m_TTLPerComfortLevel = Configuration.Current.Player.restSecondsPerComfortLevel; | ||
} | ||
var config = Configuration.Current.Player; | ||
if (!config.IsEnabled) return; | ||
__instance.m_TTLPerComfortLevel = config.restSecondsPerComfortLevel; | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Changes the radius in which pieces contribute to the rested bonus. | ||
/// </summary> | ||
[HarmonyPatch(typeof(SE_Rested), nameof(SE_Rested.GetNearbyComfortPieces))] | ||
public static class SE_Rested_GetNearbyPieces_Transpiler | ||
public static class Se_Rested_GetNearbyComfortPieces_Transpiler | ||
{ | ||
[HarmonyTranspiler] | ||
[UsedImplicitly] | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
if (!Configuration.Current.Building.IsEnabled || Configuration.Current.Building.pieceComfortRadius == 10) return instructions; | ||
|
||
List<CodeInstruction> il = instructions.ToList(); | ||
var config = Configuration.Current.Building; | ||
// ReSharper disable once CompareOfFloatsByEqualityOperator expecting exact constant | ||
if (!config.IsEnabled || config.pieceComfortRadius == 10f) return instructions; | ||
|
||
var il = instructions.ToList(); | ||
for (int i = 0; i < il.Count; ++i) | ||
{ | ||
if (il[i].opcode == OpCodes.Ldc_R4) | ||
il[i].operand = Mathf.Clamp(Configuration.Current.Building.pieceComfortRadius, 1, 300); | ||
if (il[i].opcode != OpCodes.Ldc_R4) continue; | ||
il[i].operand = Mathf.Clamp(config.pieceComfortRadius, 1f, 300f); | ||
return il; | ||
} | ||
|
||
return il.AsEnumerable(); | ||
} | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Changes the radius in which pieces contribute to the rested bonus. | ||
/// </summary> | ||
[HarmonyPatch(typeof(SE_Rested), nameof(SE_Rested.GetNearbyComfortPieces))] | ||
public static class SE_Rested_GetNearbyComfortPieces_Transpiler | ||
{ | ||
[HarmonyTranspiler] | ||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) | ||
{ | ||
if (!Configuration.Current.Building.IsEnabled || Configuration.Current.Building.pieceComfortRadius == 10) return instructions; | ||
|
||
List<CodeInstruction> il = instructions.ToList(); | ||
|
||
for (int i = 0; i < il.Count; ++i) | ||
{ | ||
if (il[i].opcode == OpCodes.Ldc_R4) | ||
il[i].operand = Mathf.Clamp(Configuration.Current.Building.pieceComfortRadius, 1, 300); | ||
} | ||
return il.AsEnumerable(); | ||
ValheimPlusPlugin.Logger.LogError( | ||
"Couldn't transpile `SE_Rested.GetNearbyComfortPieces` for `Building.pieceComfortRadius` config!"); | ||
return il; | ||
} | ||
|
||
} | ||
|
||
} | ||
} |