public static void init(LanguageType languageType) { items = new Dictionary <string, Dictionary <string, string> >(); items2 = new Dictionary <string, Dictionary <string, Dictionary <string, string> > >(); string name = "app:lang/" + languageType.ToString() + ".json"; List <FileEntry> langs = ModsManager.GetEntries(".json"); try {//没有找到文件,加载默认 Stream ssa = Storage.OpenFile(name, OpenFileMode.Read); loadJson(ssa); foreach (FileEntry entry in langs) { string filename = Storage.GetFileName(entry.Filename); if (filename.StartsWith(languageType.ToString())) { //加载该语言包 loadJson(entry.Stream); break; } } } catch { loadJson(Storage.OpenFile("app:lang/" + LanguageType.zh_CN.ToString() + ".json", OpenFileMode.Read)); foreach (FileEntry entry in langs) { string filename = Storage.GetFileName(entry.Filename); if (filename.StartsWith(LanguageType.zh_CN.ToString())) { //加载该语言包 loadJson(entry.Stream); break; } } } }
public static void Initialize() { Directory.CreateDirectory(Path = #if ENV_ANDROID #if Survivalcraft //ModsManager.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Survivalcraft/Mods")) //ModsManager.Combine(((AndroidSdCardExternalContentProvider)ExternalContentManager.m_providers).m_rootDirectory, "Survivalcraft/Mods")) //ModsManager.Combine(Storage.GetDirectoryName(Window.Activity.GetExternalFilesDir(Environment.DirectoryPictures).AbsolutePath), "Survivalcraft/Mods")) "/sdcard/Survivalcraft/Mods" #elif Bugs "/sdcard/Bugs/Mods" #else "/sdcard/RuthlessConquest/Mods" #endif #elif USE_DATA_PATH Storage.GetSystemPath("data:Mods") #else "Mods" #endif ); ModsManager.Initialize(); ContentCache.AddPackage(Storage.OpenFile("app:Content.pak", OpenFileMode.Read)); for (var enumerator = ModsManager.GetEntries(".pak").GetEnumerator(); enumerator.MoveNext();) { ContentCache.AddPackage(enumerator.Current.Stream); } }
public static Stream GetTargetFile(string name, bool throwIfNotFound = true) { for (var enumerator = ModsManager.GetEntries(Storage.GetExtension(name)).GetEnumerator(); enumerator.MoveNext();) { if (string.Equals(Path.GetFileName(enumerator.Current.Filename), name, StringComparison.OrdinalIgnoreCase)) { return(enumerator.Current.Stream); } } if (throwIfNotFound) { throw new InvalidOperationException(name + " not found."); } return(null); }
public static void Initialize() { ModsManager.Initialize(); ContentCache.AddPackage("app:/Content.pak", Encoding.UTF8.GetBytes(Pad()), new byte[1] { 63 }); LanguageControl.init(ModsManager.modSettings.languageType); List <FileEntry> .Enumerator enumerator = ModsManager.GetEntries(".pak").GetEnumerator(); while (enumerator.MoveNext()) { ContentCache.AddPackage(() => enumerator.Current.Stream, Encoding.UTF8.GetBytes(Pad()), new byte[1] { 63 }); } }
public static void Initialize() { if (m_gameDatabase == null) { XElement node = ContentManager.Get <XElement>("Database"); ContentManager.Dispose("Database"); ModsManager.CombineXml(node, ModsManager.GetEntries(".xdb"), "Guid", "Name"); m_gameDatabase = new GameDatabase(XmlDatabaseSerializer.LoadDatabase(node)); foreach (DatabaseObject explicitNestingChild in GameDatabase.Database.Root.GetExplicitNestingChildren(GameDatabase.EntityTemplateType, directChildrenOnly: false)) { ValuesDictionary valuesDictionary = new ValuesDictionary(); valuesDictionary.PopulateFromDatabaseObject(explicitNestingChild); m_valueDictionaries.Add(explicitNestingChild.Name, valuesDictionary); } return; } throw new InvalidOperationException("Database already loaded."); }
public override void Initialize() { if (Initialize1 != null) { Initialize1(); return; } int num = 0; Dictionary <int, ClothingData> dictionary = new Dictionary <int, ClothingData>(); IEnumerator <XElement> enumerator = ModsManager.CombineXml(ContentManager.Get <XElement>("Clothes"), ModsManager.GetEntries(".clo"), "Index", "Clothes").Elements().GetEnumerator(); while (enumerator.MoveNext()) { XElement item = enumerator.Current; string newDescription = LanguageControl.GetBlock(string.Format("{0}:{1}", GetType().Name, Index), "Description"); string newDisplayName = LanguageControl.GetBlock(string.Format("{0}:{1}", GetType().Name, Index), "DisplayName"); if (item.Attribute("DisplayName") != null && item.Attribute("Description") != null) { newDisplayName = XmlUtils.GetAttributeValue <string>(item, "DisplayName"); newDescription = XmlUtils.GetAttributeValue <string>(item, "Description"); } ClothingData clothingData = new ClothingData { Index = XmlUtils.GetAttributeValue <int>(item, "Index"), DisplayIndex = num++, DisplayName = newDisplayName, Slot = XmlUtils.GetAttributeValue <ClothingSlot>(item, "Slot"), ArmorProtection = XmlUtils.GetAttributeValue <float>(item, "ArmorProtection"), Sturdiness = XmlUtils.GetAttributeValue <float>(item, "Sturdiness"), Insulation = XmlUtils.GetAttributeValue <float>(item, "Insulation"), MovementSpeedFactor = XmlUtils.GetAttributeValue <float>(item, "MovementSpeedFactor"), SteedMovementSpeedFactor = XmlUtils.GetAttributeValue <float>(item, "SteedMovementSpeedFactor"), DensityModifier = XmlUtils.GetAttributeValue <float>(item, "DensityModifier"), IsOuter = XmlUtils.GetAttributeValue <bool>(item, "IsOuter"), CanBeDyed = XmlUtils.GetAttributeValue <bool>(item, "CanBeDyed"), Layer = XmlUtils.GetAttributeValue <int>(item, "Layer"), PlayerLevelRequired = XmlUtils.GetAttributeValue <int>(item, "PlayerLevelRequired"), Texture = ContentManager.Get <Texture2D>(XmlUtils.GetAttributeValue <string>(item, "TextureName")), ImpactSoundsFolder = XmlUtils.GetAttributeValue <string>(item, "ImpactSoundsFolder"), Description = newDescription }; dictionary.Add(clothingData.Index, clothingData); } m_clothingData = new ClothingData[dictionary.Count]; for (int i = 0; i < dictionary.Count; i++) { m_clothingData[i] = dictionary[i]; } Model playerModel = CharacterSkinsManager.GetPlayerModel(PlayerClass.Male); Matrix[] array = new Matrix[playerModel.Bones.Count]; playerModel.CopyAbsoluteBoneTransformsTo(array); int index = playerModel.FindBone("Hand1").Index; int index2 = playerModel.FindBone("Hand2").Index; array[index] = Matrix.CreateRotationY(0.1f) * array[index]; array[index2] = Matrix.CreateRotationY(-0.1f) * array[index2]; m_innerMesh = new BlockMesh(); foreach (ModelMesh mesh in playerModel.Meshes) { Matrix matrix = array[mesh.ParentBone.Index]; foreach (ModelMeshPart meshPart in mesh.MeshParts) { Color color = Color.White * 0.8f; color.A = byte.MaxValue; m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_innerMesh.AppendModelMeshPart(meshPart, matrix, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color); } } Model outerClothingModel = CharacterSkinsManager.GetOuterClothingModel(PlayerClass.Male); Matrix[] array2 = new Matrix[outerClothingModel.Bones.Count]; outerClothingModel.CopyAbsoluteBoneTransformsTo(array2); int index3 = outerClothingModel.FindBone("Leg1").Index; int index4 = outerClothingModel.FindBone("Leg2").Index; array2[index3] = Matrix.CreateTranslation(-0.02f, 0f, 0f) * array2[index3]; array2[index4] = Matrix.CreateTranslation(0.02f, 0f, 0f) * array2[index4]; m_outerMesh = new BlockMesh(); foreach (ModelMesh mesh2 in outerClothingModel.Meshes) { Matrix matrix2 = array2[mesh2.ParentBone.Index]; foreach (ModelMeshPart meshPart2 in mesh2.MeshParts) { Color color2 = Color.White * 0.8f; color2.A = byte.MaxValue; m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: false, doubleSided: false, flipNormals: false, Color.White); m_outerMesh.AppendModelMeshPart(meshPart2, matrix2, makeEmissive: false, flipWindingOrder: true, doubleSided: false, flipNormals: true, color2); } } base.Initialize(); }
// Replace ClothingBlock.Initialize public override void Initialize() { var num = 0; var dictionary = new Dictionary <int, ClothingData>(); for (var i = ContentManager.CombineXml(ContentManager.Get <XElement>("Clothes"), ModsManager.GetEntries(".clo"), "Index", "DisplayName", "Clothes").Elements().GetEnumerator(); i.MoveNext();) { var element = i.Current; var clothingData = new ClothingData { Index = XmlUtils.GetAttributeValue <int>(element, "Index"), DisplayIndex = num++, DisplayName = XmlUtils.GetAttributeValue <string>(element, "DisplayName"), Slot = XmlUtils.GetAttributeValue <ClothingSlot>(element, "Slot"), ArmorProtection = XmlUtils.GetAttributeValue <float>(element, "ArmorProtection"), Sturdiness = XmlUtils.GetAttributeValue <float>(element, "Sturdiness"), Insulation = XmlUtils.GetAttributeValue <float>(element, "Insulation"), MovementSpeedFactor = XmlUtils.GetAttributeValue <float>(element, "MovementSpeedFactor"), SteedMovementSpeedFactor = XmlUtils.GetAttributeValue <float>(element, "SteedMovementSpeedFactor"), DensityModifier = XmlUtils.GetAttributeValue <float>(element, "DensityModifier"), IsOuter = XmlUtils.GetAttributeValue <bool>(element, "IsOuter"), CanBeDyed = XmlUtils.GetAttributeValue <bool>(element, "CanBeDyed"), Layer = XmlUtils.GetAttributeValue <int>(element, "Layer"), PlayerLevelRequired = XmlUtils.GetAttributeValue <int>(element, "PlayerLevelRequired"), Texture = ContentManager.Get <Texture2D>(XmlUtils.GetAttributeValue <string>(element, "TextureName")), ImpactSoundsFolder = XmlUtils.GetAttributeValue <string>(element, "ImpactSoundsFolder"), Description = XmlUtils.GetAttributeValue <string>(element, "Description") }; dictionary[clothingData.Index] = clothingData; } m_clothingData = new ClothingData[dictionary.Count]; int index; for (index = 0; index < dictionary.Count; ++index) { m_clothingData[index] = dictionary[index]; } var playerModel = CharacterSkinsManager.GetPlayerModel(PlayerClass.Male); var absoluteTransforms1 = new Matrix[playerModel.Bones.Count]; playerModel.CopyAbsoluteBoneTransformsTo(absoluteTransforms1); index = playerModel.FindBone("Hand1", true).Index; int index2 = playerModel.FindBone("Hand2", true).Index; absoluteTransforms1[index] = Matrix.CreateRotationY(0.1f) * absoluteTransforms1[index]; absoluteTransforms1[index2] = Matrix.CreateRotationY(-0.1f) * absoluteTransforms1[index2]; m_innerMesh = new BlockMesh(); foreach (var mesh in playerModel.Meshes) { var matrix = absoluteTransforms1[mesh.ParentBone.Index]; foreach (var meshPart in mesh.MeshParts) { var color = Color.White * 0.8f; color.A = byte.MaxValue; m_innerMesh.AppendModelMeshPart(meshPart, matrix, false, false, false, false, Color.White); m_innerMesh.AppendModelMeshPart(meshPart, matrix, false, true, false, true, color); } } var outerClothingModel = CharacterSkinsManager.GetOuterClothingModel(PlayerClass.Male); var absoluteTransforms2 = new Matrix[outerClothingModel.Bones.Count]; outerClothingModel.CopyAbsoluteBoneTransformsTo(absoluteTransforms2); var index3 = outerClothingModel.FindBone("Leg1", true).Index; var index4 = outerClothingModel.FindBone("Leg2", true).Index; absoluteTransforms2[index3] = Matrix.CreateTranslation(-0.02f, 0.0f, 0.0f) * absoluteTransforms2[index3]; absoluteTransforms2[index4] = Matrix.CreateTranslation(0.02f, 0.0f, 0.0f) * absoluteTransforms2[index4]; m_outerMesh = new BlockMesh(); foreach (var mesh in outerClothingModel.Meshes) { var matrix = absoluteTransforms2[mesh.ParentBone.Index]; foreach (var meshPart in mesh.MeshParts) { var color = Color.White * 0.8f; color.A = byte.MaxValue; m_outerMesh.AppendModelMeshPart(meshPart, matrix, false, false, false, false, Color.White); m_outerMesh.AppendModelMeshPart(meshPart, matrix, false, true, false, true, color); } } base.Initialize(); }
public static void Initialize() { if (Initialize1 != null) { Initialize1(); return; } XElement source1 = ContentManager.Get <XElement>("CraftingRecipes"); ModsManager.CombineXml(source1, ModsManager.GetEntries(".cr"), "Description", "Result", "Recipes"); IEnumerable <XElement> source2 = source1.Descendants("Recipe"); foreach (XElement item in source2) { CraftingRecipe craftingRecipe = new CraftingRecipe(); string attributeValue = XmlUtils.GetAttributeValue <string>(item, "Result"); string desc = LanguageControl.GetBlock(attributeValue, "CRDescription"); if (item.Attribute("Description") != null) { desc = XmlUtils.GetAttributeValue <string>(item, "Description"); } craftingRecipe.ResultValue = DecodeResult(attributeValue); craftingRecipe.ResultCount = XmlUtils.GetAttributeValue <int>(item, "ResultCount"); string attributeValue2 = XmlUtils.GetAttributeValue(item, "Remains", string.Empty); if (!string.IsNullOrEmpty(attributeValue2)) { craftingRecipe.RemainsValue = DecodeResult(attributeValue2); craftingRecipe.RemainsCount = XmlUtils.GetAttributeValue <int>(item, "RemainsCount"); } craftingRecipe.RequiredHeatLevel = XmlUtils.GetAttributeValue <float>(item, "RequiredHeatLevel"); craftingRecipe.RequiredPlayerLevel = XmlUtils.GetAttributeValue(item, "RequiredPlayerLevel", 1f); craftingRecipe.Description = desc; craftingRecipe.Message = XmlUtils.GetAttributeValue <string>(item, "Message", null); if (craftingRecipe.ResultCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.ResultValue)].MaxStacking) { throw new InvalidOperationException($"In recipe for \"{attributeValue}\" ResultCount is larger than max stacking of result block."); } if (craftingRecipe.RemainsValue != 0 && craftingRecipe.RemainsCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.RemainsValue)].MaxStacking) { throw new InvalidOperationException($"In Recipe for \"{attributeValue2}\" RemainsCount is larger than max stacking of remains block."); } Dictionary <char, string> dictionary = new Dictionary <char, string>(); foreach (XAttribute item2 in from a in item.Attributes() where a.Name.LocalName.Length == 1 && char.IsLower(a.Name.LocalName[0]) select a) { DecodeIngredient(item2.Value, out string craftingId, out int?data); if (BlocksManager.FindBlocksByCraftingId(craftingId).Length == 0) { throw new InvalidOperationException($"Block with craftingId \"{item2.Value}\" not found."); } if (data.HasValue && (data.Value < 0 || data.Value > 262143)) { throw new InvalidOperationException($"Data in recipe ingredient \"{item2.Value}\" must be between 0 and 0x3FFFF."); } dictionary.Add(item2.Name.LocalName[0], item2.Value); } string[] array = item.Value.Trim().Split(new string[] { "\n" }, StringSplitOptions.None); for (int i = 0; i < array.Length; i++) { int num = array[i].IndexOf('"'); int num2 = array[i].LastIndexOf('"'); if (num < 0 || num2 < 0 || num2 <= num) { throw new InvalidOperationException("Invalid recipe line."); } string text = array[i].Substring(num + 1, num2 - num - 1); for (int j = 0; j < text.Length; j++) { char c = text[j]; if (char.IsLower(c)) { string text2 = dictionary[c]; craftingRecipe.Ingredients[j + i * 3] = text2; } } } m_recipes.Add(craftingRecipe); } Block[] blocks = BlocksManager.Blocks; foreach (Block block in blocks) { m_recipes.AddRange(block.GetProceduralCraftingRecipes()); } m_recipes.Sort(delegate(CraftingRecipe r1, CraftingRecipe r2) { int y = r1.Ingredients.Count((string s) => !string.IsNullOrEmpty(s)); int x = r2.Ingredients.Count((string s) => !string.IsNullOrEmpty(s)); return(Comparer <int> .Default.Compare(x, y)); }); }
public static void Initialize() { m_recipes = new List <CraftingRecipe>(); for (var i = ContentManager.CombineXml(ContentManager.Get <XElement>("CraftingRecipes"), ModsManager.GetEntries(".cr"), "Description", "Result", "Recipes").Descendants("Recipe").GetEnumerator(); i.MoveNext();) { var descendant = i.Current; var recipe = new CraftingRecipe(); var attributeValue1 = XmlUtils.GetAttributeValue <string>(descendant, "Result"); recipe.ResultValue = DecodeResult(attributeValue1); recipe.ResultCount = XmlUtils.GetAttributeValue <int>(descendant, "ResultCount"); var attributeValue2 = XmlUtils.GetAttributeValue(descendant, "Remains", string.Empty); if (!string.IsNullOrEmpty(attributeValue2)) { recipe.RemainsValue = DecodeResult(attributeValue2); recipe.RemainsCount = XmlUtils.GetAttributeValue <int>(descendant, "RemainsCount"); } recipe.RequiredHeatLevel = XmlUtils.GetAttributeValue <float>(descendant, "RequiredHeatLevel"); recipe.Description = XmlUtils.GetAttributeValue <string>(descendant, "Description"); if (recipe.ResultCount > BlocksManager.Blocks[Terrain.ExtractContents(recipe.ResultValue)].MaxStacking) { throw new InvalidOperationException(string.Format( "In recipe for \"{0}\" ResultCount is larger than max stacking of result block.", new object[1] { attributeValue1 })); } if (recipe.RemainsValue != 0 && recipe.RemainsCount > BlocksManager.Blocks[Terrain.ExtractContents(recipe.RemainsValue)].MaxStacking) { throw new InvalidOperationException(string.Format( "In Recipe for \"{0}\" RemainsCount is larger than max stacking of remains block.", new object[1] { attributeValue2 })); } var dictionary = new Dictionary <char, string>(); foreach (var xattribute in descendant.Attributes().Where(a => a.Name.LocalName.Length == 1 && char.IsLower(a.Name.LocalName[0]))) { string craftingId; int? data; DecodeIngredient(xattribute.Value, out craftingId, out data); if (BlocksManager.FindBlocksByCraftingId(craftingId).Length == 0) { throw new InvalidOperationException(string.Format("Block with craftingId \"{0}\" not found.", new object[1] { xattribute.Value })); } if (data.HasValue && (data.Value < 0 || data.Value > 262143)) { throw new InvalidOperationException(string.Format( "Data in recipe ingredient \"{0}\" must be between 0 and 0x3FFFF.", new object[1] { xattribute.Value })); } dictionary.Add(xattribute.Name.LocalName[0], xattribute.Value); } var strArray = descendant.Value.Trim().Split('\n'); for (var index1 = 0; index1 < strArray.Length; ++index1) { var num1 = strArray[index1].IndexOf('"'); var num2 = strArray[index1].LastIndexOf('"'); if (num1 < 0 || num2 < 0 || num2 <= num1) { throw new InvalidOperationException("Invalid recipe line."); } var str1 = strArray[index1].Substring(num1 + 1, num2 - num1 - 1); for (var index2 = 0; index2 < str1.Length; ++index2) { var c = str1[index2]; if (char.IsLower(c)) { recipe.Ingredients[index2 + index1 * 3] = dictionary[c]; } } } m_recipes.Add(recipe); } var blocks = BlocksManager.Blocks; for (int i = 0; i < blocks.Length; i++) { m_recipes.AddRange(blocks[i].GetProceduralCraftingRecipes()); } m_recipes.Sort((r1, r2) => { return(Comparer <int> .Default.Compare(r2.Ingredients.Count(s => !string.IsNullOrEmpty(s)), r1.Ingredients.Count(s => !string.IsNullOrEmpty(s)))); }); }
public static void Initialize() { if (Initialize1 != null) { Initialize1(); return; } CalculateSlotTexCoordTables(); int num = 0; Dictionary <int, Block> dictionary = new Dictionary <int, Block>(); IEnumerable <TypeInfo> jl = GetBlockTypes(); foreach (TypeInfo blockType in jl) { if (blockType.IsSubclassOf(typeof(Block)) && !blockType.IsAbstract) { FieldInfo fieldInfo = blockType.AsType().GetRuntimeFields().FirstOrDefault(c._.Initialize_b__11_0); if (!(fieldInfo != null) || !(fieldInfo.FieldType == typeof(int))) { throw new InvalidOperationException($"Block type \"{blockType.FullName}\" does not have static field Index of type int."); } int num2 = (int)fieldInfo.GetValue(null); Block block = (Block)Activator.CreateInstance(blockType.AsType()); dictionary[block.BlockIndex = num2] = block; if (num2 > num) { num = num2; } } } m_blocks = new Block[num + 1]; m_fluidBlocks = new FluidBlock[num + 1]; foreach (KeyValuePair <int, Block> current2 in dictionary) { m_blocks[current2.Key] = current2.Value; //添加普通方块 m_fluidBlocks[current2.Key] = (current2.Value as FluidBlock); //添加流体方块 } for (num = 0; num < m_blocks.Length; num++) { if (m_blocks[num] == null) { m_blocks[num] = Blocks[0]; } } string data = ContentManager.Get <string>("BlocksData"); ContentManager.Dispose("BlocksData"); LoadBlocksData(data); List <FileEntry> blocklist = ModsManager.GetEntries(".csv"); foreach (FileEntry file in blocklist) { file.Stream.Position = 0L; StreamReader reader = new StreamReader(file.Stream); string text = reader.ReadToEnd(); LoadBlocksData(text); } Block[] blocks = Blocks; for (int j = 0; j < blocks.Length; j++) { blocks[j].Initialize(); } m_categories.Add(LanguageControl.Get("BlocksManager", "Terrain")); m_categories.Add(LanguageControl.Get("BlocksManager", "Plants")); m_categories.Add(LanguageControl.Get("BlocksManager", "Construction")); m_categories.Add(LanguageControl.Get("BlocksManager", "Items")); m_categories.Add(LanguageControl.Get("BlocksManager", "Tools")); m_categories.Add(LanguageControl.Get("BlocksManager", "Weapons")); m_categories.Add(LanguageControl.Get("BlocksManager", "Clothes")); m_categories.Add(LanguageControl.Get("BlocksManager", "Electrics")); m_categories.Add(LanguageControl.Get("BlocksManager", "Food")); m_categories.Add(LanguageControl.Get("BlocksManager", "Spawner Eggs")); m_categories.Add(LanguageControl.Get("BlocksManager", "Painted")); m_categories.Add(LanguageControl.Get("BlocksManager", "Dyed")); m_categories.Add(LanguageControl.Get("BlocksManager", "Fireworks")); blocks = Blocks; foreach (Block block2 in blocks) { foreach (int creativeValue in block2.GetCreativeValues()) { string category = block2.GetCategory(creativeValue); if (!m_categories.Contains(category)) { m_categories.Add(category); } } } }
public static void Initialize() { CalculateSlotTexCoordTables(); int i = 0; var dictionary = new Dictionary <int, Block>(); foreach (var definedType in GetBlockTypes()) { if (definedType.IsSubclassOf(typeof(Block)) && !definedType.IsAbstract) { var fieldInfo = definedType.AsType().GetRuntimeFields().FirstOrDefault(fi => { if (fi.Name == "Index" && fi.IsPublic) { return(fi.IsStatic); } return(false); }); if (fieldInfo != null && fieldInfo.FieldType == typeof(int)) { var num = (int)fieldInfo.GetValue(null); // Removed 'Index of block type \"{0}\" conflicts with another block' error var instance = (Block)Activator.CreateInstance(definedType.AsType()); dictionary[instance.BlockIndex = num] = instance; if (num > i) { i = num; } } else { throw new InvalidOperationException(string.Format( "Block type \"{0}\" does not have static field Index of type int.", new object[1] { definedType.FullName })); } } } m_blocks = new Block[i + 1]; m_fluidBlocks = new FluidBlock[i + 1]; for (var e = dictionary.GetEnumerator(); e.MoveNext();) { var keyValuePair = e.Current; m_blocks[keyValuePair.Key] = keyValuePair.Value; m_fluidBlocks[keyValuePair.Key] = keyValuePair.Value as FluidBlock; } for (i = 0; i < m_blocks.Length; ++i) { if (m_blocks[i] == null) { m_blocks[i] = Blocks[0]; } } var data = ContentManager.Get <string>("BlocksData"); ContentManager.Dispose("BlocksData"); LoadBlocksData(data); var enumerator = ModsManager.GetEntries(".csv").GetEnumerator(); while (enumerator.MoveNext()) { var reader = new StreamReader(enumerator.Current.Stream); try { LoadBlocksData(reader.ReadToEnd()); } catch (Exception e) { ModsManager.ErrorHandler(enumerator.Current, e); } finally { reader.Dispose(); } } i = 0; for (int length = Blocks.Length; i < length; i++) { Blocks[i].Initialize(); } m_categories.Add("Terrain"); m_categories.Add("Plants"); m_categories.Add("Construction"); m_categories.Add("Items"); m_categories.Add("Tools"); m_categories.Add("Clothes"); m_categories.Add("Electrics"); m_categories.Add("Food"); m_categories.Add("Spawner Eggs"); m_categories.Add("Painted"); m_categories.Add("Dyed"); m_categories.Add("Fireworks"); for (i = 0; i < Blocks.Length; i++) { var block = Blocks[i]; for (var j = block.GetCreativeValues().GetEnumerator(); j.MoveNext();) { var category = block.GetCategory(j.Current); if (!m_categories.Contains(category)) { m_categories.Add(category); } } } }
public static void LoadStrings() { m_strings = new Dictionary <string, string>(); for (var i = ContentManager.CombineXml(ContentManager.Get <XElement>("Strings"), ModsManager.GetEntries(".str"), null, "Name", "Strings").Elements().GetEnumerator(); i.MoveNext();) { m_strings.Add(XmlUtils.GetAttributeValue <string>(i.Current, "Name"), i.Current.Value.Replace("\\n", "\n")); } }
public void init() { bool isNewBlock = false; foreach (ModInfo modInfo in ModsManager.LoadedMods) { if (modInfo.Name == "NewBlocks_SC") { isNewBlock = true; is_NewSC = true; } } if (isNewBlock) { XElement item = ModsManager.CombineXml(new XElement("NewBlocks"), ModsManager.GetEntries(".xjdb")); foreach (XElement element in item.Elements()) { foreach (XElement element1 in element.Elements()) { if (!newblockcrafts.ContainsKey(element1.Attribute("DisplayName").Value)) { newblockcrafts.Add(element1.Attribute("DisplayName").Value, element1.Attribute("CraftingId").Value); } } } } int k = 0; values.Add(0); blocks.Add(BlocksManager.Blocks[0]); names.Add("空气"); craftids.Add("空气"); foreach (Block block in BlocksManager.Blocks) { foreach (int cv in block.GetCreativeValues()) { //添加所有方块 if (cv == 0) { continue; } if (values.Contains(cv)) { continue; } string ll = block.GetDisplayName(null, cv); if (XjJeiManager.is_NewSC && ModsManager.customer_Strings.ContainsKey(ll)) { ll = ModsManager.customer_Strings[ll]; } if (string.IsNullOrEmpty(ll)) { continue; } if (block.GetCategory(cv) == "Painted") { continue; } if (isNewBlock) { if (newblockcrafts.TryGetValue(ll, out string namm)) { craftids.Add(namm); } else { craftids.Add(block.CraftingId); } } else { craftids.Add(block.CraftingId); } values.Add(cv); blocks.Add(block); names.Add(ll); k += 1; } } }
public static void CRInitialize() { CraftingRecipesManager.m_recipes = new List <CraftingRecipe>(); var recipes = new List <CraftingRecipe>(); var enumerator = ContentManager.CombineXml(ContentManager.Get <XElement>("CraftingRecipes"), ModsManager.GetEntries(".cr"), "Description", "Result", "Recipes").Descendants("Recipe").GetEnumerator(); while (enumerator.MoveNext()) { XElement xelement = enumerator.Current; var craftingRecipe = new CraftingRecipe { Ingredients = new string[36] }; string attributeValue = XmlUtils.GetAttributeValue <string>(xelement, "Result"); craftingRecipe.ResultValue = CraftingRecipesManager.DecodeResult(attributeValue); craftingRecipe.ResultCount = XmlUtils.GetAttributeValue <int>(xelement, "ResultCount"); string attributeValue2 = XmlUtils.GetAttributeValue(xelement, "Remains", string.Empty); if (!string.IsNullOrEmpty(attributeValue2)) { craftingRecipe.RemainsValue = CraftingRecipesManager.DecodeResult(attributeValue2); craftingRecipe.RemainsCount = XmlUtils.GetAttributeValue <int>(xelement, "RemainsCount"); } craftingRecipe.RequiredHeatLevel = XmlUtils.GetAttributeValue <float>(xelement, "RequiredHeatLevel"); craftingRecipe.Description = XmlUtils.GetAttributeValue <string>(xelement, "Description"); if (craftingRecipe.ResultCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.ResultValue)].MaxStacking) { throw new InvalidOperationException($"In recipe for \"{attributeValue}\" ResultCount is larger than max stacking of result block."); } if (craftingRecipe.RemainsValue != 0 && craftingRecipe.RemainsCount > BlocksManager.Blocks[Terrain.ExtractContents(craftingRecipe.RemainsValue)].MaxStacking) { throw new InvalidOperationException($"In Recipe for \"{attributeValue2}\" RemainsCount is larger than max stacking of remains block."); } var dictionary = new Dictionary <char, string>(); foreach (XAttribute item in xelement.Attributes().Where(CraftingRecipesManager.c._.Initialize_b__3_1)) { CraftingRecipesManager.DecodeIngredient(item.Value, out string craftingId, out int?data); if (BlocksManager.FindBlocksByCraftingId(craftingId).Length == 0) { throw new InvalidOperationException($"Block with craftingId \"{item.Value}\" not found."); } if (data.HasValue && (data.Value < 0 || data.Value > 262143)) { throw new InvalidOperationException($"Data in recipe ingredient \"{item.Value}\" must be between 0 and 0x3FFFF."); } dictionary.Add(item.Name.LocalName[0], item.Value); } string[] array = xelement.Value.Trim().Split('\n'); string[] ingredients = craftingRecipe.Ingredients; for (int i = 0; i < array.Length; i++) { int num2 = array[i].IndexOf('"'); int num3 = array[i].LastIndexOf('"'); if (num2 < 0 || num3 < 0 || num3 <= num2) { throw new InvalidOperationException("Invalid recipe line."); } string text = array[i].Substring(num2 + 1, num3 - num2 - 1); for (int j = 0; j < text.Length; j++) { char c = text[j]; if (char.IsLower(c)) { string text2 = dictionary[c]; if (ItemBlock.IdTable.TryGetValue(text2, out int value)) { text2 = BlocksManager.Blocks[Terrain.ExtractContents(value)].CraftingId + ":" + Terrain.ExtractData(value); } ingredients[j + i * 6] = text2; } } } CraftingRecipesManager.m_recipes.Add(craftingRecipe); if (craftingRecipe.RequiredHeatLevel >= 300f) { CraftingRecipesManager.DecodeIngredient(ingredients[0], out string craftingId, out int?num); if (!num.HasValue) { continue; } recipes.Add(new CraftingRecipe { ResultValue = Terrain.ReplaceData(BlocksManager.FindBlocksByCraftingId(craftingId)[0].BlockIndex, num.Value), ResultCount = GetCount(ingredients), RemainsValue = craftingRecipe.RemainsValue, RemainsCount = craftingRecipe.RemainsCount, RequiredHeatLevel = 1f, Ingredients = (string[])ingredients.Clone(), Description = craftingRecipe.Description + Utils.Get(" (温度过低)") }); } } var blocks = BlocksManager.Blocks; for (int i = 0; i < blocks.Length; i++) { using (var enumerator2 = blocks[i].GetProceduralCraftingRecipes().GetEnumerator()) while (enumerator2.MoveNext()) { var old = enumerator2.Current.Ingredients; if (old.Length == 9) { var ingredients = new string[36]; ingredients[0] = old[0]; ingredients[1] = old[1]; ingredients[2] = old[2]; ingredients[6] = old[3]; ingredients[7] = old[4]; ingredients[8] = old[5]; ingredients[12] = old[6]; ingredients[13] = old[7]; ingredients[14] = old[8]; enumerator2.Current.Ingredients = ingredients; } CraftingRecipesManager.m_recipes.Add(enumerator2.Current); } } CraftingRecipesManager.m_recipes.Sort(CraftingRecipesManager.c._.Initialize_b__3_0); CraftingRecipesManager.m_recipes.AddRange(recipes); }
public HelpScreen() { WidgetsManager.LoadWidgetContents(this, this, ContentManager.Get <XElement>("Screens/HelpScreen")); m_topicsList = Children.Find <ListPanelWidget>("TopicsList", true); m_recipaediaButton = Children.Find <ButtonWidget>("RecipaediaButton", true); m_bestiaryButton = Children.Find <ButtonWidget>("BestiaryButton", true); m_topicsList.ItemWidgetFactory = delegate(object item) { var helpTopic3 = (HelpTopic)item; XElement node2 = ContentManager.Get <XElement>("Widgets/HelpTopicItem"); var obj = (ContainerWidget)WidgetsManager.LoadWidget(this, node2, null); obj.Children.Find <LabelWidget>("HelpTopicItem.Title", true).Text = helpTopic3.Title; return(obj); }; m_topicsList.ItemClicked += delegate(object item) { if (item is HelpTopic helpTopic2) { ShowTopic(helpTopic2); } }; for (var i = ContentManager.CombineXml(ContentManager.Get <XElement>("Help"), ModsManager.GetEntries(".hlp"), "Title", "Name", "Topic").Elements().GetEnumerator(); i.MoveNext();) { var element = i.Current; var strArray = XmlUtils.GetAttributeValue(element, "DisabledPlatforms", string.Empty).Split(','); if (strArray.FirstOrDefault(Match) == null) { var attributeValue1 = XmlUtils.GetAttributeValue(element, "Name", string.Empty); var attributeValue2 = XmlUtils.GetAttributeValue <string>(element, "Title"); var str1 = string.Empty; strArray = element.Value.Split('\n'); for (int i1 = 0; i1 < strArray.Length; i1++) { str1 = str1 + strArray[i1].Trim() + " "; } var helpTopic = new HelpTopic { Name = attributeValue1, Title = attributeValue2, Text = str1.Replace("\r", "").Replace("’", "'").Replace("\\n", "\n") }; if (!string.IsNullOrEmpty(helpTopic.Name)) { m_topics.Add(helpTopic.Name, helpTopic); } m_topicsList.AddItem(helpTopic); } } }