Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at RW 1.5 #428

Merged
merged 1 commit into from
Apr 5, 2024
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
4 changes: 2 additions & 2 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<packageId>rwmt.Multiplayer</packageId>
<name>Multiplayer</name>
<supportedVersions>
<li>1.4</li>
<li>1.5</li>
</supportedVersions>
<author>RimWorld Multiplayer Team</author>
<url>https://github.com/rwmt/Multiplayer</url>
<description>&lt;color=red&gt;&lt;b&gt;Important: &lt;/b&gt; This mod should be placed right below Core and expansions in the mod list to work properly!
Requires Rimworld >= v1.4.3901&lt;/color&gt;\n
Requires Rimworld >= v1.5.4034&lt;/color&gt;\n
Multiplayer mod for RimWorld.

FAQ - https://hackmd.io/@rimworldmultiplayer/docs/
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/AsyncTime/AsyncTimePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void Postfix()
}
}

[HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), typeof(Letter), typeof(string))]
[HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), typeof(Letter), typeof(string), typeof(int), typeof(bool))]
static class ReceiveLetterPause
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts)
Expand Down
8 changes: 4 additions & 4 deletions Source/Client/Comp/World/FactionWorldData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public void ExposeData()
public void ReassignIds()
{
foreach (DrugPolicy p in drugPolicyDatabase.policies)
p.uniqueId = Find.UniqueIDsManager.GetNextThingID();
p.id = Find.UniqueIDsManager.GetNextThingID();

foreach (Outfit o in outfitDatabase.outfits)
o.uniqueId = Find.UniqueIDsManager.GetNextThingID();
foreach (ApparelPolicy o in outfitDatabase.outfits)
o.id = Find.UniqueIDsManager.GetNextThingID();

foreach (FoodRestriction o in foodRestrictionDatabase.foodRestrictions)
foreach (FoodPolicy o in foodRestrictionDatabase.foodRestrictions)
o.id = Find.UniqueIDsManager.GetNextThingID();
}

Expand Down
1 change: 1 addition & 0 deletions Source/Client/Debug/DebugActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;

using HarmonyLib;
using LudeonTK;
using RimWorld;
using RimWorld.Planet;
using UnityEngine;
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Debug/DebugPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void Prefixfactionman()
!trace.Contains("Client.FactionContext") &&
!trace.Contains("Thing.ExposeData")
)
Log.Message($"factionman call {trace}", true);
Log.Message($"factionman call {trace}");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/Client/Debug/DebugSync.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using LudeonTK;
using Multiplayer.Common;

using RimWorld;
Expand Down
2 changes: 0 additions & 2 deletions Source/Client/EarlyPatches/SettingsPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ static class PrefGettersInMultiplayer
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.PropertyGetter(typeof(Prefs), nameof(Prefs.PauseOnError));
yield return AccessTools.PropertyGetter(typeof(Prefs), nameof(Prefs.AutomaticPauseMode));
yield return AccessTools.PropertyGetter(typeof(Prefs), nameof(Prefs.PauseOnLoad));
yield return AccessTools.PropertyGetter(typeof(Prefs), nameof(Prefs.AdaptiveTrainingEnabled));
Expand All @@ -29,7 +28,6 @@ static class PrefSettersInMultiplayer
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.PropertySetter(typeof(Prefs), nameof(Prefs.PauseOnError));
yield return AccessTools.PropertySetter(typeof(Prefs), nameof(Prefs.AutomaticPauseMode));
yield return AccessTools.PropertySetter(typeof(Prefs), nameof(Prefs.PauseOnLoad));
yield return AccessTools.PropertySetter(typeof(Prefs), nameof(Prefs.AdaptiveTrainingEnabled));
Expand Down
5 changes: 2 additions & 3 deletions Source/Client/Factions/FactionContextSetters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ static void Prefix(Bill_Production __instance, ref Map __state)
{
if (Multiplayer.Client == null) return;

var zoneManager = __instance.storeZone?.zoneManager ?? __instance.includeFromZone?.zoneManager;
if (__instance.Map != null && zoneManager != null)
if (__instance.Map != null && __instance.billStack?.billGiver is Thing { Faction: { } faction })
{
__instance.Map.PushFaction(zoneManager.map.MpComp().GetFactionId(zoneManager));
__instance.Map.PushFaction(faction);
__state = __instance.Map;
}
}
Expand Down
5 changes: 3 additions & 2 deletions Source/Client/Factions/FactionCreationPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ static void Finalizer(ProgramState __state)
}
}

