Skip to content

Commit

Permalink
Making it easier to get to know the project (#725)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladik01-11 authored Jun 29, 2024
1 parent fbec0fe commit 70ba56d
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 69 deletions.
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,8 @@ Alternatively, you can install them by yourself:
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]
To run the game with the Modern plugin, you just need to run the "Local Windows Debugger" in Visual Studio.

<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
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
46 changes: 34 additions & 12 deletions contrib/install.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,58 @@
import tkinter as tk
import os
import subprocess
import winreg
from tkinter import filedialog as tkFileDialog
from pathlib import Path
import zipfile
import ctypes
import sys

def set_env_var(name, value):
try:
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', 0, winreg.KEY_ALL_ACCESS)
except WindowsError:
key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, 'Environment')
winreg.SetValueEx(key, name, 0, winreg.REG_SZ, str(value))
winreg.CloseKey(key)

def main():
if not ctypes.windll.shell32.IsUserAnAdmin():
print('Allow the launch as an administrator!')
return ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)

git_repo_root = Path.cwd()
if git_repo_root.parts[-1] == 'contrib':
git_repo_root = git_repo_root.parent

select = tkFileDialog.askopenfilename(
title='Select the executable file from the GTA:SA installation directory',
filetypes=[("GTA:SA", ".exe")], initialdir=os.environ['GTA_SA_DIR'] if 'GTA_SA_DIR' in os.environ else ''
)
if not select:
return input('You have not selected a file, we are leaving. Press Enter...')

gta_sa_file = Path(select)
gta_root_dir = gta_sa_file.parent.resolve()

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
for filename in ('gta_reversed.pdb', 'gta_reversed.asi'):
dst = gta_root_dir / 'scripts' / 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!')
print("The Env variables are changing... If VS is open with the Modern solution, restart VS")
set_env_var('GTA_SA_EXE', gta_sa_file)
set_env_var('GTA_SA_DIR', gta_root_dir)
input('Done! Press Enter...')

if __name__ == "__main__":
main()
34 changes: 0 additions & 34 deletions contrib/link_asi.bat

This file was deleted.

10 changes: 9 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ end
The Solution
--]]

solution "gta_reversed"
workspace "gta_reversed"
startproject "gta_sa_modern"
configurations { "Release", "Debug" }

location(_OPTIONS["outdir"])
Expand Down Expand Up @@ -72,6 +73,13 @@ solution "gta_reversed"
}

include "source/"
local gta_exe = os.getenv("GTA_SA_EXE")
if gta_exe ~= nil and os.isfile(gta_exe) then
debugcommand "$(GTA_SA_EXE)"
else
debugcommand "$(GTA_SA_DIR)/gta_sa.exe"
end
debugdir "$(GTA_SA_DIR)"

group "Dependencies"
defines { "WIN32", "_WINDOWS" }
Expand Down
9 changes: 6 additions & 3 deletions source/game_sa/BouncingPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ float& CBouncingPanel::BOUNCE_HANGING_DAMP_MULT = *(float*)0x8D3960;
float& CBouncingPanel::BOUNCE_HANGING_RETURN_MULT = *(float*)0x8D3964;

void CBouncingPanel::InjectHooks() {
ReversibleHooks::Install("CBouncingPanel", "ResetPanel", 0x6F4910, &CBouncingPanel::ResetPanel);
ReversibleHooks::Install("CBouncingPanel", "SetPanel", 0x6F4920, &CBouncingPanel::SetPanel);
ReversibleHooks::Install("CBouncingPanel", "ProcessPanel", 0x6F49A0, &CBouncingPanel::ProcessPanel);
RH_ScopedClass(CBouncingPanel);
RH_ScopedCategoryGlobal();

RH_ScopedInstall(ResetPanel, 0x6F4910);
RH_ScopedInstall(SetPanel, 0x6F4920);
RH_ScopedInstall(ProcessPanel, 0x6F49A0);
}

// 0x6F4910
Expand Down
4 changes: 2 additions & 2 deletions source/game_sa/CarCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void CCarCtrl::InjectHooks()
RH_ScopedInstall(Init, 0x4212E0);
RH_ScopedInstall(ReInit, 0x4213B0);
RH_ScopedInstall(InitSequence, 0x421740);
Install("CCarCtrl", "ChooseGangCarModel", 0x421A40, &CCarCtrl::ChooseGangCarModel, { .jmpCodeSize = 7 });
Install("CCarCtrl", "ChoosePoliceCarModel", 0x421980, &CCarCtrl::ChoosePoliceCarModel, { .jmpCodeSize = 7 });
RH_ScopedInstall(ChooseGangCarModel, 0x421A40, { .jmpCodeSize = 7 });
RH_ScopedInstall(ChoosePoliceCarModel, 0x421980, { .jmpCodeSize = 7 });
RH_ScopedInstall(CreateCarForScript, 0x431F80);
RH_ScopedInstall(ChooseBoatModel, 0x421970);
RH_ScopedInstall(ChooseCarModelToLoad, 0x421900);
Expand Down
1 change: 1 addition & 0 deletions source/game_sa/PathFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ void CPathFind::ComputeRoute(uint8 nodeType, const CVector& vecStart, const CVec
plugin::CallMethod<0x452760>(this, nodeType, &vecStart, &vecEnd, &address, &nodeRoute);
}

// 0x44D960
void CPathFind::SetLinksBridgeLights(float fXMin, float fXMax, float fYMin, float fYMax, bool value) {
const auto areaRect = CRect{ {fXMin, fYMax}, {fXMax, fYMin} };

Expand Down
2 changes: 1 addition & 1 deletion source/game_sa/PedGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ bool CPedGroup::IsActive() const {

void CPedGroup::InjectHooks() {
RH_ScopedClass(CPedGroup);
RH_ScopedCategory(); // TODO: Change this to the appropriate category!
RH_ScopedCategoryGlobal();

RH_ScopedInstall(Constructor, 0x5FC150);
RH_ScopedInstall(Destructor, 0x5FC190);
Expand Down
2 changes: 1 addition & 1 deletion source/game_sa/PedGroupPlacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

void CPedGroupPlacer::InjectHooks() {
RH_ScopedClass(CPedGroupPlacer);
RH_ScopedCategory(); // TODO: Change this to the appropriate category!
RH_ScopedCategoryGlobal();

RH_ScopedInstall(PlaceFormationGroup, 0x5FC9B0, {.reversed = false});
RH_ScopedInstall(PlaceChatGroup, 0x5FCE80, {.reversed = false});
Expand Down
2 changes: 1 addition & 1 deletion source/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project "gta_reversed"
project "gta_sa_modern"
cppdialect "C++latest" -- C++23
kind "SharedLib"
targetname "gta_reversed"
Expand Down
4 changes: 2 additions & 2 deletions source/toolsmenu/DebugModules/TimeCycleDebugModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ void TimeCycleDebugModule::RenderWindow() {
CWeather::NewWeatherType = static_cast<eWeatherType>(m_NewWeatherType);
}

if (ImGui::SliderInt("Hours", &m_Hours, 0, 23, "%.0f")) {
if (ImGui::SliderInt("Hours", &m_Hours, 0, 23, "%d")) {
CClock::ms_nGameClockHours = static_cast<uint8>(m_Hours);
}
if (ImGui::SliderInt("Minutes", &m_Minutes, 0, 59, "%.0f")) {
if (ImGui::SliderInt("Minutes", &m_Minutes, 0, 59, "%d")) {
CClock::ms_nGameClockMinutes = static_cast<uint8>(m_Minutes);
}

Expand Down

0 comments on commit 70ba56d

Please sign in to comment.