Example #1
0
        public override string ToString()
        {
            if (isFunction)
            {
                switch (FunctionType)
                {
                case InputFunctions.FunctionType.Not:
                    return("!(" + subkeywords[0] + ")");

                case InputFunctions.FunctionType.And:
                    return("(" + subkeywords[0] + " && " + subkeywords[1] + ")");

                case InputFunctions.FunctionType.Or:
                    return("(" + subkeywords[0] + " || " + subkeywords[1] + ")");

                case InputFunctions.FunctionType.KeyPressed:
                case InputFunctions.FunctionType.KeyReleased:
                case InputFunctions.FunctionType.KeyJustPressed:
                case InputFunctions.FunctionType.KeyJustReleased:
                    return(FunctionType + "(" + Enum.GetName(typeof(KeyCode), subkeywords[0].indexOrKeyCode) + ")");

                case InputFunctions.FunctionType.Sequence:
                    string sequence = "";
                    // Skip 1 at the end (first sequenceKey), then do -2 to skip over every other sequenceKey
                    // Then stop because first two keywords (last two processed here) are length and sequenceEnd
                    for (int i = subkeywords.Length - 1; i > 0; i--)
                    {
                        KeyWord w = subkeywords[i];
                        switch (w.FunctionType)
                        {
                        case InputFunctions.FunctionType.SequenceKey:
                        case InputFunctions.FunctionType.SequenceKeyEnd:
                            sequence += Enum.GetName(typeof(KeyCode), subkeywords[i].subkeywords[0].indexOrKeyCode);
                            break;

                        case InputFunctions.FunctionType.SequencePad:
                        case InputFunctions.FunctionType.SequencePadEnd:
                            sequence += GetJoyPadString(subkeywords[i].subkeywords);
                            break;
                        }
                    }
                    return("Sequence(\"" + sequence + "\")");

                case InputFunctions.FunctionType.PadPressed:
                case InputFunctions.FunctionType.PadReleased:
                case InputFunctions.FunctionType.PadJustPressed:
                case InputFunctions.FunctionType.PadJustReleased:
                case InputFunctions.FunctionType.JoystickPressed:
                case InputFunctions.FunctionType.JoystickReleased:
                case InputFunctions.FunctionType.JoystickJustPressed:
                case InputFunctions.FunctionType.JoystickJustReleased:
                case InputFunctions.FunctionType.JoystickOrPadPressed:
                case InputFunctions.FunctionType.JoystickOrPadReleased:
                case InputFunctions.FunctionType.JoystickOrPadJustPressed:
                case InputFunctions.FunctionType.JoystickOrPadJustReleased:
                    return(FunctionType + GetJoyPadString(subkeywords));

                case InputFunctions.FunctionType.JoystickAxeValue:
                    if (Settings.s.game == Settings.Game.LargoWinch)
                    {
                        return(FunctionType + "("
                               + (subkeywords[2].indexOrKeyCode == 4 ? "X" : "Y")
                               + ", " + subkeywords[3].valueAsInt
                               + ", " + subkeywords[4].valueAsInt
                               + (subkeywords[1].indexOrKeyCode != 0 ? (", " + subkeywords[1].indexOrKeyCode) : "") + ")");
                    }
                    else
                    {
                        return(FunctionType + "("
                               + (subkeywords[1].indexOrKeyCode == 4 ? "X" : "Y")
                               + ", " + subkeywords[2].valueAsInt
                               + ", " + subkeywords[3].valueAsInt
                               + (subkeywords[0].indexOrKeyCode != 0 ? (", " + subkeywords[0].indexOrKeyCode) : "") + ")");
                    }

                case InputFunctions.FunctionType.ActionValidated:
                case InputFunctions.FunctionType.ActionInvalidated:
                case InputFunctions.FunctionType.ActionJustValidated:
                case InputFunctions.FunctionType.ActionJustInvalidated:
                    Pointer off_action = subkeywords[0].valueAsPointer;
                    if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal)
                    {
                        return(FunctionType + "()");
                    }
                    EntryAction action = EntryAction.FromOffset(off_action);
                    return(FunctionType + "{" + (action != null ? ((action.name != null && action.name.Trim() != "") ? ("\"" + action.name + "\"") : action.ToBasicString()) : "null") + "}");

                default:
                    return(FunctionType.ToString() + "()");
                }
            }
            else
            {
                return("[" + indexOrKeyCode + "]<" + Enum.GetName(typeof(KeyCode), indexOrKeyCode) + ">");
            }
        }
