Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aap committed May 15, 2019
0 parents commit 600bf03
Show file tree
Hide file tree
Showing 116 changed files with 15,132 additions and 0 deletions.
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Intro

The aim of this project is to reverse GTA III for PC by replacing
parts of the game [one by one](https://en.wikipedia.org/wiki/Ship_of_Theseus)
such that we have a working game at all times.

# Strategy

A good approach is to start at the fringes of the code base,
i.e. classes that don't depend on code that we don't have reversed yet.
If a function uses only few unreversed functions that would be inconvenient
to reverse at the time, calling the original functions is acceptable.

# Progress

This is a list of some things that have been reversed to some non-trivial extent.
Not everything is listed, check the code.

```
CPool
CTxdStore
CVector
CVector2D
CMatrix
CModelInfo
CBaseModelInfo
CSimpleModelInfo
CTimeModelInfo
CClumpModelInfo
CPedModelInfo
CVehicleModelInfo
CVisibilityPlugins
CRenderer
CEntity
CPhysical
CCollision
CCullZones
CTheZones
CPathFind
```

# Low hanging fruit

There are a couple of things that have been reversed for other projects
already that could probably be put into this project without too much effort.
Again, the list is not complete:

* Animation (https://github.com/aap/iii_anim)
* File Loader (https://github.com/aap/librwgta/tree/master/tools/IIItest)
* ...

# Coding style

I started writing in [Plan 9 style](http://man.cat-v.org/plan_9/6/style),
but realize that this is not the most popular style, so I'm willing to compromise.
Try not to deviate too much so the code will look similar across the whole project.

To give examples, these two styles (or anything in between) are fine:

```
type
functionname(args)
{
if(a == b){
s1;
s2;
}
if(x != y)
s3;
}
type functionname(args)
{
if (a == b) {
s1;
s2;
}
if (x != y)
s3;
}
```

This one (or anything more extreme) is heavily discouraged:

```
type functionname ( args )
{
if ( a == b )
{
s1;
s2;
}
if ( x != y )
{
s3;
}
}
```

Indentation is done with TABS.

1 change: 1 addition & 0 deletions premake5.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
premake5 vs2015
Binary file added premake5.exe
Binary file not shown.
38 changes: 38 additions & 0 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
workspace "re3"
configurations { "Release","Debug" }
location "build"

files { "src/*.*" }
files { "src/math/*.*" }
files { "src/modelinfo/*.*" }
files { "src/entities/*.*" }
files { "src/render/*.*" }

includedirs { "src", "src/modelinfo" }
includedirs { "src", "src/entities" }
includedirs { "src", "src/render" }
includedirs { os.getenv("RWSDK33") }

project "re3"
kind "SharedLib"
language "C++"
targetname "re3"
targetdir "bin/%{cfg.buildcfg}"
targetextension ".dll"
characterset ("MBCS")

filter "configurations:Debug"
defines { "DEBUG" }
flags { "StaticRuntime" }
symbols "On"
debugdir "C:/Users/aap/games/gta3_re"
debugcommand "C:/Users/aap/games/gta3_re/gta3.exe"
postbuildcommands "copy /y \"$(TargetPath)\" \"C:\\Users\\aap\\games\\gta3_re\\plugins\\re3.dll\""

filter "configurations:Release"
defines { "NDEBUG" }
optimize "On"
flags { "StaticRuntime" }
debugdir "C:/Users/aap/games/gta3_re"
debugcommand "C:/Users/aap/games/gta3_re/gta3.exe"
postbuildcommands "copy /y \"$(TargetPath)\" \"C:\\Users\\aap\\games\\gta3_re\\plugins\\re3.dll\""
63 changes: 63 additions & 0 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "common.h"
#include "patcher.h"
#include "Draw.h"
#include "Camera.h"

CCamera &TheCamera = *(CCamera*)0x6FACF8;

bool
CCamera::IsSphereVisible(const CVector &center, float radius, const CMatrix *mat)
{
RwV3d c;
c = *(RwV3d*)&center;
RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix);
if(c.y + radius < CDraw::GetNearClipZ()) return false;
if(c.y - radius > CDraw::GetFarClipZ()) return false;
if(c.x*m_vecFrustumNormals[0].x + c.y*m_vecFrustumNormals[0].y > radius) return false;
if(c.x*m_vecFrustumNormals[1].x + c.y*m_vecFrustumNormals[1].y > radius) return false;
if(c.y*m_vecFrustumNormals[2].y + c.z*m_vecFrustumNormals[2].z > radius) return false;
if(c.y*m_vecFrustumNormals[3].y + c.z*m_vecFrustumNormals[3].z > radius) return false;
return true;
}

bool
CCamera::IsPointVisible(const CVector &center, const CMatrix *mat)
{
RwV3d c;
c = *(RwV3d*)&center;
RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix);
if(c.y < CDraw::GetNearClipZ()) return false;
if(c.y > CDraw::GetFarClipZ()) return false;
if(c.x*m_vecFrustumNormals[0].x + c.y*m_vecFrustumNormals[0].y > 0.0f) return false;
if(c.x*m_vecFrustumNormals[1].x + c.y*m_vecFrustumNormals[1].y > 0.0f) return false;
if(c.y*m_vecFrustumNormals[2].y + c.z*m_vecFrustumNormals[2].z > 0.0f) return false;
if(c.y*m_vecFrustumNormals[3].y + c.z*m_vecFrustumNormals[3].z > 0.0f) return false;
return true;
}

bool
CCamera::IsBoxVisible(RwV3d *box, const CMatrix *mat)
{
int i;
int frustumTests[6] = { 0 };
RwV3dTransformPoints(box, box, 8, &mat->m_matrix);

for(i = 0; i < 8; i++){
if(box[i].y < CDraw::GetNearClipZ()) frustumTests[0]++;
if(box[i].y > CDraw::GetFarClipZ()) frustumTests[1]++;
if(box[i].x*m_vecFrustumNormals[0].x + box[i].y*m_vecFrustumNormals[0].y > 0.0f) frustumTests[2]++;
if(box[i].x*m_vecFrustumNormals[1].x + box[i].y*m_vecFrustumNormals[1].y > 0.0f) frustumTests[3]++;
// Why not test z?
// if(box[i].y*m_vecFrustumNormals[2].y + box[i].z*m_vecFrustumNormals[2].z > 0.0f) frustumTests[4]++;
// if(box[i].y*m_vecFrustumNormals[3].y + box[i].z*m_vecFrustumNormals[3].z > 0.0f) frustumTests[5]++;
}
for(i = 0; i < 6; i++)
if(frustumTests[i] == 8)
return false; // Box is completely outside of one plane
return true;
}


STARTPATCHES
InjectHook(0x42C760, &CCamera::IsSphereVisible, PATCH_JUMP);
ENDPATCHES
Loading

0 comments on commit 600bf03

Please sign in to comment.