This commit is contained in:
aap 2019-05-30 00:47:33 +02:00
parent b705be0e87
commit 0a36d49d2c
20 changed files with 115 additions and 302 deletions

View File

@ -7,6 +7,8 @@ such that we have a working game at all times.
Apparently you can download a binary of the latest version Apparently you can download a binary of the latest version
[here](https://ci.appveyor.com/api/projects/aap/re3/artifacts/bin%2FReleaseCI%2Fre3.dll?branch=master). [here](https://ci.appveyor.com/api/projects/aap/re3/artifacts/bin%2FReleaseCI%2Fre3.dll?branch=master).
Re3 starts the script main_freeroam.scm by default. Make sure you copy it to your data directory.
# Strategy # Strategy
A good approach is to start at the fringes of the code base, A good approach is to start at the fringes of the code base,
@ -43,6 +45,9 @@ CCollision
CCullZones CCullZones
CTheZones CTheZones
CPathFind CPathFind
CCam
CParticle
CParticleMgr
``` ```
# Low hanging fruit # Low hanging fruit

BIN
gamefiles/main_d.scm Normal file

Binary file not shown.

BIN
gamefiles/main_freeroam.scm Normal file

Binary file not shown.

View File

@ -1,5 +1,4 @@
#pragma once
class CGeneral class CGeneral
{ {
@ -46,8 +45,8 @@ public:
{ return myrand() & 0xFFFF; } { return myrand() & 0xFFFF; }
// Probably don't want to ever reach high // Probably don't want to ever reach high
static float GetRandomNumberInRange(float low, float high) static float GetRandomNumberInRange(float low, float high)
{ return low + (high - low)*(GetRandomNumber()/float(MY_RAND_MAX + 1)); } { return low + (high - low)*(GetRandomNumber()/65536.0f); }
static Int32 GetRandomNumberInRange(Int32 low, Int32 high) static Int32 GetRandomNumberInRange(Int32 low, Int32 high)
{ return low + (high - low)*(GetRandomNumber()/float(MY_RAND_MAX + 1)); } { return low + (high - low)*(GetRandomNumber()/65536.0f); }
}; };

View File

@ -1,5 +0,0 @@
#include "common.h"
#include "RecordDataForChase.h"
UInt8 &CRecordDataForChase::Status = *(UInt8*)0x95CDCE;

View File

@ -1,7 +0,0 @@
#pragma once
class CRecordDataForChase
{
public:
static UInt8 &Status;
};

View File

@ -1,4 +0,0 @@
#include "common.h"
#include "RecordDataForGame.h"
UInt16 &CRecordDataForGame::RecordingState = *(UInt16 *)0x95CC24;

View File

@ -1,10 +1,9 @@
#include <Windows.h>
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include "DMAudio.h" #include "DMAudio.h"
#include "Record.h"
#include "Timer.h" #include "Timer.h"
#include "RecordDataForGame.h"
#include "RecordDataForChase.h"
#include <Windows.h>
uint32 &CTimer::m_snTimeInMilliseconds = *(uint32*)0x885B48; uint32 &CTimer::m_snTimeInMilliseconds = *(uint32*)0x885B48;
uint32 &CTimer::m_snTimeInMillisecondsPauseMode = *(uint32*)0x5F7614; uint32 &CTimer::m_snTimeInMillisecondsPauseMode = *(uint32*)0x5F7614;
@ -229,4 +228,3 @@ STARTPATCHES
InjectHook(0x4AD4A0, CTimer::EndUserPause, PATCH_JUMP); InjectHook(0x4AD4A0, CTimer::EndUserPause, PATCH_JUMP);
ENDPATCHES ENDPATCHES
#endif #endif

View File

@ -18,32 +18,29 @@
#define rwVENDORID_ROCKSTAR 0x0253F2 #define rwVENDORID_ROCKSTAR 0x0253F2
typedef uint8_t uint8; // Get rid of bullshit windows definitions, we're not running on an 8086
typedef int8_t int8; #ifdef far
typedef uint16_t uint16; #undef far
typedef int16_t int16; #endif
typedef uint32_t uint32; #ifdef near
typedef int32_t int32; #undef near
typedef uintptr_t uintptr; #endif
typedef uint8_t uint8, UInt8;
typedef int8_t int8, Int8;
typedef uint16_t uint16, UInt16;
typedef int16_t int16, Int16;
typedef uint32_t uint32, UInt32;
typedef int32_t int32, Int32;
typedef uintptr_t uintptr;
typedef uint64_t uint64, UInt64;
typedef int64_t int64, Int64;
typedef char Int8;
typedef unsigned char UInt8;
typedef signed char SInt8;
typedef short Int16;
typedef unsigned short UInt16;
typedef signed short SInt16;
typedef int Int32;
typedef unsigned int UInt32;
typedef signed int SInt32;
typedef float Float; typedef float Float;
typedef double Double; typedef double Double;
typedef Int8 Bool; //typedef bool Bool; typedef bool Bool;
typedef char Char; typedef char Char;
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
typedef signed __int64 SInt64;
#define nil NULL #define nil NULL
#include "config.h" #include "config.h"
@ -85,10 +82,10 @@ extern RsGlobalType &RsGlobal;
#define DEFAULT_SCREEN_HEIGHT (448) #define DEFAULT_SCREEN_HEIGHT (448)
#define SCREEN_WIDTH Float(RsGlobal.width) #define SCREEN_WIDTH Float(RsGlobal.width)
#define SCREEN_HEIGHT Float(RsGlobal.height) #define SCREEN_HEIGHT Float(RsGlobal.height)
#define SCREEN_STRETCH_X(a) Float( a * ( SCREEN_WIDTH / Float(DEFAULT_SCREEN_WIDTH) ) ) #define SCREEN_STRETCH_X(a) Float((a) * (SCREEN_WIDTH / Float(DEFAULT_SCREEN_WIDTH)))
#define SCREEN_STRETCH_Y(a) Float( a * ( SCREEN_HEIGHT / Float(DEFAULT_SCREEN_HEIGHT) ) ) #define SCREEN_STRETCH_Y(a) Float((a) * (SCREEN_HEIGHT / Float(DEFAULT_SCREEN_HEIGHT)))
#define SCREEN_FROM_RIGHT(a) Float( SCREEN_WIDTH - SCREEN_STRETCH_X(a) ) #define SCREEN_FROM_RIGHT(a) Float(SCREEN_WIDTH - SCREEN_STRETCH_X(a))
#define SCREEN_FROM_BOTTOM(a) Float( SCREEN_HEIGHT - SCREEN_STRETCH_Y(a) ) #define SCREEN_FROM_BOTTOM(a) Float(SCREEN_HEIGHT - SCREEN_STRETCH_Y(a))
char *GetUserDirectory(void); char *GetUserDirectory(void);
@ -120,41 +117,29 @@ public:
CRGBA(void) { } CRGBA(void) { }
CRGBA(uint8 r, uint8 g, uint8 b, uint8 a) : r(r), g(g), b(b), a(a) { } CRGBA(uint8 r, uint8 g, uint8 b, uint8 a) : r(r), g(g), b(b), a(a) { }
#ifdef RWCORE_H #ifdef RWCORE_H
operator RwRGBA &(void) operator RwRGBA &(void) {
{
return rwRGBA; return rwRGBA;
} }
operator RwRGBA *(void) operator RwRGBA *(void) {
{
return &rwRGBA; return &rwRGBA;
} }
operator RwRGBA (void) const operator RwRGBA (void) const {
{
return rwRGBA; return rwRGBA;
} }
#endif #endif
}; };
// inline float clamp(float v, float min, float max){ return v<min ? min : v>max ? max : v; } #define clamp(v, low, high) ((v)<(low) ? (low) : (v)>(high) ? (high) : (v))
inline float inline float sq(float x) { return x*x; }
sq(float x) { return x*x; } #define SQR(x) ((x) * (x))
#define SQR(x) ( x * x )
#define PI M_PI #define PI M_PI
#define DEGTORAD(x) ((x) * PI / 180.0f) #define DEGTORAD(x) ((x) * PI / 180.0f)
#define RADTODEG(x) ((x) * 180.0f / PI) #define RADTODEG(x) ((x) * 180.0f / PI)
#if USE_PS2_RAND == TRUE
#define MY_RAND_MAX 65535
#else
#define MY_RAND_MAX 32767
#endif
int myrand(void); int myrand(void);
void mysrand(unsigned int seed); void mysrand(unsigned int seed);
@ -167,10 +152,6 @@ void mysrand(unsigned int seed);
#define VALIDATE_SIZE(struc, size) static_assert(sizeof(struc) == size, "Invalid structure size of " #struc) #define VALIDATE_SIZE(struc, size) static_assert(sizeof(struc) == size, "Invalid structure size of " #struc)
#define VALIDATE_OFFSET(struc, member, offset) static_assert(offsetof(struc, member) == offset, "The offset of " #member " in " #struc " is not " #offset "...") #define VALIDATE_OFFSET(struc, member, offset) static_assert(offsetof(struc, member) == offset, "The offset of " #member " in " #struc " is not " #offset "...")
#define clamp(v, a, b) (max(min(v, b), a)) #define PERCENT(x, p) ((Float(x) * (Float(p) / 100.0f)))
//#define min(a, b) ((a) < (b) ? (a) : (b))
//#define max(a, b) ((a) > (b) ? (a) : (b))
#define PERCENT(x, p) ( ( Float(x) * ( Float(p) / 100.0f ) ) )
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
#define BIT(num) (1<<(num)) #define BIT(num) (1<<(num))

