Example #1
0
        public static IPO Read(EndianBinaryReader reader, Pointer offset, SuperObject so)
        {
            MapLoader l   = MapLoader.Loader;
            IPO       ipo = new IPO(offset, so);

            ipo.off_data      = Pointer.Read(reader);
            ipo.off_radiosity = Pointer.Read(reader);
            reader.ReadUInt32();
            reader.ReadUInt32();
            reader.ReadUInt32();
            reader.ReadUInt32();
            reader.ReadUInt32();
            ipo.name = "IPO";
            if (l.mode == MapLoader.Mode.Rayman3GC)
            {
                ipo.name = new string(reader.ReadChars(0x32)).TrimEnd('\0');
            }
            Pointer.Goto(ref reader, ipo.off_data);
            ipo.data = PhysicalObject.Read(reader, ipo.off_data);
            if (ipo.data != null)
            {
                ipo.data.Gao.transform.parent = ipo.Gao.transform;
            }

            /*if (ipo.data != null && ipo.data.visualSet.Count > 0) {
             *  if (ipo.data.visualSet[0].obj is R3Mesh) {
             *      GameObject meshGAO = ((R3Mesh)ipo.data.visualSet[0].obj).gao;
             *      meshGAO.transform.parent = ipo.Gao.transform;
             *  }
             * }*/
            return(ipo);
        }
Example #2
0
        public void InitPostLoad()
        {
            switch (type)
            {
            // Fill these in after loading
            case DsgVarInfoEntry.DsgVarType.Perso:
                SuperObject so = SuperObject.FromOffset(valuePointer);
                if (so != null)
                {
                    valuePerso = so.data as Perso;
                }
                break;

            case DsgVarInfoEntry.DsgVarType.Action:
                valueAction = State.FromOffset(valuePointer);
                break;

            case DsgVarInfoEntry.DsgVarType.SuperObject:
                valueSuperObject = SuperObject.FromOffset(valuePointer);
                break;
            }

            if (dsgMem != null)
            {
                RegisterReferences(dsgMem);
            }
        }
Example #3
0
 private void LeftMouseClick()
 {
     if (player.hud.MouseInBounds())
     {
         GameObject hitObject = FindHitObject();
         Vector3    hitPoint  = FindHitPoint();
         if (hitObject && hitPoint != ResourceManager.InvalidPosition)
         {
             if (player.SelectedObject)
             {
                 player.SelectedObject.MouseClick(hitObject, hitPoint, player);
             }
             else if (hitObject.name != "Ground")
             {
                 SuperObject superObject = hitObject.transform.parent.GetComponent <SuperObject>();
                 if (superObject)
                 {
                     //we already know the player has no selected object
                     player.SelectedObject = superObject;
                     superObject.SetSelection(true, player.hud.GetPlayingArea());
                 }
             }
         }
     }
 }
Example #4
0
    private void ParseSelectionJSON(JSONNode msg)
    {
        MapLoader   l     = MapLoader.Loader;
        Perso       perso = null;
        SuperObject so    = null;

        if (msg["offset"] != null && msg["offset"] != "null")
        {
            if (msg["type"] != null && msg["type"] == SuperObject.Type.Perso.ToString())
            {
                perso = l.persos.FirstOrDefault(p => p.offset.ToString() == msg["offset"]);
                if (perso != null)
                {
                    PersoBehaviour pb = perso.Gao.GetComponent <PersoBehaviour>();
                    selector.Select(pb, view: msg["view"] != null);
                }
            }
            else
            {
                so = l.superObjects.FirstOrDefault(s => s.offset.ToString() == msg["offset"]);
                if (so != null)
                {
                    selector.Select(so);
                }
            }
        }
        else
        {
            selector.Deselect();
        }
    }
Example #5
0
    private JSONObject GetSuperObjectJSON(SuperObject so)
    {
        JSONObject soJSON = new JSONObject();

        if (so.Gao != null)
        {
            soJSON["name"] = so.Gao.name;
        }
        soJSON["type"]   = so.type.ToString();
        soJSON["offset"] = so.offset.ToString();
        if (so.Gao != null)
        {
            soJSON["position"] = so.Gao.transform.localPosition;
            soJSON["rotation"] = so.Gao.transform.localEulerAngles;
            soJSON["scale"]    = so.Gao.transform.localScale;
        }
        if (so.type == SuperObject.Type.Perso)
        {
            soJSON["perso"] = GetPersoJSON((Perso)so.data);
        }
        JSONArray children = new JSONArray();

        for (int i = 0; i < so.children.Count; i++)
        {
            children.Add(GetSuperObjectJSON(so.children[i]));
        }
        soJSON["children"] = children;
        return(soJSON);
    }
Example #6
0
        private void btnAIUIConfig_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbAppId.Text))
            {
                MessageBox.Show("对不起,请输入AppId!");
                return;
            }
            if (string.IsNullOrEmpty(tbAppKey.Text))
            {
                MessageBox.Show("对不起,请输入AppKey!");
                return;
            }
            if (string.IsNullOrEmpty(tbScene.Text))
            {
                MessageBox.Show("对不起,请输入情景模式!");
                return;
            }

            if (MessageBox.Show("真的要进行吗?", "提示", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                //保存配置
                SuperObject.Config.SetValue <string>(CONFIG_ID_APPID, tbAppId.Text.Trim());
                SuperObject.Config.SetValue <string>(CONFIG_ID_APPKEY, tbAppKey.Text.Trim());
                SuperObject.Config.SetValue <string>(CONFIG_ID_Scene, tbScene.Text.Trim());
                SuperObject.SaveConfig();

                //设置AIUI属性
                string configStr = tbAppId.Text.Trim() + "|" + tbAppKey.Text.Trim() + "|" + tbScene.Text.Trim() + "|" + cbIsEnabledUseAIUIAfter.CheckState;
                MainService.AiuiOnlineService.AiuiConnection.SendAIUIConfigMessage(configStr.Trim());
            }
        }
 public static void ShowFriends(this SuperObject sup)
 {
     for (int i = 0; i < sup.friends.Count; i++)
     {
         Console.WriteLine(sup.friends[i].Username);
     }
 }
