added cvar detection for MM:S

fixed a gameinfo.txt writing bug
removed obj folder from local build

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40359
This commit is contained in:
David Anderson 2007-04-05 17:51:23 +00:00
parent 69be233d2c
commit 05e09416ef
4 changed files with 92 additions and 16 deletions

View File

@ -16,10 +16,15 @@
section .text section .text
global GetThisPointer, GetGameDir global GetThisPointer, GetGameDir, ServerCommand
global _GetThisPointer, _GetGameDir global _GetThisPointer, _GetGameDir, _ServerCommand
global _GetICvar
extern _LoadFunction extern _LoadFunction
_GetICvar
mov eax, [icvar]
ret
GetThisPointer: GetThisPointer:
_GetThisPointer: _GetThisPointer:
mov eax, GLOBAL_POINTER mov eax, GLOBAL_POINTER
@ -45,20 +50,41 @@ _GetGameDir:
pop ebp pop ebp
ret ret
ServerCommand
_ServerCommand:
push ebp
mov ebp, esp
mov ecx, [engine] ;get this pointer
mov edx, [ecx] ;get the vtable
push dword [ebp+8] ;push string
%ifdef LINUX
push ecx ;push this pointer
%endif
call dword [edx+144] ;call IVEngineServer::ServerCommand
%ifdef LINUX
add esp, 8 ;correct stack
%endif
pop ebp
ret
thisLoadFunction: thisLoadFunction:
push ebp push ebp
mov ebp, esp mov ebp, esp
push edi
;get factory ;get factory
%ifdef LINUX %ifdef LINUX
mov eax, [ebp+12] mov edi, [ebp+12]
%else %else
mov eax, [ebp+8] mov edi, [ebp+8]
%endif %endif
push dword 0 ;NULL push dword 0 ;NULL
push dword VENGINESERVER ;iface name push dword VENGINESERVER ;iface name
call eax ;call factory call edi ;call factory
add esp, 8 ;correct stack add esp, 8 ;correct stack
test eax, eax ;do we have a valid pointer? test eax, eax ;do we have a valid pointer?
@ -66,11 +92,24 @@ thisLoadFunction:
mov [engine], eax ;store the engine pointer mov [engine], eax ;store the engine pointer
push dword 0 ;NULL
push dword VENGINECVAR ;iface name
call edi ;call factory
add esp, 8 ;correct stack
test eax, eax ;do we have a valid pointer?
jz .end ;no, bail out
mov [icvar], eax ;store the icvar pointer
call _LoadFunction call _LoadFunction
.end: .end:
;We never load, never ever ever! ;We never load, never ever ever!
xor eax, eax xor eax, eax
pop edi
pop ebp pop ebp
%ifdef LINUX %ifdef LINUX
ret ret
@ -84,6 +123,7 @@ thisUnloadFunction:
section .data section .data
INTERFACE_NAME DB "ISERVERPLUGINCALLBACKS001", 0 INTERFACE_NAME DB "ISERVERPLUGINCALLBACKS001", 0
VENGINESERVER DB "VEngineServer021", 0 VENGINESERVER DB "VEngineServer021", 0
VENGINECVAR DB "VEngineCvar003", 0
VIRTUAL_TABLE DD thisLoadFunction VIRTUAL_TABLE DD thisLoadFunction
DD thisUnloadFunction DD thisUnloadFunction
@ -94,3 +134,4 @@ section .data
temp_ret DD 0 temp_ret DD 0
temp_ptr DD temp_ret temp_ptr DD temp_ret
engine DD 0 engine DD 0
icvar DD 0

View File

@ -24,7 +24,7 @@
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
CommandLine="nasmw ..\api_link.asm -f win32 -o &quot;$(OutDir)\api_link.obj&quot; -DWIN32" CommandLine="nasmw ..\api_link.asm -f win32 -oDebug\api_link.obj -DWIN32"
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
@ -61,7 +61,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="&quot;$(OutDir)\api_link.obj&quot;" AdditionalDependencies="Debug\api_link.obj tier0.lib"
OutputFile="$(OutDir)\sourcemm_update_tool.dll" OutputFile="$(OutDir)\sourcemm_update_tool.dll"
LinkIncremental="2" LinkIncremental="2"
GenerateDebugInformation="true" GenerateDebugInformation="true"
@ -103,7 +103,7 @@
> >
<Tool <Tool
Name="VCPreBuildEventTool" Name="VCPreBuildEventTool"
CommandLine="nasmw ..\api_link.asm -f win32 -o &quot;$(OutDir)\api_link.obj&quot; -DWIN32" CommandLine="nasmw ..\api_link.asm -f win32 -oRelease\api_link.obj -DWIN32"
/> />
<Tool <Tool
Name="VCCustomBuildTool" Name="VCCustomBuildTool"
@ -137,7 +137,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="&quot;$(OutDir)\api_link.obj&quot;" AdditionalDependencies="Release\api_link.obj"
OutputFile="$(OutDir)\sourcemm_update_tool.dll" OutputFile="$(OutDir)\sourcemm_update_tool.dll"
LinkIncremental="1" LinkIncremental="1"
GenerateDebugInformation="true" GenerateDebugInformation="true"

