Skip to content

Commit

Permalink
Add lots of console commands for reload, refactoring,
Browse files Browse the repository at this point in the history
  • Loading branch information
billw2012 committed Apr 3, 2021
1 parent 3923865 commit 467a781
Show file tree
Hide file tree
Showing 9 changed files with 1,030 additions and 352 deletions.
302 changes: 220 additions & 82 deletions BetterContinents.BetterContinentsSettings.cs

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions BetterContinents.ConsolePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ private static void InputTextPrefix(Console __instance)
if (AllowDebugActions)
{
string text = __instance.m_input.text.Trim();
if (text == "bc" || text == "bc help")
{
DebugUtils.ShowHelp();
}
else if (DebugUtils.Subcommand(ref text, "bc"))
{
DebugUtils.RunConsoleCommand(text);
}
DebugUtils.RunConsoleCommand(text);
}
}
}
Expand Down
134 changes: 133 additions & 1 deletion BetterContinents.ZoneSystemPatch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System.Collections.Generic;
using HarmonyLib;
using UnityEngine;

namespace BetterContinents
Expand Down Expand Up @@ -66,6 +67,137 @@ private static bool GenerateLocationsPrefix(ZoneSystem __instance, ZoneSystem.Zo
}
return true;
}

public static int TagLocationZDOs = 0;
public static int TagVegetationZDOs = 0;

[HarmonyPrefix, HarmonyPatch(nameof(ZoneSystem.SpawnLocation))]
private static void SpawnLocationPrefix()
{
++TagLocationZDOs;
}
[HarmonyFinalizer, HarmonyPatch(nameof(ZoneSystem.SpawnLocation))]
private static void SpawnLocationFinalizer()
{
--TagLocationZDOs;
}

[HarmonyPrefix, HarmonyPatch(nameof(ZoneSystem.PlaceVegetation))]
private static void PlaceVegetationPrefix()
{
++TagVegetationZDOs;
}
[HarmonyFinalizer, HarmonyPatch(nameof(ZoneSystem.PlaceVegetation))]
private static void PlaceVegetationFinalizer()
{
--TagVegetationZDOs;
}

// [HarmonyPrefix, HarmonyPatch(nameof(ZoneSystem.SpawnLocation))]
// private static bool SpawnLocation(ZoneSystem __instance, ZoneSystem.ZoneLocation location, int seed, Vector3 pos, Quaternion rot, ZoneSystem.SpawnMode mode, List<GameObject> spawnedGhostObjects, ref GameObject __result)
// {
// // Only enable this behaviour if BC is enabled.
// SpawningLocation = Settings.EnabledForThisWorld;
//
// Vector3 position = location.m_prefab.transform.position;
// Quaternion lhs = Quaternion.Inverse(location.m_prefab.transform.rotation);
// UnityEngine.Random.InitState(seed);
// if (mode == ZoneSystem.SpawnMode.Full || mode == ZoneSystem.SpawnMode.Ghost)
// {
// foreach (ZNetView znetView in location.m_netViews)
// {
// znetView.gameObject.SetActive(true);
// }
// foreach (RandomSpawn randomSpawn in location.m_randomSpawns)
// {
// randomSpawn.Randomize();
// }
// WearNTear.m_randomInitialDamage = location.m_location.m_applyRandomDamage;
// foreach (ZNetView znetView2 in location.m_netViews)
// {
// if (znetView2.gameObject.activeSelf)
// {
// Vector3 point = znetView2.gameObject.transform.position - position;
// Vector3 position2 = pos + rot * point;
// Quaternion rhs = lhs * znetView2.gameObject.transform.rotation;
// Quaternion rotation = rot * rhs;
// if (mode == ZoneSystem.SpawnMode.Ghost)
// {
// ZNetView.StartGhostInit();
// }
// GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(znetView2.gameObject, position2, rotation);
// gameObject.GetComponent<ZNetView>().GetZDO().SetPGWVersion(__instance.m_pgwVersion);
// DungeonGenerator component = gameObject.GetComponent<DungeonGenerator>();
// if (component)
// {
// component.Generate(mode);
// }
// if (mode == ZoneSystem.SpawnMode.Ghost)
// {
// spawnedGhostObjects.Add(gameObject);
// ZNetView.FinishGhostInit();
// }
// }
// }
// WearNTear.m_randomInitialDamage = false;
// __instance.CreateLocationProxy(location, seed, pos, rot, mode, spawnedGhostObjects);
// SnapToGround.SnappAll();
// __result = null;
// return false;
// }
// foreach (RandomSpawn randomSpawn2 in location.m_randomSpawns)
// {
// randomSpawn2.Randomize();
// }
// foreach (ZNetView znetView3 in location.m_netViews)
// {
// znetView3.gameObject.SetActive(false);
// }
// __result = UnityEngine.Object.Instantiate<GameObject>(location.m_prefab, pos, rot);
// __result.SetActive(true);
// SnapToGround.SnappAll();
// return false;
// }


}

