-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mod.cs
248 lines (228 loc) · 5.88 KB
/
Mod.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
using Reloaded.Mod.Interfaces;
using nights.test.sandbox.Template;
using nights.test.sandbox.Configuration;
using Reloaded.Hooks.Definitions;
using IReloadedHooks = Reloaded.Hooks.ReloadedII.Interfaces.IReloadedHooks;
using Reloaded.Hooks.Definitions.X86;
using System.Runtime.InteropServices;
using static Reloaded.Hooks.Definitions.X86.FunctionAttribute;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace nights.test.sandbox;
/// <summary>
/// Your mod logic goes here.
/// </summary>
public class Mod : ModBase // <= Do not Remove.
{
/// <summary>
/// Provides access to the mod loader API.
/// </summary>
private readonly IModLoader _modLoader;
/// <summary>
/// Provides access to the Reloaded.Hooks API.
/// </summary>
/// <remarks>This is null if you remove dependency on Reloaded.SharedLib.Hooks in your mod.</remarks>
private readonly IReloadedHooks _hooks;
/// <summary>
/// Provides access to the Reloaded logger.
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// Entry point into the mod, instance that created this class.
/// </summary>
private readonly IMod _owner;
/// <summary>
/// Provides access to this mod's configuration.
/// </summary>
private Config _configuration;
/// <summary>
/// The configuration of the currently executing mod.
/// </summary>
private readonly IModConfig _modConfig;
public Mod(ModContext context) {
_modLoader = context.ModLoader;
_hooks = context.Hooks;
_logger = context.Logger;
_owner = context.Owner;
_configuration = context.Configuration;
_modConfig = context.ModConfig;
unsafe {
_hookSetToDateAndTime = _hooks.CreateHook<setToDateAndTime>(SetToDateAndTime, 0x5554C0).Activate();
}
switch (_configuration.Event) {
case Event.Manual:
_newDateAndTime = new DateAndTime {
year = _configuration.Year,
month = (byte)_configuration.Month,
day = _configuration.Day,
hour = _configuration.Hour,
minute = _configuration.Minute,
second = _configuration.Second
};
break;
case Event.Nothing:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 7,
day = 5,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.SummerClaris:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 7,
day = 20,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.SummerElliot:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 7,
day = 21,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.HalloweenClaris:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 10,
day = 1,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.HalloweenElliot:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 10,
day = 31,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.Winter:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 11,
day = 1,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.ChristmasNoSanta:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 11,
day = 25,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.ChristmasSanta:
_newDateAndTime = new DateAndTime {
year = 1996,
month = 12,
day = 25,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.NewYear:
_newDateAndTime = new DateAndTime {
year = 1997,
month = 1,
day = 1,
hour = 0,
minute = 0,
second = 0
};
break;
case Event.AprilFools:
_newDateAndTime = new DateAndTime {
year = 1997,
month = 4,
day = 1,
hour = 0,
minute = 0,
second = 0
};
break;
}
if (
_configuration.Event != Event.Manual
|| _configuration.DayOfWeek == Configuration.DayOfWeek.Auto
) {
DateTime dateTime = new DateTime(
_configuration.Year, (int)_configuration.Month, _configuration.Day
);
_newDateAndTime.dayOfWeek = (byte)dateTime.DayOfWeek;
} else {
_newDateAndTime.dayOfWeek = (byte)_configuration.DayOfWeek;
}
_replaceAll = _configuration.ReplaceAllCalls;
_log = _configuration.LogAddressOnCall;
}
DateAndTime _newDateAndTime;
bool _replaceAll;
bool _log;
static public IHook<setToDateAndTime> _hookSetToDateAndTime;
public unsafe int SetToDateAndTime(void* dateAndTime) {
if (_replaceAll == false && (int)dateAndTime != 0x24A6270) {
if (_log) {
Console.WriteLine(
"nights.test.customdateandtime: date and time NOT written to 0x"
+ ((int)dateAndTime).ToString("X")
);
}
return _hookSetToDateAndTime.OriginalFunction(dateAndTime);
}
if (_log) {
Console.WriteLine(
"nights.test.customdateandtime: date and time written to 0x"
+ ((int)dateAndTime).ToString("X")
);
}
DateAndTime* dateAndTimeCast = (DateAndTime*)dateAndTime;
*dateAndTimeCast = _newDateAndTime;
return dateAndTimeCast->dayOfWeek;
}
// int __usercall sub_5554C0@<eax>(int a1@<edi>)
[Function(Register.edi, Register.eax, StackCleanup.Caller)]
public unsafe delegate int setToDateAndTime(void* a1);
#region Standard Overrides
public override void ConfigurationUpdated(Config configuration)
{
// Apply settings from configuration.
// ... your code here.
_configuration = configuration;
_logger.WriteLine($"[{_modConfig.ModId}] Config Updated: Applying");
}
#endregion
#region For Exports, Serialization etc.
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public Mod() { }
#pragma warning restore CS8618
#endregion
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct DateAndTime {
public ushort year;
public byte month;
public byte day;
public byte hour;
public byte minute;
public byte second;
public byte dayOfWeek;
}