Skip to content

Commit a4348e0

Browse files
authored
Merge pull request #3 from ExMod-Team/dev
Dev
2 parents a8999ca + cb8fbbe commit a4348e0

38 files changed

+977
-55
lines changed

EXILED/Exiled.API/Enums/ScenesType.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// -----------------------------------------------------------------------
2+
// <copyright file="ScenesType.cs" company="Exiled Team">
3+
// Copyright (c) Exiled Team. All rights reserved.
4+
// Licensed under the CC BY-SA 3.0 license.
5+
// </copyright>
6+
// -----------------------------------------------------------------------
7+
8+
namespace Exiled.API.Enums
9+
{
10+
/// <summary>
11+
/// Unique identifier for the different types of Scenes the client and server can load.
12+
/// </summary>
13+
public enum ScenesType
14+
{
15+
/// <summary>
16+
/// The facility itself.
17+
/// </summary>
18+
Facility,
19+
20+
/// <summary>
21+
/// The current main menu.
22+
/// ! Will cause crash when trying joining servers !
23+
/// </summary>
24+
NewMainMenu,
25+
26+
/// <summary>
27+
/// The old main menu.
28+
/// </summary>
29+
MainMenuRemastered,
30+
31+
/// <summary>
32+
/// The old server list.
33+
/// </summary>
34+
FastMenu,
35+
36+
/// <summary>
37+
/// The loading Screen.
38+
/// ! Will cause crash when trying joining servers !
39+
/// </summary>
40+
PreLoader,
41+
42+
/// <summary>
43+
/// A black menu before loading the <see cref="NewMainMenu"/>.
44+
/// </summary>
45+
Loader,
46+
}
47+
}

EXILED/Exiled.API/Extensions/MirrorExtensions.cs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Exiled.API.Extensions
1515
using System.Reflection.Emit;
1616
using System.Text;
1717

18+
using Exiled.API.Enums;
1819
using Features;
1920
using Features.Pools;
2021

@@ -355,6 +356,111 @@ public static void MessageTranslated(this Player player, string words, string tr
355356
}
356357
}
357358

