Skip to content

Commit 5e4e0c8

Browse files
committed
Add more tools and save work
I haven't tested the tools yet so idk if they work
1 parent 1aee403 commit 5e4e0c8

File tree

11 files changed

+1737
-1
lines changed

11 files changed

+1737
-1
lines changed

CheatEngineTools.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public class CheatEngineTools
1010
private readonly OpenProcessTool _openProcessTool;
1111
private readonly ThreadListTool _threadListTool;
1212
private readonly ProcessStatusTool _processStatusTool;
13+
private readonly MemoryReadTool _memoryReadTool;
14+
private readonly MemoryWriteTool _memoryWriteTool;
15+
private readonly ConversionTool _conversionTool;
16+
private readonly AOBScanTool _aobScanTool;
17+
private readonly DisassembleTool _disassembleTool;
18+
private readonly GetInstructionSizeTool _getInstructionSizeTool;
1319

1420
public CheatEngineTools(McpPlugin plugin)
1521
{
@@ -18,6 +24,12 @@ public CheatEngineTools(McpPlugin plugin)
1824
_openProcessTool = new OpenProcessTool(plugin);
1925
_threadListTool = new ThreadListTool(plugin);
2026
_processStatusTool = new ProcessStatusTool(plugin);
27+
_memoryReadTool = new MemoryReadTool(plugin);
28+
_memoryWriteTool = new MemoryWriteTool(plugin);
29+
_conversionTool = new ConversionTool(plugin);
30+
_aobScanTool = new AOBScanTool(plugin);
31+
_disassembleTool = new DisassembleTool(plugin);
32+
_getInstructionSizeTool = new GetInstructionSizeTool(plugin);
2133
}
2234

2335
public LuaResponse ExecuteLua(LuaRequest request)
@@ -44,5 +56,35 @@ public ProcessStatusResponse GetProcessStatus()
4456
{
4557
return _processStatusTool.GetProcessStatus();
4658
}
59+
60+
public MemoryReadResponse ReadMemory(MemoryReadRequest request)
61+
{
62+
return _memoryReadTool.ReadMemory(request);
63+
}
64+
65+
public BaseResponse WriteMemory(MemoryWriteRequest request)
66+
{
67+
return _memoryWriteTool.WriteMemory(request);
68+
}
69+
70+
public ConversionResponse Convert(ConversionRequest request)
71+
{
72+
return _conversionTool.Convert(request);
73+
}
74+
75+
public AOBScanResponse AOBScan(AOBScanRequest request)
76+
{
77+
return _aobScanTool.AOBScan(request);
78+
}
79+
80+
public DisassembleResponse Disassemble(DisassembleRequest request)
81+
{
82+
return _disassembleTool.Disassemble(request);
83+
}
84+
85+
public GetInstructionSizeResponse GetInstructionSize(GetInstructionSizeRequest request)
86+
{
87+
return _getInstructionSizeTool.GetInstructionSize(request);
88+
}
4789
}
4890
}

Controllers/CheatEngineController.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,48 @@ public ProcessStatusResponse GetProcessStatus()
4848
return _tools.GetProcessStatus();
4949
}
5050

51+
[HttpPost]
52+
[Route("read-memory")]
53+
public MemoryReadResponse ReadMemory([FromBody] MemoryReadRequest request)
54+
{
55+
return _tools.ReadMemory(request);
56+
}
57+
58+
[HttpPost]
59+
[Route("write-memory")]
60+
public BaseResponse WriteMemory([FromBody] MemoryWriteRequest request)
61+
{
62+
return _tools.WriteMemory(request);
63+
}
64+
65+
[HttpPost]
66+
[Route("convert")]
67+
public ConversionResponse Convert([FromBody] ConversionRequest request)
68+
{
69+
return _tools.Convert(request);
70+
}
71+
72+
[HttpPost]
73+
[Route("aob-scan")]
74+
public AOBScanResponse AOBScan([FromBody] AOBScanRequest request)
75+
{
76+
return _tools.AOBScan(request);
77+
}
78+
79+
[HttpPost]
80+
[Route("disassemble")]
81+
public DisassembleResponse Disassemble([FromBody] DisassembleRequest request)
82+
{
83+
return _tools.Disassemble(request);
84+
}
85+
86+
[HttpPost]
87+
[Route("get-instruction-size")]
88+
public GetInstructionSizeResponse GetInstruction([FromBody] GetInstructionSizeRequest request)
89+
{
90+
return _tools.GetInstructionSize(request);
91+
}
92+
5193
[HttpGet]
5294
[Route("health")]
5395
public IHttpActionResult GetHealth()

