Skip to content

Commit

Permalink
Merging from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
raulssorban committed Mar 7, 2024
2 parents c6a58d2 + 7895028 commit e03df31
Show file tree
Hide file tree
Showing 25 changed files with 86 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Carbon.Core/.msbuild/Protocol.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
carbon that forces the users to update all the compontents at the
same time, like updating core and hooks in one shot.
-->
<CarbonProtocol>2024.02.01.0</CarbonProtocol>
<CarbonProtocol>2024.03.07.0</CarbonProtocol>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions Carbon.Core/.msbuild/References.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<Reference Include="System.Xml" />
<Reference Include="System" />

<PackageReference Include="Lib.Harmony" Version="2.3.1.1" />

<!-- Carbon API -->
<ProjectReference Include="$(SolutionDir)\Carbon.Components\Carbon.SDK\Carbon.SDK.csproj" Private="false" Condition="!$(Product.Contains('Carbon.SDK')) and !$(Product.Contains('Carbon.Compiler'))" />

Expand Down
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Client
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Common
Submodule Carbon.Common updated 42 files
+1 −1 Carbon.Common.csproj
+8 −3 src/Base/BaseHookable.cs
+8 −3 src/Base/BaseModule.cs
+2 −1 src/Base/IModule.cs
+146 −0 src/Carbon/Components/Analytics.Metrics.cs
+7 −3 src/Carbon/Components/Analytics.cs
+54 −34 src/Carbon/Components/CUI.cs
+1 −7 src/Carbon/Components/Client.cs
+2 −2 src/Carbon/Components/ClientEntity.cs
+3 −3 src/Carbon/Components/FileLogger.cs
+1 −30 src/Carbon/Components/HookCaller.cs
+3 −3 src/Carbon/Components/Logger.cs
+50 −23 src/Carbon/Config.cs
+5 −5 src/Carbon/Core/Core.Commands.Conditionals.cs
+15 −15 src/Carbon/Core/Core.Commands.Config.cs
+1 −1 src/Carbon/Core/Core.Commands.Debugging.cs
+1 −1 src/Carbon/Core/Core.Commands.Modules.cs
+2 −2 src/Carbon/Core/Core.Commands.Permission.cs
+32 −7 src/Carbon/Core/Core.Hooks.Commands.cs
+15 −10 src/Carbon/Core/Core.Hooks.Connection.cs
+4 −4 src/Carbon/Core/Core.Hooks.Entity.cs
+1 −1 src/Carbon/Core/Core.Hooks.Item.cs
+1 −1 src/Carbon/Core/Core.Hooks.NPC.cs
+5 −4 src/Carbon/Core/Core.Hooks.Player.cs
+8 −17 src/Carbon/Core/Core.Hooks.cs
+4 −4 src/Carbon/Core/Core.Plugin.cs
+3 −3 src/Carbon/Defines.cs
+10 −30 src/Carbon/ModLoader.cs
+7 −6 src/Carbon/Modules/AdminModule/AdminModule.Patches.IValidDismountPosition.cs
+25 −25 src/Carbon/Modules/AdminModule/AdminModule.Tabs.Carbon.cs
+6 −3 src/Carbon/Modules/AdminModule/AdminModule.Tabs.Entities.cs
+46 −2 src/Carbon/Modules/AdminModule/AdminModule.Tabs.Permissions.cs
+7 −4 src/Carbon/Modules/AdminModule/AdminModule.Tabs.Players.cs
+7 −10 src/Carbon/Modules/AdminModule/AdminModule.cs
+14 −4 src/Carbon/Modules/ImageDatabaseModule/ImageDatabaseModule.cs
+12 −3 src/Carbon/Oxide Overrides/PermissionStoreless.cs
+10 −24 src/CommunityCommon.cs
+1 −1 src/Oxide/Command.cs
+17 −8 src/Oxide/Libraries/Permissions.cs
+1 −1 src/Oxide/OxideMod.cs
+8 −9 src/Oxide/Plugin.cs
+1 −1 src/Oxide/RustPlugin.cs
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Common.Client
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Compat
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Components/Carbon.Preloader
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon.Hooks/Carbon.Hooks.Oxide
5 changes: 4 additions & 1 deletion Carbon.Core/Carbon/Carbon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
<Import Project="$(SolutionDir)\.msbuild\AssemblyName.props" />

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
<PackageReference Include="MonoMod.Backports" Version="1.1.0" />
<PackageReference Include="MonoMod.Core" Version="1.1.0" />
<PackageReference Include="MonoMod.Utils" Version="25.0.4" />
<ProjectReference Include="$(SolutionDir)\Carbon.Components\Carbon.Common\Carbon.Common.csproj" Private="false" />
<ProjectReference Include="$(SolutionDir)\Carbon.Components\Carbon.Common.Client\Carbon.Common.Client.csproj" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion Carbon.Core/Carbon/src/Community.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public override void Initialize()

