|
本帖最后由 differentrain 于 2014-6-20 16:05 编辑
. z2 R% h( G# v, l) F5 m, P1 p5 g6 T8 x3 C6 O
不怎么用Office系列,今天偶然和朋友聊起来,突发奇想用Excel做了个扫雷的修改器....[em1127]
* e2 ]* M* v% s( Q虽然不会Excel,不过VB咱小时候还是学过的...[em1124]( r& s: c- }. G7 _% `
+ f. Z' b5 [$ q6 }9 c" z% i( U我用的Win7的扫雷,其他版本的估计不行..可以停止计时和在表格中现实地雷位置...
" {& t3 E0 z0 s' E4 J& O) |1 t% F& @附件就是那个表格...如果版本不对就直接看代码部分自己复制过去也行..
, f6 z& T& J8 G顺便说,VBA简直反人类..MS为什么不出VBA.NET啊...大段的代码要自己写,而且抽象性巨差.... B, j* `) Q% g& `
( R5 X1 w6 x7 ~" w
MineSweeperTrainer.rar
(22.27 KB, 下载次数: 6)
7 r0 x! `$ [: {7 Y0 o- \; m* k; t8 ~ t( p' \' A
% }/ g0 K1 y4 x( G4 }( p
9 z- `. F* O1 p
5 y7 x2 w3 _* O3 l! z0 C0 Y
- 【控件】+ e4 v$ R1 k7 a2 y
- / U7 y! w2 k) \+ [' g+ T
- 窗体:frmMain3 a5 ]; ?. o3 c( ^. {: x
- 按钮:btnCatchGame,btnRefresh+ W' v3 U! Z) t3 L h: b, ^/ B
- 选择框:chkGameTime
复制代码 ! S1 }" @. ] b' M: ^
5 I; _3 o4 O, V# j3 M( `
3 k- w" e% N6 a1 A% U: E' v& W
3 o. E# j/ ?' _1 G- 【代码】6 O( n5 E: U# D" r$ X
- - b3 ]; ]* u8 N- k N$ {
7 P( Z7 }- Q' R$ |1 \; }4 k3 s2 k- Option Explicit+ u& @ n/ ]8 z1 I3 {
- $ h$ d- h, s- H3 F
- ) S) S. U7 S+ b+ ^5 j4 d
- Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
( g+ O' Q8 K% ^! @ J+ z - Private Declare Function module32First Lib "kernel32" Alias "Module32First" (ByVal hSnapShot As Long, lppe As moduleENTRY32) As Long
/ |% s1 K5 a5 k/ e9 a7 h - Private Declare Function module32Next Lib "kernel32" Alias "Module32Next" (ByVal hSnapShot As Long, lppe As moduleENTRY32) As Long! h9 S4 H+ ~4 ]9 v% d! E; D
- Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long
1 v, |' o" l1 h$ P9 k) M4 k - Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long
% I. J: h v5 d - Private Declare Function lstrcmpi Lib "kernel32" Alias "lstrcmpiA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
! L, E8 w& q8 Q2 X - ) R9 I! N0 l( _* ?0 x
- 6 ^( \3 h* {3 U# U# s% J, E z# N
- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long+ g' {, t" F& b* U# w1 ?! v& ~0 N! k" O
- 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 Long
9 } G2 a* K% v" b, k- b# n - 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
3 C% x) x7 e- `+ z7 q - Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
* Q& E3 K/ c) D" H+ g - 4 W2 d# } r2 U' h1 H
) V7 ?- X1 C+ Y. m; r9 U- Private Const TH32CS_SNAPPROCESS = &H2
' H- z W/ p; {) I0 | - Private Const TH32CS_SNAPmodule = &H8. A' _; m" T5 \8 T0 \% @0 O/ ~
- Private Const CB_SHOWDROPDOWN = &H1573 ~/ N7 ~4 [; L3 ^0 {" t; N
- Private Type moduleENTRY32, C, {& R# f3 |: u
- dwSize As Long
' W* R8 A- Y8 R; @) k; p - th32ModuleID As Long3 B* Z3 b% `. E& d" ~
- th32ProcessID As Long
( m7 p: H& X" `0 A - GlblcntUsage As Long
8 K# r4 X4 v) z7 m; Z N& L' | - ProccntUsage As Long
. U1 J5 S$ A( C$ G" C4 c x, M9 j - modBaseAddr As Long) u" N* O. J' @4 U M- l- V4 b
- modBaseSize As Long
# Q9 p% O7 }+ e g2 W- H5 V - hModule As Long2 C/ T3 R+ v/ G t
- szModule As String * 256
& n- u& [) Z! j) v. S @/ U - szExePath As String * 1024. M4 Q2 u* ~( q; ]
- End Type S' K5 r. j! D7 b
- # q4 g0 f5 L0 m
- Private Type PROCESSENTRY32) {8 ]' l9 ~- \+ m# [+ M, z
- dwSize As Long7 S5 H! @* B5 E( H! D2 j
- cntUsage As Long
* F4 s6 Y4 P9 @; B; h - th32ProcessID As Long
8 A& c. B' f( f3 i7 W% P* }* _ - th32DefaultHeapID As Long, I9 q5 i$ Q2 X( T
- th32ModuleID As Long
; w! z" A! B s e: ~" h1 p# ~ - cntThreads As Long
2 Q$ k* T8 @! y% l5 i - th32ParentProcessID As Long, X% W) M9 o8 ], ]3 {& D1 {
- pcPriClassBase As Long2 B2 U5 B% M( c& l
- dwFlags As Long
X* e; R: I0 Q/ o ^ T - szExeFile As String * 1024
1 W$ j6 j% A, L* y- ~ - End Type
1 j" m1 A- Z. X) ~2 x( G# h
. ^ V+ K2 A) H
p6 w- }7 ^4 X+ r0 c" Y; ?- ; n# A2 B' _8 A$ ?8 S0 v' [
- Private Const PROCESS_ALL_ACCESS = &H1F0FFF; d9 E3 C X9 D9 X9 L3 {5 p1 p# D1 Z
- Private hProcess As Long
2 W3 n- {/ U. I1 {: R+ o4 D - Private PID As Long& ^& ^$ I0 C U# V H
- ) i# u4 |! P! k5 s
- ( _$ _$ I( j s% h* A
- Private Type asmNum4 A3 f8 H7 R, \* ~8 @& K! H5 f
- nuM1 As Byte& k0 [/ F* J% |) Z: K3 t
- nuM2 As Byte
8 k! h' a5 C0 |! W' z7 I - nuM3 As Byte& p7 W; c9 z, a4 i- p
- End Type$ g' c/ O1 A/ v
$ z1 x( |! h% I8 G- Private adrTime As Long
( `" M" ~! |* Z, ?: v1 m: i - Private adrMine As Long
- t H: a7 ?8 l# D o
, T' B' M6 a) ^' [8 L8 G( u: b, r- Private Function GetProcIdByName(ByVal ProcName As String) As Long
* l2 Q/ O! X/ ]! y - Dim PE32 As PROCESSENTRY325 s& m; j! r: l& K. a/ F8 _, |5 S! [
- Dim Procid As Long4 H* G0 D4 W! C- O$ |
- Dim hSnapShot As Long1 N- P( {5 H4 Z% g
- hSnapShot = CreateToolhelp32Snapshot(ByVal TH32CS_SNAPPROCESS, ByVal 0)% U* f4 I+ g6 s3 S
- PE32.dwSize = LenB(PE32)6 i* R% U1 T( k0 X5 k$ A$ l* o$ O
- Process32First hSnapShot, PE32
! R* Z& R6 I' f9 p3 C* [ - Do
7 Y% v A+ |/ h% X1 q0 Q! X& g \ - If lstrcmpi(Trim$(ProcName), Trim$(PE32.szExeFile)) = 0 Then
& s, {) d7 f1 `, x2 X) ] - Procid = PE32.th32ProcessID0 N |) l! |' z/ ]- F2 P
- Exit Do
0 M* j4 p# h# L+ k - End If
; o8 i0 k Y3 X, s ? - PE32.szExeFile = vbNullString
: n* |4 @* d* O' v - Loop Until Process32Next(hSnapShot, PE32) = 0& \4 {, ~( c2 J/ M2 ^6 q5 M
- CloseHandle hSnapShot S3 H5 L" C; t4 O6 y% z1 h
- GetProcIdByName = Procid$ ]7 R) H" ]' O/ Z. L& S( V, R
- End Function* X- [0 E' ]. t o. u1 V1 r
2 @. K9 f$ J& H
" U9 s- w, ?, G) r# r/ R4 X- 7 C ]% r$ F+ V1 p4 O2 F9 Y
- Private Function GetModuleBaseByProcName(ByVal ModuleName As String) As Long
8 x0 B- `& }3 N8 j. v6 [) O
# q. y2 y8 z$ B- Dim ME32 As moduleENTRY32, ModuleBase As Long
: F1 V6 y: c* F( v/ i' l! k2 Q9 f/ K - Dim hSnapShot As Long
! ?! L& A0 ^# F* h6 d9 M* I/ V" ~# x - hSnapShot = CreateToolhelp32Snapshot(ByVal TH32CS_SNAPmodule, ByVal PID)
, k2 l9 v& Z8 S2 x2 e2 U2 ]1 h) P - ME32.dwSize = LenB(ME32): K9 F1 Q: m4 ~1 W
- module32First hSnapShot, ME32. ]! O% i& ?( O: A! ?
-
2 n6 d" ~7 X* M5 M# a - Do
. W5 E7 U6 N" n/ x' z -
% l3 R" K/ L3 z$ m - If lstrcmpi(Trim$(ModuleName), Trim$(ME32.szModule)) = 0 Then7 R% [' b/ y/ k' t0 k1 W0 F R: p4 P
- ModuleBase = ME32.modBaseAddr
9 y5 j" m m! { \ - Exit Do4 D' T& y, u8 @5 f6 Q, {8 x
- End If% a) {' y0 W) _4 c
-
1 ` D2 k2 [' m) |) X( i - ME32.szModule = vbNullString5 N/ q) o* p- ]! I) P' |
-
* C: n+ Y: \. L4 |' i - Loop Until module32Next(hSnapShot, ME32) = 05 v9 X7 [. R* l! G6 G: U
- CloseHandle hSnapShot' [: v6 A! N3 D0 p4 z, ^5 W2 y
- GetModuleBaseByProcName = ModuleBase5 Y6 D& w$ D8 k' f6 _3 f& F; ` [
( A m8 E% T0 e: R+ r4 L- End Function
: O& W) k: C" `3 ~# _
- n0 s% D' o5 w/ r- : D8 G2 n; U, r8 M
- Private Function GetMemory(ByVal Adderss As Long, Optional Length As Byte = 4) As Long
9 j9 U4 \! j! y- O - ReadProcessMemory hProcess, Adderss, GetMemory, Length, 0
) z5 F) N$ C2 | - End Function& C% q# V, y) a1 o6 E1 ?
- Private Sub SetMemoryAsm(ByVal Adderss As Long, NumVal As asmNum)' A2 ]! J P: G3 |7 ~0 W
- WriteProcessMemory hProcess, Adderss, NumVal, 3, 0
# S" h! e5 ?+ {1 [7 u - End Sub
, C$ ?, F9 Y% L: l5 V6 t
( C# k; h, c! A5 i; W+ c
' D) Y" K8 } p. V- Private Function FindGame() As Boolean
6 t P. `/ y/ f" x- z -
$ K9 x2 K/ ?6 o: _8 U1 b - PID = GetProcIdByName("MineSweeper.exe")8 _: j6 i7 I3 F& S
- 9 H' p( G7 D& Q6 }
- Select Case PID
( U( L! Z% a; a s+ U0 t L4 p+ f - Case 0
" S) U6 W) b$ [! g: c, v* k" h - FindGame = False
0 c4 ] q: X! p' i! S3 F - Case Else5 N: ~' {( p6 {
- Dim adrBase As Long/ q/ `! T& u5 T6 h9 j/ F5 g( u
- adrBase = GetModuleBaseByProcName("MineSweeper.exe")
' k5 S0 \6 l2 U& Y1 q0 w7 { - adrTime = adrBase + &H21446
* z& T: v+ j4 E8 }7 m. D4 J8 |% _3 e - adrMine = adrBase + &H868B4 `- q. M/ }! H {& R
- FindGame = True; e2 I* p b# Y0 N1 g4 {& L
- End Select
0 Y7 l0 o3 ]8 ?' p) ?( o& I6 y - End Function* F) J# F: H/ R1 R0 s
- 6 l7 S9 p2 v4 I) }: Z/ Q
- Private Sub TrainerState(ByVal State As Boolean)2 T6 y% T" }! R; l6 Z! P( {
- chkGameTime.Enabled = State9 [4 S% A' |0 M7 S: N/ V9 x6 j
- btnRefresh.Enabled = State
$ r9 x) R8 a, L - Select Case State2 `! U+ Q5 s: m& {- B/ |
- Case True: O& }2 A6 L0 B. h
- btnCatchGame.Caption = "ReleaseGame"
% T! P9 K, e# p0 V5 N9 V% D: l - Case False& H4 y8 f! F0 I) y
- btnCatchGame.Caption = "CatchGame": Z' I$ A5 |5 C. C O
- chkGameTime.Value = False* W1 a$ s. N+ m+ E e$ X8 q* j
- End Select
" h" ^# `6 Q" \% r. u - End Sub
) `6 [0 C! e# X/ ~
( \& r$ Q2 R1 H/ o( A- & C4 m7 X; i2 I
- Private Sub AsmState(ByVal State As Boolean)
) V/ K' h: h- j" S/ B# m6 ]0 e - Dim asm As asmNum
) |7 @2 I, d- A) p: U5 C7 N8 v - Select Case State
8 p" n5 u7 E# U9 z. A7 \1 p% z - Case True) Z8 w, t# H5 T( i0 i x7 m
- asm.nuM1 = &H907 q' F5 t2 \& ]: B8 e
- asm.nuM2 = &H903 |5 E; k/ K& ~6 D! \7 @; E) P2 j; B
- asm.nuM3 = &H90
2 ?6 z5 c) C; z; k" `/ `# X' o - Case False$ r0 e: V6 K! d" L9 B8 h+ ?
- asm.nuM1 = &HD9
3 m8 Y6 E# M3 o. O# Q! b, p - asm.nuM2 = &H58% C! _- J6 U* w7 j. q
- asm.nuM3 = &H1C8 ^% J( i, r$ y: J4 {( _" [- E( N
- End Select; {* s# @- |; m' X0 I3 N# E* e
- Call SetMemoryAsm(adrTime, asm)( @6 Z4 ]$ P6 ?& F: s3 |
- End Sub4 p, ]/ o. U. v1 S3 D: J% E
- # F# k2 k( x" x) g4 M
- + X. t% I1 G+ s8 m
- Private Sub chkGameTime_Click()
) ]* U$ G. r$ W- z- d$ Q* V/ X - AsmState (chkGameTime.Value)6 R/ Q) i! c# m% e) \$ q
- End Sub
+ j* P0 T6 A) R9 e' B: @+ b' U - 0 ^& X0 b$ u: J9 }, V1 b4 j
- ' q3 p# w! j' S: J$ T/ L& F
- Private Sub isOpen(ByVal State As Boolean)
( f! O( O0 T) z. ^* j" f5 Y3 J( i - Select Case State
% g& Z& A* y& A6 p - Case True1 J: t) D5 [! }# o, z* R% ~; A
- If FindGame = True Then
) e2 [5 B; f5 a \' f7 o& a - hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)/ ~( l% s3 ?2 W& G" F2 \
- TrainerState (True)' n6 L) {8 ^- _ u6 \' g# B
- End If0 A- T5 m) I* L* n1 o) C9 M3 h8 a' o
- Case False# x9 ]+ L$ U1 t8 S
- If FindGame = True Then. } u- a8 Q5 u, o3 _6 W
- AsmState (False), w* h3 M6 ]! ^/ v w: @
- CloseHandle hProcess
2 O4 W5 ?$ l! y - End If
* _$ S8 j S5 f3 y - End Select7 I; A8 n0 |: P
- End Sub6 T' q; D1 z5 a' A9 E+ v! p0 ]/ _9 L- ~
- * P3 D7 A) a( f V
- / X3 ^% P* E; D
- Private Sub btnCatchGame_Click()" Q7 r8 G W1 a4 x% u* _
- Select Case btnCatchGame.Caption
], ^4 [: c4 ^8 B - Case "CatchGame"1 ^' N9 [) ?" |; p1 O y. k
- isOpen (True)
" q# y" |! N, [) D - Case "ReleaseGame"
. L4 K4 M$ z& K3 ^( c) H - isOpen (False)
% t1 [+ h: l1 n6 W" c/ P$ p! r% E - TrainerState (False)
! K+ [' N. x+ ?: I# k6 H( m - End Select
/ q6 O- b3 U5 X% A, a6 z6 a6 L - End Sub5 Z* o4 d/ V8 {
- 9 i# W9 v9 x) r9 l- G2 H4 U1 j
- Private Sub btnRefresh_Click()
: U' w. R7 }4 u. `, [
- r& f4 P/ D9 b% i- Dim mineColumn As Byte, mineLine As Byte
& B" s. R* ^7 y - Dim adrPoint As Long, adrTemp As Long, adrColumn As Long
) g0 ~ e( U8 V; y) y7 [5 k6 z - Dim i As Byte, j As Byte
2 @# x$ U7 G6 Y/ B! ~, i - $ |% o$ C4 A2 [! L: T: e
- 3 V) Q6 w0 y* D5 u( O: G
-
8 N- ?; `6 m8 F! f1 a) r. o& k - btnRefresh.Enabled = False
G4 P! f" L; w0 g -
& e2 g4 u9 ?5 b8 }+ c - adrTemp = GetMemory(adrMine)
9 A% m G0 z* [) s) i* ^2 Z - adrPoint = GetMemory(adrTemp + &H10)
6 F* ~2 A9 L3 r' h. ~. i -
+ u' K4 K- k( c0 L! t% c - mineLine = GetMemory(adrPoint + &H8) - 1
) U3 y7 m+ a3 [7 v - mineColumn = GetMemory(adrPoint + &HC) - 1
5 C G9 @) a! v2 S5 u# q _/ p -
8 h' k5 I$ [0 j( M }8 X5 Z - adrPoint = GetMemory(adrPoint + &H44); d0 G* a7 t9 N6 F" M
- adrPoint = GetMemory(adrPoint + &HC)
. o8 [# A J3 E: Z, _8 W, H7 W& c! t - ' m. K: ?+ ^! c2 J2 A2 Z
- : L" Y+ L1 w$ p0 ^0 [9 M4 Y* h
- ( x' G' s5 f* `1 Q, V
- For i = 0 To 30
+ i6 ?$ T6 X6 X' |) V; M% ]7 T, r - adrColumn = GetMemory(adrPoint + i * 4)4 d4 x7 w* W8 V7 h
- adrColumn = GetMemory(adrColumn + &HC)' M: w% d) e1 S5 ^2 I3 s) t2 M
- For j = 0 To 23* L* z+ U$ E# c+ T% G" {5 V
- If i > mineColumn Or j > mineLine Then
: q4 V% a$ [% x- Q8 \( J' O& i - Sheet1.Cells(j + 1, i + 1) = ""' G) U3 q: d2 }. c: g
- Else9 L4 _0 w4 `8 y& g. E5 C
- Sheet1.Cells(j + 1, i + 1) = GetMemory(adrColumn + j, 1)
! R# z8 N2 Y+ Z) g% I, ^ - End If. A/ v! Y! d2 ~/ c4 w9 F
- Next j
* l% g* H Z4 V - Next i+ ]( Z9 a. V: F+ P5 x9 C4 a
- btnRefresh.Enabled = True7 G3 V. o2 F y* \
- 2 ~' t& F4 A2 v# X0 z: C( L8 R
- : |8 X. [+ W$ [- E! O; O
- End Sub* N9 N8 b9 E0 i- p. \' l
- " v. K+ Z5 p: `( r% @
- Private Sub UserForm_Initialize()- [0 q8 z+ L, }- {& }3 k7 T
- TrainerState (False)
" S5 P& j v B& D1 O - Sheet1.Cells(1, 2) = 16 o0 |) e) l8 _. u! S
- End Sub
* o& U9 L0 k: z+ t" Z
) o( C- ]/ c2 T, _6 W3 p- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
5 |9 X+ ~+ D# q' s0 d1 ~/ @1 J8 W6 s - isOpen (False)
# a7 ^3 S1 J- | - End Sub
0 ~! _- I, ?8 z! [' j" A
复制代码
' j7 @! d9 ]' J" v2 y; b. i7 c6 [# N5 a5 I4 a1 O% m; q: k$ V
+ A! b+ ^0 e' |
. c3 P$ M* M# @7 L3 S' e% j( l
|
|