Skip to content

Commit

Permalink
basic support for new games
Browse files Browse the repository at this point in the history
  • Loading branch information
garungorp committed May 6, 2023
1 parent 69f84e7 commit ae12d7d
Show file tree
Hide file tree
Showing 6 changed files with 341 additions and 1 deletion.
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Frequently Asked Questions at top of README
Restore Defaults
Restart emulator and injector
Proper BIOS
Keybinds/Controller Setup is not provided
Unlisted games
PCSX2 | use pointer to PS2 RAM? "pcsx2-qtx64-avx2.exe"+342CDD0
seems to be static

Expand Down
8 changes: 7 additions & 1 deletion games/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ extern const GAMEDRIVER *GAME_PS2_EARTHDEFENSEFORCE;
extern const GAMEDRIVER *GAME_PS2_SHADOWOFROME;
extern const GAMEDRIVER *GAME_GC_TUROKEVOLUTION;
extern const GAMEDRIVER *GAME_PS2_THESUFFERING;
extern const GAMEDRIVER *GAME_PS1_007THEWORLDISNOTENOUGH;
extern const GAMEDRIVER *GAME_PS2_RETURNTOCASTLEWOLF;
extern const GAMEDRIVER *GAME_PS2_BEVERLYHILLSCOP;

static const GAMEDRIVER **GAMELIST[] =
{
Expand Down Expand Up @@ -242,7 +245,10 @@ static const GAMEDRIVER **GAMELIST[] =
&GAME_PS2_EARTHDEFENSEFORCE,
&GAME_PS2_SHADOWOFROME,
&GAME_GC_TUROKEVOLUTION,
&GAME_PS2_THESUFFERING
&GAME_PS2_THESUFFERING,
&GAME_PS1_007THEWORLDISNOTENOUGH,
&GAME_PS2_RETURNTOCASTLEWOLF,
&GAME_PS2_BEVERLYHILLSCOP
};

static const GAMEDRIVER *CURRENT_GAME = NULL;
Expand Down
118 changes: 118 additions & 0 deletions games/ps1_007twine.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//===========================================================
// Mouse Injector for Dolphin
//==========================================================================
// Copyright (C) 2019-2020 Carnivorous
// All rights reserved.
//
// Mouse Injector is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, visit http://www.gnu.org/licenses/gpl-2.0.html
//==========================================================================
#include <stdint.h>
#include "../main.h"
#include "../memory.h"
#include "../mouse.h"
#include "game.h"

#define TWINE_CAMY 0xB60F8
#define TWINE_CAMY_AIM 0xB7148
#define TWINE_CAMX 0x16BB62
#define TWINE_CAMX_AIM 0xB7140

#define TWINE_IS_IN_GAME_CUTSCENE 0xA118C
#define TWINE_IS_INTERACTION 0xA0F34

static uint8_t PS1_TWINE_Status(void);
static void PS1_TWINE_Inject(void);

static const GAMEDRIVER GAMEDRIVER_INTERFACE =
{
"007 The World Is Not Enough",
PS1_TWINE_Status,
PS1_TWINE_Inject,
1, // 1000 Hz tickrate
0 // crosshair sway supported for driver
};

const GAMEDRIVER *GAME_PS1_007THEWORLDISNOTENOUGH = &GAMEDRIVER_INTERFACE;

static float xAccumulator = 0.f;
static float yAccumulator = 0.f;

