Skip to content

Commit

Permalink
Simple settings and spawn fixes I think
Browse files Browse the repository at this point in the history
  • Loading branch information
adamd3v committed Nov 18, 2023
1 parent 0ea4b12 commit 8b580f0
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 22 deletions.
4 changes: 4 additions & 0 deletions DOOMLAB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -58,6 +61,7 @@
<Compile Include="src\Entities\MobjProxy.cs" />
<Compile Include="src\Entities\MobjGun.cs" />
<Compile Include="src\Entities\MobjInteraction.cs" />
<Compile Include="src\Patches\AttackPatch.cs" />
<Compile Include="src\Patches\DamagePatches.cs" />
<Compile Include="src\Patches\GunPatches.cs" />
<Compile Include="src\Patches\SpawnPatches.cs" />
Expand Down
Binary file modified Resources/doomlab_pcvr.pack
Binary file not shown.
4 changes: 2 additions & 2 deletions src/BuildInfo.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NEP.DOOMLAB
{
static partial class BuildInfo
{
public const int Epoch = 1697904181;
public const string GitCommit = "a5bba7b30f40cb9046e7c684976a479b5dbbc613";
public const int Epoch = 1700279253;
public const string GitCommit = "ed056811e315911ab1b79dfd78dc91bb170c082c";
}
}
11 changes: 11 additions & 0 deletions src/DoomGame.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using MelonLoader;
using NEP.DOOMLAB.Data;
using NEP.DOOMLAB.Entities;
using UnityEngine;

namespace NEP.DOOMLAB.Game
Expand Down Expand Up @@ -87,6 +88,16 @@ public DoomGame()

private float ticTimer;

public static void DeleteCorpses()
{
var corpses = MobjManager.Instance.mobjs.FindAll((mobj) => mobj.flags.HasFlag(MobjFlags.MF_CORPSE));

foreach(var corpse in corpses)
{
MobjManager.Instance.RemoveMobj(corpse);
}
}

