Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
fixed config and added some other things.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakuliv committed Oct 27, 2021
1 parent 5ffc46a commit 80a6c3f
Show file tree
Hide file tree
Showing 27 changed files with 237 additions and 34 deletions.
Binary file modified .vs/Sapiox/v16/.suo
Binary file not shown.
1 change: 1 addition & 0 deletions Fedora.Example/Fedora.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="SpawnFakePlayer.cs" />
<Compile Include="SpawnWorkStation.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
17 changes: 3 additions & 14 deletions Fedora.Example/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using MEC;
using Sapiox.API;
using Sapiox.Events.EventArgs;
using System;
using System.Collections.Generic;
using UnityEngine;
using PlayerEvent = Sapiox.Events.Handlers.Player;

Expand All @@ -20,11 +22,11 @@ public override void Load()
{
base.Load();
Server.RegisterRemoteAdminCommand(new ExampleCommand());
Server.RegisterRemoteAdminCommand(new SpawnFakePlayer());
PlayerEvent.Join += OnPlayerJoin;
PlayerEvent.Leave += OnPlayerLeave;
PlayerEvent.Ban += OnPlayerBan;
PlayerEvent.Kick += OnPlayerKick;
Sapiox.Events.Handlers.Round.Start += OnRoundStart;
}

public void OnPlayerBan(PlayerBanEventArgs ev)
Expand All @@ -44,18 +46,5 @@ public void OnPlayerJoin(PlayerJoinEventArgs ev)
{
Log.Info($"Player {ev.NickName} has joined the server!");
}

