Ejemplo n.º 1
0
        public static Mind Read(EndianBinaryReader reader, Pointer offset)
        {
            Mind m = new Mind(offset);

            m.off_AI_model            = Pointer.Read(reader);
            m.off_intelligence_normal = Pointer.Read(reader);
            m.off_intelligence_reflex = Pointer.Read(reader);
            m.off_dsgMem = Pointer.Read(reader);
            m.off_name   = Pointer.Read(reader);

            if (m.off_AI_model != null)
            {
                m.AI_model = AIModel.FromOffset(m.offset);
                if (m.AI_model == null)
                {
                    Pointer.Goto(ref reader, m.off_AI_model);
                    m.AI_model = AIModel.Read(reader, m.off_AI_model);
                }
            }

            if (MapLoader.Loader.mode == MapLoader.Mode.Rayman2PC && m.off_dsgMem != null)
            {
                Pointer.Goto(ref reader, m.off_dsgMem);
                m.dsgMem = DsgMem.Read(reader, m.off_dsgMem);
            }
            return(m);
        }
Ejemplo n.º 2
0
        protected override void ReadInternal(Reader reader) {
            off_aiModel = Pointer.Read(reader); // 0x0
            off_actionTree = Pointer.Read(reader); //0x4
            off_comport = Pointer.Read(reader); //0x8
            if (Settings.s.game != Settings.Game.R2Demo) {
                off_lastComport = Pointer.Read(reader);
                off_actionTable = Pointer.Read(reader);
            }

            aiModel = Load.FromOffset<AIModel>(off_aiModel);
            comport = Load.FromOffset<Behavior>(off_comport);
            lastComport = Load.FromOffset<Behavior>(off_lastComport);
        }
Ejemplo n.º 3
0
        public string GetShortName(AIModel model, int index)
        {
            string shortName = "";

            if (name != null)
            {
                shortName = name;
                if (shortName.Contains("^CreateMacro:"))
                {
                    shortName = shortName.Substring(shortName.LastIndexOf("^CreateMacro:") + 13);
                }
                shortName = "[\"" + shortName + "\"]";
            }
            shortName = model.name + ".Macro[" + index + "]" + shortName;
            return(shortName);
        }
Ejemplo n.º 4
0
        public string GetShortName(AIModel model, BehaviorType type, int index)
        {
            string shortName = "";

            if (name != null)
            {
                shortName = name;
                //string comportNamePattern = @"^(?<family>[^\\]+?)\\(?<model>[^\\]+?)\\(?<model2>[^\\]+?)\.(?<type>...?)\^CreateIntelligence\^CreateComport:(?<name>.*?)$";
                if (shortName.Contains("^CreateComport:"))
                {
                    shortName = shortName.Substring(shortName.LastIndexOf("^CreateComport:") + 15);
                }
                shortName = "[\"" + shortName + "\"]";
            }
            shortName = (model != null?model.name:"") + "." + type + "[" + index + "]" + shortName;
            return(shortName);
        }
Ejemplo n.º 5
0
        public static AIModel FromOffsetOrRead(Pointer offset, Reader reader)
        {
            if (offset == null)
            {
                return(null);
            }
            AIModel ai = FromOffset(offset);

            if (ai == null)
            {
                Pointer.DoAt(ref reader, offset, () => {
                    ai = AIModel.Read(reader, offset);
                    MapLoader.Loader.aiModels.Add(ai);
                });
            }
            return(ai);
        }
Ejemplo n.º 6
0
        public static Intelligence Read(Reader reader, Pointer offset)
        {
            MapLoader    l = MapLoader.Loader;
            Intelligence i = new Intelligence(offset);

            i.off_aiModel    = Pointer.Read(reader); // 0x0
            i.off_actionTree = Pointer.Read(reader); //0x4
            i.off_comport    = Pointer.Read(reader); //0x8
            if (Settings.s.game != Settings.Game.R2Demo)
            {
                i.off_lastComport = Pointer.Read(reader);
                i.off_actionTable = Pointer.Read(reader);
            }

            i.aiModel     = AIModel.FromOffset(i.off_aiModel);
            i.comport     = Behavior.FromOffset(i.off_comport);
            i.lastComport = Behavior.FromOffset(i.off_comport);

            return(i);
        }