public void Update()
{
try
Expand Down
6 changes: 3 additions & 3 deletions src/Entities/Mobj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ public enum MoveDirection

private void Awake()
{
info = Info.MobjInfos[(int)type];
playerHealth = BoneLib.Player.rigManager.GetComponent<Player_Health>();

if(ComponentCache == null)
{
ComponentCache = new Instances<Mobj>();
Expand All @@ -98,6 +95,9 @@ private void Awake()

private void Start()
{
info = Info.MobjInfos[(int)type];
playerHealth = BoneLib.Player.rigManager.GetComponent<Player_Health>();

player.health = player.playerHealth.curr_Health;
DoomGame.Instance.OnTick += WorldTick;
}
Expand Down
13 changes: 6 additions & 7 deletions src/Entities/MobjManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ public Mobj SpawnMobj(Vector3 position, MobjType type, float angle = 0f)
GameObject mobjBase = GameObject.Instantiate(mobjPrefab, position, Quaternion.AngleAxis(angle, Vector3.up));
Mobj mobj = mobjBase.GetComponent<Mobj>();
mobj.brain = mobjBase.GetComponent<MobjBrain>();

if(mobj.flags.HasFlag(MobjFlags.MF_SHOOTABLE) || mobj.flags.HasFlag(MobjFlags.MF_COUNTKILL))
{
var trpSphere = mobjBase.transform.GetChild(0).gameObject;
trpSphere.AddComponent<MobjProxy>();
}

mobj.rigidbody = mobjBase.GetComponent<Rigidbody>();
mobj.collider = mobjBase.GetComponent<BoxCollider>();
mobj.audioSource = mobjBase.GetComponent<AudioSource>();
Expand All @@ -61,6 +54,12 @@ public Mobj SpawnMobj(Vector3 position, MobjType type, float angle = 0f)
mobj.collider.center = Vector3.up * (mobj.height / 32f) / 2f;
mobj.collider.size = new Vector3(mobj.radius / 32f, mobj.height / 32f, mobj.radius / 32f);

if(mobj.flags.HasFlag(MobjFlags.MF_SHOOTABLE) || mobj.flags.HasFlag(MobjFlags.MF_COUNTKILL))
{
var trpSphere = mobjBase.transform.GetChild(0).gameObject;
trpSphere.transform.localPosition = Vector3.up * mobj.height / 32f;
}

ImpactProperties impactProperties = mobjBase.GetComponent<ImpactProperties>();
impactProperties.surfaceData = Main.mobjSurfaceData;

Expand Down
4 changes: 3 additions & 1 deletion src/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using SLZ.Data;
using SLZ.Combat;
using SLZ.Marrow.Warehouse;
using NEP.DOOMLAB.Patches;

namespace NEP.DOOMLAB
{
Expand Down Expand Up @@ -120,7 +121,7 @@ internal void BoneMenuStuff()
MenuCategory menuCategory = MenuManager.CreateCategory("Not Enough Photons", Color.white);
var doomCategory = menuCategory.CreateCategory("DOOMLAB", Color.white);

var gameFlagsCategory = doomCategory.CreateCategory("Game Flags", Color.white);
var gameFlagsCategory = doomCategory.CreateCategory("Game Settings", Color.white);
var debugCategory = doomCategory.CreateCategory("Debug", Color.white);

gameFlagsCategory.CreateBoolElement("Disable Thinking", Color.white, false, (value) => Settings.DisableAI = value);
Expand All @@ -131,6 +132,7 @@ internal void BoneMenuStuff()
DoomGame.Instance.UpdateFastMonsters(Settings.FastMonsters);
});
gameFlagsCategory.CreateBoolElement("Respawn Monsters", Color.white, false, (value) => Settings.RespawnMonsters = value);
gameFlagsCategory.CreateFunctionElement("Clear Corpses", Color.red, () => DoomGame.DeleteCorpses());

debugCategory.CreateFloatElement("Projectile Pruning Distance", Color.white, 128f, 32f, 0f, 4096f, (value) => Settings.ProjectilePruneDistance = value);
debugCategory.CreateBoolElement("MOBJ Debug Stats", Color.white, false, (value) => Settings.EnableMobjDebug = value);
Expand Down
91 changes: 91 additions & 0 deletions src/Patches/AttackPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Reflection;
using System.Runtime.InteropServices;

using UnityEngine;

using MelonLoader;

using SLZ.AI;
using SLZ.Combat;
using SLZ.Marrow.Data;

namespace NEP.DOOMLAB.Patches
{
internal static class AttackPatch
{

public static Action<Attack> OnAttackReceived;

private static AttackPatchDelegate _original;
private delegate void AttackPatchDelegate(IntPtr instance, IntPtr attack, IntPtr method);

public static unsafe void Patch()
{
AttackPatchDelegate patch = Patch;

string nativeInfoName = "NativeMethodInfoPtr_ReceiveAttack_Public_Virtual_Final_New_Void_Attack_0";
var tgtPtr = *(IntPtr*)(IntPtr)typeof(ImpactProperties).GetField(nativeInfoName, BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
var dstPtr = patch.Method.MethodHandle.GetFunctionPointer();

MelonUtils.NativeHookAttach((IntPtr)(&tgtPtr), dstPtr);
_original = Marshal.GetDelegateForFunctionPointer<AttackPatchDelegate>(tgtPtr);
}

public static void Patch(IntPtr instance, IntPtr attack, IntPtr method)
{
_original(instance, attack, method);

unsafe
{
try
{
Attack_ refAttack = *(Attack_*)attack;

Attack _attack = new Attack()
{
damage = refAttack.damage,
normal = refAttack.normal,
origin = refAttack.origin,
backFacing = refAttack.backFacing == 1 ? true : false,
OrderInPool = refAttack.OrderInPool,
collider = refAttack.Collider,
attackType = refAttack.attackType,
proxy = refAttack.Proxy
};

OnAttackReceived?.Invoke(_attack);
}
catch
{

}
}
}

[StructLayout(LayoutKind.Sequential)]
public struct Attack_
{
public float damage;
public Vector3 normal;
public Vector3 origin;
public byte backFacing;
public int OrderInPool;
public IntPtr collider;
public AttackType attackType;
public IntPtr proxy;

public Collider Collider
{
get => new Collider(collider);
set => collider = value.Pointer;
}

public TriggerRefProxy Proxy
{
get => new TriggerRefProxy(proxy);
set => proxy = value.Pointer;
}
}
}
}
11 changes: 2 additions & 9 deletions src/Patches/NPCPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@

using MelonLoader;
using PuppetMasta;
using UnityEngine;

namespace NEP.DOOMLAB.Patches
{
[HarmonyLib.HarmonyPatch(typeof(SubBehaviourSensors))]
[HarmonyLib.HarmonyPatch(nameof(SubBehaviourSensors.AddThreat))]
public static class BehaviourBaseNavPatches4
{
public static void Postfix(TriggerRefProxy trp, float threat)
{
MelonLoader.MelonLogger.Msg("Add threat: " + trp.name + " Threat: " + threat);
}
}

}

0 comments on commit 8b580f0

Please sign in to comment.