View File

@ -1,5 +1,4 @@
#ifndef _CONFIG_H_ #pragma once
#define _CONFIG_H_
enum Config { enum Config {
NUMCDIMAGES = 50, // was 12 NUMCDIMAGES = 50, // was 12
@ -52,7 +51,3 @@ enum Config {
NUMWEATHERS = 4, NUMWEATHERS = 4,
NUMHOURS = 24, NUMHOURS = 24,
}; };
#define USE_PS2_RAND TRUE
#endif

6
src/control/Record.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "common.h"
#include "Record.h"
UInt16 &CRecordDataForGame::RecordingState = *(UInt16*)0x95CC24;
UInt8 &CRecordDataForChase::Status = *(UInt8*)0x95CDCE;

View File

@ -5,3 +5,9 @@ class CRecordDataForGame
public: public:
static UInt16 &RecordingState; static UInt16 &RecordingState;
}; };
class CRecordDataForChase
{
public:
static UInt8 &Status;
};

View File

@ -24,37 +24,22 @@ void operator delete(void *ptr) noexcept { gtadelete(ptr); }
unsigned __int64 myrand_seed = 1; unsigned __int64 myrand_seed = 1;
int _cwrand() // original codewarrior rand
{
return ((int (__cdecl *)())0x5A41D0)();
}
int int
myps2rand(void) myps2rand(void)
{ {
return _cwrand();
myrand_seed = 0x5851F42D4C957F2D * myrand_seed + 1; myrand_seed = 0x5851F42D4C957F2D * myrand_seed + 1;
return ((myrand_seed >> 32) & 0x7FFFFFFF); return ((myrand_seed >> 32) & 0x7FFFFFFF);
} }
int myrand(void) int myrand(void)
{ {
#if USE_PS2_RAND == TRUE
return myps2rand(); return myps2rand();
#else
return _cwrand();
#endif
} }
void void
mysrand(unsigned int seed) mysrand(unsigned int seed)
{ {
#if USE_PS2_RAND == TRUE
myrand_seed = seed; myrand_seed = seed;
#else
;
#endif
} }
// platform stuff // platform stuff

