1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/update_tool/api_link.asm Sat Mar 31 16:23:19 2007 +0000
1.3 @@ -0,0 +1,92 @@
1.4 +;;;;
1.5 +;; (C)2005-2007 AlliedModders LLC
1.6 +;; By the Metamod:Source Development Team
1.7 +;; This software is licensed under the zlib/libpng free software license.
1.8 +;;
1.9 +;; This assembly file is a short thunk wrapper to let us load as a VSP and exit quietly,
1.10 +;; without any overhead of the rest of the interface, and also to prevent linking against
1.11 +;; tierX or vstdlib
1.12 +;;;;
1.13 +
1.14 +;;Exports:
1.15 +;; void GetBaseDir(char *buffer, maxlength);
1.16 +;; void *GetThisPointer();
1.17 +;;Imports:
1.18 +;; void LoadFunction();
1.19 +
1.20 +section .text
1.21 +
1.22 +global GetThisPointer, GetGameDir
1.23 +global _GetThisPointer, _GetGameDir
1.24 +extern _LoadFunction
1.25 +
1.26 +GetThisPointer:
1.27 +_GetThisPointer:
1.28 + mov eax, GLOBAL_POINTER
1.29 + ret
1.30 +
1.31 +GetGameDir:
1.32 +_GetGameDir:
1.33 + push ebp
1.34 + mov ebp, esp
1.35 +
1.36 + mov ecx, [engine] ;get this pointer
1.37 + mov edx, [ecx] ;get the vtable
1.38 + %ifdef LINUX
1.39 + push ecx ;push this pointer
1.40 + %endif
1.41 + push dword [ebp+12] ;push maxlenth
1.42 + push dword [ebp+8] ;push buffer
1.43 + call dword [edx+216] ;call IVEngineServer::GetGameDir
1.44 + %ifdef LINUX
1.45 + add esp, 8 ;correct stack
1.46 + %endif
1.47 +
1.48 + pop ebp
1.49 + ret
1.50 +
1.51 +thisLoadFunction:
1.52 + push ebp
1.53 + mov ebp, esp
1.54 +
1.55 + ;get factory
1.56 + mov eax, [ebp+8]
1.57 +
1.58 + push dword 0 ;NULL
1.59 + push dword VENGINESERVER ;iface name
1.60 + call eax ;call factory
1.61 + add esp, 8 ;correct stack
1.62 +
1.63 + test eax, eax ;do we have a valid pointer?
1.64 + jz .end ;no, bail out
1.65 +
1.66 + mov [engine], eax ;store the engine pointer
1.67 +
1.68 + call _LoadFunction
1.69 +
1.70 +.end:
1.71 + ;We never load, never ever ever!
1.72 + xor eax, eax
1.73 + pop ebp
1.74 + %ifdef LINUX
1.75 + ret
1.76 + %else
1.77 + retn 8
1.78 + %endif
1.79 +
1.80 +thisUnloadFunction:
1.81 + ret
1.82 +
1.83 +section .data
1.84 + INTERFACE_NAME DB "ISERVERPLUGINCALLBACKS001", 0
1.85 + VENGINESERVER DB "VEngineServer021", 0
1.86 +
1.87 + VIRTUAL_TABLE DD thisLoadFunction
1.88 + DD thisUnloadFunction
1.89 + ;We don't need any more of the vtable here
1.90 +
1.91 + GLOBAL_POINTER DD VIRTUAL_TABLE
1.92 +
1.93 + temp_ret DD 0
1.94 + temp_ptr DD temp_ret
1.95 + engine DD 0
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/update_tool/msvc8/update_tool.sln Sat Mar 31 16:23:19 2007 +0000
2.3 @@ -0,0 +1,20 @@
2.4 +
2.5 +Microsoft Visual Studio Solution File, Format Version 9.00
2.6 +# Visual Studio 2005
2.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "update_tool", "update_tool.vcproj", "{DDD1563F-7EE2-4E76-BE57-ED84A2664A51}"
2.8 +EndProject
2.9 +Global
2.10 + GlobalSection(SolutionConfigurationPlatforms) = preSolution
2.11 + Debug|Win32 = Debug|Win32
2.12 + Release|Win32 = Release|Win32
2.13 + EndGlobalSection
2.14 + GlobalSection(ProjectConfigurationPlatforms) = postSolution
2.15 + {DDD1563F-7EE2-4E76-BE57-ED84A2664A51}.Debug|Win32.ActiveCfg = Debug|Win32
2.16 + {DDD1563F-7EE2-4E76-BE57-ED84A2664A51}.Debug|Win32.Build.0 = Debug|Win32
2.17 + {DDD1563F-7EE2-4E76-BE57-ED84A2664A51}.Release|Win32.ActiveCfg = Release|Win32
2.18 + {DDD1563F-7EE2-4E76-BE57-ED84A2664A51}.Release|Win32.Build.0 = Release|Win32
2.19 + EndGlobalSection
2.20 + GlobalSection(SolutionProperties) = preSolution
2.21 + HideSolutionNode = FALSE
2.22 + EndGlobalSection
2.23 +EndGlobal
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/update_tool/msvc8/update_tool.vcproj Sat Mar 31 16:23:19 2007 +0000
3.3 @@ -0,0 +1,203 @@
3.4 +<?xml version="1.0" encoding="Windows-1252"?>
3.5 +<VisualStudioProject
3.6 + ProjectType="Visual C++"
3.7 + Version="8.00"
3.8 + Name="update_tool"
3.9 + ProjectGUID="{DDD1563F-7EE2-4E76-BE57-ED84A2664A51}"
3.10 + RootNamespace="update_tool"
3.11 + Keyword="Win32Proj"
3.12 + >
3.13 + <Platforms>
3.14 + <Platform
3.15 + Name="Win32"
3.16 + />
3.17 + </Platforms>
3.18 + <ToolFiles>
3.19 + </ToolFiles>
3.20 + <Configurations>
3.21 + <Configuration
3.22 + Name="Debug|Win32"
3.23 + OutputDirectory="$(SolutionDir)$(ConfigurationName)"
3.24 + IntermediateDirectory="$(ConfigurationName)"
3.25 + ConfigurationType="2"
3.26 + CharacterSet="2"
3.27 + >
3.28 + <Tool
3.29 + Name="VCPreBuildEventTool"
3.30 + CommandLine="nasmw ..\api_link.asm -f win32 -o ..\obj\api_link.obj -DWIN32"
3.31 + />
3.32 + <Tool
3.33 + Name="VCCustomBuildTool"
3.34 + />
3.35 + <Tool
3.36 + Name="VCXMLDataGeneratorTool"
3.37 + />
3.38 + <Tool
3.39 + Name="VCWebServiceProxyGeneratorTool"
3.40 + />
3.41 + <Tool
3.42 + Name="VCMIDLTool"
3.43 + />
3.44 + <Tool
3.45 + Name="VCCLCompilerTool"
3.46 + Optimization="0"
3.47 + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;UPDATE_TOOL_EXPORTS;_CRT_SECURE_NO_DEPRECATE;_CRT_STD_NO_DEPRECATE"
3.48 + MinimalRebuild="true"
3.49 + BasicRuntimeChecks="3"
3.50 + RuntimeLibrary="1"
3.51 + UsePrecompiledHeader="0"
3.52 + WarningLevel="3"
3.53 + Detect64BitPortabilityProblems="true"
3.54 + DebugInformationFormat="4"
3.55 + />
3.56 + <Tool
3.57 + Name="VCManagedResourceCompilerTool"
3.58 + />
3.59 + <Tool
3.60 + Name="VCResourceCompilerTool"
3.61 + />
3.62 + <Tool
3.63 + Name="VCPreLinkEventTool"
3.64 + />
3.65 + <Tool
3.66 + Name="VCLinkerTool"
3.67 + AdditionalDependencies="..\obj\api_link.obj"
3.68 + OutputFile="$(OutDir)\sourcemm_update_tool.dll"
3.69 + LinkIncremental="2"
3.70 + GenerateDebugInformation="true"
3.71 + SubSystem="2"
3.72 + TargetMachine="1"
3.73 + />
3.74 + <Tool
3.75 + Name="VCALinkTool"
3.76 + />
3.77 + <Tool
3.78 + Name="VCManifestTool"
3.79 + />
3.80 + <Tool
3.81 + Name="VCXDCMakeTool"
3.82 + />
3.83 + <Tool
3.84 + Name="VCBscMakeTool"
3.85 + />
3.86 + <Tool
3.87 + Name="VCFxCopTool"
3.88 + />
3.89 + <Tool
3.90 + Name="VCAppVerifierTool"
3.91 + />
3.92 + <Tool
3.93 + Name="VCWebDeploymentTool"
3.94 + />
3.95 + <Tool
3.96 + Name="VCPostBuildEventTool"
3.97 + />
3.98 + </Configuration>
3.99 + <Configuration
3.100 + Name="Release|Win32"
3.101 + OutputDirectory="$(SolutionDir)$(ConfigurationName)"
3.102 + IntermediateDirectory="$(ConfigurationName)"
3.103 + ConfigurationType="2"
3.104 + CharacterSet="1"
3.105 + WholeProgramOptimization="1"
3.106 + >
3.107 + <Tool
3.108 + Name="VCPreBuildEventTool"
3.109 + CommandLine="nasmw ..\api_link.asm -f win32 -o ..\obj\api_link.obj -DWIN32"
3.110 + />
3.111 + <Tool
3.112 + Name="VCCustomBuildTool"
3.113 + />
3.114 + <Tool
3.115 + Name="VCXMLDataGeneratorTool"
3.116 + />
3.117 + <Tool
3.118 + Name="VCWebServiceProxyGeneratorTool"
3.119 + />
3.120 + <Tool
3.121 + Name="VCMIDLTool"
3.122 + />
3.123 + <Tool
3.124 + Name="VCCLCompilerTool"
3.125 + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;UPDATE_TOOL_EXPORTS;_CRT_SECURE_NO_DEPRECATE"
3.126 + RuntimeLibrary="0"
3.127 + UsePrecompiledHeader="0"
3.128 + WarningLevel="3"
3.129 + Detect64BitPortabilityProblems="true"
3.130 + DebugInformationFormat="3"
3.131 + />
3.132 + <Tool
3.133 + Name="VCManagedResourceCompilerTool"
3.134 + />
3.135 + <Tool
3.136 + Name="VCResourceCompilerTool"
3.137 + />
3.138 + <Tool
3.139 + Name="VCPreLinkEventTool"
3.140 + />
3.141 + <Tool
3.142 + Name="VCLinkerTool"
3.143 + AdditionalDependencies="..\obj\api_link.obj"
3.144 + OutputFile="$(OutDir)\sourcemm_update_tool.dll"
3.145 + LinkIncremental="1"
3.146 + GenerateDebugInformation="true"
3.147 + SubSystem="2"
3.148 + OptimizeReferences="2"
3.149 + EnableCOMDATFolding="2"
3.150 + TargetMachine="1"
3.151 + />
3.152 + <Tool
3.153 + Name="VCALinkTool"
3.154 + />
3.155 + <Tool
3.156 + Name="VCManifestTool"
3.157 + />
3.158 + <Tool
3.159 + Name="VCXDCMakeTool"
3.160 + />
3.161 + <Tool
3.162 + Name="VCBscMakeTool"
3.163 + />
3.164 + <Tool
3.165 + Name="VCFxCopTool"
3.166 + />
3.167 + <Tool
3.168 + Name="VCAppVerifierTool"
3.169 + />
3.170 + <Tool
3.171 + Name="VCWebDeploymentTool"
3.172 + />
3.173 + <Tool
3.174 + Name="VCPostBuildEventTool"
3.175 + />
3.176 + </Configuration>
3.177 + </Configurations>
3.178 + <References>
3.179 + </References>
3.180 + <Files>
3.181 + <Filter
3.182 + Name="Source Files"
3.183 + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
3.184 + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
3.185 + >
3.186 + <File
3.187 + RelativePath="..\update_tool.cpp"
3.188 + >
3.189 + </File>
3.190 + </Filter>
3.191 + <Filter
3.192 + Name="Header Files"
3.193 + Filter="h;hpp;hxx;hm;inl;inc;xsd"
3.194 + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
3.195 + >
3.196 + </Filter>
3.197 + <Filter
3.198 + Name="Resource Files"
3.199 + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
3.200 + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
3.201 + >
3.202 + </Filter>
3.203 + </Files>
3.204 + <Globals>
3.205 + </Globals>
3.206 +</VisualStudioProject>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/update_tool/update_tool.cpp Sat Mar 31 16:23:19 2007 +0000
4.3 @@ -0,0 +1,230 @@
4.4 +#include <stdio.h>
4.5 +#include <stdarg.h>
4.6 +#include <string.h>
4.7 +#include <ctype.h>
4.8 +
4.9 +extern "C" void GetGameDir(char *buffer, int maxlength);
4.10 +extern "C" void *GetThisPointer();
4.11 +
4.12 +#if defined _MSC_VER
4.13 +#define SEPCHAR "\\"
4.14 +#define MMPATH "|gameinfo_path|addons\\metamod\\bin"
4.15 +#define WINDOWS_LEAN_AND_MEAN
4.16 +#include <windows.h>
4.17 +#elif defined __linux__
4.18 +#define SEPCHAR "/"
4.19 +#define MMPATH "|gameinfo_path|addons/metamod/bin"
4.20 +#include <unistd.h>
4.21 +#endif
4.22 +
4.23 +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
4.24 +bool s_isspace(char c);
4.25 +bool RenameFile(const char *old, const char *newf);
4.26 +
4.27 +/* This will be called by the thunk */
4.28 +#if defined _MSC_VER
4.29 +extern "C" void LoadFunction()
4.30 +#elif defined __linux__
4.31 +extern "C" void _LoadFunction()
4.32 +#endif
4.33 +{
4.34 + char gamedir[260];
4.35 +
4.36 + GetGameDir(gamedir, sizeof(gamedir));
4.37 +
4.38 + char old_path[260];
4.39 + char new_path[260];
4.40 +
4.41 + UTIL_Format(old_path, sizeof(old_path), "%s" SEPCHAR "gameinfo.txt", gamedir);
4.42 + UTIL_Format(new_path, sizeof(new_path), "%s" SEPCHAR "gameinfo.new.txt", gamedir);
4.43 +
4.44 + FILE *fp = fopen(old_path, "rt");
4.45 +
4.46 + if (!fp)
4.47 + {
4.48 + return;
4.49 + }
4.50 +
4.51 + FILE *op = fopen(new_path, "wt");
4.52 + if (!op)
4.53 + {
4.54 + fclose(fp);
4.55 + return;
4.56 + }
4.57 +
4.58 + enum ParseState
4.59 + {
4.60 + Parse_None,
4.61 + Parse_Root,
4.62 + Parse_GameInfo,
4.63 + Parse_FileSystem,
4.64 + Parse_SearchPaths,
4.65 + };
4.66 +
4.67 + ParseState ps = Parse_Root;
4.68 +
4.69 + char input[1024];
4.70 + char backup[1024];
4.71 +
4.72 + while (!feof(fp) && fgets(input, sizeof(input), fp) != NULL)
4.73 + {
4.74 + UTIL_Format(backup, sizeof(backup), "%s", input);
4.75 +
4.76 + if (ps != Parse_None)
4.77 + {
4.78 + char *inbuf = input;
4.79 +
4.80 + /* Strip beginning whitespace */
4.81 + while (*inbuf != '\0' && s_isspace(*inbuf))
4.82 + {
4.83 + inbuf++;
4.84 + }
4.85 +
4.86 + /* Strip ending whitespace */
4.87 + size_t len = strlen(inbuf);
4.88 + for (size_t i = len - 1;
4.89 + i >= 0 && i < len;
4.90 + i--)
4.91 + {
4.92 + if (s_isspace(inbuf[i]))
4.93 + {
4.94 + inbuf[i] = '\0';
4.95 + len--;
4.96 + } else {
4.97 + break;
4.98 + }
4.99 + }
4.100 +
4.101 + /* Strip quotation marks */
4.102 + if (inbuf[0] == '"'
4.103 + && inbuf[len-1] == '"')
4.104 + {
4.105 + inbuf[len - 1] = '\0';
4.106 + inbuf = &inbuf[1];
4.107 + len -= 2;
4.108 + }
4.109 +
4.110 + /* Do tests */
4.111 + if (ps == Parse_Root && strcmp(inbuf, "GameInfo") == 0)
4.112 + {
4.113 + ps = Parse_GameInfo;
4.114 + } else if (ps == Parse_GameInfo && strcmp(inbuf, "FileSystem") == 0) {
4.115 + ps = Parse_FileSystem;
4.116 + } else if (ps == Parse_FileSystem && strcmp(inbuf, "SearchPaths") == 0) {
4.117 + ps = Parse_SearchPaths;
4.118 + } else if (ps == Parse_SearchPaths) {
4.119 + const char *game = strstr(inbuf, "Game");
4.120 + if (game)
4.121 + {
4.122 + if (strstr(game, "GameBin") != NULL
4.123 + && strstr(game, MMPATH) != NULL)
4.124 + {
4.125 + fclose(op);
4.126 + op = NULL;
4.127 + break; /* Nothing more to do! */
4.128 + } else {
4.129 + fputs("\t\t\t\tGameBin\t\t" MMPATH "\n", op);
4.130 + ps = Parse_None;
4.131 + }
4.132 + }
4.133 + }
4.134 + }
4.135 +
4.136 + fputs(backup, op);
4.137 + }
4.138 +
4.139 + if (!op)
4.140 + {
4.141 + /* Well, we can't really do anything else. Give up. */
4.142 + fclose(fp);
4.143 + return;
4.144 + }
4.145 +
4.146 + /* Close all streams */
4.147 + fclose(op);
4.148 + fclose(fp);
4.149 +
4.150 + /* Move the old file to a backup name */
4.151 + char backup_name[260];
4.152 + UTIL_Format(backup_name, sizeof(backup_name), "%s" SEPCHAR "gameinfo.backup.txt", gamedir);
4.153 +
4.154 + if (!RenameFile(old_path, backup_name))
4.155 + {
4.156 + /* If we can't rename, just bail out.
4.157 + * We don't want to overwrite the client's default
4.158 + * without backing it up first!
4.159 + */
4.160 + return;
4.161 + }
4.162 + if (!RenameFile(new_path, old_path))
4.163 + {
4.164 + /* Since this failed, we really have no choice.
4.165 + * Try and rename the old back.
4.166 + */
4.167 + RenameFile(backup_name, old_path);
4.168 + return;
4.169 + }
4.170 +#if defined _MSC_VER
4.171 + _unlink(new_path);
4.172 +#else
4.173 + unlink(new_path);
4.174 +#endif
4.175 +}
4.176 +
4.177 +bool s_isspace(char c)
4.178 +{
4.179 + if ((unsigned)c & 0x80)
4.180 + {
4.181 + return false;
4.182 + } else {
4.183 + return isspace(c) ? true : false;
4.184 + }
4.185 +}
4.186 +
4.187 +size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
4.188 +{
4.189 + va_list ap;
4.190 +
4.191 + va_start(ap, fmt);
4.192 + size_t len = vsnprintf(buffer, maxlength, fmt, ap);
4.193 + va_end(ap);
4.194 +
4.195 + if (len >= maxlength)
4.196 + {
4.197 + len = maxlength - 1;
4.198 + buffer[len] = '\0';
4.199 + }
4.200 +
4.201 + return len;
4.202 +}
4.203 +
4.204 +bool RenameFile(const char *old, const char *newf)
4.205 +{
4.206 +#if defined __linux__
4.207 + return (rename(old, newf) == 0);
4.208 +#elif defined WIN32
4.209 + return (MoveFileA(old, newf) != 0);
4.210 +#endif
4.211 +}
4.212 +
4.213 +#if defined _MSC_VER
4.214 +extern "C" __declspec(dllexport) void *CreateInterface(const char *iface, int *ret)
4.215 +#elif defined __linux__
4.216 +extern "C" __attribute__((visibility("default"))) void *CreateInterface(const char *iface, int *ret)
4.217 +#endif
4.218 +{
4.219 + if (strcmp(iface, "ISERVERPLUGINCALLBACKS001") == 0)
4.220 + {
4.221 + if (ret)
4.222 + {
4.223 + *ret = 0;
4.224 + }
4.225 + return GetThisPointer();
4.226 + }
4.227 +
4.228 + if (ret)
4.229 + {
4.230 + *ret = 1;
4.231 + }
4.232 + return NULL;
4.233 +}