Skip to content

Commit

Permalink
Remove ASFE DisabledCmds support
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Mar 10, 2024
1 parent eddebab commit 168acd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 10 additions & 0 deletions CS2Interface/AdapterBridge.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Steam;

// ASFEnhanced Adapter https://github.com/chr233/ASFEnhanceAdapterDemoPlugin

Expand Down Expand Up @@ -29,4 +30,13 @@ public static bool InitAdapter(string pluginName, string pluginId, string? cmdPr

return false;
}

internal static string? Response(Bot bot, EAccess access, ulong steamID, string message, string[] args) {
// ASFEnhance wants to intercept commands meant for this plugin, for the purpose of it's DisabledCmds config setting.
// Seems buggy though: https://github.com/Citrinate/FreePackages/issues/28
// Therefore I'm feeding it this dummy response function, as ASFEnhance requires that cmdHandler not be null.
// This disables DisabledCmds support, but should not effect PLUGINSUPDATE command support

return null;
}
}
14 changes: 4 additions & 10 deletions CS2Interface/CS2Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,23 @@ public sealed class CS2Interface : IASF, IBotModules, IBotSteamClient, IBotComma
internal static ConcurrentDictionary<string, bool> AutoStart = new();
public string Name => nameof(CS2Interface);
public Version Version => typeof(CS2Interface).Assembly.GetName().Version ?? new Version("0");
private bool ASFEnhanceEnabled = false;

public Task OnLoaded() {
ASF.ArchiLogger.LogGenericInfo("Counter-Strike 2 Interface ASF Plugin by Citrinate");
GameData.Update();

// ASFEnhanced Adapter https://github.com/chr233/ASFEnhanceAdapterDemoPlugin
var flag = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
var handler = typeof(Commands).GetMethod(nameof(Commands.Response), flag);
var handler = typeof(AdapterBridge).GetMethod(nameof(AdapterBridge.Response), flag);
const string pluginId = nameof(CS2Interface);
const string cmdPrefix = "CS2INTERFACE";
const string repoName = "Citrinate/CS2Interface";
var registered = AdapterBridge.InitAdapter(Name, pluginId, cmdPrefix, repoName, handler);
ASFEnhanceEnabled = registered;

AdapterBridge.InitAdapter(Name, pluginId, cmdPrefix, repoName, handler);

return Task.CompletedTask;
}

public async Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) {
if (ASFEnhanceEnabled) {
return null;
}

public async Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) {
return await Commands.Response(bot, access, steamID, message, args).ConfigureAwait(false);
}

Expand Down

0 comments on commit 168acd6

Please sign in to comment.