public void UpdateLivePreview() { Reader reader = MapLoader.Loader.livePreviewReader; foreach (SuperObject so in MapLoader.Loader.superObjects) { if (!(so.data is Perso)) { continue; } if (so.off_matrix == null) { continue; } Pointer.Goto(ref reader, so.off_matrix); so.matrix = Matrix.Read(MapLoader.Loader.livePreviewReader, so.off_matrix); if (so.data != null && so.data.Gao != null) { so.data.Gao.transform.localPosition = so.matrix.GetPosition(convertAxes: true); so.data.Gao.transform.localRotation = so.matrix.GetRotation(convertAxes: true); so.data.Gao.transform.localScale = so.matrix.GetScale(convertAxes: true); if (so.data is Perso) { Perso perso = (Perso)so.data; PersoBehaviour pb = perso.Gao.GetComponent <PersoBehaviour>(); if (pb != null) { Pointer.Goto(ref reader, perso.p3dData.offset); perso.p3dData.UpdateCurrentState(reader); // State offset changed? if (perso.p3dData.stateCurrent != null) { pb.SetState(perso.p3dData.stateCurrent.index); pb.autoNextState = true; } } MindComponent mc = perso.Gao.GetComponent <MindComponent>(); if (mc != null) { Mind mind = mc.mind; Pointer.DoAt(ref reader, mind.Offset, () => { mind.UpdateCurrentBehaviors(reader); }); } DsgVarComponent dsgVarComponent = perso.Gao.GetComponent <DsgVarComponent>(); if (dsgVarComponent != null) { dsgVarComponent.SetPerso(perso); } CustomBitsComponent customBitsComponent = perso.Gao.GetComponent <CustomBitsComponent>(); if (customBitsComponent != null) { Pointer.Goto(ref reader, perso.off_stdGame); perso.stdGame = StandardGame.Read(reader, perso.off_stdGame); customBitsComponent.stdGame = perso.stdGame; customBitsComponent.Init(); } DynamicsMechanicsComponent dnComponent = perso.Gao.GetComponent <DynamicsMechanicsComponent>(); if (dnComponent != null) { Pointer.DoAt(ref reader, perso.off_dynam, () => { perso.dynam = Dynam.Read(reader, perso.off_dynam); }); dnComponent.SetDynamics(perso.dynam.dynamics); } } } } Perso camera = loader.persos.FirstOrDefault(p => p != null && p.namePerso.Equals("StdCamer")); if (camera != null) { SuperObject cameraSO = camera.SuperObject; Pointer.Goto(ref reader, cameraSO.off_matrix); cameraSO.matrix = Matrix.Read(reader, cameraSO.off_matrix); camera.Gao.transform.localPosition = cameraSO.matrix.GetPosition(convertAxes: true); camera.Gao.transform.localRotation = cameraSO.matrix.GetRotation(convertAxes: true); camera.Gao.transform.localScale = cameraSO.matrix.GetScale(convertAxes: true); Camera.main.transform.position = camera.Gao.transform.position; Camera.main.transform.rotation = camera.Gao.transform.rotation * Quaternion.Euler(0, 180, 0); } }
public static Perso Read(Reader reader, Pointer offset, SuperObject so) { MapLoader l = MapLoader.Loader; Perso p = new Perso(offset, so); //l.print("Perso " + offset); l.persos.Add(p); p.off_3dData = Pointer.Read(reader); // 0x0 p.off_stdGame = Pointer.Read(reader); // 4 Standard Game info p.off_dynam = Pointer.Read(reader); // 0x8 Dynam if (Settings.s.engineVersion == Settings.EngineVersion.Montreal) { reader.ReadUInt32(); } p.off_brain = Pointer.Read(reader); // 0xC p.off_camera = Pointer.Read(reader); // 0x10 is Camera in Rayman 2 p.off_collSet = Pointer.Read(reader); // 0x14 collset p.off_msWay = Pointer.Read(reader); // 0x18 p.off_msLight = Pointer.Read(reader); // 0x1C - MSLight if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { reader.ReadUInt32(); } p.off_sectInfo = Pointer.Read(reader); // 0x20 // Pointer to struct that points to active sector reader.ReadUInt32(); // 0x24 reader.ReadUInt32(); if (Settings.s.game == Settings.Game.RA || Settings.s.game == Settings.Game.RM) { reader.ReadUInt32(); } if (Settings.s.engineVersion < Settings.EngineVersion.R3) { reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); } Pointer.DoAt(ref reader, p.off_3dData, () => { p.p3dData = Perso3dData.Read(reader, p.off_3dData); }); Pointer.DoAt(ref reader, p.off_stdGame, () => { p.stdGame = StandardGame.Read(reader, p.off_stdGame); if (Settings.s.hasObjectTypes) { p.nameFamily = p.stdGame.GetName(0); p.nameModel = p.stdGame.GetName(1); p.namePerso = p.stdGame.GetName(2); } else { p.nameFamily = "Family" + p.stdGame.objectTypes[0]; p.nameModel = "Model" + p.stdGame.objectTypes[1]; p.namePerso = "Instance" + p.stdGame.objectTypes[2]; if (p.p3dData != null && p.p3dData.family != null && p.p3dData.family.name == null) { p.p3dData.family.name = p.nameFamily; p.p3dData.family.family_index = p.stdGame.objectTypes[0]; if (UnitySettings.CreateFamilyGameObjects && p.p3dData.family.Gao != null) { p.p3dData.family.Gao.name = "[Family] " + p.nameFamily; } } } }); l.print("[" + p.nameFamily + "] " + p.nameModel + " | " + p.namePerso + " - offset: " + offset + " superObject offset: " + (so != null?so.offset.ToString():"null")); if (Settings.s.engineVersion > Settings.EngineVersion.Montreal && Settings.s.game != Settings.Game.R2Revolution) { Pointer.DoAt(ref reader, p.off_dynam, () => { p.dynam = Dynam.Read(reader, p.off_dynam); }); } Pointer.DoAt(ref reader, p.off_brain, () => { p.brain = Brain.Read(reader, p.off_brain); if (p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null && p.nameModel != null) { p.brain.mind.AI_model.name = p.nameModel; } }); /*if (l.mode == MapLoader.Mode.Rayman2PC && off_msWay != null) { * MS_Way is always empty at start, instead check DsgVars for graphs * Pointer off_current = Pointer.Goto(ref reader, off_msWay); * * p.msWay = MSWay.Read(reader, off_msWay); * Pointer.Goto(ref reader, off_current); * * // Graph read? * if (p.msWay.graph != null) { * GameObject go_msWay = new GameObject("MSWay"); * go_msWay.transform.SetParent(p.Gao.transform); * * GameObject go_graph = new GameObject("Graph"); * go_graph.transform.SetParent(go_msWay.transform); * * int nodeNum = 0; * foreach (GraphNode node in p.msWay.graph.nodeList) { * GameObject go_graphNode = new GameObject("GraphNode[" + nodeNum + "].WayPoint"); * go_graphNode.transform.position.Set(node.wayPoint.position.x, node.wayPoint.position.y, node.wayPoint.position.z); * go_graphNode.transform.SetParent(go_graph.transform); * nodeNum++; * } * } * }*/ if (p.p3dData != null && p.p3dData.family != null) { if (p.p3dData.off_objectList != null && p.p3dData.family.GetIndexOfPhysicalList(p.p3dData.off_objectList) == -1) { ObjectList ol = ObjectList.FromOffsetOrRead(p.p3dData.off_objectList, reader); p.p3dData.family.AddNewPhysicalList(ol); /*if (ol != null) { * p.p3dData.family.AddNewPhysicalList(ol); * ol.Gao.transform.SetParent(p.p3dData.family.Gao.transform); * }*/ } if (p.p3dData.off_objectListInitial != null && p.p3dData.family.GetIndexOfPhysicalList(p.p3dData.off_objectListInitial) == -1) { ObjectList ol = ObjectList.FromOffsetOrRead(p.p3dData.off_objectListInitial, reader); p.p3dData.family.AddNewPhysicalList(ol); /*if (ol != null) { * p.p3dData.family.AddNewPhysicalList(ol); * ol.Gao.transform.SetParent(p.p3dData.family.Gao.transform); * }*/ } if (p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null && !(Settings.s.engineVersion == Settings.EngineVersion.R3 && Settings.s.loadFromMemory)) // Weird bug for R3 memory loading // Add physical objects tables hidden in scripts { AIModel ai = p.brain.mind.AI_model; if (ai.behaviors_normal != null) { for (int i = 0; i < ai.behaviors_normal.Length; i++) { if (ai.behaviors_normal[i].scripts != null) { for (int j = 0; j < ai.behaviors_normal[i].scripts.Length; j++) { List <ScriptNode> nodes = p.brain.mind.AI_model.behaviors_normal[i].scripts[j].scriptNodes; foreach (ScriptNode node in nodes) { if (node.param_ptr != null && node.nodeType == ScriptNode.NodeType.ObjectTableRef) { ObjectList ol = ObjectList.FromOffsetOrRead(node.param_ptr, reader); ol.unknownFamilyName = p.p3dData.family.name; ol.AddToFamilyLists(p); } } } } } } if (ai.behaviors_reflex != null) { for (int i = 0; i < ai.behaviors_reflex.Length; i++) { if (ai.behaviors_reflex[i].scripts != null) { for (int j = 0; j < ai.behaviors_reflex[i].scripts.Length; j++) { List <ScriptNode> nodes = p.brain.mind.AI_model.behaviors_reflex[i].scripts[j].scriptNodes; foreach (ScriptNode node in nodes) { if (node.param_ptr != null && node.nodeType == ScriptNode.NodeType.ObjectTableRef) { ObjectList ol = ObjectList.FromOffsetOrRead(node.param_ptr, reader); ol.unknownFamilyName = p.p3dData.family.name; ol.AddToFamilyLists(p); } } } } } } if (ai.macros != null) { for (int i = 0; i < ai.macros.Length; i++) { if (ai.macros[i].script != null) { List <ScriptNode> nodes = p.brain.mind.AI_model.macros[i].script.scriptNodes; foreach (ScriptNode node in nodes) { if (node.param_ptr != null && node.nodeType == ScriptNode.NodeType.ObjectTableRef) { ObjectList ol = ObjectList.FromOffsetOrRead(node.param_ptr, reader); ol.unknownFamilyName = p.p3dData.family.name; ol.AddToFamilyLists(p); } } } } } } if (p.p3dData.family.GetIndexOfPhysicalList(p.p3dData.off_objectList) != -1) { p.p3dData.objectList = ObjectList.FromOffset(p.p3dData.off_objectList); } } Pointer.DoAt(ref reader, p.off_collSet, () => { p.collset = CollSet.Read(reader, p, p.off_collSet); }); Pointer.DoAt(ref reader, p.off_sectInfo, () => { p.sectInfo = PersoSectorInfo.Read(reader, p.off_sectInfo); }); return(p); }