Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
yukani committed Aug 1, 2023
2 parents 25a1cf2 + 9eb18e0 commit c58ac9a
Show file tree
Hide file tree
Showing 253 changed files with 6,436 additions and 2,411 deletions.
14 changes: 11 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[submodule "libs/vorbis"]
path = libs/vorbis
url = https://github.com/xiph/vorbis
url = https://github.com/xiph/vorbis.git
[submodule "libs/ogg"]
path = libs/ogg
url = https://github.com/xiph/ogg
url = https://github.com/xiph/ogg.git
[submodule "libs/imgui"]
path = libs/imgui
url = ../../ocornut/imgui.git
url = https://github.com/ocornut/imgui.git
branch = docking
[submodule "libs/spdlog"]
path = libs/spdlog
url = https://github.com/gabime/spdlog.git
[submodule "libs/tracy"]
path = libs/tracy
url = https://github.com/wolfpld/tracy.git

3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (MSVC)
set(CMAKE_GENERATOR_PLATFORM Win32)
endif()
Expand Down
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,19 @@ Building this project will result in a DLL file that can be injected into GTA:SA

### Progress
The progress of reversed classes can be tracked [here](docs/ReversedClasses.MD). (needs to be updated)
We currently estimate that about 50-60% of the code is done.
Since this project is done as a hobby, and worked on at irregular intervals, there's no real time estimate.

### Coding Guidelines
Before you start writing code, please make sure to read the [coding guidelines](docs/CodingGuidelines.MD) for this project.

### Requirements

