mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2024-12-22 20:17:24 +08:00
refactor!: repo cleanup (#2650)
- Move cmake files to dedicated cmake folder - Move scattered python files to `scripts/` folder - Update CMakeLists.txt to reflect changes * feat(scripts): add README to folder
This commit is contained in:
parent
22e15e95d6
commit
9a1a75b675
@ -5,19 +5,19 @@ project(YimMenu CXX ASM_MASM)
|
|||||||
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
|
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
|
||||||
|
|
||||||
# Git commit embed
|
# Git commit embed
|
||||||
include(scripts/git.cmake)
|
include(cmake/git.cmake)
|
||||||
|
|
||||||
# Fetch modules
|
# Fetch modules
|
||||||
message("\nFetching modules")
|
message("\nFetching modules")
|
||||||
include(scripts/minhook.cmake)
|
include(cmake/minhook.cmake)
|
||||||
include(scripts/async-logger.cmake)
|
include(cmake/async-logger.cmake)
|
||||||
include(scripts/pugixml.cmake)
|
include(cmake/pugixml.cmake)
|
||||||
include(scripts/json.cmake)
|
include(cmake/json.cmake)
|
||||||
include(scripts/cpr.cmake)
|
include(cmake/cpr.cmake)
|
||||||
include(scripts/lua.cmake)
|
include(cmake/lua.cmake)
|
||||||
include(scripts/imgui.cmake)
|
include(cmake/imgui.cmake)
|
||||||
message("\nFetching custom modules")
|
message("\nFetching custom modules")
|
||||||
include(scripts/gtav-classes.cmake)
|
include(cmake/gtav-classes.cmake)
|
||||||
|
|
||||||
|
|
||||||
# YimMenu
|
# YimMenu
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
message("AsyncLogger")
|
message("AsyncLogger")
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
AsyncLogger
|
AsyncLogger
|
||||||
GIT_REPOSITORY https://github.com/Yimura/AsyncLogger.git
|
GIT_REPOSITORY https://github.com/Yimura/AsyncLogger.git
|
||||||
GIT_TAG v0.0.6
|
GIT_TAG v0.0.6
|
||||||
GIT_PROGRESS TRUE
|
GIT_PROGRESS TRUE
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(AsyncLogger)
|
FetchContent_MakeAvailable(AsyncLogger)
|
||||||
|
|
||||||
set_property(TARGET AsyncLogger PROPERTY CXX_STANDARD 23)
|
set_property(TARGET AsyncLogger PROPERTY CXX_STANDARD 23)
|
39
scripts/README.md
Normal file
39
scripts/README.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# Scripts
|
||||||
|
|
||||||
|
This directory contains a collection of scripts used to generate certain parts of the code base.
|
||||||
|
|
||||||
|
## Doc Gen
|
||||||
|
|
||||||
|
`doc_gen.py` is used to generate the Lua documentation that's provided by YimMenu.
|
||||||
|
It relies on specifically formatted code comments to generate Lua documentation.
|
||||||
|
|
||||||
|
## Generate Natives
|
||||||
|
|
||||||
|
`generate_natives.py` is responsible for generating the `src/natives.hpp` and `src/invoker/crossmap.hpp` files.
|
||||||
|
|
||||||
|
It takes a `natives.json` from [here](https://github.com/alloc8or/gta5-nativedb-data) and a `crossmap.txt` file which needs follow a certain format of:
|
||||||
|
```csv
|
||||||
|
[first_seen_native_hash]<comma>[current_native_hash]
|
||||||
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```csv
|
||||||
|
0xE1A0450ED46A7812,0x11FD21BA1B765FE2
|
||||||
|
0x39BE7CEA8D9CC8E6,0x5F7C6361179DFFC4
|
||||||
|
0x3C5FD37B5499582E,0x54BC5E0B6A29AE8A
|
||||||
|
0xE2A99A9B524BEFFF,0x1FDE21A286357401
|
||||||
|
0x51F1A8E48C3D2F6D,0xD1BAD83E70275AEB
|
||||||
|
0x0A6D923DFFC9BD89,0x93693D93BD53ACB1
|
||||||
|
0x112CEF1615A1139F,0x203607236413B185
|
||||||
|
0xD47A2C1BA117471D,0x4F3198DEED415E95
|
||||||
|
0xC2F7FE5309181C7D,0xCFE92984BF3486D5
|
||||||
|
0x23789E777D14CE44,0x2B3725FC402B94A8
|
||||||
|
0x350AA5EBC03D3BD2,0x606408352C7741AD
|
||||||
|
0x498C1E05CE5F7877,0x59E8FA762FB527C5
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
## Natives Gen
|
||||||
|
|
||||||
|
`natives_gen.py` is used to generate the Lua bindings for all the natives currently present in the menu.
|
||||||
|
It'll read through the `src/natives.hpp` file and generate the appropriate bindings under `src/lua/natives/`.
|
File diff suppressed because it is too large
Load Diff
@ -1,123 +1,123 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
crossmap = {}
|
crossmap = {}
|
||||||
natives = {}
|
natives = {}
|
||||||
current_idx = 0
|
current_idx = 0
|
||||||
crossmap_hash_list = []
|
crossmap_hash_list = []
|
||||||
|
|
||||||
class Arg:
|
class Arg:
|
||||||
def __init__(self, name: str, type: str):
|
def __init__(self, name: str, type: str):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = type#.replace("BOOL", "bool")# .replace("Any*", "void*")
|
self.type = type#.replace("BOOL", "bool")# .replace("Any*", "void*")
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return str(self.type) + " " + str(self.name)
|
return str(self.type) + " " + str(self.name)
|
||||||
|
|
||||||
class NativeFunc:
|
class NativeFunc:
|
||||||
def __init__(self, namespace: str, name: str, hash: int, args: list[dict], return_type: str):
|
def __init__(self, namespace: str, name: str, hash: int, args: list[dict], return_type: str):
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
self.name = name
|
self.name = name
|
||||||
self.hash = hash
|
self.hash = hash
|
||||||
self.args: list[Arg] = []
|
self.args: list[Arg] = []
|
||||||
self.return_type = return_type#.replace("BOOL", "bool")# .replace("Any*", "void*")
|
self.return_type = return_type#.replace("BOOL", "bool")# .replace("Any*", "void*")
|
||||||
self.native_index = -1
|
self.native_index = -1
|
||||||
self.fix_vectors = "false"
|
self.fix_vectors = "false"
|
||||||
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
self.args.append(Arg(arg["name"], arg["type"]))
|
self.args.append(Arg(arg["name"], arg["type"]))
|
||||||
if arg["type"] == "Vector3*":
|
if arg["type"] == "Vector3*":
|
||||||
self.fix_vectors = "true"
|
self.fix_vectors = "true"
|
||||||
|
|
||||||
def get_native_def_str(self) -> str:
|
def get_native_def_str(self) -> str:
|
||||||
assert self.native_index != -1
|
assert self.native_index != -1
|
||||||
|
|
||||||
param_decl = ""
|
param_decl = ""
|
||||||
param_pass = ""
|
param_pass = ""
|
||||||
if len(self.args) > 0:
|
if len(self.args) > 0:
|
||||||
for arg in self.args:
|
for arg in self.args:
|
||||||
param_decl += str(arg) + ", "
|
param_decl += str(arg) + ", "
|
||||||
param_pass += arg.name + ", "
|
param_pass += arg.name + ", "
|
||||||
param_decl = param_decl[:-2]
|
param_decl = param_decl[:-2]
|
||||||
param_pass = param_pass[:-2]
|
param_pass = param_pass[:-2]
|
||||||
|
|
||||||
return f"FORCEINLINE constexpr {self.return_type} {self.name}({param_decl}) {{ return big::native_invoker::invoke<{self.native_index}, {self.fix_vectors}, {self.return_type}>({param_pass}); }}"
|
return f"FORCEINLINE constexpr {self.return_type} {self.name}({param_decl}) {{ return big::native_invoker::invoke<{self.native_index}, {self.fix_vectors}, {self.return_type}>({param_pass}); }}"
|
||||||
|
|
||||||
class CrossmapEntry:
|
class CrossmapEntry:
|
||||||
def __init__(self, translated_hash: int):
|
def __init__(self, translated_hash: int):
|
||||||
self.hash = translated_hash
|
self.hash = translated_hash
|
||||||
self.native_index = -1
|
self.native_index = -1
|
||||||
|
|
||||||
def load_crossmap_data():
|
def load_crossmap_data():
|
||||||
global crossmap
|
global crossmap
|
||||||
|
|
||||||
data = open("crossmap.txt").readlines()
|
data = open("crossmap.txt").readlines()
|
||||||
for item in data:
|
for item in data:
|
||||||
translation = item.split(",")
|
translation = item.split(",")
|
||||||
crossmap[int(translation[0], 16)] = CrossmapEntry(int(translation[1], 16))
|
crossmap[int(translation[0], 16)] = CrossmapEntry(int(translation[1], 16))
|
||||||
|
|
||||||
def load_natives_data():
|
def load_natives_data():
|
||||||
global natives
|
global natives
|
||||||
|
|
||||||
data = json.load(open("natives.json"))
|
data = json.load(open("natives.json"))
|
||||||
for ns, natives_list in data.items():
|
for ns, natives_list in data.items():
|
||||||
natives[ns] = []
|
natives[ns] = []
|
||||||
for hash_str, native_data in natives_list.items():
|
for hash_str, native_data in natives_list.items():
|
||||||
natives[ns].append(NativeFunc(ns, native_data["name"], int(hash_str, 16), native_data["params"], native_data["return_type"]))
|
natives[ns].append(NativeFunc(ns, native_data["name"], int(hash_str, 16), native_data["params"], native_data["return_type"]))
|
||||||
|
|
||||||
def allocate_indices():
|
def allocate_indices():
|
||||||
global current_idx, crossmap_hash_list
|
global current_idx, crossmap_hash_list
|
||||||
|
|
||||||
for _, n in natives.items():
|
for _, n in natives.items():
|
||||||
for native in n:
|
for native in n:
|
||||||
hash = native.hash
|
hash = native.hash
|
||||||
if hash in crossmap:
|
if hash in crossmap:
|
||||||
crossmap[hash].native_index = current_idx
|
crossmap[hash].native_index = current_idx
|
||||||
native.native_index = current_idx
|
native.native_index = current_idx
|
||||||
crossmap_hash_list.append(crossmap[hash].hash)
|
crossmap_hash_list.append(crossmap[hash].hash)
|
||||||
current_idx += 1
|
current_idx += 1
|
||||||
|
|
||||||
|
|
||||||
def write_crossmap_header():
|
def write_crossmap_header():
|
||||||
open("crossmap.hpp", "w+").write(f"""#pragma once
|
open("crossmap.hpp", "w+").write(f"""#pragma once
|
||||||
#include <script/scrNativeHandler.hpp>
|
#include <script/scrNativeHandler.hpp>
|
||||||
|
|
||||||
namespace big
|
namespace big
|
||||||
{{
|
{{
|
||||||
constexpr std::array<rage::scrNativeHash, {len(crossmap_hash_list)}> g_crossmap = {{{",".join([f"0x{x:X}" for x in crossmap_hash_list])}}};
|
constexpr std::array<rage::scrNativeHash, {len(crossmap_hash_list)}> g_crossmap = {{{",".join([f"0x{x:X}" for x in crossmap_hash_list])}}};
|
||||||
}}
|
}}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def write_natives_header():
|
def write_natives_header():
|
||||||
natives_buf = ""
|
natives_buf = ""
|
||||||
natives_index_buf = ""
|
natives_index_buf = ""
|
||||||
|
|
||||||
for ns, nvs in natives.items():
|
for ns, nvs in natives.items():
|
||||||
natives_buf += f"namespace {ns}\n{{\n"
|
natives_buf += f"namespace {ns}\n{{\n"
|
||||||
for nat_data in nvs:
|
for nat_data in nvs:
|
||||||
if nat_data.native_index == -1:
|
if nat_data.native_index == -1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
natives_buf += f"\t{nat_data.get_native_def_str()}\n"
|
natives_buf += f"\t{nat_data.get_native_def_str()}\n"
|
||||||
natives_index_buf += f"\t{nat_data.name} = {nat_data.native_index},\n"
|
natives_index_buf += f"\t{nat_data.name} = {nat_data.native_index},\n"
|
||||||
natives_buf += "}\n\n"
|
natives_buf += "}\n\n"
|
||||||
|
|
||||||
natives_buf = natives_buf[:-2]
|
natives_buf = natives_buf[:-2]
|
||||||
|
|
||||||
open("../natives.hpp", "w+").write(f"""#pragma once
|
open("../natives.hpp", "w+").write(f"""#pragma once
|
||||||
#include "invoker/invoker.hpp"
|
#include "invoker/invoker.hpp"
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
enum class NativeIndex
|
enum class NativeIndex
|
||||||
{{
|
{{
|
||||||
{natives_index_buf}}};
|
{natives_index_buf}}};
|
||||||
|
|
||||||
{natives_buf}
|
{natives_buf}
|
||||||
// clang-format on
|
// clang-format on
|
||||||
""")
|
""")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
load_crossmap_data()
|
load_crossmap_data()
|
||||||
load_natives_data()
|
load_natives_data()
|
||||||
allocate_indices()
|
allocate_indices()
|
||||||
write_crossmap_header()
|
write_crossmap_header()
|
||||||
write_natives_header()
|
write_natives_header()
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user