Browse Source

Added player join/leave events and fix errors

- Fixed anticheat status error spam
- Fixed IMGUI not actually running on OnGUI because that runner was changed in Svelto
- Added player join and leave events
- Made Game.Enter only trigger when both the game has finished loading *and* the local player has joined
tags/v2.2.0
NorbiPeti 2 years ago
parent
commit
93a0b2287a
7 changed files with 90 additions and 15 deletions
  1. +1
    -0
      TechbloxModdingAPI/App/AntiAntiCheatPatch.cs
  2. +29
    -2
      TechbloxModdingAPI/App/GameGameEngine.cs
  3. +1
    -7
      TechbloxModdingAPI/Interface/IMGUI/IMGUIManager.cs
  4. +22
    -0
      TechbloxModdingAPI/Player.Events.cs
  5. +8
    -2
      TechbloxModdingAPI/Player.cs
  6. +13
    -4
      TechbloxModdingAPI/Players/PlayerEventsEngine.cs
  7. +16
    -0
      TechbloxModdingAPI/Tasks/OnGuiRunner.cs

+ 1
- 0
TechbloxModdingAPI/App/AntiAntiCheatPatch.cs View File

@@ -21,6 +21,7 @@ namespace TechbloxModdingAPI.App
harmony.Patch(AccessTools.Method(type, "StartProtectedSession"), new HarmonyMethod(((AntiAnticheatDelegate) AntiAntiCheat).Method));
harmony.Patch(AccessTools.Method(type, "StopProtectedSession"), new HarmonyMethod(((AntiAnticheatDelegateBool) AntiAntiCheat).Method));
harmony.Patch(AccessTools.Method("Techblox.Services.Eos.Anticheat.Client.EosGetPendingMessagesToSendServiceRequest:Execute"), new HarmonyMethod(((AntiAnticheatDelegateTask)AntiAntiCheatTask).Method));
harmony.Patch(AccessTools.Method("Techblox.Anticheat.Client.Engines.ShowFeedbackDialogEngine:PollAnticheatStatus"), new HarmonyMethod(((AntiAnticheatDelegateTask)AntiAntiCheatTask).Method));
}

private static bool AntiAntiCheat() => false;


+ 29
- 2
TechbloxModdingAPI/App/GameGameEngine.cs View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

using RobocraftX.Common;
using RobocraftX.Schedulers;
@@ -13,6 +14,7 @@ using Techblox.Environment.Transition;
using Techblox.GameSelection;
using TechbloxModdingAPI.Blocks;
using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Players;
using TechbloxModdingAPI.Utility;

namespace TechbloxModdingAPI.App
@@ -30,16 +32,32 @@ namespace TechbloxModdingAPI.App
public EntitiesDB entitiesDB { set; private get; }

private bool enteredGame;
private bool loadingFinished;
private bool playerJoined;

public void Dispose()
{
ExitGame.Invoke(this, new GameEventArgs { GameName = GetGameData().saveName, GamePath = GetGameData().gameID });
IsInGame = false;
loadingFinished = false;
playerJoined = false;
enteredGame = false;
}

public void Ready()
{
enteredGame = true;
Player.Joined += OnPlayerJoined;
}

private void OnPlayerJoined(object sender, PlayerEventArgs args)
{
Console.WriteLine("Player joined: " + args.PlayerId + " asd");
if (args.Player.Type != PlayerType.Local) return;
Console.WriteLine("Player joined is local asd");
playerJoined = true;
Player.Joined -= OnPlayerJoined;
CheckJoinEvent();
}

// game functionality
@@ -142,9 +160,18 @@ namespace TechbloxModdingAPI.App
public void Remove(ref LoadingActionEntityStruct entityComponent, EGID egid)
{ // Finished loading
if (!enteredGame) return;
enteredGame = false;
loadingFinished = true;
Console.WriteLine("Loading finished - asd");
CheckJoinEvent();
}

private void CheckJoinEvent()
{
Console.WriteLine($"Check: {loadingFinished} {playerJoined}");
if (!loadingFinished || !playerJoined) return;
EnterGame.Invoke(this, new GameEventArgs { GameName = GetGameData().saveName, GamePath = GetGameData().gameID });
IsInGame = true;
enteredGame = false;
}
}
}

+ 1
- 7
TechbloxModdingAPI/Interface/IMGUI/IMGUIManager.cs View File

@@ -1,13 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TechbloxModdingAPI.App;
using TechbloxModdingAPI.Utility;
using Rewired.Internal;
using Svelto.DataStructures;
using Svelto.Tasks;
using Svelto.Tasks.ExtraLean;
using Svelto.Tasks.ExtraLean.Unity;
using TechbloxModdingAPI.Tasks;
using UnityEngine;

