Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoJF committed Feb 16, 2020
1 parent 5e2d348 commit 441ec28
Show file tree
Hide file tree
Showing 4 changed files with 861 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/compile-plugin-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Compile Plugin

on: [push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
sm-version: [ '1.10.x', '1.11.x' ]

name: SM version ${{ matrix.sm-version }}

steps:
- uses: actions/checkout@v2

- name: Setup SourcePawn Compiler
id: setup
uses: rumblefrog/setup-sp@v1.0.0
with:
version: ${{ matrix.sm-version }}

- name: Create plugins directory
run: mkdir plugins

- name: Compile
run: spcomp -i scripting/include scripting/fps_booster.sp -o plugins/fps_booster.smx

- name: Prepare files for artifact
run: |
mkdir artifact
mv plugins artifact
mv scripting artifact
mv LICENSE artifact
- name: Upload compiled plugin
uses: actions/upload-artifact@v1
with:
name: Compiled plugin with SM ${{ steps.setup.outputs.version }}
path: artifact
90 changes: 90 additions & 0 deletions .github/workflows/create-release-on-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Publish release

on:
push:
tags:
- 'v*'

jobs:
release:
name: Create GitHub release
runs-on: ubuntu-latest
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Output Release URL File
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt

- name: Save Release URL File for publish
uses: actions/upload-artifact@v1
with:
name: release_url
path: release_url.txt

compile:
runs-on: ubuntu-latest
needs: release
strategy:
matrix:
sm-version: [ '1.10.x', '1.11.x' ]

name: SM version ${{ matrix.sm-version }}

steps:
- uses: actions/checkout@v2

- name: Setup SourcePawn Compiler
id: setup
uses: rumblefrog/setup-sp@v1.0.0
with:
version: ${{ matrix.sm-version }}

- name: Create plugins directory
run: mkdir -p plugins

- run: spcomp -i ./scripting/include ./scripting/fps_booster.sp -o ./plugins/fps_booster.smx

- name: Prepare files for artifact
run: |
mkdir artifact
mv ./plugins ./artifact/
mv ./scripting ./artifact/
mv ./LICENSE ./artifact/
- name: Zip plugin
run : |
cd artifact
zip -r deathmatch-loader *
cd ..
mv artifact/fps-booster.zip .
- name: Load Release URL File from release job
uses: actions/download-artifact@v1
with:
name: release_url

- name: Get Release File Name & Upload URL
id: release_url
run: |
value=`cat release_url/release_url.txt`
echo ::set-output name=upload_url::$value
- name: Upload Release files
id: upload-release-files
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.release_url.outputs.upload_url }}
asset_path: ./fps-booster.zip
asset_name: fps-booster-sm${{ steps.setup.outputs.version }}.zip
asset_content_type: application/zip
172 changes: 172 additions & 0 deletions scripting/fps_booster.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <csgocolors>
#include <clientprefs>

#define PLUGIN_NAME "FPS boost"
#define PLUGIN_AUTHOR "GoD-Tony, de_nerdTV"
#define PLUGIN_VERSION "0.0.1"
#define PLUGIN_DESCRIPTION "Melhor performance client-side evitando transmissão de sons desnecessários"
#define PLUGIN_URL "https://denerdtv.com"

bool g_bStopSound[MAXPLAYERS+1];
bool g_bHooked;

Handle g_hClientCookie = INVALID_HANDLE;

public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_URL
};

public OnPluginStart()
{
LoadTranslations("common.phrases");

g_hClientCookie = RegClientCookie("sm_fps", "Controla boost de FPS", CookieAccess_Private);
SetCookieMenuItem(StopSoundCookieHandler, g_hClientCookie, "Boost de FPS");

// Detect game and hook appropriate tempent.
char sGame[32];
GetGameFolderName(sGame, sizeof(sGame));

if (StrEqual(sGame, "cstrike") || StrEqual(sGame, "csgo")) {
AddTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot);
}

