Browse Source

Add fix for glitching thru underside of player structures

tags/v0.0.2
NGnius (Graham) 2 years ago
parent
commit
11d650890f
4 changed files with 192 additions and 5 deletions
  1. +2
    -2
      CLre/API/Engines/FrontEndEngines.cs
  2. +2
    -2
      CLre/API/Engines/GameEngines.cs
  3. +2
    -1
      CLre/CLre.cs
  4. +186
    -0
      CLre/Fixes/UnderStructureCollider.cs

+ 2
- 2
CLre/API/Engines/FrontEndEngines.cs View File

@@ -86,9 +86,9 @@ namespace CLre.API.Engines
[HarmonyPatch(typeof(FrontEnd.MainFrontEnd), "BuildEngines")]
class MainFrontEnd_BuildEngines_Patch
{
internal static FasterList<FrontEndEnginePreBuild> beforeBuildEngines = new FasterList<FrontEndEnginePreBuild>();
internal static FasterList<ICLreEngine> beforeBuildEngines = new FasterList<ICLreEngine>();
internal static FasterList<FrontEndEnginePostBuild> afterBuildEngines = new FasterList<FrontEndEnginePostBuild>();
internal static FasterList<ICLreEngine> afterBuildEngines = new FasterList<ICLreEngine>();
internal static MethodInfo addEngine = AccessTools.Method(typeof(FrontEnd.MainFrontEnd), "AddEngine");


+ 2
- 2
CLre/API/Engines/GameEngines.cs View File

@@ -31,9 +31,9 @@ namespace CLre.API.Engines
[HarmonyPatch(typeof(GameFramework.MainLevel), "BuildDeprecatedEngines")]
class MainLevel_BuildDeprecatedEngines_Patch
{
internal static FasterList<GameObsoleteEnginePreBuild> beforeBuildEngines = new FasterList<GameObsoleteEnginePreBuild>();
internal static FasterList<ICLreEngine> beforeBuildEngines = new FasterList<ICLreEngine>();
internal static FasterList<GameObsoleteEnginePostBuild> afterBuildEngines = new FasterList<GameObsoleteEnginePostBuild>();
internal static FasterList<ICLreEngine> afterBuildEngines = new FasterList<ICLreEngine>();

[HarmonyPrefix]
public static void BeforeMethodCall(GameFramework.MainLevel __instance)


+ 2
- 1
CLre/CLre.cs View File

@@ -49,6 +49,7 @@ namespace CLre
// patches for bugs
Fixes.InitLogSooner.Init();
Fixes.MiniScreenHelper.Init();
Fixes.UnderStructureCollider.Init();
// misc
LogIPAPlugins();
@@ -119,7 +120,7 @@ namespace CLre
int modCount = IllusionInjector.PluginManager.Plugins.Count();
StringBuilder sb = new StringBuilder();
sb.AppendFormat(" {0} {1}\n", Name, Version);
sb.AppendFormat("{0} bugfixes, {1} plugins, no frills\n", fixCount, modCount);
sb.AppendFormat(" {0} bugfixes, {1} plugins, no frills\n", fixCount, modCount);
#if DEBUG
sb.AppendFormat(" DEBUG version\n");
#endif


+ 186
- 0
CLre/Fixes/UnderStructureCollider.cs View File

@@ -0,0 +1,186 @@
using System.Collections;
using System.Reflection;
using CLre.API.Engines;
using Game.Building;
using Game.Character;
using Game.Utilities;
using HarmonyLib;
using Svelto.ECS;
using Svelto.Tasks;
using UnityEngine;
using voxelfarm.VFCol;

namespace CLre.Fixes
{
[Bugfix(name = "UnderStructureCollider",
description = "Prevent passing through structures from below a bit better",
more = "https://trello.com/c/nfuaZWQZ/10-passing-through-structures",
component = BugfixType.Initialiser, id = 7)]
public static class UnderStructureCollider
{
public static void Init()
{
#if DEBUG
MainLevel_BuildDeprecatedEngines_Patch.afterBuildEngines.Add(new CharacterGroundedCheckEngine());
#endif
MainLevel_BuildDeprecatedEngines_Patch.afterBuildEngines.Add(new CharacterUnderStructureRaycastEngine());
}
}
[Bugfix(name = "UnderStructureCollider",
description = "Prevent passing through structures from below a bit better",
more = "https://trello.com/c/nfuaZWQZ/10-passing-through-structures",
component = BugfixType.HarmonyPatch, id = 7)]
[HarmonyPatch(typeof(VFColUtility), "Move")]
class VFCOlUtility_Move_Patch
{
internal static bool Override = false;

[HarmonyPostfix]
public static void AfterMethodCall(ref Vector3 __result)
{
#if DEBUG
API.Utility.Logging.MetaLog("Intercepting CharacterMovementEngine.ApplyForces(...)");
#endif
if (Override)
{
if (__result.y > 0)
{
__result = Vector3.zero;
}
}
}
}

#if DEBUG
[Bugfix(name = "UnderStructureCollider",
description = "Prevent passing through structures from below a bit better",
more = "https://trello.com/c/nfuaZWQZ/10-passing-through-structures",
component = BugfixType.Debug, id = 7)]
public class CharacterGroundedCheckEngine : SingleEntityViewEngine<CharacterOnStructureNode>, ICLreEngine
{
private CharacterOnStructureNode _characterOnStructureNode;
public void Ready() {}

public IEntitiesDB entitiesDB { get; set; }
public IEntityFactory entityFactory { get; set; }
protected override void Add(CharacterOnStructureNode entityView)
{
_characterOnStructureNode = entityView;
CheckNode().Run();
}

protected override void Remove(CharacterOnStructureNode entityView)
{
_characterOnStructureNode = null;
}

public IEnumerator CheckNode()
{
while (_characterOnStructureNode != null)
{
if (_characterOnStructureNode.characterGroundedRaycastComponent.didHit)
{
if (_characterOnStructureNode.characterGroundedRaycastComponent.hitResult.transform != null)
{
API.Utility.Logging.MetaLog($"HIT: {_characterOnStructureNode.characterGroundedRaycastComponent.hitResult.transform.tag} (audio: '{_characterOnStructureNode.characterOnStructureComponent.characterPositionStructureAudioSwitch.value}')");
RaycastHit raycastHitInfo = _characterOnStructureNode.characterGroundedRaycastComponent.hitResult;
if (raycastHitInfo.transform.tag == GameTags.STRUCTURE_TAG)
{
int instanceID = raycastHitInfo.transform.GetComponentInParent<DEPRECATED_REMOVE_EntityProxy>().gameObject.GetInstanceID();
if (entitiesDB.TryQueryEntityView(instanceID, DEPRECATED_SveltoExtensions.DEPRECATED_GROUP,
out PlacedStructureNode entityView))
{
API.Utility.Logging.MetaLog($"Structure: {entityView.structureNameComponent.resourceName}");
}
}
}
else
{
API.Utility.Logging.MetaLog("No transform (not on a structure?)");
}
}
else
{
API.Utility.Logging.MetaLog("No hit");
}
yield return null;
}
}
}
#endif

[Bugfix(name = "UnderStructureCollider",
description = "Prevent passing through structures from below a bit better",
more = "https://trello.com/c/nfuaZWQZ/10-passing-through-structures",
component = BugfixType.Miscellaneous, id = 7)]
public class CharacterUnderStructureRaycastEngine : SingleEntityViewEngine<CharacterMovementNode>, ICLreEngine
{
private bool _playerExists = false;

private int _layer = GameLayers.CARD_INTERACTABLE;
public void Ready()
{
}

public IEntitiesDB entitiesDB { get; set; }
public IEntityFactory entityFactory { get; set; }
protected override void Add(CharacterMovementNode entityView)
{
_playerExists = true;
RaycastStructureCheck(entityView.ID.entityID).RunOnScheduler(StandardSchedulers.physicScheduler);
}

protected override void Remove(CharacterMovementNode entityView)
{
_playerExists = false;
}

public IEnumerator RaycastStructureCheck(int playerId)
{
while (_playerExists)
{
CharacterMovementNode cmn;
while (entitiesDB.TryQueryEntityView(playerId, DEPRECATED_SveltoExtensions.DEPRECATED_GROUP, out cmn))
{
Vector3 position = cmn.characterMovementComponent.characterController.transform.position;
CharacterController cc = cmn.characterMovementComponent.characterController;
RaycastHit rayInfo;
bool didHit = Physics.SphereCast(
position, //+ Vector3.up * (cc.height * 0.5f), // center of player
cc.radius,
Vector3.up,
out rayInfo,
cc.height, //* 0.5f - cc.radius * 0.05f,
_layer);
if (didHit && rayInfo.transform != null)
{
if (rayInfo.transform.CompareTag(GameTags.STRUCTURE_TAG))
{
#if DEBUG
API.Utility.Logging.MetaLog("Structure is above me!");
#endif
VFCOlUtility_Move_Patch.Override = true;
}
}
else
{
#if DEBUG
API.Utility.Logging.MetaLog("No structure above :(");
#endif
VFCOlUtility_Move_Patch.Override = false;
}
yield return null;
}

yield return null;
}
}
}
}

Loading…
Cancel
Save