Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Source/Client/Patches/Odyssey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
}
}

public static int WaterBodyHash(WaterBody body) =>
Gen.HashCombineInt(body.map?.uniqueID ?? 0, body.rootCell.x, body.rootCell.z, (int)body.waterBodyType);
public static int WaterBodyHash(WaterBody body)
{
if (Multiplayer.Client == null)
return body.GetHashCode();

return Gen.HashCombineInt(body.map?.uniqueID ?? 0, body.rootCell.x, body.rootCell.z, (int)body.waterBodyType);
}

}
}
75 changes: 75 additions & 0 deletions Source/Client/Patches/OdysseyMultifaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using HarmonyLib;
using RimWorld;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using Verse;

namespace Multiplayer.Client.Patches
{
[HarmonyPatch]
internal static class PatchVisualEffectsUsingShouldSpawnMotesAt
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(FishShadowComponent), nameof(FishShadowComponent.SpawnFishFleck));
yield return AccessTools.Method(typeof(LavaFXComponent), nameof(LavaFXComponent.ThrowLavaSmoke));
}

static void Prefix(Map map, ref sbyte __state)
{
if (Multiplayer.Client == null) return;

__state = Current.Game.currentMapIndex;
Current.Game.currentMapIndex = (sbyte)map.Index;
}

static void Finalizer(sbyte __state)
{
if (Multiplayer.Client == null) return;

Current.Game.currentMapIndex = __state;
}
}

[HarmonyPatch(typeof(CompFleckEmitterLongTerm), nameof(CompFleckEmitterLongTerm.EmissionTick))]
static class PatchEmissionTickShouldSpawnMotesAt
{
static MethodInfo OriginalMethod = AccessTools.Method(typeof(GenView), nameof(GenView.ShouldSpawnMotesAt),[typeof(IntVec3), typeof(Map), typeof(bool)]);
static MethodInfo ReplacementMethod = AccessTools.Method(typeof(PatchEmissionTickShouldSpawnMotesAt), nameof(ShouldSpawnMotesAtReplacement));

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo changed = AccessTools.Method(typeof(PatchEmissionTickShouldSpawnMotesAt), nameof(ShouldSpawnMotesAtReplacement));

foreach (var ins in instructions)
{
if (ins.Calls(OriginalMethod))
yield return new CodeInstruction(OpCodes.Call, changed);
else
yield return ins;
}
}

public static bool ShouldSpawnMotesAtReplacement(IntVec3 cell, Map map, bool flag)
{
if (Multiplayer.Client == null)
return cell.ShouldSpawnMotesAt(map, flag);

bool shouldSpawn;
sbyte prevMapIndex = Current.Game.currentMapIndex;
Current.Game.currentMapIndex = (sbyte)map.Index;

try
{
shouldSpawn = cell.ShouldSpawnMotesAt(map, flag);
}
finally
{
Current.Game.currentMapIndex = prevMapIndex;
}

return shouldSpawn;
}
}
}
Loading