Skip to content
Open
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
Binary file added References/EccentricDefenseGrid.dll
Binary file not shown.
1 change: 1 addition & 0 deletions References/EccentricDefenseGrid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2CAF9AB8B7DE9F0347A53E1F688395533DA5B163
61 changes: 61 additions & 0 deletions Source/Mods/EccentricTechFlares.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using HarmonyLib;
using Multiplayer.API;
using Verse;
using System.Reflection;
using System;
namespace Multiplayer.Compat
{
/// <summary>Eccentric Extras - Flares by Aelanna</summary>
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=2552628275"/>
[MpCompatFor("Aelanna.EccentricTech.Flares2")]
internal class EccentricTechFlares
{

private static ConstructorInfo commandThrowIlluminatorConstructor;
private static Type compIlluminatorPackType;
public EccentricTechFlares(ModContentPack mod)
{
// RNG
{
}

// Gizmos
{
var commandThrowIlluminatorType = AccessTools.TypeByName("EccentricFlares.Command_ThrowIlluminator");
compIlluminatorPackType = AccessTools.TypeByName("EccentricFlares.CompIlluminatorPack");

commandThrowIlluminatorConstructor = AccessTools.DeclaredConstructor(commandThrowIlluminatorType, [compIlluminatorPackType]);

MP.RegisterSyncWorker<object>(SyncCommandThrowIlluminator, commandThrowIlluminatorType);
MP.RegisterSyncMethod(commandThrowIlluminatorType, "SelectOption");



LongEventHandler.ExecuteWhenFinished(LatePatch);
}

}
public static void LatePatch()
{
var type = AccessTools.TypeByName("EccentricFlares.CompIlluminatorPack");

MP.RegisterSyncMethod(compIlluminatorPackType, "DoStartThrow");
MpCompat.RegisterLambdaMethod(type, "CompGetWornGizmosExtra", 1);
}

private static void SyncCommandThrowIlluminator(SyncWorker sync, ref object command)
{

if (sync.isWriting)
{
Traverse traverse = Traverse.Create(command);
ThingComp comp = traverse.Field("pack").GetValue<ThingComp>();
sync.Write(comp);
}
else
{
command = commandThrowIlluminatorConstructor.Invoke([sync.Read<ThingComp>()]);
}
}
}
}
25 changes: 12 additions & 13 deletions Source/Mods/VanillaExpandedFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ private static void SyncCommandWithBuilding(SyncWorker sync, ref Command command
else
building.SetValue(sync.Read<Thing>());
}
private static void SyncCommandWithCompBuilding(SyncWorker sync, ref Command command)
{
var traverse = Traverse.Create(command);
var building = traverse.Field("building");

if (sync.isWriting)
sync.Write(building.GetValue() as ThingComp);
else
building.SetValue(sync.Read<ThingComp>());
}

#endregion

Expand Down Expand Up @@ -619,7 +629,6 @@ private static void SyncHireable(SyncWorker sync, ref object obj)
#region Vanilla Furniture Expanded

// Vanilla Furniture Expanded
private static AccessTools.FieldRef<object, ThingComp> setStoneBuildingField;
private static Type randomBuildingGraphicCompType;
private static FastInvokeHandler randomBuildingGraphicCompChangeGraphicMethod;

Expand All @@ -634,14 +643,12 @@ private static void PatchVanillaFurnitureExpanded()

var type = AccessTools.TypeByName("VanillaFurnitureExpanded.Command_SetItemsToSpawn");
MpCompat.RegisterLambdaDelegate(type, "ProcessInput", 1);
MP.RegisterSyncWorker<Command>(SyncCommandWithBuilding, type, shouldConstruct: true);
MP.RegisterSyncWorker<Command>(SyncCommandWithCompBuilding, type, shouldConstruct: true);

MpCompat.RegisterLambdaMethod("VanillaFurnitureExpanded.CompRockSpawner", "CompGetGizmosExtra", 0);

type = AccessTools.TypeByName("VanillaFurnitureExpanded.Command_SetStoneType");
setStoneBuildingField = AccessTools.FieldRefAccess<ThingComp>(type, "building");
MpCompat.RegisterLambdaMethod(type, "ProcessInput", 0);
MP.RegisterSyncWorker<Command>(SyncSetStoneTypeCommand, type, shouldConstruct: true);
MP.RegisterSyncWorker<Command>(SyncCommandWithCompBuilding, type, shouldConstruct: true);
MpCompat.RegisterLambdaDelegate(type, "ProcessInput", 1);