359+
/// <summary>
360+
/// Moves object for the player.
361+
/// </summary>
362+
/// <param name="player">Target to send.</param>
363+
/// <param name="identity">The <see cref="Mirror.NetworkIdentity"/> to move.</param>
364+
/// <param name="pos">The position to change.</param>
365+
public static void MoveNetworkIdentityObject(this Player player, NetworkIdentity identity, Vector3 pos)
366+
{
367+
identity.gameObject.transform.position = pos;
368+
ObjectDestroyMessage objectDestroyMessage = new()
369+
{
370+
netId = identity.netId,
371+
};
372+
373+
player.Connection.Send(objectDestroyMessage, 0);
374+
SendSpawnMessageMethodInfo?.Invoke(null, new object[] { identity, player.Connection });
375+
}
376+
377+
/// <summary>
378+
/// Sends to the player a Fake Change Scene.
379+
/// </summary>
380+
/// <param name="player">The player to send the Scene.</param>
381+
/// <param name="newSceneName">The new Scene the client will load.</param>
382+
public static void SendFakeSceneLoading(this Player player, ScenesType newSceneName)
383+
{
384+
SceneMessage message = new()
385+
{
386+
sceneName = newSceneName.ToString(),
387+
};
388+
389+
player.Connection.Send(message);
390+
}
391+
392+
/// <summary>
393+
/// Emulation of the method SCP:SL uses to change scene.
394+
/// </summary>
395+
/// <param name="scene">The new Scene the client will load.</param>
396+
public static void ChangeSceneToAllClients(ScenesType scene)
397+
{
398+
SceneMessage message = new()
399+
{
400+
sceneName = scene.ToString(),
401+
};
402+
403+
NetworkServer.SendToAll(message);
404+
}
405+
406+
/// <summary>
407+
/// Scales an object for the specified player.
408+
/// </summary>
409+
/// <param name="player">Target to send.</param>
410+
/// <param name="identity">The <see cref="Mirror.NetworkIdentity"/> to scale.</param>
411+
/// <param name="scale">The scale the object needs to be set to.</param>
412+
public static void ScaleNetworkIdentityObject(this Player player, NetworkIdentity identity, Vector3 scale)
413+
{
414+
identity.gameObject.transform.localScale = scale;
415+
ObjectDestroyMessage objectDestroyMessage = new()
416+
{
417+
netId = identity.netId,
418+
};
419+
420+
player.Connection.Send(objectDestroyMessage, 0);
421+
SendSpawnMessageMethodInfo?.Invoke(null, new object[] { identity, player.Connection });
422+
}
423+
424+
/// <summary>
425+
/// Moves object for all the players.
426+
/// </summary>
427+
/// <param name="identity">The <see cref="NetworkIdentity"/> to move.</param>
428+
/// <param name="pos">The position to change.</param>
429+
public static void MoveNetworkIdentityObject(this NetworkIdentity identity, Vector3 pos)
430+
{
431+
identity.gameObject.transform.position = pos;
432+
ObjectDestroyMessage objectDestroyMessage = new()
433+
{
434+
netId = identity.netId,
435+
};
436+
437+
foreach (Player ply in Player.List)
438+
{
439+
ply.Connection.Send(objectDestroyMessage, 0);
440+
SendSpawnMessageMethodInfo?.Invoke(null, new object[] { identity, ply.Connection });
441+
}
442+
}
443+
444+
/// <summary>
445+
/// Scales an object for all players.
446+
/// </summary>
447+
/// <param name="identity">The <see cref="Mirror.NetworkIdentity"/> to scale.</param>
448+
/// <param name="scale">The scale the object needs to be set to.</param>
449+
public static void ScaleNetworkIdentityObject(this NetworkIdentity identity, Vector3 scale)
450+
{
451+
identity.gameObject.transform.localScale = scale;
452+
ObjectDestroyMessage objectDestroyMessage = new()
453+
{
454+
netId = identity.netId,
455+
};
456+
457+
foreach (Player ply in Player.List)
458+
{
459+
ply.Connection.Send(objectDestroyMessage, 0);
460+
SendSpawnMessageMethodInfo?.Invoke(null, new object[] { identity, ply.Connection });
461+
}
462+
}
463+
358464
/// <summary>
359465
/// Send fake values to client's <see cref="SyncVarAttribute"/>.
360466
/// </summary>
@@ -363,6 +469,7 @@ public static void MessageTranslated(this Player player, string words, string tr
363469
/// <param name="targetType"><see cref="NetworkBehaviour"/>'s type.</param>
364470
/// <param name="propertyName">Property name starting with Network.</param>
365471
/// <param name="value">Value of send to target.</param>
472+
[Obsolete("Use overload with type-template instead.")]
366473
public static void SendFakeSyncVar(this Player target, NetworkIdentity behaviorOwner, Type targetType, string propertyName, object value)
367474
{
368475
if (!target.IsConnected)
@@ -386,6 +493,38 @@ void CustomSyncVarGenerator(NetworkWriter targetWriter)
386493
}
387494
}
388495

