Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
2.9 KiB

  1. MODULE_TEMPLATE MACRO mod, style, mod_list
  2. include cmacros.inc
  3. include xlib.inc
  4. fNOLOADLIBRARY = 0
  5. IFNB <style>
  6. IRP astyle,<style>
  7. IFIDN <astyle>,<NOLOADLIBRARY>
  8. fNOLOADLIBRARY = 1
  9. ENDIF
  10. ENDM
  11. ENDIF
  12. externFP GetProcAddress
  13. IFE fNOLOADLIBRARY
  14. externFP LoadLibrary
  15. externFP SetErrorMode
  16. IF UNLINK
  17. externFP FreeLibrary
  18. ENDIF
  19. ELSE
  20. externFP GetModuleHandle
  21. ENDIF
  22. sBegin Data
  23. globalW __h&mod, 0
  24. staticW procptr, 0
  25. sEnd Data
  26. sBegin Code
  27. assumes cs,Code
  28. assumes ds,Data
  29. IF fNOLOADLIBRARY
  30. IFNB <mod_list>
  31. __&mod&string label byte
  32. IRP amod, <mod_list>
  33. db "&amod&",0
  34. ENDM
  35. db 0
  36. ELSE
  37. __&mod&string db "&mod&",0
  38. ENDIF
  39. ELSE
  40. __&mod&string db "&mod&",0
  41. __&mod&file db "&mod&.dll",0
  42. ENDIF
  43. __&mod&dynlink proc far
  44. public __&mod&dynlink
  45. IF UNLINK
  46. mov ax, procptr
  47. ENDIF
  48. mov procptr, bx
  49. IF UNLINK
  50. mov bx, cs:[bx].pcData
  51. mov [bx].pdNext, ax
  52. ENDIF
  53. cmp __h&mod, 0
  54. jne get_proc
  55. farPtr mstr,cs,bx
  56. IF fNOLOADLIBRARY
  57. lea bx, __&mod&string
  58. mod_loop:
  59. save <bx, si, di, es>
  60. cCall GetModuleHandle,<mstr>
  61. or ax, ax
  62. jz no_link
  63. ELSE
  64. mov ax,08000h ;SEM_NOOPENFILEERRORBOX 0x8000
  65. save <si, di, es>
  66. cCall SetErrorMode,<ax>
  67. mov dx, ax ; old error flags to DX
  68. lea bx, __&mod&file
  69. save <dx, si, di, es>
  70. cCall LoadLibrary,<mstr>
  71. xchg dx, ax ; old error flags to AX, LoadLibrary ret to DX
  72. save <dx, si, di, es>
  73. cCall SetErrorMode,<ax>
  74. cmp dx, 32
  75. jb no_link
  76. ENDIF
  77. mov __h&mod, ax
  78. get_proc:
  79. push bx ;; save ptr into module name list
  80. push es
  81. push cs
  82. pop es
  83. mov bx, procptr
  84. farPtr pstr,es,bx
  85. lea bx, cs:[bx].pcStr
  86. cmp byte ptr cs:[bx], 0
  87. jnz @f
  88. les bx, cs:[bx+1]
  89. @@:
  90. mov ax, __h&mod
  91. save <si, di>
  92. cCall GetProcAddress,<ax,pstr>
  93. push ax
  94. or ax,dx
  95. pop ax
  96. pop es
  97. pop bx ;; restore module name list ptr
  98. jz no_link
  99. mov bx, procptr
  100. mov bx, cs:[bx].pcData
  101. lea bx, [bx].pdPtr
  102. mov [bx], ax
  103. mov [bx+2], dx
  104. jmp dword ptr [bx]
  105. no_link:
  106. IF fNOLOADLIBRARY
  107. IFNB <mod_list>
  108. @@:
  109. cmp byte ptr cs:[bx], 0
  110. jz @f
  111. inc bx
  112. jmp short @b
  113. @@:
  114. inc bx
  115. cmp byte ptr cs:[bx], 0
  116. jz @f
  117. jmp mod_loop
  118. @@:
  119. ENDIF
  120. ENDIF
  121. xor ax, ax
  122. xor dx, dx
  123. mov bx, procptr
  124. lea bx, cs:[bx].pcRetF
  125. jmp bx
  126. __&mod&dynlink endp
  127. IF UNLINK
  128. __Unlink&mod proc far
  129. public __Unlink&mod
  130. mov bx, __h&mod
  131. cmp bx, 0
  132. jz unlink_done
  133. mov __h&mod, 0
  134. IFE fNOLOADLIBRARY
  135. cCall FreeLibrary,<bx>
  136. ENDIF
  137. unlink_procs:
  138. mov bx, procptr
  139. @@:
  140. cmp bx, 0
  141. jz unlink_done
  142. mov ax, cs:[bx].pcLinkProc
  143. mov bx, cs:[bx].pcData
  144. mov word ptr [bx].pdPtr, ax
  145. mov ax, cs
  146. mov word ptr [bx].pdPtr+2, ax
  147. mov bx, [bx].pdNext
  148. jmp @b
  149. unlink_done:
  150. mov procptr, 0
  151. ret
  152. __Unlink&mod endp
  153. ENDIF
  154. sEnd Code
  155. end
  156. ENDM
  157.