Пример #1
0
    public WebJSON.Localization GetLocalizationJSON()
    {
        MapLoader l = MapLoader.Loader;

        if (l is OpenSpace.Loader.R2ROMLoader)
        {
            OpenSpace.Loader.R2ROMLoader rl   = l as OpenSpace.Loader.R2ROMLoader;
            OpenSpace.ROM.Localization   rloc = rl.localizationROM;
            if (rloc != null)
            {
                int commonStart = rloc.languageTables[1].num_txtTable + rloc.languageTables[1].num_binaryTable;
                WebJSON.Localization.Language GetLanguage(int langIndex)
                {
                    OpenSpace.ROM.LanguageTable lang = rloc.languageTables[langIndex];
                    string[] entries = new string[lang.num_txtTable + lang.num_binaryTable];
                    if (langIndex == 0)
                    {
                        for (int i = 0; i < entries.Length; i++)
                        {
                            entries[i] = rloc.Lookup(commonStart + i);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < entries.Length; i++)
                        {
                            entries[i] = rloc.Lookup(i, languageIndex: langIndex);
                        }
                    }
                    return(new WebJSON.Localization.Language()
                    {
                        Name = lang.name.Split(':')[0],
                        NameLocalized = lang.name.Split(':')[1],
                        Entries = entries
                    });
                }

                return(new WebJSON.Localization()
                {
                    LanguageStart = 0,
                    CommonStart = commonStart,
                    Common = GetLanguage(0),
                    Languages = Enumerable.Range(1, rloc.languageTables.Length - 1).Select(ind => GetLanguage(ind)).ToArray()
                });
            }
        }
        else if (l is OpenSpace.Loader.R2PS1Loader)
        {
        }
        else
        {
            OpenSpace.Text.LocalizationStructure loc = l.localization;
            if (loc != null)
            {
                return(new WebJSON.Localization()
                {
                    LanguageStart = 0,
                    CommonStart = 20000,
                    Common = new WebJSON.Localization.Language()
                    {
                        Name = "Common",
                        NameLocalized = "Common",
                        Entries = loc.misc.entries
                    },
                    Languages = Enumerable.Range(0, loc.num_languages).Select(ind => new WebJSON.Localization.Language()
                    {
                        Name = l.languages?[ind] ?? ("Language " + ind),
                        NameLocalized = l.languages_loc?[ind] ?? ("Language " + ind),
                        Entries = loc.languages[ind].entries
                    }).ToArray()
                });
            }
        }
        return(null);
    }
Пример #2
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.FromOffset(\"" + param + "\")");

                case NodeType.PersoRef:
                    return("Perso.FromOffset(\"" + param + "\")");

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

                case NodeType.SuperObjectRef:
                    return("SuperObject.FromOffset(\"" + param + "\")");

                case NodeType.WayPointRef:
                    return("WayPoint.FromOffset(\"" + param + "\")");

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

                    /*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;
                    LanguageTable table    = l.localizationROM[1];
                    if (txtIndex >= table.num_txtTable + table.num_txtTable2)
                    {
                        txtIndex = txtIndex - (table.num_txtTable + table.num_txtTable2);
                        table    = l.localizationROM[0];  // Common table
                    }
                    if (txtIndex < table.num_txtTable)
                    {
                        return("\"" + table.textTable.Value.strings[txtIndex].Value.str.Value.str + "\"");
                    }
                    else if (txtIndex < table.num_txtTable + table.num_txtTable2)
                    {
                        return("\"" + table.textTable2.Value.strings[txtIndex - table.num_txtTable].Value.ToString() + "\"");
                    }
                    return("TextRef_" + param);

                case NodeType.ComportRef:

                    return("Comport.FromOffset(\"" + param + "\")");

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

                case NodeType.ObjectTableRef:


                    return("ObjectTable.FromOffset(\"" + param + "\")");

                case NodeType.GameMaterialRef:

                    return("GameMaterial.FromOffset(\"" + param + "\")");

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

                case NodeType.VisualMaterial:
                    return("VisualMaterial.FromOffset(\"" + param + "\")");

                case NodeType.ModelRef:     // ModelCast

                    return("AIModel.FromOffset(\"" + param + "\")");

                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.FromOffset(\"" + param + "\")");
                }

                return("unknown");
            }