public override void ProcessPacket(DysonSphereColorChangePacket packet, NebulaConnection conn)
        {
            DysonSphere sphere = GameMain.data.dysonSpheres[packet.StarIndex];

            if (sphere == null)
            {
                return;
            }
            using (Multiplayer.Session.DysonSpheres.IsIncomingRequest.On())
            {
                DysonSphereLayer layer = sphere.GetLayer(packet.LayerId);
                if (layer == null)
                {
                    Multiplayer.Session.DysonSpheres.HandleDesync(packet.StarIndex, conn);
                    return;
                }
                Color32 color = packet.Color.ToColor32();
                switch (packet.Type)
                {
                case DysonSphereColorChangePacket.ComponentType.Node:
                    DysonNode node = packet.Index < layer.nodeCursor ? layer.nodePool[packet.Index] : null;
                    if (node != null)
                    {
                        node.color = color;
                        sphere.UpdateColor(node);
                    }
                    break;

                case DysonSphereColorChangePacket.ComponentType.Frame:
                    DysonFrame frame = packet.Index < layer.frameCursor ? layer.framePool[packet.Index] : null;
                    if (frame != null)
                    {
                        frame.color = color;
                        sphere.UpdateColor(frame);
                    }
                    break;

                case DysonSphereColorChangePacket.ComponentType.Shell:
                    DysonShell shell = packet.Index < layer.shellCursor ? layer.shellPool[packet.Index] : null;
                    if (shell != null)
                    {
                        shell.color = color;
                    }
                    break;
                }
            }
            if (IsHost)
            {
                Multiplayer.Session.DysonSpheres.SendPacketToDysonSphereExcept(packet, packet.StarIndex, conn);
            }
        }
        public static void SendShellPacket(DysonShell shell)
        {
            int starIndex = UIRoot.instance.uiGame.dysonEditor.selection.viewStar.index;

            Multiplayer.Session.Network.SendPacket(new DysonSphereColorChangePacket(starIndex, shell.layerId, shell.color, DysonSphereColorChangePacket.ComponentType.Shell, shell.id));
        }
        public static void ImportBP(this DysonShell _this, BinaryReader r, DysonSphere dysonSphere)
        {
            _this.SetEmpty();
            r.ReadInt32();
            _this.id       = r.ReadInt32();
            _this.protoId  = r.ReadInt32();
            _this.layerId  = r.ReadInt32();
            _this.randSeed = r.ReadInt32();
            int num = r.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                Vector3 item = default(Vector3);
                item.x = r.ReadSingle();
                item.y = r.ReadSingle();
                item.z = r.ReadSingle();
                _this.polygon.Add(item);
            }
            int num2 = r.ReadInt32();

            for (int j = 0; j < num2; j++)
            {
                int       num3      = r.ReadInt32();
                DysonNode dysonNode = dysonSphere.FindNode(_this.layerId, num3);
                Assert.NotNull(dysonNode);
                if (dysonNode != null)
                {
                    _this.nodeIndexMap[num3] = _this.nodes.Count;
                    _this.nodes.Add(dysonNode);
                    if (!dysonNode.shells.Contains(_this))
                    {
                        dysonNode.shells.Add(_this);
                    }
                }
            }
            Assert.True(_this.nodeIndexMap.Count == _this.nodes.Count);
            int count = _this.nodes.Count;

            for (int k = 0; k < count; k++)
            {
                int        index      = k;
                int        index2     = (k + 1) % count;
                DysonFrame dysonFrame = DysonNode.FrameBetween(_this.nodes[index], _this.nodes[index2]);
                Assert.NotNull(dysonFrame);
                _this.frames.Add(dysonFrame);
            }
            _this.vertexCount   = r.ReadInt32();
            _this.triangleCount = r.ReadInt32();
            int num4 = r.ReadInt32();

            _this.verts = new Vector3[num4];
            for (int l = 0; l < num4; l++)
            {
                _this.verts[l].x = r.ReadSingle();
                _this.verts[l].y = r.ReadSingle();
                _this.verts[l].z = r.ReadSingle();
            }
            num4        = r.ReadInt32();
            _this.pqArr = new IntVector2[num4];
            for (int m = 0; m < num4; m++)
            {
                _this.pqArr[m].x = r.ReadInt32();
                _this.pqArr[m].y = r.ReadInt32();
            }
            num4       = r.ReadInt32();
            _this.tris = new int[num4];
            for (int n = 0; n < num4; n++)
            {
                _this.tris[n] = r.ReadInt32();
            }
            num4        = r.ReadInt32();
            _this.vAdjs = new int[num4];
            for (int num5 = 0; num5 < num4; num5++)
            {
                _this.vAdjs[num5] = r.ReadInt32();
            }
            num4           = r.ReadInt32();
            _this.vertAttr = new int[num4];
            for (int num6 = 0; num6 < num4; num6++)
            {
                _this.vertAttr[num6] = r.ReadInt32();
            }
            Assert.True(_this.vertAttr.Length == _this.verts.Length);
            num4         = r.ReadInt32();
            _this.vertsq = new int[num4];
            for (int num7 = 0; num7 < num4; num7++)
            {
                _this.vertsq[num7] = r.ReadInt32();
            }
            Assert.True(_this.vertsq.Length == _this.verts.Length);
            num4 = r.ReadInt32();
            _this.vertsqOffset = new int[num4];
            for (int num8 = 0; num8 < num4; num8++)
            {
                _this.vertsqOffset[num8] = r.ReadInt32();
            }
            Assert.True(_this.vertsqOffset.Length == _this.nodes.Count + 1);
            num4          = r.ReadInt32();
            _this.nodecps = new int[num4];
            Assert.True(_this.nodecps.Length == _this.nodes.Count + 1);
            num4                    = r.ReadInt32();
            _this.vertcps           = new uint[num4];
            num4                    = r.ReadInt32();
            _this.vertRecycleCursor = r.ReadInt32();
            _this.vertRecycle       = new int[num4];
            for (int num11 = 0; num11 < _this.vertRecycleCursor; num11++)
            {
                _this.vertRecycle[num11] = r.ReadInt32();
            }
            Assert.True(_this.vertRecycle.Length == _this.verts.Length);
            _this.GenerateGeometryOnImport();
        }
        public static void ExportBP(this DysonShell _this, BinaryWriter w)
        {
            w.Write(0);
            w.Write(_this.id);
            w.Write(_this.protoId);
            w.Write(_this.layerId);
            w.Write(_this.randSeed);
            w.Write(_this.polygon.Count);
            for (int i = 0; i < _this.polygon.Count; i++)
            {
                w.Write(_this.polygon[i].x);
                w.Write(_this.polygon[i].y);
                w.Write(_this.polygon[i].z);
            }
            w.Write(_this.nodes.Count);
            for (int j = 0; j < _this.nodes.Count; j++)
            {
                w.Write(_this.nodes[j].id);
            }
            w.Write(_this.vertexCount);
            w.Write(_this.triangleCount);
            int num = _this.verts.Length;

            w.Write(num);
            for (int k = 0; k < num; k++)
            {
                w.Write(_this.verts[k].x);
                w.Write(_this.verts[k].y);
                w.Write(_this.verts[k].z);
            }
            num = _this.pqArr.Length;
            w.Write(num);
            for (int l = 0; l < num; l++)
            {
                w.Write(_this.pqArr[l].x);
                w.Write(_this.pqArr[l].y);
            }
            num = _this.tris.Length;
            w.Write(num);
            for (int m = 0; m < num; m++)
            {
                w.Write(_this.tris[m]);
            }
            num = _this.vAdjs.Length;
            w.Write(num);
            for (int n = 0; n < num; n++)
            {
                w.Write(_this.vAdjs[n]);
            }
            num = _this.vertAttr.Length;
            w.Write(num);
            for (int num2 = 0; num2 < num; num2++)
            {
                w.Write(_this.vertAttr[num2]);
            }
            num = _this.vertsq.Length;
            w.Write(num);
            for (int num3 = 0; num3 < num; num3++)
            {
                w.Write(_this.vertsq[num3]);
            }
            num = _this.vertsqOffset.Length;
            w.Write(num);
            for (int num4 = 0; num4 < num; num4++)
            {
                w.Write(_this.vertsqOffset[num4]);
            }
            num = _this.nodecps.Length;
            w.Write(num);
            num = _this.vertcps.Length;
            w.Write(num);
            num = _this.vertRecycle.Length;
            w.Write(num);
            w.Write(_this.vertRecycleCursor);
            for (int num7 = 0; num7 < _this.vertRecycleCursor; num7++)
            {
                w.Write(_this.vertRecycle[num7]);
            }
        }
        public static void ImportBP(this DysonSphereLayer _this, BinaryReader r)
        {
            r.ReadInt32();
            _this.id                = r.ReadInt32();
            _this.orbitRadius       = r.ReadSingle();
            _this.orbitRotation.x   = r.ReadSingle();
            _this.orbitRotation.y   = r.ReadSingle();
            _this.orbitRotation.z   = r.ReadSingle();
            _this.orbitRotation.w   = r.ReadSingle();
            _this.orbitAngularSpeed = r.ReadSingle();
            _this.currentAngle      = r.ReadSingle();
            _this.currentRotation.x = r.ReadSingle();
            _this.currentRotation.y = r.ReadSingle();
            _this.currentRotation.z = r.ReadSingle();
            _this.currentRotation.w = r.ReadSingle();
            _this.nextRotation.x    = r.ReadSingle();
            _this.nextRotation.y    = r.ReadSingle();
            _this.nextRotation.z    = r.ReadSingle();
            _this.nextRotation.w    = r.ReadSingle();
            _this.gridMode          = r.ReadInt32();
            _this.ResetNew();
            int num = r.ReadInt32();

            Traverse.Create(_this).Method("SetNodeCapacity", num).GetValue();
            _this.nodeCursor        = r.ReadInt32();
            _this.nodeRecycleCursor = r.ReadInt32();
            for (int i = 1; i < _this.nodeCursor; i++)
            {
                int num2 = r.ReadInt32();
                if (num2 != 0)
                {
                    Assert.True(num2 == i);
                    DysonNode dysonNode = new DysonNode();
                    dysonNode.ImportBP(r);
                    Assert.True(dysonNode.id == i);
                    if (dysonNode.id != i || num2 != i)
                    {
                        throw new Exception($"node id doesn't match! {dysonNode.id} and {num2}");
                    }
                    _this.nodePool[i] = dysonNode;
                }
            }
            for (int j = 0; j < _this.nodeRecycleCursor; j++)
            {
                _this.nodeRecycle[j] = r.ReadInt32();
            }
            num = r.ReadInt32();
            Traverse.Create(_this).Method("SetFrameCapacity", num).GetValue();
            _this.frameCursor        = r.ReadInt32();
            _this.frameRecycleCursor = r.ReadInt32();
            for (int k = 1; k < _this.frameCursor; k++)
            {
                int num3 = r.ReadInt32();
                if (num3 != 0)
                {
                    Assert.True(num3 == k);
                    DysonFrame dysonFrame = new DysonFrame();
                    dysonFrame.ImportBP(r, _this.dysonSphere);
                    Assert.True(dysonFrame.id == k);
                    if (dysonFrame.id != k || num3 != k)
                    {
                        throw new Exception("frame id doesn't match!");
                    }
                    _this.framePool[k] = dysonFrame;
                }
            }
            for (int l = 0; l < _this.frameRecycleCursor; l++)
            {
                _this.frameRecycle[l] = r.ReadInt32();
            }
            num = r.ReadInt32();
            Traverse.Create(_this).Method("SetShellCapacity", num).GetValue();
            _this.shellCursor        = r.ReadInt32();
            _this.shellRecycleCursor = r.ReadInt32();
            for (int m = 1; m < _this.shellCursor; m++)
            {
                int num4 = r.ReadInt32();
                if (num4 != 0)
                {
                    Assert.True(num4 == m);
                    DysonShell dysonShell = new DysonShell(_this);
                    dysonShell.ImportBP(r, _this.dysonSphere);
                    Assert.True(dysonShell.id == m);
                    if (dysonShell.id != m || num4 != m)
                    {
                        throw new Exception("shell id doesn't match!");
                    }
                    _this.shellPool[m] = dysonShell;
                }
            }
            for (int n = 0; n < _this.shellRecycleCursor; n++)
            {
                _this.shellRecycle[n] = r.ReadInt32();
            }
            for (int num5 = 1; num5 < _this.nodeCursor; num5++)
            {
                if (_this.nodePool[num5] != null && _this.nodePool[num5].id == num5)
                {
                    _this.nodePool[num5].RecalcSpReq();
                    _this.nodePool[num5].RecalcCpReq();
                }
            }
        }