View File

@ -0,0 +1,6 @@
//This is a sample VDF file. You need to edit "cstrike" to point to the mod you use.
"Plugin"
{
"file" "cstrike/addons/sourcemm_update_tool"
}

View File

@ -3,9 +3,6 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
extern "C" void GetGameDir(char *buffer, int maxlength);
extern "C" void *GetThisPointer();
#if defined _MSC_VER #if defined _MSC_VER
#define SEPCHAR "\\" #define SEPCHAR "\\"
#define MMPATH "addons\\metamod\\bin" #define MMPATH "addons\\metamod\\bin"
@ -17,9 +14,17 @@ extern "C" void *GetThisPointer();
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <icvar.h>
extern "C" void GetGameDir(char *buffer, int maxlength);
extern "C" void *GetThisPointer();
extern "C" void ServerCommand(const char *command);
extern "C" ICvar *GetICvar();
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...); size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
bool s_isspace(char c); bool s_isspace(char c);
bool RenameFile(const char *old, const char *newf); bool RenameFile(const char *old, const char *newf);
bool RemoveFile(const char *file);
/* This will be called by the thunk */ /* This will be called by the thunk */
#if defined _MSC_VER #if defined _MSC_VER
@ -28,6 +33,13 @@ extern "C" void LoadFunction()
extern "C" void _LoadFunction() extern "C" void _LoadFunction()
#endif #endif
{ {
ICvar *pCvar = GetICvar();
if (pCvar->FindVar("metamod_version") != NULL)
{
/* Already exists, bail out */
return;
}
char gamedir[260]; char gamedir[260];
char mmpath[260]; char mmpath[260];
@ -142,6 +154,8 @@ extern "C" void _LoadFunction()
char input[1024]; char input[1024];
char backup[1024]; char backup[1024];
bool bWroteOutput = false;
while (!feof(fp) && fgets(input, sizeof(input), fp) != NULL) while (!feof(fp) && fgets(input, sizeof(input), fp) != NULL)
{ {
UTIL_Format(backup, sizeof(backup), "%s", input); UTIL_Format(backup, sizeof(backup), "%s", input);
@ -199,10 +213,11 @@ extern "C" void _LoadFunction()
op = NULL; op = NULL;
break; /* Nothing more to do! */ break; /* Nothing more to do! */
} else { } else {
fputs("\t\t\tGameBin\t\t\t|gameinfo_path|", op); fputs("\t\t\tGameBin\t\t\t", op);
fputs(mmpath, op); fputs(mmpath, op);
fputs("\n", op); fputs("\n", op);
ps = Parse_None; ps = Parse_None;
bWroteOutput = true;
} }
} }
} }
@ -222,6 +237,13 @@ extern "C" void _LoadFunction()
fclose(op); fclose(op);
fclose(fp); fclose(fp);
/* If we didn't change anything, abort here */
if (!bWroteOutput)
{
RemoveFile(new_path);
return;
}
/* Move the old file to a backup name */ /* Move the old file to a backup name */
char backup_name[260]; char backup_name[260];
UTIL_Format(backup_name, sizeof(backup_name), "%s" SEPCHAR "gameinfo.backup.txt", gamedir); UTIL_Format(backup_name, sizeof(backup_name), "%s" SEPCHAR "gameinfo.backup.txt", gamedir);
@ -242,10 +264,17 @@ extern "C" void _LoadFunction()
RenameFile(backup_name, old_path); RenameFile(backup_name, old_path);
return; return;
} }
RemoveFile(new_path);
Error("Server is restarting to load Metamod:Source");
}
bool RemoveFile(const char *file)
{
#if defined _MSC_VER #if defined _MSC_VER
_unlink(new_path); return (_unlink(file) == 0);
#else #else
unlink(new_path); return (unlink(file) == 0);
#endif #endif
} }