Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Make module parameter required
Browse files Browse the repository at this point in the history
  • Loading branch information
BC46 committed Dec 13, 2023
1 parent 1d51a08 commit 4f55067
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br /><br />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.<br /><br />For a 32-bit signed integer, an integer should be given which fits in the supported range.<br /><br />For signed bytes, values should be given between -128 and 127 (inclusive).<br /><br />For floats, a float value is expected (4 bytes). <br /><br />**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. |
Expand Down
11 changes: 5 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

DWORD _;

typedef enum PatchType {
typedef enum PatchType
{
Hex, Int, Byte, Float, Double
} PatchType;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4f55067

Please sign in to comment.