예제 #1
0
            public string ToString(Perso perso, TranslatedROMScript.TranslationSettings ts, bool advanced = false)
            {
                R2ROMLoader l    = Loader;
                short       mask = 0;

                AITypes aiTypes = Settings.s.aiTypes;

                Vector3 vector3 = new Vector3 {
                    x = 0, y = 0, z = 0
                };

                switch (nodeType)
                {
                case NodeType.KeyWord:     // KeyWordFunctionPtr
                    if (param < aiTypes.keywordTable.Length)
                    {
                        if (ts.exportMode)
                        {
                            if (aiTypes.keywordTable[param] == "Me")
                            {
                                return("this");
                            }
                            if (aiTypes.keywordTable[param] == "MainActor")
                            {
                                return("Controller.MainActor");
                            }
                            if (aiTypes.keywordTable[param] == "Nobody" || aiTypes.keywordTable[param] == "NoInput" || aiTypes.keywordTable[param] == "Nowhere" || aiTypes.keywordTable[param] == "NoGraph" || aiTypes.keywordTable[param] == "NoAction" || aiTypes.keywordTable[param] == "CapsNull")
                            {
                                return("null");
                            }
                        }

                        return(aiTypes.keywordTable[param]);
                    }
                    return("UnknownKeyword_" + param);

                case NodeType.Condition:     // GetConditionFunctionPtr
                    if (param < aiTypes.conditionTable.Length)
                    {
                        return(aiTypes.conditionTable[param]);
                    }
                    return("UnknownCondition_" + param);

                case NodeType.Operator:     // GetOperatorFunctionPtr
                    if (advanced)
                    {
                        if (param < aiTypes.operatorTable.Length)
                        {
                            return(aiTypes.operatorTable[param] + " (" + param + ")");
                        }
                    }
                    if (param < aiTypes.operatorTable.Length)
                    {
                        return(aiTypes.operatorTable[param]);
                    }
                    return("UnknownOperator_" + param);

                case NodeType.Function:     // GetFunctionFunctionPtr
                    if (param < aiTypes.functionTable.Length)
                    {
                        return(aiTypes.functionTable[param]);
                    }
                    return("UnknownFunction_" + param);

                case NodeType.Procedure:     // ProcedureFunctionReturn
                    if (param < aiTypes.procedureTable.Length)
                    {
                        return(aiTypes.procedureTable[param]);
                    }
                    return("UnknownProcedure_" + param);

                case NodeType.MetaAction:     // meta action
                    if (param < aiTypes.metaActionTable.Length)
                    {
                        return(aiTypes.metaActionTable[param]);
                    }
                    return("UnknownMetaAction_" + param);

                case NodeType.BeginMacro:
                    return("BeginMacro");

                case NodeType.EndMacro:
                    return("EndMacro");

                case NodeType.Field:
                    if (param < aiTypes.fieldTable.Length)
                    {
                        return(aiTypes.fieldTable[param]);
                    }
                    return("UnknownField_" + param);

                case NodeType.DsgVarRef:     // Dsg Var
                    /*if (perso != null && perso.brain != null && perso.brain.mind != null) {
                     *  Mind mind = perso.brain.mind;
                     *  if (mind.dsgMem != null && mind.dsgMem.dsgVar != null) {
                     *      if (param < mind.dsgMem.dsgVar.dsgVarInfos.Length) {
                     *          return mind.dsgMem.dsgVar.dsgVarInfos[param].NiceVariableName;
                     *      }
                     *  } else if (mind.AI_model != null && mind.AI_model.dsgVar != null) {
                     *      if (param < mind.AI_model.dsgVar.dsgVarInfos.Length) {
                     *          return mind.AI_model.dsgVar.dsgVarInfos[param].NiceVariableName;
                     *      }
                     *  }
                     * }*/
                    return("dsgVar_" + param);

                case NodeType.Constant:
                    if (advanced)
                    {
                        return("Constant: " + paramInt.Value?.value);
                    }
                    return(paramInt.Value?.value + "");

                case NodeType.Real:
                    NumberFormatInfo nfi = new NumberFormatInfo()
                    {
                        NumberDecimalSeparator = "."
                    };
                    return(paramFloat.Value?.value.ToString(nfi) + "f");

                case NodeType.Button:     // Button/entryaction
                    EntryAction ea = paramButton.Value;

                    if (ea == null)
                    {
                        return("ERR_ENTRYACTION_NOTFOUND");
                    }

                    string eaName = (advanced ? ea.ToString() : ea.ToScriptString());
                    if (advanced)
                    {
                        return("Button: " + eaName + "(" + ea.Offset + ")");
                    }

                    if (!ts.expandEntryActions && ea != null)
                    {
                        return("\"" + eaName + "\"");
                    }
                    return(eaName);

                case NodeType.ConstantVector:
                    return("Constant Vector: " + paramVector3.Value?.value.ToString());

                case NodeType.Vector:
                    return("new Vector3");    // TODO: same

                case NodeType.Mask:
                    mask = (short)param;     // TODO: as short
                    if (advanced)
                    {
                        return("Mask: " + (mask).ToString("x4"));
                    }
                    if (ts.exportMode)
                    {
                        return("\"" + (mask).ToString("x4") + "\"");
                    }
                    return("Mask(" + (mask).ToString("x4") + ")");

                case NodeType.ModuleRef:
                    if (advanced)
                    {
                        return("ModuleRef: " + "0x" + (param).ToString("x8"));
                    }
                    return("GetModule(" + (int)param + ")");

                case NodeType.DsgVarId:
                    if (advanced)
                    {
                        return("DsgVarId: " + "0x" + (param).ToString("x8"));
                    }
                    return("DsgVarId(" + param + ")");

                case NodeType.String:
                    return(paramString.Value.ToString());

                case NodeType.LipsSynchroRef:
                    return("LipsSynchroRef: " + param);

                case NodeType.FamilyRef:

                    return("Family.FromIndex(" + ParamString + ")");

                case NodeType.PersoRef:
                    return("Perso.FromIndex(" + ParamString + ")");

                case NodeType.ActionRef:
                    return("GetAction(" + ParamString + ")");

                case NodeType.SuperObjectRef:
                    return("SuperObject.FromIndex(" + ParamString + ")");

                case NodeType.WayPointRef:
                    return("WayPoint.FromIndex(" + ParamString + ")");

                case NodeType.TextRef:
                    if (param == 0xFFFF || l.localizationROM == null)
                    {
                        return("TextRef.Null");
                    }

                    /*if (advanced) return "TextRef: " + param + " (" + l.localizationROM.GetTextForHandleAndLanguageID((int)param, 0) + ")";
                     * if (ts.expandStrings) {
                     *  return "\"" + l.localizationROM[0].GetTextForHandleAndLanguageID((int)param, 0) + "\""; // Preview in english
                     * } else {
                     *  return "new TextReference(" + (int)param + ")";
                     * }*/
                    int    txtIndex = param;
                    string result   = l.localizationROM.Lookup(txtIndex);
                    if (result != null)
                    {
                        return("\"" + result + "\"");
                    }
                    else
                    {
                        return("TextRef_" + param);
                    }

                case NodeType.ComportRef:

                    return("Comport.FromIndex(" + ParamString + ")");

                case NodeType.SoundEventRef:
                    if (advanced)
                    {
                        return("SoundEventRef: " + (int)param);
                    }
                    return("SoundEvent.FromID(0x" + ((int)param).ToString("X8") + ")");

                case NodeType.ObjectTableRef:


                    return("ObjectTable.FromIndex(" + ParamString + ")");

                case NodeType.GameMaterialRef:

                    return("GameMaterial.FromIndex(" + ParamString + ")");

                case NodeType.ParticleGenerator:
                    return("ParticleGenerator: " + "0x" + (param).ToString("x8"));

                case NodeType.VisualMaterial:
                    return("VisualMaterial.FromIndex(" + ParamString + ")");

                case NodeType.ModelRef:     // ModelCast

                    return("AIModel.FromIndex(" + ParamString + ")");

                case NodeType.DataType42:
                    if (advanced)
                    {
                        return("EvalDataType42: " + "0x" + (param).ToString("x8"));
                    }
                    return("EvalDataType42(" + "0x" + (param).ToString("x8") + ")");

                case NodeType.CustomBits:
                    if (advanced)
                    {
                        return("CustomBits: " + "0x" + (param).ToString("x8"));
                    }
                    if (ts.exportMode)
                    {
                        return("0x" + (param).ToString("x8"));
                    }
                    return("CustomBits(" + "0x" + (param).ToString("x8") + ")");

                case NodeType.Caps:
                    if (advanced)
                    {
                        return("Caps: " + "0x" + (param).ToString("x8"));
                    }
                    if (ts.exportMode)
                    {
                        return("0x" + (param).ToString("x8"));
                    }
                    return("Caps(" + "0x" + (param).ToString("x8") + ")");

                case NodeType.SubRoutine:
                    string macroString = "/* Subroutine */";
                    macroString += Environment.NewLine;
                    TranslatedROMScript macroScript = new TranslatedROMScript(paramScript.Value, perso);
                    macroString += macroScript.ToString();
                    macroString += Environment.NewLine + "/* End Subroutine */";
                    return(macroString);

                case NodeType.Null:
                    return("null");

                case NodeType.GraphRef:
                    if (advanced)
                    {
                        return("Graph: " + "0x" + (param).ToString("x8"));
                    }
                    return("Graph.FromIndex(" + ParamString + ")");
                }

                return("unknown");
            }
