Skip to content

Commit

Permalink
Merge pull request #8 from Citrinate/asf6
Browse files Browse the repository at this point in the history
Update to ASF 6
  • Loading branch information
Citrinate authored Mar 9, 2024
2 parents 0972ad9 + 117acca commit 27c3c7f
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 211 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 177 files
32 changes: 32 additions & 0 deletions CS2Interface/AdapterBridge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Reflection;
using ArchiSteamFarm.Core;

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

namespace CS2Interface;
internal static class AdapterBridge {
public static bool InitAdapter(string pluginName, string pluginId, string? cmdPrefix, string? repoName, MethodInfo? cmdHandler) {
try {
var adapterEndpoint = Assembly.Load("ASFEnhance").GetType("ASFEnhance._Adapter_.Endpoint");
var registerModule = adapterEndpoint?.GetMethod("RegisterModule", BindingFlags.Static | BindingFlags.Public);
var pluinVersion = Assembly.GetExecutingAssembly().GetName().Version;

if (registerModule != null && adapterEndpoint != null) {
var result = registerModule?.Invoke(null, new object?[] { pluginName, pluginId, cmdPrefix, repoName, pluinVersion, cmdHandler });

if (result is string str) {
if (str == pluginName) {
return true;
} else {
ASF.ArchiLogger.LogGenericWarning(str);
}
}
}
} catch (Exception ex) {
ASF.ArchiLogger.LogGenericException(ex, "Community with ASFEnhance failed");
}

return false;
}
}
4 changes: 4 additions & 0 deletions CS2Interface/CS/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ private void OnGCMessage(SteamGameCoordinator.MessageCallback callback) {
return;
}

#if DEBUG
Bot.ArchiLogger.LogGenericDebug(String.Format("Message Received: {0}", callback.EMsg));
#endif

OnGCMessageRecieved?.Invoke(callback);

var messageMap = new Dictionary<uint, Action<IPacketGCMsg>> {
Expand Down
33 changes: 25 additions & 8 deletions CS2Interface/CS2Interface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,61 @@
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Plugins.Interfaces;
using Newtonsoft.Json.Linq;
using SteamKit2;
using System.Collections.Concurrent;
using System.Text.Json;
using System.Reflection;

namespace CS2Interface {
[Export(typeof(IPlugin))]
public sealed class CS2Interface : IASF, IBotModules, IBotSteamClient, IBotCommand2, IBotConnection, IBotCardsFarmerInfo {
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);
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;

return Task.CompletedTask;
}

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

return await Commands.Response(bot, access, steamID, message, args).ConfigureAwait(false);
}

public Task OnASFInit(IReadOnlyDictionary<string, JToken>? additionalConfigProperties = null) {
public Task OnASFInit(IReadOnlyDictionary<string, JsonElement>? additionalConfigProperties = null) {
if (additionalConfigProperties == null) {
return Task.FromResult(0);
}

return Task.FromResult(0);
}

public Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JToken>? additionalConfigProperties = null) {
public Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JsonElement>? additionalConfigProperties = null) {
if (additionalConfigProperties == null) {
return Task.FromResult(0);
}

foreach (KeyValuePair<string, JToken> configProperty in additionalConfigProperties) {
foreach (KeyValuePair<string, JsonElement> configProperty in additionalConfigProperties) {
switch (configProperty.Key) {
case "AutoStartCS2Interface" when configProperty.Value.Type == JTokenType.Boolean: {
bot.ArchiLogger.LogGenericInfo("AutoStartCS2Interface : " + configProperty.Value);
AutoStart[bot.BotName] = configProperty.Value.ToObject<bool>();
case "AutoStartCS2Interface" when (configProperty.Value.ValueKind == JsonValueKind.True || configProperty.Value.ValueKind == JsonValueKind.False): {
bot.ArchiLogger.LogGenericInfo("AutoStartCS2Interface : " + configProperty.Value.GetBoolean());
AutoStart[bot.BotName] = configProperty.Value.GetBoolean();
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion CS2Interface/CS2Interface.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Authors>Citrinate</Authors>
<AssemblyVersion>1.0.6</AssemblyVersion>
<AssemblyVersion>1.0.7</AssemblyVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<TargetFramework>net8.0</TargetFramework>
Expand Down
5 changes: 5 additions & 0 deletions CS2Interface/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ internal static class Commands {
switch (args.Length) {
case 1:
switch (args[0].ToUpperInvariant()) {
case "CS2INTERFACE" when access >= EAccess.FamilySharing:
return String.Format("{0} {1}", nameof(CS2Interface), (typeof(CS2Interface).Assembly.GetName().Version ?? new Version("0")).ToString());

case "CSTART" or "CSSTART" or "CS2START" or "CRUN" or "CSRUN" or "CS2RUN":
return await ResponseRun(bot, access).ConfigureAwait(false);

case "CSTOP" or "CSSTOP" or "CS2STOP":
return ResponseStop(bot, access);

case "CSA":
return ResponseStatus(access, steamID, "ASF");
case "CSTATUS" or "CSSTATUS" or "CS2STATUS":
return ResponseStatus(bot, access);

Expand Down
17 changes: 9 additions & 8 deletions CS2Interface/Data/InspectItem.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.Linq;
using Newtonsoft.Json;
using System.Text.Json.Serialization;
using SteamKit2.GC.CSGO.Internal;

namespace CS2Interface {
internal sealed class InspectItem : Item {
[JsonProperty(PropertyName = "iteminfo")]
internal CEconItemPreviewDataBlock ItemInfo;
internal string s;
internal string a;
internal string d;
internal string m;
public sealed class InspectItem : Item {
[JsonInclude]
[JsonPropertyName("iteminfo")]
public CEconItemPreviewDataBlock ItemInfo { get; private init; }
public string s;
public string a;
public string d;
public string m;

internal InspectItem(CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockResponse item, ulong param_s, ulong param_a, ulong param_d, ulong param_m) {
ItemInfo = item.iteminfo;
Expand Down
29 changes: 17 additions & 12 deletions CS2Interface/Data/InventoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using ArchiSteamFarm.Core;
using Newtonsoft.Json;
using SteamKit2;
using SteamKit2.GC.CSGO.Internal;

namespace CS2Interface {
internal sealed class InventoryItem : Item {
[JsonProperty(PropertyName = "iteminfo")]
internal CSOEconItem ItemInfo;
public sealed class InventoryItem : Item {
[JsonInclude]
[JsonPropertyName("iteminfo")]
public CSOEconItem ItemInfo { get; private init; }

[JsonProperty(PropertyName = "attributes")]
[JsonInclude]
[JsonPropertyName("attributes")]
[JsonConverter (typeof(AttributeConverter))]
Dictionary<string, IAttribute>? Attributes;
public Dictionary<string, IAttribute>? Attributes { get; private set; }

[JsonProperty(PropertyName = "position")]
internal uint? Position;
[JsonInclude]
[JsonPropertyName("position")]
public uint? Position { get; private set; }

[JsonProperty(PropertyName = "casket_id")]
internal ulong? CasketID;
[JsonInclude]
[JsonPropertyName("casket_id")]
public ulong? CasketID { get; private set; }

[JsonProperty(PropertyName = "moveable")]
internal bool? Moveable;
[JsonInclude]
[JsonPropertyName("moveable")]
public bool? Moveable { get; private set; }

public bool ShouldSerializeAttributes() => Attributes != null && ShouldSerializeAdditionalProperties;
public bool ShouldSerializePosition() => Position != null && ShouldSerializeAdditionalProperties;
Expand Down
Loading

0 comments on commit 27c3c7f

Please sign in to comment.