public static void ReplaceMessageScript(MessageScript messageScript)
 {
     foreach (var message in messageScript.Dialogs)
     {
         foreach (var line in message.Lines)
         {
             for (int k = 0; k < line.Tokens.Count; k++)
             {
                 switch (line.Tokens[k].Kind)
                 {
                 case TokenKind.String:
                     var textToken = (StringToken)line.Tokens[k];
                     if (Options.Markov)
                     {
                         line.Tokens[k] = new StringToken(Markov(textToken.Value));
                     }
                     else if (Options.New != "" && Options.Old != "")
                     {
                         line.Tokens[k] = new StringToken(textToken.Value.Replace(Options.Old, Options.New));
                     }
                     break;
                 }
             }
         }
     }
 }
 void Start()
 {
     playerScript   = player.GetComponent <PlayerScript> ();
     gameManager    = GameObject.Find("GameManager");
     gameOverScript = gameManager.GetComponent <GameOverScript> ();
     messageScript  = gameManager.GetComponent <MessageScript> ();
 }
Beispiel #3
0
        public static void RandomizeMessageScript(string path)
        {
            var messageScript = MessageScript.FromFile(path);

            RandomizeMessageScript(messageScript);
            messageScript.ToFile(path + ".randomized");
        }
Beispiel #4
0
    private void RemoveItem(MessageScript item)
    {
        messages.Remove(item);
        readMessages.Remove(item);

        m_GameplaUiController.OnAmountOfMemoriesChange(messages.Count);
    }
Beispiel #5
0
 public void FromStream_ShouldNotThrow_Version1BigEndian()
 {
     using (var fileStream = File.OpenRead("TestResources\\Version1BigEndian.bmd"))
     {
         var script = MessageScript.FromStream(fileStream);
     }
 }
        public static void ReplaceMessageScript(string path, string originalPath)
        {
            var messageScript = MessageScript.FromFile(path);

            ReplaceMessageScript(messageScript);
            messageScript.ToFile(path + ".Replaced");
        }
        public static Stream ReplaceMessageScript(Stream stream)
        {
            var messageScript = MessageScript.FromStream(stream, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1, null, true);

            ReplaceMessageScript(messageScript);

            return(messageScript.ToStream());
        }
Beispiel #8
0
        public void Constructor_ShouldNotFailDefaultValueCheck()
        {
            var script = new MessageScript(FormatVersion.Version1);

            Assert.AreEqual(0, script.Id);
            Assert.AreEqual(FormatVersion.Version1, script.FormatVersion);
            Assert.AreEqual(0, script.Dialogs.Count);
        }
Beispiel #9
0
        public void ToBinary_ShouldMatchSourceBinary_Version1BigEndian()
        {
            var binary    = MessageScriptBinary.FromFile("TestResources\\Version1BigEndian.bmd");
            var script    = MessageScript.FromBinary(binary);
            var newBinary = script.ToBinary();

            Compare(binary, newBinary);
        }
Beispiel #10
0
        public static Stream RandomizeMessageScript(Stream stream)
        {
            var messageScript = MessageScript.FromStream(stream, true);

            RandomizeMessageScript(messageScript);

            return(messageScript.ToStream());
        }
 public void Decompile(MessageScript script)
 {
     foreach (var message in script.Dialogs)
     {
         Decompile(message);
         mWriter.WriteLine();
     }
 }
Beispiel #12
0
    public void AddMessage(MessageItemScript item, string messageText)
    {
        MessageScript m = new MessageScript(item, messageText, messages.Count);

        messages.Add(m);

        m_GameplaUiController.OnAmountOfMemoriesChange(messages.Count);
    }
Beispiel #13
0
        public static void FixMessageScript(string path, string originalPath)
        {
            var messageScript         = MessageScript.FromFile(path);
            var originalMessageScript = MessageScript.FromFile(originalPath);

            FixMessageScript(messageScript, originalMessageScript);
            messageScript.ToFile(path + ".Fixd");
        }
Beispiel #14
0
        private static bool TryDoMessageScriptCompilation()
        {
            // Compile source
            Logger.Info("Compiling MessageScript...");

            var version = GetMessageScriptFormatVersion();

            if (version == AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Detect)
            {
                Logger.Error("Invalid MessageScript file format");
                return(false);
            }

            var encoding = GetEncoding();
            var compiler = new MessageScriptCompiler(GetMessageScriptFormatVersion(), encoding);

            compiler.AddListener(Listener);

            if (LibraryName != null)
            {
                var library = LibraryLookup.GetLibrary(LibraryName);

                if (library == null)
                {
                    Logger.Error("Invalid library name specified");
                    return(false);
                }

                compiler.Library = library;
            }

            bool          success = false;
            MessageScript script  = null;

            try
            {
                success = compiler.TryCompile(File.OpenText(InputFilePath), out script);
            }
            catch (UnsupportedCharacterException e)
            {
                Logger.Error($"Character '{e.Character}' not supported by encoding '{e.EncodingName}'");
            }

            if (!success)
            {
                Logger.Error("One or more errors occured during compilation!");
                return(false);
            }

            // Write binary
            Logger.Info("Writing binary to file...");
            if (!TryPerformAction("An error occured while saving the file.", () => script.ToFile(OutputFilePath)))
            {
                return(false);
            }

            return(true);
        }
