/// <summary> /// Helper method which sets all the properties in the class to their respected FlashObject field. /// Use InternalNameAttribute to specify a property which has a FlashObject counter-part. /// SetFields does not travel the hierarchy. So Derived types must make their own separate call to SetFields. /// </summary> /// <param name="obj">Object to change properties</param> /// <param name="flash">Flash object to get fields from</param> public static void SetFields <T>(T obj, ASObject flash) { if (flash == null) { return; } foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { var intern = prop.GetAttribute <InternalNameAttribute>(); if (intern == null) { continue; } var type = prop.PropertyType; object value; if (!flash.TryGetValue(intern.Name, out value)) { StaticLogger.Warning(string.Format("{0} missing ASObject property {1}", typeof(T).FullName, intern.Name)); continue; } try { if (type == typeof(string)) { value = Convert.ToString(flash[intern.Name]); } else if (type == typeof(Int32)) { value = Convert.ToInt32(flash[intern.Name]); } else if (type == typeof(Int64)) { value = Convert.ToInt64(flash[intern.Name]); } else if (type == typeof(double)) { value = Convert.ToInt64(flash[intern.Name]); } else if (type == typeof(bool)) { value = Convert.ToBoolean(flash[intern.Name]); } else if (type == typeof(DateTime)) { value = Convert.ToDateTime(flash[intern.Name]); } else if (type == typeof(ASObject)) { value = flash[intern.Name] as ASObject; } else if (type == typeof(ArrayCollection)) { value = flash[intern.Name] as ArrayCollection; } else if (type == typeof(object)) { value = flash[intern.Name]; } else { try { value = Activator.CreateInstance(type, flash[intern.Name]); } catch (Exception e) { throw new NotSupportedException(string.Format("Type {0} not supported by flash serializer", type.FullName), e); } } prop.SetValue(obj, value, null); } catch (Exception e) { StaticLogger.Error(new Exception(string.Format("Error parsing {0}#{1}", typeof(T).FullName, prop.Name), e)); } } }
void launcher_ProcessFound(object sender, ProcessMonitor.ProcessEventArgs e) { try { if (!Settings.DeleteLeaveBuster) { return; } var dir = Path.GetDirectoryName(e.Process.MainModule.FileName); if (dir == null) { StaticLogger.Warning("Launcher module not found"); return; } var needle = "\\RADS\\"; var i = dir.LastIndexOf(needle, StringComparison.InvariantCulture); if (i == -1) { StaticLogger.Warning("Launcher Rads not found"); return; } dir = dir.Remove(i + needle.Length); dir = Path.Combine(dir, "projects\\lol_air_client\\releases"); if (!Directory.Exists(dir)) { StaticLogger.Warning("lol_air_client directory not found"); return; } foreach (var ver in new DirectoryInfo(dir).GetDirectories()) { var filename = Path.Combine(ver.FullName, "deploy\\preferences\\global\\global.properties"); if (!File.Exists(filename)) { StaticLogger.Warning(filename + " not found"); continue; } ASObject obj = null; using (var amf = new AMFReader(File.OpenRead(filename))) { try { obj = amf.ReadAMF3Data() as ASObject; if (obj == null) { StaticLogger.Warning("Failed to read " + filename); continue; } } catch (Exception ex) { StaticLogger.Warning("LeaverBuster: Unable to read global.properties '" + filename + "'"); continue; } } object leaver; object locale; if ((obj.TryGetValue("leaverData", out leaver) && leaver != null) || (obj.TryGetValue("localeData", out locale) && locale != null)) { obj["leaverData"] = null; obj["localeData"] = null; using (var amf = new AMFWriter(File.Open(filename, FileMode.Create, FileAccess.Write))) { try { amf.WriteAMF3Data(obj); StaticLogger.Info("Removed leaverData/localeData from global.properties"); } catch (Exception ex) { StaticLogger.Warning("LeaverBuster: Unable to write global.properties '" + filename + "'"); continue; } } } else { StaticLogger.Info("leaverData/localeData already removed from global.properties"); } } } catch (Exception ex) { StaticLogger.Error(ex); } }