//==========================================================================
// Purpose: return 1 if game is detected
//==========================================================================
static uint8_t PS1_TWINE_Status(void)
{
// SLUS_012.72
return (PS1_MEM_ReadWord(0x9394) == 0x534C5553U &&
PS1_MEM_ReadWord(0x9398) == 0x5F303132U &&
PS1_MEM_ReadWord(0x939C) == 0x2E37323BU);
}
//==========================================================================
// Purpose: calculate mouse look and inject into current game
//==========================================================================
static void PS1_TWINE_Inject(void)
{
// TODO: disable during
// pause
// in-game cutscenes
// TODO: camBase
// TODO: cheats for each level?
// look for cheat base
// FIXME: camY popping?
// TODO: use menu (60 FPS) to find FPS cheat

// disable camY rebound level 1?, only works on level reset
// needs to be a cheat but keep here as reference for cheat base search
// PS1_MEM_WriteWord(0x52120, 0x0);
// PS1_MEM_WriteWord(0x5236C, 0x0);
// PS1_MEM_WriteWord(0x527FC, 0x0);
// PS1_MEM_WriteWord(0x52A58, 0x0);

if(xmouse == 0 && ymouse == 0) // if mouse is idle
return;

if (PS1_MEM_ReadHalfword(TWINE_IS_IN_GAME_CUTSCENE))
return;

if (PS1_MEM_ReadHalfword(TWINE_IS_INTERACTION))
return;

uint16_t camX = PS1_MEM_ReadHalfword(TWINE_CAMX);
int16_t camY = PS1_MEM_ReadInt16(TWINE_CAMY);
float camXF = (float)camX;
float camYF = (float)camY;

const float looksensitivity = (float)sensitivity / 20.f;
const float scale = 1.f;

float dx = (float)xmouse * looksensitivity * scale;
AccumulateAddRemainder(&camXF, &xAccumulator, xmouse, dx);

while (camXF > 4096)
camXF -= 4096;
while (camXF < 0)
camXF += 4096;

float ym = (float)(invertpitch ? -ymouse : ymouse);
float dy = -ym * looksensitivity * scale;
AccumulateAddRemainder(&camYF, &yAccumulator, -ym, dy);

// TODO: only clamp when in-game, not during in-game cutscenes
camYF = ClampFloat(camYF, -640.f, 800.f);

PS1_MEM_WriteHalfword(TWINE_CAMX, (uint16_t)camXF);
PS1_MEM_WriteHalfword(TWINE_CAMX_AIM, (uint16_t)camXF);
PS1_MEM_WriteInt16(TWINE_CAMY, (int16_t)camYF);
PS1_MEM_WriteInt(TWINE_CAMY_AIM, (int32_t)camYF);
}
88 changes: 88 additions & 0 deletions games/ps2_beverlyhillscop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//===========================================================
// Mouse Injector for Dolphin
//==========================================================================
// Copyright (C) 2019-2020 Carnivorous
// All rights reserved.
//
// Mouse Injector is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, visit http://www.gnu.org/licenses/gpl-2.0.html
//==========================================================================
#include <stdint.h>
#include "../main.h"
#include "../memory.h"
#include "../mouse.h"
#include "game.h"

#define BHC_CAMY 0x31DC90
#define BHC_CAMX_BASE_PTR 0x31D050
// offset from camX base
#define BHC_CAMX 0xE38

#define BHC_CAN_ACT 0x3BD4B8

static uint8_t PS2_BHC_Status(void);
static void PS2_BHC_Inject(void);

static const GAMEDRIVER GAMEDRIVER_INTERFACE =
{
"Beverly Hills Cop",
PS2_BHC_Status,
PS2_BHC_Inject,
1, // 1000 Hz tickrate
0 // crosshair sway not supported for driver
};

const GAMEDRIVER *GAME_PS2_BEVERLYHILLSCOP = &GAMEDRIVER_INTERFACE;

uint32_t camXBase = 0;

//==========================================================================
// Purpose: return 1 if game is detected
//==========================================================================
static uint8_t PS2_BHC_Status(void)
{
// SLES_544.56
return (PS2_MEM_ReadWord(0x93390) == 0x534C4553U &&
PS2_MEM_ReadWord(0x93394) == 0x5F353434U &&
PS2_MEM_ReadWord(0x93398) == 0x2E35363BU);
}
//==========================================================================
// Purpose: calculate mouse look and inject into current game
//==========================================================================
static void PS2_BHC_Inject(void)
{
if(xmouse == 0 && ymouse == 0) // if mouse is idle
return;

if (!PS2_MEM_ReadUInt(BHC_CAN_ACT))
return;

camXBase = PS2_MEM_ReadUInt(BHC_CAMX_BASE_PTR);
if (!camXBase)
return;

float looksensitivity = (float)sensitivity / 40.f;
float scale = 250.f;

float camX = PS2_MEM_ReadFloat(camXBase + BHC_CAMX);
float camY = PS2_MEM_ReadFloat(BHC_CAMY);

camX += (float)xmouse * looksensitivity / scale;
camY -= (float)(invertpitch ? -ymouse : ymouse) * looksensitivity / scale;

camY = ClampFloat(camY, -1.221730471f, 1.221730471f);

PS2_MEM_WriteFloat(camXBase + BHC_CAMX, (float)camX);
PS2_MEM_WriteFloat(BHC_CAMY, (float)camY);

}
123 changes: 123 additions & 0 deletions games/ps2_returntocastlewolf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//===========================================================
// Mouse Injector for Dolphin
//==========================================================================
// Copyright (C) 2019-2020 Carnivorous
// All rights reserved.
//
// Mouse Injector is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, visit http://www.gnu.org/licenses/gpl-2.0.html
//==========================================================================
#include <stdint.h>
#include "../main.h"
#include "../memory.h"
#include "../mouse.h"
#include "game.h"