Example #8
0
 public Sector(Pointer offset, SuperObject so)
 {
     this.offset       = offset;
     this.superObject  = so;
     sectorLights      = new List <LightInfo>();
     neighbors         = new List <Sector>();
     neighborsPointers = new List <Pointer>();
 }
    private JSONObject GetDsgVarValueJSON(DsgVarComponent.DsgVarEditableEntry.Value value)
    {
        if (value == null)
        {
            return(null);
        }
        JSONObject dsgObj = new JSONObject();

        dsgObj["string"] = value.ToString();
        switch (value.type)
        {
        case DsgVarInfoEntry.DsgVarType.Perso:
            PersoBehaviour pb = value.AsPerso;
            if (pb != null)
            {
                Perso p = pb.perso;
                if (p != null)
                {
                    JSONObject persoJSON = new JSONObject();
                    persoJSON["offset"]       = p.offset.ToString();
                    persoJSON["nameFamily"]   = p.nameFamily;
                    persoJSON["nameModel"]    = p.nameModel;
                    persoJSON["nameInstance"] = p.namePerso;
                    dsgObj["perso"]           = persoJSON;
                }
            }
            break;

        case DsgVarInfoEntry.DsgVarType.SuperObject:
            SuperObjectComponent soc = value.AsSuperObject;
            if (soc != null)
            {
                SuperObject spo    = soc.so;
                JSONObject  soJSON = new JSONObject();
                soJSON["offset"] = spo.offset.ToString();
                soJSON["type"]   = spo.type.ToString();
                soJSON["offset"] = spo.offset.ToString();
                if (spo.type == SuperObject.Type.Perso && spo.data != null)
                {
                    Perso p = spo.data as Perso;
                    if (p != null)
                    {
                        JSONObject persoJSON = new JSONObject();
                        persoJSON["offset"]       = p.offset.ToString();
                        persoJSON["nameFamily"]   = p.nameFamily;
                        persoJSON["nameModel"]    = p.nameModel;
                        persoJSON["nameInstance"] = p.namePerso;
                        soJSON["perso"]           = persoJSON;
                    }
                }
                dsgObj["value"] = soJSON;
            }
            break;
        }
        return(dsgObj);
    }
Example #10
0
        public void InitPostLoad()
        {
            switch (nodeType)
            {
            case NodeType.GraphRef:
                Graph graphRef = Graph.FromOffset(param_ptr);
                if (graphRef != null)
                {
                    graphRef.References.referencedByNodes.Add(this);
                }
                else
                {
                    Debug.LogWarning("Couldn't add ScriptNode reference to Graph offset " + param_ptr);
                }
                break;

            case NodeType.PersoRef:
                Perso persoRef = Perso.FromOffset(param_ptr);
                if (persoRef != null)
                {
                    persoRef.References.referencedByNodes.Add(this);
                }
                else
                {
                    Debug.LogWarning("Couldn't add ScriptNode reference to Perso offset " + param_ptr);
                }
                break;

            case NodeType.SectorRef:
                Sector sectorRef = Sector.FromOffset(param_ptr);
                if (sectorRef != null)
                {
                    sectorRef.References.referencedByNodes.Add(this);
                }
                else
                {
                    Debug.LogWarning("Couldn't add ScriptNode reference to Sector offset " + param_ptr);
                }
                break;

            case NodeType.SuperObjectRef:
                SuperObject superObjectRef = SuperObject.FromOffset(param_ptr);
                if (superObjectRef != null)
                {
                    superObjectRef.References.referencedByNodes.Add(this);
                }
                else
                {
                    Debug.LogWarning("Couldn't add ScriptNode reference to SuperObject offset " + param_ptr);
                }
                break;

            default: return;
            }
        }
Example #11
0
 private void ChangeSelection(SuperObject worldObject, Player controller)
 {
     //this should be called by the following line, but there is an outside chance it will not
     SetSelection(false, playingArea);
     if (controller.SelectedObject)
     {
         controller.SelectedObject.SetSelection(false, playingArea);
     }
     controller.SelectedObject = worldObject;
     worldObject.SetSelection(true, controller.hud.GetPlayingArea());
 }
Example #12
0
 public virtual void MouseClick(GameObject hitObject, Vector3 hitPoint, Player controller)
 {
     //only handle input if currently selected
     if (currentlySelected && hitObject && hitObject.name != "Ground")
     {
         SuperObject worldObject = hitObject.transform.root.GetComponent <SuperObject>();
         //clicked on another selectable object
         if (worldObject)
         {
             ChangeSelection(worldObject, controller);
         }
     }
 }
Example #13
0
        public void Main()
        {
            SuperObject.AddErrorMethod(ConsoleOutput);
            SuperObject testUser = new SuperObject();

            testUser.SetUsername("pr9n");
            testUser.SetPassword("pass");

            users.Add(testUser);

            users[0].AddToFriend(new SuperObject());
            Login("pr9n", "pass");
            users[0].AddToFriend(new SuperObject());
        }
Example #14
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (SaveToConfig())
            {
                //保存配置
                SuperObject.SaveConfig();

                //重置本地服务
                ResetDataService();

                MessageBox.Show("保存完成");
                Close();
            }
        }
