Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
33 changes: 33 additions & 0 deletions EXILED/Exiled.API/Extensions/MirrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public static void MessageTranslated(this Player player, string words, string tr
/// <param name="targetType"><see cref="NetworkBehaviour"/>'s type.</param>
/// <param name="propertyName">Property name starting with Network.</param>
/// <param name="value">Value of send to target.</param>
[Obsolete("Use overload with type-template instead.")]
public static void SendFakeSyncVar(this Player target, NetworkIdentity behaviorOwner, Type targetType, string propertyName, object value)
{
if (!target.IsConnected)
Expand All @@ -386,6 +387,38 @@ void CustomSyncVarGenerator(NetworkWriter targetWriter)
}
}

/// <summary>
/// Send fake values to client's <see cref="SyncVarAttribute"/>.
/// </summary>
/// <typeparam name="T">Target SyncVar property type.</typeparam>
/// <param name="target">Target to send.</param>
/// <param name="behaviorOwner"><see cref="NetworkIdentity"/> of object that owns <see cref="NetworkBehaviour"/>.</param>
/// <param name="targetType"><see cref="NetworkBehaviour"/>'s type.</param>
/// <param name="propertyName">Property name starting with Network.</param>
/// <param name="value">Value of send to target.</param>
public static void SendFakeSyncVar<T>(this Player target, NetworkIdentity behaviorOwner, Type targetType, string propertyName, T value)
{
if (!target.IsConnected)
return;

NetworkWriterPooled writer = NetworkWriterPool.Get();
NetworkWriterPooled writer2 = NetworkWriterPool.Get();
MakeCustomSyncWriter(behaviorOwner, targetType, null, CustomSyncVarGenerator, writer, writer2);
target.Connection.Send(new EntityStateMessage
{
netId = behaviorOwner.netId,
payload = writer.ToArraySegment(),
});

NetworkWriterPool.Return(writer);
NetworkWriterPool.Return(writer2);
void CustomSyncVarGenerator(NetworkWriter targetWriter)
{
targetWriter.WriteULong(SyncVarDirtyBits[$"{targetType.Name}.{propertyName}"]);
WriterExtensions[typeof(T)]?.Invoke(null, new object[2] { targetWriter, value });
}
}

/// <summary>
/// Force resync to client's <see cref="SyncVarAttribute"/>.
/// </summary>
Expand Down
40 changes: 36 additions & 4 deletions EXILED/Exiled.Events/Patches/Generic/DoorList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,46 @@ namespace Exiled.Events.Patches.Generic
[HarmonyPatch(typeof(DoorVariant), nameof(DoorVariant.RegisterRooms))]
internal class DoorList
{
private static void Postfix(DoorVariant __instance)
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
if (Door.DoorVariantToDoor.ContainsKey(__instance))
List<CodeInstruction> newInstructions = ListPool<CodeInstruction>.Pool.Get(instructions);

Label ret = generator.DefineLabel();

// new Generator(this)
Comment thread
IRacle1 marked this conversation as resolved.
Outdated
newInstructions.InsertRange(
0,
new CodeInstruction[]
{
new(OpCodes.Ldarg_0),
new(OpCodes.Callvirt, PropertyGetter(typeof(DoorVariant), nameof(DoorVariant.Rooms))),
new(OpCodes.Brfalse_S, ret),
});

newInstructions.InsertRange(
newInstructions.Count - 1,
new CodeInstruction[]
{
new(OpCodes.Ldarg_0),
new(OpCodes.Call, Method(typeof(DoorList), nameof(DoorList.InitDoor))),
});
Comment thread
IRacle1 marked this conversation as resolved.

newInstructions[newInstructions.Count - 1].labels.Add(ret);

for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];

ListPool<CodeInstruction>.Pool.Return(newInstructions);
}

private static void InitDoor(DoorVariant doorVariant)
{
if (Door.DoorVariantToDoor.ContainsKey(doorVariant))
return;

List<Room> rooms = __instance.Rooms.Select(identifier => Room.RoomIdentifierToRoom[identifier]).ToList();
List<Room> rooms = doorVariant.Rooms.Select(identifier => Room.RoomIdentifierToRoom[identifier]).ToList();

Door door = Door.Create(__instance, rooms);
Door door = Door.Create(doorVariant, rooms);

foreach (Room room in rooms)
{
Expand Down