Пример #6
0
        public static bool DysonShell_Export_Prefix(DysonShell __instance, BinaryWriter w)
        {
            if (!optimiseSave)
            {
                return(true);
            }

            w.Write(SAVE_FIX_VERSION);
            w.Write(__instance.id);
            w.Write(__instance.protoId);
            w.Write(__instance.layerId);
            w.Write(__instance.randSeed);
            w.Write(__instance.polygon.Count);

            for (int i = 0; i < __instance.polygon.Count; i++)
            {
                w.Write(__instance.polygon[i].x);
                w.Write(__instance.polygon[i].y);
                w.Write(__instance.polygon[i].z);
            }

            w.Write(__instance.nodes.Count);
            for (int j = 0; j < __instance.nodes.Count; j++)
            {
                w.Write(__instance.nodes[j].id);
            }

            // saving the following counts and length only for validation purpose
            // there's no need to save the actual contents of those arrays as they can be recalculalted using GenerateGeometry() from just
            // polygon and nodes (and frames but those are inferred from nodes)

            w.Write(__instance.vertexCount);
            w.Write(__instance.triangleCount);

            w.Write(__instance.verts.Length);
            w.Write(__instance.pqArr.Length);
            w.Write(__instance.tris.Length);
            w.Write(__instance.vAdjs.Length);
            w.Write(__instance.vertAttr.Length);
            w.Write(__instance.vertsq.Length);
            w.Write(__instance.vertsqOffset.Length);

            // the nodecps and vertcps (that gets updated every time a new piece of the shell has been completed) must be saved.
            // a further optimisation could be to tag a shell as 'complete' and at that point there would be no need to store
            // all this data

            var num = __instance.nodecps.Length;

            w.Write(num);
            for (int num5 = 0; num5 < num; num5++)
            {
                w.Write(__instance.nodecps[num5]);
            }
            num = __instance.vertcps.Length;
            w.Write(num);
            for (int num6 = 0; num6 < num; num6++)
            {
                w.Write(__instance.vertcps[num6]);
            }
            num = __instance.vertRecycle.Length;
            w.Write(num);
            w.Write(__instance.vertRecycleCursor);
            for (int num7 = 0; num7 < __instance.vertRecycleCursor; num7++)
            {
                w.Write(__instance.vertRecycle[num7]);
            }

            return(false);
        }
