summaryrefslogtreecommitdiff
path: root/src/SMAPI/Mod.cs
blob: 1a5f559487a822072c82ba0a97ffda3db9920f01 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;

namespace StardewModdingAPI
{
    /// <summary>The base class for a mod.</summary>
    public abstract class Mod : IMod, IDisposable
    {
        /*********
        ** Accessors
        *********/
        /// <inheritdoc />
        public IModHelper Helper { get; internal set; } = null!;

        /// <inheritdoc />
        public IMonitor Monitor { get; internal set; } = null!;

        /// <inheritdoc />
        public IManifest ModManifest { get; internal set; } = null!;


        /*********
        ** Public methods
        *********/
        /// <inheritdoc />
        public abstract void Entry(IModHelper helper);

        /// <inheritdoc />
        public virtual object? GetApi()
        {
            return null;
        }

        /// <inheritdoc />
        public virtual object? GetApi(IManifest manifest)
        {
            return null;
        }

        /// <summary>Release or reset unmanaged resources.</summary>
        public void Dispose()
        {
            (this.Helper as IDisposable)?.Dispose(); // deliberately do this outside overridable dispose method so mods don't accidentally suppress it
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }


        /*********
        ** Private methods
        *********/
        /// <summary>Release or reset unmanaged resources when the game exits. There's no guarantee this will be called on every exit.</summary>
        /// <param name="disposing">Whether the instance is being disposed explicitly rather than finalized. If this is false, the instance shouldn't dispose other objects since they may already be finalized.</param>
        protected virtual void Dispose(bool disposing) { }

        /// <summary>Destruct the instance.</summary>
        ~Mod()
        {
            (this.Helper as IDisposable)?.Dispose(); // deliberately do this outside overridable dispose method so mods don't accidentally suppress it
            this.Dispose(false);
        }
    }
}