-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
287 lines (216 loc) · 11.5 KB
/
Plugin.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
using BepInEx;
using BepInEx.Logging;
using BepInEx.Configuration;
using HarmonyLib;
using System;
using System.Reflection;
using UnityEngine;
namespace MoreNoise
{
[BepInPlugin("dampfschlaghammer.MoreNoise", Plugin.ModName, Plugin.Version)]
public class Plugin : BaseUnityPlugin
{
private static readonly bool isDebug = true;
public const string Version = "0.1";
public const string ModName = "MoreNoise";
public static ConfigEntry<float> miningNoise;
public static ConfigEntry<float> woodNoise;
public static ConfigEntry<float> noiseMax;
public static ConfigEntry<int> CaptureWidth;
private static float noiseTracker =0f;
private static float noiseTracker_x = 0f;
private static float c_value= 0f;
private static float k_value = 0.000004f;
Harmony _Harmony;
public static ManualLogSource Log;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug)
Debug.Log((pref ? typeof(Plugin).Namespace + " " : "") + str);
}
private void Awake()
{
//miningNoise = Config.AddSetting("General", "miningNoise", 200f, new ConfigDescription("Description", new AcceptableValueRange<float>(100f, 300f)));
//woodNoise = Config.AddSetting("General", "woodNoise", 50f, new ConfigDescription("Description", new AcceptableValueRange<float>(50f, 300f)));
//noiseMax = Config.AddSetting("General", "noiseMax", 100f, new ConfigDescription("Description", new AcceptableValueRange<float>(301f, 500f)));
miningNoise = Config.Bind("General", "miningNoise", 100f, new ConfigDescription("Description", new AcceptableValueRange<float>(100f, 300f)));
woodNoise = Config.Bind("General", "woodNoise", 50f, new ConfigDescription("Description", new AcceptableValueRange<float>(50f, 300f)));
noiseMax = Config.Bind("General", "noiseMax", 400f, new ConfigDescription("Description", new AcceptableValueRange<float>(301f, 500f)));
//woodNoise = Config.Bind<float>("General", "woodNoise", 50f, "Noise multiplier to chopping wood");
//noiseMax = Config.Bind<float>("General", "noiseMax", 371f, "Maximum Noise");
#if DEBUG
Log = Logger;
#else
Log = new ManualLogSource(null);
#endif
_Harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), null);
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
public static class ZNetScene_Awake_Patch
{
public static void Postfix(ZNetScene __instance)
{
//var beehive = __instance.GetPrefab("Beehive");
var Beech = ZNetScene.instance.GetPrefab("Beech_Stub");
var BeechCom = Beech.GetComponent<Destructible>();
//Destructible beehiveCom = beehive.GetComponent<Destructible>();
BeechCom.m_hitNoise = woodNoise.Value;
var Birch = ZNetScene.instance.GetPrefab("BirchStub");
var BirchCom = Birch.GetComponent<Destructible>();
//Destructible beehiveCom = beehive.GetComponent<Destructible>();
BirchCom.m_hitNoise = woodNoise.Value;
var FirTree = ZNetScene.instance.GetPrefab("FirTree_Stub");
var FirTreeCom = FirTree.GetComponent<Destructible>();
//Destructible beehiveCom = beehive.GetComponent<Destructible>();
FirTreeCom.m_hitNoise = woodNoise.Value;
var Oak = ZNetScene.instance.GetPrefab("OakStub");
var OakCom = Oak.GetComponent<Destructible>();
//Destructible beehiveCom = beehive.GetComponent<Destructible>();
OakCom.m_hitNoise = woodNoise.Value;
var Pinetree_01 = ZNetScene.instance.GetPrefab("Pinetree_01_Stub");
var Pinetree_01Com = Pinetree_01.GetComponent<Destructible>();
//Destructible beehiveCom = beehive.GetComponent<Destructible>();
Pinetree_01Com.m_hitNoise = woodNoise.Value;
var SwampTree1 = ZNetScene.instance.GetPrefab("SwampTree1_Stub");
var SwampTree1Com = SwampTree1.GetComponent<Destructible>();
//Destructible beehiveCom = beehive.GetComponent<Destructible>();
SwampTree1Com.m_hitNoise = woodNoise.Value;
}
}
[HarmonyPatch(typeof(MineRock5), "Damage")]
static class MineRock5_Damage_Patch
{
static void Prefix(MineRock5 __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
noiseTracker = closestPlayer.GetNoiseRange();
}
}
static void Postfix(MineRock5 __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
double miningNoise_conv = System.Convert.ToDouble(miningNoise.Value);
double noiseMax_conv = System.Convert.ToDouble(noiseMax.Value);
c_value = (float)Math.Exp((float)k_value * (float)noiseMax.Value * (float)(miningNoise.Value)) * ((float)noiseMax.Value / 100f - 1f);
noiseTracker_x = (float)Math.Max(
-1f*Math.Log((float)noiseMax.Value / ((float)noiseTracker * (float)c_value) - 1 / (float)c_value) / ((float)k_value * (float)noiseMax.Value) + (float)miningNoise_conv
, (float)miningNoise_conv);
noiseTracker = (float)((float)noiseMax_conv / (1 + (float)c_value * Math.Exp((float)(k_value) * (float)(noiseMax_conv) * (float)noiseTracker_x * -1f)));
/*
Dbgl($"Noise was given back as {closestPlayer.m_noiseRange}");
Dbgl($"Noise value was {miningNoise.Value}");
Dbgl($"noiseTracker_x valuex was {noiseTracker_x}");
Dbgl($"c_value was {c_value}");
*/
Dbgl($"Final Noise value was {noiseTracker}");
closestPlayer.m_noiseRange = noiseTracker;
}
}
}
[HarmonyPatch(typeof(MineRock), "Damage")]
static class MineRock_Damage_Patch
{
static void Prefix(MineRock __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
//Dbgl($"Noise was{closestPlayer.GetNoiseRange()}");
noiseTracker = closestPlayer.GetNoiseRange();
}
}
static void Postfix(MineRock __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
double miningNoise_conv = System.Convert.ToDouble(miningNoise.Value);
double noiseMax_conv = System.Convert.ToDouble(noiseMax.Value);
c_value = (float)Math.Exp((float)k_value * (float)noiseMax.Value * (float)(miningNoise.Value)) * ((float)noiseMax.Value / 100f - 1f);
noiseTracker_x = (float)Math.Max(
-1f * Math.Log((float)noiseMax.Value / ((float)noiseTracker * (float)c_value) - 1 / (float)c_value) / ((float)k_value * (float)noiseMax.Value) + (float)miningNoise_conv
, (float)miningNoise_conv);
noiseTracker = (float)((float)noiseMax_conv / (1 + (float)c_value * Math.Exp((float)(k_value) * (float)(noiseMax_conv) * (float)noiseTracker_x * -1f)));
/*
Dbgl($"Noise was given back as {closestPlayer.m_noiseRange}");
Dbgl($"Noise value was {miningNoise.Value}");
Dbgl($"noiseTracker_x value was {noiseTracker_x}");
Dbgl($"c_value was {c_value}");
*/
Dbgl($"Final Noise value was {noiseTracker}");
closestPlayer.m_noiseRange = noiseTracker;
//closestPlayer.m_seman.ModifyNoise(noiseTracker, ref closestPlayer.m_noiseRange);
}
}
}
[HarmonyPatch(typeof(TreeBase), "Damage")]
static class TreeBase_Damage_Patch
{
static void Prefix(TreeBase __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
//Dbgl($"Noise was{closestPlayer.GetNoiseRange()}");
noiseTracker = closestPlayer.GetNoiseRange();
}
}
static void Postfix(TreeBase __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
// closestPlayer.AddNoise(noiseTracker);
//Dbgl($"51Noise was really {noiseMax}");
double woodNoise_conv = System.Convert.ToDouble(woodNoise.Value);
//double noiseMax_conv = System.Convert.ToDouble(noiseMax.Value);
noiseTracker = (float)Math.Max((float)woodNoise_conv, (float)noiseTracker);
/*
Dbgl($"Noise was given back as {closestPlayer.m_noiseRange}");
Dbgl($"Noise value was {woodNoise.Value}");
noiseTracker = miningNoise - noiseMax;
*/
Dbgl($"Final Noise value was {noiseTracker}");
closestPlayer.m_noiseRange = noiseTracker;
}
}
}
[HarmonyPatch(typeof(TreeLog), "Damage")]
static class TreeLog_Damage_Patch
{
static void Prefix(TreeLog __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
Dbgl($"Noise was{closestPlayer.GetNoiseRange()}");
noiseTracker = closestPlayer.GetNoiseRange();
}
}
static void Postfix(TreeLog __instance, ref HitData hit)
{
Player closestPlayer = Player.GetClosestPlayer(hit.m_point, 10f);
if ((bool)closestPlayer)
{
double woodNoise_conv = System.Convert.ToDouble(woodNoise.Value);
noiseTracker = (float)Math.Max((float)woodNoise_conv, (float)noiseTracker);
/*
Dbgl($"Noise was given back as {closestPlayer.m_noiseRange}");
Dbgl($"Noise value was {woodNoise.Value}");
*/
Dbgl($"Final Noise value was {noiseTracker}");
closestPlayer.m_noiseRange = noiseTracker;
}
}
}
private void OnDestroy()
{
if (_Harmony != null
) _Harmony.UnpatchSelf();
}
}
}