Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidev committed Sep 7, 2024
0 parents commit 9c33fdb
Show file tree
Hide file tree
Showing 26 changed files with 1,502 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/verify-signatures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Verify Signatures

on:
push:
branches:
- main

env:
GPG_KEY_ID: 4E8CD129EB607A51

jobs:
verify-signatures:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up GPG and fetch public key
run: |
sudo apt-get update
sudo apt-get install -y gnupg
gpg --version
gpg --keyserver hkps://keys.openpgp.org --recv-keys ${{ env.GPG_KEY_ID }}
gpg --list-keys
- name: Verify signatures
run: |
cd mods
make verify
- name: Report verification result
if: failure()
run: |
echo "Signature verification failed. Please check the integrity of the files and signatures."
exit 1
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# .github
99 changes: 99 additions & 0 deletions algorithms/shutdown_bounty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* Shutdown Bounty logic in v10.02.5
* Detailed explanation here: https://github.com/LegionTD2-Modding/.github/wiki/Details-on-game-logic#shutdown-bounty
**/
public static int GetShutdownBounty(ushort player, Dictionary<ushort, float> powerScores)
{
// Return value
int playerBounty = 0;

// Get all needed data
float avgPowerScore_teamLeft = 0.0;
float avgPowerScore_teamRight = 0.0;
int teamLeft_numUsers = 0;

for (ushort user_id = 1; user_id <= 4; user_id += 1)
{
if (powerScores.ContainsKey(user_id))
{
avgPowerScore_teamLeft += powerScores[user_id];
teamLeft_numUsers++;
}
}

if (teamLeft_numUsers > 0)
{
avgPowerScore_teamLeft /= (float)teamLeft_numUsers;
}

int teamRight_numUsers = 0;
for (ushort user_id = 5; user_id <= 8; user_id += 1)
{
if (powerScores.ContainsKey(user_id))
{
avgPowerScore_teamRight += powerScores[user_id];
teamRight_numUsers++;
}
}

if (teamRight_numUsers > 0)
{
avgPowerScore_teamRight /= (float)teamRight_numUsers;
}

if (teamLeft_numUsers == 0 || teamRight_numUsers == 0)
{
return (playerBounty = 0);
}


float teamsDiffAvgPowerScore = avgPowerScore_teamLeft - avgPowerScore_teamRight;
bool playerIsFromLeftTeam = PlayerApi.IsPlayerAlly(player, 1);
bool teamLeftIsAhead = avgPowerScore_teamLeft >= avgPowerScore_teamRight;

List<ushort> usersInTeamAhead =
teamLeftIsAhead ? new List<ushort>{1, 2, 3, 4} : new List<ushort>{5, 6, 7, 8};

int teamAhead_numUsers = (teamLeftIsAhead ? teamLeft_numUsers : teamRight_numUsers);
float aheadTeamPowerScore = (teamLeftIsAhead ? avgPowerScore_teamLeft : avgPowerScore_teamRight);
float behindTeamPowerScore = (teamLeftIsAhead ? avgPowerScore_teamRight : avgPowerScore_teamLeft);

if ((playerIsFromLeftTeam && !teamLeftIsAhead) || (!playerIsFromLeftTeam && teamLeftIsAhead)) {
return (playerBounty = 0);
}

// Actual algorithm
float absoluteAvgPowerScoreDifference = Math.Abs(teamsDiffAvgPowerScore);
float bountyAmount = (absoluteAvgPowerScoreDifference / 6.0) * teamAhead_numUsers;

Dictionary<ushort, float> powerscoreAboveAvgLosingTeam =
new Dictionary<ushort, float>();

foreach (ushort user_id in usersInTeamAhead)
{
if (!powerScores.ContainsKey(user_id))
{
powerscoreAboveAvgLosingTeam[user_id] = 0.0;
}
else
{
powerscoreAboveAvgLosingTeam[user_id] = powerScores[user_id] - behindTeamPowerScore;
if (powerscoreAboveAvgLosingTeam[user_id] < 0.0)
{
powerscoreAboveAvgLosingTeam[user_id] = 0.0;
}
}
}

float totalPowerscoreAboveAvgLosingTeam = powerscoreAboveAvgLosingTeam.Values.Sum();
if (totalPowerscoreAboveAvgLosingTeam == 0.0)
{
return (playerBounty = 0);
}

float finalWeight = bountyAmount / totalPowerscoreAboveAvgLosingTeam;
float rawResult = powerscoreAboveAvgLosingTeam[player] * finalWeight;
int resultRoundedToFloor25 = (25 * (int)(Math.Floor(rawResult / 25.0)));

return (playerBounty = resultRoundedToFloor25);
}
25 changes: 25 additions & 0 deletions mods/LTD2Mods.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function Download-File {
param(
[string]$Url,
[string]$OutputFile
)
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($Url, $OutputFile)
}