Пример #7
0
        public static bool DysonShell_Import_Prefix(DysonShell __instance, BinaryReader r, DysonSphere dysonSphere)
        {
            __instance.SetEmpty();
            var version = r.PeekChar();

            if (version != SAVE_FIX_VERSION)
            {
                Debug.Log($"Using native import {version}");
                return(true);
            }

            Debug.Log($"Using smart import {version}");

            r.ReadChar();
            __instance.id       = r.ReadInt32();
            __instance.protoId  = r.ReadInt32();
            __instance.layerId  = r.ReadInt32();
            __instance.randSeed = r.ReadInt32();
            int num = r.ReadInt32();

            for (int i = 0; i < num; i++)
            {
                Vector3 item = default(Vector3);
                item.x = r.ReadSingle();
                item.y = r.ReadSingle();
                item.z = r.ReadSingle();
                __instance.polygon.Add(item);
            }
            int num2 = r.ReadInt32();

            for (int j = 0; j < num2; j++)
            {
                int       num3      = r.ReadInt32();
                DysonNode dysonNode = dysonSphere.FindNode(__instance.layerId, num3);
                Assert.NotNull(dysonNode);
                if (dysonNode != null)
                {
                    __instance.nodeIndexMap[num3] = __instance.nodes.Count;
                    __instance.nodes.Add(dysonNode);
                    if (!dysonNode.shells.Contains(__instance))
                    {
                        dysonNode.shells.Add(__instance);
                    }
                }
            }
            Assert.True(__instance.nodeIndexMap.Count == __instance.nodes.Count);
            int count = __instance.nodes.Count;

            for (int k = 0; k < count; k++)
            {
                int        index      = k;
                int        index2     = (k + 1) % count;
                DysonFrame dysonFrame = DysonNode.FrameBetween(__instance.nodes[index], __instance.nodes[index2]);
                Assert.NotNull(dysonFrame);
                __instance.frames.Add(dysonFrame);
            }
            var vertexCount        = r.ReadInt32();
            var triangleCount      = r.ReadInt32();
            int vertsLength        = r.ReadInt32();
            var pqArrLength        = r.ReadInt32();
            var trisLength         = r.ReadInt32();
            var vAdjsLength        = r.ReadInt32();
            var vertAttrLength     = r.ReadInt32();
            var vertsqLength       = r.ReadInt32();
            var vertsqOffsetLength = r.ReadInt32();

            __instance.GenerateGeometry();

            // Verify that generated geometry is 'at least' formally correct from a counting point of view
            Assert.True(vertexCount == __instance.vertexCount);
            Assert.True(triangleCount == __instance.triangleCount);
            Assert.True(vertsLength == __instance.verts.Length);

            Assert.True(pqArrLength == __instance.pqArr.Length);
            Assert.True(trisLength == __instance.tris.Length);
            Assert.True(vAdjsLength == __instance.vAdjs.Length);
            Assert.True(vertAttrLength == __instance.vertAttr.Length);
            Assert.True(vertsqLength == __instance.vertsq.Length);
            Assert.True(vertsqOffsetLength == __instance.verts.Length);


            Assert.True(__instance.vertAttr.Length == __instance.verts.Length);
            Assert.True(__instance.vertsq.Length == __instance.verts.Length);
            Assert.True(__instance.vertsqOffset.Length == __instance.nodes.Count + 1);

            // Restore nodecps, vertcps and vertRecycle from save
            var num4 = r.ReadInt32();

            __instance.nodecps = new int[num4];
            for (int num9 = 0; num9 < num4; num9++)
            {
                __instance.nodecps[num9] = r.ReadInt32();
            }
            Assert.True(__instance.nodecps.Length == __instance.nodes.Count + 1);
            num4 = r.ReadInt32();
            __instance.vertcps = new uint[num4];
            for (int num10 = 0; num10 < num4; num10++)
            {
                __instance.vertcps[num10] = r.ReadUInt32();
            }
            num4 = r.ReadInt32();
            __instance.vertRecycleCursor = r.ReadInt32();
            __instance.vertRecycle       = new int[num4];
            for (int num11 = 0; num11 < __instance.vertRecycleCursor; num11++)
            {
                __instance.vertRecycle[num11] = r.ReadInt32();
            }
            Assert.True(__instance.vertRecycle.Length == __instance.verts.Length);

            Array.Resize(ref __instance.vertcps, __instance.vertexCount);

            __instance.SyncCellBuffer();
            return(false);
        }