Example #2
0
        public static KeyWord Read(Reader reader, Pointer offset, bool isFunction = true)
        {
            KeyWord keyword = new KeyWord(offset);

            // Read 20 in total for R2iOS
            if (Settings.s.hasExtraInputData)
            {
                reader.ReadInt32();
                reader.ReadInt32();
                reader.ReadInt32();
            }

            Pointer off_value = Pointer.Current(reader);

            keyword.indexOrKeyCode = reader.ReadUInt16();
            Pointer.Goto(ref reader, off_value);

            if (Settings.s == Settings.R2PC)
            {
                keyword.valueAsInt = reader.ReadInt16();
                reader.ReadInt16();
            }
            else
            {
                keyword.valueAsInt = reader.ReadInt32();
            }

            keyword.valueAsPointer = Pointer.GetPointerAtOffset(off_value);
            if (Settings.s.engineVersion == Settings.EngineVersion.R3 && Settings.s.game != Settings.Game.LargoWinch)
            {
                reader.ReadInt32();
            }
            if (Settings.s.game != Settings.Game.R2Revolution)
            {
                reader.ReadInt32();
            }

            /*if (isFunction && Settings.s.game != Settings.Game.TTSE) {
             *  keyWord.isFunction = true;
             *  switch (keyWord.FunctionType) {
             *      case InputFunctions.FunctionType.Not:
             *          keyWord.subkeywords = new KeyWord[1];
             *          keyWord.subkeywords[0] = KeyWord.Read(reader, Pointer.Current(reader));
             *          break;
             *      case InputFunctions.FunctionType.And:
             *      case InputFunctions.FunctionType.Or:
             *          keyWord.subkeywords = new KeyWord[2];
             *          keyWord.subkeywords[0] = KeyWord.Read(reader, Pointer.Current(reader));
             *          keyWord.subkeywords[1] = KeyWord.Read(reader, Pointer.Current(reader));
             *          break;
             *      case InputFunctions.FunctionType.KeyPressed:
             *      case InputFunctions.FunctionType.KeyReleased:
             *      case InputFunctions.FunctionType.KeyJustPressed:
             *      case InputFunctions.FunctionType.KeyJustReleased:
             *          keyWord.subkeywords = new KeyWord[1];
             *          keyWord.subkeywords[0] = KeyWord.Read(reader, Pointer.Current(reader), isFunction: false);
             *          break;
             *      case InputFunctions.FunctionType.Sequence:
             *          keyWord.subkeywords = new KeyWord[1];
             *          keyWord.subkeywords[0] = KeyWord.Read(reader, Pointer.Current(reader), isFunction: false);
             *          int sequenceLength = keyWord.subkeywords[0].indexOrKeyCode;
             *          if (sequenceLength > 0) {
             *              Array.Resize(ref keyWord.subkeywords, sequenceLength*2 + 2);
             *              keyWord.subkeywords[1] = KeyWord.Read(reader, Pointer.Current(reader));
             *              for (int i = 0; i < sequenceLength; i++) {
             *                  keyWord.subkeywords[2+i*2] = KeyWord.Read(reader, Pointer.Current(reader), isFunction: false); // Keycode
             *                  keyWord.subkeywords[3+i*2] = KeyWord.Read(reader, Pointer.Current(reader), isFunction: true); // SequenceKey
             *              }
             *          }
             *          break;
             *                          case InputFunctions.FunctionType.JoystickPressed:
             *                          case InputFunctions.FunctionType.JoystickReleased:
             *                          case InputFunctions.FunctionType.JoystickJustPressed:
             *                          case InputFunctions.FunctionType.JoystickJustReleased:
             *                                  keyWord.subkeywords = new KeyWord[2];
             *                                  keyWord.subkeywords[0] = KeyWord.Read(reader, Pointer.Current(reader));
             *                                  keyWord.subkeywords[1] = KeyWord.Read(reader, Pointer.Current(reader));
             *                                  break;
             *                  }
             * } else {
             * }*/

            return(keyword);
        }