예제 #2
0
            public override string ToString()
            {
                if (isFunction)
                {
                    switch (FunctionType)
                    {
                    case FunctionType.Not:
                        return("!(" + subkeywords[0] + ")");

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

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

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

                    case 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 - 2; i > 1; i -= 2)
                        {
                            sequence += Enum.GetName(typeof(OpenSpace.Input.KeyCode), subkeywords[i].indexOrKeyCode);
                        }
                        return("Sequence(\"" + sequence + "\")");

                    case FunctionType.JoystickPressed:
                    case FunctionType.JoystickReleased:
                    case FunctionType.JoystickOrPadPressed:
                    case FunctionType.JoystickOrPadReleased:
                        return(FunctionType + "("
                               + GetKeyCodeString(subkeywords[1].indexOrKeyCode)
                               + (subkeywords[0].indexOrKeyCode != 0 ? (", " + subkeywords[0].indexOrKeyCode) : "")
                               + (subkeywords[2].indexOrKeyCode != 0 ? (", " + subkeywords[2].indexOrKeyCode) : "") + ")");

                    case FunctionType.JoystickJustPressed:
                    case FunctionType.JoystickJustReleased:
                    case FunctionType.JoystickOrPadJustPressed:
                    case FunctionType.JoystickOrPadJustReleased:
                        return(FunctionType + "("
                               + GetKeyCodeString(subkeywords[1].indexOrKeyCode)
                               + (subkeywords[0].indexOrKeyCode != 0 ? (", " + subkeywords[0].indexOrKeyCode) : "") + ")");

                    case FunctionType.JoystickAxeValue:
                        return(FunctionType + "("
                               + (subkeywords[1].indexOrKeyCode == 4 ? "X" : "Y")
                               + ", " + subkeywords[2].indexOrKeyCode
                               + ", " + subkeywords[3].indexOrKeyCode
                               + (subkeywords[0].indexOrKeyCode != 0 ? (", " + subkeywords[0].indexOrKeyCode) : "") + ")");

                    case FunctionType.ActionValidated:
                    case FunctionType.ActionInvalidated:
                        EntryAction action = subkeywords[0]?.subAction.Value;
                        return(FunctionType + "("
                               + (action != null ? action.GetNameString() : "null")
                               + (subkeywords[1].indexOrKeyCode != 0 ? (", " + subkeywords[1].indexOrKeyCode) : "")
                               + ")");

                    //return FunctionType + "{" + (action != null ? ((action.name != null && action.name.Trim() != "") ? ("\"" + action.name + "\"") : action.ToBasicString()) : "null") + "}";
                    case FunctionType.ActionJustValidated:
                    case FunctionType.ActionJustInvalidated:
                        EntryAction action2 = subkeywords[0]?.subAction.Value;
                        return(FunctionType + "("
                               + (action2 != null ? action2.GetNameString() : "null")
                               + ")");

                    //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) + ">");
                }
            }