private double GetMaxTerrainHeight()
    {
        double num = 0.0;

        CelestialBodyData.TerrainData.HeightMapData[] heightMaps = this.terrainData.heightMaps;
        for (int i = 0; i < heightMaps.Length; i++)
        {
            CelestialBodyData.TerrainData.HeightMapData heightMapData = heightMaps[i];
            if (heightMapData.apply)
            {
                num += heightMapData.height;
            }
        }
        for (int j = 0; j < this.terrainData.perlinLayers.Length; j++)
        {
            if (this.terrainData.perlinLayers[j].apply)
            {
                if (this.terrainData.perlinLayers[j].NeedLocalValue)
                {
                    double num2 = 0.0;
                    for (int k = 0; k < this.terrainData.perlinLayers[j].layerComponents.Length; k++)
                    {
                        CelestialBodyData.TerrainData.PerlinaLayer.Layer layer = this.terrainData.perlinLayers[j].layerComponents[k];
                        switch (layer.applyType)
                        {
                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.AddToGlobal:
                            num += num2 * (double)layer.height;
                            break;

                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.AddToLocal:
                            num2 += (double)layer.height;
                            break;

                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.MultiplyLocal:
                            num2 *= (double)layer.height;
                            break;

                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.MultiplyByLocalAddToGlobal:
                            num += num2 * (double)layer.height;
                            break;
                        }
                    }
                }
                else
                {
                    for (int l = 0; l < this.terrainData.perlinLayers[j].layerComponents.Length; l++)
                    {
                        CelestialBodyData.TerrainData.PerlinaLayer.Layer layer2 = this.terrainData.perlinLayers[j].layerComponents[l];
                        num += (double)layer2.height;
                    }
                }
            }
        }
        return(num);
    }
    private double[] GetTerrainSamples(double from, double LOD, int pointCount, bool addRadius)
    {
        double[] array  = new double[pointCount];
        double[] array2 = new double[pointCount];
        for (int i = 0; i < pointCount; i++)
        {
            array2[i] = from + (double)i / LOD;
            if (addRadius)
            {
                array[i] = this.radius;
            }
        }
        CelestialBodyData.TerrainData.HeightMapData[] heightMaps = this.terrainData.heightMaps;
        for (int j = 0; j < heightMaps.Length; j++)
        {
            CelestialBodyData.TerrainData.HeightMapData heightMapData = heightMaps[j];
            if (heightMapData.apply)
            {
                for (int k = 0; k < pointCount; k++)
                {
                    float num  = (float)(array2[k] * heightMapData.repeat % 1.0);
                    int   num2 = (int)(array2[k] * heightMapData.repeat);
                    array[k] += heightMapData.height * (double)(heightMapData.heightMap.HeightDataArray[num2 % heightMapData.heightMap.HeightDataArray.Length] * (1f - num) + heightMapData.heightMap.HeightDataArray[(num2 + 1) % heightMapData.heightMap.HeightDataArray.Length] * num);
                }
            }
        }
        for (int l = 0; l < this.terrainData.perlinLayers.Length; l++)
        {
            if (this.terrainData.perlinLayers[l].apply)
            {
                if (this.terrainData.perlinLayers[l].NeedLocalValue)
                {
                    double[] array3 = new double[pointCount];
                    for (int m = 0; m < this.terrainData.perlinLayers[l].layerComponents.Length; m++)
                    {
                        CelestialBodyData.TerrainData.PerlinaLayer.Layer layer = this.terrainData.perlinLayers[l].layerComponents[m];
                        switch (layer.applyType)
                        {
                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.AddToGlobal:
                            for (int n = 0; n < pointCount; n++)
                            {
                                array[n] += array3[n] + (double)(layer.perlinCurve.Evaluate(Mathf.PerlinNoise((float)array2[n] * layer.repeatX, 0f)) * layer.height);
                            }
                            break;

                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.AddToLocal:
                            for (int num3 = 0; num3 < pointCount; num3++)
                            {
                                array3[num3] += (double)(layer.perlinCurve.Evaluate(Mathf.PerlinNoise((float)array2[num3] * layer.repeatX, 0f)) * layer.height);
                            }
                            break;

                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.MultiplyLocal:
                            for (int num4 = 0; num4 < pointCount; num4++)
                            {
                                array3[num4] *= (double)(layer.perlinCurve.Evaluate(Mathf.PerlinNoise((float)array2[num4] * layer.repeatX, 0f)) * layer.height);
                            }
                            break;

                        case CelestialBodyData.TerrainData.PerlinaLayer.Layer.ApplyType.MultiplyByLocalAddToGlobal:
                            for (int num5 = 0; num5 < pointCount; num5++)
                            {
                                array[num5] += array3[num5] * (double)layer.perlinCurve.Evaluate(Mathf.PerlinNoise((float)array2[num5] * layer.repeatX, 0f)) * (double)layer.height;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    for (int num6 = 0; num6 < this.terrainData.perlinLayers[l].layerComponents.Length; num6++)
                    {
                        CelestialBodyData.TerrainData.PerlinaLayer.Layer layer2 = this.terrainData.perlinLayers[l].layerComponents[num6];
                        for (int num7 = 0; num7 < pointCount; num7++)
                        {
                            array[num7] += (double)(layer2.perlinCurve.Evaluate(Mathf.PerlinNoise((float)array2[num7] * layer2.repeatX, 0f)) * layer2.height);
                        }
                    }
                }
            }
        }
        return(array);
    }