public static void Postfix(MyScriptManager __instance) { try { HashSet <ulong> currentMods; if (MySession.Static.Mods != null) { currentMods = new HashSet <ulong>(MySession.Static.Mods.Select(x => x.PublishedFileId)); } else { currentMods = new HashSet <ulong>(); } PluginList list = Main.Instance.List; foreach (string id in Main.Instance.Config.EnabledPlugins) { PluginData data = list[id]; if (data is ModPlugin mod && !currentMods.Contains(mod.WorkshopId) && mod.Exists) { LogFile.WriteLine("Loading client mod scripts for " + mod.WorkshopId); loadScripts(__instance, mod.ModLocation, mod.GetModContext()); } } } catch (Exception e) { LogFile.WriteLine("An error occured while loading client mods: " + e); throw; } }
public static void AddScriptGameLogic(MyEntity entity, MyObjectBuilderType builderType, string subTypeName = null) { MyScriptManager @static = MyScriptManager.Static; if ((@static != null) && (entity != null)) { HashSet <Type> emptySet; if (subTypeName == null) { emptySet = m_emptySet; } else { Tuple <Type, string> key = new Tuple <Type, string>((Type)builderType, subTypeName); emptySet = @static.SubEntityScripts.GetValueOrDefault <Tuple <Type, string>, HashSet <Type> >(key, m_emptySet); } HashSet <Type> first = @static.EntityScripts.GetValueOrDefault <Type, HashSet <Type> >((Type)builderType, m_emptySet); int capacity = emptySet.Count + first.Count; if (capacity != 0) { List <MyGameLogicComponent> logicComponents = new List <MyGameLogicComponent>(capacity); foreach (Type local1 in first.Concat <Type>(emptySet)) { MyGameLogicComponent item = (MyGameLogicComponent)Activator.CreateInstance(local1); MyEntityComponentDescriptor descriptor = (MyEntityComponentDescriptor)local1.GetCustomAttribute(typeof(MyEntityComponentDescriptor), false); if (descriptor.EntityUpdate == null) { ((IMyGameLogicComponent)item).EntityUpdate = true; } else if (descriptor.EntityUpdate.Value) { ((IMyGameLogicComponent)item).EntityUpdate = true; } logicComponents.Add(item); } MyGameLogicComponent component = MyCompositeGameLogicComponent.Create(logicComponents, entity); entity.GameLogic = component; } } }
private void SetupReflection() { if (m_compile && m_type == WorkshopType.Mod) { if (_scriptManager == null) { _scriptManager = new MyScriptManager(); } if (_compileMethod == null) { _compileMethod = typeof(MyScriptManager).GetMethod("LoadScripts", BindingFlags.NonPublic | BindingFlags.Instance); MyDebug.AssertDebug(_compileMethod != null); if (_compileMethod != null) { var parameters = _compileMethod.GetParameters(); MyDebug.AssertDebug(parameters.Count() == 2); MyDebug.AssertDebug(parameters[0].ParameterType == typeof(string)); MyDebug.AssertDebug(parameters[1].ParameterType == typeof(MyModContext)); if (!(parameters.Count() == 2 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(MyModContext))) { _compileMethod = null; MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "LoadScripts")); } } } } if (!m_dryrun) { _publishMethod = typeof(MySteamWorkshop).GetMethod("PublishItemBlocking", BindingFlags.Static | BindingFlags.NonPublic); MyDebug.AssertDebug(_publishMethod != null); if (_publishMethod != null) { var parameters = _publishMethod.GetParameters(); MyDebug.AssertDebug(parameters.Count() == 7); MyDebug.AssertDebug(parameters[0].ParameterType == typeof(string)); MyDebug.AssertDebug(parameters[1].ParameterType == typeof(string)); MyDebug.AssertDebug(parameters[2].ParameterType == typeof(string)); MyDebug.AssertDebug(parameters[3].ParameterType == typeof(ulong?)); MyDebug.AssertDebug(parameters[4].ParameterType == typeof(SteamSDK.PublishedFileVisibility)); MyDebug.AssertDebug(parameters[5].ParameterType == typeof(string[])); MyDebug.AssertDebug(parameters[6].ParameterType == typeof(string[])); if (!(parameters.Count() == 7 && parameters[0].ParameterType == typeof(string) && parameters[1].ParameterType == typeof(string) && parameters[2].ParameterType == typeof(string) && parameters[3].ParameterType == typeof(ulong?) && parameters[4].ParameterType == typeof(SteamSDK.PublishedFileVisibility) && parameters[5].ParameterType == typeof(string[]) && parameters[6].ParameterType == typeof(string[]))) { _publishMethod = null; MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "PublishItemBlocking")); } } } }