public void SetPerso(OpenSpace.ROM.Perso perso) { this.persoROM = perso; if (perso != null && perso.brain?.Value != null) { dsgMemROM = perso.brain.Value.dsgMem.Value; dsgVarROM = perso.brain.Value.aiModel?.Value.dsgVar?.Value; if (dsgVarROM?.info?.Value == null) { return; } editableEntries = new DsgVarEditableEntry[dsgVarROM.info.Value.entries.Length]; for (int i = 0; i < editableEntries.Length; i++) { List <OpenSpace.ROM.DsgMemInfo> memInfos = new List <OpenSpace.ROM.DsgMemInfo>(); if (dsgMemROM?.info?.Value != null && dsgMemROM.info.Value.info.Length > 0) { for (int j = 0; j < dsgMemROM.info.Value.info.Length; j++) { OpenSpace.ROM.DsgMemInfo info = dsgMemROM.info.Value.info[j].Value; OpenSpace.ROM.DsgVarInfo.Entry entry = dsgVarROM.info.Value.GetEntryFromIndex(info.value.index); if (entry == dsgVarROM.info.Value.entries[i]) { memInfos.Add(info); } } } DsgVarEditableEntry editableEntry = new DsgVarEditableEntry(dsgVarROM.info.Value.entries[i], memInfos); editableEntries[i] = editableEntry; } } }
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 || 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.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"); }
public void CreateGameObjects(OpenSpace.AI.Behavior.BehaviorType type, BrainComponent brain, Perso perso) { if (this.comports.Value == null) { return; } string ruleOrReflex = type.ToString(); GameObject intelParent = new GameObject(ruleOrReflex + " behaviours"); intelParent.transform.parent = brain.gameObject.transform; Reference <Comport>[] behaviors = this.comports.Value.comports; int iter = 0; foreach (var behaviorRef in behaviors) { Comport behavior = behaviorRef.Value; if (behavior == null) { continue; } BrainComponent.Comport c = new BrainComponent.Comport(); GameObject behaviorGao = new GameObject(ruleOrReflex + " #" + iter); behaviorGao.transform.parent = intelParent.transform; if (behavior.scripts?.Value?.scripts != null) { foreach (Reference <OpenSpace.ROM.Script> scriptRef in behavior.scripts?.Value?.scripts) { OpenSpace.ROM.Script script = scriptRef.Value; GameObject scriptGao = new GameObject("Script"); scriptGao.transform.parent = behaviorGao.transform; ROMScriptComponent scriptComponent = scriptGao.AddComponent <ROMScriptComponent>(); scriptComponent.SetScript(script, perso); c.Scripts.Add(scriptComponent); } } if (behavior.firstScript.Value != null) { ROMScriptComponent scriptComponent = behaviorGao.AddComponent <ROMScriptComponent>(); scriptComponent.SetScript(behavior.firstScript.Value, perso); c.FirstScript = scriptComponent; } if (iter == 0) { behaviorGao.name += " (Init)"; } if ((behavior.scripts?.Value == null || behavior.scripts?.Value.length == 0) && behavior.firstScript?.Value == null) { behaviorGao.name += " (Empty)"; } c.Offset = behavior.Offset; c.GaoName = behaviorGao.name; c.Name = behavior.IndexString; switch (type) { case AI.Behavior.BehaviorType.Intelligence: brain.Intelligence.Add(c); break; case AI.Behavior.BehaviorType.Reflex: brain.Reflex.Add(c); break; } iter++; } }
public string ToString(Perso perso) { if (scriptNode != null) { string firstChildNode = (this.children.Count > 0 && this.children[0] != null) ? this.children[0].ToString() : "null"; string secondChildNode = (this.children.Count > 1 && this.children[1] != null) ? this.children[1].ToString() : "null"; string prefix = (ts.printAddresses ? "{" + scriptNode.offset + "}" : ""); AITypes aiTypes = Settings.s.aiTypes; uint param = scriptNode.param; switch (scriptNode.nodeType) { case ScriptNode.NodeType.KeyWord: string keyword = param < aiTypes.keywordTable.Length ? aiTypes.keywordTable[param] : ""; switch (keyword) { // If keywords case "If": return(prefix + "if ({condition})".Replace("{condition}", firstChildNode)); case "IfNot": return(prefix + "if (!({condition}))".Replace("{condition}", firstChildNode)); case "If2": return(prefix + "if (globalRandomizer % 2 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If4": return(prefix + "if (globalRandomizer % 4 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If8": return(prefix + "if (globalRandomizer % 8 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If16": return(prefix + "if (globalRandomizer % 16 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If32": return(prefix + "if (globalRandomizer % 32 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "If64": return(prefix + "if (globalRandomizer % 64 == 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot2": return(prefix + "if (globalRandomizer % 2 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot4": return(prefix + "if (globalRandomizer % 4 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot8": return(prefix + "if (globalRandomizer % 8 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot16": return(prefix + "if (globalRandomizer % 16 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot32": return(prefix + "if (globalRandomizer % 32 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfNot64": return(prefix + "if (globalRandomizer % 64 != 0 && ({condition}))".Replace("{condition}", firstChildNode)); case "IfDebug": return(prefix + "if (debug && {condition})".Replace("{condition}", firstChildNode)); case "IfNotU64": return(prefix + "if (!u64)\n{\n{childNodes}\n}\n".Replace("{childNodes}", string.Join("\n", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())))); // Then case "Then": return(prefix + "{\n{childNodes}\n}\n".Replace("{childNodes}", string.Join("\n", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())))); // Else case "Else": return(prefix + "else\n{\n{childNodes}\n}\n".Replace("{childNodes}", string.Join("\n", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())))); default: return(prefix + scriptNode.ToString(perso, ts.settings)); } case ScriptNode.NodeType.Condition: string cond = param < aiTypes.conditionTable.Length ? aiTypes.conditionTable[param] : ""; switch (cond) { // Boolean conditions: case "Cond_And": return(prefix + firstChildNode + " && " + secondChildNode); case "Cond_Or": return(prefix + firstChildNode + " || " + secondChildNode); case "Cond_Not": return(prefix + "!" + "(" + firstChildNode + ")"); case "Cond_XOR": return(prefix + firstChildNode + " xor " + secondChildNode); // XOR // Real (float) comparisons: case "Cond_Equal": return(prefix + firstChildNode + " == " + secondChildNode); case "Cond_Different": return(prefix + firstChildNode + " != " + secondChildNode); case "Cond_Lesser": return(prefix + firstChildNode + " < " + secondChildNode); case "Cond_Greater": return(prefix + firstChildNode + " > " + secondChildNode); case "Cond_LesserOrEqual": return(prefix + firstChildNode + " <= " + secondChildNode); case "Cond_GreaterOrEqual": return(prefix + firstChildNode + " >= " + secondChildNode); // Button condition: /*case 44: * case 45: * case 46: * case 47: * return prefix + firstChildNode;*/ default: if (firstChildNode != null) { return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); } else { return(prefix + scriptNode.ToString(perso, ts.settings) + "()"); } } case ScriptNode.NodeType.Function: string function = param < aiTypes.functionTable.Length ? aiTypes.functionTable[param] : ""; string ternaryCheck = ""; switch (function) { // Ternary real operators (e.g. x > y ? true : false) case "Func_TernInf": case "Func_TernSup": case "Func_TernEq": case "Func_TernInfEq": case "Func_TernSupEq": switch (function) { case "Func_TernInf": ternaryCheck = " < "; break; case "Func_TernSup": ternaryCheck = " > "; break; case "Func_TernEq": ternaryCheck = " == "; break; case "Func_TernInfEq": ternaryCheck = " <= "; break; case "Func_TernSupEq": ternaryCheck = " >= "; break; } if (this.children.Count >= 4) { return(prefix + "((" + this.children[0] + ternaryCheck + this.children[1] + ") ? " + this.children[2] + " : " + this.children[3] + ")"); } else { return("ERROR"); } case "Func_TernOp": // conditional ternary operator (cond ? true : false) string childCast1 = ""; string childCast2 = ""; if (this.children[1].scriptNode.nodeType == ScriptNode.NodeType.DsgVarRef && this.children[2].scriptNode.nodeType == ScriptNode.NodeType.Real) { childCast1 = "(float)"; } if (this.children[2].scriptNode.nodeType == ScriptNode.NodeType.DsgVarRef && this.children[1].scriptNode.nodeType == ScriptNode.NodeType.Real) { childCast2 = "(float)"; } return(prefix + "((" + this.children[0] + ") ? " + childCast1 + this.children[1] + " : " + childCast2 + this.children[2] + ")"); default: string func = scriptNode.ToString(perso, ts.settings); return(prefix + func + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); } case ScriptNode.NodeType.Procedure: string procedure = param < aiTypes.procedureTable.Length ? aiTypes.procedureTable[param] : ""; switch (procedure) { case "Proc_Loop": return(prefix + "for(int i = 0; i < " + firstChildNode + "; i++)\n{"); case "Proc_EndLoop": return(prefix + "}\n"); case "Proc_Break": return(prefix + "break;\n"); default: string proc = scriptNode.ToString(perso, ts.settings); return(prefix + proc + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ");"); } case ScriptNode.NodeType.Operator: string op = param < aiTypes.operatorTable.Length ? aiTypes.operatorTable[param] : ""; //Pointer persoPtr = null; switch (op) { // scalar: case "Operator_Plus": return("(" + firstChildNode + (children[1].scriptNode.param >= 0 ? " + " : "") + secondChildNode + ")"); case "Operator_Minus": case "Operator_UnaryMinus": if (children.Count > 1) { return("(" + firstChildNode + " - " + secondChildNode + ")"); } else { return("-" + firstChildNode); } case "Operator_Mul": return("(" + firstChildNode + " * " + secondChildNode + ")"); case "Operator_Div": return("(" + firstChildNode + " / " + secondChildNode + ")"); case "Operator_Mod": return("(" + firstChildNode + " % " + secondChildNode + ")"); // affect: case "Operator_PlusAffect": case "Operator_PlusPlusAffect": return(children.Count > 1 ? (firstChildNode + " += " + secondChildNode + ";") : firstChildNode + "++" + ";"); case "Operator_MinusAffect": case "Operator_MinusMinusAffect": return(children.Count > 1 ? (firstChildNode + " -= " + secondChildNode + ";") : firstChildNode + "--" + ";"); case "Operator_MulAffect": return(firstChildNode + " *= " + secondChildNode + ";"); case "Operator_DivAffect": return(firstChildNode + " /= " + secondChildNode + ";"); case "Operator_Affect": return(firstChildNode + " = " + secondChildNode + ";"); case "Operator_Dot": // dot operator return(firstChildNode + "." + secondChildNode); case ".X": return(firstChildNode + ".x"); // vector case ".Y": return(firstChildNode + ".y"); // vector case ".Z": return(firstChildNode + ".z"); // vector case "Operator_VectorPlusVector": return(firstChildNode + " + " + secondChildNode); case "Operator_VectorMinusVector": return(firstChildNode + " - " + secondChildNode); case "Operator_VectorMulScalar": return(firstChildNode + " * " + secondChildNode); case "Operator_VectorDivScalar": return(firstChildNode + " / " + secondChildNode); case "Operator_VectorUnaryMinus": return("-" + firstChildNode); case ".X:=": return(firstChildNode + ".x = " + secondChildNode + ";"); // vector case ".Y:=": return(firstChildNode + ".y = " + secondChildNode + ";"); // vector case ".Z:=": return(firstChildNode + ".z = " + secondChildNode + ";"); // vector case "Operator_Ultra": // Ultra operator (execute code for different object) return(firstChildNode + ".{code}".Replace("{code}", secondChildNode)); case "Operator_ModelCast": return("((" + firstChildNode + ")(" + secondChildNode + "))"); case "Operator_Array": return(firstChildNode + "[" + secondChildNode + "]"); default: string proc = "(" + scriptNode.param + ")" + scriptNode.ToString(perso, ts.settings); return(prefix + proc + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ");"); } case ScriptNode.NodeType.Field: if (firstChildNode != null) { return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); } else { return(prefix + scriptNode.ToString(perso, ts.settings)); } case ScriptNode.NodeType.Vector: case ScriptNode.NodeType.ConstantVector: return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ")"); case ScriptNode.NodeType.MetaAction: return(prefix + scriptNode.ToString(perso, ts.settings) + "(" + string.Join(", ", Array.ConvertAll <Node, string>(this.children.ToArray(), x => x.ToString())) + ");"); case ScriptNode.NodeType.SubRoutine: return(prefix + scriptNode.ToString(perso, ts.settings)); default: return(prefix + scriptNode.ToString(perso, ts.settings)); } } else // Root node returns all children concatenated { string result = ""; foreach (Node child in this.children) { result += child.ToString() + '\n'; } return(result); } }