Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yukieiji committed Nov 14, 2023
1 parent 7970ee9 commit ff3bda8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
26 changes: 8 additions & 18 deletions ExtremeRoles/Compat/ModIntegrator/SubmergedMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ public enum ElevatorSelection
private MethodInfo calculateLightRadiusMethod;

private MethodInfo rpcRequestChangeFloorMethod;
private MethodInfo registerFloorOverrideMethod;
private FieldInfo onUpperField;
private MethodInfo getFloorHandlerInfo;

private Type submarineOxygenSystem;
private PropertyInfo submarineOxygenSystemInstanceGetter;
private MethodInfo submarineOxygenSystemRepairDamageMethod;

private PropertyInfo submarinePlayerFloorSystemInstanceGetter;
private MethodInfo submarinePlayerFloorSystemChangePlayerFloorStateMethod;

private Type elevatorMover;

private MonoBehaviour? submarineStatus;
Expand Down Expand Up @@ -115,13 +113,6 @@ public SubmergedIntegrator(PluginInfo plugin) : base(Guid, plugin)
this.submarineOxygenSystemRepairDamageMethod = AccessTools.Method(
this.submarineOxygenSystem, "RepairDamage");

Type floorSubmarinePlayerFloorSystem = this.ClassType.First(
t => t.Name == "SubmarinePlayerFloorSystem");
this.submarinePlayerFloorSystemInstanceGetter = AccessTools.Property(
floorSubmarinePlayerFloorSystem, "Instance");
this.submarinePlayerFloorSystemChangePlayerFloorStateMethod = AccessTools.Method(
floorSubmarinePlayerFloorSystem, "ChangePlayerFloorState");

// サブマージドのカスタムMonoを取ってくる
this.elevatorMover = this.ClassType.First(t => t.Name == "ElevatorMover");

Expand All @@ -131,6 +122,9 @@ public SubmergedIntegrator(PluginInfo plugin) : base(Guid, plugin)
floorHandlerType, "GetFloorHandler", new Type[] { typeof(PlayerControl) });
this.rpcRequestChangeFloorMethod = AccessTools.Method(
floorHandlerType, "RpcRequestChangeFloor");
this.registerFloorOverrideMethod = AccessTools.Method(
floorHandlerType, "RegisterFloorOverride");

this.onUpperField = AccessTools.Field(floorHandlerType, "onUpper");

this.submarineStatusType = ClassType.First(
Expand All @@ -145,13 +139,6 @@ public SubmergedIntegrator(PluginInfo plugin) : base(Guid, plugin)
}
#pragma warning restore CS8618

public void ChangeFloorTo(byte playerId, bool isUpper)
{
this.submarinePlayerFloorSystemChangePlayerFloorStateMethod.Invoke(
this.submarinePlayerFloorSystemInstanceGetter.GetValue(null),
new object[] { playerId, isUpper });
}

public void Awake(ShipStatus map)
{
var component = map.GetComponent(Il2CppType.From(this.submarineStatusType));
Expand Down Expand Up @@ -232,7 +219,10 @@ public void ChangeFloor(PlayerControl player, int floor)
MonoBehaviour? floorHandler = getFloorHandler(player);
if (floorHandler == null) { return; }

this.rpcRequestChangeFloorMethod.Invoke(floorHandler, new object[] { floor == 1 });
object[] args = new object[] { floor == 1 };

this.rpcRequestChangeFloorMethod.Invoke(floorHandler, args);
this.registerFloorOverrideMethod.Invoke(floorHandler, args);
}

public Console? GetConsole(TaskTypes task)
Expand Down
25 changes: 16 additions & 9 deletions ExtremeRoles/RPCOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using ExtremeRoles.Extension.Ship;
using ExtremeRoles.Performance;
using ExtremeRoles.Extension.Player;
using ExtremeRoles.Compat.ModIntegrator;
using ExtremeRoles.Compat;

namespace ExtremeRoles;

Expand Down Expand Up @@ -379,18 +381,23 @@ public static void UncheckedSnapTo(
byte teleporterId, UnityEngine.Vector2 pos)
{
PlayerControl teleportPlayer = Helper.Player.GetPlayerControlById(teleporterId);
if (teleportPlayer != null)
{
if (CompatModManager.Instance.TryGetModMap<SubmergedIntegrator>(out var mapMod) &&
AmongUsClient.Instance.AmHost)
if (teleportPlayer == null) { return; }

var curPos = teleportPlayer.GetTruePosition();
teleportPlayer.NetTransform.SnapTo(pos);

if (CompatModManager.Instance.TryGetModMap<SubmergedIntegrator>(out var mapMod) &&
CachedPlayerControl.LocalPlayer.PlayerId == teleporterId)
{
int targetFloor = pos.y > -6.19f ? 1 : 0;
int prevFloor = curPos.y > -6.19f ? 1 : 0;
if (targetFloor != prevFloor)
{
bool isUpper = pos.y > -6.19;
mapMod.ChangeFloorTo(teleporterId, isUpper);
mapMod.ChangeFloor(teleportPlayer, targetFloor);
}
}

teleportPlayer.NetTransform.SnapTo(pos);
}
}
}

public static void UncheckedShapeShift(
byte sourceId, byte targetId, byte useAnimation)
Expand Down

0 comments on commit ff3bda8

Please sign in to comment.