Skip to content
This repository was archived by the owner on Oct 2, 2021. It is now read-only.

Commit eb06a47

Browse files
authored
New functionality
1 parent 4d5c45f commit eb06a47

File tree

7 files changed

+270
-7
lines changed

7 files changed

+270
-7
lines changed

SCP Speech/EventHandlers.cs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using Smod2;
2+
using Smod2.Events;
3+
using Smod2.EventHandlers;
4+
using System.Collections.Generic;
5+
using UnityEngine;
6+
using MEC;
7+
using System.Reflection;
8+
using System;
9+
10+
namespace SCP_Speech
11+
{
12+
public class EventHandlers : IEventHandlerWaitingForPlayers, IEventHandlerRoundStart
13+
{
14+
private readonly Plugin plugin;
15+
private static Transform intercomeArea = null;
16+
private static readonly Dictionary<GameObject, ReferenceHub> _hubs = new Dictionary<GameObject, ReferenceHub>();
17+
public List<CoroutineHandle> Coroutines = new List<CoroutineHandle>();
18+
19+
public EventHandlers(Plugin plugin)
20+
{
21+
this.plugin = plugin;
22+
}
23+
24+
public void OnWaitingForPlayers(WaitingForPlayersEvent ev)
25+
{
26+
if (plugin.GetConfigBool("sp_disabled"))
27+
{
28+
plugin.PluginManager.DisablePlugin(plugin);
29+
}
30+
}
31+
32+
public void OnRoundStart(RoundStartEvent ev)
33+
{
34+
Coroutines.Add(Timing.RunCoroutine(CheckFor939Intercom()));
35+
intercomeArea = null;
36+
}
37+
38+
public static List<ReferenceHub> GetHubs()
39+
{
40+
List<ReferenceHub> hubs = new List<ReferenceHub>();
41+
foreach (GameObject obj in PlayerManager.players)
42+
if (_hubs.ContainsKey(obj))
43+
hubs.Add(_hubs[obj]);
44+
else
45+
{
46+
ReferenceHub rh = ReferenceHub.GetHub(obj);
47+
_hubs.Add(obj, rh);
48+
hubs.Add(rh);
49+
}
50+
51+
return hubs;
52+
}
53+
54+
public static Transform IntercomArea
55+
{
56+
get
57+
{
58+
if (intercomeArea == null)
59+
intercomeArea = typeof(Intercom).GetField("area", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(Intercom.host) as Transform;
60+
61+
if (intercomeArea == null)
62+
throw new MissingFieldException("Field for intercom not found.");
63+
return intercomeArea;
64+
}
65+
}
66+
67+
public IEnumerator<float> CheckFor939Intercom()
68+
{
69+
while (true)
70+
{
71+
yield return Timing.WaitForSeconds(0.1f);
72+
73+
if (Intercom.host.speaker != null || Intercom.host.speaking)
74+
continue;
75+
76+
foreach (ReferenceHub rh in GetHubs())
77+
{
78+
try
79+
{
80+
if (!rh.characterClassManager.CurClass.Is939())
81+
continue;
82+
83+
GameObject player = rh.gameObject;
84+
Intercom intercom = player.GetComponent<Intercom>();
85+
Scp939PlayerScript script = player.GetComponent<Scp939PlayerScript>();
86+
87+
if (Vector3.Distance(player.transform.position, IntercomArea.position) > intercom.triggerDistance)
88+
continue;
89+
90+
if (!script.NetworkusingHumanChat)
91+
continue;
92+
93+
Intercom.host.RequestTransmission(player);
94+
}
95+
catch (Exception e)
96+
{
97+
while (e != null)
98+
{
99+
plugin.Error(e.ToString());
100+
e = e.InnerException;
101+
}
102+
}
103+
}
104+
}
105+
}
106+
}
107+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Assets._Scripts.Dissonance;
2+
using HarmonyLib;
3+
4+
namespace SCP_Speech
5+
{
6+
[HarmonyPatch(typeof(DissonanceUserSetup), nameof(DissonanceUserSetup.CallCmdAltIsActive))]
7+
public class Scp049Speak
8+
{
9+
public static bool Prefix(DissonanceUserSetup __instance, bool value)
10+
{
11+
CharacterClassManager ccm = __instance.gameObject.GetComponent<CharacterClassManager>();
12+
13+
if (ccm.CurClass == RoleType.Scp049 || ccm.CurClass.Is939())
14+
__instance.MimicAs939 = value;
15+
16+
return true;
17+
}
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using HarmonyLib;
3+
using UnityEngine;
4+
5+
namespace SCP_Speech
6+
{
7+
[HarmonyPatch(typeof(Intercom), "ServerAllowToSpeak")]
8+
[HarmonyPatch(new Type[] { })]
9+
public class ServerAllowSpeakOverride
10+
{
11+
public static void Postfix(Intercom __instance, ref bool __result)
12+
{
13+
CharacterClassManager ccm = __instance.GetComponent<CharacterClassManager>();
14+
15+
if (!ccm.CurClass.Is939())
16+
return;
17+
18+
__result = Vector3.Distance(__instance.transform.position, ccm.transform.position) < __instance.triggerDistance;
19+
}
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using HarmonyLib;
2+
using UnityEngine;
3+
4+
namespace SCP_Speech
5+
{
6+
[HarmonyPatch(typeof(Intercom), "RequestTransmission")]
7+
[HarmonyPatch(new[] { typeof(GameObject) })]
8+
public class RequestTransmissionOverride
9+
{
10+
public static bool Prefix(Intercom __instance, GameObject spk)
11+
{
12+
if (spk != null)
13+
return true;
14+
15+
if (Intercom.host.speaker == null)
16+
return true;
17+
18+
CharacterClassManager ccm = Intercom.host.speaker.GetComponent<CharacterClassManager>();
19+
if (!ccm.CurClass.Is939())
20+
return true;
21+
Scp939PlayerScript script = Intercom.host.speaker.GetComponent<Scp939PlayerScript>();
22+
23+
if (!script.NetworkusingHumanChat)
24+
__instance.Networkspeaker = null;
25+
return false;
26+
}
27+
}
28+
}

SCP Speech/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
8-
[assembly: AssemblyTitle("SCP Speech")]
8+
[assembly: AssemblyTitle("SCPSpeech")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("SCP Speech")]
12+
[assembly: AssemblyProduct("SCPSpeech")]
1313
[assembly: AssemblyCopyright("Copyright © 2020")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]

SCP Speech/SCPSpeech.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Smod2;
1+
using HarmonyLib;
2+
using Smod2;
23
using Smod2.Attributes;
34

45
namespace SCP_Speech
@@ -8,21 +9,32 @@ namespace SCP_Speech
89
name = "SCP Speech",
910
description = "Allow certain SCP to speak with other classes.",
1011
id = "TeMbI4.SCP.Speech",
11-
version = "1.0",
12+
version = "1.1",
1213
SmodMajor = 3,
1314
SmodMinor = 8,
1415
SmodRevision = 4
1516
)]
1617
public class SCPSpeech : Plugin
1718
{
1819
public static SCPSpeech plugin;
20+
public Harmony Instance;
1921

20-
public override void OnEnable() { this.Info("SCP Speech has loaded :D"); }
21-
public override void OnDisable() { this.Info("SCP Speech has been unloaded"); }
22+
public override void OnEnable()
23+
{
24+
Instance = new Harmony("TeMbI4");
25+
Instance.PatchAll();
26+
this.Info("SCP Speech has loaded :D");
27+
}
28+
29+
public override void OnDisable()
30+
{
31+
Instance.UnpatchAll();
32+
this.Info("SCP Speech has been unloaded");
33+
}
2234

2335
public override void Register()
2436
{
25-
this.AddEventHandlers(new EventHandler(this));
37+
this.AddEventHandlers(new EventHandlers(this));
2638

2739
this.AddConfig(new Smod2.Config.ConfigSetting("sp_disabled", false, true, "Is plugin enabled?"));
2840
}

SCP Speech/SCPSpeech.csproj

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{3F58D94A-0EB7-4316-9CD2-3A55AA8800AC}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>SCPSpeech</RootNamespace>
11+
<AssemblyName>SCPSpeech</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>..\..\Plugin Release\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="0Harmony">
36+
<HintPath>..\..\References\0Harmony.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Assembly-CSharp">
39+
<HintPath>..\..\References\Assembly-CSharp.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
42+
<SpecificVersion>False</SpecificVersion>
43+
<HintPath>..\..\References\Assembly-CSharp-firstpass.dll</HintPath>
44+
</Reference>
45+
<Reference Include="Mirror">
46+
<HintPath>..\..\References\Mirror.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Smod2">
49+
<HintPath>..\..\References\Smod2.dll</HintPath>
50+
</Reference>
51+
<Reference Include="System" />
52+
<Reference Include="System.Core" />
53+
<Reference Include="System.Xml.Linq" />
54+
<Reference Include="System.Data.DataSetExtensions" />
55+
<Reference Include="Microsoft.CSharp" />
56+
<Reference Include="System.Data" />
57+
<Reference Include="System.Net.Http" />
58+
<Reference Include="System.Xml" />
59+
<Reference Include="UnityEngine">
60+
<HintPath>..\..\References\UnityEngine.dll</HintPath>
61+
</Reference>
62+
<Reference Include="UnityEngine.CoreModule">
63+
<HintPath>..\..\References\UnityEngine.CoreModule.dll</HintPath>
64+
</Reference>
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Compile Include="Patches\Scp939SpeakOverride.cs" />
68+
<Compile Include="Patches\Scp049SpeechPatch.cs" />
69+
<Compile Include="Patches\Scp939TransmissionOverride.cs" />
70+
<Compile Include="SCPSpeech.cs" />
71+
<Compile Include="EventHandlers.cs" />
72+
<Compile Include="Properties\AssemblyInfo.cs" />
73+
</ItemGroup>
74+
<ItemGroup />
75+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
76+
</Project>

0 commit comments

Comments
 (0)