using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEditor; namespace HotPatch.Editor { internal sealed class HotPatchAndroidResolverScope : IDisposable { readonly List<(PropertyInfo Property, bool Value)> previous = new List<(PropertyInfo, bool)>(); public HotPatchAndroidResolverScope() { if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android) return; var type = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetType("GooglePlayServices.SettingsDialog")) .FirstOrDefault(t => t != null); if (type == null) return; try { foreach (var name in new[] { "AutoResolveOnBuild", "EnableAutoResolution" }) { var property = type.GetProperty(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (property == null || !property.CanRead || !property.CanWrite || property.PropertyType != typeof(bool)) continue; previous.Add((property, (bool)property.GetValue(null))); property.SetValue(null, false); } } catch { Dispose(); throw; } } public void Dispose() { foreach (var item in previous) item.Property.SetValue(null, item.Value); previous.Clear(); } } }