Skip to content

Commit

Permalink
Fix Tournament & Add Subplugin Folder Cvar [M]
Browse files Browse the repository at this point in the history
Fixes #45
Closes #47
  • Loading branch information
Batfoxkid committed Dec 26, 2022
1 parent e741dce commit a0fb4be
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 66 deletions.
2 changes: 2 additions & 0 deletions addons/sourcemod/scripting/freak_fortress_2.sp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ enum

AggressiveOverlay,
AggressiveSwap,

SubpluginFolder,

SoundType,
BossTriple,
Expand Down
139 changes: 76 additions & 63 deletions addons/sourcemod/scripting/freak_fortress_2/bosses.sp
Original file line number Diff line number Diff line change
Expand Up @@ -3018,59 +3018,64 @@ static void EnableSubplugins()
{
if(!PluginsEnabled)
{
PluginsEnabled = true;

char path[PLATFORM_MAX_PATH], filename[PLATFORM_MAX_PATH], filepath1[PLATFORM_MAX_PATH], filepath2[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "plugins/freaks");

FileType filetype;
DirectoryListing dir = OpenDirectory(path);
if(dir)
char folder[128];
Cvar[SubpluginFolder].GetString(folder, sizeof(folder));
if(folder[0])
{
while(dir.GetNext(filename, sizeof(filename), filetype))
PluginsEnabled = true;

char path[PLATFORM_MAX_PATH], filename[PLATFORM_MAX_PATH], filepath1[PLATFORM_MAX_PATH], filepath2[PLATFORM_MAX_PATH];
BuildPath(Path_SM, path, sizeof(path), "plugins/%s", folder);

FileType filetype;
DirectoryListing dir = OpenDirectory(path);
if(dir)
{
if(filetype == FileType_File)
while(dir.GetNext(filename, sizeof(filename), filetype))
{
int pos = strlen(filename) - 4;
if(pos > 0)
if(filetype == FileType_File)
{
if(StrEqual(filename[pos], ".smx"))
int pos = strlen(filename) - 4;
if(pos > 0)
{
FormatEx(filepath1, sizeof(filepath1), "%s/%s", path, filename);

if(!IsSubpluginLoaded(filename))
InsertServerCommand("sm plugins load freaks/%s", filename);

DataPack pack = new DataPack();
pack.WriteString(filepath1);
RequestFrame(Bosses_RenameSubplugin, pack);
}
else if(StrEqual(filename[pos], ".ff2"))
{
FormatEx(filepath1, sizeof(filepath1), "%s/%s", path, filename);

strcopy(filename[pos], 5, ".smx");
FormatEx(filepath2, sizeof(filepath2), "%s/%s", path, filename);

if(FileExists(filepath2))
if(StrEqual(filename[pos], ".smx"))
{
DeleteFile(filepath1);
FormatEx(filepath1, sizeof(filepath1), "%s/%s", path, filename);

if(!IsSubpluginLoaded(filename))
InsertServerCommand("sm plugins load %s/%s", folder, filename);

DataPack pack = new DataPack();
pack.WriteString(filepath1);
RequestFrame(Bosses_RenameSubplugin, pack);
}
else
else if(StrEqual(filename[pos], ".ff2"))
{
RenameFile(filepath2, filepath1);
InsertServerCommand("sm plugins load freaks/%s", filename);
FormatEx(filepath1, sizeof(filepath1), "%s/%s", path, filename);

strcopy(filename[pos], 5, ".smx");
FormatEx(filepath2, sizeof(filepath2), "%s/%s", path, filename);

if(FileExists(filepath2))
{
DeleteFile(filepath1);
}
else
{
RenameFile(filepath2, filepath1);
InsertServerCommand("sm plugins load %s/%s", folder, filename);
}

DataPack pack = new DataPack();
pack.WriteString(filepath2);
RequestFrame(Bosses_RenameSubplugin, pack);
}

DataPack pack = new DataPack();
pack.WriteString(filepath2);
RequestFrame(Bosses_RenameSubplugin, pack);
}
}
}

ServerExecute();
}

ServerExecute();
}
}
}
Expand Down Expand Up @@ -3105,37 +3110,45 @@ public void Bosses_RenameSubplugin(DataPack pack)
int pos = strcopy(buffer2, sizeof(buffer2), buffer1) - 4;
strcopy(buffer2[pos], 5, ".ff2");

RenameFile(buffer2, buffer1);
if(!RenameFile(buffer2, buffer1))
LogError("Failed to rename '%s' to '%s'", buffer1, buffer2);
}

