Skip to content

Commit

Permalink
fix: Missing member errors during Set/Invoke command auto-complete
Browse files Browse the repository at this point in the history
  • Loading branch information
psyGamer committed Feb 12, 2025
1 parent 515d375 commit d3d7fde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static IEnumerable<CommandAutoCompleteEntry> GetInvokeTypeAutoCompleteEn
private static IEnumerator<CommandAutoCompleteEntry> GetParameterAutoCompleteEntries(string[] targetArgs, int parameterIndex) {
if (targetArgs.Length >= 1 && TargetQuery.ResolveBaseTypes(targetArgs, out string[] memberArgs, out _, out _) is { } types && types.IsNotEmpty() && memberArgs.Length == 1) {
// Assume the first type
var parameters = types[0].GetMethodInfo(memberArgs[0]).GetParameters();
var parameters = types[0].GetMethodInfo(memberArgs[0], logFailure: false)?.GetParameters() ?? [];
if (parameterIndex >= 0 && parameterIndex < parameters.Length) {
// End arguments if further parameters aren't settable anymore
bool final = parameterIndex == parameters.Length - 1 ||
Expand Down Expand Up @@ -220,7 +220,7 @@ private static void Invoke(string[] args) {
return;
}

var valuesResult = TargetQuery.ResolveValues(args[1..], methodResult.Value!.GetParameters().Select(param => param.ParameterType).ToArray());
var valuesResult = TargetQuery.ResolveValues(args[1..], methodResult.Value.GetParameters().Select(param => param.ParameterType).ToArray());
if (valuesResult.Failure) {
ReportError(valuesResult);
return;
Expand Down
22 changes: 10 additions & 12 deletions CelesteTAS-EverestInterop/Source/TAS/Input/Commands/SetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
using StudioCommunication;
using StudioCommunication.Util;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using TAS.Entities;
using TAS.EverestInterop;
using TAS.EverestInterop.InfoHUD;
using TAS.Gameplay;
using TAS.InfoHUD;
using TAS.ModInterop;
Expand Down Expand Up @@ -144,7 +142,7 @@ public IEnumerator<CommandAutoCompleteEntry> GetAutoCompleteEntries(string[] arg
foreach (object variant in Enum.GetValues(variantsEnum)) {
string typeName = string.Empty;
try {
var variantType = ExtendedVariantsInterop.GetVariantType(new Lazy<object>(variant));
var variantType = ExtendedVariantsInterop.GetVariantType(new Lazy<object?>(variant));
if (variantType != null) {
typeName = variantType.CSharpName();
}
Expand Down Expand Up @@ -196,13 +194,13 @@ private static IEnumerable<CommandAutoCompleteEntry> GetSetTypeAutoCompleteEntri
private static IEnumerator<CommandAutoCompleteEntry> GetParameterAutoCompleteEntries(string[] targetArgs) {
if (targetArgs.Length == 1) {
// Vanilla setting / session / assist
if (typeof(Settings).GetFieldInfo(targetArgs[0], BindingFlags.Instance | BindingFlags.Public) is { } fSettings) {
if (typeof(Settings).GetFieldInfo(targetArgs[0], logFailure: false) is { } fSettings) {
return GetParameterTypeAutoCompleteEntries(fSettings.FieldType);
}
if (typeof(SaveData).GetFieldInfo(targetArgs[0], BindingFlags.Instance | BindingFlags.Public) is { } fSaveData) {
if (typeof(SaveData).GetFieldInfo(targetArgs[0], logFailure: false) is { } fSaveData) {
return GetParameterTypeAutoCompleteEntries(fSaveData.FieldType);
}
if (typeof(Assists).GetFieldInfo(targetArgs[0], BindingFlags.Instance | BindingFlags.Public) is { } fAssists) {
if (typeof(Assists).GetFieldInfo(targetArgs[0], logFailure: false) is { } fAssists) {
return GetParameterTypeAutoCompleteEntries(fAssists.FieldType);
}
}
Expand Down Expand Up @@ -251,11 +249,11 @@ internal static IEnumerator<CommandAutoCompleteEntry> GetParameterTypeAutoComple
private static Type RecurseSetType(Type baseType, string[] memberArgs) {
var type = baseType;
foreach (string member in memberArgs) {
if (type.GetFieldInfo(member) is { } field) {
if (type.GetFieldInfo(member, logFailure: false) is { } field) {
type = field.FieldType;
continue;
}
if (type.GetPropertyInfo(member) is { } property && property.SetMethod != null) {
if (type.GetPropertyInfo(member, logFailure: false) is { } property && property.SetMethod != null) {
type = property.PropertyType;
continue;
}
Expand Down Expand Up @@ -392,11 +390,11 @@ private static void SetGameSetting(string settingName, string[] valueArgs) {
object? settings = null;

FieldInfo? field;
if ((field = typeof(Settings).GetFieldInfo(settingName)) != null) {
if ((field = typeof(Settings).GetFieldInfo(settingName, logFailure: false)) != null) {
settings = Settings.Instance;
} else if ((field = typeof(SaveData).GetFieldInfo(settingName)) != null) {
} else if ((field = typeof(SaveData).GetFieldInfo(settingName, logFailure: false)) != null) {
settings = SaveData.Instance;
} else if ((field = typeof(Assists).GetFieldInfo(settingName)) != null) {
} else if ((field = typeof(Assists).GetFieldInfo(settingName, logFailure: false)) != null) {
settings = SaveData.Instance.Assists;
}

Expand Down Expand Up @@ -425,7 +423,7 @@ private static void SetGameSetting(string settingName, string[] valueArgs) {
}
}
private static void SetExtendedVariant(string variantName, string[] valueArgs) {
var variant = new Lazy<object>(ExtendedVariantsInterop.ParseVariant(variantName));
var variant = new Lazy<object?>(ExtendedVariantsInterop.ParseVariant(variantName));
var variantType = ExtendedVariantsInterop.GetVariantType(variant);
if (variantType is null) {
ReportError($"Failed to resolve type for extended variant '{variantName}'");
Expand Down

0 comments on commit d3d7fde

Please sign in to comment.