Skip to content

Commit

Permalink
Payload: Add WritePointer patch type
Browse files Browse the repository at this point in the history
  • Loading branch information
mkwcat committed Feb 22, 2024
1 parent 35d845d commit 6350c30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/wwfcCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,19 @@ typedef enum {
* @param arg1 Temporary register to use for call.
*/
WWFC_PATCH_TYPE_BRANCH_CTR_LINK = 5,

/**
* Write a pointer specified in `arg0` to the destination `address`.
* @param arg0 Pointer destination address.
* @param arg1 Not used.
*/
WWFC_PATCH_TYPE_WRITE_POINTER = 6,
} wwfc_patch_type;

/**
* Flags for different patch levels.
*/
typedef enum {

/**
* Critical, used for security patches and other things required to connect
* to the server. This has no value and is always automatically applied.
Expand Down
11 changes: 11 additions & 0 deletions payload/wwfcPatch.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "wwfcPatch.hpp"
#include <cstring>
#include <import/revolution.h>
#include <wwfcCommon.h>

namespace wwfc::Patch
{
Expand Down Expand Up @@ -111,6 +112,16 @@ void ApplyPatch(u32 base, wwfc_patch& patch)
address[3] = 0x4E800421;
flushSize = sizeof(u32) * 4;
break;

/**
* Write a pointer specified in `arg0` to the destination `address`.
* @param arg0 Pointer destination address.
* @param arg1 Not used.
*/
case WWFC_PATCH_TYPE_WRITE_POINTER:
*address = baseArg0;
flushSize = sizeof(u32);
break;
}

RVL::DCFlushRange(address, flushSize);
Expand Down
10 changes: 10 additions & 0 deletions payload/wwfcPatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ constexpr wwfc_patch WriteString(u8 level, u32 address, const char (&string)[N])
};
}

constexpr wwfc_patch WritePointer(u8 level, u32 address, auto pointer)
{
return wwfc_patch{
.level = level,
.type = WWFC_PATCH_TYPE_WRITE_POINTER,
.address = address,
.arg0 = u32(+pointer),
};
}

constexpr wwfc_patch
WriteASM(u8 level, u32 address, u32 instructionCount, auto function)
{
Expand Down

0 comments on commit 6350c30

Please sign in to comment.