Ejemplo n.º 7
0
        protected override void ReadInternal(Reader reader)
        {
            off_AI_model            = Pointer.Read(reader);
            off_intelligence_normal = Pointer.Read(reader);
            if (Settings.s.game == Settings.Game.R2Demo)
            {
                off_dsgMem = Pointer.Read(reader);
                off_intelligence_reflex = Pointer.Read(reader);
            }
            else
            {
                off_intelligence_reflex = Pointer.Read(reader);
                off_dsgMem = Pointer.Read(reader);
            }
            if (Settings.s.hasNames)
            {
                off_name = Pointer.Read(reader);
            }
            byte0 = reader.ReadByte();
            byte1 = reader.ReadByte();
            byte2 = reader.ReadByte();
            byte3 = reader.ReadByte();

            if (Settings.s.game == Settings.Game.R2Demo)
            {
                // null
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
            }

            MapLoader l = MapLoader.Loader;

            AI_model           = l.FromOffsetOrRead <AIModel>(reader, off_AI_model);
            dsgMem             = l.FromOffsetOrRead <DsgMem>(reader, off_dsgMem);
            intelligenceNormal = l.FromOffsetOrRead <Intelligence>(reader, off_intelligence_normal);
            intelligenceReflex = l.FromOffsetOrRead <Intelligence>(reader, off_intelligence_reflex);
        }
Ejemplo n.º 8
0
        public static Mind Read(Reader reader, Pointer offset)
        {
            Mind m = new Mind(offset);

            m.off_AI_model            = Pointer.Read(reader);
            m.off_intelligence_normal = Pointer.Read(reader);
            //if (m.off_intelligence_normal != null) MapLoader.Loader.print(m.off_intelligence_normal);
            m.off_intelligence_reflex = Pointer.Read(reader);
            m.off_dsgMem = Pointer.Read(reader);
            if (Settings.s.hasNames)
            {
                m.off_name = Pointer.Read(reader);
            }
            m.byte0 = reader.ReadByte();
            m.byte1 = reader.ReadByte();
            m.byte2 = reader.ReadByte();
            m.byte3 = reader.ReadByte();

            m.AI_model = AIModel.FromOffsetOrRead(m.off_AI_model, reader);

            if (m.off_dsgMem != null)
            {
                Pointer.Goto(ref reader, m.off_dsgMem);
                m.dsgMem = DsgMem.Read(reader, m.off_dsgMem);
            }

            if (m.off_intelligence_normal != null)
            {
                Pointer.Goto(ref reader, m.off_intelligence_normal);
                m.intelligenceNormal = Intelligence.Read(reader, m.off_intelligence_normal);
            }

            if (m.off_intelligence_reflex != null)
            {
                Pointer.Goto(ref reader, m.off_intelligence_reflex);
                m.intelligenceReflex = Intelligence.Read(reader, m.off_intelligence_reflex);
            }
            return(m);
        }
