From 70ba56d0ac55a04881cf0a2444e38a1dce618984 Mon Sep 17 00:00:00 2001
From: Vladik01-11 <70571714+Vladik01-11@users.noreply.github.com>
Date: Sat, 29 Jun 2024 23:29:29 +0300
Subject: [PATCH] Making it easier to get to know the project (#725)
---
README.md | 13 +-----
contrib/install.py | 46 ++++++++++++++-----
contrib/link_asi.bat | 34 --------------
premake5.lua | 10 +++-
source/game_sa/BouncingPanel.cpp | 9 ++--
source/game_sa/CarCtrl.cpp | 4 +-
source/game_sa/PathFind.cpp | 1 +
source/game_sa/PedGroup.cpp | 2 +-
source/game_sa/PedGroupPlacer.cpp | 2 +-
source/premake5.lua | 2 +-
.../DebugModules/TimeCycleDebugModule.cpp | 4 +-
11 files changed, 58 insertions(+), 69 deletions(-)
delete mode 100644 contrib/link_asi.bat
diff --git a/README.md b/README.md
index 93c2f7e240..5a4b977619 100644
--- a/README.md
+++ b/README.md
@@ -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.
-
-Instructions
-
-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.
-
-
-
### What to work on?
Check [this](https://github.com/gta-reversed/gta-reversed-modern/discussions/402) out for some inspiration ;)
diff --git a/contrib/install.py b/contrib/install.py
index f03af96af6..7ed6dc3d0e 100644
--- a/contrib/install.py
+++ b/contrib/install.py
@@ -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()
diff --git a/contrib/link_asi.bat b/contrib/link_asi.bat
deleted file mode 100644
index 6c53e9f87b..0000000000
--- a/contrib/link_asi.bat
+++ /dev/null
@@ -1,34 +0,0 @@
-@echo off
-rem Check for admin rights
-net session >nul 2>&1
-if not %errorlevel% == 0 (
- echo This script needs to be run as administrator!
- pause
- exit
-)
-
-set pwd=%~dp0
-
-:scriptdir_loop
-set /p scriptdir="GTA SA 'scripts' directory path: "
-if "%scriptdir%"=="" (
- echo Invalid path!
- goto scriptdir_loop
-)
-
-set /p scriptname="Name of the script file (default: gta_reversed): "
-if "%scriptname%"=="" set scriptname="gta_reversed"
-
-:scriptconf_loop
-set /p scriptconf="Choose configuration to link (debug/release, default: debug): "
-if "%scriptconf%"=="" set scriptconf=debug
-
-if not "%scriptconf%"=="debug" if not "%scriptconf%"=="release" (
- echo Invalid configuration! Only 'debug' and 'release' is applicable!c
- goto scriptconf_loop
-)
-
-mklink "%scriptdir%\%scriptname%.asi" "%pwd%\..\bin\%scriptconf%\gta_reversed.asi"
-mklink "%scriptdir%\%scriptname%.pdb" "%pwd%\..\bin\%scriptconf%\gta_reversed.pdb"
-
-pause
\ No newline at end of file
diff --git a/premake5.lua b/premake5.lua
index 8e12971abf..03672f124d 100644
--- a/premake5.lua
+++ b/premake5.lua
@@ -27,7 +27,8 @@ end
The Solution
--]]
-solution "gta_reversed"
+workspace "gta_reversed"
+ startproject "gta_sa_modern"
configurations { "Release", "Debug" }
location(_OPTIONS["outdir"])
@@ -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" }
diff --git a/source/game_sa/BouncingPanel.cpp b/source/game_sa/BouncingPanel.cpp
index 16ec0bde7c..6776f2fbfe 100644
--- a/source/game_sa/BouncingPanel.cpp
+++ b/source/game_sa/BouncingPanel.cpp
@@ -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
diff --git a/source/game_sa/CarCtrl.cpp b/source/game_sa/CarCtrl.cpp
index 9b5ebd624d..c5f3ffd9c8 100644
--- a/source/game_sa/CarCtrl.cpp
+++ b/source/game_sa/CarCtrl.cpp
@@ -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);
diff --git a/source/game_sa/PathFind.cpp b/source/game_sa/PathFind.cpp
index 443d20cfa0..001daf1634 100644
--- a/source/game_sa/PathFind.cpp
+++ b/source/game_sa/PathFind.cpp
@@ -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} };
diff --git a/source/game_sa/PedGroup.cpp b/source/game_sa/PedGroup.cpp
index 2f73c8487e..f0f910355f 100644
--- a/source/game_sa/PedGroup.cpp
+++ b/source/game_sa/PedGroup.cpp
@@ -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);
diff --git a/source/game_sa/PedGroupPlacer.cpp b/source/game_sa/PedGroupPlacer.cpp
index 075bb92066..161526b092 100644
--- a/source/game_sa/PedGroupPlacer.cpp
+++ b/source/game_sa/PedGroupPlacer.cpp
@@ -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});
diff --git a/source/premake5.lua b/source/premake5.lua
index 639e39542a..b2591e4d50 100644
--- a/source/premake5.lua
+++ b/source/premake5.lua
@@ -1,4 +1,4 @@
-project "gta_reversed"
+project "gta_sa_modern"
cppdialect "C++latest" -- C++23
kind "SharedLib"
targetname "gta_reversed"
diff --git a/source/toolsmenu/DebugModules/TimeCycleDebugModule.cpp b/source/toolsmenu/DebugModules/TimeCycleDebugModule.cpp
index acf2d0c411..d916589845 100644
--- a/source/toolsmenu/DebugModules/TimeCycleDebugModule.cpp
+++ b/source/toolsmenu/DebugModules/TimeCycleDebugModule.cpp
@@ -67,10 +67,10 @@ void TimeCycleDebugModule::RenderWindow() {
CWeather::NewWeatherType = static_cast(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(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(m_Minutes);
}