update_tool/api_link.asm
author David Anderson <dvander@alliedmods.net>
Thu Apr 05 17:51:23 2007 +0000 (2007-04-05)
changeset 305 539f25c00858
parent 301 659940583dc3
child 307 f96e6461132b
permissions -rw-r--r--
added cvar detection for MM:S
fixed a gameinfo.txt writing bug
removed obj folder from local build
     1 ;;;;
     2 ;; (C)2005-2007 AlliedModders LLC
     3 ;; By the Metamod:Source Development Team
     4 ;; This software is licensed under the zlib/libpng free software license.
     5 ;;
     6 ;; This assembly file is a short thunk wrapper to let us load as a VSP and exit quietly,
     7 ;; without any overhead of the rest of the interface, and also to prevent linking against
     8 ;; tierX or vstdlib
     9 ;;;;
    10 
    11 ;;Exports:
    12 ;; void GetBaseDir(char *buffer, maxlength);
    13 ;; void *GetThisPointer();
    14 ;;Imports:
    15 ;; void LoadFunction();
    16 
    17 section .text
    18 
    19 global GetThisPointer, GetGameDir, ServerCommand
    20 global _GetThisPointer, _GetGameDir, _ServerCommand
    21 global _GetICvar
    22 extern _LoadFunction
    23 
    24 _GetICvar
    25 	mov 	eax, [icvar]
    26 	ret
    27 
    28 GetThisPointer:
    29 _GetThisPointer:
    30 	mov		eax, GLOBAL_POINTER
    31 	ret
    32 	
    33 GetGameDir:
    34 _GetGameDir:
    35 	push	ebp
    36 	mov		ebp, esp			
    37 	
    38 	mov		ecx, [engine]		;get this pointer
    39 	mov		edx, [ecx]			;get the vtable
    40 	push	dword [ebp+12]		;push maxlenth
    41 	push	dword [ebp+8]		;push buffer
    42 	%ifdef LINUX
    43 	push	ecx					;push this pointer
    44 	%endif
    45 	call	dword [edx+216]		;call IVEngineServer::GetGameDir
    46 	%ifdef LINUX
    47 	add		esp, 12				;correct stack
    48 	%endif
    49 	
    50 	pop 	ebp
    51 	ret
    52 	
    53 ServerCommand
    54 _ServerCommand:
    55 	push	ebp
    56 	mov		ebp, esp
    57 	
    58 	mov		ecx, [engine]		;get this pointer
    59 	mov		edx, [ecx]			;get the vtable
    60 	push	dword [ebp+8]		;push string
    61 	%ifdef LINUX
    62 	push	ecx					;push this pointer
    63 	%endif
    64 	call	dword [edx+144]		;call IVEngineServer::ServerCommand
    65 	%ifdef LINUX
    66 	add		esp, 8				;correct stack
    67 	%endif
    68 	
    69 	pop		ebp
    70 	ret
    71 	
    72 thisLoadFunction:
    73 	push	ebp
    74 	mov		ebp, esp
    75 	
    76 	push	edi
    77 	
    78 	;get factory
    79 	%ifdef LINUX
    80 	mov		edi, [ebp+12]
    81 	%else
    82 	mov		edi, [ebp+8]
    83 	%endif
    84 	
    85 	push	dword 0				;NULL
    86 	push	dword VENGINESERVER	;iface name
    87 	call	edi					;call factory
    88 	add		esp, 8				;correct stack
    89 	
    90 	test	eax, eax			;do we have a valid pointer?
    91 	jz		.end				;no, bail out
    92 	
    93 	mov		[engine], eax		;store the engine pointer
    94 	
    95 	push	dword 0				;NULL
    96 	push	dword VENGINECVAR	;iface name
    97 	call	edi					;call factory
    98 	add		esp, 8				;correct stack
    99 	
   100 	test	eax, eax			;do we have a valid pointer?
   101 	jz		.end				;no, bail out
   102 	
   103 	mov		[icvar], eax		;store the icvar pointer
   104 	
   105 	call	_LoadFunction
   106 	
   107 .end:
   108 	;We never load, never ever ever!
   109 	xor		eax, eax
   110 	
   111 	pop		edi
   112 	
   113 	pop		ebp
   114 	%ifdef LINUX
   115 	ret
   116 	%else
   117 	retn	8
   118 	%endif
   119 	
   120 thisUnloadFunction:
   121 	ret
   122 	
   123 section .data
   124 	INTERFACE_NAME		DB		"ISERVERPLUGINCALLBACKS001", 0
   125 	VENGINESERVER		DB		"VEngineServer021", 0
   126 	VENGINECVAR			DB		"VEngineCvar003", 0
   127 	
   128 	VIRTUAL_TABLE		DD		thisLoadFunction
   129 						DD		thisUnloadFunction
   130 						;We don't need any more of the vtable here
   131 								
   132 	GLOBAL_POINTER		DD		VIRTUAL_TABLE
   133 
   134 	temp_ret			DD		0
   135 	temp_ptr			DD		temp_ret
   136 	engine				DD		0
   137 	icvar				DD		0