Ejemplo n.º 9
0
        public string ToString(Perso perso, TranslatedScript.TranslationSettings ts, bool advanced = false)
        {
            MapLoader l    = MapLoader.Loader;
            short     mask = 0;

            AITypes aiTypes = Settings.s.aiTypes;

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

            switch (nodeType)
            {
            case ScriptNode.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 ScriptNode.NodeType.Condition:                     // GetConditionFunctionPtr
                if (param < aiTypes.conditionTable.Length)
                {
                    return(aiTypes.conditionTable[param]);
                }
                return("UnknownCondition_" + param);

            case ScriptNode.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 ScriptNode.NodeType.Function:                     // GetFunctionFunctionPtr
                if (param < aiTypes.functionTable.Length)
                {
                    return(aiTypes.functionTable[param]);
                }
                return("UnknownFunction_" + param);

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

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

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

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

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

            case ScriptNode.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 ScriptNode.NodeType.Constant:
                if (advanced)
                {
                    return("Constant: " + BitConverter.ToInt32(BitConverter.GetBytes(param), 0));
                }
                return(BitConverter.ToInt32(BitConverter.GetBytes(param), 0).ToString());

            case ScriptNode.NodeType.Real:
                NumberFormatInfo nfi = new NumberFormatInfo()
                {
                    NumberDecimalSeparator = "."
                };
                if (advanced)
                {
                    return("Real: " + BitConverter.ToSingle(BitConverter.GetBytes(param), 0).ToString(nfi));
                }
                return(BitConverter.ToSingle(BitConverter.GetBytes(param), 0).ToString(nfi) + "f");

            case ScriptNode.NodeType.Button:     // Button/entryaction
                EntryAction ea = EntryAction.FromOffset(param_ptr);

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

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

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

            case ScriptNode.NodeType.ConstantVector:
                return("Constant Vector: " + "0x" + param.ToString("x8"));    // TODO: get from address

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

            case ScriptNode.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 ScriptNode.NodeType.ModuleRef:
                if (advanced)
                {
                    return("ModuleRef: " + "0x" + (param).ToString("x8"));
                }
                return("GetModule(" + (int)param + ")");

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

            case ScriptNode.NodeType.String:
                string str = "ERR_STRING_NOTFOUND";
                if (l.strings.ContainsKey(param_ptr))
                {
                    str = l.strings[param_ptr];
                }
                if (advanced)
                {
                    return("String: " + param_ptr + " (" + str + ")");
                }
                return("\"" + str + "\"");

            case ScriptNode.NodeType.LipsSynchroRef:
                return("LipsSynchroRef: " + param_ptr);

            case ScriptNode.NodeType.FamilyRef:
                if (advanced)
                {
                    return("FamilyRef: " + param_ptr);
                }
                Family f = Family.FromOffset(param_ptr);
                if (f != null)
                {
                    return("GetFamily(\"" + f.name + "\")");
                }
                else
                {
                    return("Family.FromOffset(\"" + param_ptr + "\")");
                }

            case ScriptNode.NodeType.PersoRef:
                Perso argPerso = Perso.FromOffset(param_ptr);
                if (argPerso != null && perso != null && argPerso.offset == perso.offset)
                {
                    if (advanced)
                    {
                        return("PersoRef: this");
                    }
                    return("this");
                }
                string persoName = argPerso == null ? "ERR_PERSO_NOTFOUND" : argPerso.fullName;
                if (advanced)
                {
                    return("PersoRef: " + param_ptr + " (" + persoName + ")");
                }
                if (argPerso?.brain?.mind?.AI_model != null)
                {
                    AIModel aiModel = argPerso.brain.mind.AI_model;
                    // Make sure to add a cast in case the AI Model is accessed
                    return("((" + aiModel.name + ")GetPerso(\"" + argPerso.namePerso + "\"))");
                }
                return("GetPerso(\"" + argPerso.namePerso + "\")");

            case ScriptNode.NodeType.ActionRef:
                State  state     = State.FromOffset(param_ptr);
                string stateName = state == null ? "ERR_STATE_NOTFOUND" : state.ShortName;
                if (advanced)
                {
                    return("ActionRef: " + param_ptr + " " + stateName);
                }
                if (ts.useStateIndex)
                {
                    return("GetAction(" + state.index.ToString() + ")");
                }
                return(stateName);

            case ScriptNode.NodeType.SuperObjectRef:
                if (advanced)
                {
                    return("SuperObjectRef: " + param_ptr);
                }
                SuperObject so = SuperObject.FromOffset(param_ptr);
                if (so != null)
                {
                    return("GetSuperObject(\"" + so.Gao.name + "\")");
                }
                else
                {
                    return("SuperObject.FromOffset(\"" + param_ptr + "\")");
                }

            case ScriptNode.NodeType.WayPointRef:
                if (advanced)
                {
                    return("WayPointRef: " + param_ptr);
                }
                return("WayPoint.FromOffset(\"" + param_ptr + "\")");

            case ScriptNode.NodeType.TextRef:
                if (l.localization == null)
                {
                    return("TextRef");
                }
                if (advanced)
                {
                    return("TextRef: " + param + " (" + l.localization.GetTextForHandleAndLanguageID((int)param, 0) + ")");
                }
                if (ts.expandStrings)
                {
                    return("\"" + l.localization.GetTextForHandleAndLanguageID((int)param, 0) + "\"");    // Preview in english
                }
                else
                {
                    return("new TextReference(" + (int)param + ")");
                }

            case ScriptNode.NodeType.ComportRef:
                Behavior comportRef = Behavior.FromOffset(param_ptr);

                if (comportRef == null)
                {
                    if (advanced)
                    {
                        return("ComportRef: " + param_ptr + " (null)");
                    }
                    return("null");
                }
                else
                {
                    return(comportRef.ShortName);
                    //string type = comportRef.type == Behavior.BehaviorType.Normal ? "normalBehavior" : "reflexBehavior";
                    //return type + "[" + script.behaviorOrMacro.aiModel.GetBehaviorIndex(comportRef) + "]";
                }

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

            case ScriptNode.NodeType.ObjectTableRef:
                if (advanced)
                {
                    return("ObjectTableRef: " + param_ptr);
                }

                if (ts.useHashIdentifiers)
                {
                    string objectListJson = ObjectList.FromOffset(param_ptr).ToJSON();

                    string objectListHash = HashUtils.MD5Hash(objectListJson);
                    return("ObjectList.FromHash(\"" + objectListHash + "\")");
                }

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

            case ScriptNode.NodeType.GameMaterialRef:
                if (advanced)
                {
                    return("GameMaterialRef: " + param_ptr);
                }
                if (ts.useHashIdentifiers)
                {
                    string gmtJson = GameMaterial.FromOffset(param_ptr).ToJSON();

                    string gmtHash = HashUtils.MD5Hash(gmtJson);
                    return("GameMaterial.FromHash(\"" + gmtHash + "\")");
                }
                return("GameMaterial.FromOffset(\"" + param_ptr + "\")");

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

            case ScriptNode.NodeType.VisualMaterial:
                if (advanced)
                {
                    return("VisualMaterial: " + param_ptr);
                }

                if (ts.useHashIdentifiers)
                {
                    string vmtJson = VisualMaterial.FromOffset(param_ptr).ToJSON();

                    string vmtHash = HashUtils.MD5Hash(vmtJson);
                    return("VisualMaterial.FromHash(\"" + vmtHash + "\")");
                }

                return("VisualMaterial.FromOffset(\"" + param_ptr + "\")");

            case ScriptNode.NodeType.ModelRef:                     // ModelCast
                if (advanced)
                {
                    return("AIModel: " + param_ptr);
                }
                AIModel model = AIModel.FromOffset(param_ptr);
                return(model != null ? model.name : "null");

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

            case ScriptNode.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 ScriptNode.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 ScriptNode.NodeType.SubRoutine:
                if (advanced)
                {
                    return("Eval SubRoutine: " + param_ptr);
                }
                Macro macro = Macro.FromOffset(param_ptr);
                if (macro == null)
                {
                    return("null");
                }
                return("evalMacro(" + macro.ShortName + ");");

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

            case ScriptNode.NodeType.GraphRef:
                if (advanced)
                {
                    return("Graph: " + "0x" + (param).ToString("x8"));
                }
                return("Graph.FromOffset(\"" + param_ptr + "\")");
            }

            return("unknown");
        }
