Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-menezes committed Apr 28, 2024
0 parents commit 4319bd3
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
.idea
.vs
cmake-build-debug
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.19)

project(sa-asi-loader VERSION 1.0 LANGUAGES CXX)

set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(CMAKE_CXX_STANDARD 17)

add_library(vorbisFile SHARED dllmain.cpp)
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Carlos Menezes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# sa-asi-loader

A simple [ASI Loader](https://gtamods.com/wiki/ASI_Loader) for Grand Theft Auto: San Andreas.

## Requirements

- cmake 3.19 (or higher)
- Visual Studio 17 2022

## Building

1. `mkdir build`
2. `cd build`
3. `cmake .. -G "Visual Studio 17 2022" -A Win32`
4. `cmake --build .` (optionally, suffix with `--config Release`)

A `vorbisFile.dll` will be output to the `Debug`/`Release` folder. Before moving that file into the root folder of GTA: San Andreas, rename the original `vorbisFile.dll` to `vorbisFileHooked.dll` (or whichever name you specify in as the original file in `dllmain.h`).

Your directory should look like this:

```
GTA San Andreas
`-- vorbis.dll
`-- vorbisFile.dll (the build artifact)
`-- vorbisFileHooked.dll (the renamed, original file)
```

You should then be able to load any ASI mod upon starting up the game.
49 changes: 49 additions & 0 deletions dllmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "pch.h"
#include "dllmain.h"

#include <windows.h>
#include <string>
#include <vector>
#include <filesystem>

HMODULE DLL_ENTRY_POINT;

static void GetASIFiles(const std::wstring& directory, std::vector<std::wstring>* out) {
WIN32_FIND_DATAW findFileData;
HANDLE hFind = FindFirstFileW(directory.c_str(), &findFileData);

if (hFind != INVALID_HANDLE_VALUE) {
do {
if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
out->push_back(directory.substr(0, directory.find_last_of(L'\\') + 1) + findFileData.cFileName);
}
} while (FindNextFileW(hFind, &findFileData) != 0);
FindClose(hFind);
}
}

static void InitializeASILoader() {
wchar_t modulePath[MAX_PATH];
GetModuleFileNameW(nullptr, modulePath, MAX_PATH);

// Get the directory containing the DLL
std::wstring dllDirectory = modulePath;
dllDirectory = dllDirectory.substr(0, dllDirectory.find_last_of(L"\\") + 1);

// Find all .asi files in the directory
std::vector<std::wstring> asiFiles;
GetASIFiles(dllDirectory + L"*.asi", &asiFiles);

// Load each .asi file
for (const auto& asiFile : asiFiles) {
LoadLibraryW(asiFile.c_str());
}
}

static BOOL APIENTRY DllMain(HMODULE hModule, const DWORD ul_reason_for_call, LPVOID lpReserved) {
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
DLL_ENTRY_POINT = hModule;
InitializeASILoader();
}
return TRUE;
}
36 changes: 36 additions & 0 deletions dllmain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#pragma comment(linker,"/export:ov_bitrate=vorbisFileHooked.ov_bitrate,@1")
#pragma comment(linker,"/export:ov_bitrate_instant=vorbisFileHooked.ov_bitrate_instant,@2")
#pragma comment(linker,"/export:ov_clear=vorbisFileHooked.ov_clear,@3")
#pragma comment(linker,"/export:ov_comment=vorbisFileHooked.ov_comment,@4")
#pragma comment(linker,"/export:ov_crosslap=vorbisFileHooked.ov_crosslap,@5")
#pragma comment(linker,"/export:ov_halfrate=vorbisFileHooked.ov_halfrate,@6")
#pragma comment(linker,"/export:ov_halfrate_p=vorbisFileHooked.ov_halfrate_p,@7")
#pragma comment(linker,"/export:ov_info=vorbisFileHooked.ov_info,@8")
#pragma comment(linker,"/export:ov_open=vorbisFileHooked.ov_open,@9")
#pragma comment(linker,"/export:ov_open_callbacks=vorbisFileHooked.ov_open_callbacks,@10")
#pragma comment(linker,"/export:ov_pcm_seek=vorbisFileHooked.ov_pcm_seek,@11")
#pragma comment(linker,"/export:ov_pcm_seek_lap=vorbisFileHooked.ov_pcm_seek_lap,@12")
#pragma comment(linker,"/export:ov_pcm_seek_page=vorbisFileHooked.ov_pcm_seek_page,@13")
#pragma comment(linker,"/export:ov_pcm_seek_page_lap=vorbisFileHooked.ov_pcm_seek_page_lap,@14")
#pragma comment(linker,"/export:ov_pcm_tell=vorbisFileHooked.ov_pcm_tell,@15")
#pragma comment(linker,"/export:ov_pcm_total=vorbisFileHooked.ov_pcm_total,@16")
#pragma comment(linker,"/export:ov_raw_seek=vorbisFileHooked.ov_raw_seek,@17")
#pragma comment(linker,"/export:ov_raw_seek_lap=vorbisFileHooked.ov_raw_seek_lap,@18")
#pragma comment(linker,"/export:ov_raw_tell=vorbisFileHooked.ov_raw_tell,@19")
#pragma comment(linker,"/export:ov_raw_total=vorbisFileHooked.ov_raw_total,@20")
#pragma comment(linker,"/export:ov_read=vorbisFileHooked.ov_read,@21")
#pragma comment(linker,"/export:ov_read_float=vorbisFileHooked.ov_read_float,@22")
#pragma comment(linker,"/export:ov_seekable=vorbisFileHooked.ov_seekable,@23")
#pragma comment(linker,"/export:ov_serialnumber=vorbisFileHooked.ov_serialnumber,@24")
#pragma comment(linker,"/export:ov_streams=vorbisFileHooked.ov_streams,@25")
#pragma comment(linker,"/export:ov_test=vorbisFileHooked.ov_test,@26")
#pragma comment(linker,"/export:ov_test_callbacks=vorbisFileHooked.ov_test_callbacks,@27")
#pragma comment(linker,"/export:ov_test_open=vorbisFileHooked.ov_test_open,@28")
#pragma comment(linker,"/export:ov_time_seek=vorbisFileHooked.ov_time_seek,@29")
#pragma comment(linker,"/export:ov_time_seek_lap=vorbisFileHooked.ov_time_seek_lap,@30")
#pragma comment(linker,"/export:ov_time_seek_page=vorbisFileHooked.ov_time_seek_page,@31")
#pragma comment(linker,"/export:ov_time_seek_page_lap=vorbisFileHooked.ov_time_seek_page_lap,@32")
#pragma comment(linker,"/export:ov_time_tell=vorbisFileHooked.ov_time_tell,@33")
#pragma comment(linker,"/export:ov_time_total=vorbisFileHooked.ov_time_total,@34")
5 changes: 5 additions & 0 deletions framework.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files
#include <windows.h>
5 changes: 5 additions & 0 deletions pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// pch.cpp: source file corresponding to the pre-compiled header

#include "pch.h"

// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
13 changes: 13 additions & 0 deletions pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// pch.h: This is a precompiled header file.
// Files listed below are compiled only once, improving build performance for future builds.
// This also affects IntelliSense performance, including code completion and many code browsing features.
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
// Do not add files here that you will be updating frequently as this negates the performance advantage.

#ifndef PCH_H
#define PCH_H

// add headers that you want to pre-compile here
#include "framework.h"

#endif //PCH_H

0 comments on commit 4319bd3

Please sign in to comment.