public static void LoadDelegates() { try { Assembly a = AccessExtensionPatcher.GetLoadedAssemblybyName("CustomComponents"); if (a == null) { SimpleMechAssembly_Main.Log.Log("CustomComponents not found"); return; } SimpleMechAssembly_Main.Log.Log("loading CustomComponents..."); // do reflection magic to get delegates to CustomComponents funcs Type ccflags = a.GetType("CustomComponents.Flags"); Type cclootable = a.GetType("CustomComponents.LootableDefault"); AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.MechDefExtensions", "GetComponent", ref GetCCFlagsMechDef, null, (mi, _) => mi.MakeGenericMethod(ccflags), SimpleMechAssembly_Main.Log.Log); AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.ChassisDefExtensions", "GetComponent", ref GetCCFlagsChassisDef, null, (mi, _) => mi.MakeGenericMethod(ccflags), SimpleMechAssembly_Main.Log.Log); AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.MechComponentDefExtensions", "GetComponent", ref GetCCFlagsMCDef, null, (mi, _) => mi.MakeGenericMethod(ccflags), SimpleMechAssembly_Main.Log.Log); AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.MechComponentDefExtensions", "GetComponent", ref GetCCLootable, null, (mi, _) => mi.MakeGenericMethod(cclootable), SimpleMechAssembly_Main.Log.Log); AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.Registry", "RegisterSimpleCustomComponents", ref RegisterCCTypes, (mi) => mi.GetParameters().First().Name == "types", null, SimpleMechAssembly_Main.Log.Log); AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.Contract_GenerateSalvage", "IsDestroyed", ref MechDefIsDead, null, null, SimpleMechAssembly_Main.Log.Log); // do more magic to get no_salvage flag out of it if (ccflags != null) { SimpleMechAssembly_Main.Log.Log("generating CCFlags.GetNotSalvageable"); MethodInfo m = ccflags.GetMethods().Where((i) => i.Name.Equals("get_NotSalvagable")).Single(); CCFlagsGetNotSalvageable = AccessExtensionPatcher.GenerateCastAndCall <Func <object, bool> >(m); CCLootableGetItem = AccessExtensionPatcher.GenerateCastAndCall <Func <object, string> >(cclootable.GetProperty("ItemID").GetGetMethod()); } // do a lot more magic to register AssemblyVariant & VAssemblyVariant SimpleMechAssembly_Main.Log.Log("Generating Customs"); ConstructorInfo custcomatctor = a.GetType("CustomComponents.CustomComponentAttribute").GetConstructor(new Type[] { typeof(string) }); Type simplecustom = a.GetType("CustomComponents.SimpleCustom`1"); AssemblyVariantType = AccessExtensionPatcher.GenerateType("AssemblyVariant", simplecustom.MakeGenericType(typeof(ChassisDef)), new Type[] { typeof(IAssemblyVariant) }, new CustomAttributeBuilder[] { new CustomAttributeBuilder(custcomatctor, new object[] { "AssemblyVariant" }) }); VAssemblyVariantType = AccessExtensionPatcher.GenerateType("VAssemblyVariant", simplecustom.MakeGenericType(typeof(VehicleChassisDef)), new Type[] { typeof(IVAssemblyVariant) }, new CustomAttributeBuilder[] { new CustomAttributeBuilder(custcomatctor, new object[] { "VAssemblyVariant" }) }); SimpleMechAssembly_Main.Log.Log("Registering Customs"); RegisterCCTypes(new Type[] { AssemblyVariantType, VAssemblyVariantType }); AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.ChassisDefExtensions", "GetComponent", ref GetCCAssemblyVariant, null, (mi, _) => mi.MakeGenericMethod(AssemblyVariantType), SimpleMechAssembly_Main.Log.Log); if (!AccessExtensionPatcher.GetDelegateFromAssembly(a, "CustomComponents.VehicleExtentions", "GetComponent", ref GetCCVehicleAssemblyVariant, null, (mi, _) => mi.MakeGenericMethod(VAssemblyVariantType), SimpleMechAssembly_Main.Log.Log)) { if (SimpleMechAssembly_Main.Settings.FakeVehilceTag != null) { SimpleMechAssembly_Main.Log.LogWarning("warning: SMA FakeVehilceTag is set, but CustomComponents does not support VehicleDef Customs. Upgrade your CustomComponents to use Vehicle CrossAssembly"); } } } catch (Exception e) { FileLog.Log(e.ToString()); } }
public static void LoadDelegates() { try { if (!AccessExtensionPatcher.GetDelegateFromAssembly("CustomUnits", "CustomUnits.SimGameState_AddMech", "GetFirstFreeMechBay", ref GetFirstFreeMechBay, null, null, SimpleMechAssembly_Main.Log.Log)) { if (SimpleMechAssembly_Main.Settings.FakeVehilceTag != null) { SimpleMechAssembly_Main.Log.LogWarning("warning: SMA FakeVehilceTag is set, but CustomUnits is missing. unsetting it now."); SimpleMechAssembly_Main.Settings.FakeVehilceTag = null; } } } catch (Exception e) { FileLog.Log(e.ToString()); } }