我致力于单人游戏的作弊。我喜欢函数组合、不变性和没有样板的代码,所以这就是我决定用 F# 编写作弊代码的原因。我完成了一些工作正常的事情。我知道代码远非完美,但今天我开始使用 F#。
我想知道是否有办法以某种方式从我的代码中消除副作用。你能给我一些提示如何实现吗?
谢谢,
拉法尔
open System;
open System.Diagnostics;
open System.Runtime.InteropServices;
open System.Text;
open System.ComponentModel;
let flip f x y = f y x
let curry f a b = f (a,b)
let uncurry f (a,b) = f a b
type MemoryOperation = int -> int -> int -> byte[]
//(f:int * int * byte[] * int * byref<int> -> bool)
[<DllImport("kernel32.dll")>]
extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId)
[<DllImport("kernel32.dll")>]
extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, int& lpNumberOfBytesWritten)
//let WriteMemory hProcess lpBaseAddress dwSize =
// let mutable buffer = Array.init dwSize byte
// let mutable lpNumberOfBytesWritten = 0
// WriteProcessMemory(hProcess, lpBaseAddress, buffer, dwSize, &lpNumberOfBytesWritten) |> ignore
// buffer
[<DllImport("kernel32.dll")>]
extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, int& lpNumberOfBytesRead)
let ReadMemory hProcess lpBaseAddress dwSize =
let mutable buffer = Array.init dwSize byte
let mutable lpNumberOfBytesRidden = 0
ReadProcessMemory(hProcess, lpBaseAddress, buffer, dwSize, &lpNumberOfBytesRidden) |> ignore
buffer
let gameProcesses = Array.toList(Process.GetProcessesByName("gameName"))
let openProcess (p: Process) =
let PROCESS_WM_READ = 0x0010
OpenProcess(PROCESS_WM_READ, false, p.Id)
let readMemory<'a>(bitConverter:byte[] -> 'a)(length:int)(memoryOperation: MemoryOperation)(memory:int)(ptr:IntPtr) =
(memoryOperation ((int)ptr) memory length) |> bitConverter
let bitConverter func = func
|> curry
|> flip <| 0
|> readMemory
let intIO = bitConverter BitConverter.ToInt32 4
let booleanIO = bitConverter BitConverter.ToBoolean 1
let charIO = bitConverter BitConverter.ToChar 1
let readInt = intIO ReadMemory
let readBoolean = booleanIO ReadMemory
let readChar = charIO ReadMemory
//let writeInt = intIO WriteMemory
//let writeBoolean = booleanIO WriteMemory
//let writeChar = charIO WriteMemory
let readHp = readInt 0x00A20D58
[<EntryPoint>]
let main argv =
while true do
gameProcesses |> (openProcess |> List.map)
|> (readHp |> List.map)
|> List.iter(printfn "%d")
0