Exemple #1
0
        public bool SaveNewEncodedFile()
        {
            if (this.CurrentMap.HasErrors)
            {
                MessageBox.Show($"Map contains errors, please find and resolve with View > Errors before saving.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }

            var saveFileDialog = new CommonSaveFileDialog
            {
                RestoreDirectory   = false,
                InitialDirectory   = Directory.GetCurrentDirectory() + "\\data\\",
                DefaultExtension   = "she",
                NavigateToShortcut = true,
                OverwritePrompt    = true,
                DefaultFileName    = Path.GetFileName(this.LoadedMapPath),
                Title = "Save .she"
            };

            saveFileDialog.Filters.Add(new CommonFileDialogFilter("Encoded Map File", "*.she"));
            saveFileDialog.Filters.Add(new CommonFileDialogFilter("All Files", "*.*"));

            var dialogSuccess = saveFileDialog.ShowDialog();

            if (dialogSuccess == CommonFileDialogResult.Ok)
            {
                TCDEncodeDecode.SaveFile(saveFileDialog.FileName, TCDEncodeDecode.EncodeMap(this.CurrentMap.StringValue));
                this.LoadedMapPath = saveFileDialog.FileName;
                this.LastLoadedMap = (Map)this.CurrentMap.Clone();

                return(true);
            }

            return(false);
        }
Exemple #2
0
        public void PackTCD()
        {
            var folderBrowserDialog = new CommonOpenFileDialog
            {
                RestoreDirectory = false,
                InitialDirectory = Directory.GetCurrentDirectory(),
                IsFolderPicker   = true,
                EnsureFileExists = true,
                Title            = "Pack Folder into .tcd"
            };

            var folderBrowserDialogSuccess = folderBrowserDialog.ShowDialog();

            if (folderBrowserDialogSuccess == CommonFileDialogResult.Ok)
            {
                var fileBase = new DirectoryInfo(Path.GetFullPath(folderBrowserDialog.FileName)).Name;
                TCDEncodeDecode.PackTCDFile(
                    folderBrowserDialog.FileName,
                    fileBase,
                    (fileName, progress) =>
                {
                    this.ProgressStatus = fileName;
                    this.Progress       = progress;
                });
            }
        }
Exemple #3
0
        public void UnpackTCD()
        {
            var selectFileDialog = new CommonOpenFileDialog
            {
                RestoreDirectory = false,
                InitialDirectory = Directory.GetCurrentDirectory(),
                EnsureFileExists = true,
                Multiselect      = false,
                Title            = "Unpack .tcd"
            };

            selectFileDialog.Filters.Add(new CommonFileDialogFilter("Packed Resource File", "*.tcd"));

            var dialogSuccess = selectFileDialog.ShowDialog();

            if (dialogSuccess == CommonFileDialogResult.Ok)
            {
                var    selectedFile = selectFileDialog.FileName;
                string resourceFile, patternFile, fileBase;
                resourceFile = patternFile = fileBase = string.Empty;
                if (selectedFile.EndsWith(Constants.ResourceSuffix, StringComparison.InvariantCultureIgnoreCase))
                {
                    fileBase     = Path.GetFileName(selectedFile.Substring(0, selectedFile.Length - Constants.ResourceSuffix.Length));
                    resourceFile = selectedFile;
                    patternFile  = Path.Combine(Path.GetDirectoryName(selectedFile), fileBase + Constants.PatternSuffix);
                    if (!File.Exists(patternFile))
                    {
                        MessageBox.Show($"Missing associated pattern file \"{selectedFile}\".", "Missing pattern file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                else if (selectedFile.EndsWith(Constants.PatternSuffix, StringComparison.InvariantCultureIgnoreCase))
                {
                    fileBase     = Path.GetFileName(selectedFile.Substring(0, selectedFile.Length - Constants.PatternSuffix.Length));
                    resourceFile = Path.Combine(Path.GetDirectoryName(selectedFile), fileBase + Constants.ResourceSuffix);
                    patternFile  = selectedFile;
                    if (!File.Exists(resourceFile))
                    {
                        MessageBox.Show($"Missing associated resource file \"{resourceFile}\".", "Missing resource file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show($"Invalid selection \"{selectedFile}\".{Environment.NewLine}Please select a \"<name>Resource\" or \"<name>Pattern\" .tcd file.", "Invalid file", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                var newDirectory = Path.Combine(Path.GetDirectoryName(selectedFile), fileBase);
                TCDEncodeDecode.UnpackTCDFile(
                    newDirectory,
                    fileBase,
                    (fileName, progress) =>
                {
                    this.ProgressStatus = fileName;
                    this.Progress       = progress;
                });
            }
        }
Exemple #4
0
        public bool LoadMap(string fileName, bool decode)
        {
            if (!this.ConfirmMapChange())
            {
                return(false);
            }

            var mapContents = TCDEncodeDecode.ReadTextFile(fileName, decode);

            if (mapContents == null)
            {
                return(false);
            }

            var openedMap = new Map {
                StringValue = mapContents, Name = Path.GetFileNameWithoutExtension(fileName)
            };

            if (openedMap.HasErrors)
            {
                MessageBox.Show($"Map contains errors, please find and resolve with View > Errors", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            this.CurrentMap    = openedMap;
            this.LoadedMapPath = fileName;
            this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            //var mapLoadSuccess = !openedMap.HasErrors;
            //if (mapLoadSuccess)
            //{
            //    this.CurrentMap = openedMap;
            //    this.LoadedMapPath = fileName;
            //    this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            //}
            //else
            //{
            //    var filteredErrors = openedMap.Errors.Distinct();
            //    if (filteredErrors.Count() < 25)
            //    {
            //        MessageBox.Show($"Map failed to parse, with the following errors:{Environment.NewLine}{string.Join(Environment.NewLine, filteredErrors)}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            //    }
            //    else
            //    {
            //        MessageBox.Show($"Map failed to parse, with many errors.{Environment.NewLine}Please check that you've chosen the right file:{Environment.NewLine}{string.Join(Environment.NewLine, filteredErrors.Take(25))}{Environment.NewLine}...", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            //    }

            //    this.CurrentMap = Constants.BlankMapCreator();
            //    this.LoadedMapPath = null;
            //    this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            //}

            MapRenderer.Refresh();
            MainWindowViewModel.MapLoadProgressEvent?.Invoke();

            return(true);
        }
Exemple #5
0
        private Map LoadMap(string fileName, bool decode)
        {
            var mapContents = TCDEncodeDecode.ReadTextFile(fileName, decode);

            if (mapContents == null)
            {
                return(null);
            }

            return(new Map {
                StringValue = mapContents, Name = Path.GetFileNameWithoutExtension(fileName)
            });
        }
Exemple #6
0
        public bool SaveOrCreateEncodedFile()
        {
            var success = false;

            if (this.LoadedMapPath == null)
            {
                success = this.SaveNewEncodedFile();
            }
            else
            {
                var shdFile = Path.ChangeExtension(this.LoadedMapPath, ".she");
                success            = TCDEncodeDecode.SaveFile(shdFile, TCDEncodeDecode.EncodeMap(this.CurrentMap.StringValue));
                this.LastLoadedMap = (Map)this.CurrentMap.Clone();
            }

            return(success);
        }
Exemple #7
0
        public void SaveDecodedFile()
        {
            var saveFileDialog = new CommonSaveFileDialog
            {
                RestoreDirectory   = false,
                InitialDirectory   = Directory.GetCurrentDirectory() + "\\data\\",
                DefaultExtension   = "shd",
                NavigateToShortcut = true,
                OverwritePrompt    = true,
                DefaultFileName    = Path.ChangeExtension(Path.GetFileName(this.LoadedMapPath), ".shd"),
                Title = "Export .shd"
            };

            saveFileDialog.Filters.Add(new CommonFileDialogFilter("Decoded Map File", "*.shd"));
            saveFileDialog.Filters.Add(new CommonFileDialogFilter("All Files", "*.*"));

            var dialogSuccess = saveFileDialog.ShowDialog();

            if (dialogSuccess == CommonFileDialogResult.Ok)
            {
                TCDEncodeDecode.SaveFile(saveFileDialog.FileName, this.CurrentMap.StringValue);
            }
        }
Exemple #8
0
        public static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Invalid arguments, expected \"ResourcePackingBuildStep.exe <pack|encode> <packed directory> <output file prefix|directory>\"");
                return(-1);
            }

            if (args[0] == "pack")
            {
                var packComplete = false;
                TCDEncodeDecode.PackTCDFile(
                    args[1],
                    args[2],
                    (fileName, progress) =>
                {
                    if (fileName != null)
                    {
                        Console.WriteLine($"({100 * progress:F1}%) {fileName}");
                    }
                    else
                    {
                        packComplete = true;
                    }
                });

                while (!packComplete)
                {
                    Thread.Sleep(1);
                }

                Console.WriteLine($"(100.0%) Directory packed into:");
                Console.WriteLine($"         > {args[1]}Resource.tcd");
                Console.WriteLine($"         > {args[1]}Pattern.tcd");
            }
            else if (args[0] == "encode")
            {
                Directory.CreateDirectory(args[2]);

                var mapfiles = Directory.GetFiles(args[1]);

                for (int i = 0; i < mapfiles.Length; i++)
                {
                    var map             = mapfiles[i];
                    var contents        = TCDEncodeDecode.ReadTextFile(map, false);
                    var encodedContents = TCDEncodeDecode.EncodeMap(contents);

                    var filename = Path.GetFileNameWithoutExtension(map);
                    var newPath  = Path.Combine(args[2], Path.ChangeExtension(filename, ".she"));
                    TCDEncodeDecode.SaveFile(newPath, encodedContents);

                    Console.WriteLine($"({100 * ((double)i / mapfiles.Length):F1}%) {filename}");
                }

                Console.WriteLine($"(100.0%) Map files encoded to directory:");
                Console.WriteLine($"         > {args[2]}");
            }
            else
            {
                Console.Error.WriteLine($"Invalid operation \"{args[0]}\", expected \"pack\" or \"encode\"");
                return(-1);
            }


            return(0);
        }
Exemple #9
0
        public MapField(IAudioEngine s, string txtname, SaveData save, SceneMap p)
            : base(s)
        {
            this.save   = save;
            this.parent = p;
            this.parent.parent.KeepActiveTexList.RemoveAll(e => !e.Contains(txtname));
            this.parent.parent.TexClear(false);
            this.mapname = txtname;
            save.nowMap  = txtname;
            string path = NSGame.Debug.MaskMapFile ? "data/" + txtname + ".she" : "map/" + txtname + ".txt";

            if (!File.Exists(path))
            {
                return;
            }
            StreamReader reader = new StreamReader(path, Encoding.GetEncoding("Shift_JIS"));
            string       A1     = reader.ReadLine();

            if (NSGame.Debug.MaskMapFile)
            {
                A1 = TCDEncodeDecode.EncMapScript(A1);
            }
            string[] strArray1 = A1.Split(',');
            int      length1   = int.Parse(strArray1[0]);
            int      length2   = int.Parse(strArray1[1]);
            int      length3   = int.Parse(strArray1[8]);

            this.rendX         = int.Parse(strArray1[2]);
            this.rendY         = int.Parse(strArray1[3]);
            this.rect          = new Rectangle(0, 0, int.Parse(strArray1[4]), int.Parse(strArray1[5]));
            save.plase         = ShanghaiEXE.Translate(strArray1[6]);
            this.height        = int.Parse(strArray1[7]);
            this.map           = new UnboundedMap(new byte[length3, length1, length2]);
            this.backNo        = int.Parse(strArray1[9]);
            this.back          = BackgroundBase.BackMake(this.backNo);
            this.encountCap[0] = int.Parse(strArray1[10]);
            this.encountCap[1] = int.Parse(strArray1[11]);
            string str1 = strArray1[12];

            this.graphicName = new string[length3 + (length3 - 1)];
            for (int index = 0; index < ((IEnumerable <string>) this.graphicName).Count <string>(); ++index)
            {
                this.graphicName[index] = str1 + (index + 1).ToString();
            }
            string str2;

            for (int index1 = 0; index1 < this.map.GetLength(0); ++index1)
            {
                for (int index2 = 0; index2 < this.map.GetLength(2); ++index2)
                {
                    string A2 = reader.ReadLine();
                    if (NSGame.Debug.MaskMapFile)
                    {
                        A2 = TCDEncodeDecode.EncMapScript(A2);
                    }
                    string[] strArray2 = A2.Split(',');
                    for (int index3 = 0; index3 < this.map.GetLength(1); ++index3)
                    {
                        this.map[index1, index3, index2] = 0;
                        this.map[index1, index3, index2] = byte.Parse(strArray2[index3]);
                    }
                }
                string A3 = reader.ReadLine();
                if (NSGame.Debug.MaskMapFile)
                {
                    str2 = TCDEncodeDecode.EncMapScript(A3);
                }
            }
            this.encounts.Clear();
            string A4;

            while ((A4 = reader.ReadLine()) != "")
            {
                if (NSGame.Debug.MaskMapFile)
                {
                    A4 = TCDEncodeDecode.EncMapScript(A4);
                }
                if (!(A4 == ""))
                {
                    EventManager m         = new EventManager(this.sound);
                    string[]     strArray2 = A4.Split(':');
                    m.AddEvent(new BgmSave(this.sound, m, this, save));
                    Battle battle;
                    if (strArray2.Length >= 20)
                    {
                        battle = new NSEvent.Battle(this.sound,
                                                    m,
                                                    int.Parse(strArray2[1]),
                                                    byte.Parse(strArray2[2]),
                                                    int.Parse(strArray2[3]),
                                                    int.Parse(strArray2[4]),
                                                    int.Parse(strArray2[5]),
                                                    int.Parse(strArray2[6]),
                                                    int.Parse(strArray2[7]),
                                                    int.Parse(strArray2[8]),
                                                    ShanghaiEXE.Translate(strArray2[9]),
                                                    int.Parse(strArray2[10]),
                                                    byte.Parse(strArray2[11]),
                                                    int.Parse(strArray2[12]),
                                                    int.Parse(strArray2[13]),
                                                    int.Parse(strArray2[14]),
                                                    int.Parse(strArray2[15]),
                                                    int.Parse(strArray2[16]),
                                                    int.Parse(strArray2[17]),
                                                    ShanghaiEXE.Translate(strArray2[18]),
                                                    int.Parse(strArray2[19]),
                                                    byte.Parse(strArray2[20]),
                                                    int.Parse(strArray2[21]),
                                                    int.Parse(strArray2[22]),
                                                    int.Parse(strArray2[23]),
                                                    int.Parse(strArray2[24]),
                                                    int.Parse(strArray2[25]),
                                                    int.Parse(strArray2[26]),
                                                    ShanghaiEXE.Translate(strArray2[27]),
                                                    (Panel.PANEL) int.Parse(strArray2[28]),
                                                    (Panel.PANEL) int.Parse(strArray2[29]),
                                                    int.Parse(strArray2[30]),
                                                    bool.Parse(strArray2[31]),
                                                    bool.Parse(strArray2[32]),
                                                    bool.Parse(strArray2[33]),
                                                    bool.Parse(strArray2[34]),
                                                    strArray2[35],
                                                    this.backNo,
                                                    save);
                    }
                    else
                    {
                        battle = new NSEvent.Battle(this.sound,
                                                    m,
                                                    (EnemyBase.VIRUS)Enum.Parse(typeof(EnemyBase.VIRUS), strArray2[1]),
                                                    byte.Parse(strArray2[2]),
                                                    int.Parse(strArray2[3]),
                                                    int.Parse(strArray2[4]),
                                                    (EnemyBase.VIRUS)Enum.Parse(typeof(EnemyBase.VIRUS), strArray2[5]),
                                                    byte.Parse(strArray2[6]),
                                                    int.Parse(strArray2[7]),
                                                    int.Parse(strArray2[8]),
                                                    (EnemyBase.VIRUS)Enum.Parse(typeof(EnemyBase.VIRUS), strArray2[9]),
                                                    byte.Parse(strArray2[10]),
                                                    int.Parse(strArray2[11]),
                                                    int.Parse(strArray2[12]),
                                                    (Panel.PANEL)Enum.Parse(typeof(Panel.PANEL), strArray2[13]),
                                                    (Panel.PANEL)Enum.Parse(typeof(Panel.PANEL), strArray2[14]),
                                                    int.Parse(strArray2[15]),
                                                    bool.Parse(strArray2[16]),
                                                    bool.Parse(strArray2[17]),
                                                    bool.Parse(strArray2[18]),
                                                    save);
                    }
                    m.AddEvent(battle);
                    m.AddEvent(new BgmLoad(this.sound, m, this, save));
                    m.AddEvent(new Fade(this.sound, m, 17, 0, 0, 0, 0, false, save));
                    this.encounts.Add(m);
                }
                else
                {
                    break;
                }
            }
            string A5 = reader.ReadLine();

            if (NSGame.Debug.MaskMapFile)
            {
                A5 = TCDEncodeDecode.EncMapScript(A5);
            }
            string[]             strArray3         = A5.Split(':');
            List <RandomMystery> randomMysteryList = new List <RandomMystery>();

            foreach (string str3 in strArray3)
            {
                if (str3 == "")
                {
                    break;
                }
                if (str3 == "random")
                {
                    continue;
                }
                string[] strArray2 = str3.Split(',');
                randomMysteryList.Add(new RandomMystery()
                {
                    itemType   = int.Parse(strArray2[0]),
                    itemNumber = int.Parse(strArray2[1]),
                    itemSub    = int.Parse(strArray2[2]),
                    getInfo    = ShanghaiEXE.Translate(strArray2[3])
                });
            }
            this.randomMystery = randomMysteryList.ToArray();
            string A6 = reader.ReadLine();

            if (NSGame.Debug.MaskMapFile)
            {
                str2 = TCDEncodeDecode.EncMapScript(A6);
            }
            var    eventIndex = 0;
            string A7;

            while ((A7 = reader.ReadLine()) != null)
            {
                if (NSGame.Debug.MaskMapFile)
                {
                    A7 = TCDEncodeDecode.EncMapScript(A7);
                }
                string[] strArray2 = A7.Split(':');
                if (strArray2[0] == "ID")
                {
                    string id = strArray2[1];
                    string A2 = reader.ReadLine();
                    if (NSGame.Debug.MaskMapFile)
                    {
                        A2 = TCDEncodeDecode.EncMapScript(A2);
                    }
                    string[] strArray4 = A2.Split(':');
                    Point    po        = new Point(int.Parse(strArray4[1]), int.Parse(strArray4[2]));
                    var      mapEvent  = new MapEventBase(s, this.parent, po, int.Parse(strArray4[3]), MapCharacterBase.ANGLE.UP, this, id, save, reader, this.mapname);
                    mapEvent.index = eventIndex;
                    this.Events.Add(mapEvent);
                }
                else
                {
                    string id = strArray2[1];
                    string A2 = reader.ReadLine();
                    if (NSGame.Debug.MaskMapFile)
                    {
                        A2 = TCDEncodeDecode.EncMapScript(A2);
                    }
                    string[]      strArray4 = A2.Split(':');
                    Point         po        = new Point(int.Parse(strArray4[1]), int.Parse(strArray4[2]));
                    int           floor     = int.Parse(strArray4[3]);
                    RandomMystery random    = new RandomMystery();
                    string        A3        = reader.ReadLine();
                    if (NSGame.Debug.MaskMapFile)
                    {
                        A3 = TCDEncodeDecode.EncMapScript(A3);
                    }
                    string[] strArray5 = A3.Split(':')[1].Split(',');
                    random.type       = int.Parse(strArray5[0]);
                    random.itemType   = int.Parse(strArray5[1]);
                    random.itemNumber = int.Parse(strArray5[2]);
                    random.itemSub    = int.Parse(strArray5[3]);
                    random.getInfo    = ShanghaiEXE.Translate(strArray5[4]);
                    random.flugNumber = int.Parse(strArray5[5]);
                    var mysteryData = new MysteryData(s, this.parent, po, floor, MapCharacterBase.ANGLE.UP, this, id, save, reader, random);
                    mysteryData.index = eventIndex;
                    this.Events.Add(mysteryData);
                }
                eventIndex++;
            }
            reader.Close();
            this.threadEnd = false;
            this.MapTexLoad();
            this.threadTexRead = new Thread(new ThreadStart(this.MapTexLoad));
            this.threadTexRead.Start();
            this.parent.eventmanagerParallel.events.Clear();
            this.parent.eventmanagerParallel.playevent = false;
        }