Ejemplo n.º 10
0
        public static AIModel Read(EndianBinaryReader reader, Pointer offset)
        {
            MapLoader l  = MapLoader.Loader;
            AIModel   ai = new AIModel(offset);

            ai.off_behaviors_normal = Pointer.Read(reader);
            ai.off_behaviors_reflex = Pointer.Read(reader);
            ai.off_dsgVar           = Pointer.Read(reader);
            ai.off_macros           = Pointer.Read(reader);
            ai.flags = reader.ReadUInt32();

            if (ai.off_behaviors_normal != null)
            {
                Pointer.Goto(ref reader, ai.off_behaviors_normal);
                Pointer off_entries = Pointer.Read(reader);
                uint    num_entries = reader.ReadUInt32();
                ai.behaviors_normal = new Behavior[num_entries];
                if (num_entries > 0 && off_entries != null)
                {
                    Pointer.Goto(ref reader, off_entries);
                    for (int i = 0; i < num_entries; i++)
                    {
                        ai.behaviors_normal[i] = Behavior.Read(reader, Pointer.Current(reader));
                    }
                }
            }
            if (ai.off_behaviors_reflex != null)
            {
                Pointer.Goto(ref reader, ai.off_behaviors_reflex);
                Pointer off_entries = Pointer.Read(reader);
                uint    num_entries = reader.ReadUInt32();
                ai.behaviors_reflex = new Behavior[num_entries];
                if (num_entries > 0 && off_entries != null)
                {
                    Pointer.Goto(ref reader, off_entries);
                    for (int i = 0; i < num_entries; i++)
                    {
                        ai.behaviors_reflex[i] = Behavior.Read(reader, Pointer.Current(reader));
                    }
                }
            }

            if (l.mode == MapLoader.Mode.Rayman2PC && ai.off_dsgVar != null)
            {
                Pointer.Goto(ref reader, ai.off_dsgVar);
                ai.dsgVar = DsgVar.Read(reader, ai.off_dsgVar);
            }

            if (ai.off_macros != null)
            {
                Pointer.Goto(ref reader, ai.off_macros);
                Pointer off_entries = Pointer.Read(reader);
                byte    num_entries = reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                ai.macros = new Macro[num_entries];
                if (num_entries > 0 && off_entries != null)
                {
                    Pointer.Goto(ref reader, off_entries);
                    for (int i = 0; i < num_entries; i++)
                    {
                        ai.macros[i] = Macro.Read(reader, Pointer.Current(reader));
                    }
                }
            }
            l.aiModels.Add(ai);
            return(ai);
        }