496+
/// <summary>
497+
/// Send fake values to client's <see cref="SyncVarAttribute"/>.
498+
/// </summary>
499+
/// <typeparam name="T">Target SyncVar property type.</typeparam>
500+
/// <param name="target">Target to send.</param>
501+
/// <param name="behaviorOwner"><see cref="NetworkIdentity"/> of object that owns <see cref="NetworkBehaviour"/>.</param>
502+
/// <param name="targetType"><see cref="NetworkBehaviour"/>'s type.</param>
503+
/// <param name="propertyName">Property name starting with Network.</param>
504+
/// <param name="value">Value of send to target.</param>
505+
public static void SendFakeSyncVar<T>(this Player target, NetworkIdentity behaviorOwner, Type targetType, string propertyName, T value)
506+
{
507+
if (!target.IsConnected)
508+
return;
509+
510+
NetworkWriterPooled writer = NetworkWriterPool.Get();
511+
NetworkWriterPooled writer2 = NetworkWriterPool.Get();
512+
MakeCustomSyncWriter(behaviorOwner, targetType, null, CustomSyncVarGenerator, writer, writer2);
513+
target.Connection.Send(new EntityStateMessage
514+
{
515+
netId = behaviorOwner.netId,
516+
payload = writer.ToArraySegment(),
517+
});
518+
519+
NetworkWriterPool.Return(writer);
520+
NetworkWriterPool.Return(writer2);
521+
void CustomSyncVarGenerator(NetworkWriter targetWriter)
522+
{
523+
targetWriter.WriteULong(SyncVarDirtyBits[$"{targetType.Name}.{propertyName}"]);
524+
WriterExtensions[typeof(T)]?.Invoke(null, new object[2] { targetWriter, value });
525+
}
526+
}
527+
389528
/// <summary>
390529
/// Force resync to client's <see cref="SyncVarAttribute"/>.
391530
/// </summary>

EXILED/Exiled.API/Features/Items/Armor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ namespace Exiled.API.Features.Items
1515
using Exiled.API.Interfaces;
1616

1717
using InventorySystem.Items.Armor;
18-
1918
using PlayerRoles;
2019

2120
using Structs;
@@ -110,6 +109,11 @@ public float StaminaUseMultiplier
110109
set => Base._staminaUseMultiplier = value;
111110
}
112111

112+
/// <summary>
113+
/// Gets or sets the stamina regen multiplier.
114+
/// </summary>
115+
public float StaminaRegenMultiplier { get; set; } = 1f;
116+
113117
/// <summary>
114118
/// Gets or sets how much the users movement speed should be affected when wearing this armor. (higher values = slower movement).
115119
/// </summary>
@@ -153,6 +157,7 @@ public IEnumerable<BodyArmor.ArmorCategoryLimitModifier> CategoryLimits
153157
StaminaUseMultiplier = StaminaUseMultiplier,
154158
RemoveExcessOnDrop = RemoveExcessOnDrop,
155159
CategoryLimits = CategoryLimits,
160+
StaminaRegenMultiplier = StaminaRegenMultiplier,
156161
AmmoLimits = AmmoLimits,
157162
VestEfficacy = VestEfficacy,
158163
HelmetEfficacy = HelmetEfficacy,
@@ -168,6 +173,7 @@ internal override void ReadPickupInfo(Pickup pickup)
168173
VestEfficacy = armorPickup.VestEfficacy;
169174
RemoveExcessOnDrop = armorPickup.RemoveExcessOnDrop;
170175
StaminaUseMultiplier = armorPickup.StaminaUseMultiplier;
176+
StaminaRegenMultiplier = armorPickup.StaminaRegenMultiplier;
171177
AmmoLimits = armorPickup.AmmoLimits;
172178
CategoryLimits = armorPickup.CategoryLimits;
173179
}

EXILED/Exiled.API/Features/Map.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public static class Map
5454

5555
private static AmbientSoundPlayer ambientSoundPlayer;
5656

57+
private static SqueakSpawner squeakSpawner;
58+
5759
/// <summary>
5860
/// Gets the tantrum prefab.
5961
/// </summary>
@@ -104,11 +106,28 @@ public static int Seed
104106
}
105107
}
106108

109+
/// <summary>
110+
/// Gets or sets a value indicating whether decontamination is enabled.
111+
/// </summary>
112+
public static bool IsDecontaminationEnabled
113+
{
114+
get => DecontaminationController.Singleton.NetworkDecontaminationOverride == DecontaminationController.DecontaminationStatus.None;
115+
set =>
116+
DecontaminationController.Singleton.NetworkDecontaminationOverride = value
117+
? DecontaminationController.DecontaminationStatus.None
118+
: DecontaminationController.DecontaminationStatus.Disabled;
119+
}
120+
107121
/// <summary>
108122
/// Gets the <see cref="global::AmbientSoundPlayer"/>.
109123
/// </summary>
110124
public static AmbientSoundPlayer AmbientSoundPlayer => ambientSoundPlayer ??= ReferenceHub.HostHub.GetComponent<AmbientSoundPlayer>();
111125

