Skip to content

Commit

Permalink
Added windows version, some code improvments and fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
shel committed Mar 14, 2020
1 parent da5661c commit 6acc8a8
Show file tree
Hide file tree
Showing 36 changed files with 287 additions and 5,127 deletions.
55 changes: 21 additions & 34 deletions .github/workflows/OnRelease.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,26 @@
name: Build Linux
name: 'Build'
on:
release:
types:
- published
jobs:
build-linux:
name: Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install
shell: bash
run: sudo apt update && sudo apt install -y gcc g++ gcc-multilib g++-multilib
- name: Get the version
id: get_version
run: echo ::set-output name=GIT_TAG_VERSION::${GITHUB_REF/refs\/tags\//}
- name: Build
shell: bash
run: |
chmod -R 755 *
./Compile.sh ${{ steps.get_version.outputs.GIT_TAG_VERSION }}
mkdir $GITHUB_WORKSPACE/Release/addons/amxmodx/modules/
mv $GITHUB_WORKSPACE/enviromentvariables_amxx_i386.so $GITHUB_WORKSPACE/Release/addons/amxmodx/modules/enviromentvariables_amxx_i386.so
tar -zcvf enviromentvariables.tar.gz Release
- name: "Get upload url"
run: echo "::set-output name=upload_url::https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)/assets{?name,label}"
id: release

- name: "Upload Release Asset"
uses: "actions/upload-release-asset@master"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
upload_url: ${{ steps.release.outputs.upload_url }}
asset_path: ./enviromentvariables.tar.gz
asset_name: enviromentvariables.tar.gz
asset_content_type: application/tar+gzip
build-linux:
name: Linux
runs-on: ubuntu-latest
steps:
- {uses: actions/checkout@master}
- {name: 'Multilib installing', shell: bash, run: 'sudo apt update && sudo apt install -y gcc g++ gcc-multilib g++-multilib'}
- {name: 'Getting version', id: get_version, run: 'echo ::set-output name=GIT_TAG_VERSION::${GITHUB_REF/refs\/tags\//}'}
- {name: Build, shell: bash, run: "chmod -R 755 *\n./Compile.sh ${{ steps.get_version.outputs.GIT_TAG_VERSION }}\nmkdir $GITHUB_WORKSPACE/Release/addons/amxmodx/modules/\nmv $GITHUB_WORKSPACE/environmentvariables_amxx_i386.so $GITHUB_WORKSPACE/Release/addons/amxmodx/modules/environmentvariables_amxx_i386.so\ntar -zcvf environmentvariables.tgz Release\n"}
- {name: 'Asset attaching', uses: svenstaro/upload-release-action@v1-release, env: {GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'}, with: {repo_token: '${{ secrets.GITHUB_TOKEN }}', file: ./environmentvariables.tgz, asset_name: environmentvariables.tgz, tag: '${{ github.ref }}'}}
build-windows:
name: Windows
runs-on: windows-latest
steps:
- {uses: actions/checkout@master}
- {name: 'Get the version', id: get_version, run: 'echo ::set-output name=GIT_TAG_VERSION::${GITHUB_REF/refs\/tags\//}', shell: bash}
- {name: 'Install v141_xp', run: "& \"C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vs_installer.exe\" modify `\n --installPath \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\" `\n --add Microsoft.VisualStudio.Component.WinXP --passive --norestart\n", shell: pwsh}
- {name: 'Going to dir', run: "cd msvc\n"}
- {name: 'Build', run: "set _CL_=/MT\n\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe\" %GITHUB_WORKSPACE%\\msvc\\EnvironmentVariables.vcxproj /p:WarningLevel=0 /p:Configuration=Release /p:Platform=x86 /t:Rebuild /p:Version=\"${{ steps.get_version.outputs.GIT_TAG_VERSION }}\"\n%systemroot%\\System32\\xcopy /i /y %GITHUB_WORKSPACE%\\msvc\\Release\\environmentvariables_amxx.dll %GITHUB_WORKSPACE%\\Release\\addons\\amxmodx\\modules\\environmentvariables_amxx.dll*\npowershell Compress-Archive %GITHUB_WORKSPACE%\\Release\\ %GITHUB_WORKSPACE%\\msvc\\environmentvariables_static.zip\nset _CL_=/MD\n\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\MSBuild.exe\" %GITHUB_WORKSPACE%\\msvc\\EnvironmentVariables.vcxproj /p:WarningLevel=0 /p:Configuration=Release /p:Platform=x86 /t:Rebuild /p:Version=\"${{ steps.get_version.outputs.GIT_TAG_VERSION }}\"\n%systemroot%\\System32\\xcopy /i /y %GITHUB_WORKSPACE%\\msvc\\Release\\environmentvariables_amxx.dll %GITHUB_WORKSPACE%\\Release\\addons\\amxmodx\\modules\\environmentvariables_amxx.dll*\npowershell Compress-Archive %GITHUB_WORKSPACE%\\Release\\ %GITHUB_WORKSPACE%\\msvc\\environmentvariables_dynamic.zip\n", shell: cmd}
- {name: 'Dynamic windows asset attaching', uses: svenstaro/upload-release-action@v1-release, env: {GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'}, with: {repo_token: '${{ secrets.GITHUB_TOKEN }}', file: '${{ github.workspace }}\msvc\environmentvariables_dynamic.zip', asset_name: environmentvariables_dynamic.zip, tag: '${{ github.ref }}'}}
- {name: 'Static windows asset attaching', uses: svenstaro/upload-release-action@v1-release, env: {GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'}, with: {repo_token: '${{ secrets.GITHUB_TOKEN }}', file: '${{ github.workspace }}\msvc\environmentvariables_static.zip', asset_name: environmentvariables_static.zip, tag: '${{ github.ref }}'}}
11 changes: 6 additions & 5 deletions Compile.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
g++ -DMODULE_VERSION_A=\"$1\" -DRelease -O3 -g0 -m32 -s -shared -msse3 -std=c++14 -mtune=generic -static-libstdc++ \
gcc -DMODULE_VERSION_A=\"$1\" -DRelease -O3 -g0 -m32 -s -shared -msse3 -std=c++14 -mtune=generic \
-Wno-pointer-arith -Wno-conversion-null -Wno-write-strings -Wno-attributes \
-fPIC -fomit-frame-pointer -fno-builtin -fno-rtti -fno-exceptions \
-fPIC -fomit-frame-pointer -fno-builtin -fno-rtti -fno-exceptions -ffunction-sections -fdata-sections \
-fomit-frame-pointer -fvisibility=hidden -fvisibility-inlines-hidden -flto \
-I. -Isdk/hlsdk/common -Isdk/hlsdk/dlls -Isdk/hlsdk/engine -Isdk/hlsdk/pm_shared -Isdk/hlsdk/public -Isdk/metamod \
-I. -Isdk/metamod \
main.cpp amxxmodule.cpp \
-Wl,--version-script=version_script.lds -Wl,--gc-sections -lrt -ldl -lm \
-o enviromentvariables_amxx_i386.so
-Wl,--version-script=version_script.lds -Wl,--gc-sections \
-o environmentvariables_amxx_i386.so

8 changes: 8 additions & 0 deletions CompileIda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
gcc -DMODULE_VERSION_A=\"$1\" -DRelease -O3 -g3 -m32 -shared -msse3 -std=c++14 -mtune=generic \
-Wno-pointer-arith -Wno-conversion-null -Wno-write-strings -Wno-attributes \
-fPIC -fomit-frame-pointer -fno-builtin -fno-rtti -fno-exceptions \
-fomit-frame-pointer -fvisibility=hidden -fvisibility-inlines-hidden -flto \
-I. -Isdk/metamod \
main.cpp amxxmodule.cpp \
-Wl,--version-script=version_script.lds -Wl,--gc-sections \
-o environmentvariables_amxx_i386.so
9 changes: 9 additions & 0 deletions FIX_NO_USE_META.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#ifndef USE_METAMOD
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
// Misc C-runtime library headers
#include <stdio.h>
#include <stdlib.h>
#endif
#endif
13 changes: 0 additions & 13 deletions Main.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if defined _enviroment_variables
#if defined _environment_variables
#endinput
#endif

#define _enviroment_variables
#define _environment_variables

#if !defined EINVAL
#define EINVAL 22 // Invalid argument
Expand All @@ -13,12 +13,12 @@
#endif

#if AMXX_VERSION_NUM >= 175
#pragma reqlib enviromentvariables
#pragma reqlib environmentvariables
#if !defined AMXMODX_NOAUTOLOAD
#pragma loadlib enviromentvariables
#pragma loadlib environmentvariables
#endif
#else
#pragma library enviromentvariables
#pragma library environmentvariables
#endif

/**
Expand Down
9 changes: 6 additions & 3 deletions amxxmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,9 +2311,12 @@ C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason)
#endif // FN_META_DETACH
return TRUE;
}

C_DLLEXPORT void WINAPI GiveFnptrsToDll(enginefuncs_t* pengfuncsFromEngine, globalvars_t *pGlobals)
{
#if !defined(_WIN32)
C_DLLEXPORT
#endif
void WINAPI GiveFnptrsToDll(enginefuncs_t * pengfuncsFromEngine, globalvars_t * pGlobals) {
#pragma message("Exporting function " __FUNCTION__ " [" __FUNCDNAME__ "]")
#pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
memcpy(&g_engfuncs, pengfuncsFromEngine, sizeof(enginefuncs_t));
gpGlobals = pGlobals;
}
Expand Down
53 changes: 43 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
#include "FIX_NO_USE_META.h"
#include "osDep.h"
#include "amxxmodule.h"
#ifdef _WIN32
#include <windows.h>
int unsetenv(const char* name);
int setenv(const char* name, const char* value, int overwrite);
#endif
static const char* empty = "";
static cell AMX_NATIVE_CALL GetEnvironmentVariable(AMX *amx, cell *params){
static cell AMX_NATIVE_CALL NGetEnvironmentVariable(AMX *amx, cell *params){
enum args_e { arg_null, arg_name, arg_buffer, arg_bufferlength };
int len, iLen;
const char *b = MF_GetAmxString(amx, params[arg_name], 0, &len);
const char *value = secure_getenv(b);
iLen = value?strlen(value):0;
len = params[arg_bufferlength];
return MF_SetAmxStringUTF8Char(amx, params[arg_buffer], iLen?value:empty, iLen, len);
const char* value
#ifdef _WIN32
= getenv(b);
#else
= secure_getenv(b);
#endif
iLen = value ? strlen(value) : 0;
return MF_SetAmxStringUTF8Char(amx, params[arg_buffer], iLen ? value : empty, iLen, len);
}

static cell AMX_NATIVE_CALL SetEnvironmentVariable(AMX *amx, cell *params){
static cell AMX_NATIVE_CALL NSetEnvironmentVariable(AMX *amx, cell *params){
enum args_e { arg_null, arg_name, arg_value, arg_replace, arg_errno };
int len;
const char *n = MF_GetAmxString(amx, params[arg_name], 0, &len);
Expand All @@ -23,23 +35,44 @@ static cell AMX_NATIVE_CALL SetEnvironmentVariable(AMX *amx, cell *params){
return (cell)ret;
}

static cell AMX_NATIVE_CALL UnSetEnvironmentVariable(AMX *amx, cell *params){
static cell AMX_NATIVE_CALL NUnSetEnvironmentVariable(AMX *amx, cell *params){
enum args_e { arg_null, arg_name, arg_errno };
int len;
const char *n = MF_GetAmxString(amx, params[arg_name], 0, &len);
auto ret = unsetenv(n);
auto ret = unsetenv(n);
cell *cErrno = MF_GetAmxAddr(amx, params[arg_errno]);
*cErrno = ret?errno:0;
return (cell)ret;
}

/* native int GetEnvironmentVariable(const char[] szName, char[] szBuffer, int iBufferLength, bool &bExists = false); */
AMX_NATIVE_INFO _Natives[] = {
{"GetEnvironmentVariable", GetEnvironmentVariable},
{"SetEnvironmentVariable", SetEnvironmentVariable},
{"UnSetEnvironmentVariable", UnSetEnvironmentVariable},
{"GetEnvironmentVariable", NGetEnvironmentVariable},
{"SetEnvironmentVariable", NSetEnvironmentVariable},
{"UnSetEnvironmentVariable", NUnSetEnvironmentVariable},

{NULL, NULL}
};

void OnAmxxAttach(){ MF_AddNatives(_Natives); }

#ifdef _WIN32
int setenv(const char* name, const char* value, int overwrite) {
if (!overwrite && getenv(name) != nullptr) return 0;
if (*value != '\0') { auto e = _putenv_s(name, value); if (e != 0) { errno = e; return -1; } return 0;}
if (_putenv_s(name, " ") != 0) { errno = EINVAL; return -1; }
*getenv(name) = '\0'; *(getenv(name) + 1) = '=';
if (_wenviron != nullptr) {
wchar_t buf[_MAX_ENV + 1];size_t len;
if (mbstowcs_s(&len, buf, _MAX_ENV + 1, name, _MAX_ENV) != 0) {errno = EINVAL;return -1;}
*_wgetenv(buf) = u'\0'; *(_wgetenv(buf) + 1) = u'=';
}
if (!SetEnvironmentVariableA(name, value)) { errno = EINVAL; return -1; }
return 0;
}

int unsetenv(const char* name) {
if (_putenv_s(name, "") != 0)return -1;
return 0;
}
#endif
10 changes: 5 additions & 5 deletions moduleconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include <amxmodx_version.h>

// Module info
#define MODULE_NAME "EnviromentVariables"
#define MODULE_NAME "Environment Variables"
#define MODULE_VERSION MODULE_VERSION_A
#define MODULE_AUTHOR "Unknown"
#define MODULE_URL "shel/Garey/F@ntom/wopox1337"
#define MODULE_LOGTAG "Enviroment Variables"
#define MODULE_LIBRARY "enviromentvariables"
#define MODULE_LOGTAG "Environment Variables"
#define MODULE_LIBRARY "environmentvariables"
#define MODULE_LIBCLASS ""
// If you want the module not to be reloaded on mapchange, remove / comment out the next line
//#define MODULE_RELOAD_ON_MAPCHANGE
Expand All @@ -34,7 +34,7 @@
#endif // __DATE__

// metamod plugin?
#define USE_METAMOD
/* #define USE_METAMOD */

// use memory manager/tester?
// note that if you use this, you cannot construct/allocate
Expand All @@ -44,7 +44,7 @@

// Unless you use STL or exceptions, keep this commented.
// It allows you to compile without libstdc++.so as a dependency
// #define NO_ALLOC_OVERRIDES
#define NO_ALLOC_OVERRIDES

// Uncomment this if you are using MSVC8 or greater and want to fix some of the compatibility issues yourself
// #define NO_MSVC8_AUTO_COMPAT
Expand Down
Loading

0 comments on commit 6acc8a8

Please sign in to comment.