Skip to content

Commit

Permalink
Merging from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
raulssorban committed Jul 23, 2024
2 parents 58a2bce + 01603e9 commit 67e5e4c
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 165 deletions.
131 changes: 0 additions & 131 deletions .github/workflows/client-build.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Compat
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.SDK
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Test
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Hooks/Carbon.Hooks.Base
17 changes: 7 additions & 10 deletions Carbon.Core/Carbon/src/Hooks/HookCallerInternal.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Carbon.Base;
using Carbon.Components;
using Carbon.Extensions;
using Carbon.Pooling;
using Facepunch;
using Oxide.Core.Plugins;
Expand All @@ -23,11 +21,8 @@ public class HookCallerInternal : HookCallerCommon
{
public override object[] AllocateBuffer(int count)
{
if (!_argumentBuffer.TryGetValue(count, out var pool))
{
_argumentBuffer.Add(count, pool = new HookArgPool(count, 15));
}

if (_argumentBuffer.TryGetValue(count, out var pool)) return pool.Take();
_argumentBuffer[count] = pool = new HookArgPool(count, 15);
return pool.Take();
}
public override object[] RescaleBuffer(object[] oldBuffer, int newScale, CachedHook hook)
Expand Down Expand Up @@ -86,10 +81,12 @@ public override void ProcessDefaults(object[] buffer, CachedHook hook)
}
public override void ReturnBuffer(object[] buffer)
{
if (_argumentBuffer.TryGetValue(buffer.Length, out var pool))
if (!_argumentBuffer.TryGetValue(buffer.Length, out var pool))
{
pool.Return(buffer);
_argumentBuffer[buffer.Length] = pool = new HookArgPool(buffer.Length, 15);
}

pool.Return(buffer);
}

