bool FillPropertiesFromPublished() { var results = WorkshopHelper.GetItemsBlocking(m_modId); if (results?.Count > 0) { System.Threading.Thread.Sleep(1000); // Fix for DLC not being filled in if (results.Count > 0) { m_workshopItems[m_modId[0]] = results[0]; if (m_modId.Length > 1 && results.Count > 1) { m_workshopItems[m_modId[1]] = results[1]; } m_title = results[0].Title; // Check if the mod owner in the sbmi matches steam owner var owner = results[0].OwnerId; if (m_visibility == null) { m_visibility = (PublishedFileVisibility)(int)results[0].Visibility; } #if SE m_dlcs = results[0].DLCs.ToArray(); #endif m_deps = results[0].Dependencies.ToArray(); MyDebug.AssertDebug(owner == MyGameService.UserId); if (owner != MyGameService.UserId) { MySandboxGame.Log.WriteLineError(string.Format("Owner mismatch! Mod owner: {0}; Current user: {1}", owner, MyGameService.UserId)); MySandboxGame.Log.WriteLineError("Upload/Publish FAILED!"); return(false); } return(true); } return(false); } return(false); }
public static MethodInfo ReflectInitModAPI() { ParameterInfo[] parameters; // Init ModAPI var initmethod = typeof(MySandboxGame).GetMethod("InitModAPI", BindingFlags.Instance | BindingFlags.NonPublic); MyDebug.AssertRelease(initmethod != null); if (initmethod != null) { parameters = initmethod.GetParameters(); MyDebug.AssertRelease(parameters.Count() == 0); if (!(parameters.Count() == 0)) { initmethod = null; } } return(initmethod); }
public static bool ReplaceMethod(MethodInfo methodtoreplace, MethodInfo methodtoinject, Type[] types = null) { ParameterInfo[] sourceParameters; ParameterInfo[] destinationParameters; MyDebug.AssertRelease(methodtoreplace != null); if (methodtoreplace != null && methodtoinject != null) { sourceParameters = methodtoreplace.GetParameters(); destinationParameters = methodtoinject.GetParameters(); MyDebug.AssertDebug(sourceParameters.Length == destinationParameters.Length); bool valid = true; // Verify signatures for (var x = 0; x < Math.Min(destinationParameters.Length, sourceParameters.Length); x++) { MyDebug.AssertDebug(destinationParameters[x].ParameterType == sourceParameters[x].ParameterType); if (destinationParameters[x].ParameterType != sourceParameters[x].ParameterType) { valid = false; } } if (sourceParameters.Length != destinationParameters.Length || !valid) { methodtoreplace = null; } } if (methodtoreplace != null && methodtoinject != null) { MethodUtil.ReplaceMethod(methodtoreplace, methodtoinject); return(true); } else { return(false); } }
void ProcessTags() { // TODO: This code could be better. // 0a) Get the list of existing tags, if there are any var existingTags = GetTags(); var userTags = new List <string>(m_tags); // 0b) Add user-specified tags *to add* m_tagsToAdd.ForEach(t => userTags.Add(t)); // Order or tag processing matters // 1) Copy mod type into tags var modtype = m_type.ToString(); // 2) Verify the modtype matches what was listed in the workshop // TODO If type doesn't match, process as workshop type if (existingTags?.Length > 0 && !existingTags.Contains(modtype, StringComparer.InvariantCultureIgnoreCase)) { MySandboxGame.Log.WriteLineWarning(string.Format("Workshop category '{0}' does not match expected '{1}'. Is something wrong?", existingTags[0], modtype)); } #if SE // 3a) check if user passed in the 'development' tag // If so, remove it, and mark the mod as 'dev' so it doesn't get flagged later userTags.RemoveAll(t => t.Equals(MyWorkshop.WORKSHOP_DEVELOPMENT_TAG, StringComparison.InvariantCultureIgnoreCase)); #endif // 4) If no user-specified tags were set, grab them from the workshop // NOTE: Specifically check m_tags here if (m_tags?.Length == 0 && existingTags?.Length > 0) { existingTags.ForEach(t => userTags.Add(t)); } // 5) If tags contain mod type, remove it userTags.RemoveAll(t => t.Equals(modtype, StringComparison.InvariantCultureIgnoreCase)); // 6) Check user-specified tags to add and remove m_tagsToRemove.ForEach(t => userTags.RemoveAll(n => n.Equals(t, StringComparison.InvariantCultureIgnoreCase))); // 7) Strip empty values userTags.RemoveAll(x => string.IsNullOrEmpty(x?.Trim())); if (userTags.Count > 0) { // Verify passed in tags are valid for this mod type var validTags = new List <MyWorkshop.Category>(); validTags.AddHiddenTags(); switch (m_type) { case WorkshopType.Mod: MyWorkshop.ModCategories.ForEach(c => validTags.Add(c)); break; case WorkshopType.Blueprint: MyWorkshop.BlueprintCategories.ForEach(c => validTags.Add(c)); break; case WorkshopType.Scenario: MyWorkshop.ScenarioCategories.ForEach(c => validTags.Add(c)); break; case WorkshopType.World: MyWorkshop.WorldCategories.ForEach(c => validTags.Add(c)); break; case WorkshopType.IngameScript: //tags = new MyWorkshop.Category[0]; // There are none currently break; default: MyDebug.FailRelease("Invalid category."); break; } // Mods and blueprints have extra tags not in the above lists validTags.AddHiddenTags(m_type); // This query gets all the items in 'm_tags' that do *not* exist in 'validTags' // This is for detecting invalid tags passed in var invalidItems = (from utag in userTags where !( from tag in validTags select tag.Id ).Contains(utag, StringComparer.InvariantCultureIgnoreCase) select utag); if (invalidItems.Count() > 0) { MySandboxGame.Log.WriteLineWarning(string.Format("{0} invalid tags: {1}", (m_force ? "Forced" : "Removing"), string.Join(", ", invalidItems))); if (!m_force) { invalidItems.ToList().ForEach(t => userTags.RemoveAll(n => n.Equals(t, StringComparison.InvariantCultureIgnoreCase))); } } // Now prepend the 'Type' tag var newTags = new List <string>(); newTags.AddOrInsert(m_type.ToString(), 0); var tags = from tag in validTags select tag.Id; // Convert all tags to proper-case for (var x = 0; x < userTags.Count; x++) { var tag = userTags[x]; var newtag = (from vtag in tags where (string.Compare(vtag, tag, true) == 0) select vtag).FirstOrDefault(); if (!string.IsNullOrEmpty(newtag)) { newTags.AddOrInsert(newtag, x + 1); } else { newTags.AddOrInsert(userTags[x], x + 1); } } userTags = newTags; } #if SE // 8) Always remove DEV tag, if present if (userTags.Contains(MyWorkshop.WORKSHOP_DEVELOPMENT_TAG)) { userTags.RemoveAll(t => t.Equals(MyWorkshop.WORKSHOP_DEVELOPMENT_TAG, StringComparison.InvariantCultureIgnoreCase)); } #endif // Sanity check, tags, if set, should always have the type if (userTags?.Count == 0) { userTags.Add(m_type.ToString()); } // Done m_tags = userTags.Distinct().ToArray(); }