$configUrl = "https://raw.githubusercontent.com/LegionTD2-Modding/.github/main/mods/config.json"
$configFile = "config.json"
Download-File -Url $configUrl -OutputFile $configFile

$config = Get-Content $configFile | ConvertFrom-Json
$installerUrl = $config.core.installers.win

$installerFile = "LegionTD2-Mods-Installer.msi"
Download-File -Url $installerUrl -OutputFile $installerFile

Start-Process msiexec.exe -Wait -ArgumentList "/i $installerFile /qn"

Remove-Item $configFile
Remove-Item $installerFile

Write-Host "Installation complete!"
34 changes: 34 additions & 0 deletions mods/LTD2Mods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

download_file() {
if command -v curl &> /dev/null; then
curl -L -o "$2" "$1"
elif command -v wget &> /dev/null; then
wget -O "$2" "$1"
else
echo "Error: Neither curl nor wget is installed. Please install one of them and try again."
exit 1
fi
}

config_url="https://raw.githubusercontent.com/LegionTD2-Modding/.github/main/mods/config.json"
config_file="config.json"
download_file "$config_url" "$config_file"

if command -v jq &> /dev/null; then
installer_url=$(jq -r '.core.installers.linux' "$config_file")
else
echo "Error: jq is not installed. Please install jq and try again."
exit 1
fi

installer_file="LegionTD2-Mods-Installer.sh"
download_file "$installer_url" "$installer_file"

chmod +x "$installer_file"

./"$installer_file"

rm "$config_file" "$installer_file"

echo "Installation complete!"
69 changes: 69 additions & 0 deletions mods/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
FILES_TO_SIGN := \
config.json \
LTD2Mods.ps1 \
LTD2Mods.sh \
mods_menu.html \
Uninstall_LTD2Mods.ps1 \
Uninstall_LTD2Mods.sh \
core/Core_linux.zip \
core/Core_win.zip \
core/LegionTD2-Mods-Installer.ps1 \
core/LegionTD2-Mods-Installer.sh

GPG_KEY := 4E8CD129EB607A51
SIGNATURES_DIR := signatures

all: sign

$(SIGNATURES_DIR):
mkdir -p $@

check_key:
@if ! gpg --list-keys $(GPG_KEY) > /dev/null 2>&1; then \
echo "GPG key $(GPG_KEY) not found locally. Attempting to fetch from key servers..."; \
gpg --keyserver hkps://keys.openpgp.org --recv-keys $(GPG_KEY) || \
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys $(GPG_KEY) || \
{ echo "Failed to fetch GPG key $(GPG_KEY). Please ensure the key ID is correct and the key is available."; exit 1; } \
fi

sign: $(SIGNATURES_DIR) check_key
@for file in $(FILES_TO_SIGN); do \
if [ -f $$file ]; then \
echo "Signing $$file..."; \
gpg --default-key $(GPG_KEY) --detach-sign --armor $$file; \
mv $$file.asc $(SIGNATURES_DIR)/$$(basename $$file).asc; \
else \
echo "Warning: $$file not found, skipping."; \
fi; \
done
@echo "Signing process completed. Signatures are in $(SIGNATURES_DIR)/"

