/
CustomEntity.cs
49 lines (44 loc) · 1.49 KB
/
CustomEntity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Reflection;
using BepInEx;
using Jotunn.Utils;
namespace Jotunn.Entities
{
/// <summary>
/// Base class for all custom entities
/// </summary>
public abstract class CustomEntity
{
/// <summary>
/// Reference to the <see cref="BepInPlugin"/> which added this entity.
/// </summary>
public BepInPlugin SourceMod { get; }
/// <summary>
/// ctor automatically getting the SourceMod
/// </summary>
internal CustomEntity()
{
SourceMod = BepInExUtils.GetSourceModMetadata();
}
/// <summary>
/// ctor with manual assigned SourceMod
/// </summary>
/// <param name="sourceMod">Metadata of the mod adding this entity</param>
internal CustomEntity(BepInPlugin sourceMod)
{
SourceMod = sourceMod;
}
/// <summary>
/// ctor with passed calling assembly.
/// If the calling is no BepInEx plugin or Jotunn itself, the SourceMod will be searched via reflection
/// </summary>
/// <param name="callingAssembly"></param>
internal CustomEntity(Assembly callingAssembly)
{
SourceMod = BepInExUtils.GetPluginInfoFromAssembly(callingAssembly)?.Metadata;
if (SourceMod == null || SourceMod.GUID == Main.Instance.Info.Metadata.GUID)
{
SourceMod = BepInExUtils.GetSourceModMetadata();
}
}
}
}