[HarmonyPatch(typeof(Page_ConfigureStartingPawns), nameof(Page_ConfigureStartingPawns.RandomizeCurPawn))]
static class ConfigureStartingPawns_RandomizeCurPawn_Patch
[HarmonyPatch(typeof(StartingPawnUtility), nameof(StartingPawnUtility.RandomizePawn))]
static class StartingPawnUtility_RandomizePawn_Patch
{
static void Prefix(ref ProgramState __state)
{
// todo is this compatible with 1.5's "Create new wanderers?"
__state = Current.ProgramState;
Current.programStateInt = ProgramState.Entry;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Client/Factions/MultifactionPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static void Postfix(IAttackTarget target, ref bool __result)
}
}

[HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), typeof(Letter), typeof(string))]
[HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), typeof(Letter), typeof(string), typeof(int), typeof(bool))]
static class LetterStackReceiveOnlyMyFaction
{
// todo the letter might get culled from the archive if it isn't in the stack and Sync depends on the archive
Expand All @@ -333,7 +333,7 @@ static void Postfix(LetterStack __instance, Letter let)
}
}

[HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), typeof(Letter), typeof(string))]
[HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), typeof(Letter), typeof(string), typeof(int), typeof(bool))]
static class LetterStackReceiveSoundOnlyMyFaction
{
private static MethodInfo PlayOneShotOnCamera =
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Multiplayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<ItemGroup>
<PackageReference Include="Krafs.Publicizer" Version="2.0.1" />
<PackageReference Include="Lib.Harmony" Version="2.2.2" ExcludeAssets="runtime" />
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.4.3901" />
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.5.4034-beta" />
<PackageReference Include="RestSharp" Version="106.12.0" />
<PackageReference Include="RimWorld.MultiplayerAPI" Version="0.5.0" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Source/Client/MultiplayerGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using LudeonTK;
using Multiplayer.API;
using Multiplayer.Client.AsyncTime;
using Multiplayer.Client.Comp;
Expand Down
7 changes: 4 additions & 3 deletions Source/Client/MultiplayerStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,18 @@ void TryPatch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod po
var randomBoltMesh = typeof(LightningBoltMeshPool).GetProperty(nameof(LightningBoltMeshPool.RandomBoltMesh))!.GetGetMethod();
var drawTrackerCtor = typeof(Pawn_DrawTracker).GetConstructor(new[] { typeof(Pawn) });
var randomHair = typeof(PawnStyleItemChooser).GetMethod(nameof(PawnStyleItemChooser.RandomHairFor));
var cannotAssignReason = typeof(Dialog_BeginRitual).GetMethod(nameof(Dialog_BeginRitual.CannotAssignReason), BindingFlags.NonPublic | BindingFlags.Instance);
// todo for 1.5
// var cannotAssignReason = typeof(Dialog_BeginRitual).GetMethod(nameof(Dialog_BeginRitual.CannotAssignReason), BindingFlags.NonPublic | BindingFlags.Instance);
var canEverSpectate = typeof(RitualRoleAssignments).GetMethod(nameof(RitualRoleAssignments.CanEverSpectate));

var effectMethods = new MethodBase[] { subSustainerStart, sampleCtor, subSoundPlay, effecterTick, effecterTrigger, effecterCleanup, randomBoltMesh, drawTrackerCtor, randomHair };
var moteMethods = typeof(MoteMaker).GetMethods(BindingFlags.Static | BindingFlags.Public)
.Where(m => m.Name != "MakeBombardmentMote"); // Special case, just calls MakeBombardmentMote_NewTmp, prevents Hugslib complains
.Where(m => m.Name != "MakeBombardmentMote"); // Special case, just calls MakeBombardmentMote_NewTmp, prevents Hugslib complaints
var fleckMethods = typeof(FleckMaker).GetMethods(BindingFlags.Static | BindingFlags.Public)
.Where(m => m.ReturnType == typeof(void))
.Concat(typeof(FleckManager).GetMethods() // FleckStatic uses Rand in Setup method, FleckThrown uses RandomInRange in TimeInterval. May as well catch all in case mods do the same.
.Where(m => m.ReturnType == typeof(void)));
var ritualMethods = new[] { cannotAssignReason, canEverSpectate };
var ritualMethods = new[] { canEverSpectate };

foreach (MethodBase m in effectMethods.Concat(moteMethods).Concat(fleckMethods).Concat(ritualMethods))
TryPatch(m, randPatchPrefix, randPatchPostfix);
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Patches/ArbiterPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static IEnumerable<MethodBase> TargetMethods()
yield return AccessTools.Method(typeof(Prefs), nameof(Prefs.Save));
yield return AccessTools.Method(typeof(FloatMenuOption), nameof(FloatMenuOption.SetSizeMode));
yield return AccessTools.Method(typeof(Section), nameof(Section.RegenerateAllLayers));
yield return AccessTools.Method(typeof(Section), nameof(Section.RegenerateLayers));
yield return AccessTools.Method(typeof(Section), nameof(Section.RegenerateDirtyLayers));
yield return AccessTools.Method(typeof(SectionLayer), nameof(SectionLayer.DrawLayer));
yield return AccessTools.Method(typeof(Map), nameof(Map.MapUpdate));
yield return AccessTools.Method(typeof(GUIStyle), nameof(GUIStyle.CalcSize));
Expand Down
60 changes: 2 additions & 58 deletions Source/Client/Patches/Determinism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,36 +277,6 @@ static bool Prefix()
}
}