Example #3
0
        public static EntryAction Read(Reader reader, Pointer offset)
        {
            MapLoader   l  = MapLoader.Loader;
            EntryAction ea = new EntryAction(offset);

            //l.print("EntryAction " + offset);
            l.entryActions.Add(ea);

            if (Settings.s.game == Settings.Game.TTSE)
            {
                ea.off_entryAction_next = Pointer.Read(reader);
                ea.off_entryAction_prev = Pointer.Read(reader);
                reader.ReadUInt32(); //element.off_entryAction_hdr = Pointer.Read(reader); // hdr pointer doesn't work here
                ea.keywords = LinkedList <KeyWord> .Read(ref reader, Pointer.Current(reader),
                                                         (off_element) => {
                    return(KeyWord.Read(reader, off_element));
                },
                                                         flags : Settings.s.hasLinkedListHeaderPointers?
                                                         LinkedList.Flags.HasHeaderPointers :
                                                         LinkedList.Flags.NoPreviousPointersForDouble,
                                                         type : LinkedList.Type.Default);

                ea.off_name = Pointer.Read(reader);
                reader.ReadInt32(); // -2
                reader.ReadUInt32();
                reader.ReadByte();
                ea.active = reader.ReadByte();
                reader.ReadBytes(2);
            }
            else
            {
                if (Settings.s.hasExtraInputData)
                {
                    reader.ReadBytes(0x18);
                }
                if (Settings.s.platform == Settings.Platform.PS2 &&
                    (Settings.s.game == Settings.Game.RM ||
                     Settings.s.game == Settings.Game.RA ||
                     Settings.s.mode == Settings.Mode.Rayman3PS2Demo_2002_12_18))
                {
                    reader.ReadBytes(0x8);
                }
                ea.num_keywords = reader.ReadUInt32();
                ea.off_keywords = Pointer.Read(reader);
                ea.keywords     = new LinkedList <KeyWord>(Pointer.Current(reader), ea.off_keywords, ea.num_keywords, type: LinkedList.Type.SingleNoElementPointers);
                if (Settings.s.engineVersion < Settings.EngineVersion.R2)
                {
                    reader.ReadUInt32();                                                       // Offset of extra input data in tmp memory? It's different by 0x18 every time
                }
                ea.off_name = Pointer.Read(reader);
                if (Settings.s.hasExtraInputData || Settings.s.platform == Settings.Platform.DC || Settings.s.engineVersion == Settings.EngineVersion.R3)
                {
                    ea.off_name2 = Pointer.Read(reader);
                }
                reader.ReadInt32();                 // -2
                reader.ReadUInt32();
                ea.active = reader.ReadByte();
                reader.ReadBytes(3);

                ea.keywords.ReadEntries(ref reader, (off_element) => {
                    return(KeyWord.Read(reader, off_element));
                });
            }
            if (ea.keywords != null && ea.keywords.Count > 0)
            {
                int keywordsRead = ea.keywords[0].FillInSubKeywords(ref reader, ea.keywords, 0);
                if (keywordsRead != ea.keywords.Count)
                {
                    Debug.LogError(offset + " - Keywords read was: " + keywordsRead + " vs " + ea.keywords.Count);
                    Debug.LogError(ea.ToString());
                }
            }
            Pointer.DoAt(ref reader, ea.off_name, () => {
                ea.name = reader.ReadNullDelimitedString();
            });
            Pointer.DoAt(ref reader, ea.off_name2, () => {
                ea.name2 = reader.ReadNullDelimitedString();
            });

            return(ea);
        }