Skip to content

Commit

Permalink
Added Virtua Cop 3 support for Cxbx-Reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
argonlefou committed Nov 14, 2018
1 parent 889b021 commit 32688b3
Show file tree
Hide file tree
Showing 10 changed files with 527 additions and 45 deletions.
1 change: 1 addition & 0 deletions DemulShooter/DemulShooter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Game_ArtIsDead.cs" />
<Compile Include="Game_BE.cs" />
<Compile Include="Game_Bhapc.cs" />
<Compile Include="Game_CxBxVcop3.cs" />
<Compile Include="Game_DemulAtomiswave.cs" />
<Compile Include="Game_BE_OLD.cs" />
<Compile Include="Game_Dolphin5.cs" />
Expand Down
2 changes: 1 addition & 1 deletion DemulShooter/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Game()

#region Screen

public void GetScreenResolution()
public virtual void GetScreenResolution()
{
_screenWidth = Screen.PrimaryScreen.Bounds.Width;
_screenHeight = Screen.PrimaryScreen.Bounds.Height;
Expand Down
424 changes: 424 additions & 0 deletions DemulShooter/Game_CxBxVcop3.cs

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions DemulShooter/Game_TtxGundam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DemulShooter
{
class Game_TtxGundam : Game
{
private const string FOLDER_GAMEDATA = @"MemoryData\ttx";
private const string FOLDER_GAMEDATA = @"MemoryData\ttx";

/*** MEMORY ADDRESSES **/
protected int _P1_X_Offset;
Expand Down Expand Up @@ -39,19 +39,19 @@ class Game_TtxGundam : Game
private byte _Pedal1_Key;
private bool _isPedal1_Pushed = false;
private int _Pedal2_Enable;
private byte _Pedal2_Key;
private byte _Pedal2_Key;
private bool _isPedal2_Pushed = false;

Memory _Cave_Check1, _Cave_Check2;

/// <summary>
/// Constructor
/// </summary>
public Game_TtxGundam(string RomName, int Pedal1_Enable, byte Pedal1_Key, int Pedal2_Enable, byte Pedal2_Key, bool Verbose)
: base ()
public Game_TtxGundam(string RomName, int Pedal1_Enable, byte Pedal1_Key, int Pedal2_Enable, byte Pedal2_Key, bool Verbose)
: base()
{
GetScreenResolution();

_RomName = RomName;
_Pedal1_Enable = Pedal1_Enable;
_Pedal1_Key = Pedal1_Key;
Expand Down Expand Up @@ -115,7 +115,7 @@ private void tProcess_Tick(Object Sender, EventArgs e)
Environment.Exit(0);
}
}
}
}

#region File I/O