Beispiel #15
0
        private void WriteMessageScriptDisassembly()
        {
            mWriter.WriteLine(".msg");

            using (var messageScriptDecompiler = new MessageScriptDecompiler(mWriter))
            {
                messageScriptDecompiler.Decompile(MessageScript.FromBinary(mScript.MessageScriptSection));
            }
        }
Beispiel #16
0
        public static Stream FixMessageScript(Stream stream, Stream originalStream)
        {
            var messageScript         = MessageScript.FromStream(stream, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1, null, true);
            var originalMessageScript = MessageScript.FromStream(originalStream, AtlusScriptLibrary.MessageScriptLanguage.FormatVersion.Version1, null, true);

            FixMessageScript(messageScript, originalMessageScript);

            return(messageScript.ToStream());
        }
Beispiel #17
0
        static void WriteMessageScriptWithDecompiler(string name, MessageScript script)
        {
            Writer.WriteLine(name);

            Decompiler.Decompile(script);

            Writer.WriteLine();
            Writer.Flush();
        }
Beispiel #18
0
        public static Stream FixMessageScript(Stream stream, Stream originalStream)
        {
            var messageScript         = MessageScript.FromStream(stream, true);
            var originalMessageScript = MessageScript.FromStream(originalStream, true);

            FixMessageScript(messageScript, originalMessageScript);

            return(messageScript.ToStream());
        }
Beispiel #19
0
        /// <summary>
        /// Attempts to compile the given input source.
        /// </summary>
        /// <param name="input">The input source.</param>
        /// <param name="script">The output of the compilaton. Is only guaranteed to be valid if the operation succeeded.</param>
        /// <returns>A boolean value indicating whether the compilation succeeded or not.</returns>
        public bool TryCompile(Stream input, out MessageScript script)
        {
            LogInfo("Parsing MessageScript source");
            var cst = MessageScriptParserHelper.ParseCompilationUnit(input, new AntlrErrorListener(this));

            LogInfo("Done parsing MessageScript source");

            return(TryCompile(cst, out script));
        }
Beispiel #20
0
    public void DecideTurn()
    {
        int turn = Random.Range(0, 2);

        currentPlayer = turn > 0 ? rival : player;
        MessageScript msg = Instantiate(messagePrefab, canvas.transform);

        msg.SetText(currentPlayer.name + " goes first!");
        StartCoroutine(PerformAction(1f, DiceThrow));
    }
Beispiel #21
0
        public void Decompile(MessageScript script)
        {
            WriteHeaderComment("Decompiled by Atlus Script Tools (2017-2021) © TGE");

            for (var i = 0; i < script.Dialogs.Count; i++)
            {
                var message = script.Dialogs[i];
                WriteHeaderLine($"const int {FormatIdentifier( message.Name ).PadRight(32)} = {i};");
                Decompile(message);
                mWriter.WriteLine();
            }
        }
Beispiel #22
0
        public void Decompile(MessageScript script)
        {
            mWriter.WriteLine("// Decompiled by Atlus Script Tools (2017-2021) © TGE");

            for (var i = 0; i < script.Dialogs.Count; i++)
            {
                var message = script.Dialogs[i];
                mWriter.WriteLine($"// index {i}");
                Decompile(message);
                mWriter.WriteLine();
            }
        }
