Exemple #1
0
 private static void SaveASync_Prefix()
 {
     using (BinaryWriter writer = new BinaryWriter(new FileStream(BetterTerrain.db_path + ".hmap", FileMode.Create)))
     {
         HMAPManager.WriteHMAP(writer);
     }
 }
Exemple #2
0
 private static void SpawnZone_Postfix(ZoneSystem __instance, Vector2i zoneID, GameObject root)
 {
     if (!(root == null))
     {
         HMAPManager.SetGameObject(zoneID, root.GetComponentInChildren <Heightmap>().gameObject);
         HMAPManager.SetHeightmap(zoneID, root.GetComponentInChildren <Heightmap>());
         HMAPManager.CalcTMods(zoneID);
         HMAPManager.GetZoneInfo(zoneID).hmap.Regenerate();
     }
 }
Exemple #3
0
 private static void Load_Prefix()
 {
     if (File.Exists(BetterTerrain.db_path + ".hmap"))
     {
         using (BinaryReader reader = new BinaryReader(new FileStream(BetterTerrain.db_path + ".hmap", FileMode.Open)))
         {
             HMAPManager.ReadHMAP(reader);
         }
     }
 }
Exemple #4
0
        private static void LocationAwake_Postfix(ZoneSystem __instance, GameObject __result, Vector3 pos)
        {
            Vector2i zone2 = ZoneSystem.instance.GetZone(pos);

            BetterTerrain.ZoneInfo zone = HMAPManager.GetZoneInfo(zone2);
            if (HMAPManager.IsZoneKnown(zone2))
            {
                if (zone.has_location)
                {
                    zone.hmap.Regenerate();
                }
                zone.has_location = true;
            }
        }
Exemple #5
0
        private static bool Generate_Prefix(Heightmap __instance, int ___m_width, ref List <float> ___m_heights, ref Texture2D ___m_clearedMask, HeightmapBuilder.HMBuildData ___m_buildData)
        {
            if (ZoneSystem.instance == null)
            {
                return(true);
            }
            Vector3 position = __instance.transform.position;

            __instance.Initialize();
            int num3 = __instance.m_width + 1;
            int num2 = num3 * num3;

            BetterTerrain.ZoneInfo zone = HMAPManager.GetZoneInfo(__instance.transform.position);
            if (zone == null || zone.game_object != __instance.gameObject)
            {
                return(true);
            }
            if (!zone.generated)
            {
                if (__instance.m_buildData == null || __instance.m_buildData.m_baseHeights.Count != num2 || __instance.m_buildData.m_center != position || __instance.m_buildData.m_scale != __instance.m_scale || __instance.m_buildData.m_worldGen != WorldGenerator.instance)
                {
                    __instance.m_buildData    = HeightmapBuilder.instance.RequestTerrainSync(position, __instance.m_width, __instance.m_scale, __instance.m_isDistantLod, WorldGenerator.instance);
                    __instance.m_cornerBiomes = __instance.m_buildData.m_cornerBiomes;
                }
                for (int i = 0; i < num2; i++)
                {
                    __instance.m_heights[i] = __instance.m_buildData.m_baseHeights[i];
                }
                Color[] pixels = new Color[__instance.m_clearedMask.width * __instance.m_clearedMask.height];
                __instance.m_clearedMask.SetPixels(pixels);
                zone.generated = true;
                zone.hmap      = __instance;
            }
            HMAPManager.RegenerateZone(zone);
            return(false);
        }
Exemple #6
0
 private static void Shutdown_Postfix()
 {
     HMAPManager.Reset();
     TModManager.Reset();
 }
Exemple #7
0
        private static bool ApplyModifier_Prefix(TerrainModifier modifier, Heightmap __instance, int ___m_width, ref List <float> ___m_heights, ref Texture2D ___m_clearedMask, HeightmapBuilder.HMBuildData ___m_buildData)
        {
            if (ZoneSystem.instance == null)
            {
                return(true);
            }
            Vector2i zoneID = ZoneSystem.instance.GetZone(__instance.transform.position);

            BetterTerrain.ZoneInfo zone = HMAPManager.GetZoneInfo(zoneID);
            if (zone == null || modifier == null || __instance != zone.hmap)
            {
                return(false);
            }
            bool was_applied = zone.applied_tmods.Contains(modifier);

            if (!was_applied)
            {
                zone.applied_tmods.Add(modifier);
            }
            bool  can_delete      = true;
            float modifier_radius = modifier.GetRadius();

            if (!zone.deletable_tmods.Contains(modifier))
            {
                for (int y = -1; y <= 1; y++)
                {
                    for (int x = -1; x <= 1; x++)
                    {
                        BetterTerrain.ZoneInfo check_zone = HMAPManager.GetZoneInfo(new Vector2i(zoneID.x + x, zoneID.y + y));
                        if (check_zone != null && check_zone.generated)
                        {
                            foreach (TerrainModifier tmod in check_zone.tmods.Except(check_zone.applied_tmods))
                            {
                                if (tmod != null)
                                {
                                    float radius = Math.Max(tmod.GetRadius(), modifier_radius);
                                    if (tmod != modifier && Vector3.Distance(tmod.transform.position, modifier.transform.position) <= radius)
                                    {
                                        Debug.Log(Vector3.Distance(tmod.transform.position, modifier.transform.position));
                                        can_delete = false;
                                    }
                                }
                            }
                        }
                        else
                        {
                            can_delete = false;
                        }
                    }
                }
                if (can_delete)
                {
                    Debug.Log("x");
                    zone.deletable_tmods.Add(modifier);
                }
            }
            if (was_applied)
            {
                return(false);
            }
            if (zone.saved && HMAPManager.loading_object)
            {
                return(false);
            }
            return(true);
        }