public void OnRoundStart()
{
foreach (Player ply in Server.Players)
{
Timing.CallDelayed(5f, () =>
{
Log.Info("debug 1");
FakePlayer fp = new FakePlayer(ply.Position);
Log.Info("debug 2");
});
}
}
}
}
57 changes: 57 additions & 0 deletions Fedora.Example/SpawnFakePlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using CommandSystem;
using MEC;
using Sapiox.API;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Sapiox.Example
{
public class SpawnFakePlayer : ICommand
{
public string Command { get; } = "SpawnFakePlayer";

public string[] Aliases { get; } = new string[] { "spawnfakeplayer", "spawnfp", "spfakeplayer" };

public string Description { get; } = "Spawn fake player.";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Player player = Server.GetPlayer(sender);
var fp = new FakePlayer(player.Position, new Quaternion());
Timing.RunCoroutine(Walk(player, fp));
response = $"Spawned FakePlayer following the {player.NickName} !";
return true;
}

private IEnumerator<float> Walk(Player _dood, FakePlayer _dummy)
{
for (; ; )
{
yield return Timing.WaitForSeconds(0.1f);
try
{
if (_dood == null)
{
_dummy.DeSpawn();
continue;
}
_dummy.MoveState = PlayerMovementState.Walking;
_dummy.MoveDirection = Sapiox.API.Enum.MovementDirection.Forward;
_dummy.RotateToPosition(_dood.Position);
float distance = Vector3.Distance(_dood.Position, _dummy.Position);

if (distance <= 1.25f)
_dummy.MoveDirection = Sapiox.API.Enum.MovementDirection.None;
}
catch (Exception e)
{
Log.Error($"Error:\n{e}");
}
}
}
}
}
Binary file modified Fedora.Example/bin/Debug/CommandSystem.Core.dll
Binary file not shown.
Binary file modified Fedora.Example/bin/Debug/Sapiox.Example.dll
Binary file not shown.
Binary file modified Fedora.Example/bin/Debug/Sapiox.Example.pdb
Binary file not shown.
Binary file modified Fedora.Example/bin/Debug/Sapiox.dll
Binary file not shown.
Binary file modified Fedora.Example/bin/Debug/Sapiox.pdb
Binary file not shown.
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a03778d4e2a25d28745b492e7993b8b9ad8913c4
f05195ac0acd94a70140d7d38357d4e7012edb8b
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ C:\Users\CCWAN\source\repos\Cwaniaak\Sapiox\Fedora.Example\bin\Debug\Newtonsoft.
C:\Users\CCWAN\source\repos\Cwaniaak\Sapiox\Fedora.Example\obj\Debug\Fedora.Example.csproj.AssemblyReference.cache
C:\Users\CCWAN\source\repos\Cwaniaak\Sapiox\Fedora.Example\obj\Debug\Sapiox.Example.dll
C:\Users\CCWAN\source\repos\Cwaniaak\Sapiox\Fedora.Example\obj\Debug\Sapiox.Example.pdb
C:\Users\CCWAN\source\repos\Cwaniaak\Sapiox\Fedora.Example\obj\Debug\Fedora.Example.csproj.CopyComplete
Binary file modified Fedora.Example/obj/Debug/Sapiox.Example.dll
Binary file not shown.
Binary file modified Fedora.Example/obj/Debug/Sapiox.Example.pdb
Binary file not shown.
4 changes: 1 addition & 3 deletions Sapiox/API/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public static void Load()
{
foreach (IPlugin plugin in SapioxManager.Plugins)
{
if (!File.Exists(path)) File.Create(path);

Dictionary<string, object> rawConfigs = Deserializer.Deserialize<Dictionary<string, object>>(File.ReadAllText(path)) ?? new Dictionary<string, object>();
Dictionary<string, object> rawConfigs = Deserializer.Deserialize<Dictionary<string, object>>(File.Exists(path)?File.ReadAllText(path): " ") ?? new Dictionary<string, object>();

if (!rawConfigs.TryGetValue(plugin.Info.Name, out object rawConfig))
{
Expand Down
17 changes: 17 additions & 0 deletions Sapiox/API/Enum/MovementDirection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sapiox.API.Enum
{
public enum MovementDirection
{
Forward,
BackWards,
Right,
Left,
None
}
}
149 changes: 135 additions & 14 deletions Sapiox/API/FakePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using InventorySystem.Items.Firearms.Attachments;
using InventorySystem.Items.Firearms.BasicMessages;
using InventorySystem.Items.Firearms.Modules;
using MEC;
using Mirror;
using RemoteAdmin;
using Sapiox.API.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -18,8 +20,30 @@ public class FakePlayer
{
public Player Player { get; internal set; }
public GameObject GameObject { get; internal set; }
public string NickName => Player.Hub.nicknameSync.Network_myNickSync;
public RoleType Role => Player.Hub.characterClassManager.CurClass;
public MovementDirection MoveDirection { get; set; }
public float SneakSpeed { get; set; } = 1.8f;
public float WalkSpeed { get; set; }
public float RunSpeed { get; set; }

public PlayerMovementState MoveState
{
get => Player.Hub.animationController.MoveState;
set
{
Player.Hub.animationController.MoveState = value;
Player.Hub.animationController.RpcReceiveState((byte)value);
}
}
public string NickName
{
get => Player.Hub.nicknameSync.Network_myNickSync;
set => Player.Hub.nicknameSync.Network_myNickSync = value;
}
public RoleType Role
{
get => Player.Hub.characterClassManager.CurClass;
set => Player.Hub.characterClassManager.CurClass = value;
}
public Vector3 Position
{
get => Player.transform.position;
Expand All @@ -29,30 +53,50 @@ public Vector3 Position
Player.Hub.playerMovementSync.RealModelPosition = value;
}
}
public Vector3 Scale
{
get => Player.transform.localScale;
set => Player.transform.localScale = value;
}
public Vector2 Rotation
{
get => Player.Rotation;
set
{
Player.Rotation = value;
Player.Hub.PlayerCameraReference.rotation = Quaternion.Euler(new Vector3(value.x, value.y, 90f));
}
}
public void RotateToPosition(Vector3 pos)
{
var rot = Quaternion.LookRotation((pos - GameObject.transform.position).normalized);
Rotation = new Vector2(rot.eulerAngles.x, rot.eulerAngles.y);
}

public FakePlayer(Vector3 pos, RoleType role = RoleType.ClassD, string nickname = "FakePlayer", float health = 100, int maxHealth = 150, bool godmode = false)
public FakePlayer(Vector3 pos, Quaternion rot, RoleType role = RoleType.ClassD, string nickname = "FakePlayer", bool godmode = false)
{
try
{
GameObject obj = UnityEngine.Object.Instantiate(NetworkManager.singleton.playerPrefab);
GameObject = obj;

Player = Server.GetPlayer(GameObject);


Player.transform.localScale = Vector3.one;
Player.transform.position = pos;
Player.Hub.playerMovementSync.RealModelPosition = pos;
Scale = Vector3.one;
Position = pos;
Rotation = new Vector2(rot.eulerAngles.x, rot.eulerAngles.y);
Player.Hub.queryProcessor.NetworkPlayerId = QueryProcessor._idIterator;
Player.Hub.queryProcessor._ipAddress = Server.Host.IPAddress;
Player.Hub.characterClassManager.CurClass = role;
Player.Hub.nicknameSync.Network_myNickSync = nickname;
Role = role;
NickName = nickname;
Player.GodMode = godmode;
Player.Health = health;
Player.MaxHealth = maxHealth;
Player.Health = Player.MaxHealth;
Player.MaxHealth = Player.MaxHealth = Player.Hub.characterClassManager.Classes.SafeGet((int)Player.Role).maxHP;
Player.RankName = "Admin";
Player.RankColor = "red";
Player.Hub.playerMovementSync.NetworkGrounded = true;
RunSpeed = CharacterClassManager._staticClasses[(int)role].runSpeed;
WalkSpeed = CharacterClassManager._staticClasses[(int)role].walkSpeed;
Timing.RunCoroutine(Update());


NetworkServer.Spawn(GameObject);
Expand All @@ -78,11 +122,88 @@ public void Spawn()

public void DeSpawn()
{
NetworkServer.UnSpawn(GameObject);
UnityEngine.Object.Destroy(GameObject);
Server.FakePlayers.Remove(Player);
}
}

private IEnumerator<float> Update()
{
for (; ; )
{
yield return MEC.Timing.WaitForSeconds(0.1f);
try
{
if (GameObject == null) yield break;
if (MoveDirection == MovementDirection.None)
{
continue;
}

var wall = false;
var speed = 0f;

switch (MoveState)
{
case PlayerMovementState.Sneaking:
speed = SneakSpeed;
break;

case PlayerMovementState.Sprinting:
speed = RunSpeed * Server.SprintSpeed;
break;

case PlayerMovementState.Walking:
speed = WalkSpeed * Server.WalkSpeed;
break;
}

switch (MoveDirection)
{
case MovementDirection.Forward:
var pos = Position + Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.MovementSync.CollidableSurfaces))
Player.MovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.BackWards:
pos = Position - Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.MovementSync.CollidableSurfaces))
Player.MovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.Right:
pos = Position + Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.MovementSync.CollidableSurfaces))
Player.MovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;

case MovementDirection.Left:
pos = Position - Quaternion.AngleAxis(90, Vector3.up) * Player.CameraReference.forward / 10 * speed;

if (!Physics.Linecast(Position, pos, Player.MovementSync.CollidableSurfaces))
Player.MovementSync.OverridePosition(pos, 0f, true);
else wall = true;
break;
}

if (wall)
{
MoveDirection = MovementDirection.None;
}
}
catch (Exception e)
{
Log.Error($"FakePlayer Update Failed:\n{e}");
}
}
}
}
//patches