Example #15
0
        private SuperObject ParseObject(string data, ref int pos, int deep)
        {
            if (pos >= data.Length || data[pos] != '{')
            {
                return(null);
            }

            pos++;

            SkipSpaces(data, ref pos);

            if (pos >= data.Length)
            {
                return(null);
            }

            if (data[pos] == '}')
            {
                pos++;
                return(new SuperObject());
            }

            SuperObject result = new SuperObject();

            var props = ParseObjectPropsList(data, ref pos, deep + 1);

            if (props == null)
            {
                return(null);
            }

            result.Value = new Dictionary <string, SuperToken>();

            foreach (var pair in props)
            {
                result.TypedValue[pair.String] = pair.Token;
            }

            SkipSpaces(data, ref pos);

            if (pos >= data.Length || data[pos] != '}')
            {
                return(null);
            }

            pos++;

            return(result);
        }
Example #16
0
        private void ibFree_Click(object sender, EventArgs e)
        {
            SuperObject.Config.CurrentGoType = GoType.Free;
            SwitchButtonState(SuperObject.Config.CurrentGoType);
            SuperObject.SaveConfig();

            if (File.Exists(SuperObject.Config.GoAppPath))
            {
                try
                {
                    System.Diagnostics.Process.Start(SuperObject.Config.GoAppPath);
                }
                catch (Exception ex) { }
            }
        }
Example #17
0
    private void ParseSuperObjectJSON(JSONNode msg)
    {
        MapLoader   l  = MapLoader.Loader;
        SuperObject so = null;

        if (msg["type"] != null && msg["type"] == "Always")
        {
            // Fake superobject
            Perso alwaysPerso = l.globals.spawnablePersos.FirstOrDefault(s => s.offset.ToString() == msg["offset"]);
            if (alwaysPerso != null)
            {
                if (msg["position"] != null)
                {
                    alwaysPerso.Gao.transform.localPosition = msg["position"].ReadVector3();
                }
                if (msg["rotation"] != null)
                {
                    alwaysPerso.Gao.transform.localEulerAngles = msg["rotation"].ReadVector3();
                }
                if (msg["scale"] != null)
                {
                    alwaysPerso.Gao.transform.localScale = msg["scale"].ReadVector3();
                }
            }
        }
        else
        {
            if (msg["offset"] != null)
            {
                so = l.superObjects.FirstOrDefault(s => s.offset.ToString() == msg["offset"]);
            }
            if (so != null)
            {
                if (msg["position"] != null)
                {
                    so.Gao.transform.localPosition = msg["position"].ReadVector3();
                }
                if (msg["rotation"] != null)
                {
                    so.Gao.transform.localEulerAngles = msg["rotation"].ReadVector3();
                }
                if (msg["scale"] != null)
                {
                    so.Gao.transform.localScale = msg["scale"].ReadVector3();
                }
            }
        }
    }
Example #18
0
        public override SuperToken Serialize(object obj, Type declaredType, SuperJsonSerializer serializer)
        {
            var typedValue = (Task)obj;

            var resultType = obj.GetType().GetGenericArguments()[0];
            var id         = Guid.NewGuid();

            typedValue.ContinueWith(t =>
            {
                var taskResult = new TaskResult {
                    TaskID = id
                };
                if (t.IsCanceled)
                {
                    taskResult.Status = TaskCompletionStatus.Canceled;
                    taskResult.Result = false;
                }
                else if (t.IsFaulted)
                {
                    taskResult.Status = TaskCompletionStatus.Exception;
                    taskResult.Result = t.Exception;
                }
                else
                {
                    var resultProp    = t.GetType().GetProperty(nameof(Task <object> .Result));
                    taskResult.Status = TaskCompletionStatus.Result;
                    taskResult.Result = resultProp.GetValue(t);
                }

                mSuper.SendData(taskResult);
            });

            var result = new SuperObject
            {
                TypedValue =
                {
                    { "$type",      new SuperString("TaskWrapper")                    },
                    { "ID",         new SuperString(id.ToString())                    },
                    { "ResultType", new SuperString(resultType.AssemblyQualifiedName) }
                }
            };

            return(result);
        }
Example #19
0
        private void FillSuperObject(SuperObject superObject, XElement xObject)
        {
            // Determine which type of object we are
            var xPolygon  = xObject.Element("polygon");
            var xPolyline = xObject.Element("polyline");
            var xEllipse  = xObject.Element("ellipse");
            var xPoint    = xObject.Element("point");
            var xText     = xObject.Element("text");

            bool collisions = Importer.SuperImportContext.LayerIgnoreMode != LayerIgnoreMode.Collision;

            if (superObject.m_TileId != 0)
            {
                ProcessTileObject(superObject, xObject);
            }
            else if (xPolygon != null && collisions)
            {
                ProcessPolygonElement(superObject.gameObject, xPolygon);
            }
            else if (xPolyline != null && collisions)
            {
                ProcessPolylineElement(superObject.gameObject, xPolyline);
            }
            else if (xEllipse != null && collisions)
            {
                ProcessEllipseElement(superObject.gameObject, xObject);
            }
            else if (xText != null)
            {
                // Text objects are not yet supported
            }
            else if (xPoint != null)
            {
                // A point is simply an empty game object out in space.
                // We don't need to add anything else
            }
            else if (collisions)
            {
                // Default object is a rectangle
                ProcessObjectRectangle(superObject.gameObject, xObject);
            }
        }
        public override SuperToken Serialize(object obj, Type declaredType, SuperJsonSerializer serializer)
        {
            var result = new SuperObject();

            var id = Guid.NewGuid();

            var typed = (Delegate)obj;

            var delegateParameters = typed.Method.GetParameters().Select(p => p.ParameterType).ToArray();


            Type wrapperType = null;

            if (typed.Method.ReturnType == typeof(void))
            {
                wrapperType = Utils.GetActionWrapper <DelegateActionWrapperBase>(delegateParameters);
            }
            else
            {
                wrapperType = Utils.GetFuncWrapper <DelegateFuncWrapperBase>(typed.Method.ReturnType, delegateParameters);
            }

            mSuper.Register(Activator.CreateInstance(wrapperType, typed), id);

            result.TypedValue.Add("$type", new SuperString("DelegateWrapper"));
            result.TypedValue.Add("ID", new SuperString(id.ToString()));
            result.TypedValue.Add("DelegateType", new SuperString(typed.GetType().AssemblyQualifiedName));

            var listArgs = new List <SuperToken>();

            foreach (var param in typed.Method.GetParameters())
            {
                listArgs.Add(new SuperString(param.ParameterType.AssemblyQualifiedName));
            }

            var args = new SuperArray(listArgs.ToArray());

            result.TypedValue.Add("ArgumentTypes", args);
            result.TypedValue.Add("ReturnType", new SuperString(typed.Method.ReturnType.AssemblyQualifiedName));

            return(result);
        }