[HarmonyPatch(typeof(QuestNode_Root_PollutionRetaliation), nameof(QuestNode_Root_PollutionRetaliation.RunInt))]
static class ReplaceUnityRngPollutionRetaliation
{
// Simplified transpiler from MP Compat.
// Source: https://github.com/rwmt/Multiplayer-Compatibility/blob/2e82e71aef64c5a5a4fc879db6f49d3c20da25cb/Source/PatchingUtilities.cs#L226
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts, MethodBase original)
{
var anythingPatched = false;

var parameters = new[] { typeof(int), typeof(int) };
var unityRandomRangeInt = AccessTools.DeclaredMethod(typeof(Random), nameof(Random.Range), parameters);
var verseRandomRangeInt = AccessTools.DeclaredMethod(typeof(Rand), nameof(Rand.Range), parameters);

foreach (var inst in insts)
{
if ((inst.opcode == OpCodes.Call || inst.opcode == OpCodes.Callvirt) && inst.operand is MethodInfo method && method == unityRandomRangeInt)
{
inst.opcode = OpCodes.Call;
inst.operand = verseRandomRangeInt;

anythingPatched = true;
}

yield return inst;
}

if (!anythingPatched) Log.Warning($"No Unity RNG was patched for method: {original?.FullDescription() ?? "(unknown method)"}");
}
}

[HarmonyPatch(typeof(Pawn_RecordsTracker), nameof(Pawn_RecordsTracker.ExposeData))]
static class RecordsTrackerExposePatch
{
Expand Down Expand Up @@ -376,15 +346,15 @@ private static int NewQueryTick(int ticks, SituationalThoughtHandler thoughtHand
}
}

[HarmonyPatch(typeof(SituationalThoughtHandler), nameof(SituationalThoughtHandler.CheckRecalculateMoodThoughts))]
[HarmonyPatch(typeof(SituationalThoughtHandler), nameof(SituationalThoughtHandler.UpdateAllMoodThoughts))]
static class DontRecalculateMoodThoughtsInInterface
{
static bool Prefix(SituationalThoughtHandler __instance)
{
if (Multiplayer.Client != null && !Multiplayer.Ticking && !Multiplayer.ExecutingCmds) return false;

// Notify_SituationalThoughtsDirty was called
if (__instance.lastMoodThoughtsRecalculationTick == -99999)
if (__instance.thoughtsDirty)
__instance.cachedThoughts.Clear();

return true;
Expand Down Expand Up @@ -521,30 +491,4 @@ private static int NewCacheStatus(int gameTick)
}
}

[HarmonyPatch(typeof(CompPollutionPump), nameof(CompPollutionPump.CompTick))]
static class PollutionPumpRemoveCurrentMap
{
private static MethodInfo currentMapGetter = AccessTools.PropertyGetter(typeof(Find), nameof(Find.CurrentMap));

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts)
{
foreach (var inst in insts)
{
if (inst.operand == currentMapGetter)
{
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Call, MethodOf.Lambda(CompMap));
continue;
}

yield return inst;
}
}

static Map CompMap(CompPollutionPump pump)
{
return pump.parent.Map;
}
}

}
4 changes: 2 additions & 2 deletions Source/Client/Patches/Feedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static IEnumerable<MethodBase> TargetMethods()
static bool Prefix() => !Cancel;
}

[HarmonyPatch(typeof(Targeter), nameof(Targeter.BeginTargeting), typeof(TargetingParameters), typeof(Action<LocalTargetInfo>), typeof(Pawn), typeof(Action), typeof(Texture2D))]
[HarmonyPatch(typeof(Targeter), nameof(Targeter.BeginTargeting), typeof(TargetingParameters), typeof(Action<LocalTargetInfo>), typeof(Pawn), typeof(Action), typeof(Texture2D), typeof(bool))]
static class CancelBeginTargeting
{
static bool Prefix()
Expand All @@ -57,7 +57,7 @@ static class CancelMotesNotTargetedAtMe
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(MoteMaker), nameof(MoteMaker.MakeStaticMote), new[] { typeof(IntVec3), typeof(Map), typeof(ThingDef), typeof(float) });
yield return AccessTools.Method(typeof(MoteMaker), nameof(MoteMaker.MakeStaticMote), new[] { typeof(Vector3), typeof(Map), typeof(ThingDef), typeof(float), typeof(bool) });
yield return AccessTools.Method(typeof(MoteMaker), nameof(MoteMaker.MakeStaticMote), new[] { typeof(Vector3), typeof(Map), typeof(ThingDef), typeof(float), typeof(bool), typeof(float) });
}