View File

@ -1,78 +0,0 @@
#include "common.h"
#include "Vector.h"
void CVector::Normalise()
{
float sq = MagnitudeSqr();
if(sq > 0.0f){
float invsqrt = 1.0f/sqrt(sq); // CMaths::RecipSqrt
x *= invsqrt;
y *= invsqrt;
z *= invsqrt;
}else
x = 1.0f;
}
// operator +
CVector operator + (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x + refRight.x, refLeft.y + refRight.y, refLeft.z + refRight.z);
}
CVector operator + (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x + fRight, refLeft.y + fRight, refLeft.z + fRight);
}
CVector operator + (float fLeft, CVector const &refRight)
{
return CVector(fLeft + refRight.x, fLeft + refRight.y, fLeft + refRight.z);
}
// operator -
CVector operator - (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x - refRight.x, refLeft.y - refRight.y, refLeft.z - refRight.z);
}
CVector operator - (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x - fRight, refLeft.y - fRight, refLeft.z - fRight);
}
CVector operator - (float fLeft, CVector const &refRight)
{
return CVector(fLeft - refRight.x, fLeft - refRight.y, fLeft - refRight.z);
}
// operator *
CVector operator * (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x * refRight.x, refLeft.y * refRight.y, refLeft.z * refRight.z);
}
CVector operator * (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x * fRight, refLeft.y * fRight, refLeft.z * fRight);
}
CVector operator * (float fLeft, CVector const &refRight)
{
return CVector(fLeft * refRight.x, fLeft * refRight.y, fLeft * refRight.z);
}
// operator /
CVector operator / (CVector const &refLeft, CVector const &refRight)
{
return CVector(refLeft.x / refRight.x, refLeft.y / refRight.y, refLeft.z / refRight.z);
}
CVector operator / (CVector const &refLeft, float fRight)
{
return CVector(refLeft.x / fRight, refLeft.y / fRight, refLeft.z / fRight);
}
CVector operator / (float fLeft, CVector const &refRight)
{
return CVector(fLeft / refRight.x, fLeft / refRight.y, fLeft / refRight.z);
}