Models/LuaModels.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,73 @@ public class ProcessStatusResponse : BaseResponse
4343
public bool IsOpen { get; set; }
4444
public string ProcessName { get; set; }
4545
}
46+
47+
public class MemoryReadRequest
48+
{
49+
public string Address { get; set; }
50+
public string DataType { get; set; }
51+
public bool? Signed { get; set; }
52+
public int? ByteCount { get; set; }
53+
public bool? ReturnAsTable { get; set; }
54+
public int? MaxLength { get; set; }
55+
public bool? WideChar { get; set; }
56+
}
57+
58+
public class MemoryReadResponse : BaseResponse
59+
{
60+
public object Value { get; set; }
61+
}
62+
63+
public class MemoryWriteRequest
64+
{
65+
public string Address { get; set; }
66+
public string DataType { get; set; }
67+
public object Value { get; set; }
68+
public int[] ByteValues { get; set; }
69+
public bool? WideChar { get; set; }
70+
}
71+
72+
public class ConversionRequest
73+
{
74+
public string Input { get; set; }
75+
public string ConversionType { get; set; }
76+
}
77+
78+
public class ConversionResponse : BaseResponse
79+
{
80+
public string Output { get; set; }
81+
}
82+
83+
public class AOBScanRequest
84+
{
85+
public string AOBString { get; set; }
86+
public string ProtectionFlags { get; set; }
87+
public int? AlignmentType { get; set; }
88+
public string AlignmentParam { get; set; }
89+
}
90+
91+
public class AOBScanResponse : BaseResponse
92+
{
93+
public string[] Addresses { get; set; }
94+
}
95+
96+
public class DisassembleRequest
97+
{
98+
public string Address { get; set; }
99+
}
100+
101+
public class DisassembleResponse : BaseResponse
102+
{
103+
public string Disassembly { get; set; }
104+
}
105+
106+
public class GetInstructionSizeRequest
107+
{
108+
public string Address { get; set; }
109+
}
110+
111+
public class GetInstructionSizeResponse : BaseResponse
112+
{
113+
public int Size { get; set; }
114+
}
46115
}

Tools/AOBScanTool.cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using CESDK;
4+
using CeMCP.Models;
5+
6+
namespace CeMCP.Tools
7+
{
8+
public class AOBScanTool
9+
{
10+
private readonly McpPlugin _plugin;
11+
12+
public AOBScanTool(McpPlugin plugin)
13+
{
14+
_plugin = plugin ?? throw new ArgumentNullException(nameof(plugin));
15+
}
16+
17+
public AOBScanResponse AOBScan(AOBScanRequest request)
18+
{
19+
try
20+
{
21+
if (string.IsNullOrWhiteSpace(request.AOBString))
22+
{
23+
return new AOBScanResponse
24+
{
25+
Success = false,
26+
Error = "AOBString parameter is required"
27+
};
28+
}
29+
30+
var lua = _plugin.sdk.lua;
31+
32+
// Build Lua code for AOB scanning
33+
string luaCode;
34+
35+
// Build parameter list for AOBScan function
36+
var parameters = new List<string> { $"\"{request.AOBString}\"" };
37+
38+
if (!string.IsNullOrWhiteSpace(request.ProtectionFlags))
39+
{
40+
parameters.Add($"\"{request.ProtectionFlags}\"");
41+
}
42+
43+
if (request.AlignmentType.HasValue)
44+
{
45+
parameters.Add(request.AlignmentType.Value.ToString());
46+
47+
if (!string.IsNullOrWhiteSpace(request.AlignmentParam))
48+
{
49+
parameters.Add($"\"{request.AlignmentParam}\"");
50+
}
51+
}
52+
53+
string parameterString = string.Join(", ", parameters);
54+
55+
luaCode = $@"
56+
local success, result = pcall(function()
57+
return AOBScan({parameterString})
58+
end)
59+
60+
if success and result then
61+
-- Convert StringList to table for easier handling
62+
local addresses = {{}}
63+
if result.Count then
64+
for i = 0, result.Count - 1 do
65+
addresses[i + 1] = result[i]
66+
end
67+
end
68+
result.destroy()
69+
return addresses
70+
else
71+
return {{}}
72+
end
73+
";
74+
75+
int luaResult = lua.DoString(luaCode);
76+
if (luaResult != 0)
77+
{
78+
string error = lua.ToString(-1);
79+
lua.Pop(1);
80+
return new AOBScanResponse
81+
{
82+
Success = false,
83+
Error = $"Lua execution failed: {error}"
84+
};
85+
}
86+
87+
// Get the result
88+
var addresses = new List<string>();
89+
90+
if (lua.IsTable(-1))
91+
{
92+
int tableLength = lua.ObjLen(-1);
93+
94+
for (int i = 1; i <= tableLength; i++)
95+
{
96+
lua.PushInteger(i);
97+
lua.GetTable(-2);
98+
99+
if (lua.IsString(-1))
100+
{
101+
string address = lua.ToString(-1);
102+
addresses.Add(address);
103+
}
104+
lua.Pop(1);
105+
}
106+
}
107+
else if (lua.IsNil(-1))
108+
{
109+
// No results found, which is valid
110+
}
111+
112+
lua.Pop(1);
113+
114+
return new AOBScanResponse
115+
{
116+
Success = true,
117+
Addresses = addresses.ToArray()
118+
};
119+
}
120+
catch (Exception ex)
121+
{
122+
return new AOBScanResponse
123+
{
124+
Success = false,
125+
Error = ex.Message
126+
};
127+
}
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)