RegConsoleCmd("sm_fps", Command_StopSound, "Controla boost de FPS");

for (new i = 1; i <= MaxClients; ++i) {
if (!AreClientCookiesCached(i)) {
continue;
}

OnClientCookiesCached(i);
}
}

public void StopSoundCookieHandler(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
{
switch (action)
{
case CookieMenuAction_DisplayOption:
{
}

case CookieMenuAction_SelectOption:
{
if (CheckCommandAccess(client, "sm_fpsboost", ADMFLAG_RESERVATION)) {
ToggleStopSound(client);
} else {
ReplyToCommand(client, "[SM] You have no access!");
}
}
}
}

void ToggleStopSound(int client)
{
char info[1];
int value = !g_bStopSound[client];

IntToString(value, info, sizeof(info));
SetClientCookie(client, g_hClientCookie, info);

g_bStopSound[client] = (value == 1) ? true : false;
CPrintToChat(client, "{default}[{darkred}FPS{default}] Boost de FPS: %s.", value ? "{green}ligado" : "{darkred}desligado");
CheckHooks();
}

public void OnClientCookiesCached(client)
{
char sValue[8];
GetClientCookie(client, g_hClientCookie, sValue, sizeof(sValue));

g_bStopSound[client] = (sValue[0] != '\0' && StringToInt(sValue));
CheckHooks();
}

public Action Command_StopSound(client, args)
{
if (AreClientCookiesCached(client)) {
if (CheckCommandAccess(client, "sm_fpsboost", ADMFLAG_RESERVATION)) {
ToggleStopSound(client);
} else {
ReplyToCommand(client, "[SM] Você precisa ser subscriber para ter acesso ao boost de FPS!");
}
} else {
ReplyToCommand(client, "[SM] Aguardando cookies, por favor tente novamente...");
}

return Plugin_Handled;
}

public OnClientDisconnect_Post(client)
{
g_bStopSound[client] = false;
CheckHooks();
}

void CheckHooks()
{
bool bShouldHook = false;

for (int i = 1; i <= MaxClients; i++) {
if (g_bStopSound[i]) {
bShouldHook = true;
break;
}
}

// Fake (un)hook because toggling actual hooks will cause server instability.
g_bHooked = bShouldHook;
}

public Action CSS_Hook_ShotgunShot(const char[] te_name, const Players[], numClients, float delay)
{
if (!g_bHooked) {
return Plugin_Continue;
}

// Check which clients need to be excluded.
int newClients[MAXPLAYERS];
int client;
int newTotal = 0;

for (int i = 0; i < numClients; i++) {
client = Players[i];

if (!g_bStopSound[client]) {
newClients[newTotal++] = client;
}
}

if (newTotal == numClients) { // No clients were excluded.
return Plugin_Continue;
} else if (newTotal == 0) { // All clients were excluded and there is no need to broadcast.
return Plugin_Stop;
}

// Re-broadcast to clients that still need it.
float vTemp[3];
TE_Start("Shotgun Shot");
TE_ReadVector("m_vecOrigin", vTemp);
TE_WriteVector("m_vecOrigin", vTemp);
TE_WriteFloat("m_vecAngles[0]", TE_ReadFloat("m_vecAngles[0]"));
TE_WriteFloat("m_vecAngles[1]", TE_ReadFloat("m_vecAngles[1]"));
TE_WriteNum("m_weapon", TE_ReadNum("m_weapon"));
TE_WriteNum("m_iMode", TE_ReadNum("m_iMode"));
TE_WriteNum("m_iSeed", TE_ReadNum("m_iSeed"));
TE_WriteNum("m_iPlayer", TE_ReadNum("m_iPlayer"));
TE_WriteFloat("m_fInaccuracy", TE_ReadFloat("m_fInaccuracy"));
TE_WriteFloat("m_fSpread", TE_ReadFloat("m_fSpread"));
TE_Send(newClients, newTotal, delay);

return Plugin_Stop;
}
Loading

0 comments on commit 441ec28

Please sign in to comment.