public override object CallHook<T>(T hookable, uint hookId, BindingFlags flags, object[] args)
Expand Down Expand Up @@ -184,7 +181,7 @@ public override object CallHook<T>(T hookable, uint hookId, BindingFlags flags,
}
else
{
if (hookInstance.IsValid())
if (hookInstance != null && hookInstance.IsValid())
{
foreach (var cachedHook in hookInstance.Hooks)
{
Expand Down
6 changes: 3 additions & 3 deletions Carbon.Core/Carbon/src/Hooks/HookEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ public bool ApplyPatch()
try
{
if (_runtime.Prefix != null)
prefix = new HarmonyMethod(_runtime.Prefix);
prefix = new HarmonyMethod(_runtime.Prefix, Priority.VeryHigh);

if (_runtime.Postfix != null)
postfix = new HarmonyMethod(_runtime.Postfix);
postfix = new HarmonyMethod(_runtime.Postfix, Priority.VeryHigh);

if (_runtime.Transpiler != null)
transpiler = new HarmonyMethod(_runtime.Transpiler);
transpiler = new HarmonyMethod(_runtime.Transpiler, Priority.VeryHigh);

if (prefix is null && postfix is null && transpiler is null)
throw new Exception($"(prefix, postfix, transpiler not found");
Expand Down
38 changes: 26 additions & 12 deletions Carbon.Core/Carbon/src/Managers/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,25 +522,25 @@ private IEnumerable<HookEx> Hooks
{ get => _patches.Concat(_dynamicHooks).Concat(_staticHooks).Concat(_metadataHooks); }

private IEnumerable<HookEx> GetHookByName(string name)
=> LoadedHooks.Where(x => x.HookName.Equals(name, StringComparison.InvariantCulture)) ?? null;
=> LoadedHooks.Where(x => x.HookName.Equals(name)) ?? null;

private IEnumerable<HookEx> GetHookByFullName(string name)
=> LoadedHooks.Where(x => x.HookFullName.Equals(name, StringComparison.InvariantCulture)) ?? null;
=> LoadedHooks.Where(x => x.HookFullName.Equals(name)) ?? null;

private HookEx GetHookById(string identifier)
=> LoadedHooks.FirstOrDefault(x => x.Identifier.Equals(identifier, StringComparison.InvariantCulture)) ?? null;
=> LoadedHooks.FirstOrDefault(x => x.Identifier.Equals(identifier)) ?? null;

private IEnumerable<HookEx> GetHookByNameAll(string name)
=> Hooks.Where(x => x.HookName.Equals(name, StringComparison.InvariantCulture)) ?? null;
=> Hooks.Where(x => x.HookName.Equals(name)) ?? null;

private IEnumerable<HookEx> GetHookByFullNameAll(string name)
=> Hooks.Where(x => x.HookFullName.Equals(name, StringComparison.InvariantCulture)) ?? null;
=> Hooks.Where(x => x.HookFullName.Equals(name)) ?? null;

private HookEx GetHookByIdAll(string identifier)
=> Hooks.FirstOrDefault(x => x.Identifier.Equals(identifier, StringComparison.InvariantCulture)) ?? null;
=> Hooks.FirstOrDefault(x => x.Identifier.Equals(identifier)) ?? null;

internal bool IsHookLoaded(HookEx hook)
=> LoadedHooks.Any(x => x.HookFullName.Equals(hook.HookFullName, StringComparison.InvariantCulture) && x.TargetType == hook.TargetType && x.TargetMethod == hook.TargetMethod && (x.TargetMethodArgs?.SequenceEqual(hook.TargetMethodArgs) ?? true));
=> LoadedHooks.Any(x => x.HookFullName.Equals(hook.HookFullName) && x.TargetType == hook.TargetType && x.TargetMethod == hook.TargetMethod && (x.TargetMethodArgs?.SequenceEqual(hook.TargetMethodArgs) ?? true));

public bool IsHook(string hookName)
{
Expand Down Expand Up @@ -578,21 +578,20 @@ public IEnumerable<IHook> LoadedDynamicHooks
public IEnumerable<IHook> InstalledDynamicHooks
{ get => _dynamicHooks.Where(x => x.IsInstalled); }


private bool HookIsSubscribedBy(string identifier, string subscriber)
=> _subscribers?.Where(x => x.Identifier.Equals(identifier, StringComparison.InvariantCulture)).Any(x => x.Subscriber == subscriber) ?? false;
=> _subscribers?.Where(x => x.Identifier.Equals(identifier)).Any(x => x.Subscriber == subscriber) ?? false;

private bool HookHasSubscribers(string identifier)
=> _subscribers?.Any(x => x.Identifier.Equals(identifier, StringComparison.InvariantCulture)) ?? false;
=> _subscribers?.Any(x => x.Identifier.Equals(identifier)) ?? false;

public int GetHookSubscriberCount(string identifier)
=> _subscribers.Count(x => x.Identifier.Equals(identifier, StringComparison.InvariantCulture));
=> _subscribers.Count(x => x.Identifier.Equals(identifier));

private void AddSubscriber(string identifier, string subscriber)
=> _subscribers.Add(item: new Subscription { Identifier = identifier, Subscriber = subscriber });

private void RemoveSubscriber(string identifier, string subscriber)
=> _subscribers.RemoveAll(x => x.Identifier.Equals(identifier, StringComparison.InvariantCulture) && x.Subscriber.Equals(subscriber, StringComparison.InvariantCulture));
=> _subscribers.RemoveAll(x => x.Identifier.Equals(identifier) && x.Subscriber.Equals(subscriber));


public void Subscribe(string hookName, string requester)
Expand Down Expand Up @@ -661,6 +660,11 @@ private void Subscribe(HookEx hook, string requester)
}
}

public IEnumerable<string> GetHookSubscribers(string identifier)
{
return _subscribers.Where(x => x.Identifier.Equals(identifier)).Select(x => x.Subscriber);
}

public void Unsubscribe(string hookName, string requester)
{
try
Expand Down Expand Up @@ -721,6 +725,16 @@ private void Unsubscribe(HookEx hook, string requester)
}
}

public void UnsubscribeAll(string hookName)
{
var subscribers = GetHookSubscribers(hookName);

foreach (var subscriber in subscribers)
{
Unsubscribe(hookName, subscriber);
}
}

public static string GetMethodMSILHash(MethodInfo method)
=> SHA1(method?.GetMethodBody()?.GetILAsByteArray());

Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<a href="https://github.com/CarbonCommunity/Carbon/releases/tag/edge_build"><img src="https://github.com/CarbonCommunity/Carbon/actions/workflows/edge-build.yml/badge.svg" /></a>
<a href="https://github.com/CarbonCommunity/Carbon/releases/tag/preview_build"><img src="https://github.com/CarbonCommunity/Carbon/actions/workflows/preview-build.yml/badge.svg" /></a>
<a href="https://github.com/CarbonCommunity/Carbon/releases/latest"><img src="https://github.com/CarbonCommunity/Carbon/actions/workflows/production-build.yml/badge.svg" /></a>
<a href="https://github.com/CarbonCommunity/Carbon/releases/tag/client_build"><img src="https://github.com/CarbonCommunity/Carbon/actions/workflows/client-build.yml/badge.svg" /></a>
<br />
<a href="https://github.com/CarbonCommunity/Carbon/releases/tag/rustbeta_staging_build"><img src="https://github.com/CarbonCommunity/Carbon/actions/workflows/rust-staging-build.yml/badge.svg" /></a>
<a href="https://github.com/CarbonCommunity/Carbon/releases/tag/rustbeta_release_build"><img src="https://github.com/CarbonCommunity/Carbon/actions/workflows/rust-release-build.yml/badge.svg" /></a>
Expand Down Expand Up @@ -65,7 +64,6 @@ The following branches are shared across all Component and Hook projects and syn
- [Carbon.Preloader](https://github.com/CarbonCommunity/Carbon.Preloader/tree/develop): Runtime preloader of dependencies and responsible assembly patching (publicising, injecting, etc.).
- [Carbon.Bootstrap](https://github.com/CarbonCommunity/Carbon.Bootstrap/tree/develop): Initial Carbon execution and boot in the primary app-domain.
- [Carbon.Common](https://github.com/CarbonCommunity/Carbon.Common/tree/develop): The very basis of Carbon, tools and extensions for overall use and functionality. Primarily a center piece for all dependant sub-components.
- [Carbon.Common.Client](https://github.com/CarbonCommunity/Carbon.Common.Client/tree/develop): Represents a bundle of common features, patches and implementations for Carbon for client communication.
- [Carbon.SDK](https://github.com/CarbonCommunity/Carbon.SDK/tree/develop): Infrastructural and contractual features with no implementation. An easy way to identify and organise the structure of our systems.
- [Carbon.Modules](https://github.com/CarbonCommunity/Carbon.Modules/tree/develop): Carbon optional modules expanding functionality, enhanced QoL and tools.
- [Carbon.Compat](https://github.com/CarbonCommunity/Carbon.Compat/tree/develop): Previously known as Carbon Compatibility Loader written by Patrette (community member).
Expand Down

0 comments on commit 67e5e4c

Please sign in to comment.