Beispiel #23
0
        static void ScanForMessageScripts(string prettyFileName, Stream stream, CancellationToken cancellationToken)
        {
            byte[] magic = new byte[4];

            while (stream.Position <= stream.Length)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                if (stream.Position + BinaryHeader.SIZE < stream.Length)
                {
                    // Read 4 bytes
                    magic[0] = ( byte )stream.ReadByte();
                    magic[1] = ( byte )stream.ReadByte();
                    magic[2] = ( byte )stream.ReadByte();
                    magic[3] = ( byte )stream.ReadByte();

                    if (magic.SequenceEqual(BinaryHeader.MAGIC_V0) ||
                        magic.SequenceEqual(BinaryHeader.MAGIC_V1) ||
                        magic.SequenceEqual(BinaryHeader.MAGIC_V1_BE))
                    {
                        long scriptStartPosition = stream.Position - 12;
                        var  scriptBinary        = MessageScriptBinary.FromStream(new StreamView(stream, scriptStartPosition, stream.Length - scriptStartPosition));
                        var  script = MessageScript.FromBinary(scriptBinary);

                        Console.WriteLine($"Found message script at 0x{scriptStartPosition:X8}. Writing to file...");

                        if (UseDecompiler)
                        {
                            WriteMessageScriptWithDecompiler($"{prettyFileName} @ 0x{scriptStartPosition:X8}", script);
                        }
                        else
                        {
                            WriteMessageScript($"{prettyFileName} @ 0x{scriptStartPosition:X8}", script);
                        }

                        stream.Position = scriptStartPosition + scriptBinary.Header.FileSize;
                    }
                    else if (DisableScanAlignment)
                    {
                        // Scan alignment is disabled, so we make sure to retry every byte
                        // 4 steps forward, 3 steps back
                        stream.Position -= 3;
                    }
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #24
0
    // Use this for initialization
    void Start()
    {
        playerSprite      = gameObject.GetComponent <SpriteRenderer> ();
        animator          = gameObject.GetComponent <Animator> ();
        gameManager       = GameObject.Find("GameManager");
        gameOverScript    = gameManager.GetComponent <GameOverScript> ();
        gameManagerScript = gameManager.GetComponent <GameManagerScript> ();
        messageScript     = gameManager.GetComponent <MessageScript> ();

        regular = true;
        Sound.LoadSe("down", "down");
        Sound.LoadBgm("muteki", "muteki");
    }
Beispiel #25
0
    // Use this for initialization
    void Start()
    {
        message = MessageScript.message.getMessageInstance();
        CsvReader csv = CsvReader.GetInstance();

        csv.loadFile("map1");
        map1 = csv.getArrayData();

        BuildMap(map1);
        StartCoroutine(getBuildList(map1));

        GetComponent <EnemySpawnerScript>().Init();
    }
Beispiel #26
0
        static void WriteMessageScript(string name, MessageScript script)
        {
            Writer.WriteLine(name);

            for (var i = 0; i < script.Dialogs.Count; i++)
            {
                var window = script.Dialogs[i];
                Writer.WriteLine($"Id: {i}");
                WriteWindow(window);
            }

            Writer.WriteLine();
        }
Beispiel #27
0
        // Compilation methods
        private bool TryCompile(MessageScriptParser.CompilationUnitContext context, out MessageScript script)
        {
            LogInfo(context, "Compiling MessageScript compilation unit");

            if (!TryCompileImpl(context, out script))
            {
                LogError(context, "Failed to compile message script");
                return(false);
            }

            LogInfo(context, "Done compiling MessageScript compilation unit");

            return(true);
        }
        private bool TryCompileImpl(MessageScriptParser.CompilationUnitContext context, out MessageScript script)
        {
            LogContextInfo(context);

            script = null;

            if (!TryGetFatal(context, context.dialog, "Expected message dialog window", out var dialogContexts))
            {
                return(false);
            }

            script = new MessageScript(mVersion, mEncoding);

            foreach (var dialogContext in dialogContexts)
            {
                IDialog dialog;

                if (TryGet(dialogContext, () => dialogContext.messageDialog(), out var messageDialogContext))
                {
                    if (!TryCompileMessageDialog(messageDialogContext, out var dialogWindow))
                    {
                        LogError(messageDialogContext, "Failed to compile dialog window");
                        return(false);
                    }

                    dialog = dialogWindow;
                }
                else if (TryGet(dialogContext, () => dialogContext.selectionDialog(), out var selectionDialogContext))
                {
                    if (!TryCompileSelectionDialog(selectionDialogContext, out var selectionWindow))
                    {
                        LogError(selectionDialogContext, "Failed to compile selection window");
                        return(false);
                    }

                    dialog = selectionWindow;
                }
                else
                {
                    LogError(dialogContext, "Expected dialog or selection window");
                    return(false);
                }

                // Declare variable for dialog name referring to index
                mVariables[dialog.Name] = script.Dialogs.Count;
                script.Dialogs.Add(dialog);
            }

            return(true);
        }
Beispiel #29
0
    private void MarkAsRead(MessageScript message)
    {
        message.Item.MarkAsRead(true);

        if (!readMessages.Contains(message))
        {
            readMessages.Add(message);
        }

        m_GameplaUiController.OnAmountOfViewedMemoriesChange();

        if (messages.Count == readMessages.Count && Mode == GameManagerMode.ReadMode)
        {
            m_GameplaUiController.OnAllMemoriesRead();
        }
    }
Beispiel #30
0
 public void ChangePlayerTurn()
 {
     if (rival.GetHealth() <= 0 || player.GetHealth() <= 0)
     {
         string        pnme = rival.GetHealth() <= 0 ? player.name : rival.name;
         MessageScript msg  = Instantiate(messagePrefab, canvas.transform);
         msg.SetText(pnme + " won the game!");
         StartCoroutine(PerformAction(2f, ChangeScene));
     }
     else
     {
         currentPlayer = currentPlayer == player ? rival : player;
         MessageScript msg = Instantiate(messagePrefab, canvas.transform);
         msg.SetText("Ready " + currentPlayer.name);
         StartCoroutine(PerformAction(1f, DiceThrow));
     }
 }