126+
/// <summary>
127+
/// Gets the <see cref="global::SqueakSpawner"/>.
128+
/// </summary>
129+
public static SqueakSpawner SqueakSpawner => squeakSpawner ??= Object.FindObjectOfType<SqueakSpawner>();
130+
112131
/// <summary>
113132
/// Broadcasts a message to all <see cref="Player">players</see>.
114133
/// </summary>
@@ -152,7 +171,7 @@ public static void ShowHint(string message, float duration = 3f)
152171
public static void ClearBroadcasts() => Server.Broadcast.RpcClearElements();
153172

154173
/// <summary>
155-
/// Starts the light containment zone decontamination process.
174+
/// Forces the light containment zone decontamination process.
156175
/// </summary>
157176
public static void StartDecontamination() => DecontaminationController.Singleton.ForceDecontamination();
158177

@@ -362,6 +381,19 @@ public static void PlayGunSound(Vector3 position, ItemType firearmType, byte max
362381
msg.SendToAuthenticated();
363382
}
364383

384+
/// <summary>
385+
/// Spawns mice inside the <see cref="RoomType.EzShelter"/>.
386+
/// </summary>
387+
/// <param name="mice">The type of mice you want to spawn..</param>
388+
public static void SpawnMice(byte mice = 1)
389+
{
390+
if (mice > SqueakSpawner.mice.Length)
391+
throw new ArgumentOutOfRangeException($"Mouse type must be between 1 and {SqueakSpawner.mice.Length}.");
392+
393+
SqueakSpawner.NetworksyncSpawn = mice;
394+
SqueakSpawner.SyncMouseSpawn(0, SqueakSpawner.NetworksyncSpawn);
395+
}
396+
365397
/// <summary>
366398
/// Clears the lazy loading game object cache.
367399
/// </summary>

EXILED/Exiled.API/Features/Pickups/BodyArmorPickup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public int VestEfficacy
9898
/// </summary>
9999
public float StaminaUseMultiplier { get; set; }
100100

101+
/// <summary>
102+
/// Gets or sets the stamina regen multiplier.
103+
/// </summary>
104+
public float StaminaRegenMultiplier { get; set; }
105+
101106
/// <summary>
102107
/// Gets how much the users movement speed should be affected when wearing this armor. (higher values = slower movement).
103108
/// </summary>
@@ -129,6 +134,7 @@ internal override void ReadItemInfo(Item item)
129134
vestEfficacy = armoritem.VestEfficacy;
130135
RemoveExcessOnDrop = armoritem.RemoveExcessOnDrop;
131136
StaminaUseMultiplier = armoritem.StaminaUseMultiplier;
137+
StaminaRegenMultiplier = armoritem.StaminaRegenMultiplier;
132138
AmmoLimits = armoritem.AmmoLimits;
133139
CategoryLimits = armoritem.CategoryLimits;
134140
}
@@ -144,6 +150,7 @@ protected override void InitializeProperties(ItemBase itemBase)
144150
vestEfficacy = armoritem.VestEfficacy;
145151
RemoveExcessOnDrop = !armoritem.DontRemoveExcessOnDrop;
146152
StaminaUseMultiplier = armoritem._staminaUseMultiplier;
153+
StaminaRegenMultiplier = armoritem.StaminaRegenMultiplier;
147154
AmmoLimits = armoritem.AmmoLimits.Select(limit => (ArmorAmmoLimit)limit);
148155
CategoryLimits = armoritem.CategoryLimits;
149156
}

EXILED/Exiled.API/Features/Pickups/Pickup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ internal Pickup(ItemType type)
133133
public PickupStandardPhysics PhysicsModule
134134
{
135135
get => Base.PhysicsModule as PickupStandardPhysics;
136+
[Obsolete("Unsafe.")]
136137
set
137138
{
138139
Base.PhysicsModule.DestroyModule();

0 commit comments

Comments
 (0)