Skip to content

Commit

Permalink
Fix some issues with transpilers
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetrith committed May 6, 2024
1 parent 75cb8bf commit 0cf13ed
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Source/Client/Factions/MultifactionPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ static bool ShouldCancelCacheClear()
[HarmonyPatch(typeof(Apparel), nameof(Apparel.WornGraphicPath), MethodType.Getter)]
static class ApparelWornGraphicPathGetterPatch
{
private static FieldInfo thingIDNumberField = AccessTools.Field(typeof(Apparel), nameof(Apparel.thingIDNumber));
private static FieldInfo thingIDNumberField = AccessTools.Field(typeof(Thing), nameof(Thing.thingIDNumber));

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Client/Multiplayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

<ItemGroup>
<Publicize Include="Assembly-CSharp;0Harmony;UnityEngine.IMGUIModule" />
<DoNotPublicize Include="0Harmony:System.Runtime.CompilerServices.DefaultInterpolatedStringHandler" />
</ItemGroup>

<ItemGroup>
Expand Down
18 changes: 9 additions & 9 deletions Source/Client/Patches/Determinism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static bool Prefix(SituationalThoughtHandler __instance, Pawn otherPawn)
}

[HarmonyPatch(typeof(SituationalThoughtHandler), nameof(SituationalThoughtHandler.AppendSocialThoughts))]
static class DontUpdateThoughQueryTickInInterface
static class DontUpdateThoughtQueryTickInInterface
{
private static FieldInfo queryTickField = AccessTools.Field(typeof(SituationalThoughtHandler.CachedSocialThoughts), nameof(SituationalThoughtHandler.CachedSocialThoughts.lastQueryTick));

Expand All @@ -331,7 +331,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
{
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldarg_1);
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DontUpdateThoughQueryTickInInterface), nameof(NewQueryTick)));
yield return new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DontUpdateThoughtQueryTickInInterface), nameof(NewQueryTick)));
}

yield return inst;
Expand Down Expand Up @@ -411,7 +411,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
AccessTools.Method(typeof(PawnCapacitiesHandlerGetLevelPatch), nameof(NewCacheStatus)))
);

return matcher.codes;
return matcher.Instructions();
}

private static bool ShouldUpdateCache(PawnCapacitiesHandler.CacheStatus status)
Expand Down Expand Up @@ -459,18 +459,18 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
new CodeMatch(OpCodes.Newobj)
).Advance(1).Insert(
new CodeInstruction(OpCodes.Call,
AccessTools.Method(typeof(StatWorkerGetValuePatch), nameof(NewCacheStatusCtor)))
AccessTools.Method(typeof(StatWorkerGetValuePatch), nameof(NewCacheTicksCtor)))
);

// Modify status setter
matcher.MatchEndForward(
new CodeMatch(OpCodes.Stfld, typeof(StatCacheEntry).GetField(nameof(StatCacheEntry.gameTick)))
).Insert(
new CodeInstruction(OpCodes.Call,
AccessTools.Method(typeof(StatWorkerGetValuePatch), nameof(NewCacheStatus)))
AccessTools.Method(typeof(StatWorkerGetValuePatch), nameof(NewCacheTicks)))
);

return matcher.codes;
return matcher.Instructions();
}

private static bool HasValueInCache(bool hasValueInCache, StatWorker worker, Thing t)
Expand All @@ -479,13 +479,13 @@ private static bool HasValueInCache(bool hasValueInCache, StatWorker worker, Thi
return hasValueInCache && !(simulating && worker.temporaryStatCache[t].gameTick < 0);
}

private static StatCacheEntry NewCacheStatusCtor(StatCacheEntry entry)
private static StatCacheEntry NewCacheTicksCtor(StatCacheEntry entry)
{
entry.gameTick = NewCacheStatus(entry.gameTick);
entry.gameTick = NewCacheTicks(entry.gameTick);
return entry;
}

private static int NewCacheStatus(int gameTick)
private static int NewCacheTicks(int gameTick)
{
return Multiplayer.InInterface ? -gameTick : gameTick;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Patches/UniqueIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
{
// Handle negative thing ids when loading
// These come from getting a unique id in the interface and are fixed (replaced) later when necessary
if (inst.operand == "\\d+$")
if (inst.operand is "\\d+$")
inst.operand = "-?\\d+$";

yield return inst;
Expand Down
14 changes: 13 additions & 1 deletion Source/Client/Windows/ServerBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool Button(Texture2D icon, string labelKey, string tip, Color baseIconColor, fl

using (MpStyle.Set(mouseOver ? Color.yellow : Color.white))
using (MpStyle.Set(TextAnchor.MiddleCenter))
MpUI.Label(new Rect(x, 0, labelWidth, 24f), labelKey.Translate());
Widgets.Label(new Rect(x, 0, labelWidth, 24f), labelKey.Translate());

x += labelWidth;
x += 10;
Expand All @@ -140,6 +140,18 @@ bool Button(Texture2D icon, string labelKey, string tip, Color baseIconColor, fl
if (Button(MultiplayerStatic.DiscordIcon, "MpDiscordButton", "MpLinkButtonDesc".Translate() + " " + discordLink, Color.white))
Application.OpenURL(discordLink);

x += 10;
Widgets.Label(new Rect(x, 0, 400, 24), "Note: Multiplayer for 1.5 is still in testing phase.");

const string v15Notice =
"""
Anomaly compatibility is also a work-in-progress. Compatibility with other mods is likely going to take the longest to flesh out.
We recommend downgrading RimWorld to 1.4 if you want to continue playing a stable version.
""";

TooltipHandler.TipRegion(new Rect(x, 0, 400, 300), v15Notice);

if (false) // todo
Button(
TexButton.NewItem,
Expand Down
6 changes: 6 additions & 0 deletions Source/Multiplayer.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Parameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="__" Suffix="" Style="aaBb" /&gt;&lt;ExtraRule Prefix="___" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PublicFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=53eecf85_002Dd821_002D40e8_002Dac97_002Dfdb734542b84/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Instance fields (not private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=70345118_002D4b40_002D4ece_002D937c_002Dbbeb7a0b2e70/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Static fields (not private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=8a85b61a_002D1024_002D4f87_002Db9ef_002D1fdae19930a1/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Parameters"&gt;&lt;ElementKinds&gt;&lt;Kind Name="PARAMETER" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="__" Suffix="" Style="aaBb" /&gt;&lt;ExtraRule Prefix="___" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=8b8504e3_002Df0be_002D4c14_002D9103_002Dc732f2bddc15/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Enum members"&gt;&lt;ElementKinds&gt;&lt;Kind Name="ENUM_MEMBER" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=a0b4bc4d_002Dd13b_002D4a37_002Db37e_002Dc9c6864e4302/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Any" AccessRightKinds="Any" Description="Types and namespaces"&gt;&lt;ElementKinds&gt;&lt;Kind Name="NAMESPACE" /&gt;&lt;Kind Name="CLASS" /&gt;&lt;Kind Name="STRUCT" /&gt;&lt;Kind Name="ENUM" /&gt;&lt;Kind Name="DELEGATE" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="AaBb_AaBb" /&gt;&lt;/Policy&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=addr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=allocs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Archivables/@EntryIndexedValue">True</s:Boolean>
Expand Down

0 comments on commit 0cf13ed

Please sign in to comment.