Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 14 additions & 6 deletions FloLib/Automation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FloLib.Attributes;
using FloLib.Events;
using GTFO.API;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static void RegisterTypes()
var targetAssem = new StackFrame(1).GetMethod()?.GetType()?.Assembly ?? null;
if (targetAssem == null)
throw new NullReferenceException("Caller Assembly was null");

RegisterTypes(targetAssem);
}

Expand Down Expand Up @@ -112,9 +113,11 @@ public static void RegisterTypes(Assembly target)

private static void InjectAll(Assembly assem)
{
var types = assem
.GetTypes()?
.Where(x=>Attribute.IsDefined(x, typeof(AutoInjectAttribute))) ?? Enumerable.Empty<Type>();
//var types = assem
// .GetTypes()?
// .Where(x=>Attribute.IsDefined(x, typeof(AutoInjectAttribute))) ?? Enumerable.Empty<Type>();
var types = AccessTools.GetTypesFromAssembly(assem)?
.Where(x => Attribute.IsDefined(x, typeof(AutoInjectAttribute))) ?? Enumerable.Empty<Type>();

foreach (var type in types)
{
Expand All @@ -136,13 +139,18 @@ private static void InjectAll(Assembly assem)

private static void AddAutoInvokes(Assembly assem)
{
var methods = assem
.GetTypes()?
var methods = AccessTools.GetTypesFromAssembly(assem)?
.SelectMany(x => x.GetMethods(ALL))?
.Where(x => x.IsStatic && Attribute.IsDefined(x, typeof(AutoInvokeAttribute))) ?? Enumerable.Empty<MethodInfo>();

//var methods = assem
// .GetTypes()?
// .SelectMany(x => x.GetMethods(ALL))?
// .Where(x => x.IsStatic && Attribute.IsDefined(x, typeof(AutoInvokeAttribute))) ?? Enumerable.Empty<MethodInfo>();

foreach (var method in methods)
{

var attribute = (AutoInvokeAttribute)Attribute.GetCustomAttribute(method, typeof(AutoInvokeAttribute));
var args = attribute.Arguments;
var when = attribute.When;
Expand Down
32 changes: 32 additions & 0 deletions FloLib/Networks/Inject/Inject_OnRecallDone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using HarmonyLib;
using SNetwork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FloLib.Networks.Inject
{
namespace FloLib.Networks.Inject
{
// Token: 0x02000038 RID: 56
[HarmonyPatch]
internal class Inject_OnRecallDone
{
// Token: 0x14000007 RID: 7
// (add) Token: 0x06000145 RID: 325 RVA: 0x000059A4 File Offset: 0x00003BA4
// (remove) Token: 0x06000146 RID: 326 RVA: 0x000059D8 File Offset: 0x00003BD8
public static event Action OnRecallDone;

// Token: 0x06000147 RID: 327 RVA: 0x00005A0B File Offset: 0x00003C0B
[HarmonyPostfix]
[HarmonyPatch(typeof(SNet_SyncManager), nameof(SNet_SyncManager.OnRecallDone))]
private static void Post_OnRecallDone(SNet_SyncManager __instance)
{
OnRecallDone?.Invoke();
}
}
}

}
25 changes: 24 additions & 1 deletion FloLib/Networks/Replications/ReplicatorHandshake.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using GTFO.API;
using FloLib.Networks.Inject.FloLib.Networks.Inject;
using GTFO.API;
using SNetwork;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -29,6 +31,27 @@ private ReplicatorHandshake(string eventName)
{
EventName = eventName;
NetworkAPI.RegisterEvent<Packet>(eventName, OnSyncAction);
Inject_OnRecallDone.OnRecallDone += delegate ()
{
Logger.Warn("ReplicatorHandshake: client sending sync request");
ClientSyncRequest();
};
}

private void ClientSyncRequest()
{
if (SNet.IsMaster)
{
return;
}
foreach(uint replicatorID in _Lookup.Keys)
{
NetworkAPI.InvokeEvent(this.EventName, new ReplicatorHandshake.Packet
{
replicatorID = replicatorID,
action = PacketAction.SyncRequest
}, SNet.Master, SNet_ChannelType.GameOrderCritical);
}
}

public void Reset()
Expand Down
6 changes: 5 additions & 1 deletion FloLib/Networks/Replications/StateReplicator.Static.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FloLib.Networks.Inject;
using FloLib.Networks.Inject.FloLib.Networks.Inject;
using FloLib.Networks.Replications;
using GTFO.API;
using SNetwork;
Expand Down Expand Up @@ -35,7 +36,8 @@ static StateReplicator()
StateSize = Marshal.SizeOf(typeof(S));
StateSizeType = StatePayloads.GetSizeType(StateSize);

using var md5 = MD5.Create();
using var md5 = MD5.Create(); // unused

HashName = UName.GetHash(typeof(S).FullName);
ClientRequestEventName = $"SRs{Name}-{HashName}";
HostSetStateEventName = $"SRr{Name}-{HashName}";
Expand All @@ -45,6 +47,8 @@ static StateReplicator()
_H_SetStateEvent = StatePayloads.CreateEvent<S>(StateSizeType, HostSetStateEventName, HostSetStateEventCallback);
_H_SetRecallStateEvent = StatePayloads.CreateEvent<S>(StateSizeType, HostSetRecallStateEventName, HostSetRecallStateEventCallback);
_Handshake = ReplicatorHandshake.Create($"{Name}-{HashName}");


_Handshake.OnClientSyncRequested += ClientSyncRequested;

Inject_SNet_Capture.OnBufferCapture += BufferStored;
Expand Down