verify: check_key
@echo "Verifying signatures..."
@exit_code=0; \
for file in $(FILES_TO_SIGN); do \
base_name=$$(basename $$file); \
if [ -f $$file ] && [ -f $(SIGNATURES_DIR)/$$base_name.asc ]; then \
echo "Verifying $$file..."; \
if gpg --verify $(SIGNATURES_DIR)/$$base_name.asc $$file; then \
echo "Signature for $$file is valid."; \
else \
echo "Error: Signature verification failed for $$file."; \
exit_code=1; \
fi; \
else \
echo "Error: $$file or its signature not found."; \
exit_code=1; \
fi; \
done; \
if [ $$exit_code -ne 0 ]; then \
echo "Verification failed. One or more signatures could not be verified."; \
exit 1; \
else \
echo "All signatures verified successfully."; \
fi

clean:
rm -rf $(SIGNATURES_DIR)

.PHONY: all sign clean check_key verify
43 changes: 43 additions & 0 deletions mods/Uninstall_LTD2Mods.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function Find-GameFolder {
$steamPath = "C:\Program Files (x86)\Steam"
$gamePath = Join-Path $steamPath "steamapps\common\Legion TD 2"

if (-not (Test-Path $gamePath)) {
Write-Host "Legion TD 2 folder not found in the default Steam location."
$gamePath = Read-Host "Please enter the full path to your Legion TD 2 game folder"

if (-not (Test-Path $gamePath)) {
Write-Host "Error: The provided path does not exist or is not a directory."
exit 1
}
}

return $gamePath
}

$gameFolder = Find-GameFolder

$removeList = @(
"BepInEx",
".doorstop_version",
"changelog.txt",
"winhttp.dll",
"doorstop_config.ini"
)

foreach ($item in $removeList) {
$fullPath = Join-Path $gameFolder $item
if (Test-Path $fullPath) {
Write-Host "Removing: $fullPath"
if (Test-Path $fullPath -PathType Container) {
Remove-Item -Path $fullPath -Recurse -Force
} else {
Remove-Item -Path $fullPath -Force
}
} else {
Write-Host "Not found, skipping: $fullPath"
}
}

Write-Host "Uninstallation complete. The mod manager and its components have been removed from: $gameFolder"
Write-Host "If you want to completely reset your game, you might consider verifying the game files through Steam."
47 changes: 47 additions & 0 deletions mods/Uninstall_LTD2Mods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

set -e

find_game_folder() {
local steam_path="$HOME/.steam/steam"
local game_path="$steam_path/steamapps/common/Legion TD 2"

if [ ! -d "$game_path" ]; then
echo "Legion TD 2 folder not found in the default Steam location."
read -e -p "Please enter the full path to your Legion TD 2 game folder: " -i "$game_path" game_path

if [ ! -d "$game_path" ]; then
echo "Error: The provided path does not exist or is not a directory."
exit 1
fi
fi

echo "$game_path"
}

GAME_FOLDER=$(find_game_folder)

REMOVE_LIST=(
"BepInEx"
".doorstop_version"
"changelog.txt"
"libdoorstop.so"
"run_bepinex.sh"
)

for item in "${REMOVE_LIST[@]}"; do
full_path="$GAME_FOLDER/$item"
if [ -e "$full_path" ]; then
echo "Removing: $full_path"
if [ -d "$full_path" ]; then
rm -rf "$full_path"
else
rm -f "$full_path"
fi
else
echo "Not found, skipping: $full_path"
fi
done

echo "Uninstallation complete. The mod manager and its components have been removed from: $GAME_FOLDER"
echo "If you want to completely reset your game, you might consider verifying the game files through Steam."
Loading

0 comments on commit 9c33fdb

Please sign in to comment.