Beispiel #1
0
        public override string ToString()
        {
            string pzlName = PuzzleName.Contains('\0') ? PuzzleName.Substring(0, PuzzleName.IndexOf('\0')) : PuzzleName;
            string pckName = PackName.Contains('\0') ? PackName.Substring(0, PackName.IndexOf('\0')) : PackName;

            return("Original Puzzle #" + IndexForGui.ToString("D3") + " - " + pckName + " - " + pzlName);
        }
Beispiel #2
0
        public PackOperationsViewModel(string packFilePath)
        {
            FilePath = packFilePath;
            PackName = Path.GetFileName(FilePath);

            var match = Regex.Match(PackName, PackFileTestRegex).Value;

            IsSequenceTargetable = match == PackName;

            if (PackName.Contains("_to_"))
            {
                var matchRegex = @"(_\d+)";
                match = Regex.Match(PackName, matchRegex).Value;
                var toMatch = match.Replace("_", "");

                var packVersion = 0;

                int.TryParse(toMatch, out packVersion);

                PackVersion = packVersion;
                return;
            }

            if (PackName.Contains("full"))
            {
                var matchRegex = @"(\d+_)";
                match = Regex.Match(PackName, matchRegex).Value;
                var fromMatch = match.Replace("_", "");

                var packVersion = 0;

                int.TryParse(fromMatch, out packVersion);

                PackVersion = packVersion;
                return;
            }

            PackVersion = -1;
        }
Beispiel #3
0
        //In C#, the program always starts at Main()
        static void Main(string[] args)
        {
            if (args.Length >= 3)
            {
                string MinecraftPath    = args[0];  //"F:\My Minecraft Expansion\.minecraft"
                string MinecraftJarPath = args[1];  //"C:\Users\zero318\AppData\Roaming\.minecraft\versions\18w50a\18w50a.jar"
                string OutputDirectory  = args[2];  //"F:\My Minecraft Expansion\_BlockRenderTempDirectory"

                string OptionsPath = MinecraftPath + @"\options.txt";

                //The program complains about initializing variables inside a try/catch
                string[] PackList = null;
                try
                {
                    /*
                     * This function is *really* important! Rather than just blindly loading every resource pack in
                     * the folder (because some people like myself have 50 or something stupid), this function loads
                     * the list of currently enabled resource packs directly from Minecraft's options. :D
                     *
                     * The code of the method is located in the ResourcePack class at line 50.
                     */
                    PackList = ResourcePack.GetResourcePacks(OptionsPath).ToArray();
                    //PackList = GetResourcePacks(OptionsPath).Reverse().ToArray();
                }
                catch (TrashMonkeyException e)
                {
                    /*
                     * This prints an error message and then terminates the program. An exit code of 1 is used
                     * so that a calling batch file can tell there was an error.
                     */
                    Console.WriteLine(e.Message);
                    Environment.Exit(1);
                }

                List <ResourcePack> ResourcePacks = new List <ResourcePack>();
                foreach (string PackName in PackList)
                {
                    if (!PackName.StartsWith(@"JAR\"))
                    {
                        ResourcePacks.Add(new ResourcePack(PackName, MinecraftPath));
                    }
                    else
                    {
                        string[] SplitJarPath = MinecraftJarPath.Split('\\');
                        ResourcePacks.Add(new ResourcePack(PackName.Split('\\')[1] + "_" + SplitJarPath[SplitJarPath.Length - 1], MinecraftJarPath));
                    }
                }
                //This list has to be declared outside of the using block so that it can be referenced later
                Dictionary <string, Block> Blocks = new Dictionary <string, Block>();
                foreach (ResourcePack Pack in ResourcePacks)
                {
                    List <Block> PackBlocks = new List <Block>();
                    switch (Pack.Type)
                    {
                    case ResourcePack.PackType.Mod:
                    case ResourcePack.PackType.Jar:
                    case ResourcePack.PackType.Zip:
                        using (ZipArchive ZipFolder = ZipFile.OpenRead(Pack.Path))
                        {
                            IEnumerable <ZipArchiveEntry> BlockStateEntries = ZipFolder.Entries.Where(Entry => Entry.Name.EndsWith(".json") && Entry.FullName.EndsWith(@"blockstates/" + Entry.Name));
                            foreach (ZipArchiveEntry Entry in BlockStateEntries)
                            {
                                try
                                {
                                    PackBlocks.Add(new Block(Entry.Name.Split('.')[0], GetBlockData(Entry.Open())));
                                }
                                catch
                                {
                                    /*
                                     * For some reason Mojang has a crappy blockstate for acacia_wall_sign.
                                     * It has a random 'n' after all the data, which gives my code AIDS
                                     * unless I put it all in a try/catch. :P
                                     */
                                }
                            }
                        }
                        break;

                    case ResourcePack.PackType.Folder:
                        string AssetsPath = Pack.Path + @"\assets";
                        string BlockStatesPath;
                        if (Directory.Exists(AssetsPath))
                        {
                            foreach (string Namespace in Directory.GetDirectories(AssetsPath))
                            {
                                Console.Write("");
                                BlockStatesPath = Namespace + @"\blockstates";
                                if (Directory.Exists(BlockStatesPath))
                                {
                                    foreach (string BlockStateFile in Directory.GetFiles(BlockStatesPath))
                                    {
                                        using (StreamReader sr = new StreamReader(BlockStateFile))
                                        {
                                            try
                                            {
                                                PackBlocks.Add(new Block(BlockStateFile.Split('\\').Reverse().ToArray()[0].Split('.')[0], GetBlockData(sr.BaseStream)));
                                                Console.Write("");
                                            }
                                            catch
                                            {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    Console.Write("");
                    foreach (Block block in PackBlocks)
                    {
                        Blocks[block.Name] = block;
                    }
                }

                foreach (Block block in Blocks.Values)
                {
                    Console.WriteLine(block.Name);
                    foreach (BlockState State in block.BlockStates)
                    {
                        Console.WriteLine(State.Name);
                        foreach (ModelReference Model in State.Models)
                        {
                            Console.WriteLine(Model.ModelData["model"]);
                        }
                    }
                }

                Console.WriteLine();
                Console.WriteLine("Done");
                while (true)
                {
                }
            }
            else
            {
                Console.WriteLine("Command line arguments:");
                Console.WriteLine("1. Location of .minecraft");
                Console.WriteLine("2. Location of Minecraft .jar");
                Console.WriteLine("3. Output Directory");
            }
            //Console.WriteLine();
            //Console.WriteLine("Done");
            //while (true)
            //{

            //}
        }