static bool Prefix(ThingDef moteDef)
Expand Down
4 changes: 2 additions & 2 deletions Source/Client/Patches/LongEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Multiplayer.Client.Patches
{
[HarmonyPatch(typeof(LongEventHandler), nameof(LongEventHandler.QueueLongEvent), typeof(Action), typeof(string), typeof(bool), typeof(Action<Exception>), typeof(bool))]
[HarmonyPatch(typeof(LongEventHandler), nameof(LongEventHandler.QueueLongEvent), typeof(Action), typeof(string), typeof(bool), typeof(Action<Exception>), typeof(bool), typeof(Action))]
static class MarkLongEvents
{
private static MethodInfo MarkerMethod = AccessTools.Method(typeof(MarkLongEvents), nameof(Marker));
Expand Down Expand Up @@ -62,7 +62,7 @@ static void Postfix()
}
}

[HarmonyPatch(typeof(LongEventHandler), nameof(LongEventHandler.QueueLongEvent), new[] { typeof(Action), typeof(string), typeof(bool), typeof(Action<Exception>), typeof(bool) })]
[HarmonyPatch(typeof(LongEventHandler), nameof(LongEventHandler.QueueLongEvent), new[] { typeof(Action), typeof(string), typeof(bool), typeof(Action<Exception>), typeof(bool), typeof(Action) })]
static class LongEventAlwaysSync
{
static void Prefix(ref bool doAsynchronously)
Expand Down
10 changes: 5 additions & 5 deletions Source/Client/Patches/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static class RootPlayStartMarker
static void Finalizer() => starting = false;
}

[HarmonyPatch(typeof(LongEventHandler), nameof(LongEventHandler.QueueLongEvent), new[] { typeof(Action), typeof(string), typeof(bool), typeof(Action<Exception>), typeof(bool) })]
[HarmonyPatch(typeof(LongEventHandler), nameof(LongEventHandler.QueueLongEvent), new[] { typeof(Action), typeof(string), typeof(bool), typeof(Action<Exception>), typeof(bool), typeof(Action) })]
static class CancelRootPlayStartLongEvents
{
public static bool cancel;
Expand All @@ -263,7 +263,7 @@ static class DisableScreenFade1
static bool Prefix() => LongEventHandler.eventQueue.All(e => e.eventTextKey == "MpLoading");
}

[HarmonyPatch(typeof(ScreenFader), nameof(ScreenFader.StartFade))]
[HarmonyPatch(typeof(ScreenFader), nameof(ScreenFader.StartFade), typeof(Color), typeof(float), typeof(float))]
static class DisableScreenFade2
{
static bool Prefix() => LongEventHandler.eventQueue.All(e => e.eventTextKey == "MpLoading");
Expand Down Expand Up @@ -381,11 +381,11 @@ static class WorkPrioritySameValue
static bool Prefix(Pawn_WorkSettings __instance, WorkTypeDef w, int priority) => __instance.GetPriority(w) != priority;
}

[HarmonyPatch(typeof(Pawn_PlayerSettings), nameof(Pawn_PlayerSettings.AreaRestriction), MethodType.Setter)]
[HarmonyPatch(typeof(Pawn_PlayerSettings), nameof(Pawn_PlayerSettings.AreaRestrictionInPawnCurrentMap), MethodType.Setter)]
static class AreaRestrictionSameValue
{
[HarmonyPriority(MpPriority.MpFirst + 1)]
static bool Prefix(Pawn_PlayerSettings __instance, Area value) => __instance.AreaRestriction != value;
static bool Prefix(Pawn_PlayerSettings __instance, Area value) => __instance.AreaRestrictionInPawnCurrentMap != value;
}

[HarmonyPatch]
Expand Down Expand Up @@ -426,7 +426,7 @@ internal static void Choose(QuestPart_Choice part, int index)
}

[HarmonyPatch(typeof(MoteMaker), nameof(MoteMaker.MakeStaticMote))]
[HarmonyPatch(new[] {typeof(Vector3), typeof(Map), typeof(ThingDef), typeof(float), typeof(bool)})]
[HarmonyPatch(new[] {typeof(Vector3), typeof(Map), typeof(ThingDef), typeof(float), typeof(bool), typeof(float)})]
static class FixNullMotes
{
static Dictionary<Type, Mote> cache = new();
Expand Down
Loading
Loading