update_tool/api_link.asm
author David Anderson <dvander@alliedmods.net>
Thu Sep 27 19:28:30 2007 +0000 (2007-09-27)
branchsourcemm-1.6.0
changeset 357 1319b9ef1c8a
parent 347 e82968c21606
permissions -rw-r--r--
initial import of the provider layout for ep1
     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, GetICvar
    22 extern _LoadFunction
    23 
    24 GetICvar:
    25 _GetICvar:
    26 	mov 	eax, [icvar]
    27 	ret
    28 
    29 GetThisPointer:
    30 _GetThisPointer:
    31 	mov		eax, GLOBAL_POINTER
    32 	ret
    33 	
    34 GetGameDir:
    35 _GetGameDir:
    36 	push	ebp
    37 	mov		ebp, esp			
    38 	
    39 	mov		ecx, [engine]		;get this pointer
    40 	mov		edx, [ecx]			;get the vtable
    41 	push	dword [ebp+12]		;push maxlenth
    42 	push	dword [ebp+8]		;push buffer
    43 	%ifdef LINUX
    44 	push	ecx					;push this pointer
    45 	%endif
    46 	call	dword [edx+216]		;call IVEngineServer::GetGameDir
    47 	%ifdef LINUX
    48 	add		esp, 12				;correct stack
    49 	%endif
    50 	
    51 	pop 	ebp
    52 	ret
    53 	
    54 ServerCommand
    55 _ServerCommand:
    56 	push	ebp
    57 	mov		ebp, esp
    58 	
    59 	mov		ecx, [engine]		;get this pointer
    60 	mov		edx, [ecx]			;get the vtable
    61 	push	dword [ebp+8]		;push string
    62 	%ifdef LINUX
    63 	push	ecx					;push this pointer
    64 	%endif
    65 	call	dword [edx+144]		;call IVEngineServer::ServerCommand
    66 	%ifdef LINUX
    67 	add		esp, 8				;correct stack
    68 	%endif
    69 	
    70 	pop		ebp
    71 	ret
    72 	
    73 thisLoadFunction:
    74 	push	ebp
    75 	mov		ebp, esp
    76 	
    77 	push	edi
    78 	
    79 	;get factory
    80 	%ifdef LINUX
    81 	mov		edi, [ebp+12]
    82 	%else
    83 	mov		edi, [ebp+8]
    84 	%endif
    85 	
    86 	push	dword 0				;NULL
    87 	push	dword VENGINESERVER	;iface name
    88 	call	edi					;call factory
    89 	add		esp, 8				;correct stack
    90 	
    91 	test	eax, eax			;do we have a valid pointer?
    92 	jz		.end				;no, bail out
    93 	
    94 	mov		[engine], eax		;store the engine pointer
    95 	
    96 	push	dword 0				;NULL
    97 	push	dword VENGINECVAR	;iface name
    98 	call	edi					;call factory
    99 	add		esp, 8				;correct stack
   100 	
   101 	test	eax, eax			;do we have a valid pointer?
   102 	jz		.end				;no, bail out
   103 	
   104 	mov		[icvar], eax		;store the icvar pointer
   105 	
   106 	call	_LoadFunction
   107 	
   108 .end:
   109 	;We never load, never ever ever!
   110 	xor		eax, eax
   111 	
   112 	pop		edi
   113 	
   114 	pop		ebp
   115 	%ifdef LINUX
   116 	ret
   117 	%else
   118 	retn	8
   119 	%endif
   120 	
   121 thisUnloadFunction:
   122 	ret
   123 	
   124 section .data
   125 	INTERFACE_NAME		DB		"ISERVERPLUGINCALLBACKS001", 0
   126 	VENGINESERVER		DB		"VEngineServer021", 0
   127 	VENGINECVAR			DB		"VEngineCvar003", 0
   128 	
   129 	VIRTUAL_TABLE		DD		thisLoadFunction
   130 						DD		thisUnloadFunction
   131 						;We don't need any more of the vtable here
   132 								
   133 	GLOBAL_POINTER		DD		VIRTUAL_TABLE
   134 
   135 	temp_ret			DD		0
   136 	temp_ptr			DD		temp_ret
   137 	engine				DD		0
   138 	icvar				DD		0