Code:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MediviaLightHack
{
publicpartialclassMediviaLightHack : Form
{
Process MediviaProcess;
IntPtr MediviaProcessHandle;
uint MediviaBaseAddress;
uint WorldLightAddress;
uint WorldLightPointer = 0xDE18A;
uint WorldLightNop1 = 0xDE188;
uint WorldLightNop2 = 0xCCD23;
byte[] WorldLightNopArray1 = new byte[6] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
byte[] WorldLightNopArray2 = new byte[10] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 };
uint SelfLightAddress;
uint SelfLightPointer = 0x54C090;
System.Timers.Timer LightHackTimer;
[DllImport("kernel32.dll")]
static extern IntPtr OpenProcess(uint dwDesiredAccess, int bInheritHandle, uint dwProcessId);
[DllImport("kernel32.dll")]
public static extern int ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, uint size, out IntPtr lpNumberOfBytesRead);
[DllImport("kernel32.dll")]
static extern int WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, uint size, out IntPtr lpNumberOfBytesWritten);
public MediviaLightHack()
{
InitializeComponent();
}
private void MediviaLightHack_Load(object sender, EventArgs e)
{
label1.Text = "Looking for Medivia client.";
foreach (Process process in Process.GetProcesses())
{
if (process.MainWindowTitle.Equals("Medivia Online", StringComparison.CurrentCultureIgnoreCase))
{
label1.Text = "Medivia client found.";
MediviaProcess = process;
// use OpenProcess to retrieve and store the handle to the Medivia client for future use with Read/WriteProcessMemory
MediviaProcessHandle = OpenProcess(0x1F0FFF, 0, (uint)MediviaProcess.Id);
// same with the base address
MediviaBaseAddress = (uint)MediviaProcess.MainModule.BaseAddress.ToInt32();
IntPtr ptrBytesRead;
IntPtr bytesWritten;
byte[] buffer = new byte[4];
// read and store the value from the pointer for the world light address
ReadProcessMemory(MediviaProcessHandle, new IntPtr(WorldLightPointer + MediviaBaseAddress), buffer, 4, out ptrBytesRead);
WorldLightAddress = BitConverter.ToUInt32(buffer, 0);
// nop (fill with 0x90) the two addresses that alter the world light value
WriteProcessMemory(MediviaProcessHandle, new IntPtr(WorldLightNop1), WorldLightNopArray1, 6, out bytesWritten);
WriteProcessMemory(MediviaProcessHandle, new IntPtr(WorldLightNop2), WorldLightNopArray2, 6, out bytesWritten);
// write 250 (max light value) to the world light address
WriteProcessMemory(MediviaProcessHandle, new IntPtr(WorldLightAddress), BitConverter.GetBytes(250), 1, out bytesWritten);
// read and store the value from the pointer for the self light address
ReadProcessMemory(MediviaProcessHandle, new IntPtr(SelfLightPointer + MediviaBaseAddress), buffer, 4, out ptrBytesRead);
SelfLightAddress = BitConverter.ToUInt32(buffer, 0) + 0xA4;
// create and start a timer to continuously set the self light address value every 100ms
// alternately, you could set this value once like the world light address and nop anything that modifies it (I never took the time to find the addresses that does that)
LightHackTimer = new System.Timers.Timer(100);
LightHackTimer.Elapsed += LightHackTimer_Elapsed;
LightHackTimer.Start();
label1.Text = "Light hack actively patching.";
return;
}
}
label1.Text = "Medivia client not found.";
}
private void LightHackTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
// this will set the self light address to 250 (max light value)
IntPtr bytesWritten;
WriteProcessMemory(MediviaProcessHandle, new IntPtr(SelfLightAddress), BitConverter.GetBytes(250), 1, out bytesWritten);
}
}
}