Example #21
0
        public static GeometricShadowObject Read(Reader reader, Pointer offset, SuperObject so)
        {
            MapLoader             l   = MapLoader.Loader;
            GeometricShadowObject igo = new GeometricShadowObject(offset, so);

            igo.off_data = Pointer.Read(reader);
            igo.unk4     = reader.ReadUInt32();
            igo.unk8     = reader.ReadUInt32();

            Pointer.DoAt(ref reader, igo.off_data, () => {
                igo.data = GeometricObject.Read(reader, igo.off_data);
                if (igo.data != null)
                {
                    igo.data.Gao.transform.parent = igo.Gao.transform;
                    igo.Gao.name = "[Shadow] " + igo.data.Gao.name;
                    igo.Gao.SetActive(false); // Shadows don't draw well right now
                }
            });
            return(igo);
        }
        private MovingPlatformOnTrack InstantiateMovingPlatform(string name, SuperObject marker)
        {
            var go = Resources.Load("MovingPlatform");

            if (go == null)
            {
                m_ImportedArgs.AssetImporter.ReportError("MovingPlatform resource not found.");
                return(null);
            }

            var goPlatform   = UnityEngine.Object.Instantiate(go, marker.transform) as GameObject;
            var compPlatform = goPlatform.GetComponent <MovingPlatformOnTrack>();

            // Custom properties can control platform speed and inital direction
            compPlatform.m_Speed = marker.gameObject.GetSuperPropertyValueFloat("Speed", 64.0f);
            compPlatform.m_InitialDirection.x = marker.gameObject.GetSuperPropertyValueFloat("Direction_x", 1.0f);
            compPlatform.m_InitialDirection.y = marker.gameObject.GetSuperPropertyValueFloat("Direction_y", 1.0f);

            return(compPlatform);
        }
Example #23
0
        public ActionEditor(bool isNew)
        {
            InitializeComponent();

            //初始化设计控件
            SuperObject.InitActionControl(adcActionControl);

            IsNewRecord = isNew;

            if (IsNewRecord)
            {
                Text = "创建动作";
            }
            else
            {
                Text = "修改动作";
            }

            OnLoad(new EventArgs());
        }
Example #24
0
        public override SuperToken Serialize(object obj, Type declaredType, SuperJsonSerializer serializer)
        {
            var result = new SuperObject {
                TypedValue = { { "$type", new SuperString("InterfaceWrapper") } }
            };

            var regType = declaredType;
            var regInst = obj;

            var registrationID = Guid.NewGuid();

            var registerMethod = typeof(Super).GetMethod(nameof(Super.Register),
                                                         BindingFlags.Instance | BindingFlags.Public);

            registerMethod = registerMethod.MakeGenericMethod(regType);
            registerMethod.Invoke(mSuper, new[] { regInst, registrationID });

            result.TypedValue.Add("ID", new SuperString(registrationID.ToString()));
            result.TypedValue.Add("InterfaceType", new SuperString(regType.AssemblyQualifiedName));

            return(result);
        }
Example #25
0
    public void Init()
    {
        if (MapLoader.Loader is OpenSpace.Loader.R3Loader)
        {
            MapLoader l = MapLoader.Loader;
            foreach (SuperObject so in l.superObjects)
            {
                if (so.type == SuperObject.Type.IPO_2)
                {
                    //Debug.LogWarning("TYPE 2 " + so.Gao.name);
                    Portal portal = new Portal()
                    {
                        containerSO  = so,
                        containerIPO = so.data as IPO
                    };
                    portal.cameraSO = SuperObject.FromOffset(portal.containerIPO.off_portalCamera);
                    GeometricObject geo = portal.containerIPO.data.visualSet[0].obj as GeometricObject;
                    portal.geometricObject = geo;
                    if (geo != null)
                    {
                        GeometricObjectElementTriangles el = geo.elements[0] as GeometricObjectElementTriangles;
                        portal.meshElement = el;
                        portal.material    = el.Gao.GetComponent <Renderer>().sharedMaterial;
                        //Debug.LogWarning(so.type + " - " + portal.containerIPO.offset + " - " + portal.containerIPO.off_portalCamera);
                        if (portal.cameraSO != null)
                        {
                            GameObject camGao = new GameObject("Portal Camera - " + portal.containerIPO.Gao.name + " - " + portal.cameraSO.Gao.name);
                            Camera     camera = camGao.AddComponent <Camera>();
                            camGao.transform.position   = portal.cameraSO.matrix.GetPosition(true);
                            camGao.transform.rotation   = portal.cameraSO.matrix.GetRotation(true) * Quaternion.Euler(-180, 0, 0);
                            camGao.transform.localScale = portal.cameraSO.matrix.GetScale(true);
                            camera.fieldOfView          = Camera.main.fieldOfView;
                            camera.enabled = false;
                            camGao.transform.SetParent(transform);
                            portal.camera = camera;
                            portals.Add(portal);
                        }
                        else
                        {
                            // it's a mirror
                            portal.isMirror = true;
                            GameObject camGao = new GameObject("Mirror Camera - " + portal.containerIPO.Gao.name);
                            Camera     camera = camGao.AddComponent <Camera>();
                            camGao.transform.position = geo.vertices[0];

                            /*camGao.transform.rotation = portal.cameraSO.matrix.GetRotation(true) * Quaternion.Euler(-180, 0, 0);
                             * camGao.transform.localScale = portal.cameraSO.matrix.GetScale(true);*/
                            camera.fieldOfView = Camera.main.fieldOfView;
                            camera.enabled     = false;
                            camGao.transform.SetParent(transform);
                            portal.camera = camera;
                            portals.Add(portal);
                        }

                        el.Gao.layer = LayerMask.NameToLayer("VisualMirror");
                        PortalBehaviour pb = el.Gao.AddComponent <PortalBehaviour>();
                        pb.m_ReflectLayers = (1 << LayerMask.NameToLayer("Visual")) | (1 << LayerMask.NameToLayer("VisualOnlyInMirror"));
                        pb.portal          = portal;
                        pb.textureIndex    = portal.material.GetInt("_NumTextures");
                        portal.material.SetInt("_NumTextures", pb.textureIndex + 1);
                    }
                }
            }
        }
        loaded = true;
    }
