Skip to content

Commit

Permalink
CI Fixes, improve Deactivate anticrash.
Browse files Browse the repository at this point in the history
 - Fixes CI
 - Improves readme
 - Completely rewrite game_ui's deactivate in sourcepawn, hopefully resolving several crashes that occur with it.
  • Loading branch information
Mooshua committed Jun 1, 2023
1 parent 81b8fdd commit 22be534
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 31 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# SourceForks

| Status | [![Gamedata](https://github.com/edgegamers/SourceForks/actions/workflows/gamedata.yml/badge.svg)](https://github.com/edgegamers/SourceForks/actions/workflows/gamedata.yml) | [![Plugins](https://github.com/edgegamers/SourceForks/actions/workflows/plugins.yml/badge.svg)](https://github.com/edgegamers/SourceForks/actions/workflows/plugins.yml)
| ------ | ----- | ----- |

Maintained forks of various sourcemod plugins and gamedatas

## About Us

EdgeGamers is a multi-game community that hosts Minecraft, FiveM, CS:GO, TF2, Rust, and Day of Defeat: Source servers. If you like what we do and want to help, you can join our volunteer tech team using [this application](https://www.edgegamers.com/threads/318139/), or learn how to get involved as a plain old player [here](https://www.edgegamers.com/pages/registration/).

## Plugins

**Current SourceMod Version:** 1.11
Expand All @@ -23,7 +30,7 @@ You can use the cvar `sourceforks_antilag_punishment` to configure the punishmen
- **2**: Kick the cheater if they continue
- **3**: Permanently ban the cheater if they continue.

> **Note**: It is impossible for any legitimate player on a vanilla client to reach the "attempted DDOS" or "suspicious network activity" alert.
> **Note**: From SourceForks 1.2 up, It is impossible for any legitimate player on a vanilla client to reach the "attempted DDOS" or "suspicious network activity" alert.
> If you see this, or they were banned for DDoSing, they are cheating. Period.
- **Command** `noop_antilag` presents users with RCON flags the status of all active patches.
Expand All @@ -40,15 +47,16 @@ Almost identical to the original, but refactored to use gamedata.
*An Original Plugin*

Prevents several map issues from crashing or lagging the server. This includes:
- Calling `Deactivate` on a `game_ui` that has no active player
- Several issues with a game_ui's `Deactivate` input that cause crashes
- Maps with no navmesh causing re-generation on the fly (Usually doesn't crash, but lots of lag.)
- Killing a teleport destination will crash the server when anyone attempts to use it as a destination

### GOTV Hibernation
*An Original Plugin*

Prevents GOTV bots from leaving the server when server hibernation (`sv_hibernate`) is enabled.
> **Note**: Also appears to prevent *any* bot from leaving the server during hibernation. This does not appear to have an impact on the hibernation's efficiency, so it should be fine.
> **Note**: In the rare event that the internal m_isHLTV field changes, this plugin will allow any kicks that contain the word "override"
> and will warn admins if it detects the field may have changed.
- **Command** `noop_tvhibernation` presents users with RCON flags the status of all active patches.

Expand Down
35 changes: 19 additions & 16 deletions gamedata/sourceforks_mapcrashfix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@
}
"Addresses"
{
"DeactivateNullReference"
{
// Source has a warning when there is no player on a game_ui.
// However, this involves including the activator in a warning message. Which is null. For some ungodly reason.
// Yep, that's the crash. So we're no-oping the warning block.
"signature" "CGameUI::Deactivate"
"windows"
{
"offset" "544"
}
"linux"
{
"offset" "59"
}
}
"NavmeshUpdateGeneration"
{
// Navmesh generation which occurs every frame.
Expand Down Expand Up @@ -72,6 +57,25 @@
}
}
}
"Functions"
{
"CGameUI::Deactivate"
{
"signature" "CGameUI::Deactivate"
"callconv" "thiscall"
"return" "void"
"this" "entity"
"hooktype" "raw"

"arguments"
{
"activator"
{
"type" "cbaseentity"
}
}
}
}
"Signatures"
{
"CNavMesh::Update"
Expand All @@ -90,7 +94,6 @@
"windows" "\x55\x8B\xEC\x83\xEC\x14\x53\x56\x8B\xF1\x57\x8B\x8E\x50\x05\x00\x00"
"linux" "\x55\x89\xE5\x57\x56\x53\x83\xEC\x4C\x8B\x5D\x08\x8B\x93\x68\x05\x00\x00"
}

"CTeleportTrigger::Touch"
{
// "Teleport trigger '%s' cannot find destination named '%s'!\n"
Expand Down
94 changes: 91 additions & 3 deletions src/scripting/sourceforks_mapcrashfix.sp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <sourcemod>
#include <dhooks>
#include "asm_patch.sp"
#include "asm_x86.sp"
#include "sourceforks_version.sp"
Expand All @@ -12,8 +13,11 @@ public Plugin myinfo = {
}

#define GAMEDATA_FILE "sourceforks_mapcrashfix"
#define DEBUG 0

GameData Config;
DynamicDetour Detour_GameUIDeactivate;


public OnPluginStart()
{
Expand All @@ -25,8 +29,6 @@ public OnPluginStart()
SetFailState("This plugin is only compatible with CS:GO.");

PatchCommand("noop_mapcrashfix");
// GameUI::Deactivate fix
NoOpFunction(Config, "DeactivateNullReference", "DeactivateNullReferenceSize");
// CNavMesh::UpdateGeneration fix
NoOpFunction(Config, "NavmeshUpdateGeneration", "NavmeshUpdateGenerationSize");
// CTeleportTrigger::Touch fix
Expand All @@ -35,11 +37,97 @@ public OnPluginStart()
any teleport_ent_lookup[] = { PUSH_IMM32, 0, 0, 0, 0 };
PatchFunction(Config, "TeleportEntLookup", "TeleportEntLookupSize", teleport_ent_lookup, sizeof(teleport_ent_lookup));

Detour_GameUIDeactivate = DynamicDetour.FromConf(Config, "CGameUI::Deactivate");
Detour_GameUIDeactivate.Enable(Hook_Pre, GameUIDeactivate)
}

#define GAMEUI_FREEZE 0x20
#define GAMEUI_WEAPON 0x40

#define FLAG_FROZEN 0x80
#define HIDE_HUD_FLAG 0x1

public MRESReturn GameUIDeactivate(int self, DHookParam params)
{
#if DEBUG
PrintToServer("CGameUI::Deactivate (%d)", self);
#endif

// Get the player entity
int player = GetEntPropEnt(self, Prop_Data, "m_player");

#if DEBUG
PrintToServer("CGameUI::Deactivate - Player (%d)", player);
#endif

// Is the player still valid/in game?
// If so, handle some funky logic
if (player != -1)
{
int spawnflags = GetEntProp(self, Prop_Data, "m_spawnflags");

#if DEBUG
PrintToServer("CGameUI::Deactivate - Spawnflags %b - Player %N", spawnflags, player);
#endif

if ((spawnflags & GAMEUI_FREEZE) != 0)
{
// GameUI is in freeze mode.
// Remove the frozen flag from the player
int old_flags = GetEntProp(player, Prop_Data, "m_fFlags");

#if DEBUG
PrintToServer("CGameUI::Deactivate - Unfreezing");
#endif

SetEntProp(player, Prop_Data, "m_fFlags", old_flags & (~FLAG_FROZEN));
}

if ((spawnflags & GAMEUI_WEAPON))
{
// GameUI is in hide-hud mode.
// Re-enable the hud and give player weapons
int old_flags = GetEntProp(player, Prop_Send, "m_iHideHUD");
int old_weapon = GetEntPropEnt(self, Prop_Data, "m_hSaveWeapon");

SetEntProp(player, Prop_Send, "m_iHideHUD", old_flags & (~HIDE_HUD_FLAG));

#if DEBUG
PrintToServer("CGameUI::Deactivate - Re-Weaponing (%d)", old_weapon);
#endif

if (old_weapon != -1)
EquipPlayerWeapon(player, old_weapon);
}

// Fire some outputs to reset everything to 0
FireEntityOutput(self, "PlayerOff", player, 0);

SetVariantFloat(0); FireEntityOutput(self, "XAxis", player, 0);
SetVariantFloat(0); FireEntityOutput(self, "YAxis", player, 0);
SetVariantFloat(0); FireEntityOutput(self, "AttackAxis", player, 0);
SetVariantFloat(0); FireEntityOutput(self, "Attack2Axis", player, 0);
}
else
{
// NOT BASEGAME: Ensure playeroff is always fired
FireEntityOutput(self, "PlayerOff", self, 0);
}
// Reset the game_ui
SetEntProp(self, Prop_Data, "m_nLastButtonState", 0);
SetEntPropEnt(self, Prop_Data, "m_player", -1);

#if DEBUG
PrintToServer("CGameUI::Deactivate - Done", self);
#endif

// Prevent original (crashing) function from being called
return MRES_Supercede;
}

public OnPluginEnd()
{
RecoverFunction(Config, "DeactivateNullReference", "DeactivateNullReferenceSize");
Detour_GameUIDeactivate.Disable(Hook_Pre, GameUIDeactivate);
RecoverFunction(Config, "NavmeshUpdateGeneration", "NavmeshUpdateGenerationSize");
RecoverFunction(Config, "TeleportEntLookup", "TeleportEntLookupSize");
}
12 changes: 5 additions & 7 deletions test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ RUN make
# Clone depot downloader
FROM bitnami/git as depot_downloader_clone

# Specifically use stable release DepotDownloader_2.4.7.
RUN git clone --depth 1 --branch DepotDownloader_2.4.7 https://github.com/SteamRE/DepotDownloader.git
RUN git clone --depth 1 --branch master https://github.com/SteamRE/DepotDownloader.git

# depot_downloader_build
# Uses dotnet to build depot downloader cloned from earlier stage
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine as depot_downloader_build

COPY --from=depot_downloader_clone DepotDownloader/DepotDownloader DepotDownloader
WORKDIR DepotDownloader
COPY --from=depot_downloader_clone DepotDownloader .

RUN dotnet restore
RUN dotnet build -c Release --no-restore
RUN dotnet restore DepotDownloader
RUN dotnet build DepotDownloader -c Release --no-restore

# runtime
# contains gdc, depot downloader,
Expand All @@ -73,7 +71,7 @@ COPY test/filelist.txt filelist.txt
ARG CSGOVERSION

# Fetch CS:GO
RUN dotnet $DEPOT_DOWNLOADER_PATH -app 740 -depot 740 -validate -all-platforms -dir server -filelist filelist.txt
RUN dotnet $DEPOT_DOWNLOADER_PATH -app 740 -depot 740 -validate -branch public -all-platforms -dir server -filelist filelist.txt


# runtime_multiarch
Expand Down
1 change: 0 additions & 1 deletion test/filelist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
regex:(\.so)$
regex:(\.dll)$

2 changes: 1 addition & 1 deletion test/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if ($USE_BUILDX -eq $True)
else
{
Write-Host "* Using Vanilla Docker"
iex "docker build $docker_args --file Dockerfile ../ -t sourceforks-gdc:latest --build-arg CSGOVERSION=$csgo_version"
iex "docker build $docker_args --progress plain --file Dockerfile ../ -t sourceforks-gdc:latest --build-arg CSGOVERSION=$csgo_version"
}
Write-Host "* Done!"

Expand Down

0 comments on commit 22be534

Please sign in to comment.