#define RTCW_ACTUAL_CAMY_BASE_PTR 0x236974
#define RTCW_CAM_Y 0x5E4034
#define RTCW_CAM_X 0x5E4038
#define RTCW_FOV 0x5AFEC0
#define RTCW_SANITY 0x5E4050

#define RTCW_IS_PAUSED 0x236490

#define RTCW_CURRENT_WEAPON 0xD459E0

static uint8_t PS2_RTCW_Status(void);
static uint8_t PS2_RTCW_DetectCam(void);
static void PS2_RTCW_Inject(void);

static const GAMEDRIVER GAMEDRIVER_INTERFACE =
{
"Return to Castle Wolfenstein: Operation Resurrection",
PS2_RTCW_Status,
PS2_RTCW_Inject,
1, // 1000 Hz tickrate
0 // crosshair sway not supported for driver
};

const GAMEDRIVER *GAME_PS2_RETURNTOCASTLEWOLF = &GAMEDRIVER_INTERFACE;

static uint32_t actualCamYBase = 0;

//==========================================================================
// Purpose: return 1 if game is detected
//==========================================================================
static uint8_t PS2_RTCW_Status(void)
{
// SLUS_202.97
return (PS2_MEM_ReadWord(0x00093390) == 0x534C5553U &&
PS2_MEM_ReadWord(0x00093394) == 0x5F323032U &&
PS2_MEM_ReadWord(0x00093398) == 0x2E39373BU);
}

static uint8_t PS2_RTCW_DetectCam(void)
{
uint32_t tempCamBase = PS2_MEM_ReadUInt(RTCW_ACTUAL_CAMY_BASE_PTR);
if (tempCamBase)
{
actualCamYBase = tempCamBase;
return 1;
}
return 0;
}

static void PS2_RTCW_Inject(void)
{
// TODO: Disable on menu, as camera addresses are used by something else
// check for some kind of base, look for camera values as offsets with debugger
// TODO: disable during mission end stats (optional)
// make sure it's not based on the graphic appearing as you can get close
// to the exit without leaving to see stats

// TODO: current weapon base
// TODO: check if current weapon has ammo before switching
// TODO: change weapon keys based on weapon type (pistols, SMG, sniper, etc)
// pressing same key will scroll through weapons of same type
// TODO: attach silence button (switches to silenced variant of current weapon)
// TODO: prevent weapon switch while reloading or stop reload when switching

// uint32_t currentWeapon = PS2_MEM_ReadUInt(RTCW_CURRENT_WEAPON);
// if (K_1)
// PS2_MEM_WriteUInt(RTCW_CURRENT_WEAPON, 1);
// if (K_2)
// PS2_MEM_WriteUInt(RTCW_CURRENT_WEAPON, 2);
// if (K_3)
// PS2_MEM_WriteUInt(RTCW_CURRENT_WEAPON, 3);

if(xmouse == 0 && ymouse == 0) // if mouse is idle
return;

// if (!PS2_RTCW_DetectCam())
// return;

if (PS2_MEM_ReadWord(RTCW_SANITY) != 0x48554E4BU)
return;

if (PS2_MEM_ReadUInt(RTCW_IS_PAUSED))
return;

float looksensitivity = (float)sensitivity / 40.f;
float scale = 5.f;
float fov = PS2_MEM_ReadFloat(RTCW_FOV) / 106.5f;

float camX = PS2_MEM_ReadFloat(RTCW_CAM_X);
camX -= (float)xmouse * looksensitivity / scale * fov;
PS2_MEM_WriteFloat(RTCW_CAM_X, (float)camX);

float camY = PS2_MEM_ReadFloat(RTCW_CAM_Y);
camY += (float)(invertpitch ? -ymouse : ymouse) * looksensitivity / scale * fov;
// game clamps internally to actual camY
PS2_MEM_WriteFloat(RTCW_CAM_Y, (float)camY);

}
3 changes: 3 additions & 0 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#define BUILDINFO "(v0.31 - "__DATE__")"
#define LINE "__________________________________________________________________"
// input for interface
#define K_1 GetAsyncKeyState(0x31) // key '1'
#define K_2 GetAsyncKeyState(0x32) // key '2'
#define K_3 GetAsyncKeyState(0x33) // key '3'
#define K_4 GetAsyncKeyState(0x34) // key '4'
#define K_5 GetAsyncKeyState(0x35) // key '5'
#define K_6 GetAsyncKeyState(0x36) // key '6'
Expand Down

0 comments on commit ae12d7d

Please sign in to comment.