|
本帖最后由 differentrain 于 2014-6-20 16:05 编辑
( K/ P; g% Z! l- d$ c- O( T
& `3 u3 C6 _$ w0 K, K不怎么用Office系列,今天偶然和朋友聊起来,突发奇想用Excel做了个扫雷的修改器....[em1127]# {; L X7 i0 U7 h( e
虽然不会Excel,不过VB咱小时候还是学过的...[em1124]
$ ~1 N4 _4 s" r/ z3 j& b$ \% E5 P1 G( w
我用的Win7的扫雷,其他版本的估计不行..可以停止计时和在表格中现实地雷位置...
8 d0 H. _1 B1 F) f0 r; p附件就是那个表格...如果版本不对就直接看代码部分自己复制过去也行..& u& y$ \9 P/ A0 z/ B% s
顺便说,VBA简直反人类..MS为什么不出VBA.NET啊...大段的代码要自己写,而且抽象性巨差....2 p2 R: }" y0 D! @- D2 _/ s
# P6 o2 a0 U+ H( S- O" i
MineSweeperTrainer.rar
(22.27 KB, 下载次数: 6)
5 j7 y1 I/ N5 }
4 N( [" u4 {5 D8 ^ y
% j2 `' `/ _% {) B0 M. {
: Y, B# Q' ]1 e( J$ S. _+ S2 a. K5 W3 y, w9 E7 w, r; y
- 【控件】
}8 t J# z( r* _+ k/ _7 {
' n+ j- R5 `% O7 G% M' I8 ~5 |- 窗体:frmMain
( d7 v, o7 B) |. q; G5 H - 按钮:btnCatchGame,btnRefresh& Q$ m& ^; W6 `. T
- 选择框:chkGameTime
复制代码 ' n9 E$ Z, S: b5 N+ u( K( m" N
9 y$ C# h, \/ Y+ n
& b0 b R: N: H" h% k6 {* f( e% K. G
7 n& K- t: F- `- 【代码】( U& w* f4 ]0 b$ I' x) _) j+ f& v
- 3 T- r' [9 r" ^4 e
% ]8 W9 z. C& J7 I6 u% D- @- Option Explicit- V" `- R# ?9 p1 |& H. e8 o
- - h5 f7 [' u2 C4 g; t) ^
- : k- o- r% V X) Z4 t
- Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long6 ?& X$ x) B6 E
- Private Declare Function module32First Lib "kernel32" Alias "Module32First" (ByVal hSnapShot As Long, lppe As moduleENTRY32) As Long
' w. t1 R, W1 l% K& X: I; ? - Private Declare Function module32Next Lib "kernel32" Alias "Module32Next" (ByVal hSnapShot As Long, lppe As moduleENTRY32) As Long
( ~0 r: W$ D: D9 ?) y$ a8 n2 e - Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long2 }1 g7 y# I! a9 P) ^, \5 m) a3 X
- Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long9 z! m$ C9 _) C0 f1 C( G
- Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
# O: V' R. q9 w$ {
9 _3 G$ W8 a% t) s: u
( t Y3 y- K- C" T5 m+ X( I; Q3 Z- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
6 |2 a( N: i! k5 {! }0 m - Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long7 p) N2 W3 M+ x6 f8 x
- Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
9 n5 I: O+ y3 B, S: e - Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long7 }3 Y; ]* [2 O W! _% |
( `: J% F: o2 ?$ {; r" s3 [0 A
& j' `7 }. \% b* C- Private Const TH32CS_SNAPPROCESS = &H2
- W9 T2 g% l- V6 Q1 d( Z3 A; E6 M - Private Const TH32CS_SNAPmodule = &H8
& H! U( {' \+ g& e% t" k8 {$ q; H - Private Const CB_SHOWDROPDOWN = &H157
" T& K S& z$ Y: w - Private Type moduleENTRY32
0 `* N- {" ]% g, b - dwSize As Long, K# L( R% \$ z& {5 }
- th32ModuleID As Long
) T; ?- \: U* a- k2 C - th32ProcessID As Long
# _% [- H" q; D4 v' o7 F* y - GlblcntUsage As Long# r" F* k1 \- O& Y2 R" l
- ProccntUsage As Long2 {9 R0 t1 U& L. m' }5 A. t. L
- modBaseAddr As Long$ J- J' `' S" y. q. E+ A1 v) |
- modBaseSize As Long* v) E+ y* ~5 d8 D& V! y* i( e
- hModule As Long3 G1 J6 D8 ?, t" O; I7 s
- szModule As String * 256
2 |1 ^( D$ S) U# ]) l7 z {3 O0 \- B% f - szExePath As String * 1024
& _2 Q5 m( b& l Y7 }& F - End Type! x) A6 u c$ y# D8 V# `( w, ~! t
- ' E2 v/ e/ b P" c4 C
- Private Type PROCESSENTRY32
_9 x$ ]( F! [& R6 t - dwSize As Long9 m- R; O4 M: n# s- [4 t
- cntUsage As Long, ^7 p6 r1 \6 `4 U& p' a
- th32ProcessID As Long, m! }7 k, ]+ K1 }; m
- th32DefaultHeapID As Long6 H3 X/ ]! _/ Y1 d
- th32ModuleID As Long1 K9 \ {0 _8 c# C( ]
- cntThreads As Long8 j3 y9 b' e4 [; [2 i& I
- th32ParentProcessID As Long( T, r8 z1 e; K1 G% X9 ]- @* ?9 Z; W
- pcPriClassBase As Long4 P# q4 q' P% J9 k6 s3 w- f
- dwFlags As Long) I, c; s5 t& d9 S' x5 @; P
- szExeFile As String * 10245 ~* Z. j4 d) a& Y
- End Type! P$ h3 F W9 t; i
( x0 [( \& P6 q5 ]7 m* v& }( \
/ {' R8 `& C7 P! J5 Z
6 ~, K8 e# S- i3 j/ I- `7 J- Private Const PROCESS_ALL_ACCESS = &H1F0FFF; J* W, U) Q$ d: u
- Private hProcess As Long
/ c# \! _5 D& |2 ?: x; @8 O - Private PID As Long$ k+ g1 @) Y5 K, q: L
) [* V8 a) N( R. T* `
' H9 B( ^, r% b- S3 p0 M3 X- Private Type asmNum
: n8 R. o5 Z( u: `5 T% x9 X6 F4 Z3 S; Z - nuM1 As Byte6 W1 l! V6 V3 X- v2 t4 p Z0 `
- nuM2 As Byte
8 R& O. @5 s. t - nuM3 As Byte" G1 V# E5 Y% l1 G$ n: {
- End Type8 S2 C7 O0 L) M' s
- + j9 u1 @$ Q5 U' S
- Private adrTime As Long
/ h2 \5 C- w5 s R - Private adrMine As Long$ v5 ~2 N/ ]/ K4 I+ G
! g- e, ?# o) L5 C2 m3 C- Private Function GetProcIdByName(ByVal ProcName As String) As Long
" {: T. j4 s5 y4 D - Dim PE32 As PROCESSENTRY32
( x# T& c, O6 h7 P; P& g6 u! Z - Dim Procid As Long1 v/ \8 j& E9 K# |# U( s
- Dim hSnapShot As Long8 X8 g/ k# v8 I" q. {# P/ |! ~
- hSnapShot = CreateToolhelp32Snapshot(ByVal TH32CS_SNAPPROCESS, ByVal 0)
" d4 ~/ l" J$ w e8 G. c - PE32.dwSize = LenB(PE32)
0 J- l5 w7 i4 q5 y, i3 P - Process32First hSnapShot, PE32! X8 R5 q9 P* N
- Do& P4 W1 r* u6 Z0 J# }
- If lstrcmpi(Trim$(ProcName), Trim$(PE32.szExeFile)) = 0 Then
& a8 i1 K$ h2 p - Procid = PE32.th32ProcessID
( Y, `* G3 s" k* @- N - Exit Do
: \ q l& D+ {3 C! h - End If T& e7 O4 }+ l7 ~ ]
- PE32.szExeFile = vbNullString
8 b) ]' g9 E# c& J" z0 p - Loop Until Process32Next(hSnapShot, PE32) = 0 O4 m' E( d# l3 J, f& r* a' s, r
- CloseHandle hSnapShot3 r* K e5 X1 O
- GetProcIdByName = Procid" J5 a0 I% c: K: y
- End Function7 f( K) ~0 @$ g- b# F
- * P6 V9 l" p+ y) y0 W9 m
|/ T9 z" {7 }. K \! O/ o- / p- m, t/ c: Q/ h
- Private Function GetModuleBaseByProcName(ByVal ModuleName As String) As Long) C. P! ` s+ Z1 t" J
- $ }5 T. T4 r8 g9 y7 _- `% n
- Dim ME32 As moduleENTRY32, ModuleBase As Long
" D* B3 p. d! \/ b1 ~' p% o1 u - Dim hSnapShot As Long5 b- U) M- g# P, u
- hSnapShot = CreateToolhelp32Snapshot(ByVal TH32CS_SNAPmodule, ByVal PID)2 E: E7 R9 {1 a
- ME32.dwSize = LenB(ME32)+ ~1 R' Y+ L1 {$ Z0 Q" B9 G4 h
- module32First hSnapShot, ME32; Q! ^- f' G; V) W4 h3 q! V( B
-
1 w* R7 H0 T; ]' H% a5 V - Do5 v/ Z) e! V0 c2 x; x5 U) M& A
-
6 N+ t" A! b9 \! @3 V" `9 O - If lstrcmpi(Trim$(ModuleName), Trim$(ME32.szModule)) = 0 Then7 ?8 x7 q4 V. L# [* r$ P
- ModuleBase = ME32.modBaseAddr0 T4 s" I8 L6 \) |
- Exit Do
6 `" i. A8 y7 T* Z$ ]/ z0 T: j - End If
5 M2 N$ ?7 u# y+ z$ P. R/ k" k -
4 N8 r4 [: d( B# A - ME32.szModule = vbNullString
% f) k; Q3 U2 w8 q9 L4 N -
2 _ y' ^3 U# N* \0 { H - Loop Until module32Next(hSnapShot, ME32) = 0
; H* \& `% n* s5 d, r2 S3 Z4 L. _/ b$ W - CloseHandle hSnapShot
3 v2 J; n8 C4 n. I - GetModuleBaseByProcName = ModuleBase, S! i! Q- J# j! y; ?7 w
- & U! ^ l/ u5 X. _* u) z
- End Function
# H' e( i3 l8 U - 3 h* q x( y. u! P" E! D9 O! Q
, V6 ~1 z6 M. i: P9 J% A7 d+ Z- Private Function GetMemory(ByVal Adderss As Long, Optional Length As Byte = 4) As Long
2 e& V* _% O# w7 l2 r - ReadProcessMemory hProcess, Adderss, GetMemory, Length, 0
" }, ?- K+ [; i1 W B1 s - End Function& ~/ \8 ]4 G4 z
- Private Sub SetMemoryAsm(ByVal Adderss As Long, NumVal As asmNum)6 y V" C7 S4 Z, c' z: Y
- WriteProcessMemory hProcess, Adderss, NumVal, 3, 0
1 e, T4 I- y0 b; [4 o, P0 G/ Q: d - End Sub
3 X6 t7 z# d+ k g - 0 i" r( n; m5 O
- ( o2 u* a+ u) o5 E
- Private Function FindGame() As Boolean7 c3 |/ c+ x5 F0 d6 M% C" L3 r( C
- + P6 ~" B: v) i8 r }5 o
- PID = GetProcIdByName("MineSweeper.exe")% j F# F! h" I
-
2 A& E0 [ n% O4 O - Select Case PID
3 W' n& l$ W B - Case 0
, V2 U B1 O- k$ F - FindGame = False
8 m8 o, F1 @4 s - Case Else
' \! B8 r: F' [' Q& o. w1 M - Dim adrBase As Long
8 H6 n6 h: W2 E/ Y6 N- k8 g: ` - adrBase = GetModuleBaseByProcName("MineSweeper.exe")1 W+ Q6 S" O' o) `6 C4 }/ y- q1 ]
- adrTime = adrBase + &H21446: V4 u- s* x& [8 m1 q
- adrMine = adrBase + &H868B4% ^. M; e) C2 y2 H- q6 `7 F
- FindGame = True
5 b, g: y2 {7 j! C% v( L% R - End Select
6 E, V( C0 I- K - End Function
/ A7 f9 n1 S3 i8 [ - * D1 f! U( L' n+ E: h- D1 n
- Private Sub TrainerState(ByVal State As Boolean): U& }6 V( w- i
- chkGameTime.Enabled = State
3 d6 N3 m! [) d6 Z: y) ]! B - btnRefresh.Enabled = State4 U- Q+ y7 ^' y3 P
- Select Case State% \, |; t9 C# Z% t" Q2 y, ?' [+ \
- Case True7 b/ @4 Q, D% H% `& g/ {
- btnCatchGame.Caption = "ReleaseGame"+ L7 H7 g- o3 Q. T, M
- Case False0 c; x" I6 s1 t, B/ \
- btnCatchGame.Caption = "CatchGame"
9 n; b6 o, d: D2 r - chkGameTime.Value = False" e* S6 \# r3 Y. h0 k- @0 T
- End Select% k+ S0 w z: _! \3 ^4 Q
- End Sub' I5 w( {/ w) U
- : n5 |; A8 [ N* Y) F3 E' z
- . K6 Y& o0 v( E7 m& | {
- Private Sub AsmState(ByVal State As Boolean)
$ \9 B' l, [8 D( L2 M - Dim asm As asmNum
1 w- x, z- u$ d - Select Case State
. Y; h8 f4 H' @0 }7 }" A - Case True' F& L. F8 |' v8 o# r/ b5 j
- asm.nuM1 = &H90' w$ f. X4 v$ ~8 K2 \* k/ \# v o9 ]
- asm.nuM2 = &H903 ]1 ]( c3 L5 U' @% t% m; K# \
- asm.nuM3 = &H900 z6 [+ v2 O1 F* S ]
- Case False) k: X7 @8 W! y. r
- asm.nuM1 = &HD9: [0 |& g ^ Y3 O8 I8 u' q. v
- asm.nuM2 = &H58% ]/ J7 ^1 x! A: x- W
- asm.nuM3 = &H1C1 d) L$ b Z4 i# f& m
- End Select
# f, i2 o$ M: V- ^+ B# g: o8 V; H - Call SetMemoryAsm(adrTime, asm)9 g, L$ J! U6 m8 I' I, V
- End Sub; f/ J/ s5 m5 ]% `. G' z
5 A0 \, O- p2 U. o* |9 g- 9 r Q' j9 s: _$ K. j
- Private Sub chkGameTime_Click()* B1 x: u2 C# S4 @+ ]1 }2 `
- AsmState (chkGameTime.Value): t" J: W M: @8 g5 D# L
- End Sub# ? u9 ?9 t# T6 u$ |
& {' G3 J1 A3 i+ P. n- W; G5 O n- , t! ~9 Q. Z0 F, A ?
- Private Sub isOpen(ByVal State As Boolean)
% F$ B# d7 B; C% u; N; d - Select Case State( v7 r5 r; `8 s! f6 G
- Case True
8 e- R3 j$ r. h- g0 `0 ~: j; o - If FindGame = True Then
1 @3 a- @' }9 e0 P - hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)- N7 @& k" O7 j6 d. \
- TrainerState (True)
. L8 Q" _5 W' m$ u2 j - End If
7 P2 `) Q* n5 Q( S. z; u; K- g$ F% K - Case False( H) \8 q. B: ~
- If FindGame = True Then
0 u ~$ g( a8 i6 d - AsmState (False)
% P7 ]6 S) ], G1 D: D: X' D - CloseHandle hProcess
" }) G* N' ^' ^! m, z - End If
. n- u# d5 B8 Q) o/ f - End Select! {( B9 @2 v( o# E. {& v" J3 g+ H7 p
- End Sub
1 L- e/ c! q3 z: s Y - 4 D6 a* F0 ]5 n% B
, e0 t+ B$ h" |7 F- Private Sub btnCatchGame_Click()* |6 O- W! q( m9 v. q
- Select Case btnCatchGame.Caption$ _( F1 K# J y5 f \3 u' \
- Case "CatchGame"1 E. a" ]1 M: d% Y. j- g0 F
- isOpen (True)7 g. W/ p% f' n) [0 k3 [
- Case "ReleaseGame"! O3 Q3 F! u& H `# o# \% R3 m: L
- isOpen (False)6 [% ^5 U( _2 g& `
- TrainerState (False)
( m- Y5 o3 ?& }* A t6 Q6 b) ^ - End Select
: i$ G7 g. n" J( O" h* v- U - End Sub$ e* x* o( X3 V0 T) c+ k; ]& U2 k1 d& x
- 9 Z/ i# H3 Y) c9 O7 F% f* H( L" w
- Private Sub btnRefresh_Click()
8 l# ]0 y" K& q0 B7 } - + C3 t. m+ C z6 r7 {3 Z0 m
- Dim mineColumn As Byte, mineLine As Byte
& `( [6 ]5 @) A4 K1 Z) E7 ]: n - Dim adrPoint As Long, adrTemp As Long, adrColumn As Long; U; S$ z3 W, ]! m
- Dim i As Byte, j As Byte
, {3 B& C- z G - & n# j$ i3 T6 Q$ O3 L2 `* y$ F
- & [$ L, \4 k+ x9 [* @& R. z
-
7 a1 P, t) n: O9 N& h - btnRefresh.Enabled = False$ I2 J8 a( p1 ?7 D5 K
- 1 }. `1 ^1 a( B8 W- J6 C6 s
- adrTemp = GetMemory(adrMine)- T" Q- e" `+ O2 n3 D A1 p
- adrPoint = GetMemory(adrTemp + &H10)9 b. }" x2 b' |- {' x
-
1 Q4 B5 H T2 E6 N( K - mineLine = GetMemory(adrPoint + &H8) - 14 ~& K8 C7 Y# P) V0 v
- mineColumn = GetMemory(adrPoint + &HC) - 13 x' l9 C6 \6 o4 h# ], d
- ) t; K$ Q! M! B( G# y5 a9 o
- adrPoint = GetMemory(adrPoint + &H44). o# W. U7 k/ w6 s( A, D
- adrPoint = GetMemory(adrPoint + &HC)
/ _- D1 f( m- C - & [# e* U8 W9 _( {% C( E; D' M
- 8 d/ u3 t3 J. Q* _% i, _4 {
- 5 X4 B0 G P, v
- For i = 0 To 30
, A1 m7 V8 q. B0 `5 n4 J- t - adrColumn = GetMemory(adrPoint + i * 4)4 E. r# t- f9 i( E
- adrColumn = GetMemory(adrColumn + &HC)
! W; Y: m+ ]) ?# } - For j = 0 To 23' q( H% C# D5 l- F/ u, i$ k
- If i > mineColumn Or j > mineLine Then
7 ^* T. W" `$ u, k$ }4 O3 u& e4 ] - Sheet1.Cells(j + 1, i + 1) = ""( e$ e0 e3 U8 `1 M
- Else
7 B. v @9 j. m% q* Z% Z% E$ o! c - Sheet1.Cells(j + 1, i + 1) = GetMemory(adrColumn + j, 1)+ O& t/ Q. h7 S* a; s& E- a2 V
- End If: _8 U9 p2 n8 h6 P' }# S
- Next j# E* J5 m/ w# M- v7 I/ |+ L
- Next i
( m# k0 u4 C9 R# [ - btnRefresh.Enabled = True) t; @/ \7 y5 U$ v4 f
-
+ d3 N2 t/ K" u8 i -
0 R6 E9 @1 }5 C7 }" c$ P2 a0 a - End Sub5 z: I5 h1 M2 p7 Q8 N* h- f
- : n( j( d7 e! ]) y. F
- Private Sub UserForm_Initialize()
9 |& f/ t9 y9 @# Q& D2 I3 Q - TrainerState (False)
* ^8 w$ m# N1 }# P0 }% Y - Sheet1.Cells(1, 2) = 13 [8 ]) \2 k7 T ]6 [' g
- End Sub
' J+ O. k. h8 v; [ o) m) i! m
* ]+ A- B H% B5 h ^- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)) p s! v0 ?& \( g, A$ \
- isOpen (False): O ]; \7 t, H" @9 E
- End Sub* o, X/ @! q4 e1 K
复制代码
4 ` R; ]- X6 N9 W; @% ?; R3 C8 G7 }. U) e0 o7 S0 O
: a( h4 H: Y# s2 V/ D- j
# f+ ^2 M. p9 O# `) ^& C9 w |
|