if (IsInitialized) return;

Compat.Init();

HookCaller.Caller = new HookCallerInternal();

LoadConfig();
Expand Down Expand Up @@ -219,7 +221,7 @@ public override void Uninitialize()
#if WIN
try
{
if (IsConfigReady && Config.ShowConsoleInfo && ServerConsole.Instance != null && ServerConsole.Instance.input != null)
if (IsConfigReady && Config.Misc.ShowConsoleInfo && ServerConsole.Instance != null && ServerConsole.Instance.input != null)
{
ServerConsole.Instance.input.statusText = new string[3];
}
Expand Down
42 changes: 12 additions & 30 deletions Carbon.Core/Carbon/src/Hooks/HookCallerInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,7 @@ public override object CallHook<T>(T hookable, uint hookId, BindingFlags flags,

Carbon.Logger.Warn($" {hookable.Name} hook '{readableHook}' took longer than 100ms [{afterHookTime:0}ms]{(hookable.HasGCCollected ? " [GC]" : string.Empty)}");

if (Analytic.Enabled)
{
Analytic.Include("name",
$"{readableHook} ({basePlugin.Name} v{basePlugin.Version} by {basePlugin.Author})");
Analytic.Include("time", $"{afterHookTime.RoundUpToNearestCount(50)}ms");
Analytic.Include("memory", $"{ByteEx.Format(totalMemory, shortName: true).ToLower()}");
Analytic.Include("fires", $"{cachedHook.TimesFired}");
Analytic.Include("hasgc", hookable.HasGCCollected);
Analytic.Send("plugin_time_warn");
}
Analytics.plugin_time_warn(readableHook, basePlugin, afterHookTime, totalMemory, cachedHook, hookable);
}

HookCaller.ConflictCheck(conflicts, ref result, hookId);
Expand Down Expand Up @@ -236,24 +227,24 @@ public override object CallHook<T>(T hookable, uint hookId, BindingFlags flags,
HookCaller.ConflictCheck(conflicts, ref result, hookId);
FrameDispose(false, args, ref conflicts);

static object DoCall(T hookable, uint hookId, CachedHook hook, object[] args, ref bool hasRescaledBuffer)
static object DoCall(T hookable, uint hookId, CachedHook cachedHook, object[] args, ref bool hasRescaledBuffer)
{
if (args != null)
{
var actualLength = hook.Parameters.Length;
var actualLength = cachedHook.Parameters.Length;

if (actualLength != args.Length)
{
args = HookCaller.Caller.RescaleBuffer(args, actualLength, hook);
args = HookCaller.Caller.RescaleBuffer(args, actualLength, cachedHook);
hasRescaledBuffer = true;
}
else
{
HookCaller.Caller.ProcessDefaults(args, hook);
HookCaller.Caller.ProcessDefaults(args, cachedHook);
}
}

if (args == null || SequenceEqual(hook.Parameters, args))
if (args == null || SequenceEqual(cachedHook.Parameters, args))
{
#if DEBUG
Profiler.StartHookCall(hookable, hookId);
Expand All @@ -265,7 +256,7 @@ static object DoCall(T hookable, uint hookId, CachedHook hook, object[] args, re

try
{
result2 = hook.Method.Invoke(hookable, args);
result2 = cachedHook.Method.Invoke(hookable, args);
}
catch (Exception ex)
{
Expand All @@ -282,11 +273,11 @@ static object DoCall(T hookable, uint hookId, CachedHook hook, object[] args, re
var afterMemory = hookable.TotalMemoryUsed;
var totalMemory = afterMemory - beforeMemory;

if (hook != null)
if (cachedHook != null)
{
hook.HookTime += afterHookTime;
hook.MemoryUsage += totalMemory;
hook.Tick();
cachedHook.HookTime += afterHookTime;
cachedHook.MemoryUsage += totalMemory;
cachedHook.Tick();
}

if (afterHookTime > 100)
Expand All @@ -296,16 +287,7 @@ static object DoCall(T hookable, uint hookId, CachedHook hook, object[] args, re
var readableHook = HookStringPool.GetOrAdd(hookId);
Carbon.Logger.Warn($" {hookable.Name} hook '{readableHook}' took longer than 100ms [{afterHookTime:0}ms]{(hookable.HasGCCollected ? " [GC]" : string.Empty)}");

if (Analytic.Enabled)
{
Analytic.Include("name",
$"{readableHook} ({basePlugin.Name} v{basePlugin.Version} by {basePlugin.Author})");
Analytic.Include("time", $"{afterHookTime.RoundUpToNearestCount(50)}ms");
Analytic.Include("memory", $"{ByteEx.Format(totalMemory, shortName: true).ToLower()}");
Analytic.Include("fires", $"{hook.TimesFired}");
Analytic.Include("hasgc", hookable.HasGCCollected);
Analytic.Send("plugin_time_warn");
}
Analytics.plugin_time_warn(readableHook, basePlugin, afterHookTime, totalMemory, cachedHook, hookable);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Carbon.Core/Carbon/src/Hooks/Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public Subscription(string id, string sub)

public struct TaskStatus
{
public int Static, Patch, Dynamic;
public int Total { get => (Static + Patch + Dynamic); }
public int Static, Patch, Dynamic, Metadata;
public int Total { get => (Static + Patch + Dynamic + Metadata); }
}
15 changes: 5 additions & 10 deletions Carbon.Core/Carbon/src/Jobs/ScriptCompilationThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public override void ThreadFunction()

try
{
conditionals.AddRange(Community.Runtime.Config.ConditionalCompilationSymbols);
conditionals.AddRange(Community.Runtime.Config.Debugging.ConditionalCompilationSymbols);
}
catch (Exception ex)
{
Expand All @@ -350,9 +350,9 @@ public override void ThreadFunction()
string pdb_filename =
#if DEBUG
Debugger.IsAttached
? (string.IsNullOrEmpty(Community.Runtime.Config.ScriptDebuggingOrigin)
? (string.IsNullOrEmpty(Community.Runtime.Config.Debugging.ScriptDebuggingOrigin)
? InitialSource.ContextFilePath
: Path.Combine(Community.Runtime.Config.ScriptDebuggingOrigin, InitialSource.ContextFileName))
: Path.Combine(Community.Runtime.Config.Debugging.ScriptDebuggingOrigin, InitialSource.ContextFileName))
: InitialSource.ContextFileName;
#else
InitialSource.ContextFileName;
Expand Down Expand Up @@ -508,7 +508,7 @@ public override void ThreadFunction()
{
var hash = HookStringPool.GetOrAdd(method.Name);

if (Community.Runtime.HookManager.IsHookLoaded(method.Name))
if (Community.Runtime.HookManager.IsHook(method.Name))
{
if (!hooks.Contains(hash)) hooks.Add(hash);
}
Expand Down Expand Up @@ -537,12 +537,7 @@ public override void ThreadFunction()
}
catch (Exception ex)
{
if (Analytic.Enabled)
{
Analytic.Include("file", $"{InitialSource.ContextFilePath}");
Analytic.Include("stacktrace", $"({ex.Message}) {ex.StackTrace}");
Analytic.Send("plugin_native_compile_fail");
}
Analytics.plugin_native_compile_fail(InitialSource, ex);

System.Console.WriteLine($"Threading compilation failed for '{InitialSource.ContextFilePath}': {ex}");
}
Expand Down
6 changes: 3 additions & 3 deletions Carbon.Core/Carbon/src/Loaders/ScriptLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public static void LoadAll(IEnumerable<string> except = null)
{
var config = Community.Runtime.Config;
var extensionPlugins = OsEx.Folder.GetFilesWithExtension(Defines.GetExtensionsFolder(), "cs");
var plugins = OsEx.Folder.GetFilesWithExtension(Defines.GetScriptFolder(), "cs", option: config.ScriptWatcherOption);
var zipPlugins = OsEx.Folder.GetFilesWithExtension(Defines.GetScriptFolder(), "cszip", option: config.ScriptWatcherOption);
var plugins = OsEx.Folder.GetFilesWithExtension(Defines.GetScriptFolder(), "cs", option: config.Watchers.ScriptWatcherOption);
var zipPlugins = OsEx.Folder.GetFilesWithExtension(Defines.GetScriptFolder(), "cszip", option: config.Watchers.ScriptWatcherOption);

ExecuteProcess(Community.Runtime.ScriptProcessor, false, extensionPlugins, plugins);
ExecuteProcess(Community.Runtime.ZipScriptProcessor, false, zipPlugins);
Expand Down Expand Up @@ -410,7 +410,7 @@ public IEnumerator Compile()

if (type.GetCustomAttribute(typeof(InfoAttribute), true) is not InfoAttribute info) continue;

if (!IsExtension && firstPlugin && Community.Runtime.Config.FileNameCheck && !BypassFileNameChecks)
if (!IsExtension && firstPlugin && Community.Runtime.Config.Watchers.FileNameCheck && !BypassFileNameChecks)
{
var name = Path.GetFileNameWithoutExtension(InitialSource.FilePath).ToLower().Replace(" ", "").Replace(".", "").Replace("-", "");

Expand Down
44 changes: 36 additions & 8 deletions Carbon.Core/Carbon/src/Managers/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed class PatchManager : CarbonBehaviour, IPatchManager, IDisposable
internal List<HookEx> _patches { get; set; }
internal List<HookEx> _staticHooks { get; set; }
internal List<HookEx> _dynamicHooks { get; set; }
internal List<HookEx> _metadataHooks { get; set; }

// TODO --------------------------------------------------------------------
// Allows patch uninstallation on the correct order and should be replaced
Expand Down Expand Up @@ -72,6 +73,13 @@ public void Enqueue(string identifier)
"Carbon.Hooks.Oxide.dll",
};

private static readonly string[] WarnExclusions =
{
"IOnServerCommand",
"IOnRunCommandLine",
"SingleCharCmdPrefix [patch]"
};

private void Awake()
{
Logger.Log($"Initializing {this}..");
Expand All @@ -81,6 +89,7 @@ private void Awake()
_installed = new List<HookEx>();
_patches = new List<HookEx>();
_staticHooks = new List<HookEx>();
_metadataHooks = new List<HookEx>();
_subscribers = new List<Subscription>();
_workQueue = new Queue<string>();

Expand Down Expand Up @@ -340,9 +349,12 @@ private void Update()
#if !(STAGING || AUX01 || AUX02)
if (!hasValidChecksum)
{
Logger.Warn($"Checksum validation failed for '{hook.TargetType}.{hook.TargetMethod}' [{hook.HookFullName}]");
Logger.Debug($"live:{checksum} | expected:{hook.Checksum}");
hook.SetStatus(HookState.Warning, "Invalid checksum");
if (!WarnExclusions.Contains(hook.HookFullName))
{
Logger.Warn($"Checksum validation failed for '{hook.TargetType}.{hook.TargetMethod}' [{hook.HookFullName}]");
Logger.Debug($"live:{checksum} | expected:{hook.Checksum}");
hook.SetStatus(HookState.Warning, "Invalid checksum");
}
}
#endif
}
Expand Down Expand Up @@ -433,6 +445,10 @@ private TaskStatus LoadHooks(IEnumerable<TypeInfo> types)

if (hook.Options.HasFlag(HookFlags.MetadataOnly))
{
hook.SetStatus(HookState.Inactive);
retvar.Metadata++;
_metadataHooks.Add(hook);
HookStringPool.GetOrAdd(hook.HookName);
continue;
}

Expand Down Expand Up @@ -472,11 +488,6 @@ private TaskStatus LoadHooks(IEnumerable<TypeInfo> types)
}
}

foreach(var internalHook in HookCaller.InternalHooks)
{
HookStringPool.GetOrAdd(internalHook);
}

sw.Stop();
return retvar;
}
Expand All @@ -494,6 +505,9 @@ private IEnumerable<HookEx> GetHookDependantTree(HookEx hook)
private IEnumerable<HookEx> LoadedHooks
{ get => _patches.Concat(_dynamicHooks).Concat(_staticHooks).Where(x => x.IsLoaded); }

private IEnumerable<HookEx> Hooks
{ get => _patches.Concat(_dynamicHooks).Concat(_staticHooks).Concat(_metadataHooks); }

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

Expand All @@ -503,10 +517,24 @@ private IEnumerable<HookEx> GetHookByFullName(string name)
private HookEx GetHookById(string identifier)
=> LoadedHooks.FirstOrDefault(x => x.Identifier == identifier) ?? null;

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

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

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

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

public bool IsHook(string hookName)
{
var hooks = GetHookByNameAll(hookName);
return hooks.Any();
}

public bool IsHookLoaded(string hookName)
{
var hooks = GetHookByName(hookName);
Expand Down
4 changes: 2 additions & 2 deletions Carbon.Core/Carbon/src/Processors/ScriptProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Carbon.Managers;
public class ScriptProcessor : BaseProcessor, IScriptProcessor
{
public override string Name => "Script Processor";
public override bool EnableWatcher => !Community.IsConfigReady || Community.Runtime.Config.ScriptWatchers;
public override bool EnableWatcher => !Community.IsConfigReady || Community.Runtime.Config.Watchers.ScriptWatchers;
public override string Folder => Defines.GetScriptFolder();
public override string Extension => ".cs";
public override Type IndexedType => typeof(Script);
Expand All @@ -34,7 +34,7 @@ public override void Start()

base.Start();

IncludeSubdirectories = Community.Runtime.Config.ScriptWatcherOption == SearchOption.AllDirectories;
IncludeSubdirectories = Community.Runtime.Config.Watchers.ScriptWatcherOption == SearchOption.AllDirectories;
}

public bool AllPendingScriptsComplete()
Expand Down
2 changes: 1 addition & 1 deletion Carbon.Core/Carbon/src/Processors/ZipDevScriptProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Carbon.Managers;
public class ZipDevScriptProcessor : BaseProcessor, IZipDevScriptProcessor
{
public override string Name => "ZipDebugScript Processor";
public override bool EnableWatcher => !Community.IsConfigReady || Community.Runtime.Config.ScriptWatchers;
public override bool EnableWatcher => !Community.IsConfigReady || Community.Runtime.Config.Watchers.ZipScriptWatchers;
public override string Folder => Defines.GetZipDevFolder();
public override string Extension => ".cs";
public override Type IndexedType => typeof(ZipDevScript);
Expand Down
4 changes: 2 additions & 2 deletions Carbon.Core/Carbon/src/Processors/ZipScriptProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Carbon.Managers;
public class ZipScriptProcessor : BaseProcessor, IZipScriptProcessor
{
public override string Name => "ZipScript Processor";
public override bool EnableWatcher => !Community.IsConfigReady || Community.Runtime.Config.ScriptWatchers;
public override bool EnableWatcher => !Community.IsConfigReady || Community.Runtime.Config.Watchers.ZipScriptWatchers;
public override string Folder => Defines.GetScriptFolder();
public override string Extension => ".cszip";
public override Type IndexedType => typeof(ZipScript);
Expand All @@ -36,7 +36,7 @@ public override void Start()

base.Start();

IncludeSubdirectories = Community.Runtime.Config.ScriptWatcherOption == SearchOption.AllDirectories;
IncludeSubdirectories = Community.Runtime.Config.Watchers.ScriptWatcherOption == SearchOption.AllDirectories;
}

public bool AllPendingScriptsComplete()
Expand Down
2 changes: 1 addition & 1 deletion Tools/Build/win/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ echo "%BUILD_TARGET%" | findstr /C:"Unix" >NUL && (

if "%2" NEQ "--no-archive" (
echo ** Create the compressed archive 'Carbon.%TOS%.%TAG%.zip'
powershell -Command "Compress-Archive -Update -Path '%BUILD_ROOT%\Release\.tmp\%BUILD_TARGET%\*' -DestinationPath '%BUILD_ROOT%\Release\Carbon.%TOS%.%TAG%.zip'"
pwsh -Command "Compress-Archive -Update -Path '%BUILD_ROOT%\Release\.tmp\%BUILD_TARGET%\*' -DestinationPath '%BUILD_ROOT%\Release\Carbon.%TOS%.%TAG%.zip'"
)
Loading

0 comments on commit e03df31

Please sign in to comment.