* [Visual Studio 2022](https://visualstudio.microsoft.com/en/downloads/) (Community Edition is enough)
* [CMake](https://cmake.org) (for those who want to use CMake instead of premake5)

#### Game

* GTA SA **Compact** exe
* [ASI Loader](https://gtaforums.com/topic/523982-relopensrc-silents-asi-loader/)
* [III.VC.SA.WindowedMode.asi](https://github.com/ThirteenAG/III.VC.SA.WindowedMode)
* [Improved Fast Loader](https://www.gtagarage.com/mods/show.php?id=25665) (Optional)
* Mouse Fix (**dinput8.dll**)

You can download them in a single [archive](https://github.com/codenulls/gta-reversed/files/6949371/gta_sa.zip).
Using other plugins is strongly discouraged as the compact version doesn't like them.

### Build Instructions

You can either build with **Premake5** or **CMake**; that's up to you, but a C++20 capable compiler with <ranges> support is required.
You can either build with **Premake5** or **CMake**; that's up to you, but a C++20 capable compiler [with `<ranges>`, `<format>` support] is required.

First clone the project, including the submodules:
```shell
Expand All @@ -39,10 +29,11 @@ git clone --recurse-submodules https://github.com/gta-reversed/gta-reversed-mode
<details>
<summary>Premake5</summary>

1) Execute `premake5.bat` for 2022, or `premake5.bat vs20xx` for other VS versions. (Note: Premake works fine with vs2019, CMake requires vs2022) (e.g: `premake5.bat vs2019`)
1) Execute `premake5.bat`

2) You'll find gta_reversed.sln shortcut in the same folder as premake5.

3) Open it, and once the project has loaded, just hit `CTRL + SHIFT + B`
</details>

<details>
Expand Down Expand Up @@ -80,13 +71,30 @@ git clone --recurse-submodules https://github.com/gta-reversed/gta-reversed-mode

</details>

### Game
To install all the necessary files, run `install.py` with **__administrator privileges__** [Necessary to create symlinks on Windows] in the root directory.
Alternatively, you can install them by yourself:

* GTA SA **Compact** exe
* [ASI Loader](https://gtaforums.com/topic/523982-relopensrc-silents-asi-loader/)
* [III.VC.SA.WindowedMode.asi](https://github.com/ThirteenAG/III.VC.SA.WindowedMode)
* Mouse Fix (**dinput8.dll**) [Can be found in the zip in `./contrib`]

You can download them in a single [archive](https://github.com/gta-reversed/gta-reversed-modern/blob/master/contrib/plugins.zip).
Using other plugins is strongly discouraged and we provide __**no support**__.

### Preparing Environment (Optional)
[If you have ran `install.py` in the previous step then this step is already done]

You can create symbolic links for artifacts to not copy them every time you compiled the project.
<details>
<summary>Instructions</summary>

You can create symbolic links [symlinks] for artifacts [the `.asi`] to need not copy them every time you compile the project.

Open a console with administrator privileges in the git repo's directory and run `contrib\link_asi.bat` or right click `link_asi.bat` file and click `Run as administrator`, then
Open a console with **__administrator privileges__** in the git repo's directory and run `contrib\link_asi.bat` or right click `link_asi.bat` file and click `Run as administrator`, then
follow instructions at the command window.

</details>

### What to work on?
Check [this](https://github.com/gta-reversed/gta-reversed-modern/discussions/402) out for some inspiration ;)
Expand Down
5 changes: 3 additions & 2 deletions contrib/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if %errorlevel% neq 0 (
echo CMake is required to use this tool. Exiting.
exit
)

REM rm -rf build/
cmake --build ./build --target clean
cmake -Bbuild -H. -A Win32
cmake --build build
cmake --build build
124 changes: 124 additions & 0 deletions contrib/clean-srs-calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
"""
Python script to format garbage RwRenderStateSet calls to be nice
Make sure to copy the garbage looking code to the clipboard, then run the program
And the output will be set on the clipboard.
When pasting to VS make sure to press CTRL Z once, because it automatically gets formatted incorrectly
"""

import pyperclip as pyc # If the program fails here, please run `pip install pyperclip`
from typing import Type
import re
from enum import Enum

def cint(val : str): # C-style int
return int(val.rstrip('u'))

def cenum(enum_type : Type[Enum]): # enum cast
return lambda val: enum_type(cint(val)).name

def cbool(val : str): # c-style capitalized bool [TRUE, FALSE]
return str(bool(val)).upper()

#
# RW renderstate enums
#

class RwTextureAddressMode(Enum):
rwTEXTUREADDRESSNATEXTUREADDRESS = 0
rwTEXTUREADDRESSWRAP = 1
rwTEXTUREADDRESSMIRROR = 2
rwTEXTUREADDRESSCLAMP = 3
rwTEXTUREADDRESSBORDER = 4

class RwBlendFunction(Enum):
rwBLENDNABLEND = 0
rwBLENDZERO = 1
rwBLENDONE = 2
rwBLENDSRCCOLOR = 3
rwBLENDINVSRCCOLOR = 4
rwBLENDSRCALPHA = 5
rwBLENDINVSRCALPHA = 6
rwBLENDDESTALPHA = 7
rwBLENDINVDESTALPHA = 8
rwBLENDDESTCOLOR = 9
rwBLENDINVDESTCOLOR = 10
rwBLENDSRCALPHASAT = 11

class RwAlphaTestFunction(Enum):
rwALPHATESTFUNCTIONNAALPHATESTFUNCTION = 0
rwALPHATESTFUNCTIONNEVER = 1
rwALPHATESTFUNCTIONLESS = 2
rwALPHATESTFUNCTIONEQUAL = 3
rwALPHATESTFUNCTIONLESSEQUAL = 4
rwALPHATESTFUNCTIONGREATER = 5
rwALPHATESTFUNCTIONNOTEQUAL = 6
rwALPHATESTFUNCTIONGREATEREQUAL = 7
rwALPHATESTFUNCTIONALWAYS = 8


# Render state to type mapping
RwRenderState_To_Type = {
# None - Not yet implemented
# Any other type means that the value has to be of that type

'rwRENDERSTATENARENDERSTATE': cint,
'rwRENDERSTATETEXTURERASTER': str, # pointer in reality
'rwRENDERSTATETEXTUREADDRESS': cenum(RwTextureAddressMode),
'rwRENDERSTATETEXTUREADDRESSU': cenum(RwTextureAddressMode),
'rwRENDERSTATETEXTUREADDRESSV': cenum(RwTextureAddressMode),
'rwRENDERSTATETEXTUREPERSPECTIVE': None,
'rwRENDERSTATEZTESTENABLE': cbool,
'rwRENDERSTATESHADEMODE': None,
'rwRENDERSTATEZWRITEENABLE': cbool,
'rwRENDERSTATETEXTUREFILTER': None,
'rwRENDERSTATESRCBLEND': cenum(RwBlendFunction),
'rwRENDERSTATEDESTBLEND': cenum(RwBlendFunction),
'rwRENDERSTATEVERTEXALPHAENABLE': cbool,
'rwRENDERSTATEBORDERCOLOR': cint,
'rwRENDERSTATEFOGENABLE': cbool,
'rwRENDERSTATEFOGCOLOR': cbool,
'rwRENDERSTATEFOGTYPE': None,
'rwRENDERSTATEFOGDENSITY': int,
'rwRENDERSTATECULLMODE': None,
'rwRENDERSTATESTENCILENABLE': cbool,
'rwRENDERSTATESTENCILFAIL': None,
'rwRENDERSTATESTENCILZFAIL': None,
'rwRENDERSTATESTENCILPASS': None,
'rwRENDERSTATESTENCILFUNCTION': None,
'rwRENDERSTATESTENCILFUNCTIONREF': str,
'rwRENDERSTATESTENCILFUNCTIONMASK': None,
'rwRENDERSTATESTENCILFUNCTIONWRITEMASK': None,
'rwRENDERSTATEALPHATESTFUNCTION': cenum(RwAlphaTestFunction),
'rwRENDERSTATEALPHATESTFUNCTIONREF': None,
}

input("Make sure to have copied the code to the clipboard!")

# Example user input
# RwEngineInstance->dOpenDevice.fpRenderStateSet(rwRENDERSTATEZWRITEENABLE, 0);
# RwEngineInstance->dOpenDevice.fpRenderStateSet(rwRENDERSTATEZTESTENABLE, 1u);
# RwEngineInstance->dOpenDevice.fpRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, 1u);
# RwEngineInstance->dOpenDevice.fpRenderStateSet(rwRENDERSTATEFOGENABLE, 0);
# RwEngineInstance->dOpenDevice.fpRenderStateSet(rwRENDERSTATESRCBLEND, 5u);
# RwEngineInstance->dOpenDevice.fpRenderStateSet(rwRENDERSTATEDESTBLEND, 6u);
# RwEngineInstance->dOpenDevice.fpRenderStateSet(rwRENDERSTATETEXTURERASTER, (unsigned int)gpCloudMaskTex->raster);

# Tuples of (state_name, state_value); [Ex.: ("rwRENDERSTATEZWRITEENABLE", "0")]
input_values : list[tuple[str, str]] = [
re.search(r'\((\w+), (.+)\)', line).groups()
for line in pyc.paste().splitlines()
]

# Find longest name
longest = max(len(n) for (n, v) in input_values)

# Format it
output = []
for n, v in input_values:
value_type = RwRenderState_To_Type[n]
if value_type is None:
raise NotImplementedError(f'Value type for state {n} is not yet implemented!')
output.append(
f'RwRenderStateSet({n}, {" " * (longest - len(n))}RWRSTATE({value_type(v)}));'
)
pyc.copy('\n'.join(output))
36 changes: 36 additions & 0 deletions contrib/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import tkinter as tk
import os
import subprocess
from tkinter import filedialog as tkFileDialog
from pathlib import Path
import zipfile

def main():
git_repo_root = Path.cwd()

gta_root_dir = Path(tkFileDialog.askdirectory(
title='Select GTA:SA install directory'
))
gta_scripts_dir = gta_root_dir / 'scripts'

# Unpack zip into gta dir
print("Unpacking `plugins.zip` into GTA:SA root directory...")
with zipfile.ZipFile(git_repo_root / 'contrib' / 'plugins.zip') as plugins_zip:
plugins_zip.extractall(gta_root_dir)

# Create symlinks
config_name = input("Choose configuration to link (debug/release, default: debug): ") or 'debug'
print(f"Creating the symlinks for `{config_name}` configuration...")
config_bin_dir = git_repo_root / 'bin' / Path(config_name)
print(f'{config_bin_dir=}')
for filename in ('gta_reversed.pdb', 'gta_reversed.asi',):
dst = gta_scripts_dir / filename
dst.unlink(missing_ok=True) # Delete symlink if it already exists
# This fails [WinError 1314] if the script isn't run with admin rights [softlinks require it]
# To run as admin just open an admin cmd, and type `python ./install.py` in the repo root dir
os.symlink(config_bin_dir / filename, dst)

print('Done!')

if __name__ == "__main__":
main()
Binary file added contrib/plugins.zip
Binary file not shown.
61 changes: 48 additions & 13 deletions docs/CodingGuidelines.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* Please check and try to eliminate warnings from your code.

### Code style
* 4 space indentation, LF line endings.
* If some rule about something is not specified here, refer to how it's done in the code.
* Some classes may have *helper* functions to make code more readable. (usually denoted by *NOTSA* or *Helpers*) Try looking for and use them.
* 4 space indentation, LF line endings
* No hungarian notation [It's useless]
* If some rule about something is not specified here, refer to how it's done in the code
* Some classes may have *helper* functions to make code more readable. (Denoted by *NOTSA*) - Try adding new ones, or looking for and using them.
* Prefer `get`-ters/`set`-ters over raw member access
* Use range-based for loops as much as possible.
* We encourage you to write modern C++, but if that's not your style, please keep the following in mind:
```cpp
for (auto& element : array); // <-- GOOD

Expand All @@ -17,23 +20,55 @@ for (int i = 0; i < std::size(array); i++); // <-- BAD
```cpp
for (auto&& [i, e] : notsa::enumerate(array));
```
* If there's a dynamic `count` variable associated with a fixed size array, use `std::span` or `rng::views::take`. E.g.:
```cpp
// Bad
for (auto i = 0u; i < m_numThings; i++);

// Good
for (auto& thing : std::span{ m_things, m_numThings });
// Also good
for (auto& thing : m_things | rng::views::take(m_numThings));

* Use `f` in float literals, omitting it makes them double. (e.g. `1.0f`)
* Use `std` library for generic functions like `min`, `max`, `lerp` etc.
* Function prototypes must look like it's from Android symbols. Except for output parameters like `T*` can be changed to `T&` to make the code prettier.
* Use lambdas for repetitive procedures in functions.
* Use `constexpr` variables instead of macros.
// ^ If these funcs are called more than once, make a helper function in the header. Like below:
auto GetActiveThings() {
return std::span{ m_things, m_numThings }
}
* Use `f` in float literals [As omitting it would make them a `double`] (e.g. `1.0f`)
* Use `std` library for generic functions like `min`, `max`, `lerp`, etc...
* `CVector` is interchangible with 3 floats [As is `CVector2D` with 2 floats] for function args
* Use lambdas for repetitive procedures in functions
* Use `constexpr` variables instead of macros
* Use `static inline` instead of `extern` and `static` in headers:
```cpp
class Foo {
static uint32& m_FooCount; // Bad

static inline auto& m_FooCount = StaticRef<uint32, 0xDEADBEEF>(); // Good
}
```
#### Types
* Use `auto` in function bodies if the variables' type is guessable.
* Guess for enum values, at least leave a TODO comment for it.
* Take care of const correctness. (e.g. `const char*` over `char*`)
* Guess for enum values [Or at least leave a `TODO` comment]
* Take care of const correctness [Especially of class methods] (e.g. `const char*` over `char*`)
* Try to use SA types over RW as much as possible, **except** `RwMatrix`. (e.g. `CVector` for `RwV3d`, `CRGBA` for `RwRGBA`)
* Use fixed width integer types (e.g. `uint8`, `int32`).
* Use `std::array` for arrays most of the time. Do not use it if the variable is just a pair of values or something basic like that.
* Do not use Win32 types. (e.g. `DWORD` -> `uint32`)
* Do not use Win32 integer types. [Except for Win32 exclusive code] (e.g. `DWORD` -> `uint32`)
* For array sizes, etc.. prefer using `unsigned` types over `signed` ones
* Whenever possible use `std::array` over `C-Style` array [as the former has bounds checking in debug mode, and can help us discover many bugs]
#### Fixing bugs
Whenever you find a bug, we encourage you to fix it [and/or at least] leave a comment explaining what the bug is.
Bug fixes should only be active if `notsa::IsFixBugs()` returns `true`.
If that's not possible [due to code complexity], then wrap into an `#ifdef`:
```c
#ifdef FIX_BUGS
// Bug fixing code here
#endif
```

### Contributing
Please make sure to test your contribution before opening a PR. Guess what places/missions are affected by your code and test them. Use debug menu (F7) for quick access to stuff.
Please make sure to test your code before opening a PR. Guess what places/missions are affected by your code and test them. Use debug menu (F7) for quick access to stuff.

If you don't know how to test the code or think you have not tested enough specify it in the PR message.
11 changes: 11 additions & 0 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ set(OGG_FOUND 1)

add_subdirectory(vorbis EXCLUDE_FROM_ALL)

option(SPDLOG_ENABLE_PCH "" ON)
option(SPDLOG_USE_STD_FORMAT "" ON)
add_subdirectory(spdlog EXCLUDE_FROM_ALL)

#############################################################################################
############# create the imgui project
#############################################################################################
Expand Down Expand Up @@ -39,3 +43,10 @@ target_include_directories(imgui PUBLIC
)
target_link_libraries(imgui PRIVATE d3d9 ${CMAKE_DL_LIBS})
target_compile_definitions(imgui PRIVATE _CRT_SECURE_NO_WARNINGS)

# set options before add_subdirectory
# available options: TRACY_ENABLE , TRACY_ON_DEMAND , TRACY_NO_BROADCAST , TRACY_NO_CODE_TRANSFER , ...
option(TRACY_ENABLE "" ON)
option(TRACY_ON_DEMAND "" ON)
option(TRACY_CALLSTACK "" ON)
add_subdirectory(tracy) # target: TracyClient or alias Tracy :: TracyClient
2 changes: 1 addition & 1 deletion libs/imgui
Submodule imgui updated 189 files
Loading

0 comments on commit c58ac9a

Please sign in to comment.