public void askStructures(CSteamID steamID, byte x, byte y)
        {
            StructureRegion structureRegion;

            if (StructureManager.tryGetRegion(x, y, out structureRegion))
            {
                if (structureRegion.structures.Count > 0)
                {
                    byte b = 0;
                    int  i = 0;
                    int  j = 0;
                    while (i < structureRegion.structures.Count)
                    {
                        int num = 0;
                        while (j < structureRegion.structures.Count)
                        {
                            num += 38;
                            j++;
                            if (num > Block.BUFFER_SIZE / 2)
                            {
                                break;
                            }
                        }
                        base.channel.openWrite();
                        base.channel.write(x);
                        base.channel.write(y);
                        base.channel.write(b);
                        base.channel.write((ushort)(j - i));
                        while (i < j)
                        {
                            StructureData structureData = structureRegion.structures[i];
                            base.channel.write(new object[]
                            {
                                structureData.structure.id,
                                structureData.point,
                                structureData.angle_x,
                                structureData.angle_y,
                                structureData.angle_z,
                                structureData.owner,
                                structureData.group,
                                structureRegion.drops[i].instanceID
                            });
                            base.channel.write((byte)Mathf.RoundToInt((float)structureData.structure.health / (float)structureData.structure.asset.health * 100f));
                            i++;
                        }
                        base.channel.closeWrite("tellStructures", steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER);
                        b += 1;
                    }
                }
                else
                {
                    base.channel.openWrite();
                    base.channel.write(x);
                    base.channel.write(y);
                    base.channel.write(0);
                    base.channel.write(0);
                    base.channel.closeWrite("tellStructures", steamID, ESteamPacket.UPDATE_RELIABLE_CHUNK_BUFFER);
                }
            }
        }
        public static void dropStructure(Structure structure, Vector3 point, float angle_x, float angle_y, float angle_z, ulong owner, ulong group)
        {
            ItemStructureAsset itemStructureAsset = (ItemStructureAsset)Assets.find(EAssetType.ITEM, structure.id);

            if (itemStructureAsset != null)
            {
                Vector3 eulerAngles = Quaternion.Euler(-90f, angle_y, 0f).eulerAngles;
                angle_x = (float)(Mathf.RoundToInt(eulerAngles.x / 2f) * 2);
                angle_y = (float)(Mathf.RoundToInt(eulerAngles.y / 2f) * 2);
                angle_z = (float)(Mathf.RoundToInt(eulerAngles.z / 2f) * 2);
                byte            b;
                byte            b2;
                StructureRegion structureRegion;
                if (Regions.tryGetCoordinate(point, out b, out b2) && StructureManager.tryGetRegion(b, b2, out structureRegion))
                {
                    StructureData structureData = new StructureData(structure, point, MeasurementTool.angleToByte(angle_x), MeasurementTool.angleToByte(angle_y), MeasurementTool.angleToByte(angle_z), owner, group, Provider.time);
                    structureRegion.structures.Add(structureData);
                    StructureManager.manager.channel.send("tellStructure", ESteamCall.ALL, b, b2, StructureManager.STRUCTURE_REGIONS, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[]
                    {
                        b,
                        b2,
                        structure.id,
                        structureData.point,
                        structureData.angle_x,
                        structureData.angle_y,
                        structureData.angle_z,
                        owner,
                        group,
                        StructureManager.instanceCount += 1u
                    });
                }
            }
        }
        private static void updateActivity(StructureRegion region, CSteamID owner, CSteamID group)
        {
            ushort num = 0;

            while ((int)num < region.structures.Count)
            {
                StructureData structureData = region.structures[(int)num];
                if (OwnershipTool.checkToggle(owner, structureData.owner, group, structureData.group))
                {
                    structureData.objActiveDate = Provider.time;
                }
                num += 1;
            }
        }
        private static void saveRegion(River river, StructureRegion region)
        {
            uint   time = Provider.time;
            ushort num  = 0;
            ushort num2 = 0;

            while ((int)num2 < region.structures.Count)
            {
                StructureData structureData = region.structures[(int)num2];
                if ((!Dedicator.isDedicated || Provider.modeConfigData.Structures.Decay_Time == 0u || time < structureData.objActiveDate || time - structureData.objActiveDate < Provider.modeConfigData.Structures.Decay_Time) && structureData.structure.asset.isSaveable)
                {
                    num += 1;
                }
                num2 += 1;
            }
            river.writeUInt16(num);
            ushort num3 = 0;

            while ((int)num3 < region.structures.Count)
            {
                StructureData structureData2 = region.structures[(int)num3];
                if ((!Dedicator.isDedicated || Provider.modeConfigData.Structures.Decay_Time == 0u || time < structureData2.objActiveDate || time - structureData2.objActiveDate < Provider.modeConfigData.Structures.Decay_Time) && structureData2.structure.asset.isSaveable)
                {
                    river.writeUInt16(structureData2.structure.id);
                    river.writeUInt16(structureData2.structure.health);
                    river.writeSingleVector3(structureData2.point);
                    river.writeByte(structureData2.angle_x);
                    river.writeByte(structureData2.angle_y);
                    river.writeByte(structureData2.angle_z);
                    river.writeUInt64(structureData2.owner);
                    river.writeUInt64(structureData2.group);
                    river.writeUInt32(structureData2.objActiveDate);
                }
                num3 += 1;
            }
        }
        public static void load()
        {
            bool flag = false;

            if (LevelSavedata.fileExists("/Structures.dat") && Level.info.type == ELevelType.SURVIVAL)
            {
                River river = LevelSavedata.openRiver("/Structures.dat", true);
                byte  b     = river.readByte();
                if (b > 3)
                {
                    StructureManager.serverActiveDate = river.readUInt32();
                }
                else
                {
                    StructureManager.serverActiveDate = Provider.time;
                }
                if (b > 1)
                {
                    for (byte b2 = 0; b2 < Regions.WORLD_SIZE; b2 += 1)
                    {
                        for (byte b3 = 0; b3 < Regions.WORLD_SIZE; b3 += 1)
                        {
                            StructureRegion region = StructureManager.regions[(int)b2, (int)b3];
                            StructureManager.loadRegion(b, river, region);
                        }
                    }
                }
                if (b < 6)
                {
                    flag = true;
                }
            }
            else
            {
                flag = true;
            }
            if (flag && LevelObjects.buildables != null)
            {
                for (byte b4 = 0; b4 < Regions.WORLD_SIZE; b4 += 1)
                {
                    for (byte b5 = 0; b5 < Regions.WORLD_SIZE; b5 += 1)
                    {
                        List <LevelBuildableObject> list = LevelObjects.buildables[(int)b4, (int)b5];
                        if (list != null && list.Count != 0)
                        {
                            StructureRegion structureRegion = StructureManager.regions[(int)b4, (int)b5];
                            for (int i = 0; i < list.Count; i++)
                            {
                                LevelBuildableObject levelBuildableObject = list[i];
                                if (levelBuildableObject != null)
                                {
                                    ItemStructureAsset itemStructureAsset = levelBuildableObject.asset as ItemStructureAsset;
                                    if (itemStructureAsset != null)
                                    {
                                        Vector3       eulerAngles   = levelBuildableObject.rotation.eulerAngles;
                                        byte          newAngle_X    = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.x / 2f) * 2));
                                        byte          newAngle_Y    = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.y / 2f) * 2));
                                        byte          newAngle_Z    = MeasurementTool.angleToByte((float)(Mathf.RoundToInt(eulerAngles.z / 2f) * 2));
                                        Structure     structure     = new Structure(itemStructureAsset.id, itemStructureAsset.health, itemStructureAsset);
                                        StructureData structureData = new StructureData(structure, levelBuildableObject.point, newAngle_X, newAngle_Y, newAngle_Z, 0UL, 0UL, uint.MaxValue);
                                        structureRegion.structures.Add(structureData);
                                        StructureManager.manager.spawnStructure(structureRegion, structure.id, structureData.point, structureData.angle_x, structureData.angle_y, structureData.angle_z, (byte)Mathf.RoundToInt((float)structure.health / (float)itemStructureAsset.health * 100f), 0UL, 0UL, StructureManager.instanceCount += 1u);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Level.isLoadingStructures = false;
        }
        public void tellTransformStructure(CSteamID steamID, byte x, byte y, uint instanceID, Vector3 point, byte angle_x, byte angle_y, byte angle_z)
        {
            StructureRegion structureRegion;

            if (base.channel.checkServer(steamID) && StructureManager.tryGetRegion(x, y, out structureRegion))
            {
                if (!Provider.isServer && !structureRegion.isNetworked)
                {
                    return;
                }
                StructureData structureData = null;
                StructureDrop structureDrop = null;
                ushort        num           = 0;
                while ((int)num < structureRegion.drops.Count)
                {
                    if (structureRegion.drops[(int)num].instanceID == instanceID)
                    {
                        if (Provider.isServer)
                        {
                            structureData = structureRegion.structures[(int)num];
                        }
                        structureDrop = structureRegion.drops[(int)num];
                        break;
                    }
                    num += 1;
                }
                if (structureDrop == null)
                {
                    return;
                }
                structureDrop.model.position = point;
                structureDrop.model.rotation = Quaternion.Euler((float)(angle_x * 2), (float)(angle_y * 2), (float)(angle_z * 2));
                byte b;
                byte b2;
                if (Regions.tryGetCoordinate(point, out b, out b2) && (x != b || y != b2))
                {
                    StructureRegion structureRegion2 = StructureManager.regions[(int)b, (int)b2];
                    structureRegion.drops.RemoveAt((int)num);
                    if (structureRegion2.isNetworked || Provider.isServer)
                    {
                        structureRegion2.drops.Add(structureDrop);
                    }
                    else if (!Provider.isServer)
                    {
                        Object.Destroy(structureDrop.model.gameObject);
                    }
                    if (Provider.isServer)
                    {
                        structureRegion.structures.RemoveAt((int)num);
                        structureRegion2.structures.Add(structureData);
                    }
                }
                if (Provider.isServer)
                {
                    structureData.point   = point;
                    structureData.angle_x = angle_x;
                    structureData.angle_y = angle_y;
                    structureData.angle_z = angle_z;
                }
            }
        }