-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added compat for Hemogen Extractor (#300)
* Added compat for Hemogen Extractor * Updated Hemogen Extractor compat Now uses the changed API introduced by Zetrith, instead of the (now outdated) ones made by me. --------- Co-authored-by: Sokyran <toCy&#$VIH$1cSOu8s&Fv@UVN%L3snN*H09$1^Xghq*hKo9Itnmq#bNf8Ld67#T$#a&cEaY1>
- Loading branch information
1 parent
4b6b34a
commit 575db9e
Showing
1 changed file
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using HarmonyLib; | ||
using Multiplayer.API; | ||
using RimWorld; | ||
using Verse; | ||
|
||
namespace Multiplayer.Compat | ||
{ | ||
/// <summary>Hemogen Extractor by Уверен?</summary> | ||
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=2903919607"/> | ||
[MpCompatFor("Uveren.HemogenExtractor")] | ||
public class HemogenExtractor | ||
{ | ||
private static FastInvokeHandler getStoreSettingsMethod; | ||
private static FastInvokeHandler getParentStoreSettingsMethod; | ||
|
||
private static Type nutritionRefuelableType; | ||
|
||
public HemogenExtractor(ModContentPack mod) | ||
{ | ||
MpCompat.RegisterLambdaMethod("HemogenExtractor.CompSpawnerHemogen", "CompGetGizmosExtra", 0, 1).SetDebugOnly(); | ||
|
||
var type = nutritionRefuelableType = AccessTools.TypeByName("HemogenExtractor.CompNutritionRefuelable"); | ||
getStoreSettingsMethod = MethodInvoker.GetHandler(AccessTools.DeclaredMethod(type, "GetStoreSettings")); | ||
getParentStoreSettingsMethod = MethodInvoker.GetHandler(AccessTools.DeclaredMethod(type, "GetParentStoreSettings")); | ||
|
||
MpCompat.harmony.Patch(AccessTools.DeclaredMethod("HemogenExtractor.ITab_CustomNutrition:FillTab"), | ||
prefix: new HarmonyMethod(typeof(HemogenExtractor), nameof(PreFillTab)), | ||
finalizer: new HarmonyMethod(typeof(HemogenExtractor), nameof(PostFillTab))); | ||
} | ||
|
||
private static void PreFillTab() | ||
{ | ||
if (!MP.IsInMultiplayer || Find.Selector.SingleSelectedThing is not ThingWithComps thing) | ||
return; | ||
|
||
if (thing.comps.FirstOrDefault(c => c.GetType() == nutritionRefuelableType) is CompRefuelable comp) | ||
MP.SetThingFilterContext(new HemogenExtractorContext(comp)); | ||
} | ||
|
||
private static void PostFillTab() => MP.SetThingFilterContext(null); | ||
|
||
[MpCompatRequireMod("Uveren.HemogenExtractor")] | ||
public record HemogenExtractorContext(CompRefuelable Obj) : ThingFilterContext | ||
{ | ||
public CompRefuelable Obj { get; } = Obj; | ||
|
||
public override ThingFilter Filter => ((StorageSettings)getStoreSettingsMethod(Obj)).filter; | ||
public override ThingFilter ParentFilter => ((StorageSettings)getParentStoreSettingsMethod(Obj))?.filter; | ||
} | ||
} | ||
} |