-
-
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.
- Loading branch information
1 parent
f519f5d
commit 972e964
Showing
1 changed file
with
50 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,50 @@ | ||
using System; | ||
using HarmonyLib; | ||
using Multiplayer.API; | ||
using Verse; | ||
|
||
namespace Multiplayer.Compat; | ||
|
||
/// <summary>Automatic Parking by rabiosus</summary> | ||
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=3365473553"/> | ||
[MpCompatFor("rabiosus.vfautoparking")] | ||
public class AutomaticParking | ||
{ | ||
// CompParkingController | ||
private static Type parkingControllerCompType; | ||
private static AccessTools.FieldRef<ThingComp, object> parkingControllerCompControllerField; | ||
// ParkingController | ||
private static AccessTools.FieldRef<object, Pawn> parkingControllerVehicleField; | ||
|
||
public AutomaticParking(ModContentPack mod) | ||
{ | ||
MpCompatPatchLoader.LoadPatch(this); | ||
|
||
// CompParkingController | ||
var type = parkingControllerCompType = AccessTools.TypeByName("VehicleAutoParking.Core.CompParkingController"); | ||
parkingControllerCompControllerField = AccessTools.FieldRefAccess<object>(type, "parkingController"); | ||
// ParkingController | ||
type = AccessTools.TypeByName("VehicleAutoParking.Core.ParkingController"); | ||
parkingControllerVehicleField = AccessTools.FieldRefAccess<Pawn>(type, "vehicle"); | ||
MP.RegisterSyncMethod(type, "SaveParkingPosition"); | ||
MP.RegisterSyncMethod(type, "ResetParkingPosition"); | ||
MP.RegisterSyncMethod(type, "MoveToParkingPosition"); | ||
} | ||
|
||
[MpCompatSyncWorker("VehicleAutoParking.Core.ParkingController")] | ||
private static void SyncParkingController(SyncWorker sync, ref object controller) | ||
{ | ||
if (sync.isWriting) | ||
{ | ||
sync.Write(parkingControllerVehicleField(controller)); | ||
} | ||
else | ||
{ | ||
var comp = sync.Read<Pawn>().AllComps.FirstOrDefault(c => parkingControllerCompType.IsInstanceOfType(c)); | ||
if (comp != null) | ||
controller = parkingControllerCompControllerField(comp); | ||
else | ||
Log.Error("A vehicle is missing CompParkingController."); | ||
} | ||
} | ||
} |