Skip to content

Commit 3f1af65

Browse files
committed
v1.0 (BepInEx)
There was actually nothing here but a template until now so uuh...here's the mod!
1 parent 4bcb91d commit 3f1af65

File tree

14 files changed

+517
-77
lines changed

14 files changed

+517
-77
lines changed

.env

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/auto-deploy.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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>{ABECAEA3-A747-4065-B6B0-F25A870E0E58}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>CustomDeathMessages</RootNamespace>
11+
<AssemblyName>CustomDeathMessages</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
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>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Distance\BepInEx\core\0Harmony.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Assembly-CSharp">
39+
<HintPath>..\..\publicized_assemblies\Assembly-CSharp.dll</HintPath>
40+
</Reference>
41+
<Reference Include="BepInEx">
42+
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Distance\BepInEx\core\BepInEx.dll</HintPath>
43+
</Reference>
44+
<Reference Include="JsonFx, Version=2.0.1209.2802, Culture=neutral, PublicKeyToken=315052dd637f8a52, processorArchitecture=MSIL">
45+
<HintPath>..\packages\JsonFx.2.0.1209.2802\lib\net35\JsonFx.dll</HintPath>
46+
</Reference>
47+
<Reference Include="System" />
48+
<Reference Include="System.Core" />
49+
<Reference Include="System.Xml.Linq" />
50+
<Reference Include="System.Data.DataSetExtensions" />
51+
<Reference Include="System.Data" />
52+
<Reference Include="System.Xml" />
53+
<Reference Include="UnityEngine">
54+
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Distance\Distance_Data\Managed\UnityEngine.dll</HintPath>
55+
</Reference>
56+
</ItemGroup>
57+
<ItemGroup>
58+
<Compile Include="Extensions\Assembly-CSharp\ClientPlayerInfo.cs" />
59+
<Compile Include="Messages.cs" />
60+
<Compile Include="MessageType.cs" />
61+
<Compile Include="Patches\Assembly-CSharp\ClientLogic\OnEventPlayerActionMessage.cs" />
62+
<Compile Include="Patches\Assembly-CSharp\ClientLogic\OnEventToAllClientsRemotePlayerActionMessage.cs" />
63+
<Compile Include="Plugin.cs" />
64+
<Compile Include="Properties\AssemblyInfo.cs" />
65+
</ItemGroup>
66+
<ItemGroup />
67+
<ItemGroup>
68+
<None Include="packages.config" />
69+
</ItemGroup>
70+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
71+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma warning disable RCS1110
2+
public static class ClientPlayerInfoExtensions
3+
{
4+
public static string GetChatName(this ClientPlayerInfo playerInfo, bool closeColorTag)
5+
{
6+
return ClientPlayerInfo.GetColorPrefix(playerInfo.index_) + playerInfo.username_ + (closeColorTag ? "[-]" : string.Empty);
7+
}
8+
}

CustomDeathMessages/MessageType.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace CustomDeathMessages
4+
{
5+
[Flags]
6+
public enum MessageType : uint
7+
{
8+
None,
9+
KillGrid,
10+
SelfTermination,
11+
LaserOverheated,
12+
Impact,
13+
Overheated,
14+
AntiTunnelSquish,
15+
StuntCollect,
16+
KickNoLevel,
17+
Finished,
18+
NotReady,
19+
Spectate,
20+
TagPointsLead
21+
}
22+
}