static void DisableSubplugins()
{
if(PluginsEnabled)
{
PluginsEnabled = false;

//TODO: Reverse
ArrayList list = new ArrayList(PLATFORM_MAX_PATH);

char filename[PLATFORM_MAX_PATH];
Handle iter = GetPluginIterator();
while(MorePlugins(iter))
char folder[128];
Cvar[SubpluginFolder].GetString(folder, sizeof(folder));
if(folder[0])
{
Handle plugin = ReadPlugin(iter);
GetPluginFilename(plugin, filename, sizeof(filename));
if(!StrContains(filename, "freaks\\", false))
list.PushString(filename);
}
delete iter;

for(int i = list.Length-1; i >= 0; i--)
{
list.GetString(i, filename, sizeof(filename));
InsertServerCommand("sm plugins unload %s", filename);
PluginsEnabled = false;

StrCat(folder, sizeof(folder), "\\");

ArrayList list = new ArrayList(PLATFORM_MAX_PATH);

char filename[PLATFORM_MAX_PATH];

Handle iter = GetPluginIterator();
while(MorePlugins(iter))
{
Handle plugin = ReadPlugin(iter);
GetPluginFilename(plugin, filename, sizeof(filename));
if(!StrContains(filename, folder, false))
list.PushString(filename);
}
delete iter;

for(int i = list.Length-1; i >= 0; i--)
{
list.GetString(i, filename, sizeof(filename));
InsertServerCommand("sm plugins unload %s", filename);
}

delete list;
ServerExecute();
}

delete list;
ServerExecute();
}
}

Expand Down
6 changes: 4 additions & 2 deletions addons/sourcemod/scripting/freak_fortress_2/convars.sp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void ConVar_PluginStart()
Cvar[BossSapper] = CreateConVar("ff2_boss_sapper", "1", "If sappers can apply a slow on a boss similar to MvM.", _, true, 0.0, true, 1.0);
Cvar[PrefSpecial] = CreateConVar("ff2_pref_special", "0.0", "If non-zero, difficulties will be randomly applied onto a boss based on the chance set.", FCVAR_NOTIFY, true, 0.0, true, 1.0);
Cvar[Telefrags] = CreateConVar("ff2_game_telefrag", "5000", "How much damage telefrags do on bosses");
Cvar[SubpluginFolder] = CreateConVar("ff2_plugin_subplugins", "freaks", "Folder to load/unload when bosses are at play relative to the plugins folder.");

CreateConVar("ff2_oldjump", "1", "Backwards Compatibility ConVar", FCVAR_DONTRECORD|FCVAR_HIDDEN, true, 0.0, true, 1.0);
CreateConVar("ff2_base_jumper_stun", "0", "Backwards Compatibility ConVar", FCVAR_DONTRECORD|FCVAR_HIDDEN, true, 0.0, true, 1.0);
Expand All @@ -59,7 +60,6 @@ void ConVar_PluginStart()
Cvar[PreroundTime] = FindConVar("tf_arena_preround_time");
//Cvar[BonusRoundTime] = FindConVar("mp_bonusroundtime");
Cvar[Tournament] = FindConVar("mp_tournament");
Cvar[Tournament].Flags &= ~(FCVAR_NOTIFY|FCVAR_REPLICATED);

CvarList = new ArrayList(sizeof(CvarInfo));

Expand Down Expand Up @@ -101,7 +101,7 @@ static void GenerateConfig()
if(file)
{
file.WriteLine("// Settings present are for Freak Fortress 2: Rewrite (" ... PLUGIN_VERSION ... "." ... PLUGIN_VERSION_REVISION ... ")");
file.WriteLine("// Updating the plugin version will generate new ConVars and any non-FF2 commands will be lost");
file.WriteLine("// Updating the plugin version will generate new cvars and any non-FF2 commands will be lost");
file.WriteLine("ff2_version \"" ... PLUGIN_VERSION_FULL ... "\"");
file.WriteLine(NULL_STRING);

Expand Down Expand Up @@ -207,6 +207,7 @@ void ConVar_Enable()
info.cvar.AddChangeHook(ConVar_OnChanged);
}

Cvar[Tournament].Flags &= ~(FCVAR_NOTIFY|FCVAR_REPLICATED);
CvarHooked = true;
}
}
Expand All @@ -225,6 +226,7 @@ void ConVar_Disable()
info.cvar.SetString(info.defaul);
}

Cvar[Tournament].Flags |= (FCVAR_NOTIFY|FCVAR_REPLICATED);
CvarHooked = false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ echo "SCRIPTS_PATH=addons/sourcemod/scripting" >> $GITHUB_ENV
echo "PLUGIN_VERSION_REVISION<<EOF" >> $GITHUB_ENV
git rev-list --count HEAD >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
echo $PLUGIN_VERSION_REVISION
cp scripts/compile.sh addons/sourcemod/scripting/compile.sh
cd addons/sourcemod/scripting

Expand All @@ -15,7 +16,7 @@ echo 'EOF' >> $GITHUB_ENV
sed -i -e 's/#define PLUGIN_VERSION_REVISION.*".*"/#define PLUGIN_VERSION_REVISION "'$PLUGIN_VERSION_REVISION'"/g' freak_fortress_2.sp
for file in $(find -type f -name "ff2r_*.sp")
do
sed -i -e 's/#define PLUGIN_VERSION.*".*"/#define PLUGIN_VERSION "'$PLUGIN_VERSION'.'$PLUGIN_VERSION_REVISION'"/g' $file
sed -i -e 's/#define PLUGIN_VERSION.*".*"/#define PLUGIN_VERSION "'$PLUGIN_VERSION'"."'$PLUGIN_VERSION_REVISION'"/g' $file
done

# Install Required Includes
Expand Down

0 comments on commit a0fb4be

Please sign in to comment.