Example #26
0
        private void ProcessTileObject(SuperObject superObject, XElement xObject)
        {
            Assert.IsNull(superObject.m_SuperTile);
            Assert.IsNotNull(GlobalTileDatabase, "Cannot process tile objects without a tileset database");

            SuperTile tile       = null;
            var       tileId     = new TileIdMath(superObject.m_TileId);
            int       justTileId = tileId.JustTileId;

            // Are we getting the tile from a template?
            var template = xObject.GetAttributeAs("template", "");

            if (!string.IsNullOrEmpty(template))
            {
                var asset = Importer.RequestAssetAtPath <ObjectTemplate>(template);
                if (asset == null)
                {
                    Importer.ReportError("Template file '{0}' was not found.", template);
                    return;
                }

                tile = asset.m_Tile;
                if (tile == null)
                {
                    Importer.ReportError("Missing tile '{0}' from template '{1}' on tile object '{2}'", justTileId, template, superObject.name);
                    return;
                }
            }

            // Are we getting the tile from our tile database?
            if (tile == null)
            {
                GlobalTileDatabase.TryGetTile(justTileId, out tile);

                if (tile == null)
                {
                    Importer.ReportError("Missing tile '{0}' on tile object '{1}'", justTileId, template, superObject.name);
                    return;
                }
            }

            // Our type may come from the tile as well (this is 'Typed Tiles' in Tiled)
            if (string.IsNullOrEmpty(superObject.m_Type))
            {
                superObject.m_Type = tile.m_Type;
            }

            // Construct the game objects for displaying a single tile
            var  inversePPU = Importer.SuperImportContext.Settings.InversePPU;
            bool flip_h     = tileId.HasHorizontalFlip;
            bool flip_v     = tileId.HasVerticalFlip;

            var scale = Vector3.one;

            scale.x = xObject.GetAttributeAs("width", 1.0f);
            scale.y = xObject.GetAttributeAs("height", 1.0f);

            scale.x /= tile.m_Width;
            scale.y /= tile.m_Height;

            var tileOffset      = new Vector3(tile.m_TileOffsetX * inversePPU, -tile.m_TileOffsetY * inversePPU);
            var translateCenter = new Vector3(tile.m_Width * 0.5f * inversePPU, tile.m_Height * 0.5f * inversePPU);

            // Our root object will contain the translation, rotation, and scale of the tile object
            var goTRS = superObject.gameObject;

            goTRS.transform.localScale = scale;

            // Add another object to handle tile flipping
            // This object will center us into the tile and perform the flips through scaling
            // This object also contains the tile offset in her transform
            var goCF = new GameObject();

            goCF.name = string.Format("{0} (CF)", superObject.m_TiledName);
            goTRS.AddChildWithUniqueName(goCF);

            goCF.transform.localPosition = translateCenter + tileOffset;
            goCF.transform.localRotation = Quaternion.Euler(0, 0, 0);
            goCF.transform.localScale    = new Vector3(flip_h ? -1 : 1, flip_v ? -1 : 1, 1);

            // Note: We may not want to put the tile "back into place" depending on our coordinate system
            var fromCenter = -translateCenter;

            // Isometric maps referece tile objects by bottom center
            if (SuperMap.m_Orientation == MapOrientation.Isometric)
            {
                fromCenter.x -= Importer.SuperImportContext.MakeScalar(tile.m_Width * 0.5f);
            }

            // Add another child, putting our coordinates back into the proper place
            var goTile = new GameObject(superObject.m_TiledName);

            goCF.AddChildWithUniqueName(goTile);
            goTile.transform.localPosition = fromCenter;
            goTile.transform.localRotation = Quaternion.Euler(0, 0, 0);
            goTile.transform.localScale    = Vector3.one;

            if (Importer.SuperImportContext.LayerIgnoreMode != LayerIgnoreMode.Visual)
            {
                // Add the renderer
                var renderer = goTile.AddComponent <SpriteRenderer>();
                renderer.sprite = tile.m_Sprite;
                renderer.color  = new Color(1, 1, 1, superObject.CalculateOpacity());
                Importer.AssignMaterial(renderer, m_ObjectLayer.m_TiledName);
                Importer.AssignSpriteSorting(renderer);

                // Add the animator if needed
                if (!tile.m_AnimationSprites.IsEmpty())
                {
                    var tileAnimator = goTile.AddComponent <TileObjectAnimator>();
                    tileAnimator.m_AnimationFramerate = AnimationFramerate;
                    tileAnimator.m_AnimationSprites   = tile.m_AnimationSprites;
                }
            }

            if (Importer.SuperImportContext.LayerIgnoreMode != LayerIgnoreMode.Collision)
            {
                // Add any colliders that were set up on the tile in the collision editor
                tile.AddCollidersForTileObject(goTile, Importer.SuperImportContext);
            }

            // Store a reference to our tile object
            superObject.m_SuperTile = tile;
        }