[HarmonyPatch(typeof(PlayerMovementSync), nameof(PlayerMovementSync.OverridePosition))]
Expand Down
8 changes: 8 additions & 0 deletions Sapiox/API/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public Vector3 Position
get => Hub.playerMovementSync.GetRealPosition();
set => Hub.playerMovementSync.OverridePosition(value, 0f);
}
public Vector2 Rotation
{
get => Hub.playerMovementSync.RotationSync;
set => Hub.playerMovementSync.NetworkRotationSync = value;
}

public Transform CameraReference => Hub.PlayerCameraReference;
public PlayerMovementSync MovementSync => Hub.playerMovementSync;

public bool IsUsingVoiceChat => Radio.UsingVoiceChat;

Expand Down
12 changes: 12 additions & 0 deletions Sapiox/API/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public static string Name
set => ServerConsole._serverName = value;
}

public static float WalkSpeed
{
get => ServerConfigSynchronizer.Singleton.NetworkHumanWalkSpeedMultiplier;
set => ServerConfigSynchronizer.Singleton.NetworkHumanWalkSpeedMultiplier = value;
}

public static float SprintSpeed
{
get => ServerConfigSynchronizer.Singleton.NetworkHumanSprintSpeedMultiplier;
set => ServerConfigSynchronizer.Singleton.NetworkHumanSprintSpeedMultiplier = value;
}

public static void SendDiscordWebhook(string token, string username, string content, string description = null,
bool embed = false, int embedColor = 65417, string embedTitle = null, string thumbnailUrl = null)
{
Expand Down
1 change: 1 addition & 0 deletions Sapiox/Sapiox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="API\Config.cs" />
<Compile Include="API\Enum\MovementDirection.cs" />
<Compile Include="API\FakePlayer.cs" />
<Compile Include="API\IConfig.cs" />
<Compile Include="API\Log.cs" />
Expand Down
Binary file modified Sapiox/bin/Debug/Assembly-CSharp-Publicized.dll
Binary file not shown.
Binary file modified Sapiox/bin/Debug/Sapiox.dll
Binary file not shown.
Binary file modified Sapiox/bin/Debug/Sapiox.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion Sapiox/obj/Debug/Sapiox.csproj.CoreCompileInputs.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8851858b32884f2e9be752b9d96054fc5c2664c8
f48e7dd588a0e5b78c24487c6dc4e85053f256b4
Binary file modified Sapiox/obj/Debug/Sapiox.dll
Binary file not shown.
Binary file modified Sapiox/obj/Debug/Sapiox.pdb
Binary file not shown.

0 comments on commit 80a6c3f

Please sign in to comment.