CustomDeathMessages/Messages.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using Events.ClientToAllClients;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace CustomDeathMessages
6+
{
7+
public static class Message
8+
{
9+
internal const string ResetFormatting = "[-][-][-][-][-]";
10+
11+
internal static readonly List<KeyValuePair<string, MessageType>> MessageDictionary = new List<KeyValuePair<string, MessageType>>()
12+
{
13+
new KeyValuePair<string, MessageType>("was terminated by the laser grid", MessageType.KillGrid ),
14+
new KeyValuePair<string, MessageType>("reset", MessageType.SelfTermination ),
15+
new KeyValuePair<string, MessageType>("was wrecked after getting split", MessageType.LaserOverheated ),
16+
new KeyValuePair<string, MessageType>("got wrecked?", MessageType.AntiTunnelSquish ),
17+
new KeyValuePair<string, MessageType>("got wrecked", MessageType.Impact ),
18+
new KeyValuePair<string, MessageType>("exploded from overheating", MessageType.Overheated ),
19+
new KeyValuePair<string, MessageType>("multiplier!", MessageType.KillGrid ),
20+
new KeyValuePair<string, MessageType>("was kicked due to not having this level", MessageType.KickNoLevel ),
21+
new KeyValuePair<string, MessageType>("finished", MessageType.Finished ),
22+
new KeyValuePair<string, MessageType>("is not ready", MessageType.NotReady ),
23+
new KeyValuePair<string, MessageType>("left the match to spectate", MessageType.Spectate ),
24+
new KeyValuePair<string, MessageType>("has taken the lead!", MessageType.TagPointsLead )
25+
};
26+
27+
public static MessageType GetMessageType(string message)
28+
{
29+
foreach (var element in MessageDictionary)
30+
{
31+
if (message.IndexOf(element.Key, System.StringComparison.InvariantCultureIgnoreCase) >= 0)
32+
{
33+
return element.Value;
34+
}
35+
}
36+
37+
return MessageType.None;
38+
}
39+
40+
public static int GetStuntMultiplier(string message)
41+
{
42+
int.TryParse(message.Substring(14), out int result);
43+
return result;
44+
}
45+
46+
public static string GetMessage(string message, string username, string formattedName)
47+
{
48+
MessageType type = GetMessageType(message);
49+
50+
int stuntMultiplier = 0;
51+
52+
if (type == MessageType.StuntCollect)
53+
{
54+
stuntMultiplier = GetStuntMultiplier(message);
55+
}
56+
57+
Mod.Instance.MessagesDictionary.TryGetValue(type.ToString(), out string[] customMessages);
58+
59+
if (type == MessageType.None || customMessages.IsNullOrEmpty())
60+
{
61+
return $"{username} {message}";
62+
}
63+
64+
return string.Format(customMessages.RandomElement(), formattedName, stuntMultiplier, username).Colorize(Colors.tan);
65+
}
66+
67+
public static void Send(string message)
68+
{
69+
ChatMessage.Broadcast(new ChatMessage.Data(message));
70+
}
71+
}
72+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Events.Local;
2+
using HarmonyLib;
3+
4+
namespace CustomDeathMessages.Patches
5+
{
6+
[HarmonyPatch(typeof(ClientLogic), "OnEventPlayerActionMessage")]
7+
internal static class ClientLogic__OnEventPlayerActionMessage
8+
{
9+
[HarmonyPrefix]
10+
internal static bool Prefix(ClientLogic __instance, PlayerActionMessage.Data data)
11+
{
12+
string message = data.message_;
13+
string username = __instance.GetLocalPlayerInfo().username_;
14+
string formattedName = __instance.GetLocalPlayerInfo().GetChatName(true);
15+
16+
string replacement = Message.GetMessage(message, username, formattedName);
17+
18+
Message.Send(replacement);
19+
20+
return false;
21+
}
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Events.Local;
2+
using HarmonyLib;
3+
4+
namespace CustomDeathMessages.Patches
5+
{
6+
[HarmonyPatch(typeof(ClientLogic), "OnEventToAllClientsRemotePlayerActionMessage")]
7+
internal static class ClientLogic__OnEventToAllClientsRemotePlayerActionMessage
8+
{
9+
[HarmonyPrefix]
10+
internal static bool Prefix(ClientLogic __instance, ToAllClientsRemotePlayerActionMessage.Data data)
11+
{
12+
string message = data.message_;
13+
string username = __instance.ClientPlayerList_[data.index_].username_;
14+
string formattedName = __instance.ClientPlayerList_[data.index_].GetChatName(true);
15+
16+
string replacement = Message.GetMessage(message, username, formattedName);
17+
18+
Message.Send(replacement);
19+
20+
return false;
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)