Example #27
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");
        }
Example #28
0
 public IPO(Pointer offset, SuperObject so)
 {
     this.offset      = offset;
     this.superObject = so;
 }
Example #29
0
        async UniTask LoadLVLSNA()
        {
            loadingState = "Loading level memory";
            await WaitIfNecessary();

            Reader  reader = files_array[Mem.Lvl].reader;
            Pointer off_current;
            SNA     sna = (SNA)files_array[Mem.Lvl];

            // First read GPT
            files_array[Mem.Lvl].GotoHeader();
            reader = files_array[Mem.Lvl].reader;
            print("LVL GPT offset: " + Pointer.Current(reader));

            if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
            {
                // SDA

                /*sna.GotoSDA();
                 * print(Pointer.Current(reader));
                 * reader.ReadUInt32();
                 * reader.ReadUInt32(); // same as next
                 * uint num_strings = reader.ReadUInt32();
                 * uint indexOfTextGlobal = reader.ReadUInt32(); // dword_6EEE78
                 * uint dword_83EC58 = reader.ReadUInt32();
                 * print(num_strings + " - " + Pointer.Current(reader));
                 *
                 * // DLG
                 * sna.GotoDLG();
                 * Pointer off_strings = Pointer.Read(reader);
                 * for (int i = 0; i < num_strings; i++) {
                 *  Pointer.Read(reader);
                 * }
                 * reader.ReadUInt32();*/

                // GPT
                sna.GotoHeader();
                if (Settings.s.game != Settings.Game.PlaymobilLaura)
                {
                    Pointer.Read(reader); // sound related
                }
                Pointer.Read(reader);
                Pointer.Read(reader);
                reader.ReadUInt32();
            }
            if (Settings.s.engineVersion != Settings.EngineVersion.Montreal)
            {
                loadingState = "Reading settings for persos in fix";
                await WaitIfNecessary();

                // Fill in fix -> lvl pointers for perso's in fix
                uint      num_persoInFixPointers = reader.ReadUInt32();
                Pointer[] persoInFixPointers     = new Pointer[num_persoInFixPointers];
                for (int i = 0; i < num_persoInFixPointers; i++)
                {
                    Pointer off_perso = Pointer.Read(reader);
                    if (off_perso != null)
                    {
                        off_current = Pointer.Goto(ref reader, off_perso);
                        reader.ReadUInt32();
                        Pointer off_stdGame = Pointer.Read(reader);
                        if (off_stdGame != null)
                        {
                            if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                            {
                                Pointer.Goto(ref reader, off_stdGame);
                                reader.ReadUInt32(); // type 0
                                reader.ReadUInt32(); // type 1
                                reader.ReadUInt32(); // type 2
                                Pointer off_superObject = Pointer.Read(reader);
                                Pointer.Goto(ref reader, off_current);
                                if (off_superObject == null)
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                Pointer.Goto(ref reader, off_current);
                            }
                            // First read everything from the GPT
                            Pointer off_newSuperObject = null, off_nextBrother = null, off_prevBrother = null, off_father = null;
                            byte[]  matrixData = null, floatData = null, renderBits = null;
                            if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                            {
                                off_newSuperObject = Pointer.Read(reader);
                                matrixData         = reader.ReadBytes(0x58);
                                renderBits         = reader.ReadBytes(4);
                                floatData          = reader.ReadBytes(4);
                                off_nextBrother    = Pointer.Read(reader);
                                off_prevBrother    = Pointer.Read(reader);
                                off_father         = Pointer.Read(reader);
                            }
                            else
                            {
                                matrixData         = reader.ReadBytes(0x58);
                                off_newSuperObject = Pointer.Read(reader);
                                Pointer.DoAt(ref reader, off_stdGame + 0xC, () => {
                                    ((SNA)off_stdGame.file).AddPointer(off_stdGame.offset + 0xC, off_newSuperObject);
                                });
                            }

                            // Then fill everything in
                            off_current = Pointer.Goto(ref reader, off_newSuperObject);
                            uint    newSOtype             = reader.ReadUInt32();
                            Pointer off_newSOengineObject = Pointer.Read(reader);
                            if (SuperObject.GetSOType(newSOtype) == SuperObject.Type.Perso)
                            {
                                persoInFixPointers[i] = off_newSOengineObject;
                                Pointer.Goto(ref reader, off_newSOengineObject);
                                Pointer off_p3dData = Pointer.Read(reader);
                                if (Settings.s.game == Settings.Game.R2Demo)
                                {
                                    ((SNA)off_p3dData.file).OverwriteData(off_p3dData.FileOffset + 0x1C, matrixData);
                                }
                                else
                                {
                                    ((SNA)off_p3dData.file).OverwriteData(off_p3dData.FileOffset + 0x18, matrixData);
                                }

                                if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                                {
                                    FileWithPointers file = off_newSuperObject.file;
                                    file.AddPointer(off_newSuperObject.FileOffset + 0x14, off_nextBrother);
                                    file.AddPointer(off_newSuperObject.FileOffset + 0x18, off_prevBrother);
                                    file.AddPointer(off_newSuperObject.FileOffset + 0x1C, off_father);
                                    ((SNA)file).OverwriteData(off_newSuperObject.FileOffset + 0x30, renderBits);
                                    ((SNA)file).OverwriteData(off_newSuperObject.FileOffset + 0x38, floatData);
                                }
                            }
                            else
                            {
                                persoInFixPointers[i] = null;
                            }
                        }
                        Pointer.Goto(ref reader, off_current);
                    }
                }
            }
            loadingState = "Loading globals";
            await WaitIfNecessary();

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                globals.off_actualWorld          = Pointer.Read(reader);
                globals.off_dynamicWorld         = Pointer.Read(reader);
                globals.off_inactiveDynamicWorld = Pointer.Read(reader);
                globals.off_fatherSector         = Pointer.Read(reader);
                globals.off_firstSubMapPosition  = Pointer.Read(reader);
            }
            else
            {
                globals.off_actualWorld  = Pointer.Read(reader);
                globals.off_dynamicWorld = Pointer.Read(reader);
                globals.off_fatherSector = Pointer.Read(reader);
                uint soundEventIndex = reader.ReadUInt32(); // In Montreal version this is a pointer, also sound event related
                if (Settings.s.game == Settings.Game.PlaymobilLaura)
                {
                    Pointer.Read(reader);
                }
            }

            globals.num_always      = reader.ReadUInt32();
            globals.spawnablePersos = LinkedList <Perso> .ReadHeader(reader, Pointer.Current(reader), LinkedList.Type.Double);

            globals.off_always_reusableSO = Pointer.Read(reader); // There are (num_always) empty SuperObjects starting with this one.
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                globals.off_always_reusableUnknown1 = Pointer.Read(reader); // (num_always) * 0x2c blocks
                globals.off_always_reusableUnknown2 = Pointer.Read(reader); // (num_always) * 0x4 blocks
            }
            else
            {
                reader.ReadUInt32(); // 0x6F. In Montreal version this is a pointer to a pointer table for always
                globals.spawnablePersos.FillPointers(reader, globals.spawnablePersos.off_tail, globals.spawnablePersos.offset);
            }

            if (Settings.s.game == Settings.Game.DD)
            {
                reader.ReadUInt32();
            }
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                Pointer dword_4A6B1C_always_header = Pointer.Read(reader);
                Pointer dword_4A6B20_always_last   = Pointer.Read(reader);

                Pointer v28 = Pointer.Read(reader);
                Pointer v31 = Pointer.Read(reader);
                Pointer v32 = Pointer.Read(reader);
                Pointer v33 = Pointer.Read(reader);

                // These things aren't parsed, but in raycap they're null. This way we'll notice when they aren't.
                if (v28 != null)
                {
                    print("v28 is not null, it's " + v28);
                }
                if (v31 != null)
                {
                    print("v31 is not null, it's " + v31);
                }
                if (v32 != null)
                {
                    print("v32 is not null, it's " + v32);
                }
                if (v33 != null)
                {
                    print("v33 is not null, it's " + v33);
                }

                // Fill in pointers for the unknown table related to "always".
                FillLinkedListPointers(reader, dword_4A6B20_always_last, dword_4A6B1C_always_header);
            }

            // Fill in pointers for the object type tables and read them
            objectTypes = new ObjectType[3][];
            for (uint i = 0; i < 3; i++)
            {
                Pointer off_names_header = Pointer.Current(reader);
                Pointer off_names_first  = Pointer.Read(reader);
                Pointer off_names_last   = Pointer.Read(reader);
                uint    num_names        = reader.ReadUInt32();

                FillLinkedListPointers(reader, off_names_last, off_names_header);
                ReadObjectNamesTable(reader, off_names_first, num_names, i);
            }

            // Begin of engineStructure
            loadingState = "Loading engine structure";
            await WaitIfNecessary();

            print("Start of EngineStructure: " + Pointer.Current(reader));
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                reader.ReadByte();
                string mapName = reader.ReadString(0x1E);
                reader.ReadChars(0x1E);
                string mapName2 = reader.ReadString(0x1E);
                reader.ReadByte();
                reader.ReadBytes(0x178); // don't know what this data is
            }
            else
            {
                reader.ReadByte();
                string mapName = reader.ReadString(0x104);
                reader.ReadChars(0x104);
                string mapName2 = reader.ReadString(0x104);
                if (Settings.s.game == Settings.Game.PlaymobilLaura)
                {
                    reader.ReadChars(0x104);
                    reader.ReadChars(0x104);
                }
                string mapName3 = reader.ReadString(0x104);
                if (Settings.s.game == Settings.Game.TT)
                {
                    reader.ReadBytes(0x47F7); // don't know what this data is
                }
                else if (Settings.s.game == Settings.Game.TTSE)
                {
                    reader.ReadBytes(0x240F);
                }
                else if (Settings.s.game == Settings.Game.PlaymobilLaura)
                {
                    reader.ReadBytes(0x240F); // don't know what this data is
                }
                else                          // Hype & Alex
                {
                    reader.ReadBytes(0x2627); // don't know what this data is
                }
            }
            Pointer off_unknown_first = Pointer.Read(reader);
            Pointer off_unknown_last  = Pointer.Read(reader);
            uint    num_unknown       = reader.ReadUInt32();

            families = LinkedList <Family> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);

            families.FillPointers(reader, families.off_tail, families.off_head);

            if (Settings.s.game == Settings.Game.PlaymobilLaura)
            {
                LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);
            }

            LinkedList <SuperObject> alwaysActiveCharacters = LinkedList <SuperObject> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double);

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                reader.ReadUInt32();
                reader.ReadUInt32();
                reader.ReadUInt32();
                if (Settings.s.game == Settings.Game.RedPlanet || Settings.s.game == Settings.Game.R2Demo)
                {
                    reader.ReadUInt32();
                }
                Pointer off_languages = Pointer.Read(reader);
                reader.ReadUInt32();

                Pointer.DoAt(ref reader, off_languages, () => {
                    ReadLanguages(reader, off_languages, localization.num_languages);
                });

                for (uint i = 0; i < 2; i++)
                {
                    Pointer off_matrix = Pointer.Current(reader);
                    Matrix  mat        = Matrix.Read(reader, off_matrix);
                }

                reader.ReadUInt32();
                reader.ReadUInt16();

                ReadLevelNames(reader, Pointer.Current(reader), 80);
                uint num_mapNames = reader.ReadUInt32();
                Array.Resize(ref levels, (int)num_mapNames);
                reader.ReadUInt16();
                reader.ReadUInt32();
                reader.ReadUInt32();

                if (Settings.s.game == Settings.Game.DD)
                {
                    reader.ReadUInt32();
                }

                // End of engineStructure
                Pointer off_light    = Pointer.Read(reader); // the offset of a light. It's just an ordinary light.
                Pointer off_mainChar = Pointer.Read(reader); // superobject
                Pointer off_characterLaunchingSoundEvents = Pointer.Read(reader);
                if (Settings.s.game == Settings.Game.DD)
                {
                    globals.off_backgroundGameMaterial = Pointer.Read(reader);
                }
                Pointer off_shadowPolygonVisualMaterial   = Pointer.Read(reader);
                Pointer off_shadowPolygonGameMaterialInit = Pointer.Read(reader);
                Pointer off_shadowPolygonGameMaterial     = Pointer.Read(reader);
                Pointer off_textureOfTextureShadow        = Pointer.Read(reader);
                Pointer off_col_taggedFacesTable          = Pointer.Read(reader);

                for (int i = 0; i < 10; i++)
                {
                    Pointer off_elementForShadow      = Pointer.Read(reader);
                    Pointer off_geometricShadowObject = Pointer.Read(reader);
                }
                Pointer.Read(reader); // DemoSOList

                if (Settings.s.game == Settings.Game.R2Demo || Settings.s.game == Settings.Game.RedPlanet || Settings.s.mode == Settings.Mode.DonaldDuckPCDemo)
                {
                    Pointer.Read(reader);
                }

                if (Settings.s.mode == Settings.Mode.DonaldDuckPCDemo)
                {
                    reader.ReadUInt32();
                    reader.ReadUInt32();
                }

                loadingState = "Loading level animation bank";
                //print("Animation bank: " + Pointer.Current(reader));
                await WaitIfNecessary();

                AnimationBank.Read(reader, Pointer.Current(reader), 0, 1, files_array[Mem.LvlKeyFrames], append: true);
                animationBanks[1] = animationBanks[0];
            }
            if (FileSystem.mode != FileSystem.Mode.Web)
            {
                string levelsFolder = gameDataBinFolder + ConvertPath(gameDsb.levelsDataPath) + "/";
                ((SNA)files_array[0]).CreateMemoryDump(levelsFolder + "fix.dmp", true);
                ((SNA)files_array[1]).CreateMemoryDump(levelsFolder + lvlName + "/" + lvlName + ".dmp", true);
            }

            // Read PTX
            loadingState = "Loading level textures";
            await WaitIfNecessary();

            // Can't yield inside a lambda, so we must do it the old fashioned way, with off_current
            if (sna.PTX != null)
            {
                off_current = Pointer.Goto(ref reader, sna.PTX);
                await ReadTexturesLvl(reader, Pointer.Current(reader));

                Pointer.Goto(ref reader, off_current);
            }

            /*Pointer.DoAt(ref reader, sna.PTX, () => {
             * ReadTexturesLvl(reader, Pointer.Current(reader));
             * });*/

            // Read background game material (DD only)
            globals.backgroundGameMaterial = GameMaterial.FromOffsetOrRead(globals.off_backgroundGameMaterial, reader);

            // Parse actual world & always structure
            loadingState = "Loading families";
            await WaitIfNecessary();

            ReadFamilies(reader);

            loadingState = "Creating animation bank";
            await WaitIfNecessary();

            if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
            {
                animationBanks    = new AnimationBank[2];
                animationBanks[0] = new AnimationBank(null)
                {
                    animations = new Animation.Component.AnimA3DGeneral[0]
                };
                animationBanks[1] = animationBanks[0];
            }
            else if (Settings.s.engineVersion <= Settings.EngineVersion.TT)
            {
                uint maxAnimIndex = 0;
                foreach (State s in states)
                {
                    if (s.anim_ref != null && s.anim_ref.anim_index > maxAnimIndex)
                    {
                        maxAnimIndex = s.anim_ref.anim_index;
                    }
                }
                animationBanks    = new AnimationBank[2];
                animationBanks[0] = new AnimationBank(null)
                {
                    animations = new Animation.Component.AnimA3DGeneral[maxAnimIndex + 1]
                };
                foreach (State s in states)
                {
                    if (s.anim_ref != null)
                    {
                        animationBanks[0].animations[s.anim_ref.anim_index] = s.anim_ref.a3d;
                    }
                }
                animationBanks[1] = animationBanks[0];
            }

            loadingState = "Loading superobject hierarchy";
            await WaitIfNecessary();
            await ReadSuperObjects(reader);

            loadingState = "Loading always structure";
            await WaitIfNecessary();

            ReadAlways(reader);
            loadingState = "Filling in cross-references";
            await WaitIfNecessary();

            ReadCrossReferences(reader);

            // TODO: Make more generic
            if (Settings.s.game == Settings.Game.R2)
            {
                loadingState = "Filling in comport names";
                await WaitIfNecessary();

                string path = gameDataBinFolder + "R2DC_Comports.json";

                if (!FileSystem.FileExists(path))
                {
                    path = "Assets/StreamingAssets/R2DC_Comports.json"; // Offline, the json doesn't exist, so grab it from StreamingAssets
                }

                Stream stream = FileSystem.GetFileReadStream(path);
                if (stream != null)
                {
                    ReadAndFillComportNames(stream);
                }
            }
        }
Example #30
0
    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);
        }
    }