namespace TechbloxModdingAPI.Interface.IMGUI


+ 22
- 0
TechbloxModdingAPI/Player.Events.cs View File

@@ -20,6 +20,22 @@ namespace TechbloxModdingAPI
add => seatExited += value;
remove => seatExited -= value;
}

internal static WrappedHandler<PlayerEventArgs> joined;
public static event EventHandler<PlayerEventArgs> Joined
{
add => joined += value;
remove => joined -= value;
}

internal static WrappedHandler<PlayerEventArgs> left;
public static event EventHandler<PlayerEventArgs> Left
{
add => left += value;
remove => left -= value;
}
}

public struct PlayerSeatEventArgs
@@ -27,4 +43,10 @@ namespace TechbloxModdingAPI
public EGID SeatId;
public Seat Seat => (Seat)Block.New(SeatId);
}

public struct PlayerEventArgs
{
public EGID PlayerId;
public Player Player => Player.GetInstance(PlayerId.entityID);
}
}

+ 8
- 2
TechbloxModdingAPI/Player.cs View File

@@ -23,8 +23,8 @@ namespace TechbloxModdingAPI
public partial class Player : EcsObjectBase, IEquatable<Player>, IEquatable<EGID>
{
// static functionality
private static PlayerEngine playerEngine = new PlayerEngine();
private static PlayerEventsEngine playerEventsEngine = new PlayerEventsEngine();
private static readonly PlayerEngine playerEngine = new PlayerEngine();
private static readonly PlayerEventsEngine playerEventsEngine = new PlayerEventsEngine();
private static Player localPlayer;

/// <summary>
@@ -76,6 +76,12 @@ namespace TechbloxModdingAPI
}
}

internal static Player GetInstance(uint id)
{
return EcsObjectBase.GetInstance(new EGID(id, CharacterExclusiveGroups.OnFootGroup),
e => new Player(e.entityID));
}

/// <summary>
/// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Player"/> class.
/// </summary>


+ 13
- 4
TechbloxModdingAPI/Players/PlayerEventsEngine.cs View File

@@ -1,13 +1,13 @@
using RobocraftX.Character;
using RobocraftX.Character.Movement;
using RobocraftX.Common.Input;
using Svelto.ECS;

using TechbloxModdingAPI.Engines;
using TechbloxModdingAPI.Utility;

namespace TechbloxModdingAPI.Players
{
public class PlayerEventsEngine : IApiEngine, IReactOnSwap<CharacterPilotSeatEntityStruct>
public class PlayerEventsEngine : IApiEngine, IReactOnSwap<CharacterPilotSeatEntityStruct>, IReactOnAddAndRemove<PlayerIDStruct>
{
public void Ready()
{
@@ -24,12 +24,21 @@ namespace TechbloxModdingAPI.Players
public void MovedTo(ref CharacterPilotSeatEntityStruct entityComponent, ExclusiveGroupStruct previousGroup, EGID egid)
{
entitiesDB.TryGetEGID(entityComponent.pilotSeatEntity, out var seatId); //TODO: Can't get EGID
var player = EcsObjectBase.GetInstance(new EGID(egid.entityID, CharacterExclusiveGroups.OnFootGroup),
e => new Player(e.entityID));
var player = Player.GetInstance(egid.entityID);
if (previousGroup == CharacterExclusiveGroups.InPilotSeatGroup)
player.seatExited.Invoke(this, new PlayerSeatEventArgs { SeatId = seatId});
else if (egid.groupID == CharacterExclusiveGroups.InPilotSeatGroup)
player.seatEntered.Invoke(this, new PlayerSeatEventArgs { SeatId = seatId });
}

public void Add(ref PlayerIDStruct entityComponent, EGID egid)
{
Player.joined.Invoke(this, new PlayerEventArgs { PlayerId = egid });
}

public void Remove(ref PlayerIDStruct entityComponent, EGID egid)
{
Player.left.Invoke(this, new PlayerEventArgs { PlayerId = egid });
}
}
}

+ 16
- 0
TechbloxModdingAPI/Tasks/OnGuiRunner.cs View File

@@ -0,0 +1,16 @@
using System.Collections;
using Svelto.Tasks;
using Svelto.Tasks.ExtraLean;
using Svelto.Tasks.Unity.Internal;

namespace TechbloxModdingAPI.Tasks
{
public class OnGuiRunner : BaseRunner<ExtraLeanSveltoTask<IEnumerator>>
{
public OnGuiRunner(string name, uint runningOrder = 0)
: base(name)
{
UnityCoroutineRunner.StartOnGuiCoroutine(this._processEnumerator, runningOrder);
}
}
}

Loading…
Cancel
Save