Ejemplo n.º 11
0
        public static AIModel Read(Reader reader, Pointer offset)
        {
            MapLoader l  = MapLoader.Loader;
            AIModel   ai = new AIModel(offset);

            //l.print("AIModel @ " + offset);

            ai.off_behaviors_normal = Pointer.Read(reader);
            ai.off_behaviors_reflex = Pointer.Read(reader);
            ai.off_dsgVar           = Pointer.Read(reader);
            if (Settings.s.engineVersion >= Settings.EngineVersion.R2)
            {
                ai.off_macros = Pointer.Read(reader);
                ai.flags      = reader.ReadUInt32();
            }

            if (ai.off_behaviors_normal != null)
            {
                Pointer.Goto(ref reader, ai.off_behaviors_normal);
                Pointer off_entries = Pointer.Read(reader);
                uint    num_entries = reader.ReadUInt32();
                ai.behaviors_normal = new Behavior[num_entries];
                if (num_entries > 0 && off_entries != null)
                {
                    Pointer.Goto(ref reader, off_entries);
                    for (int i = 0; i < num_entries; i++)
                    {
                        ai.behaviors_normal[i]         = Behavior.Read(reader, Pointer.Current(reader));
                        ai.behaviors_normal[i].type    = Behavior.BehaviorType.Rule;
                        ai.behaviors_normal[i].aiModel = ai;
                        ai.behaviors_normal[i].index   = i;
                    }
                }
            }
            if (ai.off_behaviors_reflex != null)
            {
                Pointer.Goto(ref reader, ai.off_behaviors_reflex);
                Pointer off_entries = Pointer.Read(reader);
                uint    num_entries = reader.ReadUInt32();
                ai.behaviors_reflex = new Behavior[num_entries];
                if (num_entries > 0 && off_entries != null)
                {
                    Pointer.Goto(ref reader, off_entries);
                    for (int i = 0; i < num_entries; i++)
                    {
                        ai.behaviors_reflex[i]         = Behavior.Read(reader, Pointer.Current(reader));
                        ai.behaviors_reflex[i].type    = Behavior.BehaviorType.Reflex;
                        ai.behaviors_reflex[i].aiModel = ai;
                        ai.behaviors_reflex[i].index   = i;
                    }
                }
            }

            if (ai.off_dsgVar != null)
            {
                Pointer.Goto(ref reader, ai.off_dsgVar);
                ai.dsgVar = DsgVar.Read(reader, ai.off_dsgVar);
            }

            if (ai.off_macros != null)
            {
                Pointer.Goto(ref reader, ai.off_macros);
                Pointer off_entries = Pointer.Read(reader);
                byte    num_entries = reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                reader.ReadByte();
                ai.macros = new Macro[num_entries];
                if (num_entries > 0 && off_entries != null)
                {
                    Pointer.Goto(ref reader, off_entries);
                    for (int i = 0; i < num_entries; i++)
                    {
                        ai.macros[i]         = Macro.Read(reader, Pointer.Current(reader));
                        ai.macros[i].aiModel = ai;
                        ai.macros[i].index   = i;
                    }
                }
            }
            //l.aiModels.Add(ai);
            return(ai);
        }