type = randomBuildingGraphicCompType = AccessTools.TypeByName("VanillaFurnitureExpanded.CompRandomBuildingGraphic");
Expand Down Expand Up @@ -679,14 +686,6 @@ private static void PatchVanillaFurnitureExpanded()
MP.RegisterSyncWorker<CompGlower>(SyncCompGlower);
}

private static void SyncSetStoneTypeCommand(SyncWorker sync, ref Command obj)
{
if (sync.isWriting)
sync.Write(setStoneBuildingField(obj));
else
setStoneBuildingField(obj) = sync.Read<ThingComp>();
}

private static bool Dialog_ChooseGraphic_ReplacementButton(Rect butRect, bool doMouseoverSound, Thing thingToChange, int index, Window window)
{
var result = Widgets.ButtonInvisible(butRect, doMouseoverSound);
Expand Down
232 changes: 232 additions & 0 deletions Source_Referenced/EccentricDefenseGrid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
using HarmonyLib;
using Multiplayer.API;
using RimWorld;
using Verse;
using EccentricDefenseGrid;
using System.Linq;

namespace Multiplayer.Compat
{
/// <summary>EccentricTech.DefenseGrid by Aelanna</summary>
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=3066838686"/>
[MpCompatFor("Aelanna.EccentricTech.DefenseGrid")]
internal class EccentricTechDefenseGrid
//
{
private static ISyncField autoReload;
private static CompArtilleryMissileLauncher parentCompArtilleryMissileLauncher;
public EccentricTechDefenseGrid(ModContentPack mod)
{
// RNG
{
// patch this or every effect
// Seems all effcts go through this class and many of them contains rand
var type = AccessTools.TypeByName("EccentricProjectiles.EffectMapComponent");
var methods = new[]
{
AccessTools.Method(type, "MapComponentTick"),
AccessTools.Method(type,"CreateEffect")
};
PatchingUtilities.PatchPushPopRand(methods);
}

// Gizmos
{
var type = AccessTools.TypeByName("EccentricDefenseGrid.CompArtilleryDesignator");
MP.RegisterSyncMethod(type, "NextDesignationMode");
MP.RegisterSyncMethod(type, "SetDesignationMode");
MP.RegisterSyncMethod(type, "SetOrdnanceIndex");
// This delegate set field `ordnanceDef` & call `DoArtilleryDesignation`
MpCompat.RegisterLambdaDelegate(type, "DoArtilleryTargeting", 0);

type = AccessTools.TypeByName("EccentricDefenseGrid.DefenseGridNetwork");
MP.RegisterSyncMethod(type, "NextDesignationMode");
MP.RegisterSyncMethod(type, "SetDesignationMode");
MP.RegisterSyncMethod(type, "SetSelectedOrdnance");
MpCompat.RegisterLambdaDelegate(type, "DoArtilleryTargeting", 0);

MP.RegisterSyncWorker<object>(SyncDefenseGridNetwork, type);
type = AccessTools.TypeByName("EccentricDefenseGrid.OrdnanceCount");
MP.RegisterSyncWorker<object>(SyncOrdnanceCount, type, shouldConstruct: true);



type = AccessTools.TypeByName("EccentricDefenseGrid.DefenseGridMapComponent");

MP.RegisterSyncMethod(type, "RecountOrdnance");

type = AccessTools.TypeByName("EccentricDefenseGrid.CompArtilleryMissileLauncher");
MpCompat.RegisterLambdaMethod(type, "CompGetGizmosExtra", 0, 1);


type = AccessTools.TypeByName("EccentricDefenseGrid.CompDefenseProjector");
//called from gizmo
MP.RegisterSyncMethod(type, "ApplyRadius").SetContext(SyncContext.MapSelected);
MP.RegisterSyncMethod(type, "ApplyColor").SetContext(SyncContext.MapSelected);
MpCompat.RegisterLambdaMethod(type, "CompGetGizmosExtra", 1).SetDebugOnly();

type = AccessTools.TypeByName("EccentricDefenseGrid.CompDefenseGenerator");
MpCompat.RegisterLambdaMethod(type, "CompGetGizmosExtra", 2, 4, 6, 8, 10, 11, 12).TakeLast(2).SetDebugOnly();

type = AccessTools.TypeByName("EccentricDefenseGrid.CompDefenseHeatsink");
MpCompat.RegisterLambdaMethod(type, "CompGetGizmosExtra", 0, 1, 2).SetDebugOnly();


}
{
var type = AccessTools.TypeByName("EccentricDefenseGrid.OrdnanceSlot");

MP.RegisterSyncWorker<OrdnanceSlot>(SyncOrdnanceSlot, type);
}
// ITab
{

var type = AccessTools.TypeByName("EccentricDefenseGrid.ITab_OrdnanceStorage");


MpCompat.harmony.Patch(AccessTools.Method(type, "FillTab"),
prefix: new HarmonyMethod(typeof(EccentricTechDefenseGrid), nameof(PreFillTab)),
postfix: new HarmonyMethod(typeof(EccentricTechDefenseGrid), nameof(PostFillTab)));


MpCompat.RegisterLambdaDelegate(type, "DrawOrdnance_GenerateMenu", 0, 1).SetContext(SyncContext.MapSelected);



type = AccessTools.TypeByName("EccentricDefenseGrid.OrdnanceSlot");
autoReload = MP.RegisterSyncField(type, "autoReload");
type = AccessTools.TypeByName("EccentricDefenseGrid.CompArtilleryMissileLauncher");

MP.RegisterSyncWorker<CompArtilleryMissileLauncher>(SyncCompArtilleryMissileLauncher, type);
}

}

private static void PreFillTab(ITab __instance)
{
if (!MP.IsInMultiplayer)
{
return;
}
Building building = __instance.SelThing as Building;
parentCompArtilleryMissileLauncher = building.GetComp<CompArtilleryMissileLauncher>();

MP.WatchBegin();
parentCompArtilleryMissileLauncher.slots.ForEach((slot) => autoReload.Watch(slot));
}
private static void PostFillTab()
{
if (!MP.IsInMultiplayer)
return;
parentCompArtilleryMissileLauncher = null;
MP.WatchEnd();
}
private static void SyncOrdnanceSlot(SyncWorker sync, ref OrdnanceSlot obj)
{
if (sync.isWriting)
{
sync.Write<bool>(obj is null);
if (obj is null)
return;


}
else
{
// is null
// does exist as method `DrawOrdnance_GenerateMenu` could be called with this param null
if (sync.Read<bool>())
{
obj = null;
return;
}
}

CompArtilleryMissileLauncher compArtilleryMissileLauncher = Find.Selector.SingleSelectedThing?.TryGetComp<CompArtilleryMissileLauncher>();
if (compArtilleryMissileLauncher != null)
{
if (sync.isWriting)
{
sync.Write<int>(compArtilleryMissileLauncher.slots.IndexOf(obj));
return;
}
else
{
int index = sync.Read<int>();
if (index != -1)
{
obj = compArtilleryMissileLauncher.slots[index];
return;

}
else
{
// to normal
}
}

}

// normally copied by exposeFields
//sync.Bind(ref obj, ordnanceSlot);
if (sync.isWriting)
{

sync.Write<bool>(obj.autoReload);
sync.Write<ThingWithComps>(obj.ordnance as ThingWithComps);
sync.Write<string>(obj.def.defName);
}
else
{


obj.autoReload = sync.Read<bool>();
obj.ordnance = sync.Read<ThingWithComps>() as Ordnance;
obj.def = DefDatabase<OrdnanceDef>.GetNamed(sync.Read<string>());

}
}
private static void SyncOrdnanceCount(SyncWorker sync, ref object ordnanceCount)
{
OrdnanceCount _oc = ordnanceCount as OrdnanceCount;
if (sync.isWriting)
{
sync.Write(_oc.def.defName);
sync.Write(_oc.count);
}
else
{
_oc.def = DefDatabase<OrdnanceDef>.GetNamed(sync.Read<string>());
_oc.count = sync.Read<int>();
}
}
private static void SyncDefenseGridNetwork(SyncWorker sync, ref object network)
{
DefenseGridNetwork _net = network as DefenseGridNetwork;
if (sync.isWriting)
{
sync.Write(_net.mapComponent.map);
sync.Write(_net.id);
}
else
{
Map map = sync.Read<Map>();
int id = sync.Read<int>();
network = map.GetComponent<DefenseGridMapComponent>().networks.Find((net) => net.id == id);
}
}

private static void SyncCompArtilleryMissileLauncher(SyncWorker sync, ref CompArtilleryMissileLauncher compArtilleryMissileLauncher)
{
if (sync.isWriting)
{
sync.Write(compArtilleryMissileLauncher.parent as ThingWithComps);
}
else
{
compArtilleryMissileLauncher = sync.Read<ThingWithComps>().GetComp<CompArtilleryMissileLauncher>();
}
}

}
}