Expand Down Expand Up @@ -271,7 +271,7 @@ public override bool GameScale(MouseInfo Mouse, int Player)
//Player One will have X value cut-off to [0-639] next
//For player 2 we first shift value to the left
if (Player == 2)
Mouse.pTarget.X -= 640;
Mouse.pTarget.X -= 640;
}
else if (_RomName.Equals("gsoz"))
{
Expand All @@ -296,13 +296,13 @@ public override bool GameScale(MouseInfo Mouse, int Player)
if (Mouse.pTarget.X < 1)
Mouse.pTarget.X = 1;
if (Mouse.pTarget.X > 639)
Mouse.pTarget.X = 639;
Mouse.pTarget.X = 639;
if (Mouse.pTarget.Y < 1)
Mouse.pTarget.Y = 1;
Mouse.pTarget.Y = 1;
if (Mouse.pTarget.Y > (int)dMaxY)
Mouse.pTarget.Y = (int)dMaxY;
return true;
Mouse.pTarget.Y = (int)dMaxY;

return true;
}
catch (Exception ex)
{
Expand All @@ -326,7 +326,7 @@ private void SetHack()
SetNops((int)_TargetProcess_MemoryBaseAddress, _Btn_Up_NOP_Offset);
SetNops((int)_TargetProcess_MemoryBaseAddress, _Btn_Up_NOP_Offset2);
SetNops((int)_TargetProcess_MemoryBaseAddress, _Btn_Reset_NOP_Offset);

/***
* If neither Pedal1 nor Pedal2 are enabled, no need for a codecave (default game).
* Else, We need to make 2 codecave for the 2 checking procedure (X-Y min-max)
Expand Down Expand Up @@ -436,7 +436,7 @@ private void SetHack()
Buffer.AddRange(BitConverter.GetBytes(jumpTo));
Buffer.Add(0x90);
Win32.WriteProcessMemory((int)ProcessHandle, (int)_TargetProcess_MemoryBaseAddress + _Border_Check1_Injection_Offset, Buffer.ToArray(), Buffer.Count, ref bytesWritten);

_Cave_Check2 = new Memory(_TargetProcess, _TargetProcess.MainModule.BaseAddress);
_Cave_Check2.Open();
_Cave_Check2.Alloc(0x800);
Expand Down Expand Up @@ -485,7 +485,7 @@ private void SetHack()
_Cave_Check2.Write_jng((int)_TargetProcess_MemoryBaseAddress + 0xA7B85);
//jmp EXIT
_Cave_Check2.Write_StrBytes("E9 2E 00 00 00");

//player2:
if (_Pedal2_Enable != 0)
//cmp di, 00
Expand Down Expand Up @@ -523,7 +523,7 @@ private void SetHack()
_Cave_Check2.Write_jng((int)_TargetProcess_MemoryBaseAddress + 0xA7B85);
//jmp EXIT
_Cave_Check2.Write_jmp((int)_TargetProcess_MemoryBaseAddress + _Border_Check2_Injection_Return_Offset);

WriteLog("Adding check2 CodeCave at : 0x" + _Cave_Check2.CaveAddress.ToString("X8"));
bytesWritten = 0;
jumpTo = _Cave_Check2.CaveAddress - ((int)_TargetProcess_MemoryBaseAddress + _Border_Check2_Injection_Offset) - 5;
Expand All @@ -535,7 +535,7 @@ private void SetHack()

ApplyKeyboardHook();
}

//Initializing values
byte[] initX = { 0x10, 0 };
byte[] initY = { 0x10, 0 };
Expand All @@ -556,13 +556,13 @@ protected override IntPtr KeyboardHookCallback(int nCode, IntPtr wParam, IntPtr
Win32.KBDLLHOOKSTRUCT s = (Win32.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32.KBDLLHOOKSTRUCT));
if ((UInt32)wParam == Win32.WM_KEYDOWN)
{
if (s.scanCode == _Pedal1_Key && _Pedal1_Enable !=0)
if (s.scanCode == _Pedal1_Key && _Pedal1_Enable != 0)
{
_isPedal1_Pushed = true;
WriteBytes((int)_Cave_Check1.CaveAddress + 0x21, new byte[] { 0x80, 0x02 }); //640
WriteBytes((int)_Cave_Check2.CaveAddress + 0x21, new byte[] { 0x80, 0x02 }); //640
}
else if (s.scanCode == _Pedal2_Key && _Pedal2_Enable !=0)
else if (s.scanCode == _Pedal2_Key && _Pedal2_Enable != 0)
{
_isPedal2_Pushed = true;
WriteBytes((int)_Cave_Check1.CaveAddress + 0x54, new byte[] { 0x80, 0x02 }); //640
Expand All @@ -573,23 +573,23 @@ protected override IntPtr KeyboardHookCallback(int nCode, IntPtr wParam, IntPtr
{
if (s.scanCode == _Pedal1_Key && _Pedal1_Enable != 0)
{
_isPedal1_Pushed = false;
_isPedal1_Pushed = false;
WriteBytes((int)_Cave_Check1.CaveAddress + 0x21, new byte[] { 0x00, 0x00 }); //0
WriteBytes((int)_Cave_Check2.CaveAddress + 0x21, new byte[] { 0x00, 0x00 }); //0
}
else if (s.scanCode == _Pedal2_Key && _Pedal2_Enable != 0)
{
_isPedal2_Pushed = false;
_isPedal2_Pushed = false;
WriteBytes((int)_Cave_Check1.CaveAddress + 0x54, new byte[] { 0x00, 0x00 }); //0
WriteBytes((int)_Cave_Check2.CaveAddress + 0x54, new byte[] { 0x00, 0x00 }); //0
}
}
}
return Win32.CallNextHookEx(_KeyboardHookID, nCode, wParam, lParam);
}
}

public override void SendInput(MouseInfo mouse, int Player)
{
{
byte[] bufferX = { (byte)(mouse.pTarget.X & 0xFF), (byte)(mouse.pTarget.X >> 8) };
byte[] bufferY = { (byte)(mouse.pTarget.Y & 0xFF), (byte)(mouse.pTarget.Y >> 8) };

Expand All @@ -602,7 +602,7 @@ public override void SendInput(MouseInfo mouse, int Player)
//Inputs
if (mouse.button == Win32.RI_MOUSE_LEFT_BUTTON_DOWN)
{
WriteBytes((int)_TargetProcess_MemoryBaseAddress + _P1_Trigger_Offset, new byte[] { 0x01, 0x01, 0x00});
WriteBytes((int)_TargetProcess_MemoryBaseAddress + _P1_Trigger_Offset, new byte[] { 0x01, 0x01, 0x00 });
}
else if (mouse.button == Win32.RI_MOUSE_LEFT_BUTTON_UP)
{
Expand Down Expand Up @@ -633,7 +633,7 @@ public override void SendInput(MouseInfo mouse, int Player)
}
}
else if (Player == 2)
{
{
//Write Axis
WriteBytes((int)_TargetProcess_MemoryBaseAddress + _P2_X_Offset, bufferX);
WriteBytes((int)_TargetProcess_MemoryBaseAddress + _P2_Y_Offset, bufferY);
Expand All @@ -649,7 +649,7 @@ public override void SendInput(MouseInfo mouse, int Player)
}
if (mouse.button == Win32.RI_MOUSE_MIDDLE_BUTTON_DOWN)
{
WriteBytes((int)_TargetProcess_MemoryBaseAddress + _P2_WeaponChange_Offset, new byte[] { 0x01, 0x01, 0x00 });
WriteBytes((int)_TargetProcess_MemoryBaseAddress + _P2_WeaponChange_Offset, new byte[] { 0x01, 0x01, 0x00 });
}
else if (mouse.button == Win32.RI_MOUSE_MIDDLE_BUTTON_UP)
{
Expand Down
25 changes: 20 additions & 5 deletions DemulShooter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ static void Main(string[] args)
bool isVerbose = false;
string _target = string.Empty;

string[] _Targets = new string[] { "demul057", "demul058", "demul07a", "dolphin4", "dolphin5", "globalvr", "model2", "model2m", "ringwide", "ttx", "windows", "wip" };
string[] _Targets = new string[] { "chihiro", "demul057", "demul058", "demul07a", "dolphin4", "dolphin5", "globalvr", "model2", "model2m", "ringwide", "ttx", "windows", "wip" };
string[] _DemulRoms = new string[] { "braveff", "claychal", "confmiss", "deathcox", "hotd2", "hotd2o", "hotd2p", "lupinsho", "mok", "ninjaslt", "ninjaslta", "ninjasltj", "ninjasltu", "pokasuka", "rangrmsn", "sprtshot", "xtrmhunt", "xtrmhnt2" };
string[] _Model2Roms = new string[] { "bel", "gunblade", "hotd", "rchase2", "vcop", "vcop2" };
string[] _WindowsRoms = new string[] { "artdead", "hfa", "hfa2p", "hfa_s", "hfa2p_s", "hfss", "hfss2p", "hfss_s", "hfss2p_s", "hod2pc", "hod3pc", "reload" };
string[] _TTXRoms = new string[] { "sha", "eadp", "gattack4", "gsoz", "gsoz2p", "hmuseum", "hmuseum2", "mgungun2" };
string[] _GlobalVrRoms = new string[] { "aliens", "alienshasp", "farcry", "fearland" };
string[] _RingWideRoms = new string[] { "sgg", "lgi", "lgi3d", "og", "sdr" };
string[] _WipRoms = new string[] { "bestate", "wartran", "bhapc" };
string[] _ChihiroRoms = new string[] { "vcop3" };
string[] _WipRoms = new string[] { "bestate", "wartran", "bhapc"};

if (args.Length > 0)
{
Expand All @@ -45,12 +46,13 @@ static void Main(string[] args)
{
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("DemulShooter v8.2");
Console.WriteLine("Build date : July, 27th 2018");
Console.WriteLine("DemulShooter v8.3b");
Console.WriteLine("Build date : November, 14th 2018");
Console.WriteLine("");
Console.WriteLine("usage : DemulShooter.exe -target=[target] -rom=[rom] [options]");
Console.WriteLine("");
Console.WriteLine("Supported [target] :");
Console.WriteLine("chihiro\tCxbx-Reloaded 001100eaf (30 Oct 2018)");
Console.WriteLine("demul057\tDemul v0.57");
Console.WriteLine("demul058\tDemul v0.582");
Console.WriteLine("demul07a\tDemul v0.7a 180428");
Expand All @@ -64,6 +66,9 @@ static void Main(string[] args)
Console.WriteLine("windows\t\tWindows games");
Console.WriteLine("");
Console.WriteLine("Supported [rom] :");
Console.WriteLine("Chihiro roms :");
Console.WriteLine(" vcop3\t\tVirtua Cop 3");
Console.WriteLine("");
Console.WriteLine("Demul roms :");
Console.WriteLine(" braveff\tBrave Fire Fighters");
Console.WriteLine(" claychal\tSega Clay Challenge");
Expand Down Expand Up @@ -173,7 +178,17 @@ static void Main(string[] args)
if (args[i].ToLower().StartsWith("-rom"))
{
string rom = (args[i].ToLower().Split('='))[1].Trim();
if (_target.StartsWith("demul"))
if (_target.StartsWith("chihiro"))
{
if (!CheckParameter(rom, _ChihiroRoms))
{
Console.WriteLine("Unsupported Chihiro rom parameter : \"" + rom + "\". See help for supported roms list");
//Dangerous : send ENTER to active window
System.Windows.Forms.SendKeys.SendWait("{ENTER}");
Environment.Exit(0);
}
}
else if (_target.StartsWith("demul"))
{
if (!CheckParameter(rom, _DemulRoms))
{
Expand Down
2 changes: 1 addition & 1 deletion DemulShooter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
[assembly: AssemblyVersion("8.2.0.*")]
[assembly: AssemblyVersion("8.3.0.*")]
18 changes: 17 additions & 1 deletion DemulShooter/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,28 @@ public static string GetDeviceType(uint device)
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesWritten);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool QueryFullProcessImageName([In]IntPtr hProcess, [In]int dwFlags, [Out]StringBuilder lpExeName, ref int lpdwSize);

[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetDesktopWindow();

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowTextLength(IntPtr hWnd);

[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowText(IntPtr Hwnd, StringBuilder lpString, int nMaxCount);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindowVisible(IntPtr hWnd);

[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetWindowRect(IntPtr hWnd, ref Rect rectangle);

Expand Down Expand Up @@ -254,7 +270,7 @@ public static string GetDeviceType(uint device)
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetForegroundWindow(IntPtr hWnd);
public static extern IntPtr SetForegroundWindow(IntPtr hWnd);

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
Expand Down
2 changes: 1 addition & 1 deletion DemulShooter/WndParam.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32688b3

Please sign in to comment.