View File

@ -6,128 +6,71 @@ public:
float x, y, z; float x, y, z;
CVector(void) {} CVector(void) {}
CVector(float x, float y, float z) : x(x), y(y), z(z) {} CVector(float x, float y, float z) : x(x), y(y), z(z) {}
// CVector(CVector &refVector) : x(refVector.x), y(refVector.y), z(refVector.z) { }
// CVector(const CVector &refVector) : x(refVector.x), y(refVector.y), z(refVector.z) {}
// CVector(CVector2D &refVector, float _z = 0.0f) : x(refVector.x), y(refVector.y), z(_z) {}
#ifdef RWCORE_H #ifdef RWCORE_H
CVector(RwV3d const &v) : x(v.x), y(v.y), z(v.z) {} CVector(const RwV3d &v) : x(v.x), y(v.y), z(v.z) {}
operator RwV3d (void) const { operator RwV3d (void) const {
RwV3d vecRw = { this->x, this->y, this->z }; RwV3d vecRw = { this->x, this->y, this->z };
return vecRw; return vecRw;
} }
operator RwV3d *(void) operator RwV3d *(void) {
{ return (RwV3d*)this;
return (RwV3d *)this;
} }
operator RwV3d &(void) operator RwV3d &(void) {
{ return *((RwV3d*)this);
return *((RwV3d *)this);
} }
#endif #endif
float Magnitude(void) const { return sqrt(x*x + y*y + z*z); } float Magnitude(void) const { return sqrt(x*x + y*y + z*z); }
float MagnitudeSqr(void) const { return x*x + y*y + z*z; } float MagnitudeSqr(void) const { return x*x + y*y + z*z; }
float Magnitude2D(void) const { return sqrt(x*x + y*y); } float Magnitude2D(void) const { return sqrt(x*x + y*y); }
void Normalise(void); void Normalise(void) {
float sq = MagnitudeSqr();
if(sq > 0.0f){
float invsqrt = 1.0f/sqrt(sq); // CMaths::RecipSqrt
x *= invsqrt;
y *= invsqrt;
z *= invsqrt;
}else
x = 1.0f;
}
inline const CVector &operator+=(CVector const &right) {
// operator = x += right.x;
inline CVector const& operator = (CVector const &refRight) y += right.y;
{ z += right.z;
x = refRight.x;
y = refRight.y;
z = refRight.z;
return *this; return *this;
} }
inline CVector const& operator = (float fRight) inline const CVector &operator-=(CVector const &right) {
{ x -= right.x;
x = fRight; y -= right.y;
y = fRight; z -= right.z;
z = fRight;
return *this; return *this;
} }
// operator += inline const CVector &operator*=(float right) {
inline CVector const& operator += (CVector const &refRight) x *= right;
{ y *= right;
x += refRight.x; z *= right;
y += refRight.y;
z += refRight.z;
return *this; return *this;
} }
inline CVector const& operator += (float fRight) inline const CVector &operator/=(float right) {
{ x /= right;
x += fRight; y /= right;
y += fRight; z /= right;
z += fRight;
return *this; return *this;
} }
// operator -= inline CVector operator-() const {
inline CVector const& operator -= (CVector const &refRight)
{
x -= refRight.x;
y -= refRight.y;
z -= refRight.z;
return *this;
}
inline CVector const& operator -= (float fRight)
{
x -= fRight;
y -= fRight;
z -= fRight;
return *this;
}
// operator *=
inline CVector const& operator *= (CVector const &refRight)
{
x *= refRight.x;
y *= refRight.y;
z *= refRight.z;
return *this;
}
inline CVector const& operator *= (float fRight)
{
x *= fRight;
y *= fRight;
z *= fRight;
return *this;
}
// operator /=
inline CVector const& operator /= (CVector const &refRight)
{
x /= refRight.x;
y /= refRight.y;
z /= refRight.z;
return *this;
}
inline CVector const& operator /= (float fRight)
{
x /= fRight;
y /= fRight;
z /= fRight;
return *this;
}
inline CVector operator - () const
{
return CVector(-x, -y, -z); return CVector(-x, -y, -z);
} }
bool IsZero(void) { return x == 0.0f && y == 0.0f && z == 0.0f; } bool IsZero(void) { return x == 0.0f && y == 0.0f && z == 0.0f; }
}; };
//extern CVector operator*(CMatrix const& matrix, CVector const& vector);
inline float inline float
DotProduct(const CVector &v1, const CVector &v2) DotProduct(const CVector &v1, const CVector &v2)
{ {
@ -143,22 +86,22 @@ CrossProduct(const CVector &v1, const CVector &v2)
v1.x*v2.y - v1.y*v2.x); v1.x*v2.y - v1.y*v2.x);
} }
// operator + inline CVector operator+(const CVector &left, const CVector &right)
extern CVector operator + (CVector const &refLeft, CVector const &refRight); {
extern CVector operator + (CVector const &refLeft, float fRight); return CVector(left.x + right.x, left.y + right.y, left.z + right.z);
extern CVector operator + (float fLeft, CVector const &refRight); }
// operator - inline CVector operator-(const CVector &left, const CVector &right)
extern CVector operator - (CVector const &refLeft, CVector const &refRight); {
extern CVector operator - (CVector const &refLeft, float fRight); return CVector(left.x - right.x, left.y - right.y, left.z - right.z);
extern CVector operator - (float fLeft, CVector const &refRight); }
// operator * inline CVector operator*(const CVector &left, float right)
extern CVector operator * (CVector const &refLeft, CVector const &refRight); {
extern CVector operator * (CVector const &refLeft, float fRight); return CVector(left.x * right, left.y * right, left.z * right);
extern CVector operator * (float fLeft, CVector const &refRight); }
// operator / inline CVector operator/(const CVector &left, float right)
extern CVector operator / (CVector const &refLeft, CVector const &refRight); {
extern CVector operator / (CVector const &refLeft, float fRight); return CVector(left.x / right, left.y / right, left.z / right);
extern CVector operator / (float fLeft, CVector const &refRight); }

