-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.cpp
More file actions
64 lines (50 loc) · 1.68 KB
/
commands.cpp
File metadata and controls
64 lines (50 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "commands.h"
#include "Patch.h"
#include "PatchManager.h"
namespace {
void ListCommandCallback(const CCommand &command) {
PatchCollection &patches = g_PatchManager.GetAllPatches();
g_pSM->LogMessage(myself, "Name\tDescription\tAddress\tLength\tApplied");
for (PatchCollection::iterator iter = patches.begin(); iter != patches.end(); ++iter) {
g_pSM->LogMessage(myself, "%s\t%s\t%p\t%d\t%s",
(*iter)->GetName().c_str(),
(*iter)->GetDescription().c_str(),
(*iter)->GetAddress(),
(*iter)->GetLength(),
(*iter)->IsPatched() ? "Yes" : "No");
}
}
Patch *FindPatchByName(const CCommand &command) {
if (command.ArgC() < 2) {
g_pSM->LogError(myself, "Syntax: %s <name>", command.Arg(0));
return NULL;
}
Patch *patch = g_PatchManager.GetPatchByName(command.Arg(1));
if (patch == NULL) {
g_pSM->LogError(myself, "Could not find patch \"%s\"", command.Arg(1));
return NULL;
}
return patch;
}
void PatchCommandCallback(const CCommand &command) {
Patch *patch = FindPatchByName(command);
if (patch == NULL)
return;
patch->ApplyPatch();
}
void UnpatchCommandCallback(const CCommand &command) {
Patch *patch = FindPatchByName(command);
if (patch == NULL)
return;
patch->Unpatch();
}
}
ListCommand::ListCommand()
: ConCommand("sm_codepatch_list", ::ListCommandCallback, "Lists available code patches and their status") {
}
PatchCommand::PatchCommand()
: ConCommand("sm_codepatch_patch", ::PatchCommandCallback, "Applies a code patch") {
}
UnpatchCommand::UnpatchCommand()
: ConCommand("sm_codepatch_unpatch", ::UnpatchCommandCallback, "Unloads a code patch") {
}