-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
172 lines (147 loc) · 7.58 KB
/
Plugin.cs
File metadata and controls
172 lines (147 loc) · 7.58 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
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
// General Roleplay Plugin
// Copyright (C) 2025 Site-12, VisLuke, SticksDeveloper
// Copyright (C) 2026 Site-27, z5tm
//
// This file is part of General Roleplay Plugin.
//
// General Roleplay Plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// General Roleplay Plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Foobar. If not, see <https://www.gnu.org/licenses/>.
//
namespace GRPP;
using System;
using System.Linq;
using System.Net;
using System.Reflection;
using API.Attributes;
using Exiled.API.Enums;
using Exiled.API.Features;
using HarmonyLib;
using ProjectMER.Events.Arguments;
using UnityEngine;
using Log = Exiled.API.Features.Log;
public sealed class Plugin : Plugin<Config>
{
static Plugin()
{
Harmony = new Harmony("com.grpp.main");
Harmony.PatchAll();
/*AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => // subscribe to AssemblyResolve get notified when shit fails, args contains name that tried to load but failed - sender due to convention - we also use a lambda operator, which is cool - basically tells the code that this is the function to call after this event fires, and here - take these two args :sunglasses:
{
if (args.Name.StartsWith("System.ComponentModel.DataAnnotations")) // if the args provided by assemblyresolve's broken shi ~= dataannotations, continue - we use startswith because the actual output has too much shit going on
{
var name = new AssemblyName("System.ComponentModel.DataAnnotations") // easier on the eyes. we could totally just put it right into the definedynamicassembly
{
Version = new Version(4, 0, 0, 0) // set that version to 4.0.0.0
};
return AppDomain.CurrentDomain.DefineDynamicAssembly( // Create a empty assembly, in memory (hence AssemblyBuilderAccess.Run), with said identity, faking having the DLL :sunglasses:
name,
System.Reflection.Emit.AssemblyBuilderAccess.Run // this allows us to create assemblies at runtime, in memory, to disk, etc! RunAndSave = run + save to disk, Save = make, write to file
);
}
return null; // If we can't handle it, we say so - null basically tells AssemblyResolve that we do not know how to handle this error and to move on. This also applies to non-DataAnnotations breaks.
};*/// I did NOT just spend like 5 hours on this just for it to be an upstream issue. FUCKKKKKKKK
}
public override string Name => "grpp"; // General Roleplay Plugin
public override string Author => "Site-27 & 12 Development Team"; // Thank you Stick and VisLuke
public override Version Version => new(1, 3, 0); // Reset to v1 due to name change
public static Plugin Singleton = null!;
public static Harmony Harmony;
private bool _wasEverEnabled;
public override void OnEnabled()
{
base.OnEnabled();
if (_wasEverEnabled)
return;
Singleton = this;
_wasEverEnabled = true;
Log.Info($"GRPP enabled.");
ProjectMER.Events.Handlers.Schematic.SchematicSpawned += SpawningSchematic;
if (Singleton.Config.Debug)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;
// new GRPPMenu().Activate();
Log.Debug("Debug mode is enabled. Not enabling SSS as it's currently broken, and enabling TLS 2 + 3 for webhook sending.");
}
ListResourceNames();
InvokeOnEnabledAttributes();
// new WebServer([$"http://*:{Server.Port}/"]).Start(); // Runs on your automatically port forwarded IP
// https://discord\.com/api/webhooks/[0-9]+/$
}
public override void OnDisabled()
{
// base.OnDisabled();
// if ()
// {
//
// }
}
// need to find out how to make that thing above stop the webserver - a bit out of me but i shall figure it out soon
private static void SpawningSchematic(SchematicSpawnedEventArgs ev)
{
foreach (var gameObject in ev.Schematic.AttachedBlocks)
{
GameObject? resultObj;
var objPos = gameObject.transform.position;
var objRot = gameObject.transform.rotation;
resultObj = gameObject.name switch
{
"HCZDoor" => PrefabHelper.Spawn(PrefabType.HCZBreakableDoor, objPos, objRot),
"EZDoor" => PrefabHelper.Spawn(PrefabType.EZBreakableDoor, objPos, objRot),
"LCZDoor" => PrefabHelper.Spawn(PrefabType.LCZBreakableDoor, objPos, objRot),
"BreachDoor" => PrefabHelper.Spawn(PrefabType.HCZBulkDoor, objPos, objRot),
"Clutter_1" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Clutter_A, objPos, objRot),
"Clutter_2" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Clutter_B, objPos, objRot),
"Clutter_3" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Clutter_C, objPos, objRot),
"Clutter_4" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Clutter_D, objPos, objRot),
"Clutter_5" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Clutter_E, objPos, objRot),
"Clutter_6" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Clutter_F, objPos, objRot),
"Clutter_7" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Clutter_G, objPos, objRot),
"Clutter_8" => PrefabHelper.Spawn(PrefabType.HCZOpenHallway_Construct_A, objPos, objRot),
_ => null
};
if (!resultObj) continue;
resultObj.transform.localScale = gameObject.transform.localScale;
resultObj.transform.parent = ev.Schematic.transform;
}
}
/// <summary>
/// Lists all resource names within this assembly to the server console.
/// </summary>
private void ListResourceNames()
{
foreach (var resourceName in typeof(Plugin).Assembly.GetManifestResourceNames())
Log.Info($"RESOURCE: '{resourceName}'");
}
/// <summary>
/// Invokes all static void methods within the assembly which have the <see cref="OnPluginEnabledAttribute"/> attribute.
/// </summary>
private void InvokeOnEnabledAttributes()
{
foreach (var method in AccessTools.GetTypesFromAssembly(Assembly).SelectMany(AccessTools.GetDeclaredMethods))
{
if (method.GetCustomAttribute<OnPluginEnabledAttribute>() is null)
continue;
if (!method.IsStatic)
{
Log.Warn($"Failed to invoke method {method.DeclaringType}::{method.Name} on plugin enabled, as it is not static.");
continue;
}
if (method.GetParameters().Length != 0)
{
Log.Warn($"Failed to invoke method {method.DeclaringType}::{method.Name} on plugin enabled, as it contains parameters.");
continue;
}
try
{
method.Invoke(null, null);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
}