-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathBaseOpenModRustHost.cs
More file actions
101 lines (81 loc) · 2.41 KB
/
Copy pathBaseOpenModRustHost.cs
File metadata and controls
101 lines (81 loc) · 2.41 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using System.Threading.Tasks;
using Autofac;
using Cysharp.Threading.Tasks;
using OpenMod.API;
using OpenMod.API.Persistence;
using OpenMod.Extensions.Games.Abstractions;
using Rust;
namespace OpenMod.Rust
{
public abstract class BaseOpenModRustHost : IOpenModHost, IDisposable
{
private readonly IRuntime m_Runtime;
public string OpenModComponentId { get; } = "OpenMod.Rust";
public string WorkingDirectory { get; }
public bool IsComponentAlive { get; private set; }
public ILifetimeScope LifetimeScope { get; }
public IDataStore DataStore { get; }
private bool m_IsDisposing;
protected BaseOpenModRustHost(
ILifetimeScope lifetimeScope,
IRuntime runtime,
IDataStoreFactory dataStoreFactory
)
{
m_Runtime = runtime;
LifetimeScope = lifetimeScope;
WorkingDirectory = runtime.WorkingDirectory;
DataStore = dataStoreFactory.CreateDataStore(new DataStoreCreationParameters
{
Component = this,
Prefix = "openmod.rust",
Suffix = null,
WorkingDirectory = WorkingDirectory
});
}
public Task InitAsync()
{
IsComponentAlive = true;
return OnInitAsync();
}
protected abstract Task OnInitAsync();
public Task ShutdownAsync()
{
async UniTask ShutdownTask()
{
await UniTask.SwitchToMainThread();
Application.Quit();
}
return ShutdownTask().AsTask();
}
public bool HasCapability(string capability)
{
if (capability == KnownGameCapabilities.Inventory)
{
return true;
}
if (capability == KnownGameCapabilities.Health)
{
return true;
}
return false;
}
public Task PerformHardReloadAsync()
{
// todo
return m_Runtime.PerformSoftReloadAsync();
}
public void Dispose()
{
if (m_IsDisposing)
{
return;
}
OnDispose();
m_IsDisposing = true;
IsComponentAlive = false;
}
protected abstract void OnDispose();
}
}