diff --git a/README.md b/README.md index 70d55ac..8df703e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This will patch file offset `1234AB` in `common.dll` and set the float value `42 ### Patch parameters documentation | Name | Required / optional | Data type | Description | | -------- | --------- | --------- | --------- | -| module | Optional | String | Name of the binary file in which the patch should be applied. E.g. `common.dll`, `freelancer.exe`. The file name extension may be omitted. The default value is `freelancer.exe`. | +| module | Required | String | Name of the binary file in which the patch should be applied. E.g. `common.dll`, `freelancer.exe`. The file name extension may be omitted, so e.g. `freelancer` is also fine. | | offset | Required | String in hex-format | The file offset in hex-format; the patch location within the given `module`. Example: `1234AB`. | | type | Optional | String | FLPatch supports the following value types: Hexadecimal, 32-bit signed integer, signed byte, float, double. It suffices to specify these value types using `h`, `i`, `b`, `f`, `d`, respectively. Though it is also fine to e.g. specify signed byte by entering `byte`, or `BytE` (with upper case letters) as long as the string starts with one of the previously mentioned characters. The default value for type is Hexadecimal. | | value | Required | Depends on `type` | Depending on the chosen `type`, a value of the corresponding type will be expected here.

For Hexadecimal, a string should be given in hexadecimal format, e.g. `EB 07 12`, `c9aee0`. Spaces between the bytes are optional and both upper case and lower case-letters are recognized.

For a 32-bit signed integer, an integer should be given which fits in the supported range.

For signed bytes, values should be given between -128 and 127 (inclusive).

For floats, a float value is expected (4 bytes).

**NOTE:** Double values are retrieved as floats (4 bytes) and later converted to doubles (8 bytes). Hence more elaborate double values may lose their precision. | diff --git a/src/main.cpp b/src/main.cpp index 5cc671e..636a2e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,8 @@ DWORD _; -typedef enum PatchType { +typedef enum PatchType +{ Hex, Int, Byte, Float, Double } PatchType; @@ -63,7 +64,8 @@ void StringToHex(LPCSTR str, std::string &dest) } } -HMODULE __stdcall LoadLibraryAHook(LPCSTR lpLibFileName) { +HMODULE __stdcall LoadLibraryAHook(LPCSTR lpLibFileName) +{ HMODULE result = LoadLibraryA(lpLibFileName); if (result != NULL) @@ -102,16 +104,13 @@ void Init(UINT onlyAllowedModule = NULL) if (!reader.is_header("Patch")) continue; - UINT module = 0x400000; - UINT offset = NULL; + UINT module, offset = NULL; PatchType patchType = Hex; while (reader.read_value()) { if (reader.is_value("module")) - { module = (UINT) GetModuleHandleA(reader.get_value_string()); - } if (reader.is_value("offset")) offset = (UINT) strtoul(reader.get_value_string(), NULL, 16);