Skip to content

Instantly share code, notes, and snippets.

@ikt32
Last active August 12, 2019 07:44
Show Gist options
  • Save ikt32/933899c32ba90a5684c9c13b80383ef9 to your computer and use it in GitHub Desktop.
Save ikt32/933899c32ba90a5684c9c13b80383ef9 to your computer and use it in GitHub Desktop.
// Warning: These are non-compiling code snippets from a larger project.
// Warning: Defunct, check Compatibility.cpp/h now. This is only kept as a reference.
#include <Windows.h>
namespace MT
{
////Gears.asi integration/////
static HMODULE Module;
static bool FunctionsPresent;
static bool(*NeutralGear)(void) = nullptr;
static int(*GetShiftIndicator)(void) = nullptr;
static void* CheckAddr(HMODULE lib, const char* funcName)
{
FARPROC mtFunc = GetProcAddress(lib, funcName);
if (mtFunc == nullptr)
{
logger.Writef("%s not available", funcName);
return nullptr;
}
logger.Writef("%s available", funcName);
return mtFunc;
}
}
void initialize()
{
//Gears.asi integration
MT::Module = GetModuleHandle("Gears.asi");
if (MT::Module)
{
MT::FunctionsPresent = true;
MT::NeutralGear = (bool(*)(void))MT::CheckAddr(MT::Module, "MT_NeutralGear");
MT::FunctionsPresent &= (MT::NeutralGear != nullptr);
MT::GetShiftIndicator = (int(*)(void))MT::CheckAddr(MT::Module, "MT_GetShiftIndicator");
MT::FunctionsPresent &= (MT::GetShiftIndicator != nullptr);
if (MT::FunctionsPresent)
{
logger.Write("Manual Transmission functions present");
}
else
{
logger.Write("Manual Transmission functions not present");
}
}
}
void something_onTick()
{
if (MT::FunctionsPresent)
{
int shiftIndicator = MT::GetShiftIndicator();
switch (shiftIndicator)
{
case 1: displayIndicator = DisplayIndicator::Up; break;
case 2: displayIndicator = DisplayIndicator::Down; break;
default: break;
}
if (MT::NeutralGear())
{
displayGear = DisplayGears::N;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment