Skip to content

Commit

Permalink
Merge branch 'dev' into xmas-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Dec 31, 2024
2 parents fd5db8b + d7425db commit 1452e13
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 120 deletions.
2 changes: 2 additions & 0 deletions EXILED/Exiled.API/Features/Items/Firearm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Exiled.API.Features.Items
using Extensions;
using InventorySystem;
using InventorySystem.Items;
using InventorySystem.Items.Autosync;
using InventorySystem.Items.Firearms;
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.Attachments.Components;
Expand Down Expand Up @@ -690,6 +691,7 @@ public override Item Clone()
/// <param name="newOwner">new <see cref="Firearm"/> owner.</param>
internal override void ChangeOwner(Player oldOwner, Player newOwner)
{
Base.InstantiationStatus = newOwner == Server.Host ? AutosyncInstantiationStatus.SimulatedInstance : AutosyncInstantiationStatus.InventoryInstance;
Base.Owner = newOwner.ReferenceHub;
Base._footprintCacheSet = false;
foreach (ModuleBase module in Base.Modules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override bool IsCocked

set
{
PumpBarrel.SyncCocked = MaxAmmo;
PumpBarrel.SyncCocked = value ? MaxAmmo : 0;
Resync();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public override int MaxAmmo
set => MagazineModule._defaultCapacity = value;
}

/// <inheritdoc/>
public override int Ammo
{
set
{
MagazineModule.SyncData[MagazineModule.ItemSerial] = Math.Max(value, 0) + 1;
Resync();
}
}

/// <inheritdoc/>
public override int ConstantMaxAmmo => MagazineModule._defaultCapacity;

Expand Down
4 changes: 3 additions & 1 deletion EXILED/Exiled.API/Features/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public Item(ItemBase itemBase)
ushort serial = ItemSerialGenerator.GenerateNext();
Serial = serial;
itemBase.OnAdded(null);
if (Base is ModularAutosyncItem syncItem)
syncItem.InstantiationStatus = AutosyncInstantiationStatus.SimulatedInstance;
#if DEBUG
Log.Debug($"{nameof(Item)}.ctor: Generating new serial number. Serial should now be: {serial}. // {Serial}");
#endif
Expand Down Expand Up @@ -311,7 +313,7 @@ public static T Get<T>(ushort serial)
BodyArmor => new Armor(type),
AmmoItem => new Ammo(type),
ToggleableLightItemBase => new Flashlight(type),
JailbirdItem jailbird => new Jailbird(jailbird),
JailbirdItem => new Jailbird(),
ThrowableItem throwable => throwable.Projectile switch
{
FlashbangGrenade => new FlashGrenade(owner),
Expand Down
16 changes: 16 additions & 0 deletions EXILED/Exiled.API/Features/Items/MicroHid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace Exiled.API.Features.Items

using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;

using InventorySystem.Items.Autosync;
using InventorySystem.Items.Firearms.Modules;
using InventorySystem.Items.MicroHID;
using InventorySystem.Items.MicroHID.Modules;

Expand Down Expand Up @@ -214,5 +217,18 @@ public bool TryGetFireController<T>(MicroHidFiringMode firingMode, out T module)
/// </summary>
/// <returns>A string containing MicroHid-related data.</returns>
public override string ToString() => $"{Type} ({Serial}) [{Weight}] *{Scale}* |{Energy}| -{State}-";

/// <inheritdoc/>
internal override void ChangeOwner(Player oldOwner, Player newOwner)
{
Base.Owner = newOwner.ReferenceHub;

for (int i = 0; i < Base.AllSubcomponents.Length; i++)
{
Base.AllSubcomponents[i].OnAdded();
}

Base.InstantiationStatus = newOwner == Server.Host ? AutosyncInstantiationStatus.SimulatedInstance : AutosyncInstantiationStatus.InventoryInstance;
}
}
}
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Pickups/Pickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,12 @@ public static IEnumerable<T> Get<T>(IEnumerable<GameObject> gameObjects)
ThrownProjectile thrownProjectile => thrownProjectile switch
{
BaseScp018Projectile => new Projectiles.Scp018Projectile(),
ExplosionGrenade explosionGrenade => new ExplosionGrenadeProjectile(explosionGrenade),
ExplosionGrenade explosionGrenade => new ExplosionGrenadeProjectile(type),
FlashbangGrenade => new FlashbangProjectile(),
BaseScp2176Projectile => new Projectiles.Scp2176Projectile(),
EffectGrenade => new EffectGrenadeProjectile(type),
TimeGrenade => new TimeGrenadeProjectile(type),
_ => new Projectile(thrownProjectile),
_ => new Projectile(type),
},
_ => new Pickup(type),
};
Expand Down
5 changes: 5 additions & 0 deletions EXILED/Exiled.API/Features/Roles/Scp3114Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ public float WarningTime
set => Identity._warningTimeSeconds = value;
}

/// <summary>
/// Gets or sets the next bound dance.
/// </summary>
public DanceType? NextDanceType { get; set; }

/// <summary>
/// Gets or sets the bound dance.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions EXILED/Exiled.API/Features/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ public void UnlockAll()
/// Factory method to create and add a <see cref="Room"/> component to a Transform.
/// We can add parameters to be set privately here.
/// </summary>
/// <param name="roomIdentifier">The Game Object to attach the Room component to.</param>
internal static void CreateComponent(RoomIdentifier roomIdentifier) => roomIdentifier.gameObject.AddComponent<Room>();
/// <param name="baseRoom">The Game Object to attach the Room component to.</param>
internal static void CreateComponent(GameObject baseRoom) => baseRoom.AddComponent<Room>().InternalCreate();

/// <summary>
/// Factory method to complete all element inside a Room.
Expand Down
3 changes: 2 additions & 1 deletion EXILED/Exiled.Events/EventArgs/Scp3114/DancingEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public DancingEventArgs(bool newState, Player player, bool isAllowed = true)
Player = player;
Scp3114 = player.Role.As<Scp3114Role>();
IsDancing = newState;
DanceType = (DanceType)(newState ? UnityEngine.Random.Range(0, Scp3114.Dance._danceVariants) : byte.MaxValue);
DanceType = newState ? (Scp3114.NextDanceType ?? (DanceType)UnityEngine.Random.Range(0, Scp3114.Dance._danceVariants)) : (DanceType)byte.MaxValue;
Scp3114.NextDanceType = null;
IsAllowed = isAllowed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Exiled.Events.EventArgs.Server
{
using System;
using System.Collections.Generic;

using Exiled.API.Features;
Expand Down Expand Up @@ -39,7 +40,7 @@ public RespawningTeamEventArgs(List<Player> players, int maxRespawn, SpawnableWa
{
Players = players;
MaximumRespawnAmount = maxRespawn;
SpawnQueue = WaveSpawner.SpawnQueue;
Wave.PopulateQueue(SpawnQueue, MaximumRespawnAmount);
Wave = new TimedWave((TimeBasedWave)wave);
IsAllowed = true;
}
Expand Down
19 changes: 12 additions & 7 deletions EXILED/Exiled.Events/Patches/Events/Server/RespawningTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new CodeInstruction(OpCodes.Ldloc_S, ev.LocalIndex).WithLabels(continueLabel),
new(OpCodes.Dup),
new(OpCodes.Dup),
new(OpCodes.Dup),

// num = ev.MaximumRespawnAmount
new(OpCodes.Callvirt, PropertyGetter(typeof(RespawningTeamEventArgs), nameof(RespawningTeamEventArgs.MaximumRespawnAmount))),
Expand All @@ -98,8 +99,19 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
new(OpCodes.Callvirt, PropertyGetter(typeof(RespawningTeamEventArgs), nameof(RespawningTeamEventArgs.Wave))),
new(OpCodes.Callvirt, PropertyGetter(typeof(TimedWave), nameof(TimedWave.Base))),
new(OpCodes.Starg_S, 0),

// WaveSpawner.SpawnQueue = ev.SpawnQueue;
new(OpCodes.Callvirt, PropertyGetter(typeof(RespawningTeamEventArgs), nameof(RespawningTeamEventArgs.SpawnQueue))),
new(OpCodes.Stsfld, Field(typeof(WaveSpawner), nameof(WaveSpawner.SpawnQueue))),
});

// remove "wave.PopulateQueue(WaveSpawner.SpawnQueue, num);"
offset = -3;
index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(SpawnableWaveBase), nameof(SpawnableWaveBase.PopulateQueue)))) + offset;
List<Label> extractLabels = newInstructions[index].ExtractLabels();
newInstructions.RemoveRange(index, 4);
newInstructions[index].WithLabels(extractLabels);

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

Expand All @@ -109,12 +121,5 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
private static List<Player> GetPlayers(List<ReferenceHub> hubs) => hubs.Select(Player.Get).ToList();

private static List<ReferenceHub> GetHubs(List<Player> players) => players.Select(player => player.ReferenceHub).ToList();

private static void RefillQueue(Queue<RoleTypeId> newQueue)
{
WaveSpawner.SpawnQueue.Clear();
foreach (RoleTypeId role in newQueue)
WaveSpawner.SpawnQueue.Enqueue(role);
}
}
}
32 changes: 32 additions & 0 deletions EXILED/Exiled.Events/Patches/Fixes/ServerHubMicroHidFix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// -----------------------------------------------------------------------
// <copyright file="ServerHubMicroHidFix.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.Events.Patches.Fixes
{
#pragma warning disable SA1313
using API.Features.Items;
using Exiled.API.Features;

using HarmonyLib;

using InventorySystem.Items.Autosync;
using InventorySystem.Items.MicroHID.Modules;
using InventorySystem.Items.Pickups;
using InventorySystem.Items.Usables.Scp330;

/// <summary>
/// Patches <see cref="CycleSyncModule.Update()"/> to fix phantom <see cref="MicroHid"/> for <see cref="Item.Create(ItemType, API.Features.Player)"/>.
/// </summary>
[HarmonyPatch(typeof(CycleSyncModule), nameof(CycleSyncModule.Update))]
internal static class ServerHubMicroHidFix
{
private static bool Prefix(CycleSyncModule __instance)
{
return __instance.MicroHid.InstantiationStatus == AutosyncInstantiationStatus.InventoryInstance;
}
}
}
72 changes: 0 additions & 72 deletions EXILED/Exiled.Events/Patches/Fixes/ServerSideDancesPatch.cs

This file was deleted.

33 changes: 25 additions & 8 deletions EXILED/Exiled.Events/Patches/Generic/AmmoDrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Exiled.Events.Patches.Generic

using HarmonyLib;

using InventorySystem;
using InventorySystem.Items;
using InventorySystem.Items.Firearms;
using InventorySystem.Items.Firearms.Modules;
Expand Down Expand Up @@ -66,6 +67,22 @@ internal static IEnumerable<CodeInstruction> GetInstructions(LocalBuilder firear
yield return new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel);
}

/// <summary>
/// Calculates modified ammo limit.
/// </summary>
/// <param name="ammoLimit">Current ammo limit for reloading.</param>
/// <param name="ammoDrain">Target <see cref="API.Features.Items.Firearm.AmmoDrain"/>.</param>
/// <returns>Modified ammo limit for reloading.</returns>
internal static int GetAmmoDrainLimit(int ammoLimit, int ammoDrain)
{
if (ammoDrain == 0)
{
return int.MaxValue;
}

return ammoLimit / ammoDrain;
}

// that patch for open bolted firearms
[HarmonyPatch(nameof(AutomaticActionModule.ServerShoot))]
[HarmonyTranspiler]
Expand All @@ -89,7 +106,7 @@ private static IEnumerable<CodeInstruction> First(IEnumerable<CodeInstruction> c
newInstructions.InsertRange(index, new CodeInstruction[]
{
new(OpCodes.Ldloc_S, ammoDrain.LocalIndex),
new(OpCodes.Div),
new(OpCodes.Call, Method(typeof(AmmoDrainAutomatic), nameof(AmmoDrainAutomatic.GetAmmoDrainLimit))),
});

offset = 0;
Expand Down Expand Up @@ -131,7 +148,7 @@ private static IEnumerable<CodeInstruction> Second(IEnumerable<CodeInstruction>
newInstructions.InsertRange(index, new CodeInstruction[]
{
new(OpCodes.Ldloc_S, ammoDrain.LocalIndex),
new(OpCodes.Div),
new(OpCodes.Call, Method(typeof(AmmoDrainAutomatic), nameof(AmmoDrainAutomatic.GetAmmoDrainLimit))),
});

offset = 0;
Expand Down Expand Up @@ -177,7 +194,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
newInstructions.InsertRange(index, new CodeInstruction[]
{
new(OpCodes.Ldloc_S, ammoDrain.LocalIndex),
new(OpCodes.Div),
new(OpCodes.Call, Method(typeof(AmmoDrainAutomatic), nameof(AmmoDrainAutomatic.GetAmmoDrainLimit))),
});

offset = 0;
Expand All @@ -200,7 +217,7 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
/// <summary>
/// Patch for adding <see cref="API.Features.Items.Firearm.AmmoDrain"/> support for revolvers.
/// </summary>
[HarmonyPatch(typeof(RevolverClipReloaderModule), nameof(RevolverClipReloaderModule.InsertAmmoFromClip))]
[HarmonyPatch(typeof(RevolverClipReloaderModule), nameof(RevolverClipReloaderModule.ServerWithholdAmmo))]
internal class AmmoDrainRevolver
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> codeInstructions, ILGenerator generator)
Expand All @@ -224,17 +241,17 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
newInstructions.InsertRange(index, new CodeInstruction[]
{
new(OpCodes.Ldloc_S, ammoDrain.LocalIndex),
new(OpCodes.Mul),
new(OpCodes.Call, Method(typeof(AmmoDrainAutomatic), nameof(AmmoDrainAutomatic.GetAmmoDrainLimit))),
});

offset = 0;
index = newInstructions.FindIndex(i => i.Calls(Method(typeof(IPrimaryAmmoContainerModule), nameof(IPrimaryAmmoContainerModule.ServerModifyAmmo)))) + offset;
index = newInstructions.FindIndex(i => i.Calls(Method(typeof(InventoryExtensions), nameof(InventoryExtensions.ServerAddAmmo)))) + offset;

// and divide ammo that are inserting in magazine, to implement AmmoDrain
// and multiply ammo that are inserting in magazine, to implement AmmoDrain
newInstructions.InsertRange(index, new CodeInstruction[]
{
new(OpCodes.Ldloc_S, ammoDrain.LocalIndex),
new(OpCodes.Div),
new(OpCodes.Mul),
});

for (int z = 0; z < newInstructions.Count; z++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Exiled.Events.Patches.Generic
{
using Exiled.API.Features;
#pragma warning disable SA1313
#pragma warning disable SA1402

using HarmonyLib;

Expand Down
Loading

0 comments on commit 1452e13

Please sign in to comment.