Skip to content

Commit

Permalink
Removed Bloodstone, Added CrimsonLog +semver: major
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyTech6 committed Dec 4, 2024
1 parent 241c5e7 commit c525fdf
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
`1.0.0`
- Removed Bloodstone Dependency
- Added Optional CrimsonLog Support

`0.1.3`
- Don't filter System messages

Expand Down
10 changes: 7 additions & 3 deletions CrimsonChatFilter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
<Copy SourceFiles="$(OutDir)\CrimsonChatFilter.dll" DestinationFolder="$(SolutionDir)/dist" />
</Target>
<ItemGroup>
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.700" IncludeAssets="compile" />
<PackageReference Include="BepInEx.Core" Version="6.0.0-be.700" IncludeAssets="compile" />
<PackageReference Include="BepInEx.Unity.IL2CPP" Version="6.0.0-be.721" IncludeAssets="compile" />
<PackageReference Include="BepInEx.Core" Version="6.0.0-be.721" IncludeAssets="compile" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" />
<PackageReference Include="VRising.Unhollowed.Client" Version="1.0.5.802790001" />
<PackageReference Include="VRising.Bloodstone" Version="0.2.2" />
</ItemGroup>
<ItemGroup>
<None Include=".github\workflows\build.yml" />
<None Include=".github\workflows\release.yml" />
</ItemGroup>
<ItemGroup>
<Reference Include="CrimsonLog">
<HintPath>..\CrimsonLog\bin\Debug\net6.0\CrimsonLog.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mode: Mainline
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
commit-message-incrementing: Enabled
increment: Major
27 changes: 19 additions & 8 deletions Hooks/ChatHook.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CrimsonChatFilter.Utils;
using CrimsonChatFilter.Structs;
using CrimsonChatFilter.Utils;
using HarmonyLib;
using ProjectM;
using ProjectM.Network;
Expand All @@ -14,8 +15,7 @@ public static class ChatMessageSystem_Patch
[HarmonyPrefix]
public static bool OnUpdate(ChatMessageSystem __instance)
{
if (!Plugin.Settings.GetActiveOption(Structs.Settings.Options.Enable)) return true;
if (Plugin.Settings.GetActiveOption(Structs.Settings.Options.FullRemove)) return true;
if (!Plugin.Settings.GetActiveOption(Settings.Options.Enable)) return true;

if (__instance.__query_661171423_0 != null)
{
Expand All @@ -27,14 +27,25 @@ public static bool OnUpdate(ChatMessageSystem __instance)
var chatEventData = __instance.EntityManager.GetComponentData<ChatMessageEvent>(entity);

var messageText = chatEventData.MessageText.ToString();

if (chatEventData.MessageType == ChatMessageType.System) continue;

messageText = messageText.Filter();

chatEventData.MessageText = messageText;
__instance.EntityManager.SetComponentData(entity, chatEventData);
if (Plugin.Settings.GetActiveOption(Settings.Options.FullRemove) && messageText.ContainsFiltered())
{
Plugin.AddLog($"REMOVED from {userData.CharacterName}: \"{messageText}\"");
__instance.EntityManager.DestroyEntity(entity);
continue;
}
else
{
Plugin.AddLog($"CENSORED from {userData.CharacterName}: \"{messageText}\"");
messageText = messageText.Filter();

chatEventData.MessageText = messageText;
__instance.EntityManager.SetComponentData(entity, chatEventData);
}
}
entities.Dispose();
}

return true;
Expand Down
39 changes: 24 additions & 15 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,54 @@
using BepInEx.Unity.IL2CPP;
using CrimsonChatFilter.Structs;
using HarmonyLib;
using CrimsonChatFilter.Utils;
using BepInEx.Logging;
using Logger = CrimsonLog.Systems.Logger;

Check failure on line 6 in Plugin.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'CrimsonLog' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 6 in Plugin.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'CrimsonLog' could not be found (are you missing a using directive or an assembly reference?)

namespace CrimsonChatFilter;

[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("gg.deca.Bloodstone")]
[Bloodstone.API.Reloadable]
[BepInDependency("CrimsonLog", BepInDependency.DependencyFlags.SoftDependency)]
public class Plugin : BasePlugin
{
Harmony _harmony;
public static Settings Settings { get; private set; }
public static ManualLogSource Logger { get; private set; }
public static ManualLogSource LogInstance { get; private set; }

public static bool LogLoaded = false;

public override void Load()
{
Logger = Log;
LogInstance = Log;
Settings = new(Config);
Settings.InitConfig();
Database.InitFiltered("filtered_words");

// Plugin startup logic
Log.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} version {MyPluginInfo.PLUGIN_VERSION} is loaded!");

// Harmony patching
_harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
_harmony.PatchAll(System.Reflection.Assembly.GetExecutingAssembly());

Bloodstone.Hooks.Chat.OnChatMessage += ((x) =>
foreach (var plugin in IL2CPPChainloader.Instance.Plugins)
{
if (x.Type == ProjectM.Network.ChatMessageType.System) return;
if (!Settings.GetActiveOption(Settings.Options.Enable)) return;
if (!Settings.GetActiveOption(Settings.Options.FullRemove)) return;
if (x.Message.ContainsFiltered())
var metadata = plugin.Value.Metadata;
if (metadata.GUID.Equals("CrimsonLog"))
{
Logger.LogWarning($"FILTERED: {x.Message}");
x.Cancel();
LogLoaded = true;
break;
}
});
}
}

public static void AddLog(string message, bool console = false)
{
if (LogLoaded && CrimsonLog.Plugin.LogInstance != null && !console)
{
Logger.Record("Chat/Filter", "filter", message);
}
else
{
LogInstance.LogInfo(message);
}
}

public override bool Unload()
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# CrimsonChatFilter
`Server side only` mod to filter unwanted words (or urls) from chat. The sending user will see their messages unfiltered, but all other clients will.

If you use [CrimsonLog](https://thunderstore.io/c/v-rising/p/skytech6/CrimsonLog/), it will also retain a log of filtered & removed messages.

## Installation
* Install [BepInEx](https://v-rising.thunderstore.io/package/BepInEx/BepInExPack_V_Rising/)
* Install [Bloodstone](https://github.com/decaprime/Bloodstone/releases/tag/v0.2.1)
* Extract _CrimsonChatFilter.dll_ into _(VRising server folder)/BepInEx/plugins_

* Run server to generate _(VRising server folder)/BepInEx/plugins/CrimsonChatFilter/filtered_words.json_
Expand Down Expand Up @@ -42,8 +43,12 @@ Want to support my V Rising Mod development?

Donations Accepted with [Ko-Fi](https://ko-fi.com/skytech6)

I also do paid mod work. Want a custom mod? DM me on Discord! (skytech6)

Or buy/play my games!

[Train Your Minibot](https://store.steampowered.com/app/713740/Train_Your_Minibot/)

[Boring Movies](https://store.steampowered.com/app/1792500/Boring_Movies/)
[Boring Movies](https://store.steampowered.com/app/1792500/Boring_Movies/) **FREE TO PLAY**

***I do paid commission mods. Contact me on Discord (skytech6) for all your Unity game modding needs!**

0 comments on commit c525fdf

Please sign in to comment.