View File

@ -1229,7 +1229,9 @@ void CParticle::Update()
moveStep.z = point.point.z; moveStep.z = point.point.z;
if ( psystem->m_Type == PARTICLE_DEBRIS2 ) if ( psystem->m_Type == PARTICLE_DEBRIS2 )
{ {
particle->m_vecVelocity *= CVector(0.8f, 0.8f, -0.4f); particle->m_vecVelocity.x *= 0.8f;
particle->m_vecVelocity.y *= 0.8f;
particle->m_vecVelocity.z *= -0.4f;
if ( particle->m_vecVelocity.z < 0.005f ) if ( particle->m_vecVelocity.z < 0.005f )
particle->m_vecVelocity.z = 0.0f; particle->m_vecVelocity.z = 0.0f;
} }

View File

@ -4,12 +4,6 @@
#include "Camera.h" #include "Camera.h"
#include "Sprite.h" #include "Sprite.h"
// Get rid of bullshit windows definitions, we're not running on an 8086
#ifdef far
#undef far
#undef near
#endif
float &CSprite::m_f2DNearScreenZ = *(float*)0x8F1ABC; float &CSprite::m_f2DNearScreenZ = *(float*)0x8F1ABC;
float &CSprite::m_f2DFarScreenZ = *(float*)0x8F2C94; float &CSprite::m_f2DFarScreenZ = *(float*)0x8F2C94;
float &CSprite::m_fRecipNearClipPlane = *(float*)0x8F5FFC; float &CSprite::m_fRecipNearClipPlane = *(float*)0x8F5FFC;

View File

@ -4,12 +4,6 @@
#include "Camera.h" #include "Camera.h"
#include "Sprite2d.h" #include "Sprite2d.h"
// Get rid of bullshit windows definitions, we're not running on an 8086
#ifdef far
#undef far
#undef near
#endif
RwIm2DVertex *CSprite2d::maVertices = (RwIm2DVertex*)0x6E9168; RwIm2DVertex *CSprite2d::maVertices = (RwIm2DVertex*)0x6E9168;
float &CSprite2d::RecipNearClip = *(float*)0x880DB4; float &CSprite2d::RecipNearClip = *(float*)0x880DB4;
int32 &CSprite2d::mCurrentBank = *(int32*)0x8F1AF4; int32 &CSprite2d::mCurrentBank = *(int32*)0x8F1AF4;
@ -18,7 +12,6 @@ int32 *CSprite2d::mCurrentSprite = (int32*)0x6F4500;
int32 *CSprite2d::mBankStart = (int32*)0x774BE8; int32 *CSprite2d::mBankStart = (int32*)0x774BE8;
RwIm2DVertex *CSprite2d::maBankVertices = (RwIm2DVertex*)0x8429F8; RwIm2DVertex *CSprite2d::maBankVertices = (RwIm2DVertex*)0x8429F8;
void void
CSprite2d::SetRecipNearClip(void) CSprite2d::SetRecipNearClip(void)
{ {