reformatted file a bit

This commit is contained in:
David Anderson 2006-02-14 16:57:44 +00:00
parent f1a4cfee61
commit 13360bec73
4 changed files with 203 additions and 217 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@ MM_ROOT = ../metamod/metamod
### EDIT BELOW FOR OTHER PROJECTS ### ### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O2 -funroll-loops -s -pipe OPT_FLAGS = -O2 -funroll-loops -s -fomit-frame-pointer -pipe
DEBUG_FLAGS = -g -ggdb3 DEBUG_FLAGS = -g -ggdb3
CPP = gcc CPP = gcc
NAME = amxmodx_mm NAME = amxmodx_mm

View File

@ -3602,15 +3602,6 @@ static cell AMX_NATIVE_CALL amx_abort(AMX *amx, cell *params)
return 1; return 1;
} }
static cell AMX_NATIVE_CALL get_tick_count(AMX *amx, cell *params)
{
#if defined WIN32
return GetTickCount();
#else
return 0;
#endif
}
static cell AMX_NATIVE_CALL module_exists(AMX *amx, cell *params) static cell AMX_NATIVE_CALL module_exists(AMX *amx, cell *params)
{ {
int len; int len;
@ -3844,7 +3835,6 @@ AMX_NATIVE_INFO amxmodx_Natives[] =
{"get_systime", get_systime}, {"get_systime", get_systime},
{"get_time", get_time}, {"get_time", get_time},
{"get_timeleft", get_timeleft}, {"get_timeleft", get_timeleft},
{"get_tick_count", get_tick_count},
{"get_user_aiming", get_user_aiming}, {"get_user_aiming", get_user_aiming},
{"get_user_ammo", get_user_ammo}, {"get_user_ammo", get_user_ammo},
{"get_user_armor", get_user_armor}, {"get_user_armor", get_user_armor},

View File

@ -24,20 +24,20 @@ global init_format_jumps, _init_format_jumps
init_format_jumps: init_format_jumps:
_init_format_jumps: _init_format_jumps:
push ebp push ebp
mov ebp, esp mov ebp, esp
lea edx, [g_jumptbl] lea edx, [g_jumptbl]
mov [edx+'c'*4], dword format_parameter.fmt_num mov [edx+'c'*4], dword format_parameter.fmt_num
mov [edx+'d'*4], dword format_parameter.fmt_num mov [edx+'d'*4], dword format_parameter.fmt_num
mov [edx+'f'*4], dword format_parameter.fmt_float mov [edx+'f'*4], dword format_parameter.fmt_float
mov [edx+'g'*4], dword format_parameter.fmt_float mov [edx+'g'*4], dword format_parameter.fmt_float
mov [edx+'i'*4], dword format_parameter.fmt_num mov [edx+'i'*4], dword format_parameter.fmt_num
mov [edx+'L'*4], dword format_parameter.fmt_ml mov [edx+'L'*4], dword format_parameter.fmt_ml
mov [edx+'p'*4], dword format_parameter.fmt_ptr mov [edx+'p'*4], dword format_parameter.fmt_ptr
mov [edx+'s'*4], dword format_parameter.fmt_string mov [edx+'s'*4], dword format_parameter.fmt_string
mov [edx+'x'*4], dword format_parameter.fmt_num mov [edx+'x'*4], dword format_parameter.fmt_num
pop ebp pop ebp
ret ret
@ -54,199 +54,199 @@ _init_format_jumps:
; esi - lexptr (given) ; esi - lexptr (given)
format_parameter: format_parameter:
push ebp push ebp
mov ebp, esp mov ebp, esp
push edi push edi
push ebx push ebx
;len=30 ;len=30
mov ecx, 30 mov ecx, 30
;edi=char[32] (+1 for offset) ;edi=char[32] (+1 for offset)
sub esp, 32 sub esp, 32
mov [esp], byte '%' mov [esp], byte '%'
lea edi, [esp+1] lea edi, [esp+1]
;esi=lexptr already ;esi=lexptr already
;eax=*lexptr ;eax=*lexptr
xor eax, eax xor eax, eax
mov al, [esi] mov al, [esi]
test al, al test al, al
jz .abort jz .abort
;ebx=g_chartbl ;ebx=g_chartbl
lea ebx, [g_chartbl] lea ebx, [g_chartbl]
;start looping ;start looping
.fmtloop .fmtloop
mov edx, [ebx+eax*4];get char flag mov edx, [ebx+eax*4] ;get char flag
test edx, edx ;is it zero? test edx, edx ;is it zero?
jnz .fmtdone ;yes, we've got a format code jnz .fmtdone ;yes, we've got a format code
test ecx, ecx ;are we over maxlen? test ecx, ecx ;are we over maxlen?
jz .fmtdone ;yes, dump out jz .fmtdone ;yes, dump out
mov [edi], al ;copy into destination mov [edi], al ;copy into destination
inc edi ;dest++ inc edi ;dest++
inc esi ;src++ inc esi ;src++
dec ecx ;len-- dec ecx ;len--
mov al, [esi] ;get next char mov al, [esi] ;get next char
test al, al ;is it zero? test al, al ;is it zero?
jnz .fmtloop ;no, continue jnz .fmtloop ;no, continue
.fmtdone: .fmtdone:
;if there's no control code, we dumped out. ;if there's no control code, we dumped out.
;just abort in that case. ;just abort in that case.
test al, al test al, al
jz .abort jz .abort
;terminate fmtptr ;terminate fmtptr
mov [edi], al mov [edi], al
mov [edi+1], byte 0 mov [edi+1], byte 0
;sto fmtsrc back ;sto fmtsrc back
inc esi inc esi
;get output ptr ;get output ptr
mov edi, [ebp-4] mov edi, [ebp-4]
lea ebx, [g_jumptbl] lea ebx, [g_jumptbl]
jmp [ebx+eax*4] ;LOLolOLoL. jmp [ebx+eax*4] ;LOLolOLoL.
.fmt_string .fmt_string
;check parameter count ;check parameter count
mov ebx, [ebp+12] ;params mov ebx, [ebp+12] ;params
mov eax, [ebx] ;params[0] mov eax, [ebx] ;params[0]
shr eax, 2 ;params[0]/4 shr eax, 2 ;params[0]/4
mov edx, [ebp+16] ;param mov edx, [ebp+16] ;param
mov ecx, [edx] ;*param mov ecx, [edx] ;*param
cmp ecx, eax ;*param / params[0]/4 ? cmp ecx, eax ;*param / params[0]/4 ?
ja .error ja .error
;get the param - it's in eax ;get the param - it's in eax
add dword [edx], 1 add dword [edx], 1
mov eax, ebx mov eax, ebx
sub esp, 2048 sub esp, 2048
mov ebx, esp mov ebx, esp
push 2047 ;buffer size push 2047 ;buffer size
push ebx push ebx
push dword [eax+ecx*4] push dword [eax+ecx*4]
push dword [ebp+8] ;context push dword [ebp+8] ;context
call _get_amxstring_r call _get_amxstring_r
push ebx ;push buffer push ebx ;push buffer
lea ebx, [ebp-40] lea ebx, [ebp-40]
push ebx ;push format push ebx ;push format
push dword [ebp+28] ;push maxlen push dword [ebp+28] ;push maxlen
push edi ;push output push edi ;push output
call __snprintf call __snprintf
add esp, 4*8 add esp, 4*8
add esp, 2048 add esp, 2048
add edi, eax add edi, eax
jmp .end jmp .end
.fmt_num .fmt_num
;check parameter count ;check parameter count
mov ebx, [ebp+12] ;params mov ebx, [ebp+12] ;params
mov eax, [ebx] ;params[0] mov eax, [ebx] ;params[0]
shr eax, 2 ;params[0]/4 shr eax, 2 ;params[0]/4
mov edx, [ebp+16] ;param mov edx, [ebp+16] ;param
mov ecx, [edx] ;*param mov ecx, [edx] ;*param
cmp ecx, eax ;*param / params[0]/4 ? cmp ecx, eax ;*param / params[0]/4 ?
ja .error ja .error
;get the param - it's in eax ;get the param - it's in eax
add dword [edx], 1 ;incr *param add dword [edx], 1 ;incr *param
mov edx, [ebp+8] ;get AMX into edx mov edx, [ebp+8] ;get AMX into edx
mov edx, [edx] ;get AMX->base into edx mov edx, [edx] ;get AMX->base into edx
mov eax, [edx+16] ;get base->dat into eax mov eax, [edx+16] ;get base->dat into eax
add edx, eax ;add dat to base add edx, eax ;add dat to base
add edx, dword [ebx+ecx*4] ;add params[ecx] add edx, dword [ebx+ecx*4] ;add params[ecx]
push dword [edx] push dword [edx]
lea ebx, [ebp-40] lea ebx, [ebp-40]
push ebx push ebx
push dword [ebp+28] push dword [ebp+28]
push edi push edi
call __snprintf call __snprintf
add esp, 4*4 add esp, 4*4
add edi, eax add edi, eax
jmp .end jmp .end
.fmt_float .fmt_float
;check parameter count ;check parameter count
mov ebx, [ebp+12] ;params mov ebx, [ebp+12] ;params
mov eax, [ebx] ;params[0] mov eax, [ebx] ;params[0]
shr eax, 2 ;params[0]/4 shr eax, 2 ;params[0]/4
mov edx, [ebp+16] ;param mov edx, [ebp+16] ;param
mov ecx, [edx] ;*param mov ecx, [edx] ;*param
cmp ecx, eax ;*param / params[0]/4 ? cmp ecx, eax ;*param / params[0]/4 ?
ja .error ja .error
;get the param - it's in eax ;get the param - it's in eax
add dword [edx], 1 add dword [edx], 1
mov edx, [ebp+8] mov edx, [ebp+8]
mov edx, [edx] mov edx, [edx]
mov eax, [edx+16] mov eax, [edx+16]
add edx, eax add edx, eax
add edx, dword [ebx+ecx*4] add edx, dword [ebx+ecx*4]
;load the float, convert to double ;load the float, convert to double
fld dword [edx] fld dword [edx]
sub esp, 8 sub esp, 8
fstp qword [esp] fstp qword [esp]
;it's already on the stack now, push rest ;it's already on the stack now, push rest
lea ebx, [ebp-40] lea ebx, [ebp-40]
push ebx push ebx
push dword [ebp+28] push dword [ebp+28]
push edi push edi
call __snprintf call __snprintf
add esp, 4*5 add esp, 4*5
add edi, eax add edi, eax
jmp .end jmp .end
.fmt_ml .fmt_ml
mov ebx, [ebp+12] ;params mov ebx, [ebp+12] ;params
mov eax, [ebx] ;params[0] mov eax, [ebx] ;params[0]
shr eax, 2 ;params[0]/4 shr eax, 2 ;params[0]/4
mov edx, [ebp+16] ;param mov edx, [ebp+16] ;param
mov ecx, [edx] ;*param mov ecx, [edx] ;*param
inc ecx inc ecx
cmp ecx, eax ;*param / params[0]/4 ? cmp ecx, eax ;*param / params[0]/4 ?
ja .error ja .error
add dword [edx], 2 add dword [edx], 2
push ecx push ecx
push dword 0 ;NULL push dword 0 ;NULL
push dword 3 ;buffer 3 push dword 3 ;buffer 3
push dword [ebx+ecx*4] push dword [ebx+ecx*4]
push dword [ebp+8] push dword [ebp+8]
call _MNF_GetAmxString call _MNF_GetAmxString
add esp, 4*4 add esp, 4*4
pop ecx pop ecx
dec ecx dec ecx
push eax push eax
push eax ;key push eax ;key
push dword [ebx+ecx*4] ;lang_addr push dword [ebx+ecx*4] ;lang_addr
push dword [ebp+8] ;AMX push dword [ebp+8] ;AMX
call _translate call _translate
add esp, 4*3 add esp, 4*3
pop ecx pop ecx
test eax, eax test eax, eax
je .fmt_error je .fmt_error
;invoke the translator ;invoke the translator
;;store this on the stack so we can pass the address ;;store this on the stack so we can pass the address
push eax push eax
mov edx, esp mov edx, esp
push 1 ;no reparse ^ push 1 ;no reparse ^
push dword [ebp+20] ;maxlen push dword [ebp+20] ;maxlen
push edi ;output push edi ;output
push edx ;lexptr push edx ;lexptr
push dword [ebp+16] ;param push dword [ebp+16] ;param
push ebx ;params push ebx ;params
push dword [ebp+8] ;amx push dword [ebp+8] ;amx
call do_amx_format call do_amx_format
add esp, 4*8 add esp, 4*8
;we don't care about the return lex ;we don't care about the return lex
add edi, eax add edi, eax
jmp .end jmp .end
.fmt_error .fmt_error
push ecx push ecx
lea eax, [g_mlfmt] lea eax, [g_mlfmt]
push eax push eax
push dword [ebp+20] push dword [ebp+20]
push edi push edi
call __snprintf call __snprintf
add esp, 4*4 add esp, 4*4
add edi, eax add edi, eax
jmp .end jmp .end
.fmt_default .fmt_default
@ -260,17 +260,17 @@ format_parameter:
push 10 ;AMX_ERR_NATIVE push 10 ;AMX_ERR_NATIVE
push dword [ebp+8] push dword [ebp+8]
call _LogError call _LogError
add esp, 4*5 add esp, 4*5
.abort .abort
xor eax, eax xor eax, eax
.end .end
add esp, 32 add esp, 32
pop ebx pop ebx
pop ecx pop ecx
pop ebp pop ebp
ret ret
;size_t do_amx_format(AMX *amx, cell *params, int *param, const char **lex, char *output, size_t maxlen, int level) ;size_t do_amx_format(AMX *amx, cell *params, int *param, const char **lex, char *output, size_t maxlen, int level)
@ -285,138 +285,134 @@ _do_amx_format:
push edi ;output push edi ;output
;current esp offset is 12 (0=edi,4=esi,8=ret) ;current esp offset is 12 (0=edi,4=esi,8=ret)
mov esi, [esp+24] ;lex (dbl addr) mov esi, [esp+24] ;lex (dbl addr)
mov esi, [esi] mov esi, [esi]
mov edi, [esp+28] ;get output mov edi, [esp+28] ;get output
mov ecx, [esp+32] ;get maxlen mov ecx, [esp+32] ;get maxlen
;initial checks ;initial checks
mov al, [esi] mov al, [esi]
test al, al test al, al
jz .done jz .done
.loop: .loop:
test ecx, ecx test ecx, ecx
jz .done jz .done
cmp al, '%' cmp al, '%'
je .perc je .perc
cmp al, '^' cmp al, '^'
je .esc je .esc
.copy: .copy:
;*output++ = *lexptr++ ;*output++ = *lexptr++
mov [edi], al mov [edi], al
inc esi inc esi
inc edi inc edi
dec ecx dec ecx
.next .next
mov al, [esi] mov al, [esi]
test al, al test al, al
jz .done jnz .loop
jmp .loop jmp .done
;we got a '^' ;we got a '^'
.esc: .esc:
cmp dword [esp+36], 0 cmp dword [esp+36], 0
je .copy je .copy
inc esi inc esi
mov al, [esi] mov al, [esi]
cmp al, 'n' cmp al, 'n'
je .escn je .escn
cmp al, 't' cmp al, 't'
je .esct je .esct
;*outptr++ = *lexptr ;*outptr++ = *lexptr
mov [edi], al mov [edi], al
inc edi inc edi
;lexptr++ ;lexptr++
;maxlen-- ;maxlen--
.escdone .escdone
inc esi inc esi
dec ecx dec ecx
jmp .next jmp .next
.escn .escn
;*outptr++ = '\n' ;*outptr++ = '\n'
mov [edi], byte 0xA ;'\n' mov [edi], byte 0xA ;'\n'
inc edi inc edi
jmp .escdone jmp .escdone
.esct .esct
;*outptr++ = '\t' ;*outptr++ = '\t'
mov [edi], byte 0x9 ;'\t' mov [edi], byte 0x9 ;'\t'
inc edi inc edi
jmp .escdone jmp .escdone
;we got a '%' ;we got a '%'
.perc: .perc:
inc esi inc esi
mov al, [esi] mov al, [esi]
test al, al ;'\0' test al, al ;'\0'
je .percatend je .percatend
cmp al, '%' cmp al, '%'
je .percnone je .percnone
jmp .percfmt jmp .percfmt
.percatend .percatend
dec esi dec esi
add ecx, 1 add ecx, 1
.percnone: .percnone:
;*outptr++=*lexptr++; x2 ;*outptr++=*lexptr++; x2
;maxlen -= 2 ;maxlen -= 2
;note we recalculate eax and then ;note we recalculate eax and then
;only move once, since this is a 2byte move anyway. ;only move once, since this is a 2byte move anyway.
mov ax, [esi] mov ax, [esi]
mov [edi], ax mov [edi], ax
add esi, 2 add esi, 2
add edi, 2 add edi, 2
sub ecx, 2 sub ecx, 2
jmp .next jmp .next
.percfmt: .percfmt:
;call do_amx_format_parameter. ;call do_amx_format_parameter.
push ecx push ecx
push ecx ;maxlen push ecx ;maxlen
push dword [esp+28] ;param push dword [esp+28] ;param
push dword [esp+28] ;params push dword [esp+28] ;params
push dword [esp+28] ;amx push dword [esp+28] ;amx
call format_parameter ;will return edi adjusted for us call format_parameter ;will return edi adjusted for us
add esp, 4*4 ;will also return esi adjusted for us add esp, 4*4 ;will also return esi adjusted for us
pop ecx pop ecx
sub ecx, eax ;adjust maxlength sub ecx, eax ;adjust maxlength
mov al, [esi] ;reiterate mov al, [esi] ;reiterate
test al, al test al, al
jnz .loop jnz .loop
.done: .done:
;end the string ;end the string
mov [edi], dword 0 mov [edi], dword 0
mov edi, [esp+24] ;get lexptr ref mov edi, [esp+24] ;get lexptr ref
mov [edi], esi ;sto into lexptr ref mov [edi], esi ;sto into lexptr ref
mov eax, [esp+32] ;get maxlen mov eax, [esp+32] ;get maxlen
sub eax, ecx ;subtract what we did sub eax, ecx ;subtract what we did
pop edi pop edi
pop esi pop esi
ret ret
section .data section .data
align 16 align 16
g_errfmt db "String formatted incorrectly - parameter %d (total %d)", 0 g_errfmt db "String formatted incorrectly - parameter %d (total %d)", 0
g_mlfmt db "ML_NOTFOUND: %s", 0 g_mlfmt db "ML_NOTFOUND: %s", 0
;Stores whether a character is a letter or not. hAxXx ;Stores whether a character is a letter or not. hAxXx
g_chartbl times 65 dd 0 g_chartbl times 65 dd 0
times 26 dd 1 times 26 dd 1
times 6 dd 0 times 6 dd 0
times 26 dd 1 times 26 dd 1
times 133 dd 0 times 133 dd 0
g_jumptbl times 256 dd format_parameter.fmt_default g_jumptbl times 256 dd format_parameter.fmt_default
;end ;end