[HarmonyPatch(typeof(CreatureSpawner))]
private class CreatureSpawnerPatch
{
public static int TagSpawnZDOs = 0;

[HarmonyPrefix, HarmonyPatch(nameof(CreatureSpawner.Spawn))]
private static void SpawnPrefix()
{
++TagSpawnZDOs;
}
[HarmonyFinalizer, HarmonyPatch(nameof(CreatureSpawner.Spawn))]
private static void SpawnFinalizer()
{
--TagSpawnZDOs;
}
}

[HarmonyPatch(typeof(ZDOMan))]
private class ZDOManPatch
{
[HarmonyPostfix, HarmonyPatch(nameof(ZDOMan.CreateNewZDO), typeof(ZDOID), typeof(Vector3))]
private static void CreateNewZDOPostfix(ref ZDO __result)
{
if (BetterContinents.Settings.EnabledForThisWorld && ZoneSystemPatch.TagLocationZDOs > 0)
{
__result.Set("bc_loc", 1);
}
if (BetterContinents.Settings.EnabledForThisWorld && ZoneSystemPatch.TagVegetationZDOs > 0)
{
__result.Set("bc_veg", 1);
}
if (BetterContinents.Settings.EnabledForThisWorld && CreatureSpawnerPatch.TagSpawnZDOs > 0)
{
__result.Set("bc_spawn", 1);
}
}
}
}
}
74 changes: 38 additions & 36 deletions BetterContinents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,52 @@ namespace BetterContinents
public partial class BetterContinents : BaseUnityPlugin
{
// See the Awake function for the config descriptions
private static ConfigEntry<bool> ConfigEnabled;
public static ConfigEntry<bool> ConfigEnabled;

private static ConfigEntry<float> ConfigContinentSize;
private static ConfigEntry<float> ConfigMountainsAmount;
private static ConfigEntry<float> ConfigSeaLevelAdjustment;
private static ConfigEntry<bool> ConfigOceanChannelsEnabled;
private static ConfigEntry<bool> ConfigRiversEnabled;
private static ConfigEntry<bool> ConfigMapEdgeDropoff;
private static ConfigEntry<bool> ConfigMountainsAllowedAtCenter;
public static ConfigEntry<float> ConfigContinentSize;
public static ConfigEntry<float> ConfigMountainsAmount;
public static ConfigEntry<float> ConfigSeaLevelAdjustment;
public static ConfigEntry<bool> ConfigOceanChannelsEnabled;
public static ConfigEntry<bool> ConfigRiversEnabled;
public static ConfigEntry<bool> ConfigMapEdgeDropoff;
public static ConfigEntry<bool> ConfigMountainsAllowedAtCenter;

private static ConfigEntry<string> ConfigMapSourceDir;
public static ConfigEntry<string> ConfigMapSourceDir;

private static ConfigEntry<string> ConfigHeightmapFile;
private static ConfigEntry<float> ConfigHeightmapAmount;
private static ConfigEntry<float> ConfigHeightmapBlend;
private static ConfigEntry<float> ConfigHeightmapAdd;
public static ConfigEntry<string> ConfigHeightmapFile;
public static ConfigEntry<float> ConfigHeightmapAmount;
public static ConfigEntry<float> ConfigHeightmapBlend;
public static ConfigEntry<float> ConfigHeightmapAdd;

private static ConfigEntry<string> ConfigBiomemapFile;
public static ConfigEntry<string> ConfigBiomemapFile;

private static ConfigEntry<string> ConfigSpawnmapFile;
public static ConfigEntry<string> ConfigSpawnmapFile;

private static ConfigEntry<string> ConfigRoughmapFile;
private static ConfigEntry<float> ConfigRoughmapBlend;
public static ConfigEntry<string> ConfigRoughmapFile;
public static ConfigEntry<float> ConfigRoughmapBlend;

private static ConfigEntry<bool> ConfigUseRoughInvertedForFlat;
private static ConfigEntry<string> ConfigFlatmapFile;
private static ConfigEntry<float> ConfigFlatmapBlend;
public static ConfigEntry<bool> ConfigUseRoughInvertedForFlat;
public static ConfigEntry<string> ConfigFlatmapFile;
public static ConfigEntry<float> ConfigFlatmapBlend;

private static ConfigEntry<float> ConfigForestScale;
private static ConfigEntry<float> ConfigForestAmount;
private static ConfigEntry<bool> ConfigForestFactorOverrideAllTrees;
private static ConfigEntry<string> ConfigForestmapFile;
private static ConfigEntry<float> ConfigForestmapMultiply;
private static ConfigEntry<float> ConfigForestmapAdd;
public static ConfigEntry<float> ConfigForestScale;
public static ConfigEntry<float> ConfigForestAmount;
public static ConfigEntry<bool> ConfigForestFactorOverrideAllTrees;
public static ConfigEntry<string> ConfigForestmapFile;
public static ConfigEntry<float> ConfigForestmapMultiply;
public static ConfigEntry<float> ConfigForestmapAdd;

private static ConfigEntry<float> ConfigMaxRidgeHeight;
private static ConfigEntry<float> ConfigRidgeSize;
private static ConfigEntry<float> ConfigRidgeBlend;
private static ConfigEntry<float> ConfigRidgeAmount;
public static ConfigEntry<float> ConfigMaxRidgeHeight;
public static ConfigEntry<float> ConfigRidgeSize;
public static ConfigEntry<float> ConfigRidgeBlend;
public static ConfigEntry<float> ConfigRidgeAmount;

private static ConfigEntry<bool> ConfigOverrideStartPosition;
private static ConfigEntry<float> ConfigStartPositionX;
private static ConfigEntry<float> ConfigStartPositionY;
public static ConfigEntry<bool> ConfigOverrideStartPosition;
public static ConfigEntry<float> ConfigStartPositionX;
public static ConfigEntry<float> ConfigStartPositionY;

private static ConfigEntry<bool> ConfigDebugModeEnabled;
private static ConfigEntry<bool> ConfigDebugSkipDefaultLocationPlacement;
public static ConfigEntry<bool> ConfigDebugModeEnabled;
public static ConfigEntry<bool> ConfigDebugSkipDefaultLocationPlacement;

private const float WorldSize = 10500f;
private static readonly Vector2 Half = Vector2.one * 0.5f;
Expand Down Expand Up @@ -168,7 +168,8 @@ private static void OnSpawnedPrefix(Player __instance)

[HarmonyPostfix, HarmonyPatch(nameof(Player.OnSpawned))]
private static void OnSpawnedPostfix()
{ if (AllowDebugActions)
{
if (AllowDebugActions)
{
AccessTools.Field(typeof(Console), "m_cheat").SetValue(Console.instance, true);
Minimap.instance.ExploreAll();
Expand All @@ -177,6 +178,7 @@ private static void OnSpawnedPostfix()
EnvMan.instance.m_debugTimeOfDay = true;
EnvMan.instance.m_debugTime = 0.5f;
Player.m_localPlayer.SetGodMode(true);
GameCamera.instance.m_minWaterDistance = -1000f;
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions BetterContinents.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
<Private>False</Private>
</Reference>
<Reference Include="assembly_valheim, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Valheim\valheim_Data\Managed\assembly_valheim.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Valheim\valheim_Data\Managed\publicized_assemblies\assembly_valheim_publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx, Version=5.4.8.0, Culture=neutral, PublicKeyToken=null">
<HintPath>lib\BepInEx\core\BepInEx.dll</HintPath>
Expand Down Expand Up @@ -259,7 +258,7 @@
<Assemblies Include="$(TargetDir)*.dll" />
</ItemGroup>
<Exec Command="C:\Programs\pdb2mdb\pdb2mdb.exe &quot;$(TargetPath)&quot;" />
<Copy SourceFiles="@(Assemblies)" DestinationFolder="C:\program files (x86)\steam\steamapps\common\Valheim\BepInEx\plugins" />
<Copy SourceFiles="@(Assemblies)" DestinationFolder="C:\program files (x86)\steam\steamapps\common\Valheim-debug\BepInEx\plugins" />
</Target>
<Import Project="packages\Fody.6.3.0\build\Fody.targets" Condition="Exists('packages\Fody.6.3.0\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Loading

0 comments on commit 467a781

Please sign in to comment.